Re: turning differences into sums

Stavros Macrakis <[email protected]> Sun, 21 Jun 2026 07:33:10 -0400
Newsgroups gmane.comp.mathematics.maxima.general
Message-ID <CACLVabUUCY8i8Qzsda=Mxp3u8XnboACxbOVMObJQLD4Pi9JELg@mail.gmail.com>
--===============5685061744014082163==
Content-Type: multipart/alternative; boundary="000000000000a3bba00654c1e422"

--000000000000a3bba00654c1e422
Content-Type: text/plain; charset="UTF-8"

I'm on my phone right now, so can't really investigate.

But try radcan(ex) and map('factor,radcan(ex)) to see if those give better
forms to work with.

On Sun, Jun 21, 2026, 07:02 Claude Heiland-Allen <[email protected]> wrote:

> 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) := (x^2 + y^2 - z^2 - w^2) * (x^2 - y^2) / (x^2 + y^2);
> >     t(x,y,z,w) := (x^2 + y^2 - z^2 - w^2) * (2 * x * y) / (x^2 + y^2);
> >     u(x,y,z,w) := 2 * sqrt((x^2 + y^2) * (z^2 + w^2)) * (z^2 - w^2) /
> >     (z^2 + w^2);
> >     v(x,y,z,w) := 2 * sqrt((x^2 + y^2) * (z^2 + w^2)) * (2 * z * w) /
> >     (z^2 + w^2);
> >     p(f) := 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://mathr.co.uk
> >
> >
> >     _______________________________________________
> >     Maxima-discuss mailing list
> >     [email protected]
> >     https://lists.sourceforge.net/lists/listinfo/maxima-discuss
> >
>

