login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Edit detail for SandBoxTensorProduct revision 4 of 9

1 2 3 4 5 6 7 8 9
Editor: Bill Page
Time: 2009/05/12 13:35:17 GMT-7
Note: tensor product axioms

added:
Demonstrating the axioms of the tensor product:
\begin{axiom}
x:M
y:M
u:M
p:=2*x+3*u
q:=5*x+7*y+11*u
MxM:=TensorProduct(Integer,Symbol,Symbol,M,M);
r:=product(p,q)$MxM
w:= 13*y+17*y+19*u
test( product(p+q,w)$MxM = product(p,w)$MxM + product(q,w)$MxM )
test( product(p,q+w)$MxM = product(p,q)$MxM + product(p,w)$MxM )
test( product(p,23*w)$MxM = 23*product(p,w)$MxM )
test( product(23*p,w)$MxM = 23*product(p,w)$MxM )
\end{axiom}

On Date: Thu, 14 May 2009 21:46:06 +0200 Franz Lehner wrote:

Attached is a prototype for tensor products. It is free modules over commutative rings. There seems to be some confusion with free modules.

FreeModule? is defined in poly.spad with a local category. FreeModuleCat? is defined in xpoly.spad. FreeModule1? is of category FreeModuleCat?, its Rep however is FreeModule?.

spad
)abbrev category TENSORC TensorProductCategory
TensorProductCategory(R:CommutativeRing, M : Module(R), N : Module(R)):Category == Module(R) with
    product: (M, N) -> %
)abbrev category TENSORP TensorProductProperty TensorProductProperty(R:CommutativeRing, M : Module(R), N : Module(R), _ MxN : TensorProductCategory(R, M, N), S : Module(R)): Category == with eval: (MxN, (M, N) -> S) -> S
)abbrev package TENSORD TensorProduct TensorProduct(R:CommutativeRing, B1:SetCategory, B2:SetCategory,M1:FreeModuleCat(R,B1),M2:FreeModuleCat(R,B2)): TPcat == TPimp where TPcat == Join(TensorProductCategory(R,M1,M2),FreeModuleCat(R,Product(B1,B2))) TERM1 == Record(k: B1, c: R) TERM2 == Record(k: B2, c: R) B1xB2 == Product(B1,B2) TERM == Record(k: B1xB2, c: R) TPimp == FreeModule1(R,Product(M1,M2)) add -- Representation -- Rep == FreeModule1(R,Product(M1,M2)) Rep == List TERM import Rep, TERM1, TERM2, TERM, B1xB2
-- One should expect the following 3 functions to be inherited from FreeModule1 -- but there are problems if these are omitted. outTerm(r:R, s:B1xB2):OutputForm == r=1 => s::OutputForm r::OutputForm * s::OutputForm coerce(a:%):OutputForm == empty? (a pretend Rep) => (0$R)::OutputForm reduce(_+, reverse_! [outTerm(t.c, t.k) for t in (a pretend Rep)])$List(OutputForm) leadingMonomial(x:%):B1xB2 == (x pretend Rep).first.k
product(x1:M1,x2:M2):% == zero? x1 or zero? x2 => return 0 x1l:List TERM1 := ListOfTerms x1 x2l:List TERM2 := ListOfTerms x2 res:List Rep := [[[makeprod(s1.k,s2.k),s1.c*s2.c ] for s2 in x2l] for s1 in x1l] (reduce(concat,res)) pretend %
spad
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/4415200928774662710-25px001.spad using 
      old system compiler.
   TENSORC abbreviates category TensorProductCategory 
------------------------------------------------------------------------
   initializing NRLIB TENSORC for TensorProductCategory 
   compiling into NRLIB TENSORC 
