Docsity

Logical Operator Laws - Computer Science - Lecture Notes, Study notes of Computer Science

Partial preview of the text

Download Logical Operator Laws - Computer Science - Lecture Notes and more Study notes Computer Science in PDF only on Docsity!

Today ...

  • Quiz 7
  • Logical operator laws
  • Sorting

Logical Operator Review ... and Laws

What is returned?

  1. "ham" and ("spam" or "eggs")
  2. "ham" or ("spam" and "eggs")

What about for these?

  1. ("ham" and "spam") or ("ham" and "eggs") Distributive Law
  2. ("ham" or "spam") and ("ham" or "eggs") Distributive Law

In general:

  1. x and (y or z) ≡ (x and y) or (x and z)
  2. x or (y and z) ≡ (x or y) and (x or z)

What about for these?

  1. not ("ham" or "spam")
  2. (not "ham") and (not "spam") DeMorgan’s Law

In general:

  1. not (x or y) ≡ (not x) and (not y)
  2. not (x and y) ≡ (not x) or (not y)

For example:

  • not (c == "red" or c == "blue") ≡ c != "red" and c != "blue"
  • and different than: c != "red" or c != "blue" ... common mistake