Le mercredi 14 août 2013 10:30:43 UTC+2, Jose Guzman a écrit : > > Very impressive Emmanuel! >
(Possibly) impressive but **FALSE* !* Coming back to the subject, I wanted to see what maxima would do with the same problem. I got the same final answer but not with the same intermediate results ! Let's start with sage: sage: var("x,y,l") (x, y, l) sage: f = x + 2*y sage: g = 2*x^(1/4)*y^(1/2) sage: L = f - l * (16 - g) sage: var("x14,y12") (x14, y12) sage: Lt=L.subs(x=x14^4,y=y12^2) sage: Lt x14^4 + 2*((x14^4)^(1/4)*sqrt(y12^2) - 8)*l + 2*y12^2 sage: Lt.simplify_full() x14^4 + 2*l*x14*y12 + 2*y12^2 - 16*l One notes that simplify_full() replaces ((x14^4)^(1/4)*sqrt(y12^2) with x14*y12. Let's compare with maxima : (%i1) f:x+2*y; (%o1) 2*y+x (%i2) g:2*x^(1/4)*y^(1/2); (%o2) 2*x^(1/4)*sqrt(y) (%i3) L:f-l*(16-g); (%o3) 2*y-l*(16-2*x^(1/4)*sqrt(y))+x (%i4) Lt:ratsimp(factor(radcan(expand(subst([x=x14^4,y=y12^2],L))))); (%o4) 2*l*abs(x14)*abs(y12)+2*y12^2+x14^4-16*l One notes that radcan() replaces the same subexpression with abs(y12)*abs(x14), which is quite different, analysis-wise... Maxima is unable to solve the gradient of this expression : (%i5) solve([diff(Lt,x14)=0,diff(Lt,y12)=0,diff(Lt,l)=0],[x14,y12,l]); (%o5) [] (%i6) load(to_poly_solve); (%o6) "/usr/share/maxima/5.30.0/share/to_poly_solve/to_poly_solve.mac" (%i7) %solve([diff(Lt,x14)=0,diff(Lt,y12)=0,diff(Lt,l)=0],[x14,y12,l]); (%o7) %solve([2*l*abs(x14)*y12/abs(y12)+4*y12 = 0, 2*l*x14*abs(y12)/abs(x14)+4*x14^3 = 0, 2*abs(x14)*abs(y12)-16 = 0],[l,x14,y12]) On the other hand, sage *does* solve it (albeit quite slowly...). We get four symmetric solutions : sage: SI=solve([diff(Lto,x14)==0,diff(Lto,y12)==0,diff(Lto,l)==0], [x14,y12,l],solution_dict=True) sage: SI [{l: -4, y12: -4, x14: -2}, {l: -4, y12: 4, x14: -2}, {l: -4, y12: -4, x14: 2}, {l: -4, y12: 4, x14: 2}] All those solutions check for the transformed problem : sage: SIcheck=map(lambda s:[diff(Lt,x14).subs(s).expand(),\ diff(Lt,y12).subs(s).expand(),\ diff(Lt,l).subs(s).expand()], SI) ....: ....: sage: sage: SIcheck [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]] Getting back to the original variable gives us a quadruple root : sage: S=map(lambda s:{x:(s.get(x14))^4,\ y:(s.get(y12))^2,\ l:s.get(l)},SI) ....: ....: sage: sage: Scheck=map(lambda s:bool(diff(L,x14).subs(s)==0) &\ bool(diff(L,y12).subs(s).expand()==0) &\ bool(diff(L,l).subs(s)==0), S) ....: ....: sage: sage: S [{x: 16, l: -4, y: 16}, {x: 16, l: -4, y: 16}, {x: 16, l: -4, y: 16}, {x: 16, l: -4, y: 16}] sage: Scheck [True, True, True, True] Some lessons : - While derived from maxima's radcan(), simplify_full() does different things ! In this case, getting rid of the abs() calls was the Wrong Thing (TM) do to. - Always, always, always check the answers from solve() (both maxima's and sage's) if this is even remotely possible. - (Todo) check sage's documentation to learn how to obtain valid substitutions of absolute values to radicals-of-powers and power-of-radicals expressions... - Don't post at midnight after a day of hospital work... HTH, Emmanuel Charpentier [ Snip... ] -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/groups/opt_out.