Re: Re: TransformationFunctions
- To: mathgroup at smc.vnet.net
- Subject: [mg101964] Re: [mg101922] Re: TransformationFunctions
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Fri, 24 Jul 2009 06:14:22 -0400 (EDT)
- References: <h46p31$e4g$1@smc.vnet.net> <200907230754.DAA26659@smc.vnet.net>
On 23 Jul 2009, at 16:54, Peter Breitfeld wrote: > ". at ntaxa.com" wrote: > >> Can anyone advice why following code does not work: >> >> In[538]:=tf[z_NonCommutativeMultiply] := -z[[2]]**z[[1]] >> In[539]:=Simplify[x ** y + y ** x,TransformationFunctions -> {tf, >> Automatic}] >> Out[539]:=x ** y + y ** x >> >> I expect rather 0 >> >> By the way: >> In[540]:=x ** y + tf[y ** x] >> Out[540]:=0 >> > > I think, the problem here is, that Simplify will apply tf to both > products. So I would suggest you do something like this: > > tfrule = (x_ ** y_ + y_ ** x_) :> 0; > tf[expr_] := expr /. tfrule; > Simplify[x ** y + y ** x, TransformationFunctions -> {tf}] > > Out=0 > > > -- > _________________________________________________________________ > Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de > There are problems with this approach. Consider: tfrule = (x_ ** y_ + y_ ** x_) :> 0; tf[expr_] := expr /. tfrule; Simplify[x ** y + y ** x, TransformationFunctions -> {tf}] 0 but Simplify[2 x ** y + y ** x, TransformationFunctions -> {tf}] 2 x ** y + y ** x by contrast: tf1[expr_] := expr /. z_NonCommutativeMultiply :> If[Not[OrderedQ[z]], -Sort[z], z] In[42]:= Simplify[x ** y + y ** x, TransformationFunctions -> {Automatic, tf1}] Out[42]= 0 but also Simplify[2 x ** y + y ** x, TransformationFunctions -> {Automatic, tf1}] x ** y Andrzej Kozlowski
- References:
- Re: TransformationFunctions
- From: Peter Breitfeld <phbrf@t-online.de>
- Re: TransformationFunctions