Logic 2010/2011 Introduction to

R. Gennari

Contents

1 Introduction 1 1.1 Logic in a Nutshell ...... 1 1.2 Examples ...... 3 1.2.1 Informal Arguments ...... 3 1.2.2 Formal Verification ...... 3 1.3 The ideal Logic ...... 5 1.4 Main Topics of the Course ...... 5 1.5 Conclusions: Slogans ...... 6

2 Language, Informally 7 2.1 Propositional Language, Informally ...... 7

3 4 CONTENTS

2.2 First-order Language, Informally ...... 9

3 Semantics and Interpretations, Informally 11

4 Proofs, Informally 15 4.1 Proofs ...... 15 4.2 Propositional Proof Rules ...... 16 4.2.1 Conjunction ...... 17 4.2.2 Disjunction ...... 17 4.2.3 Implication ...... 18 4.2.4 Negation ...... 19 4.2.5 Other Propositional Rules ...... 20 4.3 First-order Proof Rules ...... 21 4.3.1 Universal quantifier elimination ...... 21 4.3.2 Universal quantifier introduction ...... 22 4.4 Natural Induction Proof Rule ...... 23

5 Main Meta-questions 25 Chapter 1

Introduction

1.1 Logic in a Nutshell

Logics are systems for formally representing and inferring information, hopefully, with terminating procedures of a certain computational complexity. The first two requirements means that a logic is characterised by:

–a formal language, defining primitive symbols and the rules for composing symbols in formulae of the language (syntax), – interpretations for specifying the so-called meaning of formulae, that is, when they are true (semantics).

1 2 CHAPTER 1. INTRODUCTION

The others mean that a logic is also characterised by

–a proof calculus with inference rules for the formulae of the logic (),

– hopefully, terminating procedures for scheduling those rules (decidability)

– within specific computational bounds (complexity). 1.2. EXAMPLES 3 1.2 Examples

1.2.1 Informal Arguments If our government fails to control military spending then we will suffer huge budget deficits. We are suffering huge budget deficits. Therefore our government has failed to control military spending.

Is the argument correct? In other words, is there a proof that the conclusion follows from the premises?

If our government fails to control military spending then we will suffer huge budget deficits. We are not suffering huge budget deficits. Therefore our government has not failed to control military spending.

Is the argument correct? In other words, is there a proof that the conclusion follows from the premises?

1.2.2 Formal Verification

Consider the following classical integer division problem: Let x, y ∈ N. Write a program that computes x/y. 4 CHAPTER 1. INTRODUCTION

{x ≥ 0, y ≥ 0} a:=0; b:=x; while b ≥ y do b:=b − y; a:=a + 1; {ay˙ + b = x ∧ 0 ≤ b < y}

The language of Peano arithmetic, augmented with −, allows us to formalise assertions about the program’s statements as formulae. See the blue formulae. A suitable proof calculus allows us to formally prove that

if x ≥ 0 ∧ y ≥ 0 before executing the program then ay˙ + b = x ∧ 0 ≤ b < y at the termination of the program.

Alas, proof calculi for Peano arithmetics turn out not to be decidable. . . In general, full automatic formal verification of program assertions is an undecidable problem, and therefore impossible to be fully automatize. Nevertheless in special cases, e.g., for specific calculi, the verification can be automatized. This is for instance the case of programs that manipulate only variables ranging over finite data types. Besides formal verification, logic is relevant in several other fields of formal methods, e.g., formal synthesis. See the first chapter of [Apt et al.2010] for an overview and pointers. 1.3. THE IDEAL LOGIC 5 1.3 The ideal Logic

The ideal logic. . . depends on the problem at hand:

– its formal language should be sufficiently expressive (for the problem)

– it should have a proof theory that

– is sound and complete for its semantics – and allow for efficient inference procedures – scheduling the proof theory’s rules

In this course, we focus on classical : propositional logic; first order logic.

