Ratsubst
works find for exponents in many cases:
ratsubst(q,r,a^r) => a^q
ratsubst(q,r,a^(r+1)) => a^(q+1)
ratsubst(q,r^2,a^(r^2)) => a^q
ratsubst(q,r^2-1,a^((r-1)*(r+1))) => a^q
ratsubst(q,r^2-1,a^((r-2)*(r+1))) => a^((-r)+q-1)
but not in some others:
ratsubst(q,r+1,a^(r+1)) => a^(r+1) <<< should be a^q
ratsubst(q,2*r,a^(2*r)) => a^(2*r) <<< ditto
ratsubst(q,2*r+1,a^(2*r+1)) => a^(2*r+1) <<< ditto
I don't know why this would be designed like this, but if it's intentional behavior, it should at least be documented. fullratsubst
and ratsubstflag
don't change the results.
Maxima 5.46.0 SBCL 2.3.0 MacOS Intel 14.3.1
rat(a^(r+1)) looks like aa^r, so there is no occurrence of r+1 at all.
ratsubst(q-1,r,a^(r+1)) results in a^q, which is presumably the desired result.
a^(2r+1) is a(a^r)^2 , so there is not a simple hack for making it a^q.
Just use subst instead of ratsubst for exponents; ratsubst(a,b,c) works
for a,b,c polynomials or rational functions, since it relies on CRE form
(canonical rational expression) form, where division-with-remainder can
be used to find subexpressions. Sometimes extracting kernels like a^r
from a^(2r) to form (a^r)^2 work too. But not always, as this behavior
demonstrates.
Maybe add to documentation: The methods used by ratsubst work when a,b,c are polynomials
or rational functions, where division works. Essentially ratsubst uses division by b
to compute Quotient and Remainder such that c=Qb+R. The result of substitution is then Qa+R.
RJF