Re: Taylor Series Reversion error: 'quotient' by 'zero'
Richard Fateman <[email protected]>
| Newsgroups | gmane.comp.mathematics.maxima.general |
|---|---|
| Message-ID | <CADB8Zm6XyPK5=CdZO75bVwB3LecW+8zC91uBXcAGb-CAhK7qxQ@mail.gmail.com> |
If this reversion is essentially solving an algebraic equation x=f(t) to
find t= g(x) in a power series domain,
this is discussed in
https://people.eecs.berkeley.edu/~fateman/papers/newton.pdf . There are 2
or 3 methods described
which are linear or quadratic convergence [Hensel vs Newton]. Here's a
clip of a (working) program.
nr2(f,x,t,aroot,n):=
block([s,deg,ex,df],
if (subst([x=aroot,t=0],f)#0) or
(subst([x=aroot,t=0],(df:diff(f,x)))=0)
then return (print("Can't expand", f, "at", aroot)),
ex:horner(x-f/df),
s:aroot, deg:0,
while deg<n
do (deg:min(2*(deg+1)-1,n),
s:taylor(subst(x=taylor(ratdisrep(s),x,aroot,deg),ex),t,0,deg)),
return(s))$
f:x^2+3*x+2+t;
nr2(f,x,t,-1,3);
This doesn't mess with finding or creating a correct lowest power.
On Sat, Aug 15, 2026 at 5:32 AM Barton Willis via Maxima-discuss <
[email protected]> wrote:
> Correct--looking at the source code (located in /share/calculus/) it's
> clear that the first argument to 'revert` must be a Taylor polynomial whose
> lowest power is one.
>
> Changes:
>
>
> 1. Reformated the source code,
> 2. Inserted few checks for valid arguments,
> 3. Used taylorinfo to find n, not the highest power
> 4. Algorithmically, modified the code as Viktor suggested
>
>
> revert(exp, t) := block([f, n, m, v, w, r1, g],
>
> if not taylorp(exp) then (
> error("The first argument to exp must be a Taylor polynomial;
> found ~M ~%", exp)),
>
> /* Lowest and highest powers of t in exp */
> m : lopow(exp, t),
> n : last(first(taylorinfo(exp))),
>
> if not integerp(m) or not integerp(n) then
> error("Unable to find the lowest or highest powers of ", t, " in
> the expression ", exp),
>
> if n < 0 then
> error("The highest power of ", t, " in the expression ", exp, "
> must be positive"),
>
>
> /* If lowest power is not 1, normalize: exp -> taylor(exp^(1/m),t,0,n)
> */
> g : if m = 1 then exp
> else taylor(exp^(1/m),t,0,n),
>
> /* Allocate arrays */
> array([v, w], n),
>
> /* Leading coefficient normalization */
> r1 : 1 / ratcoef(g, t, 1),
> v[1] : 1,
>
> /* Build v[k] and initial w[k] */
> for k : 2 thru n do (
> v[k] : ratcoef(g, t, k) * r1,
> w[k] : -v[k]
> ),
> w[1] : 1,
>
> /* Define update function */
> f : lambda([j],
> for i from j + 1 thru n do
> w[i] : w[i] - w[j] * v[i - j + 1]
> ),
>
> /* First sweep */
> for j from 2 thru n - 1 do
> apply(f, [j]),
>
> /* Second sweep */
> for k from 2 thru n - 1 do
> (for j from k thru n - 1 do
> apply(f, [j])
> ),
>
> /* Accumulate final polynomial for g^{-1}(t) */
> f : 0,
> for k thru n do
> f : f + w[k] * (t * r1)^k,
>
> subst(t^(1/m),t,f)
> )$
>
> The code mutates f from a lambda form to a polynomial accumulator—that's
> okay, but it's a bit weird. Also, I think that v and w need to be declared
> local.
>
> This code was only lightly tested.
>
> (%i24) load(revert)$
>
> (%i25) eq : 1/x^2+x^4 + x^6;
>
> (%o25) x^6+x^4+1/x^2
> (%i26) revert(taylor(eq,x,0,12),x);
>
> (%o26) (2/sqrt(x)+1/x^(7/2)+1/x^(9/2))/2
> (%i27) subst(x=eq,%);
>
> (%o27)
> (2/sqrt(x^6+x^4+1/x^2)+1/(x^6+x^4+1/x^2)^(7/2)+1/(x^6+x^4+1/x^2)^(9/2))/2
> (%i28) taylor(%,x,0,14);
>
> (%o28) x-(11*x^13)/8
>
> ------------------------------
> *From:* Michel Gosse <[email protected]>
> *Sent:* Saturday, August 15, 2026 4:54 AM
> *To:* Justin Jensen <[email protected]>
> *Cc:* [email protected] <
> [email protected]>
> *Subject:* Re: [Maxima-discuss] Taylor Series Reversion error: 'quotient'
> by 'zero'
>
> Caution: Non-NU Email
>
> It seems that revert needs a term in t within the taylor serie.
> For eq, the t coefficient is 0, so the error quotient by zero appears.
> I have tried this to have a linear term, but don't know if the result is
> correct
> ser2:subst(u^(1/3),t,ser);
> sol:revert(ser2,u);
> subst(t^3,u,sol);
> i get
> \[\frac{{{\ensuremath{\pi} }^{3}} {{t}^{9}}}{2240}\mathop{+}\frac{3
> \ensuremath{\pi} {{t}^{3}}}{4}\]
>
> Le sam. 15 août 2026 à 10:45, Justin Jensen <[email protected]> a
> écrit :
>
> I'm new to Maxima and Computer Algebra Systems in general. So far Maxima
> seems to be exactly what I need right now.
>
> As part of a side project I'm trying to find the inverse of a function. It
> has no closed-form function, at least in the general case, so I'm
> approximating it with a Taylor series. Note that the series has
> coefficients of 0 for the 0th, 1st, and 2nd terms. When I try to do a
> reversion of series using the `revert` command, it fails and gives the
> error: "'quotient' by 'zero'" (see below). How do I resolve this? Once upon
> a time, I used Mathematica to find the inverse of a very similar series and
> it worked fine. How do I do this with Maxmia?
>
> (%i1) eq: (2*t-sin(2*t))/%pi;
> eq (2*t-sin(2*t))/%pi
> (%i9) ser: taylor(eq,t,0,9);
> ser
> (4*t^3)/(3*%pi)-(4*t^5)/(15*%pi)+(8*t^7)/(315*%pi)-(4*t^9)/(2835*%pi)+...
> (%i10) revert(ser,t);
> (%o10)
> revert(-((4*t^9)/(2835*%pi))+(8*t^7)/(315*%pi)-(4*t^5)/(15*%pi)+(4*t^3)/(3*%pi),t)
> (%i11) load("revert")$
> (%i61) revert(ser,t);
> `quotient' by `zero'
>
> -- an error. To debug this try: debugmode(true);
>
>
> Thanks in advance,
>
> --
> Justin
> _______________________________________________
> Maxima-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/maxima-discuss
> <https://urldefense.com/v3/__https://lists.sourceforge.net/lists/listinfo/maxima-discuss__;!!PvXuogZ4sRB2p-tU!AaLiMFWH52pN9V6ZzKztvrA2MQXISJxriaAuZ1fuo9sIikMLYWXaZR5_sSm0fjukriwqDk4JNYFPdA$>
>
> _______________________________________________
> Maxima-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/maxima-discuss
>
_______________________________________________
Maxima-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/maxima-discuss