Ticket #8568: trac_8568-diff_conversion.patch

File trac_8568-diff_conversion.patch, 2.4 KB (added by burcin, 13 years ago)
  • sage/symbolic/expression_conversions.py

    # HG changeset patch
    # User Burcin Erocal <burcin@erocal.org>
    # Date 1274956635 -7200
    # Node ID d3bb1a7a0ac49eccad3ea4053f938a3518c403ed
    # Parent  f32a14699e32bb046acd4c1789e0d83d4b0c8a17
    trac 8568: fix conversion of derivatives to maxima.
    
    Corresponding method sage.symbolic.expression_conversions.InterfaceInit.diff()
    was calling "args()" on an expression to fetch the operands. Changing this to
    operands() fixes the problem.
    
    diff --git a/sage/symbolic/expression_conversions.py b/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
     486
     487        TESTS::
     488
     489        Check if #8568 is fixed::
     490
     491            sage: var('c,x')
     492            (c, x)
     493            sage: erf(c*x).diff(x)._maxima_init_()
     494            Traceback (most recent call last):
     495            ...
     496            NotImplementedError: arguments must be distinct variables
    476497        """       
    477498        #This code should probably be moved into the interface
    478499        #object in a nice way.
    479500        from sage.symbolic.ring import is_SymbolicVariable
    480501        if self.name_init != "_maxima_init_":
    481502            raise NotImplementedError
    482         args = ex.args()
     503        args = ex.operands()
    483504        if (not all(is_SymbolicVariable(v) for v in args) or
    484505            len(args) != len(set(args))):
    485506            raise NotImplementedError, "arguments must be distinct variables"