List Archives > 
Maple User Group List Archive > 
Archive by date > 
This Month By Date > 
This Month By Topic
[MUG] Rings ...
| [MUG] Rings ... |
|
Author: L C G Rogers
Posted: 14/11/2000 17:48:12 GMT
|
>> From: L C G Rogers
Is there any way in Maple to do symbolic manipulation
without the assumption that a*b=b*a?
-----------------------------------------------------------------------
L C G Rogers, Professor of Probability tel:+44 1225 826224
Department of Mathematical Sciences fax:+44 1225 826492
University of Bath, Bath BA2 7AY, GB
Email: web: www.bath.ac.uk/~maslcgr/home.html
-----------------------------------------------------------------------
|
| [MUG] Re: Rings ... |
|
Author: Maple Group
Posted: 20/11/2000 16:24:00 GMT
|
>> From: Maple Group
| >> From: L C G Rogers
|
| Is there any way in Maple to do symbolic manipulation
| without the assumption that a*b=b*a?
|
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Thu, 16 Nov 2000 11:05:51 +0100
From: Maerivoet Roland
To:
Subject: Rings ...
You could use the matrixoperator &*
Roland Maerivoet
Applied Informatics
Hogeschool Gent
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Thu, 16 Nov 2000 13:01:39 +0000
From: "Dr Francis J. Wright"
To:
Subject: Rings ...
The standard non-commutative multiplication operator is &* (and . in
maple6).
Francis
--
Dr Francis J. Wright | mailto:
School of Mathematical Sciences | tel: (020) 7882 5453 (direct)
Queen Mary, University of London | fax: (020) 8981 9587 (dept.)
Mile End Road, London E1 4NS, UK | http://centaur.maths.qmw.ac.uk/
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
From: Douglas Wilhelm Harder
Subject: Rings ...
To:
Date: Thu, 16 Nov 2000 11:38:15 -0500 (EST)
Hello,
In Maple6, you can use modules to override operators. Here is an example of
a ring of 2x2 matrices module 19 which overrides +, * and -, and it recognizes
the special ring members 0 and 1. Once you have done 'with(Matrix22mod19);',
the call:
> A * B;
is immediately converted to `*`( A, B ) and so there you may decide whether or
not * should be commutative.
> Matrix22mod19 := module()
export `*`, `+`, `-`;
`*` := proc( A::{Matrix(integer), 0, 1}, B::{Matrix(integer), 0, 1} )
local result;
if (member( A, {0, 1} ) or LinearAlgebra[Dimensions]( A ) = (2, 2)) and
(member( B, {0, 1} ) or LinearAlgebra[Dimensions]( B ) = (2, 2)) then
if A = 0 then
0;
elif B = 0 then
0;
elif A = 1 and B = 1 then
1;
elif A = 1 then
LinearAlgebra[Map]( `modp`, B, 19 );
elif B = 1 then
LinearAlgebra[Map]( `modp`, A, 19 );
else
result := Matrix( [[(A[1,1] * B[1,1] + A[1,2] * B[2,1]) mod 19,
(A[1,1] * B[1,2] + A[1,2] * B[2,2]) mod 19],
[(A[1,1] * B[1,1] + A[1,2] * B[2,1]) mod 19,
(A[1,1] * B[1,2] + A[1,2] * B[2,2]) mod 19]] );
if LinearAlgebra[Equal]( result, Matrix([[0,0],[0,0]]) ) then
0;
elif LinearAlgebra[Equal]( result, Matrix([[1,0],[0,1]]) ) then
1;
else
result;
end if;
end if;
else
error "expecting 2 by 2 matrices";
end if;
end proc;
`-` := proc( A::{Matrix(integer), 0, 1} )
local result;
if A = 0 then
0;
elif A = 1 then
Matrix( [[18, 0], [0, 18]] );
elif LinearAlgebra[Dimensions]( A ) = (2, 2) then
result := map( `modp`, map( :-`-`, A ), 19 );
if LinearAlgebra[Equal]( result, Matrix([[0,0],[0,0]]) ) then
0;
elif LinearAlgebra[Equal]( result, Matrix([[1,0],[0,1]]) ) then
1;
else
result;
end if;
else
error "expecting a 2 by 2 matrix";
end if;
end proc;
`+` := proc( A::{Matrix(integer), 0, 1}, B::{Matrix(integer), 0, 1} )
local result;
if (member( A, {0, 1} ) or LinearAlgebra[Dimensions]( A ) = (2, 2)) and
(member( B, {0, 1} ) or LinearAlgebra[Dimensions]( B ) = (2, 2)) then
if A = 0 and B = 0 then
0;
elif A = 1 then
procname( Matrix([[1,0],[0,1]]), B );
elif B = 1 then
procname( A, Matrix([[1,0],[0,1]]) );
elif A = 0 then
LinearAlgebra[Map]( `modp`, B, 19 );
elif B = 0 then
LinearAlgebra[Map]( `modp`, A, 19 );
else
result := Matrix( [[(A[1,1] + B[1,1]) mod 19,
(A[1,2] + B[1,2]) mod 19],
[(A[2,1] + B[2,1]) mod 19,
(A[2,2] + B[2,2]) mod 19]] );
if LinearAlgebra[Equal]( result, Matrix([[0,0],[0,0]]) ) then
0;
elif LinearAlgebra[Equal]( result, Matrix([[1,0],[0,1]]) ) then
1;
else
result;
end if;
end if;
else
error "expecting 2 by 2 matrices";
end if;
end proc;
end module:
So now you can do:
> with(Matrix22mod19);
[*, +, -]
> <<1,5>|<7,3>> + 1; # New short form for entering the new Matrices.
[2 7]
[ ]
[5 4]
> <<1,5>|<7,3>> * 1;
[1 7]
[ ]
[5 3]
> 1 + 1;
[2 0]
[ ]
[0 2]
> <<1,5>|<7,3>> * <<7,2>|<5,2>>;
[2 0]
[ ]
[2 0]
> <<7,2>|<5,2>> * <<1,5>|<7,3>>;
[13 7]
[ ]
[13 7]
> <<1,5>|<7,3>> * <<7,2>|<5,2>> + <<18, 17>|<0, 1>>;
1
> <<7,2>|<5,2>> * <<1,5>|<7,3>> - <<12, 13>|<7, 6>>;
1
> -<<1,5>|<7,3>>;
[18 12]
[ ]
[14 16]
> -1;
[18 0]
[ ]
[ 0 18]
Note that since you have overridden +, -, and *, you can no longer do
very much else:
> -3;
Error, - expects its 1st argument, A, to be of type {0, 1, Matrix(integer)},
but received 3
> 3 + 4;
Error, + expects its 1st argument, A, to be of type {0, 1, Matrix(integer)},
but received 3
so you might want to not just return an error if you get something other
than 0, 1, or a Matrix of type integer.
Hopefully this is somewhat useful.
Cheers,
Douglas
--
Douglas Wilhelm Harder ||\_ _\ /_/\_ _/\_\ /_ _/|| MM BSc MCpl (Retd)
University of Waterloo ||\ _\ /_/\_\ /_ _/
Waterloo Fractal Compression Project _\ / _/||
_/\_\||\_ _/ /_/\_
http://links.uwaterloo.ca/~douglas _/||\_ _/ /_/\
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
From: "Willard, Daniel Dr DUSA-OR"
To:
Subject: Rings ...
Date: Thu, 16 Nov 2000 09:30:23 -0500
In the help section "evalm" (evaluate matrix expressions) you will find the
paragraph:
To indicate non-commutative matrix multiplication, use the operator &*. The
matrix product ABC may be entered as A &* B &* C or as &*(A,B,C), the latter
being more efficient. Automatic simplifications such as collecting constants
and powers will be applied. Do NOT use the * to indicate purely matrix
multiplication, as this will result in an error. The operands of &* must be
matrices (or names) with the exception of 0. Unevaluated matrix products are
considered to be matrices. The operator &* has the same precedence as the *
operator.
|
Previous by date: [MUG] MCMC Example?, David Robinson
Next by date: [MUG] Re: Comments / Documentation, Maple Group
Previous thread: [MUG] neutral operator, Jean-Pierre Douris
Next thread: [MUG] Comments / Documentation, Nathan Sokalski
|