solve

Bugs

Modérateur : xcasadmin

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

solve

Message par lukamar » lun. août 21, 2017 12:46 am

Hello,

the function 'solve' fails to find the solution (x=4/3,y=sqrt(2/3),u1=sqrt(2/3),u2=0,u3=0) to the following system of equations:
y-u1+u2=0, x-2*y*u1+u3=0, u1*(2-x-y^2)=0, u2*x=0, u3*y=0.

When I enter

Code : Tout sélectionner

solve([y-u1+u2=0,x-2*u1*y+u3=0,u1*(2-x-y^2)=0,u2*x=0,u3*y=0],[x,y,u1,u2,u3])
I get only the solution [0,-u2,0,u2,0]. Assuming

Code : Tout sélectionner

assume(u1>0)
the function 'solve' fails to find any solution. As the above system is quite easy to solve, I think it may be a bug.

parisse
Messages : 5739
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: solve

Message par parisse » lun. août 21, 2017 7:50 am

I checked, it's a limitation of the solve algorithm if the number of solutions is infinite, you get only generic solutions. Here after computing the Groebner basis in lex order, the first equation solved is -u2*u3=0 with respect to u3, and the solver returns 0 (u2 is considered generic, the special case u2=0 is unfortunately ignored).

parisse
Messages : 5739
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: solve

Message par parisse » mar. août 22, 2017 1:59 pm

I have improved the solve postprocessing algorithm, it will now return [[0,0,0,0,0],[2*(1/3*sqrt(6))^2,1/3*sqrt(6),1/3*sqrt(6),0,0],[2*(-1/3*sqrt(6))^2,-1/3*sqrt(6),-1/3*sqrt(6),0,0],[0,-u2,0,u2,0],[-u3,0,0,0,u3]]

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: solve

Message par lukamar » mar. août 22, 2017 3:15 pm

That's it. I was solving some problems using Karush-Kuhn-Tucker conditions and I noticed that 'solve' failed to find solution in some quite simple cases. The above system is one example. I believe this fix covers for that.

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: solve

Message par lukamar » jeu. sept. 07, 2017 6:56 am

There is a bug in function 'solve'. When I enter

Code : Tout sélectionner

assume(x>-pi/2 and x<pi/2); solve(1/(1+tan(x)^2)=0,x)
'solve' returns [-pi/2,pi/2]. But not only these points are excluded from domain of x, but the expression 1/(1+tan(x)^2) can't vanish because it's undefined for x=k*pi/2, where k is integer.

parisse
Messages : 5739
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: solve

Message par parisse » jeu. sept. 07, 2017 8:36 am

There is indeed a missing check for excluded values that I'm fixing now.
If the assume inequations are large, solve will still return -pi/2 and pi/2 because trigonometric equations are sometimes rewritten in terms of half tangent and it's too difficult to track. It's not wrong if you consider limits :-)

Répondre