grzegorzmazur / yacas

Computer calculations made easy
http://www.yacas.org
GNU Lesser General Public License v2.1
124 stars 24 forks source link

Solve: strange behaviour #281

Open mikldk opened 4 years ago

mikldk commented 4 years ago

I am trying to solve a system of equations, and I get different solutions depending on whether 1 is on the RHS or -1 on the LHS.

Here it is demonstrated:

In> Solve({lambda-y1/p1==0, lambda-y2/p2==0, lambda-y3/p3==0, p1+p2+p3==1}, {p1, p2, p3, lambda})
Out> {{p1==y1/lambda,p2==y2/lambda,p3==y3/lambda,lambda==y1+y2+y3}}
In> Solve({lambda-y1/p1==0, lambda-y2/p2==0, lambda-y3/p3==0, p1+p2+p3-1==0}, {p1, p2, p3, lambda})
Out> {{p1==y1/lambda,p2==y2/lambda,p3==y3/lambda,lambda==lambda}}
In> 

The first with 1 on RHS gives the solution I expect, whereas the second with -1 on the LHS gives an incomplete solution.

Maybe there is a bug somewhere?

grzegorzmazur commented 4 years ago

Slightly reduced test-case:

In> Solve({lambda-y1/p1==0, lambda-y2/p2==0, p1+p2==1}, {p1, p2, lambda})
Out> {{p1==y1/lambda,p2==y2/lambda,lambda==y1+y2}}
In> Solve({lambda-y1/p1==0, lambda-y2/p2==0, p1+p2-1==0}, {p1, p2, lambda})
Out> {{p1==y1/lambda,p2==y2/lambda,lambda==lambda}}

One-dimensional case works correctly

aavogt commented 4 years ago

This might be the same problem with Solve With yacas-1.3.6-2 (probably the default ubuntu bionic package) and also with yacas-console 1.8.0-1~bionic I have:

In> Solve(C + x + x, x)
Out> {x== -C/2}            // good
In> Solve({C + x + x}, {x})
Out> {{x==x}}
In> Solve({C + 2* x}, {x})
Out> {{x==C/2}}

I've only tried with 1.8 below. Removing the {} leads to correct output.

In> Solve({C / x}, {x})
Out> {{x==C}}
In> Solve({C * x}, {x})
Out> {{x==C}}
grzegorzmazur commented 4 years ago

Hi,

When in {}, it's solved as a system of equations, which apparently has issues (I'm working to solve them), without it's solved by a different procedure. Actually, your case has a simple solution, which I'll implement in next few days - if the system has just one equation, pass it to the single equation solver, bypassing the system solver altogether. It's a workaround, but I think a reasonable one. So thanks a lot for reporting!

Cheers, Grzesiek