1.4 Main Topics of the Course

– Classical Propositional Logic:

– formal language, – semantics and interpretations, – proof theory and calculi, – computability Issues. 6 CHAPTER 1. INTRODUCTION

– Classical First Order Logic:

– formal language, – semantics and interpretations, – proof theory and calculi, – computability.

1.5 Conclusions: Slogans

– A warning:

– this is a rigorous and formal course

– Two promises:

– many examples – few concepts and theorems Chapter 2

Language, Informally

2.1 Propositional Language, Informally

Propositional symbols are the elementary building blocks of a propositional (logic) language. Intuitively, they formalise atomic statements, that we do not need to decompose any further, and of which we can meaningfully ask the following question:

is the statement true?

According to such a criterion, “the program terminates” would qualify as an atomic statement, whereas “the program” would not.

7 8 CHAPTER 2. LANGUAGE, INFORMALLY

0 Statements, in symbols, are usually represented by p, q, r, pi, pi,. . . The following example lists several atomic statements and their formalisation with propositional symbols.

Example 1. Natural language atomic statements Formalisation The program terminates p The program computes the square root of 4 q The program has 4 as input r

Propositional formulae are specific sequences of propositional symbols and connec- tives: ∧ (“and”), ∨ (“or”), → (“if. . . then”), ¬ (“not”). Intuitively, they formalise compound statements.

In symbols, p → q,(p0 → p2) ∨ p1,...

Example 2. Natural language compound statements Formalisation (1) If the program terminates then it computes the square (p → q) root of 4 (2) If the program has 4 as input and it terminates then it ((r ∧ p) → q) computes the square root of 4 (3) If the program has 4 as input then, if it terminates, it (r → (p → q)) computes the square root of 4 (4) The program terminates or not (p ∨ (¬p)) 2.2. FIRST-ORDER LANGUAGE, INFORMALLY 9 2.2 First-order Language, Informally

The terms of a first-order language are:

– the nouns of our language: they are the expressions that can formalise objects of a domain, and the applications of functions to objects;

– the pronouns of our language: they allow to render variables, and the applications of functions to variables and objects of the domain.

Example 3. Consider the semi-group of natural number N = (N, ×, 1), then terms allow us to render 1, 2, but also 1 × 2, and x × 2.

The atomic formulae of a first-order language will be those formulae having neither connective nor quantifier ∀, ∃ symbols. They allow us to name relations between objects of a domain, and hence are obtained by applying relations symbols, like <, to terms.

Example 4. Consider the linear order Q = (Q, <), then atomic formulae allow us to formalise 1 < 2 as well as inequalities like x < 2 and y < 2.

The formulae of a first-order language are those expressions that can be (recursively) built up from the atomic formulae by use of the connective symbols and the quantifier symbols, ∀ and ∃, finitely many times.

Example 5. Consider the linear order Q = (Q, <), then first-order formulae allow us 10 CHAPTER 2. LANGUAGE, INFORMALLY to formalise that a system of inequalities over Q like  x < x  1 2  x2 < x3 .  .   xn < 2 has a solution: ∃x1 ... ∃xn(x1 < x2 ∧ · · · ∧ xn < 2). Chapter 3

Semantics and Interpretations, Informally

Interpreting symbols of a logic language with a semantics amounts to giving them “mean- ings”. Think of the process of interpreting the letters of a foreign language into your native language. There are two main types of interpretations:

– for propositional logic languages; – for first-order logic languages.

Propositional interpretations allow us to interpret connectives with a fixed interpreta-

11 12 CHAPTER 3. SEMANTICS AND INTERPRETATIONS, INFORMALLY tion, they behave like pattern words. Similarly, first-order interpretations allow us to interpret also quantifiers. Other symbols, like atomic formulae, have no fixed meaning. Interpretations allow us to attach temporary meanings to them. Think of interpreting variables of a system of linear inequalities. The interpretation depend on the domain over which, we say in maths, “variables range”. The interpretation of a compound formula is compositional, e.g., the interpretation of p0 ∧ p1 depends on the interpretation of p0 “and” that of p1. Example 6. Consider the following system of numerical inequalities.   x1 < x2 x2 < x3  x3 < 2

