I define the following in Sage.
rank=8
R=PolynomialRing(QQ, 'a' ,rank+1)
a=R.gens()
I would like to define a function f which returns the index of a[3]: f(a[3])=3 and define another function g such that g(a[3])=a. How to do this in Sage? Thank you very much!
This answer draws on the one by Alex J Best for defining
f, but also definesg.Define a multivariate polynomial ring and its generator tuple:
Consider one of the generators (or "indeterminates", or "variables"):
To get its index in the generator tuple:
This can be made into the function
frequested in the question:The above is tied to the definition of
a; more generally:What function
gthe question requests is not entirely clear.If we want
g(a[2])to return the string'a':With that definition:
If instead we want
g(a[2])to return the tupleR.gens():With that definition: