Menu ▾ ▴

#5880 linsolve returns wrong solutions for systems with nested radicals like sqrt(sqrt(z)+1)

None
open
nobody
5
3 days ago
3 days ago
No

By Claude:

With algebraic : true, linsolve returns wrong solutions when the coefficients contain a radical of a variable next to a radical nested on it, like sqrt(z) and sqrt(sqrt(z)+1):

(%i1) display2d : false$
(%i2) algebraic : true$
(%i3) eqs : [(sqrt(z)+sqrt(sqrt(z)+1))*x + sqrt(z)*y = 1, sqrt(z)*x + z*y = 0]$
(%i4) sol : linsolve(eqs, [x, y]);
(%o4) [x = sqrt(sqrt(z)+1)/2,y = -1/((sqrt(z)+sqrt(sqrt(z)+1)-1)*sqrt(z))]
(%i5) float(subst(z = 2, subst(sol, map(lhs, eqs) - map(rhs, eqs))));
(%o5) [0.79765759528007,0.38007510999930394]

The residuals should be zero. The same happens with z^(1/3) and sqrt(z^(1/3)+1):

(%i6) eqs : [sqrt(z^(1/3)+1)*x + z^(1/3)*y = 1, z^(1/3)*x + z^(1/3)*y = 0]$
(%i7) sol : linsolve(eqs, [x, y]);
(%o7) [x = sqrt(z^(1/3)+1)*z^(1/3)+1,y = -sqrt(z^(1/3)+1)*z^(1/3)-1]
(%i8) float(subst(z = 2, subst(sol, map(lhs, eqs) - map(rhs, eqs))));
(%o8) [-0.29564093439746486,0.0]

The underlying problem is a wrong inverse, which shows without linsolve:

(%i9) rat(1)/rat(sqrt(z)+sqrt(sqrt(z)+1)-1);
(%o9) sqrt(sqrt(z)+1)/2

ratsimp(1/(sqrt(z)+sqrt(sqrt(z)+1)-1)) gives the right result, since it orders the radicals differently. With algebraic : false the systems are solved correctly. This is not a corner case: of 11664 small 2x2 systems with coefficients built from sqrt(sqrt(z)+1), sqrt(z) and z, 856 came back wrong. Some related systems exhaust the control stack instead, for example linsolve([x*(z^(1/3)+1)+y*(sqrt(z^(1/3)+1)+1) = 1, y*(sqrt(z^(1/3)+1)+1)*(z^(1/3)+1)+x = 1], [x, y]).

Discussion


Log in to post a comment.