Opened 5 years ago

Last modified 3 years ago

#17504 new defect

solve() breaks substitute_function()

Reported by: wonder Owned by:
Priority: major Milestone: sage-6.4
Component: symbolics Keywords:
Cc: jakobkroeker Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description

Seems like this should work differently:

$ sage
┌────────────────────────────────────────────────────────────────────┐
│ Sage Version 6.4.1, Release Date: 2014-11-23                       │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘
sage: z = sage.symbolic.function_factory.function('z',nargs=1)
sage: z_eq = ( z(x) == x/(1-x) )
sage: z_eq.substitute_function( z, (x^2).function(x) )
x^2 == -x/(x - 1)
sage: x_expr = solve( z_eq, x )[0].rhs()
sage: x_expr
z(x)/(z(x) + 1)
sage: x_expr.substitute_function( z, (x^2).function(x) )
z(x)/(z(x) + 1)

I believe it should replace z(x) with x^2 in the last result.

Change History (6)

comment:1 Changed 5 years ago by rws

  • Component changed from PLEASE CHANGE to symbolics
  • Type changed from PLEASE CHANGE to defect

comment:2 Changed 5 years ago by nbruin

I think the problem here is that we can't really support/recognize the "nargs" argument, but we do have:

sage: sage.symbolic.function_factory.function('z') == sage.symbolic.function_factory.function('z',nargs=1)
False

When we see the symbol appear on the maxima side, we have no idea whether it's a variadic function or one with a fixed number of arguments. Apparently, the interface presently chooses to go with variadic, since that is most generic. Indeed, if you change the first line to

sage: z= sage.symbolic.function_factory.function('z')

there is no problem.

Further problems arise with bare functions, because that concept doesn't exist in the maxima interface and/or maxima itself:

sage: f= sage.symbolic.function_factory.function('f',nargs=2)
sage: maxima_calculus(f)._sage_()(x)
x
sage: maxima_calculus(f)._sage_()(f=x)
x
sage: maxima_calculus(f)._sage_()(x,x)
ValueError: the number of arguments must be less than or equal to 1

comment:3 follow-up: Changed 5 years ago by wonder

Wouldn't it be best to record what symbols sage is sending to maxima, and translate symbols in maxima's output back to the same things they corresponded to in the input?

comment:4 in reply to: ↑ 3 Changed 5 years ago by nbruin

Replying to wonder:

Wouldn't it be best to record what symbols sage is sending to maxima, and translate symbols in maxima's output back to the same things they corresponded to in the input?

We do that to some extent, but lack of scoping makes this unpredictable:

sage: f=function('f')
sage: F1=maxima_calculus(f(x))
sage: f=function('f',nargs=2)
sage: F2=maxima_calculus(f(x,x))

Since we're already mangling names for variables, one possibility would be to mangle any attributes into the names of functions, in which we'd get something along the lines:

sage: f=function('f',nargs=2)
sage: maxima_calculus(f(x,x)) #we could do it like this:
'_SAGE_FUNCTION_NARGS_2_f(_SAGE_VAR_x,_SAGE_VAR_x)

comment:5 Changed 5 years ago by wonder

I see, yeah.

one possibility would be to mangle any attributes into the names of functions

Maybe streamlined by only using mangled names for non-variadic functions. Or only when a function comes up whose simple name is already in use...

comment:6 Changed 3 years ago by jakobkroeker

  • Cc jakobkroeker added
Note: See TracTickets for help on using tickets.