Csru 1100 structures of computer science
Download
1 / 37

CSRU 1100 Structures of Computer Science - PowerPoint PPT Presentation


  • 159 Views
  • Updated On :

CSRU 1100 Structures of Computer Science. Chapter 2 Logic . 1. Smullyan’s Island Puzzle. You meet two inhabitants of Smullyan’s Island (where each one is either a liar or a truth-teller). A says, “Either B is lying or I am” B says, “A is lying” Who is telling the truth ? . 2.

Related searches for CSRU 1100 Structures of Computer Science

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'CSRU 1100 Structures of Computer Science' - ainsley


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Csru 1100 structures of computer science l.jpg

CSRU 1100 Structures of Computer Science

Chapter 2

Logic

CS1100

1


Smullyan s island puzzle l.jpg
Smullyan’s Island Puzzle

  • You meet two inhabitants of Smullyan’s Island (where each one is either a liar or a truth-teller).

    • A says, “Either B is lying or I am”

    • B says, “A is lying”

  • Who is telling the truth ?

CS1100

2


Symbolic logic l.jpg
Symbolic logic

Numerical Algebra

Identify important parts of the numerical problem, assigning them to variables.

Use algebraic laws and formulas to solve the problem.

Symbolic Logic

Identify important parts of a logical argument, assign them to logical variables.

Use laws and formulas of symbolic logic to determine whether or not the logical argument is valid.

CS1100

3


Propositional logic l.jpg
Propositional Logic

  • A proposition is a statement which is either true or false

    • For example:

      • Ten is less than seven.

      • There are life forms on other planets in the universe.

      • A set of cardinality n has 2n subsets.

    • The followings are not propositions:

      • x2 = 16

      • How are you ?

      • x+y<10

CS1100

4


Proposition l.jpg
Proposition

  • Truth value of a proposition is either true or false.

  • We use logical variables, usually a lower case letter, to represent a proposition

    • p = “Ten is smaller than seven”

    • p has truth value of false, i.e., F.

CS1100

5


Logical operation negation l.jpg
Logical Operation : Negation

  • Negation ¬ applies to a single proposition

    • If p is true, then ¬ p is false

    • If p is false, then ¬ p is true

Truth Table of Negation Operator

CS1100


Logical operation negation7 l.jpg
Logical Operation : Negation

  • Example

    p = It will rain tomorrow.

    ¬ p = It will not rain tomorrow.

    • If it’s true that it will rain tomorrow, it is false that it will not rain tomorrow.

    • If it’s false that it will rain tomorrow, it is true that it will not rain tomorrow.

CS1100

7


Logical conjunction and l.jpg
Logical Conjunction (AND)

The conjunction is true if and only if both of two simple propositions are true; otherwise it’s false.

We use Λ to connect the two simple propositions:

CS1100

8


Logical conjunction example l.jpg
Logical Conjunction Example

I am a female andyou are a male.

  • p = I am a female.

  • q = You are a male.

  • p Λ q = I am a female and you are a male.

CS1100


Logical disjunction or l.jpg
Logical Disjunction (OR)

The conjunction is true whenever one or more of two simple propositions are true; otherwise it’s false.

The conjunction is false if and only if both of two simple propositions are false.

We use ν to connect the two simple propositions:

CS1100

10


Logical disjunction example l.jpg
Logical Disjunction Example

The computer is fast or the printer is fast.

  • p = The computer is fast

  • q = The printer is fast

  • p ν q = The computer is fast or the printer is fast.

CS1100


Inclusive or vs exclusive or xor l.jpg
Inclusive OR vs. Exclusive OR(XOR)

Inclusive OR is true when both of two simple compositions are true.

Exclusive OR (XOR) is true if and only if two simple propositions are not true or false at the same; otherwise it’s false.

We use ⊕ to connect the two simple propositions:

CS1100

12


Exclusive or example l.jpg
Exclusive OR Example

You may have coffee or you may have tea.

  • p = You may have coffee.

  • q = You may have tea.

  • p ⊕ q = You may have coffee or you may have tea.

CS1100


From english to propositions l.jpg
From English to Propositions

  • English words connecting the propositions might be “but”, “nevertheless”, “unfortunately”, …. For example:

    • Although the villain is French, the movie is good.

    • The hero is not American, but the villain is French.

  • As long as it means that both simple propositions are true, it’s a conjunction, i.e., AND. In proposition forms:

CS1100

14


Exercises l.jpg
Exercises

  • Introduce letters to stand for simple propositions, and write the following statements as complicated propositions:

    • Either the food is good or the service is excellent.

      p v q

    • He does the homework himself, or his girl friend helps him to do the homework.

      p ⊕ q

CS1100


Complicated proposition l.jpg
Complicated Proposition

  • One can connect propositions using “and”, “or”, “not”, “only if” …to form complicated proposition:

    • It will not rain tomorrow.

    • Fishes are jumping and the cotton is high.

  • Truth value of compound proposition depends on the truth value of the simple propositions involved.

CS1100

16


Complicated propositions l.jpg
Complicated Propositions

Connectives (¬, Λ,ν, etc.) can be applied to build complicated propositions, e.g.: ¬(p Λ q),

(¬p) ν (p Λ q)

CS1100

17


Order of evaluation l.jpg
Order of Evaluation

  • Parenthesized sub-expressions are evaluated first.

  • Operations have a precedence hierarchy:

    • Negations (¬) are done first.

    • Logical conjunction (Λ) are done next.

    • Inclusive OR and Exclusive OR(XOR) (ν, ⊕) are done next.

    • Other operations are done last.

  • For tie, follow left-to-right order.

CS1100


