Ask Your Question
0

field extensions in python

asked 2013-04-06 05:57:22 -0600

strangerland gravatar image

updated 2015-01-13 11:11:31 -0600

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

edit retag flag offensive close merge delete

3 answers

Sort by » oldest newest most voted
0

answered 2013-04-06 09:14:48 -0600

strangerland gravatar image

this basically worked but I had to

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

thanks for the help

edit flag offensive delete link more
0

answered 2013-04-06 07:25:03 -0600

ppurka gravatar image

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

$ sage filename.sage
edit flag offensive delete link more
0

answered 2013-04-06 06:33:33 -0600

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
edit flag offensive delete link more

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: 2013-04-06 05:57:22 -0600

Seen: 193 times

Last updated: Apr 06 '13