Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Bradley, Manna. The Calculus of Computation, Springer, 2007

.pdf
Скачиваний:
600
Добавлен:
10.08.2013
Размер:
2.75 Mб
Скачать

XII Contents

2.6.2 Decidability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 2.6.3 Complexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 2.7 Meta-Theorems of First-Order Logic . . . . . . . . . . . . . . . . . . . . . 56 2.7.1 Simplifying the Language of FOL . . . . . . . . . . . . . . . . . . . . 57 2.7.2 Semantic Argument Proof Rules . . . . . . . . . . . . . . . . . . . . . 58 2.7.3 Soundness and Completeness . . . . . . . . . . . . . . . . . . . . . . . 58 2.7.4 Additional Theorems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

2.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Bibliographic Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

3 First-Order Theories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

3.1 First-Order Theories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

3.2 Equality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

3.3 Natural Numbers and Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

3.3.1 Peano Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

3.3.2 Presburger Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

3.3.3 Theory of Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

3.4 Rationals and Reals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

3.4.1 Theory of Reals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

3.4.2 Theory of Rationals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

3.5 Recursive Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

3.6 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

3.7 Survey of Decidability and Complexity . . . . . . . . . . . . . . . . . . . 90

3.8 Combination Theories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91

3.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

Bibliographic Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

4 Induction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

4.1 Stepwise Induction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

4.2 Complete Induction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

4.3 Well-Founded Induction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

4.4 Structural Induction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

4.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110

Bibliographic Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

5 Program Correctness: Mechanics . . . . . . . . . . . . . . . . . . . . . . . . . .

113

5.1

pi: A Simple Imperative Language . . . . . . . . . . . . . . . . . . . . . . . . .

114

 

5.1.1

The Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

115

 

5.1.2

Program Annotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

118

5.2

Partial Correctness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

123

 

5.2.1

Basic Paths: Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

125

 

5.2.2

Basic Paths: Function Calls . . . . . . . . . . . . . . . . . . . . . . . . .

131

Contents XIII

5.2.3 Program States . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

5.2.4 Verification Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136

5.2.5 P -Invariant and P -Inductive . . . . . . . . . . . . . . . . . . . . . . . . 142

5.3 Total Correctness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143

5.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149

Bibliographic Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151

6 Program Correctness: Strategies . . . . . . . . . . . . . . . . . . . . . . . . . . . 153

6.1 Developing Inductive Annotations . . . . . . . . . . . . . . . . . . . . . . . . . 153

6.1.1 Basic Facts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154

6.1.2 The Precondition Method . . . . . . . . . . . . . . . . . . . . . . . . . . 156

6.1.3 A Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162

6.2 Extended Example: QuickSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

6.2.1 Partial Correctness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

6.2.2 Total Correctness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171

6.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172

Bibliographic Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173

Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173

Part II Algorithmic Reasoning

7 Quantified Linear Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 7.1 Quantifier Elimination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 7.1.1 Quantifier Elimination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 7.1.2 A Simplification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 7.2 Quantifier Elimination over Integers . . . . . . . . . . . . . . . . . . . . . . . 185 7.2.1 Augmented Theory of Integers . . . . . . . . . . . . . . . . . . . . . . 185 7.2.2 Cooper’s Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 7.2.3 A Symmetric Elimination . . . . . . . . . . . . . . . . . . . . . . . . . . 194 7.2.4 Eliminating Blocks of Quantifiers . . . . . . . . . . . . . . . . . . . . 195 7.2.5 Solving Divides Constraints . . . . . . . . . . . . . . . . . . . . . . . 196

7.3 Quantifier Elimination over Rationals . . . . . . . . . . . . . . . . . . . . . . 200 7.3.1 Ferrante and Racko ’s Method . . . . . . . . . . . . . . . . . . . . . . 200 7.4 Complexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204

7.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 Bibliographic Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205

8 Quantifier-Free Linear Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . 207

8.1 Decision Procedures for Quantifier-Free Fragments . . . . . . . . . . . 207

8.2 Preliminary Concepts and Notation . . . . . . . . . . . . . . . . . . . . . . . . 209

8.3 Linear Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213

8.4 The Simplex Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218

XIV Contents

8.4.1 From M to M0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 8.4.2 Vertex Traversal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 8.4.3 Complexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 8.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237

Bibliographic Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238

