Wrong output of method arguments() on symbolic functions

60 views
Skip to first unread message

Eric Gourgoulhon

unread,
Mar 8, 2022, 10:23:15 AM3/8/22
to sage-devel
Hi,

We have currently

sage: x, y = var('x y')
sage: fyx = function('f')(y, x)
sage: fyx.arguments()
(x, y)

which is just the reverse of the expected output.

Similarly, we have

sage: atan2(y,x).arguments()
(x, y)

Taking a look at the code, one sees that fyx.arguments() calls fyx.variables(), which returns a "sorted tuple of variables that occur in this expression" (according to the documentation). The "sorted" action explains the result. But the latter remains plain false.

Note that SymPy provides the correct result:

sage: fyx._sympy_().args
(y, x)
sage: atan2(y,x)._sympy_().args
(y, x)

Eric.

Matthias Koeppe

unread,
Mar 8, 2022, 12:06:20 PM3/8/22
to sage-devel
Yes, callable symbolic expressions need a lot of fixes. See meta-ticket https://trac.sagemath.org/ticket/28434

Matthias Koeppe

unread,
Mar 9, 2022, 1:19:06 AM3/9/22
to sage-devel
Note also that function('f')(y, x) does not actually create a function with named arguments. 
It is an ordinary symbolic expression that evaluates the undefined function f of unspecified arity.
Unbound variables in ordinary symbolic expression use alphabetical order. 
https://trac.sagemath.org/ticket/32227 attempts to deprecate calling "arguments" on such expressions.

To create a function with named arguments, you would have to use callable symbolic expressions:

sage: x, y = var('x y')
sage: function('f')(y, x).function(y, x)
(y, x) |--> f(y, x)
sage: _.arguments()

Eric Gourgoulhon

unread,
Mar 10, 2022, 5:24:59 PM3/10/22
to sage-devel
Le mercredi 9 mars 2022 à 07:19:06 UTC+1, Matthias Koeppe a écrit :
Note also that function('f')(y, x) does not actually create a function with named arguments. 
It is an ordinary symbolic expression that evaluates the undefined function f of unspecified arity.
Unbound variables in ordinary symbolic expression use alphabetical order. 
https://trac.sagemath.org/ticket/32227 attempts to deprecate calling "arguments" on such expressions.

This would indeed avoid some confusion; thanks for this ticket!

Eric.
 
Reply all
Reply to author
Forward
0 new messages