On Thu, Jul 09, 2009 at 04:04:05PM +0200, Waldek Hebisch wrote:
> AFAICS this is compiler bug.  Compiler got confused and compiling
> * in CCRAlgebra wants FreeModule(R, $) -- it should use
> FreeModule(R, CCRBasis(R)).
ok, that's a relief. I spent some time on this and couldn't figure out
the problem. With Martin's suggestion it sort of works:
********************************************************************
(1) -> CCR:=CCRAlgebra(Complex Expression Integer,h/%i)

   (1)  CCRAlgebra(Complex(Expression(Integer)),(-h)*%i)
                                                                 Type: Domain
(2) -> Q1:=position(1)$CCR

   (2)  Q
         1
                       Type: CCRAlgebra(Complex(Expression(Integer)),(-h)*)
(3) -> Q2:=position(2)$CCR

   (3)  Q
         2
                       Type: CCRAlgebra(Complex(Expression(Integer)),(-h)*)
(4) -> P1:=momentum(1)$CCR

   (4)  P
         1
                       Type: CCRAlgebra(Complex(Expression(Integer)),(-h)*)
(5) -> P2:=momentum(2)$CCR

   (5)  P
         2
                       Type: CCRAlgebra(Complex(Expression(Integer)),(-h)*)
(6) -> P1*Q1

   (6)  Q P  - h %i 1
         1 1
                       Type: CCRAlgebra(Complex(Expression(Integer)),(-h)*)
(7) -> P1*Q2

   (7)  Q P
         2 1
                       Type: CCRAlgebra(Complex(Expression(Integer)),(-h)*)

(8) -> P1^2*Q1^3
 

          3  2           2       2
   (8)  Q  P   - 6h %i Q  P  - 6h Q
         1  1           1  1       1
                       Type: CCRAlgebra(Complex(Expression(Integer)),(-h)*)
********************************************************************

The multiplication can probably be optimized.
AlgebraWithBasis can be used for other algebras like this.
Suggestions for a better name?

best regards,
Franz

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/fricas-devel?hl=en
-~----------~----~----~----~------~----~------~--~---

\documentclass{article}
\usepackage{axiom,amsthm,amsmath,url}
\newtheorem{ToDo}{ToDo}[section]

\newcommand{\Axiom}{{\tt Axiom}}


\begin{document}
\title{CCR algebra}
\author{Franz Lehner}
\maketitle

\tableofcontents

\section{category ALGBAS AlgebraBasis}
<<category ALGBAS AlgebraBasis>>=
)abbrev category ALGBAS AlgebraBasis
++ Author: Franz Lehner <[email protected]>
++ Date Created: 2009
++ Date Last Updated: July 2009
++ Fix History: 
++ Basic Functions:
++ Related Constructors:
++ Also See:
++ AMS Classifications:
++ Keywords:
++ References:
++ Description:
++   An algebra basis is an ordered set with multiplication 
++   such that a product of two basis elements is a finite
++   linear combination of other basis elements (i.e., an element
++   of the free module over the basis).
++   This is used in AlgebraWithBasis.
AlgebraBasis(R:Ring):Category == C where
    C ==> OrderedSet with
        _*:(%,%) -> FreeModule(R,%)
        ++ \spad{x*y} returns the product as an element of 
        ++ the free module spanned by the basis.
@
\section{category ALGWBC AlgebraWithBasisCategory}
<<category ALGWBC AlgebraWithBasisCategory>>=
)abbrev category ALGWBC AlgebraWithBasisCategory
++ Author: Franz Lehner <[email protected]>
++ Date Created: 2009
++ Date Last Updated: July 2009
++ Fix History: 
++ Basic Functions:
++ Related Constructors:
++ Also See:
++ AMS Classifications:
++ Keywords:
++ References:
++ Description:
++   A category for algebras which are given by generators and
++   a multiplication rule.
AlgebraWithBasisCategory(R:CommutativeRing,B:AlgebraBasis(R)):Category ==
    Join(Algebra(R),FreeModuleCategory(R,B),OrderedSet)
@ 
Note: [[OrderedSet]] is needed here because of a compiler bug.
The compiler gets confused with [[*:(B,B)->FreeModule(R,%)]].

