# An error when use subs

I defined a simple function as follows.

def BarInvolution(q,l):
r1=l
r=r1.subs(q=1/q)

return r


Then I use the following codes.

R=PolynomialRing(QQ,'a',15)
a=R.gens()
BarInvolution(a[5], a[5]+1)


But it has the following errors:

KeyError Traceback (most recent call last) <ipython-input-212-6b33633fbe0d> in <module>() 1 ----> 2 BarInvolution(a[Integer(5)], a[Integer(5)])

<ipython-input-209-4f401596da47> in BarInvolution(q, l) 1 def BarInvolution(q,l): 2 r1=l ----> 3 r=r1.subs(q=Integer(1)/q) 4 5 return r

/Users/jianrongli/SageMath/local/lib/python3.7/site-packages/sage/rings/polynomial/multi_polynomial_libsingular.pyx in sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular.subs (build/cythonized/sage/rings/polynomial/multi_polynomial_libsingular.cpp:29147)() 3485 gd = parent.gens_dict(copy=False) 3486 for m,v in kw.iteritems(): -> 3487 m = gd[m] 3488 for i from 0 < i <= _ring.N: 3489 if p_GetExp((<mpolynomial_libsingular>m)._poly, i, _ring) != 0:

KeyError: 'q'

How to fix this problem? Thank you very much!

edit retag close merge delete

Sort by ยป oldest newest most voted

Use r=r1.subs({q:1/q}) instead of r=r1.subs(q=1/q).

more