Search code examples
pythonsagepolynomials

NameError when using Sage polynomials


I read here how to work with polynomials. But when I try this

R = QQ['t']
poly = (t+1) * (t+2); poly

Sage gives me the following error:

NameError: name 't' is not defined

What can I do about it?


Solution

  • Right, you have to inject the variable name when using polynomial rings. The document you point to points out that

    sage: R.<t> = PolynomialRing(QQ)
    

    does do this. Or, you can do

    sage: R=QQ['t']
    sage: R.inject_variables()
    Defining t
    sage: t+1
    t + 1
    

    You wanted to know how to do it without printing the name:

    sage: R.inject_variables(verbose=False)
    

    Have fun!