\section{domain ALGWB AlgebraWithBasis}
<<domain ALGWB AlgebraWithBasis>>=
)abbrev domain ALGWB AlgebraWithBasis
++ Author: Franz Lehner <[email protected]>
++ Date Created: 2009
++ Date Last Updated: July 2009
++ Fix History: 
++ Basic Functions:
++ Related Constructors:
++ Also See:
++ AMS Classifications:
++ Keywords:
++ References:
++ Description:
++   A domain for algebras which are given by a basis and
++   a multiplication rule which multiplies two basis elements
++   into a linear combination of basis elements.
AlgebraWithBasis(R:CommutativeRing,B:AlgebraBasis(R)):Public == Private where
    Public ==> AlgebraWithBasisCategory(R,B)
    TERM ==> Record(k:B, c:R)
    Private ==> FreeModule(R,B) add
        Rep := FreeModule(R,B)
        x,y:%
        x1,y1:TERM
        
        _*(x,y):% ==
            zero? x or zero? y => 0
            res := 0
            for x1 in listOfTerms x repeat
                for y1 in listOfTerms y repeat
                    res:= res + (x1 c * y1 c) * (x1 k * y1 k)
            res
@ 
<<example.input>>=
R:=Expression Integer
QB:=CCRBasis(R,h)
CCR:=AlgebraWithBasis(Expression Integer, QB)

Q1:=position(1)$QB
Q2:=position(2)$QB
P1:=momentum(1)$QB
P2:=momentum(2)$QB
Q:=leadingSupport (Q1*Q2)

Q1a:=monomial(1,Q1)$CCR
Q2a:=monomial(1,Q2)$CCR
P1a:=monomial(1,P1)$CCR
P2a:=monomial(1,P2)$CCR
@
\section{domain INDVAR IndexedVariable}
<<domain INDVAR IndexedVariable>>=
)abbrev domain INDVAR IndexedVariable
++ Author: Franz Lehner <[email protected]>
++ Date Created: 2009
++ Date Last Updated: July 2009
++ Fix History: 
++ Basic Functions:
++ Related Constructors:
++ Also See:
++ AMS Classifications:
++ Keywords:
++ References:
++ Description:
++   A domain for an indexed variable over an index set.
IndexedVariable(S:Symbol,K:OrderedSet):C == T where
    C ==> OrderedSet with
        index:% -> K
        ++ \spad{index(S_i)} returns the index i
        symbol  : % -> Symbol
        ++ symbol(x) returns the symbol
        coerce  : % -> Symbol
        ++ coerce(x) returns the symbol
        variable: () -> Symbol
        ++ variable() returns the symbol
        makeVariable:K -> %
        ++ \spad{makeVariable(i)} returns the variable S_i
       
    T ==> add
        Rep:= K
        v:%

        index(v) == v::Rep
        
        symbol(v) ==
            i:K := index v
            (subscript(S,[coerce(i)$...@outputform])) 
        
        makeVariable(i:K):% == i::%
    
        coerce(v):Symbol     == symbol v
        
        coerce(v):OutputForm == (symbol v)::OutputForm

        variable()             == S
        
        x = y                  == index x =$Rep index y

        latex(x:%):String      == latex symbol x

        x < y                  == index x <$Rep index y 
--$
@ 
        

<<example.input>>=
IVI:=IndexedVariable (P,Integer)
P1:=makeVariable(1)$IVI
P2:=makeVariable(2)$IVI
@ 

