Ask Your Question

Revision history [back]

sYou can not create infinitely many symbols (a.k.a. symbolic variables) in the sense that they will fill up your memory, but you can create as many such symbols on demand (lazily), as a quick example, you can define the following function:

sage: def x(i):
....:     return SR.var('x_{}'.format(i))

Then, you can do things like:

sage: x(4)
x_4

sage: x(4) + x(7)^2
x_7^2 + x_4

sage: sum(x(i)^i for i in range(10))
x_9^9 + x_8^8 + x_7^7 + x_6^6 + x_5^5 + x_4^4 + x_3^3 + x_2^2 + x_1 + 1

sYou You can not create infinitely many symbols (a.k.a. symbolic variables) in the sense that they will fill up your memory, but you can create as many such symbols on demand (lazily), as a quick example, you can define the following function:

sage: def x(i):
....:     return SR.var('x_{}'.format(i))

Then, you can do things like:

sage: x(4)
x_4

sage: x(4) + x(7)^2
x_7^2 + x_4

sage: sum(x(i)^i for i in range(10))
x_9^9 + x_8^8 + x_7^7 + x_6^6 + x_5^5 + x_4^4 + x_3^3 + x_2^2 + x_1 + 1

You can not create infinitely many symbols (a.k.a. symbolic variables) in the sense that they will fill up your memory, but you can create as many such symbols on demand (lazily), as a quick example, you can define the following function:

sage: def x(i):
....:     return SR.var('x_{}'.format(i))

Then, you can do things like:

sage: x(4)
x_4

sage: x(4) + x(7)^2
x_7^2 + x_4

sage: sum(x(i)^i for i in range(10))
x_9^9 + x_8^8 + x_7^7 + x_6^6 + x_5^5 + x_4^4 + x_3^3 + x_2^2 + x_1 + 1

Note that if you reuse twice the same symbol, it is not recreated:

sage: x(2) is x(2)
True

You can not create infinitely many symbols (a.k.a. symbolic variables) in the sense that they will fill up your memory, but you can create as many such symbols on demand (lazily), as (lazily). As a quick example, you can define the following function:

sage: def x(i):
....:     return SR.var('x_{}'.format(i))

Then, you can do things like:

sage: x(4)
x_4

sage: x(4) + x(7)^2
x_7^2 + x_4

sage: sum(x(i)^i for i in range(10))
x_9^9 + x_8^8 + x_7^7 + x_6^6 + x_5^5 + x_4^4 + x_3^3 + x_2^2 + x_1 + 1

Note that if you reuse twice the same symbol, it is not recreated:

sage: x(2) is x(2)
True