Ask Your Question
1

get short name for QQ, RDF, AA etc

asked 2017-01-03 21:15:23 +0100

mf gravatar image

I wonder whether there is a way to get back the short name of the function of the various rings and fields like QQ, RDF, AA, RLF, RR, etc. as a string.

For example

sage: a=QQ
sage: str(a)
'Rational Field'

But I am looking for something like:

sage: function_I_want(a)
'QQ'

I guess I could predefine a dictionary like this:

shortnames={eval(name):name for name in ['QQ', 'RDF', 'AA', 'RLF', 'RR']}

and then have a function

def function_I_want(a):
    return shortnames[a]

But this seems a bit clumsy. Is there a better way to do this; or is there somewhere in the sage code such a dictionary already defined?

The reason I am thinking about this is the following tiny bug: https://trac.sagemath.org/ticket/22132

edit retag flag offensive close merge delete

Comments

1

The name QQ is not an intrinsic property of the field of rational numbers. It's just that for convenience, the default toplevel environment has the binding QQ=RationalField(). You cannot really let the Rational Field depend on it. For the bug you're referring to: You cannot assume rings have a "short, globally defined name". There are infinitely many possible finite fields and number fields already, in different representations.

nbruin gravatar imagenbruin ( 2017-01-03 21:30:51 +0100 )edit

thanks for the explanation!

mf gravatar imagemf ( 2017-01-03 23:32:50 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2017-01-03 21:40:10 +0100

tmonteil gravatar image

updated 2017-01-03 21:42:48 +0100

You can use the sage_input function, which, luckily selects the short name among the possible constructions:

sage: a = RationalField()
sage: sage_input(a)
QQ

It seems however not to work with RLF:

sage: for obj in [QQ, RDF, AA, RR, ZZ, QQbar, RLF]:
....:     print sage_input(obj)
QQ
RDF
AA
RR
ZZ
QQbar
ValueError: Can't convert Real Lazy Field to sage_input form
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

1 follower

Stats

Asked: 2017-01-03 21:15:23 +0100

Seen: 589 times

Last updated: Jan 03 '17