\section{domain CCRALGB CCRBasis}
The CCR algebra is spanned by monomials which are
products of position operators $Q_i$ and momentum operators $P_i$
which satisfy the canonical commutation relation
$[P_i,Q_j] = h I\delta_{ij}$
therefore $P_i$ acts like a derivation on $Q_i$:
$[P,Q^k] = h k Q^{k-1}$.
The normal form of a monomial has first position, then momentum operators.
Therefore we implement them as the product of the free abelian monoid 
over the $Q_i$'s and the free abelian monoid over the $P_i$'s
with modified output form.
\section{domain CCRALGB CCRBasis}
<<domain CCRALGB CCRBasis>>=
)abbrev domain CCRALGB CCRBasis
++ Author: Franz Lehner <[email protected]>
++ Date Created: 2009
++ Date Last Updated: July 2009
++ Fix History: 
++ Basic Functions:
++ Related Constructors:
++ Also See:
++ AMS Classifications:
++ Keywords:
++ References:
++ Description:
++   A simple domain for the canonical commutation relations of quantum 
mechanics
CCRBasis(R:CommutativeRing,h:R):C == T where
    C ==> AlgebraBasis(R) with
        position:PositiveInteger -> %
        ++ \spad{position(i)} produces the i-th position operator Qi
        momentum:PositiveInteger -> %
        ++ \spad{momentum(i)} produces the i-th momentum operator Pi
    QVAR ==> IndexedVariable(Q,Integer)
    PVAR ==> IndexedVariable(P,Integer)
    Pos ==> IndexedExponents QVAR
    Mom ==> IndexedExponents PVAR
    Term ==> Record(k:%,c:R)
    QTerm ==> Record(k:QVAR,c:NonNegativeInteger)
    PTerm ==> Record(k:PVAR,c:NonNegativeInteger)
    T ==> Product(Pos,Mom) add
        Rep:= Product(Pos,Mom)

        position(i:PositiveInteger):% ==
            makeprod(monomial(1,makeVariable(i)),0)
        momentum(i:PositiveInteger):% ==
            makeprod(0,monomial(1,makeVariable(i)))
        
        coerce(x:%):OutputForm ==
            qq:Pos := selectfirst(x::Rep)
            pp:Mom := selectsecond(x::Rep)
            zero? qq => pp::OutputForm
            zero? pp => qq::OutputForm
            (qq::OutputForm) * (pp::OutputForm)
        
        <<CCRBasis mult>>
