# [Maxima] Two questions

Barton Willis willisb at unk.edu
Mon Jul 12 12:07:32 CDT 2010

```-----maxima-bounces at math.utexas.edu wrote: -----

>I checked also that when I write:
>eq: transpose(A . B . C);
>I obtain as expected
>    transpose(C) . transpose(B) . transpose(A)
>
>Is this possible to do it in back, e.g.:
>eq1: transpose(C) . transpose(B) . transpose(A)
>and get: transpose(A . B . C)

Pattern matching is a popular way to do such things. An alternative is to
substitute a
function for "."; for example:

(%i1) transpose_p(x) := not mapatom(x) and op(x)=nounify('transpose)\$

(%i2) transpose_dot(e) := subst("." = lambda([[s]], if
every('transpose_p, s) then 'transpose(xreduce(".",   reverse(map('first,
s)))) else funmake(".", s)),e)\$

(%i4) transpose_dot(transpose(a) . transpose(b) - %pi);
(%o4) transpose(b . a)-%pi

(%i5) transpose_dot(42*transpose(a) . transpose(b) . transpose(c)- %pi);
(%o5) 42*transpose(c . b . a)-%pi

Quoting transpose might help with some expressions:

(%i6) transpose_dot(42*transpose(a) . transpose(b) . 'transpose(c + d)-
%pi);
(%o6) 42*transpose((d+c) . b . a)-%pi

This code doesn't handle expressions such as

(%i10) transpose_dot(a.b . transpose(p) . transpose(q));
(%o10) a . b . transpose(p) . transpose(q)

Similarly, you can make a substitution on "+" that does transpose(a) +
transpose(b) --> transpose(a+b).

The built-in simplifications for transpose expressions cannot be turned
off, so I'd guess that
the function transpose_dot will not work all that well--whenever an
expression is (re-)evaluated, whatever
work transpose_dot did will be reversed.

--Barton

```