Package for Blockmatrices
- To: mathgroup at smc.vnet.net
- Subject: [mg7725] Package for Blockmatrices
- From: hans.steffani at e-technik.tu-chemnitz.de (Hans Steffani)
- Date: Wed, 2 Jul 1997 14:21:48 -0400 (EDT)
- Organization: University of Technology Chemnitz, FRG
- Sender: owner-wri-mathgroup at wolfram.com
As you maybe saw, I am working on a package which handles symbolik block matrices ie matrices which elements are matrices themselfes. This leads to different behavior of Dot and Transpose which are implemented in the package. The package seems to work but I am not sure whether the simplify functions are optimal concerning calculating time. Trace[] showed me that old versions of the scalars variable are used which may become a problem when calling DotSimplify[] very often. I hope to get some hints but also that the package may be interesting for other mathematica users. Hans Friedrich Steffani --snip--snap--begin of block.m--snip--snap-- (* block.m Handles the dot product of symbolik block matrix. This means that the elements of a matrix are not skalars but matrices. eg: (A11 A12) (B11 B12) (A11.B11+A12.B21 A11.B12+A12.B22) ( ) ( ) = ( ) (A21 A22) (B21 B22) (A21.B11+A22.B21 A21.B12+A22.B22) using the dot product on the right hand side instead of the normal times. Also Transpose[] has been enhaced because not only the blockmatrix itsself but also its elements have to be transposed. Hans Friedrich Steffani *) BeginPackage["Utilities`Block`"] DotSimplify::usage = "DotSimplify[expr, Skalar->{list of scalars}] replaces Dot[a,b] by Times[a,b] if a or b are in the list of scalars" SymmetricSimplify::usage = "SymmetricSimplify[expr, Symmetric->{list of symmetric values}] replaces Transpose[a] if a is in the list of symmetric values" Unprotect[Transpose] (* To Transpose the matrix all Elements get transposed and the matrix itself too *) Transpose[m_?MatrixQ] := Transpose[Map[Transpose, m,{2}], {2,1}] Transpose[m_?NumberQ] := m Transpose[Transpose[expr_]] := expr Protect[Transpose] Unprotect[Dot] Dot[a_?MatrixQ, b_?MatrixQ] := Inner[Dot, a, b, Plus] Dot[a_?NumberQ, b_] := Times[a, b] Dot[a_, b_?NumberQ] := Times[a, b] Protect[Dot] Begin["`Private`"] SkalarOptionQ[opt_]:=False SkalarOptionQ[(opt_?OptionQ)?ListQ]:= MemberQ[Transpose[opt/.Rule->List][[1]], Skalar] SkalarOptionQ[opt_?OptionQ] := TrueQ[opt[[1]] == Skalar] SymmetricOptionQ[opt_]:=False SymmetricOptionQ[(opt_?OptionQ)?ListQ]:= MemberQ[Transpose[opt/.Rule->List][[1]], Symmetric] SymmetricOptionQ[opt_?OptionQ] := TrueQ[opt[[1]] == Symmetric] End (* Private *) DotSimplify[expr_, opt_?SkalarOptionQ] := Module[{skalars}, skalars=opt[[2]]; Unprotect[mydot]; Clear[mydot]; mydot[m1_/; (MemberQ[skalars,m1]), m2_ ] := Times[m1,m2] ; mydot[m1_, m2_/; (MemberQ[skalars,m2]) ] := Times[m1,m2] ; SetAttributes[ mydot,{Flat,OneIdentity} ]; Protect[mydot]; mytranspose[ m_/; (MemberQ[skalars,m]) ] := m; expr/.{Dot->mydot,Transpose->mytranspose}/.{mydot->Dot,mytranspose->Transpose} ] SymmetricSimplify[expr_, opt_?SymmetricOptionQ]:= Module[{}, Clear[mytranspose]; mytranspose[ m_/;(MemberQ[ opt[[2]], m]) ] := m; expr/.{Transpose->mytranspose}/.{mytranspose->Transpose} ] Unprotect[Simplify] Protect[Simplify] EndPackage[] --snip--snap--end of block.m--snip--snap-- -- Hans Friedrich Steffani Institut fuer Elektrische Maschinen und Antriebe, TU Chemnitz-Zwickau mailto:hans.steffani at e-technik.tu-chemnitz.de http://www.tu-chemnitz.de/~hfst/