LiCS-RSJ

Embed Size (px)

Citation preview

  • 7/29/2019 LiCS-RSJ

    1/61

    Ramprasad Joshi, September 12, 2013 Header - p. 1

    Logic in Computer Science

    CS/IS F214 Handout, Slides, and Notes

    Ramprasad Joshi

    BITS, Pilani - K. K. Birla Goa Campus

    http://www.bits-goa.ac.in/CSIS/CSIS.htm

    mailto:[email protected]://www.bits-goa.ac.in/CSIS/CSIS.htmhttp://www.bits-goa.ac.in/CSIS/CSIS.htmmailto:[email protected]
  • 7/29/2019 LiCS-RSJ

    2/61

    Handout Part II

    Handout

    Introduction

    Logic and Common Sense

    Formal Languages

    Ramprasad Joshi, September 12, 2013 Header - p. 2

    Handout Part II

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    3/61

    Handout Part II

    Handout

    Introduction

    Logic and Common Sense

    Formal Languages

    Ramprasad Joshi, September 12, 2013 Header - p. 3

    Handout-II

    In addition to Part -I (General Handout for all courses in theBulletin) this portion gives further details pertaining to thecourse.

    mailto:[email protected]://cs-is_f214_2013-14-semi-handout.pdf/http://cs-is_f214_2013-14-semi-handout.pdf/mailto:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    4/61

    Handout Part II

    Introduction

    Puzzles?

    Puzzles?

    Logic and Common Sense

    Formal Languages

    Ramprasad Joshi, September 12, 2013 Header - p. 4

    Introduction

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    5/61

    Handout Part II

    Introduction

    Puzzles?

    Puzzles?

    Logic and Common Sense

    Formal Languages

    Ramprasad Joshi, September 12, 2013 Header - p. 5

    Can you make sense of this?-I

    All men are mortal. Socrates is a man. So Socrates ismortal.

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    6/61

    Handout Part II

    Introduction

    Puzzles?

    Puzzles?

    Logic and Common Sense

    Formal Languages

    Ramprasad Joshi, September 12, 2013 Header - p. 5

    Can you make sense of this?-I

    All men are mortal. Socrates is a man. So Socrates ismortal.

    A mortal must die some time. So must Socrates.

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    7/61

    Handout Part II

    Introduction

    Puzzles?

    Puzzles?

    Logic and Common Sense

    Formal Languages

    Ramprasad Joshi, September 12, 2013 Header - p. 5

    Can you make sense of this?-I

    All men are mortal. Socrates is a man. So Socrates ismortal.

    A mortal must die some time. So must Socrates.

    All men are mortal. Can we say anything about womenbeing mortal or not from this?

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    8/61

    Handout Part II

    Introduction

    Puzzles?

    Puzzles?

    Logic and Common Sense

    Formal Languages

    Ramprasad Joshi, September 12, 2013 Header - p. 5

    Can you make sense of this?-I

    All men are mortal. Socrates is a man. So Socrates ismortal.

    A mortal must die some time. So must Socrates.

    All men are mortal. Can we say anything about womenbeing mortal or not from this?

    Belgaumskis are slard after they are teahed. If they arelooced, they become hoft. Tawer psees from them if you puttheiwgh on them while they are hoft. Chikkodiovs areBelgaumskis. Tuppappa is a Chikkodiov having tonten onhim while being looced. If tonten is a theiwgh, will Tuppappapsee tawer?

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    9/61

    Handout Part II

    Introduction

    Puzzles?

    Puzzles?

    Logic and Common Sense

    Formal Languages

    Ramprasad Joshi, September 12, 2013 Header - p. 6

    Can you make sense of this?-II

    Naistib must take his cat, hen, and grain-sack across theriver in a boat that can carry at most one of the three alongwith him. The cat is looking for the first opprtunity when

    Naistib is not around to eat the hen. The hen is constantlytrying to peck the sack and he is constantly shooing it away.Naistib does not want to lose his grain or poultry. Can hecross the river with them and the cat?

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    10/61

    Handout Part II

    Introduction

    Puzzles?

    Puzzles?

    Logic and Common Sense

    Formal Languages

    Ramprasad Joshi, September 12, 2013 Header - p. 6

    Can you make sense of this?-II

    Naistib must take his cat, hen, and grain-sack across theriver in a boat that can carry at most one of the three alongwith him. The cat is looking for the first opprtunity when

    Naistib is not around to eat the hen. The hen is constantlytrying to peck the sack and he is constantly shooing it away.Naistib does not want to lose his grain or poultry. Can hecross the river with them and the cat?

    ... what the king fundamentally insisted upon was that hisauthority should be respected. He tolerated nodisobedience. He was an absolute monarch. But, becausehe was a very good man, he made his orders reasonable.

    If I ordered a general, he would say, by way of example, if Iordered a general to change himself into a sea bird, and ifthe general did not obey me, that would not be the fault ofthe general. It would be my fault.

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    11/61

    Handout Part II

    Introduction

    Puzzles?

    Puzzles?

    Logic and Common Sense

    Formal Languages

    Ramprasad Joshi, September 12, 2013 Header - p. 6

    Can you make sense of this?-II

    Naistib must take his cat, hen, and grain-sack across theriver in a boat that can carry at most one of the three alongwith him. The cat is looking for the first opprtunity when

    Naistib is not around to eat the hen. The hen is constantlytrying to peck the sack and he is constantly shooing it away.Naistib does not want to lose his grain or poultry. Can hecross the river with them and the cat?

    ... what the king fundamentally insisted upon was that hisauthority should be respected. He tolerated nodisobedience. He was an absolute monarch. But, becausehe was a very good man, he made his orders reasonable.

    If I ordered a general, he would say, by way of example, if Iordered a general to change himself into a sea bird, and ifthe general did not obey me, that would not be the fault ofthe general. It would be my fault.

    What is common between all these quizzical paragraphs?

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    12/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Aristotle

    Tom Paine

    Formal Languages

    Ramprasad Joshi, September 12, 2013 Header - p. 7

    Logic and Common Sense

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    13/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Aristotle

    Tom Paine

    Formal Languages

    Ramprasad Joshi, September 12, 2013 Header - p. 8

    The Law of the Excluded Middle

    In symbolic logic, it is assumed that there are two distinctvalues, and no more.

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    14/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Aristotle

    Tom Paine

    Formal Languages

    Ramprasad Joshi, September 12, 2013 Header - p. 8

    The Law of the Excluded Middle

    In symbolic logic, it is assumed that there are two distinctvalues, and no more.

    Each symbol takes either one or the other of the two values.

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    15/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Aristotle

    Tom Paine

    Formal Languages

    Ramprasad Joshi, September 12, 2013 Header - p. 8

    The Law of the Excluded Middle

    In symbolic logic, it is assumed that there are two distinctvalues, and no more.

    Each symbol takes either one or the other of the two values.

    No symbol can take more than one value, nor can it take anyother value than the designated two values.

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    16/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Aristotle

    Tom Paine

    Formal Languages

    Ramprasad Joshi, September 12, 2013 Header - p. 8

    The Law of the Excluded Middle

    In symbolic logic, it is assumed that there are two distinctvalues, and no more.

    Each symbol takes either one or the other of the two values.

    No symbol can take more than one value, nor can it take anyother value than the designated two values.

    Each symbol must take one of the two values; it cannot beindeterminate.

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    17/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Aristotle

    Tom Paine

    Formal Languages

    Ramprasad Joshi, September 12, 2013 Header - p. 8

    The Law of the Excluded Middle

    In symbolic logic, it is assumed that there are two distinctvalues, and no more.

    Each symbol takes either one or the other of the two values.

    No symbol can take more than one value, nor can it take anyother value than the designated two values.

    Each symbol must take one of the two values; it cannot beindeterminate.

    In sum: each statement is either true or false; it cannot beboth; it cannot be none.

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    18/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Aristotle

    Tom Paine

    Formal Languages

    Ramprasad Joshi, September 12, 2013 Header - p. 8

    The Law of the Excluded Middle

    In symbolic logic, it is assumed that there are two distinctvalues, and no more.

    Each symbol takes either one or the other of the two values.

    No symbol can take more than one value, nor can it take anyother value than the designated two values.

    Each symbol must take one of the two values; it cannot beindeterminate.

    In sum: each statement is either true or false; it cannot beboth; it cannot be none.

    It is important to understand the implication: we cannot, forinstance, talk about a photon being a particle and a wave atonce. They must be two difference entities, or they mustreside in two different worlds.

    C S

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    19/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Aristotle

    Tom Paine

    Formal Languages

    Ramprasad Joshi, September 12, 2013 Header - p. 9

    Common Sense

    Wrote Tom Paine: One of the strongest NATURAL proofs ofthe folly of hereditary right in kings, is, that naturedisapproves it, otherwise she would not so frequently turn it

    into ridicule by giving mankind an ASS FOR A LION.

    C S

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    20/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Aristotle

    Tom Paine

    Formal Languages

    Ramprasad Joshi, September 12, 2013 Header - p. 9

    Common Sense

    Wrote Tom Paine: One of the strongest NATURAL proofs ofthe folly of hereditary right in kings, is, that naturedisapproves it, otherwise she would not so frequently turn it

    into ridicule by giving mankind an ASS FOR A LION. Here, words like natural proof, disapproves, frequently,

    etc. are telltale signs that this is a sentence in commonsense (indeed, in a pamphlet entitled Common Sense), but

    not in formal sense.

    C S

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    21/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Aristotle

    Tom Paine

    Formal Languages

    Ramprasad Joshi, September 12, 2013 Header - p. 9

    Common Sense

    Wrote Tom Paine: One of the strongest NATURAL proofs ofthe folly of hereditary right in kings, is, that naturedisapproves it, otherwise she would not so frequently turn it

    into ridicule by giving mankind an ASS FOR A LION. Here, words like natural proof, disapproves, frequently,

    etc. are telltale signs that this is a sentence in commonsense (indeed, in a pamphlet entitled Common Sense), but

    not in formal sense. Here is an answer to the biggest problem of Computer

    Science of today ;-) P = NP iff N = 1 P = 0

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    22/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal LanguagesSymbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proofThe first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 10

    Formal Languages

    The Players

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    23/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal LanguagesSymbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proofThe first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 11

    The Players

    Symbols are letters A . . . Z , a . . . z and their extensionsA1, A2, . . . , B1, B2, . . . , . . . , Z 1, Z2, . . . , . . . , . . .

    The Players

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    24/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal LanguagesSymbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proofThe first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 11

    The Players

    Symbols are letters A . . . Z , a . . . z and their extensionsA1, A2, . . . , B1, B2, . . . , . . . , Z 1, Z2, . . . , . . . , . . .

    T and F are special symbols, in that all other symbols are

    equivalent to either one of them.

    The Players

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    25/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal LanguagesSymbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proofThe first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 11

    The Players

    Symbols are letters A . . . Z , a . . . z and their extensionsA1, A2, . . . , B1, B2, . . . , . . . , Z 1, Z2, . . . , . . . , . . .

    T and F are special symbols, in that all other symbols are

    equivalent to either one of them. Operators are or,and,not.

    The Players

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    26/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal LanguagesSymbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 11

    The Players

    Symbols are letters A . . . Z , a . . . z and their extensionsA1, A2, . . . , B1, B2, . . . , . . . , Z 1, Z2, . . . , . . . , . . .

    T and F are special symbols, in that all other symbols are

    equivalent to either one of them. Operators are or,and,not.

    Other interesting operators (called syntactic sugar) are:implies , impliedby , equivalent , nor , nand ,xor.

    The Rules of the Game

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    27/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 12

    The Rules of the Game

    Buchstaben (Alphabet)by Hermann Hessetranslation by Richard S. Ellis

    We now and then take pen in handAnd make some marks on empty paper.Just what they say, all understand.It is a game with rules that matter.

    The Rules of the Game

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    28/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 12

    The Rules of the Game

    Buchstaben (Alphabet)by Hermann Hessetranslation by Richard S. Ellis

    We now and then take pen in handAnd make some marks on empty paper.Just what they say, all understand.It is a game with rules that matter.

    formula ::= atomformula ::= formulaformula ::= (formula)formula ::= formula op formulaatom ::= a|b| . . . |a

    1|a2

    | . . . |b1

    | . . . |p for any p Pop ::= | | | | | | |

    Structural Induction

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    29/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 13

    Structural Induction

    P is all atoms. F is all formulas, including atoms. Anassignment is a mapping : P {T, F}. An interpretationis an extension of such an assignment to : F {T, F}

    Structural Induction

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    30/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 13

    Structural Induction

    P is all atoms. F is all formulas, including atoms. Anassignment is a mapping : P {T, F}. An interpretationis an extension of such an assignment to : F {T, F}

    Each formula is either an atom, a negation of a formula, or acomposite of two formulas joined by an operator.

    Structural Induction

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    31/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proofThe first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 13

    Structural Induction

    P is all atoms. F is all formulas, including atoms. Anassignment is a mapping : P {T, F}. An interpretationis an extension of such an assignment to : F {T, F}

    Each formula is either an atom, a negation of a formula, or acomposite of two formulas joined by an operator.

    To show a property(A) for any A U F, it is sufficient toshow that:

    Structural Induction

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    32/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 13

    Structural Induction

    P is all atoms. F is all formulas, including atoms. Anassignment is a mapping : P {T, F}. An interpretationis an extension of such an assignment to : F {T, F}

    Each formula is either an atom, a negation of a formula, or acomposite of two formulas joined by an operator.

    To show a property(A) for any A U F, it is sufficient toshow that:

    1. For any atom p U, property(p) holds.

    Structural Induction

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    33/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 13

    Structural Induction

    P is all atoms. F is all formulas, including atoms. Anassignment is a mapping : P {T, F}. An interpretationis an extension of such an assignment to : F {T, F}

    Each formula is either an atom, a negation of a formula, or acomposite of two formulas joined by an operator.

    To show a property(A) for any A U F, it is sufficient toshow that:

    1. For any atom p U, property(p) holds. 2. If for any A U, property(A) holds and A U, then,

    necessarily, property(A) can be shown.

    Structural Induction

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    34/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 13

    P is all atoms. F is all formulas, including atoms. Anassignment is a mapping : P {T, F}. An interpretationis an extension of such an assignment to : F {T, F}

    Each formula is either an atom, a negation of a formula, or acomposite of two formulas joined by an operator.

    To show a property(A) for any A U F, it is sufficient toshow that:

    1. For any atom p U, property(p) holds. 2. If for any A U, property(A) holds and A U, then,

    necessarily, property(A) can be shown.

    3. If for any A, B U, property(A) and property(B) hold,then, necessarily, whenever A B U for each {, , , , , , , }, property(A B) can be shown.

    Structural Induction

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    35/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 13

    P is all atoms. F is all formulas, including atoms. Anassignment is a mapping : P {T, F}. An interpretationis an extension of such an assignment to : F {T, F}

    Each formula is either an atom, a negation of a formula, or acomposite of two formulas joined by an operator.

    To show a property(A) for any A U F, it is sufficient toshow that:

    1. For any atom p U, property(p) holds. 2. If for any A U, property(A) holds and A U, then,

    necessarily, property(A) can be shown.

    3. If for any A, B U, property(A) and property(B) hold,

    then, necessarily, whenever A B U for each {, , , , , , , }, property(A B) can be shown.

    Principal Operator: The operator at the root of the parse treeof a formula.

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    36/61

    Satisfiability, Validity, Consequence

    mailto:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    37/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 15

    y y q

    A propositional formula A is satisfiable iff there is aninterpretation such that (A) = T. Such a is called amodel for A. A is valid, or a tautology, denoted |= A, iff

    (A) = T for all interpretations .

    Satisfiability, Validity, Consequence

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    38/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 15

    A propositional formula A is satisfiable iff there is aninterpretation such that (A) = T. Such a is called amodel for A. A is valid, or a tautology, denoted |= A, iff

    (A) = T for all interpretations . A propositional formula A is unsatisfiableor contradictory or

    invalid, iff it is not satisfiable. A is not-valid or falsifiable,denoted |= A iff it is not valid.

    The Universe of Formulas

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    39/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 16

    Each formula can be negated by just putting the negationoperator before it. Thus each valid formula has a negationthat is a contradiction, and vice versa. All formulas that are

    satisfiable as well as falsifiable will form a middle space,each such formula has its negation also in this middle space.We can show the space of formulas divided up like thesymmetric figure in Figure 1:

    Valid

    Satisfia

    bleas

    well

    asfalsifi

    able

    Satisfiable

    = Not Invalid

    Falsifiable

    = Not valid

    Contradictory

    Invalid

    Figure 1: The Universe of Formulas

    Structural Induction Example

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    40/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 17

    Define binary trees as follows: 1. is a binary tree. 2. If Land R are binary trees, then (L, R) is a binary tree. 3.Nothing else except one that satisfies 1 or 2 above is a

    binary tree.

    Structural Induction Example

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    41/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 17

    Define binary trees as follows: 1. is a binary tree. 2. If Land R are binary trees, then (L, R) is a binary tree. 3.Nothing else except one that satisfies 1 or 2 above is a

    binary tree. Let the set of binary trees be B. Define the height function

    H : B N as follows: H() = 0;H((L, R)) = max(H(L), H(R)) + 1.

    Structural Induction Example

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    42/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 17

    Define binary trees as follows: 1. is a binary tree. 2. If Land R are binary trees, then (L, R) is a binary tree. 3.Nothing else except one that satisfies 1 or 2 above is a

    binary tree. Let the set of binary trees be B. Define the height function

    H : B N as follows: H() = 0;H((L, R)) = max(H(L), H(R)) + 1.

    Similarly define the size function S : B N as follows:S() = 0; S((L, R)) = S(L) + S(R) + 1.

    Structural Induction Example

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    43/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 17

    Define binary trees as follows: 1. is a binary tree. 2. If Land R are binary trees, then (L, R) is a binary tree. 3.Nothing else except one that satisfies 1 or 2 above is a

    binary tree. Let the set of binary trees be B. Define the height function

    H : B N as follows: H() = 0;H((L, R)) = max(H(L), H(R)) + 1.

    Similarly define the size function S : B N as follows:S() = 0; S((L, R)) = S(L) + S(R) + 1.

    To Prove:

    H(T) S(T) 2H(T) 1 (1)

    S.I. contd...

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    44/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 18

    H() = 0; H((L, R)) = max(H(L), H(R)) + 1.

    S.I. contd...

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    45/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 18

    H() = 0; H((L, R)) = max(H(L), H(R)) + 1.

    S() = 0; S((L, R)) = S(L) + S(R) + 1.

    S.I. contd...

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    46/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 18

    H() = 0; H((L, R)) = max(H(L), H(R)) + 1.

    S() = 0; S((L, R)) = S(L) + S(R) + 1.

    To Prove: T = H(T) + 1 S(T) 2H(T) 1

    S.I. contd...

    mailto:[email protected]:[email protected]://showbookmarks/http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    47/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 18

    H() = 0; H((L, R)) = max(H(L), H(R)) + 1.

    S() = 0; S((L, R)) = S(L) + S(R) + 1.

    To Prove: T = H(T) + 1 S(T) 2H(T) 1

    Proof: By Structural Induction. Base Case: For T0 = it istrivially true; or for T1 = (, ),H(T1) = max(0, 0) + 1 = 0 + 1 = 1 andS(T1) = 0 + 0 + 1 = 1, hence the result is true.

    S.I. contd...

    mailto:[email protected]:[email protected]://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    48/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 18

    H() = 0; H((L, R)) = max(H(L), H(R)) + 1.

    S() = 0; S((L, R)) = S(L) + S(R) + 1.

    To Prove: T = H(T) + 1 S(T) 2H(T) 1

    Proof: By Structural Induction. Base Case: For T0 = it istrivially true; or for T1 = (, ),H(T1) = max(0, 0) + 1 = 0 + 1 = 1 andS(T1) = 0 + 0 + 1 = 1, hence the result is true.

    Induction Hypothesis: Assume that for T = Tk, 1 k h,such that H(Tk) = k, the result is true.

    S.I. contd...

    mailto:[email protected]:[email protected]://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    49/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 19

    To Prove: H(T) S(T) 2H(T) 1

    S.I. contd...

    mailto:[email protected]:[email protected]://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    50/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 19

    To Prove: H(T) S(T) 2H(T) 1

    Proof: By Structural Induction. Base Case: For T0 = orT1 = (, ), the result is true.

    S.I. contd...

    mailto:[email protected]:[email protected]://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    51/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 19

    To Prove: H(T) S(T) 2H(T) 1

    Proof: By Structural Induction. Base Case: For T0 = orT1 = (, ), the result is true.

    Induction Hypothesis: Assume that for T = Tk, 1 k h,such that H(Tk) = k, the result is true.

    S.I. contd...

    mailto:[email protected]:[email protected]://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    52/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 19

    To Prove: H(T) S(T) 2H(T) 1

    Proof: By Structural Induction. Base Case: For T0 = orT1 = (, ), the result is true.

    Induction Hypothesis: Assume that for T = Tk, 1 k h,such that H(Tk) = k, the result is true.

    Induction Step: Let T = Th+1, with H(Th+1) = h + 1. Sinceh > 0, = Th+1 = (L, R). h + 1 = max(H(L), H(R)) + 1, H(L) h and H(R) h; and, H(L) = h H(R) = h. LetH(L) = h and 0 H(R) h. By the I.H., h S(L) 2h 1

    and 0 S(R) 2h 1. Now S(Th+1) = S(L) + S(R) + 1.Combining with the inequalities just proved,

    h + 0 + 1 S(Th+1) 2h

    1 + 2h

    1 + 1, hence(h + 1) S(Th+1) 2

    (h+1) 1. Thus assuming the result forTk, 1 k h leads to the result for Th+1.

    More Structural Induction

    mailto:[email protected]:[email protected]://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    53/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 20

    Let us take a subset C B: T C T = (T = (L, R) ({L, R} C) (|H(L) H(R)| 1)). Such trees arehistorically called AVL trees, but if that makes you skitter

    about frantically to google up acronyms, confusing you moreand leading to a stampede and a scare, we might as well callthem LVA trees or Yranib trees. The name does not matter, arose with the name esor would also smell like a rose andlook like a rose.

    More Structural Induction

    mailto:[email protected]:[email protected]://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    54/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 20

    Let us take a subset C B: T C T = (T = (L, R) ({L, R} C) (|H(L) H(R)| 1)). Such trees arehistorically called AVL trees, but if that makes you skitter

    about frantically to google up acronyms, confusing you moreand leading to a stampede and a scare, we might as well callthem LVA trees or Yranib trees. The name does not matter, arose with the name esor would also smell like a rose andlook like a rose.

    To prove: T C H(T) c log(S(T) + 1) for some c > 0,not dependent on H(T) (or for that matter not dependent anyother quantity related to T; dependent only on the fact that Tis in C).

    More Structural Induction

    mailto:[email protected]:[email protected]://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    55/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 20

    Let us take a subset C B: T C T = (T = (L, R) ({L, R} C) (|H(L) H(R)| 1)). Such trees arehistorically called AVL trees, but if that makes you skitterabout frantically to google up acronyms, confusing you moreand leading to a stampede and a scare, we might as well callthem LVA trees or Yranib trees. The name does not matter, arose with the name esor would also smell like a rose andlook like a rose.

    To prove: T C H(T) c log(S(T) + 1) for some c > 0,not dependent on H(T) (or for that matter not dependent anyother quantity related to T; dependent only on the fact that Tis in C).

    Proof: A little harder, because c is not known. So whats thetrick now?

    More Structural Induction

    mailto:[email protected]:[email protected]://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    56/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 20

    Let us take a subset C B: T C T = (T = (L, R) ({L, R} C) (|H(L) H(R)| 1)). Such trees arehistorically called AVL trees, but if that makes you skitterabout frantically to google up acronyms, confusing you moreand leading to a stampede and a scare, we might as well callthem LVA trees or Yranib trees. The name does not matter, arose with the name esor would also smell like a rose andlook like a rose.

    To prove: T C H(T) c log(S(T) + 1) for some c > 0,not dependent on H(T) (or for that matter not dependent anyother quantity related to T; dependent only on the fact that Tis in C).

    Proof: A little harder, because c is not known. So whats thetrick now?

    For the base case, take or (, ). Any one will do. Whatnext?

    More S. I. ...

    mailto:[email protected]:[email protected]://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    57/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 21

    I. H. : For Tk C, 0 k n, such that S(Tk) = k,H(Tk) c log(k + 1).

    More S. I. ...

    mailto:[email protected]:[email protected]://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    58/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    Symbols

    Syntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 21

    I. H. : For Tk C, 0 k n, such that S(Tk) = k,H(Tk) c log(k + 1).

    I. S. : Tn+1 = (L, R) such that S(Tn+1) = n + 1. Let

    H(Tn+1) = h. Now Tn+1 C B, max(H(L), H(R)) = H(Tn+1) 1 = h 1, as alsomin(H(L), H(R)) H(Tn+1) 2 = h 2. Nown + 1 max(S(L), S(R)) + 1 hence the I.H. applies to bothL, R. Let hL, hR be the heights and sL, sR be the sizes ofL, R respectively.

    More S. I. ...

    mailto:[email protected]:[email protected]://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    59/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    SymbolsSyntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 21

    I. H. : For Tk C, 0 k n, such that S(Tk) = k,H(Tk) c log(k + 1).

    I. S. : Tn+1 = (L, R) such that S(Tn+1) = n + 1. Let

    H(Tn+1) = h. Now Tn+1 C B, max(H(L), H(R)) = H(Tn+1) 1 = h 1, as alsomin(H(L), H(R)) H(Tn+1) 2 = h 2. Nown + 1 max(S(L), S(R)) + 1 hence the I.H. applies to bothL, R. Let hL, hR be the heights and sL, sR be the sizes ofL, R respectively.

    Thus h 2 min(hL, hR) max(hL, hR) = h 1. By I.H.h 2 c log(min(sL, sR) + 1) andh 1 c log(max(sL, sR) + 1).

    mailto:[email protected]:[email protected]
  • 7/29/2019 LiCS-RSJ

    60/61

    More S. I. ...

    http://showbookmarks/
  • 7/29/2019 LiCS-RSJ

    61/61

    Handout Part II

    Introduction

    Logic and Common Sense

    Formal Languages

    SymbolsSyntax

    Syntax

    Interpretation

    Interpretation

    Symmetry

    A Proof

    The first proof

    The first proof

    Another Proof

    The second proof

    Ramprasad Joshi, September 12, 2013 Header - p. 21

    I. H. : For Tk C, 0 k n, such that S(Tk) = k,H(Tk) c log(k + 1).

    I. S. : Tn+1 = (L, R) such that S(Tn+1) = n + 1. Let

    H(Tn+1) = h. Now Tn+1 C B, max(H(L), H(R)) = H(Tn+1) 1 = h 1, as alsomin(H(L), H(R)) H(Tn+1) 2 = h 2. Nown + 1 max(S(L), S(R)) + 1 hence the I.H. applies to bothL, R. Let hL, hR be the heights and sL, sR be the sizes ofL, R respectively.

    Thus h 2 min(hL, hR) max(hL, hR) = h 1. By I.H.h 2 c log(min(sL, sR) + 1) andh 1 c log(max(sL, sR) + 1).

    min(sL, sR) 2h2

    c 1 and max(sL, sR) 2h1

    c .

    But 2 min(sL, sR) + 1 n + 1 2 max(sL, sR) + 1. Simplealgebra gives h c log(n + 2) c + 2 h + 1. This proves

    the result for any c 2, independent of n.

    mailto:[email protected]:[email protected]