I have a little annoyance with the mod function. As you know mod(x,p):
is defined as an integer <k> in
`[-(<p>-1)/2, ..., 0, ..., (<p>-1)/2]' when <p> is odd, or
`[-(<p>/2 - 1), ..., 0, ...., <p>/2]' when <p> is even, such that
`<a> <p> + <k>' equals <n> for some integer <a>
This seems to me to be non-standard; more generally mod(x,n) is defined do
be in the range 0.. n-1. Now, I can use ?mod to do this, except that ?mod
doesn't apply to matrices in the same way mod does:
--
(%i19) M:genmatrix(lambda([i,j],random(100)),3,3);
[ 60 71 12 ]
[ ]
(%o19) [ 9 29 18 ]
[ ]
[ 26 95 53 ]
(%i20) mod(M,10);
[ 0 1 2 ]
[ ]
(%o20) [ - 1 - 1 - 2 ]
[ ]
[ - 4 5 3 ]
(%i21) ?mod(M, 10);
Maxima encountered a Lisp error:
MOD: (($MATRIX SIMP) ((MLIST SIMP) 60 71 12) ((MLIST SIMP) 9 29 18)
((MLIST SIMP) 26 95 53)) is not a REAL
Automatically continuing.
To reenable the Lisp debugger set *debugger-hook* to nil.
(%i22) matrixmap(lambda([x],?mod(x,10)),M);
[ 0 1 2 ]
[ ]
(%o22) [ 9 9 8 ]
[ ]
[ 6 5 3 ]
--
Is there any way of coercing map or ?map to produce the last answer without
having to fiddle with matrixmap and lambda definitions?
Thanks,
Alasdair