9 Quantifier-Free Equality and Data Structures . . . . . . . . . . . . . . 241 9.1 Theory of Equality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 9.2 Congruence Closure Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 9.2.1 Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 9.2.2 Congruence Closure Algorithm . . . . . . . . . . . . . . . . . . . . . . 247 9.3 Congruence Closure with DAGs . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 9.3.1 Directed Acyclic Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 9.3.2 Basic Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 9.3.3 Congruence Closure Algorithm . . . . . . . . . . . . . . . . . . . . . . 255 9.3.4 Decision Procedure for TE-Satisfiability . . . . . . . . . . . . . . . 256 9.3.5 Complexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258

9.4 Recursive Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 9.5 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 9.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 Bibliographic Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267

10 Combining Decision Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 10.1 Combining Decision Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 10.2 Nelson-Oppen Method: Nondeterministic Version . . . . . . . . . . . . 271 10.2.1 Phase 1: Variable Abstraction . . . . . . . . . . . . . . . . . . . . . . . 271 10.2.2 Phase 2: Guess and Check . . . . . . . . . . . . . . . . . . . . . . . . . . 273 10.2.3 Practical E ciency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274 10.3 Nelson-Oppen Method: Deterministic Version . . . . . . . . . . . . . . . 276 10.3.1 Convex Theories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276 10.3.2 Phase 2: Equality Propagation . . . . . . . . . . . . . . . . . . . . . . 278 10.3.3 Equality Propagation: Implementation . . . . . . . . . . . . . . . 282

10.4 Correctness of the Nelson-Oppen Method . . . . . . . . . . . . . . . . . 283 10.5 Complexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 10.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288 Bibliographic Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288

11 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291

11.1 Arrays with Uninterpreted Indices . . . . . . . . . . . . . . . . . . . . . . . . . 292

11.1.1 Array Property Fragment . . . . . . . . . . . . . . . . . . . . . . . . . . 292

11.1.2 Decision Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294

11.2 Integer-Indexed Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299

Contents XV

11.2.1 Array Property Fragment . . . . . . . . . . . . . . . . . . . . . . . . . . 300

11.2.2 Decision Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301

11.3 Hashtables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304

11.3.1 Hashtable Property Fragment . . . . . . . . . . . . . . . . . . . . . . . 305

11.3.2 Decision Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306

11.4 Larger Fragments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308

11.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309

Bibliographic Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310

Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310

12 Invariant Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 12.1 Invariant Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 12.1.1 Weakest Precondition and Strongest Postcondition . . . . 312 12.1.2 General Definitions of wp and sp . . . . . . . . . . . . . . . . . . . 315 12.1.3 Static Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 12.1.4 Abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 12.2 Interval Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325

12.3 Karr’s Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333 12.4 Standard Notation and Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 341 12.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344 Bibliographic Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345

13 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357

Part I

Foundations

Everything is vague to a degree you do not realize till you have tried to make it precise.

— Bertrand Russell

Philosophy of Logical Atomism, 1918

Modern design and implementation of software and hardware systems lacks precision. Design documents written in a natural language admit misinterpretation. Informal arguments about why a system works miss crucial weaknesses. The resulting systems are fragile. Part I of this book presents an alternative approach to system design and implementation based on using a formal language to specify and reason about software systems.

Chapters 1 and 2 introduce the (first-order) predicate calculus. Chapter 1 presents the propositional calculus, and Chapter 2 presents the full predicate calculus. A central task is determining whether formulae of the calculus are valid. Chapter 3 formalizes common data types of software in the predicate calculus. It also introduces the concepts of decidability and complexity of deciding validity of formulae.

The final three chapters of Part I discuss applications of the predicate calculus. Chapter 4 formalizes mathematical induction in the predicate calculus, in the process introducing several forms of induction that may be new to the reader. Chapters 5 and 6 then apply the predicate calculus and mathematical induction to the specification and verification of software. Specification consists of asserting facts about software. Verification applies mathematical induction to prove that each assertion evaluates to true when program control reaches it; and to prove that program control eventually reaches specific program locations.

Part I thus provides the mathematical foundations for precise engineering. Part II will investigate algorithmic aspects of applying these foundations.

1

Propositional Logic

A deduction is speech in which, certain things having been supposed, something di erent from the things supposed results of necessity because of their being so.

— Aristotle

Prior Analytics, 4th century BC

