If anyone is curious here's my code so far unvetted to create clifford
algebra with free algebra quotient: I need to add some comments...

nn=4
MyRing=QQ
Metric = diagonal_matrix(MyRing,[1,-2,-3,-5])
PRGA=FreeAlgebra(MyRing,nn,'g')
F = PRGA.monoid()
MyStr=str(PRGA.gens())
MyStr=MyStr[1:len(MyStr)-1]
exec MyStr+' = F.gens()'
#MG=matrix(F.gens())
#MGG=MG.transpose()*MG
#MGGM=MGG+MGG.transpose()-2*Metric
def cmmm(ii,jj):
    if ii!=jj:
        return (Metric-MGG.transpose())[ii,jj]
    else:
        return Metric[ii,jj]
def MyDeg2(MyIntStr):
    mydeg=0
    for ii in range(len(MyIntStr)):
        mydeg=mydeg+Integer(MyIntStr[ii])
    return mydeg
def MySignDelta(MyIntStr,mm):
    mysign=0
    for ii in range(nn-mm-1):
        mysign=mysign+Integer(MyIntStr[ii])
    return (-1)^mysign
def MyProduct(MyList):
    myprod=MyList[0]
    for jj in range(1,len(MyList)):
        myprod=myprod*MyList[jj]
    return myprod
def MyMonList(MyIntStr):
    MyList2=[]
    for jj in range(nn):
        if MyIntStr[jj]=='0':
            MyList2.append(F(1))
        else:
            MyList2.append(F.gen(nn-jj-1))
    return MyList2[::-1]
def MyCoeff(mylist3,kk):
    if ('0'==mylist3[kk][nn-kk-1]):
        return Metric[kk,kk]
    else:
        return 1
MyList1=[]
MyList2=[]
MyList4=[]
MyList5=[]
MyList7=[]
def runthis():
    for ii in range(2**nn):
        MyIntStr=Integer(ii+nn^2).binary()[1:nn+1]
        MyList2.append(MyIntStr)
        MyList=MyMonList(MyIntStr)
        myprod=MyProduct(MyList)
        MyList7.append(myprod)
        MyList1.append(str(myprod))
        MyList3=[Integer((ii+nn^2)^^(2^kk)).binary()[1:nn+1] for kk in
range(nn)]
        MyList4.append([MyProduct(MyMonList(MyList3[kk])) for kk in
range(nn)])
        MyList5.append([MySignDelta(MyIntStr,kk)*MyCoeff(MyList3,kk) for kk
in range(nn)])
runthis()
MyList6=sorted(sorted(MyList1),key=len)
MyList2=[MyList2[[MyList1.index(MyList6[kk]) for kk in
range(len(MyList1))][ll]] for ll in range(len(MyList1))]
MyList4=[MyList4[[MyList1.index(MyList6[kk]) for kk in
range(len(MyList1))][ll]] for ll in range(len(MyList1))]
MyList5=[MyList5[[MyList1.index(MyList6[kk]) for kk in
range(len(MyList1))][ll]] for ll in range(len(MyList1))]
MyList7=[MyList7[[MyList1.index(MyList6[kk]) for kk in
range(len(MyList1))][ll]] for ll in range(len(MyList1))]
mats=[]
for ii in range(nn):
    MyMatrix=matrix(MyRing,nn^2,nn^2,0)
    for jj in range(len(MyList1)):
        for kk in range(len(MyList1)):
            if MyList4[jj][ii]==MyList7[kk]:
                MyMatrix[jj,kk]=MyList5[jj][ii]
    mats.append(MyMatrix)
#ST=FreeAlgebraQuotient(PRGA,MyList6,mats, MyStr)
#exec 'ST.<'+MyStr+'> = FreeAlgebraQuotient(PRGA,MyList6,mats)'
#exec MyStr+' = ST.gens()'


On Mon, Jul 28, 2014 at 7:59 AM, Stephen Kauffman <[email protected]>
wrote:

> The mons list MyList6 was in the original free algebra generators, but I
> managed to fix it so it's in the monoid F generators and that fixed the
> first error AttributeError: 'FreeAlgebra_generic_with_
> category.element_class' object has no attribute '_element_list' My
> matrices were transposed but I fixed that also. Checking the behavior of
> the results now.
>
> The other good answer for Clifford Algebras was from David Joyner to use
> sympy packages
>
> plenty to read in http://docs.sympy.org/latest/modules/galgebra/GA.html
>
> import sympy
> from sympy import *
> from sympy.galgebra import *
> from sympy.galgebra.ga import *
>
> Fully featured but every statement has to be predicated in sage with a
> print statement to display the result and the sympy package doesn't
> dovetail with sage polynomial and quotient rings if you what to define
> something like g^2(1-b^2)=1 or a^2+b^2+c^2=1 with quotients. You get
> incompatible operand errors when you b*(sympyGAvector). Hopefully the free
> algebra solution can be created over these quotient and polynomial rings
> but I would have to reinvent all the myriad Clifford algebra operations...
>
>
>
> On Mon, Jul 28, 2014 at 1:21 AM, Nils Bruin <[email protected]> wrote:
>
>> On Sunday, July 27, 2014 8:40:50 PM UTC-7, Stephen Kauffman wrote:
>>>
>>> Thanks for your help but I think I need more. I've written some code for
>>> a somewhat general case of n orthogonal generators and an arbitrary
>>> diagonal metric and I think I've generated the correct 16x16 matrices for
>>> my n=4 case.
>>>
>>
>> I think you're mainly running into python syntax issues here. For the
>> most part, whenever you use "exec" in a computer algebra package, you're
>> doing something wrong. There is probably a better way of passing around
>> information (mind you, sometimes there's not. You're still doing something
>> wrong, but the package might not give you the tools to do it right).
>>
>>
>>> When I finish running the .sage file and return to sage I execute
>>>
>>> F = PRGA.monoid()
>>> MyStr=str(PRGA.gens())
>>> MyStr=MyStr[1:len(MyStr)-1]
>>> exec MyStr+' = F.gens()'
>>> ST.<g0,g1,g2,g3>=FreeAlgebraQuotient(PRGA,MyList6,mats)
>>> ST
>>>   Free algebra quotient on 4 generators ('g0', 'g1', 'g2', 'g3') and
>>> dimension 16 over Rational Field
>>>
>>> but when I do
>>>
>>> g3*g3 # or ST.gen(3)*ST.gen(3)
>>> AttributeError: 'FreeAlgebra_generic_with_category.element_class'
>>> object has no attribute '_element_list'
>>>
>>
>> I can't reproduce this error because you're not telling what MyList6 and
>> mats are. If I set
>>
>> sage: g0,g1,g2,g3 = F.gens()
>> sage: MyList6 = [ F(1), g0, g1, g2, g3, g0*g1, g0*g2, g0*g3, g1*g2,
>> g2*g3, g3*g1, g0*g1*g2*g3*g0, g0*g1*g2*g3*g1, g0*g1*g2*g3*g2,
>> g0*g1*g2*g3*g3, g0*g1*g2*g3]
>> sage: mats=[matrix(QQ,16,16,1) for j in range(4)]
>> sage: ST.<g0,g1,g2,g3>=FreeAlgebraQuotient(PRGA,MyList6,mats)
>> sage: ST.gen(3)*ST.gen(3)
>> g3
>>
>> I get no error (I do get a rather nonsensical result because I
>> initialized the matrices to nonsense).
>>
>>
>>> Further when I try to automate with the generated string MyStr='g0, g1,
>>> g2, g3' and within the .sage file
>>>
>>> exec 'ST.<'+MyStr+'> = FreeAlgebraQuotient(PRGA,MyList6,mats)'
>>>
>>> Traceback (most recent call last):
>>>   File "<string>", line 1
>>>     ST.<g0, g1, g2, g3> = FreeAlgebraQuotient(PRGA,MyList6,mats)
>>>        ^
>>> SyntaxError: invalid syntax
>>>
>>
>> That's because "exec" is just python's "exec" and you're giving syntax
>> that needs sage's preparser. The ST.<g0> syntax is not valid python. To see
>> how it converts:
>>
>> sage: preparse("ST.<g0,g1,g2,g3> = FreeAlgebraQuotient(PRGA, mons, mats)")
>> "ST = FreeAlgebraQuotient(PRGA, mons, mats, names=('g0', 'g1', 'g2',
>> 'g3',)); (g0, g1, g2, g3,) = ST._first_ngens(4)"
>>
>> which also helps you for your next error:
>>
>>
>>> If I try:
>>>
>>> ST=FreeAlgebraQuotient(PRGA,MyList6,mats, names='g0, g1, g2, g3') # or
>>> anything else I try in names
>>>
>>> Traceback (most recent call last):
>>> ValueError: first letter of variable name must be a letter
>>>
>>
>> As the preparse command shows, it should work if you set names to a tuple
>> (really, an iterable) of strings. A nasty design choice is that strings
>> themselves are iterables, which produce their individual characters. Compare
>>
>>  sage: [x for x in ('g0', 'g1', 'g2', 'g3')]
>> ['g0', 'g1', 'g2', 'g3']
>> sage: [x for x in "g0, g1, g2, g3"]
>> ['g', '0', ',', ' ', 'g', '1', ',', ' ', 'g', '2', ',', ' ', 'g', '3']
>>
>> Hence the error message: '0' is not a valid generator name.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "sage-support" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/sage-support.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to