Subject: code for the transpose of a list of lists.
From: Stavros Macrakis
Date: Mon, 28 Jun 2010 19:17:52 -0400
The Maxima convention is that no functions are destructive except for
explicit component setting (e.g. x:'[a,b,c]$ x[2]:'q$ or m: matrix(...)$
m[2,3]:...).
You could of course make this non-destructive by making a 2-level copy of
the input first. (Or maybe it already does that? I hate the 'loop' macro
and can't read code written with it....)
-s
On Mon, Jun 28, 2010 at 18:22, Pedro Garrido gomez <
perogarridogomez at yahoo.es> wrote:
> This is the code for a version of transpose, this one is destructive, so
> perhaps should be called transpose!.
>
> This version is about seven time faster than the version in maxima list.
>
> Yours sincerely, Pero Garrido
>
>
> (defun transpose(m)
> (let (m1)
> (setq m1 (loop for x on (car m) collect x))
> (transposeaux m)
> m1))
>
> (defun transposeaux(ll)
> (let (next)
> (loop for l1 in ll
> for l2 in (cdr ll) do
> (loop for ai = l1 then next
> for bi on l2 do
> (setf next (cdr ai))
> (rplacd ai bi))
> finally
> (loop for bi = l2 then next
> while (cdr bi) do
> (setf next (cdr bi)
> (cdr bi) nil)))
> ll))
>
> (defmacro tra(m)
> `(setq ,m (transpose ,m)))
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>