Re: turning differences into sums
Barton Willis via Maxima-discuss <[email protected]> Sun, 21 Jun 2026 11:39:24 +0000
| Newsgroups | gmane.comp.mathematics.maxima.general |
|---|---|
| Message-ID | <SN6PR07MB7952698A56D9003858EAFAF2B6E02@SN6PR07MB7952.namprd07.prod.outlook.com> |
--===============5101156010919927589== Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_SN6PR07MB7952698A56D9003858EAFAF2B6E02SN6PR07MB7952namp_" --_000_SN6PR07MB7952698A56D9003858EAFAF2B6E02SN6PR07MB7952namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable If your primary goal is accurate floating-point evaluation, you might try H= erbie<https://github.com/herbie-fp/herbie>. But the online<http://herbie.u= wplse.org> interface to Herbie timed out when I tried loading it a moment a= go. Let us know what you all discover. --Barton ________________________________ From: Claude Heiland-Allen <[email protected]> Sent: Sunday, June 21, 2026 6:02 AM To: Stavros Macrakis <[email protected]> Cc: maxima-discuss <[email protected]> Subject: Re: [Maxima-discuss] turning differences into sums Caution: Non-NU Email Thanks for your reply Stavros, however the first example doesn't make any difference in this case and the second one has the copy/paste issue that I'm trying to avoid (though, it uses a nicer syntax than my previous attempts, which is good to learn). Concretely, I want to programmatically transform all the subtractions in the numerator to additions, that is, go from -((4*(W*sqrt(Y^2+X^2)*Z*sqrt(z^2+2*Z*z+w^2+2*W*w+Z^2+W^2) -sqrt(Z^2+W^2)*w*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2)*z -W*sqrt(Z^2+W^2)*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2)*z -Z*sqrt(Z^2+W^2)*w*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2) -W*Z*sqrt(Z^2+W^2)*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2))) to -((4*(W*sqrt(Y^2+X^2)*Z*sqrt(z^2+2*Z*z+w^2+2*W*w+Z^2+W^2) +sqrt(Z^2+W^2)*w*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2)*z +W*sqrt(Z^2+W^2)*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2)*z +Z*sqrt(Z^2+W^2)*w*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2) +W*Z*sqrt(Z^2+W^2)*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2))) so that I can the multiply the parts of the fraction by it. Thanks, Claude On 21/06/2026 12:49, Stavros Macrakis wrote: > Try > > factor(1/ratsimp(1/ex)),algebraic; > > ratsimp/algebraic generally eliminates roots in the denominator > > or more "manually" > > apply("/",factor(expand(args(ex)*(sqrt(a)+sqrt(b))))) > > > On Sun, Jun 21, 2026, 04:46 Claude Heiland-Allen <[email protected]> > wrote: > > Hi all, > > I have something like > > (sqrt(a) - sqrt(b)) / c > > and I would like to multiply to and bottom by > > (sqrt(a) + sqrt(b)) > > and simplify each to get > > (a - b) / (c * (sqrt(a) + sqrt(b))) > > of course my actual expressions are much more complicated (and I > hope my (a-b) will simplify further) and I cannot see how to do it > programmatically without lots of manual copy and paste with > potential for errors. > > actual code: > > s(x,y,z,w) :=3D (x^2 + y^2 - z^2 - w^2) * (x^2 - y^2) / (x^2 + y^2); > t(x,y,z,w) :=3D (x^2 + y^2 - z^2 - w^2) * (2 * x * y) / (x^2 + y^2); > u(x,y,z,w) :=3D 2 * sqrt((x^2 + y^2) * (z^2 + w^2)) * (z^2 - w^2) / > (z^2 + w^2); > v(x,y,z,w) :=3D 2 * sqrt((x^2 + y^2) * (z^2 + w^2)) * (2 * z * w) / > (z^2 + w^2); > p(f) :=3D factor(expand(f(X+x,Y+y,Z+z,W+w) - f(X,Y,Z,W))); > p(s); > p(t); > p(u); > p(v); > > the last two expressions are the ones I want to manipulate as > described, here is the last one: > > -((4*(W*sqrt(Y^2+X^2)*Z*sqrt(z^2+2*Z*z+w^2+2*W*w+Z^2+W^2) > -sqrt(Z^2+W^2)*w*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2)*z > -W*sqrt(Z^2+W^2)*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2)*z > -Z*sqrt(Z^2+W^2)*w*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2) > -W*Z*sqrt(Z^2+W^2)*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2))) > /(sqrt(Z^2+W^2)*sqrt(z^2+2*Z*z+w^2+2*W*w+Z^2+W^2))) > > > context: I'm trying to apply perturbation techniques to iterations > of the 4D Hopfbrot fractal, a cousin of the famous 3D Mandelbulb. > Perturbation techniques popularized in the last years allow > computationally efficient deep zooming of 2D fractals like the > Mandelbrot set, and recently have been applied to the Mandelbulb. > The main idea is to use "small" differences from one "large" > reference orbit, and the key step is symbolically simplifying so > there is no catastrophic cancellation when evaluating numerically > (i.e. naively (X+x)-X will give 0 instead of x when x << X). > > Thanks, > > > Claude > > https://urldefense.com/v3/__https://mathr.co.uk__;!!PvXuogZ4sRB2p-tU!= HNBMY8w_rKA70J6zDmTJj3M67tGC5xyBsRZ4uBzQTT764MBPm7zFlVo4-1aaHkqqukTjwTljmsT= idt0$ > > > _______________________________________________ > Maxima-discuss mailing list > [email protected] > https://urldefense.com/v3/__https://lists.sourceforge.net/lists/listi= nfo/maxima-discuss__;!!PvXuogZ4sRB2p-tU!HNBMY8w_rKA70J6zDmTJj3M67tGC5xyBsRZ= 4uBzQTT764MBPm7zFlVo4-1aaHkqqukTjwTljtm35Guw$ > _______________________________________________ Maxima-discuss mailing list [email protected] https://urldefense.com/v3/__https://lists.sourceforge.net/lists/listinfo/ma= xima-discuss__;!!PvXuogZ4sRB2p-tU!HNBMY8w_rKA70J6zDmTJj3M67tGC5xyBsRZ4uBzQT= T764MBPm7zFlVo4-1aaHkqqukTjwTljtm35Guw$ --_000_SN6PR07MB7952698A56D9003858EAFAF2B6E02SN6PR07MB7952namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable <html> <head> <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"= > <style type=3D"text/css" style=3D"display:none;"> P {margin-top:0;margin-bo= ttom:0;} </style> </head> <body dir=3D"ltr"> <div class=3D"elementToProof" style=3D"font-family: Georgia, serif; font-si= ze: 12pt; color: rgb(0, 0, 0);"> If your primary goal is accurate floating-point evaluation, you might try <= a href=3D"https://github.com/herbie-fp/herbie" id=3D"OWA08c4dd08-244c-fd58-= 87d5-f32d219facd8" class=3D"OWAAutoLink" title=3D"https://github.com/herbie= -fp/herbie"> Herbie</a>. But the <a href=3D"http://herbie.uwplse.org" title=3D"her= bie.uwplse.org"> online</a> interface to Herbie timed out when I tried loading it a mom= ent ago. </div> <div class=3D"elementToProof" style=3D"font-family: Georgia, serif; font-si= ze: 12pt; color: rgb(0, 0, 0);"> <br> </div> <div class=3D"elementToProof" style=3D"font-family: Georgia, serif; font-si= ze: 12pt; color: rgb(0, 0, 0);"> Let us know what you all discover.</div> <div class=3D"elementToProof" style=3D"font-family: Georgia, serif; font-si= ze: 12pt; color: rgb(0, 0, 0);"> <br> </div> <div class=3D"elementToProof" style=3D"font-family: Georgia, serif; font-si= ze: 12pt; color: rgb(0, 0, 0);"> --Barton</div> <div class=3D"elementToProof" style=3D"font-family: Georgia, serif; font-si= ze: 12pt; color: rgb(0, 0, 0);"> <br> </div> <div class=3D"elementToProof" style=3D"font-family: Georgia, serif; font-si= ze: 12pt; color: rgb(0, 0, 0);"> <br> </div> <div class=3D"elementToProof" style=3D"font-family: Georgia, serif; font-si= ze: 12pt; color: rgb(0, 0, 0);"> <br> </div> <div class=3D"elementToProof" style=3D"font-family: Georgia, serif; font-si= ze: 12pt; color: rgb(0, 0, 0);"> <br> </div> <div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo= nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c= olor: rgb(0, 0, 0);"> <br> </div> <div class=3D"elementToProof" style=3D"font-family: Aptos, Aptos_EmbeddedFo= nt, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; c= olor: rgb(0, 0, 0);"> <br> </div> <div id=3D"appendonsend"></div> <hr style=3D"display:inline-block;width:98%" tabindex=3D"-1"> <div id=3D"divRplyFwdMsg" dir=3D"ltr"><font face=3D"Calibri, sans-serif" st= yle=3D"font-size:11pt" color=3D"#000000"><b>From:</b> Claude Heiland-Allen = <[email protected]><br> <b>Sent:</b> Sunday, June 21, 2026 6:02 AM<br> <b>To:</b> Stavros Macrakis <[email protected]><br> <b>Cc:</b> maxima-discuss <[email protected]><br> <b>Subject:</b> Re: [Maxima-discuss] turning differences into sums</font> <div> </div> </div> <div class=3D"BodyFragment"><font size=3D"2"><span style=3D"font-size:11pt;= "> <div class=3D"PlainText">Caution: Non-NU Email<br> <br> <br> Thanks for your reply Stavros, however the first example doesn't make<br> any difference in this case and the second one has the copy/paste issue<br> that I'm trying to avoid (though, it uses a nicer syntax than my<br> previous attempts, which is good to learn).<br> <br> Concretely, I want to programmatically transform all the subtractions in<br= > the numerator to additions, that is, go from<br> <br> -((4*(W*sqrt(Y^2+X^2)*Z*sqrt(z^2+2*Z*z+w^2+2*W*w+Z^2+W^2)<br> -s= qrt(Z^2+W^2)*w*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2)*z<br> -W= *sqrt(Z^2+W^2)*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2)*z<br> -Z= *sqrt(Z^2+W^2)*w*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2)<br> <br> -W*Z*sqrt(Z^2+W^2)*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2)))<br> <br> <br> to<br> <br> <br> -((4*(W*sqrt(Y^2+X^2)*Z*sqrt(z^2+2*Z*z+w^2+2*W*w+Z^2+W^2)<br> +sqrt(Z^2+W^2)*w*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2)*z<br> <br> +W*sqrt(Z^2+W^2)*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2)*z<br> +Z*sqrt(Z^2+W^2)*w*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2)<br> +W*Z*sqrt(Z^2+W^2)*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2)))<br> <br> <br> so that I can the multiply the parts of the fraction by it.<br> <br> <br> Thanks,<br> <br> <br> Claude<br> <br> On 21/06/2026 12:49, Stavros Macrakis wrote:<br> > Try<br> ><br> > factor(1/ratsimp(1/ex)),algebraic;<br> ><br> > ratsimp/algebraic generally eliminates roots in the denominator<br> ><br> > or more "manually"<br> ><br> > apply("/",factor(expand(args(ex)*(sqrt(a)+sqrt(b)))))<br> ><br> ><br> > On Sun, Jun 21, 2026, 04:46 Claude Heiland-Allen <[email protected]= k><br> > wrote:<br> ><br> > Hi all,<br> ><br> > I have something like<br> ><br> > (sqrt(a) - sqrt(b)) / c<br> ><br> > and I would like to multiply to and bottom by<= br> ><br> > (sqrt(a) + sqrt(b))<br> ><br> > and simplify each to get<br> ><br> > (a - b) / (c * (sqrt(a) + sqrt(b)))<br> ><br> > of course my actual expressions are much more = complicated (and I<br> > hope my (a-b) will simplify further) and I can= not see how to do it<br> > programmatically without lots of manual copy a= nd paste with<br> > potential for errors.<br> ><br> > actual code:<br> ><br> > s(x,y,z,w) :=3D (x^2 + y^2 - z^2 - w^2) * (x^2= - y^2) / (x^2 + y^2);<br> > t(x,y,z,w) :=3D (x^2 + y^2 - z^2 - w^2) * (2 *= x * y) / (x^2 + y^2);<br> > u(x,y,z,w) :=3D 2 * sqrt((x^2 + y^2) * (z^2 + = w^2)) * (z^2 - w^2) /<br> > (z^2 + w^2);<br> > v(x,y,z,w) :=3D 2 * sqrt((x^2 + y^2) * (z^2 + = w^2)) * (2 * z * w) /<br> > (z^2 + w^2);<br> > p(f) :=3D factor(expand(f(X+x,Y+y,Z+z,W+w) - f= (X,Y,Z,W)));<br> > p(s);<br> > p(t);<br> > p(u);<br> > p(v);<br> ><br> > the last two expressions are the ones I want t= o manipulate as<br> > described, here is the last one:<br> ><br> > -((4*(W*sqrt(Y^2+X^2)*Z*sqrt(z^2+2*Z*z+w^2+2*W= *w+Z^2+W^2)<br> > -sqrt(Z^2+W^2)*w*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+= X^2)*z<br> > -W*sqrt(Z^2+W^2)*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+= X^2)*z<br> > -Z*sqrt(Z^2+W^2)*w*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^= 2+X^2)<br> > -W*Z*sqrt(Z^2+W^2)*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^= 2+X^2)))<br> > /(sqrt(Z^2+W^2)*sqrt(z^2+2*Z*z+w^2+2*W*w= +Z^2+W^2)))<br> ><br> ><br> > context: I'm trying to apply perturbation tech= niques to iterations<br> > of the 4D Hopfbrot fractal, a cousin of the fa= mous 3D Mandelbulb.<br> > Perturbation techniques popularized in the las= t years allow<br> > computationally efficient deep zooming of 2D f= ractals like the<br> > Mandelbrot set, and recently have been applied= to the Mandelbulb.<br> > The main idea is to use "small" diff= erences from one "large"<br> > reference orbit, and the key step is symbolica= lly simplifying so<br> > there is no catastrophic cancellation when eva= luating numerically<br> > (i.e. naively (X+x)-X will give 0 instead of x= when x << X).<br> ><br> > Thanks,<br> ><br> ><br> > Claude<br> ><br> > <a href=3D"https://urldefense.com/v3/__https:/= /mathr.co.uk__;!!PvXuogZ4sRB2p-tU!HNBMY8w_rKA70J6zDmTJj3M67tGC5xyBsRZ4uBzQT= T764MBPm7zFlVo4-1aaHkqqukTjwTljmsTidt0$"> https://urldefense.com/v3/__https://mathr.co.uk__;!!PvXuogZ4sRB2p-tU!HNBMY8= w_rKA70J6zDmTJj3M67tGC5xyBsRZ4uBzQTT764MBPm7zFlVo4-1aaHkqqukTjwTljmsTidt0$<= /a><br> ><br> ><br> > ______________________________________________= _<br> > Maxima-discuss mailing list<br> > [email protected]<br> > <a href=3D"https://urldefense.com/v3/__https:/= /lists.sourceforge.net/lists/listinfo/maxima-discuss__;!!PvXuogZ4sRB2p-tU!H= NBMY8w_rKA70J6zDmTJj3M67tGC5xyBsRZ4uBzQTT764MBPm7zFlVo4-1aaHkqqukTjwTljtm35= Guw$"> https://urldefense.com/v3/__https://lists.sourceforge.net/lists/listinfo/ma= xima-discuss__;!!PvXuogZ4sRB2p-tU!HNBMY8w_rKA70J6zDmTJj3M67tGC5xyBsRZ4uBzQT= T764MBPm7zFlVo4-1aaHkqqukTjwTljtm35Guw$</a><br> ><br> <br> <br> _______________________________________________<br> Maxima-discuss mailing list<br> [email protected]<br> <a href=3D"https://urldefense.com/v3/__https://lists.sourceforge.net/lists/= listinfo/maxima-discuss__;!!PvXuogZ4sRB2p-tU!HNBMY8w_rKA70J6zDmTJj3M67tGC5x= yBsRZ4uBzQTT764MBPm7zFlVo4-1aaHkqqukTjwTljtm35Guw$">https://urldefense.com/= v3/__https://lists.sourceforge.net/lists/listinfo/maxima-discuss__;!!PvXuog= Z4sRB2p-tU!HNBMY8w_rKA70J6zDmTJj3M67tGC5xyBsRZ4uBzQTT764MBPm7zFlVo4-1aaHkqq= ukTjwTljtm35Guw$</a><br> </div> </span></font></div> </body> </html> --_000_SN6PR07MB7952698A56D9003858EAFAF2B6E02SN6PR07MB7952namp_-- --===============5101156010919927589== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --===============5101156010919927589== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Maxima-discuss mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/maxima-discuss --===============5101156010919927589==--