Re: Factorising
- To: mathgroup at smc.vnet.net
- Subject: [mg38984] Re: Factorising
- From: "News Admin" <news at news.demon.net>
- Date: Thu, 23 Jan 2003 08:05:42 -0500 (EST)
- References: <b0lun3$58e$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
While playing variations on Hartmut's elegant solution I came across the
following illustration of the perils of blocking basic operations like Plus
expr = {(a - 2*wone*Sin[a*t])/4, (a - 2*wone*Sin[a*t])/
4, (a + 2*wone*Sin[a*t])/4, (a + 2*wone*Sin[a*t])/
4, (-a - 2*Sqrt[a^2 + wone^2*Sin[a*t]^2])/
4, (-a - 2*Sqrt[a^2 + wone^2*Sin[a*t]^2])/
4, (-a + 2*Sqrt[a^2 + wone^2*Sin[a*t]^2])/
4, (-a + 2*Sqrt[a^2 + wone^2*Sin[a*t]^2])/4}
Block[{Plus},
HoldForm[#] &[FullSimplify[expr]]]//InputForm
HoldForm[{(4 + a)/4, (4 + a)/4, (4 + a)/4, (4 + a)/4, (-a - 2*Sqrt[1 +
a^2])/4,
(-a - 2*Sqrt[1 + a^2])/4, (-a + 2*Sqrt[1 + a^2])/4, (-a + 2*Sqrt[1
+ a^2])/4}]
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
"Wolf, Hartmut" <Hartmut.Wolf at t-systems.com> wrote in message
news:b0lun3$58e$1 at smc.vnet.net...
>
> >-----Original Message-----
> >From: Chris Rodgers [mailto:christopher.rodgers at st-johns.oxford.ac.uk]
To: mathgroup at smc.vnet.net
> >Sent: Tuesday, January 21, 2003 1:40 PM
> >To: mathgroup at smc.vnet.net
> >Subject: [mg38984] Factorising
> >
> >
> >Hi
> >
> >How can I tell Mathematica to pull a particular factor out of
> >an expression.
> >
> >For example in this expression:
> >{(a - 2*wone*Sin[a*t])/4, (a - 2*wone*Sin[a*t])/4, (a +
> >2*wone*Sin[a*t])/4,
> >(a + 2*wone*Sin[a*t])/4,
> > (-a - 2*Sqrt[a^2 + wone^2*Sin[a*t]^2])/4, (-a - 2*Sqrt[a^2 +
> >wone^2*Sin[a*t]^2])/4,
> > (-a + 2*Sqrt[a^2 + wone^2*Sin[a*t]^2])/4, (-a + 2*Sqrt[a^2 +
> >wone^2*Sin[a*t]^2])/4}
> >
> >I would like to bring the "a" out to the front of the expression, even
> >outside the matrix.
> >
> >How can I ask Mathematica to do this, and how can I stop the "a" just
> >floating back into the main expression?
> >
> >Yours
> >
> >Chris Rodgers
> >St John's College
> >http://rodgers.org.uk/
> >
> >
> >
>
> Chris,
>
> The problem comes from the Listable attribute of Plus. If you want to see
> your expression (which I call alist for a while) as you want, you can
clear
> that Attribute for a while:
>
> ClearAttributes[Plus, Listable]
>
> Thread[Apart[alist], Plus]
>
>
> Now, I think, you see what you want. The procedure is dangerous however,
> since the attributes of Plus should be restored, before you make any other
> evaluation.
>
> SetAttributes[Plus, Listable]
>
>
> Assuming you need that form only for printing purposes, it might be more
> convenient just to wrap it into HoldForm:
>
> Block[{Plus},
> HoldForm[#] &[Thread[Sort /@ Apart[alist], Plus]]]
>
> The Block temporarily inactivates Plus (and its attributes), HoldForm
> prevents threading back to the original form, after the expression having
> left Block.
>
> --
> Hartmut Wolf
>
>