Re: Apart, Factor on different operations
- To: mathgroup at smc.vnet.net
- Subject: [mg41328] Re: Apart, Factor on different operations
- From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
- Date: Thu, 15 May 2003 03:56:44 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Paolo wrote: Let op[x,y] be a binary associative operatoration but not commutative, say Dot: op[x_,y_+z_]:=op[x,y]+op[x,z] op[x_+y_,z_]:=op[x,z]+op[y,z] op[x_,y_]:=x.y and let term = x+y now, exp= op[term,z] is x.z + y.z So far so good. What I am trying to do is go back from x.z+y.z to op[term,z] by means of pattern matching: ============== This will work: ClearAll[hd]; exp/.((a_).d_+(b_).d_):>hd[a+b,d]/.term->X/.hd->op X.z Without parentheses around (a_), (b_) the input would be parsed as Times[(a_.),d_]+Times[(b_.),d_] where (a_.) and (b_.) are optional patterns. ============== Regards, Ted Ersek Download Mathematica tips, tricks from http://www.verbeia.com/mathematica/tips/Tricks.html