Subject: Factoring matrix expressions, even trivial ones?
From: Henry Baker
Date: Fri, 03 May 2013 10:58:22 -0700
Hi Stavros:
This one seems to work a good deal better:
matrix_gcd(m):=
block([nums,denoms,numgcd,denomgcd],
m:factor(m),
nums:matrixmap('num,m),
denoms:matrixmap('denom,m),
numgcd:apply('ezgcd,list_matrix_entries(nums))[1],
denomgcd:apply('ezgcd,list_matrix_entries(denoms))[1],
factor(numgcd/denomgcd));
At 07:41 AM 5/3/2013, Stavros Macrakis wrote:
>For your trivial case, you could always do something like this:
>
>/* Returns a list [ const, m/const ], where const is the GCD of the vector/matrix entries. */
>matrix_constant(m) :=
> block([const, flat, inflag:true],
> if mapatom(m)
> then [1,m]
> elseif member(op(m),["[",op(matrix())])
> then
> (flat: if op(m)="[" then m else apply('append,args(m)),
> const: xreduce('gcd,flat,1),
> [const, m/const] )
> else [1,m])$
>
>This gets its basic behavior from GCD, so there may be some surprising cases:
>
> matrix_constant([a/3,a/2]) => [a/6,[2,3]]
> matrix_constant([a,a/x]) => [a/x,[x,1]]
>
>You can define your own variant of GCD if necessary.
>
> -s
>
>On Fri, May 3, 2013 at 9:30 AM, Henry Baker <hbaker1 at pipeline.com> wrote:
>Is there any way for Maxima to factor 'a' back out of a*M, as below?
>
>Maxima 5.28.0-2 http://maxima.sourceforge.net
>using Lisp GNU Common Lisp (GCL) GCL 2.6.8 (a.k.a. GCL)
>Distributed under the GNU Public License. See the file COPYING.
>Dedicated to the memory of William Schelter.
>The function bug_report() provides bug reporting information.
>(%i1) M:transpose([x,y]);
> [ x ]
>(%o1) [ ]
> [ y ]
>(%i2) a*M;
> [ a x ]
>(%o2) [ ]
> [ a y ]
>(%i3) %,factor;
> [ a x ]
>(%o3) [ ]
> [ a y ]
>(%i4) ????