MathGroup Archive 1995

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

Search the Archive

Re: Simplifying vector expressions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg2168] Re: [mg2140] Simplifying vector expressions
  • From: Daniel Lichtblau <danl>
  • Date: Wed, 11 Oct 1995 01:59:13 -0400

  The difficulty lies in the fact that Times is Listable.

In[1]:= vec1 = { a, b, c }
Out[1]= {a, b, c}

In[2]:= vec2 = (1/x) * vec1 // InputForm
Out[2]//InputForm= {a/x, b/x, c/x}

In[3]:= ClearAttributes[Times, Listable]

In[4]:= vec3 = (1/x) * vec1 // InputForm
Out[4]//InputForm= {a, b, c}/x

 You can change this as above, but if you do not change it back prior  
to invoking any internal functions that rely on this property, be  
prepared for strange results. In particular, I'dn ot be surprised if  
Simplify got flaky, and it is not clear to me how Expand could work  
if one argument involved a List.
  A tactic that might serve your purposes is to (i) use Factor et al  
as they are (that is, with Times left as Listable), (ii) find out the  
PolynomialGCD of all elements in your list, (iii) divide through by  
that gcd to remove it from each element (might need to apply Together  
to get the job done completely), and (iv) make Times nonListable as  
above, and now multiply through by that gcd to restore it. Note that  
this will pull out factors in numerators as well as denominators,  
which may or may not be what you want.

  Daniel Lichtblau
  WRI
  danl at wri.com

Begin forwarded message:

>Date: Wed, 4 Oct 1995 01:57:42 -0400
>From: shenkin at still3.chem.columbia.edu (Peter Shenkin)
>Subject: [mg2140] Simplifying vector expressions
>Organization: MacroModel Development Group, Chemistry, Columbia U.,  
>NY, NY

Consider the following vectors:

In[2]:= vec1 = { a, b, c }

Out[2]= {a, b, c}

In[3]:= vec2 = (1/x) * vec1

         a  b  c
Out[3]= {-, -, -}
         x  x  x


I am looking for a mechanism I can apply to vec2 to put it in the  
form:

	 1
	(-) { a, b, c }
	 x

or

	{ a, b, c }
        -----------
             x

This would be the list equivalent of Factor[], as shown by the 

following example:

In[4]:= expr = a/x + b/x + c/x

        a   b   c
Out[4]= - + - + -
        x   x   x

In[5]:= Factor[ expr ]

        a + b + c
Out[5]= ---------
            x


Does this facility (for lists) exist in Mathematica, or in a package  
I can obtain easily?  If not, can you suggest guidelines for implementing
something like this?  Naturally, I'd want access to the full panoply
of algebraic functionality:  Simplify[], Expand[], etc., in addition
to Factor[].

	Thanks,
	-P.

-- 

******** When somebody says, "It's a matter of principle,"...  
********
*Peter S. Shenkin, Box 768 Havemeyer Hall, Chemistry, Columbia  
Univ.,*
*NY, NY  10027;  shenkin at columbia.edu;  (212)854-5143;  FAX:  
678-9039*
************ ...it's a sure sign he wants the whole pie.  
*************



  • Prev by Date: Re: trying to evaluate a piecewise function
  • Next by Date: Re: A simple swap function
  • Previous by thread: Re: Simplifying vector expressions
  • Next by thread: RE:MmaToHTML_for_Macs