Ticket #8568: trac_8568-diff-conv-and-erf-deriv.patch

File trac_8568-diff-conv-and-erf-deriv.patch, 3.0 KB (added by kcrisman, 13 years ago)

Apply only this.

  • sage/functions/other.py

    # HG changeset patch
    # User Karl-Dieter Crisman <kcrisman@gmail.com>
    # Date 1274975156 14400
    # Node ID 9bb80f99660c983fe1708d152382bafbd6155af8
    # Parent  27c18494b6cb25ffdad2749fbea6a09efc363916
    Trac 8568 - implement derivative for erf and ensure only legal symbolic derivatives are converted to Maxima
    
    diff -r 27c18494b6cb -r 9bb80f99660c sage/functions/other.py
    a b  
    7979            raise NotImplementedError, "erf not implemented for precision higher than 53"
    8080        return parent(1 - pari(float(x)).erfc())
    8181       
     82    def _derivative_(self, x, diff_param=None):
     83        """
     84        Derivative of erf function
     85
     86        EXAMPLES::
     87
     88            sage: erf(x).diff(x)
     89            2*e^(-x^2)/sqrt(pi)
     90
     91        TESTS::
     92
     93        Check if #8568 is fixed::
     94
     95            sage: var('c,x')
     96            (c, x)
     97            sage: derivative(erf(c*x),x)
     98            2*c*e^(-c^2*x^2)/sqrt(pi)
     99            sage: erf(c*x).diff(x)._maxima_init_()
     100            '((%pi)^(-1/2))*(c)*(exp(((c)^(2))*((x)^(2))*(-1)))*(2)'
     101        """
     102        return 2*exp(-x**2)/sqrt(pi)
     103
     104
    82105erf = Function_erf()
    83106
    84107class Function_abs(GinacFunction):
  • sage/symbolic/expression_conversions.py

    diff -r 27c18494b6cb -r 9bb80f99660c sage/symbolic/expression_conversions.py
    a b  
    463463        """
    464464        EXAMPLES::
    465465
    466             sage: import operator
    467466            sage: from sage.symbolic.expression_conversions import InterfaceInit
    468467            sage: m = InterfaceInit(maxima)
    469             sage: a = function('f', x).diff(x); a
     468            sage: f = function('f')
     469            sage: a = f(x).diff(x); a
    470470            D[0](f)(x)
    471471            sage: print m.derivative(a, a.operator())
    472472            diff('f(x), x, 1)
    473             sage: b = function('f', x).diff(x).diff(x)
     473            sage: b = f(x).diff(x, x)
    474474            sage: print m.derivative(b, b.operator())
    475475            diff('f(x), x, 2)
     476
     477        We can only convert to Maxima derivatives if the corresponding operand
     478        of the function is a variable::
     479
     480            sage: y = var('y')
     481            sage: t = f(x*y).diff(x)
     482            sage: m.derivative(t, t.operator())
     483            Traceback (most recent call last):
     484            ...
     485            NotImplementedError: arguments must be distinct variables
    476486        """       
    477487        #This code should probably be moved into the interface
    478488        #object in a nice way.
    479489        from sage.symbolic.ring import is_SymbolicVariable
    480490        if self.name_init != "_maxima_init_":
    481491            raise NotImplementedError
    482         args = ex.args()
     492        args = ex.operands()
    483493        if (not all(is_SymbolicVariable(v) for v in args) or
    484494            len(args) != len(set(args))):
    485495            raise NotImplementedError, "arguments must be distinct variables"