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.

Reply via email to