# Truth value of an expression (Boolean Polynomials)

I need to find the truth value of an expression. Consider this:

sage: R = BooleanPolynomialRing( 2, \
['s%d'%(i) for i in range (2)])
sage: expr = R('s0') + R('s0')*R('s1')


Now I need expr is to be evaluated; given, say, both s0 and s1 are True. How can we do that?

edit retag close merge delete

Sort by ยป oldest newest most voted

You can try:

sage: bool(expr(s0=True, s1=True))
True


You can also fix only some variables:

sage: expr(s0=True)
s1 + 1

more

@tmonteil Thanks. In my current situation, I get the truth values of the variables from solving a SAT problem. Thus, I have a dictionary like {s0: True, s1: False}, I need that these values are put to the expression. But I am stuck with that! Can you help me?

( 2013-11-26 00:33:16 -0600 )edit

@tmonteil But, more than 256 variables is not allowed in this method!

( 2013-11-26 05:17:18 -0600 )edit

@tmonteil Moreover, I found that instead of doing calculations over finite of degree 2, it simply calculates the value!!

( 2013-11-26 05:32:40 -0600 )edit
1

Well, this how a boolean expression should be called, see expr.__call__? for more details. Now, if you want to evaluate according to a dictionary, you can type expr.substitute(d) or bool(expr.substitute(d)). I didn't check, but if you need more than 256 variables and it does not work, you should open a ticket on the trac server http://trac.sagemath.org . Concerning the values, this is the way Python handles boolean: 0 stands for False and any positive int stands for True, you can notice that it is consistent with the addition as the or and the multiplication as the and. By the way, to see all available methods that can be applied to expr, you can type expr.[TABULATION] and see the list.

( 2013-11-26 07:56:23 -0600 )edit

Another problem, how can I use something like: (expr([s'%d'%(i)=True for i in range(2)])) ?

( 2018-02-05 09:54:07 -0600 )edit

Should I create a ticket?

( 2018-02-05 09:56:23 -0600 )edit