boolean-expression

Is there a logical difference between 'not ==' and '!= (without is)

我的未来我决定 提交于 2019-12-29 08:41:59
问题 Is there a substantial difference in Python 3.x between: for each_line in data_file: if each_line.find(":") != -1: #placeholder for code #more placeholder and for each_line in data: if not each_line.find(":") == -1: #placeholder for code #more placeholder My question isn't particular to the above usage, but is more general or essential - is this syntactical difference working in a different way, even though the result is the same? Is there a logical difference? Are there tasks where one is

XOR of three values

▼魔方 西西 提交于 2019-12-28 03:45:09
问题 What is the simplest way to do a three-way exclusive OR? In other words, I have three values, and I want a statement that evaluates to true IFF only one of the three values is true. So far, this is what I've come up with: ((a ^ b) && (a ^ c) && !(b && c)) || ((b ^ a) && (b ^ c) && !(a && c)) || ((c ^ a) && (c ^ b) && !(a && b)) Is there something simpler to do the same thing? Here's the proof that the above accomplishes the task: a = true; b = true; c = true ((a ^ b) && (a ^ c) && !(b && c))

Check equivalent CTL formulas

[亡魂溺海] 提交于 2019-12-25 11:58:19
问题 I'm doing an CTL exercise, I'm trying to check if the following formulas are equivalent or not. But I'm not sure if I'm doing right. EF (p or q) = EF(p) or EF(q) ? AF(p or q) = AF(p) or AF(q) ? A(p U ( A(q U r) )) = A(A(p U q) U r) ? Firt formula: Equivalent Second formula: Equivalent Third formula: Equivalent Is it right? If are wrong could you give me one of possible counter-examples in Kripke model? Thanks in advance. 回答1: I'll try to use the semantics of CTL defined here: Wikipedia about

Represent a business rule as a constraint model to find the solution set

柔情痞子 提交于 2019-12-25 09:02:18
问题 In my enterprise application I have business rules like : ((AMOUNT < 20000.00) || ((AMOUNT >= 20000.00) && (RISKEXPOSURE == 'N'))) (ind = A1 || ind = A2 || ind = A3 || ind = S1 || ind = S2 || ind = S9) The rule, as you can see, is made of business expressions ex: (AMOUNT < 20000.00) . The rules could have any number of business conditions joined by boolean operators && and || . The identifiers AMOUNT , RISKEXPOSURE and ind are the business variables (which could vary from 1 to n based on the

Is that js expression safe: if( !x || doSomething( x[prop], y[prop] ) === false )

痞子三分冷 提交于 2019-12-24 15:50:31
问题 From a bug report, I think that the following expression might throw an exception if x is null: if ( !x || doSomething( x[prop], y[prop] ) === false ) The exception is: Cannot read property 'prop' of null ... as if the right side of the || is evaluated even if the left side is true. The javascript reference seems to indicate that that should not happen, but I'm not sure. I've tested that just writing x = null does not (always) crash, but is it guaranteed on every JS engine ? EDIT: Same

Trigger with multiple WHEN conditions

心不动则不痛 提交于 2019-12-24 07:04:25
问题 How do I include the columns I need to monitor? I.e. instead of one WHEN condition I want to have 3 WHEN conditions: CREATE TRIGGER freeradius.insert_into_day_summations BEFORE INSERT ON freeradius.day_guiding_usage FOR EACH ROW WHEN (OLD.col1 IS DISTINCT FROM NEW.col1) WHEN (OLD.col2 IS DISTINCT FROM NEW.col2) WHEN (OLD.col3 IS DISTINCT FROM NEW.col3) EXECUTE procedure update_sessioninfo(); 回答1: Form a single expression with OR or AND - depending on whether you want to trigger when all

Evaluate boolean tuple in Python

为君一笑 提交于 2019-12-24 05:39:39
问题 I'm trying to get this to evaluate to false. (False,) It's currently equaled to true, because I think the tuple is not empty. So how might one extract or cast this to a boolean? Thanks~ 回答1: Extract the element from the tuple is the most simple approach: value = (False,)[0] Python2 is more lenient, but in general it isn't good practice to treat a tuple as a single value for comparison purposes (Python3 explicetly bans it) Instead, look at the all and any functions for this behavior. As always

Boolean Logic Design - Reduction

安稳与你 提交于 2019-12-24 00:59:48
问题 I have the following function to be reduced/simplified. F(A,B,C,D) = BC + (A + C'D') where ' denotes the complement Here's my solution: = BC + (A + C'D')' = BC + (A + (C+D) = BC + (A + C + D) = BC + C + A + D = C(B + 1) + A + D = C*1 + A + D = C + A + D Is this correct? 回答1: As in traditional algebra, if you do something to one side of the equation, you must do it to the other side, including complementing. Here we state the original equation: F'(A,B,C,D) = BC + (A + (CD)') Since we have F'

convert “Yes” or “No” to boolean

流过昼夜 提交于 2019-12-22 10:36:50
问题 I want to parse user values contained in .CSV file. I don't want my users to enter "Yes" or "No" but instead enter "True" or "False". In each case I want to convert to the equivalent boolean values: $true or $false . Ideally I would like a default value, so if there's misspelt "Yes or "No" I would return my default value: $true or $false . Hence, I wondered if there is a neat way of doing this other than if(){} else (){} 回答1: One way is a switch statement: $bool = switch ($string) { 'yes' {

Where might I find a method to convert an arbitrary boolean expression into conjunctive or disjunctive normal form?

独自空忆成欢 提交于 2019-12-21 03:56:17
问题 I've written a little app that parses expressions into abstract syntax trees. Right now, I use a bunch of heuristics against the expression in order to decide how to best evaluate the query. Unfortunately, there are examples which make the query plan extremely bad. I've found a way to provably make better guesses as to how queries should be evaluated, but I need to put my expression into CNF or DNF first in order to get provably correct answers. I know this could result in potentially