If the domain of interpretation is the linear order Q = (Q, <), then the first-order formula ∃x1∃x2∃x3(x1 < x2 ∧ x1 < x2 ∧ x3 < 2) allows us to formalise that the system of inequalities over Q has a solution, that is, the formula “is true in this interpretation”. The same formula can be interpreted over the natural order N = (N, <). Then the system has no solutions, that is, the same formula “is not true in this interpretation”.

Example 7. Consider the following statement—the fifth of Euclidean geometry.

Take a line l and a point A that does not belong to it. It is unique the line parallel to l and to which A belongs. 13

If l, A and “parallel” are given their standard interpretation in the Euclidean plane, than the statement is true. However, if lines and points are interpreted like in Figure 3.1, then the statement is no more true: there are infinite lines going through A and parallel to l.

Figure 3.1: The Klein-Beltrami model of hyperbolic 2-dimension geometry, in which points are interpreted as the points in the interior of the unit disc, and lines are in- terpreted as chords. Taken from wikipedia, http://en.wikipedia.org/wiki/Klein_ model. 14 CHAPTER 3. SEMANTICS AND INTERPRETATIONS, INFORMALLY Chapter 4

Proofs, Informally

4.1 Proofs

A mathematical proof is a proof of a statement. Generally, this statement is called the conclusion of the proof, or the thesis to be proved. The proof may use some statements as assumptions, also called hypotheses. For proceeding from its assumptions to its conclusion, a proof uses or proof rules. As for the axioms, think of Euclidean geometry at your high-school: axioms stated properties of points and lines. For instance, the fifth axiom of Euclides (in modern terms) states the following property of lines and points.

15 16 CHAPTER 4. PROOFS, INFORMALLY

Take a line l and a point A that does not belong to it. It is unique the line parallel to l and to which A belongs.

Such an axiom forbids interpreting points and straight lines as in Figure 3.1. Proof rules complement axioms for conducting proofs. In the following, we informally overview

– propositional rules,

– first-order rules,

– and a second-order rule about natural numbers.

Later on, we will study the first two types of rules formally, as rules of our proof theories. Note 1. In these notes, φ, ψ, θ,. . . represent statements. Θ, Γ,. . . represent sets of state- ments.

4.2 Propositional Proof Rules

Propositional proof rules concern compound statements of the form: ψ and φ; ψ or φ; if ψ then φ; not φ, that is, φ is false. 4.2. PROPOSITIONAL PROOF RULES 17

4.2.1 Conjunction

Conjunction introduction. Suppose we have a proof of a statement φ. Suppose that we also have a proof of a statement ψ. Then we can “glue” them into a proof of the statement φ and ψ. √ Example 8. 2 < 5 < 3. √ √ Proof. The conclusion can be rewritten as 2 < 5 and 5 < 3. In order to prove this, we proceed as follows: √ – build a proof of 2 < 5, √ – build a proof of 5 < 3, √ √ and obtain as conclusion 2 < 5 and 5 < 3.

Conjunction elimination. Vice-versa, if we have a proof for φ ∧ ψ, we can “reduce” it to a proof of φ (ψ).

4.2.2 Disjunction

Disjunction elimination. Suppose we have a proof of a statement φ by assuming ψ. Suppose that we also have a proof of the same statement φ by assuming ψ0. Then we can “glue” them into a proof of the statement φ with assumption ψ or ψ0. Let us make a simple example. 18 CHAPTER 4. PROOFS, INFORMALLY

Example 9. Let G = (V,E) be a directed graph. If E is reflexive or transitive then G is not a tree.

Proof. The proof goes as follows:

