## solve

Bugs

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

### solve

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 : 5084
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

### Re: solve

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 : 5084
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

### Re: solve

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 : 294
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

### Re: solve

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 : 294
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

### Re: solve

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 : 5084
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

### Re: solve

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