A calculus is a set of symbols and a system of rules for manipulating the symbols. In an interesting calculus, the symbols and rules have meaning in some domain that matters. For example, the di erential calculus defines rules for manipulating the integral symbol over a polynomial to compute the area under the curve that the polynomial defines. Area has meaning outside of the calculus; the calculus provides the tool for computing such quantities. The domain of the di erential calculus, loosely speaking, consists of real numbers and functions over those numbers.

Computer scientists are interested in a di erent domain and thus require a di erent calculus. The behavior of programs, or computation, is a computer scientist’s chief concern. What is an appropriate domain for studying computation? The basic entity of the domain is state: roughly, the assignment of values (for example, Booleans, integers, or addresses) to variables. Pairs of states comprise transitions. A computation is a sequence of states, each adjacent pair of which is a transition. A program defines the form of its states, the set of transitions between states, and the set of computations that it can produce. A program’s set of computations characterizes the program itself as precisely as its source code. Chapter 5 studies these ideas in depth.

With a domain in mind, a computer scientist can now ask questions. Does this program that accepts an array of integers produce a sorted array? In other words, does each of the program’s computations have a state in which a sorted array is returned? Does this program ever access unallocated memory? Does this function always halt? To answer such questions, we need a calculus to reason about computations.

41 Propositional Logic

This chapter and the next introduce the calculus that will be the basis for studying computation in this book. In this chapter, we cover propositional logic (PL); in the next chapter, we build on the presentation to define firstorder logic (FOL). PL and FOL are also known as propositional calculus and predicate calculus, respectively, because they are calculi for reasoning about propositions (“the sky is blue”, “this comment references itself”) and predicates (“x is blue”, “y references z”), respectively. Propositions are either true or false, while predicates evaluate to true or false depending on the values given to their parameters (x, y, and z).

Just as di erential calculus has a set of symbols, a set of rules, and a mapping to reality that provides its meaning, propositional logic has its own symbols, rules of inference, and meaning. Sections 1.1 and 1.2 introduce the syntax and semantics (meaning) of PL formulae. Then Section 1.3 discusses two concepts that are fundamental throughout this book, satisfiability (Is this formula ever true?) and validity (Is this formula always true?), and the rules for computing whether a PL formula is satisfiable or valid. Rules for manipulating PL formulae, some of which preserve satisfiability and validity, are discussed in Section 1.5 and applied in Section 1.6.

1.1 Syntax

In this section, we introduce the syntax of PL. The syntax of a logical language consists of a set of symbols and rules for combining them to form “sentences” (in this case, formulae) of the language.

The basic elements of PL are the truth symbols (“true”) and (“false”) and the propositional variables, usually denoted by P , Q, R, P1, P2, . . .. A countably infinite set of propositional variable symbols exists.

Logical connectives, also called Boolean connectives, provide the expressive power of PL. A formula is simply , , or a propositional variable P ; or the application of one of the following connectives to formulae F , F1, or F2:

¬F : negation, pronounced “not”;

F1 F2: conjunction, pronounced “and”;

F1 F2: disjunction, pronounced “or”;

F1 → F2: implication, pronounced “implies”;

F1 ↔ F2: i , pronounced “if and only if”.

Each connective has an arity (the number of arguments that it takes): negation is unary (it takes one argument), while the other connectives are binary (they take two arguments). The left and right arguments of → are called the antecedent and consequent, respectively.

Some common terminology is useful. An atom is a truth symbol , or propositional variable P , Q, . . .. A literal is an atom α or its negation ¬α. A formula is a literal or the application of a logical connective to a formula or formulae.

1.1 Syntax

5

Formula G is a subformula of formula F if it occurs syntactically within G. More precisely,

the only subformula of P is P ;

the subformulae of ¬F are ¬F and the subformulae of F ;

and the subformulae of F1 F2, F1 F2, F1 → F2, F1 ↔ F2 are the formula itself and the subformulae of F1 and F2.

Notice that every formula is a subformula of itself. The strict subformulae of a formula are all its subformulae except itself.

Example 1.1. Consider the formula

F : (P Q) → (P ¬Q) .

It contains two propositional variables, P and Q. Each instance of P and Q is an atom and a literal. ¬Q is a literal, but not an atom. F has six distinct subformulae:

F , P ¬Q , ¬Q , P Q , P , Q .

 

