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>.&nbsp; But the <a href=3D"http://herbie.uwplse.org" title=3D"her=
bie.uwplse.org">
online</a>&nbsp;interface to Herbie timed out when I tried loading it a mom=
ent ago.&nbsp;</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 =
&lt;[email protected]&gt;<br>
<b>Sent:</b> Sunday, June 21, 2026 6:02 AM<br>
<b>To:</b> Stavros Macrakis &lt;[email protected]&gt;<br>
<b>Cc:</b> maxima-discuss &lt;[email protected]&gt;<br>
<b>Subject:</b> Re: [Maxima-discuss] turning differences into sums</font>
<div>&nbsp;</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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -s=
qrt(Z^2+W^2)*w*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2)*z<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -W=
*sqrt(Z^2+W^2)*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2)*z<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -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>
&gt; Try<br>
&gt;<br>
&gt; factor(1/ratsimp(1/ex)),algebraic;<br>
&gt;<br>
&gt; ratsimp/algebraic generally eliminates roots in the denominator<br>
&gt;<br>
&gt; or more &quot;manually&quot;<br>
&gt;<br>
&gt; apply(&quot;/&quot;,factor(expand(args(ex)*(sqrt(a)+sqrt(b)))))<br>
&gt;<br>
&gt;<br>
&gt; On Sun, Jun 21, 2026, 04:46 Claude Heiland-Allen &lt;[email protected]=
k&gt;<br>
&gt; wrote:<br>
&gt;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; Hi all,<br>
&gt;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; I have something like<br>
&gt;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; (sqrt(a) - sqrt(b)) / c<br>
&gt;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; and I would like to multiply to and bottom by<=
br>
&gt;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; (sqrt(a) + sqrt(b))<br>
&gt;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; and simplify each to get<br>
&gt;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; (a - b) / (c * (sqrt(a) + sqrt(b)))<br>
&gt;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; of course my actual expressions are much more =
complicated (and I<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; hope my (a-b) will simplify further) and I can=
not see how to do it<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; programmatically without lots of manual copy a=
nd paste with<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; potential for errors.<br>
&gt;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; actual code:<br>
&gt;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; s(x,y,z,w) :=3D (x^2 + y^2 - z^2 - w^2) * (x^2=
 - y^2) / (x^2 + y^2);<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; t(x,y,z,w) :=3D (x^2 + y^2 - z^2 - w^2) * (2 *=
 x * y) / (x^2 + y^2);<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; u(x,y,z,w) :=3D 2 * sqrt((x^2 + y^2) * (z^2 + =
w^2)) * (z^2 - w^2) /<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; (z^2 + w^2);<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; v(x,y,z,w) :=3D 2 * sqrt((x^2 + y^2) * (z^2 + =
w^2)) * (2 * z * w) /<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; (z^2 + w^2);<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; p(f) :=3D factor(expand(f(X+x,Y+y,Z+z,W+w) - f=
(X,Y,Z,W)));<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; p(s);<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; p(t);<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; p(u);<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; p(v);<br>
&gt;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; the last two expressions are the ones I want t=
o manipulate as<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; described, here is the last one:<br>
&gt;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; -((4*(W*sqrt(Y^2+X^2)*Z*sqrt(z^2+2*Z*z+w^2+2*W=
*w+Z^2+W^2)<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; -sqrt(Z^2+W^2)*w*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+=
X^2)*z<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; -W*sqrt(Z^2+W^2)*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+=
X^2)*z<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; -Z*sqrt(Z^2+W^2)*w*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^=
2+X^2)<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; -W*Z*sqrt(Z^2+W^2)*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^=
2+X^2)))<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /(sqrt(Z^2+W^2)*sqrt(z^2+2*Z*z+w^2+2*W*w=
+Z^2+W^2)))<br>
&gt;<br>
&gt;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; context: I'm trying to apply perturbation tech=
niques to iterations<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; of the 4D Hopfbrot fractal, a cousin of the fa=
mous 3D Mandelbulb.<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; Perturbation techniques popularized in the las=
t years allow<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; computationally efficient deep zooming of 2D f=
ractals like the<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; Mandelbrot set, and recently have been applied=
 to the Mandelbulb.<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; The main idea is to use &quot;small&quot; diff=
erences from one &quot;large&quot;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; reference orbit, and the key step is symbolica=
lly simplifying so<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; there is no catastrophic cancellation when eva=
luating numerically<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; (i.e. naively (X+x)-X will give 0 instead of x=
 when x &lt;&lt; X).<br>
&gt;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; Thanks,<br>
&gt;<br>
&gt;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; Claude<br>
&gt;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; <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>
&gt;<br>
&gt;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; ______________________________________________=
_<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; Maxima-discuss mailing list<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; [email protected]<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; <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>
&gt;<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==--