# How to know if some indexed variables are implied in a list of conditions

Suppose you have an indexed list of variables say :

x = var("x", n=11)
Z=list(x)


and a list of conditions :

Cond = [x_1 >=0, x_2==0, x_6<=0]


First I am not sure that x_1 refers to the indexed variable with the same index. Then how to make a list of variables for which there is no condition inside Cond.

edit retag close merge delete

Sort by » oldest newest most voted

After defining x = var("x", n=11) the variables are x0, x1, ..., x10.

If you want x_0, x_1, ..., x_10, use

sage: x = var("x_", n=11)


Then to test if a certain condition involves a certain variable, use the has method:

sage: Cond = [x_1 >= 0, x_2 == 0, x_6 <= 0]

sage: c = Cond[0]
sage: c.has(x_1)
True
sage: c.has(x_2)
False


One way to list the variables not used in any of the conditions is therefore:

sage: [xj for xj in x if not any(c.has(xj) for c in Cond)]
[x_0, x_3, x_4, x_5, x_7, x_8, x_9, x_10]

more