Questions tagged [demorgans-law]

De Morgan's laws are two important rules of Boolean algebra, relating the logical operators "AND" and "OR" in terms of each other via negation.

enter image description here

In another form:

NOT (A AND B) = (NOT A) OR (NOT B)  
NOT (A OR B) = (NOT A) AND (NOT B)  

The rules can be expressed in English as:

  • The negation of a conjunction is the disjunction of the negations.
  • The negation of a disjunction is the conjunction of the negations.
58 questions
34
votes
3 answers

Why does non-equality check of one variable against many values always return true?

I have a variable v in my program, and it may take any value from the set of values "a", "b", "c", ..., "z" And my goal is to execute some statement only when v is not "x", "y", or "z". I have tried, for C-like languages (where equality operators…
24
votes
6 answers

Is De Morgan's Law Pythonic?

Which of the following if statements is more Pythonic? if not a and not b: do_something OR if not ( a or b ): do something Its not predicate logic so I should use the Python key words because its more readable right? In the later solution…
nialloc
  • 805
  • 7
  • 17
23
votes
8 answers

De Morgan's rules explained

Could you please explain the De Morgan's rules as simply as possible (e.g. to someone with only a secondary school mathematics background)?
Stefano Borini
  • 138,652
  • 96
  • 297
  • 431
8
votes
5 answers

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

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…
Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321
7
votes
6 answers

De Morgan's Law

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.
user3003605
  • 385
  • 4
  • 6
  • 13
5
votes
1 answer

Negation and De Morgan's Law not part of C++20 partial ordering by constraints

The rules for partial ordering by constraints refer to AND and OR, but do not refer to NOT: 13.5.4 Partial ordering by constraints [temp.constr.order] (1.2) ... - The constraint A ∧ B subsumes A, but A does not subsume A ∧ B. - The constraint A…
Amir Kirsh
  • 12,564
  • 41
  • 74
4
votes
2 answers

How to understand De Morgan Laws Boolean Expression

I got screwed when trying to understand this expression. I've thought several times but I cant get the meaning. ! (p || q) is equivalent to !p && !q For this one, somehow I can comprehend a little bit. My understanding is " Not (p q) = not p and…
YLTO
  • 41
  • 2
4
votes
6 answers

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

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…
Mike
  • 43
  • 5
4
votes
4 answers

Emacs LISP - DeMorgan'ify a list

I am in an Artificial Intelligence course and we were given a program to write. The program is apparently simple, and all other students did it in java. However I know that it can be done in LISP with less work. Well. Less typing. But I've been…
kaleoh
  • 92
  • 1
  • 9
4
votes
3 answers

Are these statements equivalent?

Can I refactor like this, are these equivalent and therefore the simpler straighforward version of the code is preferred? Before refactoring: if (!matcher.matches() && !matcher2.matches() && !matcher3.matches() && !matcher4.matches()…
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
3
votes
1 answer

Error in replacing arguments in math formula

I have some problems with recursion in replacing arguments in math formula. I use the predicate which replacing arguments in math formula. replace(Term,Term,With,With) :- !. replace(Term,Find,Replacement,Result) :- Term =.. [Functor|Args], …
3
votes
5 answers

Boolean Algebra - Proving Demorgan's Law

I looked all over Google for a boolean algebra (not set theory) proof of DeMorgan's Law, and couldn't find one. Stack Overflow was also lacking in DeMorgan's Law questions. As part of a homework assignment for my CIS 251 class, we were asked to…
Chris Cirefice
  • 5,475
  • 7
  • 45
  • 75
2
votes
1 answer

DeMorgan's Law Clarification

Our lesson recently was about DeMorgan's law. I kinda get the concept on it already that (A+B)' = A'B' (AB)' = A'+B' I came across this one specific problem concerning such law and I want to clarify if ((A'B')+(AB))' = (A'B')(AB) or should it be…
Patrick
  • 31
  • 2
2
votes
2 answers

Is !(~A && ~B) better than (A||B) in programming?

I am developing in Java and I am using IntelliJ as my IDE. I wrote an if statement as follows. if( list1.size() >= 1 || list2.contains(itemX) ) { //do something } IntelliJ suggested a transformation (DeMorgan's Law) and it transformed it…
subject-q
  • 91
  • 3
  • 19
2
votes
1 answer

Haskell dot (.) operator in de Morgan's law implementation

In this question, the author has written an implementation of de Morgan's laws in Haskell. I understand the implementations of notAandnotB, and notAornotB, but I'm struggling to understand the implementation of notAorB which is: notAorB :: (Either a…
helencrump
  • 1,351
  • 1
  • 18
  • 27
1
2 3 4