question about solve, solveset, and nonlinsolve

179 views
Skip to first unread message

Thomas Ligon

unread,
Jan 6, 2021, 12:20:27 PM1/6/21
to sympy
I am trying to solve some algebraic (polynomial) equations. In the first approximation, I have 4 equations in 4 variables, and it is very easy to solve them manually. In the second approximation, I have 8 equations in 8 variables, and I am trying to solve them. At the beginning, the equations are linear or quadratic in the variables. After solving one equation for one variable and substituting the result into the other equations, the complexity grows very fast.
One very naive attempt I made was to give all 8 equations and 8 variables to solve. That has been running for over 3 weeks and I don't know if it will succeed.
Then I started using solveset and solving the equations one by one. After one call to nonlinsolve and one substitution, I tried giving this expression (Latex form)
2 \(-1\) b_{-1} \left( - \frac{\(1\) b_{-1}^{2} + 2 \(1\) b_{-2} + \[1,-1\] b_{-1} b_{-2} + \[1\]}{\[1,2\] b_{2} + 2 \[1\] b_{-1} - 1}\right) + \(-1\) + \[-1,-2\] b_{-1} b_{-2} + \[-1,1\] b_{2} \left( - \frac{\(1\) b_{-1}^{2} + 2 \(1\) b_{-2} + \[1,-1\] b_{-1} b_{-2} + \[1\]}{\[1,2\] b_{2} + 2 \[1\] b_{-1} - 1}\right) + \[-1\] b_{-1}^{2} + 2 \[-1\] b_{-2} - b_{-1}
to solveset as
solbm1 = solveset([exbm1], [bm1])
and I got the error
[2b_{-1}b_{-1}2 + 2*(1)*b_{-2} + [1,-1]*b_{-1}*b_{-2} + [1])/([1,2]*b_2 + 2*[1]*b_{-1} - 1),) + (-1) + [-1,-2]*b_{-1}*b_{-2} + [-1,1]*b_2*(-((1)*b_{-1}2 + 2b_{-2} + [1,-1]b_{-2} + [1])/([1,2][1]b_{-1}**2 + 2b_{-2} - b_{-1}] is not a valid SymPy expression
When I use nonlinsolve instead, I get the error
'Tuple' object has no attribute '_eval_is_polynomial'
When I use solve instead, I get the error
Can't multiply sequence by non-integer of type '<class 'sympy.core.mul.Mul'>'
The complex expression came from solving one equation and using subs to put the result into a second equation. If it helps, I could try calling expand before trying to solve the resulting equation.
Basically, I am looking for advice about the best strategy for solving multiple polynomial equations. Is it better to try to solve them all at once, or one equation at a time (but with multiply substitutions and multiple calls to solve/solveset/nonlinsol), or all equations but one variable at a time?

Aaron Meurer

unread,
Jan 6, 2021, 3:27:05 PM1/6/21
to sympy
Ideally SymPy would be smart enough to split up the equations
automatically, so that you can pass them all at once. But someone more
familiar with the solvers code would have to verify if that is
actually what currently happens. The errors you describe mostly look
like bugs (except the solveset one, which I think is just it telling
you that solveset doesn't support systems of equations yet). So it
would be useful to have an example that reproduces them.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/137d76ed-8168-4ecf-9fb9-c5c2a14b66a5n%40googlegroups.com.

Oscar Benjamin

unread,
Jan 6, 2021, 4:29:24 PM1/6/21
to sympy
Ideally the best strategy would be to pass all the equations to solve
all at once but the implementation for polynomial systems still needs
a lot of work so that isn't always the best way.

Beyond that it's hard to say more without being able to try it out
myself. Can you show (shortened) code that gives the equations (e.g.
the repr of the equations)?

Oscar
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6Kvh3SQc8DFLAwJKmuhSJR%3DA4n6REDSSBmC%2B%2BnQpn1MQw%40mail.gmail.com.

Thomas Ligon

unread,
Jan 11, 2021, 12:11:57 PM1/11/21
to sympy
Hello Aaron and Oscar,

things on my side are taking longer than expected, so I want to give you a quick update. In order to respond to both of your requests, I decided to write a test program and post it as a bug report / GitHub issue. So I set up some symbols and the eight equations hard coded, and then I wanted to write the solveset and nonlinsolve calls where I had problems. In doing so, I included a call to solve, asking it to solve one equation (the second one after substituting the results of the first call to solve), solving for one variable. That has now been running for 3-4 days, so I want to give it a decent chance to finish before continuing work on the test program.

Reply all
Reply to author
Forward
0 new messages