boolean-expression

Why are products called minterms and sums called maxterms?

匆匆过客 提交于 2019-12-02 17:19:25
Do they have a reason for doing so? I mean, in the sum of minterms, you look for the terms with the output 1; I don't get why they call it "minterms." Why not maxterms because 1 is well bigger than 0? Is there a reason behind this that I don't know? Or should I just accept it without asking why? Rubenulis The convention for calling these terms "minterms" and "maxterms" does not correspond to 1 being greater than 0. I think the best way to answer is with an example: Say that you have a circuit and it is described by X̄YZ̄ + XȲZ . "This form is composed of two groups of three. Each group of

Why does `a == b or c or d` always evaluate to True?

吃可爱长大的小学妹 提交于 2019-12-02 10:37:49
I am writing a security system that denies access to unauthorized users. import sys print("Hello. Please enter your name:") name = sys.stdin.readline().strip() if name == "Kevin" or "Jon" or "Inbar": print("Access granted.") else: print("Access denied.") It grants access to authorized users as expected, but it also lets in unauthorized users! Hello. Please enter your name: Bob Access granted. Why does this occur? I've plainly stated to only grant access when name equals Kevin, Jon, or Inbar. I have also tried the opposite logic, if "Kevin" or "Jon" or "Inbar" == name , but the result is the

What does “?” and “:” do in boolean statements? [duplicate]

霸气de小男生 提交于 2019-12-02 04:18:38
This question already has an answer here: java ternary operator 2 answers I think this question is a general programming question, but let's assume I'm asking this for Java. what does the following statement do ? return a ? (b || c) : (b && c); I have seen the syntax with ? 's and : 's in many topics at SO, this particular one I found in Check if at least two out of three booleans are true But I don't know what they mean, so how to use them, and I believe it's something very useful for me. Thanks ! That's the conditional operator. It means something like: condition ? value-if-true : value-if

Slicing with a logical (boolean) expression a Pandas Dataframe

て烟熏妆下的殇ゞ 提交于 2019-12-01 21:19:36
I am getting an exception as I try to slice with a logical expression my Pandas dataframe. My data have the following form: df GDP_norm SP500_Index_deflated_norm Year 1980 2.121190 0.769400 1981 2.176224 0.843933 1982 2.134638 0.700833 1983 2.233525 0.829402 1984 2.395658 0.923654 1985 2.497204 0.922986 1986 2.584896 1.09770 df.info() <class 'pandas.core.frame.DataFrame'> Int64Index: 38 entries, 1980 to 2017 Data columns (total 2 columns): GDP_norm 38 non-null float64 SP500_Index_deflated_norm 38 non-null float64 dtypes: float64(2) memory usage: 912.0 bytes The command is the following: df[(

DeMorgan's law and C++

匆匆过客 提交于 2019-12-01 11:52:57
For each of the following write the equivalent C++ expressions, without any unary negation operators (!). (!= is still permitted) Use DeMorgan's law !( P && Q) = !P || !Q !( P || Q) = !P && !Q For !(x!=5 && x!=7) !(x<5 || x>=7) !( !(a>3 && b>4) && (c != 5)) My answers: (x>5 || x<5) || (x>7 || x<7) x>=5 && x < 7 (a>3 && b > 4) && (c!=5) Are these correct? If not, can you give me answers and explain why they are wrong? I am a beginner in C++ so take it easy. Check this out: !(x!=5 && x!=7) --> x==5 || x==7 !(x<5 || x>=7) --> x>=5 && x<7 !( !(a>3 && b>4) && (c != 5)) --> (a>3 && b>4) || c==5 So,

DeMorgan's law and C++

天涯浪子 提交于 2019-12-01 10:55:25
问题 For each of the following write the equivalent C++ expressions, without any unary negation operators (!). (!= is still permitted) Use DeMorgan's law !( P && Q) = !P || !Q !( P || Q) = !P && !Q For !(x!=5 && x!=7) !(x<5 || x>=7) !( !(a>3 && b>4) && (c != 5)) My answers: (x>5 || x<5) || (x>7 || x<7) x>=5 && x < 7 (a>3 && b > 4) && (c!=5) Are these correct? If not, can you give me answers and explain why they are wrong? I am a beginner in C++ so take it easy. 回答1: Check this out: !(x!=5 && x!=7)

Boolean expressions optimizations in Java

邮差的信 提交于 2019-12-01 09:50:36
Consider the following method in Java: public static boolean expensiveComputation() { for (int i = 0; i < Integer.MAX_VALUE; ++i); return false; } And the following main method: public static void main(String[] args) { boolean b = false; if (expensiveComputation() && b) { } } Logical conjunction (same as &&) is a commutative operation . So why the compiler doesn't optimize the if-statement code to the equivalent: if (b && expensiveComputation()) { } which has the benefits of using short-circuit evaluation ? Moreover, does the compiler try to make other logic simplifications or permutation of

what is the correct way to check for False? [duplicate]

本小妞迷上赌 提交于 2019-12-01 01:28:20
问题 This question already has answers here : Why does comparing strings using either '==' or 'is' sometimes produce a different result? (14 answers) Is there a difference between “== False” and “is not” when checking for an empty string? (2 answers) Closed 3 years ago . Which is better? (and why?) if somevalue == False: or if somevalue is False: Does your answer change if somevalue is a string? 回答1: It rather depends on what somevalue can be: if somevalue could be anything you could check that it

How do I make AND or OR expressions?

≡放荡痞女 提交于 2019-12-01 01:00:38
问题 I wrote this: if( a == -11 && b == -1 ){ { if( a == -1) AND ( b == -1)... But neither work, and I have the same problem with OR . How do I write expressions that include OR or AND ? 回答1: You use && for “and”, and || for “or”. 回答2: (a == -11 && b == -1) is fine and correct. Objective-C uses all of the same logical operators as C. || is the logical-or operator. 回答3: if (a==-11 && b==-1) { if perfectly legal in C, and therefore Objective-C. Your second example is not C or Objective-C 来源: https:/

How can I express that two values are not equal to eachother?

…衆ロ難τιáo~ 提交于 2019-11-30 17:56:03
Is there a method similar to equals() that expresses "not equal to"? An example of what I am trying to accomplish is below: if (secondaryPassword.equals(initialPassword)) { JOptionPane.showMessageDialog(null, "You've successfully completed the program."); } else { secondaryPassword = JOptionPane.showInputDialog(null, "Your passwords do not match. Please enter you password again."); } I am trying to find something that will not require me to use if ( a != c) . Just put a '!' in front of the boolean expression "Not equals" can be expressed with the "not" operator ! and the standard .equals . if