Skip to content

solve() breaks substitute_function() #17504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sagetrac-wonder mannequin opened this issue Dec 14, 2014 · 4 comments
Open

solve() breaks substitute_function() #17504

sagetrac-wonder mannequin opened this issue Dec 14, 2014 · 4 comments

Comments

@sagetrac-wonder
Copy link
Mannequin

sagetrac-wonder mannequin commented Dec 14, 2014

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.

CC: @sagetrac-jakobkroeker

Component: symbolics

Issue created by migration from https://trac.sagemath.org/ticket/17504

@sagetrac-wonder sagetrac-wonder mannequin added this to the sage-6.4 milestone Dec 14, 2014
@sagetrac-wonder sagetrac-wonder mannequin added the p: major / 3 label Dec 14, 2014
@nbruin
Copy link
Contributor

nbruin commented Dec 15, 2014

comment:2

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

@sagetrac-wonder
Copy link
Mannequin Author

sagetrac-wonder mannequin commented Dec 17, 2014

comment:3

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?

@nbruin
Copy link
Contributor

nbruin commented Dec 17, 2014

comment:4

Replying to @sagetrac-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)

@sagetrac-wonder
Copy link
Mannequin Author

sagetrac-wonder mannequin commented Dec 17, 2014

comment:5

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...

@mkoeppe mkoeppe removed this from the sage-6.4 milestone Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants