Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to substitute variables in a rational function by numbers?

I have a program in which the first part needs to use a polynomial ring in a[1], ..., a[n]. In the last part of the program, I need to substitute a[i] in a rational function by some numbers. I define

Ra=PolynomialRing(QQ,'a',n0)
Fa=Ra.fraction_field()
a=Ra.gens()

For example, I have a rational function

r1=(a[1]^2+a[2])/(a[3]+2*a[4])

I tried the following:

a_random=[2,4,2,5]
for i in [1..4]:
    a[i]=a_random[i-1]

But it has an error:

'tuple' object does not support item assignment

How to solve this problem? Thank you very much.