Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Mapping Distribute, losing constant factor
Replies: 1   Last Post: Jan 25, 2012 7:04 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Andrzej Kozlowski

Posts: 2,112
Registered: 1/29/05
Re: Mapping Distribute, losing constant factor
Posted: Jan 25, 2012 7:04 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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
>






Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.