;;; *** |TensorProductCategory| REDEFINED Time: 0 SEC.
finalizing NRLIB TENSORC Processing TensorProductCategory for Browser database: --->-->TensorProductCategory((product (% M N))): Not documented!!!! --->-->TensorProductCategory(constructor): Not documented!!!! --->-->TensorProductCategory(): Missing Description ------------------------------------------------------------------------ TensorProductCategory is now explicitly exposed in frame initial TensorProductCategory will be automatically loaded when needed from /var/zope2/var/LatexWiki/TENSORC.NRLIB/code
TENSORP abbreviates category TensorProductProperty ------------------------------------------------------------------------ initializing NRLIB TENSORP for TensorProductProperty compiling into NRLIB TENSORP
;;; *** |TensorProductProperty| REDEFINED Time: 0 SEC.
finalizing NRLIB TENSORP Processing TensorProductProperty for Browser database: --->-->TensorProductProperty((eval (S MxN (Mapping S M N)))): Not documented!!!! --->-->TensorProductProperty(constructor): Not documented!!!! --->-->TensorProductProperty(): Missing Description ------------------------------------------------------------------------ TensorProductProperty is now explicitly exposed in frame initial TensorProductProperty will be automatically loaded when needed from /var/zope2/var/LatexWiki/TENSORP.NRLIB/code
TENSORD abbreviates package TensorProduct ------------------------------------------------------------------------ initializing NRLIB TENSORD for TensorProduct compiling into NRLIB TENSORD importing List Record(k: Product(B1,B2),c: R) importing Record(k: B1,c: R) importing Record(k: B2,c: R) importing Record(k: Product(B1,B2),c: R) importing Product(B1,B2) compiling local outTerm : (R,Product(B1,B2)) -> OutputForm Time: 0.03 SEC.
compiling exported coerce : $ -> OutputForm Time: 0.07 SEC.
compiling exported leadingMonomial : $ -> Product(B1,B2) Time: 0 SEC.
compiling exported product : (M1,M2) -> $ Time: 0.11 SEC.
(time taken in buildFunctor: 0)
;;; *** |TensorProduct| REDEFINED
;;; *** |TensorProduct| REDEFINED Time: 0 SEC.
Warnings: [1] not known that (OrderedSet) is of mode (CATEGORY domain (IF (has M1 (Finite)) (IF (has M2 (Finite)) (ATTRIBUTE (Finite)) noBranch) noBranch) (IF (has M1 (Monoid)) (IF (has M2 (Monoid)) (ATTRIBUTE (Monoid)) noBranch) noBranch) (IF (has M1 (AbelianMonoid)) (IF (has M2 (AbelianMonoid)) (ATTRIBUTE (AbelianMonoid)) noBranch) noBranch) (IF (has M1 (CancellationAbelianMonoid)) (IF (has M2 (CancellationAbelianMonoid)) (ATTRIBUTE (CancellationAbelianMonoid)) noBranch) noBranch) (IF (has M1 (Group)) (IF (has M2 (Group)) (ATTRIBUTE (Group)) noBranch) noBranch) (IF (has M1 (AbelianGroup)) (IF (has M2 (AbelianGroup)) (ATTRIBUTE (AbelianGroup)) noBranch) noBranch) (IF (has M1 (OrderedAbelianMonoidSup)) (IF (has M2 (OrderedAbelianMonoidSup)) (ATTRIBUTE (OrderedAbelianMonoidSup)) noBranch) noBranch) (IF (has M1 (OrderedSet)) (IF (has M2 (OrderedSet)) (ATTRIBUTE (OrderedSet)) noBranch) noBranch) (SIGNATURE makeprod ($ M1 M2)) (SIGNATURE selectfirst (M1 $)) (SIGNATURE selectsecond (M2 $)))
Cumulative Statistics for Constructor TensorProduct Time: 0.21 seconds
--------------non extending category---------------------- .. TensorProduct(#1,#2,#3,#4,#5) of cat (|Join| (|TensorProductCategory| |#1| |#4| |#5|) (|FreeModuleCat| |#1| (|Product| |#2| |#3|))) has no (|FreeModuleCat| |#1| (|Product| |#4| |#5|)) finalizing NRLIB TENSORD Processing TensorProduct for Browser database: --->-->TensorProduct(): Missing Description ------------------------------------------------------------------------ TensorProduct is now explicitly exposed in frame initial TensorProduct will be automatically loaded when needed from /var/zope2/var/LatexWiki/TENSORD.NRLIB/code

axiom
M:=FreeModule1(Integer,Symbol)
LatexWiki Image(1)
Type: Domain
axiom
N:=FreeModule1(Integer,Symbol)
LatexWiki Image(2)
Type: Domain
axiom
a1:='a1::M
LatexWiki Image(3)
Type: FreeModule1?(Integer,Symbol)
axiom
a2:='a2::M
LatexWiki Image(4)
Type: FreeModule1?(Integer,Symbol)
axiom
b1:='b1::N
LatexWiki Image(5)
Type: FreeModule1?(Integer,Symbol)
axiom
b2:='b2::N
LatexWiki Image(6)
Type: FreeModule1?(Integer,Symbol)
axiom
MxN:=TensorProduct(Integer,Symbol,Symbol,M,N);
Type: Domain
axiom
t:=product(a1+a2,b1+b2)$MxN;
Type: TensorProduct?(Integer,Symbol,Symbol,FreeModule1?(Integer,Symbol),FreeModule1?(Integer,Symbol))
axiom
t
LatexWiki Image(7)
Type: TensorProduct?(Integer,Symbol,Symbol,FreeModule1?(Integer,Symbol),FreeModule1?(Integer,Symbol))

The code seems to work partially, at least elements are created, but most of the other functions are not accessible. Eq:

axiom
leadingMonomial t
LatexWiki Image(8)
Type: Product(Symbol,Symbol)

axiom
numberOfMonomials t
LatexWiki Image(9)
Type: PositiveInteger?

The last output shows that t was really created and the above errors are due to malfunction of the inheritance mechanism.

Questions:

  1. The missing functions are probably due to the mixup of categories. Why does the compiler not complain?
  2. Is there a way to extract the basis automatically from FreeModule?? Typing TensorProduct?(R,B1,B2,M,N) every time is tedious. That would need functions returning domains I guess.
  3. Is it difficult to implement a rep/per mechanism? The current magic is rather mysterious, moreover the error messages of the compiler are somewhat cryptic. I had a hard time interpreting the message:
         >> Apparent user error:
             NoValueMode
                 is an unknown mode
    
       before I split::
    
         reduce(concat,[[[makeprod(s1.k,s2.k),s1.c*s2.c ]@TERM for s2 in x2l] for s1 in x1l]) pretend %
    
       into two lines::
    
         res:List Rep := [[[makeprod(s1.k,s2.k),s1.c*s2.c ]@TERM for s2 in x2l] for s1 in x1l]
         (reduce(concat,res)) pretend %
    
  4. After TensorProduct? ... == FreeModule1?(R,Product(M1,M2)) add ..., is it better to use:
         Rep == FreeModule1(R,Product(M1,M2)) 
    
       or rather::
    
         Rep == List TERM 
    
       as I did?
    

On Date: Fri, 15 May 2009 03:23:33 +0200 (CEST) Waldek Hebisch wrote:

The following seem to work OK:

axiom
)clear completely
All user variables and function definitions have been cleared. All )browse facility databases have been cleared. Internally cached functions and constructors have been cleared. )clear completely is finished.

