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

An introduction to boolean logic, focusing on propositions, boolean variables, and logical operators such as not, and, or, exclusive or, nand, nor, conditional, and bi-conditional. It includes examples and explanations of each operator, as well as their precedence and logical equivalences.

Typology: Slides

2012/2013

Uploaded on 04/27/2013

ashwini
ashwini 🇮🇳

4.5

(18)

167 documents

1 / 50

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Boolean Logic
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32

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 &&

  • pq = “Today is Friday and

today is my birthday”

p q pq 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 ||

  • pq = “Today is Friday or

today is my birthday (or possibly both)”

p q pq 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 ≡ ¬( pq )
    • Nor: pq ≡ ¬( pq )

p q pq pq p | q pq 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: pq = “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 pq 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 pq ¬ p →¬ q qp ¬ 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 )”
  • pqpqq →p
  • Note that a bi-conditional has the opposite truth values of the exclusive or

p q pq 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 pq 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 pq 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 pq ∧ ¬ rst

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

pq p ∧¬ q ¬ p ∧¬ q pq pq ( pq )∧( p →¬ q )

pq