Re: TransformationFunctions
- To: mathgroup at smc.vnet.net
- Subject: [mg102115] Re: TransformationFunctions
- From: O <kakabomba at gmail.com>
- Date: Thu, 30 Jul 2009 05:29:40 -0400 (EDT)
- References: <h46p31$e4g$1@smc.vnet.net> <200907230754.DAA26659@smc.vnet.net>
On Jul 24, 3:14 am, Andrzej Kozlowski <a... at mimuw.edu.pl> wrote: > On 24 Jul 2009, at 15:46, Oles Zaburannyi wrote: > > > > > > > 2009/7/23 Andrzej Kozlowski <a... at mimuw.edu.pl> > > > 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 > > > thanks, but your solution give incorrect result for > > > In[3]:=Simplify[(z ** x ** y + z ** y ** x), > > TransformationFunctions -> {Automatic, tf1}] > > Out[3]:=-2 x ** y ** z > > (should be 0) > > > As i understand my main problem is that Simplify apply > > transformation function and select simplest form AT EACH STEP. > > So, if globally simplest form is achieved only by MORE COMPLEX > > intermediate forms that simplification will be omited. > > > Am i right? > > > in another words simplification like > > > initial form -> a bit complex form -> maybe even more complex form - > > > simplest form > > > is omited by Simplify? > > > -- > > No Signature > > You are right. I did not give this enough thought and did not consider = > the possibility of multiplying more than two > elements. However, this is easy to fix: > > tf1[expr_] := > expr /. z_NonCommutativeMultiply :> > If[Not[OrderedQ[z]], Signature[List @@ z]*Sort[z], z] > > I think will not work correctly: > > Simplify[x ** y + y ** x, TransformationFunctions -> {Automatic, tf1}] > 0 > > Simplify[(z ** x ** y + z ** y ** x), > TransformationFunctions -> {Automatic, tf1}] > 0 > > As for your question; yes. Simplification generally only proceeds to > forms which are simpler (with respect to the given complexity > function, which can be user controlled) at every step. However, there > are some exceptions to this, because at eeach step simplify remembers > not only the form of the expression that has the least complexity > found so far but also (for most expression) a standard form of the > expression. It will therefore sometimes notice cancellations when > between two expressions which have the same standard form, even if > there is no complexity decreasing route "connecting" them. But this is = > not really something that a user can control and shows itself most > often when Simplify is used to show that some expression is 0 (rather > then in finding the simplest form of the expression). > > Andrzej Kozlowski sorry, maybe my question is to general. more precisely: i have In[1]:= tr[l___ ** (a_ + b_) ** r___] := l ** a ** r + l ** b ** r This DON'T work: In[2]:= Simplify[a ** (b + c) ** d - a ** b ** d, TransformationFunctions -> {Automatic, tr}] Out[2]:= -(a ** b ** d) + a ** (b + c) ** d But this DOES work of course In[3]:= Simplify[tr[a ** (b + c) ** d] - a ** b ** d, TransformationFunctions -> {Automatic}] Out[3]:= a ** c ** d Question is: exist way to describe function "tr" to act only on part of expression or is way to tell Simplify to try apply transformation function "tr" to EACH part of expression thanks a lot
- Follow-Ups:
- Re: Re: TransformationFunctions
- From: Andrzej Kozlowski <akoz@mimuw.edu.pl>
- Re: Re: TransformationFunctions
- References:
- Re: TransformationFunctions
- From: Peter Breitfeld <phbrf@t-online.de>
- Re: TransformationFunctions