Ask Your Question
1

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

asked 9 years ago

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 9 years ago

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
Preview: (hide)
link

Comments

Thank you. This solved my problem.

adnanbaysal gravatar imageadnanbaysal ( 9 years ago )

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: 9 years ago

Seen: 616 times

Last updated: Feb 03 '16