Its strict subformulae are all of its subformulae except F itself.

 

Parentheses are cumbersome. We define the relative precedence of the logical connectives from highest to lowest as follows: ¬, , , →, ↔. Additionally, let → and ↔ associate to the right, so that P → Q → R is the same formula as P → (Q → R).

Example 1.2. Abbreviate F of Example 1.1 as

F : P Q → P ¬Q .

Also,

P1 ¬P2 ¬P1 P2

stands for

(P1 ((¬P2) )) ((¬P1 ) P2) .

Finally,

P1 → P2 → P3

abbreviates

P1 → (P2 → P3) .

61 Propositional Logic

1.2 Semantics

So far, we have considered the syntax of PL. The semantics of a logic provides its meaning. What exactly is meaning? In PL, meaning is given by the truth values true and false, where true 6= false. Our objective is to define how to give meaning to formulae.

The first step in defining the semantics of PL is to provide a mechanism for evaluating the propositional variables. An interpretation I assigns to every propositional variable exactly one truth value. For example,

I : {P 7→true, Q 7→false, . . .}

is an interpretation assigning true to P and false to Q, where . . . elides the (countably infinitely many) assignments that are not relevant to us. That is, I assigns to every propositional variable available to us (and there are countably infinitely many) a value. We usually do not write the elision. Clearly, many interpretations exist.

Now given a PL formula F and an interpretation I, the truth value of F can be computed. The simplest manner of computing the truth value of F is via a truth table. Let us first examine truth tables that indicate how to evaluate each logical connective in terms of its arguments. First, a propositional variable gets its truth value immediately from I. Now consider the possible evaluations of F : it is either true or false. How is ¬F evaluated? The following table summarizes the possibilities, where 0 corresponds to the value false, and 1 corresponds to true:

F ¬F

0

1

1

0

The other connective can be defined similarly given values of F1 and F2:

F1 F2 F1 F2 F1 F2 F1 → F2 F1 ↔ F2

0

0

0

0

1

1

0

1

0

1

1

0

1

0

0

1

0

0

1

1

1

1

1

1

In particular, F1 → F2 is false i F1 is true and F2 is false. (Throughout the book, we use the word “i ” to abbreviate the phrase “if and only if”; one can also read it as “precisely when”.)

Example 1.3. Consider the formula

F : P Q → P ¬Q

and the interpretation

1.2 Semantics

7

I : {P 7→true, Q 7→false} .

To evaluate the truth value of F under I, construct the following table:

P Q ¬Q P Q P ¬Q F

1 0 1 0 1 1

The top row is given by the subformulae of F . I provides values for the first two columns; then the semantics of PL provide the values for the remainder of the table. Hence, F evaluates to true under I.

This tabular notation is convenient, but it is unsuitable for the predicate logic of Chapter 2. Instead, we introduce an inductive definition of PL’s semantics that will extend to Chapter 2. An inductive definition defines the meaning of basic elements first, which in the case of PL are atoms. Then it assumes that the meaning of a set of elements is fixed and defines a more complex element in terms of these elements. For example, in PL, F1 F2 is a more complex formula than either of the formulae F1 or F2.

Recall that we want to compute whether F has value true under interpretation I. We write I |= F if F evaluates to true under I and I 6|= F if F evaluates to false. To start our inductive definition, define the meaning of truth symbols:

I |=

I 6|=

Under any interpretation I, has value true, and has value false. Next, define the truth value of propositional variables:

I |= P i I[P ] = true

P has value true i the interpretation I assigns P to have value true.

Since an interpretation assigns a truth value to every propositional variable, I assigns false to P when I does not assign true to P . Thus, we can instead define the truth values of propositional variables as follows:

I 6|= P i I[P ] = false

Since true 6= false, both definitions yield the same (unique) truth values. Having completed the base cases of our inductive definition, we turn to

the inductive step. Assume that formulae F , F1, and F2 have truth values. From these formulae, evaluate the semantics of more complex formulae:

I |= ¬F

i I 6|= F

I

|=

F1

F2

i I |= F1 and I |= F2

I |= F1 F2

i I |= F1 or I |= F2

I

|=

F1

→ F2

i , if I |= F1 then I |= F2

I

|=

F1

↔ F2

i I |= F1 and I |= F2, or I 6|= F1 and I 6|= F2