demorgans-law

I'm having issues with applying De Morgan's Law … Feedback?

戏子无情 提交于 2021-02-16 17:57:29
问题 Every time one of these questions comes up in my assignments I get it wrong...can anyone help me understand? Or is the teacher's key off? (There is no way for me to know as I'm not given the correct answer, it only lets me know that mine is wrong.) Assume x = 7 and y = 5 . Applying De Morgan's Law, select the logical expression below that is equivalent to the following logical expression: !(x>5)||!(y>7) (a) !(x>5)&&!(y>7) (b) !((x>5)||(y>7)) (c) !(x>5)&&(y>7) (d) (x>5)||!(y>7) (e) None of the

Is there any advantage to using De Morgan's laws in python?

落花浮王杯 提交于 2020-01-21 06:51:33
问题 I use pycharm and a few times when using if statements I have seen the suggestion to change the statement using De Morgan laws, such as with the following if statement: if new_odds > 10 and new_odds <= 30: if not (not (new_odds > 10) or not (new_odds <= 20)): For me it makes it less readable, so is there any advantage to using De Morgan's laws or is it strictly a personal choice? 回答1: De Morgan's laws state that: "not (A and B)" is the same as "(not A) or (not B)" and also, "not (A or B)" is

De Morgan's Laws in Haskell via the Curry-Howard Correspondence

此生再无相见时 提交于 2020-01-01 19:15:54
问题 I implemented three of the four De Morgan's Laws in Haskell: notAandNotB :: (a -> c, b -> c) -> Either a b -> c notAandNotB (f, g) (Left x) = f x notAandNotB (f, g) (Right y) = g y notAorB :: (Either a b -> c) -> (a -> c, b -> c) notAorB f = (f . Left, f . Right) notAorNotB :: Either (a -> c) (b -> c) -> (a, b) -> c notAorNotB (Left f) (x, y) = f x notAorNotB (Right g) (x, y) = g y However, I don't suppose that it's possible to implement the last law (which has two inhabitants): notAandBLeft

De Morgan's Law

独自空忆成欢 提交于 2019-12-22 07:46:49
问题 I am trying to simplify the following using DeMorgan's Law: ! (x!=0 || y !=0) Does x!=0 simplify to x>0? Or am I wrong in the following: !(x>0 || y>0) !(x>0) && !(y>0) ((x<=0) && (y<=0)) Thanks. 回答1: Does x!=0 simplify to x>0? No that's not true. Because integers are signed. How to simplify : !(x!=0 || y !=0) ? Consider this rules : (second De Morgan's laws ) By 1., it implies !(x!=0 || y !=0) <=> (!(x!=0)) && (!(y != 0)) By 2., it implies (!(x!=0)) && (!(y != 0)) <=> (x == 0) && (y == 0) To

De Morgan's Law

我与影子孤独终老i 提交于 2019-12-22 07:46:30
问题 I am trying to simplify the following using DeMorgan's Law: ! (x!=0 || y !=0) Does x!=0 simplify to x>0? Or am I wrong in the following: !(x>0 || y>0) !(x>0) && !(y>0) ((x<=0) && (y<=0)) Thanks. 回答1: Does x!=0 simplify to x>0? No that's not true. Because integers are signed. How to simplify : !(x!=0 || y !=0) ? Consider this rules : (second De Morgan's laws ) By 1., it implies !(x!=0 || y !=0) <=> (!(x!=0)) && (!(y != 0)) By 2., it implies (!(x!=0)) && (!(y != 0)) <=> (x == 0) && (y == 0) To

Python And Or statements acting ..weird

随声附和 提交于 2019-12-17 21:10:46
问题 I have this simple line of code: i = " " if i != "" or i != " ": print("Something") This should be simple, if i is not empty "" OR it's not a space " " , but it is, print Something. Now, why I see Something printed if one of those 2 conditions is False ? 回答1: De Morgan's laws, "not (A and B)" is the same as "(not A) or (not B)" also, "not (A or B)" is the same as "(not A) and (not B)". In your case, as per the first statement, you have effectively written if not (i == "" and i == " "): which

If not condition doesn't work as expected

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 03:33:55
问题 I have written an if else condition which makes use of if not(!) to throw an error. However, the condition does not behave how I had expected and the error gets thrown regardless of who is the currentUser: public void findCorrectUserRole() { if (Book.name.equals("Test Answers")) { User currentUser = User.getCurrentUser() if (currentUser) { if (!currentUser.hasUserRole("Teacher") || !currentUser.hasUserRole("System Administrator")) { throw new LCEX("Sorry, only a teacher or System

De Morgan's Law

烂漫一生 提交于 2019-12-05 10:55:13
I am trying to simplify the following using DeMorgan's Law: ! (x!=0 || y !=0) Does x!=0 simplify to x>0? Or am I wrong in the following: !(x>0 || y>0) !(x>0) && !(y>0) ((x<=0) && (y<=0)) Thanks. Alexis C. Does x!=0 simplify to x>0? No that's not true. Because integers are signed. How to simplify : !(x!=0 || y !=0) ? Consider this rules : (second De Morgan's laws ) By 1., it implies !(x!=0 || y !=0) <=> (!(x!=0)) && (!(y != 0)) By 2., it implies (!(x!=0)) && (!(y != 0)) <=> (x == 0) && (y == 0) To test you can write the following loop : for(int x = -5; x < 5; x++){ for(int y = -5; y < 5; y++){

De Morgan's Laws in Haskell via the Curry-Howard Correspondence

此生再无相见时 提交于 2019-12-04 18:06:50
I implemented three of the four De Morgan's Laws in Haskell: notAandNotB :: (a -> c, b -> c) -> Either a b -> c notAandNotB (f, g) (Left x) = f x notAandNotB (f, g) (Right y) = g y notAorB :: (Either a b -> c) -> (a -> c, b -> c) notAorB f = (f . Left, f . Right) notAorNotB :: Either (a -> c) (b -> c) -> (a, b) -> c notAorNotB (Left f) (x, y) = f x notAorNotB (Right g) (x, y) = g y However, I don't suppose that it's possible to implement the last law (which has two inhabitants): notAandBLeft :: ((a, b) -> c) -> Either (a -> c) (b -> c) notAandBLeft f = Left (\a -> f (a, ?)) notAandBRight :: (

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,