Applyrule
Introduction
With applyrule, a rule or a list of rules can be applied to a given expression. applyrule computes the fix point; it applies the rule until it cannot be applied anymore. It is more powerful than the command subs, but does not do mathematical transformations as algsubs does.
restart
Examples
Syntax: applyrule(rule, expression) where rule is a rule or a set of rules. The syntax for rule is the same as that used in the pattern matcher. (For more details, see the help page of patmatch.)
A simple manipulation:
applyrule⁡a+b=x,f⁡a+b+c
f⁡x+c
applyrule⁡x=y,x2
y2
applyrule⁡x2=y,f⁡x2,ⅇsin⁡x+2⁢x2
f⁡y,ⅇsin⁡x+2⁢y
One can use parameters in applyrule:
applyrule⁡f⁡a::integer⁢x=a⁢f⁡x,f⁡2⁢x+g⁡x−p⁢f⁡x
2⁢f⁡x+g⁡x−p⁢f⁡x
applyrule can be used over data structures:
applyrule⁡a::even=even,a::prime=prime,1,2,4,3,5,6,4,8,15,21
1,even,even,prime,prime,even,even,even,15,21
applyrule⁡sin⁡2⁢x=2⁢sin⁡x⁢cos⁡x,sin⁡x+sin⁡2⁢x−cos⁡x
sin⁡x+2⁢sin⁡x⁢cos⁡x−cos⁡x
Return to Example Worksheet Index
Download Help Document