I have a question about Sage/Python, but I’m sure it’s a very general CS question. I have a large system of N non-linear equations in N variables. Before I pass it off to a numerical solver, I try and let Sage simplify the equations using solve. When working through a simple example, I have the following: ‘eqa’ is a list of equations to solve in the variables x0, x1, w0, w1, etc. The following works just fine from the command line:
j(x0,x1,w0,w1,y0,y1,z0,z1) = solve(eqa, var('x0 x1 w0 w1 y0 y1 z0 z1'))
(I’m trying to define the list of equations as a ‘callable symbolic expression’ (Sage) because the numerical optimization I use works better with these rather than normal def python functions.)
In any case, when I include this in a script and try to load it, I get the error:
j(x0,x1,w0,w1,y0,y1,z0,z1) = solve(eqa, var('x0 x1 w0 w1 y0 y1 z0 z1'))
SyntaxError: can't assign to function call
I know I must be doing something wrong at the command line and its just working by some dumb luck. Or is special care needed when defining these callable symbolic expressions in a script? Thanks for any insight you can provide. Here is a link on the difference between these types of ‘functions’
This way of defining functions is Sage-specific, and forbidden by standard Python syntax. My guess is that either (1) you’re trying to run your script using Python, or (2) you’re using Sage, but your filename ends with
.pyand so Sage is interpreting it as a Python file.For example: