Ask Your Question
1

subs() function gives KeyError when keyword is a list member

asked 2016-02-03 10:25:06 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I have a multivariate Boolean polynomial my_poly in xi (x0,x1,...,etc) and want to substitute one of the variables (say e.g. x0=0). my_poly subs(x0=0) works but I need to determine the exact variable (left hand side of '=') and value (right hand side of '=') at run-time depending on some conditions. The problem is subs() function do not accept expression on the left hand side of '=' and I have many xi variables, so if else is not practical. How can I solve this issue?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-02-03 11:39:39 +0200

tmonteil gravatar image

You can use Python dictionaries in the substitute method, for example:

sage: R = BooleanPolynomialRing(5,'x') ; R
Boolean PolynomialRing in x0, x1, x2, x3, x4
sage: R.inject_variables()
Defining x0, x1, x2, x3, x4
sage: P = R.random_element() ; P
x0*x1 + x0*x4 + x0 + x1*x2 + x1*x4

sage: a = x0
sage: mydict = {a:0} ; mydict
{x0: 0}
sage: P.substitute(mydict)
x1*x2 + x1*x4
edit flag offensive delete link more

Comments

Thank you. This solved my problem.

adnanbaysal gravatar imageadnanbaysal ( 2016-02-05 15:51:01 +0200 )edit

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2016-02-03 10:25:06 +0200

Seen: 471 times

Last updated: Feb 03 '16