Ask Your Question
0

field extensions in python

asked 12 years ago

strangerland gravatar image

updated 10 years ago

FrédéricC gravatar image

You can define a field extenion at the sage prompt with

QC.<j>; = QQ.extension(x^2+1)

however this same line in a python script yields a syntax error

def mytest(): 
    QC.<j> = QQ.extension(x^2+1);
    return

Traceback (most recent call last):
...
def mytest(): QC.<j> = QQ.extension(x**_sage_const_2 +_sage_const_1 ); return
                 ^
SyntaxError: invalid syntax

Note:syntax error point to < character

eval also fails

eval('QC.&lt;j&gt; = QQ.extension(x^2+1)')

Traceback (most recent call last):
....    
QC.<j> = QQ.extension(x^2+1)
   ^
SyntaxError: invalid syntax

I also have similar problems with defining Quaternion Algebras in python

HQ.<q1,q2,q3> = QuaternionAlgebra(QC,-1,-1)

so why does QC.<j> = QQ.extension(x^2+1) work at the sage prompt and not in python or with eval(string)

Thanks, Steve

Preview: (hide)

3 Answers

Sort by » oldest newest most voted
0

answered 12 years ago

vdelecroix gravatar image

The Sage preparser is not the same as the python preparser. This one of the difference. You can access the Sage parser with sage_eval

sage: sage_eval('QQ[sqrt(2)]')
Number Field in sqrt2 with defining polynomial x^2 - 2

sage: eval('type(1)')
int
sage: sage_eval('type(1)')
sage.rings.integer.Integer
Preview: (hide)
link
0

answered 12 years ago

ppurka gravatar image

Rename your file to something like filename.sage. Then run it as

$ sage filename.sage
Preview: (hide)
link
0

answered 12 years ago

strangerland gravatar image

this basically worked but I had to

load "/home/stephen/sage/example.sage"

thanks for the help

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 12 years ago

Seen: 750 times

Last updated: Apr 06 '13