def _sympysage_derivative(self): """ EXAMPLES:: sage: from sympy import Derivative sage: f = function('f') sage: sympy_diff = Derivative(f(x)._sympy_(), x._sympy_()) sage: assert diff(f(x),x)._sympy_() == sympy_diff sage: assert diff(f(x),x) == sympy_diff._sage_() TESTS: Check that :trac:`28964` is fixed:: sage: f = function('f') sage: _ = var('x,t') sage: assert diff(f(x, t), t)._sympy_()._sage_() == diff(f(x, t), t) sage: assert diff(f(x, t), x, 2, t)._sympy_()._sage_() == diff(f(x, t), x, 2, t) sage: diff(f(x, t), x).integrate(x) f(x, t) sage: diff(f(x, t), x).integrate(t, algorithm='maxima') integrate(diff(f(x, t), x), t) sage: diff(f(x, t), x).integrate(t, algorithm='sympy') integrate(diff(f(x, t), x), t) sage: integrate(f(x, t), x).diff(t) integrate(diff(f(x, t), t), x) """ from sage.calculus.functional import derivative from sympy.core.containers import Tuple f = self.args[0]._sage_() args = [a._sage_() for arg in self.args[1:] for a in (arg if isinstance(arg, (tuple, Tuple)) else [arg])] return derivative(f, *args)
def special_curve(j, Phi): field = j.parent() if j == field(0) or j == field(1728): return True x = PolynomialRing(field, 'x').gen() f = Phi(x, j) der = derivative(f, x) return f.gcd(der) != 1
def _sympysage_derivative(self): """ EXAMPLES:: sage: from sympy import Derivative sage: f = function('f') sage: sympy_diff = Derivative(f(x)._sympy_(), x._sympy_()) sage: assert diff(f(x),x)._sympy_() == sympy_diff sage: assert diff(f(x),x) == sympy_diff._sage_() """ from sage.calculus.functional import derivative args = [arg._sage_() for arg in self.args] return derivative(*args)
def _sympysage_derivative(self): """ EXAMPLES:: sage: from sympy import Derivative sage: f = function('f') sage: sympy_diff = Derivative(f(x)._sympy_(), x._sympy_()) sage: assert diff(f(x),x)._sympy_() == sympy_diff sage: assert diff(f(x),x) == sympy_diff._sage_() """ from sage.calculus.functional import derivative f = self.args[0]._sage_() args = [[a._sage_() for a in arg] if isinstance(arg, tuple) else arg._sage_() for arg in self.args[2:]] return derivative(f, *args)
def _tderivative_(self, a, b, z, *args, **kwargs): """ EXAMPLES:: sage: hypergeometric([1/3, 2/3], [5], x^2).diff(x) 4/45*x*hypergeometric((4/3, 5/3), (6,), x^2) sage: hypergeometric([1, 2], [x], 2).diff(x) Traceback (most recent call last): ... NotImplementedError: derivative of hypergeometric function with... respect to parameters. Try calling .simplify_hypergeometric()... first. sage: hypergeometric([1/3, 2/3], [5], 2).diff(x) 0 """ diff_param = kwargs['diff_param'] if diff_param in hypergeometric(a, b, 1).variables(): # ignore z raise NotImplementedError("derivative of hypergeometric function " "with respect to parameters. Try calling" " .simplify_hypergeometric() first.") t = (reduce(lambda x, y: x * y, a, 1) * reduce(lambda x, y: x / y, b, Integer(1))) return (t * derivative(z, diff_param) * hypergeometric([c + 1 for c in a], [c + 1 for c in b], z))
def airy_bi(alpha, x=None, hold_derivative=True, **kwds): r""" The Airy Bi function The Airy Bi function `\operatorname{Bi}(x)` is (along with `\operatorname{Ai}(x)`) one of the two linearly independent standard solutions to the Airy differential equation `f''(x) - x f(x) = 0`. It is defined by the initial conditions: .. MATH:: \operatorname{Bi}(0)=\frac{1}{3^{1/6} \Gamma\left(\frac{2}{3}\right)}, \operatorname{Bi}'(0)=\frac{3^{1/6}}{ \Gamma\left(\frac{1}{3}\right)}. Another way to define the Airy Bi function is: .. MATH:: \operatorname{Bi}(x)=\frac{1}{\pi}\int_0^\infty \left[ \exp\left( xt -\frac{t^3}{3} \right) +\sin\left(xt + \frac{1}{3}t^3\right) \right ] dt. INPUT: - ``alpha`` -- Return the `\alpha`-th order fractional derivative with respect to `z`. For `\alpha = n = 1,2,3,\ldots` this gives the derivative `\operatorname{Bi}^{(n)}(z)`, and for `\alpha = -n = -1,-2,-3,\ldots` this gives the `n`-fold iterated integral. .. MATH:: f_0(z) = \operatorname{Bi}(z) f_n(z) = \int_0^z f_{n-1}(t) dt - ``x`` -- The argument of the function - ``hold_derivative`` -- Whether or not to stop from returning higher derivatives in terms of `\operatorname{Bi}(x)` and `\operatorname{Bi}'(x)` .. SEEALSO:: :func:`airy_ai` EXAMPLES:: sage: n, x = var('n x') sage: airy_bi(x) airy_bi(x) It can return derivatives or integrals:: sage: airy_bi(2, x) airy_bi(2, x) sage: airy_bi(1, x, hold_derivative=False) airy_bi_prime(x) sage: airy_bi(2, x, hold_derivative=False) x*airy_bi(x) sage: airy_bi(-2, x, hold_derivative=False) airy_bi(-2, x) sage: airy_bi(n, x) airy_bi(n, x) It can be evaluated symbolically or numerically for real or complex values:: sage: airy_bi(0) 1/3*3^(5/6)/gamma(2/3) sage: airy_bi(0.0) 0.614926627446001 sage: airy_bi(I) airy_bi(I) sage: airy_bi(1.0*I) 0.648858208330395 + 0.344958634768048*I The functions can be evaluated numerically using mpmath, which can compute the values to arbitrary precision, and scipy:: sage: airy_bi(2).n(prec=100) 3.2980949999782147102806044252 sage: airy_bi(2).n(algorithm='mpmath', prec=100) 3.2980949999782147102806044252 sage: airy_bi(2).n(algorithm='scipy') # rel tol 1e-10 3.2980949999782134 And the derivatives can be evaluated:: sage: airy_bi(1, 0) 3^(1/6)/gamma(1/3) sage: airy_bi(1, 0.0) 0.448288357353826 Plots:: sage: plot(airy_bi(x), (x, -10, 5)) + plot(airy_bi_prime(x), ....: (x, -10, 5), color='red') Graphics object consisting of 2 graphics primitives **References** - Abramowitz, Milton; Stegun, Irene A., eds. (1965), "Chapter 10" - :wikipedia:`Airy_function` """ # We catch the case with no alpha if x is None: x = alpha return airy_bi_simple(x, **kwds) # We take care of all other cases. if not alpha in ZZ and not isinstance(alpha, Expression): return airy_bi_general(alpha, x, **kwds) if hold_derivative: return airy_bi_general(alpha, x, **kwds) elif alpha == 0: return airy_bi_simple(x, **kwds) elif alpha == 1: return airy_bi_prime(x, **kwds) elif alpha > 1: # We use a different variable here because if x is a # particular value, we would be differentiating a constant # which would return 0. What we want is the value of # the derivative at the value and not the derivative of # a particular value of the function. v = SR.symbol() return derivative(airy_bi_simple(v, **kwds), v, alpha).subs({v: x}) else: return airy_bi_general(alpha, x, **kwds)
def airy_ai(alpha, x=None, hold_derivative=True, **kwds): r""" The Airy Ai function The Airy Ai function `\operatorname{Ai}(x)` is (along with `\operatorname{Bi}(x)`) one of the two linearly independent standard solutions to the Airy differential equation `f''(x) - x f(x) = 0`. It is defined by the initial conditions: .. MATH:: \operatorname{Ai}(0)=\frac{1}{2^{2/3} \Gamma\left(\frac{2}{3}\right)}, \operatorname{Ai}'(0)=-\frac{1}{2^{1/3}\Gamma\left(\frac{1}{3}\right)}. Another way to define the Airy Ai function is: .. MATH:: \operatorname{Ai}(x)=\frac{1}{\pi}\int_0^\infty \cos\left(\frac{1}{3}t^3+xt\right) dt. INPUT: - ``alpha`` -- Return the `\alpha`-th order fractional derivative with respect to `z`. For `\alpha = n = 1,2,3,\ldots` this gives the derivative `\operatorname{Ai}^{(n)}(z)`, and for `\alpha = -n = -1,-2,-3,\ldots` this gives the `n`-fold iterated integral. .. MATH:: f_0(z) = \operatorname{Ai}(z) f_n(z) = \int_0^z f_{n-1}(t) dt - ``x`` -- The argument of the function - ``hold_derivative`` -- Whether or not to stop from returning higher derivatives in terms of `\operatorname{Ai}(x)` and `\operatorname{Ai}'(x)` .. SEEALSO:: :func:`airy_bi` EXAMPLES:: sage: n, x = var('n x') sage: airy_ai(x) airy_ai(x) It can return derivatives or integrals:: sage: airy_ai(2, x) airy_ai(2, x) sage: airy_ai(1, x, hold_derivative=False) airy_ai_prime(x) sage: airy_ai(2, x, hold_derivative=False) x*airy_ai(x) sage: airy_ai(-2, x, hold_derivative=False) airy_ai(-2, x) sage: airy_ai(n, x) airy_ai(n, x) It can be evaluated symbolically or numerically for real or complex values:: sage: airy_ai(0) 1/3*3^(1/3)/gamma(2/3) sage: airy_ai(0.0) 0.355028053887817 sage: airy_ai(I) airy_ai(I) sage: airy_ai(1.0*I) 0.331493305432141 - 0.317449858968444*I The functions can be evaluated numerically either using mpmath. which can compute the values to arbitrary precision, and scipy:: sage: airy_ai(2).n(prec=100) 0.034924130423274379135322080792 sage: airy_ai(2).n(algorithm='mpmath', prec=100) 0.034924130423274379135322080792 sage: airy_ai(2).n(algorithm='scipy') # rel tol 1e-10 0.03492413042327323 And the derivatives can be evaluated:: sage: airy_ai(1, 0) -1/3*3^(2/3)/gamma(1/3) sage: airy_ai(1, 0.0) -0.258819403792807 Plots:: sage: plot(airy_ai(x), (x, -10, 5)) + plot(airy_ai_prime(x), ....: (x, -10, 5), color='red') Graphics object consisting of 2 graphics primitives REFERENCES: - Abramowitz, Milton; Stegun, Irene A., eds. (1965), "Chapter 10" - :wikipedia:`Airy_function` """ # We catch the case with no alpha if x is None: x = alpha return airy_ai_simple(x, **kwds) # We take care of all other cases. if alpha not in ZZ and not isinstance(alpha, Expression): return airy_ai_general(alpha, x, **kwds) if hold_derivative: return airy_ai_general(alpha, x, **kwds) elif alpha == 0: return airy_ai_simple(x, **kwds) elif alpha == 1: return airy_ai_prime(x, **kwds) elif alpha > 1: # We use a different variable here because if x is a # particular value, we would be differentiating a constant # which would return 0. What we want is the value of # the derivative at the value and not the derivative of # a particular value of the function. v = SR.symbol() return derivative(airy_ai_simple(v, **kwds), v, alpha).subs({v: x}) else: return airy_ai_general(alpha, x, **kwds)
def f(p): return apply_young_idempotent(derivative(p, x), mu)