--000000000000a3bba00654c1e422
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto">I&#39;m on my phone right now, so can&#39;t really invest=
igate.=C2=A0<div dir=3D"auto"><br></div><div dir=3D"auto">But try radcan(ex=
) and map(&#39;factor,radcan(ex)) to see if those give better forms to work=
 with.</div></div><br><div class=3D"gmail_quote gmail_quote_container"><div=
 dir=3D"ltr" class=3D"gmail_attr">On Sun, Jun 21, 2026, 07:02 Claude Heilan=
d-Allen &lt;<a href=3D"mailto:[email protected]">[email protected]</a>&gt=
; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .=
8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks for your reply Stav=
ros, however the first example doesn&#39;t make <br>
any difference in this case and the second one has the copy/paste issue <br=
>
that I&#39;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 <b=
r>
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>
=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 -sqrt(Z^2+W^2)*w*sqrt(y^2+2=
*Y*y+x^2+2*X*x+Y^2+X^2)*z<br>
=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 -W*sqrt(Z^2+W^2)*sqrt(y^2+2=
*Y*y+x^2+2*X*x+Y^2+X^2)*z<br>
=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 -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;<a href=3D"mailto=
:[email protected]" target=3D"_blank" rel=3D"noreferrer">[email protected]=
k</a>&gt; <br>
&gt; wrote:<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0Hi all,<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0I have something like<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0(sqrt(a) - sqrt(b)) / c<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0and I would like to multiply to and bottom by<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0(sqrt(a) + sqrt(b))<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0and simplify each to get<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0(a - b) / (c * (sqrt(a) + sqrt(b)))<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0of course my actual expressions are much more compl=
icated (and I<br>
&gt;=C2=A0 =C2=A0 =C2=A0hope my (a-b) will simplify further) and I cannot s=
ee how to do it<br>
&gt;=C2=A0 =C2=A0 =C2=A0programmatically without lots of manual copy and pa=
ste with<br>
&gt;=C2=A0 =C2=A0 =C2=A0potential for errors.<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0actual code:<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0s(x,y,z,w) :=3D (x^2 + y^2 - z^2 - w^2) * (x^2 - y^=
2) / (x^2 + y^2);<br>
&gt;=C2=A0 =C2=A0 =C2=A0t(x,y,z,w) :=3D (x^2 + y^2 - z^2 - w^2) * (2 * x * =
y) / (x^2 + y^2);<br>
&gt;=C2=A0 =C2=A0 =C2=A0u(x,y,z,w) :=3D 2 * sqrt((x^2 + y^2) * (z^2 + w^2))=
 * (z^2 - w^2) /<br>
&gt;=C2=A0 =C2=A0 =C2=A0(z^2 + w^2);<br>
&gt;=C2=A0 =C2=A0 =C2=A0v(x,y,z,w) :=3D 2 * sqrt((x^2 + y^2) * (z^2 + w^2))=
 * (2 * z * w) /<br>
&gt;=C2=A0 =C2=A0 =C2=A0(z^2 + w^2);<br>
&gt;=C2=A0 =C2=A0 =C2=A0p(f) :=3D factor(expand(f(X+x,Y+y,Z+z,W+w) - f(X,Y,=
Z,W)));<br>
&gt;=C2=A0 =C2=A0 =C2=A0p(s);<br>
&gt;=C2=A0 =C2=A0 =C2=A0p(t);<br>
&gt;=C2=A0 =C2=A0 =C2=A0p(u);<br>
&gt;=C2=A0 =C2=A0 =C2=A0p(v);<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0the last two expressions are the ones I want to man=
ipulate as<br>
&gt;=C2=A0 =C2=A0 =C2=A0described, here is the last one:<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0-((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;=C2=A0 =C2=A0 =C2=A0-sqrt(Z^2+W^2)*w*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2)*=
z<br>
&gt;=C2=A0 =C2=A0 =C2=A0-W*sqrt(Z^2+W^2)*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2)*=
z<br>
&gt;=C2=A0 =C2=A0 =C2=A0-Z*sqrt(Z^2+W^2)*w*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2=
)<br>
&gt;=C2=A0 =C2=A0 =C2=A0-W*Z*sqrt(Z^2+W^2)*sqrt(y^2+2*Y*y+x^2+2*X*x+Y^2+X^2=
)))<br>
&gt;=C2=A0 =C2=A0 =C2=A0=C2=A0/(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;=C2=A0 =C2=A0 =C2=A0context: I&#39;m trying to apply perturbation techn=
iques to iterations<br>
&gt;=C2=A0 =C2=A0 =C2=A0of the 4D Hopfbrot fractal, a cousin of the famous =
3D Mandelbulb.=C2=A0<br>
&gt;=C2=A0 =C2=A0 =C2=A0Perturbation techniques popularized in the last yea=
rs allow<br>
&gt;=C2=A0 =C2=A0 =C2=A0computationally efficient deep zooming of 2D fracta=
ls like the<br>
&gt;=C2=A0 =C2=A0 =C2=A0Mandelbrot set, and recently have been applied to t=
he Mandelbulb.=C2=A0<br>
&gt;=C2=A0 =C2=A0 =C2=A0The main idea is to use &quot;small&quot; differenc=
es from one &quot;large&quot;<br>
&gt;=C2=A0 =C2=A0 =C2=A0reference orbit, and the key step is symbolically s=
implifying so<br>
&gt;=C2=A0 =C2=A0 =C2=A0there is no catastrophic cancellation when evaluati=
ng numerically<br>
&gt;=C2=A0 =C2=A0 =C2=A0(i.e. naively (X+x)-X will give 0 instead of x when=
 x &lt;&lt; X).<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0Thanks,<br>
&gt;<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0Claude<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0<a href=3D"https://mathr.co.uk" rel=3D"noreferrer n=
oreferrer" target=3D"_blank">https://mathr.co.uk</a><br>
&gt;<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0_______________________________________________<br>
&gt;=C2=A0 =C2=A0 =C2=A0Maxima-discuss mailing list<br>
&gt;=C2=A0 =C2=A0 =C2=A0<a href=3D"mailto:[email protected].=
net" target=3D"_blank" rel=3D"noreferrer">[email protected].=
net</a><br>
&gt;=C2=A0 =C2=A0 =C2=A0<a href=3D"https://lists.sourceforge.net/lists/list=
info/maxima-discuss" rel=3D"noreferrer noreferrer" target=3D"_blank">https:=
//lists.sourceforge.net/lists/listinfo/maxima-discuss</a><br>
&gt;<br>
</blockquote></div>

--000000000000a3bba00654c1e422--


--===============5685061744014082163==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============5685061744014082163==
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

--===============5685061744014082163==--