spad
)abbrev package TENSORD TensorProduct
TensorProduct(R : CommutativeRing, B1 : OrderedSet, B2 : OrderedSet, _
    M1 : FreeModuleCat(R, B1), M2 : FreeModuleCat(R, B2)): TPcat == TPimp where 
    TPcat == Join(TensorProductCategory(R,M1,M2),FreeModuleCat(R,Product(B1,B2))) 
    TERM1 == Record(k: B1, c: R)
    TERM2 == Record(k: B2, c: R)
    B1xB2 == Product(B1,B2)
    TERM  == Record(k: B1xB2, c: R)
    TPimp == FreeModule1(R, Product(B1, B2)) add 
       import Rep, TERM1, TERM2, TERM, B1xB2
product(x1:M1,x2:M2):% == zero? x1 or zero? x2 => return 0 x1l:List TERM1 := ListOfTerms x1 x2l:List TERM2 := ListOfTerms x2 res : % := 0 for s1 in x1l repeat for s2 in x2l repeat res := res + monom(makeprod(s1.k, s2.k), s1.c*s2.c) res
spad
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/9103743063781848243-25px006.spad using 
      old system compiler.
   Illegal NRLIB 
   TENSORD.NRLIB claims that its constructor name is the package 
      TensorProduct but TensorProduct is already known to be the for 
      domain TENSORD .
   TENSORD abbreviates package TensorProduct 
------------------------------------------------------------------------
   initializing NRLIB TENSORD for TensorProduct 
   compiling into NRLIB TENSORD 
   importing Rep
   importing Record(k: B1,c: R)
   importing Record(k: B2,c: R)
   importing Record(k: Product(B1,B2),c: R)
   importing Product(B1,B2)
   compiling exported product : (M1,M2) -> $