@ 
Multiplication of two basis monomials proceeds as follows.
When the product of $Q_{i_1}\dots Q_{i_m}P_{j_1}^{k_1}\dots P_{j_n}$ 
with
$Q_{i'_1}^{k'_1}\dots Q_{i'_m}P_{j'_1}\dots P_{j'_n}$,
is reduced to normal form,
nontrivial commutations may occur only between
$P_{j_1}^{k_1}\dots P_{j_n}$ and $Q_{i'_1}^{k'_1}\dots Q_{i'_m}$.
We recursively commute the leading factors to the left until
$j_1=i'_1$ in which case the Weyl commutation relation is applied.
We accelerate this by using the relation
$P Q^k = Q^k P + h k Q^{k-1}$.
Note that the representing domain is an abelian monoid and uses $+$
instead of $*$.
<<CCRBasis mult>>=
(x*y):FreeModule(R,%) == 
    -- check for trivialities: 
    zero? selectfirst y or zero? selectsecond x => monomial(1,(x::Rep)+(y::Rep))
    Qi:QTerm := leadingTerm selectfirst y
    Pj:PTerm := leadingTerm selectsecond x

    kQ:Integer := index Qi k
    kP:Integer := index Pj k
@ 
Case 1: the leading $Q_{i'_1}$ commutes with all $P_{j_k}$
and we can proceed with
the product of $Q_{i_1}\dots Q_{i_m} \cdot Q_{i'_1}^{k'_1} P_{j_1}^{k_1}\dots 
P_{j_n}$ 
times
$Q_{i'_2}\dots Q_{i'_m}P_{j'_1}\dots P_{j'_n}$.
<<CCRBasis mult>>=
    -- case 1:leading Q of y commutes with all P's of x
    if kQ > kP then
        x1:% := makeprod(selectfirst x+monomial(Qi c, Qi k),selectsecond x)
        y1:% := makeprod(constructOrdered rest listOfTerms selectfirst 
y,selectsecond y)
        return (x1*y1)
@
Case 2: the leading $P_{j_1}$ commutes with all $Q_{i'_k}$
and we can proceed with
the product of $Q_{i_1}\dots Q_{i_m}P_{j_2}\dots P_{j_n}$ 
times
$Q_{i'_1}^{k'_1}\dots Q_{i'_m} P_{j_1}^{k_1}\cdot P_{j'_1}\dots P_{j'_n}$.
<<CCRBasis mult>>=
    -- case 2:leading P of x commutes with all Q's of y
    if kQ < kP then
        x1:% := makeprod(selectfirst x,constructOrdered rest listOfTerms 
selectsecond x)
        y1:% := makeprod(selectfirst y, monomial(Pj c,Pj k) + selectsecond y)
        return (x1*y1)
@
Case 3: the leading P and Q do not commute and we get
$Q_{i_1}\dots Q_{i_m} P_{j_1}^{k_1-1}$ times
$(Q_{i'_1}^{k'_1} P_{j_1} + h Q_{i'_1}^{k'_1-1}) P_{j_2}\dots P_{j_n}$.
<<CCRBasis mult>>=
    -- case 3: leading terms do not commute
    -- commute the leading momentum variable to the right
    -- the first part is similar to the one above
    x1P:List PTerm := rest listOfTerms selectsecond x
    if Pj c > 1 then -- leading P remains active
        -- must convert to NNI, otherwise it is assumed to be Integer
        -- and the compiler is confused!
        x1P1 := [Pj k, (Pj c -1)::NonNegativeInteger]
        x1P := cons(x1P1, x1P)

    x1:% := makeprod(selectfirst x,constructOrdered x1P)
    y1Q:Pos := selectfirst y
    y1P:Mom := monomial(1,Pj k)+ selectsecond y
    y1:% := makeprod(y1Q, y1P)

    -- second part: 
    x2:% := makeprod(selectfirst x,constructOrdered x1P)
    y2Q:List QTerm := rest listOfTerms selectfirst y
    if Qi c > 1 then
        y2Q1:QTerm := [Qi k, (Qi c -1)::NonNegativeInteger]$QTerm
        y2Q:=cons(y2Q1,y2Q)
    y2:% := makeprod(constructOrdered y2Q, selectsecond y)

    -- finally add the results
    x1*y1 + (Qi c)*h*(x2*y2)
@
<<example.input>>=
QB:=CCRBasis(Expression Integer,h)
Q1:=position(1)$QB
Q2:=position(2)$QB
P1:=momentum(1)$QB
P2:=momentum(2)$QB
Q12:=leadingSupport (Q1*Q2)
@
\section{domain CCRALG CCRAlgebra}
<<domain CCRALG CCRAlgebra>>=
)abbrev domain CCRALG CCRAlgebra
++ Author: Franz Lehner <[email protected]>
++ Date Created: 2009
++ Date Last Updated: July 2009
++ Fix History: 
++ Basic Functions:
++ Related Constructors:
++ Also See:
++ AMS Classifications:
++ Keywords:
++ References:
++ Description:
++   A simple domain for the canonical commutation relations of quantum 
mechanics
CCRAlgebra(R:CommutativeRing, h:R):Public == Private where
    Basis ==> CCRBasis(R,h)
    Public ==> AlgebraWithBasisCategory(R,Basis) with
        position:PositiveInteger -> %
        ++ \spad{position(i)} produces the i-th position operator Qi
        momentum:PositiveInteger -> %
        ++ \spad{momentum(i)} produces the i-th momentum operator Pi

    Private ==> AlgebraWithBasis(R,Basis) add
        position(i:PositiveInteger):% == monomial(1,position(i)$Basis)

        momentum(i:PositiveInteger):% == monomial(1,momentum(i)$Basis)
@     


<<example.input>>=
CCR:=CCRAlgebra(Complex Expression Integer,h/%i)
Q1:=position(1)$CCR
Q2:=position(2)$CCR
P1:=momentum(1)$CCR
P2:=momentum(2)$CCR
Q:=leadingSupport (Q1*Q2)
P1^2*Q1^3
@ 


\section{License}
<<license>>=
--Copyright (c) 2009, Franz Lehner <[email protected]>
--
--Redistribution and use in source and binary forms, with or without
--modification, are permitted provided that the following conditions are
--met:
--
--    - Redistributions of source code must retain the above copyright
--      notice, this list of conditions and the following disclaimer.
--
--    - Redistributions in binary form must reproduce the above copyright
--      notice, this list of conditions and the following disclaimer in
--      the documentation and/or other materials provided with the
--      distribution.
--
--THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
--IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
--TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
--PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
--OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
--EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
--PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
--PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
--LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
--NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
--SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@
<<*>>=
<<category ALGBAS AlgebraBasis>>
<<category ALGWBC AlgebraWithBasisCategory>>
<<domain ALGWB AlgebraWithBasis>>
<<domain INDVAR IndexedVariable>>
<<domain CCRALGB CCRBasis>>
<<domain CCRALG CCRAlgebra>>
<<license>>
@
<<todo>>=
@ 
\end{document}

Reply via email to