Ask Your Question

Revision history [back]

Here is how to read them line-by-line from a string:

funs = """[[[4, -1]], (x7 + x20)/x19]
[[[4, -3], [4, -1]], (x8*x19 + x7*x21 + x20*x21)/(x19*x20)]"""

R = PolynomialRing(QQ, names=[f"x{k}" for k in range(1,22)])

for line in funs.split('\n'):
    value = sage_eval(line, locals=R.gens_dict())
    print(value)

Output:

[[[4, -1]], (x7 + x20)/x19]
[[[4, -3], [4, -1]], (x8*x19 + x7*x21 + x20*x21)/(x19*x20)]

You can adapt it to read lines from a file.