MathGroup Archive 2012

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

Search the Archive

Re: Mapping Distribute, losing constant factor

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124566] Re: Mapping Distribute, losing constant factor
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Wed, 25 Jan 2012 07:02:08 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201201241005.FAA20237@smc.vnet.net>

The reason for what you are seeing is that you are mapping Distribute no 
on level 2 in the expression but on level 2 and all levels below 2. If 
you only mapped Distribute on level 2 you would not "loose" any factors 
but get the effect you probably intended:

 Map[Distribute, a, {2}]

{{((1/2)*(-1 + E^\[Theta])^2)/E^\[Theta] +
   1, -(1/(E^\[Theta]*2)) + E^\[Theta]/2, 0, 0},
   {-(1/(E^\[Theta]*2)) +
   E^\[Theta]/2, ((1/2)*(-1 + E^\[Theta])^2)/E^\[Theta] + 1, 0,
  0}, {0, 0, 1, 0},
   {0, 0, 0, 1}}

The reason why these factors of 1/2 seem to disappear is that 
distributing over level 1 elements in the expression causes terms to be 
added (by default Distribute distributes over Plus). As an example look 
at what happens to this single level 1 term:

 Distribute[{1 + ((1/2)*(-1 + E^\[Theta])^2)/
    E^\[Theta], ((1/2)*(-1 + E^\[Theta])*(1 + E^\[Theta]))/
   E^\[Theta], 0, 0}]

{1 + ((1/2)*(-1 + E^\[Theta])^2)/
   E^\[Theta], ((-1 + E^\[Theta])*(1 + E^\[Theta]))/E^\[Theta], 0, 0}

The factor 1/2 seems to have disappeared because distributing over Plus 
here causes the addition:

{1, ((1/2)*(-1 + E^\[Theta])*(1 + E^\[Theta]))/E^\[Theta], 0, 0} +
    {((1/2)*(-1 + E^\[Theta])^2)/
   E^\[Theta], ((1/2)*(-1 + E^\[Theta])*(1 + E^\[Theta]))/E^\[Theta],
  0, 0}

To understand why it happens just think of what Distribute is supposed 
to do here or look at

Trace[Distribute[{1 + ((1/2)*(-1 + E^\[Theta])^2)/E^\[Theta], ((1/2)*(-1 
+ E^\[Theta])*(1 + E^\[Theta]))/
     E^\[Theta], 0, 0}]]

Andrzej Kozlowski




On 24 Jan 2012, at 11:05, Stefan Salanski wrote:

> Hello all, I ran across this interesting problem in some quick
> calculations i was doing with matrix generators.
>
> the following matrix was the result of a generator function i defined,
> but the error persists if i just copy this in by itself:
>
> a = {{1+1/2 E^-\[Theta] (-1+E^\[Theta])^2,1/2 E^-\[Theta] (-1+E^\
> [Theta]) (1+E^\[Theta]),0,0},{1/2 E^-\[Theta] (-1+E^\[Theta]) (1+E^\
> [Theta]),1+1/2 E^-\[Theta] (-1+E^\[Theta])^2,0,0},{0,0,1,0},{0,0,0,1}}
>
> My goal being to simplify this and obtain the sinh and cosh function
> representations, i found that using Expand followed by ExpToTrig works
> perfectly:
>
> In[13]:= ExpToTrig[Expand[a]]
>
> Out[13]= {{Cosh[\[Theta]], Sinh[\[Theta]], 0, 0}, {Sinh[\[Theta]],
> Cosh[\[Theta]], 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}
>
> However, my first attempt at simplifying involved using Distribute
> (which was my first guess for getting it into a nice form). And it was
> using distribute that i noticed the constant factor 1/2 in each matrix
> element was dropped. Distribute[a] didnt change anything, so I mapped
> it over a as follows:
>
> In[17]:= Map[Distribute, a, 2]
>
> Out[17]= {{2 + E^-\[Theta] (-1 + E^\[Theta])^2, -E^-\[Theta] +  E^\
> [Theta], 0, 0}, {-E^-\[Theta] + E^\[Theta],   2 + E^-\[Theta] (-1 + 
E^\
> [Theta])^2, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}
>
> The factors of 1/2 in the non-trivial matrix elements seem to have
> disappeared. Though testing it on individual elements works fine
> (though doesn't seem to have done a whole lot of distributing, maybe
> because the Head is Plus, and not Times or something else)
>
> In[22]:= Distribute[a[[1, 1]]]
>
> Out[22]= 1 + 1/2 E^-\[Theta] (-1 + E^\[Theta])^2
>
> So my question is whether this disappearance of the 1/2 factor is a
> bug, or due to a lack of understanding of Distribute and/or Map on my
> part.
>
> -Stefan Salanski
> University of Virginia
>




  • Prev by Date: Re: Mathematica 8 + OS X + McAfee = trouble; help?
  • Next by Date: Re: Problem with compile fct. and Thread
  • Previous by thread: Mapping Distribute, losing constant factor
  • Next by thread: Automatically colred and indexed custom locators