Deprecation warning for a Sage interact

28 views
Skip to first unread message

Thomas Judson

unread,
Dec 21, 2019, 10:31:33 AM12/21/19
to sage-s...@googlegroups.com
I get the following deprecation warning for a Sage interact:

/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/sage_eval.py:203: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
See http://trac.sagemath.org/5930 for details.
  return eval(source, sage.all.__dict__, locals)


The interact code is

t = var('t')
x = function('x')(t)
y = function('y')(t)
@interact
def _(f = input_box(default = 3*x - 2*y),
     g = input_box(default = x + y),
     t_start = input_box(default = 0), x_start = input_box(default = 1), y_start = input_box(default = 1)):
   de1 = diff(x,t) == f
   de2 = diff(y,t) == g
   sol = desolve_system([de1, de2], [x,y], ics=[t_start, x_start, y_start])
   sol[0].show()
   sol[1].show()
   html(r"$\displaystyle\frac{dx}{dt} = %s$"  %latex(f))
   html(r"$\displaystyle\frac{dy}{dt} = %s$"  %latex(g))

I’m sure the fix is easy and straightforward, but I don’t see it.  Can anyone help?

Tom Judson

Nils Bruin

unread,
Dec 21, 2019, 1:57:49 PM12/21/19
to sage-support
The problem is fairly subtle, but it boils down to the fact that input_box wants a *string* as default value , because a string is also what it gets from the user. Note that your names x and y are bound to x(t) and y(t) respectively. Input box turns its default parameter to a string, so the expression 3*x-2*y turns into the string "3*x(t)-2*y(t)".

Later when this is evaluated, it is evaluated in the context of the global bindings that are currently in force in your sage session, so with x,y being bound to x(t) and y(t) this turns into evaluating

3*x(t)(t)-2*y(t)(t)

for which the deprecation warning is entirely correct.

The solution is to quote your arguments to input_box as strings, i.e.,

... input_box(default = "3*x - 2*y") ...

Tom Judson

unread,
Dec 22, 2019, 11:15:17 AM12/22/19
to sage-support
Thanks.  You saved me a lot of time.
Reply all
Reply to author
Forward
0 new messages