       Re: Q: About constants inside Distribute

• To: mathgroup at smc.vnet.net
• Subject: [mg9237] Re: [mg9187] Q: About constants inside Distribute
• From: Allan Hayes <hay at haystack.demon.co.uk>
• Date: Fri, 24 Oct 1997 01:00:51 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```sergio at scisun.sci.ccny.cuny.edu (Sergio Rojas) [mg9187] Q: About
constants inside Distribute

rule = Dot[s___,(k:(a[i_]))m___, r___]:> k Dot[s,m,r]

f = O1*a + O2*a
g = P1*a*a
h = O2*a

Distribute[f.g.h]//.rule

2
a  a O1 . P1 . a . O2 + a a a O2 . P1 . a. O2

with the a not stripped out by the rule.

The problem is seems to lie in

MatchQ[a , a m___]
False

When we would expect matches like
a ~ a 1 ~ a Times[] ~ a Times[___].

I'm not clear about what is happening here but a work-around is use
default values

MatchQ[a,a m_.]	(*   note the dot m_.  *)

True

and modify the rule to

rule2 = Dot[s___,(k:a[i_])m_., r___]:> k Dot[s,m,r]

Check:

Distribute[f.g.h]//.rule2

a^2*a^2*O1 . P1 . O2 + a*a*a^2*O2 . P1 . O2

Allan Hayes
hay at haystack.demon.co.uk
http://www.haystack.demon.co.uk/training.html voice:+44 (0)116 2714198
fax: +44 (0)116 2718642
Leicester,  UK

```

• Prev by Date: Re: Colored ListDensityPlot
• Next by Date: Re: Re: Problems with Limit, Log, E