Logic Bram What is Logic? What is logic? • Logic is the study of valid reasoning. • That is, logic tries to establish criteria to decide whether some piece of reasoning is valid or invalid. • OK, so then what do we mean by ‘valid reasoning’? Reasoning • When we reason, we infer something (Y) from something else (X). • That is, when we reason, we go like: “Well, if such-and-such-and-so (X) is the case, then this-and-that-and-the-other-thing (Y) must also be the case ” • X and Y are thus things-that-can-be-thecase-or-not-be-the-case Reasoning Diagram: XY Good vs Bad Reasoning • What is the purpose of reasoning? Well, through reasoning, we try to gain new knowledge. • ‘Good’ reasoning is a piece of reasoning that successfully fulfills this purpose, i.e. that indeed gives us a new piece of knowledge. • ‘Bad’ reasoning is a piece of reasoning that, for some reason or other, is unsuccessful in this purpose. • What can go wrong? – Reasoning is invalid – Reasoning is unsound – Reasoning is circular Valid Reasoning • While in every piece of reasoning something is believed to follow from something else, this may in fact not be so. • Example: “If I win the lottery, then I’m happy. However, I did not win the lottery. Therefore, I am not happy.” • A piece of reasoning in which Y is believed to follow from X is valid if Y does indeed follow from X. Otherwise, the reasoning is said to be invalid. Sound Reasoning • Not all valid reasoning is good reasoning. • Example: “If I win the lottery, then I’ll be poor. So, since I did win the lottery, I am poor.” • This piece of reasoning is valid, but not very good, since part of what it assumed is absurd (‘If I win the lottery, I’ll be poor.’ Huh??) (also, I did not win the lottery ) • A piece of reasoning where Y is believed to follow from X is sound if a) it is valid, and b) X is true (or at least acceptable/plausible). Truth and Implication • Logic studies the validity of reasoning. • Logic does not study soundness. • Therefore, logic alone cannot tell us whether an argument is good. Hence, logic alone is not a guide to truth. • Instead, logic can tell us, assuming certain things to be true, what else will be true as well. Thus, logic is a guide to implication. Arguments • A piece of reasoning consists of a sequence of statements, some of which are claimed to follow from previous ones. That is, some are claimed to be inferred from others. • Example: “Either the housemaid or the butler killed Mr. X. However, if the housemaid would have done it, the alarm would have gone off, and the alarm did not go off. Therefore, the butler did it.” Arguments, Premises and Conclusion • In logic, pieces of reasoning are analyzed using the notion of an argument • An argument consists of any number of premises, and one conclusion • Again, in logic, we are merely interested in whether the conclusion follows from the premises: we are not interested in whether those premises are true or acceptable. • If you want to study all aspects of good reasoning, take my class Methods of Reasoning. Deductive Validity vs Inductive Validity • An argument is said to be deductively valid if, assuming the premises to be true, the conclusion must be true as well. • An argument is said to be inductively valid if, assuming the premises to be true, the conclusion is likely to be true as well. • For now, we will limit ourselves to deductive validity only! • If you want to study non-deductive reasoning, take my Methods of Reasoning class. Argument Forms • “If I win the lottery, then I am poor. I win the lottery. Hence, I am poor.” • This argument has the following abstract structure or form: “If P then Q. P. Hence, Q” • Any argument of the above form is valid, including “If flubbers are gook, then trugs are brig. Flubbers are gook. Hence, trugs are brig.”! • Hence, we can look at the abstract form of an argument, and tell whether it is valid without even knowing what the argument is about!! Formal Logic • Formal logic studies the validity of arguments by looking at the abstract form of arguments. • Formal logic always works in 2 steps: – Step 1: Use certain symbols to express the abstract form of premises and conclusion. – Step 2: Use a certain procedure to figure out whether the conclusion follows from the premises based on their symbolized form alone. Example Step 1: Symbolization • Use symbols to represent simple propositions: – H: The housemaid did it – B: The butler did it – A: The alarm went off • Use further symbols to represent complex claims: – H B: The housemaid or the butler did it – HA: If the housemaid did it, the alarm would go off – ~A: The alarm did not go off Example Step 2: Evaluation • One possible technique is to transform the symbolic representations using basic rules that reflect elementary valid inferences: 1. H B A. 2. HA A. 3. A A. 4. H 2, 3 MT 5. B 1, 4 DS Since every step along the way is an instance of an obviously valid inference, the conclusion does indeed follow from the premises. So, valid argument! Propositional Logic • Propositional Logic studies validity at the level of simple and compound propositions. • Simple proposition: An expression that has a truth value (a claim or a statement). E.g. “John is tall” • Compound proposition: An expression that combines simple propositions using truthfunctional connectives like ‘and’, ‘or’, ‘not’, and ‘if … then’. E.g. “John is tall and Mary is smart” Predicate Logic • Predicate Logic extends Propositional Logic by adding individuals, predicates, and quantifiers • Individuals: ‘John’, ‘Mary’ • Predicates: ‘tall’, ‘smart’ • Quantifiers: ‘all’, ‘some’ Just to Put Things in Perspective All arguments All deductive arguments All deductive arguments that can be analyzed using the formal logics we cover in class (And I’m probably optimistic here!) Uses of Formal Logic • Evaluation/Checking: – Formal logic can be used to evaluate the validity of arguments. • Clarification/Specification: – Formal logic can be used to express things in a precise and unambiguous way. • Demonstration/Proof: – Formal logic can be used to figure out what follows from a set of assumptions. • Computation/Automated Reasoning: – Formal logic can be used for machine reasoning. Logic, Computers, and AI • Formal logic has many connections to computers: – Computation: Formal logic played a crucial role in the development of the notion of ‘computation’ (See my class PHIL 4420 Computability and Logic) – Circuit Design: Formal logic can be used for circuit design (See CSCI 2500 Computer Organization) – Artificial Intelligence: Formal logic is central to many AI applications (See CSCI 4150 Artificial Intelligence) Boolean Connectives Propositional Logic • Propositional Logic is the logic involving complex claims as constructed from atomic claims and connectives. • Propositional Logic is not as powerful as Predicate Logic, but it has some powerful applications already. Truth-Functional Connectives and Boolean Connectives • Connectives are usually called truth-functional connectives: – This is because the truth value of a complex claim that has been constructed using a truth-functional connective is considered to be a function of the truth values of the claims that are being connected by that connective. – This is also why propositional logic is also called truth-functional logic. • For now, we will focus on three connectives: and, or, not; these are called the Boolean connectives. Negation • The claim “a is not to the right of b” is a complex claim. It consists of the atomic claim “a is to the right of b” and the truth-functional connective “not”. • We will call the above statement a negation. • To express negations, we use the symbol ‘’ • ‘’ should be put in front of what you want to be negated. • If we symbolize the atomic claim “a is to the right of b” as P, then the original claim will be symbolized as: P Truth-Table for Negation • ‘’ is truth-functional, since the truth-value of a negation is the exact opposite of the truth-value of the statement it negates. • We can express this using a truth table: P P T F F T Conjunction • The claim “a is to the right of b, and a is in front of b” is called a conjunction. • The two claims that are being conjuncted in a conjunction are called its conjuncts. • To express conjunctions, we will use the symbol ‘’ • ‘’ should be put between the two claims. • Thus, the above statement can be symbolized as: P Q Truth-Table for Conjunction • ‘’ is truth-functional, since a conjunction is true when both conjuncts are true, and it is false otherwise. • Again, we can show this using a truth table: P T T F F Q PQ T T F F T F F F Disjunction • The claim “a is to the right of b, or a is in front of b” is called a disjunction. • The two claims that are being disjuncted in a disjunction are called its disjuncts. • To express disjunctions, we will use the symbol ‘’ • ‘’ should be put between the two claims. • Thus, the above statement can be symbolized as: P Q Truth-Table for Disjunction • ‘’ is truth-functional, since a disjunction is true when at least one of its disjuncts is true, and it is false otherwise. • Again, we can show this using a truth table: P T T F F Q PQ T T F T T T F F Combining Complex Claims: Parentheses • Using the truth-functional connectives, we can combine complex claims to make even more complex claims. • We are going to use parentheses to indicate the exact order in which claims are being combined. • Example: (P Q) (R S) is a conjunction of two disjunctions. Parentheses and Ambiguity • An ambiguous statements is a statement whose meaning is not clear due to its syntax. Example : ”P or Q and R” • In formal systems, an expression like P Q R is simply not allowed and considered unsyntactical. • Claims in our formal language are therefore never ambiguous. • One important application of the use of formal languages is exactly this: to avoid ambiguities! Exclusive Disjunction vs Inclusive Disjunction • Notice that the disjunction as defined by ‘’ is considered to be true if both disjuncts are true. This is called an inclusive disjunction. • However, when I say “a natural number is either even or odd”, I mean to make a claim that would be considered false if a number turned out to be both even and odd. Thus, I am trying to express an exclusive disjunction. How to express Exclusive Disjunctions • We could define a separate symbol for exclusive disjunctions, but we are not going to do that. • Fortunately, exclusive disjunctions can be expressed using the symbols we already have: (PQ) (PQ) P T T F F Q (P Q) (PQ) T T F F T F T T T F T T T T F F F F T F ! Conditionals The Material Conditional • Let us define the binary truth-functional connective ‘’ according to the truth-table below. • The expression P Q is called a conditional. In here, P is the antecedent, and Q the consequent. P T T F F Q PQ T T F F T T F T ‘If … then …’ Statements • The conditional is used to capture ‘if … then …’ statements. • However, the match isn’t perfect. For example, we don’t want to say that the claim “If grass is green then elephants are big” is true just because grass is green and elephants are big, nor that any ‘if … then’ statement is automatically true once the ‘if’ part is false or the ‘then part true. The problem is that most English ‘if…then’ expressions aren’t meant to make a claim that is truthfunctional in nature. • Still, any ‘if … then …’ statement will be false if the ‘if’ part is true, but the ‘then’ part false, and the conditional captures at least this important truth-functional aspect of any ‘if … then …’ statement. • So, while we will from now on refer to the conditional as an ‘if … then’ statement, we must be careful about the use of this, just as care must be taken when applying Newtonian physics to some situation. Necessary and Sufficient Conditions • Conditionals can be used to express necessary and sufficient conditions: • Sufficient Condition: Something (P) is a sufficient condition for something else (Q) iff P being the case guarantees Q being the case. Hence, if we know that P is true, we know that Q is true: P Q • Necessary Condition: Something (P) is a necessary condition for something else (Q) iff P being the case is required for Q being the case. Thus, while P may be true without Q being true, we do know that if Q is true, P is true: Q P ‘If’ vs ‘Only if’ • Sufficient conditions are expressed in English using ‘if’, while necessary conditions are expressed using ‘only if’. • Thus: – ‘If P then Q’: P Q – ‘P if Q’: Q P – ‘P only if Q’: P Q – ‘Only if P, Q’: Q P ‘If and only if’ and the Material Biconditional • A statement of the form ‘P if and only if Q’ (or ‘P iff Q’) is short for ‘P if Q, and P only if Q’. Hence, we could translate this as (P Q) (Q P). However, since this is a common expression, we define a new connective ‘’: P T T F F Q PQ T T F F T F F T Logical Properties Truth Tables • Truth-tables can be used for: – defining the truth-conditions of truth-functional connectives – evaluating the truth-conditions of any complex statement Tautologies • A tautology is a statement that is necessarily true. • Example: P P P P P T TT F T F F T TF Contradictions • A contradiction is a statement that is necessarily false. • Example: P P P P P T TF F T F F F TF Contingencies • A contingency is a statement that can be true as well as false • Example: P P P T T F F Equivalences • Two statements are equivalent if they have the exact same truth-conditions. • Example: P and P P P P T T TF T F F F TF Contradictories • Two statements are contradictories if one of them is false whenever the other one is true and vice versa. • Example: P and P P P P T T FT F F TF Implication • One statement implies a second statement if it is impossible for the second statement to be false whenever the first statement is true. • Example: P implies P Q P T T F F Q T F T F P T T F F PQ T T T F Consistency • A set of statements is consistent if it is possible for all of them to be true at the same time. • Example: {P, P Q, Q} P T T F F Q T F T F P T T F F PQ T T T F Q F T F T Consequence • A statement is a consequence of a set of statements if it is impossible for the statement to be false while each statement in the set of statements is true. • Example: P is a consequence of {PQ, Q} P T T F F Q T F T F PQ T T T F Q F T F T P T T F F Validity • An argument is valid if it is impossible for the conclusion to be false whenever all of its premises are true. • Example: P Q, Q P P T T F F Q T F T F PQ T T T F Q F T F T P T T F F Implication, Consequence, Validity • The notions of implication, consequence, and validity are very closely related: • A statement implies a statement if and only if is a consequence of the set of statements {} • For implication and consequence we use the symbol ‘’: – If statement implies statement we write – If statement is a consequence of a set of statements {1, …, n}, we write {1, …, n} • An argument consisting of premises 1, …, n and conclusion is valid iff {1, …, n} • The terms implication, consequence and validity can therefore be used interchangeably. Summary • Logical properties of a single statement: – Tautology: cannot be false – Contradiction: cannot be true – Contingent: can be true and can be false • Logical properties of 2 statements: – – – – – • Equivalent: always the same truth-value Contradictory: always opposite truth-values Contrary: cannot be both true Subcontrary: cannot be both false Implication: implied statement cannot be false while the implying statement is true Logical properties of a set of statements: – Consistent: can be all true at the same time • Logical properties of a set of statements in relation to a single statement: – Consequence: statement cannot be false if all of the statements of the set are true • Logical properties of an argument: – Valid: conclusion cannot be false if all premises are true But Wait! • Consider the statement ‘a=a’ • This statement is a tautology, since it is always true. • However, since this statement does not involve any truth-functions, propositional logic considers this an atomic statement, and symbolizes it as ‘P’. But ‘P’ is a contingency. • What is going on?? Truth-Functional Tautologies • What is going on is that truth-tables only capture the truth-functional aspects of sentences. • So, a statement may be a tautology for reasons other than truth-functional reasons. ‘a=a’ is an example. • A statement that is a tautology because of truthfunctional considerations is called a truthfunctional tautology. • Notice that while every truth-functional tautology is a tautology, not every tautology is a truthfunctional tautology (again, ‘a=a’ is a tautology, but not a truth-functional tautology) Normal Forms and Expressive Completeness Logically Equivalent Statements • To express that two statements P and Q are logically equivalent, we will write: PQ • ‘’ is not a symbol of F!! Some Important Equivalences • Double Negation: – PP • DeMorgan: – (P Q) P Q – (P Q) P Q • Distribution: – – – – P (Q R) (P Q) (P R) P (Q R) (P Q) (P R) (Q R) P (Q P) (R P) (Q R) P (Q P) (R P) More Equivalences • Commutation: – PQQP – PQQP • Association: – P (Q R) (P Q) R – P (Q R) (P Q) R • Idempotence: – PPP – PPP • Subsumption: – P (P Q) P – P (P Q) P Even More Equivalences • Implication: – P Q P Q – (P Q) P Q • Transposition: – P Q Q P • Exportation: – P (Q R) (P Q) R • Absorption: – P Q P (P Q) • Equivalence: – P Q (P Q) (Q P) – P Q (P Q) (P Q) Simplifying Statements I • Using the principle of substitution of logical equivalents, and using the logical equivalences that we saw before (Double Negation, Association, Commutation, Idempotence, DeMorgan, Distribution, and Subsumption), we can often simplify statements. • Example: (A B) A (Commutation) (B A) A (Association) B (A A) (Idempotence) BA Generalized Conjunctions and Generalized Disjunctions • Recall the Association equivalences: – P (Q R) (P Q) R – P (Q R) (P Q) R • Because of this, we’ll allow to drop brackets: – PQR – PQR • Thus we can generalize conjunctions and disjunctions – A generalized conjunction (disjunction) can have any number of conjuncts (disjuncts) Simplifying Statements II • The conjuncts (disjuncts) of a generalized conjunction (disjunction) can be switched around in any way you want. This really helps with simplifying statements. Example: C (A (B C)) (Distribution) C (A B) (A C) (Subsumption) C (A B) ‘⊤’ and ‘⊥’ • A generalized conjunction is false if it has at least one false conjunct, otherwise it is true. – So, a generalized conjunction with 0 conjuncts cannot have a false conjunct, and hence cannot be false. Therefore, it is a tautology! We will write this as ‘⊤’. • A generalized disjunction is true if it has at least one true disjunct, otherwise it is false. – Hence, a generalized disjunction with 0 disjuncts can never be true, and is therefore a contradiction! We will write this as ‘⊥’. Some equivalences involving ‘⊤’ and ‘⊥’ • • • • • • • • ⊥ ⊤ ⊤ ⊥ P⊥⊥ P⊤⊤ P⊤P P⊥P P P ⊥ P P ⊤ Simplifying Statements III • Using ‘⊤’ and ‘⊥’, we can simplify statements even more. Example: (A (B (A B)) (DeMorgan) A (B (A B)) (Double Neg.) A B (A B) (Distribution) (A B A) (A B B) ⊥⊥ ⊥ Negation Normal Form • Literals: Atomic Sentences or negations thereof. • Negation Normal Form: An expression built up with ‘’, ‘’, and literals. • Using repeated DeMorgan and Double Negation, we can transform any truth-functional expression built up with ‘’, ‘’, and ‘’ into an expression that is in Negation Normal Form. • Example: ((A B) C) (DeMorgan) (A B) C (Double Neg, DeM) (A B) C Disjunctive Normal Form • Disjunctive Normal Form: A disjunction of conjunctions of literals. • Using repeated distribution of over , any statement in Negation Normal Form can be written in Disjunctive Normal Form. • Example: (AB) (CD) (Distribution) [(AB)C] [(AB)D] (Distribution (2x)) (AC) (BC) (AD) (BD) Conjunctive Normal Form • Conjunctive Normal Form: A conjunction of disjunctions of literals. • Using repeated distribution of over , any statement in Negation Normal Form can be written in Conjunctive Normal Form. • Example: (AB) (CD) (Distribution) [(AB) C] [(AB) D] (Distribution (2x)) (AC) (BC) (AD) (BD) Truth-Functional Connectives • So far, we have seen one unary truth-functional connective (‘’), and two binary truth-functional connectives (‘’, ‘’). • Later, we will see two more binary connectives (‘’, ‘’) • However, there are many more truth-functional connectives possible: – First of all, a connective can take any number of arguments: 3 (ternary), 4, 5, etc. – Second, there are unary and binary connectives other than the ones listed above. Unary Connectives • What other unary connectives are there besides ‘’? • Thinking about this in terms of truth tables, we see that there are 4 different unary connectives: P *P P *P P *P P *P T F T T T F T F T F F T T F F F Binary Connectives • The truth table below shows that there are 24 = 16 binary connectives: P Q P*Q T T T/F T F T/F F T T/F F F T/F In general: n sentences 2n truth value combinations (i.e. 2n rows in truth table) 2n 2 different n-ary connectives! Expressing other connectives using ‘and’, ‘or’, and ‘not’ • We saw that we can express the exclusive disjunction using ‘and’, ‘or’, and ‘not’. • Q: Can we express all other connectives as well? • A: Yes! We can generalize from this example: P Q P*Q T T F Step 1: T F T PQ F T T PQ F F F Step 2: (PQ) (PQ) Truth-Functional Expressive Completeness • Since I can express any truth function using ‘’, ‘’, and ‘’, we say that the set of operators {, , } is (truth-functionally) expressively complete. • DeMorgan Laws: – (P Q) P Q – (P Q) P Q • Hence, by the principle of substitution of logical equivalents, since {, , } is expressively complete, the sets {, } and {, } are expressively complete as well! Applications: Computer Hardware and Software • The results that we have seen on the previous slides have important applications in both computer hardware and software: – Digital Circuits – Machine Reasoning Logic and Computer Circuitry 1’s and 0’s • All what modern digital computers do is transform strings of 1’s and 0’s, called bitstrings. • Information is represented using 1’s and 0’s, and information is processed through the manipulation of those bitstrings. • The 1’s and 0’s can be physically realized using any kind of physical dichotomy. We can therefore use pure mechanics (levers, pulleys, punchcards, etc.), electronics, optics, DNA, quantum physics, toilet paper and pennies, or just about anything else to physically implement the 1’s and 0’s. Logic Gates • To process information, bitstrings need to be manipulated. • Thus, depending on whatever way the 1’s and 0’s are physically implemented, there needs to be a device to change those physical representations. • But, we are not going to be interested in the physical nature of these devices, since this is just an issue of implementation. • Rather, we are going to think of these devices as logic gates: thingamabobs that transform bitstrings into other bitstrings. ‘And’, ‘Or’, and ‘Not’ Gates In1 In2 In1 In2 In Out Out Out Out In1 In2 1 1 1 1 0 0 0 1 0 0 0 0 In1 In2 1 1 1 1 0 1 0 1 1 0 0 0 In Out 1 0 0 1 Out Representing Numbers • We normally represent numbers using the decimal system. That is, we take 10 as our base number to represent numbers. • Example: 53627 7*100 = 7*1 = 7 2*101 = 2*10 = 20 6*102 = 6*100 = 600 3*103 = 3*1000 = 3000 5*104 = 5*10000 = 50000 53627 Binary Numbers • Binary numbers take 2 as their base. • Example: 10110 0*20 = 0*1 = 0 1*21 = 1*2 = 2 1*22 = 1*4 = 4 0*23 = 0*8 = 0 1*24 = 1*16 = 16 22 Adding Binary Numbers 111 1 1 11010110 10110011 110001001 Computing Binary Addition • To compute the addition of two binary numbers, we need to implement the following architecture: In10 In20 + Out0 Carry1 In11 In21 + Out1 Carry2 In12 In22 + Out2 2 Bit and Carry Adder Carryn In1n In2n Outn + Carryn+1 In1n In2n Carryn Outn Carryn+1 1 1 1 1 1 1 1 0 0 1 1 0 1 0 1 1 0 0 1 0 0 1 1 0 1 0 1 0 1 0 0 0 1 1 0 0 0 0 0 0 Circuitry for the 2 Bit and Carry Adder (output bit) In1n In2n Carryn Outn Circuitry for the 2 Bit and Carry Adder (carry bit) In1n In2n Carryn Carryn+1 Simplifying • While the Disjunctive Normal Form provides us with a working circuitry (and thus guarantees us of one!), this circuitry may not be the most efficient one. • Carryn+1 = (In1n In2n) (In1n Carryn) (In2n Carryn) • Outn = (In1n XOR In2n) XOR Carryn – where P XOR Q = (P Q) (P Q) An Interesting Trade-Off • To keep production costs down: – Use as few gates as possible – Use as few different kinds of gates as possible • However, there is a trade-off between these two objectives: The fewer the number of kinds of gates one uses, the more gates of those kinds are needed. Example of the Trade-Off • The Disjunctive Normal Form tells us that we can build any circuit using only 3 kinds of gates. • With more types of gates (e.g. the XOR), we could have saved on the total number of gates. • On the other hand, because of the DeMorgan’s Law, we know that we can express any expression using only ‘and’ and ‘not’. Thus, we can also try and cut down on the number of types of gates, but this will mean an increase in the number of gates. The NAND • Let us define the binary truth-functional connective ‘NAND’ according to the truth-table below. • Obviously, P NAND Q (P Q) (hence the name!) P T T F F Q P NAND Q T F F T T T F T Expressive Completeness of the NAND • The NAND has a very interesting property, in that it can express any truth-functional connective, i.e. {NAND} is expressively complete! • Proof: We already know that we can express every truth-functional connective using only and . Furthermore: – P NAND P (P P) P – (P NAND P) NAND (Q NAND Q) ((P NAND P) (Q NAND Q)) (P Q) P Q • In other words, we can build circuitry using only one kind of logic gate!! Of course, the drawback is that we need many of those gates. The Miniac • Behold! The world’s most powerful computer that fits in the palm of your hand: a penny!! • Instructions: Ask any question with a yes or no answer. Flip the coin. Tails means ‘yes’ and heads means ‘no’. To see whether the Miniac’s answer is correct or incorrect, flip the coin a second time, asking: “Is your answer to this question just as correct as your answer to the previous question?” • Question: How does this work? Formal Proofs Demonstrating Invalidity • To demonstrate invalidity one has to show that it is possible for all premises to be true and the conclusion to be false all at the same time. • One way to do this is to come up with a possible scenario (or possible world) in which all premises are true and the conclusion false (Tarski’s World). This is called a counterexample. Demonstrating Validity • To demonstrate validity, we have to show that there is no possible way for all premises to be true and the conclusion false all at the same time. • Showing a scenario in which all premises are true, and in which the conclusion is true as well, does not demonstrate validity, b/c there may still be a different scenario in which all premises are true and the conclusion false. • Of course, we could try and generate all possible worlds, but this method is either impractical (b/c there are too many possible worlds), or simply impossible (b/c there are infinitely many possible worlds). Proofs • OK, so what do we do? Well, we can do what we do in everyday reasoning: we start with the premises, and we gradually work our way to the conclusion: “Either the housemaid or the butler killed Mr. X. Now, we know that if the housemaid would have done it, the alarm would have gone off. But, the alarm did not go off. Therefore, the housemaid did not do it. So, since it was either the housemaid or the butler, it must have been the butler.” Intermediate Results • The previous argument had 3 premises: – 1. Either the housemaid or the butler did it. – 2. If the housemaid did it, the alarm would have gone off. – 3. The alarm did not go off. • The conclusion was: The butler did it. • We combined premises 2 and 3 to get an intermediate result: The housemaid did not do it. • We then combined the intermediate result with premise 1 to get the conclusion. • We use intermediate conclusions because without them, the inference from the premises to the conclusion may not be obvious, but with them, each of the steps does become obvious. ‘Obvious’ • In formal proofs, we try and formalize this stepby-step inference process, where each inference is obvious. • OK, but ‘obvious’ is a bit of a vague term, as what is obvious to some, may not be obvious to others. So, what are going to count as ‘obvious’? • We are going to play it safe: In formal proofs, we are only going to allow steps that are about as obvious as we can get. Thus, we are only going to allow ‘baby inferences’. • So, in formal proofs, bigger inferences, which may still be obvious to many (if not all of us), will still have to be broken up into smaller ones! Inference Rules • Formal systems of logic come with a finite set of inference rules that reflect ‘baby inferences’. • There are many formal systems of logic, each with their own set of inference rules: – The nature of the inference rules depends on the symbols that the system uses to express statements. – However, even if two systems use the same symbols, they may still have different inference rules. F: A ‘Fitch’-style Deductive System • The formal system that our book uses is called F. • F has 2 inference rules for each connective: – Introduction: A rule to infer a statement with that connective as its main connective – Elimination: A rule to infer something from a statement with that connective as its main connective. • Formal systems with these two types of inference rules are called ‘Fitch’-style systems. • Warning: While Fitch-style systems are mathematically elegant, they are not always very user-friendly. In particular, it does not contain inference rules that reflect some ‘obviously’ valid inferences! The Structure of Proofs in F • A formal proof in F will look like this: n P1 Pn n+1 I1 1 Justification 1 n+m Im Justification m n+m+1 C Justification m+1 Justification • In a formal proof, you have to indicate from which premises or intermediate results you infer the new statement. Thus, each step needs to have its own justification. • Inference rules may need any number of statements from which the new statement is inferred (though with too many statements, the rule may no longer be considered ‘obvious’). • Most inference rules require one or two statements. • Some inference rules require no statements at all. This is when the inferred statement is unconditionally true. • To help refer to previous statements, we are going to number the statements. Elim • Conjunction Elimination ( Elim) allows one to infer any conjunct from a conjunction. P1 P2 … Pn Pi Intro • Conjunction Introduction ( Intro) allows one to conjunct any number of previously established statements in any order. P1 Pn P1 P2 … Pn Intro • Disjunction Introduction ( Intro) allows one to construct any disjunction using a previous result as one of its disjuncts. Pi P1 … Pi … Pn Elim • Negation Elimination ( Elim) allows one to infer P from P: P P Do we Have Free Will? • Either determinism is true or not. Now, if determinism is true, then my actions cannot be otherwise from what they are, i.e. I don’t any freedom to exert my will. On the other hand, if indeterminism is true, then my actions are partly determined by pure randomness, so there is no such thing as a will that is in total control of my actions. Either way, I don’t have free will. Proof by Cases • The proof we just saw follows a certain pattern: ‘Either P is the case or Q is the case. However, if P is the case, then S is the case, and if Q is the case, then S is the case as well. Either way, S is therefore the case. Hence, S is the case.’ • This pattern of reasoning is called Proof by Cases • Obviously, the above pattern can be generalized to disjunctions with any number of disjuncts. • However, a very common form is to start with: ‘Either P is the case or P is not the case’. Is Space Continuous? • Suppose space is continuous. • Then between any two (different) points A and B there exist infinitely many other points. • Thus, in order to move from any point A to any other point B, you have to completely go through a sequence of infinitely many points. But, you can never reach the end of an infinite sequence. Hence, motion is impossible. • But, things do move. • Contradiction! • So, space is not continuous. (thanks to Zeno!) Proof by Contradiction • The proof we just saw relied on the following pattern: ‘Assuming P to be the case, then I get some kind of impossibility or contradiction. Hence, contrary to my assumption, P cannot be the case.’ • This pattern of reasoning is called Proof by Contradiction (or Indirect Proof or Reductio ad Absurdum or simply Reductio). Proof by Cases and Proofs by Contradiction • Proof by cases and proof by contradiction are two important proof techniques that we would like to formalize. • But, these proof techniques do not work by inferring some statement from some other statement(s). • Rather, they work by pointing to the fact that I am able to infer something from something else. Subproofs • At any time during a proof, a subproof may be started by making an additional assumption which can then be used to draw further inferences. • The subproof may be ended at any time. When it is ended, the individual statements from the subproof can no longer be used to infer others. • Subproofs demonstrate that certain statements can be inferred when an additional assumption is made, and this result can be used in the proof itself. That is, the subproof as a whole can be used to infer other statements. Formalizing Proof by Cases using Subproofs and ‘’ • Using subproofs, we can now formalize the Proof by Cases technique: – You have a disjunction P1 … Pi … Pn • These are the possible cases – You start a subproof for each of the possible disjuncts • This is going through each of the cases (what if P1 is the case?; what if P2 is the case?, etc.) – You infer the same statement (Q) in all subproofs • This show that in all cases, the same thing (‘Q’) can be inferred – You now point to the initial disjunction and all the relevant subproofs to conclude Q Elim • Disjunction Elimination ( Elim) is the formal counterpart of Proof by Cases: P1 … Pi … Pn P1 S Pn S S Subproofs and Scope • An additional line is used to indicate the start and end of the subproof. • The line can also be seen as the scope of the additional assumption made at the start of the subproof: every statement within that scope is inferred from the truth of that assumption and all previous assumptions. • The line of the proof itself can be seen in exactly this way as well. Therefore, there is no real difference between subproofs and proofs. Subproofs within Subproofs • Within any subproof, another subproof can be started. • Subproofs within subproofs must be ended before the original subproof is ended. • The general rule is: one can use as justification all and only statements that is either one of the assumptions whose scope one is working in, or some statement inferred from those. Formalizing Proof by Contradiction using subproofs and ‘’ • We can now formalize the Proof by Contradiction – Start a subproof, and assume P • All proofs by contradiction start by assuming something, and this is the opposite of what you want to prove! – In the subproof, derive • This shows that assuming P leads to a contradiction – Point to the subproof, and conclude P Intro • Negation Introduction ( Intro) is the formal counterpart of Proof by Contradiction: P P Intro • Introduction ( Intro) allows one to infer from a pair of statements P and P: P P More on contradictions • Theorem: For any statement P: P • Proof: It is impossible for to be true, so it is impossible for to be true and P to be false, and hence for any P: P • In other words: Anything is a logical consequence from a logical contradiction! Elim • Elimination ( Elim) allows one to infer any statement P from : P Elim • Conditional Elimination ( Elim) allows one to infer the consequent of a conditional, given the truth of its antecedent: PQ P Q This pattern is better known as Modus Ponens Conditional Proof • We have seen two uses of subproofs: for Proofs by Contradiction, and for Proofs by Cases. • A third use for subproofs is to do a Conditional Proof. • A Conditional Proof infers some kind of conditional P Q from a given set of statements by making P an extra assumption, and trying to infer Q from the given statements and the additional assumption P. Intro • Conditional Introduction ( Intro) is the formal counterpart of Conditional Proof: P Q PQ Modus Tollens Pattern: Proof: 1. 2. 3. 4. 1,3 Elim 5. 2,4 Intro 6. 3-5 Intro Disjunctive Syllogism Pattern: Proof: 1. 2. 3. 4. 5. 6. 7. 2,3 Intro 4 Elim 1,3-5,6-6 Elim Fitch • Fitch is the program that allows the user to construct formal proofs in F. • Fitch has a number of additional features: – Checks whether a rule is applied correctly – Allows shortcuts that are not allowed in F – Provides CON rules Metalogic Logic and Metalogic • Metalogic is the study of logic. That is, where logic has no specific subject matter (logic can be applied in any field where reasoning takes place), the subject matter of metalogic is logic itself. • Metalogic makes claims about logical properties and relationships. For example: “A statement is a tautology if and only if its negation is a contradiction” is a metalogical claim. • Of course, the paradox of metalogic is that it needs logic to support the claims it makes about logic! Hmmm… A Central Metalogical Result: Consequence as a Central Notion • Many interesting logical properties can be expressed in terms of logical consequence. For example: – Tautology: A statement is a tautology iff {} – Contradiction: A statement is a contradiction iff ⊥ – Equivalence: Two statements and are equivalent iff and – Inconsistency: A set of statements {1, …, n} is logically inconsistent iff {1, …, n} Consequence and Formal Proof • Since formal proofs can be used to demonstrate consequence, and since consequence can be used to demonstrate other logical properties, formal proofs can be used to demonstrate these other logical properties: – Tautology: • To prove that something is a tautology, derive that statement from an empty set of premises. – Contradiction: • To prove that a statement is a contradiction, derive from that statement as a premise. – Equivalence: • To prove that two statements P and Q are equivalent, do two proofs: – First, assume P as a premise, and derive Q. – Second, assume Q as a premise, and derive P. – Inconsistency: • To prove that a set of statements is inconsistent, assume all those statements as premises, and derive . Talking about Proofs … • How do we know if a formal proof does what it is supposed to do? That is, if I can derive a sentence from a set of sentences {1, …, n}, does that really mean that is a truth-functional consequence of {1, …, n}? • Notice that this is a metalogical questions: it asks something about formal proofs in relation to a logical property. But of course, we want to settle this question through the use of a rigorous proof, i.e. we want to prove something about formal proofs!?! Modus Bogus • In order to demonstrate that the question on the previous slide is an interesting and meaningful question, consider the following rule: PQ P Q Obviously, a formal proof system that would contain this rule would be able to ‘prove’ things that just don’t follow! TF • Recall: is a truth-functional consequence of {1, …, n} iff according to truth-functional properties it is impossible for to be false if each i is true. • Let us use the symbol TF to indicate truthfunctional consequence: TF iff is a truthfunctional consequence of . • Remember: If TF then , but not vice versa. E.g. LeftOf(a,b) RightOf(b,a), but not LeftOf(a,b) TF RightOf(b,a). Truth-functional Provability • Let us define truth-functional provability with regard to some formal deductive logic system S (e.g F) as follows: Q is truth-functionally provable from a set of premises {P1, …, Pn} in the system S iff there exists a formal proof in S going from P1, …, Pn as premises and Q as the conclusion using the rules for ‘’, ‘’, ‘’, ‘’, ‘’, and ‘’ (or any other truthfunctional connective defined by S). TF(S) • Let us use the symbol TF(S) to indicate truthfunctional provability in S: TF(S) iff is truth-functionally provable from in the system S. • The subscript TF(S) indicates that we restrict our proofs to the truth-functional rules of S. Two Very Important Properties • For every deductive system of formal logic S we can define the following 2 properties: – 1. Truth-Functional Deductive Soundness: A system S is truth-functionally deductively sound iff for any and : • if TF(S) then TF – 2. Truth-Functional Deductive Completeness: A system S is truth-functionally deductively complete iff for any and : • if TF then TF(S) F is Sound • Q: Is F truth-functionally deductively sound? • A: Yes! • If you want the full proof, take ‘Intermediate Logic’. A Trivially Sound System • Let S be a logic system that has no inference rules. Then, trivially, all inference rules of S are sound. Hence S is deductively sound as well. • In other words, it is trivial to make a deductively sound logic system: just don’t define any inference rules! Deductive Completeness • Q: Why is truth-functional deductive completeness important? • A: If a logic system S is not complete, then for certain and , TF but not TF(S) . So, although is a truth-functional consequence of , the rules do not allow one to prove from ! • Q: How is that possible? • A: Easy. While P TF P, the system S will not be able to prove this. Hence, S is not a truthfunctionally deductively complete system! Proving Deductive Completeness • Proving completeness for some logic system S can be very difficult. This is not hard to understand: one needs to prove that for every and such that , there exists a proof in S going from to . But, there are an infinite number of pairs and such that , and the proofs don’t seem to follow any kind of systematic pattern. • Note: If we already know a certain system S’ to be complete, we can try to prove S to be complete by demonstrating how S can prove anything that S’ is able to prove. F is Complete • Q: Is F truth-functionally deductively complete? • A: Yes, but the proof for this is rather complicated and outside the scope of this class. Again, if you’re interested, take ‘Intermediate Logic’. An Algorithm for Producing Formal Proofs • Restricting ourselves to , , , and only: – Start a proof by contradiction (assume negation of conclusion). Let be the set of statements you have. Then go through the following loop to obtain (keep adding results to ): • • • • • • • If : stop If and : get by Intro If : get by Elim If (1 … n ) : get 1 … n by DeMorgan pattern If (1 … n ) : get 1 … n by DeMorgan pattern If 1 … n : get 1, … , n by Elim If 1 … n : set up subproof for each 1 and derive from {1} / {1 … n} with this same method. Then get with Elim Hokus Ponens • The logic system B (‘Bram’) contains only one inference rule, called Hokus Ponens: P Woohoo! One line proofs! This system is going to make me famous! (Only one small problem …) Automated Theorem Proving Systematic Procedures • A systematic procedure is a procedure that follows a certain step-by-step algorithm to perform a certain task. • Examples are cookbook recipes and computer programs. • A systematic procedure will either stop after a finite amount of time, or never stop (e.g. because it goes into an infinite loop). • The truth-table method is a systematic procedure. • The method of formal proof is not a systematic procedure (though it can be used to make one). Positive Tests, Negative Tests, and Full Tests • A positive test is a systematic procedure that tries to figure out whether certain things have a certain property. • A negative test is a systematic procedure that tries to figure out whether certain things do not have a certain property. • A full test is a systematic procedure that tries to figure out whether certain things do or do not have a certain property. • The truth table method is a full test. It can answer that something is or is not a logical consequence of something else. • The formal proof method, even if it were systematic, is not a full test, but only a positive test. It can answer that something is a logical consequence of something else, but it never concludes that it isn’t a logical consequence. Soundness and Completeness for Tests and Decision Procedures • A test (positive, negative, or full) is sound iff: – if the test claims that something has (not) a certain property, then it has (not) that property. • A test (positive, negative, or full) is complete iff: – If something has (not) a certain property, then the test claims that it has (not) that property. Decision Procedures • A full test that is both sound and complete is called a decision procedure. • The truth-table method is a decision procedure for truth-functional consequence. • The Taut Con ‘rule’ (mechanism!) is also a decision procedure for truth-functional consequence. • Questions: Is there a decision procedure for TF consequence that is more efficient than the truth-table method. In fact, how does Taut Con work? Truth-Trees Logical Possibility • All logically interesting claims can be reduced to questions about logical possibility: – Logical Consistency: Is it possible for all statements to be true? – Logical Validity: Is it possible for all premises to be true and the conclusion false? – Logical Consequence: Is it possible for the implying statements to be true and the implied statement to be false? – Logical Equivalence: Is it possible for the two statements to have a different truth value? – Logical Tautology: Is it possible for the statement to be false? Truth Table Method • The truth table method systematically exhausts all possible truth value combinations of the statements involved. • In the truth-table we look for a row that reflects a certain possibility, and that will tell us the answer to whatever question we had (e.g. if there is no row where statement is false, then it is not possible for that statement to be false, and hence it is a tautology). Drawback and Room for Solution • A drawback of the truth table method is that the number of rows grows exponentially. • Fortunately, there is room for a solution to this problem. Since all we are interested in, is the existence of a specific combination of truth values of the statements involved, all we need to find is one example of such a case. Once we have found such a case, there is no need to exhaust all other cases. Simple Solution: Stopping Early • One solution to the problem of big truth tables is therefore to simply stop once you have found a row that represents the combination of truth values you are interested in. • Thus, rather than working out a truth table column by column, you may want to do it row by row, so that you can stop as soon as you have found a row of the kind you are looking for. • A big drawback of this approach is that if no row of the kind you are looking for exists, then you have to complete the whole truth table after all. A More Focused Search • Consider the following argument: P (Q R) R Q R • We are interested in whether all premises can be true and the conclusion false: – In order for the conclusion to be false, R must be false. – In order for the second premise to be true while R is false, Q must be false. – In order for the first premise to be true while Q and R are both false, P must be false. The Short Truth Table Method • The Short Truth Table Method assigns truth values to the involved atomic and complex statements in order to try and obtain a certain combination of truth values: P (Q R) F T F FF RQ F TTF / R F • The Short Truth Table Method thus tries to generate one row of the truth table that has the combination of truth values you are interested in. Short Truth Table Method and Indirect Proof • As you assign truth values to certain statements, the truth values of other statements can be forced. • If you are forced to make a statement both true and false, then you know that the combination of truth values you are looking for does not exist: P (Q P) TF TF F Contradiction, so the statement is a tautology! • The short truth table method is therefore a kind of indirect proof (proof by contradiction), except that you don’t always get a contradiction. Drawback of the Short Truth Table Method • A drawback of the short truth table method is that you are not always forced to assign any further truth values: R (Q P) T T (Q R) P T T RP T Q T • At this point, you can choose to assign certain truth values, but if your choice does not lead to the row you are looking for, then you need to try a different option, and the short truth table method has no tools to do go through all of your options in a systematic way. Truth Trees • The obvious solution to the drawback of the short truth table method is to incorporate tools to systematically keep track of multiple options. • One method that does so is the truth tree method: – The truth tree method tests for the consistency of a set of statements and, as such, can be used to determine validity, tautologies, equivalence, etc. – Like the short table method, it infers which other statements are forced to be true under this assumption. – When nothing is forced, then the tree branches into the possible options. Truth Tree Example (((PQ)R) (P(QR))) (PQ)R (P(QR)) P (QR) Q ((PQ)R) P(QR) PQ All branches close R the original P statement cannot be Q false tautology! R (PQ) R × P Q × × P × Q R Q × R × Decomposition Rules for Truth Trees P P PQ P Q PQ PQ P Q P (PQ) P Q Q PQ P Q P Q (PQ) P Q (PQ) P Q (PQ) P Q P Q Truth Trees as Decision Procedures • The truth tree method can easily be made into a systematic procedure. • As such, the truth tree method becomes a decision procedure for truth-functional consequence that is, on average, quite a bit more efficient than the truth-table method. Resolution Running Example • As a running example, let us consider the following argument with premises: – Horned(a) – Horned(a) Elusive(a) – Dangerous(a) Horned(a) – (Elusive(a) Mythical(a)) Rare(a) – Dangerous(a) (Elusive(a) Rare(a)) • And conclusion: – Rare(a) Horn Clauses • A Horn clause is a disjunction of literals with at most one positive literal (i.e. atomic statement). • We can differentiate between 3 types of Horn Clauses: –Q – P1 … Pn – P1 … Pn Q – (Q and each of Pi is atomic) Efficient Check of Consistency of a Set of Horn Clauses • Horn Clauses form an important class of statements, since the consistency of a set of Horn clauses can be checked in a systematic and efficient manner. E.g. the short truth table method will always work: – 1. Write ‘T’ under all clauses. – 2. Make all forced moves until: • A. You get a contradiction: The set is inconsistent. • B. Nothing is forced anymore: The set is consistent. Example Putting into Horn Clauses: Horned(a) H Horned(a) Elusive(a) H E Dangerous(a) Horned(a) D H (Elusive(a) Mythical(a)) Rare(a) E M R Dangerous(a) (Elusive(a) Rare(a)) D E R Negating Conclusion: Rare(a) R Short Truth Table: H E D H H T F T T T T T FT E M R FTTTFTF D E R FTTFTTF R TF Horn Clauses in Conditional Form • Horn clauses can be written in conditional form: –Q – (P1 … Pn) – (P1 … Pn) Q Algorithm for Horn Clauses in Conditional Form • To check the consistency of a set S of Horn Clauses in conditional form: – 1. Make a new set of statements T, starting with the set of all atomic statements Q. – 2. If there is a statement (P1 … Pn) in S, and each Pi is in T, then you can stop: S is inconsistent. Otherwise, go to 3. – 3. If there is a statement (P1 … Pn) Q in S, and each Pi is in T, then add Q to T, and go to 2. Otherwise stop: S is consistent. Example Putting into conditional form Horn: H H H E H E D H H D E M R (E M) R D E R (D E) R R R {H} {H,E} {H,E,D} {H,E,D,R} Prolog • The programming language Prolog is based on Horn clauses. • A Prolog program consists of 2 types of lines: – Facts: These are Horn clauses of type Q. In Prolog: P. – Rules: These are Horn clauses of the form (P1 … Pn) Q. In Prolog: P :- P1 , … , Pn. • A Prolog program is run by asking whether some atomic statement Q follows from the facts and rules. In Prolog: Q? • The Prolog program will answer ‘Yes’ or ‘No’. The Prolog Algorithm • Prolog checks whether Q follows from the facts or rules as follows: – 1. Make a set of goals G, starting with Q. – 2. If G is empty, stop with answer ‘Yes’. – 3. If a statement P is in G that is a fact, remove P from G. – 4. If P is in G and there is a rule P :- P1 , … , Pn, then remove P from G, and add each Pi to G. – 5. If you get stuck, try a different rule P :- P1 , … , Pn. – 6. If all options fail, stop with answer ‘No’. Prolog Example Putting into Prolog: Query: R? H H {R} H E E :- H. H D D :- H. (E M) R R :- E, M. {E, M} {D, E} {H, M} {H, E} {M} {E} (D E) R R :- D, E. {H} {} ‘Yes’! Resolution • While the consistency of a set of Horn Clauses can be checked systematically and efficiently, not all statements are Horn Clauses, nor can they always be transformed into Horn Clauses. • However, all sentences can be put into Conjunctive Normal Form (CNF). • Horn Clauses are a special case of claims in CNF. • The algorithms for Horn Clauses are a special case of the more general method of resolution as defined over any set of statements in CNF. The Rule of Resolution • The Rule of Resolution is defined over disjunctions of one or more literals: P1 … Pi-1 X Pi+1 … Pm Q1 … Qi-1 X Qi+1 … Qn P1 … Pi-1 Pi+1 … Pm Q1 … Qi-1 Qi+1 … Qn (each of Pi and Qi are literals; X is atomic) Clauses • A clause is a set of literals. • Assuming a clause to represent a disjunction of all literals that are in that clause, we can resolve two clauses as follows: {P1 , … , Pi-1 , X , Pi+1 , … , Pm} {Q1 , … , Qi-1 , X , Qi+1 , … , Qn} {P1 , … , Pi-1 , Pi+1 , … , Pm , Q1 , … , Qi-1 , Qi+1 , … , Qn} (each of Pi and Qi are literals; X is atomic) The Method of Resolution • The method of resolution checks whether some set of statements S is consistent. It does this as follows: – 1. Make a set T of clauses representing all conjuncts of the CNF of each statement in S. – 2. Resolve any two clauses from T that can be resolved, and add the result to T. – 3. If two clauses resolve to the empty set, stop: the original set of statements was inconsistent. Resolution Example (Elusive(a) Dangerous(a)) (Elusive(a) Rare(a)) (Rare(a) Dangerous(a)) Horned(a) Horned(a) Magical(a) Negate Conclusion and put into CNF Magical(a) (E D) (E R) (R D) H HM M (E D) (E R) (R D) H H M (R D) H (R H) (D H) Resolution Example (Cont’d) (E D) (E R) {E, D} {E, R} {E, H} From CNF to clauses and resolve (R H) (D H) H M M {R, H} {H, M} {M} {D, H} {H} {E, H} {H} {} Inconsistent, so valid! Soundness and Completeness of Resolution • The method of Resolution is sound and complete with regard to truth-functional consistency in the sense that: – If the method finds a set of statements to be inconsistent, then that set of statements is indeed inconsistent (soundness). – If a set of statements is inconsistent, then the method can find that set of statements to be inconsistent by deriving the empty clause (completeness). Algorithms for Resolution and ATP’s • Algorithms for resolution will differ in the order in which clauses get resolved. • Many ATP’s are based on some such algorithm: – Snark – Otter – Taut Con in Fitch

Descargar
# Logic