Discussion:
Common factors in a list
(too old to reply)
John Reed
2005-06-28 09:24:42 UTC
Permalink
I'm working with a list (vector) that's composed of functions such as
complex exponentials and Bessel functions. Some of the functions are common
to each element of the list. I'm trying to find a way to do the following:

{a x, a y, a z}-> a *{x, y, z}

In this expression, a, x, y, z are polynomials, exponentials and/or Bessel
functions.

So far I haven't had any luck with this. Does anyone have a simple
solution?

John Reed
Bob Hanlon
2005-06-29 02:05:16 UTC
Permalink
Mathematica will just undo the operation since the multiplication is automatic

expr1=a*{x,y,z}

{a x,a y,a z}

You can use a dummy operator such as CircleTimes

expr2=expr1/.{a_*x_,a_*y_,a_*z_}:>
CircleTimes[a,{x,y,z}]

a ? {x, y, z}

And clear it with

expr2/.CircleTimes:>Times

{a x,a y,a z}


Bob Hanlon
Date: 2005/06/28 Tue AM 05:13:27 EDT
Subject: Common factors in a list
I'm working with a list (vector) that's composed of functions such as
complex exponentials and Bessel functions. Some of the functions are
common
{a x, a y, a z}-> a *{x, y, z}
In this expression, a, x, y, z are polynomials, exponentials and/or Bessel
functions.
So far I haven't had any luck with this. Does anyone have a simple
solution?
John Reed
Andrzej Kozlowski
2005-06-29 02:12:53 UTC
Permalink
Post by John Reed
I'm working with a list (vector) that's composed of functions such as
complex exponentials and Bessel functions. Some of the functions
are common
to each element of the list. I'm trying to find a way to do the
{a x, a y, a z}-> a *{x, y, z}
In this expression, a, x, y, z are polynomials, exponentials and/or
Bessel
functions.
So far I haven't had any luck with this. Does anyone have a simple
solution?
John Reed
What you are asking for is impossible in Mathematica because
Mathematica automatically evaluates



a *{x, y, z}

{a x,a y,a z}


So you need to factor {a x, a y, a z} in some other form, for example
as {a,{x,y,z}}. This can be done as follows:

f[l_List] := With[{a = PolynomialGCD @@ l}, {a, Cancel[l/a]}]

for example


f[{x*BesselI[n, x]*BesselK[m, x], x*BesselI[n, x]*Exp[x]}]


{x*BesselI[n, x], {BesselK[m, x], E^x}}


Andrzej Kozlowski
Chiba, Japan
dh
2005-06-29 02:13:39 UTC
Permalink
Hi John,
you could try to create a polynomial in a new variable, say z, from your
vector by:
v={a x, a y, a z};
pol=Table[z^i,{i,Length[v]}] . v
now you could extract a common factor by:
com= FactorTerms[pol,z][[1]]
the residual vector you get from:
v/com

sincerely, Daniel
Post by John Reed
I'm working with a list (vector) that's composed of functions such as
complex exponentials and Bessel functions. Some of the functions are common
{a x, a y, a z}-> a *{x, y, z}
In this expression, a, x, y, z are polynomials, exponentials and/or Bessel
functions.
So far I haven't had any luck with this. Does anyone have a simple
solution?
John Reed
Jens-Peer Kuska
2005-06-29 02:20:31 UTC
Permalink
Hi,

ClearAttributes[Times, Listable]

{a x, a y, a z} /. {a*b_, c___} :> a*{b, Sequence
@@ (#/a & /@ {c})}

Regards

Jens
Post by John Reed
I'm working with a list (vector) that's composed
of functions such as
complex exponentials and Bessel functions. Some
of the functions are common
to each element of the list. I'm trying to find
{a x, a y, a z}-> a *{x, y, z}
In this expression, a, x, y, z are polynomials,
exponentials and/or Bessel
functions.
So far I haven't had any luck with this. Does
anyone have a simple
solution?
John Reed
David Bailey
2005-06-29 02:26:37 UTC
Permalink
Post by John Reed
I'm working with a list (vector) that's composed of functions such as
complex exponentials and Bessel functions. Some of the functions are common
{a x, a y, a z}-> a *{x, y, z}
In this expression, a, x, y, z are polynomials, exponentials and/or Bessel
functions.
So far I haven't had any luck with this. Does anyone have a simple
solution?
John Reed
Hello,

The best bet is to make use of Factor. This seems rather more powerful
than the help might suggest - for example it recognises that Exp[a+b] is
Exp[a]Exp[b]. To use Factor, convert the list into a polynomial in an
otherwise unused variable - say q:

Plus@@MapIndexed[#1 q^(#2[[1]]-1)&,{a Exp[m],b Exp[m+n], c Exp[m]}]

a*E^m + b*E^(m + n)*q + c*E^m*q^2

Factor[%]

E^m*(a + b*E^n*q + c*q^2)

It is not possible to convert the result back into a product of a term
and a list (as you specified) because this will evaluate and leave you
where you began! Instead, we can replace the product with a CircleTimes:

E^m*(a + b*E^n*q + c*q^2) /. (p1_)*(p2_Plus) :> p1 \[CircleTimes]
CoefficientList[p2, q]

E^m \[CircleTimes] {a, b*E^n, c}

David Bailey
http://www.dbaileyconsultancy.co.uk
Peter Pein
2005-06-29 02:31:57 UTC
Permalink
Post by John Reed
I'm working with a list (vector) that's composed of functions such as
complex exponentials and Bessel functions. Some of the functions are common
{a x, a y, a z}-> a *{x, y, z}
In this expression, a, x, y, z are polynomials, exponentials and/or Bessel
functions.
So far I haven't had any luck with this. Does anyone have a simple
solution?
John Reed
Because of Mathematica's built-in "simplification" of
In[1]:= a*{x, y, z}
to
Out[1]={a*x, a*y, a*z},
I'll use \[CircleDot] as replacement for the multiplication character:
In[2]:= a \[CircleDot] {x, y, z}
Out[2]= a \[CircleDot] {x, y, z}

In[3]:=
vecFactor[vec_List] :=
Module[{ql, fl = FactorList[Plus @@ vec], mp, f2},
ql = FoldList[Cancel[#1/Power @@ #2]& , vec, fl];
f2 = ql[[ mp = Position[#1, Min[#1]]&[LeafCount /@ ql][[1, 1]]]];
ql = Times @@ Power @@@ Take[fl, {1, mp - 1}];
ql \[CircleDot] f2
]
In[4]:=
vecFactor[
{6*BesselJ[0, x]* xp[-x]*(x^2 - 1), 4*(x - 1)*Exp[-x]*BesselJ[1, x],
2*(1 - x)^2*BesselJ[2, x]*Exp[-x]}
]
Out[4]=
((2*(-1 + x))/E^x) \[CircleDot]
{3*(1 + x)*BesselJ[0, x], 2*BesselJ[1, x], (-1 + x)*BesselJ[2, x]}

Later you can use expr/.\[CircleDot]->Times to get back your product.
Maybe someone else has a better trick to avoid the distribution of the
common factor...
--
Peter Pein
Berlin
Continue reading on narkive:
Loading...