– assume that E is reflexive and prove that G has a cycle;

– assume that E is transitive and prove that G has a cycle.

Then we can conclude that if E is reflexive or transitive then G is not a tree.

Disjunction introduction. Suppose that we have a proof of ψ, or one of ψ0 with as- sumptions Θ. Then we can use one of such proofs in order to conclude ψ or ψ0 with assumptions Θ. Let us make a simple example.

Example 10. Prove that if n > 0 then n is even or odd.

4.2.3 Implication

Implication elimination. Vice-versa, if we have a proof that ψ implies φ (“if ψ then φ”), and a proof of ψ, both with assumptions Θ. Then we can “glue” them into a proof of ψ with assumptions Θ. Such a reasoning rule, the modus ponens, is often tacitly used in mathematical proofs, for reusing previously proved theorems. Inspect a typical usage of such a rule in a well known theorem of geometry, and you find it applied over and over. 4.2. PROPOSITIONAL PROOF RULES 19

Implication introduction. Suppose that we need to prove an implication statement of the form “if φ then ψ”, possibly with assumptions Θ. How do we prove it? We can assume φ as (additional) assumption, and conclude ψ from Γ and φ.

Example 11. If x is rational so is x2.

p 2 p2 Proof. Assume that x is rational: x = q for some integers p and q. Then x = q2 , which is still rational. We can conclude that if x is rational so is x2.

4.2.4 Negation

The inference rules concerning negation are rather powerful, and tricky. Negation elimination. Suppose that we have a proof concluding with φ, and another proof concluding that φ is false. What can we say? That we have proved something absurd! Negation introduction. Now, assume that φ is true. If we obtain an absurdity, then we can conclude that φ must be false. Reduction ad absurdum. The best known rule involving negation is the reductio ad absurdum (RAA) rule. In a proof by RAA of φ from Θ, one assumes that φ is false as additional assumption. Upon reaching an absurdum, one exits the proofs concluding that there must exist a proof of φ from Θ. Such proofs of existence are non constructive. Constructivists refuse it, see Section 5.1 of [van Dalen2004]. Let us make a simple example of a proof by RAA. 20 CHAPTER 4. PROOFS, INFORMALLY

Example 12. There are infinitely many natural numbers.

Proof. Assume that there are finitely many natural numbers. Let n be the maximum of them (∗). Then n + 1 is again a natural number (right?). But n < n + 1, contradicting (∗). Therefore there are infinitely many natural numbers.

4.2.5 Other Propositional Rules

Negation and Implication: Contradiction (Modus Tollens)

In a proof by contradiction or modus tollens of the implication “if ψ then φ”, one proves the contrapositive statement:

if φ is false then ψ is false as well.

Let us make a simple example. √ Example 13. If n is irrational then n is also irrational.

√ √ p Proof. We prove that if n is rational then n is rational. Assume that n = q for some 2 natural numbers p and q. Then n = p , which is rational as well. We can now conclude √ q2 that if n is irrational then n is also irrational.

This rule is often used for proving universal statements of the form “if for all elements of a certain domain ψ holds then for all elements of a certain domain φ holds”. The 4.3. FIRST-ORDER PROOF RULES 21 contrapositive then becomes “if for an element of a certain domain ψ is false then for an element of a certain domain φ is false as well”.

Derived Rule

Such a rule appears in jokes about mathematicians as the “by the previous case” rule. In brief: if you have obtained a proof of a statement A, you can use this in order to prove a new statement B. The justification is that you can always “glue” the proof of A into that for B.

4.3 First-order Proof Rules

In the following, we will be admittedly very informal and less general than with propo- sitional rules.

4.3.1 Universal quantifier elimination

Suppose that a statement holds for all the elements of a domain. We can then conclude that it holds for any specific element of that domain, independently of how this is chosen. Such a rule is a famous by Aristotele, exemplified as follows: 22 CHAPTER 4. PROOFS, INFORMALLY

