Group Abstract Group Abstract

Message Boards Message Boards

0
|
5K Views
|
3 Replies
|
1 Total Like
View groups...
Share
Share this post:

Make a simple rule to combine a function xp of plus & minus args?

Posted 9 years ago

Here's a simple function Xpee. I want a rule that combines "Xpee[aa] (+/-) Xpee[-aa]" to give ZipIt[aa]. For example Xpee[-1/5] - Xpee[1/5] yields ZipIt[1/5]. I've used MatchQ to test various parts of the rule. I can MatchQ parts such as Xpee[aa_]. But I've failed with various combination rules such as


And I've used FullForm to get to this point but I can't quite get to the point of a workable rule to combine -Xpee[-aa] + Xpee[aa] to give ZipIt[aa]. The Times gets in the way. What am I missing to come up with a workable rule to combine Xpee[aa] (+/-) Xpee[-aa]?

POSTED BY: Anthony DeGance
3 Replies
POSTED BY: Henrik Schachner
POSTED BY: Anthony DeGance
Posted 9 years ago

Test this endlessly before you trust it

In[1]:= xprule = {Xpee[a_] + Xpee[b_] | Xpee[a_] - Xpee[b_] /; b == -a :> ZipIt[b]};
{Xpee[2] + Xpee[-2], Xpee[-2] + Xpee[2], Xpee[-x] + Xpee[x], 
 Xpee[2] - Xpee[-2], Xpee[-2] - Xpee[2], Xpee[-x] - Xpee[x], 
 Xpee[-x] + Xpee[y], Xpee[-x] - Xpee[y]} /. xprule

Out[2]= {ZipIt[2], ZipIt[2], ZipIt[x],
ZipIt[-2], ZipIt[2], ZipIt[x], 
Xpee[-x] + Xpee[y], Xpee[-x] - Xpee[y]}
POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard