Reputation: 33
I have a long list containing something like
a:[1, a, -b, -a*b, j, -j, j^2, -j^3, a*j, a*j^2, -a*j,- a*j^2, a*b*j, a*j^4, -a*b*j^7];
I would like to perform substitution like j^x -> j^(3 mod x)
Basically replace every occurrence in the list of the pattern j^x (where x = 0 to 100)
with j^(3 mod x)
.
subst and ratsubst etc seem to look for a pattern literally not symbolically.
Is there a way to do this in Maxima?
Thanks
Upvotes: 1
Views: 585
Reputation: 17577
I think you can use pattern matching for this. (Pattern matching in the sense of matching expressions, not strings.) tellsimp
and tellsimpafter
define rules that are applied automatically; defrule
and defmatch
define rules that are applied explicitly. See also matchdeclare
.
A solution via defrule
might look like this; I haven't tried it.
matchdeclare (nn, lambda ([e], integerp(e) and e >= 3));
defrule (r1, j^nn, j^(mod(3, nn)));
apply1 (mylist, r1);
where mylist
is the list above. (I think assigning the list to a
is problematic, since a
appears as a term in the products ....)
Upvotes: 2