All men are mortal. Socrates is a man. Therefore Socrates is mortal.

4.3.2 Universal quantifier introduction

Vice-versa, suppose that we aim at proving a statement concerning all elements of the domain. How do go about? We introduce a generic element of the domain, and prove the statement for it without using any specific property of such an element. This rule is better seen in the context of elementary geometry. Suppose we need to prove a statement concerning all triangles. What do we do, first? We draw a generic triangle, and make a proof with this. In the proof, we must take care not to use any specific property of the drawn triangle (e.g., the fact that one of its sides is 3 cm long). If we do so, then the proof is about all triangles, and not the specific drawn triangle.

Example 14. In any right triangle, the area of the square whose side is the hypotenuse is equal to the sum of the areas of the squares whose sides are the two legs.

Proof. There are many proofs of the pythagorean theorem in the example above, see http://en.wikipedia.org/wiki/Pythagorean_theorem. In the proofs, drawing and reasoning about a generic triangle plays a central role. 4.4. NATURAL INDUCTION PROOF RULE 23 4.4 Natural Induction Proof Rule

Natural numbers can be characterised as follows:

(1) 0 is an natural number; (2) if n is a natural number then n + 1 (the successor of n) is a natural number; (3) no other number is a natural number.

Given the above, we can prove statements S(n) about natural numbers, like

n X n × (n + 1) i = , (4.1) 2 i=0 by induction. A proof by induction goes as follows.

Base case. Prove S(0). Induction step. Assume S(n). Prove S(n + 1).

The assumption of the induction step is usually referred to as the induction hypothesis (IH), and the conclusion is the induction thesis (IT). Once we prove the base case and the induction step, clause (3) ensures that S holds for all natural numbers. Why? Because there is no other natural number besides those considered in the base case (clause (1)) and in the induction step (clause (2)). 24 CHAPTER 4. PROOFS, INFORMALLY

An equivalent form of induction proof goes as follows.

Induction step. Assume S(i), for all i < n. Prove S(n).

In this form of induction, the base case is covered in the induction step for n = 0. This is again split into an IH, and an IT to be proved using the IH. Chapter 5

Main Meta-questions

We are primarily interested in the below meta-questions concerning logic. We re-use the following example from Section 2.1 for intuitively explaining each question. Natural language compound statements Formalisation (1) If the program terminates then it computes the square (A → B) root of 4 (2) If the program has 4 as input and it terminates then it ((C ∧ A) → B) computes the square root of 4 (3) If the program has 4 as input then, if it terminates, it (C → (A → B)) computes the square root of 4 (4) The program terminates or not (A ∨ (¬A))

25 26 CHAPTER 5. MAIN META-QUESTIONS

Satisfiability: Is a formula consistent/satisfiable? Is a set of formulae consistent/satisfiable? √ Is (1) consistent? Intuitively, yes: take a program that terminates computing 4.

Validity: Is a formula φ valid, in symbols, |= φ? √ Is (1) valid? Intuitively, no: take a program that computes 4 but does not terminate. Is (4) valid? Intuitively, yes, independently of the program.

Entailment: Does a formula entail another one? Does a set Θ of formulae entail a formula φ, in symbols, Θ |= φ?

Does (2) entail (3)? Intuitively, yes, independently of the program.

Proof: Can we find a proof for φ? Can we find a proof of φ from ψ? And from Θ?

In other words, can you obtain a proof for (4), using propositional rules? Intu- itively, yes, independently of the program.

Soundness and completeness: Can we define the notion of proof so that a formula φ is provable iff |= φ? And so that a (set of) formula(e) Θ proves a formula φ iff Θ |= φ? Bibliography

[Apt et al.2010] Apt, K. R., de Boer, F. S., and Olderog, E.-R. (2010). Verification of Sequential and Concurrent Programs. Springer.

[van Dalen2004] van Dalen, D. (2004). Logic and Structure. Springer.

27