Ask Your Question

Optimization of boolean evaluation

asked 2013-09-11 15:02:54 +0200

In a code like

if (P_1 or P_2 or ... or P_n):


if (Q_1 and Q_2 and ... and Q_n):

if only one P_i is true, or only one Q_i is false,then the boolean evaluation of the whole propositions (P_1 or P_2 or ... or P_n), (Q_1 and Q_2 and ... and Q_n) are determined.
So in a goal of optimization, the program could stop to evaluate the P_i from the first true.

Does SAGE stop to evaluate like that ? (if no, is there a way to do that ?)

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2013-09-11 17:04:00 +0200

ndomes gravatar image


"The Boolean operators and and or are so-called short-circuit operators: their arguments are evaluated from left to right, and evaluation stops as soon as the outcome is determined."

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


Asked: 2013-09-11 15:02:54 +0200

Seen: 469 times

Last updated: Sep 11 '13