Professor: Munehiro Fukuda - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Professor: Munehiro Fukuda

Description:

Propositional logic is useful in CS to analyze such behavior of code ... Disjunction of p or q. Notations: p v q, p || q. True if either p or q or both are true ... – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 19
Provided by: munehir
Category:

less

Transcript and Presenter's Notes

Title: Professor: Munehiro Fukuda


1
CSS342 Propositions
  • Professor Munehiro Fukuda

2
Introduction
  • Propositional logic is useful in CS to analyze
    such behavior of code portions.
  • Proposition a statement that is either true or
    false, but not both
  • Logic reasoning whether a consequence of given
    statements is correct, but not whether each
    statement is true.
  • Example
  • Proposition pAll mathematicians wear sandals. (A
    ? B)
  • Proposition qAnyone who wears sandals is an
    algebraist (B ? C)
  • From p and qAll mathematicians are algebraists.
    (A ? C)

3
Propositions
  • Examples
  • In math
  • The only positive integers that divide 7 are 1
    and 7 itself (true)
  • For every positive integer n, there is a prime
    number larger than n (true)
  • In history
  • Alfred Hitchcock won an Academy Award in 1940 for
    directing Rebecca (false, he has never won one
    for directing)
  • Seattle held the Worlds Fair, Expo 62 (true )
  • In programming languages
  • Boolean expressions in if-else, while, and for
    statements
  • for ( index 0 index lt 100 index )
  • .

A proposition
Not a proposition
4
Compound propositions
  • Conjunction of p and q
  • notations p q, p q
  • True only if both p and q are true
  • truth table
  • Disjunction of p or q
  • Notations p v q, p q
  • True if either p or q or both are true
  • truth table

p q p q
F F F
F T F
T F F
T T T
p q p v q
F F F
F T T
T F T
T T T
5
Binary Expressions in C Part1
  • How do you examine the behavior of if-else?
  • if ( a gt 1 a lt 100 )
  • true if 1 a 100
  • if ( a gt 1 a lt 100 )
  • always true

6
Negation
  • The negation of p
  • Notations p, not p, p !p
  • Truth table
  • Example
  • P 1 1 3 (false)
  • !p !(1 1 3) 1 1 ? 3 (true)

P !p
F T
T F
7
Boolean Algebra (Axioms)
  • When T true and F false
  • If p ? F then p T, If p ? T then p F
  • F F F, T T T
  • T T T, F F F
  • F T T F F
  • F T T F T
  • !T F, !F T

8
Boolean Algebra (Theorems)
  • When T true and F false
  • p q q p, p q q p
  • (p q) r p (q r), (p q ) r
    p (q r)
  • (p q) (p r) p q r, p q
    p r p (q r)
  • p F F, p T T
  • p T p, p F p
  • p !p F, p !p T
  • p p p, p p p
  • p (p q) p, p p q p
  • !(!p) p
  • p q !p p q

Commutative Law
Associative Law
Distributive Law
Complement Law
Square Law
Absorption Law
Double Negation
Consensus Law
9
Binary Expressions in C Part2
  • How do you examine the behavior of if-else
    statements?
  • Given two distance objects, d1 and 2, if ( d1 lt
    d2 )

p d1.feet lt d2.feet q d1.feet d2.feet a
d1.inches lt d2.inches b d1.inches
d2.inches c d1.inches gt d2.inches
10
Binary Expressions in C Part2(Contd)
  • p d1.feet lt d2.feet
  • q d1.feet d2.feet
  • a d1.inches lt d2.inches
  • b d1.inches d2.inches
  • c d1.inches gt d2.inches
  • p a p b p c q a Distributive
    Law
  • p (a b c ) q a !a b c
  • p (a !a ) q a Complement Law
  • p T q a Theorem 6
  • p q a
  • ( d1.feet lt d2.feet ) ( d1.feet d2.feet )
    (d1.inches lt d2.inches)

bool Distanceoperator lt ( const Distance d2 )
const return ( feet lt d2.feet ) (feet
d2.feet) (inches lt d2.inches)
11
Conditional Propositions
  • Given two propositions such as p and q,
  • If p then q or p ? q
  • is called a conditional proposition.
  • P hypothesis, antecedent, or sufficient
    condition
  • Q conclusion, consequent, or necessary condition
  • if p then q p only if q called logically
    equivalent.
  • John may take CSS342 only if he advances to
    CSS343.
  • If John takes CSS342, he advances to CSS343.

q
p
12
Truth Table of Conditional Propositions
  • Chair statement if CSS gets an additional
    80,000, it will hire one new faculty member.
  • P CSS gets an additional 80,000.
  • Q CSS will hire one new faculty member.
  • If both p and q are true, the chair said a
    correct statement.
  • If p is true but q is false, the chair said a
    wrong statement.
  • If p is false, the chair is not responsible for
    his statement. We should regard it as true.

p q p ? q
T T T
T F F
F T T
F F T
13
Binary Expressions in C Part3
  • Two propositions
  • P 1 gt 2 Q 4 lt 8
  • According to the truth table,
  • p ? q is true, while q ? p is false.
  • C program
  • Whats the execution result?
  • Linux
  • 1 gt 2 -gt 4 lt 8 8
  • 4 lt 8 -gt 1 lt 2 0
  • Goodall
  • 1 gt 2 -gt 4 lt 8 0
  • 4 lt 8 -gt 1 lt 2 0
  • It depends on how result1 was
  • initialized.
  • In math, we consider all initialized in true.

void main( ) bool result1 if ( 1 gt 2 )
result1 4 lt 8 cout ltlt "1 gt 2 -gt 4 lt 8 " ltlt
result1 ltlt endl bool result2 if ( 4 lt 8 )
result2 1 gt 2 cout ltlt "4 lt 8 -gt 1 gt 2 "
ltlt result2 ltlt endl
14
Logical Equivalence
  • If two different compound propositions have the
    same truth values no matter what truth values
    their constituent propositions have, they are
    called
  • logically equivalent
  • Example
  • !(p q) !p !q (De Morgans Laws)

p q p q !(p q) !p !q !p !q
T T T F F F F
T F T F F T F
F T T F T F F
F F F T T T T
15
De Morgans Laws
  • !(p q) !p !q
  • Proved by the truth page on the previous page.
  • !(p q) !p !q

p q p q !(p q) !p !q !p !q
T T T F F F F
T F F T F T T
F T F T T F T
F F F T T T T
16
Biconditional Propositions
  • Given two propositions such as p and q,
  • p if and only if q p iff q or p ? q
  • is called a conditional proposition.
  • P a necessary and sufficient condition for Q
  • Q a necessary and sufficient condition for P

p q p ? q
T T T
T F F
F T F
F F T
17
Biconditional Propositions Proof of the Truth
Table
p q p ? q q ? p (p ? q) (q ? p) p ? q
T T T T T T
T F F T F F
F T T F F F
F F T T T T
18
Contrapositive
  • !q ?!p
  • The contrapositive of p ? q
  • Logically equivalent

p q p ? q !q !p !q ?!p
T T T F F T
T F F T F F
F T T F T T
F F T T T T
Write a Comment
User Comments (0)
About PowerShow.com