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

Edit detail for SandBoxTensorProduct revision 1 of 9

1 2 3 4 5 6 7 8 9
Editor: Bill Page
Time: 2009/05/12 12:47:09 GMT-7
Note: Franz Lehner

changed:
-
**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.

\begin{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 %
\end{spad}

\begin{axiom}
M:=FreeModule1(Integer,Symbol)
N:=FreeModule1(Integer,Symbol)
a1:='a1::M
a2:='a2::M
b1:='b1::N
b2:='b2::N
MxN:=TensorProduct(Integer,Symbol,Symbol,M,N);
t:=product(a1+a2,b1+b2)$MxN;
t
\end{axiom}
The code seems to work partially, at least elements are created,
but most of the other functions are not accessible. Eq:

\begin{axiom}
leadingMonomial t
\end{axiom}

\begin{axiom}
numberOfMonomials t
\end{axiom}

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: 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?.

fricas
(1) -> <spad>
fricas
)abbrev category TENSORC TensorProductCategory
TensorProductCategory(R:CommutativeRing, M : Module(R), N : Module(R)):Category == Module(R) with
    product: (M, N) -> %
fricas
)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
fricas
)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>
fricas
Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/4415200928774662710-25px001.spad
      using 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: --->/usr/local/lib/fricas/target/x86_64-linux-gnu/../../src/algebra/TENSCAT.spad-->TensorProductCategory(constructor): Not documented!!!! --->/usr/local/lib/fricas/target/x86_64-linux-gnu/../../src/algebra/TENSCAT.spad-->TensorProductCategory((product (% M N))): Not documented!!!! --->/usr/local/lib/fricas/target/x86_64-linux-gnu/../../src/algebra/TENSCAT.spad-->TensorProductCategory: Missing Description ; compiling file "/var/aw/var/LatexWiki/TENSORC.NRLIB/TENSORC.lsp" (written 22 OCT 2026 02:42:30 PM):
; wrote /var/aw/var/LatexWiki/TENSORC.NRLIB/TENSORC.fasl ; compilation finished in 0:00:00.004 ------------------------------------------------------------------------ TensorProductCategory is now explicitly exposed in frame initial TensorProductCategory will be automatically loaded when needed from /var/aw/var/LatexWiki/TENSORC.NRLIB/TENSORC
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: --->/usr/local/lib/fricas/target/x86_64-linux-gnu/../../src/algebra/TENSPRP.spad-->TensorProductProperty(constructor): Not documented!!!! --->/usr/local/lib/fricas/target/x86_64-linux-gnu/../../src/algebra/TENSPRP.spad-->TensorProductProperty((eval (S MxN (Mapping S M N)))): Not documented!!!! --->/usr/local/lib/fricas/target/x86_64-linux-gnu/../../src/algebra/TENSPRP.spad-->TensorProductProperty: Missing Description ; compiling file "/var/aw/var/LatexWiki/TENSORP.NRLIB/TENSORP.lsp" (written 22 OCT 2026 02:42:30 PM):
; wrote /var/aw/var/LatexWiki/TENSORP.NRLIB/TENSORP.fasl ; compilation finished in 0:00:00.004 ------------------------------------------------------------------------ TensorProductProperty is now explicitly exposed in frame initial TensorProductProperty will be automatically loaded when needed from /var/aw/var/LatexWiki/TENSORP.NRLIB/TENSORP
TENSORD abbreviates package TensorProduct ------------------------------------------------------------------------ initializing NRLIB TENSORD for TensorProduct compiling into NRLIB TENSORD Semantic Errors: [1] FreeModuleCat is not a known type
Warnings: [1] FreeModuleCat has no value
****** comp fails at level 1 with expression: ****** ((|FreeModuleCat| R (|Product| B1 B2))) ****** level 1 ****** x:= (FreeModuleCat R (Product B1 B2)) m:= $EmptyMode f:= ((((M2 # #) (M1 # #) (B2 # #) (B1 # #) ...)))
>> Apparent user error: cannot compile (FreeModuleCat R (Product B1 B2))

fricas
M:=FreeModule1(Integer,Symbol)
There are no library operations named FreeModule1 Use HyperDoc Browse or issue )what op FreeModule1 to learn if there is any operation containing " FreeModule1 " in its name.
Cannot find a definition or applicable library operation named FreeModule1 with argument type(s) Type Type
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

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

fricas
leadingMonomial t
There are 1 exposed and 3 unexposed library operations named leadingMonomial having 1 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op leadingMonomial to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation.
Cannot find a definition or applicable library operation named leadingMonomial with argument type(s) Variable(t)
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

fricas
numberOfMonomials t

\label{eq1}1(1)
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?