MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: TransformationFunctions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101966] Re: [mg101922] Re: TransformationFunctions
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Fri, 24 Jul 2009 06:14:44 -0400 (EDT)
  • References: <h46p31$e4g$1@smc.vnet.net> <200907230754.DAA26659@smc.vnet.net> <2B05AE03-148B-4A6B-9030-7F538CEA5105@mimuw.edu.pl> <9994fa840907232346s54968264tca41bad30357b8ed@mail.gmail.com>

On 24 Jul 2009, at 15:46, Oles Zaburannyi wrote:

>
>
> 2009/7/23 Andrzej Kozlowski <akoz 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


  • Prev by Date: Graph issue
  • Next by Date: Re: Thoughts on a Wolfram|Alpha package
  • Previous by thread: Re: Re: TransformationFunctions
  • Next by thread: Re: TransformationFunctions