Ticket #8568: trac_8568-diff_conversion.take2.patch

File trac_8568-diff_conversion.take2.patch, 2.1 KB (added by Burcin Erocal, 13 years ago)
  • sage/symbolic/expression_conversions.py

    # HG changeset patch
    # User Burcin Erocal <burcin@erocal.org>
    # Date 1274976727 -7200
    # Node ID 881de40ed182f309229b1a91207e5267297001ee
    # 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
    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"