Ask Your Question
1

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

asked 2022-03-22 17:41:24 +0100

Cyrille gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-03-22 18:32:19 +0100

slelievre gravatar image

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]
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-03-22 17:41:24 +0100

Seen: 179 times

Last updated: Mar 22 '22