Richard Fateman - 2024-03-25

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^(2
r+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^(2
r) 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