1 / 100

Computing Fundamentals 1 Lecture 2

Computing Fundamentals 1 Lecture 2. Lecturer: Patrick Browne http://www.comp.dit.ie/pbrowne/ Room K308 Based on Chapter 2. A Logical approach to Discrete Math By David Gries and Fred B. Schneider. Boolean Expressions. Boolean constants: true and false .

daw
Télécharger la présentation

Computing Fundamentals 1 Lecture 2

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computing Fundamentals 1Lecture 2 Lecturer: Patrick Browne http://www.comp.dit.ie/pbrowne/ Room K308 Based on Chapter 2. A Logical approach to Discrete Math By David Gries and Fred B. Schneider

  2. Boolean Expressions • Boolean constants: true and false. • Boolean variables can only have values true or false. • Boolean operators: ,, ,  , , ˅, ˄. • Expressions are of type Boolean (or sortBool in CafeOBJ, or type bool in Python).

  3. Truth table for  and identity (id) There are as many unary truth-functions as there are different ways to fill in a two row column in a truth-table. For unary connectives, there are 2^(2^1)=4, for binary connectives, 2^(2^2)=16, for ternary connectives, 2^(2^3), and so on)

  4. Unary Op. Truth Table • The previous TT provides a complete enumeration of the Boolean operations with one argument (unary operators). The first and last operation results do not depend on the argument, they have no names. The identity (id) operation returns the argument, and negation or not operation () returns the constant that is not the argument. The truth table for Boolean operations with two arguments is shown in the next slide.

  5. Truth table for two argument ops

  6. A look at implication • While the TTs for ˅ and ˄ are symmetric and fairly intuitive the TT for implication requires some discussion. • All States True States • T premise implies a T conclusion, therefore T -> T is T; • T premise cannot imply a F conclusion, therefore T -> F is F • and 4. You can conclude anything from a false assumption, so F -> anything is T. • The value of marked conclusions (some states of Q) doesn’t affect the value of entire proposition "4 is odd => 4 is even"  !!!

  7. Implication with constants T/F and variables P/Q

  8. A look at implication • Logicians claim that the TT for implication is consistent. • P is stronger than Q, the implication is true only once when P is true, twice when Q is true • Q is weaker than P • All States True States

  9. Strong and Weak assertions • Definition: If P and Q are two assertions, then P is stronger than Q if P  Q. If P is stronger than Q, then Q is weaker than P. • Example: i<0 (P) is stronger than i<1(Q) because i<0  i<1. Fewer states satisfy i<0than satisfy i<1. • Stronger means more selective or specific. • Weaker means more frequent or general.

  10. Binary Op Truth Table(1) • The TT on slide 5 provide a complete enumeration of the Boolean operations with two arguments (binary operators). Eight of the infix ops have names. • b = c “b equals c” • b  c “b differs c” (AKA exclusive or, XOR) • b  c “b equivales c” or b and c are equivalent. The Boolean expression b  c is evaluate exactly as b=c, except that can be used only when b and c are Boolean expressions (= can be used for arithmetic equality e.g. 2 = 1 + 1). • b  c “the inequivalence of b and c”, again strictly for Boolean operands.

  11. Binary Op Truth Table(2) • b ˄ c conjunction or AND, &, or && • b ˅ c disjunction or OR, || • bc implication. “b implies c”, “if b then c”. b is called the antecedent c is called the consequent • bc consequence. “b follows from c” b is called the consequent c is called the antecedent

  12. Binary Op Truth Table(2) • Alternative symbols for equivalence: “x if and only if y” iff  <->  • The last symbol is used in the course text. The should not be confused with the CafeOBJ equality operation ==. • CafeOBJ’s BOOL module uses iff for equivalence. • CafeOBJ’s PROPC module uses <-> for equivalence. • Check the definition in CafeOBJ (note spaces): • open BOOL • show op (_ iff _)

  13. Evaluating Truth Tables • In addition to defining Boolean operators TT can be used to compute the value of a Boolean expression in every state. They offer a decision procedure. • The TT on the following slide gives the value of : p ˅(q ˄r) • The precedence of operators are described at: http://www.cs.cornell.edu/Info/People/gries/Logic/Prec.html • A precedence specifies the order of evaluation of various operations (lower the number the higher the precedence) • Note the precedence rules may differ in CafeOBJ. This can be check with the show op or show module command.

  14. Evaluating Truth Tables

  15. Truth Table Generators • b  ( b ˅ c) • b (b ˅ c) • http://turner.faculty.swau.edu/mathematics/materialslibrary/truth/

  16. Truth Table Example • Is b (b ˅ c) a tautology? • One solution is to draw TT of • b (b ˅ c) b c b (b ˅ c)b (b ˅ c) t t f t t t f f t t f t t t t f f t f f

  17. Table Example Is b  ( b ˅ c) satisfiable? Satisfiable means at lease one solution • b c b ( b ˅ c) (b  ( b ˅ c)) • t t f t f • t f f t f • f t t t t • f f t f f

  18. Equality versus Equivalence • The Boolean expression a  b is evaluated exactly the same as a = b, except that  can only be used when b and c are Boolean expressions. • They each have different precedence indicating which operation is done 1st , 2nd , 3rd , etc.: = (arithmetic) higher precedence (done before  )  (Boolean) lower precedence (done last) • Conjunctional and Associative: • Conjunctional: b = c < d abbreviation for (b = c) ˄ (c < d) • Associative: a  b  c, (a  b)  c, or a  (b  c)

  19. Satisfiability and validity • A Boolean expression P is satisfied in a state if its value is true in that state; P is satisfiable if there is a state in which it satisfied; and P is valid if it satisfied in every state. A valid Boolean expression is called a tautology. • If Pcannot be satisfied (e.g. A ˄ A) then P is always false for all values of A. If P is unsatisfiable it is called a contradiction. • A Boolean expression that is neither a tautology nor a contradiction is called a contingency orsatisfiable.

  20. Tautologies, satisfiable, contradiction

  21. Satisfiable and Valid1 • Recall, State is a list of variables with associated values. • pq is satisfiable because it is satisfied if (p, true) is in state S1. It is not valid in the state S2: (p,false), (q,false). • pp  p is valid in every state. • A formula is valid if and only if it is true under every interpretation.

  22. Duality • The dual PD of a Boolean expression P is constructed from P by interchanging the occurrences of: • true with false •  with  •  with  •  with  • ˄ with ˅ • Duality principle: the Boolean identity remains valid when both sides of a Boolean expression are replaced by their duals. The dual is not the negation of an expression, in the negation each p is replaced by p.

  23. Examples of Duals.

  24. Meta-theorem Duality (a) P is valid iffPDisvalid (b) (P  Q) is valid iffPD  QDis valid

  25. Using duality to generate valid expression

  26. Using duality to generate valid expression

  27. Modelling English propositions • A proposition can be interpreted as being either true or false. For example: • “Henry VIII had one son and Cleopatra had two” • We wish to translate English propositions to Boolean expressions because: • English is ambiguous, computers require logical clarity. • We can automate, analyse, reason about, simplify, and prove properties of Boolean expressions. • Rules of logic provide effective computer based way to simulate human reasoning (in English).

  28. Modelling English propositions • Issues involving inclusive vs. exclusive or are encountered when translating natural language to symbolic logic. We need to decide which "or" the natural language means. • Example: • I worked hard or I played the piano. • If I worked hard, then I will get a bonus. • I did not get a bonus.

  29. Converting English • Lets use: R: its raining, S: I’m going swimming. • Whether or not it is raining, I am going swimming:(R˅ R) S • If it is raining then I will not go swimming: R  ¬S • I will go swimming only if it is not raining: S  ¬R (see later)

  30. Converting English • If we write p -> q for the sentence “We will help you(p) only if you help us(q) ” • This is false only if “We help you”(p) is true, but “you help us”(q) is false.

  31. Logic and reality • Two ways to say the same thing? • To stay dry it is sufficient to have an umbrella. • If you have an umbrella, then you will stay dry: hu  sd • We will assume common sense meanings and avoid complex interpretation issues. Coventry and Garrod1

  32. Modelling English propositions • Let Boolean (or propositional) variable p denote the proposition: • p : Henry VIII had one son and Cleopatra had two. • The proposition p contains two sub-propositions: • x: Henry VIII had one son. • y: Cleopatra had two (sons). • x ˄ y

  33. Modelling English propositions • Negated Disjunction: English sentences containing neither and nor are treated as negated disjunction (i.e. a negative version of English or). • Example: [S1] John neither washed the car nor went to the cinema. • Let W =washed car, C = went to cinema. • S1 can be written as ¬(W˅ C) .

  34. Translating into a Boolean Expression • 1. Introduce a Boolean variable to denote sub-propositions. • 2. Replace these sub-propositions by their corresponding Boolean variables. • 3. Translate the result of step 2 into a Boolean expression, using obvious translations of English words into operators. See table on next slide.

  35. Translation of English Words

  36. Translation

  37. Translation

  38. Translating Or • We must distinguish between: • “inclusive or” (or, ˅) • “exclusive or” (xor, b c, b c ) • sometimes written ‘||’ or ⊕ • Would you like coffee or tea? • Would you like sugar or milk? • Is it raining or not raining? Yes! • Island of Liars and Truth tellers?

  39. Translating Can you express the above statement using just one logical connective? This example is from Logic Made Easy by Deborah J. Bennett

  40. Implication • “If a then b” becomes ab • “if you don’t eat your spinach I will scold you.” becomes: • es  sy • In English the following have same meaning: • “if you don’t eat your spinach then I will scold you.” • “eat your spinach or I will scold you.”

  41. Implication • This gives an equivalence: • es  sy • es ˅ sy • Hidden implication: • “Every name in the Dublin West Side telephone directory is in the Dublin directory” • “If a name is in the Dublin West Side telephone directory, then it is in the Dublin directory”.

  42. Contrapositive • Contrapositive: • e  s • s e

  43. Implies in terms of OR • implies: • e  s • OR • e˅ s • Use the on line truth tables to evaluate the expression in this lecture.

  44. Implication • In English the antecedent and the consequence can be switched, and the then dropped: • If you pay me then I will go. • I will go if you give me money. • There is a subtle difference between • ‘If’ meaning ‘in case’ or ‘in the event of’ • ‘If’ meaning ‘when’

  45. Implication • There is a subtle difference between • ‘If’ meaning ‘in case’ or ‘in the event of’ • ‘If’ meaning ‘when’ • “When the sun is shining, I feel happy” • Also, in logic a consequential relation is not necessary. • If I drink too much, then I get sick. • If pigs can fly, then 2+2=5. • Logic usually needs a sensible interpretation to be useful.

  46. Implication And Equivalence • The English “if” should be sometimes regarded as an equivalence. • “If two sides of a triangle are equal, the triangle is isosceles.” • Which as a definition could be stated: • t : two sides of the triangle are equal • is: the triangle is isosceles. • t  is

  47. Necessity • A necessary condition for the occurrence of a specified event is a circumstance in whose absencethe event cannot occur. Oxygen is necessary for combustion or oxygen is necessary for human life. • A necessary implication can be used to represent sub-set-of relation (AKA subsumption or “is kind of”). • Student => Person • Does “B is a kind of A” mean “All Bs are As”? • On Computing Fundamentals 1 it is necessary to pass the exam to pass the module. • What is sufficient to pass the module?

  48. All members of B are members of A All members of a subclass can be inferred to be members of its superclass. Given an object of type A it cannot be inferred that it is a B.

  49. Sufficient • A sufficient condition for the occurrence of an event is a circumstance in whose presence the event must occur. • If a conditional statement (a->b) is true then its antecedent is said to provide a sufficient condition for its consequent.

More Related