Truth table for complicated composition l.jpg
Truth Table for Complicated Composition

  • First fill in all possible input values

    • For 2 logical variables, p, q, there are 4 possible input values

  • Next, create a column for each complicated propositions following evaluation order.

  • Third, fill in the columns one by one, starting from simple ones

CS1100

19


Exercises20 l.jpg
Exercises

  • Write the following statement as complicated propositions and build the truth table for it:

    • Neither the food is good nor the service is excellent.

      (¬p) Λ (¬q)

CS1100


Conditional operation l.jpg
Conditional Operation

  • Complicated proposition

    • If it rains, then the ground is wet.

  • Logic implication

    • If p, then q

    • If part: hypothesis; Then part: conclusion

    • If the hypothesis happens, then the conclusion happens.

    • We use ⇒ to denote conditional operation.

      p ⇒ q

CS1100

21


Conditional operation22 l.jpg
Conditional Operation

“If I am elected, then I will lower the taxes next year”.

  • p: I am elected.

  • q: I will lower the taxes next year.

  • When p ⇒ q is T :

    • If p is true, then q must be true.

    • If p is false, we can derive anything !

CS1100

22


Understand conditional operation l.jpg
Understand Conditional Operation

  • Under what conditions, the promise is broken, i.e., the whole statement is false ?

    • When he is elected, but did not lower the taxes next year!

  • For all other scenarios, he keep promise, i.e. above statement is true.

    • He is elected, and lower the taxes next year

    • He is not elected, the taxes are lowered next year.

    • He is not elected, the taxes are not lowered next year.

CS1100

23


P q in english l.jpg
p ⇒ q in English

  • If p, then q.

    • If “it rains”, then “the ground is wet”.

  • p only if q.

    • “It rains” only if “the ground is wet”.

  • p implies q.

    • “It rains” implies “the ground is wet”.

  • p is sufficient for q.

    • “It rains” is a sufficient condition for “the ground is wet”.

  • q is necessary for p.

    • “The ground is wet” is necessary for “It rains”.

CS1100

24


Exercises write following in propositional forms l.jpg
Exercises: Write following in propositional forms

A good diet is a necessary condition for a healthy cat.

p⇒ q

The central switch goes down is a sufficient condition for network failure.

p⇒ q

CS1100

25


Order of evaluating complicated composition l.jpg
Order of Evaluating Complicated Composition

  • Parenthesized sub-expressions are evaluated first.

  • Operations have a precedence hierarchy:

    • Negations (¬) are done first.

    • Logical conjunction (Λ) are done next.

    • Inclusive OR and Exclusive OR(XOR) (ν, ⊕) are done next.

    • The conditional-type operations (⇒) are done last.

  • For tie, follow left-to-right order, except for the conditional operator ⇒, which is done in a right-to-left order. That is, p⇒ q ⇒r is interpreted as p ⇒ (q⇒ r)

CS1100


Exercise l.jpg
Exercise

  • Using letter f, b, s for the simple propositions, translate following into propositional forms:

    • Plentiful fish is a sufficient condition for bears to be happy.

    • Bears are happy only if there are plentiful fish.

    • Unhappy bears is a necessary condition for heavy snow.

CS1100

27


From english to propositional forms l.jpg
From English to Propositional Forms

  • Translate into English:

    1.

    2.

    Where A: the villain is French.

    B: the hero is American.

    C: the heroine is British

    D: the movie is good.

CS1100


Equivalent propositions l.jpg
Equivalent Propositions

  • Two propositional forms p and q are logically equivalent, we write p Ξ q.

    • p is true if and only if q is true.

    • Two equivalent forms have same truth value no matter what values the variables take.

    • To demonstrate two propositions are equivalent, show they have same truth-table.

CS1100


Logic equivalences 1 l.jpg
Logic Equivalences (1)

  • Double Negation

  • Negation

  • Idempotent

CS1100


Logic equivalences 2 l.jpg
Logic Equivalences (2)

  • Commutative

  • Associative

CS1100

31


Logic equivalences 3 l.jpg
Logic Equivalences (3)

  • Distributive

  • DeMorgan’s Laws

CS1100

32


Smullyan s island puzzle33 l.jpg
Smullyan’s Island Puzzle

  • You meet two inhabitants of Smullyan’s Island (where each one is either a liar or a truth-teller).

    • A says, “Either B is lying or I am”

    • B says, “A is lying”

  • Who is telling the truth ?

CS1100

33


How to solve such puzzle l.jpg
How to solve such puzzle ?

  • The key: each inhabitant is either a liar or a truth-teller. A liar always lies; a truth-teller always tells the truth.

  • Introduce simple propositions:

    • a: A is a truth-teller, i.e., A is telling the truth

    • b: B is a truth-teller

CS1100

34


Express statements as propositional forms l.jpg
Express statements as propositional forms

  • a: A is a truth-teller, i.e., A is telling the truth

  • b: B is a truth-teller

  • A says, “Either B is lying or I am”

    (¬b) ⊕ (¬a)

  • B says, “A is lying”

    ¬a

  • CS1100

    35


    Examine all possibilities l.jpg
    Examine all possibilities

    A is lying.

    Either B is lying or I am.

    Which scenarios, if any, are consistent, i.e., truth-tellers told

    the truth, and liars lied ?

    * A is truth-teller, B is a liar.

    CS1100

    36


    Smullyan s island puzzle37 l.jpg
    Smullyan’s Island Puzzle

    • You meet one inhabitant of Smullyan’s Island (where each inhabitant is either a liar or a truth-teller).

      • He says, “I am lying.”

    • Is he a truth-teller ?

    CS1100

    37


    ad