Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #8140 > unrolled thread

Re: Mapping Distribute, losing constant factor

Started byAndrzej Kozlowski <akoz@mimuw.edu.pl>
First post2012-01-25 12:04 +0000
Last post2012-01-25 12:04 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Mapping Distribute, losing constant factor Andrzej Kozlowski <akoz@mimuw.edu.pl> - 2012-01-25 12:04 +0000

#8140 — Re: Mapping Distribute, losing constant factor

FromAndrzej Kozlowski <akoz@mimuw.edu.pl>
Date2012-01-25 12:04 +0000
SubjectRe: Mapping Distribute, losing constant factor
Message-ID<jfor3s$5qs$1@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
>

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web