Clearing/creating a ring in a loop?
I am having the ERROR x7 already used
error in sage. I have something like this:
for i in range(0, 4):
R = gen_ring(special flags, i)
do_stuff_to_ring(R)
This code basically creates a ring with the variables ordered in weird ways. Like when i = 0, the order is x11
, x2
, x7
... And the next time, the order would be x13
, x7
, x9
, x2
... or something like that, and the dimension of the ring variables is different too. The problem is that when I call gen_ring
the SECOND time, when i = 1, it says that the ring already has a variable x7
.
I've tried writing a special function to clear the variables, and I did reset(var)
for every variable in the ring. I tried del var
, and del ring
, and also reset(R)
, but that did not work. I didn't try R = None
. I will tomorrow! I am just looking for how to wipe the variables out of the namespace. If I do reset()
, ALL the variables are cleared, including the special flags, and the loop counter even. Blergh!
Hopefully some one can help? This cannot be a usual thing to want to do...
It is difficult to help without any specifics. Please add some (more or less minimal) complete runnable code that reproduces the error. If
gen_ring
creates the ring using strings for thenames
of generators, anddo_stuff_to_ring(R)
accesses the generators ofR
viaR.gens()
orR.gen(j)
orR(gen_name)
then it should work.I certainly appreciate that comment. I'll see if I can draft a minimal example. The rings are created with the R = PolynomialRing(ZZ, my_order), and then R.inject_variables(). I believe it is the inject_variables that is creating the problem. But I have a list, and so I can't create the ring via R.<my_order> = PolynomialRing(). I appreciate that you commented, and I will try to get a working example.
Okay, here is what I thought the minimal example was. But this is working in my Sage notebook. But the actual code base I am working in is a large series of sage files. Would that effect how variables are stored in the namespace, a notebook versus the sage environment?
I'm not sure yet what the issue is. Could you please post the full error you get in your actual script? (You can edit your question and add the error at the end. To format something using a monospace font, select it and press the code button labeled
101010
, next to the link button.)I suggest not to use "inject_variables", but the methods "gen" and "gens".