Docsity

Understanding Boolean Logic: Propositions, Variables, and Logical Operators, Slides of Discrete Mathematics

Partial preview of the text

Download Understanding Boolean Logic: Propositions, Variables, and Logical Operators and more Slides Discrete Mathematics in PDF only on Docsity!

1

Boolean Logic

2

Applications of Boolean logic

  • Computer programs
  • And computer addition
  • Logic problems
  • Sudoku

4

  • We use Boolean variables to refer to

propositions

  • Usually are lower case letters starting with p (i.e. p, q, r, s , etc.)
  • A Boolean variable can have one of two values true (T) or false (F)
  • A proposition can be…
  • A single variable: p
  • An operation of multiple variables: p ∧( q ∨¬ r )

Boolean variables

5

Introduction to Logical Operators

  • About a dozen logical operators
    • Similar to algebraic operators + * - /
  • In the following examples,
    • p = “Today is Friday”
    • q = “Today is my birthday”

7

Logical operators: And

  • An and operation is true if both operands are true
  • Symbol: ∧
    • It’s like the ‘A’ in And
  • In C++ and Java,

the operand is &&

  • p ∧ q = “Today is Friday and

today is my birthday”

p q p ∧ q T T T T F F F T F F F F

8

Logical operators: Or

  • An or operation is true if either operands are true
  • Symbol: ∨
  • In C++ and Java,

the operand is ||

  • p ∨ q = “Today is Friday or

today is my birthday (or possibly both)”

p q p ∨ q T T T T F T F T T F F F

10

Inclusive Or versus Exclusive Or

  • Do these sentences mean inclusive or

exclusive or?

  • Experience with C++ or Java is required
  • Lunch includes soup or salad
  • To enter the country, you need a passport or a driver’s license
  • Publish or perish

11

Logical operators: Nand and Nor

  • The negation of And and Or, respectively
  • Symbols: | and ↓, respectively
    • Nand: p | q ≡ ¬( p ∧ q )
    • Nor: p ↓ q ≡ ¬( p ∨ q )

p q p ∧ q p ∨ q p | q p ↓ q T T T T F F T F F T T F F T F T T F F F F F T T

13

Logical operators: Conditional 2

  • Let p = “I am elected” and q = “I will lower taxes”
  • I state: p → q = “If I

am elected, then I will lower taxes”

  • Consider all

possibilities

  • Note that if p is false, then

the conditional is true regardless of whether q is true or false

p q p → q T T T T F F F T T F F T

14

Logical operators: Conditional 3

Conditional Inverse Converse Contra- positive p q ¬ p ¬ q p → q ¬ p →¬ q q → p ¬ q →¬ p

T T F F T T T T

T F F T F T T F

F T T F T F F T

F F T T T T T T

16

Logical operators: Bi-conditional 1

  • A bi-conditional means “ p if and only if q ”
  • Symbol: ↔
  • Alternatively, it means “(if p then q ) and (if q then p )”
  • p ↔ q ≡ p → q ∧ q →p
  • Note that a bi-conditional has the opposite truth values of the exclusive or

p q p ↔ q T T T T F F F T F F F T

17

Logical operators: Bi-conditional 2

  • Let p = “You take this class” and q = “You get a grade”
  • Then p ↔ q means “You take this class if and only if you get a grade”
  • Alternatively, it means “If you take this class, then you get a grade and if you get a grade then you take (took) this class”

p q p ↔ q T T T T F F F T F F F T

19

Precedence of operators

  • Just as in algebra, operators have

precedence

  • 4+32 = 4+(32), not (4+3)*
  • Precedence order (from highest to lowest):
  • The first three are the most important
  • This means that p ∨ q ∧ ¬ r → s ↔ t

yields: ( p ∨ ( q ∧ (¬ r ))) ↔ ( s → t )

  • Not is always performed before any other

operation

20

Translating English Sentences

  • Problem:
    • p = “It is below freezing”
    • q = “It is snowing”
  • It is below freezing and it is snowing
  • It is below freezing but not snowing
  • It is not below freezing and it is not snowing
  • It is either snowing or below freezing (or both)
  • If it is below freezing, it is also snowing
  • It is either below freezing or it is snowing, but it is not snowing if it is below freezing
  • That it is below freezing is necessary and sufficient for it to be snowing

p ∧ q p ∧¬ q ¬ p ∧¬ q p ∨ q p → q ( p ∨ q )∧( p →¬ q )

p ↔ q