linear algebra question, also gcdex



William Schelter wrote:

> 3)  To turn a matrix into a simple list of all the entries, with first row then
> second row etc.. you could do:
> 
> ListMatrixEntries(m):=block([ans:[]],
>        for v in m do ans:append(ans,v),
>        ans);
> 
> ListMatrixEntries(matrix([a,b],[c,d]))==>[a,b,c,d]
> ListMatrixEntries(transpose([a,b,c])) ==> [a,b,c]

I suggest: 

   ListMatrixEntries (M):=  apply (append, substinpart("[",M,0))$

in lisp,
  (defun $LIST_MATRIX_ENTRIES (m)... (apply #'append (cdr v))  instead
of sloop...

> 
> In lisp to define the same thing you could do
> (defun $LIST_MATRIX_ENTRIES (m)
>    (or ($matrixp m) (error "not a matrix"))
>    (cons '(mlist) (sloop for v in (cdr m) append (cdr v))))
> 

In the diophantine equation gcdex example, I think there
are a couple of ways of improving it.

Thesize of the program can be reduced by using multiple assignment
syntax (a secret? in macsyma).
 [a,b,c]:[1,2,3]  assigns a:1, b:2, c:3.

 [quo,rem]: divide(p,q,x)  sets the quotient and remainder [main var x]

 I usually set the original inputs into rat form, making
it unnecessary to call ratsimp along the way.  It should
be possible to copy the gcdex out of Knuth vol 1, but
I'm away from my library right now.

It should be possible to do the computation even if the
two inputs are not univariate, by choosing to do the
computations in the quotient field of the other variables.
thus the call could be gcdex(u,v,x), where x is also used
in the call to divide.

The various options here are probably what made people
nervous about including the program as a user command.

The commercial Macsyma (or formerly commercial?)
has this program:

XTGCD(poly_or_integer, poly_or_integer)

[ALGFUNCS package] Computes the extended Euclidean algorithm for the
integers and/or univariate polynomials with integer coefficients.
Returns the list [p(x), a(x), b(x)] where q(x) and r(x) are the
arguments to EXTGCD, p(x) is their g.c.d., and a(x) and b(x) satisfy
Bezout's identity

 p(x) = a(x)*q(x) + b(x)*r(x) .

Do EXAMPLE(EXTGCD); for an executable example. 

See also EXTGCD_INTEGER.

The EXTGCD code follows the design in 

 J.H. Davenport, Y. Siret, and E. Tournier
 Computer Algebra: Systems and algorithms for algebraic computation
 Academic Press (1988), pp. 213-214 

even down to the names used.

 

RJF