Time: 0.03 SEC.
(time taken in buildFunctor: 0)
;;; *** |TensorProduct| REDEFINED
;;; *** |TensorProduct| REDEFINED Time: 0 SEC.
Warnings: [1] not known that (OrderedSet) is of mode (CATEGORY domain (IF (has B1 (Finite)) (IF (has B2 (Finite)) (ATTRIBUTE (Finite)) noBranch) noBranch) (IF (has B1 (Monoid)) (IF (has B2 (Monoid)) (ATTRIBUTE (Monoid)) noBranch) noBranch) (IF (has B1 (AbelianMonoid)) (IF (has B2 (AbelianMonoid)) (ATTRIBUTE (AbelianMonoid)) noBranch) noBranch) (IF (has B1 (CancellationAbelianMonoid)) (IF (has B2 (CancellationAbelianMonoid)) (ATTRIBUTE (CancellationAbelianMonoid)) noBranch) noBranch) (IF (has B1 (Group)) (IF (has B2 (Group)) (ATTRIBUTE (Group)) noBranch) noBranch) (IF (has B1 (AbelianGroup)) (IF (has B2 (AbelianGroup)) (ATTRIBUTE (AbelianGroup)) noBranch) noBranch) (IF (has B1 (OrderedAbelianMonoidSup)) (IF (has B2 (OrderedAbelianMonoidSup)) (ATTRIBUTE (OrderedAbelianMonoidSup)) noBranch) noBranch) (IF (has B1 (OrderedSet)) (IF (has B2 (OrderedSet)) (ATTRIBUTE (OrderedSet)) noBranch) noBranch) (SIGNATURE makeprod ($ B1 B2)) (SIGNATURE selectfirst (B1 $)) (SIGNATURE selectsecond (B2 $)))
Cumulative Statistics for Constructor TensorProduct Time: 0.03 seconds
--------------non extending category---------------------- .. TensorProduct(#1,#2,#3,#4,#5) of cat (|Join| (|TensorProductCategory| |#1| |#4| |#5|) (|FreeModuleCat| |#1| (|Product| |#2| |#3|))) has no ?*? : (Product(#2,#3),#1) -> % finalizing NRLIB TENSORD Processing TensorProduct for Browser database: --->/var/zope2/var/LatexWiki/4415200928774662710-25px001.spad-->TensorProduct(): Missing Description ------------------------------------------------------------------------ TensorProduct is now explicitly exposed in frame initial TensorProduct will be automatically loaded when needed from /var/zope2/var/LatexWiki/TENSORD.NRLIB/code

Note that both B1 and B2 is required to be OrderedSet?, and I use just FreeModule1?(R, Product(B1, B2))

Note that the version I wrote does not use pretend. My version may be quite slow -- if this is a problem than one can build a list using cons and add pretend. However, list must be created in correct order, otherwise functions from FreeMonoid? would work incorrectly.

axiom
M:=FreeModule1(Integer,Symbol)
LatexWiki Image(10)
Type: Domain
axiom
N:=FreeModule1(Integer,Symbol)
LatexWiki Image(11)
Type: Domain
axiom
a1:='a1::M
LatexWiki Image(12)
Type: FreeModule1?(Integer,Symbol)
axiom
a2:='a2::M
LatexWiki Image(13)
Type: FreeModule1?(Integer,Symbol)
axiom
b1:='b1::N
LatexWiki Image(14)
Type: FreeModule1?(Integer,Symbol)
axiom
b2:='b2::N
LatexWiki Image(15)
Type: FreeModule1?(Integer,Symbol)
axiom
MxN:=TensorProduct(Integer,Symbol,Symbol,M,N);
Type: Domain
axiom
t:=product(2*a1+3*a2,5*b1+7*b2)$MxN;
Type: TensorProduct?(Integer,Symbol,Symbol,FreeModule1?(Integer,Symbol),FreeModule1?(Integer,Symbol))
axiom
t
LatexWiki Image(16)
Type: TensorProduct?(Integer,Symbol,Symbol,FreeModule1?(Integer,Symbol),FreeModule1?(Integer,Symbol))
axiom
leadingMonomial t
LatexWiki Image(17)
Type: Product(Symbol,Symbol)
axiom
numberOfMonomials t
LatexWiki Image(18)
Type: PositiveInteger?

Demonstrating the axioms of the tensor product:

axiom
x:M
Type: Void
axiom
y:M
Type: Void
axiom
u:M
Type: Void
axiom
p:=2*x+3*u
LatexWiki Image(19)
Type: FreeModule1?(Integer,Symbol)
axiom
q:=5*x+7*y+11*u
LatexWiki Image(20)
Type: FreeModule1?(Integer,Symbol)
axiom
MxM:=TensorProduct(Integer,Symbol,Symbol,M,M);
Type: Domain
axiom
r:=product(p,q)$MxM
LatexWiki Image(21)
Type: TensorProduct?(Integer,Symbol,Symbol,FreeModule1?(Integer,Symbol),FreeModule1?(Integer,Symbol))
axiom
w:= 13*y+17*y+19*u
LatexWiki Image(22)
Type: FreeModule1?(Integer,Symbol)
axiom
test( product(p+q,w)$MxM = product(p,w)$MxM + product(q,w)$MxM )
LatexWiki Image(23)
Type: Boolean
axiom
test( product(p,q+w)$MxM = product(p,q)$MxM + product(p,w)$MxM )
LatexWiki Image(24)
Type: Boolean
axiom
test( product(p,23*w)$MxM = 23*product(p,w)$MxM )
LatexWiki Image(25)
Type: Boolean
axiom
test( product(23*p,w)$MxM = 23*product(p,w)$MxM )
LatexWiki Image(26)
Type: Boolean