RE: Expanding expressions with Dot, Times and Plus

*To*: mathgroup at smc.vnet.net*Subject*: [mg35511] RE: [mg35501] Expanding expressions with Dot, Times and Plus*From*: "David Park" <djmp at earthlink.net>*Date*: Wed, 17 Jul 2002 02:09:01 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

Jeremy, This is an interesting question and I hope you will get answers from some of the real experts. I had trouble writing a routine using Dot. I think the problem relates to the fact that Dot has the Attribute Flat. The following routine works for CircleDot. distributeCircleDot[expr_] := expr //. {CircleDot[a___, m_ b : CircleDot[__], c___] :> m CircleDot[a, b, c], prod : CircleDot[a_, b__] :> Distribute[prod, Plus]} test = -a\[CircleDot](b\[CircleDot]c - d\[CircleDot]e); test // distributeCircleDot -a\[CircleDot](b\[CircleDot]c) + a\[CircleDot](d\[CircleDot]e) When I tried the same routine with Dot, it didn't work. So I just changed Dot to CircleDot, applied the rules, and changed CircleDot back to Dot. distributeDot[expr_] := Module[{work}, work = expr /. Dot -> CircleDot; work = work //. {CircleDot[a___, m_ b : CircleDot[__], c___] :> m CircleDot[a, b, c], prod : CircleDot[a_, b__] :> Distribute[prod, Plus]}; work /. CircleDot -> Dot ] test = a.(b.c + d.e); test // distributeDot a.b.c + a.d.e test = -a.(b.c - d.e); test // distributeDot -a.b.c + a.d.e -ex[0, 1].(ex[0, 1].ex[1, 2] - ex[1, 2].ex[0, 1]) // distributeDot -ex[0, 1].ex[0, 1].ex[1, 2] + ex[0, 1].ex[1, 2].ex[0, 1] David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: JL [mailto:jl at aol.com] To: mathgroup at smc.vnet.net I am trying to expand a large expression that has terms that look as follows: -ex[0,1].(ex[0,1].ex[1,2]-ex[1,2].ex[0,1]) where ex[i,j] are unevaluated expressions. I would like Mathematica to simplify this and analogous expressions so that they read: ex[0,1].ex[1,2].ex[0,1]-ex[0,1].ex[0,1].ex[1,2] However, I cannot seem to find anything that will work. The problem is that I need to keep track of the order of the expressions ex[i,j]. If Dot were replaced by Times, there would be no problem whatsoever. If anyone knows how to help me with this problem, I would greatly appreciate it. Thanks, Jeremy Levy jlevy at pitt.edu