Jump to content

Extracted text: Metamathematics-of-Computer-Programming-(Book).pdf

Markdown text generated by Apache Tika. Review it before citing; OCR may contain errors. The extraction timed out and is partial. View the PDF · File:Metamathematics-of-Computer-Programming-(Book).extracted.txt
Ján Komara and Paul J. Voda 

Metamathematics of Computer Programming 

Institute of Informatics, Comenius University, 

Bratislava 

April 30, 2001

Preface 

A Historical Parallel. 

We have seriously considered to call this book Principia Programmationis in allusion to the celebrated Principia Mathematica by Russell and White- head, which was published in 1911 in a gallant attempt to reduce mathemat- ics to logic. Mathematics had stormily developed and matured during the nineteenth century and there was a real need to lay it on firm foundations. Especially after the Russell’s paradox has shattered the monumental efforts in this direction by G. Frege and seriously dented the credibility of the naive set theory of G. Cantor. 

Logicians have agreed only much later that the attempt was futile because with its principle of infinity mathematics relies on extra-logical facts, i.e. facts which do not hold in all possible worlds. The Zermelo-Fraenkel set theory is nowadays accepted by most mathematicians as the foundations of mathematics. 

With the benefit of this hindsight we do not attempt in this book to re- duce computer programming to logic. We reduce it to the most basic of formal theories: to the formalization of arithmetic known as Peano Arithmetic (PA for short). We think that after a half-century of tumultuous development of computer programming languages, and after many presentations of formal theories of programming (some of which go even beyond the powers of ZF) we have succeeded in the explication of mosts aspects of modern computer programming languages in such a simple formal theory (at least as its se- mantics is concerned). We view our choice of PA as a kind of Occam’s razor. No programming language can be without arithmetic and we believe that nothing more is needed. 

We have been encouraged in this belief by the successful use of our imple- mentation of our computer programming language CL (C lausal Language) in teaching of mathematical logic and theory of programming for the last four years at University of Bratislava. We have approximately three hundred students per year taking four courses based on CL. CL is not only a program- ming language but also a formal system for the specification and proofs of properties of its programs.

Outline of the Text. 

There is one more parallel between Principia Mathematica and the present text. Both, in their detailed development of their respective subjects (which cannot be avoided for the first time), can be perceived as tedious. In our case we refer here to the development of Peano Arithmetic in Chapters 7 and 8. The development is necessary for the formal justification of general recursive definitions which are considered de rigueur in modern computer programming. 

We have included as an extended introduction a long Chapter 1 entitled Case for the Theory of Programming in Peano Arithmetic in order to shield a reader interested mainly in the general ideas of our philosophy from the rather technical development of the subject . We argue in the chapter in favor of the explication of computer programming in arithmetic. This means that an implemented computer programming language based on these concepts should use a formal system of arithmetic. Peano arithmetic is then the most natural choice. The introductory chapter covers the entire text in sufficient detail for the reader to understand our ideas and it avoids the formal appa- ratus of theorems and proofs although we present the necessary definitions with some technical details. If the reader is well-versed in mathematical logic and/or the theory of computer programming he might be even satisfied with the argument contained in the chapter. He will perphaps go to the following chapters only for a detail or two. 

The explication of computer programming in the arithmetic is formal- ly done in the Part II of this text. We have included the Part I, entitled First-order theories and Peano arithmetic, mainly as a prerequisite for the understanding of Part II. In this part we discuss first-order theories in gener- al and Peano arithmetic in detail. The part is inluded not only to make this text self-contained but also to investigate the proof system of CL which are the signed tableaux of Smullyan. Since we extensively use the proof system for concrete proofs (as opposed to merely investigating it metatheoretically), we present the tableaux in the positive sense as proving logical consequence rather than in the usual negative sense of deriving contradictions. In the chapters dealing with Peano arithmetic we then investigate strong schemas of extensions of PA by definitions which support the kinds of flexible recursive definitions needed in the practice of computer programming. 

The Part II is entitled Computer programming and it deals within the framework of PA with 

– the definition of the clausal language, – it is enlivened by many examples of actual CL programs together with 

proofs of their properties, – discusses in the metatheory the computation of clausal programs, – introduces data types in order to optimize the execution of clausal programs 

on computers, 

VI

– shows how to obtain the flexibility of high-order programming with func- tionals in the first-order Peano arithmetic, 

– discusses the questions of modularization and abstract specification of pro- grams in the language of second-order Peano arithmetic but within a frame- work which is conservative over PA and thus does not add any extra power (except expressivity) to it. 

Targeted Audience. 

We are fully aware that the answer to the question of whom is this text addressed to may solicit in the reader an unbelieving sneer, but the text is meant for three types of audience with all pairwise intersections almost empty. 

Students. The first type are the novices in the field of theory of comput- er programming where we use this book in the teaching of two courses to our second year undergraduate students. The first course is Logic for com- puter scientists where we teach mathematical logic (up to and including the Completeness theorem) and Peano arithmetic. We deal in the course with the predicate calculus (propositional, equational, and quantification logic) as cov- ered in Chapters 2 through 5) but rather than studying it formally, we stress the practical work in computer labs where we extensively use CL for proofs of tautological, quasitautological, logical, and arithmetical consequence. The latter consists of the development of Peano arithmetic as presented in Chap- ter 7 where we expect the students to prove all theorems of PA given in the chapter in the proof system of CL. 

The second course is Specification and verification of computer programs where we use the formulas of PA for the the specification of programs, clausal definitions for their definition, and the proof system of CL for the proofs that the defined functions and programs meet the specifications. We completely cover the Chapters 11 through 16 of Part II. The material contained in these chapters contains more than four hundred theorems, (most of them proved in the text) of programs with clausal definitions. The programs deal with numeric, list and tree processing, as well as with symbolic problems. Our students are expected to prove in CL all theorems given in the text. 

Logicians. The second type of audience are logicians interested in Comput- er Science. Obviously, they are not expected to have any problems with the material covered in Part I, but they might appeciate that the metatheory is completely finitary (we even give a new finitary proof of conservativity of Skolem axioms; something not normally done in the introductory texts). Lo- gicians are also familiar with at least two mathematically impeccably founded programming languages, namely the language of Primitive recursive functions and of Primitive recursive functionals of finite types (Gödel’s T). They also 

VII

know how to compute such functions effectively. They might, however, be not aware of complex set of requirements which the designers of computer programming languages have to meet. 

Of course, all logicians know that a computer programming language must be able to execute the programs efficiently. There are additional, no less im- portant, pragmatical requirements of readability, simplicity, easy programma- bility, extensibility, and modularity. These are necessary because computer programs are large and they constantly undergo change. A good computer programming language should have versatile data structures within a typed environment. It must have provisions for modular design where whole blocks of code can be replaced with a new one without affecting the rest of the pro- gram. Our logician readers might be interested in how do we propose to meet this formidable set of practical criteria within the constraints of both of the relatively terse language of PA and of the relative weakness of its axioms. 

Computer Scientists. The third, and probably the most critical, type of audience are Computer Scientists, especially those interested in the theory of programming. During the last fifty years an enormous number of computer programming languages emerged (and most of them quickly submerged) that our computer scientist reader is extremely sceptical of a yet another program- ming language. Moreover, a choice of a programming language is like a choice of dress to wear. Everyone has a strong set of preferences and adhers to a certain style. Just like fashion, programming languages are judged by value judgements with an apparent absence of objective criteria. Not all program- ming languages are based on a formal theory. This is not too unexpected as such languages are direct descedants of programs for Turing machines and the latter are basically kitchen recipes (do first this, then that, and repeat until done). 

A Theory of Computer Programming . 

The languages based on a formal theory widely differ in the strength of the theory. The theory may be as strong (even stronger) as ZF. For instance the languages based on the HOL (High-order logic) framework, or the language of the OBJ variety which are based in category theory. A wide group of languages is based on highly non-trivial theory of domains of Scott needed for the explication of continuous functionals. Examples are the well-known functional language Haskell and the language and the proof system PVS. 

We try to explicate computer programming in a style and strength in many respects similar to the Computational logic of Boyer and Moore. The main difference is that we use as basis a formalization of arithmetic and everyone is familiar with arithmetic (if not with PA) from high school. Not only is the semantic basis of CL simple, but also the language of clausal 

VIII

definitions is entirely within the language of Peano arithmetic. The definitions have no reserved words whatsoever. 

We know that many computer scientists, scarred by complexities of for- mal theories, tend to ignore them and they wholly concentrate on the writing of programs without pausing to ask what they do and what kind of objects they manipulate with. Situation is even worse because more often than not a programming language is designed only for its ellegant syntax and neat features. Only after the syntactical issues of its computation (so called op- erational semantics) have been fixed, the language designer starts to worry about the semantical issues of what the programs are (so called denotational semantics). 

This practice of syntax before semantics runs totally opposite to the typ- ical situation in mathematics where, as J. Shoenfield in the introduction to his Mathematical logic so convincingly argues: 

We may now describe what a mathematician does as follows. He presents us with certain basic concepts and certain axioms about these concepts. He then explains these concepts to us until we under- stand them sufficiently well to see that the axioms are true. He then proceeds to define derived concepts and to prove theorems about the basic and derived concepts. The entire edifice which he constructs, consisting of basic concepts, derived concepts, axioms, and theorems, is called an axiom system. 

This is exactly how we propose to build a framework for computer program- ming languages except that the edifice which we construct is a framework for programming languages. Our basic concept is that programs are com- putable functions. By the Thesis of Church-Turing the computable functions are Turing computable functions over natural numbers and so we decide that our programs are to be definitions of functions and predicates over natural numbers. We do not have to build the theory of natural numbers from the scratch because we can use its well-known formalization: Peano arithmetic. We still have to introduce the derived concepts as used in computer program- ming (data structures, types, etc.). And we also have to bootstrap PA to the extent that it admits a very flexible kind of extensions by clausal definitions of functions and predicates. Clausal definitions serve a dual purpose. They describe extensionally the properties of the defined functions and predicates and at the same time they serve intensionally as rules for the computation of these objects. 

Our experience with CL, which is an implementation of these ideas, shows that our students have no problems with understanding that they are writing programs operating over natural numbers. They also know that our coding of data structures into numbers in the style of LISP is perfectly natural. Finally, they can see that we can execute CL programs with the efficiency of Pascal and C operating over symbolic data structures. 

IX

Our Contributions. The main contribution of this book is an integrated attempt to explicate many of the issues of modern computer programming within a single framework of Peano Arithmetic. Within this overall goal there are some new perspectives which are our own: 

1\. the design of the clausal language with extensible syntax yet totally with- in the language of Peano arithmetic (no reserved words), 

2\. a new view of abstraction types (abstract data types) which goes around the sorts and congruences needed in the usual algebraic approach, 

3\. the development of a fragment of second-order Peano arithmetic which is conservative over first-order PA and offers a flexible calculus of extensions (modularization), 

4\. the characterization of a fragment of bland intensional functionals (as opposed to curried functionals) which can be introduced into PA with the typing comfort not available for the codes of primitive recursive (curried) functionals. 

In the Part I dealing with logic we have contributed the following: 

1\. a presentation of the Henkin reduction of quantification logic to tautolo- gies in three natural steps via quasitautological consequence, 

2\. a positive calculus of Smullyan’s signed tableaux which gives them the flavor of natural deduction, 

3\. a simple finitary proof of conservativity of Skolem axioms, 4. a simple new ∆0-definition of the graph 2x = y of the exponentiation 

function, 5. a simple ∆1-definable function V which is not provably recursive in PA. 

The function V is closely connected to the Wainer-Schwichtenberg fast growing hierarchies of functions. 

Acknowledgments. 

X

Table of Contents 

Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . V 

1\. Case for the Theory of Programming in Peano Arithmetic 1 1.1 Effectively Computable Functions . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Imperative vs. Declarative Programming . . . . . . . . . . . . . . . . . . 3 1.3 Arguments in Favor of Natural Numbers . . . . . . . . . . . . . . . . . . 9 1.4 Extensional Issues of Definability in PA . . . . . . . . . . . . . . . . . . . 21 1.5 Limits of Provably Recursive Definitions in PA . . . . . . . . . . . . . 40 1.6 Intensional Issues of Computability . . . . . . . . . . . . . . . . . . . . . . . 45 1.7 Intensional Functionals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 1.8 Second-Order Issues of Modularity . . . . . . . . . . . . . . . . . . . . . . . . 71 1.9 Issues Open to Further Research . . . . . . . . . . . . . . . . . . . . . . . . . 74 

Part I. First-Order Logic and Peano Arithmetic 

2\. First-Order Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 2.1 Language of First-Order Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 

3\. Propositional Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 3.1 Tautologies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 3.2 Propositional Tableaux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 3.3 Admissible Expansion Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 3.4 Tautological Consequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 3.5 Tableaux with Axioms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 

4\. Identity Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 4.1 Some Syntactic Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 4.2 Quasitautological Consequence . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 4.3 Identity Tableaux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 

5\. Quantification Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 5.1 Some Syntactic Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 5.2 Logical Consequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128

5\.3 Quantification Tableaux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 

6\. First-order Theories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 6.1 Theorems of Predicate Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . 149 6.2 Extensions of Theories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 6.3 Extensions by Explicitly Defined Predicates . . . . . . . . . . . . . . . . 156 6.4 Skolem Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 6.5 Extensions by Contextually Defined Functions . . . . . . . . . . . . . 170 6.6 Extensions by Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 

7\. Peano Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 7.1 Basic Theorems in PA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 7.2 Extensions of PA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 7.3 Introduction of Basic Predicates into PA . . . . . . . . . . . . . . . . . . 184 7.4 Introduction of Basic Functions into PA . . . . . . . . . . . . . . . . . . . 188 7.5 The Lattice of Divisibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 

8\. Recursive Bootstrapping of PA . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 8.1 Exponentiation Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 8.2 Primitive Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 8.3 Suitable Pairing Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 8.4 Course of Values Recursion with Measure . . . . . . . . . . . . . . . . . . 242 

9\. Proof Theory of PA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 

Part II. Computer Programming 

10\. Clausal Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 10.1 Generalized Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 10.2 Clausal Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270 10.3 The Strength of Clausal Definitions . . . . . . . . . . . . . . . . . . . . . . . 270 

11\. Numeric Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 11.1 Explicit Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 11.2 Primitive Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 11.3 Course of Values Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 11.4 Recursion on Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 11.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 

12\. Programs Operating on Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 12.1 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 12.2 Operations on Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308 12.3 Combinatorial Functions over Lists . . . . . . . . . . . . . . . . . . . . . . . 317 12.4 Sorting of Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322 12.5 Applications of Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330 

XII

12\.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335 

13\. Programs Operating on Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337 13.1 Binary Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337 13.2 Binary Search Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343 13.3 Perfectly Balanced Binary Trees . . . . . . . . . . . . . . . . . . . . . . . . . . 347 13.4 Applications of Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356 13.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361 

14\. Programs Operating on Symbolic Expressions . . . . . . . . . . . . 363 14.1 Numeric Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364 14.2 Pair Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368 14.3 Propositional Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373 14.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384 

15\. Programs Operating on Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . 387 15.1 Basic operations on arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387 

16\. Programs Operating on Word Domains . . . . . . . . . . . . . . . . . . . 393 

17\. Computation of Clausal Programs . . . . . . . . . . . . . . . . . . . . . . . . 395 17.1 Computation over Monadic Numerals . . . . . . . . . . . . . . . . . . . . . 395 17.2 Computation over Binary Numerals . . . . . . . . . . . . . . . . . . . . . . . 396 17.3 Computation over Pair Numerals . . . . . . . . . . . . . . . . . . . . . . . . . 397 17.4 Computation over Mixed Numerals . . . . . . . . . . . . . . . . . . . . . . . 398 

18\. Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401 18.1 Pascal-Style Typing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401 18.2 ML-Style Typing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403 

19\. Functional Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405 

20\. Modular Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407 

Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408 

XIII

1\. Case for the Theory of Programming in Peano Arithmetic 

This chapter is intended as an extended introduction. We informally present in it the entire material of this text. We argue here in favor of declarative programming over the domain of natural numbers within the most funda- mental of formal theories: Peano arithmetic. Our argument is not in favor of a single language. We argue for the use of PA as a framework for the theory of computer programming. Although we occasionally discuss our language CL it should be understood only as an example of a possible implemetation of the ideas. 

The style of presentation in this chapter is aimed at logicians and comput- er scientists. We suppose that the reader is acquainted with the language and basic methods of first-order logic as well as with the basic issues of the theory of computer programming languages. Undergraduate students will probably not be able to follow the exposition unless they have had a first reading ex- posure to the predicate calculus and the theory of programming languages. 

An important note: The extended introduction temporarily serves also as a detailed description of the yet not written chapters and sections. This should explain a more detailed overview of these parts here. Eventually, when the missing chapters and sections will be supplied, some of the explanatory material will be removed. The level of presentation of parts not yet written is usually higher and more technical than the level of finished parts because the description is meant for expert logicians and computer scientists who might be refereeing this text. 

1\.1 Effectively Computable Functions 

1\.1.1 Formal systems. Both mathematical logic and theory of computer programming study formal systems. Formal systems deal with concretely presented syntactic objects. Syntactic objects in logic are terms and formulas and programs in computer programming. 

Syntactic objects are usually assigned denotations in some mathematical domain. The usual presence of a system of derivations with rules of inference is the main reason for the study of formal systems in the logical discipline called metamathematics. Semantic questions of denotation are usually non-

constructive whereas the manipulation of syntactic objects can be done by effectively computable processes. 

1\.1.2 Effectively computable functions. Mathematical logic was devel- oped in order to give firm foundations to mathematics. As it turned out, the characterization of effectively computable functions in logic was an impor- tant subgoal of this foundational goal. Such functions can be evaluated by a mechanical procedure. Alan Turing gave in 1936 a completely satisfactory explication of computable functions by means of what is now called Turing machines. He used the term computer to designate the agent performing the mechanical procedure. Turing meant a human computer, but as it turned out some ten years later chiefly by efforts of John von Neumann and Turing himself, computers could be constructed as mechanical or electronic devices. 

The theory of computer programming studies the effectively computable functions but due to the practical limitations of computer hardware it has to deal mostly with its rather small subclass of efficiently (feasibly) computable function. 

1\.1.3 The domain of effectively computable functions. Although one can develop the theory of computable functions over integers (both negative and positive numbers), over a subset of real numbers, over word domains, or over many suitably structured domains; logicians know that it suffices to restrict the theory of computable programs to the domain N of natural numbers: 0, 1, . . . . This is, first of all, because the greatest success of nineteen century mathematics was the discovery that all numeric domains can be defined from the domain of natural numbers. The second reason is that K. Gödel in the proof of his Incompleteness theorem convincingly demonstrated that symbolic (syntactic) objects can be coded into numbers. The process of coding is called arithmetization and the codes are Gödel numbers. 

Whether we can do the same reduction to N of domains of computer programming languages is by no means obvious. We will argue in Sect. 1.3 in favor of the reduction but the majority of computer scientists think that special domains are necessary in order to attain efficiency. 

1\.1.4 Notational basis for computable functions. We know from ele- mentary school that addition and multiplication can be effectively computed when their operands are concretly presented as, say, decimal numerals. The choice of notation basis is not important when we are interested only in ef- fectivity and so mathematicians prefer monadic notation where the natural number n is presented as the syntactic object, called a monadic numeral: 

(0 

n︷︸︸︷ ′ . . .′). When we want also efficiency then the base should be positive and the 

most natural one for electronic computers is binary. Binary numerals are 

2

terms constructed from the constant 0 by applications of two unary functions, called binary successors, and written in a postfix notation: x0 = 2·x + 0 and x1 = 2·x + 1. The reader will note that, for instance, we have 

5 = 2·(2·(2·0 + 1) + 0) + 1 = 0101 . 

Leading zeroes cause notational ambiguity because 1 = 01 = 001 = 0001 . . . and so we require that binary numerals of a form τ0 have the term τ 6≡ 0. We designate by nb the binary numeral denoting the number n. This term yielding function satisfies: 

0b ≡ 0 n0b ≡ nb0 if n \> 0 n1b ≡ nb1 . 

The reader will note that for any number x we have 

x = 0 ∨ ∃z(x = z0 ∧ z \> 0) ∨ ∃z x = z1 

with the numbers z uniquely determined, and with the three conditions pair- wise exclusive. 

1\.1.5 Closure of operations over natural numbers. Addition and mul- tiplication are closed over natural numbers. This means that both x + y and x·y are natural numbers when x and y are. The remaining two basic arith- 

metical operations go outside of natural numbers, for instance 3 − 5 and 3 5 . 

We must use instead modified subtraction x .− y satisfying: 

x .− y = 

{ x− y if x ≥ y, 0 otherwise 

and integer division and remainder functions x÷ y and x mod y satisfying: 

y \> 0 → x = (x÷ y)·y + x mod y ∧ x mod y \< y 

x÷ 0 = x mod 0 = 0 . 

All five basic arithmetic functions over N can be efficiently computed by elementary school algorithms. 

Unless we explicitly say otherwise all our functions and predicates will be over natural numbers until the end of this chapter. Also our variables and quantifiers will range over natural numbers. 

1\.2 Imperative vs. Declarative Programming 

The style of programming derived from operations of Turing machines where programs are recipes for the manipulation of computer’s store is called in 

3

computer science imperative programming. The style of programming where programs are definitions of mathematical objects such as functions or predi- cates is called declarative programming. The difference between the two styles is best explained with two definitions of the greatest common divisor function. 

1\.2.1 Greatest common divisor. The binary relation x divides y, in sym- bols x \| y, can be defined in the language of logic by 

x \| y ↔ ∃z x·z = y . 

A number z is the greatest common divisor of x and y, in symbols gcd(x, y) = z, iff x = y = 0 and z = 0 or if x + y \> 0 and z divides both x and y where z is the largest of such numbers d: 

x + y \> 0 → z \| x ∧ z \| y ∧ ∀d(d \| x ∧ d \| y → d ≤ z) . (1) 

We have 1 \| x and 1 \| y and so when x + y \> 0 we can effectively find the greatest common divisor by a brute force search which starts from x and goes downwards towards 1. 

The ancient mathematician Euclides discovered a faster algorithm com- puting gcd which relies on the following property of divisibility: 

y \> 0 → (z \| x ∧ z \| y ↔ z \| y ∧ z \| x mod y). (2) 

1\.2.2 The algorithm of Euclides imperatively. The algorithm of Eu- clides can be expressed by an imperative computer program in the style of Pascal as: 

{x = x0 ∧ y = y0} while y \> 0 do (1) 

a := x mod y; x := y; y := a; {gcd(x0, y0) = x} . 

The algorithm proceeds by operation on three registers x, y, and a located on the tape of a Turing machine or in the memory of a computer. It is basically a kitchen recipe which says that the contents of the three registers should be repeatedly swapped in the given order as long as the register y contains a positive number. 

When the algorithm is started with the registers x and y containing the numbers x0 and y0 respectively and with arbitrary contents of the contents of register a then when, and if, the swapping terminates the register x will contain the number gcd(x0, y0). The reader will note that the text enclosed within the pair of braces {} is not a part of the program and should be viewed as a remark. 

For arguments x0 = 12 and y0 = 21 we need six tests of the register y which happen in the following sequence of memory snapshots with the contents of registers given immediately above the single solid lines: 

4

x y a 

12 21 − 12 21 12 21 21 12 21 12 12 21 12 9 12 12 9 12 9 9 12 9 3 9 9 3 9 3 3 9 3 0 3 3 0 3 0 0 

1\.2.3 The algorithm of Euclides declaratively. We will discuss in Part II of this text how Peano arithmetic, which is a well-known logical theory formalizing the arithmetic, permits an introduction of the binary function symbol gcd by a clausal definition: 

gcd(x, 0) = x (1) gcd(x, y) = gcd(y, x mod y) ← y \> 0 . (2) 

The reader will note that ←, which is customarily used in clausal definitions, is just a converse implication. The two clauses should be understood as the axioms implicitly characterizing the function gcd. The definition is legal be- cause a meausure of the two arguments x and y goes down in recursion. The measure is the second argument y and since, the following is easily provable in PA: 

y \> 0 → x mod y \< y , 

the second argument x mod y of the recursive application gcd(y, x mod y) in the clause (2) decreases because the clause is applied only when y \> 0. 

Incidentally, this is exactly the reason why the imperative program (1) always terminates. We, namely, go into the while only when y \> 0. The register y will contain x mod y just before the next iteration where x and y are the values at the moment of the entry to the while. 

The computation of gcd(12, 21) can be visualized as a sequence of syn- tactic operations, called reductions, which are initially applied to the term gcd(12, 21) and which use the two clauses in an attempt to simplify the term to a numeral: 

gcd(12, 21) (2) = gcd(21, 12) 

(2) = gcd(12, 9) 

(2) = gcd(9, 3) 

(2) = gcd(3, 0) 

(1) = 3 . 

The reader will note that the computation sequence is structurally equivalent to the underlined memory snapshots for the imperative program where the two arguments of gcd play the role of the registers x and y. 

5

1\.2.4 Proving the two gcd programs correct. We will now briefly look into the question of how to formally ensure that the imperative and declara- tive programs for the greatest common divisor work correctly. The function gcd is uniquelly determined by satisfying its specification 1.2.1(1) in the fol- lowing form: 

gcd(x, y) \| x ∧ gcd(x, y) \| y (1) x + y \> 0 ∧ d \| x ∧ d \| y → d ≤ gcd(x, y) (2) 

gcd(0, 0) = 0 . (3) 

The simplest way of proving the correctness of the imperative program is to reason in a system of formal arithmetic, say PA, where we have already demonstrated the conditions (1) through (3). From the conditions we prove the recurrences 1.2.3(1)(2). We then annotate the imperative program with comments as follows: 

{x = x0 ∧ y = y0 ∧ gcd(x, y) = gcd(x0, y0)} while y \> 0 do 

a := x mod y; x := y; y := a; {gcd(x, y) = gcd(x0, y0)} 

{y = 0 ∧ x 1.2.3(1) 

= gcd(x, 0) = gcd(x, y) = gcd(x0, y0)} . 

We can then use the calculus of pre and post conditions by A. Hoare and show that the formulas given at the annotated points can be proved. The formula gcd(x, y) = gcd(x0, y0) is an invariant of the while loop because it holds whenever one tests y \> 0. 

In order to prove that the invariant holds at the end of the body of the loop one has to prove in Hoare’s calculus: 

{x = x1 ∧ y = y1 ∧ gcd(x1, y1) = gcd(x0, y0)} a := x mod y; {a = x1 mod y1 ∧ y = y1 ∧ gcd(x1, y1) = gcd(x0, y0)} x := y; {a = x1 mod y1 ∧ x = y1 ∧ gcd(x1, y1) = gcd(x0, y0)} y := a; {y = x1 mod y1 ∧ x = y1} {gcd(x, y) = gcd(y1, x1 mod y1) 

1\.2.3(2) = gcd(x1, y1) = gcd(x0, y0)} 

In order to prove the correctness of the declarative definition of the func- tion gcd by clauses 1.2.3(1)(2) we have to demonstrate its specification for- mulas (1) through (3). 

We prove ∀x(1) by complete induction on y. We take any x and consider two cases. If y = 0 then, since gcd(x, 0) = x by 1.2.3(1), we trivially have gcd(x, 0) \| x and gcd(x, 0) \| 0. If y \> 0 then we have gcd(x, y) = gcd(y, x mod y) by 1.2.3(2) and, since x mod y \< y, we obtain gcd(y, x mod y) \| y and 

6

gcd(y, x mod y) \| x mod y by IH. We then use 1.2.1(2) to get gcd(y, x mod y) \| x. 

We prove ∀x(2) by complete induction on y. We take any x, assume x + y \> 0, d \| x, d \| y and consider two cases again. If y = 0 then, since we must have x \> 0, we get d ≤ x = gcd(x, 0). If y \> 0 then, since d \| x mod y by 1.2.1(2) and y \< x mod y, we get 

d IH≤ gcd(y, x mod y) = gcd(x, y) . 

Property (3) trivially follows from 1.2.3(1). 

1\.2.5 Imperative versus declarative programming I. If we do not care about the correctness of our programs and are concerned only with their effi- ciency then we should probably program imperatively because such program- ming is with few restrictions. If we are willing to live with some restrictions of declarative programming then as discussed in Par. 1.2.7 the declarative development of highly symbolic programs can be faster and cheaper even without proofs of correctness. 

If the correctness of our programs is important then the proofs are much easier for declarative programs as was shown in the preceding paragraph. In both cases we had to use a formal theory axiomatizing the domain of our objects. For the example of the greatest common divisor the domain was N and so the the formal theory will probably be PA. In both cases we had to introduce the function gcd into the theory and prove some of its properties. 

For the proof of the declarative program we never left PA because the clausal definition of the new function was in the language of PA and its clauses were axioms. The proof proceeded by simple induction. 

For the proof of the imperative program we uses two languages: the im- perative programming language and the language of PA. We also used two formal systems: the calculus of Hoare and PA. The correctness proof was much longer, we had to introduce auxiliary variables, and at the end we have proven only the partial correctness of the program. We still have to do an inductive proof that the program always terminates. 

The only argument in favor of imperative programming is efficiency. In the given example both programs have comparable efficiency. In the following paragraph we show the same for another example. 

1\.2.6 Fibonacci function. The function fib(n) yielding the n-th element of the well-known sequence of Fibonacci satisfies the following recurrences: 

fib(0) = 1 (1) fib(1) = 1 (2) fib(n + 2) = fib(n + 1) + fib(n). (3) 

The definition is by a straightforward recursion decreasing the argument in \<. We can directly use the recurrences for computations. For instance, we 

7

can compute fib(4) = 3 as follows: 

fib(4) (3) = fib(3) + fib(2) 

2×(3) = fib(2) + fib(1) + fib(1) + fib(0) 

(3);2×(2);(1) = 

fib(1) + fib(0) + 1 + 1 + 0 (2);(1) 

= 1 + 0 + 2 = 3 . 

The only problem is that the computation sequence is too long. In order to compute the number fib(n + 2) one needs to use the recurrence (3) exactly fib(n+2) times as can be proved by a simple induction. The Fibonacci func- tion grows as fast as the exponential function and to compute the function in this way is simply too wasteful. 

The following Pascal-like program computes fib(n) into the variable b: 

a := 1; b := 0; while n \> 0 do 

n := n .− 1; c := a; a := a + b; b := c; 

The reader will note that the loop is executed only n times. This example is usually given as the ‘standard argument’ against declarative programming where the recursive version is clearly inferior to the imperative one. The argument is fallacious as one should define an auxiliary ternary function f(n, a, b) with two accumulators a and b by primitive recursion decreasing the first argument: 

f(0, a, b) = b f(n + 1, a, b) = f(n, a + b, a). 

By straightforward induction on n we can then prove: 

∀k f(n, fib(k + 1), fib(k)) = fib(n + k) 

and then explicitly define: 

fib(n) = f(n, 1, 1). 

The number of recursions of f is exactly the same as the number of iterations of the loop of the imperative program. Moreover, a good compiler can remove the so called tail recursion in the definition of f and compile it exactly as the while-loop in the above Pascal-like program. 

1\.2.7 Imperative versus declarative programming II. Imperative pro- grams can be better compiled than declarative ones when large data struc- tures are modified in them. Imperative programs can do updates directly in the memory. This is not possible in declarative programs without some restrictions. We will discuss this point in more detail UNFINISHED and only note here that our implementation of CL is written in the declarative programming language Trilogy 2 designed and implemented in 1991 by one of the authors. Trilogy 2 has declarative provisions for in situ updates and thus 

8

the CL compiler excecutes with comparable efficiency as if it were written in an imperative language. 

Trilogy programs, by being declarative, are on a much higher level of abstraction than the commands for the modification of storage typical for imperative programming. It is our estimate that the cost of implementation and maintenance of the Trilogy 2 compiler for CL was about a quarter of what the cost would have been had we implemented CL in an imperative language. 

1\.3 Arguments in Favor of Natural Numbers 

We have argued in the prececeding section in favor of declarative over im- perative programming. With the decision that our programs should have denotations as functions and predicates we must still decide on the domain of interpretation. We know from Church-Turing thesis that natural numebers suffice as the domain of computable functions. In this section we extend the argument to programming languages and we outline a natural development of data structures needed in computer programming within the domain N. This kind of development is called arithmetization. 

Arithmetization of Word Domains. 

1\.3.1 Word domains. Turing machines operate over word domains which consist of finite sequences of symbols from an alphabet. More precisely, an alphabet Σ is given by a finite set of symbols {a1, a2, · · · , an}. A word over an alphabet Σ is a finite sequence of symbols of Σ. The empty word is the empty sequence denoted by ∅. The length of a word is the length of its sequence. The domain of words over Σ, denoted by Σ∗, is the set of all words over Σ. 

Theory of computability codes a natural number n by a word of length n over a one element alphabet where a1 ≡ \|. We denote by \|n the sequence 

n︷ ︸︸ ︷ \| · · · \|. A finite sequence of numbers x1, x2, . . . , xn can be then coded as a word over the two element alphabet a1 ≡ \|, a2 ≡ # as 

\#\|x1#\|x2 . . . #\|xn . 

1\.3.2 Arithmetization of word domains. Word domains are by no means more general than natural numbers. We can turn functions over the word domain Σ∗ given by the p-element alphabet Σ = {a1, a2, · · · , ap} into functions over natural numbers by means of p-adic representation of natu- ral numbers. For that purpose we define p functions, called p-adic successor functions, S1, S2, . . . , Sp as follows: 

Si(x) = p·x + i . 

9

It is not difficult to see that every natural number has a unique representation as a p-adic numeral: 

Sim Sim−1 . . . Si2 Si1(0) 

where m ≥ 0 and for every 1 ≤ j ≤ m we have 1 ≤ ij ≤ p. This p-adic numeral codes the word ai1ai2 . . . aim 

. Note that the empty word ∅ is coded by the p-adic numeral 0. Thus every natural number is a code of exactly one word over Σ. P -adic numerals should be viewed as concrete objects consisting of terms in the form of sequences of function symbols Si which are terminated by 0. 

The reader will note that the monadic representation of natural numbers introduced in Par. 1.1.4 is a special case of p-adic representation with p = 1. The monadic successor function S1(x) = 1·x+1 = x′ is the successor function. 

1\.3.3 Dyadic representation of N. A special case of p-adic representa- tion with p = 2 is the dyadic representation. The advantage of the dyadic representation over binary (see Par. 1.1.4) is that there is no restriction on leading digits. The dyadic successor functions S1 and S2 are written in the postfix notation: x1 = 2·x + 1 and x2 = 2·x + 2. Dyadic numerals are the least class of terms containing the constant 0 and with every term τ also the terms τ1 and τ2. 

Consider the first eight words from the sequence of words over the two symbol alphabet 1, 2 which is ordered first on the length and within the same length lexicographically: 

∅, 1, 2, 11, 12, 21, 22, 111, . . . 

The corresponding dyadic numerals are: 

0 = 0 01 = 2·0 + 1 = 1 02 = 2·0 + 2 = 2 

011 = 2·(2·0 + 1) + 1 = 3 012 = 2·(2·0 + 1) + 2 = 4 021 = 2·(2·0 + 2) + 1 = 5 022 = 2·(2·0 + 2) + 2 = 6 

0111 = 2·(2·(2·0 + 1) + 1) + 1 = 7 . 

The process of going from operations over certain domain to the opera- tions over the codes of elements of the domain in N is called the arithmeti- zation of the domain. 

1\.3.4 Dyadic size. The dyadic size function \|x\|d yields the number of dyadic successors in the dyadic numeral denoting the number x. The function 

10

is the arithmetization of the word-size function taking a word over {1, 2} and yielding its length. The dyadic size function has a clausal definition: 

\|0\|d = 0 \|x1\|d = \|x\|d + 1 \|x2\|d = \|x\|d + 1 . 

Clearly, the numbers x such that 

2n − 1 = 01n ≤ x ≤ 02n = 2n+1 − 2 

and no others have the dyadic size n. 

1\.3.5 Dyadic concatenation. The basic operation over words is concate- nation. For instance, the words 211 and 122 over the alphabet {1, 2} are concatenated into the word 211122. 

The arithmetization of concatenation over the alphabet {1, 2} is the bi- nary function x ? y, called dyadic concatenation. It yields a number whose dyadic representation is obtained from dyadic representations of x and y by appending the digits of y after the digits of x. The function has the following clausal definition: 

x ? 0 = x (1) x ? y1 = (x ? y)1 (2) x ? y2 = (x ? y)2 . (3) 

The dyadic word 211 is coded by the number 0211 = 11 and the word 122 by 0122 = 10. We obtain the code of the concatenated word 211122 by using the clauses of the dyadic concatenation function in a computation as follows: 

0211 ? 0122 (3) = (0211 ? 012)2 

(3) = (0211 ? 01)22 

(2) = (0211 ? 0)122 

(1) = 0211122 . 

The reader will note that although the code of the concatenated words is 0211122 = 88, the computation can proceeds by a simple rewriting without ever having to convert into the decimal notation. 

The arithmetization of word domains is so natural that we will identify words with their codes. 

Arithmetization of Finite Sequences. 

1\.3.6 Symbolic domains. Computer programming, in addition to the s- tandard numerical types, involves a large number of data structures such as n-tuples, multidimensional arrays (vectors and matrices), lists, stacks, tables, trees, graphs, etc. Standard programming languages (both imperative and functional ones) therefore work with quite complicated domains obtained by solutions of recursive identities. We think that this is an unnecessary compli- cation and we look for a solution to the programming language LISP which 

11

offers excellent coding of symbolic data structures into the domain of S- expressions. This domain is freely generated from the set of countably many atoms by a binary operation cons. There is no advantage in having infinitely many atoms, just one, say, nil suffices. There is also no advantage of having S-expressions as a separate domain. Nothing is lost and much is gained by the arithmetization of the domain of S-expressions in N. 

1\.3.7 Pairing function. We obtain the coding convenience of LISP in the domain of natural numbers by arithmetizing the domain of symbolic expres- sions with the help of a suitable binary pairing function (x, y). The function, which, will be discussed in detail in Sect. 8.3, will have the following proper- ties: 

(x, y) = (v, w) → x = v ∧ y = w (1) v \< (v, w) ∧ w \< (v, w) (2) 

x = 0 ∨ ∃v∃w x = (v, w) . (3) 

The property (1) is called the pairing property and it ensures that for every number n in the range of the pairing function, i.e. such that n = (x, y) for some x and y, the numbers x and y, called the first and second projections of n respectively, are uniquely determined. The pairing property says that the pairing function is an injection. From the property (2) we get 0 ≤ x \< (x, y). This means that 0 is not in the range of the pairing function and so it has no projections, i.e. 0 6= (x, y). Thus the number 0 is an atom and plays the role of the atom nil of LISP. The property (3) asserts that the pairing function is onto the set N \\ {0}, i.e. that 0 is the only atom. 

1\.3.8 Pair numerals. It can be easily proved by complete induction that every natural number n can be uniquely presented as a term called pair numeral. The class of pair numerals is the least class of terms containing 0 and with every two terms τ1 and τ2 also the term (τ1, τ2). We call this the pair representation of N. 

1\.3.9 Pair size. The length of the pair numeral τ denoting the number x is 5·n+1 where n is the number of pairing operations used in the construction of the term τ . The arithmetization of the length function is the pair size function \|x\|p yieding the number of pairing operations needed for the construction of the pair numeral denoting x. The function is defined by the following clausal definition: 

\|0\|p = 0 \|(x, y)\|p = \|x\|p + \|y\|p + 1 . 

1\.3.10 Cantor’s pairing function. Without fixing the pairing function (x, y) we do not know the pair representation of any natural number except 0 

12

and our next step is to determine the function. We first note that the standard diagonal function J of Cantor (see \[4\]) when offset by one (to account for the atom 0), i.e. the function 

J(x, y) = (x + y)·(x + y + 1)÷ 2 + x + 1 , 

satisfies the properties 1.3.7(1) through 1.3.7(3). The initial segment of J is tabulated in Fig. 1.1. The subscripts of values for J(x, y) give the pair size \|J(x, y)\|p. 

J(x, y) 0 1 2 3 4 5 6 · · · 0 11 22 43 73 114 164 224 · · · 1 32 53 84 124 175 235 305 · · · 2 63 94 135 185 246 316 396 · · · 3 103 144 195 255 326 406 496 · · · 4 154 205 266 336 417 507 607 · · · 5 214 275 346 426 517 617 727 · · · 6 284 355 436 526 627 737 857 · · · ... 

... ... 

... ... 

... ... 

... 

Fig. 1.1. Pairing function J(x, y) 

Unfortunately, the pairing function J is not suitable for us because it cannot be used for the development of small functional computational class- es such as polynomial time, polynomial space, linear space etc. This was demonstrated in \[24\]. The reason why J is not suitable can be seen when we enumerate the natural numbers in the J-pair representation. The numbers with the same pair size are not grouped together as it is the case with the binary size of numbers enumerated in the binary notation. We can see from Fig. 1.1 that in the middle of the group of consecutive numbers 4 through 10 we have two numbers with the pair size 4, namely 8 = J(J(0, 0), J(0, J(0, 0))) and 9 = J(J(0, J(0, 0)), J(0, 0)), while the remaining numbers have the pair size three. 

1\.3.11 Suitable pairing function. We obtain a suitable pairing function (x, y) by keeping the numbers with the same pair size together. For that we note that every natural number in pair representation can be viewed as a binary tree. Here 0 is represented by the empty tree and the number (x, y) is represented by a tree with the left subtree representing x and the right subtree representing y. Note that that the number of inner nodes of the tree representing x is \|x\|p. We enumerate all binary trees by listing the binary trees with the lesser number of inner nodes before the ones with larger number of inner nodes. Two different binary trees t1 and t2 with the same number of inner nodes are listed lexicographically. This means that t1 is listed before t2 

13

1 = (0,0) 2 = (0,1) 3 = (1,0) 4 = (0,2) 5 = (0,3) 6 = (1,1) 7 = (2,0) 8 = (3,0)  BARB Oe  Fig. 1.2. Enumeration of binary trees  14 

if its left subtree is listed before that of t2, or if the left subtrees are identical, the right subtree of t1 is listed before that of t2. An initial segment of the enumeration is given in Fig. 1.2. 

The enumeration of binary trees uniquely fixes the pairing function (x, y). Namely, for two numbers x and y we take the x-th and y-th binary trees t1 and t2 (counting from zero). The position of the binary tree 〈t1, t2〉 is the value of (x, y). Fig. 1.3 lists the initial segment of values of (x, y) in a tabular form. The subscripts give the pair size \|(x, y)\|p. The function will be formally introduced into PA in Sect. 8.3 where we also prove the properties 1.3.7(1) through 1.3.7(3) as theorems of PA. 

It can be shown that as a consequence of keeping the numbers with the same pair size together we will have \|x\|p = Θ(log(x)), i.e. \|x\|p = O(log(x)) and log(x) = O(\|x\|p). This property assures a natural characterization by pairing of computational complexity classes such as polynomial time or space (see \[24\]). 

(x, y) 0 1 2 3 4 5 6 · · · 0 11 22 43 53 94 104 114 · · · 1 32 63 144 154 375 385 395 · · · 2 73 164 425 435 1216 1226 1236 · · · 3 83 174 445 455 1266 1276 1286 · · · 4 184 465 1316 1326 3997 4007 4017 · · · 5 194 475 1336 1346 4047 4057 4067 · · · 6 204 485 1356 1366 4097 4107 4117 · · · ... 

... ... 

... ... 

... ... 

... 

Fig. 1.3. Pairing function (x, y) 

1\.3.12 Projection functions. The pairing property 1.3.7(3) asserts that every non-zero number x has a form (v, w) for some numbers v and w which are uniquely determined by 1.3.7(1). The numbers are accessed by unary pro- jection functions. The first projection function H (head) satisfies the following identities: 

H(0) = 0 H((v, w)) = v . 

The second projection function T (tail) satisfies the following identities: 

T (0) = 0 T ((v, w)) = w . 

It should be clear that we have 

x = (H(x), T (x)) ↔ x \> 0 . 

15

1\.3.13 Contraction to unary functions. We now establish a natural cor- respondence between n-ary and unary functions and predicates over N.  If f is an n-ary function then we denote by (f) its contraction, which is an unary function defined as follows:  (f) (x) = {feet ife= U1,%2,.--,En—-1,Tn  0 otherwise. From the above we get  f(@1,%2,.--,%n) = (f)((@1, 2,---,Un—1,2n)) .  We note that the contraction (f) of an unary function f is the function f itself. For n \> 1 we clearly have  Ary dt, e = (21,-++ ,%\&) oe = AT (x), HT (x) ++» HT" ?(x),T" (2) oT" (a) \> 0 (1)  and thus we have  f(H T(x), HT'\\(a) -- HT"-2(2),T"-"(a)) if T"-2(x) \> 0 0 otherwise.  (f)(2) = (2)  If R is an n-ary relation then we denote by (R) its contraction, which is an unary predicate, satisfying:  (R) (x) @ Aavysrg... day (x = (41, %2,---,Un—1,2n) A R(a1,%2,.-.,2n)) - From this we get R(x, %2,...,%n)  (R)((@1,%2,.--,2n-1,Ln)) -  Thus in the presence of pairing there is no essential difference between n-ary and unary functions, except that the expression f(a) is meaningless for an n-ary function whenever n \> 1 but well-defined for its contraction (f)(x).  1.3.14 Conventions for the symbol comma. We will usually omit the outermost pairing parentheses around pairing (71,72). Thus, for instance, we can write f(x) = g(x), h(x) instead of f(x) = (g(x), h(a)). We postulate that the pairing operator ‘,’ groups to the right, i.e. that (71, 72,73) abbreviates (71, (72, 73)). We assign the lowest precedence to pairing. Thus x + y- v, z is an abbreviation for ((a + (y- v)), z).  The omission of parentheses around pairing can lead to ambiguities in sit- uations where commas could be confused with the separators of arguments of n-ary functions. In such situations when we write f(71,:-+ ,Tn,\*\*\* ;Ta+m)  16 

we (obviously) treat the commas as separators of arguments if m = 0 and we understand the expression as an abbreviation for f(71,--+ ,(Tn,°+\* » Tn+m)) if m \> 1. Thus the first n—1 commas separate the arguments while the remain- ing ones are the infix pairing operators. We adopt similar comma conventions for n-ary predicates.  For instance, if f is binary then f((71, 72), (73, 74, 75)) can be abbreviated by the dropping of the outermost pairing parentheses to f((71, 72), 73,74, 75)- The reader will note that we cannot drop the parentheses around 71, 72. If R is an unary predicate then R((71,72)) can be written as R(71, 72).  We extend the dual role of commas to sequences like # and 7. For instance, when f is an n-ary function then the basic property of its contraction (f) is:  The commas on the left of the identity stand for the pairing operator while they are separators on the right. We can abbreviate this to (f)(Z) = f(Z) with the same understanding about the commas in the sequence 2.  1.3.15 Arithmetization of finite sequences over N. There is a simple way of arithmetizing finite sequences over natural numbers. We assign the code 0 to the empty sequence 9. The non-empty sequence x1 %2 ... Lp is coded by the number (21, %2,...,%n,0) (see Fig. 1.4). The reader will note that the assignment of codes is one to one, every finite sequence of natural numbers is coded by exactly one natural number, and vice versa, every natural number is the code of exactly one finite sequence of natural numbers. Codes of finite sequences are called lists in computer science and this is how we will be calling them from now on.  rn 0  x, 0 z,y,0 x,y, 2,0 @1,02,...,Xn,0  Fig. 1.4. Lists  1.3.16 Length of lists. The list 71, 22,...,2,,0 codes a finite sequence of natural numbers of length n and we say that the list has the length n. The length function L(z) has the following clausal definition:  17 

L(0) = 0 L(x, y) = L(y) + 1 . 

1\.3.17 Concatenation of lists. The binary list concatenation function x⊕ y has the following clausal definition: 

0⊕ y = y (1) (v, w)⊕ y = v, w ⊕ y . (2) 

As an example we show here the computation of (1, 2, 3, 0)⊕ (4, 5, 0). The computation uses the clauses as rewriting rules and there is no need during the computation to convert into decimal (or binary notation): 

(1, 2, 3, 0)⊕ (4, 5, 0) (2) = 1, (2, 3, 0)⊕ (4, 5, 0) 

(2) = 1, 2, (3, 0)⊕ (4, 5, 0) 

(2) = 

1, 2, 3, 0⊕ (4, 5, 0) (1) = 1, 2, 3, 4, 5, 0 . 

1\.3.18 List indexing. The binary list indexing function (x)i yields the i-th element (counting from 0) of the list x. For instance, (0, 1, 2, 3, 0)2 = 2. The indexing function is defined by the following clausal definition: 

(0)x = 0 (v, w)0 = v (v, w)i+1 = (w)i . 

Arithmetization of Trees. 

1\.3.19 Arithmetization of labeled binary trees. The type Bt of binary trees labeled by natural numbers can be defined in most functional program- ming languages by a union type: 

Bt = E \| Nd(N,Bt ,Bt) , 

This asserts that a value of type Bt is either the leaf E or a node of the form Nd(x, t1, t2) where t1 and t2 are values of type Bt and x ∈ N is the label of the node. The constant E and the function Nd are called constructors. 

We arithmetize the values of the type Bt with the help of two constructor functions E = 0, 0 and Nd(x, t1, t2) = 1, x, t1, t2. Note that this guarantees that we have E 6= Nd(x, t1, t2). The predicate Bt(t) holding of codes of labeled binary trees t has a clausal definition corresponding to the union type definition: 

Bt(E) Bt Nd(x, t1, t2) ← Bt(t1) ∧ Bt(t2) . 

We identify labeled binary trees with their codes and from now on we will say the binary tree t instead of the code of the binary tree t. 

18

1\.3.20 Flattening of binary trees. As an example of an operation over binary trees we consider the function Flat(t) taking a binary tree t and yield- ing the list of all labels in t read off t from left to right. The function has the following clausal definition: 

Flat(E) = 0 Flat Nd(x, t1, t2) = Flat(t1)⊕ (x,Flat(t2)) . 

We can save the repeated concatenation by keeping the flattened list in an accumulator with an auxiliary binary function f(t, a): 

f(E, a) = a f(Nd(x, t1, t2), a) = f(t1, x, f(t2, a)) . 

We can now explicitly define a fast flatten by: 

Flat(t) = f(t, 0) . 

The correctness of this definition on labelled trees follows from the following property: 

Bt(t) → ∀a f(t, a) = Flat(t)⊕ a 

proved by complete induction on t. 

1\.3.21 Binary search trees. A binary tree t is a binary search tree if for every subtree of t labeled by n all labels in its left son are less than n and all labels in the right son are greater than n. This is equivalent to the requirement that the labels of a binary search tree read off from left to right increase. Hence, the predicate Bst holding of binary search trees has the following explicit definition: 

Incr(t) ↔ ∀i∀j(i \< j \< L(t) → (a)i \< (a)j) Bst(t) ↔ Incr Flat(t) . 

1\.3.22 Membership in binary search trees. The binary predicate x ∈b t of membership in binary search tree, has the following property: 

Bst(t) → (x ∈b t ↔ ∃i(i \< L(Flat(t)) ∧ (Flat(t))i = x)) . 

The predicate has the following clausal definition: 

x ∈b Nd(y, t1, t2) ← x \< y ∧ x ∈b t1 x ∈b Nd(y, t1, t2) ← x = y x ∈b Nd(y, t1, t2) ← x \> y ∧ x ∈b t2 . 

Arithmetization of Symbolic Expressions 

1\.3.23 Numeric terms. Suppose that we wish to operate symbolically on numeric terms, which we call here expressions, and which are formed from 

19

constants n and variables xi by the arithmetic operators + and ·. Functional programming languages use the following union type to specify the domain of expressions: 

Expr = Cns(N) \| Var(N) \| Add(Expr ,Expr) \| Mul(Expr ,Expr) . 

We arithmetize the expressions with the help of four constructors with explicit clausal definitions: 

Cns(x) = 0, x Var(x) = 1, x Add(x, y) = 2, x, y Mul(x, y) = 3, x, y . 

We can now code, for instance, the expression 356·x3 + x5 by the number 

Add(Mul(Cns(356),Var(3)),Var(5)) = 2, (3, (0, 356), 1, 3), 1, 5 = 3 442 660 716 284 . 

That the code is larger than three trillion should not be too surprising as its pair size is 25 and the ratio between the length of decimal numbers and pair size is roughly 1 to 2 (the ratio between the length of dyadic and pair size is roughly 1 to 1. 

The predicate Expr(a) true of codes a of expressions corresponds to the above union type and has the following clausal definition: 

Expr Cns(c) Expr Var(i) Expr Add(a, b) ← Expr(a) ∧ Expr(b) Expr Mul(a, b) ← Expr(a) ∧ Expr(b) . 

1\.3.24 Denotation function for expressions. We now define the binary denotation (valuation) function Val(c, v) taking the code c of an expression τ and an assignment v which is a list assigning the value (a)i to the variable xi. The application Val(c, v) yields the value of the expression τ when the variables occurring in the expression take their values from the assignment v. The denotation function has the following clausal definition: 

Val(Cns(c), v) = c Val(Var(i), v) = (v)i 

Val(Add(a, b), v) = Val(a, v) + Val(b, v) Val(Mul(a, b), v) = Val(a, v)·Val(b, v) . 

This is a typical example where we wish to use the default clauses in order not to clutter the definition. We do not care what value is yielded by the application Val(c, n) if c does not code an expression. The reader will note that in such case the value is not necessarily 0 because c can be ‘almost’ an expression. For instance Val(Add(0,Cns(1)), 0) = 1. 

20

Arithmetization of Numeric Domains 

1\.3.25 Arithmetization of the domain of integers Z. Integers, which extend the natural numbers with the negative whole numbers, are used in computer programming perhaps more often than the natural numbers. In- stead of extending the domain of natural numbers N to the domain Z of integers we arithmetize the latter domain in N. For that we need two con- structor functions +(x) = 0, x and −(x) = 1, x which respectively code the positive (including 0) and negative (excluding 0) numbers. The predicate Z(k) which holds if k codes an integer has the following explicit definition: 

Z(+(n)) Z(−(n + 1)) . 

The subtraction function x − y which is closed over the domain Z, i.e. such that 

Z(x) ∧ Z(y) → Z(x− y) 

holds, has the following explicit clausal definition: 

+(n)−+(m) = +(n .−m) ← n ≥ m +(n)−+(m) = −(m .−n) ← n \< m +(n)−−(m + 1) = +(n + m + 1) −(n + 1)−+(m) = −(n + m + 1) −(n + 1)−−(m + 1) = −(n .−m) ← n ≥ m −(n + 1)−−(m + 1) = +(m .−n) ← n \< m . 

We can define other arithmetic functions over Z in a similar style. 

1\.4 Extensional Issues of Definability in PA 

The reader accepting our arguments in the preceding sections agrees that our programs are to be definitions of computable functions and predicates over the domain N of natural numbers. Definitions are concrete objects given in a formal system of arithmetic and the defined function and predicate symbols posses denotations in the domain N. Formal systems are necessary because neither humans nor computers can work directly with the abstract domain of natural numbers. The most natural candidate for the formal system is the Peano arithmetic. 

In this section we discuss the definitions of functions and predicates in PA from the extensional point of view where we are not interested whether they are computable. Non-computable functions and predicates play important role in the theory of programming because they are used with advantage for the specification and proofs of properties of computable functions. 

21

Recursive Bootstrapping of Peano Arithmetic 

1\.4.1 Peano arithmetic. Peano arithmetic is formulated as a first-order logical theory in the language consisting of the constant 0, the unary function symbol x′, and of two binary function symbols x + y and x·y. The intended interpretation of PA is in the standard model N with the domain of natural numbers N and with the interpretation of its symbols in the above order as the number 0, the successor function S(x) = x + 1, the addition, and the multiplication functions. 

The axioms of Peano arithmetic are 

0 6= x′ 

x′ = y′ → x = y 

0 + y = y 

x′ + y = (x + y)′ 

0·y = y 

x′·y = x·y + y 

plus the infinite number of induction axioms of the form 

φ\[0\] ∧ ∀x(φ\[x\] → φ\[x′\]) → φ\[x\] (1) 

for every formula φ\[x\] of the language. It is easy to see that all axioms are satisfied in the standard model N . 

We denote by nm the monadic numeral (see Par. 1.1.4) for n. Precisely, nm is defined as a metatheoretical function yielding terms of PA to satisfy: 

0m ≡ 0 n + 1m ≡ (nm)′ . 

1\.4.2 Classification of formulas of PA. UNFINISHED definability of functions and predicates 

1\.4.3 Fragments of Peano Arithmetic. UNFINISHED Σi-definable in T . Provably recursive in T . Primrec. 

1\.4.4 Extensions of Peano arithmetic. Computer programming consists of defining new functions and predicates. Formal tools for this activity in logic are extensions of theories, in our case extensions of PA. This happens by the addition of a new function or predicate symbol to the language of the current extension of PA together with new axiom(s) defining the symbol. 

We do not wish the extended theory to be inconsistent in the sense that it can prove theorems not satisfiable in the standard model, for instance 0 = 1. Once 0 = 1 is a theorem, the theory can prove any formula. The unextended theory PA cannot prove any formulas not satisfied inN and so it is consistent. 

22

In order to maintain the consistency we restrict our extensions to conser- vative ones. Conservative extensions do not prove any new theorems in the language before the extension, i.e. formulas which do not contain the new symbol. Since 0 = 1 is such a formula the extended theory is consistent. We actually go even further and restrict our extensions to extensions by defini- tions which are a special case of conservative extensions where the extended theory cannot prove any properties not expressible already in the original language of PA. New function and predicate symbols are thus only a nota- tional convenience which make our theorems and definitions more readable. We gain on expressivity but not on power. 

When we say PA in the following we always mean the current extension of Peano arithmetic. 

1\.4.5 Extensions of PA by explicitly defined predicates. We can ex- tend PA with the binary comparison predicate x \< y by adding it to the language of the theory and then add a new axiom fully describing the predi- cate: 

x \< y ↔ ∃z x + z′ = y . 

We can then use the axiom in proving properties of the new symbol, for instance the transitivity: 

x \< y ∧ y \< z → x \< z . 

The extension does not add any strength to PA because we can always elim- inate all occurrences of \< from a formula by replacing applications τ1 \< τ2 

by formulas ∃z τ1 + z′ = τ2. In general, for any formula φ\[x1, . . . , xn\] of the current extension T of PA 

we can form its extension S by explicit definition of a predicate by adding a new n-ary predicate symbol R together with its defining axiom: 

R(x1, . . . , xn) ↔ φ\[x1, . . . , xn\] . (1) 

The new symbol can be always eliminated from a formula ψ of S by a translation similar to the one describes above whereby we obtain a formula ψ? of T . The extended theory S proves that the two formulas are equivalent: ψ ↔ ψ?. The conservativity of S over T follows from the fact that S proves ψ iff T proves ψ?. 

We can even use the new predicate symbol R in induction formulas ψ of the form 1.4.1(1) where φ is arbitrary formula of the language of S. This is because the translation ψ? is an induction formula provable in the theory T . S, by being an extension of T , proves ψ? and, since it also proves ψ ↔ ψ∗, the theory S proves the induction formula ψ. 

The reader will note that we have already used a definition by explicit definition of a predicate in Par. 1.2.1 where we have defined 

x \| y ↔ ∃z x·z = y . 

23

1\.4.6 Extensions of PA by contextually defined functions. We can extend PA by explicit definitions of functions similarly to extensions by ex- plicit definitions of predicates. For instance, we can introduce the square function x2 by explicit definition: x2 = x·x. In general case we can take a term τ \[x1, . . . , xn\] and introduce a new n-ary function symbol f by explicit definition with the defining axiom: 

f(x1, . . . , xn) = τ \[x1, . . . , xn\] . (1) 

While certainly useful, this kind of extensions does not fully utilize the power of logical notation to the same extent as extensions by explicit definitions of predicates. Formulas φ in extensions 1.4.5(1) can contain arbitrary proposi- tional connectives and quantifiers. The simpler syntax of terms τ in extensions (1) has not the same power of expression. 

We can use formulas in explicit definitions of function symbols where we define a new function symbol in the context of a formula where instead of the function f we introduce its graph f(x1, . . . , xn) = y as an (n+1)-ary relation. For instance, the modified subtraction function x .− y can be introduced by an explicit contextual definition as: 

x .− y = z ↔ x ≥ y ∧ x + z = y ∨ x \< y ∧ z = 0 . 

The trick is that no matter what the numbers x and y are, exactly one of x ≥ y and x \< y. Moreover, in the former case there is a unique z s.t. x + z = y. 

In general, for any formula φ\[x1, . . . , xn, y\] of the current extension T of PA for which T proves the existence and uniqueness conditions: 

∃yφ\[x1, . . . , xn, y\] (2) φ\[x1, . . . , xn, y1\] ∧ φ\[x1, . . . , xn, y2\] → y1 = y2 (3) 

we can form the extension S by contextual definition of a function by adding a new n-ary function symbol f together with its defining axiom: 

f(x1, . . . , xn) = y ↔ φ\[x1, . . . , xn, y\] . (4) 

The new symbol can be always eliminated from a formula ψ of S by a translation ψ?. The main idea is that for every formula ψ\[y\] s.t. ψ\[f(τ1, . . . , τn)\] is a formula of S the theory S proves 

ψ\[f(τ1, . . . , τn)\] ↔ ∃y(f(τ1, . . . , τn) = y ∧ ψ\[y\]) 

Since (4) is axiom of S, the theory then proves: 

ψ\[f(τ1, . . . , τn)\] ↔ ∃y(φ\[τ1, . . . , τn, y\] ∧ ψ\[y\]) 

where the formula on the right has at least one application of f less then the formula on the right. Continuing in this way, we can eliminate all applications 

24

of f from the formula ψ whereby we obtain a translation ψ?, which is formula of T such that T proves ψ ↔ ψ∗. That S is conservative over T follows from the highly non-trivially demonstrated fact that S proves φ iff T proves φ?. 

We can use the new function symbol f in induction formulas because they are theorems of S for the same reason as was the case with the explicit definition of predicates. 

1\.4.7 Introduction of integer division into PA. As an example of ex- tension by contextually defined functions we show how to introduce the in- teger division function x÷ y into PA by contextual definition: 

x÷ y = q ↔ y \> 0 ∧ ∃r(x = q·y + r ∧ r \< y) ∨ y = 0 ∧ q = 0 . 

This can be done because PA proves the existence condition: 

∃q(y \> 0 ∧ ∃r(x = q·y + r ∧ r \< y) ∨ y = 0 ∧ q = 0) 

as directly following from y \> 0 → ∃q∃r(x = q·y+r∧r \< y). The uniqueness condition follows easily from the uniqueness of quotients and remainders: 

q1·y + r1 = q2·y + r2 ∧ r1 \< y ∧ r2 \< y → q1 = q2 ∧ r1 = r2 . 

1\.4.8 The case analysis function D. Another example of extension by contextually defined functions is the introduction into PA of the ternary case discrimination function D satisfying: 

D(0, y, z) = z 

D(x + 1, y, z) = y . 

Computer scientists can visualize the function as 

if x \> 0 then y else z . 

The case discrimination function is introduced into PA by the folowing con- textual definition: 

D(x, y, z) = v ↔ x \> 0 ∧ v = y ∨ x = 0 ∧ v = z 

whose existence and uniqueness conditions obviously hold. 

1\.4.9 Characteristic functions of predicates. The characteristic func- tion of an n-ary predicate P is the n-ary function f such that: 

f(\~x) = 

{ 1 if P (\~x) 0 otherwise. 

We obviously have 

f(\~x) \> 1 ↔ P (\~x) . 

We usually designate the characteristic function of a predicate P by P∗. 

25

1\.4.10 Characteristic functions of = and \<. The binary characteristic functions =∗ and \<∗ of the identity and less than predicates can be introduced into PA by contextual definitions: 

(x=∗y) = z ↔ x = y ∧ z = 1 ∨ x 6= y ∧ z = 0 (x\<∗y) = z ↔ x \< y ∧ z = 1 ∨ x ≥ y ∧ z = 0 

whose existence and uniqueness conditions hold trivially. 

1\.4.11 Extensions of PA by definitions. Let T be an extension of PA and S1 an extension of T either by explicit definition of a predicate P or by contextual definition of a function f . 

We say that a theory S whose language is the same as S1 is an extension by definition of T if S and S1 are elementarily equivalent i.e. if both theories prove exactly the same theorems. 

The theory S is conservative over T , permits to translate away the in- troduced symbols, and proves all induction formulas containing the newly introduced symbol. An extension by definitions is a finite sequence of exten- sions with every sequence an extension by definition. 

We will sketch out below how to formulate a few increasingly more pow- erful forms of extensions of PA in a sense of expressive power and comfort but which will still be extensions by definitions. Comfortable and easy to use forms of extensions of PA are needed in order to obtain the kind of program- ming style computer programmers are used to. The schema of extensions by clausal definitions is such a powerful and easy to use schema. Clausal defini- tions have yet another important property because they are flexible enough to control the computation of defined functions and predicates. We will discuss this in Sect. 1.6. 

UNFINISHED If a function or a predicate is provably recursive in IΣ1 

then we will usually not mention this explicitly and just say that it is intro- duced into PA. For any other extension we mention either the definability of the formula and/or the strength of the theory. 

∆1 deinable in IΣ1 and is provably recursive there UNFINISHED power of extensions by definitions, give characterization. 

1\.4.12 Extensions of PA by explicitly defined functions. UNFIN- ISHED remainder mod 

1\.4.13 Extensions of PA by minimalization. 

P̀Ax f(\~x) = µy\[φ\[\~x, y\]\]. 

φ\[\~x, f(\~x)\] ∧ ∀y(y \< x → ¬φ\[\~x, y\]). 

\[ √ 

x\] = µy\[x \< (y + 1)2\] (1) 

26

1\.4.14 Partial Functions. UNFINISHED They are A9-definable but can be computed on their domains.  1.4.15 Extensions of PA by primitive recursion.  1.4.16 Extensions of PA by course of values recursion with mea- sure. Let T be the current extension of PA. We wish to extend T to a theory S by the addition of a new n-ary function symbol f such that S proves iden- tity  f(@) = rf; 8\] - (1)  We have indicated in the term 7 that it can have occurrences of at most the variables Z and that it can apply the function symbol f. The term 7 is thus in the language of S. We will see in UNFINISHED that such an extension is always possible when the term 7 is regular meaning that there is a measure function m(z) in which all recursive applications f(p) in 7 goes down, i.e. m(p) \< m(#) holds.  The best we can do for terms 7 which are either not regular or we do not now yet whether they are such is to satisfy the recursive identity with guards:  f(@) = T\[Ag.D((m(¥)\<.m(Z)), f(G), 0); Z . (2)  The lambda notation simply means that every recursive application f(f) in T is surrounded by a guard:  D((m(p)\<«m(#)), f(P), 9)  which guarantees that we go to recursion only if m(f) \< m(Z).  We will introduce the function f into PA by minimalization with the help of a predicate arithmetizing the computation of f into a computation tree. For the sake of simplicity we assume that f is unary and that the term 7 is built up from the variable x and from the numerals n,,, by pairing (71, tau2) and by applications of unary functions g1, ..., gy. The reader will note that this is actually no restriction because the functions g; can be contractions and instead of defining an n-ary function f we define its contraction (f).  Computation trees are binary and they have triples (p,a,v) as labels in their non-leaf nodes. The node with such a label records the computation of a subterm p of 7 with the value a assigned to the variable x and with v recording the value (denotation) of p in this assignment. The sons of the node record the necessary subcomputations.  The form of the term p determines the shape of the sons t; and te as follows. If p = p1, p2 then the computation tree looks as follows:  ((p1, p2); a, (v1, v2))  (P14, U1) (p2, @, V2) ty to  27 

where the value v, of p, is computed in the left son and the value v2 of p2 is computed in the right son. The value of (1, p2) is then the pair (v1, v2). If p =z or p=n,, then the respective computation trees are:  (x, a, a) (Py G2)  where there are no subcomputations because the values of x and n,,, can be determined directly as a and n respectively. If op = g:(1) then the computation tree is  (9i(p1), @, gi(v))  (p1; 4, v) t  where we record in the left son the computation of the argument p; into the value v and then the value of g;(p:) is then g;(v). There is not need to record any computation in the right son.  Finally, if p = f(p1) then there are two possible computation trees:  (p1, a, v) (T, v, w) (p1; a, v) th to ty  In both cases the value v of the argument p; is computed in the left son. The two cases are determined by the outcome of the test m(v) \< m(a). If the measure decreases then the computation tree is shown above on the left. This is when the identity f(x) = r\[f;a\] is used as the computation rule in the form f(wv,,) - T\[f;v,,\]. The value w of the term tau is computed in the right son and the value of the recursive application f(v,,) is determined as w. If the outcome of the test is negative then the computation tree is shown above on the right where the value of f(v,,) is 0. The reader will note that the computation of f() thus evaluates the guard.  It should be obvious that we can construct a computation tree for any subterm p of 7 and any assignment a of the value of the variable x because the terms in the labels of the tree are always smaller except in the right sons of recursive applications but then the measure decreases and the initial measure m(a) can decrease only finitely many times.  We arithmetize this computation with the help of an explicitly defined predicate Ct(t) holding iff t codes a computation tree for a subterm p of T. PA proves that we have  Avat; Ste Ct Nd((Tr), x,v), ty, te)  and that the value v and the subtrees t; and tg are unique. We can thus define f by minimalization:  28 

f(x) = H µt\[Ct Nd((pτq, x, H(t)),H T (t), T T (t))\] . 

UNFINISHED 

1\.4.17 Definition of predicates through their characteristic func- tions. UNFINISHED Example 

Extensions of PA by Clausal Definitions 

1\.4.18 Introduction to clausal definitions with an example. Clausal definitions are probably best explained with a concrete example. Suppose that we wish to extend PA with a unary function \[ 

√ z\] satisfying the following 

specification: \[ √ 

z\]2 ≤ z \< (\[ √ 

z\] + 1)2 

which means that the function should compute the whole part of the square root. We have seen in 1.4.13(1) a definition by minimalization. This was a ‘naive’ program running in time O(z) by a brute force search which was exponentially slower than it should have been. 

The following clausal definition introduces the same function in a compu- tationally optimal form running in time O(log(z)): 

\[ √ 

0\] = 0 \[ √ 

z\] = 1 ← z \< 4 ∧ z \> 0 \[ √ 

4·x + i\] = s0 ← 4·x + i ≥ 4 ∧ i \< 4 ∧ \[ √ 

x\] = s ∧ 4·x + i \< (s1)2 

\[ √ 

4·x + i\] = s1 ← 4·x + i ≥ 4 ∧ i \< 4 ∧ \[ √ 

x\] = s ∧ 4·x + i ≥ (s1)2 . 

The clauses are just formulas in the language of PA even though their impli- cations are customarily written in the converse form. The clauses should be completely self-explanatory and the reader should have no difficulties what- soever to understand the properties of the defined function. 

\[ √ 

z\] = y ↔ case z \< 4 → case 

z = 0 → 0 = y z \> 0 → 1 = y 

z ≥ 4 → let z = 4·x + i ∧ i \< 4 →x,i 

let \[ √ 

x\] = s →s case 4·x + i \< (s1)2 → s0 = y 4·x + i ≥ (s1)2 → s1 = y 

Fig. 1.5. The definition of \[ √ 

z\] with case formulas. 

29

1\.4.19 Generalized case formulas. The only problem with the clausal definition of the function \[ 

√ z\] in Par. 1.4.18 is to recognize that the clauses 

constitute a definition at all. We will show that this is indeed the case, and that it is an extension of PA by definition. Toward that end we write the claus- es in a form with case formulas given in Fig. 1.5 which resembles contextual definitions (albeit recursive). The reader should think of the case formulas as conjucts of their alternatives some of which have universally quantified lo- cal variables. For instance, he should visualize the following three alternative case formula: 

case φ1 → ψ1 

φ2\[x, y\] →x,y ψ2\[x, y\] φ3\[x\] →x ψ3\[x\] 

as standing for the formula 

(φ1 → ψ1) ∧ ∀x∀y(φ2\[x, y\] → ψ2\[x, y\]) ∧ ∀x(φ3\[x\] → ψ3\[x\]) . 

The assumptions in the alternatives of a case formula should be complete, pairwise exclusive, and the local variables should be uniquely determined. In the above three alternative case this means that we have: 

φ1 ∨ ∃x!∃y! φ2\[x, y\] ∨ ∃x! φ3\[x\] φ2\[x, y\] ∨ φ3\[x\] → ¬φ1 

φ2\[x, y\] → ¬∃xφ3\[x\] . 

Under those conditions the above case formula is equivalent to the following disjunctive formula: 

φ1 ∧ ψ1 ∨ ∃x∃y(φ2\[x, y\] ∧ ψ2\[x, y\]) ∨ ∃x(φ3\[x\] ∧ ψ3\[x\]) . 

1\.4.20 Let formulas. Some of the case formulas have only one alterna- tive and their sole purpose is to introduce local variables; the reader should vizualize them as a generalization of let constructs as known from functional programming languages. For that reason we write let instead of case as, in for instance: 

let z = 4·x + i ∧ i \< 4 →x,i φ\[x, i\] 

which splits the argument z by pattern matching into the unique values x and i satisfying the shown relation. The local variables x and i can be then referred to in the body φ\[x, i\] of the alternative. 

1\.4.21 Unfolding of the contextual definition of \[ √ 

z\]. The contextual definition from Fig. 1.5 is transformed to the four clauses for \[ 

√ z\] by unfold- 

ing. Unfolding, in this case, means the splitting of the alternatives presentend in the disjunctive form where we rely on the fact that φ ← ψ1 ∨ ψ2 and 

30

(φ ← ψ1) ∧ (φ ← ψ2) 

are propositionally equivalent and that φ ← ∃\~xψ and ∀\~x(φ ← ψ) are logically equivalent provided the variables \~x do not occur in φ. We then split the con- jucted clauses, drop the outermost universal quantifiers, and use properties of identity. For instance, the first and the third clauses for \[ 

√ z\] are in the 

following form just before the properties of identity are applied to them: 

\[ √ 

z\] = y ← z \< 4 ∧ z = 0 ∧ 0 = y \[ √ 

z\] = y ← z ≥ 4 ∧ z = 4·x + i ∧ i \< 4 ∧ \[ √ 

x\] = s ∧ 4·x + i \< (s1)2 ∧ s0 = y . 

1\.4.22 Definition of \[ √ 

z\] by generalized course of values definition with measure. We will now transform the contextual recursive formula for \[ √ 

z\] in Fig. 1.5 into a generalized course of values definition with measure. The definition is given in Fig. 1.6 and contains case terms instead of case formulas. Both definitions are satisfied by the same function and so they are equivalent. Case terms are significantly less readable than the case formulas and require explanation given in Paragraphs 1.4.23 through 1.4.26. We will define the functions applied in the case terms in Fig. 1.6 in Par. 1.4.33. 

\[ √ 

z\] = case sgn(z\<∗4) = 0 → case 

sgn(z=∗0) = 0 → 0 sgn(z=∗0) = 1 → 1 

sgn(z\<∗4) = 1 → let 0, qr(z) = 0, x, i →x,i 

let 0, \[ √ 

x\] = 0, s →s case sgn(4·x + i\<∗(s1)2) = 0 → s0 sgn(4·x + i\<∗(s1)2) = 1 → s1 

Fig. 1.6. The definition of \[ √ 

z\] with case terms. 

case τ = 0 → α0 

... τ = m− 1 

m → αm−1 

τ = mm, x1, . . . , xnm →x1,...,xnm αm\[x1, . . . , xnm \] 

... τ = k − 1 

m , x1, . . . , xnk−1 →x1,...,xnk−1 

αk−1\[x1, . . . , xnk−1 \] 

Fig. 1.7. The general form of a case term. 

31

1\.4.23 Case terms. The general form of case terms is given in Fig. 1.7 where 0 \<m\<k and all nm, ...nmg\_1 are positive numbers. Form \<7 \<k we abbreviate the local variables 71,...%, to x;. The local variables £; may occur in the terms a \[Z;\] but not in the term 7. Although all local variables in £; must be pairwise different, the sets 7;, and Z;, may share variables whenever j1 # jo. The terms 7 and a; may contain additional non-local variables.  Before the case term from Fig. 1.7 is admitted as legal it must satisfy the following completeness condition  TONNES Sn SETS tin Bn Yoo YSERA TS BL th 1  We will need more general case terms guarded by a condition which is a formula of PA. The case term from Fig. 1.7 is legal under a guard ¢ if PA proves the completeness condition (1) under the assumption ¢. Note that an absolute case term, i.e. a case term without guard, is guarded by any condition.  When the guard of a case term is satisfied then the discriminator term T denotes a (disjoint) union value determined by m, k, nm, ..., Nk-1. The tag of the union value 7 is the denotation of 7 if 7 \< m,,, and the denotation of H(r) ifr \>m,,.  The reader will note that the alternatives in (1) are pairwise disjoint and, for instance, for 7; \<\_m and m \< jg \< k we have  T= jr, bin TF I,  because j1 \< jo \< jo, %j, holds.  The tag j of r determines the meaning (denotation) of the case term as the meaning of the term a; if 7 \<\_m and the meaning of a,\[@;\] whenm \<j \<k with the assignments to the local variables #; uniquely determined from the union value T = Din? x;. We abbreviate the case term from Fig. 1.7 to  COSC mk (T, QO, ++ -;AHm\|\[Xm\],---) - (2) The generalized term (2) is well-formed under a guard ¢ if ¢ is a guard for the case term, for every 7 \< m the generalized term aj; is well-formed under the guard 6A T = Din? and for every m \< j \< k the generalized term a;\|\[i;\| is well-formed under the guard ¢ AT = Jin? Yj.  1.4.24 Let terms. Let terms are the case terms with m = 0 and k = 1, ice. one alternative case terms with local variables. For instance  let 0, \|. /z\] = 0,5 -, als\] . Note that the tag 0 is superfluous and it is included in order to maintain the  uniform form of case terms. Also note that the sole purpose of let terms is to introduce local variables.  32 

φ → α = y ↔ case φ0 → α0 = y 

... φm−1 → αm−1 = y φm, x1, . . . , xnm →x1,...,xnm 

αm\[x1, . . . , xnm \] = y ... 

φk−1, x1, . . . , xnk−1 →x1,...,xnk−1 αk−1\[x1, . . . , xnk−1 \] = y 

Fig. 1.8. The correspondence between the case terms and formulas. 

1\.4.25 Annotation of case terms. The connection of case terms to case formulas is established by the annotation of a case term with assumption formulas. The assumption formulas for the case term in Fig. 1.7 guarded by φ are φ0, . . . , φm−1, φm\[\~ym\], . . . , φk−1\[\~yk−1\] with the condition that we have 

φ → τ = j m ↔ φj (1) 

whenever j \< m and 

φ → τ = j m 

, \~yj ↔ φj \[\~yj \] (2) 

whenever m ≤ j \< k. The reader will note that this guarantees the com- pleteness and pairwise exclusivity of the assumption formulas as well as the uniqueness of local variables. This annotated case term is abbreviated to 

casem,k(τ, (φ0 → α0), . . . , (φ →\~ym αm), . . .) . (3) 

We can think of all case terms as being annotated because the unannotated term in Fig. 1.7 can be brought into the annotated form (3) by taking as its assumption formulas the corresponding identities on the left-hand-sides of (1) and (2). If we abbreviate the term (3) by α then the connection to the corresponding case formula is given in Fig. 1.8. 

D((τ=∗0m), α? 0, 

. . . D((τ=∗m− 1 

m ), α? 

m−1, D(H(τ=∗mm), α? 

m\[H T 1(τ), . . . , H T nm−1(τ), T nm(τ)\], . . . D(H(τ=∗k − 2 

m ),α? 

k−2\[H T 1(τ), . . . , H T nk−2−1(τ), T nk−2(τ)\], α? 

k−1\[H T 1(τ), . . . , H T nk−1−1(τ), T nk−1(τ)\]) . . .)) . . .) 

Fig. 1.9. The term of PA which is the translation of the generalized term in Fig. 1.7. 

33

1\.4.26 The meaning of case terms. We have informally presented the intended meaning of case terms in Par. 1.4.23. Case terms may bind local variables and so they are instances of variable binding operators. Note that lambda terms Ax.7 are another well-known examples of such operators. Be- cause of technical complications of variables bound in the terms we do not introduce the case terms formally into PA and treat them as concretely pre- sented syntactic objects on the level of meta-theory. We use a, 3, as syntactic variables to range over generalized terms which are built up from the object terms of the language of PA by the case term constructs.  To every generalized term a we associate as its translation an object term a\* in such a way that the denotations of a\* in the models of PA are the same as the intended denotations of the generalized terms. The translation is defined by recursion on the structure of generalized terms in such a way that the translation of the generalized term 1.4.23(2) (or 1.4.25(3)) is the object term given in Fig. 1.9.  1.4.27 Generalized course of values definition with measure. We call  f(@) = al\[flz: #4 (1)  a generalized course of values definition with measure p if its translation f(@) = a\*\|\[f\]%; Z\] is a definition of f by course of values with measure ju. The function f is said to be defined by the generalized definition.  We can drop the guards around recursive applications of formulas if we restrict the recursive applications in a to regular applications. The idea is  that for every recursive application f(@) occurring in a we have  1A. AVE = HA \< Hz  where w 1, ..., We are the annotation formulas governing the recursive oc- currence in a. This means that if present the generalized definition (1) in an equivalent contextual form with a case formula ¢:  f(@)=y olf; 4\]  then the governing formulas are read off from the assumptions on case formu- las enclosing the recursive application. For instance, for the single recursive application \[,/z\] in the definition in Fig. 1.5 we have  zZz\>4AAz=H4at+iNi\<4\>24\<2z  and so the measure of the definition is the argument z itself.  The generalized definitions (1) with regular recursive applications are called regular definitions. For regular generalized definitions we not only have the extensional property that  34 

a\*\[\[flzs 2\] = o\* \[fs a\] holds for all # but we also have a stronger intensional property that the recursive applications f(@) can be strictly evaluated whenever their govern- ing formulas hold. Strict evaluation (cf. UNFINISHED ) means that the arguments f are evaluated to f; before the rewrite rule f(f1) » alf; pi\] is applied.  1.4.28 Extensions of PA by clausal definitions. Let us designate the current extension of PA by T’. We now describe a clausal extension of T to S with a new function symbol f. The clausal definition of a function f is obtained by the unfolding of a regular generalized course of values definition with measure:  f(@) = olf; 2\] (1)  with a a well-formed generalized term under the guard T. The translated formula a\* must be in the language of S$ and there must be an extension by definition of the theory T to $; with a contextual definition f(Z) = yd¢\[Z, y\] for some formula ¢ of the language of T. The formula ¢ is obtained from the course of values definition with measure f(£) = a\*\|\[f\]2; a\]  We obtain the clauses for f by transforming the generalized definition (1) into an equivalent contextual form with generalized case formulas  f(@)=ye vf; 4\]  and then by reading off the clauses from it and by using the properties of identity to simplify the clauses. The clauses are then added as new axioms of S together with the single induction formula for ¢\[; f(Z)\]. The theory S' is equivalent to the theory S; and so it proves all induction formulas containing the new function symbol f. Moreover, because S$; is an extension of T by definition, so is S.  For instance, the clausal definition of the function \[,/z\] given in Par. 1.4.18 is obtained from the regular generalized definition in Fig. 1.6 which is trans- formed into a form with generalized case formulas in Fig. 1.5. The clauses for \[\\/z\] are read off this definition and simplified as described in Par. 1.4.21.  UNFINISHED predicates  1.4.29 Defaults in clausal definitions. UNFINISHED DEFAULTS  1.4.30 D-case terms. In this, and the next two paragraphs, we present three kinds of case terms which are basic.  The D-case terms are absolute and come in two forms differing only in annotation:  case2o(sgn(x), (a \> 0 — ag), ( =0 - ay)) (1) casé2,2(3gn(P.(7)), (P(7) \> a0), (\>P(T) \> a1)) - (2)  35 

The unary function sgn has the following explicit definition: sgn =1-2.  The reader will note that we have sgn(a + 1) = 0 and 3gn(0) = 1 and so PA proves  cases,o(sgn(0), ao, @1)\* = casez2(1, ao, a1)\* = at = D(0, 0%, \*1) and cases 2(sgn(x + 1),a9,a1)\* = case2,2(0,a0,01)\* = ag = D(x + 1,09, a7) .  This means that D-case terms are extensionally applications of the case dis- crimination (if-then-else) function D. However, there is a crucial intensional difference in the way the two are computed. Applications of the function D are computed strictly, i.e. arguments before the application D, while the D- case terms, as all case terms, are computed non-strictly (see Par. 1.6.4).  For the first form of D-case terms we have 3gn(x) = 0 — x \> 0 and ggn(x) = 1\< « = 0 and thus the conditions on the assumption formulas are satisfied. The second form of D-case terms is extensionally just an instanti- ation of the first form with P,(7) where P, is the characteristic function of the predicate P. The annotation with assumption formulas is legal because we have sgn P,.(7) =0 — P(r) and 397 P,(7) = 1 4P(7).  1.4.31 Binary case terms. Binary case terms are absolute and have the annotated form  caseg,2(b(T), (7 = 20 \>, ao\[z\]), (7 = 20 \>, a4 \[2\])) (1) where the unary function b is introduced into PA by a contextual definition:  b(2) =y — Az(a@ = zOAy=0,2z)V dz(a@ = zl Ay =1,2) whose existence and uniqueness conditions are easily seen provable. The function b(x) yields the union values 0,z or 1,z depending on the parity of the number x. The reader will note that the conditions on the  assumption formulas which are b(x) = 0,2 @ « = z0 and b(1) =1,zCGu= 21 are satisfied.  1.4.32 Cartesian case terms. Cartesian case (let) terms have the anno- tated form  caseg,1(c(T),(T =v, W ,w Aolv, w\])) (1)  where the unary function c is introduced into PA by a contextual definition:  36 

c(x) = y ↔ x = 0 ∧ y = 0 ∨ x \> 0 ∧ y = 0, x . 

The completeness condition (cf 1.4.23(1)) for cartesian case terms is 

∃v∃w c(τ) = 0, v, w 

and it is implied by any guard at least as strong as τ \> 0. Under such guard the condition on the assumption formula is satisfied because we have c(τ) = 0, v, w ↔ τ = v, w. 

1\.4.33 Derived case terms. Derived case terms have all functions applied in their discriminator terms definable by generalized definitions with basic case terms. 

For instance, the two let terms used in the generalized definition in Fig. 1.6 are derived terms. The second of them is a let term as used the functional programming languages. The general form of such terms is: 

case0,1((0, τ), (τ = x →x α0\[x\])) . 

The first let term of Fig. 1.6 applies the function qr yielding the pair consisting of the quotient and remainder after the division of z by 4. The let term has the form: 

case0,1((0, qr(τ)), (τ = 4·q + r ∧ r \< 4 →q,r α0\[q, r\])) 

with the condition on its assumption formula satisfied because we have: 

0, qr(τ) = 0, q, r ↔ τ = 4·q + r ∧ r \< 4 . 

This let term is derived because the function qr(z) can be defined with two nested binary case terms: 

qr(z) = case b(z) = 0, u →u case 

b(u) = 0, q →q q, 0 b(u) = 1, q →q q, 2 

b(z) = 1, u →u case b(u) = 0, q →q q, 1 b(u) = 1, q →q q, 3 . 

The unfolded clausal definition of qr just before the identity optimizations is: 

qr(z) = q, 0 ← z = u0 ∧ u = q0 qr(z) = q, 2 ← z = u0 ∧ u = q1 qr(z) = q, 1 ← z = u1 ∧ u = q0 qr(z) = q, 3 ← z = u1 ∧ u = q1 

which becomes after the identity optimizations: 

37

qr(q00) = q, 0 qr(q10) = q, 2 qr(q01) = q, 1 qr(o01) = q, 3 . 

1\.4.34 Pair case terms. Pair case terms are another example of derived terms and they have the annotated form 

case1,2(p(τ), (τ = 0 → α0), (τ = v, w →v,w α1\[v, w\])) 

where the unary function p is introduced into PA by an explicit clausal defi- nition: 

p(0) = 0 p(v, w) = 1, v, w . 

The function p(x) yields the union values 0 or 1, v, w. The conditions on the assumption formulas are satisfied because we have p(x) = 0 ↔ x = 0 and p(x) = 1, v, w ↔ x = v, w. 

The clausal definition of p is unfolded from the generalized definition with basic terms: 

p(x) = case sgn(x) = 0 → let 

c(x) = 0, v, w →v,w 1, v, w sgn(x) = 1 → 0 . 

The reader will note that the let term in the definition is well-formed because its cartesian case term has its quard satisfied since we have sgn(x) = 0 ↔ x \> 0. 

A pair case term is, for instance, used in the generalized definition 

x⊕ y = case p(x) = 0 → y p(x) = 1, v, w →v,w v, w ⊕ y 

from which the clausal definition of the list concatenation function is unfold- ed: 

0⊕ y (v, w)⊕ y = v, w ⊕ y . 

1\.4.35 A short discourse on the role of notation in mathematics and in computer programming. We have been always puzzled by the question why, in the age such dazzling computer generated graphics, the theoreticians of computer programming can live with an ancient typewriter style notation for their programs. A glance in most books on programming languages reveals programs like: 

38

filter \[\] = \[\] filter (y:ys) \| p y = y : filter ys filter (y:ys) \| otherwise = filter ys . 

whereas the same definition in our mathematical notation looks as follows: 

filter(0) = 0 filter(v, w) = v,filter(w) ← P (v) filter(v, w) = filter(w) ← ¬P (v) . 

The reader will note that the test P (v) in our clauses unfolds from a D-case term and so the repeated evaluation of P (v) is avoided. The same must be achieved with an otherwise in the first program. 

The typewriter style is even more puzzling to us because the readability of programs is one of the most basic dictums of a good programming language design. The situation is similar in the existing automated theorem provers, or rather intelligent proof checkers. We typically see in them formulas like: 

forall x ( Sqrt(x)^2 \<= x and x \< ( Sqrt(x) + 1 )^2 ) 

although mathematicians, who in general do not put so much emphasis on the readability as computer scientists, would not dream of presenting the formula in a form different than: 

∀x(\[ √ 

x\]2 ≤ x ∧ x \< (\[ √ 

x\] + 1)2) . 

Part of the reason for this strange way of presentation lies in the tradi- tionally understood role the syntax analysis should play in the design and presentation of computer programs. Language designers seem to insist on the ‘what you see is what you get’ approach to the writing of programs. This is because otherwise the parsing of programs would be difficult as e fancy mathematical notation cannot be easily parsed. True, but the same comput- er scientists use, apparently without any thoughts, a markup language (most often Latex) when writing their papers. They know that they have to enter their formulas in a slightly less readable marked up form and for the price of this minor inconvenience the formulas will be presented in an esthetically pleasing form. 

The reader has certainly noticed that we consistently use mathemati- cal notation for function and predicate applications, logical connectives, and quantifiers. CL, our current implementation of the clausal language, has somewhat limited Latex-like possibilities of presenting formulas as 

∃y(x⊕ y ≺ \[ √ 

x\] ∧ x 6= y) . 

In order to simplify the syntax analysis, the above (somewhat non-sensical) formula is typed in as 

\\e y ( Prec(App(x,y),Sqrt(x)) \& x != y) . 

39

The cultural gap between what is the standard in the supposedly ultra modern computer science and in the old fashioned mathematics is wide and it is still opening up. Referees of our papers which we submit to computer science conferences almost invariably chide us for the funny looking syntax of our programs without apparently realizing that we do not use anything special, just the language of Peano arithmetic. 

The clauses of the present CL system are still syntactically analysed and so we cannot use fancy assumption formulas in our pattern matching presen- tation of arguments. We plan to change this dramatically with the prepared new version of CL. We plan to limit the syntax analysis to the parsing of simple terms and formulas. The case terms will be prompted in a top-down fashion. This, together with the enormous flexibility of extensible syntax of our case terms, will permit the use of arbitrary assumption formulas in the annotations of our case terms. The reader will note that the ‘syntaxless’ syn- tax of our clausal definitions, and the almost unlimited power of extensibility of case terms, will be possible only because the constraints on the case terms will have to be proved in the proof system before a new kind of a case term will be admitted. 

The existing version of CL has a builtin set of pattern matching ex- pressions by far surpassing the ones permitted in current functional lan- guages such as Haskell. Patterns in Haskell are expressions (terms) where- as already the current version CL permits also pattern formulas such as z = 4·x + i ∧ i \< 4. The dramatic difference between the powers of ex- pressibility of patterns as terms and patterns as formulas can be compared to the similarly dramatic difference between the power of explicit definitions f(\~x) = τ in PA which are limited to applications in τ of previously introduced function symbols and the power of contextual definitions f(\~x) = y ↔ φ where one has at disposal in the formula φ the full logical apparatus of propositional connectives and quantifiers. 

We are convinced that the radical step of abandoning in the planned version of CL of the syntax analysis in favor of top-down prompting, together with the full extensibility of case terms, will unleash dramatically new ways of presentation of programs. The reader will note that this will happen fully within the language of Peano arithmetic without the addition of any reserved words or fancy syntax of current programming languages. 

1\.5 Limits of Provably Recursive Definitions in PA 

1\.5.1 Ordinal numbers less than ε0. We wish to give a definition of a function V over N which is ∆1-definable and so it is effectively computable (recursive) but not provably recursive in PA. The function V will grow so enormously fast that it will be practically uncomputable for all but the s- mallest arguments. The function will be defined with a measure into the 

40

initial segment of ordinal numbers less than the first epsilon number €g. This number satisfies the identity 69 = w®.  It is well-known that every ordinal number \~ €g can be uniquely denoted in the Cantor’s normal form by a term  wl +w?...+ Ww" +0 (1)  where n \> 0, a, = a2 \>... = Gy, and the terms q; are constructed similarly. Let a \~ €9 be an ordinal whose Cantor’s normal form is (1) and @ \~\< €9 an ordinal whose Cantor’s normal form is  wh + wh... + wm 40,  The natural sum a{( of the two ordinals is the ordinal less than €9 whose Cantor’s normal form is  wi tw? ...+wIrtm +0  where each 7; is some a; or 3; and all latter numbers are some yx. It should be clear that we have at 6 = Gitta \>a, /.  It is not hard to see that every ordinal number less than €9 is denoted (but not uniquely) by a term built up from 0 by the binary operation afw%. We abbreviate (atw’) tw? to atw’ tw?. The advantage of this representation is that we do not have to order the exponents in non-increasing order and, for instance, the terms a fw? fw? and aftw? tw? denote the same ordinals.  1.5.2 Coding of ordinals \<¢) in N. We encode the ordinals less than € into natural numbers by encoding the ordinal number 0 by 0 € N and the ordinal number a fw by the natural number a @ (b,0) where a, b encode a and (@ respectively. It shuld be clear that every natural number is a code of an ordinal. Note that we have a © (b,c,0) 4 a @ (c,b,0) whenever b 4 c but both numbers code the same ordinal.  The reader will note that we can have a more optimal ‘reverse’ encoding where atw® is encoded by b,a but, since we will be dealing with practically non-computable functions, the efficiency of coding does not really matter.  We ‘overload’ the ordinal function a fw and explicitly introduce it as a binary function over N:  atw’ =a@ (b,0) .  In order to distinguish the two functions we will use variables a, 3, y, ...to range over ordinals and the variables a, b, c, ... to range over the correspond- ing natural numbers coding ordinals.  The ternary function a{w?-n over N yielding the code of the ordinal  — ot Bt...16  is introduced into PA by primitive recursion:  Al 

atw?-0=a atw?-(nt1) =atw?-ntw? .  The binary function wh over N yielding the code of the ordinal designated by the same symbol is introduced into PA by primitive recursion:  wh = Ofw?-i . 4 Wry = Owe.  We also overload the ordinal relation \< and use it as a binary relation a \~\< b over N holding of codes if a \< G holds. The relation is provably recursive in JX, and although transitive and irreflexive, it is not an order because the law of trichotomy does not hold for it (this is because of the non-unique coding of ordinals). We will need a special case of \~ as a ternary relation a \< wh which is introduced into PA by course of values recursion in a:  0O\<wi  k\>0vi\>0  atw® \<wit! —a \<u  atw? X whi, — aX wey, AbX\< uy, .  1.5.3 Arithmetization of fundamental sequences for limit ordinals. We call the code a of an ordinal less than €9 a right successor code if a = bh w® for some 6. A non-zero code a which is not a right successor is a right limit code. The code a is a right limit iff a = b @ (c,0) = bfw\* for some b and c\>0.  We arithmetize the fundamental sequences (a){n\] for limit ordinals a (see \[18\]) by primitive recursion:  (atw#”)\[n\] = atw”.(n+1) (atwt")in\] =atw er\] ce 40.  ID/; proves a#0-—(a)\[n\] \<a. 1.5.4 A function growing faster than functions provably recursive  in PA. Consider the following clauses for the unary function symbol V:  V(Otw?-n) = Ofw?-n V(atubte pun) = V((agw?\*")\[n\] bw?) Viatwet" tun) =V((atwt\*)\[n\] tw-n) —c 40.  The clauses for V are well-discriminated because every number c can be uniquely written as c= d @e where Va(a ¢ e \> x = 0) and  d =0V dadbicd = a @ (0 \& (c,0),0) .  Note that then e codes a finite ordinal, ie. e = Ofw®-n for n = L(e), and d is either 0 or it codes a transfinite ordinal d = afw?#”°. Thus the first clause,  42 

where d = 0, is discriminated from the remaining two where d # 0. The last two clauses are discriminated on whether d = b{w\* is a right successor (c = 0) or a right limit (c 4 0). We have  aguPt gun \> (ato )\[n\] do®-max(1,n)  and so the recursive argument in the last two clauses decreases in the relation \~\<. This relation is not an order over N so it cannot be a well-order. However, the relation is well-founded and so the recursion has to stop after finitely many steps.  The problem is that PA is not strong enough to prove (in the form of a schema of well-founded induction on \<) that the relation \~ is well-founded. This means that the function V, although A -definable, i.e. recursive, is not provably recursive and so it cannot be introduced into PA by extensions by definitions.  On the other hand, for every m \> 0, k \> O and any i the fragment Ixim4+k—1 proves that the restriction of \< to codes \<wi,, i.e. the explicitly defined relation  a\<pibGa\<bAb\<w,” ;  “Mm  is well-founded. This means that J, proves a schema of well-founded induc- tion on \<;,; for ¥,,-formulas.  1.5.5 Extended Ackermann-Péter function. We have chosen the above  form of definition of the function V for two reasons. The first one is that the  function has a close connection to an extension into transfinite codes of the  well-known Ackermann-Péter function from which we can define the so called  fast growing hierarchy of functions. The second reason is a close connection  to the intensional primitive recursive functionals (see UNFINISHED ). We define a binary function A over N by explicit definition:  A(a,n) =LV(Ofw?tw®-n) .  The definition must be done in the standard model of PA because the function A cannot be introduced into PA. The clauses for V imply (in the model) the following recurrences for the function A:  A(0,n)=n+1 A(afw°,0) = A(a, 1) A(atw®,n +1) = A(a, A(atw®,n)) A(atw’,n) = A((atw”)\[n\],n) —b 40.  The binary Ackermann-Péter function which grows faster than all primi- tive recursive functions and satisfies:  43 

Ack(0,n) =n+1 (1)  Ack(m + 1,0) = Ack(m, 1) (2)  Ack(m+1,n+1) = Ack(m, Ack(m + 1,n)) (3)  can be now explicitly defined as Ack(m,n) = A(Ofw°-m,n). The reader will note that we have 0{w°-m \~\< wi and so the codes of ordinals used in the  computation of Ack do not even start to exploit the incredible rate of growth of the function A applied to the codes of larger ordinals.  1.5.6 Fast growing hierarchy. The extended Ackermann-Péter function can be also used to define a fast growing hierarchy of functions FQ similar to the ones studied by Wainer \[25\] and Schwichtenberg \[19\] (see also Rose \[18\]). To that end we assign to every ordinal a \~ €9 as its canonical code a the code obtained from the Cantor’s normal form for a by replacing + by natural sums {. We then explicitly define:  Fy(x) = A(a, x) and obtain the following properties of functions Fy: Fo(z) =a2+1 Fo4i(v) = Fy\*\*(1) Fy(«) = Fra)\[a\\() a is a limit ordinal. We have chosen the hierarchy functions in such a way that for finite ordinals  m we have F,,(n) = Ack(m,n).  1.5.7 Provably recursive restrictions of V. It is well-known that the function F,, satisfying:  Feo(#) = Feeo){aj(t) = Fux (x) = Az, 2) = LV(0d wis tw-r) = LV (wt) tw?) is not provably recursive in PA. This is another reason why the function V cannot be provably recursive.  Let us now investigate restrictions of V which are provably recursive in PA. The unary function V.(a) is introduced into PA by explicit clausal defi- nition:  V.(Ofw?-n) = Ofw?-n  V.(at weve tw?-n) =attw?-(n+1) tw?  Vela tw?" tn) = atwltlrl tun He £0.  and its binary iteration V,”(p) is introduced by primitive recursion:  Vo(p) =p V+ (p) = Ve Ve"(p)  44 

The standard model of PA then satisfies: Anim V."(a) = 0fw-m (1)  which is the condition of regularity for an expansion of the standard model of PA by a function V defined by minimalization:  V(a) = T up\[V" (a) = 04w°-T(p)\| (2)  The clauses for V are then provable in PA extended by the axiom (2). This means that Peano arithmetic is not strong enough to prove the existence condition (1) because otherwise V would be provably recursive.  On the other hand, for k \> 1 and any i the fragment J’, proves  a \~\< wi" — Indm V."(a) = Of w?-m (3) and so the function V;; satisfying Vii (d) =O0fw?-n —d Xx wi" Ad=0fw°-n  Vii(d) = Vii (atw?-(n+1) tw®) — dX wn A d=atwt” tw Vii (d) = Ve r(atw Feld fon) — d \< we" Ad=atwt tw®nvhc#0  is provably recursive in J, and the standard model of PA satisfies a \~\< wi" \> Vi i(a) = V(a) .  For any k \> 1 and any ordinal a \< wz with the canonical code a we have a \<wi\_, for some i \> 0 and so w® \< wi. Thus 0fw7 tw°-a \< a,” and, since  F(x) = A(a,x) = LV(Otw\* tw?-a) = LVp (OLw\* tw-x) ,  the function Fy is provably recursive in \[’,. Hence all functions F, where Q@ \~\< € are provably recursive in PA.  1.6 Intensional Issues of Computability  UNFINISHED Intensional issues have to do with the form of terms and definitions rather than with the functions and predicates defined. UNFINISHED annotation on case terms plays no role.  Computation Over Mixed Numerals  We have introduced the clausal definitions with the help of generalized terms in such a way that to every clausal definition there is a regular generalized course of values definition with measure. We will now show how to use the latter for effective computation.  45 

1\.6.1 Mixed numerals. We will compute over the class of mixed numerals which are the least set of terms containing the constant 0, with every terms ρ1, ρ2 also the terms ρ11 and (ρ1, ρ2), and with every term ρ 6≡ 0 also the term ρ0. Binary and pair numerals are thus proper subsets of mixed numerals. 

In contrast to monadic, binary, or pair numerals, the mixed numerals do not enjoy the unique representation of natural numbers. For instance, the number three is denoted by four mixed numerals which are all different as terms: 

011 (0, 0)1 (01, 0) ((0, 0), 0) . 

1\.6.2 Mixed definitions of functions. We will compute functions de- fined by mixed definitions which are certain regular generalized course of values definitions with measure. The generalized definitions use D, binary, cartesian, and case terms derived from these. The object terms in the defini- tions are built up from the constant 0 and variables by applications of binary successors, pairing, and of previously defined functions. Decimal numerals are abbreviations for the corresponding binary numerals and predicates are computed from the definitions of their characteristic functions. 

We distinguish two classes of mixed definitions. Mixed definitions in the narrow sense, or narrow mixed definitions, are such that the measure terms in recursive generalized definitions apply only functions which are also definable by narrow mixed definitions. Unlimited mixed definitions allow functions in the measures to be introduced into PA by any extension by definition, say by a contextual definition. 

The difference in the two classes is substantial. It is easy to see that the narrow mixed definitions define only primitive recursive functions while arbitrary mixed definitions define all provably recursive functions of PA, i.e. the ≺ε0-recursive functions. 

1\.6.3 Reductions. We will compute well-formed generalized terms α by reductions. The terms α will be closed, i.e. without free (non-local) variables. Reductions proceed by locating in α, which is not yet a mixed literal, the leftmost and innermost generalized term, called redex, and by rewriting the redex with a corresponding generalized term, called contractum. The rewrit- ing is repeated until the generalized term being reduced becomes a mixed numeral. 

UNFINISHED I notation UNFINISHED it is a good approximation of compilation for simplicity we substitute for local variables and arguments instead of using environments. 

UNFINISHED termination 

1\.6.4 Redexes and their contracta. In the following we list all redex contracta pairs using the notation I. We denote by α closed generalized terms, by τ closed object terms, and ρ the mixed numerals. The reader will 

46

note that for all redex contracta pairs a, » a2 the terms a; and ag denote the same natural number, i.e. we have af = a}. The reduction  p00 » pO removes one leading zero. Reductions  sgn(0) » O1 sgn(p1) \> sgn (pO) \> if p #0 5g7(p1, p2) \>  simplify the discriminators of D-case terms. Reductions  b(0) » 0,0 b(p0)®0,p ifp40  b(p1) » 00, p  b(p1,p2) ® 0,p where p0 = pi, po (1) b(p1,p2) » 01,p — where pl = pi, p2 (2)  simplify the discriminators of binary case terms. Reductions  c(p) ® 0,p1,p2 where p = pi, p2 (3)  simplify the discriminators of cartesian case terms. The reader will note that in any such then we must have p # 0. The reduction  f(p) » alf, A\]  opens a mixed definition f(Z) = a\[f; 2\]. The final set of reductions involves case terms (both basic and derived)  COSC mk (P,Q0,---;QAml\[Ym\],--.) \& a (4)  where if p = j, with j \< m then a = a; and if p = j,, pj then a = a; \[pj\]. The reader will note that the well-formedness restrictions on case terms guarantee that the term p denotes a union value determined by m, k, nm, .--, Mk—1-  Reductions (1), (2) involve and reductions (3), (4) may involve conversions between representations of mixed numerals. The no conversion condition for the reduction (3) is p = p1, p2 and for (4) the condition is p= j, with 7 \<m and p = j,, p; with m \< 3 \< k. Conversions are effectively computable but may be time consuming.  AT 

Data Types 

Conversions in the marked reductions of Par. 1.6.4 are quite time consuming (although computable in linear space and polynomial time as shown in \[24\]) and we would like to avoid them. This can be done by means of syntactic restrictions on the form of mixed definitions by means of typing. Moreover, well-typed definitions of functions can be efficiently compiled into machine code (or C for that matter). 

Types are intuitively certain sets of data values. Since our values are nat- ural numbers, the types are certain subsets of N, and hence can be defined by unary type predicates. With a proof system integrated with a programming language we can define arbitrary type predicates and provide proofs that our definitions of functions yield values of certain types when provided with argu- ments of some types. We, however, feel that the full power of the proof system should be reserved to the proofs of theorems about our functions rather than being used for typing. We think that the type predicates should form a rather weak class so the typing can be performed in a decidable manner. Moreover, as mentioned above, the typing should prevent needless conversion of repre- sentation of data values and should enable efficient compilation. For the last, the types should reflect the memory representation of data structures and it seems to us that the Pascal-style typing is a natural choice. Pascal-style type predicates can be then naturally extended to polymorphic type predicates in the style of ML. 

There are two aspects to typing. The extensional aspect deals with the specification of the class of type predicates. The intensional aspect deals with a decidable typing calculus for deriving assertions about the types of terms, generalized terms, and definitions. Well-typed closed generalized terms then reduce without any conversion of mixed numerals. Well-typed definitions of functions and predicates with the polymorhic types instantiated, can be efficiently translated into machine code. 

1\.6.5 Pascal-style type predicates. Pascal-style type predicates can be defined by ordinary clausal definitions of predicates whose syntax is severely restricted. We will by convention choose the predicate symbols to be postfix operators whose applications are written as x : T and read as (the value of) x is of type T . The reader should view the combination : T as the symbol of a type predicate rather than to view : as a binary infix operator taking a value and a type. In the folowing we will use S, T as meta-variables ranging over the symbols for types predicates. 

The Pascal-style type predicates can be classified as primitive, cartesian, list, and union type predicates. 

1\.6.6 Primitive type predicates. The type of natural numbers is given by the predicate N with the following explicit clausal definition: 

x : N . 

48

The type N is the type of natural numbers. Values of type N can be repre- sented in computer memory as the bignums of LISP, i.e. as numbers in the unlimited precision. 

In a concrete implementation of CL we can choose more kinds of primitive type predicates. Unsigned and signed limited precision numbers represented in memory by, say, 32-bit words come to mind. 

1\.6.7 Cartesian type predicates. Suppose that T1, . . . Tn have been in- troduced into PA as type predicates. The unary type predicate T explicitly defined by the clausal definition 

x1, . . . , xn : T ← x : T1 ∧ . . . ∧ x : Tn 

is the type predicate of cartesian product of T1, . . . , Tn. For instance, the predicate 

x, y, z : N3 ← x : N ∧ x : N ∧ x : N 

is the type of triples of natural numbers. The reader will note that the same predicate has a simpler definition 

x, y, z : N3 

which, however, does not have the prescribed syntactic form. 

1\.6.8 List type predicates. Suppose that T hat been introduced into PA as a type predicate. The predicate 

0 : List(T ) x, y : List(T ) ← x : T ∧ y : List(T ) . 

is the type predicate of lists with elements from S. The reader should read the combination : List(T ) as a ‘structured’ predicate symbol rather than as an operator taking types and yielding types. 

Note that in the absence of polymorhism, the Pascal-style typing requires that, for instance, the predicates List(N) and List(N3 ) should be introduced as two different predicates. The reader will also note that we have ∀x x : List(N). 

The memory representation of values of type List(T ) can, for intance, be a 32-bit pointer which is either nil for empty lists or a pointer to a cartesian pair T×List(T ). 

1\.6.9 Union type predicates. Union type predicates hold of union values. Rather than discussing the general form of union types we illustrate them with an example. Consider the following clausal definition: 

0 : Bt(T ) 1, n, l, r : Bt ← n : T ∧ l : Bt(T ) ∧ r : Bt(T ) 

49

where the type predicate T has been previously introduced into PA. A more familiar definition of the same predicate is with the help of two constructor functions E = 0 and Nd(n, l, r) = 1, n, l, r as 

E : Bt(T ) Nd(n, l, r) : Bt ← n : T ∧ l : Bt(T ) ∧ r : Bt(T ) . 

Values of type Bt(T ) are union values determined by 1, 2, and 3 (the arity of the value with the tag 1) where the values 1, n, l, r have the components appropriately typed. 

Values of this type may be represented by pointers. The value E by nil and the values with the tag 1 by a pointer to a cartesian quadruple N×N×Bt(T )×Bt(T ) with the first component holding the tag 1. 

The reader will note that we have 

x : Bt(N) → x : Bt(T ) 

for any union type predicate Bt(T ). UNFINISHED general form of representation of union values UNFINISHED union The type Ch is the type of extended ASCII char- 

acters and can be represented as bytes. 

1\.6.10 ML-style type predicates. Polymorphic typing in the style of the programming language ML corrects the greatest shortcoming of Pascal-style typing where the symbol T in the application x : List(T ) is a part of the predicate symbol rather than a second argument to the binary predicate x : List(t) where the type parameter t ranges over all Pascal-style typing predicates. We cannot achieve this without going to the second-order calculus of arithmetic because in PA both arguments x and t must be natural numbers. Hence, the argument t does not range over type predicates but over the codes of type predicates. The polymorphic list predicate is then introduced into PA as a binary predicate by the following clausal definition: 

0 : List(t) x, y : List(t) ← x :: t ∧ y : List(t) 

which applies a binary universal typing predicate x :: t. The reader will note the bold colon symbol signifying that this is a binary infix predicate rather than a part of the predicate symbol. 

The universal predicate, which will be discussed in Par. 1.6.13, is such that PA proves 

x :: ′T (t1, . . . , tn) ↔ x : T (t1, . . . , tn) (1) 

for every type predicate T with n type parameters, i.e. an (n + 1)-ary type predicate x : T (t1, . . . , tn), introduced into PA. Here ′T (τ1, . . . , τn) is an ab- breviation for a certain term of PA which denotes the code of x : T (τ1, . . . , τn). 

50

When T has no paramaters, i.e. when x: T is a unary type predicate, then (1) should be read as e:/Toa:T.  This style of polymorphism which permits type parameters in the form of variables ranging over (codes of) Pascal-style types but no new types is called predicative polymorhism (see, for instance, \[15\]).  With the polymorphic list type predicate one now takes arbitrary type predicate T and writes x : List(’T) instead of having to introduce the type predicate : List(T) separately for each T.  We introduce a convention of writing the type applications 'T(T1,..., Tn) for n \> 0 in an abbreviated form T(71,..., 7). We can thus write x : List(T) instead of x : List(’/T). The reader will note that by (1) the last is equivalent to x :/List('T) which can be abbreviated to x: List(T).  Polymorphic type of binary trees is defined by the type predicate with one type parameter:  E: Bt(t) Nd(n,l,r): Bt(t) —n:tAl: Bt(t) Ar: Bt(t)  We can now, for instance, assert x : Bt List(N3) which is an abbreviation for x : Bt('List(’N3)) or equivalently x : Bt List(N3) which is an abbreviation for x :'Bt('List(’N3)).  1.6.11 Polymorphic vector type predicate. Vectors (arrays) are exten- sionally lists of given length. The importance of vectors lies in their inten- sional properties of having good memory representations. It would seem that we need two kinds of vector types. The ternary polymorphic type predicate x: Vecti(n,t) holding of fixed vectors is introduced into PA by primitive recursion:  0: Vect,(0, t) v,w: Vecti(n+1,t) —v:tAw: Vecty(n,t) .  For every positive number n and every type predicate T the fixed vectors x : Vect;(n,,'T) are represented in memory just like the Pascal arrays of type array\|0..(n—1)\] of T.  The binary polymorphic type predicate x : Vect(t) holding of flexible vectors is introduced explicitly into PA by:  n,x: Vect(t) — a: Vecty(n,t) .  For every type predicate T the flexible vectors x : Vect('T) are represent- ed in computer memory as pointers to dependent cartesian pairs of type Nx Vect,(n,'T) where the value of the first component is n. The first com- ponent thus hold the length of the vector.  However, the practice of programming in our programming language Tril- ogy II, in which we have implemented the system CL, shows that fixed vectors  51 

are not used at all. For this reason we will work below with the flexible vectors only. 

1\.6.12 Operations on vectors. Although vectors are extensionally just lists it is of advantage to select some operations on them as basic ones and enforce by means of typing (see UNFINISHED ) that the vectors are efficiently operated upon through these operations. These restrictions will guararantee an efficient compilation of vector operations into machine code. 

There are three operations on vectors: creation of new vectors New(n, v), indexing of vectors a\[i\], and modification of vectors a\[i := v\]. The operations are introduced into PA with the help of auxiliary operations performing the same tasks with fixed vectors whose clausal definitions are: 

New1(0, v) = 0 New1(n + 1, v) = v,New1(n, v) (v, a)\[0\]1 = v (v, a)\[i + 1\]1 = a\[i\]1 (v, a)\[0 := w\]1 = w, a (v, a)\[i + 1 := w\]1 = v, a\[i := w\]1 . 

The operations for (flexible) vectors are then introduced into PA by explicit clausal definitions: 

New(n, v) = n,New1(n + 1, v) (n, a)\[i\] = a\[i\]1 ← i \< n (n, a)\[i\] = a\[0\]1 ← i ≥ n (n, a)\[i := v\] = n, a\[i := v\]1 ← i \< n (n, a)\[i := v\] = n, a ← i ≥ n . 

The reader will note that in the application Nev(n, v) the number n is not the length of the vector but rather its highest index. This means that the result is a vector with at least one component. This arrangment is important for the smooth typing of vector operations where the indexing operation yields an element of its argument vector (rather than the default 0 which is difficult to type properly) even if the index is out of bounds. 

1\.6.13 The universal typing predicate. By a detour through some aux- iliary predicates we can introduce into PA a binary predicate x :: c which acts as a universal typing predicate such that PA proves 

x :: tappl(pTq, t1, . . . , tn, 0) ↔ x : T (t1, . . . , tn) (1) 

for every type predicate T with n type parameters introduced into PA. Here pTq is a mixed numeral denoting the code of T obtained by the arithme- tization (see below) of the definition of T . The binary constructor function tappl codes the type application of T to its parameters. When T is without parameters then (1) should be read as 

52

x:tappl("T',0)ca:T.  The abbreviation 'T'(p1,..., Pn) discussed in Par. 1.6.10 stands for the term papply("T, pi,--+,Pn;0).  The arithmetization of definitions of type predicates needs the follow- ing constructors which are explicitly introduced into PA as follows: N = 0; tappl(c,p) = 1,p,s; vect(t) = 2,t; tixtg = 3,t1,te; t1x\*te = 4,t1, to; Un(m, s) = 5,m, 8; par(n) = 6,n; and rec(x,c, p) = 7,2, ¢,p.  PA proves the following properties of the universal typing predicate:  z:N x: vect(t) @ dInda(a =n aA L(a) =n+1AVili\<n— (a); 2 t)) u:tyXte @ dvdw(a =v,wAvit; Aw: te) wit)xX\*te 9 @ =OVa:tXte x: tappl(c,p) @ x: sb(c,x,c¢,p) ri rec(y,c,p) \|x\|, \< \|y\|, \\@ + tappl(c, p) x:Un(m,s) ox“ \< mv didy(i \< L(s)Ac=m+i,yAys: (s)i) .  The constant N denotes the code of the definition of the type predicate N (see Par. 1.6.6), ie. "N'= N, and so  'N = tappl("N7,0) = tappl(N,0) .  The term vect par(0) denotes the code of the definition of the one-parameter type predicate Vect (see Par. 1.6.11), ie. " Vect! = vect par(0), and so  ‘Vect(p) = tappl(" Vect”, p,0) = tappl(vect par(0), p,0) .  For every ¢; and tz the term t; xtz denotes the code of the cartesian product of t; and tg. We abbreviate t; x(t2xt3) to t; xtextg. Thus, for instance, the code "N3! of the type predicate N3 (see Par. 1.6.7) is ’Nx’Nx’N, and so  'N3 = tappl(" N31,0) = tappl(tappl(N,0)xtappl(N,0)xtappl(.N,0),0) . For every ¢; and tz the term t; x\*tz codes the ‘optional’ cartesian product of t,, tg which holds of 0 or of cartesian products t; Xt.  For instance, the code ' List” of the polymorphic list type predicate List (t) (see Par. 1.6.10) is as in the following:  ‘List(p) = tappl(" List’, p,0) = tappl(par (0) x\*rec(0,0), p,0) .  The constructor par codes the type parameters in the codes of type pred- icates with type parameters such that the i-th parameter is coded by  53 

par(i− 1b). The constructor rec codes recursive applications of type pred- icates in their definitions. The purpose of both constructors can be seen in the following: 

x :: ′List(t) ⇔ x :: tappl(par(0)×∗rec(0, 0, 0), t, 0) ⇔ x :: sb(par(0)×∗rec(0, 0, 0), x, par(0)×∗rec(0, 0, 0), t, 0) ⇔ x :: t×∗rec(x, par(0)×∗rec(0, 0, 0), t, 0) ⇔ x = 0 ∨ x :: t×rec(x, par(0)×∗rec(0, 0, 0), t, 0) ⇔ x = 0 ∨ ∃v∃w(x = v, w ∧ v :: t ∧ w :: rec(x, par(0)×∗rec(0, 0, 0), t, 0) ⇔ x = 0 ∨ ∃v∃w(x = v, w ∧ v :: t ∧ w :: tappl(par(0)×∗rec(0, 0, 0), t, 0)) ⇔ x = 0 ∨ ∃v∃w(x = v, w ∧ v :: t ∧ w :: ′List(t)) ⇔ x = 0 ∨ x :: t×′List(t) ⇔ x :: t×∗′List(t) . 

The four-place substitution function sb(c, y, d, p) yields the code obtained from the code c by substituting in it for every occurrence of parameter par(i) the value (p)i and for every occurrence of rec(0, 0, 0) the value rec(y, d, p). Since we have 

x :: rec(y, d, p) ↔ \|x\|p \< \|y\|p ∧ x : tappl(d, p) , 

we can see that after the substitution rec acts as a guarded type application tappl(d, p) which is invoked only if x is structurally simpler than y. This use of guards is similar to that in definitions by course of values recursion with measure and in both cases we enforce by it the termination of recursion. Clausal definitions of recursive type predicates must be regular in the first argument and so the guards are always satisfied for their codes. 

The substitution sb(c, y, d, p) is shallow in the sense that it does not enter the codes tappl(e, q) embedded in c. This means that we have no non-local parameters and recursion in the codes and as a consequence the predicate x :: c is primitive recursive. 

The constructor Un codes union type predicates. The idea is that we have x :: Un(m, ρm, . . . , ρk−1, 0) iff x is a union value determined by m, k, nm, . . . , nk−1 (see Par. 1.4.23). Moreover, for every j s.t. m ≤ j \< k the number nj is the ‘arity’ of the code ρj , i.e. the code has a form σ1× . . .×σnj , and we have x = j 

b , y1, . . . , ynj with y1 :: σ1, . . . , ynj :: σnj . The reader will note that the 

last is equivalent with x = j b , y and y :: ρj . 

For instance, the code pBtq of the polymorphic type predicate of labelled binary trees Bt(t) (see Par. 1.6.10) is as in the following: 

′Bt(ρ) ≡ tappl(pBtq, ρ, 0) ≡ tappl(Un(1b, (par(0)×rec(0, 0, 0)×rec(0, 0, 0)), 0), ρ, 0) . 

1\.6.14 Type terms. We will present below a calculus for deriving asser- tions about well-typed generalized terms and definitions. For that we need a 

54

flexible language whose terms ρ denote codes of type predicates. The terms are called type terms and they are used in applications x :: ρ. Type terms are constructed from variables (say t1, t2, . . . ) ranging over type codes (i.e. over N) by constructors ρ1×ρ2, ρ1×∗ρ2, 

Un(mb, ρm, . . . , ρk−1, 0) , 

and by type applications of the form ′T (ρ1, . . . , ρn) where T is a type predi- cate with n-parameters previously introduced into PA. The reader will recall that the last type application abbreviates the term tappl(pTq, ρ1, . . . , ρn, 0). 

For every type predicate T with n parameters (n ≥ 0) introduced into PA except N and Vect we take its code pTq, express it via constructors as a term of PA, shallowly replace in it every subterm par(ib) by the variable ti+1, every subterm rec(0, 0, 0) by the type term ′T (t1, . . . , tn) We obtain thereby a type term ρ\[t1, . . . , tn\] such that PA proves 

x :: ′T (t1, . . . , tn) ↔ x :: ρ\[t1, . . . , tn\] (1) 

For instance, for the type predicates mentioned in Par. 1.6.13 PA proves 

x :: N3 ↔ x :: N×N×N 

x :: List(t) ↔ x :: t×∗List(t) x :: Bt(t) ↔ x :: Un(1, (t×Bt(t)×Bt(t)), 0) 

where we have consistently used the abbreviations for type applications (see Par. 1.6.10). 

1\.6.15 Typing calculus. We wish to type a mixed definition of the n-ary function symbol f in the polymorphic style of ML (see \[10\]) as 

f :: ρ1, . . . , ρn 7→ρ (1) 

where ρ, ρ1, . . . , ρn are type terms. This extensionally means 

x1 :: ρ1 ∧ . . . xn :: ρn → f(x1, . . . , xn) :: ρ , (2) 

but intensionally the typing (1) is a much stronger assertion because it will be derived in a considerably weaker calculus, indeed a decidable one, than a formal proof system of the first-order theory PA. 

Consider for instance, the explicit clausal definition: 

f(x) = 3, x 

for which PA trivially proves 

x :: N → f(x) :: N 

but we will not be able to derive f :: N 7→N in the type calculus. 

55

The derivation of (1) in the weak type calculus will guarantee the compu- tation by reduction without any conversions of applications f(τ1, . . . , τn) for all mixed numerals τ1, . . . , τn for which the typing calculus derives τ1 :: ρ1, . . . , τn :: ρn. A mixed numeral τ such that the typing calculus derives τ :: ρ is called a canonical numeral of type ρ. Another advantage of the derivation of (1) in the typing calculus with closed type terms (without free type variables) is that the definition of f can be efficiently compiled into machine code or into the programming language C using the Pascal-like representation of its data types. 

The typing calculus will be deriving either assertions of the form (1) or type sequents of the form 

∆ ⇒ α :: ρ (3) 

where α is a generalized term and ρ a type term. ∆ is a sequence of finitely many (possibly empty) assumptions (guards). The assumptions are of the form x :: ρ or f :: ρ1, . . . , ρn 7→ρ. The order of assumptions in ∆ is irrelevant and the reader can treat ∆ as a finite set or, alternatively, he can enrich the type calculus by structural rules permitting interchange, duplication, and removal of duplications in the assumption sequence ∆. We say that the typing calculus derives α :: ρ if it derives the sequent ∅ ⇒ α :: ρ. 

Derivations in the typing calculus are trees with roots of the form (1) or (3). The derivation trees are constructed in the usual way by means of 

rules of inference which are of the form φ1 . . . φn 

φ where the conclusion φ is 

derived from the premises φ1, . . . φn. We do not exclude n = 0 and such rules are axioms. 

The typing calculus is extensible in the sense that with every extension by definition of PA the typing calculus is extended with new rules of inference involving the newly introduced symbols. 

We leave it to the reader to check that whenever the typing calculus derives the sequent ∆ ⇒ α :: ρ then PA proves ∆? → α∗ :: ρ where ∆? stands for the conjunction of translated assumptions. Here an assumption x :: ρ is translated into itself and an assumption f :: ρ1, . . . , ρn 7→ρ into 

∀x1 . . . ∀xn(x1 :: ρ1 ∧ . . . xn :: ρn → f(x1, . . . , xn) :: ρ) . 

Similarly, when (1) is derived in the typing calculus then PA proves (2). These two facts prove the soundness of the typing calculus. The completeness of the calculus is not desirable because of its intensional benefits. 

In the following paragraphs we present the inference rules of the typing calculus categorized into groups. UNFINISHED metavariables ....... α, τ , ρ, σ 

1\.6.16 Inference rules using assumptions. Only two kinds of inference rules use assumptions (guards) in sequents. The first kind are axioms which 

56

type object variables and the second kind are rules with n premises typing applications of n-ary function symbols:  A,x:p\>x:p A, fis pi,..-,\~ProepS\>tiipi ... A, fs pi,.-., PnP \> Tn? Pn A, fi Pisses PuP \> F(Ty--s Tn) #P  1.6.17 Axioms typing the constant 0. The constant 0 can be typed in three ways. This kind of multiple typing is often called ad hoc polymorhism. The first two kinds are given by the following axioms and the third kind is discussed in Par. 1.6.20:  A=0:'N A+ 0: p,x\*po  1.6.18 Axioms typing the binary successor functions. The binary successor functions -0 and -1 have the following typing:  0::/NH'N ‘Li /NWIN  The reader will note that this, the typing of 0 as ‘N, and the typing of function applications (see Par. 1.6.16) permits to derive the sequents A =\> 7 :’N where 7 are binary numerals. The assumptions about the types of binary successor functions can be eliminated from A by the rules discussed in Par. 1.6.25. This enables the derivation of 7 :’N for all binary numerals. As it happens, these are the only mixed numerals which can be typed as NV. Compare this with a trivial proof of 7 :’N in PA for arbitrary terms rT.  1.6.19 Inference rules typing applications of the pairing function. Pairs can be typed in three ways. The first two kinds type pairs as cartesian products:  A\>m1:p, A\>? po A =\> 71,72 2 PX po  A =\> 71,72 2 piXpe2 A =\> 71,72: p1X\* pe  and the third kind as union values (see Par. 1.6.20).  1.6.20 Inference rules typing union values. Union values are typed by two kinds of inference rules:  where 7 \<™m A = j, 2 Un(my, Pm, +++; Pk—1,9) J  A\>T:)p;  ; wherem\<j\<k A = j,,7 + Un(my, Pm, +--+; Pk—1;9)  57 

The reader will note that the binary numerals j, can be typed either as 'N (see Par. 1.6.18) or as union values of suitable union types. Binary numerals are included as tags also in union value pairs typed by the inference rules of the second kind. Pairs can be thus typed either as (optional) cartesian products or as union values.  1.6.21 Axioms typing operations on vectors. The three operations on vectors introduced in Par. 1.6.12 have the following polymorphic typing:  New ::'N, tr! Vect(t) \[-\] : /Vect(t),’Nrot  ‘\[ = -\] 2: /Vect(t),’N, tr’ Vect(t)  These are the only inference rules for the typing of vectors. Thus every well- typed function definition with the vector type must be built up from the three operations and/or auxiliary functions applying the operations.  1.6.22 Axioms typing the discriminators of basic case terms. The discriminators of case terms (both basic and derived) yield union-values. For the typing of case terms we wish the union values to be typed by union types. This is achieved for the discriminators of the three basic case terms by the following typing axioms  3gn ::'N+' Bool ggn ::' Bool’ Bool b::'NrUn(0,'N,'N,0) cit) xtgUn(0, (ti xt), 0)  where the union type predicate Bool is introduced into PA as follows:  Bool(0) Bool(1) .  It should be clear that we have xz:'Bool + x: Un(2,,0)  but the reader should not associate the value 0 with truth and 1 with false- hood because the characteristic functions of predicates yield 1 for truth and 0 for falsehood. The type Bool should be understood simply as holding of 0 or 1.  The function sgn is typed in two ways in a form of ad hoc polymorhism. The first typing is intended to be used with the first form 1.4.30(1) of D- terms which test for zero. The second typing is intended for the second form 1.4.30(2) where the arguments of sgn are results of characteristic functions of predicates. The reader will recall that we treat the clausal definitions of characteristic functions of predicates as defining the predicates themselves and we wish the functions to be typed as ...+’ Bool.  58 

1\.6.23 Inference rules typing case terms. The idea of typing of a case term 

casem,k(τ, α0, . . . , αm−1, αm\[y1, . . . , ynm \], . . . , αk−1\[y1, . . . , ynk−1 \]) 

under assumptions ∆ by a type term ρ is to type its discriminator by a union type 

Un(mb, (σ (m) 1 × . . .×σ(m) 

nm ), . . . (σ(k−1) 

1 × . . .×σ(k−1) nk−1 

), 0) (1) 

and all of its terms αi by ρ. Note that the assumption formulas in case terms do not play any role. We can type only such guarded case terms whose guards are implied by the assumptions ∆. However, the implication is not to be proved in PA but rather in the typing caluclus with its limited means. The sole purpose of guards is to act as assumptions for the proof of the completeness condition 1.4.23(1). Note that the property is satisfied under assumptions ∆ by the typing under the same assumptions of the disciminator term τ by the union type (1). These considerations lead to the following inference rule: 

∆ ⇒ τ :: Un(mb, (σ (m) 1 × . . .×σ(m) 

nm ), . . . (σ(k−1) 

1 × . . .×σ(k−1) nk−1 

), 0) 

∆ ⇒ α0 :: ρ 

... ∆ ⇒ αm−1 :: ρ 

∆, y1 :: σ (m) 1 , . . . , ynm :: σ(m) 

nm ⇒ αm :: ρ 

... 

∆, y1 :: σ (k−1) 1 , . . . , ynk−1 :: σ(k−1) 

nk−1 ⇒ αk−1 :: ρ 

∆ ⇒ casem,k(τ, α0, . . . , αm−1, αm\[y1, . . . , ynm \], . . . , αk−1\[y1, . . . , ynk−1 \]) :: ρ 

1\.6.24 Inference rules introducing defined type predicates. Every type predicate T other than N or Vect can be presented by a typed term in the form 1.6.14(1). For such predicates we have the following typing rules: 

∆ ⇒ α :: ρ\[ρ1, . . . , ρn\] ∆ ⇒ α :: ′T (ρ1, . . . , ρn) 

As an example of such rules we show in Fig. 1.10 the derivation of 0, 1, 0 :: List(Bool) where the reader will recall that 1 stands for the binary numeral 1b. 

1\.6.25 Inference rules eliminating assumptions on function types. For the typing of function applications (see Par. 1.6.16) we need assumptions 

59

∅ ⇒ 0 :: Un(2b, 0) 

0 :: Bool 

∅ ⇒ 1 :: Un(2b, 0) 

∅ ⇒ 1 :: Bool 

∅ ⇒ 0 :: Bool×∗List(Bool) 

∅ ⇒ 0 :: List(Bool) 

∅ ⇒ 1, 0 :: Bool×List(Bool) 

∅ ⇒ 1, 0 :: Bool×∗List(Bool) 

∅ ⇒ 1, 0 :: Bool×List(Bool) 

∅ ⇒ 0, 1, 0 :: Bool×List(Bool) 

∅ ⇒ 0, 1, 0 :: Bool×∗List(Bool) 

∅ ⇒ 0, 1, 0 :: List(Bool) 

Fig. 1.10. Example of a derivation in the typing calculus. 

of the form 1.6.15(1). The assumptions can be eliminated by the followoing inference rules: 

∆, f :: ρ1, . . . , ρn 7→ρ ⇒ α :: ρ f :: σ1, . . . , σn 7→σ 

∆ ⇒ α :: ρ 

where the assumption f :: ρ1, . . . , ρn 7→ρ is an instance of the polymorphic typing f :: σ1, . . . , σn 7→σ in the second premise. The instance is obtained by a possible simultaneous substitution of suitable type terms for some (or all) type variables occurring in the type terms σ, σ1, . . . , σn. 

1\.6.26 Inference rules typing mixed definitions of functions. We can derive the typing of a form 1.6.15(1) for a mixed definition f(x1, . . . , xn) = α\[f ; x1, . . . , xn\] with n ≥ 1 by typing the body α\[f ;x1, . . . , xn\] under assump- tions about the types of its free variables and about the type of f (this is needed for possible recursive applications). This is captured by the following inference rules: 

x1 :: ρ1, . . . , xn :: ρn, f :: ρ1, . . . , ρn 7→ρ ⇒ α :: ρ 

f :: ρ1, . . . , ρn 7→ρ 

If f is a constant, i.e. a nullary function, and it has an explicit mixed definition f = α then we type it by the following inference rules 

∅ ⇒ α :: ρ 

f :: ρ . 

1\.6.27 Example of typing. UNFINISHED Reverse 

1\.6.28 Type inference. Type inference is the general problem of deriving a type assertion about an untyped or partially typed program. Clausal defi- nitions are untyped. Even when a type definition is well-typed, i.e. typable, it can happen that it can be typed in an ad hoc polymorphism by more than one unrelated types. For instance 

60

f(x) = x,0,0  can be typed as f :: tetxNxN, fo: t1x\*te 3 List(tyx\*te), or fos: N+\>List(N). There are many more typings when one considers union types. It is probably the case that any typeable definition can be typed by a finite number of principal, i.e. most general typings, such that any typing is an instance of one of the typings.  What is important is that for any sequent A = a: p we can decide the formula  5t(A\* \> a\* : p)  by finding the type witnesses for f. This is done by adaptation of the unifi- cation algorithm for polymorphic typing of Milner \[14\]. We can thus decide whether function definitions are well-typed.  1.6.29 Computation of well-typed mixed definitions. All closed gen- eralized terms used in mixed definitions reduce to mixed numerals. We claim that the well-typed ones reduce without taking the reductions marked in Par. 1.6.4. We note first of all, that all reductions preserve the types and so all terms in a chain of reductions are well-typed.  Reductions 1.6.4(1) or (2) are taken when the discriminator of a binary case term is b(p1, 2) with p, and p2 mixed numerals. Since the case term is well-typed, we have b :: N++Un(0, N, N,0), the argument of 6 must be typed as N. However, all mixed numerals of type N are binary numerals and so the situation cannot happen.  Reductions 1.6.4(3) are taken when reducing the discriminator of a carte- sian case term c(p) with p a mixed numeral. Since the only typing for c is ci: ty xtgUn(0, (t1 xtz),0), we must have p : t; xtg for some t, and tz. The only way this can happen is when p = p1, P2. But then there is no conversion.  Reductions 1.6.4(4) are taken when the mixed term discriminator p of a case term denotes a union value. Since the case term is well-typed, p must be of an union type 1.6.23(1). But the mixed numerals of this type are of the form either j » OF dy» p; and so the reduction takes place without conversion.  If a mixed definition of f is typed as f :: 01,...,@nteo then its application f(p1,---;Pn) to mixed numerals s.t. p1 : 01, ..., P1 2 01 is typed as p and the application reduces to a mixed numeral without conversions.  1.6.30 Compilation of well-typed mixed definitions. If a mixed def- inition of a function f is non-polymorphically typed, i.e. typed as f :: 01,---,0nt-o without variables in the type terms o, oj, ..., On, then the types are Pascal-like. Since all applications of auxiliary functions needed by the definition of f must go through inference rules in Par. 1.6.25, also the types of the auxiliary functions are Pascal-like. There is no conversion in the computation of any well-typed application of f and so the definition of f and of its auxiliary functions can be compiled into machine code (or C) with the  61 

standard Pascal-like representation of all types used. True, the auxiliary func- tions can be polymorphically typed and applied with different instantiations but there is only a finite number of such. Thus the auxiliary functions can be compiled in multiple copies with different Pascal-like types. An objection that this is be memory consuming is not a serious one because the machine (or C) code is compact, memories of modern computers are large, and the additional storage is nothing compared with the storage needed by pictures, music, or video. 

1\.7 Intensional Functionals 

It is often said that LISP is a programming language based on the lamb- da calculus of functionals, i.e. functions operating on functions. It seems to us quite surprising that this characterization was not seriously questioned before because the domain of LISP are S-expressions. and so there can be no extensional functionals in LISP. Functionals of LISP are only coded into S-expressions in the form of intensional functionals. This is done by a univer- sal partial function Apply. Since S-expressions can be embedded into natural numbers by the pairing function, it suffices for us to analyze the situation in the domain N. 

We hasten to state here that although intensional functionals have been studied in logic, for instance by Tait \[?\], the author does not know of an analysis similar to ours done on such a large scale. We mean here that we analyze a real typing system, which is moreover a polymorphic one, and definitions of functions expressed in a real programming language such as the extensible language of clausal definitions. The analysis by Tait was of a simple type system whose types have been generated from N by s 7→t, and of a simple language of primitive recursive functionals of Gödel. Moreover, our proposal for the introduction of functionals into a programming language leads to a very useful extension of mixed definitions. The proposed language is very simple to understand and use. 

1\.7.1 Universal function. To every Σ1-definition of a unary partial func- tion f we can assign its code c. The reader will note that such an f does not have a Π1-definition unless it is total, i.e. recursive. We can then find a Σ1-definition (but not a Π1) of a binary partial universal function U(c, x). The universal function is such that U(c, x) ' f(x) holds for all x. This should be read as that either both U(c, x) and f(x) are defined and the results are identical, or neither is defined. 

The assignment of codes can be extended to n-ary partial Σ1-definable functions f to which we assign the same codes c as to their unary contractions 〈f〉. We then have 

f(x1, . . . , xn) ' 〈f〉(x1, . . . , xn) ' U(c, x1, . . . , xn) . 

62

The universal function U has a code because its contraction (U) is 2- definable. Applications U(c, x) are in the Computability theory usually writ- ten as {c}(x). Functional programming languages would use the notation c(z) or even cx. We will write cex in order to make visible that the application operator is a binary function over N. The operator associates to the left and we let cexey to stand for (cex)ey.  We work in PA with total functions only and so we can introduce the universal function e into PA as the A -definable completion of the partial function. Any definition of a partial function f with an argument c passed in the body of f to the first argument of e can be viewed as an intensional functional where the argument c is the code of a function rather than a function directly. Intensional functionals are thus A2-definable as completed partial functions.  We are interested in a characterization of decidable constraints on argu- ments under which the intensional functionals can be computed. Decidable constraints will allow us to turn the Ao9-definition of e into a A ;-definition of its restriction e.  One of the possibilities for the constraints on arguments is to use a syn- tactic scheme of stratification of arguments in order to prevent the self- application cec of which we cannot decide in general whether its computation terminates or not.  1.7.2 Hereditarily recursive operations. The simplest stratification of arguments of functionals is by function types s-\>t which are called in logic finite types. The ground type is N and when the types s and t have been defined then we can define the type s+-+t by explicit definition:  c: sheet ao Va(a:s \> dy(cex \~yAy:t)).  The function type st thus holds of all intensional functionals c which are defined and yield functionals of type t if applied to functionals of type s. Such functionals are known as hereditarily recursive operations \[6, 23\]. This is a perfectly feasible approach except that it does not integrate well-with our data types. The reason is that the function types are of increasing quantifier complexity. While the predicate c : Nr-N can be defined by a I/2-definition, the definition of c: (NV\>N) NON requires a \[73-formula and the definition of c: ((NGN)GNGN)(NGN)GNEN  a II4-formula etc. The increasing quantifier complexity of function types means that we cannot introduce into PA the predicate x : t with t admitting besides data types also the function types.  In order to stay within PA we substantially weaken the function types where we intuitively let c : s++t to hold iff c codes a mixed definition of a unary function f s.t. f :: st is derivable in the typing calculus. This is discussed in more detail below.  63 

1\.7.3 Bland intensional functionals. We will investigate first a rather limited class of intensional functionals which we call bland as opposed to a substantially larger class of curried functionals which will be introduced in Par. 1.7.13.  The idea of bland functionals is simple enough. Suppose for a moment that we have managed to introduce into PA the application operator e and that we have suitably extended the definition of the universal typing predicate x :: t (see Par. 1.6.13) to function types t = s;+\>s9 by treating the symbol + as a new constructor function: st = 8,s,t. PA will prove  LisetAy:s—\>xey:t. (1)  In order to be able to derive this also in the typing calculus we extend it with the axiom:  “0-3: (stot), stot 2)  We also extend the narrow mixed definitions by allowing in them appli- cations of the operator e and call them bland definitions. Suppose now that we have introduced into PA by a bland definition an n-ary function symbol f. Suppose further that the definition is well-typed and that we have derived in the (extended) typing calculus f :: 1,...,8 tot. The function f will have assigned a code ’f such that PA will prove:  'f 2 81X...XS8prt (3)  @1281A...AN an 2 $n \> fe(xy,...,2n) = f(@1,.--,2%n) - (4)  Whenever, the index property (4) holds we say that the function f has an index ' f. We will see below that in the case of bland functionals the sufficient condition for f to have an index is that we have a well-typed bland definition of f.  The typing property (3) is derivable in PA but not in the typing calculus. For that we add to the typing calculus new axioms:  (5)  A, f 1 81,...,8nt0t \>/f 2spX...X8,ret”  1.7.4 Computation of bland definitions. We compute bland functionals by adding to the mixed numerals as new irreducible terms also the codes 'f of bland functionals f with indices. We call this extended class the bland numerals. Note that unlike the mixed numerals, the class of bland numerals is defined relatively to the current extension of PA. The new reductions are  ‘fe() » f(A) (1)  where f are bland numerals and f(/) is well-typed.  64 

It can be shown that the reductions of all well-typed terms terminate with bland terminals. Note that while terms typed by function types are obtained from the indices of bland functionals by the operator e, the only irreducible numerals of function types are the codes’ f of functions with bland definitions.  1.7.5 Example: The bland functional Map. The canonical example of use of functionals is in the functional programming the binary functional Map which can be defined by  Map(f,0) =0 Map(f,v,w) = fev, Map(f,w) .  The function is polymorphically typable as fs sot, List(s) List(t)  is function can be polymorphically typed as and so it has an index 'Map such that ‘Map : (stot) x List(s) List(t) and PA proves:  f:srtAax: List(s) +'Mape(f,x) = Map(f,2) . (1) UNFINISHED Example of use  1.7.6 Comment on the introduction of bland functionals. The reader will probably agree with us that the idea and use of (bland) intensional functionals is simple. The description of their computation is straightforward because it takes just one additional easy to understand type of reduction 1.7.4(1). This should be contrasted with the following outline of the hard work needed to introduce the function types and the application operator into PA and to prove the indexing properties 1.7.3(4). The hard work involves the arithmetization of both the typing calculus and of the computation process. The later is needed for the definition of the application operator e. We stress here that the difficult introduction of e and its inefficient definition has to do only with the semantics of proving that the reduction 1.7.4(1) preserves meaning, i.e. that PA proves 'fe(p) = f(p). The simplicity and the efficiency of computation with bland functionals is not affected by this.  1.7.7 Arithmetization of generalized terms. We now arithmetize the  generalized terms as used in bland definitions. UNFINISHED  1.7.8 Arithmetization of the typing calculus. UNFINISHED 1.7.9 Type levels. An important measure of complexity of a recursive typed definition is its type level which counts the complexity of its func-  tion types. We introduce into PA the unary function lev(t) yielding the type level of the (code of the) type ¢ to satisfy the following:  65 

lev(N) = lev rec(a, b,c) = lev par(i) = 0 lev vect(t) = lev(t) leu(sxt) = leu(sx\*t) = max(lev(s), TL/(t)) lev(tapply(c, p) = lev sb(c,0, N, p) leu(Un(m, s) = max leu(t)  leu(st\>t) = max(lev(s 4 1, lev(t)) .  Type level of a value x s.t. x : t is lev(x). Note that the type level of a function definition with index 'f : st is thus lev(s-\>t) \> 0. Values with type level 0 are therefore the data structures typed by types not contain- ing any function types. We for instance, have lev List Vect(NxN) = 0 and leu List Vect(N x(st-t)) = lev(stet) \> 0. Functions over data structures with type level 0 are of type level 1 and functions taking such functions as argu- ments are at least of type level 2.  Ct(ai,c, x, z\[i\],0)  Ct(z,c, x, 0)  Ct(So(a ); c, x, v0, (a,c, 2, v), 0)  Ct(Si(a),c, x, v1, (a,c, x, v), 0)  Ct(P(a, b), C,@, (v, w), (a, C, 2, v), (a, C,@, v), 0) Cilsgm(a),c,,0,(a,¢,2, 0+ 1),0)  Ct(sgn(a),c, x, 1, (a,c, x, 0), 0)  Ct(b(a), c, x, (0, v), (a, c, x, vO), 0)  Ct(b(a),c, x, (1, v), (a,c, 2,01), 0)  Ct(e(a),c, ©, (0,0, 6), (a, 6,0, (v,w)),0)  Ct(cs(a,m,t),c, x, w, (a,c, 2, v), (tos c,£,w),0)-—v\<m Ct(cs(a,m,t),c, x, w, (a,c, x, Vv), ((t);,¢, (a, y),w),0) —v \>mAv=j,y Ct(cd(a,n,m e), C2, ed(a, n,m, e),0)  Ct(aeb, c, x, z, (a,c, x, v), (b,c, 2 wy, d,v,w,z),0) — v = cd(d,n,m,e) Ct(rec(a), C,0,W, (a, c,£, 0), (d, m, v,Y1); (d, Mm, \&, y2); (0, c,U,W ,0) —\_  c= cd(b,n,m,e) Am = cd(d,n1,m1,€1) A yi \< ye Ct(rec(a),c,x,w, (a,c, 2,0), (d, m,v;Y1); (d, m, x, Y2), (e, ed(e, n, 0, 0), v, w), 0) —\_ c= cd(b,n,m,e) \\m = cd(d,n1,m1,€1) A yi \> Ye .  Fig. 1.11. Computation trees for bland functionals  1.7.10 Definition of the application operator.  1.7.11 Ackerman. UNFINISHED  F(f,0) = FQ) F(f,m+1) = feF(f,m)  typed as F’ :: (N++N), NN and so it has an index ’F typed as 'F (NieN)x NHN. We would like to define a function  66 

A(0) ='S A(n +1) = Am.'Fe(A(n),m) .  Then Ack(n,m) = A(n)em.  1.7.12 Function types. Suppose that f is an n-ary function with a defi- nition which can be typed as  t1X...Xtpres (1)  and c is the code of this definition. Although f can be a A2-definable function because it can apply directly or indirectly the universal function e, it can be  computed for arguments of correct types and we have in the standard model of PA:  apityA...Aa, ity \> {c}(a1,...,¢n) = f(ai,...,2n) . (2)  We say that the function f has an index c. We will designate the index c by ‘f. If (2) can be proved in a fragment T of PA, we say that f has a T-provable index. The index c of the function f can be now used as an intensional functional of type (1).  1.7.13 Curried intensional functionals. UNFINISHED For curried functionals:  Ct(aeb, c, x, vew, (a,c, x, v), (b,c, x, w),0) — Red(1,v,w) =0  Red(1,v,w) = d,y Ad = cd(f,n,m,e)  Red (i, cd(a,n,m,e),y) = cd(a,n,m,e),yon=i  Red(i, cd(a,n,m,e),y) =O—n\>i  Red(i, aeb, y) = Red(i+1,a,b,y) .  UNFINISHED Computation trees, this is real language rather than for a minimal scheme.  UNFINISHED The idea is that n-ary functions are assigned function types t) x... Xt,tes. If a function f is of the latter type then we have:  arty A...anity \> f(a1,...,an) 28 Note that this is to be the same as  The universal function U is assigned the polymorphic function type (stot) x stot and we would like to have  ersrotAr:t— {c}(x):t.  In order to stay within PA we substantially weaken the typing predicate and we let c: tres hold iff c codes a syntactically well-typed definition of a unary function f taking values of type t to values of type s.  67 

1\.7.14 Currying. Instead of letting the binary application symbol • to s- tand for the universal function U , as was the case in the scheme of intensional functionals discussed in Par. 1.7.12, we can assign the codes to typed defini- tions in a more refined way and obtain more powerful intensional functionals. If an n-ary function symbol f has a definition typed as 

t1× . . .×tn 7→s 

we can treat its code c as typed in the curried form: 

c :: t1 7→ . . . 7→tn 7→s . 

This is done by defining the application symbol • as 

c•x = 

   

c1 c codes f(y1, y2 . . . , yn) ' τ \[f ; y1, y2 . . . , yn\], n \> 1, and c1 codes g(y2, . . . , yn) ' τ \[g;x, y2, . . . , yn\] 

U(c, x) otherwise. 

The standard model of PA thus satisfies 

x1 :: t1 ∧ . . . ∧ x1 :: tn → c•x1• . . . •xn = f(x1, . . . , xn) 

and we call c the (currried) index of f . In the next two paragraph we will show that curried intensional function- 

als are much more powerful than the ones from Par. 1.7.12 which we might call bland functionals. 

1\.7.15 Fast growing intensional functionals. UNFINISHED The ternary iteration intensional functional I(n, a, b) of polymorphic type N×(t7→t)×t 7→t, which we abbreviate to a(n)(b), is defined by primitive recursion: 

a(0)(b) = b 

a(n+1)(b) = a•(a(n)(b)) . 

An infinite sequence of types T k is defined as: 

T 0 = N T k+1 = T k 7→T k . 

An infinite sequence of (k + 1)-ary intensional functionals Kk+1 0 of type 

T k×T k−1× . . .×T 1×T 0 7→T 0 

is explicitly defined by: 

68

Kj(n) = Ko(a, 2) = aye(nt) K§(a2,a1,n) = an (a)e1 Ke (ap43,0b42;0b415 + 4) G1, N) = at (ap p2)eany1® .eajen .  The definitions are well-typed and the functionals have indices ‘K}\*! such  that ap: T’A...a,:T! \> ‘Ket eae... eajen = Ket" (ap, 1. +;Q1,7)  is satisfied in the standard model. Unfortunately, this can be proved in PA only for numerals:  . 7k .7l ryck+1 \_ aekt+l Gk, #T™ N...d1,, To Kg edn, © +801, 02m = KO (Ako +++ 1 yy 12m) -  We can define a binary meta-theoretical function K k+l (q) yielding terms of PA such that:  Ket! (0) =/Kett K\* (atw?) = K\*\*? (byek\*t1(a) ; The fast growing function V from Par. 1.5.4, although Aj-definable, can be  introduced into PA only as a completed partial function by a A\> definition and PA proves:  V(a,,) = Of w°-(K'(a)e0) . (1)  This follows by the meta-theoretical \<-induction from the following theorems of PA: K'(atw®-njem = K\*(a)e(m+n) KE (atwt eK (ays )e...eK'(a,)en = KR? ((atw?t\*)\[nj)eK\*t (ansz)e...eK!(a,)en We can also introduce into PA a binary function K\*\*!(a) by course of values recursion in a: K\*k+1(0) \_ ‘KR K\*\*1(atw?) = KP+?(b)ek\*\*1(a)  The function K\*+!(qa) yields the code of a functional of type T+! such that if K\*\*?(b) yields the code c and K\*\*+!(a) the code d, the application ced yields the code of ced. The definition of K\*\*!(a) is not well-typed although PA proves  69 

anm :: T k → Kk+1(am)•anm 

= Kk+1(a)•anm . 

From this and from (1) we can see that standard model of PA satisfies: 

V (a) = 0 \] ω0·(K1(a)•0) 

but this is unprovable in PA because, otherwise we could introduce the func- tion V into PA. 

UNFINISHED codes of functionals are clausal definitions with mea- sures and •. 

UNFINISHED what is U UNFINISHED well-typed codes. We wish a programming comfort not the largest possible class of provably 

recursive functions. Primitive recursive functions are by far more that can be feasibly computed. Thus we wish indices but not for all functions. 

We have seen in the previous paragraph that curried intensional func- tionals very soon reach the limits of provability in PA and so they cannot be worked comfortably with. The situation is actually even worse Map 

Example: Strengthening by V makes the typing possible, although provably recur- 

sive are much more but they do not have provable indices. It is possible to strengthen PA, basically by asserting that well-typed 

definitions of functionals have indices but the question is whether it is worth it? Although the proponents of functional programming in the style of Haskell will not agree with us, we think that the full power of curried intensional functionals is not needed and the bland functionals introduced in Par. 1.7.12 are sufficient for the the needs of programming. 

What does the currying gives us. Similar argument for Ack as above for V . What does the currying gives us. So this is a C-style programming Characterization. Ackermann is definable but does not have an index. 

1\.7.16 Infinite lists. UNFINISHED Functional languages as Haskell can operationally deal with infinite lists by the device of lazy evaluation. Infinite lists must be denotationally added to the domain of Haskell. Our schema of intensional functionals has significant advantage of semantic simplicity over functional languages and we can deal with infinite sequences (even with eager evaluation) in a mathematically clean way. Infinite sequences can be coded by indices p of their enumerating functions where p7→n denotes the n-th element of the sequence. 

Infinite lists of natural numbers are thus of type N 7→N . We present the standard example of infinite lists where the primitive recursive function pn 

yielding the n-th prime is defined by detour through three intensional func- tionals whose indices are typed as follows: 

70

‘TL: (NGN) NON ‘Mults : N-(NGN)ONGN (2..): NON.  The binary function Sv is typed as (N-ON)xNON and the unary function Dn as N/ON. The functionals and functions are defined as:  TI(s,n) = se(n+1)  Mults(k,s,n) = Mults(k, Tl(s),n) — se0=hAk\|h  Mults(k,s,0) =h— seQ=hAkth  als (k,s,n +1) = Mults(k, Ti(s),n) — se0O=hAkth Su(s,0) =h— seQ=h  Su(s,n+1) = Sv(/ Multsehe(Tles),n) — se0 =h  a n)=n+2  Su(’\[2..\], 7) .  tithe s) transforms an infinite list s into another infinite list by deleting all  elements of s divisible by k. Su(s,n) implements the sieve of Erasthothenes by  yielding the n-th element of the infinite list obtained from s by the process of  sieving s. Although Sv is a total function, it can transform a total infinite list  into a partial one if s does not contain infinitely many primes. The infinite  sequence 2,3,4,... with an index ’\[2..\] has infinitely many primes and so  ‘Sve’\[2..\] yields an index of the infinite sequence of all primes.  The definition of the elementary function p, by a detour through level two partial functionals may be illustrating the power of functional languages but it is hardly the right way of defining the function. The proof that the function does what it should is difficult because one has to deal with partial functions.  1.8 Second-Order Issues of Modularity  Conservative Second-Order Calculus of Extensions  1.8.1 Tree of extensions. UNFINISHED UNFINISHED existential instantiation of functions by proofs as a gen- eralization of extraction of programs.  Abstract Data Types  1.8.2 Abstraction Types. UNFINISHED  71 

1\.8.3 Representants. UNFINISHED Let ∼ be an equivalence over T : 

x ∼ y → T (x) ∧ T (y) T (x) → x ∼ x 

x ∼ y → y ∼ x 

x ∼ y ∧ y ∼ z → x ∼ z . 

We define a predicate provably recursive in ∼: 

Isr(x) ↔ ∀y(y ∼ x → y ≥ x) 

and a function provably recursive in ∼: 

r(0) = 0 r(x + 1) = y + 1 ← Isr(x + 1) ∧ r(x) = y ∧ Isr(y) r(x + 1) = y ← Isr(x + 1) ∧ r(x) = y ∧ ¬Isr(y) r(x + 1) = r(x) ← ¬Isr(x + 1) . 

If T is infinite, i.e. if ∃y(y ≥ x ∧ T (y)) 

then 

x ∼ y → r(x) = r(y) T (x) ∧ T (y) ∧ r(x) = r(y) → x ∼ y 

∃y(x = r(y) ∧ T (y)) . 

1\.8.4 Finite Sequences. Sequences and three specializations: lists, arrays, queues, first typeless, then typed. 

1\.8.5 Finite Sets. Language: ∅ empty set, s∪{a} insert into set, ch choice function, \|s\|s size of the set, Set predicate of being a set. SET is abbreviation for the formulas of the following groups: 

Properties of ch, ∅, and Set : 

ch(∅) = 0 . 

Clausal property of set size (there is no measure which goes down): 

\|s\|s = 0 ← ch(s) = 0 \|s\|s = \|t\|s + 1 ← ch(s) = x, t . 

Clausal definition of predicate x : Set (\|s\|s is the measure): 

∅ : Set s : Set ← ch(s) = y, t ∧ t : Set . 

Clausal definition of set membership (\|s\|s is the measure): 

72

x ∈ s ← ch(s) = y, t ∧ (x = y ∨ x ∈ t) . 

Extensionality: 

s : Set ∧ t : Set → (s = t ↔ ∀x(x ∈ s ↔ x ∈ t)) . 

Properties of insert: 

s : Set → s ∪ {x} : Set s ∪ {x} : Set → (y ∈ s ∪ {x} ↔ y = x ∨ y ∈ s) . 

1\.8.6 Typing of sets. Every implementation of SET can be typed for every type T by defining: 

s : Set(T ) ↔ s : Set ∧ ∀x(x ∈ s → x : T ) . 

We can then prove the typing properties: 

∅ : Set(T ) s : Set(T ) ∧ ch(s) = x, t → x : T ∧ t : Set(T ) 

x : T ∧ s : Set(T ) → s ∪ {x} : Set(T ) . 

1\.8.7 Finite Sets II. Language: ∅ empty set, s ∪ {a} insert into set, ch choice function, Axioms: Properties of ch: 

ch(∅) = 0 ch(s) = x, t → t \< s . 

Clausal definition of set membership 

x ∈ s ← ch(s) = y, t ∧ (x = y ∨ x ∈ t) . 

Extensionality: 

s = t ↔ ∀x(x ∈ s ↔ x ∈ t) . 

Basic property of insert: 

y ∈ s ∪ {x} ↔ y = x ∨ y ∈ s . 

UNFINISHED three implementations, bitmap, ordered list, binary search tree, Note that membership can be faster than through choice. 

1\.8.8 Abstract binary trees. Language: ∅, Nd(n, s, t). Axioms: 

x = ∅ ∨ ∃n∃s∃t x = Nd(n, s, t) (1) ∅ 6= Nd(n, s, t) (2) 

Nd(n1, s1, t1) = Nd(n2, s2, t2) → n1 = n2 ∧ s1 = s2 ∧ t1 = t2 (3) s \< Nd(n, s, t) ∧ t \< Nd(n, s, t) . (4) 

73

1\.9 Issues Open to Further Research 

In-place Modification 

UNFINISHED The analysis is intensional, but it can be extensionalized with dag type. 

Dag = V (N) \| P (N) \| (Dag ,Dag) \| Dag whList(N,Dag) . 

Functions are then rewriten to take and yield: w wh b. 

Optimization by Computer-Aided Transformations 

Some ten years ago there was a considerable research into the techniques of computer-assisted program transformations in order to optime programs. This was before the semantics of programming languages was sufficiently sim- plified so the languages could be designed together with formal proof systems. The following problem shows how a rather deep knowledge of properties of underlying data structures is required before programs can be transformed in computer assisted way. 

1\.9.1 Breadth-first Numbering. We present a so called functional pro- gramming pearl posed by John Launchberry and discussed by Chris Okasaki in \[16\]: 

Given a tree, create a new tree of the same shape, but with the values at the nodes replaced by the numbers 1, 2,. . . in breadth-first order. 

Okasaki’s solution in the programming language ML can be formulated for our binary trees (see Par. 1.3.19) by designing an auxiliary function B(n, a) = b taking a number n and a forest a of type List Bt(t) into the forest b of type List Bt(N), such that L(a) = L(b), the trees of b are of the same shape as the corresponding trees in a, and the entire forest is numbered starting with n in a breadth-first order. For instance, if a is the forest: 

a 

b c 

d b 

c d c 

Then b = B(1, a) should be the forest: 

1 5 

8 6 

2 7 

3 4 

The function B looks at its second argument as a queue and yields and works with the output forest as a backward queue to which one adds in the front and removes from the end: 

74

B(n, 0) = 0 B(n, \[E\]⊕ a) = \[E\]⊕B(n, a) B(n, \[Nd(x, t, s)\]⊕ a) = \[Nd(n, t1, s1)\]⊕ a1 ← 

B(n + 1, a⊕ \[t\]⊕ \[s\]) = a1 ⊕ \[t1\]⊕ \[s1\] . 

In the third clause of B, the subtrees t and s are placed at the end of the argument queue and after the recursive application B(n + 1, a⊕ \[t\]⊕ \[s\]) = b they will be correctly numbered as t1 and s1 respectively in the output forest b which is destructed from the end as b = a1 ⊕ \[t1\] ⊕ \[s1\]. The forest a1 is now correctly numbered to follow the tree Nd(n, t1, s1) in the forest yielded by B(n, \[Nd(x, t, s)\]⊕ a). 

The clausal definition of B(n, a) is regular in the measure ∑ 

sεa 2·\|t\|t + 1 where \|s\|t is the size of the tree s clausally defined as: 

\|E\|t = 0 \|Nd(x, s1, s2)\|t = \|s1\|t + \|s2\|t + 1 . 

This is because UNFINISHED The function Bf (t) breadth-first numbering the tree t is now explicitly 

defined as: 

Bf (t) = t1 ← B(1, \[t\]) = \[t1\] 

because the breadth-first numbering of t is the same as the breadth-first numbering of the single element forest \[t\]. 

1\.9.2 Turning the backwards queue into a normal one. Okasaki notes that the output backwards queue yielded by B can be turned into an ordinary queue in a function B1(n, a) yielding the same forest as B(n, a) but in the reversed order. We can view the problem of designing the function B1 as a program transformation problem where we are looking for a recursive clausal definition of the function B1 given its explicit ‘definition’ 

B1(n, a) = RevB(n, a) (1) 

which should be viewed as the desired property of B1 rather than as a defi- nition. The clausal definition of B1 can be semi-mechanically obtained from the clasuses for B when we note that we have a = b ↔ Rev(a) = Rev(b). We accordingly modify the clauses of B to obtain: 

Rev B(n, 0) = Rev(0) Rev B(n, \[E\]⊕ a) = Rev(E ⊕B(n, a)) Rev B(n, \[Nd(x, t, s)\]⊕ a) = Rev(\[Nd(n, t1, s1)\]⊕ a1) ← 

Rev B(n + 1, a⊕ \[t\]⊕ \[s\]) = Rev(a1 ⊕ \[t1\]⊕ \[s1\]) . 

We now use the obvious properties 

Rev(0) = 0 (2) Rev(\[a\]) = \[a\] (3) 

Rev(a⊕ b) = Rev(b) + Rev(a) (4) 

75

of the list reversal function Rev and obtain: 

Rev B(n, 0) = 0 Rev B(n, \[E\]⊕ a) = Rev B(n, a)⊕ \[E\] Rev B(n, \[Nd(x, t, s)\]⊕ a) = Rev(a1)⊕ \[Nd(n, t1, s1)\] ← 

Rev B(n + 1, a⊕ \[t\]⊕ \[s\]) = \[s1\]⊕ \[t1\]⊕ Rev(a1) . 

As the final step, we replace the auxiliary result Rev(a1) by a1 and use the property (1) to get the desired clausal definition of the function B1: 

B1(n, 0) = 0 B1(n, \[E\]⊕ a) = B1(n, a)⊕ \[E\] B1(n, \[Nd(x, t, s)\]⊕ a) = a1 ⊕ \[Nd(n, t1, s1)\] ← 

B1(n + 1, a⊕ \[t\]⊕ \[s\]) = \[s1\]⊕ \[t1\]⊕ a1 . 

Both input and output queues are now standard where we add at the end and remove from the front. The new breadth-first numbering function Bf 1 

has an explicit definition: 

Bf 1(t) = t1 ← B1(1, \[t\]) = \[t1\] . 

1\.9.3 Speeding up the en-queuing. We note that our function B1(t) op- erates in time O(\|t\|2s) because of the naive implementation of the en-queuing operation q ⊕ \[x\] by concatenation. Okasaki improves this naive solution by using a fast implementation of the ADT queue. One such implementation represents a queue q = a ⊕ Rev(b) as a pair of lists (a, b). The en-queuing and de-queing functions have the following definitions: 

Enq(x, (a, b)) = a, x, b Deq(0, 0) = 0 Deq(0, b) = x, a, 0 ← b \> 0 ∧ Rev(b) = \[x\]⊕ a Deq((x, a), b) = x, a, b . 

The reader will note that the de-queuing function yields a pair consisting of the removed element and the new shortened queue provided that the queue is not empty. For empty queues the function yields 0. 

Instead of modifying B1 for the ADT queue, we transform it into a ternary function B2(n, a, b) where (a, b) represents the input queue a ⊕ Rev(b) and B2 yields the pair (b1, a1) representing the output queue b1 ⊕ Rev(a1). In other words, we are looking for a recursive clausal definition of the function B2 satisfying: 

B2(n, a, b) = b1, a1 ↔ B1(n, a⊕ Rev(b)) = b1 ⊕ Rev(a1) ∧ L(a) = L(a1) . (1) 

Towards that end we rewrite the clauses of B1 in an equivalent homogeneous form: 

76

B1(n, a) = 0 ← a = 0 B1(n, a) = b⊕ \[E\] ← a = \[E\]⊕ a1 ∧B1(n, a1) = b B1(n, a) = a2 ⊕ \[Nd(n, t1, s1)\] ← a = \[Nd(x, t, s)\]⊕ a1 ∧ 

B1(n + 1, a1 ⊕ \[t\]⊕ \[s\]) = \[s1\]⊕ \[t1\]⊕ a2 . 

Substituting a0 ⊕ Rev for a yields: 

B1(n, a0 ⊕ Rev(b)) = 0 ← a0 ⊕ Rev(b) = 0 (2) B1(n, a0 ⊕ Rev(b)) = c⊕ \[E\] ← a0 ⊕ Rev(b) = \[E\]⊕ a1 ∧B1(n, a1) = c (3) B1(n, a0 ⊕ Rev(b)) = a2 ⊕ \[Nd(n, t1, s1)\] ← a0 ⊕ Rev(b) = \[Nd(x, t, s)\]⊕ a1 ∧ 

B1(n + 1, a1 ⊕ \[t\]⊕ \[s\]) = \[s1\]⊕ \[t1\]⊕ a2 . (4) 

Clause (2) can be equivalently written as 

B1(n, 0⊕ Rev(0)) = 0⊕ Rev(0) 

and then by property (1) as 

B2(n, 0, 0) = 0, 0 . (5) 

We will now transform the clause (4) under the assumption that a0 \> 0, i.e. a0 = \[x\]⊕ a for some x and a. We then have 

a0 ⊕ Rev(b) = \[Nd(x, t, s)\]⊕ a1 ↔ x = Nd(x, t, s) ∧ a⊕ Rev(b) = a1 

and so we can simplify the clause (4) to 

B1(n, (\[Nd(x, t, s)\]⊕ a)⊕ Rev(b)) = a2 ⊕ \[Nd(n, t1, s1)\] ← B1(n + 1, a⊕ Rev(b)⊕ \[t\]⊕ \[s\]) = \[s1\]⊕ \[t1\]⊕ a2 . 

Since a⊕ Rev(b)⊕ \[t\]⊕ \[s\] = a⊕ Rev(\[s\]⊕ \[t\]⊕ b) , 

we further get 

B1(n, (\[Nd(x, t, s)\]⊕ a)⊕ Rev(b)) = a2 ⊕ \[Nd(n, t1, s1)\] ← B1(n + 1, a⊕ Rev(\[s\]⊕ \[t\]⊕ b)) = \[s1\]⊕ \[t1\]⊕ a2 . 

We always have a2 = b1 ⊕ Rev(a1) for some b1 and a1 and, since 

L(a2)+2 = LB1(n+1, a⊕Rev(\[s\]⊕\[t\]⊕b)) = L(a⊕Rev(\[s\]⊕\[t\]⊕b)) = L(a)+L(b)+2 , 

we can also assume that L(a1) = L(a) (and L(b1) = L(b)). The last clause can be then written as 

B1(n, (\[Nd(x, t, s)\]⊕ a)⊕ Rev(b)) = (b1 ⊕ Rev(a1))⊕ \[Nd(n, t1, s1)\] ← B1(n + 1, a⊕ Rev(\[s\]⊕ \[t\]⊕ b)) = \[s1\]⊕ \[t1\]⊕ (b1 ⊕ Rev(a1)) ∧ L(a) = L(a1) 

which simplifies to: 

B1(n, (\[Nd(x, t, s)\]⊕ a)⊕ Rev(b)) = b1 ⊕ Rev(\[Nd(n, t1, s1)\]⊕ a1) ← B1(n + 1, a⊕ Rev(\[s\]⊕ \[t\]⊕ b)) = (\[s1\]⊕ \[t1\]⊕ b1)⊕ Rev(a1) ∧ L(a) = L(a1) . 

Using the property (1) we get from this a clause for B2: 

77

B2(n, \[Nd(x, t, s)\]⊕ a, b) = b1, \[Nd(n, t1, s1)\]⊕ a1 ← B2(n + 1, a, \[s\]⊕ \[t\]⊕ b) = \[s1\]⊕ \[t1\]⊕ b1, a1 . (6) 

By similar transformations we obtain under the assumption a0 \> 0 from the clause (3) the clause 

B2(n, \[E\]⊕ a, b) = b1, \[E\]⊕ a1 ← B2(n, a, b) = b1, a1 . (7) 

We now transform the clauses (3) and (4) under the assumption that a0 = 0. The clauses simplify to: 

B1(n, 0⊕ Rev(b)) = c⊕ \[E\] ← Rev(b) = \[E\]⊕ a1 ∧B1(n, a1) = c B1(n, 0⊕ Rev(b)) = a2 ⊕ \[Nd(n, t1, s1)\] ← Rev(b) = \[Nd(x, t, s)\]⊕ a1 ∧ 

B1(n + 1, a1 ⊕ \[t\]⊕ \[s\]) = \[s1\]⊕ \[t1\]⊕ a2 . 

Both clauses have in their antecedents Rev(b) 6= 0 from which we get b 6= 0 and we can collapse both clauses into one ‘trivial’ clause: 

B1(n, 0⊕ Rev(b)) = c ← b 6= 0 ∧B1(n,Rev(b)) = c . 

We substitute c := Rev(b1) to get: 

B1(n, 0⊕ Rev(b)) = Rev(b1) ← b 6= 0 ∧B1(n,Rev(b)) = Rev(b1) . 

We have 

L(b) = LRev(b) = LB1(n,Rev(b)) = LRev(b1) = L(b1) 

and so we can equivalently write the clause as: 

B1(n, 0⊕ Rev(b)) = Rev(b1)⊕ Rev(0) ← b 6= 0 ∧ B1(n,Rev(b)⊕ Rev(0)) = 0⊕ Rev(b1) ∧ LRev(b) = LRev(b1) . 

Using the property (1) we get from this a clause for B2: 

B2(n, 0, b) = Rev(b1), 0 ← b 6= 0 ∧B2(n,Rev(b), 0) = 0, b1 . (8) 

The clauses (5), (8), (7), and (6) constitute a clausal definition for the function B2 which we write with the list notation x, y instead of the identical sequence notation \[x\]⊕ y as follows: 

B2(n, 0, 0) = 0, 0 B2(n, 0, b) = Rev(b1), 0 ← b 6= 0 ∧B1(n,Rev(b), 0) = 0, b1 

B2(n, (E, a), b) = b1, E, a1 ← B2(n, a, b) = b1, a1 

B2(n, (Nd(x, t, s), a), b) = b1,Nd(n, t1, s1), a1 ← B2(n + 1, a, s, t, b) = (s1, t1, b1), a1 . 

It remains to explicitly define the function Bf 2 numbering one tree as 

Bf 2(t) = t1 ← B2(1, (t, 0), 0) = (t1, b), a . 

The function Bf 2(s) performs in time O(\|s\|t) because the second clause for B2 is taken once for each level of the tree s with the corresponding forest of children of t as b. This means that the function Rev performs total 2·\|s\|t applications and the maximal length. 

is probably one the fastest functional algorithms for the breadth 3 times through. 

78

Concurrency 

79

80 

Part I 

First-Order Logic and Peano Arithmetic 

81

2\. First-Order Languages 

2\.1 Language of First-Order Logic 

2\.1.1 First order languages. A first-order language L is given by at most countable sets of function symbols and predicate symols. Every function and predicate symbol has arity n ≥ 0 which is the number of arguments the sym- bol expects. We require that there are effective procedures to decide whether p is an n-ary function or predicate symbol of L. 

Expressions in L will be terms and formulas and they will be finite se- quences of symbols. Expressions will be metamathematical objects in contrast to mathemathical objects such as natural numbers, real numbers, topological spaces, etc. The expressions of L will have have no meaning by themselves. They will be defined in such a way that it will be effectively decidable whether an expression is correctly formed. 

We write τ1 ≡ τ2 to mean that the expressions τ1 and τ2 are identical sequences of symbols. 

In these notes we will deal exclusively with first order languages logic so from now on we will use the term language to denote a first order language. 

2\.1.2 Definition of terms of L. The set of terms of a language L is the smallest set of finite sequences of symbols satisfying: 

1\. variables v0, v1, v2, . . . are terms, 2. if τ1, . . . , τn are terms and f is an n-ary function symbol of L then also 

f(τ1, . . . , τn) is a term called function application. 

Nullary function symbols are constant symbols and their applications f(), which will be abbrevaited to f , are constants. 

We will use possibly subscripted symbols x, y, z as syntactic (meta) vari- ables ranging over variables, symbols f , g as syntactic variables ranging over function symbols, and τ , ρ as syntactic variables ranging over terms. 

Some binary function symbols, such as +, are customarily written in the infix form τ1 + τ2 as an abbreviation for +(τ1, τ2). 

2\.1.3 Definition of formulas of L. The set of formulas of a language L is the smallest set of finite sequences of symbols satisfying:

1\. if τ1 and τ2 are terms of L then τ1 = τ2 is a formula called identity, 2. if τ1, . . . , τn are terms and P is an n-ary predicate symbol of L then 

P (τ1, . . . , τn) is a formula called predicate application, 3. the symbol \>, called the truth symbol, is a formula, 4. the symbol ⊥, called falsehood symbol, is a formula, 5. if φ is a formula so is ¬φ called negation, 6. if φ1 and φ2 are formulas so is (φ1 ∨ φ2), (called disjunction), (φ1 ∧ φ2) 

(called conjunction), (φ1 → φ2) (called implication), and (φ1 ↔ φ2) (called equivalence), 

7\. if φ is a formula and x a variable then so are ∀xφ (called universal quan- tification) and ∃xφ (called existential quantification). 

Formulas formed by the rules (1) and (2) are atomic formulas. Formulas formed by the rules (3) though (6) are propositional formulas. Formulas formed by the rule (7) are quantifier formulas. 

The formula φ1 in the implication (φ1 → φ2) is called antecedent and φ2 consequent. The symbols used in propositional formulas are propositional connectives. Nullary predicate symbols are propositional constants and their applications P (), which will be abbreviated to P , are propositional constants. 

We use the possibly subscripted symbols φ, ψ as syntactic variables rang- ing over formulas. 

In order to increase the readability of formulas we can drop the topmost pair of parentheses around a formula. All binary propositional connectives associate to the right, for instance φ1 → φ2 → φ3 abbreviates φ1 → (φ2 → φ3). Negations and quantification have larger precedence (bind stronger) than conjunctions, which have larger precedence than disjunctions, which have larger precedence than implications and equivalences. We often abbreviate ¬τ1 = τ2 to τ1 6= τ2. 

2\.1.4 Propositional atoms. Atomic and quantified formulas of L are called the propositional atoms of L. The metamathematical function FPA(α) is defined to yield the set of free propositional atoms of α, i.e. propositional atoms of α outside of quantifiers. The function is defined for formulas α ≡ φ and sets of formulas α ≡ T to satisfy the identities given in Fig. 2.1. 

2\.1.5 Extension of languages. The language L1 is an extension of the language L if every function and predicate symbol of L is a symbol of L1. It should be clear that every term or formula of L is a term or formula of L1. Note that every L is an extension of itself. 

2\.1.6 Metamathematical implication and equivalence. In order to shorten the metamathematical discursion in English we will use the sym- bol ⇒ in context · · · ⇒ · · · as abbreviation for if · · · then · · · and the symbol ⇔ in context · · · ⇔ · · · as abbreviation for · · · if and only if · · · . Sometimes we will write the last also as · · · iff · · · . We use the metamathematical sym- 

84

FPA(τ1 = τ2) = {τ1 = τ2} FPA(P (τ1, . . . , τn)) = {P (τ1, . . . , τn)} 

FPA(∀xφ) = {∀xφ} FPA(∃xφ) = {∃xφ} 

FPA(\>) = ∅ FPA(⊥) = ∅ 

FPA(¬φ) = FPA(φ) 

FPA(φ1 ∨ φ2) = FPA(φ1) ∪ FPA(φ2) 

FPA(φ1 ∧ φ2) = FPA(φ1) ∪ FPA(φ2) 

FPA(φ1 → φ2) = FPA(φ1) ∪ FPA(φ2) 

FPA(φ1 ↔ φ2) = FPA(φ1) ∪ FPA(φ2) 

FPA(T ) = ⋃ {FPA(φ) \| φ ∈ T} . 

Fig. 2.1. Function yielding sets of propositional atoms 

bols ⇒ and ⇔ in order to distinguish them from the logical symbols → and ↔ wchich are from the object, i.e. first order, language. 

85

86 

3\. Propositional Logic  3.1 Tautologies  In this section we investigate formulas which are always true only on the strength of their propositional connectives.  3.1.1 Propositional interpretations. A propositional interpretation TZ for £ is a subset of propositional atoms of L. T is finite or infinite if the set TZ is finite or infinite. The intention is that a propositional atom ¢ is true in the propositional interpretation Z iff @ € Z.  We denote by Z? the restriction of I to the free propositional atoms of the set T: I? =IN FPA(T).  3.1.2 Satisfaction relation for propositional interpretations. For a given propositional interpretation Z for £ and a formula @ we define the unary relation 7 satisfies ¢, written as J F ¢, as shown in Fig. 3.1 where @, @; and @2 are arbitrary formulas and w are propositional atoms of CL:  TEYSvEeT TET TEL TE-A¢STEo TE dV d2 STE 1 or TE de TE bi Ade STF oi and TF do TE b\> do OLE b1 or TE do TFd oh SLE dod andITEhG og.  Fig. 3.1. Propositional satisfaction relation  Note that the propositional atoms obtain meaning directly from Z whereas the meaning of other kinds of propositional formulas is uniquely determined by the meaning of its subformulas. 

We write ZF T as an abbreviation for ZF @ for all ¢ € T and say that T is satisfied in T.  Two (propositional) interpretations J and 7 for £ are (elementarily) T- equivalent, in writing IT =7 J, if  TETSIFT.  T and J are (elementarily) equivalent, in writing ZT = J, if they are {¢\| dE L£}-equivalent, ic. ZF 6 JF ¢ holds for all formulas ¢.  3.1.3 Sequents. Fix a language L. For a finite sequence of formulas A: 4},  .., On we write AA as an abbreviation for the conjunction ¢, A--- A @y if n \> 1 and for T if nm = 0. For any propositional interpretation Z we clearly have TF AA iff ZF ¢ for all ¢ € A. Note that this holds also for A = 0 because /\\@ = T for which Z F T holds just as J F @ vacuously holds for all GED.  For the same sequence A we write \\/A as an abbreviation for the dis- junction ¢, V--- V ¢, if mn \> 1 and for 1 if nm = 0. For any propositional interpretation Z we clearly have JF \\/A iff ZF ¢@ for some ¢ € A.  For two finite sequences of formulas A and I we call the formula (\\A— VI a sequent. For any propositional interpretation Z we clearly have ZT F AA VI iff ZF @ for some ¢ € A or ZT F ¢ for some ¢ € I. Thus TF AASV iff TE ¢ for all 6 € AandT F ¢ for all 6 € I. We have T¥ AO — VO because this stands for T# T \> L.  3.1.4 Tautologies. A formula ¢ of £ is a tautology, in symbols Fp, ¢, if TF ¢ holds for all propositional interpretations Z for L.  We say that two formulas ¢; and ¢2 are propositionally equivalent if we have ZF ¢, \& ZF @ for all propositional interpretations Z. But this means that ZF @1 © ¢2 holds for all propositional interpretations Z and so ¢1 \<— ¢2 is a tautology. Note that we then also have Fy ¢; iff Fy ¢2.  Because ZF ¢1 A d2 holds iff ZF ¢, and ZF ¢2 hold we have F, ¢1 A d2 iff Fp \~1 and Fp o2.  3.1.5 Equivalence lemma. T=J' sT=rJ.  Proof. Assume I’ = J? and for any ¢ € T prove TE ¢S J F o by a straightforward induction on the construction of ¢ because for every @ € FPA(¢) we have PET Soe J. im  3.1.6 Decidability of tautologies. Fix a language £. We call a set S  of formulas of £ decidable if we can effectively decide for every formula ¢ whether or not @ € S holds. Finite sets S are clearly decidable.  88 

For every decidable propositional interpretation I and for every formula φ of L we can effectively decide whether I ² φ holds by simply using the properties Par. 3.1.2 of propositional truth. 

We can effectively decide whether a formula φ is a tautology because the set FPAφ of all of its free propositional atoms contains finitely many, say n, atoms. We claim that ²p φ holds iff I ²p φ holds for all 2n subsets I of FPA(φ) and the last is clearly effectively decidable. The claim holds because if φ is a tautology then it is true in all subsets of FPA(φ). On the other hand, if φ is true in all subsets of FPA(φ) then if I is any propositional interpretation for L then so is Iφ ⊆ FPA(φ) and we have Iφ ² φ and hence I ² φ by Lemma 3.1.5. Thus φ is a tautology. 

The just described method of deciding whether φ is a tautology is called the truth table method because every propositional interpretation I ⊆ FPA(φ) can be viewed as a row in a table containing t or f according to whether I ² φ holds or not. 

3\.2 Propositional Tableaux 

We now introduce a method of testing for tautologies by propositional tableau proofs. Tableaux were first used by Beth \[2\] and refined by R. Smullyan \[21\]. We use the signed tableaux of Smullyan but in a positive way which proves goals rather than refuting them. We will show that tableau proofs prove exactly the tautologies. We introduce the tableaux because they can be extended to deal with identity and quantifiers whereas the truth table method cannot, at least not directly. 

3\.2.1 Signed formulas. A formula φ of a language L is signed if it is written in one of two forms: φ or φ∗. The signed formula of the first form is called assumption and of the second form goal. We will use φ+ as a syntactic variable ranging over signed formulas. We will denote by ∆ finite nonempty sequences of signed formulas. Every sequence ∆ of signed formulas can be associated with a sequent 

∧ Λ → ∨ 

Γ where the sequence Λ contains exactly the assumptions in ∆ and the sequence Γ contains exactly the goals in ∆ (with the signs ∗ deleted). 

3\.2.2 Propositional tableaux. Fix a language L. Propositional tableaux for L are finitely branching trees built by to two kinds of expansion rules. A unary tableau expansion is of the form 

∆1 

φ+ 1 

(1) 

where ∆1 is a possibly empty sequence of signed formulas and φ+ 1 a signed 

formula. A binary tableau expansion rule is of the form 

89

Ai oF \| os where also $3 is a signed formula. The signed formulas of A are called premis- es and the signed formulas of and ot conclusions of the expansion rules. Let A be a non-empty sequence of signed formulas and AA \> VI a  sequent associated with A. A binary tree 7 with signed formulas as labels is a tableau for A:  (2)  A  T  if the tree 7 is either empty or it is obtained by an expansion rule. In the graphical representation we place the tableau 7 under the sequence of signed formulas A. The tableau is separated from the sequence by a solid line.  If the tableau z for A is empty then it has the form  A  If the tableau a for A is obtained by a unary rule (1) then it has the form  A “ of where A; C A and Ot TY Ty  Note that 71 is a tableau for the sequence A, oy. The unary propositional rules will be such that  Fp (A\\4 \> VP) 3 (AA = VE) (3)  where the sequent on the right is associated with A, oy. If the tableau a for A is obtained by a binary rule (2) then it has the form  A A A ot o3 4 4 where A; CA, \_“! ,and \_\_\*%? 1 3 TH Tr asi 72  Note that 7, is a tableau for the sequence A,¢, and 7 a tableau for the sequence A, ¢2. The binary rules will be such that  B(M=Vr (ia Vna\\aVe  where the two sequents on the right are associated with A, @f and A, df respectively.  90 

3\.2.3 Propositional tableau expansion rules. Fix a language £. The following unary propositional tableau expansion rules are called flatten rules:  b1 A 2 1 A $2 go. \& b2 1 — b2 a a) ge) Goa? gi \> b2\* o1 \> do g1 V bo o1 V bo SO Gy Ge YO)  The following binary propositional tableau expansion rules are called split rules:  g1 V bo y oi — 2 - gr A bo (Ax) o1 — b2\* (o o1 \| d2 g2 \| or\* d1\* \| bax 1 — b2\* \| b2 \> o1\*  The following unary propositional tableau expansion rules are called in- version rules:  m2 (=) age  ox a) Note that we have for each propositional connective two rules, one when the connective is the premise formula as an assumption and one as a goal.  We will now convince ourselves by the truth table method that, for in- stance, the rule — satisfies 3.2.2(4) which has the form:  Fp (61 \> 2) A\\A\>V/T) @ (2 A f\\A\> VE) A(A\\A\> eV V2) -  Indeed, for every propositional interpretation Z we have  TF (¢1 \> d2) A f\\A\>\\/P  iff ZK $6, \> dp or TE AA VI iff (LE ¢) and Z¥ 2) or TF AA\> VI iff ZF N\\A \> 6, VV and ZF 69 A \\A = VIF iff  TE (mA AAs VP) A((\\A\> ev VP).  3.2.4 Proofs with propositional tableaux. Fix a language £. Let A be a non-empty finite sequence of signed formulas of £, and 7 a propositional tableau for A.  A branch of the tableau 7 is a sequence of signed formulas A, A; where A, is read off some branch of the tree 7. We say that the branch is closed on ¢ if both ¢ and $x are in the branch A, A;. The branch is closed if A, A, contains either the goal T\*, or the assumption 1, or the branch is closed on some ¢ different from T and L. The tableau a is closed if all of its branches are closed.  91 

We write 7: +, \[A\] when 7 is a closed propositional tableau for A. We write +, \[A\] if there is a propositional tableau 7 such that 7: , \[A\]. By a simple induction proof on the structure of 7 we can show:  mw: Fy \[A\] and AC Ay Sm: Fy \[Aj\]  where by A C A; we mean d+ € A\> ¢\* € A, for all ¢\*.  For a formula ¢@ we say that the tableau 7 proves ¢, in symbols 7: Fy @, if 7: -, \[¢\*\] holds. The same conventions as for sequences A apply also to formulas @. In particular, we say that ¢ is provable if Fp @ holds. For a set of of formulas S we write F, S if F, ¢ holds for all ¢ € S.  3.2.5 Lemma (Soundness of propositional tableaux). If \\A — \\/I is associated to A then  bp \[A\] \> Fp \\A\> VT.  Proof. By induction on the structure of 7. So assume that the tableau a for  A is closed: A  T  and perform a case analysis on 7. If 7 is empty then either Tx € A, ice. Téelr,or le A,ie. L € A, or else y, Wx € A, ie. \~W € A and \~ € I for some propositional atom w. For any propositional interpretation Z we then have ZF AA— \\VT and so the sequent is a tautology.  If the first expansion in a is by a unary rule 3.2.2(1) such that A; C A then we have  A A  ———\_— + ot te, OF Ty Ty  for some tableau 7 such that 7:1, \[A,éf\]. Let AA: \> VI be a sequent associated with A, f. We get Fp, \\A1 — VI, by IH and so Fy, AA VI by 3.2.2(3).  If the first expansion in 7 is by a binary rule 3.2.2(2) such that A, C A then we have  A A A + + 1 4 i.e. ot and 72 oj 3 TH 1 TY 712  for some tableaux 7 and 7 such that 7: +, \[A,¢f\] and 72: Fy \[A, oF\]. Let AA; \~ VI\\ and AA — \\I% be sequents associated with A,@f and  92 

A, of respectively. We get F, Ai — VIy and F, A\\A2 — VL» by two IH’s. Hence F, \\A— VT by 3.2.2(4). Oo  3.2.6 Lemma (Completeness of propositional tableaux). If \\A —\> VI is associated with A then  Fp \\A\> Vr = +, \[A\] .  Proof. Assume F, (\\A— \\/JI and prove \|, \[A\] by induction on the total number n of propositional connectives in the formulas of A (not counting those within quantifiers).  If n = 0 then A consists at most of propositional atoms L and T. If 1 € A or T € I then the branch A is closed. If neither of the two cases applies and the sequences A and I’ have no propositional atom in common then we have a contradiction because JT ¥ A\\A— VI for T = {¢\| ¢ € A}. Thus A must be closed on some ¢. Hence, in both cases it suffices to take 7 empty.  If n \> 0 then select a signed propositional formula ¢\*+ of A which is not T or L and denote by A, the sequence obtained from A by omitting the selected formula from it. Denote by A; the sequence obtained from A by deleting ¢ if the selected signed formula is an assumption and the sequence A otherwise and denote by I the sequence obtained from I" by deleting ¢ if the selected formula is a goal and the sequence I’ otherwise. Thus if the selected formula is a goal then AA; — ¢V \\VI{ is a tautology and if the selected formula is an assumption then ¢ A AA; — \\/I{ is a tautology. We wish to prove -, \[A\] by the case analysis of the signed formula ¢t.  If 6 = 7d\\\* € A then, since F, A\\A1 \> 7d, V \\VI4, we also have  F, d1 A \\Ai — VI. The associated sequence A, ¢; has n — 1 connectives and so 7: py \[A1, ¢1\] for some 7; by IH. This is shown on the left and the constructed tableau is shown on the right:  A; A ot =\> od: (7\*) Ty TY  The constructed tableau is closed and so F, \[A\]. If dt = $1 V }o\* € A then, since Fp A Ai — (¢1 V 2) V VI, we also have  The associated sequence Aj, $1\*, 62\* has n—1 propositional connectives and so 71: Fy \[Ai, 61%, G2\*\] for some 71 by IH. This is shown in the following on the left and the constructed tableau is shown on the right:  93 

Ai A  pik  (Vi¥) Got bok (a8) Ty TTY  The constructed tableau is closed and so F, \[A\]. If ot = di — 2 € A then, since Fy (¢1 \> $2) \\A\\A1 \> VI4, we also have  Fp d2\\ \\Ai \> \\/Ti and Fy (\\Ar \> di V VL -  The sequences Aj, 62 and Aj, ¢,\* have n — 1 propositional connectives each and so 77: Fp \[A1, ¢2\] and m1: Fp, \[Ai, ¢1\*\] for some 72 and 7 by two IH’s. The two tableaux are shown on the left and the constructed tableau is shown on the right:  A Ay Ai 2 and yx \> ) 15 Ty 2 oi\* 72 TY  The constructed tableau is closed and so +, \[A\]. The remaining cases are similar. O  3.2.7 Theorem (Soundness and completeness of propositional tableaux).  rpOS EO.  Proof. We have \| , ¢ iff by definition -, \[¢\*\] iff by Lemmas 3.2.5 and 3.2.6 FE, T \> diff F, ¢. Oo  3.2.8 Falsification of open branches in propositional tableaux. A branch A of a propositional tableau a for @\* is propositionally complete if with every expansion rule with a premise in A the branch contains also at least one of its conclusions.  If a tableau for ¢\* does not close then it contains an open branch A and this can be clearly propositionally completed by finitely many expansions because the conclusions of expansion rules are formulas with a lesser number of propositional connectives than the premises.  For every propositionally complete and not closed branch A of a tableau for we can construct a propositional interpretation Z by collecting all propo- sitional atoms in assumptions:  T={w\|v € A and ¢v is a propositional atom} .  94 

We prove by induction on the number of connectives in w that the following holds:  (bE ASTE wp) and (yx EC ASTEY).  If w is a propositional atom then the claim holds directly from the definition of Z. If w = 7y, then if ay, € A we have wx € A because the branch is propositionally complete and so Z F yw, by IH, ie. Z F 71. The case ay \* € A is similar.  If h = vA then if YAW € A we have w1, {2 € A because of saturation and ZF wy, ZF we by two IH’s. Hence ZF 1 A Wo. If Wy A Yox € A then one of the subformulas is a goal in A, say y,\* € A. Thus Z F wy, by IH and hence ZF wy A we. The remaining cases for w are similar.  The goal ¢\* cannot be a tautology because we have ZT F ¢ by the just proved property.  3.3 Admissible Expansion Rules  3.3.1 Admissible expansion rules. We can often considerably shorten a tableau proof by the use of admissible expansion rules. Admissible rules can be reduced to the basic expansion rules, which are in the propositional case given in Par. 3.2.3), and so they do not add any strength to the proof system. Precisely, the n-ary expansion rule (n \> 1)  ey ot \|---\| bn is admissible if for all sequences of signed formulas A, s.t. A C A, and all tableaux 7, ..., Tm 8.t. 71: Fp \[41,7\], ---, Ti Fp \[41,65\] we can  effectively construct a basic tableau a such that a: -, \[Aj\]. The situation can be visualized as follows:  (AI =\> . (A) oy a on T TY Tn  where we have indicated by \[A\] that the premises of A are in the branch above. An application of the admissible rule and the subsequent closure by tableaux 71, ..., 7 on the left can be effectively replaced by the tableau 7.  95 

The reader will note that we can permit in the tableau π also expansions by previously justified admissible rules of inference because they can be al- ways replaced by basic inferences. After we have demonstrated the effective reduction of tableaux π1, . . . , πn to the tableau π we may freely use the admissible rule (A) as if it were a basic rule. 

3\.3.2 Theorem (Generalized flatten rules). Following generalized flat- ten rules are admissible in propositional tableaux for any n ≥ 2 and 1 ≤ i ≤ n: 

φ1 ∧ · · · ∧ φi ∧ · · · ∧ φn 

φi (G∧i) 

φ1 ∨ · · · ∨ φi ∨ · · · ∨ φn∗ φi∗ (G∨i∗) . 

Proof. We prove the admissibility of the rule (G∧i) by induction on i; the admissibility of (G∨i∗) is proved similarly. In the base case when i = 1 there is nothing to prove as (G∧1) is the basic flatten rule (∧1). For 2 ≤ i + 1 ≤ n we consider an expansion by the rule: 

... φ1 ∧ φ2 ∧ · · · ∧ φn 

... 

φi+1 (G∧i+1) π 

If n = 2 then this is the basic (∧2) rule and we are done. If n \> 2 then we replace the rule (G∧i+1) by the basic rule (∧2) followed by the (G∧i) rule which is admissible by IH. The new tableau is as follows: 

... φ1 ∧ φ2 ∧ · · · ∧ φn 

... 

φ2 ∧ · · · ∧ φn (∧2) φi+1 (G∧i) 

π 

ut 

3\.3.3 Theorem (Generalized split rules). The following generalizations of rules (∨) and (∧∗) are admissible in propositional tableaux for any n ≥ 1: 

96

φ1 ∨ · · · ∨ φn 

φ1 \| · · · \| φn (G∨) 

φ1 ∧ · · · ∧ φn∗ φ1∗ \| · · · \| φn∗ (G∧∗) 

Proof. We prove here only (G∧∗) by induction on n. In the base case when n = 1 there is nothing to prove as (G∧∗) is the basic split rule (∧). In the inductive case when n + 1 ≥ 2 we consider an expansion by the rule: 

... φ1 ∧ φ2 ∧ · · · ∧ φn+1∗ 

... 

(G∧∗) φ1∗ π1 

φ2∗ π2 

· · · φn+1∗ πn+1 

We replace the rule (G∧∗) by (∧∗) followed on the right by an n-ary (G∧∗) rule which is admissible by IH. The new tableau is as follows: 

... φ1 ∧ φ12 ∧ · · · ∧ φn+1∗ 

... 

(∧∗) φ1∗ 

π1 

φ2 ∧ · · · ∧ φn+1∗ (G∧∗) 

φ2∗ π2 

· · · φn+1∗ πn+1 

ut 

3\.3.4 Inversion of expansion rules. Let 

φ+ 

φ+ 1 \| · · · \| φ+ 

n (R) 

be an expansion rule with n ≥ 1. The rule R can be an inversion or split rule as well as an identity or quantifier rule which will be introduced later. We say that the rule (R) is invertible if for every sequence of signed formulas ∆ such that π : \`p \[∆,φ+\] there are tableaux πi for 1 ≤ i ≤ n such that 

97

πi : \`p \[∆,φ+ i \]. Moreover the rule (R) is not applied with φ+ as a premise, 

and the formula φ+ is not used for the closing of a branch, in neither of tableaux πi. The inversion of the rule R can be visualized as follows: 

... φ+ 

... 

π 

⇒ 

... φ+ 

... 

(R) 

φ+ 1 

π1 

· · · φ+ n 

πn 

where we can in effect assume that the first expansion in the closed tableau on the right is by the rule (R) and that the premise φ+ is used only once as indicated. This also means that the premise φ+ is not used to close a branch. 

Propositional flatten rules have the following schematic form: 

φ+ 

φ+ 1 

(F1) φ+ 

φ+ 2 

(F2) . 

We say that the flatten rules (F1) and (F2) are invertible if from π: \`p \[∆,φ+\] we can form a tableau π1 such that π1: \`p \[∆,φ+ 

1 , φ+ 2 \] where the rules (F1) 

and (F2) are not used in π1 with φ+ as a premise and neither is the formula φ+ used for closing of a branch. The inversion can be visualized as follows: 

... φ+ 

... 

π 

⇒ 

... φ+ 

... 

φ+ 1 (F1) 

φ+ 2 (F2) 

π1 

where we can in effect assume that the first two expansions in the closed tableau on the right are by the rules (F1) and (F2) and that the premise φ+ 

is used only once as indicated. This also means that the premise φ+ is not used to close a branch. 

3\.3.5 Inversion theorem. Inversion, split, and flatten rules are invertible in propositional tableaux. 

Proof. The following diagram illustrates the inversion of a (¬) inversion rule: 

98

... ¬φ ... 

φ∗ (¬) π 

¬φ∗ 

⇒ 

... φ∗ ... 

π ¬φ∗ φ (¬∗) 

The closed tableau on the left shows just two of possibly many uses of the premise ¬φ. The first one uses the premise in a (¬) rule and the second one closes the branch with ¬φ∗. The closed tableau on the right shows the inversion where the first used formula has been removed (because it is now in the top sequence) and the second one is now used as a premise of a (¬∗) rule after which the branch closes. The two indicated transformations should be applied to all uses of the premise ¬φ. The inversion of ¬∗ inversion rules is similar. 

The following diagram shows a closed tableau before the inversion of a (→) split rule: 

... φ1 → φ2 

... 

(→) φ2 

π2 

φ1∗ π1 

φ1 → φ2∗ 

We have indicated two possible uses of the premise φ1 → φ2. The first use is in a (→) rule and the second use is in the closure of a branch. We form the two inverted tableux as follows: 

... φ2 

... 

π2 

φ1 → φ2∗ (→2∗) φ2∗ 

... φ1∗ ... 

π1 

φ1 → φ2∗ (→1∗) φ1 

99

The expansions by the (→) rule have been replaced in the inverted tableau by tableaux π2 and π1 respectively and the closing formulas φ1 → φ2∗ have been expanded by the corresponding flatten rules after which the branches close. The inversion of other split rules is similar. 

The following diagram shows a tableau before the inversion of a (∨i∗) flatten rules: 

... φ1 ∨ φ2∗ 

... 

φ1∗ (∨1∗) 

φ2∗ (∨2∗) π 

φ1 ∨ φ2 

We have indicated three possible uses of the premise φ1 ∨ φ2∗. The first use is in a (∨1∗) rule after which there is a use in a (∨2∗) rule and third use is in the closure of a branch. We form the closed inverted tableau as follows: 

... φ1∗ φ2∗ ... 

π 

φ1 ∨ φ2 

(∨) φ1 φ2 

In the inverted tableau the expansions by the (∨i) rules have been removed and the closing formulas φ1 ∨ φ2 have been expanded by (∨) split rules after which the branches close. The inversion of other flatten rules is similar. ut 

3\.3.6 Cut rules. For any formula π the following is a cut rule on φ: 

φ \| φ∗ (C) . 

100

That cut rules are admissible in propositional tableaux, i.e. that T1: Fp \[A, @\] and 7: Fy \[A, \*\] \> Fy \[A\] .  holds can be proved by the following semantic argument. Assume 71: Fp \[A, ¢\] and 7: Fp \[A, ox\] and let AA — VI be a sequent associated with A. By the Soundness lemma (3.2.5) we have Fp 6A \\A— VI and F, A\\A— @V VT. By the truth table method we can see that also  Fp (6A As VL) A(A\\4\> ov VL) = \\A Vr  holds and hence F, A.A — VI. By the Completeness lemma (3.2.6) we then get Fp \[Al\].  Unfortunately, this argument, which depends on the soundness and com- pleteness of propositional tableaux, cannot be extended to tableaux with quantifier rules without first proving the soundness and completeness theo- rem for such tableaux. Our intention is to reduce the quantificational logic to the propositional logic and to obtain the soundness and completeness of quantificational tableaux through the reduction and so the above semantical argument proving the admissibility of cut rules cannot be used.  We will now prove the admissibility of cuts by a syntactic (proof-theoretic) argument in a way which extends to the quantificational case.  3.3.7 Lemma (Admissibility of cuts on propositional formulas). If the cut rules on all propositional atoms in a formula @ are admissible in propositional tableaux then also the cut rule on ¢ is admissible.  Proof. Assume that the cuts on the propositional atoms in F'PA(@) are ad- missible and prove by induction on the structure of ¢ that the cut on ¢ is admissible. We perform the case analysis of ¢ used in a cut as follows:  A  (C) ob or  If ¢ is a propositional atom then the cut on ¢ is admissible from the assump- tion.  If 6 =T then the expansion by the cut on T is shown in the following on the left:  T Tx T 7  The assumption T is not used for anything in 7 and so the tableau a for A is closed as shown on the right. The case @ = L is similar.  101 

If φ ≡ ¬φ1 then the expansion by the cut on ¬φ1 is shown in the following on the left: 

∆ 

(C) ¬φ1 

φ1∗ (¬) π1 

¬φ1∗ φ1 (¬∗) π2 

⇒ 

∆ 

(C) φ1 

π2 

φ1∗ π1 

where we may assume without loss of generality that both inversion rules have been inverted. As a consequence the assumption ¬φ1 is not used for anything in π1 and the goal ¬φ1∗ is not used in π2. We transform the tableau as shown on the right where the cut on ¬φ1 has been removed and the inversion rules replaced by a cut on φ1 which is admissible by IH. 

If φ ≡ φ1 ∨ φ2 then the expansion by the cut on φ1 ∨ φ2 is as follows: 

∆ 

(C) φ1 ∨ φ2 

(∨) φ1 

π1 

φ2 

π2 

φ1 ∨ φ2∗ φ1∗ (∨1∗) φ2∗ (∨2∗) π3 

where we may assume without loss of generality that the (∨) split rule on the left and the (∨i∗) flatten rules on the right have been inverted. As a consequence the assumption φ1 ∨ φ2 is not used for anything in π1 and π2 

and the goal φ1 ∨φ2∗ is not used in π3. We transform the tableau as follows: 

∆ 

(C) φ1 

π1 

φ1∗ (C) 

φ2 

π2 

φ2∗ π3 

where the formula φ has been removed and the disjunctive rules replaced by two cuts on φ1 and φ2 respectively which are admissible by IH. The cases when the main propositional connective of φ is ∧, →, or ↔ are similar. ut 

3\.3.8 Lemma (Admissibility of cut rules on propositional atoms). Cut rules on propositional atoms are admissible in propositional tableaux. 

Proof. Consider a closed propositional tableaux with a cut on a propositional atom φ shown in the following on the left: 

102

∆ 

(C) φ 

π 

φ∗ 

φ 

⇒ 

∆ 

φ π 

We have shown in the tableau for ∆,φ∗ one of possibly many branches closed on the pair of propositional atoms φ, φ∗. Because the goal φ∗ cannot be used in propositional tableaux for anything else we can form a closed tableau for ∆ shown on the right where we perform the indicated transformation for all branches closed on φ, φ∗. ut 

3\.3.9 Theorem (Admissibility of cuts). Cut rules are admissible in propositional tableaux on arbitrary formulas. 

Proof. This is a direct consequence of Lemmas 3.3.7 and 3.3.8. ut 

3\.3.10 Theorem (Lemma rule). If \`p φ then the following unary lemma rule 

φ (L) 

is admissible in propositional tableaux, i.e. for any closed propositional tableau for ∆ such that 

∆ 

φ (L) π 

(1) 

we have \`p \[∆\]. 

Proof. Assume π1: \`p φ and that the tableau (1) is closed and form the following closed tableau witnessing \`p \[∆\]: 

∆ 

(C) φ 

π 

φ∗ π1 

ut 

103

3\.4 Tautological Consequence  Important extension of the notion of tautology is the notion of tautological consequence where we ask whether a formula ¢ follows from a finite or infinite set of formulas T by the laws of propositional logic alone.  3.4.1 Tautological consequence. Fix a language £ and let T be a set of formulas from £. We define the relation formula ¢ is a tautological conse- quence of T, in symbols T'F, ¢ as follows:  TE,¢@(ZET=TE 6) for all propositional interpretations Z.  From this we can see that for T = we have 0F, 6 F, ¢.  Tautological consequence is a generalization of implication where we so to speak permit infinite many formulas in antecedent. If T is finite then we have TF, 6 = F, AT — ¢ by Lemma 3.4.2. If the set T is infinite then it can contain infinitely many propositional atoms and we cannot replace infinite propositional interpretations by finite ones as we did in the truth table method. Thus it seems that that the testing of TF, ¢ is a hard prob- lem having to do with quantification over uncountably many propositional interpretations. Fortunately, this kind of quantification can be replaced by existential quantification over countably many finite sets of formulas. This is a consequence of the fundamental theorem 3.4.4.  3.4.2 Semantic deduction lemma. For every finite set S' of formulas we have:  Skrok \\S\>¢. Proof. We have TF S iff ZF w for ally € S iff ZF AS. Thus SF, ¢ iff TES=}Te, ¢ forall Tif ZTE ASSTZE, oforalTif -,AS—-¢ O  3.4.3 Semantic weakening lemma. If S CT then  SF,¢o=\>TE,o.  Proof. Assume S Fy ¢ and take any propositional interpretation such that TE T holds. Since this means JZ F ¢ for all ¢ € T we also have J F S' and thus ZF ¢ from the assumption. oO  3.4.4 Compactness theorem.  TF, ¢=\> SF, ¢ for a finite S CT.  104 

Proof. Assume T F, ¢. T is a set of formulas of a first order language £ which has countably many formulas. Thus the set T is at most countable and we can write it in a form T’ = U;-, Si where each of the sets $; is finite and we have So = @ and S; C S;,, (This is trivial if T is finite; otherwise, for instance, enumerate T’ and define 5S; to be the set of the first 7 formulas in the enumeration).  We assign by the function W(Z) to every propositional interpretation Z one of the finite sets S; by:  W(Z) = 8S; where i is the least such that JF 5S; \> ZF ¢.  This is a legal definition because if ZF ¢@ then we have JF So \> ZF ¢ and if Z F ¢ then we have Z F T. Thus Z F w for some w € T and, since then w € S; for some i, we have J F S; for some 7 and there is a least such i. Define the set S to satisfy:  S:= LJ{w(z) \| Z is a propositional interpretation. }  We clearly have S C T’.. We also have S F, ¢ because for any propositional interpretation Z such that ZF S we have W(Z) C S and so ZT F W(Z). We then obtain Z F ¢ from the definition of W(Z). Thus the theorem will be proved if we demonstrate by an indirect proof that the set S is finite.  So suppose that S is infinite. We will construct an increasing chain of propositional interpretations Z; in which the infiniteness of S will be propa- gated. Enumerate towards that end all propositional atoms of £ in an infinite  sequence W1, W2,W3,... and define the finite sets of propositional atoms A; for i € N by A, = U {Wj} 1\<j\<i  Note that Ap = 9. Define an infinite sequence {7;}ien of finite propositional interpretations Z; to satisfy:  DL=%  aan T,U {i411} otherwise.  We clearly have Z; C Z;41. Define the sets I; for i € N to satisfy: I, =(J{(W@ \| 20 A; = Fi} and prove by induction on 2: M,; C A; and J; is infinite.  In the base case we have Zp = @ = Ag and the set  105 

ly =( JWOD IN 40 =D} = WD \|0=0 = 5.  is infinite. In the inductive case we have  IH Tian CTU {Vig} C AU {igi} = Aigi - We note that if 7M A; = Z; then  \| \| \_ fz, if Wi41 LZ TUL {vi41}) = { U{dini} if din. © L  and so In =\| J{W@) \|TN A; =F} = UW @® \|B Ain =T}ULY{W\]D \| I Aig = Tv {digs}} -  One of the two sets on the right must be infinite because \[,, is by IH. We consider two cases. If the first set is infinite then Z;,, = Z; by definition and the first set is I,41. If the first set is finite then Z;4, = Z; U {w;41} and so the second set, which must be infinite, is \[,,41. Thus in both cases \[,,41 is an infinite set.  We construct a propositional interpretation J = U{Z; \| i ¢ N} and we have W(Z) = 5S, for the least \& such that J F S,; \> ZF @. Let i be the least number such that FPA(S; U {¢}) C A; and let 7 be any propositional interpretation such that 7 NM A; = Z;. We have  ToRAPF = T FPA(St U{O}) = J 9 AiN FPA(Sk U {6}) = Tin FPA(S, U {o}) \_ Tote}  and so J and J; are S,U{¢}-equivalent by the Equivalence lemma (see 3.1.5). From this we get W(.7) = W(Z;) and hence  =V{w(J) \| JOA: = LB} =UY(WG) \| 704: = 1} = WG)  which is a contradiction because the set W(Z;) is finite (the set is actually equal to S;). Oo  3.4.5 Corollary (Tautological reduction).  TKpo Fp \\S\>¢ for a finite subset S of T.  Proof. From T F, ¢ we obtain S F, ¢ for a finite subset S of T by Thm. 3.4.4. The opposite direction follows from Lemma 3.4.3 and we have S F, ¢ iff FE, \\S — ¢ by Lemma 3.4.2. Oo  106 

3\.4.6 Remark. The reader familiar with set theory will recognize the con- struction of the sequence {Ii}iN in the proof of the Compactness theorem as the construction of an infinite branch of an infinite tree with finitely branch- ing nodes in the proof of the König’s lemma. The lemma says that in every finitely branching tree with an infinite number of nodes there is an infinite branch. 

3\.4.7 Semidecidability of tautological consequence. Let L be a lan- guage and T an infinite decidable set of its formulas. We have noted in Par. 3.4.1 that in order to decide the unary relation φ is a tautological con- sequence of T , i.e. T ²p φ, one would expect to test I ² T ⇒ I ² φ for uncountably many propositional interpretations I. By the Compactness the- orem and Lemma 3.4.3 we however know that it is sufficient to decide whether S ²p φ holds for a finite subset S of T . As there are countably many finite subsets S of the countable T we have to test by Lemma 3.4.2 countably many times whether 

∧ S → φ is a tautology. 

One of the ways to organize the tests is as follows. We encode all formulas of L into N. Starting from 0 we then successively test for all natural numbers i whether i is a list such that for every j ∈ i (there are finitely many such j’s) the number j codes a formula φ (this can be effectively done). If so, then we test whether φ ∈ T . If this holds for all j ∈ i we can effectively form the finite set S of all formulas of L coded by i. We then test whether 

∧ S → φ 

is a tautology. If this is the case we stop the testing and we know that φ is a tautological consequence of T . If not then we have to continue with the next number i+1 and if φ is not a tautological consequence then by Lemmas 3.4.3 and 3.4.2 there is no finite S ⊂ T such that 

∧ S → φ is a tautology and we 

will never discover the fact. Predicates P (x) such that if there is an x satisfying P we can effectively 

find it but we go on searching forever if for all x not P (x) are called semide- cidable predicates. It can be shown by the methods of recursion theory that the unary predicate T ²p φ is semidecidable and that the above described method of crude search cannot be improved upon. Later in this text we will show how to reduce the general questions of logical validity of formulas and of logical consequence to the questions of tautological consequence from de- cidable sets. This will mean that the best we can do in first order logic is to find a proof of a formula from given axioms if there is one. If the formula is unprovable we might never discover it. 

3\.5 Tableaux with Axioms 

3\.5.1 Axiom rules. Fix a language L. We now extend propositional tableaux so we can prove that φ is a tautological consequence of a decidable set T of formulas L. For every ψ ∈ T we add a unary axiom rule: 

107

y (Az) which means that we can extend a branch of a tableau at an arbitrary position with the assumption w. Note that the decidability of T is crucial for this because we can use the axiom rule only if \~ € T. Without decidability we would not be able to recognize whether a given tree of signed formulas is a legal tableau or not.  3.5.2 Proofs with propositional tableaux with axioms. A proposi- tional tableau a for a sequence of signed formulas A which possibly uses axiom rules from T’ is a propositional tableau for A from axioms T. If 7 is closed then we assert this by writing 7 : T Fp \[A\]. Note that if T = 0 then we have 7: QF, \[A\] = 7: Fp \[A\]. When A = ¢\* then we say that 7 proposition- ally proves @ from axioms T and write it as 7: T+, ¢. We use abbreviations similar to those discussed in Par. 3.2.4 also for the proofs from axioms.  3.5.3 Theorem (Admissible expansion rules in propositional tableaux with axioms). All rules proved admissible for propositional tableaux in Sec- t. 8.8 are also admissible in propositional tableauz with axioms.  Proof. Inspection of the proofs of admissibility of expansion rules in Sect. 3.3 reveals that the proofs remain correct also for tableaux with axiom rules because their presence does not affect the proofs of admissibility. oO  3.5.4 Syntactic weakening lemma. /f S CT then Stpos\>Ttypo.  Proof. Assume 7 : SF, ¢@. Every every axiom rule for \~ € S used in 7 is also an axiom rule for 7 € T and so 7: TF, @. oO  3.5.5 Theorem on syntactic compactness.  Trp o\> SF, ¢ for a finite S CT. Proof. Assume t : TF, ¢ and construct the finite set S' to consist of all conclusions 7 of axiom rules for \~ € T used in the tableau 7. The same rules are axiom rules for 7) € S and so 7: SF, @. oO 3.5.6 Deduction theorem. For a finite set of formulas S:  Stpoe typ AS oe.  Proof. Let S = {u1,...,Wn}. In the direction (=) assume 7: S Fy @, ice. a: Sp \[bx\]. Ifn = 0 then AS =T and we derive \|, T — ¢ as follows:  108 

Tao 7  If n \> 0 then denote by 7; the tableau formed from 7 by deleting all expan- sions by axiom rules. We clearly have 7: +, \[¢\*, W1,.-., Yn\]. which is shown in the following on the left:  UiAr AUn \> oO  ‘ be (+9)  ; W1A++\*ANUn (1%) Un .  m1 Un (GAn) asi  We form the closed tableau on the right which is expanded with the help of the generalized flatten rules (see Thm. 3.3.2) and so Fp, AS — ¢.  In the direction (\<=) assume 7: Fy \[1 A---A Wn — ox\]. We can assume by inversion that the first two expansions in 7 are by (—;\*) flatten rules such that the goal \\.S — ¢x is not used in 7. If n = 0 then the situation is shown on the left:  T — ox oe (2%) oF T (—1\*) Ty  TY  and we can form a closed tableau 7 for ¢\* because the assumption T cannot be used in 71. If n \> 0 then we can assume that the inversion of (—;\*) flatten rules is followed by by n — 1 inversions of (A) flatten rules which is shown in the following on the left:  W1 A+++ An \> o\*  Ui A Avn (1) oF W2AN-+-AUn (Ag) Un (An) : TY Un (A2)  Ty  We form the closed tableau on the right which is expanded with the help of axiom rules from S and in which we have omitted the assumptions w;A---AWUn for 1 \<i \<n because they cannot be used in 71. We thus have SF, ¢. oO  109 

3\.5.7 Theorem (Introduction/elimination of axioms).  Thpo tp \\ So for a finite subset S of T.  Proof. From TF, ¢ we obtain SF, ¢ for a finite subset S of T by Thm. 3.5.5. The opposite direction follows from Lemma 3.5.4 and we have S +, @ iff Fy \\S — ¢ by Thm. 3.5.6. Oo  3.5.8 Corollary (Soundness and completeness of propositional tableaux). For any fromula ¢ and set of formulas T there is in each direction a finite subset S of T such that the following holds:  TEp Tp fy 3.4.3 I 3.4.4 fy 3.5.4 J) 3.5.5 SE, ¢ Sty @ {N) 3.4.2 tN) 3.5.6 Fp \\S \> ¢ \<= 3.2.5 \> 3.2.6 tp \\S\>¢ Oo  3.5.9 Semidecidability of tautological consequence revisited. One of the consequences of the Corollary 3.5.8 is that we can semidecide the relation T Fp ¢ by tableaux instead of testing for tautologies as outlined in Par. 3.4.7. We do this by constructing possibly infinite branches which are axiomatically complete, i.e. which apply the axiom rules for all axioms from T.  In order to decide the relation J’ F, @ we enumerate the axioms of T into a sequence 71, wo, ..., and construct a propositional tableau for the goal ¢\*. We select an open propositionally complete branch of it (if any) and we extend it by an axiom rule by taking 7, into assumptions. We then construct a propositional tableau under the assumption. We select a not closed propositionally complete branch again (if any) and expand it with the axiom rule for w2. We continue in this way in the hope of closing the branch. If this happens we apply the same procedure of systematically applying one axiom after another to the remaining open branches. If all branches close then TF, ¢ holds.  Otherwise, if T is finite we stop with at least one open branch A which is both propositionally and axiomatically complete. The branch is finite. If T is infinite we will go on extending a branch forever because there is at least one infinite branch which is open and propositionally and axiomatically complete.  In both cases there is a propositional interpretation Z constructed by collecting all propositional atoms in the assumptions. We have proved in Par. 3.2.8 that we have J F ¢ and ZF ¢, for every assumption ¢, in the  110 

branch. Since the branch contains all axioms T as assumptions we have in particular I ² T . But this means that we have T 2p φ. Note that we can effectively determine this fact only when T is finite. 

111

112 

4\. Identity Logic 

In this chapter we investigate formulas always true on the strength of propo- sitional logic and of properties of identity. 

4\.1 Some Syntactic Concepts 

4\.1.1 Free terms. Free terms of a set of formulas S of a language L are terms occurring outside of quantifiers in the formulas of S. This is made precise by a metamathematical function FT (α) defined on terms, formulas, and sets of formulas to yield the set of free terms of α. The function FT satisfies: 

FT (x) = {x} FT (f(τ1, . . . , τn)) = {f(τ1, . . . , τn)} ∪ FT (τ1) ∪ . . . ∪ FT (τn) 

FT (τ1 = τ2) = FT (τ1) ∪ FT (τ2) FT (P (τ1, . . . , τn)) = FT (τ1) ∪ . . . ∪ FT (τn) 

FT (∀xφ) = ∅ FT (∃xφ) = ∅ 

FT (\>) = ∅ FT (⊥) = ∅ 

FT (¬φ) = FT (φ) FT (φ1 ∨ φ2) = FT (φ1) ∪ FT (φ2) FT (φ1 ∧ φ2) = FT (φ1) ∪ FT (φ2) 

FT (φ1 → φ2) = FT (φ1) ∪ FT (φ2) FT (φ1 ↔ φ2) = FT (φ1) ∪ FT (φ2) 

FT (T ) = ⋃ {FT (φ) \| φ ∈ T} . 

4\.2 Quasitautological Consequence 

4\.2.1 Structures. A structure M for a language L is given by

1\. a non-empty set D, called the domain of the structure, 2. for every n-ary function symbol f of L an n-ary function fM over D, i.e. 

fM : Dn 7→ D, called the interpretation of f , 3. for every n-ary predicate symbol P of L a subset PM of Dn called the 

interpretation of P . 

Here we define D0 = {∅} and identify nullary functions over D with elements of D. Thus for every constant c of L we have cM ∈ D and for every propo- sitional constant P of L we have PM ⊆ {∅}. We agree to identify the value PM = ∅ with falsehood and the value PM = {∅} with truth. 

Structures are mathematical objects (triples of sets) whose purpose is to assign meaning to terms and formulas of L. A structure M is finite if its domain D is a finite set and infinite otherwise. M is a numeric structure if its domain is a subset of natural numbers. 

4\.2.2 Assignments. For a structure M for L with the domain D we call a function a from N to D assignment in M. The idea is that the assignment a assigns the value a(i) ∈ D to the variable vi. 

4\.2.3 Identity interpretations. An identity interpretation I for L is a triple 〈Q,M, a〉 where Q, called the quantifier set, is a subset of quantifier formulas of L, M is a structure for L and a is an assignment in M. An identity I is finite if its structure is finite and numeric if its structure is numeric. 

Identity interpretations uniquely determine the meaning of terms and formulas as shown in the following two paragraphs. 

4\.2.4 Denotation of terms. For a given identity interpretation I = 〈Q,M, a〉 for L with D the domain of M we assign to every term τ of L its denotation, designated as τI , to be the element of D satisfying the following: 

vIi = a(i) 

f(τ1, . . . , τn)I = fM(τI1 , . . . , τIn ) f is n-ary function symbol of L. 

If f is a constant symbol, i.e. a nullary function symbol, then we abbreviate fM() to fM. 

The identity interpretation I is canonical if it is a numeric interpretation and for every element d in the domain of its structure we have d = τI for some term τ . 

4\.2.5 Satisfaction relation for identity interpretations. Let I = 〈Q,M, a〉 be an identity interpretation for L. For every formula φ of L we define the unary relation I ² φ, read as I satisfies φ, to be similar to the satisfac- tion relation for propositional interpretations (see Par. 3.1.2) when φ is a propositional formula. If φ is a propositional atom then we define 

114

TEVcd \& Vr\~eQ  TE Ard \& Ard EQ  TEN =ReT=T%  TE P(n,..-,T) @ (t,.--,T) E P™.  Here the ‘zero-tuple’ () is defined as the empty set @. This means that for a propositional constant P we have ZF P iff PM = {0}. This should explain why we have identified the set {9} with the truth.  Assignments in Z are used only in atomic formulas which obtain the mean- ing from the interpretation of function and predicate symbols specified by the points (2) and (3) in Par. 4.2.1. Specifically, the meaning of identity 7, = 79  is determined as the identity of the denotations tT? = 7#. The reader will note that the symbol of identity in the formula 7, = 72 is just a symbol  whereas the same symbol in rt? = 73 stands for the relation of identity over  the domain of Z. The meaning of quantifier formulas is determined from the quantifier set Q similarly as the meaning of propositional atoms is determined from propositional interpretations.  4.2.6 Lemma (Reduction to propositional interpretations). To every identity interpretation I for £L there is an equivalent propositional interpre- tation J.  Proof. Take an identity interpretation ZT = (Q,M,a) for £. We construct the propositional interpretation 7 as follows:  J ={w\|TE w for propositional atoms w} .  We prove the equivalence by induction on the construction of ¢. If ¢ is a propositional atom then J F ¢ iff Pe J iff ZF ¢. If 6 = oi V G2 then we have J F $1 V do iff J F od, or J \& oo iff, by IH, Z F d, or ZF do iff TE 1 V og. The remaining cases are similar. oO  4.2.7 Equality axioms. Let £ be a first-order language. For all terms 7, -++3Tns Pls +-+\> Pn the following formulas, designated by Eq, are called equality axioms for L:  T\]1=Ti1 (1) TL =T2 7\] =T (2) T1 = 7 AT2 = 73 9 T1 =T3 (3)  f is n-ary function symbol, n \> 0  T1 = piA-+:AT = pn A P(1,.--,T) 2 P(p1,---5 Pn) P is n-ary predicate symbol, n \> 0.  115 

Formulas (1) are axioms of reflexivity, (2) are axioms of symmetry, (3) are axioms of transitivity, (4) and (5) are axioms of function and predicate sub- stitution respectively.  We designate by Eq’ the restriction of equality axioms to the free terms of a set of formulas T, i-e.:  Eq’ ={¢\|¢€ EqA FT(¢) C FT(T)} .  4.2.8 Lemma (Expansion of propositional interpretations). To every set of formulas T of £ and every propositional interpretation ZT for L such that Z \& Eq’ there is a T-equivalent canonical identity interpretation J. J is finite if the set FT(T) is finite. Every element of the domain of the structure of J is denoted by a term of FT(T) if the last set is not empty.  Proof. Take any T and any propositional interpretation Z such that ZF Eq’. We wish to define the identity interpretation 7 = (Q,M,a). We define the quantifier set Q as follows:  Q = {wv \| v is a quantifier formula and w € Z .}  We enumerate the set J = FT(T) by a possibly finite or even empty sequence: 00, 01, 02,.--  Clearly, the sequence has as many elements as is the cardinality of T. We define the domain D of the structure M with the help of a representant function r mapping the terms of £ to N by  r(r) =min{t\|r ET S\>TEtr=o;}.  This is a legal definition only if the argument set to min is non-empty for every T. That this is so can be seen by considering two cases. If 7 ¢ T then the argument to min is N and so r(r) = 0. If 7 € T then we have r = o; for some i and, since the reflexivity axiom T = 9; is in Eq’, we have TF t = 0. Hence the argument to min contains 7. We now define the domain D of J as the range of the function r:  D={r(r)\|7 is aterm of £}.  We have D C N and if T = then D = {0}. Otherwise o9 € T and r(oo) = 0 € D. Note that D has no more elements than T if T # 0 is finite. We prove  71,72 €T =\> (r(11) =r(m) OLE mM =7). (1)  Assume T,,72 € T. In the direction (=) also assume r(71) = r(72). From this we get ZF 7, =o; and ZF 72 = o; for some 7. Since o; € T, the symmetry axiom Tj = 0; — 0; = 72 and the transitivity axiom 7, = 0; — 0; = T2 \>  116 

T, = 7» are in the set Eq’. Thus also Z \& 7 = 7» holds. In the direction (\<=) assume J F 71 = 79. We have r(7,) = 7 for the least i such that o; € T and I 7 =o; holds. By appropriate symmetry and transitivity axioms in Eq? we obtain Z F 72 = 0;. We have r(72) = j for the least j \<4 such that oj € T and ZF T2 = a; holds. If 7 \<i then by symmetry and transitivity axioms in Eq! we would get ZF 7 = a; contradicting the definition of 7. Hence 1 = 7 and so r(71) = 1r(79).  We now take any n-ary function symbol f of £ and define the interpre- tation f“@ : D" % D of f as follows:  f“(di,...,dn) =r(f(m,---,7)) where r(71) =d),..., 7(t™m) = dn.  We must convince ourselves first that this is a legal definition. If n = 0 then we have f =r(f). Ifn \> 0 and T = 0 then, since D = {0}, we always have r(f(m1,.--,T™)) =0. Ifn \> 0 and T ¥ O then, since for every d € D we have d=r/(p) for some p € T, the definition determines f“(d,,...,d,) uniquely if the following holds:  r(n1) = r(p1) Nv APT) = 1 (Pn) \> F(T +++ Tn) = (F (P1s +++ Pn))  for every T1, ---, Tn; P1; ---; Pn in JT. From the assumptions we obtain TEm1 = pi,.--, ZF tT = pn by (1). Since the function substitution axiom 4.2.7(4) is in Eq’ and ZF Eq’, we have ZTE f(11,--.,t™) = f(pis---s Pn) and 80 "(f(T1,-++,Tm)) =f (Pis+++sPn)) by (1).  For every n-ary predicate symbol P of £ we define its interpretation PMc p”:  PM = {(r(m),---,7(™m)) \| ZE P(n,...,Tm) and 1,...,m €T}. We prove  Pis-s-sPn © T \> (ZF Plpi,--s Pn) \& (r(p1),-+-:7(Pn)) €P™) (2)  by taking any 1,...,n € J. In the direction (=) the property follows from the definition of P™ (even when n = 0 because p1,.--, Pn € T holds vacuously and we then have P™ = {()} = {0}). In the direction (\<=) assume (r(p1),---,7(pn)) € P™. If n = 0 then this means () € P™ and so ZF P. If n \> 0 we have r(m1) = r(p1), ---; T(™m) = 1(pn) and TF P(m,...,7) for some 71,...,T € JT. We get TF m1 =p1,..., ZF ™m = pn from (1). Since the predicate substitution axiom 4.2.7(5) € Eq’ and Z \& Eq’, we obtain TE P(p,---5 Pn):  The structure M is now defined and we define the assignment a: Nt D by a(i) = r(vu;). Thus also the identity interpretation 7 is defined and we prove:  TET Sr =r(r) (3)  117 

by induction on the construction of the term T. So assume r € T and continue by the case analysis of 7. If 7 = v; then v? = a(t) = r(v;). If = f(m,..-,T™m) then  I f(ti,---5T)% =f" (77... 757) =  Note that 7 is a canonical interpretation because if d € D then d = r(r) = r7 for some 7 which is one of o; € FT(T) if the last set is not empty. The lemma will be proved when we prove for every formula ¢ € T the  property: JFOEStTeKe.  So take any ¢ € T. Note that FT(¢) C T and proceed by induction on the construction of ¢. If ¢ is a quantifier formula then we have J F ¢ iff 6 € Q if @€ Tif TE ¢.  If 6 =7 = 7. then we must have T 40 and so JF 7 = 72 iff r7 = 137 iff, by (3), r(71) = r(72) iff, by (1), TE m1 = 72.  If ¢ = P(14,..-,7) then we must have T 4 9 and so J F P(m,...,7) iff (r7,...,7:7) € PN iff, by (3), (r(1),---,7(™m)) € P iff, by (2), TE  aon  P(11,.-+;Tn)- If 6 = $1 V dg then J F ¢1 V oo iff FJ F dy or J F oo iff, by IH, ZF dy or ZF do iff ZF do, V dg. The remaining cases are similar. oO  4.2.9 Quasitautological consequence. Fix a language £ and let T be a set of formulas from £. We define the relation ¢@ is a quasitautological consequence of T, in symbols T F; ¢, as follows:  TE,¢\<(ZET=TE @) for all identity interpretations T. We write F; ¢ for OF; ¢ and such a ¢ is quasitautology. Note that we have EF; ¢6@TZE ¢ for all identity interpretations Z.  4.2.10 Lemma. F; Eq.  Proof. Take any identity interpretation J = (Q,M,a) for £. We wish to prove Z F @ for an equality axiom @¢. If ¢ is a predicate substitution ax-  iom 4.2.7(5) then Z F ¢ iff from JT F 1 =p, ..., ZT —F Tm=Ppn, and TF P(n,.--,T) follows J F P(p1,...,pn). If the assumptions are sat- isfied we have ti? = pi, ..., TL = pz, and (77,...,77) € P™ and so (pt,---, pz) € P™, ie. JE P(pi,---; Pn).  The remaining cases are similar. oO  118 

4\.2.11 Theorem (Quasitautological reduction).  TE O3T, EE, o (1) TE OST, Eq, ¢. (2)  Proof. (1): Assume T F; ¢ and take any propositional interpretation Z such that JE TU Eq? holds. From Lemma 4.2.8 we obtain a T U {¢}- equivalent identity interpretation % and so J F T. We then get J F o from the assumption and ZF ¢@ from the equivalence.  (2): The direction (=) follows from (1) by weakening. In the direction (\<) assume T, Eq F, ¢ and take any identity interpretation Z for £ such that TF T holds. We have J F Eq by Lemma 4.2.10. From Lemma 4.2.6 we obtain an equivalent propositional interpretation 7. We thus have 7 F T'U Eq, we get J F ¢ from the assumption, and ZF ¢ from the equivalence. oO  4.2.12 Decidability of quasitautologies. One of the consequences of the Reduction theorem is that the predicate F; ¢ of being a quasitautology is decidable. We namely have  Fie Fp \\ Bal?! \> @. (1)  First note that the set FT(d) is finite and so there are only finitely many equality axioms with free terms from F'T'(¢) which means that the set Eq? is finite. We have F, ¢ iff, by 4.2.11(2), Eq F, ¢ iff, by Semantic deduction lemma 3.4.2, Fp AEq'?} — ¢.  4.2.13 Theorem. TF, ¢\> TF; ¢.  Proof. If T Fp @ holds then we have T, Eq Fp ¢ by weakening and TF, ¢ by 4.2.11(2). oO  4.2.14 Theorem. For every set of formulas T of some L and for every identity interpretation ZT for £L there is a T-equivalent canonical identity in- terpretation J. Every element of the domain of the structure of J is denoted by a term of FT(T) if the last set is not empty.  Proof. For a given identity interpretation Z for £ we obtain an equivalent propositional interpretation Z,; by Lemma 4.2.6. By Lemma 4.2.10 we have TI Eq and so Z; F Eq’ by the equivalence. From Lemma 4.2.8 we obtain a T-equivalent canonical identity interpretation JZ such that every element of the domain of the structure of 7 is denoted by a term of FT(T) if the last set is not empty. oO  4.3 Identity Tableaux  4.3.1 Identity tableau expansion rules. Fix a language £. All expansion rules for identity tableaux are unary with premises in assumptions. In the  119 

following τ , τ1, . . . , τn, ρ1, . . . , ρn are arbitrary terms. Reflexivity, symmetry, and transitivity rules are in that order: 

τ = τ (Refl) 

τ1 = τ2 

τ2 = τ1 (Sym) 

τ1 = τ2 τ2 = τ3 

τ1 = τ3 (Trans) 

Function substitution rules are for every n-ary function symbol f of L with n \> 0 as follows: 

τ1 = ρ1 · · · τn = ρn 

f(τ1, . . . , τn) = f(ρ1, . . . , ρn) (Fsub) 

Predicate substitution rules are for every n-ary predicate symbol P of L with n \> 0 as follows: 

τ1 = ρ1 · · · τn = ρn P (τ1, . . . , τn) P (ρ1, . . . , ρn) 

(Psub) 

We can see that every identity rule corresponds to exactly one equality axiom. 

4\.3.2 Proofs with identity tableaux. An identity tableau π for a se- quence of signed formulas ∆ from axioms in T is called an identity tableau for ∆ from axioms T . If π is closed then we assert this by writing π : T \`i \[∆\]. When ∆ ≡ φ∗ then we say that π is an identity tableau proving φ from ax- ioms T and write it as π : T \`i φ. We use additional abbreviations similar to those discussed in Par. 3.2.4. 

4\.3.3 Theorem (Admissible expansion rules in identity tableaux). All rules proved admissible for propositional tableaux in Sect. 3.3 are also admissible in identity tableaux. 

Proof. Inspection of the proofs of admissibility of expansion rules in Sect. 3.3 reveals that the proofs remain correct also for identity tableaux, the presence of identity rules does not affect the proofs. 

The only potential problem could be in the admissibility of cuts on propo- sitional atoms (see Lemma 3.3.8) because we now have identity rules on propositional atoms τ1 = τ2 in assumptions. Fortunately, the elimination of cuts on such formulas removes the goals τ1 = τ2∗ which are not affected by the identity expansion rules. ut 

4\.3.4 Lemma. \`i Eq. 

Proof. An axiom of reflexivity 4.2.7(1) has the following proof: 

τ = τ∗ τ = τ (Refl) 

120

An axiom of predicate substitution 4.2.7(5) has the following proof:  T= pPiA-+: AT = Pn A P(1,---,Tnr) \> P(p1,---; Pn)\*  M1 =P (GA1) Tn = Pn (GAn) P(t1,.--,Tn) (GAn41) P(pi,---;Pn)  (Psub) Remaining axioms have similar proofs. oO  4.3.5 Lemma (Introduction of identity rules).  n:T, Eq, \[A\] \> TF; \[Al\]  Proof. By induction on the structure of the tableau 7. Assume 7 : T, Eq Fp \[A\] and consider the form of z. If 7 is empty then we trivially have T +; \[A\].  If the first expansion in 7 is by a propositional rule, say (A\*), then ¢1 A o2\* € A and 7 has a form shown in the following on the left:  A A A (Mm) (Ax) pix box o1\* oo\* TT T2 TT eh  We obtain identity tableaux a; and 74 such that a, : T +; \[A,¢1\*\] and 15: T+; \[A, 62x\] by two TH’s and construct the closed identity tableau for A from axioms T shown on the right. The remaining expansions by propositional rules and by axiom rules from T are similar.  If the first expansion in 7 is by an axiom rule for ¢ € Eq then 7 has a form shown in the following on the left:  A eee Ty Th  We obtain an identity tableau 7} such that 7; : TF; \[A,¢\] by IH, note that -; @ by Lemma 4.3.4, and construct by a lemma rule the closed identity tableau for A from axioms T shown on the right. oO  121 

4\.3.6 Lemma (Elimination of identity rules). nm: Th; \[A\] \> T, Eq Fy \[Al .  Proof. By induction on the structure of the tableau 7. Assume a: T+; \[A\] and consider the form of 7. If 7 is empty then we trivially have T +, \[A\] and we obtain T, Eq, \[A\] by weakening.  If the first expansion in 7 is by a propositional rule, say (—), then ¢, \> 2 € A and a has a form shown in the following on the left:  A A oO  . () b2 ox 2 pix 72 T7 1 Th  We obtain propositional tableaux a and m4 such that 7: T, Eq kp \[A, 1 \*\] and 75: T, Eq Fp \[A, ¢2\] by two IH’s and construct the closed propositional tableau for A from axioms T, Eq shown on the right. The remaining propo- sitional and axiom expansions are similar.  If the first expansion in 7 is by a reflexivity rule then 7 has a form shown in the following on the left:  A A T=T (Refl) \> rT=T (Az)  TM Ty  We obtain a propositional tableau m{ such that a, : T, Eq kp \[A,r =7\] by IH and construct the closed propositional tableau for A from axioms T, Eq shown on the right.  If the first expansion in 7 is by a function substitution rule then 7 has a following form:  A  f(T1,+++5T) = f(Pis+++,Pn)  (Fsub) m4  where 7\] = (1,---,;Tn =Pn EA  We obtain a propositional tableau 7} such that  m2 T, Eq' p (A, f(t1,---,7) = f(p1,---; Pn)\|  by IH and construct the following closed propositional tableau for A from axioms T, Eq:  122 

A s.t. T) = P1,---;Tn =Pn EA  (—)  f(t1,+++5Tr) = f(P1,-++5 Pn) T1 = pr N-++ AT = Pn\* (GA) x TL= Pik ts Tn = Pn The remaining identity expansion rules are similar. oO  4.3.7 Theorem (Introduction/elimination of identity rules). ThKiO\<T,Eqty?¢.  Proof. In the direction (=\>) assume 7: T' +; ¢, i.e 7: T +, \[bx\], and obtain T, Eq Fp \[@\*\], ic. T, Eg Fp ¢, by Lemma 4.3.6.  In the direction (\<) assume T, Eq Fp ¢, ie. T, Eq Fp \[b\*\], and obtain T +; \[ox\], ie. T+; o, by Lemma 4.3.5. Oo  4.3.8 Corollary (Soundness and completeness of identity tableaux). For any fromula @ and a set of formulas T from L we have  TK ¢ Thi {4 4.2.11(2) dN) 4.3.7 T, Eq Fp ¢ 3.5.8 T,Eqtpo q  4.3.9 Decidability of quasitautologies revisited. Property 4.2.12(1) re- duces the problem of deciding whether a formula ¢ of some £ is quasitau- tology to the problem of deciding whether the formula AEq'?! \> gisa tautology. This decision procedure can be called the method of associates because the conjunction of equality axioms AEq'?} is an identity associate of ¢. Quantifier associates were introduced by R. Smullyan \[21\].  Lemma 4.2.6 and property 4.2.11(1) give us another method of deciding quasitautologies: test Z F ¢ in all finite identity interpretations 7 for a finite language consisting of function and predicate symbols in ¢. Note that the quantifier sets Q of such interpretations can be restricted to subsets of finitely many quantifier formulas among FPA(¢). Also note that there are only finitely many assignments a to be considered because the only values which matter are the finitely many values a(z) where v; € FT(¢). The formula ¢ is a quasitautology iff 7 F @ for all such finite identity interpretations 7. Such a test for quasitautologies seems to be much less convenient than the method of associates. We mention it here because this is the method used by Boolos and Jeffrey \[3\] to recognize proofs in their proof calculus for predicate logic.  123 

Identity tableaux offer the most convenient test for quasitautologies. We call a branch ∆ of an identity tableau identically complete if whenever an identity rule has its premises ∆1 in ∆ then also its conclusion φ is an as- sumption in ∆ provided FT (φ) ⊆ FT (∆1). The reader will note that the last condition can be violated only by function substitution rules whose conclu- sions can introduce new terms into identity tableaux. 

In order to test whether φ is a quasitautology we construct a tableau for φ∗ and in every open propositionally complete branch we saturate the branch by the conclusions of finitely many identity rules which can be applied on the branch and which do not introduce new terms. If all branches close then φ is a quasitautology by Corollary 4.3.8. If there is an open propositionally and identically complete branch then we construct a propositional interpretation I by collecting all propositional atoms in the assumptions of the branch. We have proved in Par. 3.2.8 that we have I 2 φ and I ² ψ for all assumptions ψ in the branch. Now, the branch is identically complete, and so we must have I ² Eq{φ}. But this means that Eq{φ} 2p φ holds and so we have 2i φ by 4.2.11(1). 

Identity tableaux facilitate also a semidecidable test for quasitautological consequence from decidable axioms T : T ²i φ. This is an extension of the procedure described in Par. 3.5.9 where we identically complete every open branch which is propositionally complete just before we add the next axiom to the assumptions of the branch. By the same reasoning as above we can show that if there is an open branch which is propositionally, identically, and axiomatically complete then we have a propositional interpretation I such that I ² T ∪ EqT∪{φ} and I 2 φ. Hence I witnesses T,EqT∪{φ} 2p φ and we get T 2i φ by 4.2.11(1). 

124

5\. Quantification Logic 

In this section we investigate the notion of logical consequence where a formula φ follows from a set of axioms T by the laws of logic alone. This means that φ follows from T because of the properties of propositional connectives, identitity relation, and quantifiers and without taking into considerations the extralogical properties of its function and predicate symbols beyond those which are captured by the axioms T . 

5\.1 Some Syntactic Concepts 

In contrast to the preceding chapters where the variables played no special role we will need in this chapter to pay the attention to the variables occurring in formulas of first order languages. 

5\.1.1 Free variables. Free variables of a set of formulas S of a language L are variables x occurring in the formulas of S outside of quantifiers ∃x and ∀x. This is made precise by a metamathematical function FV (α) defined on terms, formulas, and sets of formulas to yield the set of free variables of α. The function FV satisfies the set identities given in Fig. 5.1. 

5\.1.2 Sentences. A term τ (formula φ) of some L such that FV (τ) = ∅ (FV (φ) = ∅) is closed and open otherwise. Closed formulas are called sentences. Sets T of closed formulas are closed. Universal instantiation of a formula φ is any sentence ∀x1 . . . ∀xnφ such that x1, . . . , xn ∈ FV (φ). We usually denote by ∀φ any universal instantiation of φ. 

A variable x is bound in a formula φ if ∃xψ or ∀xψ occurs as a subformula in φ. 

5\.1.3 Substitution. If α is a term, formula, or a set of formulas of a lan- guage L then we will denote by αx\[τ \] the application of the ternary meta- mathematical substitution function which yields term, formula, or set similar to α but with every free occurrence of the variable x replaced by the term τ . The substitution function is defined to satisfy the term identities given in Fig. 5.2.

FV (x) = {x} FV (f(τ1, . . . , τn)) = FV (τ1) ∪ . . . ∪ FV (τn) 

FV (τ1 = τ2) = FT (τ1) ∪ FT (τ2) 

FV (P (τ1, . . . , τn)) = FV (τ1) ∪ . . . ∪ FV (τn) 

FV (∀xφ) = FV (φ) \\ {x} FV (∃xφ) = FV (φ) \\ {x} 

FV (\>) = ∅ FV (⊥) = ∅ 

FV (¬φ) = FV (φ) 

FV (φ1 ∨ φ2) = FV (φ1) ∪ FV (φ2) 

FV (φ1 ∧ φ2) = FV (φ1) ∪ FV (φ2) 

FV (φ1 → φ2) = FV (φ1) ∪ FV (φ2) 

FV (φ1 ↔ φ2) = FV (φ1) ∪ FV (φ2) 

FV (T ) = ⋃ {FV (φ) \| φ ∈ T} . 

Fig. 5.1. Function yielding sets of free variables 

yx\[τ \] ≡ { 

τ if y ≡ x 

y otherwise 

f(τ1, . . . , τn)x\[τ \] ≡ f(τ1x\[τ \], . . . , τnx\[τ \]) 

(τ1 = τ2)x\[τ \] ≡ τ1x\[τ \] = τ2x\[τ \] 

P (τ1, . . . , τn)x\[τ \] ≡ P (τ1x\[τ \], . . . , τnx\[τ \]) 

(∀yφ)x\[τ \] ≡ { ∀yφ if y ≡ x 

∀yφx\[τ \] otherwise 

(∃yφ)x\[τ \] ≡ { ∃yφ if y ≡ x 

∃yφx\[τ \] otherwise 

\>x\[τ \] ≡ \> ⊥x\[τ \] ≡ ⊥ ¬φx\[τ \] ≡ φx\[τ \] 

(φ1 ∨ φ2)x\[τ \] ≡ φ1x\[τ \] ∨ φ2x\[τ \] 

(φ1 ∧ φ2)x\[τ \] ≡ φ1x\[τ \] ∧ φ2x\[τ \] 

(φ1 → φ2)x\[τ \] ≡ φ1x\[τ \] → φ2x\[τ \] 

(φ1 ↔ φ2)x\[τ \] ≡ φ1x\[τ \] ↔ φ2x\[τ \] 

Tx\[τ \] ≡ {φx\[τ \] \| φ ∈ T} . 

Fig. 5.2. Substitution function 

126

For reasons discussed in Par. 5.2.11 we will use the the substitution func- tion αx\[τ \] only with terms τ which are free for x in α meaning that no variable occurring in τ becomes bound in the result of the substitution. In other word- s, whenever the recursion reaches a quantified formula, say, (∀yφ)x\[τ \] with y 6≡ x we have y /∈ FV (τ). Note that a closed term τ is free for x in any φ. 

We now agree on a convention that whenever we will write αx\[τ \] without explicitly mentioning that τ is free for x in α this restriction will be tacitly assumed. 

5\.1.4 Indication of variables. We will often indicate by writing φ\[x\] that the variable x is possibly free in φ. When we later write φ\[τ \] we are designating the same formula as φx\[τ \]. 

The method of indication is useful when we indicate more variables at once: φ\[\~x\]. In such situations we always tacitly assume that the n-tuple of variables \~x consists of pairwise distinct variables. By writing φ\[\~τ \] we designate the same formula as φx1 \[τ1\] . . .xn 

\[τn\]. 

5\.1.5 Cantor’s diagonal pairing function. We will need the well-known Cantor’s ‘diagonal’ pairing function J defined as 

J(x, y) = (x + y + 1)·(x + y) 

2 + x . 

It is not hard to see that every natural number z can be uniquely written as z = J(x, y). Moreover, for any numbers x and y the value J(x, y) can be efectively computed and also for a given number z the unique numbers x and y such that z = J(x, y) can be effectively computed. 

5\.1.6 Witnessing extensions of first-order languages. Let L be a first- order language. We denote by Lc its witnessing extension by the addition of Henkin (witnessing) constants ck where k = J(i + 1, j) for some i, j. This ck is said to be of rank (i + 1). Henkin constants are always chosen as new constants not occurring in L. 

A formula φ of Lc is of rank i if φ is of L and i = 0 or if for some Henkin constant ck with rank i we have ck ∈ FT (φ) and no Henkin constant of higher rank is in FT (φ). 

We now assign the Henkin constants to the existentially quantified sen- tences of Lc as follows. We can clearly enumerate the formulas of any language into a sequence. Moreover, by ommiting certain formulas, we can also enu- merate for every number i all existentially quantified sentences of Lc of rank i: 

ψi 0 ψi 

1 ψi 2 . . . , (1) 

i.e. sentences where ψi j ≡ ∃xφ for some φ of rank i from Lc. We fix one such 

enumeration relatively to every L (and thus also relatively to Lc) and i. The Henkin constant cJ(i+1,j) is said to belong to the sentence ψi 

j . 

127

5\.1.7 Quantifier axioms. Fix a language L and consider its witnessing extension Lc. We call the sentences 

φx\[τ \] → ∃xφ (1) ∀xφ → φx\[τ \] (2) 

where ∃xφ and ∀xφ are sentences of Lc and τ a closed term of Lc instantiation axioms. 

We call the sentence 

∃xφ → φx\[ck\] (3) 

where ∃xφ is a sentence of Lc and ck the Henkin constant belonging to it the (Henkin) witnessing axiom for ∃xφ. 

We call the sentence 

φx\[ck\] → ∀xφ (4) 

where ∀xφ is a sentence of Lc and ck the Henkin constant belonging to the sentence ∃x¬φ the (Henkin) counterexample axiom for ∀xφ. Witnessing and counterexample axioms are together called Henkin axioms. We designate the witnessing axioms by Ha. 

Note that the Henkin axioms for sentences ∃xφ and ∀xφ of rank i do not need to have ranks i + 1 because it can happen that x /∈ FV (φ). 

The set Qa of quantifier axioms is the set of sentences of Lc consisting of the instantiation and Henkin axioms. 

5\.2 Logical Consequence 

5\.2.1 Interpretations. An interpretation I for L is a pair 〈M, a〉 where M is a structure for L with domain D and a is an assignment in M. 

Denotations τI of terms τ of L are defined exactly as in Par. 4.2.4. For the definition of the satisfaction relation we will need an operator 

taking the assignment a, variable x, and d ∈ D to the assigment designated by a( d 

x ) and such that 

a( d x )(i) = 

{ d if x ≡ vi 

a(i) if x 6≡ vi. 

For the above interpretation I we designate by I( d x ) the interpretation 

〈M, a( d x )〉. 

The satisfaction relation I satisfies φ, written as I ² φ, is similar to the satisfaction relation for identity interpretations (see Par. 4.2.5) when φ is an atomic or propositional formula. For quantifier formulas we define the relation as follows: 

128

TE Vad @T(2)F ¢ for alld € D TF lrg \& T(2)F ¢ for some d € D.  Interpretations Z for £, such that J F Ha are called Henkin interpreta- tions.  5.2.2 Agreement of interpretations. If S is a set of terms then two interpretations J = (M,a) and J = (M, b) sharing the same structure agree on S if the assignments a and b agree on S, i.e. if for every variable v; € S we have a(i) = b(i).  5.2.3 Equivalence lemma. \[If the interpetations ZT and J for £L agree on  1. FV(r) thent? =r%, 2. FV(L) thenT =r J.  Proof. 1) Assume ZT = (M,a) and J = (M,b) and prove the property by induction on the construction of 7. If T = v; then v7 = a(i) = b(i) = vy. If T=f(t,.--,T7) then  f(tis---s Ta)? =f! (CF... 77) PM (7... 7) = f(t1,---,T)% 2) Take any ¢ € T and prove TEOS IF 6 forT and J agreeing on FV(T)  by induction on the construction of ¢. If 6 = 7, = 72 then we have ZT F T, =T. iff r? = rH iff, by 1), Tr = TH iff J — 7, = 7). The case when @ = P(m,..-.,7) is similar.  If ¢ = 4x¢) then ZF Ard, iff Z(4) F ¢; for some d € D where D is the domain of the structure shared by Z and J iff, by IH, 7(4) F ¢1 for some dé Diff J F dx). The case when ¢ = Vx, is similar.  If 6 = 7g, then TF 7, iff TF dy iff, by IH, J F 4, iff J F ad,. The remaining propositional cases for ¢ are similar.  5.2.4 Substitution lemma. For every interpretation Z for £, any terms f1, P2, any formula ¢, and any term 7 free for x in ¢ we have:  (prelos))? =p, (1) TF ¢\[7T\] @1(\~ Eo. (2)  Proof. Take any interpretation ZT = (M,a) and let D be the domain of M. (1): By induction on the construction of p,. If p; = v; then if v; = x we have  (vr\[po))® = pf = a( 8 )(i) =a)  129 

and if v; 4 x we have  (vielp2\])” = v7 = al 2 )(i) = 9; If p: = f(n,.--, 7) then (f(t1,---s Tr) lP2l)” = (f(tielea\],---.Tr2\[P2\]))\* = Ff“ ((rialp2l)?,-.-,(trelp2))7) = pene @?) = Fy... ta)O  (2): By induction on the construction of ¢. If 6 = 7, = 72 then we have TF (m1 =72),\[7\] iff ZF t12\[7\] = 722\[7\] iff (e\[7\])7 = (t22\[7\])7 iff, by (1),  (77 L(77 7! x? = 7! 2? iff Z(77 Er = T2. If@ = P(1,.-.,Tm) thenZF P(1,...,m™),.\[7\] FZ \& P(t12\[7\],.--, ma\[r\])  I(T ) T, x  L(t Cen ) € P™ iff  iff ((T12\[T\])7,---, (Ta\[T\])7) € P™ iff, by (1), (74 L(\*) F P(t1,..-,T7n)-  If @ = Syd, then if x = y then we have Z F (Sy¢1),,\[T\] iff ZF Syd, iff by Lemma 5.2.3, since Z and Z(7, ) agree on FV (Ay¢1), Z(\*, ) F Syd.  x  If x # y then we have ZF (Ay¢@1),,\[7\] iff ZF Sydi,\[7\] iff T(¢4) F ¢4,\[T\]  for some d € D iff by IH, since 7 is free for x in ¢), T(4)(.7)) E ¢, for some d € D iff, by Lemma 5.2.3, since y ¢ FV(r), Z(#)(\* ) F ¢1 for some déeD iff Z(77 )(4) F ¢, for some d € D iff Z( 7 ) F dydy. If é = Vyd1 then the proof is similar.  If @ = ¢1 V dg then we have ZF (¢1 V ¢2),,\[7\] iff ZF ¢1,\[7\] V $2, \[7\] iff TE ¢1, \[7\] or ZF ¢2,,\[7\] iff by TH, since 7 is free for x in ¢1, do, T( vo) E d4 or T(%)) F @ iff Z(7) F $1 V dg. The remaining propositional cases are similar. oO  5.2.5 Models. Let M be a structure for £ with a domain D and ¢\[7\| a formula of £ with all of its free variables among the indicated ones. By Lemma 5.2.3 any two assignments in M a and b which coincide on Z are such that  (M, a) F 9 = (M,b) F  and so for d € D we can write M F @\[d\] as an abbreviation for (M,a) F ¢ where a is any assignment such that a(#1) = di, ..., a(@n) = dn. We define MF ¢ as  =  ME ¢\[d\| for alldeD.  If ¢ is a sentence then we have M F ¢ iff (M,a) — ¢ for some assignment a (and equivalently for all assignments a) and in that case we say that M is a model of ¢, or that ¢ is true in M.  130 

For a set T of formulas of £ we write MF T for MF ¢ for all ¢ € T. M is a model of a set T of sentences of £ if MF T. T is satisfiable if it is true in some structure, i.e. if T has a model.  5.2.6 Expansions of structures. Let £; be an extension of a language £ and let M be a structure for £ with a domain D. The structure NV for Ly is an expansion of M if the domain of NV is D and the interpretation in V of every function and predicate symbol from £ is the same as in M.  The interpretation 7 for £1 is an expansion of the interpretation Z for £ if the structure of 7 is an expansion of the structure for Z and both interpretations have the same assignments.  Two interpretations Z for £ and J for £, where L, is an extension of L are equivalent on T, which we write as TZ =r J, if T is a subset of formulas of Land ZTF@OS TIE ¢ for all d€ T. We write TZ =; J if TZ and J are equivalent on the formulas of L.  5.2.7 Expansion theorem. If J for £1 is an expansion of TZ for L then  pF —7t for all terms Tt of L (1)  Proof. Assume that 7 = (Na) with the domain D and Z = (M,a). (1): By induction on the construction of r. If 7 = v; then vy  \_ LT If 7 = f(n,..-,7) for f in £ then  a(t) = v7.  f(tiseestm)7 = PNY... 72) FPN tT) =  mon  f(rd,...,77) =f (t1,---,T)? .  (2): The property follows from @ in £; for all J for £ and ZT for £; s.t. J expands T \>= (JE GSTE 6)  proved by induction on the construction of ¢. If ¢ = 7, = 7) then we have JE m =72 iff r = ry iff, by (1), 2 = 7H iff TE 7 = T. The case when @ = P(m,...,T) is similar.  If ¢ = Ard, then J F Ard, iff J(4) F d; for some d € D where D is the shared domain iff, by IH, Z(¢) F $1 for some d € D iff I F Jax). The case when ¢@ = Vx¢, is similar.  If 6 = 7g, then J F 7d, iff J F oy iff, by IH, ZF dy, iff ZF ad,. The remaining propositional cases for ¢ are similar. oO  5.2.8 Lemma (Reduction to identity interpretations). To every in- terpretation T for £L there is an equivalent identity interpretation J for L.  131 

Proof. Take any interpretation J = (M,a) for £. We construct the identity interpretation 7 = (Q,M,a) by defining  Q = {wv \|ZF w for quantifier formulas 7} .  Note that the assignment a in Z is also an assignment in 7 because both interpretations share the structure M. For the same reason we have  ti =7t (1)  for every term T of L.  We prove the equivalence of 7 and Z by proving J F 6 S TF o by induction on construction of formulas ¢ of £. If ¢ is a quantifier formula then JF oPOC QTE df d= = then JEN =m iff rY =e iff, by (1), 72 = 7% iff TF 1 =70. If 6 = P(n,..., Tn) then J F P(n,.--,7) iff (77,...,77) © P™ iff, by (1), (77,...,77) © P™ iff TE P(r4,..., 7). If b = 61 V ¢2 then we have J F ¢1 V do iff J FE oO; or JF oo iff, by IH, ZF dy or ZF do iff ZF 1 V dg. The remaining cases are similar. oO  5.2.9 Logical consequence. Fix a language £ and let T be a set of formu- las from £. We define the relation ¢ is a logical consequence of T, in symbols TF @, as follows:  TE¢S(ZET STE 46) for all interpretations Z. We write F ¢ for 0F ¢ and such a ¢ is a valid formula. Note that we have FE ¢@TZE ¢ for all interpretations 7.  If T is closed then we have TF ¢ iff ME @ for all models of T.  The following lemma asserts that the instantiation axioms are valid and that Henkin counterexample axioms are logical consequences of Ha. Hence, Qa is staisfied in every Henkin interpretation.  5.2.10 Lemma.  F ¢,\[T\] \> dee T, 6 of any L, T free for x ind (1) F Vad \> ¢.\[T\] T, @ of any L, T free for x ing (2) Ha® Qa. (3)  Proof. (1): Take any interpretation Z for £ with the domain D and any formula ¢,\[7\] — Jad@ satisfying the assumptions. Assume ZT F ¢,\[7\] and obtain Z( T) E @ by Lemma 5.2.4. Since 7? € D we get TF Ix¢.  (2): the proof is similar to that of (1).  132 

(3): Take any Henkin interpretation Z for £, with the domain D and any w € Qa. If w € Ha we have T F yw trivially and if w is an instantiation axiom we get the same by (1) or (2) because the term 7 is closed and so it is free for x in ¢. If \~ is a counterexample axiom of a form ¢,\|\[c\] — Vad then drag — 7¢,\[c\] € Ha and so IT F Arg — 7¢,\[c\]. We now assume IF ¢,\[c\| and obtain Z ¥ 7¢,\[c\| and then J ¥ Jr. But then Z(7) # 74, ie. Z(¢)F ¢, for alld € D and so TF Vad. Oo  5.2.11 Remark. Why did we impose the freeness restriction on substitu- tions into quantified formulas. We did this because we wish the instantiation formulas 5.2.10(1) and 5.2.10(2) to be valid.  For instance, consider the formula dyy 4 x. We have (dyy 4 z),\[y\] = dyy # y. The formula Vatyy 4 « \> (dyy 4 x), \[y\], ie. the formula  Vetyy Fu— dyy Fy  has the form of 5.2.10(2) but the term y is not free for x in yy 4 x. This violation of the substitution condition prevents the formula from being valid. This can be seen by noting that ZF Vetyy 4 x holds for any interpretation T with at least two elements in its domain whereas ZT F dyy 4 y is satisfied for no interpretation Z.  5.2.12 Lemma (Henkin expansion). For every interpretation I for £L there is a Henkin expansion J for Le.  Proof. Take any interpretation ZT = (M,a) for £ and let D be the domain of M. We wish to construct the interpretation 7 = (NV, a) as an expansion of T satisfying Ha. To that end we define for i \> 0 a sequence of interpretations J; = (Nj, a) with the structures Nj; for languages £;. We define Lp = £L and £i41 as the extension of £; with the Henkin constants of rank 7 + 1. Thus £; contains all Henkin constants with ranks \< 7. We define the structures N; and thus also the interpretations J; by induction on 7 in such a way that Ji+1 will be an expansion of J and for all Henkin constants c of rank i + 1 belonging to sentences 4r¢ of £; of rank i we will have  Firi F Arb \> bale\] - (1)  In the base case we set No = M and so J = TZ. In the inductive case we take any Henkin constant c of rank 1+ 1. The constant belongs to a sentence dad of £; which is of rank 7 and we consider two cases. If 7% F dxd holds then J;(¢) F ¢ for some d € D and we interpret Nivt = d. If J, ¥ jr¢ then we interpret cM+1 = d where d is arbritrary element of D. This ends the definition of N;41. The interpreation J,41 is an expansion of J; and they are equivalent on the formulas of £; by Lemma 5.2.7. For every Henkin constant c if rank 7+1 we prove (1) by considering the same two cases again. If J; F Jr¢ holds then we have Jj41 — dr¢ and Ji+1( oN ) E ¢ by the interpretation of c.  133 

We obtain Ji41 F ¢z\[c\] by Lemma 5.2.4. This satisfies (1). If % - Jrd then we have J;41 \~ dx¢ and so (1) holds again.  With the construction of interpretations 7; done we note that whenever 0\<i\<j the language £; is an extension of £;, J; is an expansion of /, and the interpretations are equivalent on £; by Lemma 5.2.7. Thus 7; satisfies the axioms of Ha whose Henkin constants have ranks \< 7. We also have J; =; T. We now construct the interpretation 7 = (NV,a) for £, as an expansion of T where the structure NV is an expansion of M interpreting Henkin constants of rank 7 in the same way as J;. Thus J =c TZ and, since J is also an expansion of every J; and thus J =c, J; by Lemma 5.2.7, we have 7 F Ha. oO  5.2.13 Lemma (Expansion of identity interpretations). For every L and every identity interpretation I for £L. such that TF Qa there is a canon- ical Henkin interpretation J for L. equivalent to Z on the sentences of Le.  Proof. Take any identity interpretation Z for £, such that ZF Qa. Let T be the set of sentences of £,. We obtain a T-equivalent canonical identity interpretation Z; = (Q,M,a) for a structure M with the domain D and an assignment a by Lemma 4.2.14. The set FT(T’) is not empty because it contains at least the Henkin constants and its elements are closed terms. Thus for every d € D there is a closed term tT € FT(T) such that 77! = d. Since Qa C T we have Z; F Qa. We construct the interpretation 7 = (M, a) which is canonical because  t= 7" (1) holds. By induction on the structure of formulas ¢ we prove  GETS(JFOSTLE S$). (2) Thus assume ¢ € T and if ¢ = 7 = 72 then we have J F 7, = 72 iff 77 = 13! iff, by (1), 7? = 73° iff ZT) FE 1 = 72. If ¢ = P(m,...,T™) then we have J F P(1,...,T) iff (777,...,7,7) € P™ iff, by (1), (77',...,721) € P™ iff Z, F P(n,...,7)-  mon  If ¢ = Jx¢ then if 7 — Ard, holds we have J(¢) F ¢; for some d € D. There is a closed term 7 of £, such that T7 ® 7% = dand so T( 17 )F oy and we obtain 7 F ¢1, \[7\] by Lemma 5.2.4. Because ¢),\[7\] € T we obtain TF ¢1,\[7\] by IH and, since ¢1,,\[T\] — 3rd € Qa, we get TZ, F Ard.  Vice versa, if Z; F Jad, holds then we have 3rd — ¢1,\[c\] € Qa for the Henkin constant c belonging to dard. From TZ, F Jr¢é \> ¢1,\[c\] we get T, F ¢1,\[c\] and then 7 F ¢1,,\[c\] by IH. Hence I(e) F @, by Lemma 5.2.4 and so J F dx@, holds. The case when ¢ = Vx@, is similar.  If @ = $1 Vda then JE 1 V do iff TE Gy or JE oy iff, since 1, do € T, we have by IH Z; F ¢, or Z1 F ¢2 iff Z, F @1 V bg. The remaining cases for ¢ are similar.  134 

We have Z =r TZ, from the construction of Z,;. From (2) we get Zj =r J and so IT =r J holds.  The reader will note that the use of Henkin axioms in the inductive proof of (2) works only when T consists of sentences and so the lemma cannot be extended to the formulas of L£. Oo  5.2.14 Theorem. If Z is an interpretation for £L then there is a canonical interpretation J for £L equivalent to I on the sentences of L.  Proof. For a given interpretation ZJ for £ we obtain a Henkin expansion T, for £L. by Lemma 5.2.12 and we have Z; =- Z by Lemma 5.2.7. We then get Z; F Qa by 5.2.10(3) and obtain an identity interpretation Z2 for L,. equivalent to Z; by Lemma 5.2.8. Since then Zz F Qa holds, we get a canonical interpretation 7 for £, equivalent to Zz on the sentences of £L, by Lemma 5.2.13. Since the sentences of £ are sentences of £,, the interpretation T is equivalent to 7 on the sentences of L. oO  5.2.15 Theorem (Henkin reduction). If ¢ andT consist of sentences of L then  TEO@ST,Qaki¢. (1)  Proof. In the direction (=) assume T F ¢ and take any identity interpre- tation Z for £, such that J F TU Qa. There is an interpretation J for L, equivalent to Z on the sentences of £, by Lemma 5.2.13. Since the sentences of £ are sentences of £,, we have J F T and hence J F ¢ from the assumption. But then ZF @ by the equivalence.  In the direction (\<=) assume T, Qa F; ¢ and take any interpretation T for £ such that Z — T holds. There is a Henkin expansion Z, for L. by Lemma 5.2.12 which is equivalent to Z on the formulas of £ by Lemma 5.2.7. Thus Z,; — T and we also have Z; F Qa by 5.2.10(3). There is an identity interpretation 7 for £, equivalent to Z; by Lemma 5.2.8. Hence J — TU Qa and we get J F ¢ from the assumption and ZF @ by the equivalence. oO  5.2.16 Theorem. If ¢ and T consist of sentences of £L then  TE ¢\>TKEo.  Proof. If T —; ¢ holds then we have T, Qa F; ¢ by weakening and TF ¢ by Thm. 5.2.15. oO  135 

5\.2.17 Theorem (Generalization). If T is closed and ¢ a formula of some L then  TEOSTEVO.  Proof. The theorem is proved by a repeated application of an auxiliary as- sertion TEdSTEVa«xed  which is proved in the direction (—) by assuming T F ¢ and taking any interpretation for £ with a domain D such that J F T. For any d € D interpretations Z( 2) and Z agree on F'V(T) because T is closed and so Z(¢@) F T by Lemma 5.2.3. Thus Z(¢)  ¢ from the assumption and so Z F Vad.  In the direction (\<\~) we assume T F Vad and take any interpretation for £ such that JF T. Thus ZT F Vx¢ and, since ¢,\[z\] = ¢, we obtain ZF ¢ by 5.2.10(2). o  5.2.18 Theorem (Skolem-Léwenheim). Jf T is a set of sentences of some £L and ¢ a formula of £L then  1. if T is satisfiable then T has a numerical model, 2. TE o iff o is true in all numerical models of T.  Proof. 1) If T is is satisfiable then it has a model M, i.e. MF T. Since T is a set of sentences we have (M,a) — T for any assignment a in M. There is a canonical interpretation J such that 7 — T by Thm. 5.2.14. Thus J = (N, b) for a numerical structure VV and an assignment b in NV’. But then VF T.  2) The direction (—) is trivial. In the direction (-) assume T ¥ ¢. Thus T has a model M in which M F ¢, i.e. M F 7AVd by Thm. 5.2.17 and so there is a numerical model NV of T,=V¢ by 1). Thus WV is a model of T s.t. N Ed, ie. NF ¢. Oo  5.2.19 Import of Skolem-L6wenheim’s theorem. This paragraph is not yet finished. Numeric structures are the most important ones. The next two parts of this text are devoted to the study of theorems true in the most important numeric structure: the standard model of Peano Arithmetic.  5.3 Quantification Tableaux  5.3.1 Tableau expansion rules. Fix a language £. All expansion rules for (quantifier) tableaux are unary. Quantifier instantiation rules are  Vago da@x  for all formulas ¢, variables x, and terms 7 free for x in ¢. Eigen-variable rules are  136 

∃xφ 

φx\[y\] (∃) ∀xφ∗ 

φx\[y\]∗ (∀∗) 

for all formulas φ, variables x, and eigen-variables y free for x in φ. The reader will note that the instantiation rules corrrespond to the valid 

formulas 5.2.10(2)(2) and the eigen-variable rules to Henkin axioms. 

5\.3.2 Proofs with tableaux. A tableau π for a sequence of signed formulas ∆ from axioms in T is called a tableau for ∆ from axioms T if every eigen- variable y in π satisfies the eigen-variable condition that it is not free in any signed formula in the branch above the conclusion of the corresponding eigen-variable rule and neither it is free in T . If π is closed then we assert this by writing π : T \` \[∆\]. The requirement that the eigen-variables be not free in axioms are not that severe as they might look because our axioms will be mostly closed. 

When ∆ ≡ φ∗ then we say that π is a tableau proving φ from axioms T and write it as π : T \` φ. We use additional abbreviations similar to those discussed in Par. 3.2.4. 

We first adapt to quantifier tableaux some of the theorems formulated for propositional tableaux. 

5\.3.3 Theorem (Admissible rules in tableaux). Generalized flatten (see Thm. 3.3.2), generalized split (see Thm. 3.3.3), and propositional in- version (see Thm. 3.3.5) are admissible in any tableaux. Inversion rules for (∃) and (∀∗): 

T \` \[∆,∃xφ\] ⇒ π : T \` \[∆,φx\[y\]\] for a y and π with no (∃) on ∃xφ 

T \` \[∆,∀xφ∗\] ⇒ π : T \` \[∆,φx\[y\]∗\] for a y and π with no (∀∗) on ∀xφ∗ . 

are admissible in tableaux with closed axioms T . 

Proof. Inspection of proofs of admissibility of expansion generalized flatten and split rules as well as of propositional inversion rules reveals that the proofs remain correct also for (quantifier) tableaux; the presence of quantifier and identity rules does not affect the proofs. 

We prove just that the inversion of (∃) rule is admissible, the proof of the inversion of (∀∗) is similar. Consider the following closed tableau 

... ∃xφ 

... 

φx\[y\] (∃) π1\[y\] 

φx\[z\] (∃) π2\[z\] 

∃xφ∗ 

137

where we have indicated three out of possibly many uses of the assumption dad. The first two uses are by (3) rules with the eigen-variables y and z and the third use closes the branch. The following closed tableau shows the inverted rule:  be \[w\]  ax  where we have chosen a new variable w, removed the two conclusions of (3) rules (since they occur above), systematically renamed the variables y and z to w in the tableaux ¢1\[y\] and ¢2\[z\], and closed the branch containing the goal dx¢« with a (4\*) rule. Note that we can always find a new variable w because there are only finitely many of them free or bound in the tableau. This makes w free for x in ¢ and free for y and z in the quantified formulas of 7; and 7. Also note that the renaming of variables does not affect any axiom expansions because they are sentences. oO  5.3.4 Syntactic compactness and deduction theorems. TrKgo=sSt@ finite S CT (1) Steet AS¢  S finite. (2)  Proof. (1): This is the theorem on syntactic compactness 3.5.5 whose proof directly lifts up to the general tableaux.  (2): This is the Deduction theorem 3.5.6 whose proof directly lifts up to the general tableaux. oO  5.3.5 Renaming lemma. /fT in L is closed, A\|z\] is a sequence of formu- las of L with all free variables among the indicated ones, and the variables in ¥ are free for the corresponding variables in A then  r:Tb Alz\]\>T Aly .  Proof. By induction on the number of expansions in 7. If 7 is empty then whatever closes A\[z\] must close Aly\]. If the last expansion in 7 is by a rule which does not introduce new variables, say (\>\*), then, for a premise a¢\[Z\]\* € A\[z\], we show the tableau 7 on the left:  138 

Alz\] Aly oz\] (-\*) =\> ely\] (\>)  T™7 TT  We have 7 : T+ \[A\[z\], ¢\[2\]\] and we obtain 7; : T + \[Aly\], d\[g\]\] for some 7} by IH. We construct the tableu z’ shown on the right. Note that =¢\[y\]\* € Aly\] and thus 2’: TF Aly}.  (\>\*) rules, remaining propositional rules, as well as all identity rules ex- cept reflexivity, are rules which do not introduce new variables and they are invariant to systematic renaming of free variables in their premises and conclusions.  If the first expansion in 7 is by a rule which may introduce new variables, say (4), then, for a premise 4vd\[v, Z\]\* € A\[z\] we show the tableau 7 on the left:  Az\] Aly ar\[z.z.z7\] A) = ore a9 ©)  We have 7, : TF \[A\[z\], ¢\[7\[Z, Z\], Z\]\] an we obtain 7, : T+ \[Aly\], é\[7\[Z, ¥, I\] for some 7, by IH. We construct the tableau 7’ shown on the right. Note that Jv¢\|v, y\|x € Aly\] and thus 7’: TF \[Aly\].  (A) rules, remaining quantifier rules, axiom rules, as well as reflexivity rules, may introduce new variables into tableaux. All but the axiom rules are invariant to systematic renaming of free variables in their premises and conclusions. We have assumed that the axioms in T' are closed which makes the axiom rules invariant to renaming too. oO  5.3.6 Lemma (Admissibility of cuts on propositional formulas). If the cut rules on all propositional atoms in a formula @ are admissible in (quantifier) tableaux then also the cut rule on ¢ is admissible.  Proof. Inspection of the proof of the similar Lemma 3.3.7 for propositional tableaux reveals that the lemma holds also for tableaux (with identity and quantifier rules). O  5.3.7 Theorem (Admissibility of cuts). Cut rules on arbitrary formulas are admissible in tableau with closed axioms.  Proof. For the duration of this proof we call a tableau 7: T + \[A\] normal if  1. the axioms T are sentences,  2. free variables in the formulas of A and 7a are disjoint with all bound variables used in A and 7,  3. all new variables introduced into 7 by the reflexivity, instantiation, and eigen-variable rules are pairwise distinct.  139 

We prove 

if π is a normal closed tableau from T for ∆ with a cut on the formula φ as the first and only expansion by a cut in π then there is a tableau π′ such that π′ : T \` \[∆\] 

by induction on the number of propositional connectives and quantifiers in the cut formula φ. The tableau π can be visualized as follows 

∆ 

(C) φ φ∗ 

(1) 

If φ is an atomic formula then the cut on φ is admissible by the same argument as in Lemma 3.3.8 (taking into account the comment on cuts on identity formulas in Thm. 4.3.3). 

If φ is a propositional formula then cuts on all propositional atoms in φ are admissible by IH and so the cut on φ is admissible by Lemma 5.3.6. 

If φ ≡ ∀xφ1 then (1) looks as follows: 

∆ 

(C) ∀xφ1 

φ1x\[τ \] (∀) π1 

∀xφ1∗ 

∀xφ1∗ φ1x\[y\]∗ (∀∗) π2\[y\] 

where we may assume without loss of generality that the (∀∗) rule on the right has been inverted. Thus the goal ∀xφ1∗ is not used for anything in the tableau π2\[y\]. We have also indicated on the left one of possibly many uses of the assumption ∀xφ1 in an (∀) rule and in the closing of a branch. We transform π into π′ by modifying the tableau under the assumption ∀xφ1: 

∆ 

(C) 

φ1x\[τ \] π1 

φ1x\[τ \]∗ π2\[τ \] 

∀xφ1∗ φ1x\[z\]∗ (∀∗) π2\[z\] 

where we replace every use of a (∀) rule with the conclusion φ1x\[τ \] by a cut on this formula. The branch leading to the goal φ1x\[τ \]∗ is closed by the tableau 

140

m2\[T\] obtained from 72\[y\] by substituting for the eigen-variable y the term 7. The substitution cannot affect axiom expansions in 72\[y\] because they are closed by 1). Furthermore, no variable free in 7 is bound anywhere in 7\[y\] by 2) and so all substitutions are free. Finally, no eigen-variable condition on any eigen-variable w in pig\[T\] is violated because w cannot be introduced into the branch leading to ¢1,\[7T\]\* by 3).  We also apply a (Vx) rule with new eigen-variables z everywhere where the assumption Vd, was used for closing. We restore the normality of 7’ if needed by renaming with new variables all variables introduced in the possibly many copies of 72\[y\]. The tableau 7’ clearly does not use the assumption Vr, and the cuts on all formulas ¢1,\[7\] are admissible by TH. Hence a’ : T + \[A\] holds.  The case when ¢ = Ax, is proved similarly.  In order to finish the proof we must show how to convert the tableau (1) into a normal tableau. The tableau consists of two branches such that wy (Z\] : T+ \[A\[z\], o\[z\]\] and m2\[z\] : T + \[Az\], d\[2\]\*\]. We have indicated all free variables in A and ¢. The condition 1) is satisfied by the assumption of the theorem that T is closed. We satisfy the conditions 2) and 3) by choosing new variables y and systematically renaming to new variables the free variables introduced into 7, and 7. In this way we obtain mj \[gy\] : T - \[Aly\], d\[yl\], m5\[y\| : TF \[Aly\], o\[y\]\*\] for some 7} and m5 by Lemma 5.3.5. The tableau  m™ (9): 719\]  is normal, its cut is admissible, and we obtain 2’ : T+ Aly\] for a cut-free x’. We now apply Lemma 5.3.5 again to get T A\[z\]. oO  5.3.8 Theorem (Admissibility of the generalization rule). If T is closed and ¢ a formula of some L then  TELOSTEVE.  Proof. The theorem is proved by a repeated application of an auxiliary as- sertion  TKOSTE Vad  which is proved in the direction (—) by assuming 7, : TF ¢ for some 7 and constructing the tableau 7’:  Va \* eo (We)  ust  141 

for the eigen-variable x where we note that φx\[x\] ≡ φ. Thus π′ : T \` ∀xφ. In the direction (←) we assume π : T \` ∀φ. The tableau can be presented 

by (∀)∗ inversion for some w as follows: 

∀xφ ∗ φx\[w\] (∀∗) 

π1 

We have π1 : T \` φx\[w\] from which we obtain T \` φ by Lemma 5.3.5 because φx\[x\] ≡ φ. ut 

5\.3.9 Lemma. Ha \` Qa . 

Proof. Take any ψ ∈ Q and consider four cases. If ψ is an existential in- stantiation axiom φx\[τ \] → ∃xφ then we can prove it even without Henkin axioms: 

φx\[τ \] → ∃xφ ∗ φx\[τ \] (→1∗) ∃xφ∗ (→2∗) φx\[τ \]∗ (∃∗) 

If ψ is an universal instantiation axiom ∀xφ → φx\[τ \] then the proof is similar. If ψ is a witnessing axiom ∃xφ → φx\[c\] then we construct the following 

one expansion tableau: 

∃xφ → φx\[c\] ∗ ∃xφ → φx\[c\] (Ax) 

If ψ is a counterexample axiom φx\[c\] → ∀xφ then the Henkin constant is shared with the witnessing axiom: ∃x¬φ → ¬φx\[c\]. We prove ψ with a new eigen-variable z as follows: 

φx\[c\] → ∀xφ∗ ∃x¬φ → ¬φx\[c\] (Ax) 

(→) 

¬φx\[c\] φx\[c\]∗ (¬) φx\[c\] (→1∗) 

∃x¬φ∗ ∀xφ∗ (→2∗) φx\[z\]∗ (∀∗) ¬φx\[z\]∗ (∃∗) φx\[z\] (¬∗) 

142

5\.3.10 Theorem (Elimination of Henkin witnessing axioms). /f T and @ consist of sentences of a language £L and L, is its witnessing extension then  T,Ha-o=sTre.  Proof. Assume 7: T, Hat @ for closed T and ¢. We have 7: T, Ha, \| ¢ for a finite subset Ha, of Ha by 5.3.4(1). The theorem follows from the following assertion:  if 7: T, Ha, +} @ for a finite subset Ha, of Ha then T'\| @.  which is proved by induction on the size of Ha,. If Ha, = @ there is nothing to prove. Otherwise select from Ha, a witnessing axiom Wp = AW \> w,\[c\] with the Henkin variable of maximal rank and denote by Hag the set of remaining axioms. We may assume without loss of generality that 7 has the following form  pr (\>)  Wc\] Faryyx  ust 72  where neither 7; nor 72 contain expansions by the axiom wo. This is because we can delete all expansions by the axiom Wo from a and put it as the first expansion in 7. The inversion of wp can only affect eigen-variable rules but the condition that no eigen-variable occurs free in wo, which is a sentence anyway, assures that the inversion is always possible. We can also invert the (—) expansion for Wo. We construct a tableau x’ for ¢ as follows:  pr  (C) daw Fay veel @ ™  where we have replaced the expansion by Wo by an admissible cut on the formula Jay. Its right branch is closed by 72 and the left branch is expanded by the eigen-variable rule with a new variable z after which the branch is closed with the tableau 7; obtained from 7, by replacing everywhere the constant c by z. The crucial fact is that the Henkin constant c occurs neither in T nor in ¢ because these are in the language £. Thus the axioms from T and the subformulas of ¢ occurring in 7 are not affected by the replacement. Since c is of maximal rank in Haj, it occurs neither in Hag nor in dry. Thus neither the axioms from Haz used in 7 are affected by the replacement. We have 2’ : T, Hag + @ from which we obtain T'+ ¢ by IH. oO  143 

5\.3.11 Lemma (Elimination of quantifier rules). \[fT and A consist of sentences of a language £L and L, is its witnessing extension then  mw: Tb \[A\] \> T, Qat; \[A\] .  Proof. By induction on the number of expansions in the tableau 7. Assume a: TF \[A\] with closed T, A and consider the form of 7. If 7 is empty then we trivially have T +; \[A\] and we obtain T, Qa; \[A\] by weakening.  If the first expansion in 7 is by a propositional rule, say (—), then we have a closed ¢, — ¢2 € A and z has the form shown in the following on the left:  A A GL O) 2 pi\* a) pi\* 72 unl 1 Th  Since ¢1, ¢2 are closed, we obtain identity tableaux 7} and 74 such that mw, : T, Qa +; \[A, dix\] and 74 : T, Qa -; \[A, b2\] by two IH’s and construct the closed identity tableau for A from axioms T, Qa shown on the right. The remaining propositional, axiom, and all identity expansions except reflexivity are similar. This is because neither of the mentioned expansions introduces new free variables (recall axioms in T are closed). The exception is the re- flexivity rule shown on the left:  A A rT=T (Refl) \> T= (Refl) \> T= (Refl)  ust 72 ™  If the term 7 is not closed then we substitute for its free variables some Henkin constant whereby we obtain a closed term 7,. We perform the same substitutions in the formulas of 7, whereby we obtain a tableau 72. Note that the substitutions do not affect the structure of 7; because T and A are closed. The new tableau z’ for A with the same number of expansions as 7 is shown above in the middle. We have 7’ : T+ \[A\] and also m2 : TF \[A,7m = 79\]. We apply IH to the last tableau and obtain an identity tableau 74 s.t. 74 : T, Qa lt; \[A,71 = 72\], We then construct the closed identity tableau 7” for A from axioms T, Qa shown on the right.  If the first expansion in 7 is by quantifier instantiation rule, say (4\*), then we have a closed 4r¢@\* € A and 7 has the following form:  A  ust  144 

If the term 7 contains free variables then we substitute for them, similarly as in the preceding case, some Henkin constant and we perform the same substitutions in the tableau 7, whereby we obtain a closed term 7, and a tableau 72 s.t. m2: T+ \[A,¢z\[71\]\*\]. We then obtain an identity tableau 7, such that 74: T, Qa; \[A, ¢.\[71\]\*\] by IH and construct the following closed identity tableau for A from axioms T, Qa as follws:  A oz\|t1\] \~ ded (Az) (\>) dad ox\[T1\]\*  ™  If the first expansion in 7 is by an eigen-variable rule, say (4), then we have a closed dr@ € A and 7 has the following form:  A  bxly) (A) ™(\[y\]  Note that the eigen-variable y cannot freely occur in T or in A because both are closed. Let c be the Henkin constant belonging to 4r¢. We substitute c for y in $,\[y\] and 7,\[y\] whereby we obtain a tableau 7\[c\] such that 7\[c\] : TF \[A, ¢,\[c\]\]. Since ¢,\[c\] is closed, we obtain an identity tableau m{ such that mw, : T, Qat \[A, bz\[c\]\] by TH and we construct the closed identity tableau 7’ for A from axioms T, Qa as follows:  A  dag \> ble (Az) (\>)  m The remaining quantifier expansion rules are similar. oO  5.3.12 Theorem (Introduction/elimination of quantifier rules). \[fT and @ consist of sentences of a language £L and L, is its witnessing extension then  TEOST,Qati¢.  Proof. In the direction (=) assume 7: T+ ¢, i.e. 7: T+ \[x\], and apply Lemma 5.3.11 to get T, Qa +; \[bx\], ie. T, Qa +; ¢. In the direction (\<) assume 7: T, Qa +; ¢ which is shown in the following on the left  145 

ox on  w (Az) (C) TY w wr  Ty 72  where we have indicated just one out of possibly many (or none) expansions by the axiom rule with 7 € Qa. We construct a new tableau 7’ shown on the right where we replace every such expansion by a cut on w whose right branch is closed by the tableau 72 obtained by Lemma 5.3.9 to satisfy m2 : Hat w. Cuts are admissible by Lemma 5.3.7 and so 7’ : T, Ha + @ from which we obtain T+ ¢@ by Thm. 5.3.10. oO  5.3.13 Theorem (Soundness and completeness of tableaux). \[fT of some L is closed and ¢ is a formula of £L then  TEOSTHKS. (1)  If also @ is a sentence then Fig. 5.3 shows the complete semantic and syntactic reductions.  (a)  TE —— Tké  ¢ (Henkin reduction: 5.2.15) ¢ (Intro/elim of q-rules: 5.3.12) (b)  T, Qa Fi ——s T, Qati ¢  { (Quasitautological reduction: 4.2.11) ¢ (Intro/elim of i-rules: 4.3.7) (c)  ¢ (Tautological reduction: 3.4.5) { (Intro/elim of axioms: 3.5.7) (d)  Kp iA Atn \> 6 SpA Ata \>  for some 71,...,Un € TU QaU Eq for some #1,...,Un € TU QaU Eq  (a): Soundness and completeness of tableaux: 5.3.13  (b): Soundness and completeness of identity tableaux: 4.3.8  (c): Soundness and completeness of propositional tableaux: 3.5.8  (d): Soundness and completeness of propositional tableaux without axioms: 3.2.7  Fig. 5.3. Soundness and completeness of tableaux for closed T and @.  146 

Proof. When φ is a sentence then we have T ² φ iff, by Thm. 5.2.15, T,Qa ²i 

φ iff, by Corollary 4.3.8, T,Qa \`i φ iff, by Thm. 5.3.12, T \` φ. This is shown in Fig. 5.3. 

If φ is a formula then we have T ² φ iff, by Thm. 5.2.17, T ² ∀φ for a universal closure ∀φ of φ iff, by the just proved special case, T \` ∀φ iff, by Thm. 5.3.8, T \` φ. ut 

5\.3.14 Semidecidability of validity. This paragraph is not yet finished. We can find a proof if valid. If not we may search forever for an counterex- ample. This is the best, but the proof of it requires a knowledge of the theory of computability. 

147

148 

6\. First-order Theories 

A first-order theory in L, or simply theory in L, is a set T of sentences of the first-order language L. Theorems of T are formulas φ provable from T : T \` φ. 

6\.1 Theorems of Predicate Calculus 

For every language L the theorems of the empty theory ∅ in L are called theorems of predicate calculus. 

6\.1.1 Tableau vs. informal proofs. This paragraph is not finished. It will deal with proofs proofs of basic theorems of predicate calculus formally and informally. The theorems deal with quantifiers, prenex operations, instantia- tions (substitution), etc. 

We now prove two rules of Leibnitz which are a generalization of function Fsub and predicate Psub substitution rules to arbitrary terms and formulas. 

6\.1.2 Theorem (Rules of Leibnitz). For a term σ\[x1, . . . , xn\] and a for- mula φ\[x1, . . . , xn\] with of a language L and with the free variables among the indicated ones the following are admissible rules of inference: 

τ1 = ρ1 . . . τn = ρn 

σ\[τ1, . . . , τn\] = σ\[ρ1, . . . , ρn\] (L1) 

τ1 = ρ1 . . . τn = ρn φ\[τ1, . . . , τn\] φ\[ρ1, . . . , ρn\] 

(L2) 

Proof. (L1): An application of the rule is shown on the left: 

\[\~τ = \~ρ\] ... 

σ\[τ1, . . . , τn\] = σ\[ρ1, . . . , ρn\] (L1) π 

⇒ 

\[\~τ = \~ρ\] ... 

π′ 

where we have indicated by \[\~τ = \~ρ\] the premises τ1 = ρ1, . . . , τn = ρn. We wish to find a closed tableau π′ shown on the right by induction on the structure of the term σ.

Ifo =y where y is not among the indicated variables then the conclusion of (£1) is y = y and we start 7’ with a reflexivity rule:  F=A  y=y (Refl) a  If o = x; where 1 \< i \< n then the conclusion of (£1) is 7 = p; and we can omit it altogether because it is already among the premises. Thus 7’ = 7:  F=A  T  If o = f(o1,.--,0m) then we construct 7’ by applying (£1) m-times to the terms o; because this is admissible by IH and then by using a function substitution rule for f:  F=A  fal I  o1\|T\] = o1(p\] (L1)  oml7\]=omlA\] (Ln) f(oi\[7\],---,om\[7)) = f(A, .--; om\|Al) (Fsub)  TT  (Lz): An application of the rule is shown on the left: 7 =) \[7 =A  \[P1,-++5 Pn\] (L2) ;  T Tv  We wish to find a closed tableau 7’ shown on the right by induction on the number of propositional connectives and quantifiers in the formula ¢.  If ¢6=T or d= L then both ¢\[7\] and ¢\[p\] are identical and we can omit the conclusion altogether by setting 7’ = 7 as in the case o = 2; of (Ly).  If ¢ = P(o1,...,0m) then we construct 7’ similarly as in the case ¢ = R(o1,.--,0m) of (£1) and use a predicate substitution rule for P.  150 

If 6 = 01 = 02 then we construct 7’ by applying (1) to terms o; and a2 and then by using the rules of identity as shown:  FHA  oi \[7\] = oo l7\] o2\[7\] = o2\[p\] (Li) o1(T\] = o9\[f\] (Trans) o1\[7\] = o1\[p\] (L1) o1\[p\] = 71 \[7\] (Sym) o1\[P\| = 72\[p\| ( Trans)  4  If d = 7d) then we may assume that 7 starts with an inversion of (—)-rule applied to =¢,\[p\| as shown in the following on the left:  \[7 = pl 7 = Al iG : (C) 7617\] =\~ o1 \[Al o1\[P\]\* =$1\[A\| (Le) pr= 71 (Sym) gilal\* (\>) : ™ TY Pn = Tn (Sym) oilT (L2) 1 \[T\]\* (-)  We construct 7’ as shown on the right by introducing a cut on ¢;(p\] and on the assumption side by applying IH to ¢\[p\] to obtain ¢\[7\] after inserting n symmetry rules. The branch is then closed by applying (—) to 7¢,\[7\] in the premises.  If ¢ = ¢1 V ¢2 then we may assume that 7 starts with an inversion of (V)-rule applied to ¢1\[/\] V ¢2\[A\] as shown in the following on the left:  \[f= Al 7 = Al olAY ool dlFlV ool7l OAV G21 (La) \> (v) (Vv) \[7\] $2\[7\] orlA ola oil\] (Za) ala) (La) Ty 72 Ty 72  151 

We construct 7’ as shown on the right by applying (V)-rule to the assumption ¢1\|7\] V ¢2\[7\] and then by applying (L2) on both sides by IH.  If d = Aydi\[y,Z\] then we may assume that 7 starts with an inversion of (4)-rule with an eigen-variable z applied to Jyd¢i\[y, P\| as shown in the following on the left:  F=A =A Syd Sudly. 7 Jy¢ily, P\| (Le) dilz,T\] (A) dilz,pl\| (A) bilz, P\| (Le) Ty TTY  We construct 7’ as shown on the right by applying the (3)-rule with an eigen-variable z to the premise Jy¢,\[y,7\] and then by using (L2) by IH.  If 6 = Vy¢di\[y, Z\] then in the tableau 7 shown in the following on the left we show just one of possibly many expansions of a (V)-rule applied to the assumption Vy¢,\[y, p\]. We also show a possible closure of a branch in 7 by this assumption.  r= 2 a vydrly. 71 Vydily, 7 Vydily, pl (Lo) \_, dilo,7\] (Vv) Vydaly, al dile,p\] (V)  Vydily, ox bilo, P\| (L2) — dilz, pl (Wx) ™ bilz,7\] (VY)  ™7 bilz, P\| (Le)  We construct 7’ as shown on the right by reconstructing all branches similar to the shown ones as follows. In the branch on the left we instantiate the premise Vyd¢1\[y,7\] with y := o and then apply (L2) by IH. In the branch on the right we apply the eigen-variable to Vy¢i\[y, p\|\* with a new eigen-variable z. We then instantiate the premise Vy¢,\[y,7\] with y := z and then close the branch by applying (Lz) by TH.  The remaining propositional cases for ¢ are dealt with similarly. oO  6.1.3 Theorems of Leibnitz. For any terms o\[x,...,2,\] and formulas ¢\|#1,...,2n\] we obtain as an immediate consequence of rules of Leibnitz:  b= pi A...AT = pn 2 0\|\[T1,---;Tr\] = O\[P1,---5 Pn (1) b= pi A...AT = pn AO\[1,---;Tr\] 2 OlP1,---5 Pn - (2)  152 

6\.1.4 Identity theorem. If the variable x is possibly free in a formula ¢\[2\] and does not occur in a term 7 then  F Ja(a = 7 A g\[2\]) @ \[7\] (1) + Vae(x2 = 7 = O\[z\]) @ gr\] . (2)  (1): In the direction (—) assume 7 = 7 and ¢\[2\] for some x. We obtain ¢\|T\] by the theorem of Leibnitz 6.1.3(2). In the direction (\<-) assume ¢J\[7\]. Since tT = T, we get da(a = 7 A ¢\[2\]) by setting x := Tr.  (2): This is similar.  6.1.5 Equivalence theorem. This paragraph is not yet finished. If a for-  mula ¢ contains an occurrence of a formula w\[Z\]  where we have indicated that all bound variables of ¢ in whose scope lies the occurrence of w are among 2. If the formula ¢, is obtained from ¢ by replacing this occurrence of w by a formula 71. then  EVE owW)Abd— dg. (1)  Note that we have as an immediate consequence by the Generalization rule 5.3.8:  rFyows\> Fon gy (2)  6.1.6 Variant theorem. We say that a formula ¢; is a variant of ¢ if ¢1 differs from ¢ only in the names of its bound variables. More precisely, if 1 is obtained from ¢ by a sequence of replacements of its subformulas dav\[z\] or Vay)\[x\] by the corresponding subformulas Jyw\[y\] or Vrwl\[y\] for a variable y not free in w.  If @1 is a variant of @ we have  Food. (1)  Thus follows from the following properties by 6.1.5(2): F Sabla\] \> Syvly\] (2) F Vela\] \> vyvly\] - (3)  (2): In the direction (—) assume wl\] for some x and obtain Jy¢\[a\] by setting y := x. The direction (\<) is similar.  (3): In the direction (—) assume V7)\[z\] and take any y. We get ¢\[y\] by instantiating the assumption with x := y. The direction (\<—) is similar.  153 

6\.2 Extensions of Theories  6.2.1 Theories. A theory T in £ is a set of sentences of some first-order language £. We call £ the language of T and designate it by Lr.  Sentences of T are called axioms of the theory T. A theory is open if its axioms are universal closures of quantifier-free formulas, i.e. if every axiom has a form Vz¢ with ¢ a formula without quantifiers.  A formula ¢ of £r is a theorem of T if T + ¢. Axioms ¢ € T are trivially theorems of T.  6.2.2 Lemma. IfT, 7), S are theories in L and ¢ a formula of £ then StT andT,T; + @¢\>3S5,% @.  Proof. Assume S+ T and 7: 7,7, + ¢ where z is shown in the following on the left:  oe on =\> (Az) (C) M1 w wr TY 10)  with one of possibly many expansions by an axiom w € T. We construct the tableau 7’ shown on the right by replacing every such expansion by a cut on w whose right branch is closed by a tableau m2 such that 72:5 w. We assume that the eigen-variables of 72 were systematically renamed so they do not occur freely in the branch above 7x. We clearly have 7’: S,T,;  ¢ O  6.2.3 Consistency of theories. A theory T is consistent if T  L. Be cause \| — ¢ is a tautology, every formula ¢ is a theorem of an inconsistent theory. An inconsistent theory is thus worthless and so the consistency is the minimal requirement on theories. Because the consistence is defined by provability it is a syntactic concept. The consistency of open theories is syn- tactically characterized by the theorem of Hilbert-Ackermann Thm. 6.2.4 and the consistency of all theories is semantically characterized in Thm. 6.2.5.  If the reader finds the proof of the first characterization theorem trivial he should bear in mind that our tableau system has a subformula property where the proofs proceed without any detours such as the formulas introduced by the cut rules. Hilbert and Ackermann \[13\] (see also Shoenfield \[20\]) used a formal system based on modus ponens which is a form of cut. The theorem becomes non-trivial in cut-based proof systems. The difficulty of its proof is comparable to that of the proof of our non-trivial theorem on the admissibility of cuts.  154 

6\.2.4 Theorem (Hilbert-Ackermann). An open theory is inconsistent iff +; \\S \> L for a finite set S of instances of its axioms.  Proof. Let T be an open theory. If T is inconsistent then we have 7: T+ for some basic tableau 7. The only quantifier rules in 7 are (V)-rules instantiating the axioms of T’. We remove from 7 all formulas of a form V¢, which can be only axioms from T and its instantiations, whereby we obtain a tableau 7, s.t. 71 : S -/; L where S' is a finite sets of all quantifier-free instances of axioms in T’. We then get +; AS — 1 by the Deduction theorem 5.3.4. Vice versa, if /; AS — L then 7: S +; L by Thm. 5.3.4 and we can insert into 7 in front of every application of an axiom ¢ € S the appropriate axiom V@é € T followed by instantiations by (V)-rules leading to S whereby we obtain T’F L. oO  6.2.5 Theorem. A theory is consistent iff it has a model.  Proof. We have TF iff 7 F 1, i.e. a theory T is consistent iff TF L by the Completeness theorem 5.3.13. If JT has no model, i.e. if M F T for all structures M for Lr, then TF L and so T is inconsistent. Vice versa, if T’ is inconsistent, i.e. if TF L, then take any structure M for Lr. We have MF \| and so MF T. Hence T has no model. oO  6.2.6 Extensions of theories. A theory S is an extension of a theory T if Lg is an extension of £r and every theorem of T is a theorem of S, i.e.  Tr ¢@=SFt @ for all formulas ¢ of Lr .  Note that T is an extension of itself. Also S is an extension of T iff £5 extends Lr and St T by Lemma 6.2.2 but this does not imply that the axioms of T are among those of S,i.e. SCT.  Let S be an extension of T and K a set of formulas of £7. We say that T and S are equivalent on K if St K \> T+ K. We designate this by writing T =x S. If K consists of all formulas of £r we write T =;, S.  Note that if T and S' are equivalent on K as above then, since T+ kK \> S + K because S$ extends T, a formula of K is a theorem of S' iff it is a theorem of T.  The theories TJ and S are equivalent if S extends T and T extends S. Note that we then have Lr = Lg and T =z, S which we write simply as T = S.  The following theorem characterizes the situation when we can consis- tently extend a theory T by adding a single axiom without extending the language. We can, namely, add the axiom iff its negation is unprovable in T’.  6.2.7 Theorem. Let T be a theory and ¢ a sentence of Lr. The extended theory T,@ is consistent iff T / 7d.  Proof. If T + a@ then, since T,é + ¢, we have T+ L. Vice versa, if T,@F L then T+ ¢— L by the Deduction theorem and so TF 7¢. oO  155 

6\.2.8 Conservative extensions. Not all extensions are interesting. Unin- teresting extensions are extensions turning consistent theories into inconsis- tent ones. 

For instance, take a formalized theory of natural numbers which we will study in a form of so called Peano arithmetic, shortly PA, in the second part of this text. The square root of 2 is not a natural number (not even a rational one as was already known to Greeks). An attempt to extend PA with a new constant symbol 

√ 2 and a new axiom 2 = 

√ 2·√2 yields an extension PA1 of 

PA because we trivially have PA1 \` PA. Unfortunately PA1 is inconsistent whereas PA is consistent. This is because we trivially have PA1 \` 2 = 

√ 2·√2 

but PA \` ∀x 2 6= x·x, hence PA1 \` ∀x 2 6= x·x, and so PA1 \` 2 6= √ 2·√2. 

Because φ ∧ ¬φ → ⊥ is a tautology we then get PA1 \` ⊥. This leads us to extensions S of T which are equivalent with T on LT , 

i.e. such that T ≡LT S. Such extensions are called conservative extensions 

because they do not add any new theorems in the language of T . Specifically if T is consistent then ⊥, which is in LT , is not a theorem of T and we cannot have S \` ⊥. Hence also S is consistent. 

In order to prove that the extension S of T is conservative, which is more simply put as S is conservative over T , it suffices to prove that whenever S \` φ where φ is a formula of LT then also T \` φ. Note that the converse holds because S extends T and so every theorem of T is a theorem of S. By the Generalization rule 5.3.8 it suffices to prove the above for the sentences φ of L. 

Note that the extension of T to T, φ when T 6\` ¬φ is not in general conservative because the extended theory proves φ which can be undecidable in T , i.e. neither φ nor ¬φ are provable in T . 

6\.3 Extensions by Explicitly Defined Predicates 

Mathematicians often introduce new predicates as abbreviations for larger formulas. They do it in order to increase the readability of their theorems and to shorten their proofs. A typical example is the introduction of the predicate x \< y into a theory T which contains the binary function of addition and the constant 1. Formulas of a form τ1 \< τ2 can be viewed as abbreviations for formulas 

∃z(τ1 + (z + 1) = τ2) 

where the variable z is new. One can then proceed to prove properties of \<, say the transitivity: 

T \` x \< y ∧ y \< z → x \< z , 

always keeping on mind that this is just an abbreviation for a larger and less readable theorem 

156

T \` ∃a(x + 1 + (a + 1) = y) ∧ ∃b(y + (b + 1) = z) → ∃c(x + (c + 1) = z) . 

The problem with this approach is that when one wants to prove a metathe- oretical, theorem on provability in T , which often happens in logic but rarely in mathematics, one has to eliminate all abbreviations. A cleaner approach from a logical point of view is the extension of LT with a new binary pred- icate symbol \< and the addition to T of a new axiom for \< which is any universal closure of: 

x \< y ↔ ∃z(x + (z + 1) = y) . 

We then wish to know that the extended theory S is conservative over T , i.e. that it does not add any power to T beyond notational convenience. One can actually prove more than this by defining a translation φ? into LT of every formula φ of LS such that we have 

S \` φ ⇔ T \` φ? . 

6\.3.1 Extensions by explicitly defined predicates. Let T be a theory, φ\[\~x\] a formula of LT with the free variables among the indicated ones, and P a new n-ary predicate symbol (n ≥ 0). Consider the formula 

P (\~x) ↔ φ\[\~x\] (1) 

which is in the extension LT + P of LT . Designate by S the theory T, ∀(1) whose language is the extension of LT with the symbol P and whose axioms are T plus any universal closure of (1) which is called the defining axiom for P . 

We trivially have S \` T and so S is an extension of T which we call extension by explicitly defined predicate. The term ‘explicit’ refers to the fact that the defining axiom is not ‘recursive’, i.e. that P is not applied in φ. This is obviously so because φ is in a language which does not contain the predicate symbol P . We then have 

S \` P (\~x) ↔ φ\[\~x\] (2) 

by Thm. 5.3.8 because S trivially proves its axiom ∀(1). 

6\.3.2 Translation function. Let S be the extended theory T, ∀6.3.1(1). For every formula ψ of LS we designate by ψ? any formula of LT obtained from ψ by replacing in it every application P (\~τ) by a formula φ′\[\~τ \] where φ′ 

is a variant of φ such that the substitution of \~τ in φ′ is free for \~x. We call any such formula ψ? a translation of ψ. 

6\.3.3 Translation lemma. If S is the extended theory T, ∀6.3.1(1) and ψ a formula of LS then we have 

S \` ψ ↔ ψ∗ . (1) 

157

Proof. It is clearly sufficient to show 

S \` P (\~τ) ↔ φ′\[\~τ \] (2) 

where \~τ are terms of LT (and thus of LS) and φ′ a variant of φ because we can then repeatedly apply the Equivalence theorem (6.1.5) to the theorem of S: ψ ↔ ψ until we eliminate all applications of P on the right. 

We prove (2) by working in S where we have P (\~x) ↔ φ′\[\~x\] from the defining axiom of P by the Variant theorem (6.1.6). From this we get the property by instantiating \~x := \~τ . ut 

6\.3.4 Theorem. The extension S = T, ∀(P (\~x) ↔ φ\[\~x\]) of T by the ex- plicitly defined predicate P is conservative and for any formula ψ of LT we have 

S \` ψ ⇔ T \` ψ? . (1) 

Proof. Assume S \` ψ for a formula ψ of LT . Then T \` ψ? by 6.3.3(2) and, since ψ? ≡ ψ, we have T \` ψ. This proves the conservation. Property (1) is proved in the direction (←) by assuming T \` ψ?. We have S \` ψ?, since S extends T , and so S \` ψ by Lemma 6.3.3. 

In the direction (→) Property (1) follows from an auxiliary property 

π : S \` \[∆\] ⇒ T \` \[∆?\] 

where ∆ is a sequence of formulas of LS and ∆? is the sequence of formulas of LT obtained by translating the corresponding formulas of ∆. The auxiliary property is proved by induction on the structure of π. If π is empty then ∆ is closed. This happens if \>∗ ∈ ∆ but then \>∗ ≡ \>?∗ ∈ ∆?, or ⊥ ∈ ∆ but then ⊥ ≡ ⊥? ∈ ∆?, or φ, φ∗ ∈ ∆ but then φ?, φ?∗ ∈ ∆?. In any case ∆? is closed and we even have \` \[∆?\]. 

If the first expansion in π is by a propositional rule, say (→), then π has the form shown in the following on the left: 

φ1 → φ2 ∈ ∆ 

(→) φ2 

π2 

φ1∗ π1 

⇒ 

φ? 1 → φ? 

2 ∈ ∆? 

(→) φ? 

2 

π′2 

φ? 1∗ π′1 

Since (φ1 → φ2)? ≡ φ? 1 → φ? 

2, we obtain identity tableaux π′1 and π′2 such that π′1 : T \` \[∆?, φ? 

1∗\] and π′2 : T \` \[∆?, φ? 2\] by two IH’s from π1 : S \` 

\[∆, φ1∗\] and π′2 : S \` \[∆, φ2\]. We then construct the closed tableau for ∆? 

from axioms T shown on the right. The remaining propositional, quantifier, identity expansions except by predicate substitution rule applied to P are 

158

similar. This is because the translation is recursively applied, for instance, (ψx\[τ \] → ∃xψ)? ≡ ψ? 

x\[τ \] → ∃xψ?. If the first expansion in π is by a predicate substitution rule applied to P 

then π looks as follows: 

∆ τ1 = ρ1, . . . , τn = ρn, P (τ1, . . . , τn) ∈ ∆ 

P (ρ1, . . . , ρn) (Psub) π1 

We have (τi = ρi)? ≡ τi = ρi, P (τ1, . . . , τn)? ≡ φ′\[τ1, . . . , τn\], and P (ρ1, . . . , ρn)? ≡ φ′\[ρ1, . . . , ρn\] for a variant φ′\[\~x\] of φ\[\~x\] where we may assume that the bound variables of φ′ are such that both substitutions are free for \~x. For π1 : S \` \[∆,P (ρ1, . . . , ρn)\] we obtain π′1 : T \` \[∆?, φ′\[ρ1, . . . , ρn\]\] by IH. We have 

π2 : \` \[τ1 = ρ1, . . . , τn = ρn, φ′\[τ1, . . . , τn\], φ′\[ρ1, . . . , ρn\]∗\] for some π2 by a rule of Leibnitz. We then construct the following closed tableau for ∆? from axioms T : 

∆? τ1 = ρ1, . . . , τn = ρn, φ′\[τ1, . . . , τn\] ∈ ∆? 

(C) 

φ′\[ρ1, . . . , ρn\] 

π′1 

φ′\[ρ1, . . . , ρn\]∗ π2 

If the first expansion in π is by an axiom rule for ψ ∈ T then, since ψ? ≡ ψ, we construct π′ : T \` \[∆?\] similarly as for the propositional cases above. If the axiom is the defining axiom for P then π looks as follows: 

∆ 

∀\~x(P (\~x) ↔ φ\[\~x\]) (Ax ) π1 

We have (∀\~x(P (\~x) ↔ φ\[\~x\]))? ≡ ∀\~x(φ\[\~x\] ↔ φ\[\~x\]) 

and for π1 : S \` \[∆,∀\~x(P (\~x) ↔ φ\[\~x\])\] we obtain π′1 : T \` \[∆?, ∀\~x(φ\[\~x\] ↔ φ\[\~x\])\] by IH. We clearly have π2 : \` ∀\~x(φ\[\~x\] ↔ φ\[\~x\]) for some π2. We then construct the following closed tableau for ∆? from axioms T : 

∆? 

(C) 

∀\~x(φ\[\~x\] ↔ φ\[\~x\]) 

π′1 

∀\~x(φ\[\~x\] ↔ φ\[\~x\])∗ π2 

ut 

159

6\.4 Skolem Extensions 

6\.4.1 Skolem axioms. Suppose that T is a theory whose language does not contain the n-ary function symbol f (n ≥ 0). Further suppose that φ\[\~x, y\] is a formula of LT with the free variables among the n + 1 indicated ones. The sentence 

∀\~x(∃yφ\[\~x, y\] → φ\[\~x, f(\~x)\]) (1) 

is called the Skolem axiom for φ and f . The reader will note that in view of prenex theorems of predicate calculus we could have equivalently written the sentence (1) also as a universal closure of 

φ\[\~x, y\] → φ\[\~x, f(\~x)\] . (2) 

Extension of T to S by the addition of the function symbol f to its language and of the Skolem axiom (1) to its axioms is a Skolem extension of T . We will prove in this section that S is conservative over T both by semantic and finitary proofs. For that we use until the end of this section the abbreviation 

φ1\[\~x, y\] ≡ ∃yφ\[\~x, y\] → φ\[\~x, y\]) 

and call the formulas 

∀xi . . . ∀xnφ1\[τ1, . . . , τi−1, xi, . . . , xn, τ1, . . . , f(τi−1, xi, . . . , xn)\] (3) 

where 1 ≤ i ≤ n partial instances of the Skolem axiom and formulas φ1\[\~τ , f(\~τ)\] full instances. 

Terms of the form f(\~τ) are called f -terms and function substitution ex- pansion rules for f are called f-substitution rules. If the conclusion of an f -substitution rule is f(\~τ) = f(\~τ) then the rule is called trivial. Trivial f - substitution rules are not needed because their conclusions f(\~τ) = f(\~τ) can be obtained also by reflexivity rules. 

We will need below the following notation. We designate by Lt the wit- nessing extension of LT , by Ls the witnessing extension of LS . A formula of LS is free for f if it does not contain any f -terms whose arguments contain a bound occurrence of a variable. We denote by Hs all Henkin witnessing and counterexample axioms for LS which are free for f , and by Ht all Henkin witnessing and counterexample axioms for LT . We designate by Sks the set of of full instances of the Skolem axiom: φ1\[\~τ , f(\~τ)\] where \~τ are closed terms of Ls. 

6\.4.2 Semantic proof of conservativity of Skolem extensions. Skolem axioms 6.4.1(1) are a generalization of Henkin witnessing axioms where the term f(\~τ) acts as a witness for the formula ∃yφ\[\~τ , y\]. If f is a constant, i.e. if n = 0, then the Skolem axiom is 

160

∃yφ\[y\] → φ\[f \] (1) 

and it looks like the Henkin witnessing axiom for ∃yφ\[y\] except that the constant symbol f is not fixed as it is for Henkin constants. The reader will note that the theorem on the elimination of Henkin witnessing axioms (5.3.10) asserts that the extension of any theory T in L to the theory T,Ha in Lc is conservative. 

We will now prove that Skolem extensions are conservative. When the new function symbol f is a constant then this follows Thm. 5.3.10. Indeed, if π : T, (1) \` ψ for a sentence ψ of LT then π′ : T,Ha \` ψ where π′ is formed by systematically replacing in π the constant symbol f by the Henkin constant c belonging to ∃yφ\[y\]. We then obtain T \` ψ by Thm. 5.3.10. 

The above proof is called finitary in mathematical logic. For our purpos- es it suffices to say that finitary proofs are such when one manipulates by constructive means tableaux which are syntactic objects. Finitary proofs are considered more convincing than the semantic arguments by means of mod- els. As it happens, the extension Thm. 6.4.5 of the above finitary proof to the case when n \> 0, which is the main result of this section, is extremely non-trivial. On the other hand, the semantic proof is almost trivial. 

The semantic proof that the theory S from Par. 6.4.1 is conservative over T is by assuming S \`1 ψ for a sentence ψ of LT . We have S ² ψ by Thm. 5.3.13 and it suffices to prove T ² ψ. So let M for LT be a model of T with a domain D such that d0 ∈ D. We expand M to a structure N for LS 

by defining 

fN (d1, . . . , dn) = 

{ d if for some d ∈ D we have M ² φ\[d1, . . . , dn, d\] d0 otherwise. 

We have M ² ψ1 iff N ² ψ1 for all sentences ψ1 of LT by Thm. 5.2.7. Hence N ² T and we can easily prove N ² ∀6.4.1(1). Thus N ² ψ from the assumption and then M ² φ, since ψ is a sentence of LT . 

6\.4.3 Invariance of tableau rules under replacement of f-terms. Let the theories T and S be as in Par. 6.4.1. For the finitary proof of conservativity of S over T we need to investigate the effect of systematic replacements of f - terms by another terms in tableaux π : T,Sks, Hs \` ψ where ψ is a sentence of LT . We assume that the tableau π, which is in the language Ls, consists of sentences only. This means that there are no eigen-variable rules in π. We will see from the proof of Lemma 6.4.4 that π might contain, in addition to the basic expansion rules, also cut rules applied to identities τ1 = τ2 and applications of Leibnitz rules in the following form: 

τ1 = ρ1 . . . τn = ρn φ1\[\~τ , \~σ\] φ1\[\~τ , \~σ\] 

(L2) . 

The f -terms can be introduced into π by axioms Hs and Sks, by quantifier instantiation, cut, reflexivity, and by f -substitution rules. 

161

Quantifier instantiation rules are invariant under the replacement of f - terms by other terms unless arguments of f -terms contain bound variables, i.e. they are not free fro f . For instance, take the partial instance 

∀xnφ1\[τ1, . . . , τn−1, xn, f(τ1, . . . , τn−1, xn)\] 

of the Skolem axiom 6.4.1(1). If it used as a premise to a (∀)-instantiation rule with the conclusion φ1\[τ1, . . . , τn−1, xn, f(τ1, . . . , τn−1, τn)\] then the replace- ment of the closed term f(τ1, . . . , τn−1, τn) by a different term invalidates the rule. Note that an replacement of an f -term occurring, say, in τn−1 does not destroy the character of the rule because the same change is done in both the premise and in the conclusion. The reader will note that the tableau π can apply only invariant quantifier instantiation rules. 

An f -substitution rule with the conclusion f(\~τ) = f(\~ρ) is not invariant under the replacement of the f -terms f(\~τ) and f(\~ρ). It is, however, invariant under the replacement of an f -term anywhere in the arguments \~τ and \~ρ. 

An axiom φ1\[\~τ , f(\~τ)\] from Sks is not invariant under the replacement of f(\~τ) but it is invariant under the replacement of any other f -terms applied in \~τ . 

An axiom ∃xψ1\[x\] → ψ1\[c1\] or ψ2\[c2\] → ∀xψ2\[x\] from Hs is not invariant under the replacement of an f term even though it is free for f . If, howev- er, the replacement is deep in the sense that it also systematically modifies the Henking constants c1 and c2 the invariance can be restored. In order to explain this we recall that the Henkin constant cj of rank i + 1 from Ls 

belongs to the sentence ∃xψ3\[x\] which is at the j-th in the enumeration of ex- istential sentences 5.1.6(1) of Ls of rank i. We can thus visualize the Henkin constant cj written with symbolic index: c∃xψ3\[x\]. The deep replacement of an f -term in a Henkin witnessing ∃xψ1\[x\] → ψ1\[c∃xψ1\[x\]\] or counterexample ψ2\[c∃x¬ψ2\[x\]\] → ∀xψ2\[x\] axiom means that we replace the f -term also in the symbolic indices of Henkin constants. Note that the symbolic indices ∃xψ1\[x\] and ∃x¬ψ2\[x\] may again contain Henkin constants (of lower rank) and we must perform the deep replacement also in them. After the deep replacement we look up the symbolic indices in the corresponding enumerations 5.1.6(1) and replace them by ordinary indices. It should be clear that the deep re- placement changes an axiom from Hs into an axiom from Hs and so its use in the tableau π can be visualized to be invariant under the deep replacement of f -terms. 

All other expansion rules, including the cut and Leibnitz rules in the above form, are invariant under systematic replacements of f -terms by dif- ferent terms. Since a Henkin constant can be replaced by another Henkin constant without invalidating any rules except possibly those in Hs, the deep replacement of f -terms in π may invalidate at most the f -substitution rules and the axioms from Sks. 

6\.4.4 Lemma (Elimination of f-substitution rules). If for a sentence ψ of LT as described in Par. 6.4.1 we have π : T,Sks,Hs \` ψ where π 

162

consists of sentences only and its expansion rules, except the axioms Sks and f -substitution rules, are invariant under the deep replacement of f -terms then there is a similar tableau π0 such that π0 : T,Sks,Hs \` ψ but π0 does not apply non-trivial f -substitution rules. 

Proof. Take any π satisfying the assumption os the lemma. We determine the weight of tableaux with f -terms those occurring in π as follows. We order all distinct f -terms occurring in the tableau π into a finite sequence 

σ1 σ2 . . . σk 

ordered by the non-decreasing number of applications of the symbol f . The weight of the f -term τi is i. Note that the f -terms with higher weight cannot occur as subterms of f -terms with lesser weight. 

A conclusion σi = σj of a non-trivial f -substitution rule is assigned the weight k·max(i, j)+min(i, j). The weight of a tableau with all f -terms some σi is the maximum of weights of its non-trivial conclusions of f -substitution rules. 

The lemma is proved by induction on the weight of π. If there are at most trivial f -substitution rules in π then we set π0 ≡ π and we are done. Note that this includes the case when n = 0 because then there are no f -rules. 

If the weight of π is m \> 0 then we select all non-trivial conclusions f(\~τ) = f(\~ρ) and f(\~ρ) = f(\~τ) of f -substitution rules with the weight m. We may assume without loss of generality that the weight of f(\~τ) is higher than the weight of f(\~ρ). We intend to eliminate such rules, and thereby decrease the weight of π, by turning the f -substitution rules into trivial ones by deep replacing all occurrences of terms f(\~τ) by the term f(\~ρ). As such a replacement may invalidate some f -substitution rules and axioms Sks we have to proceed with caution. We construct the tableau π′ : T,Sks,Hs \` ψ with weight \< m as: 

ψ∗ (C) 

ρ1 = τ1 

(C) ρ2 = τ2 

... (C) 

ρn = τn 

πn+1 

ρn = τn∗ πn 

ρ2 = τ2∗ 

π2 

ρ1 = τ1∗ 

π1 

where we will now determine the subtableaux π1, . . . , πn, and πn+1. The tableau π can be visualized as follows: 

163

\[\~τ = \~ρ\] 

f(\~τ) = f(\~ρ) (Fsub) πa 

\[\~ρ = \~τ \] 

f(\~ρ) = f(\~τ) (Fsub) πb 

(1) 

where we have indicated two typical conclusions of the f -substitution rules with the weight m. The notation \[\~τ = \~ρ\] is just an indication that the n- assumptions τ1 = ρ1, . . . , τn = ρn occur somewhere along the branch. For any i s.t. 1 ≤ i ≤ n we form the tableau πi from π by the following replacements: 

ψ∗ ... 

ρi = τi∗ ... 

\[\~τ = \~ρ\] 

ρi = τi (Sym) 

\[\~ρ = \~τ \] 

The reader will note that the tableau πi is in the tableau π′ at the end of the branch with the goal ρi = τi∗. In the transformation on the right the branch thus closes against the assumption ρi = τi which is among the ones indicated by \[\~ρ = \~τ \]. In the transformation on the left we apply the symmetry rule to the assumption τi = ρi which is among the ones indicated by \[\~τ = \~ρ\]. The conclusion ρi = τi of the symmetry rule thus closes the branch against the goal ρi = τi∗. We apply the shown transformation to all topmost conclusions in π of the f -substitution rule with the weight m. This means that the tableau πi is without such rules and it has a weight \< m. 

For the construction of the tableau πn+1 we can visualize the tableau π as follows: 

164

\[\~τ = \~ρ′\] 

f(\~τ) = f(\~ρ′) (Fsub) πa 

\[ \~ρ′′ = \~τ \] 

f( \~ρ′′) = f(\~τ) (Fsub) πb 

φ1\[\~τ , f(\~τ)\] (Ax ) 

πc 

(2) 

where we have not shown the conclusions of f -substitution rules with the weight m as visualized in 6.4.4(1). We have instead shown two typical con- clusions of non-trivial f -substitution rules containing f(\~τ) and which are with lesser weights. We have also application φ1\[\~τ , f(\~τ)\] of an axiom from Sks. 

We now perform the deep replacement in the above copy of π of all f - terms f(\~τ) by the f -terms f(\~ρ). The replacement turns all conclusions of f -substitution rules with weights m into conclusions of rules of reflexivity but it invalidates the conclusions of f -substitution rules similar to the two shown. It also invalidates the axiom rule from Sks The tableau-like tree after the replacement looks as shown in Fig. 6.1 where we have shown that the tree after a correction will be located in the tableau π′ at the position of πn+1. 

ψ∗ ρ1 = τ1 

... ρn = τn 

\[\~τ = \~ρ′\] 

f(\~ρ) = f(\~ρ′) (?) 

πa 

\[ \~ρ′′ = \~τ \] 

f( \~ρ′′) = f(\~ρ) (?) 

πb 

φ1\[\~τ, f(\~ρ)\] (?) 

πc 

Fig. 6.1. Tableau-like figure after the deep replacement f(\~τ) := f(\~ρ) 

Note that the additional terms shown in the figure are not affected by the replacement because the f -term f(\~τ) cannot occur in them. Hovewever, there can be f -terms in the tableau π with higher weights than f(\~τ) and which can contain the last term as subterms. Since there are no non-trivial f -substitution rules for those higher weight f -terms in π, the replacement does not invalidate any of the rules containing the higher weight f -terms although the terms themselves change. 

165

ψ∗ ρ1 = τ1 

... ρn = τn 

\[\~τ = \~ρ′\] 

ρ1 = ρ′1 (Trans) 

... ρn = ρ′n (Trans) 

f(\~ρ) = f( \~ρ′n) (Fsub) 

πa 

\[ \~ρ′′ = \~τ \] 

τ1 = ρ1 (Sym) 

ρ′′1 = ρ1 (Trans) 

... τn = ρn (Sym) 

ρ′′n = ρn (Trans) 

f( \~ρ′′) = f(\~ρ) (Fsub) 

πb 

φ1\[\~ρ, f(\~ρ)\] (Ax ) 

φ1\[\~τ, f(\~ρ)\] (L2) 

πc 

Fig. 6.2. Corrected tableau πn+1 

We now correct the tableau-like tree in Fig. 6.1 whereby we obtain the tableau πn+1 shown in Fig. 6.2. The branch above the tableau πa is corrected by the insertion of n conclusions ρi = ρ′i of transitivity rules after which the formula f(\~ρ) = f(\~ρ′) is a conclusion of an f -substitution rule with weight \< m. The branch above the tableau πb is corrected by the insertion of conclu- sions of symmetry rules τi = ρi followed by conclusions of transitivity rules ρ′′i = ρi. This is repeated n-times after which the formula f( \~ρ′′) = f(\~ρ) is a conclusion of an f -substitution rule with a weight \< m. The branch above the tableau πc is corrected by an axiom φ1\[\~ρ, f(\~ρ)\] from Sks. We then use an admissible Leibnitz rule (L2) to introduce the conclusion φ1\[\~τ , f(\~ρ)\]. 

We perform the just described corrections for all conclusions similar to typical conclusions visualized in (2). The tableau πn+1 has a weight \< m and so does the tableau π′. We now apply the induction hypothesis to π′ whereby we obtain a tableau π0 s.t. π0 : T,Sks,Hs \` ψ without any non-trivial f - substitution rules. ut 

6\.4.5 Theorem. Skolem extensions are conservative. 

Proof. Let S be a Skolem extension of T as in Par. 6.4.1 and assume π : S \` ψ for a basic tableau π and a formula ψ of LT . Because of the Generalization rule 5.3.8 we may assume without loss of generality that ψ is a sentence. We now replace in π all free variables other than eigen-variables by arbitrary 

166

Henkin constants from LS whereby we obtain a closed tableau π1 for ψ which is in the language Ls. Note that variables other than eigen-variables can be introduced into π only by quantifier instantiation and reflexivity rules. 

The next transformation is the elimination of all eigen-variable rules from π1. The elimination is similar as in the proof of the Lemma 5.3.11 on the elimination of quantifier rules except that we do not eliminate the quantifier instantiation rules. Since the premises of all eigen-variable rules in π1 are free for f , the introduced Henkin witnessing and counterexample axioms are from Hs and so we obtain a tableau π2 consisting of sentences and such that π2 : S,Hs \` ψ. 

We now delete from π2 all partial instances of the Skolem axiom 6.4.1(1) whereby we obtain a tableau π3 such that π3 : T,Sks,Hs \` ψ. The tableau satisfies the assumptions of Lemma 6.4.4 and we obtain from it a similar tableau π4 : T,Sks,Hs \` ψ which is without non-trivial f -substitution rules. 

We intend to eliminate from π4 the applications of axioms from Sks: 

φ1\[\~τ , f(\~τ)\] ≡ ∃yφ\[\~τ , y\] → φ\[\~τ , f(\~τ)\] . 

by deeply replacing the closed term f(\~τ) by the Henkin constant c belonging to the sentence ∃yφ\[\~τ , y\]. This constant can be written with symbolic index as c∃yφ\[\~τ,y\] and the deep replacement turns the above axiom to a Henkin witnessing axiom from Hs: 

∃yφ\[\~τ , y\] → φ\[\~τ , c∃xφ\[\~τ,x\]\] . 

Toward that end we deeply replace all f -terms f(\~ρ) in π4 by the Henkin constants c∃yφ\[\~ρ,y\] whereby we obtain a tableau π5. The order of elimination of f -terms is immaterial because it leads to identical results but it is crucial that we perform the replacements not only in the formulas of π4 but also in the indices of all Henking constants occurring in π4. It should be clear that the elimination of f -terms turns the full instances of Skolem axioms into Henkin witnessing axioms from Has and does not change the character of any other rules in π4. Specifically, Henkin witnessing axioms are turned into Henkin witnessing axioms without f -terms. 

There are no f -terms in the sentences of π5, nor in the indices of its Henkin constants and we have π5 : T,Hs \` ψ. We now take every Henkin constant occurring in π5 and write in the symbolic form c∃xψ0\[x\] where also the Henkin constants in ψ0 are with symbolic indices and also the Henkin constants in these symbolic indices are such . . . . We change the symbolic indices back to the numerical form by looking up the existential sentences in the appropriate enumerations 5.1.6(1) but this time for the language Lt. The look up is done first for the formulas of the lowest rank and then for the formulas with the next higher ranks, . . . . We thus obtain a tableau π6 such that π6 : T, Ht \` ψ. 

We eliminate next the Henkin counterexample axioms from π6 just as it was done in the proof of the theorem on the Introduction/elimination of 

167

quantifier rules 5.3.12. We, namely, take any counterexample axiom in π6: 

ψ∗ 

ψ0\[c\] → ∀xψ0\[x\] (Ax) 

π′ 

and replace it by a cut: 

ψ∗ 

(C) 

ψ0\[c\] → ∀xψ0\[x\] 

π′ ψ0\[c\] → ∀xψ0\[x\]∗ 

π′′ 

whose right branch is closed by the tableau π′′ obtained by Lemma 5.3.9 to satisfy π′′ : Ha \` ψ0\[c\] → ∀xψ0\[x\]. We denote by Ha the Henkin witnessing axioms for LT . We thus obtain a tableau π7 such that π7 : T,Ha \` ψ to which we apply the Theorem on the conservativity of Henkin witnessing axioms 5.3.10 and obtain T \` ψ. ut 

6\.4.6 Skolemization and Herbrand’s theorem. One of the uses of Skolem axioms is to eliminate, by a process called Skolemization, quanti- fiers from formulas at the price of introducing Skolem functions. Since we will not need this in the further development, we just illustrate the process with an example. 

In order to eliminate the quantifiers from a sentence we bring it to a prenex form, say, ∃x∀y∃z∀wφ\[x, y, z, w\] where the formula φ is quantifier free. We consider the following Skolem axioms: 

∀x(∃y∀z∃w¬φ\[x, y, z, w\] → ∀z∃w¬φ\[x, f(x), z, w\]) ∀x∀z(∃w¬φ\[x, f(x), z, w\] → ¬φ\[x, f(x), z, g(x, z)\]) 

for new function symbols f and g. It is not hard to see that we have 

\` ∀x∀z¬φ\[x, f(x), z, g(x, z)\] → ∀x∃y∀z∃w¬φ\[x, y, z, w\] (1) 

in the predicate calculus. For the proof of converse we need the two Skolem axioms and we have 

T \` ∀x∃y∀z∃w¬φ\[x, y, z, w\] → ∀x∀z¬φ\[x, f(x), z, g(x, z)\] (2) 

168

in the theory T consisting of the two Skolem axioms. The celebrated theorem of Herbrand asserts 

² ∃x∀y∃z∀wφ\[x, y, z, w\] ⇔ ²i φ\[τ1, f(τ1), ρ1, g(τ1, ρ1)\] ∨ . . . ∨ φ\[τn, f(τn), ρn, g(τn, ρn)\] for some n ≥ 1 and terms τ1, ρ1, . . . , τn, ρn. 

We first show 

\` ∃x∀y∃z∀wφ\[x, y, z, w\] ⇔ \` ∃x∃zφ\[x, f(x), z, g(x, z)\] (3) 

where the sentence ∃x∃zφ\[x, f(x), z, g(x, z)\] is called a Herbrand normal form of the sentence ∃x∀y∃z∀wφ\[x, y, z, w\]. 

(3): In the direction ⇒ we assume \` ∃x∀y∃z∀wφ\[x, y, z, w\]. Thus \` ¬∀x∃y∀z∃w¬φ\[x, y, z, w\] and we get \` ¬∀x∀z¬φ\[x, f(x), z, g(x, z)\] by (1), i.e. \` ∃x∃zφ\[x, f(x), z, g(x, z)\]. 

In the direction ⇐ we assume \` ∃x∃zφ\[x, f(x), z, g(x, z)\] and get T \` ¬∀x∀z¬φ\[x, f(x), z, g(x, z)\]. We then have T \` ¬∀x∃y∀z∃w¬φ\[x, y, z, w\] by (2). We then get \` ¬∀x∃y∀z∃w¬φ\[x, y, z, w\] by the conservativity of T and hence \` ∃x∀y∃z∀wφ\[x, y, z, w\]. 

We show next 

\` ∃x∃zφ\[x, f(x), z, g(x, z)\] ⇔ \`i φ\[τ1, f(τ1), ρ1, g(τ1, ρ1)\] ∨ . . . ∨ φ\[τn, f(τn), ρn, g(τn, ρn)\] for some n ≥ 1 and terms τ1, ρ1, . . . , τn, ρn. (4) 

In the direction (⇒) we assume π : \` ∃x∃zφ\[x, f(x), z, g(x, z)\]. We re- move from the tableau π all conclusions ∃zφ\[τ, f(τ), z, g(τ, z)\]∗ of (∃∗)- instantiation rules applied to ∃x∃zφ\[x, f(x), z, g(x, z)\]∗ and then remove al- so all conclusions φ\[τ, f(τ), ρ, g(τ, ρ)\]∗ of (∃∗)-instantiation rules applied to ∃zφ\[τ, f(τ), z, g(τ, z)\]∗ whereby we obtain a tableau π1 such that 

π1 : \` \[φ\[τ1, f(τ1), ρ1, g(τ1, ρ1)\]∗, . . . , φ\[τn, f(τn), ρn, g(τn, ρn)\]∗\] where the shown n formulas are all conclusions removed in the second step. Form this we clearly get 

π2 : \` φ\[τ1, f(τ1), ρ1, g(τ1, ρ1)\] ∨ . . . ∨ φ\[τn, f(τn), ρn, g(τn, ρn)\] 

for a tableau π2 obtained from π1 by n generalized flatten rules (G∨i∗). Since the tableau π2 cannot apply any quantifier rules, it must be an identity tableau. 

In the direction (⇐) we assume the right-hand-side of (4). We clearly have 

\` φ\[τi, f(τi), ρi, g(τi, ρi)\] → ∃x∃zφ\[x, f(x), z, g(x, z)\] 

for all 1 ≤ i ≤ n from which we get the left-hand-side. The above instance of the Herbrand’s theorem now follows by combining 

the results (3) and (4) and by using soundness and completeness theorems for both quantifier and identity tableaux. 

169

6\.5 Extensions by Contextually Defined Functions 

We can extend theories by explicit definitions of functions: f(\~x) = τ \[\~x\]. That this is conservative can be then proved similarly as the conservativity of explicit definitions of predicates. In contrast to such definitions of pred- icates, explicitly defined functions do not fully use the power of first-order logic because the terms τ do not posses the full expressiveness of formulas. Contextually defined functions utilize the full power of formulas. 

As an example consider a formal theory of arithmetic which has multi- plication, addition, and constant 1. We have seen in Sect. 6.3 how to extend such a theory by explicit definition of the predicate \<. We can further define the binary predicate x ≤ y ↔ x \< y ∨ x = y and the unary square function x2 = x·x by explicit definitions. Let us call such a theory T . We can extend T to S by extending its language with the unary function symbol \[ 

√·\] intended to denote the whole part of square root. We can find a formula of LT equiva- lent to the formula \[ 

√ x\] = y applying the square root function in the context 

of an atomic formula. We can use the formula in the contextual definition: 

\[ √ 

x\] = y ↔ y2 ≤ x ∧ x \< (y + 1)2 

This definition can be justified if we can prove in T that to every individual there will exactly one square root. This amounts to proving the following: 

T \` ∃y(y2 ≤ x ∧ x \< (y + 1)2) 

T \` y2 1 ≤ x ∧ x \< (y1 + 1)2 ∧ y2 

2 ≤ x ∧ x \< (y2 + 1)2 → y1 = y2 . 

We can then translate every formula of LS into an equivalent formula of LT 

where every application of \[ √ 

τ \] used in a context of an atomic formula φ\[z\] as φ\[\[ 

√ τ \]\] is translated to the formula on the right for which S proves: 

S \` φ\[\[ √ 

τ \]\] ↔ ∃z(z2 ≤ τ ∧ τ \< (z + 1)2 ↔ φ\[z\]) . 

6\.5.1 Extensions by contextually defined functions. Let T be a theo- ry, φ\[\~x, y\] a formula of LT with the free variables among the indicated ones, and f a new n-ary function symbol (n ≥ 0). If T proves the existence: 

T \` ∃y φ\[\~x, y\] (1) 

and the uniqueness 

T \` φ\[\~x, y1\] ∧ φ\[\~x, y2\] → y1 = y2 (2) 

conditions then we can extend T to S by adding to LT the function symbol f and to the axioms of T any closure of 

f(\~x) = y ↔ φ\[\~x, y\] (3) 

170

as the defining axiom for f . Because S = T, ∀(3) we trivially have S \` T and so S extends T . We call this kind of extension extension by contextually defined function. The term ‘contextual’ refers to the fact that although we are not able to find a term ρ of LT identical to f(\~x), we have a formula φ\[\~τ , ρ\] of LT equivalent to an application of f in the context of an atomic formula f(\~τ) = ρ for all terms \~τ , ρ of LT . Note that f cannot be applied in φ which is of L and so contextual definitions are not recursive. We have 

S \` f(\~x) = y ↔ φ\[\~x, y\] (4) 

by Thm. 5.3.8 because S trivially proves its axiom ∀(3). 

6\.5.2 Translation function. Let S be the extended theory T, ∀6.5.1(3). For every atomic formula ψ of LS we define by induction on the number k of applications of f in ψ a formula ψ? of LT called a translation of ψ. If k = 0 then we set ψ? ≡ ψ. Otherwise we have ψ ≡ ψ1\[f(\~τ)\] for some terms \~τ of LT 

and a formula ψ1\[z\] of LS with \< k applications of f . We then set 

ψ∗ ≡ ∃z(φ′\[\~τ , z\] ∧ ψ1\[z\]?) (1) 

where φ′ is a variant of φ with the bound variables different from z and those free in \~τ . Note that ψ1\[z\]? is a formula of LT by IH and so is the formula ψ?. We extend the translation function to all formulas ψ of LS by designating by ψ? any formula obtained from ψ by replacing any of its atomic formulas ψ1 

by formulas ψ? 1 . 

6\.5.3 Translation lemma. If S is the extended theory T, ∀6.5.1(3) and ψ a formula of LS then we have 

S \` ψ ↔ ψ∗ . (1) 

Proof. We first prove (1) for atomic ψ by metainduction on the number of applications of f in ψ. If there are none then the property is a tautology because ψ? ≡ ψ. Otherwise, using the notation of Par. 6.5.2 we have ψ ≡ ψ1\[f(\~τ)\] and ψ? ≡ 6.5.2(1) for some terms \~τ of LT and a formula ψ1\[z\] of LS with \< k applications of f . Working in S we obtain f(\~τ) = z ↔ φ′\[\~τ , z\] by the Variant theorem (6.1.6) from an instantiation of the defining axiom for f . Hence ∃z(f(\~τ) = z∧ψ1\[z\]?) ↔ ψ? by the Equivalence theorem (6.1.5). We have ψ\[z\] ↔ ψ1\[z\]? by IH and so ∃z(f(\~τ) = z ∧ ψ1\[z\]) ↔ ψ?. Thus ψ1\[f(\~τ)\] ↔ ψ? by Identity theorem (6.1.4). ut 

6\.5.4 Theorem. The extension S = T,∀(f(\~x) = y ↔ φ\[\~x, y\]) of T by the contextually defined function f is conservative and for any formula ψ of LT 

we have 

S \` ψ ⇔ T \` ψ? . (1) 

171

Proof. Designate by T2 the Skolem extension of T with a closure of 

∃yφ\[\~x, y\] → φ\[\~x, f(\~x)\] . (2) 

T2 is conservative over T by Thm. 6.4.5 and LS = LT2 . If we succeed in proving 

S ≡ T2 (3) 

then for any ψ of LT such that S \` ψ we will have T2 \` ψ by (3) and T \` ψ because T2 is conservative over T . 

(3): In order to prove that S extends T2 it suffices to derive (2) in S. So working in S we instantiate its defining axiom for f with y := f(\~x) and obtain φ\[\~x, f(\~x)\]. from which (2) trivially follows. 

That T2 extends S follows from a proof in T2 of f(\~x) = y ↔ φ\[\~x, y\]. In the direction (→) it suffices to prove φ\[\~x, f(\~x)\]. Since T2 proves the existence condition 6.5.1(1) because it extends T and also the instance (2) of its Skolem axiom, we obtain φ\[\~x, f(\~x)\]. In the direction (←) and working in T2 we assume φ\[\~x, y\] from which we get ∃yφ\[\~x, y\] and then φ\[\~x, f(\~x)\] from (2). We then get f(\~x) = y from the uniqueness condition 6.5.1(2) which holds in T2. 

(1): In the direction (→) assume S \` ψ. We have S \` ψ? by Lemma 6.5.3 and, since φ? is of LT , we obtain T \` ψ? because S is conservative over T . In the direction (←) assume T \` ψ?. Since S extends T , we have S \` ψ? and so S \` ψ by Lemma 6.5.3. ut 

6\.6 Extensions by Definitions 

Extensions of theories T to S by explicit definitions of predicates and by contextual definition of functions have the important property that any model of T is uniquely expanded to a model of S. This, and the property that the theorems of S can be translated to the theorems of T and back, are crucial to our treatment of formal arithmetic in the Part II of this text. 

6\.6.1 Extensions by definitions. Let T be a theory and T1 its conserva- tive extension either by explicit definition of a predicate P or by contextual definition of a function f . Let S be a theory in the same language as LT1 . We say that S is an extension by definition of T if S and T1 are equivalent. This can be visualized as 

S \` ψ1 ⇔ T, ψ \` ψ1 for any formula ψ1 of LS (1) 

where ψ is the defining axiom of T1, i.e a universal closure of either P (\~x) ↔ φ\[\~x\] or f(\~x) = y ↔ φ\[\~x, y\] for a suitable formula φ of LT . 

A theory S is an extension by definitions of a theory T if S is obtained by a finite number of extensions by definition of T , i.e. if there is a number n and theories T0, T1, . . . , Tn such that T = T0, Ti+1 is an extension by definition of Ti for every i \< n, and S = Tn. 

172

6\.6.2 Theorem (Extensions by definitions). If the theory S is an ex- tension by definitions of a theory T then S is conservative over T , every model of T has a unique expansion to the model of S, and there is an effec- tive translation function taking formulas ψ of LS to formulas ψ? of LT such that for every formula ψ of LS we have 

S \` ψ ↔ ψ? (1) S \` ψ ⇔ T \` ψ? . (2) 

Proof. By induction on the number k of extensions by definition of T to obtain S. If k = 0 then S = T and there is nothing to prove. If k \> 0 then S is an extension by definition of a theory T1 which is obtained by k− 1 extensions by definition from T . By IH there is an effective translation function taking formulas ψ of LT1 to formulas ψ?1 of LT such that 

T1 \` ψ ↔ ψ?1 (3) T1 \` ψ ⇔ T \` ψ?1 . (4) 

Since S is an extension by definition of T1, there is a defining axiom ψ1 

of LS such that S ≡ T1,∀ψ1. Depending on whether the new symbol of S is a predicate symbol P or a function symbol f , there is by Translation Lemma 6.3.3 or 6.5.3 an effective translation function, which takes formulas ψ of LS 

to formulas ψ?2 of LT1 , and such that 

T1,∀ψ1 \` ψ ↔ ψ?2 . (5) 

We also have 

T1,∀ψ1 \` ψ ⇔ T1 \` ψ?2 (6) 

by Theorem 6.3.4 or 6.5.4. We define the translation function taking formulas ψ of LS to formulas 

ψ? of LT as ψ? ≡ (ψ?2)?1 . The translation function is clearly effective. (1): We work in the theory T1, ∀ψ1 and take any formula ψ of LS . We 

have ψ iff ψ?2 by (5) iff, since T1, ∀ψ1 is an extension of T1, (ψ?2)?1 , i.e. ψ?, by (3). We have just proved T1, ∀ψ1 \` ψ ↔ ψ?. Thus also (1) because S is equivalent to T1,∀ψ1. 

(2): Take any formula ψ of LS . We have S \` ψ iff, by the equivalence, T1,∀ψ1 \` ψ iff, by (6), T1 \` ψ?2 iff, by (4), T \` (ψ?2)?1 iff T \` ψ?. 

We now prove that S is conservative over T . So we take any formula ψ of LT and assume S \` ψ. We have T \` ψ? by (2) and, since ψ? ≡ ψ, also T \` ψ. 

Now suppose that a structure M for LT with a domain D is a model of T : M ² T . There is a unique expansion M1 of M which is a model of 

173

T1 by IH. We expand M1 to the structure N for LS by choosing a suitable interpretation of the new symbol P or f . For any such interpretation we will have N ² S iff, by the completeness and by S ≡ T1, ∀ψ1, N ² T1,∀ψ1 iff, since N ² T1 by Thm. 5.2.7, N ² ∀ψ. 

We now consider two cases. If ψ ≡ P (\~x) ↔ φ\[\~x\] then N ² ∀ψ iff N ² ∀\~x(P (\~x) ↔ φ\[\~x\]) iff for all \~d ∈ D 

PN (\~d) ⇔ N ² P (\~x)\[\~d\] ⇔ N ² φ\[\~d\] 5.2.7⇔ M1 ² φ\[\~d\] 

which means that the unique interpretation PN (\~d) ⇔ M1 ² φ\[\~d\] is both sufficient and necessary for N to be a model of S. 

If ψ ≡ f(\~x) = y ↔ φ\[\~x, y\] then for all \~d ∈ D there is a k ∈ d such that M1 ² φ\[\~d, k\] by the existence condition and this k is unique because for any k1 we have 

M1 ² φ\[\~d, k\] and M1 ² φ\[\~d, k1\] ⇒ k = k1 

by the uniqueness condition. We haveN ² ∀ψ iffN ² ∀\~x∀y(f(\~x) = y ↔ φ\[\~x, y\]) iff for all \~d, k ∈ D 

fN (\~d) = k ⇔ N ² (f(\~x) = y)\[\~d, k\] ⇔ N ² φ\[\~d, k\] 5.2.7⇔ M1 ² φ\[\~d, k\] . 

But this means that interpreting fN for \~d ∈ D as the unique k ∈ D such that M1 ² φ\[\~d, k\] is both sufficient and necessary for N to be a model of S. ut 

6\.6.3 Theorem (Implicit definition of functions). For any theory T and any formula φ\[\~x, y\] of LT with the free variables among the n+1 indicated ones and satisfying the existence and uniqueness conditions the extension of LT with a new n-ary function symbol f and of T with a new axiom: 

∀\~xφ\[\~x, f(\~x)\] 

is an extension by definition. 

Proof. Designate by S the extended theory. It is sufficient to prove that S is equivalent to the extension T1 of T by the contextual definition ∀\~x∀y(f(\~x) = y ↔ φ\[\~x, y\]) because T1 is an extension by definition of T . By instantiating the defining axiom of T1 with y := f(\~x) and generalizing we obtain T1 \` ∀\~xφ\[\~x, f(\~x)\] and so T1 extends S. 

In order to demonstrate that S extends T1 it suffices to show S \` f(\~x) = y ↔ φ\[\~x, y\]. Working in S we assume in the direction (→) f(\~x) = y. We then obtain φ\[\~x, y\] because φ\[\~x, f(\~x)\] follows from the new axiom of S. In the direction (←) we assume φ\[\~x, y\] and, since φ\[\~x, f(\~x)\], we obtain f(\~x) = y by the uniqueness condition which is provable in S because S extends T . ut 

174

6\.6.4 Theorem (Explicit definition of functions). For any theory T and any term τ \[\~x\] of LT with the free variables among the n indicated ones the extension of LT with a new n-ary function symbol f and of T with a new axiom: 

∀\~x f(\~x) = τ \[\~x\] 

is an extension by definition. 

Proof. Designate by S the extended theory. We first show that T proves the existence and uniqueness conditions for the formula φ\[\~x, y\] ≡ f(\~x) = τ \[\~x\] The existence condition ∃y y = τ \[\~x\] follows from τ \[\~x\] = τ \[\~x\]. For the uniqueness condition assume y1 = τ \[\~x\] and y2 = τ \[\~x\] and obtain y1 = y2 by the properties of identity. We now use Thm. 6.6.3 to extend by definition T to S with the new axiom ∀\~x f(\~x) = τ \[\~x\]. ut 

175

176

7\. Peano Arithmetic 

7\.1 Basic Theorems in PA 

In this section we introduce and prove basic theorems of the formal system of arithmetic called Peano arithmetic. 

7\.1.1 Language of Peano arithmetic. The language LPA of Peano arith- metic consists of the constant 0, the unary function symbol x′, and of two binary function symbols x+y and x·y. Both + and · associate to the left and · has greater precedence than +. 

We will abbreviate 0′ as 1 but only in this section. 

7\.1.2 Axioms of Peano arithmetic. The axioms of Peano arithmetic con- sist of universal closures of the following six formulas: 

P̀A 0 6= x′ (1) 

P̀A x′ = y′ → x = y (2) 

P̀A 0 + y = y (3) 

P̀A x′ + y = (x + y)′ (4) 

P̀A 0·y = y (5) 

P̀A x′·y = x·y + y (6) 

and for every formula φ\[x\] of LPA and an indicated variable x a universal closure of the induction axiom Ixφ\[x\]: 

P̀A φ\[0\] ∧ ∀x(φ\[x\] → φ\[x′\]) → φ\[x\] . (7) 

The induction formula φ\[x\] can contain, in addition to the induction variable x, zero or more free variables as parameters. 

We use the symbol P̀A φ of provability in PA as an abbreviation for PA \` φ. 

7\.1.3 The standard model N of PA. The standard model N of Peano arithmetic is the structure for LPA whose domain is the set of natural numbers N and the interpretations 0N , ′N , +N , and ·N of the function symbols of

LPA are in that order the number 0, the successor function S(x) = x+1, the addition, and multiplication functions. We leave to the reader the obvious demonstration that N satisfies the six axioms 7.1.2(1) through 7.1.2(6). 

We now prove that also the induction axioms 7.1.2(7) are satisfied in N . So take any formula φ\[x, \~y\] of LPA with all its free variables among the indicated ones. We wish to show N ² ∀x∀\~yIxφ\[x, \~y\]. For that we take any \~d ≡ d1, . . . , dn ∈ N and it clearly suffices to show N ² ∀xφ\[x, \~d\]. So assume on the contrary that N 2 \[m, \~d\] for some m ∈ N. Furthermore, assume that m is the least such number. We thus have the base case assumptionN ² φ\[0, \~d\], the inductive assumption: N ² ∀x(φ\[x, \~d\] → φ\[x, \~d\]), and N 2 φ\[m, \~d\]. Consider now two cases. If m = 0 then we get a contradiction with the base case assumption. If m \> 0 then we have N ² φ\[m− 1, \~d\] by the minimality of m and we get a contradiction N ² φ\[(m− 1) + 1, \~d\] from the inductive assumption. 

7\.1.4 Informal reasoning by induction. Induction axioms of PA can be used anywhere in the proofs in PA. The typical situation is that we use an axiom Ixφ\[x\] in an instantiation x := τ : 

φ\[0\] ∧ ∀x(φ\[x\] → φ\[x′\]) → φ\[τ \] 

under certain assumptions ψ1, . . . , ψk. The informal use of this axiom is to derive the formula φ\[τ \] by considering two cases. 

In the base case we prove φ\[0\] under the above assumptions. In the inductive case we prove φ\[x′\] for a new eigen-variable x under the 

same assumptions ψ1, . . . , ψk to which we add inductive hypothesis φ\[x\], shortly IH, as an additional assumption. 

Both cases taken together then prove φ\[τ \] from Ixφ\[τ \] by modus ponens. 

7\.1.5 Case analysis on 0 and positive numbers. The base case analysis is on 0 and on positive numbers: 

P̀A x = 0 ∨ ∃y x = y′ (1) 

which is proved by induction on x. In the base case there is nothing to prove. In the inductive case we get ∃y x′ = y′ from x′ = x′. 

7\.1.6 Successor versus addition. We have 

P̀A 1 + x = x′ (1) 

because 1 + x = 0′ + x 

7\.1.2(4) = (0 + x)′ 

7\.1.2(3) = x′ . 

178

7\.1.7 Nullpoints of addition. We have the following property of addition: 

P̀A x + y = 0 ↔ x = 0 ∧ y = 0 (1) 

In the direction (→) assume x + y = 0 and consider two cases by 7.1.5(1). If 

x = 0 then we have 0 = 0 + y 7.1.2(3) 

= 0. The case x = x′1 for some x1 cannot 

hold because it leads to a contradiction: 0 = x′1+y 7.1.2(4) 

= (x+y)′ by 7.1.2(1). In the direction (←) the property is a direct consequence of 7.1.2(3). 

7\.1.8 Addition is commutative. In order to prove that + commutes 

P̀A x + y = y + x (1) 

we need two lemmas 

P̀A x + 0 = x (2) 

P̀A x + y′ = x′ + y. (3) 

(2) is proved by induction on x. In the base case we have 0 + 0 7.1.2(3) 

= 0 and in the inductive case: 

x′ + 0 7.1.2(4) 

= (x + 0)′ IH= x′ . 

(3) is proved by induction on x. In the base case we have 

0 + y′ 7.1.2(3) 

= y′ 7.1.2(3) 

= (0 + y)′ 7.1.2(4) 

= 0′ + y . 

In the inductive case we have 

x′ + y′ 7.1.2(4) 

= (x + y′)′ IH= (x′ + y)′ 7.1.2(4) 

= x′′ + y . 

We now prove (1) by induction on x. In the base case we have 

0 + y 7.1.2(3) 

= y (2) = y + 0 . 

In the inductive case we have 

x′ + y 7.1.2(4) 

= (x + y)′ IH= (y + x)′ 7.1.2(4) 

= y′ + x (3) = y + x′ . 

From now on we will not explicitly indicate the uses of the two axioms of addition 7.1.2(3)(4). 

7\.1.9 Addition is associative. That the addition is associative 

P̀A (x + y) + z = x + (y + z) (1) 

is proved by induction on x. In the base case we have: 

(0 + y) + z = y + z = 0 + (y + z) . 

In the inductive case we have: 

(x′ + y) + z = (x + y)′ + z = ((x + y) + z)′ IH= (x + (y + z))′ = x′ + (y + z) . 

179

7\.1.10 Cancellation rules for addition. Cancellation rules for the addi- tion are: 

P̀A z + x = z + y → x = y (1) 

P̀A x + z = y + z → x = y . (2) 

(1) is proved by induction on z. In the base case we have 

0 + x = 0 + y ⇒ x = y . 

In the inductive case we have 

z′ + x = z′ + y ⇒ (z + x)′ = (z + y)′ 7.1.2(2)⇒ z + x = z + y 

IH⇒ x = y . 

(2) is proved as follows: 

x + z = y + z 7.1.8(1)⇒ z + x = z + y 

(1)⇒ x = y . 

From now on we will not explicitly indicate the properties of addition proved until now. 

7\.1.11 Multiplication by 0 and 1. We have 

P̀A x·0 = 0 (1) 

P̀A x·1 = 1 . (2) 

(1) is proved by induction on x. In the base case we have 0·0 7.1.2(5) = 0. In the 

inductive case we have: 

x′·0 7.1.2(6) = x·0 + 0 = x·0 IH= 0 . 

(2) is proved by induction on x. In the base case we have 0·1 7.1.2(5) = 0. In the 

inductive case we have 

x′·1 7.1.2(6) = x·1 + 1 = 1 + x·1 IH= 1 + x = x + 1 = x′ . 

7\.1.12 Units of multiplication. Multiplication has the following property 

P̀A x·y = 1 ↔ x = 1 ∧ y = 1 . (1) 

Indeed, in the direction (→) we assume x·y = 1 and consider three cases for 

x. The case x = 0 leads to the contradiction 0′ = 1 = 0·y 7.1.2(5) = 0. If x = 1 

then we have 

1 = 1·y = 0′·y 7.1.2(6) = 0·y + y 

7\.1.2(5) = 0 + y = y . 

180

The case x = x′′1 for some x1 cannot happen, This is shown by considering two cases for y. The case y = 0 leads to a contradiction 

0′ = 1 = x′′1 ·0 7.1.11(1) 

= 0 . 

Also the second case y = y′1 for some y1 leads to a contradiction: 

0′ = 1 = x′′1 ·y′1 7.1.2(6) 

= x′1·y′1 + y′1 7.1.2(6) 

= x1·y′1 + y′1 + y′1 = (x1·y′1 + y1 + y1)′′ . 

The direction (←) follows from the following 

1·1 = 0′·1 7.1.2(6) = 0·1 + 1 

7\.1.2(5) = 0 + 1 = 1 . 

7\.1.13 Multiplication distributes over addition. The distributive prop- erty of the multiplication: 

P̀A z·(x + y) = z·x + z·y (1) 

is proved by induction on z. In the base case we have 

0·(x + y) 7.1.2(5) 

= 0 = 0 + 0 7.1.2(5) 

= 0·x + 0·y . 

In the inductive case we have 

z′·(x + y) 7.1.2(6) 

= z·(x + y) + (x + y) IH= (z·x + z·y) + (x + y) = 

z·x + (z·y + (x + y)) = z·x + (z·y + (y + x)) = z·x + ((z·y + y) + x) 7.1.2(6) 

= 

z·x + (z′·y + x) = z·x + (x + z′·y) = (z·x + x) + z′·y 7.1.2(6) = z′·x + z′·y . 

From now on we will not explicitly indicate the uses of the two axioms of multiplication 7.1.2(5)(6). 

7\.1.14 Multiplication is commutative. That the multiplication com- mutes: 

P̀A x·y = y·x (1) 

is proved by induction on x. In the base case we have 

0·y = 0 7.1.11(1) 

= y·0 . 

In the inductive case we have 

x′·y = x·y + y 7.1.11(2) 

= x·y + y·1 IH= y·x + y·1 7.1.11(1) = y·(x + 1) = y·x′ . 

181

7\.1.15 Multiplication is associative. The proof that the multiplication is associative: 

P̀A (x·y)·z = x·(y·z) (1) 

is by induction on x. In the base case we have 

(0·y)·z = 0·z = 0 = 0·(y·z) . 

In the inductive case we have 

(x′·y)·z = (x·y + y)·z 7.1.14(1) = z·(x·y + y) 

7\.1.11(1) = z·(x·y) + z·y 7.1.14(1) 

= 

(x·y)·z + y·z IH= x·(y·z) + y·z = x′·(y·z) . 

7\.1.16 Cancellation rules for multiplication. Cancellation rules for the multiplication are: 

P̀A z 6= 0 ∧ z·x = z·y → x = y (1) 

P̀A z 6= 0 ∧ x·z = y·z → x = y . (2) 

(1) follows by the commutativity of multiplication from (2) which is proved by assuming z = z′1 for some z1 and continuing by induction on x with the induction formula ∀y(x·z′1 = y·z′1 → x = y). In the base case we take any y, assume 0·z′1 = y·z′1, and consider two cases. If y = 0 then we have x = 0 = y trivially. The case y = y′1 for some y1 leads to a contradiction: 

0 = 0·z′1 = y′1·z′1 = y·z′1 + z′1 = (y1·z′1 + z1)′ . 

In the inductive case we take any y, assume x′·z′1 = y·z′1, and consider two cases again. If y = 0 then the assumption is shown contradictory similarly as above. If y = y′1 then we have 

x·z′1 + z′1 = x′·z′1 = y′1·z′1 = y1·z′1 + z′1 

and so x·z′1 = y1·z′1. We obtain x = y1 by IH and so we get x′ = y′1. From now on we will not explicitly refer to the properties of multiplication 

proved until now. 

7\.2 Extensions of PA 

We study in this section the effect of extensions by definitions of PA on the axioms of induction. 

7\.2.1 Proper extensions of PA. We are interested in proper extensions T of PA which prove all induction axioms of T , i.e. T \` Ixφ\[x\] for all fromulas φ of LT . 

Clearly, the basic theory PA is proper. The following theorem asserts that extensions by definitions yield proper theories from proper ones. 

182

7\.2.2 Theorem. If S is an extension by definitions of a proper extension T of PA then also S is proper. 

Proof. Take the induction axiom Ixφ\[x\]: 

φ\[0\] ∧ ∀x(φ\[x\] → φ\[x′\]) → φ\[x\] 

for an arbitrary formula φ of LS . We use the Theorem on Extensions by defi- nitions 6.6.2 and translate away the predicate or function symbols introduced into S. The translation (Ixφ\[x\])? of Ixφ\[x\] is the following formula of LT : 

φ?\[0\] ∧ ∀x(φ?\[x\] → φ?\[x′\]) → φ?\[x\] . 

We thus have (Ixφ\[x\])? ≡ Ixφ?\[x\] and, since φ∗ is a formula of the proper extension T , we have T \` (Ixφ\[x\])?. Hence S \` Ixφ\[x\] by 6.6.2(2). ut 

7\.2.3 Peano arithmetic in wider sense. In order to escape the irritating references to extensions of extensions of PA we will relativize our terminology. We will designate by PA not only the basic theory of Peano arithmetic, i.e. the six axioms for the function symbols of PA and infinitely many induction axioms, but also the current extension of Peano arithmetic. We will also designate by LPA the language of the current extension of PA. Thus both the language and the axioms of PA will be relative notions depending on the context where the symbols LPA and PA are used. It will be always possible to determine the meaning of both symbols. 

Only in situations where we will be introducing new schemas of exten- sion of PA such as minimalization (see Par. 7.4.3), primitive recursion (see Sect. 8.2), or course of values recursion with measure (see Sect. 8.4) we will temporary revert to designating the extensions of PA by symbols T , S, etc. 

We will also have to be specific about concrete extensions of PA when we will be introducing new induction schemas such as complete induction (see Thm. 7.3.8), the least number principle (see Par. 7.3.10), or measure induction (see Par. 8.4.5). The new induction schemas will be reduced to the induction axioms Ixφ of PA. All extensions of PA in this text will be extensions by definitions, which are proper extensions. As a consequence, the new induction principles will be always provable in the extensions. 

We will also use the expression standard model of PA in the relativized sense to designate the unique expansion of the standard model N of PA to the model of the current extension of PA. The uniqueness of expansion is guaranteed by Thm. 6.6.2. 

We will be using the symbol of provability P̀A φ in the relativized sense as T \` φ where T is the current extension of PA. We will also use the symbol P̀Ax φ with the meaning of P̀A φ when we will wish to emphasize that the formula φ is the defining axiom of the new extension of PA. 

183

7\.3 Introduction of Basic Predicates into PA 

We define in PA the four relations of comparison and prove their basic prop- erties. 

7\.3.1 Comparison predicates. We introduce into PA the binary compar- ison predicates \<, ≤, \>, and ≥ by explicit definitions: 

P̀Ax x \< y ↔ ∃z x + z′ = y (1) 

P̀Ax x ≤ y ↔ x \< y ∨ x = y (2) 

P̀Ax x \> y ↔ y \< x (3) 

P̀Ax x ≥ y ↔ y ≤ x . (4) 

The relation ≤ has the following property: 

P̀A x ≤ y ↔ ∃z x + z = y . (5) 

Indeed, in the direction (→) assume x ≤ y and consider two cases by the definition (2). If x \< y then we have x + z′ = y from the definition and so ∃z x + z = y holds. If x = y then we have x + 0 = y and ∃z x + z = y holds again. 

In the direction (←) assume x + z = y for some z and consider two cases for z. If z = 0 we have x = x + 0 = y. If z = z′1 for some z1 then we have x + z′1 = y and so x \< y holds from the definition. In either case we have x ≤ y from the definition. 

7\.3.2 The relation \< is a linear order. The relation \< (and also \>) is a linear order because we have 

P̀A ¬x \< x (1) 

P̀A x \< y ∧ y \< z → x \< z (2) 

P̀A x \< y ∨ x = y ∨ y \< x . (3) 

The properties are called in that order irreflexivity, transitivity, and linearity. Irreflexivity is proved by induction on x. In the base case we have: 0+z′ = 

(0+z)′ 6= 0 and so ¬∃z 0+z′ = 0 from which we get ¬0 \< 0 from definition. In the inductive case we derive a contradiction by assuming x′ \< x′ as follows. We have x′ + z′ = x′ for some z from the definition and from (x + z′)′ = x′ + z′ = x′ we obtain x + z′ = x from which we get x \< x contradicting IH. 

Transitivity is proved by assuming x \< y and y \< z from which we get x + a′ = y and y + b′ = z for some a and b from the definitions. Hence, x+(a+ b′)′ = x+a′+ b′ = y + b′ = z, i.e. ∃c x+ c′ = z and so we have x \< z. 

For the linearity we need an auxiliary property 

P̀A 0 \< x′ (4) 

184

which follows from 0+x′ = x′ by existential instantiation and the definition. Linearity is proved by induction on x. In the base case we wish to prove 

0 \< y ∨ 0 = y ∨ y \< 0 for which we consider two cases. If y = 0 the property 

holds trivially. If y = y′1 for some y1 then we have 0 (4) \< y′1 = y. In the inductive 

case we wish to prove x′ \< y∨x′ = y∨y \< x′. From the inductive hypothesis (3) we consider three cases. If x \< y then we have x′ + z = x + z′ = y for some z from the definition and so x′ ≤ y by 7.3.1(5). From this we get x′ \< y or x′ = y from the definition. 

If x = y we have y + 0′ = x + 0′ = x′ + 0 = x′ and so y \< x′ from the definition. 

Finally, if y \< x we have y + z′ = x for some z from the definition and so y + z′′ = (y + z′)′ = x′ from which we get y \< x′ from the definition. 

7\.3.3 Trichotomy and dichotomy laws. The laws of trichotomy and di- chotomy are in that order the following formulas: 

P̀A x \< y ∨ x = y ∨ x \> y (1) 

P̀A x ≤ y ∨ x \> y . (2) 

The laws are typically used for case analysis and they directly follow from the linearity 7.3.2(3) of \< by the definitions. 

7\.3.4 Ordering properties of relation ≤. The predicate ≤ constitutes a (total) ordering relation which is reflexive, transitive, antisymmetric, and linear. This is expressed in that order as follows: 

P̀A x ≤ x (1) 

P̀A x ≤ y ∧ y ≤ z → x ≤ z (2) 

P̀A x ≤ y ∧ y ≤ x → x = y (3) 

P̀A x ≤ y ∨ y ≤ y . (4) 

Property (1) follows directly from the definition. Property (2) follows from the transitivity of \<. 

(3): If x ≤ y, y ≤ x, and x 6= y hold then we obtain x \< y and y \< x from the definitions. From this we get x \< x by transitivity which contradicts the irreflexivity of \<. 

Property (4) is a direct consequence of linearity 7.3.2(3) of \<. 

7\.3.5 Additional properties of comparisons. We have the following ad- ditional properties of the comparison relations: 

P̀A x 6\< 0 (1) 

P̀A 0 ≤ x (2) 

P̀A x \< x′ (3) 

P̀A x \< y ↔ x′ ≤ y . (4) 

185

(1) Assume on the contrary x \< 0. We then have x + z′ = 0 for some z from the definition and we get the contradiction z′ = 0 by 7.1.7(1). 

(2) is a direct consequence of (1) and 7.3.3(2). (3): We have x + 0′ = (x + 0)′ = x′ and so ∃z x + z = x′ holds. We now 

get x \< x′ from the definition. For (4) we have x \< y iff x + z′ = y for some z iff x′ + z = y for some z 

iff x′ ≤ y by 7.3.1(5). 

7\.3.6 Monotonicity of addition and multiplication. Addition and mul- tiplication are monotone: 

P̀A x \< y ↔ z + x \< z + y (1) 

P̀A x \< y ↔ x + z \< y + z (2) 

P̀A z \> 0 → x \< y ↔ z·x \< z·y (3) 

P̀A z \> 0 → x \< y ↔ x·z \< y·z . (4) 

(1): We have x \< y iff x + u′ = y for some u iff, by 7.1.10(1) and properties of identity, z + (x + u′) = z + y for some u iff (z + x) + u′ = z + y for some u iff z + x \< z + y. 

Property (2) follows from (1) by commutativity of addition. (3): In the direction (→) assume z = z′1 and x + u′ = y for some z1 and 

u. We have 

z′1·y = z′1·(x + u′) = z′1·x + z′1·u′ = z′1·x + (z1·u′ + u′) = z′1·x + (z1·u′ + u)′ 

and so z′1·x \< z′1·y holds by definition. In the direction (←) assume z = z′1 and prove 

∀y(z′1·x \< z′1·y → x \< y) 

by induction on x. In the base case take any y and assume z′1·0 \< z′1·y. We then have 0 \< z′1·y. If it were the case that y = 0 we would get a contradiction 0 \< z′1·0 = 0 with 7.3.2(1). Hence y = y′1 for some y1 and we have 0 \< y by 7.3.2(4). 

In the inductive case take any y and assume z′1·x′ \< z′1·y. If it were the case that y = 0 we would get a contradiction z′1·x′ \< z′1·0 = 0 with 7.3.5(1). Hence y = y′1 for some y1 and we have 

x·z′1 + z′1 = x′·z′1 = z′1·x′ \< z′1·y′1 = y′1·z′1 = y1·z′1 + z′1 . 

We now obtain x·z′1 \< y1·z′1 by (2) and x \< y1 by IH. Hence x′ = x + 1 (2) \< 

y1 + 1 = y′1. Property (4) follows from (3) by the commutativity of multiplication. 

186

7\.3.7 Complete induction. Let T be a proper extension of PA containing the predicate \<, φ\[x\] a formula of LT with the indicated variable x free and with possibly additional parameters, and y a new variable. The formula of complete induction on x for φ\[x\] is the following one: 

∀x(∀y(y \< x → φ\[y\]) → φ\[x\]) → φ\[x\] . (1) 

7\.3.8 Theorem. Every proper extension T of PA containing the predicate \< proves the schema of complete induction 7.3.7(1). 

Proof. We prove 7.3.7(1) in T from an auxiliary property 

T \` ∀x(∀y(y \< x → φ\[y\]) → φ\[x\]) → ∀y(y \< x → φ\[y\]) 

which is proved by assuming the formula expressing that φ is progressive: 

∀x(∀y(y \< x → φ\[y\]) → φ\[x\]) (1) 

and proving 

∀y(y \< x → φ\[y\]) (2) 

by induction on x. In the base case there is nothing to prove. In the inductive case we take any y s.t. y \< x′ and consider two cases by dichotomy. If y \< x we obtain φ\[y\] from IH: (2). If y ≥ x then we have y = x and note that IH, i.e. (2), is the antecedent of (1) from which we obtain φ\[x\], i.e. φ\[y\]. 

We obtain T \` 7.3.7(1) from the auxiliary property by instantiating its consequent with x := x′ and y := x. ut 

7\.3.9 The least number principle. Let T be a proper extension of PA containing the predicate \<, φ\[x\] a formula of LT with the indicated variable x free and with possibly additional parameters, and y a new variable. The formula of the least number principle for φ is the following one: 

∃xφ\[x\] → ∃x(φ\[x\] ∧ ∀y(y \< x → ¬φ\[y\])) . (1) 

The least number principle says that if the property φ\[x\] holds for some x then it holds for the least such x. 

7\.3.10 Theorem. Every proper extension T of PA containing the predicate \< proves the schema of the least number principle 7.3.9(1). 

Proof. We prove 7.3.9(1) in T from the complete induction for ¬φ: 

T \` ∀x(∀y(y \< x → ¬φ\[y\]) → ¬φ\[x\]) → ¬φ\[x\] 

which is a theorem of T by Thm. 7.3.8. Its converse is 

φ\[x\] → ∃x(∀y(y \< x → ¬φ\[y\]) ∧ φ\[x\]) 

and 7.3.9(1) logically follows by quantifier operations. ut 

187

7\.4 Introduction of Basic Functions into PA 

We will extend PA by some basic functions such as division, introduce exten- sions by minimalization, and prove that they are extensions by definition. 

7\.4.1 Small constants. We have used 1 as abbreviation for the term 0′ in Sect. 7.1. We now introduce the symbols 1, 2, 3, and 4 into PA as constants by explicit definitions: 

P̀A 1 = 0′ (1) 

P̀A 2 = 1′ (2) 

P̀A 3 = 2′ (3) 

P̀A 4 = 3′ . (4) 

7\.4.2 Extensions by minimalization. Let T be a proper extension of PA containing the predicate \< and φ\[\~x, y\] a formula of LT with all free variables among the indicated ones where \~x contains n ≥ 0 variables. If T proves the existence condition: 

T \` ∃yφ\[\~x, y\] (1) 

then the extension of T to S with the n-ary function symbol f and the defining axiom a universal closure of 

φ\[\~x, f(\~x)\] ∧ ∀y(y \< f(\~x) → ¬φ\[\~x, y\]) . (2) 

is called extension by minimalization. We will use a more suggestive notation as an abbreviation for the above 

defining axiom: 

f(\~x) = µy\[φ\[\~x, y\]\] . (3) 

The idea is that the function f defined by this definition yields for every \~x the minimal y such that φ\[\~x, y\] holds because on accord of the existence condition ∃yφ\[\~x, y\] there is at least one such y. 

The defining axiom clearly implies S \` φ\[\~x, f(\~x)\] and 

S \` y \< f(\~x) → ¬φ\[\~x, y\] , 

which is equivalent to S \` φ\[\~x, y\] → f(\~x) ≤ y 

whenever T contains the predicate ≤. 

188

7\.4.3 Theorem. If T is a proper extension of PA containing the predicate \< then an extension of T by minimalization is an extension by definition. 

Proof. Let S be the extension of T by minimalization as in Par. 7.4.2 and S1 

an extension of T with f implicitly defined by ψ\[\~x, f(\~x)\] for the formula 

ψ\[\~x, y\] ≡ φ\[\~x, y\] ∧ ∀z(z \< y → ¬φ\[\~x, z\]) . 

Since ψ\[\~x, f(\~x)\] and 7.4.2(2) are variants, S will be an extension by definition of T by Thm. 6.6.3 provided T proves the existence and uniqueness conditions for ψ. We note that the existence condition ∃yψ\[\~x, y\] is the consequent of the instance of the least number principle 

T \` ∃yφ\[\~x, y\] → ∃y(φ\[\~x, y\] ∧ ∀z(z \< y → ¬φ\[\~x, z\])) , 

which is provable in T by Thm. 7.3.10. We thus get ∃yψ\[\~x, y\] in T from 7.4.2(1). 

For the proof of the uniqueness condition we work in T , assume ψ\[\~x, y1\], ψ\[\~x, y2\], and consider three cases. If y1 \< y2 then we obtain ¬φ\[\~x, y1\] from ψ\[\~x, y2\] which contradicts φ\[\~x, y1\] implied by ψ\[\~x, y1\]. If y1 \> y2 we derive a contradiction similarly. Thus it must be the case that y1 = y2. ut 

7\.4.4 Modified subtraction. We wish to extend Peano arithmetic with a binary modified subtraction function x .− y with the basic properties 

P̀A y ≤ x → x = y + (x .− y) . (1) 

P̀A y \> x → x .− y = 0 . (2) 

The modified subtraction function is introduced by minimalization 

P̀Ax x .− y = µz\[y ≤ x → x = y + z\] (3) 

with the existence condition 

P̀A ∃z(y ≤ x → x = y + z) , 

which is equivalent to y ≤ x → ∃z x = y + z, holding by 7.3.1(5). The defining axiom for .− directly implies Property (1) and 

P̀A z \< x .− y → ¬(y ≤ x → x = y + z) . (4) 

From this we obtain 0 \< x .− y → y ≤ x, which is equivalent to (2) by dichotomy and 7.3.5(1). 

7\.4.5 Maximum. The maximum function max(x, y) with the basic prop- erties 

189

P̀A x ≤ max(x, y) (1) 

P̀A y ≤ max(x, y) (2) 

P̀A x = max(x, y) ∨ y = max(x, y) (3) 

is introduced into PA by minimalization 

P̀Ax max(x, y) = µz\[x ≤ z ∧ y ≤ z\] (4) 

whose existence condition 

P̀A ∃z(x ≤ z ∧ y ≤ z) 

is proved by case analysis. If x ≤ y then we take z := y. If x \> y then we take z := x. 

The defining axiom for the maximum function directly implies Properties (1) and (2) as well as 

P̀A x ≤ z ∧ y ≤ z → max(x, y) ≤ z . 

Property (3) is proved from the last by case analysis. If x ≤ y then for z := y we get max(x, y) ≤ y and we obtain max(x, y) = y from (2) by antisymmetry. If x \> y then for z := x we get max(x, y) ≤ x and we obtain max(x, y) ≤ y similarly. 

7\.4.6 The square function. We introduce the unary function x2 yielding the square of x into PA by explicit definition: 

P̀Ax x2 = x·x . (1) 

7\.4.7 Whole part of square root. We wish to introduce into PA the function \[ 

√ x\] yielding the whole part of the square root of x which satisfies 

P̀A \[ √ 

x\]2 ≤ x \< (\[ √ 

x\] + 1)2 . (1) 

The function is defined by minimalization: 

P̀Ax \[ √ 

x\] = µy\[x \< (y + 1)2\] (2) 

whose existence condition 

P̀A ∃y x \< (y + 1)2 

holds for y := x because 

x = x·1 ≤ x·(x + 1) \< (x + 1)·(x + 1) = (x + 1)2 . 

The defining axiom for \[ √ 

x\] implies 

190

P̀A x \< (\[ √ 

x\] + 1)2 (3) 

P̀A y \< \[ √ 

x\] → (y + 1)2 ≤ x . (4) 

From (3) we can see that for the proof of (1) it suffices to show \[ √ 

x\]2 ≤ x. For that we consider two cases. If \[ 

√ x\] = 0 then we have 02 = 0 ≤ x. If 

\[ √ 

x\] = y′ for some y then, since y \< \[ √ 

x\], we obtain \[ √ 

x\]2 = (y + 1)2 ≤ x from (4). 

7\.4.8 Integer division and remainder. We wish to introduce into PA integer division x÷y and remainder x mod y functions satisfying the following 

P̀A y \> 0 → x = x÷ y·y + x mod y ∧ x mod y \< y (1) 

P̀A y \> 0 ∧ x = q·y + r ∧ r \< y → q = x÷ y ∧ r = x mod y (2) 

P̀A x÷ 0 = 0 (3) 

P̀A x mod 0 = 0 . (4) 

We claim that the functions can be introduced by minimalization: 

P̀Ax x÷ y = µq\[y \> 0 → x \< (q + 1)·y\] (5) 

P̀Ax x mod y = µz\[y \> 0 → z = x .−x÷ y·y\] (6) 

The existence condition for the division function (5) is 

P̀A ∃q(0 \< y → x \< (q + 1)·y) . 

This holds because if y = 0 then set q := 0 and if y \> 0 then set q := x because we have 

x = x·1 ≤ x·y \< (x + 1)·y . 

The defining axiom for ÷ implies: 

P̀A y \> 0 → x \< (x÷ y + 1)·y (7) 

P̀A q \< x÷ y → (q + 1)·y ≤ x (8) 

P̀A y = 0 → x÷ y ≤ q (9) 

The existence condition for the remainder function (6) is equivalent to P̀A y \> 0 → ∃z z = x .−x÷ y·y and it is proved trivially. The defining axiom for mod implies 

P̀A y \> 0 → x mod y = x .−x÷ y·y (10) 

P̀A z = x .−x÷ y·y → x mod y ≤ z (11) 

P̀A y = 0 → x mod y ≤ z . (12) 

For the proof of Property (1) we assume y \> 0 and prove an auxiliary property 

191

P̀A x÷ y·y ≤ x (13) 

by considering two cases. If x÷ y = 0 then we have 

x÷ y·y = 0·y = 0 ≤ x . 

If x÷ y = q′ for some q then, since q \< x÷ y, we obtain 

x÷ y·y = (q + 1)·y (8) 

≤ x . 

We then have 

x÷ y·y + x mod y (10) = x÷ y·y + (x .−x÷ y·y) 

(13),7.4.4(1) = x 

(7) \< 

(x÷ y + 1)·y = x÷ y·y + y . 

Note that x mod y \< y holds by 7.3.6(1). Property (2) is proved by assuming y \> 0, x = q·y + r with r \< y, and 

considering three cases by trichotomy. If x÷y \< q then we have q = x÷y+z′ 

for some z. We then obtain 

x÷ y·y + x mod y (1) = x = q·y + r = x÷ y·y + z′·y + r 

and hence x mod y = z′·y + r by 7.3.6(1). Thus x mod y = y + z·y + r from which we have x mod y ≥ y which contradicts x mod y \< y. 

If q \< x ÷ y then we have x ÷ y = q + z′ for some z. We then similarly obtain 

q·y + r = x (1) = x÷ y·y + x mod y = q·y + z′·y + x mod y 

from which we get r = z′·y + x mod y = y + z·y + x mod y and thus r ≥ y which contradicts r \< y. 

Thus the third case x÷ y = q must obtain and, since then 

q·y + r = x (1) = x÷ y·y + x mod y = q·y + x mod y , 

we get r = x mod y by 7.3.6(1). (3): Take y := 0 and q := 0 in (9) and obtain x÷ 0 ≤ 0, i.e. x÷ 0 = 0. (4): Take y := 0 and z := 0 in (12) and obtain x mod 0 ≤ 0, i.e. x mod 0 = 

0\. 

7\.5 The Lattice of Divisibility 

7\.5.1 Divisibility predicate. The binary divisibility predicate x \| y, read as x divides y is defined in PA by an explicit definition: 

192

P̀Ax x \| y ↔ ∃z y = z·x . (1) 

The predicate of divisibility is a relation of partial order (similar to ≤ but without the linearity 7.3.4(4)) which satisfies the reflexivity, transitivity, and antisymmetry. The partial order is with the least element 1 and the greatest element 0: 

P̀A x \| x (2) 

P̀A x \| y ∧ y \| z → x \| z (3) 

P̀A x \| y ∧ y \| x → x = y (4) 

P̀A 1 \| x (5) 

P̀A x \| 0 . (6) 

(2): We have x = 0 + x = 0·x + x = 0′·x and so ∃z x = z·x. (3): Assume x \| y and y \| z, i.e. y = a·x and z = b·y for some a and b. 

Then z = b·y = b·a·x and so for u := b·a we have ∃u z = u·x. (4): Assume x \| y and y \| x, i.e. y = a·x and x = b·y for some a and b. 

Then x = b·y = b·a·x. We consider two cases. If x = 0 then also y = a·0 = 0. If x \> 0 then, since x = b·a·x + 0 and x = 1·x + 0, we obtain b·a = x÷ x = 1 by 7.4.8(2). But then a = 1 and b = 1 by 7.1.12(1) and so x = y. 

(5): We have x = x·1 and so ∃z x = z·1. (6): We have 0 = 0·x and so ∃z 0 = z·x. 

7\.5.2 Additional properties of divisibility. The relation between the divisibility predicate and the remainder function is given by the following property: 

P̀A y 6= 0 → y \| x ↔ x mod y = 0 . (1) 

Indeed, assume y \> 0. In the direction (→) also assume y \| x, i.e. x = z·y = z·y +0 for some z. We get x mod y = 0 by 7.4.8(2). In the direction (←) also assume x mod y = 0. We then have 

x 7.4.8(1) 

= x÷ y·y + x mod y = x÷ y·y 

and for z := x÷ y we have ∃z x = z·y. We also have 

P̀A x 6= 0 ∧ y \| x → y ≤ x (2) 

because if x \> 0 and x = z·y for some z then it must be the case that z \> 0. If it were the case that x \< y then we would have z·x \< z·y = x = 1·x and hence z \< 1 by the monotonicity of multiplication. 

We will need the following property: 

P̀A a + b = c ∧ x \| a ∧ x \| c → x \| b (3) 

193

which is proved by assuming its antecedent and considering two cases. If x = 0 then from x \| a and x \| c we get a = b = 0 and hence b = 0 from which we have x \| b by 7.5.1(6). 

If x \> 0 then for some a1 and c1 we have a1·x = a ≤ c = c1·x and so a1 ≤ c1, i.e. a1 + u = c1 for some u. We then get 

a + u·x = a1·x + u·x = (a1 + u)·x = c1·x = c . 

Thus b = u·x, i.e. x \| b. 

7\.5.3 The lattice of divisibility. A set with a partial order where for every two elements x and y exists their least upper bound x ∪ y (called the join of x and y) and their greatest lower bound x ∩ y (called the meet of x and y) is a lattice. The partial order on natural numbers given by the relation of divisibility x \| y forms a lattice where the join x ∪ y is the least common multiple of x and y and the meet x ∩ y is the greatest common divisor of x and y. We wish to introduce the operations into PA to satisfy: 

P̀A x \| x ∪ y ∧ y \| x ∪ y (1) 

P̀A x \| z ∧ y \| z → x ∪ y \| z (2) 

P̀A x ∩ y \| x ∧ x ∩ y \| y (3) 

P̀A z \| x ∧ z \| y → z \| x ∩ y . (4) 

We claim that the least common multiple x ∪ y can be introduced by mini- malization: 

P̀Ax x ∪ y = µz\[x = 0 ∨ y = 0 ∨ z \> 0 ∧ x \| z ∧ y \| z\] (5) 

whose existence condition 

P̀A ∃z(x = 0 ∨ y = 0 ∨ z \> 0 ∧ x \| z ∧ y \| z) 

is proved by taking any x, y and considering two cases. If x = 0 or y = 0 then it suffices to take z := 0. If x \> 0 and y \> 0 then also x·y \> 0 and, since x \| x·y and y \| x·y, it suffices to take z := x·y. The defining axiom for ∪ implies 

P̀A x \> 0 ∧ y \> 0 → x ∪ y \> 0 ∧ x \| x ∪ y ∧ y \| x ∪ y (6) 

P̀A x = 0 ∨ y = 0 → x ∪ y ≤ z (7) 

P̀A z \> 0 ∧ x \| z ∧ y \| z → x ∪ y ≤ z . (8) 

We prove (1) by taking any x, y and considering two cases. If x = 0 or y = 0 then we have x ∪ y = 0 from (7) by taking z := 0 and the property holds on account of 7.5.1(6). If x \> 0 and y \> 0 then (1) follows from (6). 

We prove (2) by taking any x, y and considering two cases. If x = 0 or y = 0 then if x \| z and y \| z we obtain z = 0 and thus x ∪ y \| z by 7.5.1(6). 

194

If x \> 0 and y \> 0 then we prove (2) by complete induction on z. Assume x \| z, y \| z and consider two cases. If z = 0 then also x ∪ y \| z by 7.5.1(6). If z \> 0 then we have 

0 (6) \< x ∪ y 

(8) 

≤ z 

and so (x ∪ y) + u = z for some u. Since x \| x ∪ y, we obtain x \| u by 7.5.2(3). We get y \| u similarly and, since u \< z, we obtain x ∪ y \| u by IH, i.e u = a·(x ∪ y) for some a. From this, since 

z = (x ∪ y) + u = (x ∪ y) + a·(x ∪ y) = (1 + a)·(x ∪ y) , 

we get x ∪ y \| z. We claim that the greatest common divisor x ∩ y can be introduced by 

minimalization: 

P̀Ax x ∩ y = µz\[z \| x ∧ z \| y ∧ ∀u(u \| x ∧ u \| y → u \| z)\] (9) 

whose existence condition is implied by 

P̀A ∀y∃z(z \| x ∧ z \| y ∧ ∀u(u \| x ∧ u \| y → u \| z)) 

which is proved by complete induction on x. We take any y and consider two cases. If x = 0 then it clearly suffices to take z := y. If x \> 0 then, since x \> y mod x, we use IH with y := x to obtain a z s.t. z \| y mod x, z \| x, and 

∀u(u \| y mod x ∧ u \| x → u \| z) . (10) 

We have x = a·z and y mod x = b·z for some a and b. We claim that 

z \| x ∧ z \| y ∧ ∀u(u \| x ∧ u \| y → u \| z) 

holds for the same z. For that we note 

y 7.4.8(1) 

= y ÷ x·x + y mod x = y ÷ x·a·z + b·z = (y ÷ x·a + b)·z 

and so z \| y. Now take any u and assume u \| x and u \| y. Since y = y÷x·x+y mod x, we see that u \| y mod x by 7.5.2(3). We now get u \| z from (10). 

Properties (3) and (4) are a direct consequence of the defining axiom for x ∩ y. 

7\.5.4 Joins and meets versus the partial order. In every lattice we have x ∪ y = x iff y ≤ x iff x ∩ y = y. This has the following form in the lattice of divisibility: 

P̀A x ∪ y = x ↔ y \| x (1) 

P̀A x ∩ y = y ↔ y \| x (2) 

195

and the proof is solely by using the four properties 7.5.3(3) through 7.5.3(4) of ∪ and ∩ as well as the fact that \| is a partial order satisfying 7.5.1(2) through 7.5.1(4). 

(1): In the direction (→) assume x ∪ y = x and get y \| x ∪ y = x from 7.5.3(1). In the direction (←) assume y \| x. Since x \| x by 7.5.1(2) we get x ∪ y \| x by 7.5.3(2). We have x \| x ∪ y by 7.5.3(1) and so x ∪ y = x by 7.5.1(4). 

Property (2) is proved similarly. 

7\.5.5 The lattice of divisibility is atomic. An element p of a lattice is an atom if the only element strictly less than p is the least element of the lattice. The divisibility lattice has 1 as the least element and so the predicate Prime(p) is explicitly introduced to hold exactly of its atoms: 

P̀Ax Prime(p) ↔ p 6= 1 ∧ ∀x(x \| p → x = 1 ∨ x = p) (1) 

Thus p is an atom of the divisibility lattice iff it is a prime number. For 2 = 1′ = 0′′ we have 

P̀A ¬Prime(0) (2) 

P̀A Prime(2) . (3) 

(2): We have 2 \| 0 by 7.5.1(6) and 1 6= 2 6= 0. (3): We have 2 6= 1 and if x \| 2 then x ≤ 2 by 7.5.2(2). Since 0 - 2 we can 

have at most 1 \| 2 or 2 \| 2. A lattice with the least element is atomic if to every non-minimal element 

x which is not an atom there is an atom p less than x. The divisibility lattice is atomic because we have: 

P̀A x 6= 1 → ∃p(Prime(p) ∧ p \| x) . (4) 

This is proved by complete induction on x. We consider three cases for x. If x = 0 then it suffices to take p := 2 by (3) and 7.5.1(6). If x = 1 there is nothing to prove. Finally, if x \> 1 then we consider two cases again. If Prime(x) then it suffices to take p := x because of 7.5.1(2). If ¬Prime(x) then there is a number q \| x s.t. x 6= 1 and q 6= x from the definition. We have q ≤ x by 7.5.2(2) and, since q \< x, there is a prime p s.t. p \| q by IH for which we get p \| x by 7.5.1(3). 

7\.5.6 The lattice of divisibility is distributive. In every lattice we have (x ∩ y) ∪ (x ∩ z) ≤ x ∩ (y ∪ z). We prove this and its dual for the lattice of divisibility solely from the seven properties given in Par. 7.5.4: 

P̀A y \| z → x ∩ y \| x ∩ z (1) 

P̀A (x ∩ y) ∪ (x ∩ z) \| x ∩ (y ∪ z) . (2) 

196

(1): Assume y \| z. We have x ∩ y \| x and x ∩ y \| y and so x ∩ y \| z by transitivity. Hence x ∩ y \| x ∩ z by 7.5.3(4). 

(2): Since y \| y ∪ z and z \| y ∪ z, we obtain x ∩ y \| x ∩ (y ∪ z) and x ∩ z \| x ∩ (y ∪ z) by (1). The property now follows by 7.5.3(2). 

UNFINISHED 

P̀A x ∩ (y ∪ z) = (x ∩ y) ∪ (x ∩ z) (3) 

P̀A x ∪ (y ∩ z) = (x ∪ y) ∩ (x ∪ z) . (4) 

7\.5.7 A property of prime divisors. We will need Property (2) which is a simple consequence of distributivity of the lattice of divisibility. 

P̀A x ∪ x = x (1) 

P̀A Prime(p) ∧ p \| x ∪ y → p \| x ∨ p \| y . (2) 

(1): This follows from x \| x by 7.5.4(1). (2): Assume that p is a prime s.t. p \| x ∪ y. If it were the case that p - x 

and p - y then we would get p ∩ x 6= p, p ∩ y 6= p by 7.5.4(2). But p ∩ x \| p and p∩ y \| p by 7.5.3(3) and so p∩ x = 1 = p∩ y by the definition of primes. But then we could derive a contradiction: 

p 7.5.4(2) 

= p ∩ (x ∪ y) 7.5.6(3) 

= (p ∩ x) ∪ (p ∩ y) = 1 ∪ 1 (1) = 1 

with the definition of primes. 

7\.5.8 Coprime numbers. Two numbers x and y are coprime (relatively prime) if x∩y = 1. We will need the following property which says that every two successive numbers are coprime: 

P̀A x ∩ (x + 1) = 1 . (1) 

We claim that (1) follows from 

P̀A z \| x ∧ z \| x + 1 → z = 1 . (2) 

Indeed, take z := x∩x+1 and use 7.5.3(3). For the proof of (2) assume z \| x, z \| x + 1, and consider three cases. If z = 0 then, since x + 1 = b·z for some b, we obtain a contradiction x + 1 = b·z = 0. If z \> 1 then, since x = a·z for some a, we get x + 1 = a·z + 1 and so (x + 1) mod z = 1 by 7.4.8(2). We now obtain contradiction z - x + 1 by 7.5.2(1). Thus it must be the case that z = 1. 

7\.5.9 Least common multiple of interval \[1..x\]. We will need a func- tion 

⋃x i=1 i yielding finitely many least common multiples of numbers in the 

(possibly empty) interval \[1..x\]. The function should satisfy: 

197

P̀A 

0⋃ 

i=1 

i = 1 (1) 

P̀A 

x′⋃ 

i=1 

i = ( x⋃ 

i=1 

i) ∪ x′ . (2) 

We claim that the function can be defined by minimalization 

P̀Ax 

x⋃ 

i=1 

i = µm\[x = 0 ∧m = 1 ∨ 

x 6= 0 ∧ ∀y(0 \< y ≤ x → y \| m) ∧ ∀z(∀y(0 \< y ≤ x → y \| z) → m \| z)\] 

whose existence condition 

P̀A ∃m(x = 0 ∧m = 1 ∨ x \> 0 → ∀y(0 \< y ≤ x → y \| m) ∧ ∀z(∀y(0 \< y ≤ x → y \| z) → m \| z)) 

is proved by iduction on x. In the base case we take m := 1. In the inductive case we obtain an m1 s.t. 

x = 0 ∧m1 = 1 ∨ x 6= 0 ∧ ∀y(0 \< y ∧ y ≤ x → y \| m1) ∧ ∀z(∀y(0 \< y ≤ x → y \| z) → m1 \| z) 

(3) 

by IH. We claim that it suffices to take m := m1 ∪ x′. We consider two cases 

for x. If x = 0 then m1 = 1 and m = 1 ∪ 1 7.5.7(1) 

= 1. We now take any y s.t. 0 \< y ≤ x′ = 1, i.e. y = 1, and we have y \| m. We also have m = 1 \| z for any z. 

If x 6= 0 then for any y s.t. 0 \< y ≤ x′ we consider two cases agian. If y \< x′ then y \| m1 by (3) and, since m1 \| m, we get y \| m by transitivity. If y ≥ x′ then y = x′ and we have y = x′ \| m. If for any z we have ∀y(0 \< y ≤ x′ → y \| z) then we have x′ \| z directly and m1 \| z by (3). Hence m = m1 ∪ x′ \| z by 7.5.3(2). 

The defining axiom for ⋃x 

i=1 i directly implies Property (1) and also 

P̀A 0 \< y ≤ x → y \| x⋃ 

i=1 

i (4) 

P̀A x 6= 0 ∧ ∀y(0 \< y ≤ x → y \| u) → x⋃ 

i=1 

i \| u . (5) 

We prove Property (2) by showing first 

198

P̀A 

x′⋃ 

i=1 

i \| ( x⋃ 

i=1 

i) ∪ x′ (6) 

by taking any y s.t. 0 \< y ≤ x′ and considering two cases. If y ≤ x then y \| ⋃x 

i=1 i by (4) and, since ⋃x 

i=1 i \| (⋃x i=1 i) ∪ x′, we obtain y \| (⋃x 

i=1 i) ∪ x′ 

by transitivity. If y = x′ then we have x′ \| ( ⋃x′ 

i=1 i) ∪ x′. (6) now follows by (5). 

We then prove 

P̀A ( x⋃ 

i=1 

i) ∪ x′ \| x′⋃ 

i=1 

i (7) 

by proving first ⋃x 

i=1 i \| ⋃x′ 

i=1 i by considering two cases. If x = 0 then ⋃x 

i=1 i (1) = 1 \| ⋃x′ 

i=1 i by 7.5.1(5). If x 6= 0 we take any y s.t. 0 \< y ≤ x. We have y \| ⋃x′ 

i=1 i by (4) and hence ⋃x 

i=1 i \| ⋃x′ 

i=1 i by (5). From ⋃x 

i=1 i \| ⋃x′ 

i=1 i 

and from x′ \| ⋃x′ 

i=1 i which holds by (4) we get (7) by 7.5.3(2). Property (2) now follows from (6) and (7) by antisymmetry. Surprising as it is, we need a proof by induction on x of the following 

property: 

P̀A 

x⋃ 

i=1 

i 6= 0 . (8) 

In the base case the property follows from (1). In the inductive case we have⋃x i=1 i 6= 0 by IH and 

0 7.5.3(6) 

6= ( x⋃ 

i=1 

i) ∪ x′ (2) = 

x′⋃ 

i=1 

i . 

We will need the following lower bound on our function: 

P̀A x ≤ x⋃ 

i=1 

i (9) 

which is proved by considering two cases. If x = 0 then (9) holds by (1). If x 6= 0 then x \| ⋃x 

i=1 i by (4). Since ⋃x 

i=1 i 6= 0 by (8), the property follows from 7.5.2(2). 

7\.5.10 Euclid’s theorem on prime numbers. The lattice of divisibility has infinitely many atoms by the famous second theorem of Euclid which asserts that there are infinitely many prime numbers: 

P̀A ∃p(p \> x ∧ Prime(p)) (1) 

199

This is proved by taking any x and considering the number q = ( ⋃x 

i=1 i) + 1. For every y \> 1 s.t. y ≤ x we have y \| ⋃x 

i=1 i by 7.5.9(4). If it were the case that y \| q then by 7.5.3(4) we would have a contradiction y = 1 by 7.5.8(2). We have just proved: 

∀y(y \> 1 ∧ y ≤ x → y - q) (2) 

Since q 6= 1 by 7.5.9(8) there is a prime p s.t. p \| q by 7.5.5(4). By (2) we have p = 1, p = 0, or p \> x. But p 6= 1 by the definition of primes, p 6= 0 by 7.5.5(2), and so it must be the case that p \> x. 

200

8\. Recursive Bootstrapping of PA 

8\.1 Exponentiation Function 

8\.1.1 Binary successors. We introduce two binary successor functions by explicit definitions: 

P̀Ax x0 = 2·x (1) 

P̀Ax x1 = 2·x + 1 . (2) 

Binary successors are interesting because of binary discrimination: 

P̀A ∃y(x = y0 ∨ x = y1) (3) 

which directly follows from x = x÷ 2·2 + x mod 2 with x mod 2 \< 2 holding by 7.4.8(1). 

8\.1.2 The plan for the introduction of 2x into PA. We wish to in- troduce into PA the exponentiation function 2x satisfying the natural recur- rences: 

P̀A 20 = 1 (1) 

P̀A 2x′ = 2·2x . (2) 

We will not be able to express the computation of 2x by these recurrences but we will succeed in encoding the computation of 2x by the following ex- ponentially faster recurrences by recursion on binary notation: 

20 = 1 

2x0 = (2x)2 if x \> 0 

2x1 = 2·(2x)2 . 

We will do this by introducing in Par. 8.1.3 the predicate Pow2(p) of being a power of two satisfying 

P̀A Pow2(p) ↔ ∃x 2x = p

and with its help to define in Par. 8.1.10 the log function as the inverse of 2x 

by encoding its computation from the following recurrences: 

Pow2(p) ∧ p = 1 → log(p) = 0 

Pow2(p) ∧ p = q2 ∧ p \> 1 → log(p) = log(q)0 

Pow2(p) ∧ p = 2·q2 → log(p) = log(q)1 . 

That the recurrences cover all cases for p and that they are exclusive will be proved in Par. 8.1.5. 

Only then we will be able to introduce in Par. 8.1.11 the exponentiation function satisfying 

P̀A 2x = p ↔ Pow2(p) ∧ log(p) = x . 

8\.1.3 The predicate of being a power of two. The predicate Pow2(p) of p being a power of two, i.e. such that ∃x 2x = p, can be presented in a clausal form with binary recurrences: 

Pow2(x0) ← x \> 0 ∧ Pow2(x) Pow2(x1) ← x = 1 . 

We claim that we can introduce into PA the predicate Pow2 to satisfy the clauses properties by the following explicit definition: 

P̀Ax Pow2(p) ↔ p 6= 0 ∧ ∀x(x \| p → x = 1 ∨ 2 \| x) . (1) 

Since Pow2(p) → p \> 0 holds directly from the definition, the above clauses are equivalent to the following properties: 

P̀A Pow2(x0) ↔ Pow2(x) (2) 

P̀A Pow2(x1) ↔ x = 0 . (3) 

(2): In the direction (→) assume Pow2(x0). We have x0 \> 0 and thus x \> 0 from the definition. Now take any z s.t. z \| x. Since then z \| 2·x we get z = 1 or 2 \| z from the assumption Pow2(x0) and so Pow2(x) holds. In the direction (←) assume Pow2(x). Since x \> 0, we have 2·x \> 0 and we take any z s.t. z \| 2·x. We wish to prove z = 1 or 2 \| z. We consider two cases according to 8.1.1(3). If z = 2·z1 for some z1 then 2 \| z. If z = 2·z1 + 1 for some z1 then, since 2·x = a·z for some a, we have 2·x = 2·a·z1 + a and we get a = a1·2 for some a1 by 7.5.2(3). Thus x = a1·2·z1 + a1 = a1·(2·z1 + 1) and so z \| x. We now get z = 1 or 2 \| x from the assumption Pow2(x). 

(3): In the direction (→) assume Pow2(2·x+1). Since 2·x+1 \| 2·x+1, we get from the assumption 2·x + 1 = 1 or 2 \| 2·x + 1. The latter cannot be the case by 7.5.2(1) and so 2·x + 1 = 1 must hold. Hence x = 0. In the direction (←) it suffice to prove Pow2(1). We have 1 6= 0 and we take any z s.t. z \| 1. Since 1 \| z by 7.5.1(5), we obtain z = 1 by antisymmetry. 

202

We have the following property of powers of two: 

P̀A Pow2(p) → (Pow2(q) ↔ Pow2(p·q)) (4) 

which is proved by complete induction on p. Assume Pow2(p) and consider the two cases implied by 8.1.11(3). If p = 2·u + 1 for some u then p = 1 by (3) and the consequent of the property holds trivially. If p = 2·u for some u then Pow2(u) by (2) and we have 0 \< u \< p. Hence 

Pow2(q) IH⇔ Pow2(u·q) (2)⇔ Pow2(2·u·q) . 

8\.1.4 Order of powers. We will need the following ordering properties of powers of two: 

P̀A Pow2(p) ∧ Pow2(q) → (p \< q ↔ ∃u q = 2·u·p) (1) 

P̀A Pow2(p) ∧ Pow2(q) → (p ≤ q ↔ ∃u q = u·p) (2) 

P̀A Pow2(p) ∧ Pow2(q) → ((p \< q ↔ 2·p ≤ q) ∧ (p \< 2·q ↔ p ≤ q)) . (3) 

(1): In the direction (→) we prove 

P̀A ∀p (Pow2(p) ∧ Pow2(q) ∧ p \< q → ∃u q = 2·u·p) 

by complete induction on q. We take any p, assume Pow2(p), Pow2(q), p \< q, and consider two cases for q implied by 8.1.11(3). The case q = 2·q1 + 1 for some q1 leads to a contradiction because then p \< q = 1 by 8.1.3(3). If q = 2·q1 for some q1 then we consider two similar cases for p. If p = 2·p1 + 1 for some p1 then p = 1 by 8.1.3(3) and it suffices to take u := q1. If p = 2·p1 

for some p1 then we have Pow2(p1) and Pow2(q1) by 8.1.3(2) and, since 0 \< p1 \< q1 \< q, we have q1 = 2·u·p1 for some u by IH. It now suffices to take the same u because q = 2·q1 = 2·2·u·p1 = 2·u·p. 

In the direction (←) assume Pow2(p), Pow2(q), and q = 2·u·p. Since q 6= 0 and p \| q, we get p ≤ q by 7.5.2(2) and it cannot be the case p = q because then p = q = a = 0. 

(2): In the direction (→) assume Pow2(p), Pow2(q), p ≤ q, and consider two cases. If p \< q then the conclusion of the property holds by (1). If p = q then it suffices to take u := 1. In the direction (←) assume Pow2(p), Pow2(q), and q = u·p. We now consider two cases for u implied by 8.1.11(3). If u = 2·u1 for some u1 then p \< q by (1). If u = 2·u1 + 1 for some u1 then, since Pow2(p·u), we have Pow2(u) by (4). Hence u = 1 by 8.1.3(3) and we have p = q. 

(3): Assume Pow2(p) and Pow2(q). For the first conjunct we have p \< q iff, by (1), q = 2·u·p for some u, since Pow2(2·p) by 8.1.3(2), iff, by (2) 2·p ≤ q. 

For the second conjunct we have p ≤ q iff not q \< p iff, by the first conjunct, not 2·q ≤ p iff p \< 2·q. 

203

We will also often use the following easy to prove property of powers of two: 

P̀A Pow2(u) ∧ Pow2(p) ∧ u ≥ p ∧ u \> s ∧ p \> t → (∃b(a·u + s = b·p + t) ↔ ∃c(s = c·p + t)) (4) 

which is proved by assuming its antecedent and noting that u = d·p for some d by (2). In the direction (→) assume also a·u + s = b·p + t for some b and, since p \> 0, we get 

b·p + t = a·u + s = a·d·p + s÷ p·p + s mod p = (a·d + s÷ p)·p + s mod p . 

Because t \< p we have t = s mod p by 7.4.8(2) and, since then 

s = s÷ p·p + s mod p = s÷ p·p + t , 

it suffices to take c := s÷ p. In the direction (←) assume also s = c·p + t for some c and, since 

a·u + s = a·d·p + c·p + t = (a·d + c)·p + t , 

it suffices to take b := a·d + c. 

8\.1.5 Fast computation of Pow2. The clausal form for the predicate Pow2 given in Par. 8.1.3 has a ‘slow’ recursion. We need the recursion expo- nentially speeded up to that for the log function discussed in Par. 8.1.2. The predicate Pow2 with fast recursion has the following clausal form: 

Pow2(p) ← p = 1 Pow2(p) ← p \> 1 ∧ p = \[ 

√ p\]2 ∧ Pow2(\[ 

√ p\]) 

Pow2(p) ← p \> 1 ∧ p = 2·\[√p÷ 2\]2 ∧ Pow2(\[ √ 

p÷ 2\]) . 

We wish to prove that the three clauses cover all cases and that they are mutually exclusive. In other words we wish to prove that for every power of two p we have either p = 1 or else there is a unique power of two q \< p such that either p = q2 or p = 2·q2 and that at most one of the cases applies. 

The existence part of the discrimination is expressed by 

P̀A Pow2(p) → p = 1 ∨ p \> 1 ∧ ∃q(q \< p ∧ Pow2(q) ∧ (p = q2 ∨ p = 2·q2)) (1) 

which is proved by complete induction on p. Thus assume Pow2(p) and con- sider two cases for p implied by 8.1.11(3). If p = 2·p1 +1 for some p1 we have p = 1 by 8.1.3(3). If p = 2·p1 for some p1 then we have Pow2(p1) by 8.1.3(2). Note that p \> p1 ≥ 1. Since p1 \< p, one of the three cases obtains by IH. If p1 = 1 then we have p = 2·p1 = 2·1 = 2·12. It now suffices to take q := 1 because we also have 1 \< p and Pow2(1) by 8.1.3(3). 

204

If p1 \> 0, p1 = q2 1 , q1 \< p1, and Pow2(q1) for some q1 then it suffices to 

take q := q1 because we have q = q1 \< p1 \< p, Pow2(q), and p = 2·p1 = 2·q2 

1 = 2·q2. If p1 \> 0, p1 = 2·q2 

1 , q1 \< p1, and Pow2(q1) for some q1 then it suffices to take q := 2·q1 because we have Pow2(q) by 8.1.3(2), q = 2·q1 \< 2·p1 = p, and p = 2·p1 = 2·2·q2 

1 = (2·q1)2 = q2. The uniqueness part of the discrimination follows from 

P̀A Pow2(p) ∧ (p = q2 1 ∨ p = 2·q2 

1\) ∧ (p = q2 2 ∨ p = 2·q2 

2\) → q1 = q2 . (2) 

This property follows from two auxiliary properties 

P̀A x2 = y2 → x = y (3) 

P̀A x2 = 2·y2 → x = 0 ∧ y = 0 (4) 

because when we assume the antecedent of (2) there are four cases to consider. For the cases p = q2 

1 and p = q2 2 or p = 2·q2 

1 and p = 2·q2 2 the conclusion 

q1 = q2 follows by (3). The cases p = q2 

1 and p = 2·q2 2 or p = 2·q2 

1 and p = q2 2 cannot happen 

because we obtain p = q1 = q2 = 0 by (4) which contradicts the assumption Pow2(p). 

We now prove the two auxiliary properties: (3): This follows by trichotomy from 

x \< y → x2 \< y2 

proved by assuming x \< y and considering two cases. If x = 0 then, 02 = 0·y \< y·y = y2. If x \> 0 then, since also y \> 0, we get 

x2 = x·x \< y·x \< y·y = y2 . 

(4): This is proved as ∀y(4) by complete induction on x. Thus assume x2 = 2·y and consider two cases for x implied by 8.1.11(3). If x = 2·x1 + 1 for some x1 then we obtain a contradiction from x2 = 4·x2 

1 + 4·x1 + 1 = 2·y2 

because the left-hand side is odd. If x = 2·x1 some x1 then we get 2·x2 

1 = y2 and we consider two cases for y implied by 8.1.11(3). The case y = 2·y1 + 1 leads to a contradiction similarly as above and when y = 2·y1 for some y1 we obtain x2 

1 = 2·y2 1 . If it 

were the case that x1 \> 0 then we would have x1 \< x and we would obtain a contradiction x1 = y1 = 0 by IH. Thus it must be the case that x1 = 0 and then from 0 = 2·y2 

1 we get y1 = 0. Hence x = y = 0. We will also need the following property: 

P̀A Pow2(p) ∧ (p \> 1 ∧ p = q2 ∨ p = 2·q2) → p \> 1 ∧ q \< p ∧ Pow2(q) . (5) 

whis is proved by assuming the antecedent. In either case we have p \> 1 and from (1) we get 

q1 \< p ∧ Pow2(q1) ∧ (p = q2 1 ∨ p = 2·q2 

1\) 

for some q1. But then q = q1 by (2). 

205

8\.1.6 Sequences of powers. We wish to encode the sequence of powers needed in the computation of Pow2(p) by the clauses given in Par. 8.1.5. If p = 2x then the sequence is given by 2xk , 2xk−1 , . . . , 2x0 for some k ≥ 0 such that xk = x, xi = xi+1 ÷ 2 for all i \< k, and x0 = 0 where x1 \> 0 if k \> 0. We encode the sequence of powers by its sum s = 

∑ i≤k 2xi . The reader can 

convince himself that the following explicitly defined predicate: 

P̀Ax Ps(s) ↔ ∀p∀a∀t(Pow2(p) ∧ s = a·2·p + p + t ∧ p \> t → p = 1 ∨ ∃q∃t1(t = q + t1 ∧ q \> t1 ∧ (p\>1 ∧ p = q2 ∨ p = 2·q2))) 

(1) 

is true in the standard interpretation of PA whenever s is a sequence of powers determined as above. The main idea is that when p and q are two adjacent powers in s then either p = q2 or p = 2·q2 holds. We will need the following properties of sequences of powers: 

P̀A Ps(0) (2) 

P̀A Ps(1) (3) 

P̀A Pow2(u) ∧ u \> 1 ∧ u \> s ∧ P̀A Ps(u + s) → Ps(u2 + u + s) (4) 

P̀A Pow2(u) ∧ u \> s ∧ P̀A Ps(u + s) → Ps(2·u2 + u + s) (5) 

P̀A Pow2(u) ∧ u \> s ∧ Ps(u + s) → Ps(u) . (6) 

(2): This holds trivially because 0 = a·2·p + p + t for no p such that Pow2(p). 

(3): Take any p, a, t such that Pow2(p), 1 = a·2·p+ p+ t and p \> t holds. We then clearly have p = 1 and a = t = 0. 

(4): Assume the antecedent of the property and note that Pow2(u2) by 8.1.3(4) and Pow2(2·u2) by 8.1.3(2). For the proof of Ps(u2 +u+ s) take any p, a, t such that Pow2(p), u2 + u + s = a·2·p + p + t, p \> t, and note that Pow2(2·p) by 8.1.3(2). We consider two cases by dichotomy. If u2 ≥ 2·p then, since u2 \> u, we have u2 ≥ 2·u \> u + s by 8.1.4(3). We also have 2·p \> p + t and so u + s = a1·2·p + p + t for some a1 by 8.1.4(4). We now obtain from Ps(u + s) 

p = 1 ∨ ∃q∃t1(t = q + t1 ∧ q \> t1 ∧ (p\>1 ∧ p = q2 ∨ p = 2·q2)) 

which is the consequent of Ps(u2 + u + s). If u2 \< 2·p then u2 ≤ p by 8.1.4(3). If it were the case that a \> 0 then we 

would obtain contradiction 

u2 + u + s \< 2·u2 ≤ 2·p \< a·2·p + p + t . 

We thus have u2 + u + s = p + t and if it were the case that u2 \< p then we would obtain contradiction 

u2 + u + s \< 2·u2 8.1.4(3) 

≤ p ≤ p + t . 

206

This means that p = u2 and so u + s = t, p \> 1. Thus it suffices to take q := u and t1 := s to satisfy the consequent of Ps(u2 + u + s): 

∃q∃t1(t = q + t1 ∧ q \> t1 ∧ (p\>1 ∧ p = q2 ∨ p = 2·q2)) . 

Property (5) is proved similarly. (6): Assume Pow2(u), u \> s, Ps(u + s), and for the proof of Ps(s) take 

any p, a, t such that Pow2(p), s = a·2·p + p + t, p \> t, and note that Pow2(2·p) by 8.1.3(2). We consider two cases by dichotomy. If u ≥ 2·p then u + s = a1·2·p + p + t for some a1 by 8.1.4(4). The consequent of Ps(s) now follows from that of Ps(u + s). The case u \< 2·p cannot happen because it would lead to contradiction by 

s \< u 8.1.4(3) 

≤ p ≤ a·2·p + p + t . 

8\.1.7 The function ps(p) yielding the power sequence for p. The func- tion ps(p) yielding the sequence of powers starting from p = 2k, i.e. such that ps(p) = 

∑ i≤k 2xi (see Par. 8.1.6), is introduced into PA by minimalization: 

P̀Ax ps(p) = µs\[Pow2(p) → p ≤ s ∧ Ps(s)\] 

whose existence condition follows from the stronger property 

P̀A Pow2(p) → ∃s(Ps(p + s) ∧ p \> s) (1) 

proved by complete induction on p where we assume Pow2(p) and continue by the case analysis implied by 8.1.5(1). If p = 1 then it suffices to take s := 0 by 8.1.6(3). If p \> 1 then there is a q s.t. q \< p, Pow2(q), and either p = q2 

or p = 2·q2. In either case we have a t s.t. Ps(q + t) and q \> t by IH. If q \> 1 then we have 2·q ≤ q2 ≤ p and if q = 1 then p = 2 and we have 2·q = p. In either case it suffices to take s := q + t \< 2·q ≤ p because we have Ps(p + s) by 8.1.6(4) when p = q2 and by 8.1.6(5) when p = 2·q2. 

The defining axiom for ps implies: 

P̀A Pow2(p) → p ≤ ps(p) ∧ Ps(ps(p)) (2) 

P̀A p ≤ s ∧ Ps(s) → ps(p) ≤ s . (3) 

The basic properties of the power sequence function are: 

P̀A Pow2(p) → ps(p) \< 2·p (4) 

P̀A ps(1) = 1 (5) 

P̀A ∀s(Pow2(p) ∧ Ps(p + s) ∧ p \> s → ps(p) = p + s) (6) 

P̀A Pow2(p) ∧ (p \> 1 ∧ p = q2 ∨ p = 2·q2) → ps(p) = p + ps(q) . (7) 

(4): Assume Pow2(p) and obtain an s s.t. Ps(p + s) and p \> s by (1). Thus 

207

ps(p) (3) 

≤ p + s \< 2·p . 

(5): We have Pow2(1) by 8.1.3(3) and so 1 ≤ ps(1) by (2). We have ps(1) \< 2 by (4) and so ps(1) = 1. 

(6): By complete induction on p. Take any s, assume Pow2(p), Ps(p + s), 

p \> s, and consider two cases. If p = 1 then we have s = 0 and ps(1) (5) = 1+0. 

If p \> 1 then for s := p + s = 0·2·p + p + s we obtain from Ps(p + s) 

s = q + t1 ∧ q \> t1 ∧ (p \> 1 ∧ p = q2 ∨ p = 2·q2) 

for some q and t1. We have Pow2(q) and q \< p by 8.1.5(5), Ps(s) by 8.1.6(6), and so ps(q) = q + t1 = s by IH. 

We also have p ≤ ps(p) and Ps(ps(p)) by (2) and ps(p) \< 2·p by (4). Hence ps(p) = p + t for some t s.t. p \> t. For s := p + t = 0·2·p + p + t we obtain from Ps(p + t) 

t = q1 + t2 ∧ q1 \> t2 ∧ (p \> 1 ∧ p = q2 1 ∨ p = 2·q2 

1\) 

for some q1 and t2. We have q = q1 by 8.1.5(2) and, since Ps(t) holds by 8.1.6(6), we get ps(q) = q+t2 = t by IH. Thus ps(p) = p+t = p+ps(q) = p+s. 

(7): Assume the antecedent of the property. We have Pow2(q), q \< p, and p \> 1 by 8.1.5(5). From (1) there is an s s.t. Ps(p + s) and p \> s. Hence ps(p) = p + s by (6). For s := p + s = 0·2·p + p + s we obtain from Ps(p + s) 

s = q1 + t1 ∧ q1 \> t1 ∧ (p \> 1 ∧ p = q2 1 ∨ p = 2·q2 

1\) 

for some q1 and t1. We get q = q1 by 8.1.5(2), and, since Ps(s) holds by 8.1.6(6), we get ps(q) = q + t1 = s by (6). 

8\.1.8 Course of values sequences for the log function. We will encode the computation of the log function such that for p = 2x we have log(p) = x by the fast recurrences discussed in Par. 8.1.2. To that end we take the power sequence ps(p) = 

∑ i≤k 2xi , use the fact that each xi \< 2xi , that there are 

at least xi bits in ps(p) between the bit postions 2xi+1 and 2xi , and encode the course of values sequence xk, xk−1, . . . , x0 for the successive values of log(2xi) at the corresponding bits of the power sequence. We will define in Par. 8.1.9 a course of values function log(p) to yield the course of values sequence such that log(p) = 

∑ i≤k xi·2xi . 

We recall that two neighboring powers p and q in the power sequence ps(u) are such that either p = q2 or p = 2·q2. The relation between the values x and y stored in the course of values sequence log(u) at the powers p and q respectively, i.e. when log(u) = a·p2 + x·p + y·q + u1 for x \< p, y \< q, and q \> u1, is expressed by Nbs(log(u), p, q) where the predicate is explicitly introduced into PA as follows: 

P̀Ax Nbs(s, p, q) ↔ ∃b∃x∃y∃s1(s = b·p2 + x·p + y·q + s1 ∧ x \< p ∧ y \< q ∧ q \> s1 ∧ (p \> 1 ∧ p = q2 ∧ x = y0 ∨ p = 2·q2 ∧ x = y1)) . 

(1) 

208

The reader can convince himself that the following explicitly defined predi- cate: 

P̀Ax Cs(u, s) ↔ ∀p∀a∀t(Pow2(p) ∧ ps(u) = a·2·p + p + t ∧ p \> t → p = 1 ∧ 2 \| s ∨ ∃q Nbs(s, p, q)) (2) 

is true in the standard interpretation of PA whenever s is the course of values sequence for u, i.e. log(u) = s. We will need the following properties of Cs: 

P̀A Cs(1, 0) (3) 

P̀A Pow2(u) ∧ u \> 1 ∧ Cs(u, z·u + s) ∧ z \< u ∧ u \> s → Cs(u2, z0·u2 + z·u + s) (4) 

P̀A Pow2(u) ∧ Cs(u, z·u + s) ∧ z \< u ∧ u \> s → Cs(2·u2, z1·2·u2 + z·u + s) (5) 

P̀A Pow2(u) ∧ Cs(u, z·u + s) ∧ u \> s ∧ (u \> 1 ∧ u = u2 1 ∨ u = 2·u2 

1\) → Cs(u1, s) . (6) 

(3): Take any p, a, t such that Pow2(p), ps(1) = a·2·p + p + t and p \> t holds. We have ps(1) = 1 by 8.1.7(5) and thus we clearly must have p = 1 and a = t = 0. Since 2 \| 0, we get Cs(1, 0). 

(4): Assume the antecedent of the property and note that Pow2(2·u) by 8.1.3(2) and Pow2(u2) by 8.1.3(4). Since u \< u2, we also have 

u \< 2·u 8.1.4(3) 

≤ u2 . (7) 

For the proof of Cs(u2, z0·u2 +z·u+s) we take any p, a, t such that Pow2(p), ps(u2) = a·2·p + p + t, p \> t. We thus have 

u2 + ps(u) 8.1.7(7) 

= ps(u2) = a·2·p + p + t . (8) 

We also have Pow2(2·p) by 8.1.3(2) and 

u2 = u·u ≥ (z + 1)·u = z·u + z \> z·u + s . (9) 

We now consider two cases by dichotomy. If u2 \> p then, since u2 ≥ 2·p by 8.1.4(3), we have u2 ≥ 2·u \> ps(u) by 8.1.7(4). Since also 2·p \> p + t, we obtain 

ps(u) = a1·2·p + p + t (10) 

for some a1 by 8.1.4(4). From Cs(u, z·u + s) we now get two cases. If p = 1 and 2 \| z·u + s then, since 1 \< u \< u2, we have u2 = 2·k·u for some k by 8.1.4(1) and so 2 \| z0·u2 + z·u + s. This proves Cs(u2, z0·u2 + z·u + s). 

If Nbs(z·u + s, p, q) for some q then we have 

209

z·u + s = b·p2 + x·p + y·q + s1 ∧ x \< p ∧ y \< q ∧ q \> s1 ∧ (p \> 1 ∧ p = q2 ∧ x = y0 ∨ p = 2·q2 ∧ x = y1)) . 

for some b, x, y, and s1. We then get 

p2 = p·p ≥ (x + 1)·p = x·p + p ≥ x·p + q2 ≥ x·p + (y + 1)·q = x·p + y·q + q \> x·p + y·q + s1 . (11) 

We have 2·u 8.1.7(4) \> ps(u) 

(10) 

≥ p and so u ≥ p by 8.1.4(3). From u2 ≥ p2, (9), and (11) we obtain 

z0·u2 + z·u + s = b1·p2 + x·p + y·q + s1 

for some b1 by 8.1.4(4). But then Nbs(z0·u2 + z·u + s, p, q) which proves Cs(u2, z0·u2 + z·u + s). 

The other dichotomy case is u2 ≤ p. If a \> 0 then we contradict (8) by 

ps(u2) 8.1.7(4) 

\< 2·u2 ≤ 2·p ≤ a·2·p + p + t . 

We thus have a = 0 and by (8) we get u2 + ps(u) = p + t. If it were the case that u2 \< p then we would contradict (8) again: 

u2 + ps(u) = ps(u2) 8.1.7(4) 

\< 2·u2 8.1.4(3) 

≤ p ≤ p + t . 

Thus u2 = p and for q := u, b := 0, x := z0, y := z, and s1 := s we have Nbs(z0·u2 + z·u + s, p, q) because then y = z \< u = q, q = u \> s = s1, and 

x = z0 \< 2·u (7) 

≤ u2 = p. (5): This is proved similarly as (4). (6): Assume the antecedent of the property. We have Pow2(u1) and 

Pow2(2·u1) by 8.1.3(2) and 8.1.3(4). If u = u2 1 and u1 \> 1 then, since u \> u1, 

we get u ≥ 2·u1 by 8.1.4(3). If u = 2·u2 1 then, since u2 

1 ≥ u1, we get u ≥ 2·u1 

again. For the proof of Cs(u1, s) we take any p, a, t such that Pow2(p), ps(u1) = a·2·p + p + t, and p \> t. Since Pow2(2·p) by 8.1.3(2), 2·p \> p + t, and 

u ≥ 2·u1 

8\.1.7(4) \> ps(u1) ≥ p , (12) 

i.e. u ≥ 2·p by 8.1.4(3), we obtain 

ps(u) 8.1.7(7) 

= u + ps(u1) = a1·2·p + p + t 

for some a1 by 8.1.4(4). From Cs(u, z·u + s) we now get two cases. If p = 1 and 2 \| z·u + s then from u ≥ 2·u1 we obtain 2 \| z·u because u = k·2·u1 for some k by 8.1.4(2). Thus 2 \| s by 7.5.2(3) which proves Cs(u1, s). 

210

If Nbs(z·u + s, p, q) for some q then we have 

z·u + s = b·p2 + x·p + y·q + s1 ∧ x \< p ∧ y \< q ∧ q \> s1 ∧ (p \> 1 ∧ p = q2 ∧ x = y0 ∨ p = 2·q2 ∧ x = y1)) . 

for some b, x, y, and s1. We have Pow2(p2) by 8.1.3(4) and p2 \> x·p+y·q+s1 

similarly as in (11). We have 2·u1 \> p by (12) and so 2·u1 ≥ 2·p, i.e. u1 ≥ p, by 8.1.4(3). Hence u ≥ u2 

1 ≥ p2 and, since u \> s, we obtain s = b1·p2 + x·p + y·q + s1 for some b1 by 8.1.4(4). But then Nbs(s, p, q) which proves Cs(u1, s). 

8\.1.9 The course of values function log(p) for log(p). The function log(p) yielding the course of values sequence from p = 2k for log, i.e. such that log(p) = 

∑ i≤k xi·2xi (see Par. 8.1.8), is introduced into PA by minimal- 

ization: 

P̀Ax log(p) = µs\[Pow2(p) → Cs(p, s)\] (1) 

whose existence condition follows from the stronger property 

P̀A Pow2(p) → ∃s(Cs(p, s) ∧ p2 \> s) (2) 

proved by complete induction on p where we assume Pow2(p) and continue by the case analysis of p implied by 8.1.5(1). If p = 1 then it suffices to take s := 0 by 8.1.8(3). If p \> 1 then there is a q s.t. q \< p, Pow2(q), and either p = q2 or p = 2·q2. We obtain a t \< q2 such that Cs(q, t) by IH. We have t = z·q + s1 for z = t÷ q and s1 = t mod q \< q. Also z \< q because if z ≥ q we would get a contradiction q2 \> t = z·q + s1 ≥ q2. But then 

z1 = 2·z + 1 = z + z + 1 \< q + z + 1 ≤ q + q = 2·q 8.1.4(3) 

≤ p . (3) 

Now, if p = q2 then we have Cs(p, s) for s = z0·p + t by 8.1.8(4), and if p = 2·q2 then we have Cs(p, s) for s = z1·p + t by 8.1.8(5). In either case we have 

s ≤ z1·p + t \< z1·p + q2 ≤ z1·p + p = (z1 + 1)·p (3) 

≤ p2 . 

The defining axiom for log implies: 

P̀A Pow2(p) → Cs(p, log(p)) (4) 

P̀A Cs(p, s) → log(p) ≤ s . (5) 

We will need the following basic properties of the function log: 

P̀A Pow2(p) → log(p) \< p2 (6) 

P̀A log(1) = 0 (7) 

P̀A ∀z∀s(Pow2(p) ∧ Cs(p, z·p + s) ∧ z \< p ∧ p \> s → log(p) = z·p + s) (8) 

P̀A Pow2(p) ∧ p \> 1 ∧ p = q2 → log(p) = (log(q)÷ q)0·p + log(q) (9) 

P̀A Pow2(p) ∧ p = 2·q2 → log(p) = (log(q)÷ q)1·p + log(q) . (10) 

211

(6): Assume Pow2(p). We have Cs(p, s) for some s \< p2 by (2) and so log(p) ≤ s \< p2 by (5). 

(7): We have Cs(1, 0) by 8.1.8(3) and so log(1) ≤ 0 by (5). (8): By complete induction on p. Take any z, s, assume Pow2(p), Cs(p, z·p+ 

s), z \< p, and p \> s. We have 

ps(p) = p + t = 0·2·p + p + t (11) 

for some t \< p by 8.1.7(2) and 8.1.7(4). From Cs(p, z·p + s) we then obtain 

p = 1 ∧ 2 \| z·p + s ∨ ∃qNbs(z·p + s, p, q) . 

If p = 1 then, since z = s = 0, we have 

log(p) = log(1) (7) = 0 = z·p + s . 

If Nbs(z·p + s, p, q) for some q then we have 

z·p + s = b·p2 + x·p + y·q + s1 ∧ x \< p ∧ y \< q ∧ q \> s1 ∧ (p \> 1 ∧ p = q2 ∧ x = y0 ∨ p = 2·q2 ∧ x = y1)) 

for some b, x, y, and s1. We obtain p \> 1, q \< p, Pow2(q) by 8.1.5(5). Because z \< p we have b = 0 and, since y·q + s1 \< y·q + q = (y + 1)·q ≤ q2 ≤ p, we obtain z = x, and s = y·q + s1 by 7.4.8(1)(2). We have Cs(q, s) by 8.1.8(6) and so log(q) = y·q + s1 = s by IH. 

We have Cs(p, log(p)) by (4) and from (11), since p \> 1, we obtain Nbs(log(p), p, q1) for some q1 for which we have q = q1 by 8.1.5(2). Thus 

log(p) = b1·p2 + x1·p + y1·q + s2 ∧ x1 \< p ∧ y1 \< q ∧ q \> s2 ∧ (p \> 1 ∧ p = q2 ∧ x1 = y10 ∨ p = 2·q2 ∧ x1 = y11)) 

for some b1, x1, y1, and s2. We have b1 = 0 by (6) and, since y1·q + s2 \< p, we obtain Cs(q, y1·q + s2) by 8.1.8(6) and log(q) = y1·q + s2 by IH. Since log(q) = y·q + s1, we obtain y = y1 and s1 = s2 by 7.4.8(1)(2). Because of 8.1.5(4) we then have x = x1 and so 

log(p) = x1·p + y1·q + s2 = x·p + log(q) = z·p + y·q + s1 = z·p + s . 

(9): Assume Pow2(p), p \> 1, and p = q2. We have Pow2(q) and p \> q by 8.1.5(5), Pow2(2·q) by 8.1.3(2), and also 

ps(p) 8.1.7(7) 

= p + ps(q) = 0·2·p + p + ps(q) 

where 

ps(q) 8.1.7(4) 

\< 2·q 8.1.4(3) 

≤ p . 

212

From (4) we thus obtain Nbs(log(p), p, q1) for some q1 for which we have q = q1 by 8.1.5(2). We thus have 

log(p) = b·p2 + x·p + y·q + s ∧ x \< p ∧ y \< q ∧ q \> s ∧ x = y0 

for some b, x, y, and s, since p 6= 2·q2 by 8.1.5(4). It must be the case that b = 0 by (6) and, since p \> y·q + s, we obtain Cs(q, y·q + s) from (4) by 8.1.8(6). Hence, log(q) = y·q + s by (8), from which we get y = log(q) ÷ q and so 

log(p) = x·p + log(q) = y0·p + log(q) = (log(q)÷ q)0·p + log(q) . 

(10): This is proved similarly as (9). 

8\.1.10 Introduction of log into PA. We explicitly introduce into PA the logarithm function log by 

P̀Ax log(p) = log(p)÷ p . (1) 

The function satisfies the following: 

P̀A log(1) = 0 (2) 

P̀A Pow2(p) ∧ p = q2 ∧ p \> 1 → log(p) = log(q)0 (3) 

P̀A Pow2(p) ∧ p = 2·q2 → log(p) = log(q)1 (4) 

P̀A Pow2(p) → log(2·p) = log(p) + 1 (5) 

P̀A Pow2(p) ∧ Pow2(q) ∧ p \< q → log(p) \< log(q) . (6) 

(2): We have log(1) = log(1)÷ 1 8.1.9(7) 

= 0÷ 1 = 0. (3): Assume Pow2(p), p = q2, and p \> 1. We have Pow2(q) by 8.1.5(5) 

and by 8.1.9(9) we get log(p) = (log(q)÷ q)0·p+log(q). Since log(q) \< q2 = p by 8.1.9(6) we have 

log(p) = log(p)÷ p 7.4.8(2) 

= log(q)0 . 

(4): Assume Pow2(p) and p = 2·q2. We have Pow2(q) by 8.1.5(5) and by 8.1.9(10) we get log(p) = (log(q)÷ q)1·p + log(q). Since log(q) \< q2 \< p by 8.1.9(6) we have 

log(p) = log(p)÷ p 7.4.8(2) 

= log(q)1 . 

(5): By complete induction on p. Assume Pow2(p) and obtain Pow2(2·p) by 8.1.3(2). We now consider three cases implied by 8.1.5(1). If p = 1 then we have 

log(2·p) = log(2·1) = log(2·12) (4) = 2· log(1) + 1 

(2) = log(1) + 1 = log(p) + 1 . 

213

If p \> 1 and p = q2 for some q such that Pow2(q) then we have 

log(2·p) = log(2·q2) (4) = 2· log(q) + 1 

(3) = log(q2) + 1 = log(p) + 1 . 

If p = 2·q2 for some q \< p such that Pow2(q) then p \> 1 and we have 

log(2·p) = log(2·(2·q2)) = log((2·q)2) (3) = 2· log(2·q) IH= 2·(log(q) + 1) = 

(2· log(q) + 1) + 1 (4) = log(2·q2) + 1 = log(p) + 1 . 

(6): By complete induction on q. Assume Pow2(p), Pow2(q), and p \< q. We have q = 2·u·p for some u by 8.1.4(1) and, since Pow2(u·p) by 8.1.3(2), we obtain p ≤ u·p \< q by 8.1.4(2). Thus either p \< u·p and then log(p) \< log(u·p) by IH, or else p = u·p and then log(p) = log(u·p). In either case we have 

log(p) ≤ log(u·p) \< log(u·p) + 1 (5) = log(2·u·p) = log(q) . 

8\.1.11 Introduction of 2x into PA. We are now ready to introduce the exponentiation function by minimalization: 

P̀Ax 2x = µp\[Pow2(p) ∧ log(p) = x\] 

whose existence condition: 

P̀A ∃p(Pow2(p) ∧ log(p) = x) 

is proved by induction on x. In the base case it suffices to take p := 1 because of 8.1.3(3) and 8.1.10(2). In the inductive case we obtain a p s.t. Pow2(p) and log(p) = x by IH. We then get Pow2(2·p) by 8.1.3(2), log(2·p) = log(p)+1 = x + 1 by 8.1.10(5), and so it suffices to take p := 2·p. 

The following property asserts that the functions 2x and log are inverse: 

P̀A 2x = p ↔ Pow2(p) ∧ log(p) = x . (1) 

In the direction (→) assume 2x = p and from the first conjunct of the defining axiom for 2x: Pow2(2x) ∧ log(2x) = x we immediately obtain Pow2(p) and log(p) = x. 

In the direction (←) assume Pow2(p) and log(p) = x and obtain Pow2(2x) as well as log(2x) = x from the defining axiom for 2x. Consider three cases by trichotomy. If 2x \< p we obtain a contradiction x = log(2x) \< log(p) = x by 8.1.10(6). We similarly derive a contradiction for the case 2x \> p. This means that the third case 2x = p must hold. 

We are now ready to prove the two recurrences for the exponentiation function from Par. 8.1.2. Property 8.1.2(1) follows from (1) by 8.1.3(3) and 8.1.10(2). 

Property 8.1.2(2) is proved as follows. From 2x = 2x we get Pow2(2x) and log(2x) = x by (1). We get log(2·2x) = log(2x) + 1 = x + 1 by 8.1.10(5) and, since Pow2(2·2x) by 8.1.3(2), we get 2x+1 = 2·2x by (1). 

214

8\.1.12 Some properties of 2x. We list some of the properties of the ex- ponential function: 

P̀A 20 = 1 (1) 

P̀A 2x+1 = 2·2x (2) 

P̀A Pow2(p) ↔ ∃x 2x = p (3) 

P̀A x \< 2x (4) 

P̀A x \< y → 2x \< 2y (5) 

P̀A 2x+y = 2x·2y . (6) 

Properties (1) and (2) are just the properties 8.1.2(1)(2) proved in Par. 8.1.11. 

(3): Follows directly from 8.1.11(1) because ∃x log(p) = x holds trivially. (4): By induction on x. In the base case we have 0 \< 1 = 20. In the 

inductive case we have x \< 2x by IH from which we get x + 1 ≤ 2x \< 2x+1. (5): Assume x \< y. By substituting p := 2x in 8.1.11(1) we obtain 

Pow2(2x) and log(2x) = x. We get Pow2(2y) and log(2y) = y similarly. We thus have ¬ log(2y) \< log(2x) and we obtain ¬2y \< 2x, i.e. 2x ≤ 2y, by 8.1.10(6). If it were the case that 2x = 2y then we would het a contradiction x = log(2x) = log(2y) = y. 

(6): By induction on x. In the base case we have 20+y = 2y = 1·2y = 20·2y. In the inductive case we have 

2x′+y = 2(x+y)′ = 2·2x+y IH= 2·2x·2y = 2x′ ·2y . 

8\.2 Primitive Recursion 

8\.2.1 Primitive recursive functions. The class of primitive recursive functions can be characterized as the smallest class obtained by explicit def- initions: 

f(\~x) = τ \[\~x\] (1) 

and by primitive recursion: 

f(0, \~y) = g(\~y) f(x′, \~y) = h(x, \~y, f(x, \~y)) 

where the term τ is formed from the constant 0, variables among the n (n ≥ 0) variables of \~x, applications of the successor function ρ′, and of applications of previously introduced functions. In the scheme of primitive recursion the functions g and h are previously introduced functions, g is n-ary (n ≥ 0) and h is (n + 2)-ary. 

215

We already know that we can introduce into PA explicitly defined func- tions. In this section we show that PA is closed under primitive recursion, i.e. if functions g and h have been introduced into PA then we can introduce into PA by minimalization a function f to satisfy the above recurrences. The reader will note that by showing the closure of PA under primitive recursion will have proved more than that the primitive recursive functions can be in- troduced into PA. This is because we will be able to introduce into PA the function f defined by primitive recursion from any two functions g and h already in PA even if one or both of them will not be primitive recursive. 

8\.2.2 Bounded indexing function. For the introduction of primitive re- cursive functions into PA we will need to recover digits of numbers represented in the notation with the base 2k for for a given k ≥ 1. As is well-known, any number x can be uniquely written in such a representation as x = 

∑ i di·2k·i. 

We can recover the i-th digit di of x by a ternary bounded indexing function di = (x)\[k\] 

i which can be explicitly introduced into PA by: 

P̀Ax (s)\[k\] i = s÷ 2k·i mod 2k . (1) 

We will need the following properties of the bounded indexing function: 

P̀A b \< 2k ∧ t \< 2k·i → (a·2k·i′ + b·2k·i + t)\[k\] i = b (2) 

P̀A i \< j ∧ s \< 2k·j → (a·2k·j+s)\[k\] i = (s)\[k\] 

i . (3) 

(2): Assume the antecedent of the property. Since 

a·2k·i′ + b·2k·i + t 8.1.12(6) 

= (a·2k + b)·2k·i + t , 

we have 

(a·2k·i′+b·2k·i+t)\[k\] i = (a·2k·i′+b·2k·i+t)÷2k·i mod 2k = (a·2k+b) mod 2k = b . 

(3): Assume s \< 2k·j and i \< j, i.e. j = i + n′ for some n. We have s = b·2k·i + t for some b \< 2k and t \< 2k·i. We then obtain 

(a·2k·j+s)\[k\] i 

8\.1.12(6) = ((a·2k·n)·2k·i′ + b·2k·i + t)\[k\] 

i 

(2) = b 

(2) = 

(0·2k·i′ + b·2k·i + t)\[k\] i = (s)\[k\] 

i . 

8\.2.3 Extensions by primitive recursion. Let T be a proper extension of PA and τ1\[\~y\], τ2\[x, \~y, v\] terms of LT with free variables among the indicated ones and where \~y is an n-tuple of variables (n ≥ 0). The extension of the theory T into S with a new (n + 1)-ary function symbol f and with the axioms universal closures of 

f(0, \~y) = τ1\[\~y\] (1) f(x′, \~y) = τ2\[x, \~y, f(x, \~y)\] (2) 

Ix(φ\[x, \~y, f(x, \~y)\]) . (3) 

216

is called extension by primitive recursion. The formula φ\[x, \~y, z\], which is of LT and with all free variables indicated, will be effectively determined in Par. 8.2.6 as a graph of the function f . The formula is used in the induction axiom (3) which is the sole induction axiom of S containing the function symbol f . 

We keep the notation introduced in this paragraph fixed until the end of the section where we prove in Thm. 8.2.7 that S is an extension by definition of T . 

8\.2.4 The outline of extensions. Pursuing our plan of introducing the function f into the theory S we first extend T to T1 by definitions to contain the exponentiation function 2x and the bounded indexing function (s)\[k\] 

i if not already in T . 

We plan to extend T1 to T2 by explicitly defining a a predicate Fs such that when f will be introduced into S we will have 

Fs(k, s, x, \~y) ↔ ∃k(s mod 2k·x′ = ∑ 

i≤x 

f(i, \~y)·2k·i ∧ ∀(i ≤ x → f(i, \~y) \< 2k)) 

in the standard model of S. The third argument s of Fs is a course of values sequence for the computation of f coded in the base 2k representation. 

The function f can be then introduced into S1 by implicit definition which is equivalent to 

S1 \` ∃k∃s(Fs(k, s, x, \~y) ∧ (s)\[k\] x = f(x, \~y)) . (1) 

8\.2.5 Course of values sequences for f . We extend T1 to T2 by an explicit definition of an (n + 3)-ary predicate Fs: 

T2 \` Fs(k, s, x, \~y) ↔ (s)\[k\] 0 = τ1\[\~y\] ∧ ∀i(i \< x → (s)\[k\] 

i+1 = τ2\[i, \~y, (s)\[k\] i \]) . 

(1) 

Clearly, Fs(k, s, x, \~y) holds in the standard model of T2 iff s codes in the 2k- representation the course of values sequence for f(x, \~y) provided f(i, \~y) \< 2k 

holds for all i ≤ x. The following properties of Fs express the fact that course of values se- 

quences can be constructed for all arguments x, \~y: 

217

T2 \` τ1\[\~y\] \< 2k → Fs(k, τ1\[\~y\], 0, \~y) ∧ (τ1\[\~y\])\[k\] 0 = τ1\[\~y\] (2) 

T2 \` Fs(k, s, x, \~y) ∧ s\<2k·x′ ∧ a = τ2\[x, \~y, (s)\[k\] x \]\<2k → Fs(k, a·2k·x′+s, x′, \~y) 

(3) 

T2 \` Fs(k, a·2k·x′+s, x′, \~y) ∧ s \< 2k·x′ → Fs(k, s, x, \~y) . (4) 

T2 \` ∀s1∀s2∀i(Fs(k1, s1, x, \~y) ∧ Fs(k2, s2, x, \~y) ∧ i ≤ x → (s1) \[k1\] i = (s2) 

\[k2\] i ) 

(5) 

T2 \` ∀k1∀k2(∃sFs(k1, s, x, \~y) ∧ k1≤k2 → ∃s(s\<2k2·x′ ∧ Fs(k2, s, x, \~y))) . (6) 

(2): If τ1\[\~y\] \< 2k then, since τ1\[\~y\] = 0·2k·1 + τ1\[\~y\]·2k·0 + 0, we have (τ1\[\~y\])\[k\] 

0 = τ1\[\~y\] by 8.2.2(2) and so Fs(k, τ1\[\~y\], 0, \~y) holds by (1). (3): Assume the antecedent of the property and set t = a·2k·x′+s. Since, 

0 \< x′, we have 

(t)\[k\] 0 

8\.2.2(3) = (s)\[k\] 

0 

Fs(k,s,x,\~y) = τ1\[\~y\] . 

For i = x \< x′ we have 

(t)\[k\] i+1 

8\.2.2(2) = a = τ2\[i, \~y, (s)\[k\] 

i \] 8.2.2(3) 

= τ2\[i, \~y, (t)\[k\] i \] 

and for any i \< x \< x′ we have 

(t)\[k\] i+1 

8\.2.2(3) = (s)\[k\] 

i+1 

Fs(k,s,x,\~y) = τ2\[i, \~y, (s)\[k\] 

i \] 8.2.2(3) 

= τ2\[i, \~y, (t)\[k\] i \] . 

(4): For t = a·2k·x′+s and s \< 2k·x′ assume Fs(k, t, x′, \~y). Since 0 \< x′, we have 

(s)\[k\] 0 

8\.2.2(3) = (t)\[k\] 

0 

Fs(k,t,x′,\~y) = τ1\[\~y\] 

and for any i \< x \< x′ we have 

(s)\[k\] i+1 

8\.2.2(3) = (t)\[k\] 

i+1 

Fs(k,t,x′,\~y) = τ2\[i, \~y, (t)\[k\] 

i \] 8.2.2(3) 

= τ2\[i, \~y, (s)\[k\] i \] . 

But this means that Fs(k, s, x, \~y) holds. (5): By induction on x. In the base case take any s1, s2, and i ≤ 0, i.e. 

i = 0, s.t. Fs(k1, s1, 0, \~y), and Fs(k2, s2, 0, \~y) holds. We then have 

(s1) \[k1\] 0 

Fs(k1,s1,0,\~y) = τ1\[\~y\] 

Fs(k2,s2,0,\~y) = (s2) 

\[k2\] 0 . 

In the inductive case take any s1, s2, and i \< x′ s.t. Fs(k1, s1, x ′, \~y), and 

Fs(k2, s2, x ′, \~y). We have s1 = a1·2k1·x′ + t1, t1 \< 2k1·x′ and s2 = a2·2k2·x′ + 

t2, t2 \< 2k2·x′ for some a1, a2, t1 and t2. We then get Fs(k1, t1, x, \~y) and Fs(k2, t2, x, \~y) by (4). We now consider two cases for i. If i ≤ x \< x′ then 

(s1) \[k1\] i 

8\.2.2(3) = (t1) 

\[k1\] i 

IH= (t2) \[k2\] i 

8\.2.2(3) = (s2) 

\[k2\] i . 

218

If i = x′ then we have 

(s1) \[k1\] x+1 

Fs(k1,s1,x′,\~y) = τ2\[x, \~y, (s1)\[k1\] 

x \] IH= τ2\[x, \~y, (s2)\[k2\] x \] 

Fs(k2,s2,x′,\~y) = (s2) 

\[k2\] i . 

(6): By induction on x. In the base case take any k1, k2 s.t. k1 ≤ k2 and Fs(k1, s1, 0, \~y) for some s1. We then have 

2k 2 

8\.1.12(5) 

≥ 2k 1 \> (s1) 

\[k1\] 0 = τ1\[\~y\] 

and for s2 = τ1\[\~y\] we obtain Fs(k2, s2, 0, \~y) by (2). In the inductive case take any k1, k2 s.t. k1 ≤ k2 and Fs(k1, s1, x 

′, \~y) for some s1. We have s1 = a·2k1·x′ + t1 for some a and t1 \< 2k1·x′ . Thus Fs(k1, t1, x, \~y) by (4) and Fs(k2, t, x, \~y) for some t \< 2k2·x′ by IH. We have 

2k2 8.1.12(5) 

≥ 2k 1 \> (s1) 

\[k1\] x+1 

Fs(k1,s1,x′,\~y) = τ2\[x, \~y, (s1)\[k1\] 

x \] 8.2.2(3) 

= 

τ2\[x, \~y, (t1)\[k1\] x \] 

(5) = τ2\[x, \~y, (t)\[k2\] 

x \] . 

We set s := τ2\[x, \~y, (t)\[k2\] x \]·2k2·x′ + t and obtain Fs(k2, s, x 

′, \~y) by (3) together with: 

s = τ2\[x, \~y, (t)\[k2\] x \]·2k2·x′ + t \< τ2\[x, \~y, (t)\[k2\] 

x \]·2k2·x′ + 2k2·x′ = 

(τ2\[x, \~y, (t)\[k2\] x \] + 1)·2k2·x′ ≤ 2k2 ·2k2·x′ 8.1.12(6) 

= 2k2·x′′ . 

8\.2.6 The graph φ of the function f . We could now extend T2 to S1 by the implicit definition of f : 

S1 \` ∃k∃s(Fs(k, s, x, \~y) ∧ (s)\[k\] x = f(x, \~y)) (1) 

but we will instead equivalently extend T in Thm. 8.2.7 with the help of a formula φ\[x, \~y, z\] of LT which is a graph of f . Since T2 is an extension by definitions of T , the formula φ is effectively obtained by translation from the formula 

∃k∃s(Fs(k, s, x, \~y) ∧ (s)\[k\] x = z) 

of T2 in such a way that we have 

T2 \` φ\[x, \~y, z\] ↔ ∃k∃s(Fs(k, s, x, \~y) ∧ (s)\[k\] x = z) . (2) 

by the Theorem on Extensions by definitions 6.6.2. We will need in the proof of Thm. 8.2.7 the following properties of the formula: 

T \` φ\[0, \~y, τ1\[\~y\]\] (3) T \` φ\[x, \~y, z\] → φ\[x′, \~y, τ2\[x, \~y, z\]\] (4) T \` ∃zφ\[x, \~y, z\] (5) T \` φ\[x, \~y, z1\] ∧ φ\[x, \~y, z2\] → z1 = z2 . (6) 

219

In the following proofs we work in T2 and use the equivalence (2) without explicitly referring to it. Properties (3) through (6) are thus derived in T2 but, since they all are in the language LT , they are also theorems of T because T2 

is conservative over T . (3): We set k = τ1\[\~y\]. Since τ1\[\~y\] \< 2k by 8.1.12(4), we get Fs(k, τ1\[\~y\], 0, \~y) 

and (τ1\[\~y\])\[k\] 0 = τ1\[\~y\] by 8.2.5(2). We thus have φ\[0, \~y, τ1\[\~y\]\]. 

(4): We assume φ\[x, \~y, z\], i.e. Fs(k1, t1, x, \~y) and (t1) \[k1\] x = z for some k1 

and t1. We set k := max(k1, τ2\[x, \~y, z\]) and, since k1 ≤ k, we obtain a t \< 2k·x′ 

s.t. Fs(k, t, x, \~y) by 8.2.5(6). We have z = (t1) \[k1\] x = (t)\[k\] 

x by 8.2.5(5) and so 

2k 8.1.12(5) 

≥ 2τ2\[x,\~y,z\] 8.1.12(4) 

\> τ2\[x, \~y, z\] = τ2\[x, \~y, (t)\[k\] x \] . 

Thus by setting s := τ2\[x, \~y, (t)\[k\] x \]·2k·x′+t, we obtain Fs(k, s, x′, \~y) by 8.2.5(3) 

and (s)\[k\] x′ = τ2\[x, \~y, (t)\[k\] 

x \] = τ2\[x, \~y, z\] by 8.2.2(2). Hence φ\[x′, \~y, τ2\[x, \~y, z\]\]. (5): By induction on x. The base case is implied by (3). In the inductive 

case we have φ\[x, \~y, z\] for some z by IH, we get φ\[x′, \~y, τ2\[x, \~y, z\]\] by (4), and it suffices to set z := τ2\[x, \~y, z\]. 

(6): We assume φ\[x, \~y, z1\] and φ\[x, \~y, z2\], i.e. Fs(k1, s1, x, \~y), (s1) \[k1\] x = z1, 

Fs(k2, s2, x, \~y), and (s2) \[k2\] x = z2 for some k1, k2, s1, s2. We then obtain 

z1 = (s1)\[k1\] x 

8\.2.5(5) = (s2)\[k2\] 

x = z2 . 

8\.2.7 Theorem (Extensions by primitive recursion). If T is a proper extension of PA then an extension of T by primitive recursion is an extension by definition. 

Proof. Let S be an extension of T by primitive recursion as in Par. 8.2.3 and S1 an extension of T by implicit definition with the defining axiom an universal closure of φ\[x, \~y, f(x, \~x)\]. We have LS1 = LS and S1 is an extension by definition of T by Thm. 6.6.3 because T proves the existence 8.2.6(5) and uniqueness 8.2.6(6) conditions for f . Clearly 

S1 \` φ\[x, \~y, f(x, \~y)\] . (1) 

In order to prove the theorem it suffices to prove that the theories S and S1 

are equivalent. We prove first S1 \` S. First of all, S1 proves 8.2.3(1), i.e. S1 \` f(0, \~y) = 

τ1\[\~y\], because we have φ\[0, \~y, f(0, \~y)\] by (1) and φ\[0, \~y, τ1\[\~y\]\] by 8.2.6(3). Thus f(0, \~y) = τ1\[\~y\] by 8.2.6(6). 

Secondly, S1 proves 8.2.3(2), i.e. S1 \` f(x′, \~y) = τ2\[x, \~y, f(x, \~y)\], because we have φ\[x, \~y, f(x, \~y)\] and φ\[x′, \~y, f(x′, \~y)\], by (1) and φ\[x′, \~y, τ \[x, \~y, f(x, \~y)\]\] by 8.2.6(4). Hence f(x′, \~y) = τ \[x, \~y, f(x, \~y)\] by 8.2.6(6). 

Finally, since S1 is proper, it also proves the induction axiom 8.2.3(3) of S: Ixφ\[x, \~y, f(x, \~y)\]. 

220

Vice versa, in order to prove S \` S1 it suffices to show S \` φ\[x, \~y, f(x, \~y)\]. This is done by working in S and by using the induction axiom 8.2.3(3) of S. In the base case we have φ\[0, \~y, τ1\[\~y\]\] by 8.2.6(3) and hence φ\[0, \~y, f(0, \~y)\] by 8.2.3(1). In the inductive case we have φ\[x, \~y, f(x, \~y)\] by IH, from which we get φ\[x′, \~y, τ2\[x, \~y, f(x, \~y)\]\] by 8.2.6(4), and hence φ\[x′, \~y, f(x′, \~y)\] by 8.2.3(2). 

ut 

221

8\.3 Suitable Pairing Function 

Our main task in this section will be to introduce the suitable pairing function from Par. 1.3.11 into PA and prove its properties 1.3.7(1) through 1.3.7(3) as theorems. 

8\.3.1 Dyadic size function \|x\|d. We will introduce our suitable pairing function by arithmetizing the binary trees from Fig. 1.2 in the dyading no- tation. 

Toward that end we introduce into PA the dyadic size function (see Par. 1.3.4) by minimalization: 

P̀Ax \|x\|d = µn\[x + 1 \< 2n+1\] (1) 

whose existence condition P̀A ∃nx + 1 \< n + 1 is proved by taking n := x and using 8.1.12(4). The defining axiom for the dyadic size function implies: 

P̀A x + 1 \< 2\|x\|d+1 (2) 

P̀A n \< \|x\|d → 2n+1 ≤ x + 1 (3) 

and the function satisfies: 

P̀A \|x\|d \> 0 ↔ x \> 0 (4) 

P̀A \|x\|d = n ↔ 2n ≤ x + 1 \< 2n+1 . (5) 

(4): If 0 \< \|x\|d then 21 ≤ x+1 by (3) and so 1 ≤ x. Vice versa, if 0 \< x then 

we cannot have \|x\|d = 0 because we would then get 2 ≤ x + 1 (2) \< 20+1 = 2. 

(5): In the direction (→) assume \|x\|d = n and consider two cases. If n = 0 then x = 0 by (4) and we have 20 = 1 ≤ 0 + 1 \< 2 = 20+1. If n \> 0 then 

2n = 2n .− 1+1 (3) 

≤ x + 1 (2) \< 2n+1 . 

In the direction (→) assume 2n ≤ x + 1 \< 2n+1 and consider three cases. If n \< \|x\|d then we get a contradiction 

2n+1 (3) 

≤ x + 1 \< 2n+1 . 

If n = \|x\|d there is nothing to prove. If \|x\|d \< n then \|x\|d + 1 ≤ n and we get a contradiction: 

x + 1 (2) \< 2\|x\|d+1 

8\.1.12(5) 

≤ 2n ≤ x + 1 . 

222

8\.3.2 Dyadic concatenation function x ? y. We will also need the dyadic concatenation function x ? y (see Par. 1.3.5) which is explicitly introduced into PA as follows: 

P̀Ax x ? y = x·2\|y\|d + y (1) 

The concatenation function satisfies the following: 

P̀A x = 0 ? x ∧ x = x ? 0 (2) 

P̀A \|x ? y\|d = \|x\|d + \|y\|d (3) 

P̀A (x ? y) ? z = x ?(y ? z) (4) 

P̀A n ≤ \|x\|d → ∃a∃b(x = a ? b ∧ \|b\|d = n) (5) 

P̀A a ? b = c ? d ∧ \|b\|d = \|d\|d → a = c ∧ b = d . (6) 

(2): We have 0 ? x = 0·2\|x\|d +x = x and x ? 0 = x·2\|0\|d +0 8.3.1(4) 

= x·20+0 = x. 

(3): We have 2\|x\|d ≤ x + 1 by 8.3.1(5). Since 2\|y\|d \> 0, we get 

2\|x\|d+\|x\|d = 2\|x\|d ·2\|y\|d ≤ x·2\|y\|d + 2\|y\|d 8.3.1(5) 

≤ x·2\|y\|d + y + 1 = (x ? y) + 1 . 

We have x + 1 \< 2\|x\|d+1, i.e. x + 2 ≤ 2·2\|x\|d , by 8.3.1(5). Since 2\|y\|d \> 0, we get 

(x ? y)+1 = x·2\|y\|d +y+1 8.3.1(5) 

\< x·2\|y\|d +2·2\|y\|d ≤ 2·2\|x\|d ·2\|y\|d = 2\|x\|d+\|x\|d+1 . 

Combining the two inequalities we obtain \|x ? y\|d = \|x\|d + \|x\|d by 8.3.1(5). (4): We have 

(x ? y) ? z = (x·2\|y\|d + y)·2\|z\|d + z = x·2\|y\|d+\|z\|d + y·2\|z\|d + z (3) = 

x·2\|y ? z\|d + (y ? z) = x ?(y ? z) . 

(5): Assume n ≤ \|x\|d. We have 

2n 8.1.12(5) 

≤ 2\|x\|d 8.3.1(5) 

≤ x + 1 

and for a = (x + 1 .− 2n) ÷ 2n, c = (x + 1 .− 2n) mod 2n we get x + 1 .− 2n = a·2n + c, c \< 2n by 7.4.8(1). For b = 2n .− 1 + c we then get x = a·2n + b. We have 2n ≤ 2n + c \< 2·2n, i.e. 2n ≤ b + 1 \< 2n+1. Hence \|b\|d = n by 8.3.1(5) and thus x = a ? b. 

(6): Assume a ? b = c ? d and \|b\|d = \|d\|d. Thus 

a·2\|d\|d + b = a·2\|b\|d + b = a ? b = c ? d = c·2\|d\|d + d 

and we get a = c, b = d by 7.4.8(1)(2). In the following we will use the associativity of the concatenation opera- 

tion (4) without explicitly referring to it. 

223

8\.3.3 Counting function #(x). For the arithmetization of binary trees we will need a unary counting function #(x) yielding the number of digits 2 in the dyadic representation of x. 

The counting function is introduced with the help of an auxiliary binary dyadic indexing function \[x\]i yielding the i-th dyadic digit in the dyadic representation of x decreased by one where the least significant digit is with the index 0. We intend to introduce the function into PA by contextual definition: 

\[x\]i = z ↔ ∃a∃b(x = a ?(z + 1) ? b ∧ z ≤ 1 ∧ \|b\|d = i) ∨ i ≥ \|x\|d ∧ z = 0 . (1) 

Its existence condition follows from (2), (3) and its uniqueness condition from (4), (5): 

P̀A i \< \|x\|d → ∃z∃a∃b(x = a ?(z + 1) ? b ∧ z ≤ 1 ∧ \|b\|d = i) (2) 

P̀A i ≥ \|x\|d → ∃z z = 0 (3) 

P̀A x = a1 ?(z1 + 1) ? b1 ∧ z1 ≤ 1 ∧ \|b1\|d = i ∧ x = a2 ?(z2 + 1) ? b2 ∧ z1 ≤ 1 ∧ \|b2\|d = i → i \< \|x\|d ∧ z1 = z2 (4) 

P̀A z1 = 0 ∧ z2 = 0 → z1 = z2 . (5) 

(2): Assume i \< \|x\|d and get x = c ? b for some b, c such that \|b\|d = i by 8.3.2(5). We have \|x\|d = \|c\|d+i by 8.3.2(3). Thus 1 ≤ \|c\|d and we get c = a ? y for some a, y such that \|y\|d = 1 by 8.3.2(5) again. We have 21 ≤ y + 1 \< 22 

and so 1 ≤ y ≤ 2 by 8.3.1(5). Hence y = z + 1 for a z s.t. z ≤ 1. (3): This is trivial. (4): Assume the antecedent. We get b1 = b2, and a1 ?(z1+1) = a2 ?(z2+1) 

by 8.3.2(6). Since \|z1 + 1\|d = 1 = \|z2 + 1\|d by 8.3.1(5), we get a1 = a2 and z1 = z2 by 8.3.2(6) again. We have \|x\|d = \|a1\|d + 1 + i by 8.3.2(3) and so i \< \|x\|d. 

(5): This is trivial. We will need the following simple properties of the dyadic indexing func- 

tion: 

P̀A i \< \|b\|d → \[a ? b\]i = \[b\]i (6) 

P̀A \[a ? b\]i+\|b\|d = \[a\]i (7) 

(6): Assume i \< \|b\|d and obtain b = b1 ?(z + 1) ? b2 for some b1, b2, z ≤ 1 such that \|b2\|d = i by (2). Since also a ? b = (a ? b1) ?(z + 1) ? b2, we obtain \[b\]i = z = \[a ? b\]i by (1). 

(7): Consider two cases. If i ≥ \|a\|i then also i + \|b\|d ≥ \|a\|i + \|b\|d 8.3.2(3) 

= \|a ? b\|s and we have \[a ? b\]i+\|b\|d = 0 = \[a\]i by (1). If i \< \|a\|i then also i+\|b\|d \< \|a ? b\| and we have a = a1 ?(z+1) ? a2 for some a1, a2, z ≤ 1 such that \|a2\|d = i by (2). Since also a ? b = a1 ?(z + 1) ?(a2 ? b) with \|a2 ? b\|d = i + \|b\|d, we have \[a ? b\]i+\|b\|d = z = \[a\]i by (1) again. 

224

We also need an auxiliary binary function f which is introduced into PA by primitive recursion: 

P̀Ax f(0, x) = 0 (8) 

P̀Ax f(i′, x) = \[x\]i + f(i, x) . (9) 

We will need the following properties of f : 

P̀A ∀a∀b(i ≤ \|b\|d → f(i, a ? b) = f(i, b)) (10) 

P̀A ∀a∀b f(i + \|b\|d, a ? b) = f(i, a) + f(\|b\|d, b) . (11) 

(10): By induction on i. In the base case we have f(0, a ? b) = 0 = f(0, b). In the inductive case we assume i + 1 ≤ \|b\|d and, since i \< \|b\|d, we obtain: 

f(i + 1, a ? b) = \[a ? b\]i + f(i, a ? b) IH= 

\[a ? b\]i + f(i, b) (6) = \[b\]i + f(i, b) = f(i + 1, b) . 

(11): By induction on i. In the base case we have 

f(0 + \|b\|d, a ? b) = f(\|b\|d, a ? b) (10) = f(\|b\|d, b) = f(0, a) + f(\|b\|d, b) . 

In the inductive case we have: 

f(i + 1 + \|b\|d, a ? b) = \[a ? b\]i+\|b\|d + f(i + \|b\|d, a ? b) IH= 

\[a ? b\]i+\|b\|d + f(i, a) + f(\|b\|d, b) (7) = 

\[a\]i + f(i, a) + f(\|b\|d, b) = f(i + 1, a) + f(\|b\|d, b) . 

We introduce the function #(x) into PA by explicit definition: 

P̀Ax #(x) = f(\|x\|d, x) (12) 

The counting function has the following properties which we will need below: 

P̀A #(0) = 0 (13) 

P̀A #(1) = 0 (14) 

P̀A #(2) = 1 (15) 

P̀A #(a ? b) = #(a) + #(b) . (16) 

(13): #(0) = f(\|0\|d, 0) 8.3.1(4) 

= f(0, 0) = 0. 

(14): We have #(1) = f(\|1\|d, 1) 8.3.1(5) 

= f(1, 1) = \[1\]0 + f(0, 0) = \[1\]0 and, 

since 1 8.3.2(2) 

= 0 ?(0 + 1) ? 0, \|0\|d 8.3.1(4) 

= 0, we get \[1\]0 = 1 by (1). (15): Similarly as (14). (16): We have 

\#(a ? b) = f(\|a ? b\|d, a ? b) 8.3.2(3) 

= f(\|a\|d + \|b\|d, a ? b) (11) = 

f(\|a\|d, a) + f(\|b\|d, b) = #(a) + #(b) . 

225

Prefix Codes 

We will define a subset Prf of natural numbers which code in the dyadic notation the binary trees from Fig. 1.2 expressed in the prefix notation. 

8\.3.4 Prefix notation of pair numerals. Recall that every pair numeral is either 0 or it has a form (τ1, τ2) for pair numerals τ1 and τ2. The right parentheses and commas in pair numerals are superfluous in the sense that when we omit them we are still able to represent every natural number u- niquely. 

The sequences of words over the two element alphabet ( and 0 obtained in this way from pair numerals represent the same numbers as pair numerals in the (Polish) prefix notation. Thus the number zero 0 is represented by the pair numeral 0 and the prefix notation 0. The number 1 is represented by the pair numeral (0, 0) and by the prefix notation (00. The number 2 is denoted by the pair numeral (0, (0, 0)) and by the prefix notation (0(00. The number 3 is denoted by the pair numeral ((0, 0), 0) and by the prefix notation ((000, and so on. 

The reader will note that every number x with the pair size \|x\|p = n is represented by the prefix word of length 2·n + 1 which contains exactly n left parentheses and n + 1 zeroes. However, not every such word is a prefix notation. For instance out of 

( 5 2 

) = 10 words of length 5 six words 0(00(, 

(00(0, 00(0(, 0(0(0 (000(, 000((, 00((0, and 0((00 are not prefix notations. It can be shown that there are 

1 2·n + 1 

· ( 

2·n + 1 n 

) = 

1 n + 1 

· ( 

2·n n 

) 

prefix notations of numbers with the pair size n out of ( 2·n+1 

n 

) possible words 

with n symbols ( and n + 1 symbols 0. A moment of thought shows that the word w with n symbols ( and n + 1 

symbols 0 is a prefix notation iff for all w = w1w2 where w2 is not empty the count i of symbols ( in w2 is less than the count j of 0. We clearly have i \< j iff the size of w2 is greater than 2·i, i.e. iff i + j \> 2·i. 

The plan for the introduction of the pairing function x, y is as follows. We will first arithmetize (code) the prefix notation in the dyadic represen- tation in Par. 8.3.5. We will then define a pairing function over prefix codes in Par. 8.3.6. We will well-order the prefix codes by a relation \<p defined in Par. 8.3.8. We will then enumerate the prefix codes by a function π in Par. 8.3.13 such that \< and \<p will be isomorphic. The isomorphism then defines in Par. 8.3.14 the pairing function x, y as the isomorphic image of the pairing function on the prefix codes. 

8\.3.5 Prefix codes. We arithmetize the prefix notation by coding into nat- ural numbers where in the dyadic representation the symbol ( is coded by the 

226

digit 2 and the symbol 0 by the digit 1. The unary predicate Prf (x) holding iff x codes the prefix code of length \|x\|d is introduced into PA by explicit definition: 

P̀Ax Prf (x) ↔ \|x\|d = 2·#(x) + 1 ∧ ∀a∀b(x = a ? b ∧ b \> 0 → \|b\|d \> 2·#(b)) (1) 

We have 

P̀A \|x\|d \> 2·#(x) → ∃v∃b(x = v ? b ∧ Prf (v)) (2) 

P̀A Prf (a ? b) ∧ Prf (a) → b = 0 . (3) 

P̀A Prf (x) ∧ #(x) = 0 ↔ x = 1 . (4) 

(2): Assume \|x\|d \> 2·#(x) and consider the formula 

φ\[x, k\] ≡ ∃v∃b(\|v\|d = k ∧ x = v ? b ∧ \|v\|d \> 2·#(v)) . 

Since x = x ? 0 by 8.3.2(2), we have φ\[x, \|x\|d\] for v := x and b := 0. By the least number principle there is the smallest such k for which there are v and b such that \|v\|d = k, x = v ? b, 

\|v\|d \> 2·#(v) , (5) 

and for any m \< k we have ¬φ\[x,m\], i.e. 

∀v1∀b1(\|v1\|d \< \|v\|d ∧ x = v1 ? b1 → \|v1\|d ≤ 2·#(v1)) . (6) 

In order to prove Prf (v) we assume v = v1 ? v2 for some v1, v2 \> 0. We have 

\|v1\|d + \|v2\|d 8.3.2(3) 

= \|v\|d (5) \> 2·#(v) 

8\.3.3(16) = 2·#(v1) + 2·#(v2) (7) 

and, since x = v1 ?(v2 ? b), \|v1\|d \< \|v\|, we obtain 

\|v1\|d ≤ 2·#(v1) (8) 

by (6). This means that 

\|v2\|d \> 2·#(v2) . (9) 

It remains to derive \|v\|d = 2·#(v) + 1. We have \|v\|d \> 0 by (5) and so v = v1 ? v2 for some v1, v2 s.t. \|v2\|d = 1 by 8.3.2(5). We then get #(v2) = 0 by (9) and \|v1\|d+1 \> 2·#(v1), i.e. \|v1\|d ≥ 2·#(v1), by (7). Thus \|v1\|d = 2·#(v1) by (8) and hence \|v\|d = \|v1\|d + 1 = 2·#(v) + 1. 

(3): Assume Prf (a ? b) and Prf (a). If it were the case that b \> 0 then we would have \|b\|d \> 2·#(b) and we would obtain a contradiction 

\|a ? b\|d 8.3.2(3) 

= \|a\|d + \|b\|b = 2·#(a) + 1 + \|b\|b \> 2·#(a) + 1 + 2·#(b) = 

2·(#(a) + #(b)) + 1 8.3.3(16) 

= 2·#(a ? b) + 1 . 

227

(4): If Prf (x) and #(x) = 0 then \|x\|d = 1 and we get x = 1 or x = 2 by 8.3.1(5) and, since #(2) = 1 by 8.3.3(15), it must be the case that x = 1. 

Vice versa, if x = 1 then we have 

\|1\|d 8.3.1(5) 

= 1 8.3.3(14) 

= 2·#(1) + 1 . 

Take any b \> 0 and a such that 1 = x = a ? b. We have 1 = \|1\|d 8.3.2(3) 

= \|a\|d + \|b\|d and so a = 0 by 8.3.1(4). But then b = 1 by 8.3.2(2) and so 

\|b\|d = 1 \> 0 8.3.3(14) 

= 2·#(b) . 

8\.3.6 Pairing function over prefix codes. We define the binary prefix code pairing function x ,p y by explicit definition: 

P̀Ax x ,p y = 2 ? x ? y . (1) 

The basic properties of the function are that it is over prefix codes and that it satisfies there the pairing property: 

P̀A Prf (x) ∧ Prf (y) → Prf (x ,p y) ∧ #(x ,p y) = #(x) + #(y) + 1 (2) 

P̀A Prf (x) ∧ Prf (v) ∧ x ,p y = v ,p w → x = v ∧ y = w . (3) 

(2): Assume Prf (x) and Prf (y). We have 

\#(x, ,p y) = #(2 ? x ? y) = 1 + #(x) + #(y) (4) 

by the properties of the counting function and 

\|x ,p y\|d = \|2 ? x ? y\|d = 1 + \|x\|d + \|y\|d = 

1 + 2·#(x) + 1 + 2·#(y) + 1 (4) = 2·#(x ,p y) + 1 (5) 

by the properties of the dyadic size function. We now take any a and b \> 0 such that x ,p y = 2 ? x ? y = a ? b and, since \|b\|d ≤ \|x ,p y\|d, we consider three cases for the dyadic size of b: 

\|b\|d ≤ \|y\|d: We have y = y1 ? y2 for some y1, y2 s.t. \|b\|d = \|y2\|d by 8.3.2(5), y2 = b by 8.3.2(6), and \|y2\|d \> 2·#(y2), i.e. \|b\|d \> 2·#(b), by Prf (y). Hence Prf (x ,p y). 

\|y\|d \< \|b\|d ≤ \|x\|d + \|y\|d: We have b = b1 ? b2 for some b1, b2 s.t. \|y\|d = \|b2\|d by 8.3.2(5) and, since 2 ? x ? y = a ? b1 ? b2, we get 2 ? x = a ? b1 and y = b2 by 8.3.2(6). From \|y\|d \< \|b\|d = \|b1\|d + \|b2\|d ≤ \|x\|d + \|y\|d we get 0 \< \|b1\|d ≤ \|x\|d and so b1 \> 0, by 8.3.1(4). Thus x = x1 ? x2 for some x1, x2 s.t. \|x2\|d = \|b1\|d by 8.3.2(5) and, since 2 ? x1 ? x2 = a ? b1, we get x2 = b1 by 8.3.2(6). Now, \|x2\|d \> 2·#(x2) by Prf (x). Hence 

\|b\|d = \|b1 ? b2\|d = \|b1\|d + \|b2\|d = \|x2\|d + 2·m + 1 \> 2·#(x2) + 2·m = 2·(#(b1) + m) = 2·(#(b1) + #(b2)) = 2·#(b) 

228

and thus Prf (x ,p y). 

\|b\|d = 1+\|x\|d+\|y\|d: We have 0 ?(x ,p y) 8.3.2(2) 

= x ,p y = a ? b, \|x ,p y\|d = \|b\|d, and hence x ,p y = b by 8.3.2(6). Thus 

\|b\|d = \|x ,p y\|d (5) = 2·(1 + #(x) + #(y)) + 1 \> 2·(1 + #(x) + #(y)) 

(4) = 

2·#(x ,p y) = 2·#(b) 

and so Prf (x ,p y) again. (3): Assume Prf (x), Prf (v), and x ,p y = v ,p w. From 2 ? x ? y = 2 ? v ? w 

we get \|x ? y\|d = \|v ?w\|d by 8.3.2(3) and then x ? y = v ?w by 8.3.2(6). We now consider two cases. If \|y\|d ≤ \|w\|d then we have w = w1 ?w2 for some w1, w2 such that \|w2\|d = \|y\|d by 8.3.2(5). We obtain x = v ? w1 and w2 = y by 8.3.2(6). But then w1 = 0 by 8.3.5(3) and so x = v as well as w = w2 = y by 8.3.2(2). The case \|y\|d ≥ \|w\|d is similar. 

Additional property of the prefix code pairing function is that its range is the set of the prefix codes with positive counts of digits 2: 

P̀A 1 6= x ,p y (6) 

P̀A Prf (x) ∧ #(x) \> 0 → ∃v∃w(x = v ,p w ∧ Prf (v) ∧ Prf (w)) . (7) 

(6): This is because 

\#(1) 8.3.3(14) 

= 0 \< 1 + #(x ? y) 8.3.3(15) 

= #(2) + #(x ? y) 8.3.3(16) 

= #(2 ? x ? y) = #(x ,p y) . 

(7): Assume Prf (x) and #(x) \> 0. Since 2·#(x) + 1 = \|x\|d, we have x = x1 ? x2 for some x1, x2 s.t. \|x2\|d = 2·#(x) by 8.3.2(5). Thus \|x1\|d = 1 by 8.3.2(3). Since \|x2\|d \> 0 we have x2 \> 0 by 8.3.1(4) and from Prf (x) we obtain 

2·#(x) = \|x2\|d \> 2·#(x2) , (8) 

i.e. #(x1) + #(x2) 8.3.3(16) 

= #(x) \> #(x2) and so #(x1) \> 0. Since x1 = 1 or x1 = 2 by 8.3.1(5), it must be the case that x1 = 2 by 8.3.3(14). We have x2 = v ?w for some v, w s.t. Prf (v) by (8) and 8.3.5(2). We have x = x1 ? x2 = 2 ? v ? w = v ,p w and it suffices to prove Prf (w). For that we note that 

2 + 2·#(v) + 2·#(w) + 1 = 2·#(2 ? v ?w) + 1 = 2·#(x) + 1 = \|x\|d = \|2 ? v ? w\|d = 1 + \|v\|d + \|w\|d = 1 + 2·#(v) + 1 + \|w\|d 

by the properties of the dyadic size and counting functions. Hence 2·#(w) + 1 = \|w\|d. We now take any a, b \> 0 such that w = a ? b. From x = (2 ? v ? a) ? b and Prf (x) we get the desired \|b\|d \> 2·#(b). 

229

Order on Prefix Codes 

We will now define a well-ordering relation \<p on the prefix codes which will impose the structure of N on the codes. 

8\.3.7 Indexing properties of prefix codes. Following properties of pre- fix codes play central role in the definition of the order \<p: 

P̀A Prf (x) ∧ i \< \|x\|d → ∃a∃v∃b(x = a ? v ? b ∧ \|a\|d = i ∧ Prf (v)) (1) 

P̀A Prf (x) ∧ x = a1 ? v1 ? b1 ∧ Prf (v1) ∧ x = a2 ? v2 ? b2 ∧ Prf (v2) ∧ \|a1\|d = \|a2\|d → a1 = a2 ∧ v1 = v2 ∧ b1 = b2 . (2) 

Property (1) says that in every prefix code x it is possible to find a prefix code v at an arbitrary distance i \< \|x\|d from the beginning of x. Property (2) asserts that this v is uniquely determined. We can thus view the number i as an index selecting the prefix code v at the position i of x. 

(1): Assume Prf (x) and i \< \|x\|d. Since 0 \< \|x\|d .− i \< \|x\|d, we get x = a ? c for some a, c such that 0 \< \|c\|d = \|x\|d .− i by 8.3.2(5). We have \|a\|d = i by 8.3.2(3) and \|c\| \> #(c) because Prf (x). Thus c = v ? b for some v, b s.t. Prf (v) by 8.3.5(2). 

(2): Assume the antecedent of the property. We have \|v1 ? b1\|d = \|v2 ? b2\|d by 8.3.2(3) and a1 = a2, v1 ? b1 = v2 ? b2 by 8.3.2(6). We now consider two cases. If \|b1\|d ≤ \|b2\|d then b2 = c1 ? c2 for some c1, c2 such that \|b1\|d = \|c2\|d by 8.3.2(5), v1 = v2 ? c1, b1 = c2 by 8.3.2(6), and c1 = 0 by 8.3.5(3). Thus v1 = v2 and b1 = b2 by 8.3.2(2). 

The case \|b1\|d ≥ \|b2\|d is similar. 

8\.3.8 Order on prefix codes. We will define x \<p y to hold iff x and y code in the prefix notation binary trees t and s respectively and if in the order from left to right there is a subtree in t with a lesser number of inner nodes than the corresponding subtree in s while all corresponding subtrees to the left are identical and all corresponding ancestors subtrees have equal number of inner nodes. 

This seemingly complicated property expresses the first-by-size-than-by- lexicographic-order enumeration of binary trees in Fig. 1.2. The property is arithmetized with the help of two auxiliary ternary predicates x \<i 

p y and x =i 

p y introduced into PA by explicit definitions: 

P̀Ax x \<i p y ↔ ∃a∃v1∃b1∃v2∃b2(x = a ? v1 ? b1 ∧ Prf (v1) ∧ \|a\|d = i ∧ 

y = a ? v2 ? b2 ∧ Prf (v2) ∧ #(v1) \< #(v2)) (1) 

P̀Ax x =i p y ↔ ∃a∃v1∃b1∃v2∃b2(x = a ? v1 ? b1 ∧ Prf (v1) ∧ \|a\|d = i ∧ 

y = a ? v2 ? b2 ∧ Prf (v2) ∧ #(v1) = #(v2)) . (2) 

For two prefix codes x and y we clearly have x \<i p y (x =i 

p y) iff the code at the position i of x has a lesser (equal) dyadic size than the code at the position i of y. 

230

We now explicitly introduce into PA the binary predicate x \<p y: 

P̀Ax x \<p y ↔ Prf (x) ∧ Prf (y) ∧ ∃i(x \<i p y ∧ ∀j(j \< i → x =j 

p y)) (3) 

and prove that it is a linear order over Prf : 

P̀A Prf (x) → x 6\<p x (4) 

P̀A x \<p y ∧ y \<p z → x \<p z (5) 

P̀A Prf (x) ∧ Prf (y) ∧ x 6= y → x \<p y ∨ y \<p x . (6) 

(4): Assume Prf (x) and take any i \< \|x\|d. By Par. 8.3.7 we have x = a ? v ? b for the uniquely determined a, v, b s.t. \|a\|i = i. We cannot have #(v) \< #(v), thus ¬v \<i 

p v, and hence x 6\<p x. (5): Suppose x \<p y and y \<p z. We have Prf (x), Prf (y), Prf (z), x \<i1 

p y, y \<i2 

p z for some i1, i2 s.t. i1 \< \|x\|d, i1 \< \|y\|d, i2 \< \|y\|d, i2 \< \|z\|d. In the following we will use obvious transitivity properties of the auxiliary predicates which are direct consequences of the indexing of prefix codes (see Par. 8.3.7). We consider three cases. If i1 \< i2 then for any j \< i1 we have x =j 

p y, y =j p z, 

and hence x =j p z. From x \<i1 

p y and y =i1 p z we get x \<i1 

p z. Thus x \<p z. The case when i2 \< i1 is similar, and if i1 = i2 then we clearly have 

x \<i1 p z and x =j 

p z for any j \< i1. Hence x \<p y again. (6): Suppose Prf (x), Prf (y), x 6= y, and consider three cases. If \|x\|d \< \|y\|d 

then x \<0 p y and so x \<p y. If \|y\|d \< \|x\|d then y \<0 

p x and so y \<p x. Finally, if \|y\|d = \|x\|d = k then ¬y =i 

p x for some i \< k and there is the least such i 

by the least number principle. We thus have x =j p y for all j \< i and either 

x \<i p y or y \<i 

p x. Hence x \<p y or y \<p x. 

8\.3.9 Additional properties of \<p. We introduce the binary predicate ≤p by explicit definition: 

P̀Ax x ≤p y ↔ x \<p y ∨ x = y ∧ Prf (x) . (1) 

The reader will note that x ≤ x does not hold if x is not a prefix code. We now prove the remaining properties of the order on Prf which we will 

need below: 

P̀A Prf (x) ∧ Prf (y) → #(x) \< #(y) → x \<p y (2) 

P̀A x ≤p y → #(x) ≤ #(y) (3) 

P̀A Prf (x) → 1 ≤p x (4) 

P̀A Prf (x) ∧ Prf (y) ∧ Prf (v) ∧ Prf (w) ∧ #(x) + #(y) = #(v) + #(w) → (x ,p y \<p v ,p w ↔ x \<p v ∨ x = v ∧ y \<p w) . (5) 

(2): Suppose Prf (x), Prf (y), and #(x) \< #(y). We have x \<0 p y and so 

x \<p y. 

231

(3): Suppose x ≤p y. We have Prf (x), Prf (y). If it were the case that #(x) \> #(y) we would have y \<p x by (2) and x \<p x by 8.3.8(5) thus contradicting 8.3.8(4). 

(4): Suppose Prf (x) and consider two cases. If #(x) = 0 then x = 1 by 8.3.5(4) and we trivially have 1 ≤p 1. If #(x) \> 0 then, since #(1) = 0, we have 1 \<p x by (2). 

(5): Assume the antecedent of the property. We have Prf (x ,p y), Prf (v ,p w), and 

\#(x ,p y) = #(x) + #(v) + 1 = #(v) + #(w) + 1 = #(v ,p w) (6) 

by 8.3.6(2). Set k = 2·#(x ,p y) + 1 = \|x ,p y\|d = \|v ,p w\|d and in the direction (→) assume 2 ? x ? y = x ,p y \<p v ,p w = 2 ? v ? w. We now consider three cases. If #(x) \< #(v) then x \<p v by (2) and we are done. 

If #(x) \> #(v) then v \<p x by (2) and we have v \<i p x for some i \< 

\|v\|d = 2·#(v) + 1 \< 2·#(x) + 1 = \|x\|d. Also v =j p x for all j \< i. But we then 

get a contradiction as we obtain v ,p w = 2 ? v ?w \<p 2 ? x ? y = x ,p y from 2 ? v ? w \<i+1 

p 2 ? x ? y and 2 ? v ?w \<j p 2 ? x ? y for all j \< i + 1. 

The final case is #(x) = #(v). Then #(y) = #(w), \|x\|d = \|v\|d, and \|y\|d = \|w\|d. We cannot have v \<p x by the same reasoning as in the preceding case. Thus x ≤p v by 8.3.8(6). If x \<p v we are done. If x = v then we have 2 ? x ? y \<i 

p 2 ? v ? w for some 1 + \|x\|d ≤ i \< k and 2 ? x ? y =j p 2 ? v ? w for all 

j \< i. But then y \< i 

.−(1+\|x\|d) p w and y =j 

p w for all j \< i .−(1 + \|x\|d). Hence y \<p w. 

In the direction (←) consider two cases. If x \<p v then, since #(x) ≤ #(v) and so \|x\|d ≤ \|v\|d by (3), we have x \<i 

p v for some i \< \|x\|d and x =j p v 

for all j \< i. We then get x ,p y \<p v ,p w because 2 ? x ? y \<i+1 p 2 ? v ? w and 

2 ? x ? y =j p 2 ? v ? w for all j \< i + 1. 

The second case is when x = v and y \<p w. We similarly as in the preceding case get y \<i 

p w for some i \< \|y\|d and y =j p w for all j \< i. But then 

x ,p y \<p v ,p w because 2 ? x ? y \< i+\|x\|d+1 p 2 ? v ? w and 2 ? x ? y =j 

p 2 ? v ? w for all j \< i + \|x\|d + 1. 

8\.3.10 The principle of the least prefix code. The ordering predicate of prefix codes \<p is a well-order. This can be expressed in the first-order language of PA only as a theorem schema called the principle of the least prefix code with a formula φ\[x\] with one indicated variable x and y a variable not occurring in φ: 

T \` ∃xφ\[x\] ∧ ∀x(φ\[x\] → Prf (x)) → ∃x(φ\[x\] ∧ ∀y(y \<p x → ¬φ\[y\])) . (1) 

Here T is any proper extension of PA which contains the functions and pred- icates involved with prefix codes. 

Property (1) is proved by working in T . We assume ∀x(φ\[x\] → Prf (x)) and φ\[z0\] for some z0. For the formula ψ1\[n, x\] ≡ φ\[x\] ∧ \|x\|d = n we have 

232

ψ1\[\|z0\|d, z0\]. Hence ∃xψ1\[m,x\] for the least m by the least number principle. Thus φ\[z\] and \|z\|d = m for some z. Thus also Prf (z) and m = \|z\|d = 2·#z + 1 \> 0. By the minimality of m we have m ≤ \|y\|d for any y s.t. φ\[y\]. 

For the formula 

ψ2\[n, x\] ≡ φ\[x\] ∧ \|x\|d = m ∧ ∀y∀i(φ\[y\] ∧ i \< n ∧ ∀j(j \< i → x =j 

p y) → ¬y \<i p x) 

we prove by induction on n 

n ≤ m → ∃xψ2\[n, x\] . (2) 

Roughly speaking, the property says that for every n ≤ m there is an x satisfying φ\[x\] which is a minimal prefix code up to n. 

The base case is trivially satisfied by x := z because i 6\< 0. In the inductive case assume n+1 ≤ m and there is an x0 s.t. ψ2\[n, x0\] by IH. We have Prf (x0) and n \< m = \|x0\|d and let v0 be the code at the position n of x0. We thus have ψ3\[\|v0\|d, x0\] for the formula 

ψ3\[k, x\] ≡ ψ2\[n, x\] ∧ ∀a∀v∀b(x = a ? v ? b ∧ Prf (v) ∧ \|a\|d = n → \|v\|d = k) . 

Hence ∃k∃xψ3\[k, x\], and by the least number principle there is a smallest such k for which ∃xψ3\[k, x\]. Thus ψ3\[k, x\] for some x and so ψ2\[n, x\] and for the code v at the position n of x we have \|v\|d = k. We claim that φ2\[n+1, x\] holds. So take any y, i s.t. φ\[y\], i \< n + 1, and ∀j(j \< i → x =j 

p y). We have Prf (y) and we wish to show ¬y \<i 

p x. If i ≥ \|y\|d then we have ¬y \<i p x. If 

i \< \|y\|d we consider two cases. If i \< n then we have ¬y \<i p x from ψ2\[n, x\]. 

If i = n then let w be the code at the position n of y. By the minimality of k we have \|v0\|d = k ≤ \|w\|d and so we have x \<n 

p y or x =n p y and hence 

¬y \<n p x. This ends the induction proof of (2). 

From the just proved property we obtain ψ2\[m, x\] for some x and we claim that x is the least prefix code satisfying φ\[x\]. So take any y s.t. y \<p x and suppose on the contrary φ\[y\]. We have m ≤ \|y\|d and so there is an i such that i \< m, y \<i 

p x, and y =j p x for all j \< i. We now get the contradiction 

¬φ\[x\] from ψ2\[m, x\]. 

8\.3.11 Minima and maxima of prefix codes of count n. We call the number a the minimum of codes with the count n if 

Prf (a) ∧ #(a) = n ∧ ∀x(Prf (x) ∧ #(x) = n → a ≤p x) (1) 

We call the number b the maximum of codes with the count n if 

Prf (b) ∧ #(b) = n ∧ ∀x(Prf (x) ∧ #(x) = n → x ≤p b) (2) 

The reader will note that because \<p is a linear order over Prf there is at most one minimum (maximum) code of a given count n. For each n the maxima and minima exist: 

233

P̀A ∃b(Prf (b) ∧ #(b) = n ∧ ∀x(Prf (x) ∧ #(x) = n → x ≤p b)) (3) 

P̀A ∃a(Prf (a) ∧ #(a) = n ∧ ∀x(Prf (x) ∧ #(x) = n → a ≤p x)) . (4) 

(3): By induction on n. In the base case we set b := 1 because #(b) = 0 and for any x s.t. Prf (x), #(x) = 0 we have x = 1 by 8.3.5(4). In the inductive case we obtain the maximum b1 of the count n by IH and we set b = b1 ,p 1. Since Prf (1), #(1) = 0 by 8.3.5(4), we get Prf (b), #(b) = n + 1 by 8.3.6(2). Let x be any number such that Prf (x) and #(x) = n + 1. We have x = x1 ,p x2 for some x1, x2 such that Prf (x1), Prf (x2) by 8.3.6(7) and #(x1) + #(x2) = n by 8.3.6(2). For the proof of x = x1 ,p x2 ≤p b1 ,p 1 = b in which we use 8.3.9(5) we note that #(x1) ≤ n = #(b1). If #(x1) \< #(b1) then x1 \<p b1 by 8.3.9(2) and so x \<p b. If #(x1) = #(b1) then x1 ≤p b1 by the maximality of b1. If x1 \<p b1 then x \<p b again. If x1 = b1 then #(x2) = 0 and we get x2 = 1 by 8.3.5(4) and so x \<p b. 

(4): We use the principle of the least prefix code with the formula φ\[x, n\] ≡ Prf (x)∧#(x) = n. Let b be the maximum code with the count n existing by (3). We have φ\[b, n\] and so the antecedent of 8.3.10(1) is satisfied. Thus there is a number a s.t. φ\[a, n\] and for any y \<p a we have ¬φ\[y, n\]. To see that a is the minimum take any number x s.t. Prf (x) and #(x) = n, i.e. φ\[x, n\]. We must have x 6\<p a and so a ≤p x by 8.3.8(6). 

8\.3.12 Successor function over prefix codes. We wish to introduce the unary function sp(x) yielding the least prefix code after x in the order \<p by the following contextual definition: 

P̀Ax sp(x) = y ↔ x \<p y ∧ ∀z(x \<p z → y ≤p z) ∨ ¬Prf (x) ∧ y = 0 (1) 

Its existence condition 

P̀A ∃y(x \<p y ∧ ∀z(x \<p z → y ≤p z) ∨ ¬Prf (x) ∧ y = 0) (2) 

is proved by taking any x and considering two cases. If ¬Prf (x) then it suffices to set y := 0. If Prf (x) then also Prf (x ,p x) and #(x, ,p x) = 2#(x)+1 \> #(x) by 8.3.6(2). Hence x \<p x ,p x by 8.3.9(2) and thus ∃y x \<p y. The formula φ\[x, y\] ≡ x \<p y satisfies for y the antecedent of the principle of the least prefix code because we have ∃y x \<p y and from x \<p y we obtain Prf (y). Hence there is a y s.t. x \<p y and for any z such that z \<p y we have ¬x \<p z. But then if x \<p z we have ¬z \<p y, i.e. y ≤p z by 8.3.8(6). 

The uniqueness condition for sp follows from 

P̀A x \<p y1 ∧ ∀z(x \<p z → y1 ≤p z) ∧ x \<p y2 ∧ ∀z(x \<p z → y2 ≤p z) → y1 = y2 (3) 

P̀A y1 = 0 ∧ y2 = 0 → y1 = y2 . (4) 

(3): Assume the antecedent. We have Prf (y1) and Prf (y2). If it were the case that y1 6= y2 then we would have y1 \<p y2 or y2 \<p y1 by 8.3.8(6). If 

234

y1 \<p y2 then, since x \<p y1, we instantiate the second quantifier formula in the antecedent with z := y1 and get y2 ≤p y1. Thus y2 \<p y1 and then y1 \<p y1 by 8.3.8(5) contradicting 8.3.8(4). The case y2 \<p y1 leads to a contradiction similarly. 

(4): This is trivial. The function sp satisfies the following: 

P̀A Prf (x) → x \<p sp(x) ∧ ∀z(x \<p z → sp(x) ≤p z) (5) 

P̀A Prf (x) ↔ Prf (sp(x)) (6) 

P̀A x \<p y ↔ sp(x) \<p sp(y) (7) 

P̀A Prf (x) ∧ #(x) \> 0 → ∃y(Prf (y) ∧ sp(y) = x) . (8) 

(5): If Prf (x) then we get the consequent by instantiating (1) with y := sp(x). 

(6): If Prf (x) then x \<p sp(x) by (5) and we have Prf (sp(x)). Vice versa, if Prf (sp(x)) then if it were the case that ¬Prf (x) we would get sp(x) = 0 by instantiating (1) with y := sp(x). We would then get #(sp(x)) = 0 by 8.3.3(13) and a contradiction sp(x) = 1 by 8.3.5(4). 

(7): Assume x \<p y. We have Prf (x) and Prf (y) and we get x \<p sp(x) ≤p 

y \< sp(y) by (5) and transitivity. Vice versa, assume sp(x) \<p sp(y). We have Prf (x) and Prf (y) by 8.3.8(3) and (6). It cannot be the case that x = y because then sp(x) = sp(y) would contradict 8.3.8(4). Thus either y \<p x or x \<p y by 8.3.8(6). If the former then 

sp(y) (5) 

≤p x (5) \<p sp(x) \< sp(y) 

which by transitivity contradicts the irreflexivity of \<p. (8): In the proof of this property we will repeatedly prove sp(x) = y for 

some Prf (x) and Prf (y) by using (1) where we will derive x \<p y and then for any z such that x \<p z we will prove y ≤p z. The property follows from an auxiliary property 

P̀A ∀x(Prf (x) ∧ k = #(x) ∧ k \> 0 → ∃y(Prf (y) ∧ sp(y) = x)) 

by instantiating k := #(x). The auxiliary property is proved by complete induction on k. So assume Prf (x), k = #(x), and k \> 0. We have x = v ,p w for some v, w such that Prf (v), Prf (w) by 8.3.6(7) and #(x) = #(v)+#(w)+1 by 8.3.6(2). We consider two cases. 

The first case is when w is not the minimum code with the count #(w), i.e. a \<p w and #(a) = #(w) for some a. We then have w 6= 1 by 8.3.9(4) and #(w) \> 0 by 8.3.5(4). Since #(w) \< k, we have Prf (w1), sp(w1) = w for some w1 by IH. Thus w1 \<p w by (5) and #(w1) ≤ #(w) by 8.3.9(3). If it were the case that #(w1) \< #(w) then we would have w1 \<p a by 8.3.9(2) and we would get a contradiction w = sp(w1) ≤p a \<p w by (5). Thus #(w1) = #(w) and we get v ,p w1 \<p v ,p w by 8.3.9(5). Note that we have #(v ,p w1) = k. 

235

We claim that sp(v ,p w1) = v ,p w = x. For that it remains to show that if w ,p w1 \<p z for any z then x ≤p z. Thus take any z s.t. w ,p w1 \<p z. We have k = #(v ,p w1) ≤ #(z) by 8.3.9(3). If k \< #(z) then x \<p z by 8.3.9(2). If 0 \< k = #(z) then z = z1 ,p z2 for some z1, z2 such that Prf (z1), Prf (z2) by 8.3.6(7) and #(z) = #(z1) + #(z2) + 1 by 8.3.6(2). Since v ,p w1 \<p z1 ,p z2 

and #(v) + #(w) = #(v) + #(w1) = #(z1) + #(z2), we have either v \<p z1 

or v = z1 and w1 \<p z2, i.e. w = sp(w1) ≤p z2 by 8.3.9(5). But then x = v ,p w ≤p z1 ,p z2 = z by 8.3.9(5) again. 

The second case is that w is the minimum code with the count #(w) and we consider three subcases. 

The first subcase is when v = 1. We obtain from 8.3.11(3) the maximum code b with the count k .− 1. We claim that sp(b) = x = 1 ,p w. For that we note that b \<p x by 8.3.9(2). We now take any z s.t. b \<p z. We have Prf (z) and it must be the case that k .− 1 ≤ #(z) by 8.3.9(3). We cannot have k .− 1 = #(z) by the maximality of b. If k \< #(z) then x \<p z by 8.3.9(2). If k = #(z) then z = z1 ,p z2 for some z1, z2 such that Prf (z1), Prf (z2) by 8.3.6(7) and #(z1) + #(z2) = #(1) + #(w) = k .− 1 by 8.3.6(2). For the proof of 1 ,p w = x ≤p z1 ,p z2 = z we note that 1 ≤p z1 by 8.3.9(4). We use 8.3.9(5) in the two cases when either 1 \<p z1 and then x \<p z or else 1 = z1 and then, since #(w) = #(z2), we get w ≤p z2 by the minimality of w and so a ≤p x. 

The second subcase is when v 6= 1 and v is not the minimum with the count #(v). By similar reasoning as in the first case above we obtain by IH a v1 s.t. Prf (v1), #(v1) = #(v), v1 \<p v, and sp(v1) = v. We then obtain from 8.3.11(3) the maximum code b with the count #(w). We have Prf (b), #(b) = #(w), and we claim that sp(v1 ,p b) = v ,p w. Since #(v1)+#(b) = #(v)+#(w), we get v1 ,p b \<p v ,p w by 8.3.9(5). Now we take any z such that v1 ,p b \<p z. We have k = #(v1 ,p b) ≤ #(z) by 8.3.9(3). If k \< #(z) then x \<p z by 8.3.9(2). If 0 \< k = #(z) then z = z1 ,p z2 for some z1, z2 such that Prf (z1), Prf (z2) by 8.3.6(7) and #(z) = #(z1) + #(z2) + 1 by 8.3.6(2). Since v1 ,p b \<p z1 ,p z2 

and #(v) + #(w) = #(v1) + #(b) = #(z1) + #(z2), we have either v1 \<p z1 

or v1 = z1 and b \<p z2 by 8.3.9(5). The latter case cannot obtain because it would contradict the maximality of b because we would have #(b) = #(z2). Hence we have v1 \< z1 and so v = sp(v1) ≤p z1 by (5). If v \<p z1 then x = v ,p w \<p z1 ,p z2 = z by 8.3.9(5) If v = z1 then #(w) = #(z2) and we have w ≤ z2 by the minimality of w. Thus x = v ,p w ≤p z1 ,p z2 = z by 8.3.9(5) again. 

The third subcase is when v 6= 1 and v is the minimum code with the count #(v). We must have #(v) \> 0 by 8.3.5(4). We use 8.3.11(3) to get the maxima b1 with the count #(v) .− 1 and b2 with the count #(w) + 1. Thus Prf (b1), #(b1) = #(v) .− 1, Prf (b2), #(b2) = #(w)+1, and #(b1)+#(b2) = #(v)+#(w). We claim that sp(b1 ,p b2) = v ,p w. First of all, we have b1 \<p v by 8.3.9(2) and so b1 ,p b2 \<p v ,p w by 8.3.9(5). We now take any z s.t. b1 ,p b2 \<p z. We have Prf (z) and k = #(b1 ,p b2) ≤ #(z) by 8.3.9(3). If k \< #(z) we have x \<p z by 8.3.9(2). If 0 \< k = #(z) then we have z = z1 ,p z2 for some z1, z2 

236

such that Prf (z1), Prf (z2) by 8.3.6(7) and #(b1) + #(b2) = #(v) + #(w) = #(z1) + #(z2) by 8.3.6(2). From b1 ,p b2 \<p z1 ,p z2 we get b1 \<p z1 or b1 = z1 

and b2 \<p z2 by 8.3.9(5). The second case cannot happen because if b1 = z1 

then #(b2) = #(z2) and we get a contradiction z2 ≤p b2 from the maximality of b2. In the first case, when b1 \<p z1, we get #(b1) ≤ #(z1) by 8.3.9(3) and so #(b1) \< #(z1) by the maximality of b1. Thus #(v) ≤ #(z1). If #(v) \< #(z1) then x = v ,p w \<p z1 ,p z2 = z by 8.3.9(5). If #(v) = #(z1) then v ≤p z1 by the minimality of v and, since #(w) = #(z2), w ≤p z2 by the minimality of w. But then x = v ,p w ≤p z1 ,p z2 = z by 8.3.9(5). 

Isomorphism of N and Prf and a Pairing Function over N 

We will now establish an isomorphism between natural numbers and prefix codes. The isomorphism preserves orders and endows N with pairing. 

8\.3.13 Enumeration of prefix codes. We define the unary function π by primitive recursion: 

P̀Ax π(0) = 1 (1) 

P̀Ax π(x′) = sp π(x) . (2) 

The following properties of π assert that the function enumerates the prefix codes, i.e. it is an injection: (6), into Prf : (3), and onto Prf : (4). It is also an order isomorphism between N and Prf : (5). 

P̀A Prf (π(x)) (3) 

P̀A Prf (y) → ∃xπ(x) = y (4) 

P̀A x \< y ↔ π(y) \<p π(y) (5) 

P̀A π(x) = π(y) → x = y . (6) 

(3): By induction on x. In the base case we have π(0) = 1 and Prf (1) by 8.3.5(4). In the inductive case we obtain Prf (π(x)) from IH and π(x) \<p 

sp π(x) = π(x′) by 8.3.12(5). But then Prf (π(x′)). (4): Assume Prf (y) and ∀x π(x) 6= y. The formula 

φ\[y\] ≡ Prf (y) ∧ ∀xπ(x) 6= y 

thus satisfies the antecedent of the principle of least prefix code 8.3.10(1) and there is a z such that φ\[z\], i.e. Prf (z), ∀xπ(x) 6= z, and for all u \<p z we have ¬φ\[u\]. Since π(0) = 1, we have z 6= 1 and so #(z) \> 0 by 8.3.5(4). But then sp(u) = z for some u s.t. Prf (u) by 8.3.12(8) and u \<p z by 8.3.12(5). Hence π(x) = u for some x from ¬φ\[u\] and we contradict φ\[z\] because: 

π(x′) = sp π(x) = sp(u) = z . 

237

(5): We prove ∀y(5) by induction on x. In the base case we assume in the direction (→) 0 \< y. Then z′ = y for some z and π(y) = sp π(z). We have Prf (π(z)), Prf (π(y)) by (3) and π(x) \<p π(y) by 8.3.12(5). Since 1 ≤p π(x) by 8.3.9(4), we get π(0) = 1 \<p π(y) by 8.3.8(5). In the direction (←) we assume π(0) \<p π(y). Thus Prf (π(0)), Prf (π(y)) and then π(y) 6= 1 = π(0) by 8.3.8(4). Hence y 6= 0, i.e. 0 \< y. 

In the inductive case we have x′ \< y iff x′ \< z′ for some z s.t. z′ = y iff x \< z for some z s.t. z′ = y iff, by IH, π(x) \<p π(z) for some z s.t. z′ = y, iff by 8.3.12(7), sp π(x) \<p sp π(z) for some z s.t. z′ = y, iff π(x′) \<p π(z′) for some z s.t. z′ = y iff π(x′) \<p π(y). 

(6): if π(x) = π(y) then, since Prf (π(x)) by (3), we have π(x) 6\<p π(y) and π(y) 6\<p π(x) by 8.3.8(4) and so x 6\< y and y 6\< x by (5). 

Property (4) is the existence condition for the inverse of π introduced into PA by minimalization: 

π−1(x) = µy\[Prf (x) → π(y) = x\] (7) 

Direct consequence of the defining axiom for π−1 is 

P̀A Prf (x) → π π−1(x) = x . (8) 

8\.3.14 Pairing function. We are now ready to introduce by explicit defi- nition into PA the binary pairing function: 

P̀Ax x, y = π−1(π(x) ,p π(y)) (1) 

The function extends the order isomorphism π between N and Prf also to pairing because we have: 

P̀A π(x, y) = π(x) ,p π(y) . (2) 

Indeed, from the definition we obtain π(x, y) = π π−1(π(x) ,p π(y)) and, since Prf (π(x, y)) by 8.3.13(3), the property follows by 8.3.13(8). 

The basic properties of the pairing function are the pairing property 1.3.7(1) which is proved as (3) and the property 1.3.7(3) proved as (4) which assert that every positive number is in the range of the pairing function: 

P̀A x, y = v, w → x = v ∧ y = w (3) 

P̀A x = 0 ∨ ∃v∃w x = v, w . (4) 

(3): Assume x, y = v, w. From π(x, y) = π(v, w) we obtain π(x) ,p π(y) = π(v) ,p π(w) by (2). Since Prf (π(x)), Prf (π(v)), Prf (π(y)) by 8.3.13(3), we obtain π(x) = π(v); π(y) = π(w) by 8.3.6(3), and x = π−1π(x) = π−1π(v) = v; y = π−1π(y) = π−1π(w) = w by 8.3.13(8). 

(4): Assume 0 \< x and obtain 1 = π(x) \<p π(x) by 8.3.13(5). We have Prf (1) and Prf (π(x)). Since 1 6\<p 1 by 8.3.8(4), we have 1 6= π(x) and so 

238

\#(π(x)) \> 0 by 8.3.5(4). Thus π(x) = y ,p z for some y, z such that Prf (y), Prf (z) by 8.3.6(7). We have π(v) = y and π(w) = z for some v and w by 8.3.13(4) and so 

x 8.3.13(8) 

= π−1π(x) = π−1(y ,p z) = π−1(π(v) ,p π(w)) 8.3.14(1) 

= v, w . 

8\.3.15 Pair size function. The function #(x) measures the complexity of prefix codes x as the number of inner nodes of binary trees expressed by x. The isomorphic image of #(x) is the pair size function \|x\|p (see Par. 1.3.9) which is introduced into PA by an explicit definition: 

P̀Ax \|x\|p = #(π(x)) (1) 

The following are the basic properties of the pair size function 

P̀A \|0\|p = 0 (2) 

P̀A \|x, y\|p = \|x\|p + \|y\|p + 1 . (3) 

(2): We have π(0) = 1 and #(1) = 0 by 8.3.3(14). (3): We have Prf (π(x)) and Prf (π(y)) by 8.3.13(3) and so 

\|x, y\|p = #(π(x, y)) 8.3.14(2) 

= #(π(x) ,p π(y)) 8.3.6(2) 

= 

\#(π(x)) + #(π(y)) + 1 = \|x\|p + \|y\|p + 1 . 

8\.3.16 Ordering properties of pairs. The pairing property 8.3.14(3) and the property 8.3.14(4) which says that there is at most one atom 0 are con- cerned solely with the pairing function. We will now investigate properties connecting pairing to the order on N. Property (1) says that 0 is an atom, (2) gives sufficent and necessary conditions for the comparison of two pairs, and (3) will be the basis for the induction principle on pairs: 

P̀A 0 \< x, y (1) 

P̀A x, y \< v, w ↔ \|x, y\|p \< \|v, w\|p ∨ \|x, y\|p = \|v, w\|p ∧ (x \< v ∨ x = v ∧ y \< w) (2) 

P̀A x \< x, y ∧ y \< x, y . (3) 

(1): We have Prf (π(x)), Prf (π(y)) by 8.3.13(3) and Prf (π(x) ,p π(y)), #(π(x) ,p π(y)) \> 0 by 8.3.6(2). For π(0) = 1 we have Prf (π(0)) and #(π(0)) = 0 by 8.3.5(4). We get π(0) \<p π(x) ,p π(y) by 8.3.9(2) and, since and π(x, y) = π(x) ,p π(y) by 8.3.14(2), we obtain 0 \< x, y by 8.3.13(5). 

(2): We have x, y \< v, w iff, by 8.3.13(5), π(x, y) \<p π(v, w) iff, by 8.3.14(2), π(x) ,p π(y) \<p π(v) ,p π(w). 

We have Prf (π(x)), Prf (π(y)), Prf (π(v)), Prf (π(w)) by 8.3.13(3) and Prf (π(x) ,p π(y)), Prf (π(v) ,p π(w)) by 8.3.6(2). 

239

We also have \|x, y\|p \< \|v, w\|p iff #(π(x, y)) \< #(π(v, w)) iff, by 8.3.14(2), #(π(x) ,p π(y)) \< #(π(v) ,p π(w)) iff, by 8.3.6(2), #(π(x)) + #(π(y)) \< #(π(v)) + #(π(w)). 

We similarly have \|x, y\|p = \|v, w\|p iff #(π(x)) + #(π(y)) = #(π(v)) + #(π(w)). 

Now, in the direction (→) assume x, y \< v, w, get π(x, y) \<p π(v, w) by 8.3.13(5), and then #(π(x, y)) ≤ #(π(v, w)) by 8.3.9(3). Thus \|x, y\|p ≤ \|v, w\|p. If \|x, y\|p \< \|v, w\|p there is nothing to prove. If \|x, y\|p = \|v, w\|p then #(π(x)) + #(π(y)) = #(π(v)) + #(π(w)) and we have 

π(x) \<p π(v) ∨ π(x) = π(v) ∧ π(y) \<p π(w) (4) 

by 8.3.9(5). Thus 

x \< v ∨ x = v ∧ y \< w (5) 

by 8.3.13(5)(6). In the direction (←) consider first the case \|x, y\|p \< \|v, w\|p. We get 

\#(π(x) ,p π(y)) \< #(π(v) ,p π(w)) by 8.3.14(2) and π(x) ,p π(y) \<p π(v) ,p π(w) by 8.3.9(2). Hence x, y \< v, w by the above. 

In the second case assume \|x, y\|p = \|v, w\|p, i.e. #(π(x)) + #(π(y)) = #(π(v)) + #(π(w)), and (5). We obtain (4) by 8.3.13(5) and π(x) ,p π(y) \<p 

π(v) ,p π(w) by 8.3.9(5). Thus x, y \< v, w again. (3): If x = 0 we have x \< x, y by (1). If x \> 0 we have x = v, w for some 

v, w by 8.3.14(4), and since \|x\|d \< \|x, y\| by 8.3.15(3), we get x \< x, y by (2). The proof of y \< x, y is similar. 

8\.3.17 Projection functions. The unary projection functions H and T (see Par. 1.3.12) are introduced into PA by minimalization whose existence conditions are direct consequences of 8.3.14(4): 

P̀Ax H(x) = µv\[x \> 0 → ∃w v, w = x\] (1) 

P̀Ax T (x) = µw\[x \> 0 → ∃v v, w = x\] . (2) 

The projection functions satisfy the following: 

P̀A H(0) = 0 (3) 

P̀A H(v, w) = v (4) 

P̀A T (0) = 0 (5) 

P̀A T (v, w) = w . (6) 

(3): The defining axiom for H implies 0 \< H(0) → ¬(0 \> 0 → ∃w 0, w = 0) from which we get 0 \< H(0) → 0 \> 0 and then H(0) = 0. 

(4): The defining axiom for H implies v, w \> 0 → ∃w1 H(v, w), w1 = v, w. We then get H(v, w), w1 = v, w for some w1 by 8.3.16(1) and H(v, w) = v by 8.3.14(3). 

(5): Similarly as (3). (6): Similarly as (4). 

240

8\.3.18 List indexing. We wish to introduce into PA the list indexing func- tion (x)i. The function was defined in Par. 1.3.18 by a clausal definition to satisfy: 

P̀A (0)x = 0 (1) 

P̀A (v, w)0 = v (2) 

P̀A (v, w)i+1 = (w)i . (3) 

The reader will note that this is not a definition by primitive recursion because the paramater x changes in the recursive application. We can introduce the list indexing function into PA with the help of the binary function T i(x) called the iteration of T . The iteration function is introduced into PA by primitive recursion: 

P̀Ax T 0(x) = x (4) 

P̀Ax T i′(x) = T T i(x) . (5) 

The iteration function satisfies 

P̀A T i(0) = 0 (6) 

P̀A ∀xT i+1(x) = T iT (x) . (7) 

(6): By induction on i. In the base case we have T 0(0) = 0. In the inductive 

case we have T i′(0) = T T i(0) IH= T (0) 8.3.17(5) 

= 0. (7): By induction on i. In the base case we have T 0+1(x) = T T 0(x) = 

T (x) = T 0T (x). In the inductive case we get 

T i′+1(x) = T T i′(x) IH= T T iT (x) = T i+1T (x) . 

We can now introduce the indexing function into PA by explicit definition: 

P̀Ax (x)i = H T i(x) (8) 

and we can prove the above properties: 

(1): We have (0)i = H T i(0) (6) = H(0) 

8\.3.17(3) = 0. 

(2): We have (v, w)0 = H T 0(v, w) = H(v, w) 8.3.17(4) 

= v. 

(3): We have (v, w)i+1 = H T i+1(v, w) (7) = H T iT (v, w) 

8\.3.17(6) = H T i(w) = 

(w)i. 

241

8\.4 Course of Values Recursion with Measure 

The most general form of introducing functions into PA by recursion is the course of values recursion with measure where we introduce into PA an n-ary function f such that P̀A f(\~x) = τ \[\~x\] for a term τ applying, in addition to the previously introduced functions, also the function symbol f provided a measure term µ\[\~x\] ‘goes down’ in the recursion, i.e. we have µ\[\~ρ\] \< µ\[\~x\] for all recursive applications f(\~ρ). There are no additional restrictions on the form of recursive applications f(\~ρ) and the arguments \~ρ can again apply the function f in a nested form. The depth of nesting is not restricted. 

The requirement that that the measure of arguments goes down is not met by all terms τ . Suitable terms must satisfy certain non-trivial contex- tual properties. We leave the specification of the properties until the third part UNFINISHED of this text where we introduce a clausal language for a ‘comfortable’ definition of functions such as is expected in computer programming. 

In this section we introduce syntactical restrictions imposed on recursive applications in τ which will guarantee that the measure goes down regardless of the form of the term τ . 

8\.4.1 Case discrimination function D. We will need in PA the ternary case discrimination function D satisfying 

P̀A D(x′, y, z) = y (1) 

P̀A D(0, y, z) = z . (2) 

The function is introduced into PA by contextual definition: 

P̀Ax D(x, y, z) = v ↔ x \> 0 ∧ v = y ∨ x = 0 ∧ v = z (3) 

whose existence abd uniqueness conditions are straigtforward to prove. Prop- erties (1), (2) directly follow from the defining axiom. 

8\.4.2 Characteristic functions of predicates. Let P be an n-ary pred- icate which has been introduced into PA. We denote by P∗ its characteristic function which is an n-ary function introduced into PA by minimalization: 

P̀Ax P∗(\~x) = µy\[P (\~x) → y = 1\] . (1) 

This is legal because the existence condition P̀A ∃y(P (\~x) → y = 1) is trivially provable. We have 

P̀A P (\~x) → P∗(\~x) = 1 (2) 

P̀A P (\~x) ↔ P∗(\~x) \> 0 (3) 

because (2) directly follows from the defining axiom for P∗. Property (3) in the direction (→) follows from (2). In the direction (←) we note that the minimality condition in the defining axiom for P∗ is P̀A y \< P∗(\~x) → ¬(P (\~x) → y = 1) from which we obtain (←) of (3) by instantiation y := 0. 

242

8\.4.3 Numerals. We will need a notation for successor terms directly de- noting natural numbers. The terms are called (monadic) numerals and they are defined in the meta-theory to satisfy the following recurrences: 

0m ≡ 0 (1) n + 1m ≡ n′m . (2) 

Note that for a number n the numeral term nm is of the form 

0 

n︷︸︸︷ ′ . . .′ 

and it denotes n in the standard model of PA. 

8\.4.4 Measure induction. Properties of functions introduced into PA by course of values recursion with measure µ are generally proved by induction with measure. 

Let T be a proper extension of PA containing the predicate \<, φ\[\~x\] a formula, and µ\[\~x\] a term of LT with n ≥ 1 indicated variables. Both φ and µ can have additional free variables as parameters. Furthermore, let the new variables \~y be pairwise distinct from the variables of \~x. The formula of the induction with measure µ is 

∀\~x(∀\~y(µ\[\~y\] \< µ\[\~x\] → φ\[\~y\]) → φ\[\~x\]) → φ\[\~x\] (1) 

The reader will note that for \~x ≡ x and µ\[x\] ≡ x the schema of measure induction is the schema of complete induction (see Par. 7.3.7). 

8\.4.5 Theorem. Every proper extension T of PA containing the predicate \< proves the schema of induction with measure 8.4.4(1). 

Proof. We prove 8.4.4(1) from an auxiliary property 

T \` ∀\~x(∀\~y(µ\[\~y\] \< µ\[\~x\] → φ\[\~y\]) → φ\[\~x\]) → ∀\~v(µ\[\~v\] \< z → φ\[\~v\]) 

with \~v and z new. We work in T , assume the formula expressing that φ is µ-progressive 

∀\~x(∀\~y(µ\[\~y\] \< µ\[\~x\] → φ\[\~y\]) → φ\[\~x\]) , (1) 

and prove 

∀\~v(µ\[\~v\] \< z → φ\[\~v\]) (2) 

by induction on z. In the base case there is nothing to prove. In the inductive case we take any \~v s.t. µ\[\~v\] \< z′ and consider two cases by dichotomy. If µ\[\~v\] \< z we obtain φ\[\~v\] from IH: (2), If µ\[\~v\] ≥ z then we have µ\[\~v\] = z and we use a variant ∀\~y(µ\[\~y\] \< µ\[\~v\] → φ\[\~y\]) of IH: (2) in (1) instantiated with \~x := \~v to obtain φ\[\~v\]. 

The formula for the measure induction 8.4.4(1) follows from the auxiliary property by instantiating its consequent with z := µ\[\~x\] + 1 and \~v := \~x. ut 

243

8\.4.6 Extension by course of values recursion with measure. Let T be a proper extension of PA. We assume that the pairing function (x, y), the case discrimination function D(x, y, z), as well as the characteristic function \<∗ of the predicate \< have been introduced into T . 

We wish to extend T into a theory S whose language contains the n-ary function symbol f (n ≥ 1) in such a way that a course of values definition f(\~x) = τ is a theorem of S. For that we assume that τ \[f ; \~x\] is a term of LT + f with its free variables among the n indicated ones. Thus τ is built up from the variables among \~x, numerals nm, and applications g1(\~ρ), . . . , gk(\~ρ) of functions where for 1 ≤ j ≤ k the function gj has the arity nj ≥ 1. The term τ can also recursively apply the n-ary function symbol f which we indicate as τ \[f ; \~x\]. The recursive applications f(\~ρ) can be arbitrary, even nested when f is applied in terms \~ρ. There is no restriction on the depth of nesting. The only condition, which is a semantic one, is that the recursion ‘goes down’ in a measure term µ\[\~x\] of LT with its free variables among the n indicated ones. 

We keep the notation introduced in this paragraph fixed until the end of the section. 

For an n-tuple of terms \~ρ and an n-ary function symbol g we will denote by τ \[g; \~ρ\] the term obtained from τ by replacing in it all occurrences of variables from among \~x by the corresponding terms from among \~ρ and by the replacement of all recursive applications f(\~σ) by applications g(\~σ). We will also use the notation τ \[\[f \]µ\~x; \~x\] as an abbreviation for the term 

τ \[λ\~y.D((µ\[\~y\]\<∗µ\[\~x\], f(\~y), 0); \~x\] , 

i.e. the term where we have replaced every application of f(\~σ) in τ by the guarded application 

D((µ\[\~σ\]\<∗µ\[\~x\]), f(\~σ), 0) . 

The reader will note that the substitution of terms \~ρ for the corresponding variables \~x in the guarded term τ \[\[f \]µ\~x; \~x\] is written as τ \[\[f \]µ\] 

\~ρ ; \~ρ\] and it is an abbreviation for the term 

τ \[λ\~y.D((µ\[\~y\]\<∗µ\[\~ρ\], f(\~y), 0); \~ρ\] , 

i.e. the term where we have replaced every application of f(\~σ) in τ by the guarded application 

D((µ\[\~σ\]\<∗µ\[\~ρ\]), f(\~σ), 0) . 

We use the same notation ρ\[\[f \]µ\~x; \~x\] also for subterms ρ of τ . The extension of T to S with the (n + 1)-ary function symbol f and with 

the axioms universal closures of 

f(\~x) = τ \[\[f \]µ\~x; \~x\] (1) ∀\~v(µ\[\~v\] \< µ\[\~x\] → φ\[p〈τ〉q, \~v, f(\~v)\]) → φ\[p〈τ〉q, \~x, f(\~x)\] . (2) 

244

is called extension by course of values recursion with measure. The formula φ\[c, \~x, y\], which is of LT and it is used in the single induction (with measure) axiom of S containing the symbol f , will be determined in Par. 8.4.13. 

We do not impose any semantic restrictions on the recursion in τ to guarantee that the measure goes down, We achieve the same effect by pure- ly syntactic means where we surround recursive applications by if-then-else guards. Such a restriction is acceptable from the point of view of mathematics where it simplifies the proofs below but, by amounting to an additional test, it is not acceptable in computer programming. We will discuss the semantic conditions (which can be syntactically enforced by provability) in the part three UNFINISHED of this text. 

8\.4.7 Special terms. Pursuing our plan of introducing the function f into the theory S, we first extend the theory T to T1 by introducing the list index- ing function (x)i (see Par. 8.3.18) and, by explicit definitions, the functions hj for every 1 ≤ j ≤ k as special contractions of functions gj : 

T1 \` hj(x) = gj((x)0, (x)1m , . . . , (x)nj−1 

m ) . (1) 

It should be clear that we have for all 1 ≤ j ≤ k: 

T1 \` hj(x1, . . . , xnj , 0) = gj(x1, . . . , xnj ) . (2) 

The reader will recall our convention that the single argument of hj is ob- tained by pairing. 

For every subterm ρ of τ we define its contraction term 〈ρ〉 by induction on the structure of ρ to satisfy: 

〈xi〉 ≡ (x)i−1 m 

〈nm〉 ≡ nm 

〈gj(ρ1, . . . , ρn)〉 ≡ hj(〈ρ1〉, . . . , 〈ρn〉, 0) 〈f(ρ1, . . . , ρn)〉 ≡ r(〈ρ1〉, . . . , 〈ρn〉, 0) 

where r is a new unary function symbol. The reader will note that the term 〈τ〉 is built up from the single variable x used only in applications (x)i−1 

m where 

1 ≤ i ≤ n and from numerals mm by applications of unary function symbols r and hj where 1 ≤ j ≤ k whose arguments may contain also applications of the pairing function. Until the end of this section we call such terms special. 

We designate by µ1\[x\] the term obtained from the measure term µ\[\~x\] by replacing for every 1 ≤ i ≤ n the occurrences of variables xi by (x)i−1 

m . 

Since T1 \` (x1, . . . , xn, 0)i−1 m 

= xi for all 1 ≤ i ≤ n, we van prove by a simple meta-theoretical induction on the structure of µ: 

T1 \` µ1\[(x1, . . . , xn, 0)\] = µ\[x1, . . . , xn\] . (3) 

245

8\.4.8 Computation trees. We will introduce the function f into S by the arithmetization of computations of terms r(am) using as computation rule the identity r(x) = 〈τ〉\[\[r\]µ1 

x ;x\]. Terms of the form r(am) are special cases of subterms of 〈τ〉\[\[r\]µ1 

am ; am\] and we will need to record the computation of 

all subterms ρ of 〈τ〉. The computation of such a special term ρ is recorded by a binary labelled tree with the label consisting of a triple 〈ρ, a, v〉 where a is the value assigned to the variable x which may occur in ρ and v is the computed value, i.e. the denotation of the term ρ\[\[r\]µ1 

am ; am\]. The two sons t1 

and t2 are the trees recording possible subcomputations: 

〈ρ, a, v〉 t1 t2 

The form of the term ρ determines the shape of the sons t1 and t2 as follows. If ρ ≡ ρ1, ρ2 then the computation tree looks as follows: 

〈(ρ1, ρ2), a, (v1, v2)〉 〈ρ1, a, v1〉 

t1 

〈ρ2, a, v2〉 t2 

where the denotation v1 of ρ1\[\[r\]µ1 am 

; am\] is computed in the left son and the denotation v2 of ρ2\[\[r\]µ1 

am ; am\] is computed in the right son. The denotation 

of (ρ1, ρ2)\[\[r\]µ1 am 

; am\] is then the pair (v1, v2). If ρ ≡ (x)im 

or ρ ≡ nm then the respective computation trees are: 

〈(x)im , a, (a)i〉 〈nm, a, n〉 

where there are no subcomputations because the denotations of (x)im \[\[r\]µam 

; am\] and nm\[\[r\]µam 

; am\] can be determined directly as (a)i and n respectively. If ρ ≡ hj(ρ1) then the computation tree is 

〈hj(ρ1), a, hj(v)〉 〈ρ1, a, v〉 

t 

where we record in the left son the computation of the argument ρ1 into the value v and then the denotation of hj(ρ1)\[\[r\]µ1 

am ; am\] is hj(v). There is not 

need to record any computation in the right son. Finally, if ρ ≡ r(ρ1) then there are two possible computation trees: 

〈r(ρ1), a, w〉 〈ρ1, a, v〉 

t1 

〈〈τ〉, v, w〉 t2 

〈r(ρ1), a, 0〉 〈ρ1, a, v〉 

t1 

246

In both cases the denotation v of the argument ρ1 is computed in the left son. The two cases are determined by the outcome of the test N ² µ1\[vm\] \< µ1\[am\]. If the measure decreases, i.e. if the formula µ1\[vm\] \< µ1\[am\] is true in the standard model, then the computation tree is shown above on the left. This is when the identity r(x) = 〈τ〉\[\[r\]µ1 

x ; x\] is used as the com- putation rule in the form r(vm) 7→ 〈τ〉\[\[r\]µ1 

vm ; vm\]. The denotation w of the 

term 〈τ〉\[\[r\]µ1 vm 

; vm\] is computed in the right son and the denotation of the recursive application r(vm) is determined as w. 

If the outcome of the test is negative then the computation tree is shown above on the right where the denotation of r(vm) is 0. The reader will note that the computation of r(ρ) thus evaluates the guard 

r(ρ1)\[\[r\]µ1 am 

; am\] ≡ D(µ1\[ρ1\[\[r\]µ1 am 

; am\]\]\<∗µ1\[x\[\[r\]µ1 am 

; am\]\], r(ρ1\[\[r\]µ1 am 

; am\]), 0) . 

It should be obvious that we can construct a computation tree for any subterm ρ of 〈τ〉 and any assignment a of the value of the variable x because the terms in the labels of the tree are always smaller except in the right sons of recursive applications but then the measure decreases and the initial measure, which is the denotation of µ1\[am\], can decrease only finitely many times. 

The property of t being a computation tree can be expressed as follows: 

for all non-empty subtrees s of t the label of s is of a form 〈ρ, a, v〉 where ρ is a subterm of 〈τ〉 and the relation between this label and the labels of the two sons of s is as shown in the above diagrams. 

We will arithmetize the computation trees by extending in Par. 8.4.9 the theory T1 to T3 with the arithmetized subtree predicate a E b where a codes a subtree of the tree coded by b We will then extend in Par. 8.4.11 the theory T3 to T4 with a predicate Ct(c) holding in the standard model iff c codes a computation tree t. The predicate Ct will be introduced with the help of the he predicate Nd(a) expressing the local node relation between the label of the non-empty tree coded by a and the labels of its two sons. 

8\.4.9 Subtree predicate. We will now extend the theory T1 into a theory T3 by introducing a binary predicate u E t intended to hold whenever u codes a subtree of a binary tree coded by t. The empty binary tree is coded by the number 0 and the binary tree with the label b and two sons t1, t2 by the triple n, a1, a2 where a1 and a2 are the codes of the respective sons. 

We wish the subtree predicate to satisfy the following: 

T3 \` u E t ↔ u = 0 ∨ u = t ∨ ∃b∃t1∃t2(t = b, t1, t2 ∧ (u E t1 ∨ u E t2)) . (1) 

The reader will note that such a subtree predicate u E t does not fully express the relation that u codes a subtree of a binary tree coded by t. In particular, 

247

we have 0 E t even if t is not a code. But if t codes a binary tree and u E t holds then u codes a subtree of the tree coded by t. 

Property (1) is a recurrence where the subtree predicate is applied on the right to lesser second arguments t1 \< t and t2 \< t than on the left. Recursive predicates are usually defined from their characteristic functions. We cannot introduce E∗ by primitive recursion because its natural recurrences 

(0 E∗ t) = 1 (u E∗ u) = 1 

(u E∗ t1) = 1 ∨ (u E∗ t2) = 1 → (u E∗ b, t1, t2) = 1 

are of the form of so called course of values recursion where the recursive argument (the second one) does not decrease in the recursion to its immediate predecessor. Course of values recursion can be reduced to primitive recursion with the help ot the course of values function h for E∗ such that the following holds: 

h(t, u) = (u E∗ t− 1), (u E∗ t− 2), . . . , (u E∗ 1), (u E∗ 0), 0 . 

We clearly have (h(t + i′, u))i → u E∗ t 

and so the values of applications u E∗ t1 and u E∗ t2 in the recurrences for E∗ can be recovered from the course of values function h as (h(t, u))i where t1 + i′ = t or t2 + i′ = t respectively. 

Preparatory to the introduction of the function h we explicitly extend T1 

into T2 with an auxiliary ternary predicate R: 

T2 \` R(u, t, a) ↔ u = 0 ∨ u = t ∨ ∃b∃t1∃t2∃i(t = b, t1, t2 ∧ (t1 + i′ = t ∨ t2 + i′ = t) ∧ (a)i \> 0) , 

(2) 

we also introduce into T1 its characteristic function R∗ (see Par. 8.4.2), and finally the course of values function h which is defined by primitive recursion: 

T2 \` h(0, u) = 0 (3) T2 \` h(t′, u) = R∗(u, t, h(t, u)), h(t, u) . (4) 

The reader will note that the characteristic function E∗ for E could be now introduced into T2 (but we will not need to do this) by explicit definition u E∗ t = R∗(u, t, h(t, u)) because of the following property: 

T2 \` (h(s + i′, u))i = R∗(u, s, h(s, u)) (5) 

which is proved in T2 by induction on i. In the base case we have 

(h(s+0′, u))0 = (h(s′, u))0 = (R∗(u, s, h(s, u)), h(s, u))0 8.3.18(2) 

= R∗(u, s, h(s, u)) . 

248

In the inductive case we have 

(h(s + i′′, u))i′ = (h((s + i′)′, u))i′ = 

(R∗(u, s + i′, h(s + i′, u)), h(s + i′, u))i′ 8.3.18(3) 

= 

(h(s + i′, u))i IH= R∗(u, s, h(s, u)) . 

We are now ready to extend T2 into T3 by introducing the subtree predicate by explicit definition: 

T3 \` u E t ↔ R(u, t, h(t, u)) . (6) 

The predicate satisfies the following auxilary property: 

T3 \` u E s ∧ s \< t ↔ ∃i(s + i′ = t ∧ (h(t, u))i \> 0) (7) 

for which we have u E s and s \< t iff R(u, s, h(s, u)) and s \< t iff, by 8.4.2(3), R∗(u, s, h(s, u)) \> 0 and s + i′ = t for some i iff, by (5), (h(t, u))i \> 0 and s + i′ = t for some i. 

We are now ready to prove in T3 the basic recurrence (1) for the subtree predicate. We have u E t iff R(u, t, h(t, u)) iff, by (2), (u = 0 ∨ u = t) or t = b, t1, t2, (t1 + i′ = t∨ t2 + i′ = t), and (h(t, u))i \> 0 for some b, t1, t2, and i iff (u = 0 ∨ u = t) or t = b, t1, t2 and 

∃i(t1 + i′ = t ∧ (h(t, u))i \> 0) ∨ ∃i(t2 + i′ = t ∧ (h(t, u))i \> 0) 

for some b, t1, t2 iff, by (7), (u = 0 ∨ u = t) or t = b, t1, t2 and 

t1 \< t ∧ u E t1 ∨ t2 \< t ∧ u E t2 

for some b, t1, t2 iff, by 8.3.16(3), (u = 0 ∨ u = t) or t = b, t1, t2 and (u E t1 ∨ u E t2) for some b, t1, t2. 

8\.4.10 Codes of special terms. Special terms are arithmetized by en- coding into numbers. To that end we introduce the following constructor functions operating on terms: 

Xρ ≡ 0, ρ (1) N(ρ) ≡ 1, ρ (2) 

P (ρ1, ρ2) ≡ 2, ρ1, ρ2 (3) Hρ1(ρ2) ≡ 3, ρ1, ρ2 (4) 

R(ρ) ≡ 4, ρ . (5) 

Constructor meta-functions are used to assign codes pρq (Gödel numbers) to special terms ρ to satisfy: 

249

p(x)im q ≡ Xim 

(6) 

pmmq ≡ N(mm) (7) pτ1, τ2q ≡ P (pτ1q, pτ2q) (8) phj(τ)q ≡ Hj 

m (pτq) (9) 

pr(τ)q ≡ R(pτq) . (10) 

The reader will note that pρq stands for a closed term of LT2 whose interpre- tation in the standard model of PA denotes the code of the special term ρ. Specifically, p3mq stands for the term N(0′′′) which denotes the same number as the term 1, 3, i.e. the number 15. 

The reader may ask why we have defined the constructor function as meta-functions yielding terms rather than as functions in PA? The reason for that will be seen in Par. 8.4.13 where it will be essential that the terms constructed with the help of constructors are of LT . 

8\.4.11 The predicate Ct. We will now extend the theory T3 to T4 by introducing the predicate Ct(t) holding of codes t of computation trees. We arithmetize (encode) the empty computation tree as the number 0 and the tree 

〈ρ, a, v〉 t1 t2 

by the number denoted by the term 

(pρq, am, vm), pt1q, pt2q 

where pt1q and pt2q encode the two sons respectively. The predicate is defined with the help of an auxiliary unary predicate Nd(t) holding iff the labels of t and of its sons satisfy the local node conditions discussed in Par. 8.4.8. 

Both predicates are introduced by explicit definitions: 

T4 \` Nd(t) ↔ ∃c∃a∃v∃t1∃t2(t = (c, a, v), t1, t2 ∧ ( ∃i(c = Xi ∧ i \< n ∧ v = (a)i ∧ t1 = 0 ∧ t2 = 0) ∨ ∃m(c = N(m) ∧ v = n ∧ t1 = 0 ∧ t2 = 0) ∨ ∃c1∃c2∃v1∃v2∃s1∃s2(c = P (c1, c2) ∧ v = v1, v2 ∧ 

t1 = (c1, a, v1), s1 ∧ t2 = (c2, a, v2), s2) ∨ ∃c1∃j∃w∃s1(c = Hj(c1) ∧ t1 = (c1, a, w), s1 ∧ t2 = 0 ∧ 

(j = 1m ∧ v = h1(w) ∨ . . . ∨ j = km ∧ v = hk(w))) ∨ ∃c1∃w∃s1∃s2(c = R(c1) ∧ t1 = (c1, a, w), s1 ∧ 

(µ1\[w\] \< µ1\[a\] ∧ t2 = (pτq, w, v), s2 ∨ µ1\[w\] ≥ µ\[a\] ∧ v = 0 ∧ t2 = 0))) (1) 

T4 \` Ct(t) ↔ ∀u(u E t ∧ u \> 0 → Nd(u)) . (2) 

250

and Ct satisfies the following: 

T4 \` Ct(0) (3) T4 \` i \< n → Ct((Xi, a, (a)i), 0, 0) (4) T4 \` Ct((N(m), a,m), 0, 0) (5) T4 \` Ct((c1, a, v1), s1) ∧ Ct((c2, a, v2), s2) → 

Ct((P (c1, c2), a, v1, v2), ((c1, a, v1), s1), ((c2, a, v2), s2)) (6) T4 \` Ct((c, a, v), s) → Ct((Hj 

m (c), a, hj(v)), ((c, a, v), s), 0) (7) 

T4 \` Ct((c, a, v), s1) ∧ µ1\[v\] \< µ1\[a\] ∧ Ct((p〈τ〉q, v, w), s2) → Ct((R(c), a, w), ((c, a, v), s1), ((p〈τ〉q, v, w), s2)) (8) 

T4 \` Ct((c, a, v), s1) ∧ µ1\[v\] ≥ µ1\[a\] → Ct((R(c), a, 0), ((c, a, v), s1), 0) (9) T4 \` Ct(b, t1, t2) → Ct(t1) ∧ Ct(t2) . (10) 

Property (7) is a schema of k theorems one for each 1 ≤ j ≤ k. Properties (3) through (9) can be called sufficient conditions for computation trees to be constructed out of smaller trees. The property (10) can be seen as stating a necessary condition for a triple b, t1, t2 to be a computation tree. 

(3): This holds trivially. (4): Assume i \< n and take any u \> 0 such that u E (Xi, a, (a)i), 0, 0. 

Since u E 0 leads to contradiction u = 0, it must be the case that u = (Xi, a, (a)i)), 0, 0 by 8.4.9(1) and thus Nd(u). This proves the consequent. 

(5): Take any u \> 0 such that u E (N(m), a,m), 0, 0. Since u E 0 leads to contradiction u = 0, it must be the case that u = (N(m), a, m), 0, 0 by 8.4.9(1) and thus Nd(u). This proves the consequent. 

(6): Assume Ct((c1, a, v1), s1), Ct((c2, a, v2), s2). For 

t := (P (c1, c2), a, v1, v2), ((c1, a, v1), s1), ((c2, a, v2), s2) 

we wish to prove Ct(t). We thus take any u \> 0 such that u E t. We consider the three cases implied by 8.4.9(1). If u = t then we can see that Nd(u) and hence Ct(t) hold. If u E (c1, a, v1), s1 then we obtain Nd(u) and hence Ct(t) from the assumption Ct((c1, a, v1), s1). If u E (c2, a, v2), s2 then we obtain Nd(u) and hence Ct(t) from the assumption Ct((c2, a, v2), s2). 

(7): Take any 1 ≤ j ≤ k and assume Ct((c, a, v), s). For 

t := (Hj m 

(c), a, hj(v)), ((c, a, v), s), 0 

we wish to prove Ct(t). We thus take any u \> 0 such that u E t. Since u E 0 leads to contradiction u = 0, we consider the two cases implied by 8.4.9(1). If u = t then we can see that Nd(u) and hence Ct(t) hold. If u E (c, a, v), s we obtain Nd(u), and hence Ct(t), from the assumption Ct((c, a, v), s). 

(8): Assume Ct((c, a, v), s1), µ1\[v\] \< µ1\[a\], Ct((p〈τ〉q, v, w), s2), and for 

t := (R(c), a, w), ((c, a, v), s1), ((p〈τ〉q, v, w), s2) 

251

we wish to prove Ct(t). We thus take any u \> 0 such that u E t. We consider the three cases implied by 8.4.9(1). If u = t then we can see that Nd(u) and hence Ct(t) hold. If u E (c, a, v), s1 or u E (p〈τ〉q, v, w), s2 then we obtain Nd(u), and hence Ct(t) from the corresponding assumptions on Ct . 

(9): Assume Ct((c, a, v), s1), µ1\[v\] ≥ µ1\[a\], and for 

t := (R(c), a, 0), ((c, a, v), s1), 0 

we wish to prove Ct(t). We thus take any u \> 0 such that u E t. Since u E 0 leads to contradiction u = 0, we consider the two cases implied by 8.4.9(1). If u = t then we can see that Nd(u) and hence Ct(t) hold. If u E (c, a, v), s1 

then we obtain Nd(u), and hence Ct(t), from the assumption Ct((c, a, v), s1). (10): Assume Ct(b, t1, t2) and for the proof of Ct(t1) take any u \> 0 such 

that u E t1. We have u E b, t1, t2 by 8.4.9(1), Nd(u) from the assumption by (2), and hence Ct(t1) by (2). We prove Ct(t2) similarly. 

8\.4.12 Existence and uniqueness properties for r. We could now in- troduce the function r by the implicit definition ∃sCt((p〈τ〉q, x, r(x)), s) and prove that it solves the identity r(x) = 〈τ〉\[\[r\]µ1 

x ; x\]. In the proof of Theorem 8.4.14 we will introduce instead the n-ary function f directly by an implicit axiom equivalent to 

∃sCt((p〈τ〉q, (x1, . . . , xn, 0), f(x1, . . . , xn)), s) 

and then solve the identity f(\~x) = τ \[\[f \]µ\~x; \~x\]. In any case we will need the following properties from which the existence 

uniqueness conditions for r and f will follow: 

T4 \` ∃y∃sCt((p〈τ〉q, x, y), s) (1) T4 \` Ct((c, x, y1), s1) ∧ Ct((c, x, y2), s2) → y1 = y2 ∧ s1 = s2 . (2) 

(1): We first prove the following auxiliary properties: 

T4 \` ∀v(µ1\[v\] \< µ1\[x\] → ∃y∃sCt((p〈τ〉q, v, y), s)) → ∃y∃sCt((pρq, x, y), s) . (3) 

for the finitely many subterms ρ of 〈τ〉 in the order of their construction, i.e. by the meta-theoretical induction on the construction of the special term ρ. So assume the antecedent 

∀v(µ1\[v\] \< µ1\[x\] → ∃y∃sCt((p〈τ〉q, v, y), s) (4) 

and continue by the case analysis of the special term ρ where we wish to find a y and s such that Ct((pρq, x, y), s). 

If ρ ≡ (x)im where i \< n = nm then pρq ≡ Xi, we use 8.4.11(4), and set 

y := (x)i, s := 0, 0. 

252

If ρ ≡ mm then pρq ≡ N(mm), we use 8.4.11(5), and set y := mm, s := 0, 0. 

If ρ ≡ ρ1, ρ2 then pρq ≡ P (pρ1q, pρ2q) and we have 

T4 \` (4) → ∃y∃sCt((pρ1q, x, y), s) T4 \` (4) → ∃y∃sCt((pρ2q, x, y), s) 

by two inductive meta-hypotheses. We use the assumption (4) and obtain Ct((pρ1q, x, y1), s1), Ct((pρ2q, x, y2), s2) for some y1, y2, s1, and s2. We now use 8.4.11(6) and set y := y1, y2, s := ((pρ1q, x, y1), s1), ((pρ2q, x, y2), s2). 

If ρ ≡ hj(ρ1) where 1 ≤ j ≤ k then pρq ≡ Hj m 

(pρ1q) and we have Ct((pρ1q, x, v), s1) for some v and s1 from the inductive meta-hypothesis. We now use 8.4.11(7) and set y := hj(v), s := ((pρ1q, x, v), s1), 0. 

If ρ ≡ r(ρ1) then pρq ≡ R(pρ1q) and we have Ct((pρ1q, x, v), s1) for some v and s1 from the inductive meta-hypothesis. We now consider t- wo cases. If µ1\[v\] \< µ1\[x\] we have Ct((p〈τ〉q, v, z), s2) for some w and s2 from (4) and it suffices now to use 8.4.11(8) and set y := w, s := ((pρ1q, x, v), s1), ((p〈τ〉q, v, w), s2). If µ1\[v\] ≥ µ1\[x\] then it suffices to use 8.4.11(9) and set y := 0, s := ((pρ1q, x, v), s1), 0. This ends the proof of the auxiliary properties (3). 

We now prove (1) by measure induction with µ1\[x\]. The induction hy- pothesis is (4) and the property follows from it by (3) with ρ := 〈τ〉. 

(2): We prove 

T4 \` ∀c∀x∀y1∀y2∀s2(Ct((c, x, y1), s1) ∧ Ct((c, x, y2), s2) → y1 = y2 ∧ s1 = s2) (5) 

by complete induction on s1. So we take any c, x, y1, y2, s2, and assume Ct((c, x, y1), s1), Ct((c, x, y2), s2). We have (c, x, y1), s1 E (c, x, y1), s1 by 8.4.9(1), 

Nd((c, x, y1), s1) (6) 

by 8.4.11(2), s1 = t1, t2 for some t1 and t2 by 8.4.11(1), and Ct(t1), Ct(t2) by 8.4.11(10). We similarly obtain 

Nd((c, x, y2), s2) , (7) 

s2 = u1, u2, Ct(u1), and Ct(u2) for some u1 and u2. We now consider the cases implied by (6) and (7) where we wish to prove 

y1 = y2, t1 = u1, and t2 = u2. If c = Xi for some i then we have i \< n, y1 = (x)i = y2, t1 = 0 = u1, and 

t2 = 0 = u2. If c = N(m) for some m then we have y1 = m = y2, t1 = 0 = u1, and 

t2 = 0 = u2. If c = P (c1, c2) for some c1, c2 then we have y1 = w1, w2, t1 = 

(c1, x, w1), s3; t2 = (c2, x, w2), s4 for some w1, w2, s3, s4 by (6) and y2 = 

253

z1, z2; u1 = (c1, x, z1), s5; u2 = (c2, x, z2), s6 for some z1, z2, s5, s6 by (7). Since s3 \< t1 \< s1, we get w1 = z1; s3 = s5 from Ct(t1), Ct(u1) by IH. Similarly, since s4 \< t2 \< s1, we get w2 = z2; s4 = s6 from Ct(t2), Ct(u2) by IH. Hence y1 = y2; t1 = u1; and t2 = u2. 

If c = Hi(c1) for some i, c1 then we have 

i = 1m ∧ y1 = h1(w) ∨ . . . ∨ i = km ∧ y1 = hk(w) , 

t1 = (c1, x, w), s3; t2 = 0 for some w and s3 by (6) and 

i = 1m ∧ y2 = h1(z) ∨ . . . ∨ i = km ∧ y2 = hk(z) , 

u1 = (c1, x, z), s4; u2 = 0 for some z and s4 by (7). Since s3 \< t1 \< s1, we get w = z; s3 = s4 by IH from Ct(t1), Ct(u1). Hence y1 = y2; t1 = u1; and t2 = u2. 

If c = R(c1) for some c1 then we have t1 = (c1, x, w), s3 for some w and s3 by (6) and u1 = (c1, x, z), s4 for some z and s4 by (7). Since s3 \< t1 \< s1, we get w = z, s3 = s4 by IH from Ct(t1), Ct(u1). Hence t1 = u1. We now consider two cases. If µ1\[w\] \< µ1\[x\] then we have t2 = pτq, w, y1, s5 for some s5 by (6) and u2 = pτq, z, y2, s6 for some s6 by (7). Since s5 \< t2 \< s1, w = z, we get y1 = y2, s5 = s6 by IH from Ct(t2), Ct(u2). Hence t2 = u2. If µ1\[w\] ≥ µ1\[x\] then we have y1 = 0 = y2 and t2 = 0 = u2 by (6), (7). 

8\.4.13 Graph of the arithmetized denotation function for subterms of τ . We will now effectively determine an (n + 2)-ary formula φ\[c, \~x, y\] of LT with the free variables among the indicated ones, which is used in the induction axiom 8.4.6(2) of S. The formula can be viewed as the graph of the arithmetized denotation function for the subterms ρ of τ because we will have N ² φ\[p〈ρ〉q, \~x, y\] in the standard model of S iff y is the denotation of the term ρ\[\[f \]µ\~x, \~x\] in the assignment \~x. 

Since T4 is an extension by definitions of T , the formula φ\[c, x1, . . . , xn, y\] is effectively obtained from the formula 

∃sCt((c, (x1, . . . , xn, 0), y), s) 

of LT4 by translation and in such a way that we have 

T4 \` φ\[c, x1, . . . , xn, y\] ↔ ∃sCt((c, (x1, . . . , xn, 0), y), s) (1) 

by the Theorem on Extensions by definition 6.6.2. We will need the following properties of the formula φ: 

254

T \` ∃yφ\[p〈τ〉q, \~x, y\] (2) T \` φ\[c, \~x, y1\] ∧ φ\[c, \~x, y2\] → y1 = y2 (3) T \` φ\[Xi−1 

m , \~x, xi\] (4) 

T \` φ\[N(m), \~x,m\] (5) T \` φ\[c1, \~x, v1\] ∧ φ\[c2, \~x, v2\] → φ\[P (c1, c2), \~x, (v1, v2)\] (6) T \` φ\[c, \~x, (v1, . . . , vnj 

, 0)\] → φ\[Hj m 

(c), \~x, gj(v1, . . . , vnj )\] (7) 

T \` φ\[c, \~x, (v1, . . . , vn, 0)\] ∧ µ\[v1, . . . , vn\] \< µ\[\~x\] ∧ φ\[p〈τ〉q, v1, . . . , vn, w\] → φ\[R(c), \~x, w\] (8) 

T \` φ\[c, \~x, (v1, . . . , vn, 0)\] ∧ µ\[v1, . . . , vn\] ≥ µ\[\~x\] → φ\[R(c), \~x, 0\] . (9) 

for every 1 ≤ i ≤ n and 1 ≤ j ≤ k. In the following proofs we work in T4 

and use the equivalence (1) without explicitly referring to it. Properties (2) through (9) are thus derived in T4 but, since they all are in the language LT , they are also theorems of T because T4 is conservative over T . 

(2): A direct consequence of 8.4.12(1). (3): A direct consequence of 8.4.12(2). (4): Take an i s.t. 1 ≤ i ≤ n. Since T4 proves i− 1m \< n and 

(x1, . . . , xn, 0)i−1 m 

= xi , 

we get Ct((Xi−1 m 

, (x1, . . . , xn, 0), xi), 0, 0) by 8.4.11(4) and then 

∃sCt((Xi−1 m 

, (x1, . . . , xn, 0), xi), s) . 

(5): A direct consequence of 8.4.11(5). (6): A direct consequence of 8.4.11(6). (7): Take any j s.t. 1 ≤ j ≤ k and assume the antecedent. Then 

Ct((c, (x1, . . . , xn, 0), (v1, . . . , vnj , 0)), s1) for some s1 and we get 

∃sCt((Hj m 

(c), (x1, . . . , xn, 0), hj(v1, . . . , vnj , 0)), s) 

by 8.4.11(7). We now use 8.4.7(2) to get 

∃sCt((Hj m 

(c), (x1, . . . , xn, 0), gj(v1, . . . , vnj )), s) . 

(8): Assume the antecedent. Then Ct((c, (x1, . . . , xn, 0), (v1, . . . , vn, 0)), s1), µ\[v1, . . . , vn\] \< µ\[x1, . . . , xn\], and Ct((p〈c〉q, (v1, . . . , vn, 0), w), s2), for some s1, s2. We have µ1\[(v1, . . . , vn, 0)\] \< µ1\[(x1, . . . , xn, 0)\] by 8.4.7(3) and ∃sCt((R(c), (x1, . . . , xn, 0), w), s) by 8.4.11(8). 

(9): This is similar to and somewhat simpler than (8). 

255

8\.4.14 Theorem. If T is a proper extension of PA containing the pairing function (x, y), the case discrimination function D(x, y, z), as well as the characteristic function \<∗ of the predicate \< then an extension of T by course of values recursion with measure is an extension by definition. 

Proof. Let T be as in the theorem, S an extension of T by course of values recursion with measure as in Par. 8.4.6, and S1 an extension of T by implicit definition with the defining axiom an universal closure of φ\[p〈τ〉q, \~x, f(\~x)\]. We have LS1 = LS and S1 is an extension by definition of T by Thm. 6.6.3 because T proves the existence 8.4.13(2) and uniqueness 8.4.13(3) conditions for f . Clearly 

S1 \` φ\[p〈τ〉q, \~x, f(\~x)\] . (1) 

In order to prove the theorem it suffices to prove that the theories S and S1 

are equivalent. For the proof S1 \` S we derive auxiliary properties 

S1 \` φ\[p〈ρ〉q, \~x, ρ\[\[f \]µ\~x; \~x\]\] (2) 

for the finitely many subterms ρ of τ by the meta-induction on the construc- tion of ρ. 

If ρ ≡ xi where 1 ≤ i ≤ n then, since p〈xi〉q ≡ p(x)i−1 m 

q ≡ Xi−1 m 

, we have φ\[Xi−1 

m , \~x, xi\] by 8.4.13(4) and we note that xi\[\[f \]µ\~x; \~x\] ≡ xi. 

If ρ ≡ mm then, since p〈mm〉q ≡ pmmq ≡ N(mm), we have φ\[N(mm), \~x,mm\] by 8.4.13(5) and we note that mm\[\[f \]µ\~x; \~x\] ≡ mm. 

If ρ ≡ gj(ρ1, . . . , ρnj ) where 1 ≤ j ≤ k we obtain φ\[p〈ρ1〉q, \~x, ρ1\[\[f \]µ\~x; \~x\]\], . . . , φ\[p〈ρnj 〉q, \~x, ρn\[\[f \]µ\~x; \~x\]\] by nj inductive meta-hypotheses. Since for 

c = P (p〈ρ1〉q, . . . , P (p〈ρnj 〉q, N(0)) . . .) ≡ p〈ρ1〉, . . . , 〈ρnj 〉, 0q 

we have 

p〈gj(ρ1, . . . , ρnj )〉q ≡ phj(〈ρ1〉, . . . , 〈ρnj 〉, 0)q ≡ Hj m 

(c) , 

we get φ\[c, \~x, (ρ1\[\[f \]µ\~x; \~x\], . . . , ρnj \[\[f \]µ\~x; \~x\], 0)\] 

by nj applications of 8.4.13(6) and then 

φ\[Hj m 

(c), \~x, gj(ρ1\[\[f \]µ\~x; \~x\], . . . , ρnj \[\[f \]µ\~x; \~x\])\] 

by 8.4.13(7). We are done since 

gj(ρ1, . . . , ρnj )\[\[f \]µ\~x; \~x\] ≡ gj(ρ1\[\[f \]µ\~x; \~x\], . . . , ρnj \[\[f \]µ\~x; \~x\]) . 

If ρ ≡ f(ρ1, . . . , ρn) we obtain φ\[p〈ρ1〉q, \~x, ρ1\[\[f \]µ\~x; \~x\]\], . . . , φ\[p〈ρn〉q, \~x, ρn\[\[f \]µ\~x; \~x\]\] by n inductive meta-hypotheses. Since for 

256

c = P (p〈ρ1〉q, . . . , P (p〈ρn〉q, N(0)) . . .) ≡ p〈ρ1〉, . . . , 〈ρn〉, 0q 

we have p〈f(ρ1, . . . , ρn)〉q ≡ pr(〈ρ1〉, . . . , 〈ρn〉, 0)q ≡ R(c) , 

we get φ\[c, \~x, (ρ1\[\[f \]µ\~x; \~x\], . . . , ρn\[\[f \]µ\~x; \~x\], 0)\] 

by n applications of 8.4.13(6). We now consider two cases. If 

µ\[ρ1\[\[f \]µ\~x; \~x\], . . . , ρn\[\[f \]µ\~x; \~x\]\] \< µ\[\~x\] (3) 

then from (1) we obtain 

φ\[p〈τ〉q, \~x, f(ρ1\[\[f \]µ\~x; \~x\], . . . , ρn\[\[f \]µ\~x; \~x\])\] (4) 

and from 8.4.13(8) φ\[R(c), \~x, f(ρ1\[\[f \]µ\~x; \~x\], . . . , ρn\[\[f \]µ\~x; \~x\])\]. We are done be- cause 

f(ρ1, . . . , ρn)\[\[f \]µ\~x; \~x\] ≡ D((µ\[ρ1\[\[f \]µ\~x; \~x\], . . . , ρn\[\[f \]µ\~x; \~x\]\]\<∗µ\[\~x\]), f(ρ1\[\[f \]µ\~x; \~x\], . . . , ρn\[\[f \]µ\~x; \~x\]), 0) = 

f(ρ1\[\[f \]µ\~x; \~x\], . . . , ρn\[\[f \]µ\~x; \~x\]) . 

If not (3) then we get φ\[R(c), \~x, 0\] by 8.4.13(9) and we are done because 

f(ρ1, . . . , ρn)\[\[f \]µ\~x; \~x\] ≡ D((µ\[ρ1\[\[f \]µ\~x; \~x\], . . . , ρn\[\[f \]µ\~x; \~x\]\]\<∗µ\[\~x\]), f(ρ1\[\[f \]µ\~x; \~x\], . . . , ρn\[\[f \]µ\~x; \~x\]), 0) = 0 . 

With (2) proved, we derive the defining axiom 8.4.6(1) of S for f : S1 \` f(\~x) = τ \[\[f \]µ\~x; \~x\] by 8.4.13(3) from (1) and from (2) where we take the subterm τ of τ for ρ. Since S1 is proper, it also proves the induction axiom 8.4.6(2) of S by Thm. 8.4.5. 

Vice versa, for the proof S \` S1 we derive auxiliary properties 

S \` ∀\~v(µ\[\~v\] \< µ\[\~x\] → φ\[p〈τ〉q, \~v, f(\~y)\]) → φ\[p〈ρ〉q, \~x, ρ\[\[f \]µ\~x; \~x\]\] (5) 

for the finitely many subterms ρ of τ by the meta-induction on the construc- tion of ρ. So we assume 

∀\~v(µ\[\~v\] \< µ\[\~x\] → φ\[p〈τ〉q, \~v, f(\~y)\]) (6) 

and continue by the case analysis of ρ exactly as in the proof of (2) where the only difference is in the case when ρ ≡ f(ρ1, . . . , ρn) and (3) holds. We obtain (4) from the assumption (6) rather than from (1) as was the case above. 

With (5) proved, we derive the defining axiom (1) for f in S1: S \` φ\[p〈τ〉q, \~x, f(\~x)\] by the induction axiom with measure 8.4.6(2) where we as- sume (6) and use (5) with the subterm τ of τ for ρ to get φ\[p〈τ〉q, \~x, τ \[\[f \]µ\~x; \~x\]\]. We now get (1) from the defining axiom 8.4.6(1) for f in S. ut 

257

258

9\. Proof Theory of PA 

UNFINISHED Gentzen was first. but we need the strength of induction schemas for the characterization purposes by means of provably recursive functions.

Miscellaneous 

9\.0.15 Theorem. We have 

P̀A ∃q∃r(x = q · y + r ∧ r \< y ∧ φ\[q, r\]) ↔ y 6= 0 ∧ φ\[x÷ y, x mod y\] (1) 

P̀A ∀q∀r(x = q · y + r ∧ r \< y → φ\[q, r\]) ↔ (y 6= 0 → φ\[x÷ y, x mod y\]). (2) 

9\.0.16 Theorem. We have 

P̀A ∃y∃z(x = y, z ∧ φ\[y, z\]) ↔ x 6= 0 ∧ φ\[H(x), T (x)\] (1) 

P̀A ∀y∀z(x = y, z → φ\[y, z\]) ↔ (x 6= 0 → φ\[H(x), T (x)\]) . (2) 

9\.0.17. In the sequel we will need the following additional properties of the basic functions and predicates of PA: 

P̀A x \> 0 → x · y ≤ x · z ↔ y ≤ z (1) 

P̀A r1 \< y ∧ r2 \< y → q1 · y + r1 = q2 · y + r2 ↔ q1 = q2 ∧ r1 = r2 (2) 

P̀A r1 \< y ∧ r2 \< y → q1 · y + r1 ≤ q2 · y + r2 ↔ q1 \< q2 ∨ q1 = q2 ∧ r1 ≤ r2 

(3) 

P̀A r1 \< y ∧ r2 \< y → q1 · y + r1 \< q2 · y + r2 ↔ q1 \< q2 ∨ q1 = q2 ∧ r1 \< r2 

(4) 

P̀A x \> 0 → x · y ÷ (x · z) = y ÷ z (5) 

P̀A x \| y → (y + z)÷ x = y ÷ x + z ÷ x (6) 

P̀A x \| y ∧ x \| z → x \| y + z (7) 

P̀A x \| y → x \| y · z (8) 

260

Part II 

Computer Programming 

261

10\. Clausal Language 

10\.1 Generalized Terms 

10\.1.1 Introduction. Generalized terms extend the language of (an exten- sion of) PA with new constructs which will be used purely in the meta-theory to describe the introduction of functions and predicates into PA by clausal definitions. Generalized terms will also be used in the description of compu- tation of such functions and predicates. 

Characteristic Terms 

10\.1.2 Characteristic terms of formulas. For a formula φ we call a term ρ such that 

P̀A (φ ↔ ρ = 1) ∧ (¬φ ↔ ρ = 0) 

the characteristic term of φ. 

10\.1.3 Characteristic functions. Characteristic function of an n-ary pred- icate P (\~x) is the n-ary predicate P∗(\~x) such that: 

P∗(\~x) = 

{ 1 if P (\~x) 0 otherwise. 

The characteristic function P∗(\~x) of the predicate P (\~x) can be introduced into PA by the following contextual definition: 

P̀Ax P∗(\~x) = y ↔ P (\~x) ∧ y = 1 ∨ ¬P (\~x) ∧ y = 0. (1) 

As a special case is the characterstic function x1 =∗ x2 of the binary equality predicate x1 = x2 which can be introduced into PA by: 

P̀Ax (x1 =∗ x2) = y ↔ x1 = x2 ∧ y = 1 ∨ x1 6= x2 ∧ y = 0. (2) 

The boolean functions are introduced into PA by the following explicit defi- nitions:

P̀Ax ¬∗x = D(x, 0, 1) (3) 

P̀Ax x∧∗ y = D(x, D(y, 1, 0), 0) (4) 

P̀Ax x∨∗ y = ¬∗(¬∗x∧∗ ¬∗y) (5) 

P̀Ax x→∗ y = ¬∗x∨∗ y (6) 

P̀Ax x↔∗ y = (x→∗ y)∧∗(y→∗ x). (7) 

For an existential formula ∃y φ\[\~x, y\] with all its free variables \~x indicated its witnessing function w∃yφ(\~x) is introduced into PA by minimalization: 

P̀Ax w∃yφ(\~x) = µy\[φ\[\~x, y\] ∨ ¬∃y φ\[\~x, y\] ∧ y = 0\]. (8) 

For a universal formula ∀y φ\[\~x, y\] with all its free variables \~x indicated its counterexample function w∃yφ(\~x) is introduced into PA by minimalization: 

P̀Ax c∀yφ(\~x) = µy\[¬φ\[\~x, y\] ∨ ∀y φ\[\~x, y\] ∧ y = 0\]. (9) 

10\.1.4 Assignment of characteristic terms. The assignment φ∗ of a characteristic term to a formula is defined inductively on the construction of the formula as follows: 

\>∗ ≡ 1 (1) ⊥∗ ≡ 0 (2) 

(P (\~τ))∗ ≡ P∗(\~τ) (3) (τ1 = τ2)∗ ≡ (τ1 =∗ τ2) (4) 

(¬φ)∗ ≡ (¬∗φ∗) (5) (φ1 ∧ φ2)∗ ≡ (φ1∗ ∧∗ φ2∗) (6) (φ1 ∨ φ2)∗ ≡ (φ1∗ ∨∗ φ2∗) (7) 

(φ1 → φ2)∗ ≡ (φ1∗→∗ φ2∗) (8) (φ1 ↔ φ2)∗ ≡ (φ1∗↔∗ φ2∗) (9) (∃y φ\[\~x, y\])∗ ≡ φ∗\[\~x,w∃yφ(\~x)\] (10) (∀y φ\[\~x, y\])∗ ≡ φ∗\[\~x, c∀yφ(\~x)\]. (11) 

10\.1.5 Theorem. We have 

P̀A (φ ↔ φ∗ = 1) ∧ (¬φ ↔ φ∗ = 0). (1) 

Proof. Property (1) is proved by induction on the construction of φ. ut 

Patterns 

10\.1.6 Guarded patterns. guard Γ \[\~x,\~a\], pattern φ\[\~x; \~y\] with input vari- ables \~x and output variables \~y, pattern’s uniqueness condition 

264

T \`Γ \[\~x,\~a\] → φ\[\~x; \~y\] ∧ φ\[\~x;\~z\] → ∧ 

yi = zi. (1) 

recogniser ρ\[\~x\] 

T \`Γ \[\~x,\~a\] → ρ\[\~x\] = 0 ∨ ρ\[\~x\] = 1 (2) T \`Γ \[\~x,\~a\] → ∃\~y φ\[\~x; \~y\] ↔ ρ\[\~x\] = 1. (3) 

destructors \~δ\[\~x\] 

T \`Γ \[\~x,\~a\] → ∃\~y φ\[\~x; \~y\] ↔ φ\[\~x;\~δ\[\~x\]\]. (4) 

We have 

T \`Γ \[\~x,\~a\] → ∃\~y(φ\[\~x; \~y\] ∧ ψ\[\~y\]) ↔ ρ\[\~x\] = 1 ∧ ψ\[\~δ\] (5) 

T \`Γ \[\~x,\~a\] → ∀\~y(φ\[\~x; \~y\] → ψ\[\~y\]) ↔ ρ\[\~x\] = 1 → ψ\[\~δ\]. (6) 

Generalized Terms 

10\.1.7 Generalized terms. For a given tuple of variables \~x and a guard Γ \[\~x,\~a\] we define the set of generalized terms in \~x guarded by Γ \[\~x,\~a\] as the smallest set of expressions satisfying the following: 

– The variables \~x are generalized terms in \~x guarded by Γ \[\~x,\~a\]. – If f is a n-ary function symbol of T and \~α is an n-tuple of generalized 

terms in \~x guarded by Γ \[\~x,\~a\] then so is the expression f(\~α). – The expression of the form (m ≥ 1): 

D\~δ1,...,\~δm ρ1,...,ρm 

(φ1\[\~x; \~y1\], α1\[\~x, \~y1\], . . . , φm\[\~x; \~ym\], αm\[\~x, \~ym\]) (1) 

is a generalized term in \~x guarded by Γ \[\~x,\~a\] if for every i = 1, . . . ,m: – φi\[\~x; \~yi\] is a pattern guarded by Γ \[\~x,\~a\] with the recogniser ρi and the 

destructors \~δi, – αi\[\~x, \~yi\] is a generalized term in \~x, \~yi guarded by Γ \[\~x,\~a\] ∧ φi\[\~x; \~yi\]. Moreover, the patterns satisfies the following disjointness and completeness conditions: 

T \`Γ \[\~x,\~a\] → m∧ 

i,j=1 i 6=j 

¬(∃\~yi φi\[\~x; \~yi\] ∧ ∃\~yj φj \[\~x; \~yj \]) (2) 

T \`Γ \[\~x,\~a\] → m∨ 

i=1 

∃\~yi φi\[\~x; \~yi\]. (3) 

Generalized terms of form f(\~α) are called applications. Generalized terms of a form (1) are called case discrimination terms. 

265

As a simple consequence of the conditions (2),(3) and the properties of pattern’s recognisers we get 

T \`Γ \[\~x,\~a\] → m∧ 

i,j=1 i 6=j 

¬(ρi = 1 ∧ ρj = 1) (4) 

T \`Γ \[\~x,\~a\] → m∨ 

i=1 

ρi = 1. (5) 

10\.1.8 Translation of generalized terms. It would not be too difficult to assign denotations in the standard model of PA to the generalized terms but, since they will play role only in the meta-theory, we will not do it. We will instead translate the generalized terms to the terms of PA by defining a meta-theoretic function α? yielding a term of PA whose interpretation can be understood as the intended interpretation of α. The translation function is defined by induction on the construction of generalized terms as follows: 

x? ≡ x (1) f(α1, . . . , αn)? ≡ f(α? 

1, . . . , α ? n) (2) 

D\~δ1,...,\~δm ρ1,...,ρm 

(φ1, α1\[\~y1\], . . . , φm, αm\[\~ym\]) ? ≡ 

≡ (m−1)-times︷ ︸︸ ︷ 

D(ρ1, α ? 1\[\~δ1\], . . . D(ρm−1, α 

? m−1\[\~δm−1\], α? 

m\[\~δm\]) . . . ). 

(3) 

Generalized terms are never used in the formulas of theorems and proofs of PA except in the translated form α? which stands for a term of PA. 

10\.1.9 Graphs of generalized terms. Graphs of generalized terms are defined by induction on the construction of generalized terms as follows: 

x ³ v ≡ x = v (1) 

f(α1, . . . , αn) ³ v ≡ ∃v1 · · · ∃vn( n∧ 

i=1 

αi ³ vi ∧ f(v1, . . . , vn) = v) (2) 

D\~δ1,...,\~δm ρ1,...,ρm 

(φ1, α1\[\~y1\], . . . , φm, αm\[\~ym\]) ³ v ≡ m∨ 

i=1 

∃\~yi 

( φi ∧ αi\[\~yi\] ³ v 

) . (3) 

We have 

T \` τ ³ v ↔ τ = v (4) 

T \` n∧ 

i=1 

∀v(αi ³ v ↔ βi ³ v) → 

f(α1, . . . , αn) ³ v ↔ f(β1, . . . , βn) ³ v. 

(5) 

In the sequel we will not explicitly indicate the uses of these two properties. 

266

10\.1.10 Theorem. For every generalized term α guarded by Γ we have 

T \` Γ → ∀v(α ³ v ↔ α? = v). (1) 

Proof. Property (1) is proved induction on the construction of the generalized term α. So assume Γ , take any v, and continue by case analysis on α. If α is a variable then (1) holds trivially. If α ≡ f(α1, . . . , αn) then the generalized terms αi are guarded by Γ and we have 

f(α1, . . . , αn) ³ v IH⇔ f(α? 

1, . . . , α ? n) = v 

def⇔ f(α1, . . . , αn)? = v. 

If α ≡ D\~δ1,...,\~δm ρ1,...,ρm 

(φ1, α1\[\~y1\], . . . , φm, αm\[\~ym\]) then the generalized terms αi\[\~yi\] are guarded by Γ ∧ φi and we have 

D\~δ1,...,\~δm ρ1,...,ρm 

(φ1, α1\[\~y1\], . . . , φm, αm\[\~ym\]) ³ v def⇔ 

m∨ 

i=1 

∃\~yi 

( φi ∧ αi\[\~yi\] ³ v 

) IH⇔ m∨ 

i=1 

∃\~yi 

( φi ∧ α? 

i \[\~yi\] = v ) 10.1.6(5)⇔ 

m∨ 

i=1 

( ρi = \>∗ ∧ α? 

i \[\~δi\] = v ) (∗)⇔ 

D(ρ1, α ? 1\[\~δ1\], . . . D(ρm−1, α 

? m−1\[\~δm−1\], α? 

m\[\~δm\]) . . . ) = v def⇔ 

D\~δ1,...,\~δm ρ1,...,ρm 

(φ1, α1\[\~y1\], . . . , φm, αm\[\~ym\]) ? 

= v. 

The step marked by (∗) follows from 10.1.6(2) and 10.1.7(4)(5). ut 

Regular Course of Values Recursion with Measure 

10\.1.11 Fixing notation. Let T be a proper extension of PA. Let us denote by T \[f \] the theory obtained from T by adding a new n-ary function symbol f . Let further α\[f ; \~x\] be a generalized term of T \[f \] guarded by Γ \[\~x,\~a\] and µ\[\~x,\~a\] be a term of T . 

wi ≡ w∃ai···∃akΓ \[\~x,w1\[\~x\],...,wi−1\[\~x\],ai,...,ak\] 

We have 

T \[f \] \` ∃\~aΓ \[\~x,\~a\] ↔ Γ \[\~x, \~w\[\~x\]\]. (1) 

10\.1.12 Governing conditions. To every (generalized) term α and an oc- currence in α of a subterm β we define inductively on ‖α‖−‖β‖ the governing condition Γα 

β of β in α. Here we denote by ‖α‖ the size, i.e. the number of operations, of the term α. If β ≡ α or β is a term of PA then Γα 

β ≡ \>. If 

β ≡ D\~δ1,...,\~δm ρ1,...,ρm 

(φ1, α1, . . . , φm, αm) then 

Γα ρi ≡ Γα 

β Γα βi ≡ Γα 

β ∧ φi. (1) 

267

10\.1.13 Conditions of regularity. We assign to each recursive occurrence f(\~β) in α with governing condition Γφ 

f(\~β) \[f ; \~x,\~a\] the following condition of 

regularity : 

Γφ 

f(\~β) \[f ; \~x,\~a\] ∧ 

n∧ 

i=1 

βi ³ vi → µ\[\~v,\~a\] \< µ\[\~x,\~a\]. (1) 

We denote by RegΓ,µ α \[f ; \~x,\~a\] the conjunction of all conditions of regularity. 

10\.1.14 Lemma. Let S be the extension of T by the following course of values recursion with measure: 

f(\~x) = D(Γ∗\[\~x, \~w\[\~x\]\], α?\[\[f \]µ\[\~x,\~w\[\~x\]\] \~x ; \~x\], 0). (1) 

If S \` RegΓ,µ α \[f ; \~x,\~a\] then 

S \`∃\~aΓ \[\~x,\~a\] → f(\~x) = α?\[f ; \~x\] (2) S \`¬∃\~aΓ \[\~x,\~a\] → f(\~x) = 0. (3) 

Proof. We prove an auxiliary property by induction on the structure of β: 

for any occurrence of a subterm β\[f ; \~x\] of α\[f ; \~x\] governed in α by Γα 

β \[f ; \~x,\~a\] we have 

S \` Γα β \[f ; \~x,\~a\] → ∀v( 

β\[\[f \]µ\~x; \~x\] ³ v ↔ β\[f ; \~x\] ³ v ) . (4) 

So assume Γα β \[f ; \~x,\~a\], take any v, and continue by the case analysis of β. If 

β is a variable then the property holds trivially. If β ≡ g(\~γ) then the terms \~γ are governed in α by Γα 

β and we have 

g(\~γ\[\[f \]µ\~x; \~x\]) ³ v IH⇔ g(\~γ\[f ; \~x\]) ³ v. 

If β ≡ f(\~γ) then the terms \~γ are governed in α by Γα β . By regularity 

µ\[\~γ\[f ; \~x\],\~a\] \< µ\[\~x,\~a\] (5) 

and thus we have 

D(µ\[\~γ\[\[f \]µ\~x; \~x\],\~a\] \<∗ µ\[\~x,\~a\], f(\~γ\[\[f \]µ\~x; \~x\]), 0) ³ v IH⇔ 

D(µ\[\~γ\[f ; \~x\],\~a\] \<∗ µ\[\~x,\~a\], f(\~γ\[f ; \~x\]), 0) ³ v (5)⇔ 

D(1, f(\~γ\[f ; \~x\]), 0) ³ v ⇔ f(\~γ\[f ; \~x\]) ³ v. 

If β ≡ D\~δ1,...,\~δm ρ1,...,ρm 

(φ1, γ1, . . . , φm, γm) then the terms ρi are governed in α by Γα 

β and the terms γi by Γα β ∧ φi. We have 

268

m∧ 

i=1 

ρi\[\[f \]µ\~x; \~x\] = ρi\[f ; \~x\] (6) 

m∧ 

i=1 

∀\~yi 

( φi\[f ; \~x; \~yi\] → ∀v(γi\[\[f \]µ\~x; \~x; \~yi\] ³ v ↔ γi\[f ; \~x; \~yi\] ³ v) 

) (7) 

by IH and thus by the properties of pattern recognisers and (6): 

m∧ 

i=1 

∀\~yi 

( φi\[\[f \]µ\~x; \~x; \~yi\] ↔ φi\[f ; \~x; \~yi\] 

) . (8) 

We have 

D \~\~δ\[\[f \]µ 

\~x ;\~x\] 

\~ρ\[\[f \]µ \~x ;\~x\] 

( . . . , φi\[\[f \]µ\~x; \~x; \~yi\], γi\[\[f \]µ\~x; \~x, \~yi\], . . . 

) ³ v def⇔ 

m∨ 

i=1 

∃\~yi 

( φi\[\[f \]µ\~x; \~x; \~yi\] ∧ γi\[\[f \]µ\~x; \~x, \~yi\] ³ v 

) (8)⇔ m∨ 

i=1 

∃\~yi 

( φi\[f ; \~x; \~yi\] ∧ γi\[\[f \]µ\~x; \~x, \~yi\] ³ v 

) (7)⇔ m∨ 

i=1 

∃\~yi 

( φi\[f ; \~x; \~yi\] ∧ γi\[f ; \~x, \~yi\] ³ v 

) def⇔ 

D \~\~δ\[f ;\~x\] \~ρ\[f ;\~x\] 

( . . . , φi\[f ; \~x; \~yi\], γi\[f ; \~x, \~yi\], . . . 

) ³ v. 

With the auxiliary property proved, we prove (2) as follows. Assume ∃\~aΓ \[\~x,\~a\]. Then Γ \[\~x, \~w\[\~x\]\] by 10.1.11(1). We take in (4) the term α as its subterm and substitute \~w\[\~x\] for \~a. We have 

f(\~x) (1) = D(Γ∗\[\~x, \~w\[\~x\]\], α?\[\[f \]µ\[\~x,\~w\[\~x\]\] 

\~x ; \~x\], 0) 10.1.5(1) 

= D(1, α?\[\[f \]µ\[\~x,\~w\[\~x\]\] \~x ; \~x\], 0) = 

= α?\[\[f \]µ\[\~x,\~w\[\~x\]\] \~x ; \~x\] 

(4),10.1.10(1) = α?\[f ; \~x\]. 

Property (3) follows from 10.1.11(1) by 10.1.5(1) ut 

10\.1.15 Extensions by regular course of values recursion with mea- sure. Suppose that in the extension S1 of T by the following course of values recursion with measure: 

f(\~x) = D(Γ∗\[\~x, \~w\[\~x\]\], α?\[\[f \]µ\[\~x,\~w\[\~x\]\] \~x ; \~x\], 0) 

we have 

S1 \` RegΓ,µ α \[f ; \~x,\~a\]. 

The extension of the theory T into S with the language LT + f with the axioms universal closures of 

269

∃\~aΓ \[\~x,\~a\] → f(\~x) = α?\[f ; \~x\] (1) ¬∃\~aΓ \[\~x,\~a\] → f(\~x) = 0 (2) 

RegΓ,µ α \[f ; \~x,\~a\] (3) 

is called extension by regular course of values recursion with measure. 

10\.2 Clausal Definitions 

10\.3 The Strength of Clausal Definitions 

270

11\. Numeric Programs 

11\.1 Explicit Definitions 

11\.1.1 Explicit clausal definitions. Recall that explicit clausal defini- tions are obtained by unfolding of initial clauses of a form (see Par. ??) 

f(\~x) = α\[\~x\], 

where the generalised term α does not contain recursive applications of f . By Thm. ?? explicit clausal definitions are definitional extensions of PA. Recall also that primitive recursive functions are closed under explicit clausal definitions. 

11\.1.2 Minimum. The minumum function min(x, y) with its basic prop- erties: 

P̀A min(x, y) ≤ x (1) 

P̀A min(x, y) ≤ y (2) 

P̀A min(x, y) = x ∨min(x, y) = y (3) 

can be introduced into PA by the following explicit clausal definition as a primitive recursive function: 

min(x, y) = x ← x ≤ y min(x, y) = y ← x \> y. 

The definition uses the dichotomic discrimination on x ≤ y and x \> y. Prop- erties (1)–(3) are proved by the corresponding case analysis. For instance, (1) follows from: 

x ≤ y ⇒ min(x, y) def= x ≤ x 

x \> y ⇒ min(x, y) def= y ≤ x. 

11\.1.3 Signum function. The signum function sgn(x) with its basic prop- erty: 

P̀A x = 0 ∧ sgn(x) = 0 ∨ x \> 0 ∧ sgn(x) = 1 (1)

can be introduced into PA by the following explicit clausal definition as a primitive recursive function: 

sgn(0) = 0 sgn(x + 1) = 1. 

The definition uses monadic discrimination. Property (1) is proved by the corresponding case analysis. 

11\.2 Primitive Recursion 

11\.2.1 Primitive recursive clausal definitions. Primitive recursive clau- sal definition S of a function f(\~y, x, \~z) is a regular clausal definition for f which can be obtained by unfolding the clauses of a form 

f(\~y, x, \~z) = α1\[\~y, \~z\] ← x = 0 (1) f(\~y, x, \~z) = α2\[λ̇ \~w.f(\~y, x1, \~z); \~y, x1, \~z\] ← x = x1 + 1, (2) 

where the generalised term α1 does not apply f and each recursive application of f in the generalized term α2 has the form f(\~y, x1, \~z). 

That the clausal definition S is a regular clausal definition can be seen from the following. Consider the (initial) clause of the form 

f(\~y, x, \~z) = Num1,1 x1,u(x,Const0(x, α1\[\~y, \~z\], 0), α2\[λ̇ \~w.f(\~y, x1, \~z); \~y, x1, \~z\]). 

Since P̀A x = x1 + 1 → x1 \< x the clause is regular in the argument x. One unfolding step with numeric discrimination yields 

f(\~y, x, \~z) = Const0(x, α1\[\~y, \~z\], 0) ← x \< 1 f(\~y, x, \~z) = α2\[λ̇ \~w.f(\~y, x1, \~z); \~y, x1, \~z\] ← x = 1 ·x1 + u ∧ 1 ≤ u ∧ u \< 1 + 1. 

By simplifying the last two clauses (see Par. ??) we obtain (1) and (2). The clauses (1) and (2) are called the initial clauses of the primitive 

recursive clausal definition S. We will often say that the function f(\~y, x, \~z) is defined by primitive recursive definition on x, or even shorter by primitive recursion on x. The variables \~y and \~z are called parameters; they may be empty. We have 

P̀A f(\~y, 0, \~z) = α? 1\[\~y, \~z\] (3) 

P̀A f(\~y, x + 1, \~z) = α? 2\[λ̇ \~w.f(\~y, x, \~z); \~y, x, \~z\]. (4) 

11\.2.2 Exponentiation. The exponentiation function xy is defined by primitive recursion on y as a primitive recursive function: 

x0 = 1 xy+1 = x ·xy. 

272

We list here some properties of the exponentiation function: 

P̀A xy = 0 ↔ x = 0 ∧ y \> 0 (1) 

P̀A xy = 1 ↔ x = 1 ∨ y = 0 (2) 

P̀A xy+z = xy ·xz (3) 

P̀A x \> 0 ∧ y ≥ z → xy .− z = xy ÷ xz (4) 

P̀A x \> 1 ∧ xy = xz → y = z (5) 

P̀A x \> 1 → xy ≤ xz ↔ y ≤ z (6) 

P̀A x \> 1 → xy \< xz ↔ y \< z. (7) 

The properties are proved as follows. Property (1) is proved by induction on y. In the base case (1) trivially holds since by definition x0 = 1 6= 0. In the inductive case we have 

xy+1 = 0 def⇔ x ·xy = 0 ⇔ x = 0 ∨ xy = 0 IH⇔ x = 0 ∨ (x = 0 ∧ y \> 0) ⇔ ⇔ x = 0 ⇔ x = 0 ∨ y + 1 \> 0. 

Property (2) is similar. Property (3) is proved by induction on y similarly as the property 8.1.12(6). In the proof of the property (4) assume x \> 0 and prove 

∀z(y ≥ z → xy .− z = xy ÷ xz) (8) 

by induction on y. In the base case when y = 0 take and z such that 0 ≥ z, i.e. z = 0, and we have 

x0 .− 0 = x0 def= 1 = 1÷ 1 def= x0 ÷ x0. 

In the inductive case when y = y1 +1 for some y1 take any z such that y ≥ z and consider two cases. If z = 0 then we have 

xy .− 0 = xy = xy ÷ 1 def= xy ÷ x0. 

If z = z1 + 1 for some z1 then y1 ≥ z1 and we have 

xy1+1 .−(z1+1) = xy1 

.− z1 IH= xy1 ÷ xz1 9.0.17(5) 

= 

= x ·xy1 ÷ (x ·xz1) def= xy1+1 ÷ xz1+1. 

The remaining properties are proved similarly. 

11\.2.3 Summation. The summation function ∑n 

i=0 i computing the sum 

n∑ 

i=0 

i = 0 + 1 + 2 + · · ·+ n 

is a primitive recursive function by primitive recursive definition: 

273

∑0 i=0 i = 0∑n+1 i=0 i = 

∑n i=0 i + n + 1. 

Its basic property 

P̀A 

n∑ 

i=0 

i = n ·(n + 1)÷ 2. (1) 

is proved by induction on n. In the base case we have 

0∑ 

i=0 

i def= 0 = 0 ·(0 + 1)÷ 2. 

In the inductive case we have 

n+1∑ 

i=0 

i def= 

n∑ 

i=0 

i + n + 1 IH= n ·(n + 1)÷ 2 + n + 1 = 

= ( n ·(n + 1) + 2 ·(n + 1) 

)÷ 2 = (n + 1) ·(n + 1 + 1)÷ 2. 

11\.2.4 Factorial. The function n! computing the factorial of n 

n! = 1 · 2 · 3 · · · · ·n 

is defined by primitive recursion as a primitive recursive function: 

0! = 1 (n + 1)! = (n + 1) ·n!. 

The function satisfies 

P̀A 0 \< i ≤ n → i \| n!. (1) 

Property (1) is proved by induction on n. In the base case there is nothing to prove. In the inductive case assume 0 \< i ≤ n + 1 and consider two cases. If i ≤ n then by IH 

i \| n! 9.0.17(8)⇒ i \| (n + 1) ·n! def⇒ i \| (n + 1)!. 

Otherwise, if i = n + 1, we obtain by 7.5.1(2) 

n + 1 \| n + 1 9.0.17(8)⇒ n + 1 \| (n + 1) ·n! def⇒ n + 1 \| (n + 1)!. 

11\.2.5 Square root. The square root function b√xc yields the greatest number whose square does not exceed x: 

P̀A b √ 

xc2 ≤ x \< (b√xc+ 1)2. (1) 

274

We can derive primitive recursive definition for b√xc by assuming (as IH) that (1) holds and then considering the relation between x+1 and (b√xc+1)2. There are two cases. If 

b√xc2 ≤ x \< x + 1 \< (b√xc+ 1)2 

holds then it clearly suffices to set: b√x + 1c := b√xc. Otherwise we must have 

b√xc2 ≤ x \< (b√xc+ 1)2 = x + 1 \< (b√xc+ 2)2 

and it suffices to set b√x + 1c := b√xc + 1. This idea is expressed by the following primitive recursive definition: 

b√0c = 0 b√x + 1c = b√xc ← x + 1 \< (b√xc+ 1)2 

b√x + 1c = b√xc+ 1 ← x + 1 = (b√xc+ 1)2. 

11\.2.6 Square root with assignments. We will investigate more pro- grams (algorithms) for the square root function b√xc because the one given in Par. 11.2.5, although quite pleasing mathematically, is unfeasible in prac- tice for many reasons. One of them is the twofold computation of b√xc for every value x: once in the test and once in the result. This causes an expo- nential blowup of 2x recursions in order to compute b√xc. The blowup is prevented by the assignment in the following clausal definition of the recur- sive value b√xc to an auxiliary variable s: 

b√0c = 0 b√x + 1c = s ← b√xc = s ∧ x + 1 \< (s + 1)2 

b√x + 1c = s + 1 ← b√xc = s ∧ x + 1 = (s + 1)2. 

11\.2.7 Primitive recursive clausal definitions with substitution in parameters. Initial clauses of primitive recursive clausal definitions with substitution in parameters are of a form 

f(\~y, x, \~z) = α1\[\~y, \~z\] ← x = 0 f(\~y, x, \~z) = α2\[λ̇\~yw\~z.f(\~y, x1, \~z); \~y, x1, \~z\] ← x = x1 + 1. 

Note that recursive applications of f in the generalized term α2 are of the form f(\~τ , x1, \~ρ), where the terms \~τ and \~ρ may be different from the variables \~y and \~z, respectively. If for instance τi 6≡ yi then we say that the definition uses the substitution in the parameter yi. 

11\.2.8 Decreasing factorial. The function (n)\[k\] computing the product 

(n)\[k\] = 

k-times︷ ︸︸ ︷ n ·(n .− 1) · · · · ·(n .−(k .− 1)) 

275

is defined by primitive recursion on k with substitution in parameter as a primitive recursive function: 

(n)\[0\] = 1 (n)\[k+1\] = n ·(n .− 1)\[k\]. 

We list here some its properties: 

P̀A (n)\[k\] = 0 ↔ n \< k (1) 

P̀A k ≤ n → (n)\[k\] · (n .− k)! = n! (2) 

P̀A (n)\[n\] = n! (3) 

P̀A (n)\[k+1\] = (n)\[k\] ·(n .− k) (4) 

P̀A (n + 1)\[k\] = k ·(n)\[k .− 1\] + (n)\[k\] (5) 

P̀A k! \| (n)\[k\]. (6) 

The properties are proved as follows. Property (1) is proved by induction on k with induction formula ∀n (1), ie with 

∀n((n)\[k\] = 0 ↔ n \< k). 

The base case trivially holds since by definition (n)\[0\] = 1 6= 0. In the induc- tive case take any n and we have 

(n)\[k+1\] = 0 def⇔ n ·(n .− 1)\[k\] = 0 ⇔ n = 0 ∨ (n .− 1)\[k\] = 0 IH⇔ ⇔ n = 0 ∨ n .− 1 \< k ⇔ n \< k + 1. 

Property (2) is proved by induction on k with the induction formula ∀n (2). The base case trivially holds since by definition (n)\[0\] · (n .− 0)! = 1 ·n! = n!. In the inductive case take any n ≥ k + 1. Then n .− 1 ≥ k and we have 

(n)\[k+1\] · ( n .−(k + 1) 

) ! def= n ·(n .− 1)\[k\] · (n .− 1 .− k)! IH= n · (n .− 1)! def= n!. 

Property (3) follows from (2) by substituting n for k. Property (4) is proved by induction on k with induction formula ∀n (4). 

In the base case take any n and we have 

(n)\[1\] def= n ·(n .− 1)\[0\] 

def= n def= (n)\[0\] ·n = (n)\[0\] ·(n .− 0). 

In the inductive case take any n and we have 

(n)\[k+2\] def= n ·(n .− 1)\[k+1\] 

IH= n ·(n .− 1)\[k\] ·(n .− 1 .− k) def= (n)\[k+1\] ·(n .−(k + 1)). 

In the proof of the property (5) we consider two cases. If k \> n + 1 then by (1): (n + 1)\[k\] = (n)\[k .− 1\] = (n)\[k\] = 0 and (5) holds trivially. If k ≤ n + 1 then we consider two subcases. If k = 0 then (5) follows from the definition. If k 6= 0 then we have 

276

(n + 1)\[k\] def= (n + 1) ·(n)\[k .− 1\] = k ·(n)\[k .− 1\] + (n)\[k .− 1\] ·(n .−(k .− 1)) 

(4) = 

= k ·(n)\[k .− 1\] + (n)\[k\]. 

In order to show that (6) holds we first prove 

P̀A ∀k(k 6= 0 → k! \| (n)\[k\]) (7) 

by induction on n. In the base case take any k 6= 0 and we get k! \| 0 by 7.5.1(6) and thus k! \| (0)\[k\] by definition. In the inductive case take any k 6= 0 and we obtain by twice applications of IH: (k .− 1)! \| (n)\[k .− 1\] and k! \| (n)\[k\]. From 9.0.17(8) we get k! \| k ·(n)\[k .− 1\] and thus by 9.0.17(7) 

k! \| k ·(n)\[k .− 1\] + (n)\[k\] (5)⇒ k! \| (n + 1)\[k\]. 

Now we can prove (6). If k 6= 0 then we apply (7). Otherwise, when k = 0, we have 0! = 1 by definition and thus 0! \| (n)\[0\] by 7.5.1(5). 

11\.2.9 Binomial coefficients. The binomial coefficients ( n k 

) can be intro- 

duced into PA by the following explicit definition 

P̀Ax 

( n 

k 

) = (n)\[k\] ÷ k!. 

We have 

P̀A 

( n + 1 k + 1 

) = 

( n 

k 

) + 

( n 

k + 1 

) . (1) 

Property (1) is proved as follows ( 

n + 1 k + 1 

) def= (n)\[k+1\] ÷ (k + 1)! 

11\.2.8(5) = 

= ( (k + 1) ·(n)\[k\] + (n)\[k+1\] 

)÷ (k + 1)! 11.2.8(6);9.0.17(6) 

= 

= (k + 1) ·(n)\[k\] ÷ (k + 1)! + (n)\[k+1\] ÷ (k + 1)! def= 

= (k + 1) ·(n)\[k\] ÷ ( (k + 1) · k! 

) + (n)\[k+1\] ÷ (k + 1)! 

9\.0.17(5) = 

= (n)\[k\] ÷ k! + (n)\[k+1\] ÷ (k + 1)! def= ( 

n 

k 

) + 

( n 

k + 1 

) . 

11\.2.10 Fibonacci function. The function fib(n) yielding the n-th ele- ment of the sequence of Fibonacci is defined by course of values recursion as a primitive recursive function: 

fib(0) = 1 (1) fib(1) = 1 (2) fib(n + 2) = fib(n + 1) + fib(n). (3) 

277

We can, for instance, compute fib(4) = 3 as follows: 

fib(4) (3) = fib(3) + fib(2) 

2×(3) = fib(2) + fib(1) + fib(1) + fib(0) 

(3);2×(2);(1) = 

fib(1) + fib(0) + 1 + 1 + 0 (2);(1) 

= 1 + 0 + 2 = 3. 

The only problem is that the computation sequence is too long. In order to compute the number fib(n + 2) one needs to use the recurrence (3) exactly fib(n+2) times as can be proved by a simple induction proof. The Fibonacci function grows as fast as the exponential function and to compute the func- tion in this way is simply too wasteful. The following Pascal-like program computes fib(n) into the variable b: 

a := 1; b := 0; while n \> 0 do 

n := n− 1; c := a; a := a + b; b := c; 

The reader will note that the loop is executed only n times. This example is usually given as the ‘standard argument’ against declarative programming where the recursive version is clearly inferior to the imperative one. The argument is fallacious as one should define an auxiliary ternary function f(n, a, b) with two accumulators a and b by primitive recursion on n with substitution in parameters as a primitive recursive function: 

f(0, a, b) = b f(n + 1, a, b) = f(n, a + b, a). 

and then we could take the following property as an explicit definition of the Fibonacci function: 

P̀A fib(n) = f(n, 1, 1). (4) 

The number of recursions of f(n, a, b) is exactly the same as the number of iterations of the loop of the imperative program. 

It remains to show that (4) holds. First we prove 

P̀A ∀k f(n,fib(k + 1),fib(k)) = fib(n + k) (5) 

by induction on n. In the base case take any k and we have 

f(0, fib(k + 1),fib(k)) def= fib(k) = fib(0 + k). 

In the inductive case take any k and we have 

f(n + 1, fib(k + 1), fib(k)) def= f(n,fib(k + 1) + fib(k), fib(k + 1)) def= 

= f(n, fib(k + 2), fib(k + 1)) IH= fib(n + k + 1) = fib(n + 1 + k). 

We are now ready to prove (4): 

fib(n) (5) = f(n,fib(1), fib(0)) def= f(n, 1, 1). 

278

11\.3 Course of Values Recursion 

11\.3.1 Course of values recursive clausal definitions. Initial clauses of course of values recursive clausal definitions are clauses of a form 

f(\~y, x, \~z) = α\[λ̇\~yx\~z.f(\~y, x, \~z); \~y, x, \~z\] 

regular in measure x. 

11\.3.2 Integer division. Consider the following course of values recursive definition on x of the integer division x÷ y: 

x÷ y = 0 ← y \> 0 ∧ x \< y x÷ y = (x .− y)÷ y + 1 ← y \> 0 ∧ x ≥ y. 

We claim that 

P̀A y \> 0 → ∃r(x = x÷ y · y + r ∧ r \< y). (1) 

The property is proved by complete induction on x. Assume y \> 0, take any x and consider two cases. If x \< y then we satisfy (1) with substitution r := x since we have 

x÷ y · y + x def= 0 · y + x = x. 

If x ≥ y then x .− y \< x and thus by IH applied to x .− y there is a number r such that 

x .− y = (x .− y)÷ y · y + r ∧ r \< y. (2) 

We satisfy (1) with substitution r := r since we have 

x÷ y · y + r def= ((x .− y)÷ y + 1) · y + r = (x .− y)÷ y · y + y + r 

(2) = 

= x .− y + y = x. 

11\.3.3 Greatest common divisor. Consider the following clausal defini- tion of the greatest common divisor: 

gcd(x, 0) = x gcd(x, y) = gcd(y, x mod y) ← y \> 0. 

Since P̀A y \> 0 → x mod y \< y the definition of gcd(x, y) is by course of values recursion on y with substitution in parameter x. The idea of the algorithm is based on the observation 

P̀A y \> 0 → z \| x ∧ z \| y ↔ z \| y ∧ z \| x mod y 

which follows from the following facts 

279

P̀A y \> 0 → x = x÷ y · y + x mod y 

P̀A y \> 0 ∧ z \| x ∧ z \| y → z \| x mod y 

P̀A y \> 0 ∧ z \| y ∧ z \| x mod y → z \| x. 

We claim that 

P̀A x \> 0 ∨ y \> 0 → gcd(x, y) \| x ∧ gcd(x, y) \| y (1) 

P̀A (x \> 0 ∨ y \> 0) ∧ z \| x ∧ z \| y → z ≤ gcd(x, y). (2) 

Properties (1) and (2) are proved by complete induction on y with induction formulas ∀x (1) and ∀x (2), respectively. 

11\.3.4 Course of values recursive definitions with measure. Initial clauses of course of values recursive clausal definitions with measure are reg- ular clauses of a form 

f(\~x) = α\[λ̇\~x.f(\~x); \~x\]. 

11\.3.5 Greatest common divisor. Consider the following course of val- ues recursive definition with measure x + y of the greatest common divisor gcd(x, y): 

gcd(x, y) = gcd(x, y .−x) ← x \> 0 ∧ y \> 0 ∧ x \< y gcd(x, y) = x ← x \> 0 ∧ y \> 0 ∧ x = y gcd(x, y) = gcd(x .− y, y) ← x \> 0 ∧ y \> 0 ∧ x \> y. 

We claim that 

P̀A x \> 0 ∧ y \> 0 → gcd(x, y) \| x ∧ gcd(x, y) \| y (1) 

P̀A x \> 0 ∧ y \> 0 ∧ z \| x ∧ z \| y → z ≤ gcd(x, y). (2) 

Property (1) is proved by measure induction with measure x + y. 

11\.3.6 Bottom up program for b√xc. The program for b√xc given in Par. 11.2.6 can be improved in two respects. The first one is the shortening of the computation which goes from x, to x−1, . . . , until it reaches 0 and then it does the comparisons and the incrementation by one on the way back. As we already have commented above, the program is mathematically pleasing but every programmer will come up with a ‘bottom up’ program which searches starting with 0 for the smallest number s such that x \< (s + 1)2. For this need an auxiliary function f(x, r) defined by course of values recursion with measure x .− r2: 

f(x, r) = r ← x \< (r + 1)2 

f(x, r) = f(x, r + 1) ← x ≥ (r + 1)2. 

We can now define the square root explicitly by 

P̀Ax b √ 

xc = f(x, 0). (1) 

Note that only b√xc tests are needed. 

280

11\.3.7 A faster program for b√xc with accumulators. The second improvement is the saving of the repeated multiplication in the test x + 1 \< (s+1)2 of the program for b√xc in Par. 11.2.6 by an additional accumulator argument s maintained at the value s = r2 during the computation of the following clausal definition of the ternary function f(x, r, s): 

f(x, r, s) = r ← s + 2 · r + 1 = s1 ∧ x \< s1 

f(x, r, s) = f(x, r + 1, s1) ← s + 2 · r + 1 = s1 ∧ x ≥ s1. 

Note that this is a course of values recursive definition with measure x .− s. We can now define the square root function explicitly 

P̀Ax b √ 

xc = f(x, 0, 0). (1) 

We claim that 

P̀A b √ 

xc2 ≤ x \< (b√xc+ 1)2. (2) 

We first prove the following property of the function f : 

P̀A r2 ≤ x → f(x, r, r2)2 ≤ x \< (f(x, r, r2) + 1)2 (3) 

by measure induction with measure x .− r. Assume r2 ≤ x, let s := r2 +2 · r+ 1 = (r + 1)2 and consider two cases. If x \< s then (3) holds since we have 

f(x, r, r2)2 def= r2 ≤ x \< s = (r + 1)2 def= (f(x, r, r2) + 1)2. 

If x ≥ s then x .−(r + 1) \< x .− r and thus by IH applied to x and r + 1 we obtain 

f(x, r + 1, (r + 1)2)2 ≤ x \< ( f(x, r + 1, (r + 1)2) + 1 

)2 . (4) 

From this we get (3) as follows 

f(x, r, r2)2 def= f(x, r + 1, (r + 1)2)2 (4) 

≤ x (4) \< 

\< ( f(x, r + 1, (r + 1)2) + 1 

)2 def= (f(x, r, r2) + 1)2. 

We are now in position to prove (2): 

b√xc2 (1) = f(x, 0, 0)2 

(3) 

≤ x (3) \< (f(x, 0, 0) + 1)2 

(1) = (b√xc+ 1)2. 

11\.3.8 Simulation of for-loops by recursion. Consider the following Pascal-like program computing 

∑n i=0 i into the variable a: 

a := 0; for j := 1 to n do 

a := a + j;. 

281

We can simulate the for-loop by the following course of values recursive def- inition with measure n + 1 .− j: 

f(n, j, a) = a ← j \> n f(n, j, a) = f(n, j + 1, a + j) ← j ≤ n. 

We claim that 

P̀A 

n∑ 

i=0 

i = f(n, 1, 0). (1) 

We first prove the following property of the function f : 

P̀A 0 \< j ≤ n + 1 → f(n, j, 

j .− 1∑ 

i=0 

i) = n∑ 

i=0 

i (2) 

by measure induction with measure n + 1 .− j. Assume 0 \< j ≤ n + 1 and consider two cases. If j = n + 1 then (2) follows by definition. If j ≤ n then n + 1 .−(j + 1) \< n + 1 .− j and we get (2) as follows 

f(n, j, 

j .− 1∑ 

i=0 

i) def= f(n, j + 1, 

j .− 1∑ 

i=0 

i + j) def= f(n, j + 1, 

j∑ 

i=0 

i) = 

= f(n, j + 1, 

j+1 .− 1∑ 

i=0 

i) IH= n∑ 

i=0 

i. 

We are now in position to prove (1): 

n∑ 

i=0 

i (2) = f(n, 1, 

1 .− 1∑ 

i=0 

i) = f(n, 1, 

0∑ 

i=0 

i) def= f(n, 1, 0). 

11\.4 Recursion on Notation 

Binary arithmetic 

11\.4.1 Binary representation of N. We introduce two binary successor functions by explicit definitions: 

P̀Ax x0 = 2 ·x (1) 

P̀Ax x1 = 2 ·x + 1. (2) 

Binary numerals are the least class of terms satisfying the following: 

– the constant 0 is a binary numeral, – if τ is a binary numeral distinct from 0 so is τ0, 

282

– if τ is a binary numeral so is τ1. 

We give here some examples of binary numerals: 

0 = 0 01 = 2 · 0 + 1 = 1 

010 = 2 ·(2 · 0 + 1) = 2 011 = 2 ·(2 · 0 + 1) + 1 = 3 

0100 = 2 ·(2 ·(2 · 0 + 1)) = 4 0101 = 2 ·(2 ·(2 · 0 + 1)) + 1 = 5. 

11\.4.2 Binary case analysis. We have the following principle of binary case analysis: 

P̀A x = 0 ∨ ∃y(y \> 0 ∧ x = y0) ∨ ∃y x = y1. (1) 

Property (1) follows directly from 

P̀A x = x÷ 2 · 2 + x mod 2 ∧ x mod 2 \< 2 

holding by 7.4.8(1). 

11\.4.3 Binary induction. Let T be a proper extension of PA containing the binary successors, φ\[x\] a formula of LT with the indicated variable x free and with possibly additional parameters. The formula of binary induction on x for φ\[x\] is the following one: 

φ\[0\] ∧ ∀x(x \> 0 ∧ φ\[x\] → φ\[x0\]) ∧ ∀x(φ\[x\] → φ\[x1\]) → φ\[x\]. 

11\.4.4 Theorem. Every proper extension T of PA containing the binary successors proves the schema of binary induction: 

T \` φ\[0\] ∧ ∀x(x \> 0 ∧ φ\[x\] → φ\[x0\]) ∧ ∀x(φ\[x\] → φ\[x1\]) → φ\[x\]. 

Proof. The principle of binary induction is reduced to mathematical induc- tion as follows. Assume 

φ\[0\] (1) ∀x(x \> 0 ∧ φ\[x\] → φ\[x0\]) (2) 

∀x(φ\[x\] → φ\[x1\]) (3) 

and prove ∀x(x \< n → φ\[x\]) (4) 

by induction on n. In the base case, when n = 0, there is nothing to prove. In the inductive case take any x such that x \< n + 1 and consider three cases. If x = 0 then φ\[0\] follows from the assumption (1). If x = y0 for some y \> 0 then, since y \< x ≤ n, we have φ\[y\] from IH: (4) and we get φ\[y0\] from (2). The case when x = y1 is proved similarly. This ends the proof of (4) and we obtain φ\[x\] by substituting x + 1 for n in (4). ut 

283

11\.4.5 Binary recursion. Initial clauses for clausal definitions with binary recursion are of a form 

f(\~y, x, \~z) = α1\[\~y, \~z\] ← x = 0 f(\~y, x, \~z) = α2\[λ̇\~yw\~z.f(\~y, x1, \~z); \~y, x1, \~z\] ← x = x10 ∧ x1 \> 0 f(\~y, x, \~z) = α2\[λ̇\~yw\~z.f(\~y, x1, \~z); \~y, x1, \~z\] ← x = x11. 

Note that the clauses are regular in the argument x. 

11\.4.6 Binary size. The binary size function \|x\|b yields the number of binary successors in the binary numeral denoting the number x. The function is defined by parameterless binary recursion as a primitive recursive function: 

\|0\|b = 0 \|x0\|b = \|x\|b + 1 ← x \> 0 \|x1\|b = \|x\|b + 1. 

The function satisfies the following 

P̀A \|x\|b = 0 ↔ x = 0 (1) 

P̀A \|x\|b = n ↔ 2n ÷ 2 ≤ x \< 2n (2) 

Property (1) is proved by simple case analysis. Property (2) is a direct con- sequence of the following 

2\|x\|b ÷ 2 ≤ x \< 2\|x\|b (3) 

P̀A ∀x(2n ÷ 2 ≤ x \< 2n → \|x\|b = n). (4) 

We prove (3) by binary induction on x. In the base case when x = 0 we have 

2\|0\|b ÷ 2 def= 20 ÷ 2 = 1÷ 2 = 0 ≤ 0 \< 1 = 20 def= 2\|0\|b . 

In the inductive case when x = y0 for some y \> 0 we have \|y\|b \> 0 by (1) and thus 

2\|y\|b = 2 · 2\|y\|b .− 1 = 2 ·(2 · 2\|y\|b .− 1 ÷ 2) = 2 ·(2\|y\|b ÷ 2). (5) 

We obtain 

2\|y0\|b ÷ 2 def= 2\|y\|b+1 ÷ 2 = 2 · 2\|y\|b ÷ 2 = 2\|y\|b (5) = 

= 2 ·(2\|y\|b ÷ 2) IH≤ 2 · y IH 

\< 2 · 2\|y\|b = 2\|y\|b+1 def= 2\|y0\|b . 

The inductive case when x = y1 is similar. We prove (4) by induction on n. In the base case take any x and assume 

x \< 20 = 1. Then x = 0 and we get \|0\|b = 0 by definition. In the inductive take any x and assume 2n′ ÷ 2 ≤ x \< 2n′ , ie 

2n ≤ x \< 2 · 2n. (6) 

284

We consider three cases. If x = 0 then (6) leads to contradiction. If x = y0 

for some y \> 0 then 2n ÷ 2 ≤ y \< 2n from (6) and thus 

\|y0\|b def= \|y\|b + 1 IH= n + 1 = n′. 

The case when x = y1 is similar. 

11\.4.7 Program computing the successor function in binary repre- sentation. Consider the following program computing the successor func- tion x′ in binary representation: 

0′ = 01 x0′ = x1 ← x \> 0 x1′ = x′0. 

We can visualize the above program as a binary example of the algorithm taught on decimal numerals in the elementary school: 

0 1 

01 

x0 

1 

x1 

x1 

1 

x′0 . 

Let us denote temporarily by S(x) the function defined by the above clausal definition. We claim that 

S(x) = x′. (1) 

Property (1) is proved by binary induction on x. In the base case when x = 0 we have 

S(0) def= 01 = 0′. 

In the inductive case when x = y0 for some y \> 0 we have 

S(y0) def= y1 = (y0)′. 

In the inductive case when x = y1 we have 

S(y1) def= S(y)0 IH= y′1 = y1′. 

11\.4.8 Program computing the addition function in binary repre- sentation. The addition function x + y has the following clausal definition by binary recursion on x with substitution in the parameter y: 

0+ y = y x0+0 = x0 ← x \> 0 x0+ y0 = (x+ y)0 ← x \> 0 ∧ y \> 0 x0+ y1 = (x+ y)1 ← x \> 0 x1+0 = x1 

x1+ y0 = (x+ y)1 x1+ y1 = (x+ y)′0. 

285

The recurrences in the ‘elementary school’ form are: 

0 y 

y 

x0 

0 x0 

x0 

y0 

(x + y)0 

x0 

y1 

(x + y)1 x1 

0 x1 

x1 

y0 

(x + y)1 

x1 

y1 

(x + y)′0 . 

We can, for instance, compute 3 + 5 = 8 as follows: 

011 + 0101 = (01 + 010)′0 = ((0 + 01)1)′0 = (011)′0 = = (01)′00 = 0′000 = 01000. 

Let us denote temporarily by x+b y the function defined by the above clausal definition. We prove 

P̀A x+b y = x + y (1) 

by binary induction on x with induction formula ∀y(1). In the base case when x = 0 take any y and we have 

0+b y def= y = 0 + y. 

In the inductive case when x = x11 for some x1 take any y and consider three cases. If y = 0 then we have 

x11+b 0 def= x11 = x11 + 0. 

If y = y10 for some y1 \> 0 then we have 

x11+b y10 def= (x1 +b y1)1 

IH= (x1 + y1)1 = x11 + y10. 

If y = y11 for some y1 then we have 

x11+b y11 def= (x1 +b y1)′0 

IH= (x1 + y1)′0 = x11 + y11. 

The inductive case when x = x11 is similar. 

11\.4.9 Program computing the equality predicate in binary repre- sentation. The equality predicate x = y has the following clausal definition by binary recursion on x with substitution in the parameter y: 

0 = 0 x0 = y0 ← x \> 0 ∧ y \> 0 ∧ x = y x1 = y1 ← x = y. 

286

Let us denote temporarily by x =b y the predicate defined by the above clausal definition. We prove 

P̀A x =b y ↔ x = y (1) 

by binary induction on x with induction formula ∀y(1). In the base case when x = 0 take any y and consider three cases. If y = 0 

then 0 =b 0 by definition and we are done. If y = y10 for some y1 \> 0 or y = y11 for some y1 then 0 6=b y by definition and since also 0 6= y we get 0 =b y ↔ 0 = y. 

In the inductive case when x = x10 for some x1 \> 0 take any y and consider three cases. If y = y10 for some y1 \> 0 then we have 

x10 =b y10 def⇔ x1 =b y1 

IH⇔ x1 = y1 ⇔ x10 = y10. 

Otherwise, if either y = 0 or y = y11 for some y1 then x10 6=b y by definition and since also x10 6= y we get x10 =b y ↔ x10 = y. The inductive case when x = x11 is similar. 

p-ary arithmetic 

11\.4.10 p-ary case analysis. For a base p \> 1 we have the principle of p-ary case analysis: 

P̀A ∃y∃z(x = p · y + z ∧ z \< p). (1) 

Property (1) follows directly from 

P̀A x = x÷ p · p + x mod p ∧ x mod p \< p 

holding by 7.4.8(1). 

11\.4.11 p-ary induction. Let T be a proper extension of PA, p a constant of T such that T \` p \> 1, φ\[x\] a formula of LT with the indicated variable x free and with possibly additional parameters, and y and z new variables. The formula of p-ary induction on x for φ\[x\] is the following one: 

∀z(z \< p → φ\[z\]) ∧ ∀y∀z(z \< p ∧ y \> 0 ∧ φ\[y\] → φ\[p · y + z\]) → φ\[x\]. 

11\.4.12 Theorem. Every proper extension T of PA proves the schema of p-ary induction: 

T \` ∀z(z \< p → φ\[z\]) ∧ ∀y∀z(z \< p ∧ y \> 0 ∧ φ\[y\] → φ\[p · y + z\]) → φ\[x\] . 

Proof. The principle of p-ary induction is reduced to mathematical induction as follows. Assume 

287

∀z(z \< p → φ\[z\]) (1) ∀y∀z(z \< p ∧ y \> 0 ∧ φ\[y\] → φ\[p · y + z\]) (2) 

and prove ∀x(x \< n → φ\[x\]) (3) 

by induction on n. In the base case, when n = 0, there is nothing to prove. In the inductive case take any x such that x \< n+1. By 11.4.10(1) there are numbers y and z \< p such that x = p · y + z. We consider two cases. If y = 0 then φ\[x\] follows from the assumption (1). If y \> 0 then, since y \< x ≤ n, we have φ\[y\] from IH: (3) and we get φ\[p · y + z\] from (2). This ends the proof of (3) and we obtain φ\[x\] by substituting x + 1 for n in (3). ut 

11\.4.13 p-ary recursion. Initial clauses for clausal definitions with p-ary recursion are of a form: 

f(\~y, x, \~z) = α1\[\~y, \~z, r\] ← x = p·x1+r ∧ r \< p ∧ x1 = 0 f(\~y, x, \~z) = α2\[λ̇\~yw\~z.f(\~y, x1, \~z); \~y, x1, \~z, r\] ← x = p·x1+r ∧ r \< p ∧ x1 \> 0. 

Note that the clauses are regular in the argument x. 

11\.4.14 A fast program for the square root function. From the point of view of computational complexity the improvement of the accumulator program for the function b√xc in Par. 11.3.7 over the program in Par. 11.2.6 is insignificant because both programs work in the monadic representation. We can obtain a fast O(\|x\|b) program for b√xc by recalling a high school algorithm working with the decimal, or rather centennial, notation because it considers two decimal digits at a time. The recursion does not work well in the decimal notation because we have b√10·x + dc ≈ b√10c·b√xc while it works well in the centennial notation because b√100·x + dc ≈ 10·b√xc. 

The same works in the 4-ary representation where for every z there are unique numbers x and i such that z = 4 ·x+ i and i \< 4. The reason why we have chosen this range for i is that we have \|i\|b = 2 and we can make use of fast pattern matching with the numeric pattern 4 ·x+i (just consider the last two binary digits of the binary representation of z) and fast multiplication 4 · y + i (just append the two binary digits of i at the end of y). 

Thus assume as IH that we have for x \> 0 

b√xc2 ≤ x \< (b√xc+ 1)2. 

From the last we obtain x ≤ b√xc2 + 2 ·b√xc and so we get for i \< 4: 

(2 ·b√xc)2 ≤ 4 ·x ≤ 4 ·x + i ≤ 4 ·b√xc2 + 8 ·b√xc+ i \< 

\< 4 ·b√xc2 + 8 ·b√xc+ 4 = (2 ·b√xc+ 2)2. 

This means that we have 

288

2 ·b√xc ≤ b√4 ·x + ic ≤ 2 ·b√xc+ 1 

and so the following clausal definition is a fast program for b√xc: b√4 ·x + ic = sgn(i) ← i \< 4 ∧ x = 0 b√4 ·x + ic = s ← i \< 4 ∧ x \> 0 ∧ 2 ·b√xc = s ∧ 4 ·x + i \< (s + 1)2 

b√4 ·x + ic = s + 1 ← i \< 4 ∧ x \> 0 ∧ 2 ·b√xc = s ∧ 4 ·x + i ≥ (s + 1)2. 

The reader will note that the assignment 2 ·b√xc = s is crucial to the speed of the program because without it we would have two recursive invocations in the test 4 ·x + i \< (2 ·x + 1) ·(2 ·x + 1). Consequently, as the depth of recursion is O(\|x\|b), we would have O(2\|x\|b) = O(x) recursive invocations and the definition would not be any faster than the one by primitive recursion. 

Dyadic arithmetic 

11\.4.15 Dyadic representation of N. We introduce two dyadic successor functions by explicit definitions: 

P̀Ax x1 = 2 ·x + 1 (1) 

P̀Ax x2 = 2 ·x + 2. (2) 

Dyadic numerals are the least class of terms satisfying the following: 

– the constant 0 is a dyadic numeral, – if τ is a dyadic numeral so are τ1 and τ2. 

We give here some examples of dyadic numerals: 

0 = 0 01 = 2 · 0 + 1 = 1 02 = 2 · 0 + 2 = 2 

011 = 2 ·(2 · 0 + 1) + 1 = 3 012 = 2 ·(2 · 0 + 1) + 2 = 4 021 = 2 ·(2 · 0 + 2) + 1 = 5 022 = 2 ·(2 · 0 + 2) + 2 = 6 

0111 = 2 ·(2 ·(2 · 0 + 1) + 1) + 1 = 7. 

11\.4.16 Dyadic case analysis. We have the following principle of dyadic case analysis: 

P̀A x = 0 ∨ ∃y x = y1 ∨ ∃y x = y2. (1) 

Property (1) follows from 

P̀A x 6= 0 → x = (x .− 1)÷ 2 · 2 + (x .− 1) mod 2 + 1 ∧ 0 \< (x .− 1) mod 2 + 1 ≤ 2 

289

which is a direct consequence of 

P̀A x .− 1 = (x .− 1)÷ 2 · 2 + (x .− 1) mod 2 ∧ (x .− 1) mod 2 \< 2 

holding by 7.4.8(1). 

11\.4.17 Dyadic induction. Let T be a proper extension of PA containing the dyadic successors, φ\[x\] a formula of LT with the indicated variable x free and with possibly additional parameters. The formula of dyadic induction on x for φ\[x\] is the following one: 

φ\[0\] ∧ ∀x(φ\[x\] → φ\[x1\]) ∧ ∀x(φ\[x\] → φ\[x2\]) → φ\[x\]. 

11\.4.18 Theorem. Every proper extension T of PA containing the dyadic successors proves the schema of dyadic induction: 

T \` φ\[0\] ∧ ∀x(φ\[x\] → φ\[x1\]) ∧ ∀x(φ\[x\] → φ\[x2\]) → φ\[x\]. 

Proof. We can reduce the principle of dyadic induction to mathematical induction similarly as in the case of binary induction (see the proof of Thm. 11.4.4). ut 

11\.4.19 Dyadic recursion. Initial clauses for clausal definitions with dyadic recursion are of a form 

f(\~y, x, \~z) = α1\[\~y, \~z\] ← x = 0 f(\~y, x, \~z) = α2\[λ̇\~yw\~z.f(\~y, x1, \~z); \~y, x1, \~z\] ← x = x11 

f(\~y, x, \~z) = α2\[λ̇\~yw\~z.f(\~y, x1, \~z); \~y, x1, \~z\] ← x = x12. 

Note that the clauses are regular in the argument x. 

11\.4.20 Dyadic size. The dyadic size function \|x\|d yields the number of dyadic successors in the dyadic numeral denoting the number x. The function is defined by parameterless dyadic recursion as a primitive recursive function: 

\|0\|d = 0 \|x1\|d = \|x\|d + 1 \|x2\|d = \|x\|d + 1. 

The function satisfies the following 

P̀A \|x\|d = 0 ↔ x = 0 (1) 

P̀A \|x\|d = n ↔ 2n ≤ x + 1 \< 2n+1. (2) 

Property (1) is proved by simple dyadic case analysis. Property (2) is proved by induction on n with induction formula ∀x (2). In the base take any x and we have 

290

\|x\|d = 0 (1)⇔ x = 0 ⇔ 1 ≤ 0 + 1 \< 2 ⇔ 20 ≤ 0 + 1 \< 20+1. 

In the inductive case take any x and consider three cases. If x = 0 then the claim follows from the following facts: \|0\|d = 0 6= n+1 and 2n+1 \> 1 = 0+1. If x = y1 for some y then we have 

\|y1\|d = n + 1 def⇔ \|y\|d = n IH⇔ 2n ≤ y + 1 \< 2n+1 9.0.17(1);7.3.6(3)⇔ 

⇔ 2 · 2n ≤ 2 ·(y + 1) \< 2 · 2n+1 ⇔ 2n+1 ≤ y1 + 1 \< 2n+2. 

If x = y2 for some y then we have 

\|y2\|d = n + 1 def⇔ \|y\|d = n IH⇔ 2n ≤ y + 1 \< 2n+1 9.0.17(3);9.0.17(4)⇔ 

⇔ 2 · 2n ≤ 2 ·(y + 1) + 1 \< 2 · 2n+1 ⇔ 2n+1 ≤ y2 + 1 \< 2n+2. 

11\.4.21 Dyadic concatenation. The binary function x ? y, called dyadic concatenation, yields a number whose dyadic representation is obtained from dyadic representations of x and y by appending the digits of y after the digits of x. The dyadic concatenation function x ? y is the arithmetization of the word function concatenating words over the alphabet {1, 2} and it is defined by dyadic recursion on y as a primitive recursive function: 

x ? 0 = x x ? y1 = (x ? y)1 x ? y2 = (x ? y)2. 

From the reccurrences we get 

P̀A x ? y = x · 2\|y\|d + y (1) 

P̀A x ? y = 0 ↔ x = 0 ∧ y = 0 (2) 

P̀A 0 ? y = y (3) 

P̀A (x ? y) ? z = x ?(y ? z) (4) 

P̀A \|x ? y\|d = \|x\|d + \|y\|d. (5) 

We prove here only the properties (1) and (4). The remaining properties are left to the reader as an exercise. 

Property (1) is proved by dyadic induction on y. In the base case we have 

x ? 0 def= x = x · 1 + 0 = x · 20 + 0 def= x · 2\|0\|d + 0. 

In the inductive case when y = y11 we have 

x ? y11 def= (x ? y1)1 

IH= (x · 2\|y1\|d + y1)1 = 2 ·(x · 2\|y1\|d + y1) + 1 = 

= x · 2\|y1\|d+1 + 2 · y1 + 1 def= x · 2\|y11\|d + y11. 

The inductive case when y = y12 is proved similarly. 

291

Property (4) is proved by dyadic induction on z. In the base case we have 

(x ? y) ? 0 def= x ? y def= x ?(y ? 0). 

In the inductive case when z = z12 we have 

(x ? y) ? z11 def= ((x ? y) ? z1)1 

IH= (x ?(y ? z1))1 def= x ? (y ? z1)1 

def= x ?(y ? z11). 

The inductive case when z = z12 is proved similarly. 

11\.4.22 Dyadic reversal. 

Revd(0) = 0 Revd(x1) = 01 ?Revd(x) Revd(x2) = 02 ?Revd(x). 

From the reccurrences we get 

P̀A Revd(x) = 0 ↔ x = 0 (1) 

P̀A Revd(x ? y) = Revd(y) ?Revd(x) (2) 

P̀A Revd Revd(x) = x (3) 

P̀A Revd(x) = Revd(y) → x = y (4) 

P̀A \|Revd(x)\|d = \|x\|d. (5) 

Property (2) is proved by dyadic induction on y. In the base case we have 

Revd(x ? 0) def= Revd(x) 11.4.21(3) 

= 0 ?Revd(x). 

In the inductive case when y = y11 we have 

Revd(x ? y11) def= Revd((x ? y1)1) def= 

= 01 ?Revd(x ? y1) IH= 01 ?(Revd(y1) ?Revd(x)) 

11\.4.21(4) = 

= (01 ?Revd(y1)) ?Revd(x) def= Revd(y11) ?Revd(x). 

The inductive case when y = y12 is proved similarly. Property (3) is dyadic by induction on x. (3). Property (4) follows from 

(3). The remaining properties are left to the reader as an exercise. 

11\.4.23 Cancellation laws for dyadic concatenation. Cancellation rules for the dyadic concatenation are: 

P̀A x ? z = y ? z → x = y (1) 

P̀A z ? x = z ? y → x = y. (2) 

Property (1) is proved by dyadic induction on z. In the base case we have 

292

x ? 0 = y ? 0 def⇒ x = y. 

In the inductive case when z = z11 we have 

x ? z11 = y ? z11 def⇒ (x ? z1)1 = (y ? z1)1 ⇒ x ? z1 = y ? z1 

IH⇒ x = y. 

The inductive case when z = z12 is proved similarly. Property (2) is proved as follows: 

z ? x = z ? y ⇒ Revd(z ? x) = Revd(z ? y) 11.4.22(2)⇒ Revd(x) ?Revd(z) = 

= Revd(y) ?Revd(z) (1)⇒ Revd(x) = Revd(y) 

11\.4.22(4)⇒ x = y. 

11\.5 Exercises 

11\.5.1 Exercise. Prove 

P̀A min(x, y) = min(y, x) 

P̀A min(x, min(y, z)) = min(min(x, y), z) 

P̀A min(x, 0) = 0. 

11\.5.2 Exercise. Find an explicit clausal definition of the maximum func- tion max(x, y) satisfying 

P̀A max(x, y) ≥ x 

P̀A max(x, y) ≥ y 

P̀A max(x, y) = x ∨max(x, y) = y. 

Prove that the function has the required properties. 

11\.5.3 Exercise. Prove 

P̀A max(x, y) = max(y, x) 

P̀A max(x, max(y, z)) = max(max(x, y), z) 

P̀A max(x, 0) = x. 

11\.5.4 Exercise. Prove 

P̀A min(x, y) ≤ max(x, y) 

P̀A min(x, y) = max(x, y) ↔ x = y 

P̀A min(x,max(y, z)) = max(min(x, y), min(x, z)) 

P̀A max(x, min(y, z)) = min(max(x, y), max(x, z)). 

293

11\.5.5 Exercise. Prove 

P̀A min(x + y, x + z) = x + min(y, z) 

P̀A max(x + y, x + z) = x + max(y, z) 

P̀A min(x · y, x · z) = x ·min(y, z) 

P̀A max(x · y, x · z) = x ·max(y, z) 

P̀A min(x .− y, x .− z) = x .−max(y, z) 

P̀A min(y .−x, z .−x) = min(y, z) .−x 

P̀A max(x .− y, x .− z) = x .−min(y, z) 

P̀A max(y .−x, z .−x) = max(y, z) .−x. 

11\.5.6 Exercise. Prove 

P̀A x ≤ y → min(x, z) ≤ min(y, z) 

P̀A x ≥ y → min(x, z) ≥ min(y, z) 

P̀A x ≤ y → max(x, z) ≤ max(y, z) 

P̀A x ≥ y → max(x, z) ≥ max(y, z). 

11\.5.7 Exercise. Find an explicit clausal definition of the ternary function Median(x, y, z) satisfying 

P̀A x ≤ y ≤ z → Median(x, y, z) = y 

P̀A Median(x, y, z) = Median(y, x, z) 

P̀A Median(x, y, z) = Median(x, z, y). 

Prove that the function has the required properties. 

11\.5.8 Exercise. Consider the following primitive recursive definition of the integer division function x÷ y: 

0÷ y = 0 (x + 1)÷ y = q ← x÷ y = q ∧ x + 1 .− q · y \< y (x + 1)÷ y = q + 1 ← x÷ y = q ∧ x + 1 .− q · y ≥ y. 

Prove 

P̀A y \> 0 → ∃r(x = x÷ y · y + r ∧ r \< y). 

11\.5.9 Exercise. Let f be a function such that 

P̀A ∀x∃y x \< f(y) ∧ f(0) = 0. 

Prove 

P̀A ∃r(f(r) ≤ x \< f(r + 1)). 

294

Hint. First prove the following property 

P̀A x \< f(y) → ∃r(f(r) ≤ x \< f(r + 1)). 

11\.5.10 Exercise. Let f be a function such that P̀A ∃y x \< fg(x) and P̀A f(0) = 0. Consider the following clausal definition of the function r(x): 

r1(0, x) = 0 r1(y + 1, x) = y ← f(y) ≤ x r1(y + 1, x) = r1(y, x) ← f(y) \> x 

r(x) = r1(g(x), x). 

Prove 

P̀A f r(x) ≤ x \< f(r(x) + 1). 

11\.5.11 Exercise. Consider the following primitive recursive definition on y with substitution in parameter x of the modified subtraction function x .− y: 

x .− 0 = x 0 .− y′ = 0 x′ .− y′ = x .− y. 

Prove 

P̀A x ≥ y → x = y + (x .− y) 

P̀A x ≤ y → x .− y = 0. 

11\.5.12 Exercise. Consider the function f(n, a) defined by primitive re- cursion on n with substitution in parameter: 

f(0, a) = a f(n + 1, a) = f(n, a + n + 1). 

Prove 

P̀A 

n∑ 

i=0 

i = f(n, 0). 

Hint. First prove the following property 

P̀A f(n, a) = n∑ 

i=0 

i + a. 

295

11\.5.13 Exercise. Consider the function f(n, a) defined by primitive re- cursion on n with substitution in parameter: 

f(0, a) = a f(n + 1, a) = f(n, a ·(n + 1)). 

Prove 

P̀A n! = f(n, 1). 

11\.5.14 Exercise. Consider the following functions f(n) and g(n, a, b, c): 

f(0) = 0 f(1) = 1 f(2) = 2 f(n + 3) = f(n + 2) + f(n + 1) + f(n) 

g(0, a, b, c) = c g(n + 1, a, b, c) = g(n, a + b + c, a, b). 

Prove 

P̀A f(n) = g(n, 2, 1, 0). 

11\.5.15 Exercise. Consider the following functions f(n) and g(n, a, b, c): 

f(0) = 0 f(1) = 1 f(n + 2) = f(n + 1) + f(n) + n 

g(0, k, a, b) = b g(n + 1, k, a, b) = g(n, k + 1, a + b + k, a) . 

Prove 

P̀A f(n) = g(n, 0, 1, 0). 

Hint. First prove the following property 

P̀A g(n, k, f(k + 1), f(k)) = f(n + k). 

11\.5.16 Exercise. Consider the following course of values recursive defini- tion on x of the remainder function x mod y: recursion on x as follows: 

x mod y = x ← y \> 0 ∧ x \< y x mod y = (x .− y) mod y ← y \> 0 ∧ x ≥ y. 

Prove 

P̀A y \> 0 → ∃q(x = q · y + x mod y ∧ x mod y \< y). 

296

11\.5.17 Exercise. Let f be a function such that P̀A ∃y x \< fg(x) and P̀A f(0) = 0. Consider the following clausal definition of the function r(x): 

r1(y, x) = y ← x \< f(y + 1) r1(y, x) = r1(y + 1, x) ← x ≥ f(y + 1) ∧ y \< g(x) 

r(x) = r1(0, x). 

Prove 

P̀A f r(x) ≤ x \< f(r(x) + 1). 

11\.5.18 Exercise. Consider the function f(n, j, a) defined by course of val- ues recursion with measure n .− j: 

f(n, j, a) = a ← j = n f(n, j, a) = f(n, m + 1, a + m + 1) ← j \< n. 

Prove 

P̀A 

n∑ 

i=0 

i = f(n, 0, 0). 

11\.5.19 Exercise. Consider the function f(n, i, a) defined by course of val- ues recursion with measure 

f(n, i, a) = a ← i \> n f(n, i, a) = f(n, i + 1, i · a) ← i ≤ n. 

Prove 

P̀A n! = f(n, 1, 1). 

11\.5.20 Exercise. Consider the function f(n, i, a) defined by course of val- ues recursion with measure 

f(n, i, a) = a ← i = n f(n, i, a) = f(n, i + 1, (i + 1) · a) ← i \< n. 

Prove 

P̀A n! = f(n, 0, 1). 

11\.5.21 Exercise. Define the predecessor function x .− 1 by binary recur- sion and verify your implementation. 

11\.5.22 Exercise. Define the multiplication function x · y by binary recur- sion and verify your implementation. 

297

11\.5.23 Exercise. Define the exponentiation function xy by binary recur- sion and verify your implementation. 

11\.5.24 Exercise. Define by binary recursion the trichotomic comparision function Comp(x, y) satisfying: 

P̀A Comp(x, y) = 0 ↔ x \< y 

P̀A Comp(x, y) = 1 ↔ x = y 

P̀A Comp(x, y) = 2 ↔ x \> y. 

Prove that the function has the required properties. 

11\.5.25 Exercise. Define the predicate x ≤ y by binary recursion and ver- ify your implementation. 

11\.5.26 Exercise. Define the predicate x \< y by binary recursion and ver- ify your implementation. 

298

12\. Programs Operating on Lists 

12\.1 Lists 

12\.1.1 List representation of N. There is a simple way of arithmetizing finite sequences over natural numbers. We assign the code 0 to the empty sequence ∅. The non-empty sequence x1 x2 . . . xn is coded by the number (x1, x2, . . . , xn, 0) (see Fig. 12.1). The reader will note that the assignment of codes is one to one, every finite sequence of natural numbers is coded by exactly one natural number, and vice versa, every natural number is the code of exactly one finite sequence of natural numbers. Codes of finite sequences are called lists in computer science and this is how we will be calling them from now on. 

x, 0 x, y, 0 x, y, z, 0 x1, x2, . . . , xn, 0 

r ¡¡ @@ 

x 0 

r ¡¡ @@r 

¡¡ @@x 

y 0 

r ¡¡ @@r 

¡¡ @@r ¡¡ @@ 

x 

y 

z 0 

r ¡¡ @@r 

¡¡ @@ p p p r ¡¡ @@ 

x1 

x2 

xn 0 

Fig. 12.1. Lists 

12\.1.2 Case analysis on lists. We have the following principle of list case analysis (see 8.3.14(4)): 

P̀A x = 0 ∨ ∃v∃w x = v, w. 

12\.1.3 List induction. Let T be a proper extension of PA containing the pairing function, φ\[x\] a formula of LT with the indicated variable x free and with possibly additional parameters, and v and w new variables. The formula of list induction on x for φ\[x\] is the following one:

φ\[0\] ∧ ∀v∀w(φ\[w\] → φ\[v, w\]) → φ\[x\]. 

12\.1.4 Theorem. Every proper extension T of PA containing the pairing function proves the schema of list induction: 

T \` φ\[0\] ∧ ∀v∀w(φ\[w\] → φ\[v, w\]) → φ\[x\]. 

Proof. The principle of list induction is reduced to mathematical induction as follows. Assume 

φ\[0\] (1) ∀v∀w(φ\[w\] → φ\[v, w\]) (2) 

and prove ∀x(x \< n → φ\[x\]) (3) 

by induction on n. In the base case, when n = 0, there is nothing to prove. In the inductive case take any x such that x \< n + 1. We consider two cases. If x = 0 then φ\[0\] follows from the assumption (1). If x = v, w for some v and w then, since w \< x ≤ n, we have φ\[w\] from IH: (3) and we get φ\[v, w\] from (2). This ends the proof of (3) and we obtain φ\[x\] by substituting x + 1 for n in (3). ut 

12\.1.5 List recursion. Initial clauses for clausal definitions with list recur- sion are of a form 

f(\~y, x, \~z) = α1\[\~y, \~z\] ← x = 0 f(\~y, x, \~z) = α2\[λ̇\~yw1\~z.f(\~y, w, \~z); \~y, \~z, v, w\] ← x = v, w. 

12\.1.6 Length of lists. The list x1, x2, . . . , xn, 0 codes a finite sequence of natural numbers of length n and we say that the list has the length n. The length function has the following clausal definition by list recursion: 

L(0) = 0 L(v, w) = L(w) + 1. 

We have 

P̀A L(x) = 0 ↔ x = 0 (1) 

P̀A L(x) ≤ \|x\|p (2) 

P̀A ∃x L(x) = n. (3) 

Property (1) is proved by straightforward list case analysis. Property (2) is proved by list induction. The base case when x = 0 holds directly by definition and in the inductive case we have 

L(v, w) def= L(w) + 1 IH≤ \|w\|p + 1 ≤ \|v\|p + \|w\|p + 1 = \|v, w\|p. 

Property (3) is proved by induction on n. In the base case when n = 0 it suffices to take x := 0. In the inductive case we have by IH that n = L(y) for some y. Then L(0, y) def= L(y)+1 = n+1 and thus it suffices to take x := 0, y. 

300

12\.1.7 List indexing. The list indexing function (x)i yields the i-th ele- ment of the list x (counting from 0) or 0 if i ≥ L(x). The indexing function (x)i is defined by primitive recursion on i with substitution in parameter: 

(v, w)0 = v (v, w)i+1 = (w)i. 

We have 

P̀A (x)i = H T i(x). (1) 

Property (1) is proved by induction on i with the induction formula ∀x(1). In the base case take any x and consider two cases. If x = 0 then 

(0)0 def= 0 = H(0) = H T 0(0). 

If x = v, w then 

(v, w)0 def= v = H(v, w) = H T 0(v, w). 

In the inductive case take any x and consider two cases. If x = 0 then 

(0)i+1 def= 0 = H(0) 

8\.3.18(6) = H T i+1(0). 

If x = v, w then 

(v, w)i+1 def= (w)i 

IH= H T i(w) = H T i T (v, w) 8.3.18(7) 

= H T i+1(v, w). 

12\.1.8 Equality test for lists. We have 

P̀A x = y ↔ L(x) = L(y) ∧ ∀i(i \< L(x) → (x)i = (y)i). (1) 

Property (1) is proved by list induction on x with the induction formula ∀y(1). In the base case when x = 0 we consider two cases. If y = 0 then (1) holds trivially since L(0) = 0 by definition. If y = v2, w2 then (1) follows from 0 6= v2, w2 and L(0) = 0 6= L(w2) + 1 = L(v2, w2). In the inductive case when x = v1, w2 we consider two cases. If y = 0 then we obtain (1) as before. If y = v2, w2 then we have 

v1, w1 = v2, w2 ⇔ v1 = v2 ∧ w1 = w2 IH⇔ 

v1 = v2 ∧ L(w1) = L(w2) ∧ ∀i(i \< L(w1) → (w1)i = (w2)i) (∗)⇔ 

L(v1, w1) = L(v2, w2) ∧ ∀i(i \< L(v1, w1) → (v1, w1)i = (v2, w2)i). 

The step marked by (∗) follows from the following properties 

P̀A v1 = v2 ∧ ∀i(i \< L(w1) → (w1)i = (w2)i) → ∀i(i ≤ L(w1) → (v1, w1)i = (v2, w2)i) 

(2) 

301

P̀A ∀i(i ≤ L(w1) → (v1, w1)i = (v2, w2)i) → v1 = v2 (3) 

P̀A ∀i(i ≤ L(w1) → (v1, w1)i = (v2, w2)i) → ∀i(i \< L(w1) → (w1)i = (w2)i). 

(4) 

Property (3) is proved as follows. Assume its antecedent, take any i ≤ L(w2), and consider two cases. If i = 0 then we have 

(v1, w1)0 = v1 hyp = v2 = (v2, w2)0. 

If i = j + 1 for some j, then j \< L(w2). We have 

(v1, w1)j+1 = (w1)j hyp = (w2)j = (v2, w2)j+1. 

We obtain the property (3) by instantiation of its antecedent by i := 0: 

v1 = (v1, w1)0 hyp = (v2, w2)0 = v2. 

In the proof of the property (4) assume its antecedent, take any i \< L(w2), instantiate the antecedent by i := i + 1, and we have 

(w1)i = (v1, w1)i+1 hyp = (v2, w2)i+1 = (w2)i. 

12\.1.9 Concatenation of lists. The list concatenation function x ⊕ y is defined by list recursion on x: 

0⊕ y = y (v, w)⊕ y = v, w ⊕ y. 

We have 

P̀A x⊕ y = 0 ↔ x = 0 ∧ y = 0 (1) 

P̀A x⊕ 0 = x (2) 

P̀A x⊕ (y ⊕ z) = (x⊕ y)⊕ z (3) 

P̀A x⊕ y = x⊕ z → y = z (4) 

P̀A x⊕ z = y ⊕ z → x = y (5) 

P̀A x⊕ (a, 0) = y ⊕ (b, 0) → x = y ∧ a = b (6) 

P̀A \|x⊕ y\|p = \|x\|p + \|y\|p (7) 

P̀A L(x⊕ y) = L(x) + L(y) (8) 

P̀A i \< L(x) → (x⊕ y)i = (x)i (9) 

P̀A i \< L(y) → (x⊕ y)L(x)+i = (y)i (10) 

P̀A x 6= 0 ↔ ∃y∃a x = y ⊕ (a, 0). (11) 

Property (1) is proved by a simple list case analysis on x. Properties (2) and (3) are proved by a straightforward list induction on x. Property (4) is proved 

302

by list induction on x. The base case is straightforward and in the inductive case we have 

(v, w)⊕ y = (v, w)⊕ z def⇔ v, w ⊕ y = v, w ⊕ z ⇔ w ⊕ y = w ⊕ z 

IH⇒ y = z. 

In the proof of (5) we need the following auxiliary property 

P̀A ∀x(x⊕ y = y → x = 0) (12) 

which can be proved by list induction on y. Property (5) is proved by list induction on x with the induction formula ∀y(5). In the base case when x = 0 take any y and consider two cases. If y = 0 then (5) follows from definition. The case when y = v2, w2 leads to contradiction with 0 6= v2, w2: 

0⊕ z = (v2, w2)⊕ z def⇔ z = (v2, w2)⊕ z 

(12)⇒ 0 = v2, w2. 

In the inductive case when x = v1, w1 take any y and consider two cases. The case when y = 0 leads to contradiction by similar arguments as above. If y = v2, w2 then 

(v1, w1)⊕ z = (v2, w2)⊕ z def⇔ v1, w1 ⊕ z = v2, w2 ⊕ z ⇔ 

v1 = v2 ∧ w1 ⊕ z = w2 ⊕ z IH⇒ v1 = v2 ∧ w1 = w2 ⇔ v1, w1 = v2, w2. 

The remaining properties are left to the reader. 

12\.1.10 Alternative definition of list concatenation. The following property 

P̀A x⊕ y = z ↔ L(z) = L(x) + L(y) ∧ ∧ ∀i(i \< L(z) → (i \< L(x) → (z)i = (x)i) ∧ ∧ (i ≥ L(x) → (z)i = (y)i .−L(x)) 

) (1) 

can be used as an alternative (contextual) definition of list concatenation. The property is proved by list induction on x with the induction formula 

∀z(1). The base case follows from 12.1.8(1). In the inductive case when x = v1, w1 take any z and consider two cases. If z = 0 then (1) trivially holds since both sides of the equivalence are false. If z = v2, w2 then we have 

(v1, w1)⊕ y = v2, w2 def⇔ v1, w1 ⊕ y = v2, w2 ⇔ v1 = v2 ∧ w1 ⊕ y = w2 

IH⇔ v1 = v2 ∧ L(w2) = L(w1) + L(y) ∧ ∀i(i \< L(w2) → (i \< L(w1) → (w2)i = (w1)i) ∧ 

(i ≥ L(w1) → (w2)i = (y)i .−L(w1)) ) (∗)⇔ 

L(v2, w2) = L(v1, w1) + L(y) ∧ ∀i(i \< L(v2, w2) → (i \< L(v1, w1) → (v2, w2)i = (v1, w1)i) ∧ 

(i ≥ L(v1, w1) → (v2, w2)i = (y)i .−L(v1,w1)) 

) . 

303

The step marked by (∗) follows from the following properties 

P̀A v1 = v2 ∧ ∀i(i \< L(w1) → (w2)i = (w1)i) → ∀i(i ≤ L(w1) → (v2, w2)i = (v1, w1)i) 

(2) 

P̀A v1 = v2 ∧ ∀i(L(w1) ≤ i \< L(w2) → (w2)i = (y)i .−L(w1)) → 

∀i(L(w1) \< i ≤ L(w2) → (v2, w2)i = (y)i .−(L(w1)+1)) (3) 

P̀A ∀i(i ≤ L(w1) → (v2, w2)i = (v1, w1)i) → v1 = v2 (4) 

P̀A ∀i(i ≤ L(w1) → (v2, w2)i = (v1, w1)i) → ∀i(i \< L(w1) → (w2)i = (w1)i) 

(5) 

P̀A ∀i(L(w1) \< i ≤ L(w2) → (v2, w2)i = (y)i .−(L(w1)+1)) → ∀i(L(w1) ≤ i \< L(w2) → (w2)i = (y)i 

.−L(w1)). (6) 

Property (2) is proved as follows. Assume the antecedent of the property, take any i ≤ L(w1), and consider two cases. If i = 0 then we have 

(v2, w2)0 = v2 hyp = v1 = (v1, w1)0. 

If i = j + 1 for some j then j \< L(w1) and we have 

(v2, w2)j+1 = (w2)j hyp = (w1)j = (v1, w1)j+1. 

Property (3) is proved as follows. Assume the antecedent of the property, take any i such that L(w1) \< i ≤ L(w2). Then L(w1) ≤ i .− 1 \< L(w2) and we have 

(v2, w2)i = (w2)i .− 1 hyp = (y)i .− 1 .−L(w1) = (y)i .−(L(w1)+1). 

Property (4) is proved by instantiation of its antecedent by i := 0: 

v1 = (v1, w1)0 hyp = (v2, w2)0 = v2. 

Property (5) is proved as follows. Assume the antecedent of the property, take any i \< L(w1), and we have 

(w2)i = (v2, w2)i+1 hyp = (v1, w1)i+1 = (w1)i. 

Property (6) is proved as follows. Assume the antecedent of the property, take any i such that L(w1) ≤ i \< L(w2). Note that L(w1) \< i + 1 ≤ L(w2). We have 

(w2)i = (v2, w2)i+1 hyp = (y)i+1 .−(L(w1)+1) = (y)i .−L(w1). 

304

12\.1.11 List membership. The list membership predicate x ε y is defined by list recursion on y: 

x ε v, w ← x = v x ε v, w ← x 6= v ∧ x ε w. 

We have 

P̀A x 6ε 0 (1) 

P̀A x ε v, w ↔ x = v ∨ x ε w (2) 

P̀A x ε y ⊕ z ↔ x ε y ∨ x ε z. (3) 

Properties (1) and (2) straighforward. Property (3) is proved by list induction on y. The base is trivial and in the inductive case we have 

x ε (v, w)⊕ z ⇔ x ε v, w ⊕ z (2)⇔ x = v ∨ x ε w ⊕ z 

IH⇔ x = v ∨ x ε w ∨ x ε z 

(2)⇔ x ε v, w ∨ x ε z. 

12\.1.12 Alternative definition of list membership. The following is the basic property of list membership predicate 

P̀A x ε y ↔ ∃i(i \< L(y) ∧ (y)i = x). (1) 

The property is proved by list induction on y. The base case is straightforward and in the inductive case we have 

x ε v, w 12.1.11(2)⇔ x = v ∨ x ε w 

IH⇔ x = v ∨ ∃i(i \< L(w) ∧ (w)i = x) (∗)⇔ 

∃i(i \< L(v, w) ∧ (v, w)i = x). 

The step marked by (∗) follows from the following properties 

P̀A x = v → ∃i(i ≤ L(w) ∧ (v, w)i = x) (2) 

P̀A ∃i(i \< L(w) ∧ (w)i = x) → ∃i(i ≤ L(w) ∧ (v, w)i = x) (3) 

P̀A ∃i(i ≤ L(w) ∧ (v, w)i = x) → x = v ∨ ∃i(i \< L(w) ∧ (w)i = x). (4) 

Property (2) follows from 

x = v ⇒ 0 ≤ L(w) ∧ (v, w)0 = v = x. 

Property (3) follows from 

i \< L(w) ∧ (w)i = x ⇒ i + 1 ≤ L(w) ∧ (v, w)i+1 = (w)i = x. 

Property (4) is proved as follows. Suppose that we have i ≤ L(w) and (v, w)i = x for some i. We consider two cases. If i = 0 then 

x hyp = (v, w)0 = v ⇒ x = v. 

If i = j + 1 then 

j \< L(w) ∧ x hyp = (v, w)j+1 = (w)j ⇒ ∃i(i \< L(w) ∧ (w)i = x). 

305

12\.1.13 List reversal. The function Rev reversing lists has the following clausal definition by list recursion: 

Rev(0) = 0 Rev(v, w) = Rev(w)⊕ (v, 0). 

We have 

P̀A Rev(x) = 0 ↔ x = 0 (1) 

P̀A Rev(x⊕ y) = Rev(y)⊕ Rev(x) (2) 

P̀A Rev Rev(x) = x (3) 

P̀A Rev(x) = Rev(y) → x = y (4) 

P̀A ∃y Rev(y) = x (5) 

P̀A x ε Rev(y) ↔ x ε y (6) 

P̀A \|Rev(x)\|p = \|x\|p (7) 

P̀A LRev(x) = L(x). (8) 

Property (1) is proved by a simple list case analysis on x. Property (2) is proved by a straightforward list induction on x. Property (3) is proved by list induction on x. The base case is straightforward and in the inductive case we have 

Rev Rev((v, w)⊕ y) = Rev Rev(v, w ⊕ y) def= Rev(Rev(w ⊕ y)⊕ (v, 0)) (2) = 

= Rev(v, 0)⊕ Rev Rev(w ⊕ y) 2×def;IH 

= 0⊕ (v, 0)⊕ w ⊕ y = (v, w)⊕ y. 

Property (4) is proved as follows 

Rev(x) = Rev(y) ⇒ Rev Rev(x) = Rev Rev(y) (3)⇔ x = y. 

Property (5) follows from (3). The remaining properties are left to the reader. 

12\.1.14 Alternative definition of list reversal. The following property 

P̀A Rev(x) = y ↔ L(y) = L(x) ∧ ∀i(i \< L(y) → (y)i = (x)L(y) .−(i+1)) (1) 

can be used as an alternative (contextual) definition of list reversal. The property is proved by list induction on x with the induction formula 

∀y(1). The base case is straightforward. In the inductive case when x = v1, w1 

take any y and consider two cases. If y = 0 then (1) trivially holds since both sides of the equivalence are false. If y 6= 0 then y = w2 ⊕ (v2, 0) for some v2 

and w2 by 12.1.9(11). We have 

Rev(v1, w1) = w2 ⊕ (v2, 0) def⇔ Rev(w1)⊕ (v1, 0) = w2 ⊕ (v2, 0) 12.1.9(6)⇔ 

v1 = v2 ∧ Rev(w1) = w2 IH⇔ 

v1 = v2 ∧ L(w2) = L(w1) ∧ ∀i(i \< L(w2) → (w2)i = (w1)L(w2) .−(i+1)) 

(∗)⇔ 

306

L(w2 ⊕ (v2, 0)) = L(v1, w1) ∧ ∀i(i \< L(w2 ⊕ (v2, 0)) → (w2 ⊕ (v2, 0))i = (v1, w1)L(w2⊕(v2,0)) 

.−(i+1)). 

The step marked by (∗) follows from the following properties 

P̀A L(w2 ⊕ (v2, 0)) = L(w2) + 1 (2) 

P̀A v1 = v2 ∧ ∀i(i \< L(w2) → (w2)i = (w1)L(w2) .−(i+1)) → 

∀i(i ≤ L(w2) → (w2 ⊕ (v2, 0))i = (v1, w1)L(w2) .− i) 

(3) 

P̀A ∀i(i ≤ L(w2) → (w2 ⊕ (v2, 0))i = (v1, w1)L(w2) .− i) → v1 = v2 (4) 

P̀A ∀i(i ≤ L(w2) → (w2 ⊕ (v2, 0))i = (v1, w1)L(w2) .− i) → 

∀i(i \< L(w2) → (w2)i = (w1)L(w2) .−(i+1)). 

(5) 

Property (2) is a consequence of 12.1.9(8). Property (3) is proved as follows. Assume the antecedent of the property, take any i ≤ L(w2), and consider two cases. If i \< L(w2) then we have 

(w2 ⊕ (v2, 0))i 12.1.9(9) 

= (w2)i hyp = (w1)L(w2) 

.−(i+1) = (v1, w1)L(w2) .− i. 

If i = L(w2) then we have 

(w2 ⊕ (v2, 0))L(w2) 12.1.9(10) 

= (v2, 0)0 = v2 hyp = v1 = (w1)L(w2) 

.−L(w2). 

Property (4) is obtained by instantiating its antecedent by i := L(w2): 

v1 = (v1, w1)L(w2) .−L(w2) 

hyp = (w2 ⊕ (v2, 0))L(w2) 

12\.1.9(10) = (v2, 0)0 = v2. 

Property (5) is proved as follows. Assume the antecedent of the property, take any i \< L(w2), and we have 

(w2)i 12.1.9(9) 

= (w2 ⊕ (v2, 0))i hyp = (v1, w1)L(w2) 

.− i = (w1)L(w2) .−(i+1). 

12\.1.15 Fast list reversal. The function Rev repeatedly invokes list con- catenation to append an element to the end of a list. Namely, it takes O(L(x)2) operations to compute Rev(x). This is clearly wasteful and we can ask the question wether Rev(x) cannot be computed in O(L(x)) steps. By accumulating the reversed list into an accumulator a we can perform the reversal of x in O(L(x)) operations with the help of an accumulator function. The binary accumulator function f(x, a) is defined by list recursion on x with substitution in parameter: 

f(0, a) = a f((v, w), a) = f(w, v, a). 

307

We have 

P̀A Rev(x) = f(x, 0) (1) 

as a simple consequence of a more general property 

P̀A ∀a f(x, a) = Rev(x)⊕ a. (2) 

Property (2) is proved by list induction. The base case is straightforward and in the inductive case we have 

f((v, w), a) def= f(w, v, a) IH= Rev(w)⊕ (v, a) = 

= Rev(w)⊕ (v, 0)⊕ a def= Rev(v, w)⊕ a. 

12\.2 Operations on Lists 

12\.2.1 List modification. The list modification function x\[i := a\] takes a list x and yields a new list with i-th element replaced by a. The function satisfies 

P̀A i \< L(x) → L(x\[i := a\]) = L(x) (1) 

P̀A i \< L(x) → (x\[i := a\])i = a (2) 

P̀A i \< L(x) ∧ j \< L(x) ∧ j 6= i → (x\[i := a\])j = (x)j (3) 

and it is defined by primitive recursion on i with substitution in parameter x as a primitive recursive function: 

(v, w)\[0 := a\] = a, w (v, w)\[i + 1 := a\] = v, w\[i := a\]. 

Property ∀x(1) is proved by induction on i. In the base case take any x and assume 0 \< L(x). Then x = v, w for some v and w and we have 

L((v, w)\[0 := a\]) def= L(a,w) = L(w) + 1 = L(v, w). 

In the induction case take any x and assume i + 1 \< L(x). Then x = v, w for some v and w, and thus i \< L(w). We have 

L((v, w)\[i + 1 := a\]) def= L(v, w\[i := a\]) = L(w\[i := a\]) + 1 IH= 

= L(w) + 1 = L(v, w). 

Property ∀x(2) is proved by induction on i. In the base case take any x and assume 0 \< L(x). Then x = v, w for some v and w and we have 

((v, w)\[0 := a\])0 def= (a,w)0 = a. 

308

In the inductive case take any x and assume i + 1 \< L(x). Then x = v, w for some v and w, and thus i \< L(w). We have 

((v, w)\[i + 1 := a\])i+1 def= (v, w\[i := a\])i+1 = (w\[i := a\])i 

IH= a. 

Property ∀x∀j(3) is proved by induction on i. In the base case take any x and j, and assume 0 \< L(x), j 6= 0, and j \< L(x). Then x = v, w for some v and w, and j = k + 1 for some k. We have 

((v, w)\[0 := a\])k+1 def= (a,w)k+1 = (w)k = (v, w)k+1. 

In the inductive case take any x and j, and assume i + 1 \< L(x), j 6= i, and j \< L(x). Then x = v, w for some v and w, and thus i \< L(w). We consider two cases. If j = 0 then we have 

((v, w)\[i + 1 := a\])0 def= (v, w\[i := a\])0 = v = (v, w)0. 

If j = k + 1 for some k then k 6= i and k \< L(w). We have 

((v, w)\[i + 1 := a\])k+1 def= (v, w\[i := a\])k+1 = (w\[i := a\])k 

IH= 

= (w)k = (v, w)k+1 

12\.2.2 Map. Let f(x) be arbitrary but fixed function. The function Map(x) applies f to each element of a list. The function satisfies 

P̀A LMap(x) = L(x) (1) 

P̀A i \< L(x) → (Map(x))i = f((x)i) (2) 

and it is defined by list recursion as a primitive recursive function in f : 

Map(0) = 0 Map(v, w) = f(v),Map(w). 

Property (1) is proved by a straightforward list induction. Property ∀i(2) is proved by list induction on x. In the base case there is nothing to prove. In the inductive case when x = v, w take any i such that i \< L(v, w) = L(w)+1 and consider two cases. If i = 0 then we have 

(Map(v, w))0 def= (f(v),Map(w))0 = f(v) = f((v, w)0). 

If i = j + 1 for some j then j \< L(w) and we have 

(Map(v, w))j+1 def= (f(v),Map(w))j+1 = (Map(w))j 

IH= 

= f((w)j) = f((v, w)j+1). 

309

12\.2.3 Zip and unzip. The function Zip(x, y) takes two lists of the same length and yields a list of pairs of the corresponding elements. The function satisfies 

P̀A L(x) = L(y) → LZip(x, y) = L(x) (1) 

P̀A L(x) = L(y) ∧ i \< L(x) → (Zip(x, y))i = (x)i, (y)i (2) 

and it is defined by list recursion with substitution in parameter as a primitive recursive function: 

Zip(0, 0) = 0 Zip((v1, w1), v2, w2) = (v1, v2),Zip(w1, w2). 

The function Unzip(z) - the inverse of Zip, takes a list of pairs to a pair of lists. The function satisfies 

P̀A L(x) = L(y) → Unzip Zip(x, y) = x, y (3) 

and it is defined by list recursion as a primitive recursive function: 

Unzip(0) = 0, 0 Unzip((v1, v2), w) = (v1, w1), v2, w2 ← Unzip(w) = w1, w2. 

Property ∀y(1) is proved by list induction on x. In the base case take any y and assume L(0) = L(y). Then y = 0 and we are done since LZip(0, 0) = L(0) from the definition. In the inductive case when x = v1, w1 take any y and assume L(v1, w1) = L(w1) + 1 = L(y). Then y = v2, w2 for some v2 and w2, and thus L(w1) = L(w2). We have 

LZip((v1, w1), v2, w2) def= L((v1, v2),Zip(w1, w2)) = LZip(w1, w2) + 1 IH= 

= L(w1) + 1 = L(v1, w1). 

Property ∀x∀y(2) is proved by induction on i. In the base case take any x and y such that 0 \< L(x) = L(y). Then x = v1, w1 and y = v2, w2 for some vi and wi. Clearly L(w1) = L(w2) and thus we obtain 

(Zip((v1, w1), v2, w2))0 def= ((v1, v2),Zip(w1, w2))0 = 

= v1, v2 = (v1, w1)0, (v2, w2)0. 

In the inductive case take any x and y such that i + 1 \< L(x) = L(y). Then x = v1, w1 and y = v2, w2 for some vi and wi. Clearly i \< L(w1) = L(w2) and thus we obtain 

(Zip((v1, w1), v2, w2))i+1 def= ((v1, v2),Zip(w1, w2))i+1 = (Zip(w1, w2))i 

IH= 

= (w1)i, (w2)i = (v1, w1)i+1, (v2, w2)i+1. 

Property ∀y(3) is proved by list induction on x and is left to the reader. 

310

12\.2.4 Interval. The function \[m .. n\] yields the list of numbers from m to n. The function satisfies 

P̀A L \[m.. n\] = n + 1 .−m (1) 

P̀A i \< n + 1 .−m → (\[m .. n\])i = m + i (2) 

and it is defined by course of values recursion with measure n + 1 .−m as a primitive recursive function: 

\[m.. n\] = 0 ← m \> n \[m.. n\] = m, \[m + 1 .. n\] ← m ≤ n. 

Property (1) is proved by measure induction with measure n + 1 .−m. Take any m,n and consider two cases. If m \> n then we have 

L \[m.. n\] def= L(0) = 0 = n + 1 .−m. 

If m ≤ n then we have 

L \[m.. n\] def= L(m, \[m + 1 .. n\]) = L \[m + 1 .. n\] + 1 IH= 

= n + 1 .−(m + 1) + 1 = n + 1 .−m. 

Property ∀i(2) is proved by measure induction with measure n+1 .−m. Take any m,n, i such that i \< n + 1 .−m and consider two cases. If m \> n then there is nothing to prove. If m ≤ n then consider two cases. If i = 0 then we have 

(\[m.. n\])0 def= (m, \[m + 1 .. n\])0 = m = m + 0. 

If i = j + 1 for some j then j \< n + 1 .−m .− 1 = n + 1 .−(m + 1). We have 

(\[m.. n\])j+1 def= (m, \[m + 1 .. n\])j+1 = (\[m + 1 .. n\])j 

IH= 

= (m + 1) + j = m + (j + 1). 

12\.2.5 Elements with even and odd indices. The function Ieven(x) returns the list of all elements occurring in a list at even indices. The function satisfies 

P̀A L Ieven(x) = (L(x) + 1)÷ 2 (1) 

P̀A 2 · i \< L(x) → (Ieven(x))i = (x)2 · i (2) 

and it is defined by by course of values recursion with measure L(x) as a primitive recursive function: 

Ieven(0) = 0 Ieven(u, 0) = u, 0 Ieven(u, v, w) = u, Ieven(w). 

311

The function Iodd(x) returns the list of all elements occurring in a list at odd indices. The function satisfies 

P̀A L Iodd(x) = L(x)÷ 2 (3) 

P̀A 2 · i + 1 \< L(x) → (Iodd(x))i = (x)2 · i+1 (4) 

and it is defined by course of values recursion with measure L(x) as a primitive recursive function: 

Iodd(0) = 0 Iodd(u, 0) = 0 Iodd(u, v, w) = v, Iodd(w). 

We prove (1) by measure induction with measure L(x). Take any x and consider three cases. If x = 0 then we have 

L Ieven(0) def= L(0) = 0 = (0 + 1)÷ 2 = (L(0) + 1)÷ 2. 

If x = u, 0 for some u then we have 

L Ieven(u, 0) def= L(u, 0) = 1 = (1 + 1)÷ 2 = (L(u, 0) + 1)÷ 2. 

If x = u, v, w for some u, v, and w, then we have 

L Ieven(u, v, w) def= L(u, Ieven(w)) = L Ieven(w) + 1 IH= (L(w) + 1)÷ 2 + 1 = 

= (L(w) + 3)÷ 2 = (L(u, v, w) + 1)÷ 2. 

We prove ∀i(2) by measure induction with measure L(x). Take any x and i such that 2 · i \< L(x) and consider three cases. If x = 0 then there is nothing to prove since L(0) = 0. If x = u, 0 for some u then 2 · i \< L(u, 0) = 1 yields i = 0. We have 

(Ieven(u, 0))0 def= (u, 0)0 = (u, 0)2 · 0. 

If x = u, v, w for some u, v, and w, then 2 · i \< L(u, v, w) = L(w) + 2. We consider two subcases. If i = 0 then we have 

(Ieven(u, v, w))0 def= (u, Ieven(w))0 = u = (u, v, w)0 = (u, v, w)2 · 0. 

If i = j + 1 for some j then 2 · j \< L(w) and we have 

(Ieven(u, v, w))j+1 def= (u, Ieven(w))j+1 = (Ieven(w))j 

IH= 

= (w)2 · j = (u, v, w)2 · j+2 = (u, v, w)2 ·(j+1). 

Properties (3) and (4) are proved similarly. 

312

12\.2.6 Combining two lists. Let x and y be lists such that the length of x is at most one more than the length of y. The function Combine(x, y) combines the lists x and y into one list. The function satisfies 

P̀A L(x) = L(y) ∨ L(x) = L(y) + 1 → LCombine(x, y) = L(x) + L(y) (1) 

P̀A (L(x) = L(y) ∨ L(x) = L(y) + 1) ∧ 2 · i \< L(x) + L(y) → (Combine(x, y))2 · i = (x)i 

(2) 

P̀A (L(x) = L(y) ∨ L(x) = L(y) + 1) ∧ 2 · i + 1 \< L(x) + L(y) → (Combine(x, y))2 · i+1 = (y)i 

(3) 

and it is defined by list recursion with substitution in parameter as a primitive recursive function: 

Combine(0, 0) = 0 Combine((v1, w1), 0) = v1, w1 

Combine((v1, w1), v2, w2) = v1, v2,Combine(w1, w2). 

Property ∀y(1) is proved list induction on x. In the base when x = 0 take any y such that L(0) = L(y) ∨ L(0) = L(y) + 1. Then y = 0 and we have 

LCombine(0, 0) def= L(0) = 0 = L(0) + L(0). 

In the inductive case when x = v1, w1 take any y such that L(v1, w1) = L(y) ∨ L(v1, w1) = L(y) + 1 and consider two cases. If y = 0 then we have 

LCombine((v1, w1), 0) def= L(v1, w1) = L(v1, w1) + L(0). 

If y = v2, w2 for some v2 and w2 then L(w1) = L(w2) ∨ L(w1) = L(w2) + 1 and we have 

LCombine((v1, w1), v2, w2) def= L(v1, v2,Combine(w1, w2)) = 

= LCombine(w1, w2) + 2 IH= L(w1) + L(w2) + 2 = L(v1, w1) + L(v2, w2). 

Property ∀y∀i(2) is proved list induction on x. In the base case when x = 0 there is nothing to prove. In the inductive case when x = v1, w1 take any y, i such that L(v1, w1) = L(y)∨L(v1, w1) = L(y)+1 and 2 · i \< L(v1, w1)+L(y). We consider two cases. If y = 0 then i = 0 and we have 

(Combine((v1, w1), 0))2 · 0 def= (v1, w1)0. 

If y = v2, w2 for some v2 and w2 then we consider two subcases. If i = 0 then we have 

(Combine((v1, w1), v2, w2))2 · 0 def= (v1, w1,Combine(w1, w2))0 = 

= v1 = (v1, w1)0. 

313

If i = j + 1 for some j then 2 · j \< L(w1) + L(w2) and we have 

(Combine((v1, w1), v2, w2))2 ·(j+1) def= (v1, w1,Combine(w1, w2))2 · j+2 = 

= (Combine(w1, w2))j IH= (w1)j = (v1, w1)j . 

Property (3) is proved similarly. 

12\.2.7 Take and drop. The function Take(n, x) yields the initial segment of a list x of length n if n ≤ L(x). The function satisfies 

P̀A n ≤ L(x) → LTake(n, x) = n (1) 

P̀A n ≤ L(x) → ∃y x = Take(n, x)⊕ y (2) 

and it is defined by primitive recursion on n with substitution in parameter as a primitive recursive function: 

Take(0, x) = 0 Take(n + 1, v, w) = v,Take(n,w). 

The function Drop(n, x) removes the initial segment of a list x of length n if n ≤ L(x). The function satisfies 

P̀A n ≤ L(x) → LDrop(n, x) = L(x) .−n (3) 

P̀A n ≤ L(x) → ∃y x = y ⊕Drop(n, x) (4) 

and it is defined by primitive recursion on n with substitution in parameter as a primitive recursive function: 

Drop(0, x) = x Drop(n + 1, v, w) = Drop(n,w). 

Property ∀x(1) is proved by induction on n. In the base case take any x and we have 

LTake(0, x) def= L(0) = 0. 

In the inductive case take any x such that n + 1 ≤ L(x). Then x = v, w for some v and w, and n ≤ L(w). We have 

LTake(n + 1, v, w) def= L(v,Take(n,w)) = LTake(n, w) + 1 IH= n + 1. 

Property ∀x(2) is proved by induction on n. In the base case it suffices to take y := x in (2) since Take(0, x) ⊕ x 

def= 0 ⊕ x = x. In the inductive case assume n + 1 ≤ L(x). Then x = v, w for some v and w. Since n ≤ L(w) we get from IH that w = Take(n, w)⊕ y for some y. We have 

v, w = v,Take(n,w)⊕ y = (v,Take(n,w))⊕ y def= Take(n + 1, v, w)⊕ y. 

Properties (3) and (4) are left to the reader. 

314

12\.2.8 Minimum and maximum of lists. The function Minl(x) yields the minimum of a non-empty list. The function satisfies 

P̀A x 6= 0 → Minl(x) ε x (1) 

P̀A x 6= 0 ∧ a ε x → Minl(x) ≤ a (2) 

and it is defined by list recursion as a primitive recursive function: 

Minl(v, w) = v ← w = 0 Minl(v, w) = min(v,Minl(w)) ← w 6= 0. 

The function Maxl(x) yields the maximum of a non-empty list. The function satisfies 

P̀A x 6= 0 → Maxl(x) ε x (3) 

P̀A x 6= 0 ∧ a ε x → a ≤ Maxl(x) (4) 

and it is defined by list recursion as a primitive recursive function: 

Maxl(v, w) = v ← w = 0 Maxl(v, w) = max(v,Maxl(w)) ← w 6= 0. 

Property (1) is proved by list induction. In the base case there is nothing to prove. The inductive case when x = v, w is a consequence of the following simple case analysis: 

w = 0 ⇒ Minl(v, 0) def= v ε v, 0 

w 6= 0 ∧ v ≤ Minl(w) ⇒ Minl(v, w) def= v ε v, w 

w 6= 0 ∧ v \> Minl(w) ⇒ Minl(v, w) def= Minl(w) IH ε w ⇒ Minl(v, w) ε v, w. 

Property (2) is proved by list induction. In the base case there is nothing to prove. In the inductive case when x = v, w assume a ε v, w and consider two cases. If w = 0 then a = v and thus Minl(v, 0) def= v ≤ a. If w 6= 0 then Minl(v, w) ≤ a is a consequence of the following simple case analysis: 

v ≤ Minl(w) ∧ a = v ⇒ Minl(v, w) def= v = a 

v ≤ Minl(w) ∧ a ε w ⇒ Minl(v, w) def= v ≤ Minl(w) IH≤ a 

v \> Minl(w) ∧ a = v ⇒ Minl(v, w) def= Minl(w) \< v = a 

v \> Minl(w) ∧ a ε w ⇒ Minl(v, w) def= Minl(w) IH≤ a. 

Properties (3) and (4) are proved similarly. 

315

12\.2.9 Deleting elements from lists. The function Delall(a, x) removes all occurrences of a in the list x. The function satisfies 

P̀A b ε Delall(a, x) ↔ b ε x ∧ b 6= a (1) 

and it is defined by list recursion on x as a primitive recursive function: 

Delall(a, 0) = 0 Delall(a, v, w) = Delall(a,w) ← a = v Delall(a, v, w) = v,Delall(a,w) ← a 6= v. 

Property (1) is proved by list induction on x. The base case when x = 0 is straightforward since Delall(a, 0) def= 0. In the inductive case when x = v, w consider two case. If a = v then we have 

b ε Delall(a, v, w) def⇔ b ε Delall(a,w) IH⇔ b ε w ∧ b 6= a ⇔ (b = v ∨ b ε w) ∧ b 6= a 

12\.1.11(2)⇔ b ε v, w ∧ b 6= a. 

If a 6= v then we have 

b ε Delall(a, v, w) def⇔ b ε v,Delall(a, w) 12.1.11(2)⇔ b = v ∨ b ε Delall(a,w) IH⇔ 

b = v ∨ b ε w ∧ b 6= a ⇔ (b = v ∨ b ε w) ∧ b 6= a 12.1.11(2)⇔ b ε v, w ∧ b 6= a. 

12\.2.10 Filter. Let A(x) be arbitrary but fixed predicate. The function Filter(x) removes all elements from a list which do not satisfy the predicate. The function satisfies 

P̀A a ε Filter(x) ↔ a ε x ∧A(a) (1) 

and it is defined by list recursion as a primitive recursive predicate in the predicate A: 

Filter(0) = 0 Filter(v, w) = v,Filter(w) ← A(v) Filter(v, w) = Filter(w) ← ¬A(v). 

Property (1) is proved by list induction on x. The base case is straightforward and in the inductive case when x = v, w we consider two cases. If A(v) then we have 

a ε Filter(v, w) def⇔ a ε v,Filter(v, w) 12.1.11(2)⇔ a = v ∨ a ε Filter(w) IH⇔ 

a = v ∨ a ε w ∧A(a) (∗)⇔ (a = v ∨ a ε w) ∧A(a) 

12\.1.11(2)⇔ a ε v, w ∧A(a). 

The equivalence marked by (∗) can be proved by a simple case analysis on whether a = v or a 6= v holds. The case when ¬A(v) is similar. 

316

12\.2.11 Counting the number of occurrences in lists. The function #(a, x) counts the number of occurrences of the element a in the list x. The function is defined by list recursion on x as a primitive recursive function: 

\#(a, 0) = 0 #(a, v, w) = #(a, w) + 1 ← a = v #(a, v, w) = #(a, w) ← a 6= v. 

The function satisfies: 

P̀A ∀a#(a, x) = 0 ↔ x = 0 (1) 

P̀A a ε x ↔ #(a, x) 6= 0 (2) 

P̀A #(a, x⊕ y) = #(a, x) + #(a, y). (3) 

12\.2.12 Removal of duplicates from lists. The function Nodoubles(x) removes duplicates from a list. The function satisfies 

P̀A a ε Nodoubles(x) ↔ a ε x (1) 

P̀A a ε Nodoubles(x) → #(a,Nodoubles(x)) = 1 (2) 

and it is defined by list recursion as a primitive recursive function: 

Nodoubles(0) = 0 Nodoubles(v, w) = Nodoubles(w) ← v ε w Nodoubles(v, w) = v,Nodoubles(w) ← v 6ε w. 

12\.3 Combinatorial Functions over Lists 

12\.3.1 Suffix relation. The binary predicate x A y holds if the list y is a suffix of the list x, ie 

P̀Ax x A y ↔ ∃z x = z ⊕ y. 

The predicate has the following basic properties: 

P̀A 0 A y ↔ y = 0 (1) 

P̀A v, w A y ↔ y = v, w ∨ w A y. (2) 

12\.3.2 Generating suffixes. The function Suffixes(x) returns a list of all suffixes of the list x. The function satisfies 

P̀A y ε Suffixes(x) ↔ x A y (1) 

and it is defined by list recursion as a primitive recursive function: 

Suffixes(0) = 0, 0 Suffixes(v, w) = (v, w),Suffixes(w). 

317

Property (1) is proved by list induction on x. In the base case when x = 0 we have 

y ε Suffixes(0) def⇔ y ε 0, 0 ⇔ y = 0 12.3.1(1)⇔ 0 A y. 

In the inductive case when x = v, w we have 

y ε Suffixes(v, w) def⇔ y ε (v, w),Suffixes(w) ⇔ y = v, w ∨ y ε Suffixes(w) IH⇔ ⇔ y = v, w ∨ w A y 

12\.3.1(2)⇔ v, w A y. 

12\.3.3 Auxiliary function. Consider the function Mape(y, x) defined by by list recursion on x as a primitive recursive function: 

Mape(y, 0) = 0 Mape(y, v, w) = (y, v),Mape(y, w). 

The function satisfies: 

P̀A z ε Mape(y, x) ↔ ∃z1(z1 ε x ∧ z = y, z1). (1) 

12\.3.4 Prefix relation. The binary predicate y @ x holds if the list y is a prefix of the list x, ie 

P̀Ax y @ x ↔ ∃z x = y ⊕ z. 

The predicate has the following basic properties: 

P̀A y @ 0 ↔ y = 0 (1) 

P̀A y @ v, w ↔ y = 0 ∨ ∃z(z @ w ∧ y = v, z). (2) 

12\.3.5 Generating prefixes. The function Prefixes(x) returns a list of all prefixes of the list x. The function satisfies 

P̀A y ε Prefixes(x) ↔ y @ x (1) 

and it is defined by list recursion as a primitive recursive function: 

Prefixes(0) = 0, 0 Prefixes(v, w) = 0,Mape(v,Prefixes(w)). 

Property ∀y(1) is proved by list induction on x. In the base case when x = 0 take any y and we have 

y ε Prefixes(0) def⇔ y ε 0, 0 ⇔ y = 0 12.3.4(1)⇔ y @ 0. 

In the inductive case when x = v, w take any y and we have 

318

y ε Prefixes(v, w) def⇔ y ε 0,Mape(v,Prefixes(w)) ⇔ ⇔ y = 0 ∨ y ε Mape(v,Prefixes(w)) 

12\.3.3(1)⇔ ⇔ y = 0 ∨ ∃z(z ε Prefixes(w) ∧ y = v, z) IH⇔ ⇔ y = 0 ∨ ∃z(z @ w ∧ y = v, z) 

12\.3.4(2)⇔ y @ v, w. 

12\.3.6 Segments. The binary predicate y ⊂ x holds if the list y is a con- tiguous segment of the list x, ie 

P̀Ax y ⊂ x ↔ ∃z1∃z2 x = z1 ⊕ y ⊕ z2. 

The predicate has the following basic properties: 

P̀A y ⊂ 0 ↔ y = 0 (1) 

P̀A y ⊂ v, w ↔ ∃z(z @ w ∧ y = v, z) ∨ y ⊂ w. (2) 

12\.3.7 Generating segments. The function Segments(x) returns a list of all segments of the list x. The function satisfies 

P̀A y ε Segments(x) ↔ y ⊂ x (1) 

and it is defined by list recursion as a primitive recursive function: 

Segments(0) = 0, 0 Segments(v, w) = Mape(v,Prefixes(w))⊕ Segments(w). 

Property (1) is proved by list induction on x. In the base case when x = 0 we have 

y ε Segments(0) def⇔ y ε 0, 0 ⇔ y = 0 12.3.6(1)⇔ y ⊂ 0. 

In the inductive case when x = v, w we have 

y ε Segments(v, w) def⇔ y ε Mape(v,Prefixes(w))⊕ Segments(w) ⇔ ⇔ y ε Mape(v,Prefixes(w)) ∨ y ε Segments(w) 

12\.3.3(1),IH⇔ ⇔ ∃z(z ε Prefixes(w) ∧ y = v, z) ∨ y ⊂ w 

12\.3.5(1)⇔ ⇔ ∃z(z @ w ∧ y = v, z) ∨ y ⊂ w 

12\.3.6(2)⇔ y ⊂ v, w. 

12\.3.8 Subsequences. The binary predicate y / x holds if the list y is a subsequence of the list x. The predicate y / x is defined by list recursion on x with substitution in parameter y:: 

y / 0 ← y = 0 y / v1, w1 ← y = 0 y / v1, w1 ← y = v2, w2 ∧ v2 = v1 ∧ w2 / w1 

y / v1, w1 ← y = v2, w2 ∧ v2 6= v1 ∧ y / w1. 

319

The predicate has the following basic properties: 

P̀A y / 0 ↔ y = 0 (1) 

P̀A y / v, w ↔ ∃z(z / w ∧ y = v, z) ∨ y / w. (2) 

12\.3.9 Generating subsequences. The function Subsqs(x) returns a list of all subsequences of the list x. The function satisfies 

P̀A y ε Subsqs(x) ↔ y / x (1) 

and it is defined by list recursion as a primitive recursive function: 

Subsqs(0) = 0, 0 Subsqs(v, w) = Mape(v,Subsqs(w))⊕ Subsqs(w). 

Property ∀y(1) is proved by list induction on x. In the base case when x = 0 take any y and we have 

y ε Subsqs(0) def⇔ y ε 0, 0 ⇔ y = 0 12.3.8(1)⇔ y / 0. 

In the inductive case when x = v, w take any y and we have 

y ε Subsqs(v, w) def⇔ y ε Mape(v,Subsqs(w))⊕ Subsqs(w) ⇔ ⇔ y ε Mape(v,Subsqs(w)) ∨ y ε Subsqs(w) 

12\.3.3(1),IH⇔ ⇔ ∃z(z ε Subsqs(w) ∧ y = v, z) ∨ y / w 

IH⇔ ⇔ ∃z(z / w ∧ y = v, z) ∨ y / w 

12\.3.8(2)⇔ y / v, w. 

12\.3.10 Insertion relation. The ternary predicate y ≈ x\[↓ a\] holds if the list y is obtained from the list x by insertion of a into x, ie 

P̀Ax y ≈ x\[↓ a\] ↔ ∃z1∃z2(x = z1 ⊕ z2 ∧ y = z1 ⊕ (a, z2)). 

The predicate has the following basic properties: 

P̀A y ≈ 0\[↓ a\] ↔ y = a, 0 

P̀A y ≈ (v, w)\[↓ a\] ↔ y = a, v, w ∨ ∃z(z ≈ w\[↓ a\] ∧ y = v, z). 

12\.3.11 Permutations. The binary predicate y ∼ x holds if the list y is a permutation of the list x. The predicate is defined explicitly as follows 

P̀Ax x ∼ y ↔ ∀a #(a, x) = #(a, y). 

The predicate has the following basic properties: 

P̀A y ∼ 0 ↔ y = 0 (1) 

P̀A y ∼ v, w ↔ ∃z(z ∼ w ∧ y ≈ z\[↓ v\]). (2) 

320

12\.3.12 Generating permutations. The function Perms(x) returns a list of all permutations of the list x. The function satisfies 

P̀A y ε Perms(x) ↔ y ∼ x (1) 

and it is defined by list recursion as a primitive recursive function: 

Interleave(y, 0) = (y, 0), 0 Interleave(y, v, w) = (y, v, w),Mape(v, Interleave(y, w)) 

Mapi(y, 0) = 0 Mapi(y, v, w) = Interleave(y, v)⊕Mapi(y, w) 

Perms(0) = 0, 0 Perms(v, w) = Mapi(v,Perms(w)). 

Note that the functions Interleave(y, x) and Mapi(y, x) are defined by list recursion on x. 

The auxiliary functions satisfy 

P̀A z ε Interleave(y, x) ↔ z ≈ x\[↓ y\] (2) 

P̀A z ε Mapi(y, x) ↔ ∃z1(z1 ε x ∧ z ≈ z1\[↓ y\]). (3) 

Property ∀y(1) is proved by list induction on x. In the base case when x = 0 take any y and we have 

y ε Perms(0) def⇔ y ε 0, 0 ⇔ y = 0 12.3.11(1)⇔ y ∼ 0. 

In the inductive case when x = v, w take any y and we have 

y ε Perms(v, w) def⇔ y ε Mapi(v,Perms(w)) (3)⇔ 

⇔ ∃z(z ε Perms(w) ∧ y ≈ z\[↓ v\]) IH⇔ ⇔ ∃z(z ∼ w ∧ y ≈ z\[↓ v\]) 

12\.3.11(2)⇔ ⇔ y ∼ v, w. 

12\.3.13 List partitions. The binary predicate y J x holds if the list y is a partition of the list x, ie 

P̀Ax y J x ↔ ⋃ 

y = x ∧ 0 6ε y, 

where ⋃ 

y is the list union function defined by list recursion: ⋃ 

0 = 0⋃ (v, w) = v ⊕⋃ 

w. 

The predicate has the following basic properties: 

P̀A y J 0 ↔ y = 0 (1) 

P̀A y J v, w ↔ ∃z(z J w ∧ y = (v, 0), z) ∨ ∃z1∃z2(z1, z2 J w ∧ y = (v, z1), z2). 

(2) 

321

12\.3.14 Generating list partitions. The function Concps(x) returns a list of all partitions of the list x. The function satisfies 

P̀A y ε Concps(x) ↔ y J x (1) 

and it is defined by list recursion as a primitive recursive function: 

Mapc1(y, 0) = 0 Mapc1(y, v, w) = ((y, 0), v),Mapc1(y, w) 

Mapc2(y, 0) = 0 Mapc2(y, 0, w) = Mapc2(y, w) Mapc2(y, (v1, v2), w) = ((y, v1), v2),Mapc2(y, w) 

Concps(0) = 0, 0 Concps(v, w) = Mapc1(v,Concps(w))⊕Mapc2(v,Concps(w)). 

Note that the functions Mapc1(y, x) and Mapc2(y, x) are defined by list re- cursion on x. 

The auxiliary functions satisfy 

P̀A z ε Mapc1(y, x) ↔ ∃z1(z1 ε x ∧ z = (y, 0), z1) (2) 

P̀A z ε Mapc2(y, x) ↔ ∃z1∃z2(z1, z2 ε x ∧ z = (y, z1), z2). (3) 

Property ∀y(1) is proved by list induction on x. In the base case when x = 0 take any y and we have 

y ε Concps(0) def⇔ y ε 0, 0 ⇔ y = 0 12.3.13(1)⇔ y J 0. 

In the inductive case when x = v, w take any y and we have 

y εConcps(v, w) def⇔ ⇔ y ε Mapc1(v,Concps(w))⊕Mapc2(v,Concps(w)) ⇔ ⇔ y ε Mapc1(v,Concps(w)) ∨ y ε Mapc2(v,Concps(w)) 

(2),(3)⇔ ⇔ ∃z(z ε Concps(w) ∧ y = (v, 0), z)∨ 

∨ ∃z1∃z2(z1, z2 ε Concps(w) ∧ y = (v, z1), z2) 2×IH⇔ 

⇔ ∃z(z J w ∧ y = (v, 0), z)∨ ∨ ∃z1∃z2(z1, z2 J w ∧ y = (v, z1), z2) 

12\.3.13(2)⇔ ⇔ y J v, w. 

12\.4 Sorting of Lists 

12\.4.1 The problem of sorting. 

322

12\.4.2 Permutations. Recall that the binary predicate x ∼ y holding if the list x is a permutation of the list y is defined explicitly by 

P̀Ax x ∼ y ↔ ∀a #(a, x) = #(a, y). 

The predicate has the following properties: 

P̀A x ∼ x (1) 

P̀A x ∼ y → y ∼ x (2) 

P̀A x ∼ y ∧ y ∼ z → x ∼ z (3) 

P̀A x ∼ y → a, x ∼ a, y (4) 

P̀A x ∼ y → L(x) = L(y) (5) 

P̀A x1 ∼ y1 ∧ x2 ∼ y2 → x1 ⊕ x2 ∼ y1 ⊕ y2 (6) 

P̀A x ∼ y ∧ a ε x → a ε y (7) 

P̀A 0 ∼ y ↔ y = 0 (8) 

P̀A a, b, x ∼ b, a, x (9) 

P̀A x1 ⊕ (a, x2) ∼ y1 ⊕ (a, y2) ↔ x1 ⊕ x2 ∼ y1 ⊕ y2 (10) 

P̀A x ∼ v, w ↔ ∃z1∃z2(x = z1 ⊕ (v, z2) ∧ w ∼ z1 ⊕ z2) (11) 

P̀A x ∼ v, w ↔ ∃z(z ∼ w ∧ x ≈ z\[↓ v\]). (12) 

Properties (1)-(4), (8), and (9) have straightforward proofs. Properties (6) and (10) follow from 12.2.11(3). Property (7) follows from 12.2.11(2). 

The (→)-direction of (11) is proved as follows. Assume x ∼ v, w. Then v ε x by (7) and thus x = z1 ⊕ (v, z2) for some z1 and z2 by 12.6.1(1). Note also that w ∼ z1 ⊕ z2 by (10). The (←)-direction of (11) follows from (10). 

Property (12) follows from 

x ∼ v, w (11)⇔ ∃z1∃z2(x = z1 ⊕ (v, z2) ∧ w ∼ z1 ⊕ z2) ⇔ 

∃z3∃z4 

(∃z1∃z2(x = z1 ⊕ (v, z2) ∧ z3 ⊕ z4 = z1 ⊕ z2) ∧ w ∼ z3 ⊕ z4 

) def⇔ ∃z3∃z4(x ≈ (z3 ⊕ z4)\[↓ v\] ∧ w ∼ z3 ⊕ z4) ⇔ ∃z(z ∼ w ∧ x ≈ z\[↓ v\]). 

Property ∀y(5) is proved by list induction on x. The base case is straight- forward. In the inductive case when x = v, w take any y such that v, w ∼ y. Then y = z1 ⊕ (v, z2) and w ∼ z1 ⊕ z2 for some z1 and z2 by (11). We have 

L(v, w) = L(w) + 1 IH= L(z1 ⊕ z2) + 1 12.1.9(8) 

= L(z1) + L(z2) + 1 = 

= L(z1) + L(v, z2) 12.1.9(8) 

= L(z1 ⊕ (v, z2)). 

12\.4.3 List comparision predicates. The predicate a ¹ x holds if a ≤ b for every element b of the list x, ie 

P̀Ax a ¹ x ↔ ∀b(b ε x → a ≤ b). 

323

The predicate satisfies 

P̀A a ¹ 0 (1) 

P̀A a ¹ v, w ↔ a ≤ v ∧ a ¹ w (2) 

P̀A a ≤ b ∧ b ¹ x → a ¹ x (3) 

P̀A a ¹ x⊕ y ↔ a ¹ x ∧ a ¹ y (4) 

P̀A x ∼ y → a ¹ x ↔ a ¹ y. (5) 

The predicate a º x holds if a ≥ b for every element b of the list x, ie 

P̀Ax a º x ↔ ∀b(b ε x → a ≥ b). 

The predicate satisfies 

P̀A a º 0 (6) 

P̀A a º v, w ↔ a ≥ v ∧ a º w (7) 

P̀A a ≥ b ∧ b º x → a º x (8) 

P̀A a º x⊕ y ↔ a º x ∧ a º y (9) 

P̀A x ∼ y → a º x ↔ a º y. (10) 

The predicate x ¹s y holds if a ≤ b for every elements a and b of the lists x and y respectively, ie 

P̀Ax x ¹s y ↔ ∀a∀b(a ε x ∧ b ε y → a ≤ b). 

The predicate satisfies 

P̀A 0 ¹s y (11) 

P̀A v, w ¹s y → v ¹ y ∧ w ¹s y (12) 

P̀A x ¹s 0 (13) 

P̀A x ¹s v, w ↔ v º x ∧ x ¹s w (14) 

P̀A a º x ∧ a ¹ y → x ¹s y. (15) 

Properties (1)-(3) are straightforward. Property (4) is proved by list in- duction on x. The base case follows from (1). In the inductive case we have 

a ¹ (v, w)⊕ y ⇔ a ¹ v, w ⊕ y (2)⇔ a ≤ v ∧ a ¹ w ⊕ y 

IH⇔ a ≤ v ∧ a ¹ w ∧ a ¹ y 

(2)⇔ a ¹ v, w ∧ a ¹ y. 

Property ∀y(5) is proved by list induction on x. The base case is straight- forward. In the inductive case when x = v, w take any y such that v, w ∼ y. Then y = z1 ⊕ (v, z2) and w ∼ z1 ⊕ z2 for some z1 and z2 by 12.4.2(11). We have 

324

a ¹ v, w (2)⇔ a ≤ v ∧ a ¹ w 

IH⇔ a ≤ v ∧ a ¹ z1 ⊕ z2 (4)⇔ 

a ≤ v ∧ a ¹ z1 ∧ a ¹ z2 (2)⇔ a ¹ z1 ∧ a ¹ v, z2 

(4)⇔ a ¹ z1 ⊕ (v, z2). 

Properties (6)-(10) are proved similarly. Properties (11)-(15) are straightfor- ward. 

12\.4.4 Ordered lists. The predicate Ord(x) holds if x is an ordered list. The predicate is defined by 

P̀Ax Ord(x) ↔ ∀i∀j(i ≤ j ∧ j \< L(x) → (x)i ≤ (x)j). 

The predicate has the following basic properties: 

P̀A Ord(0) (1) 

P̀A Ord(v, w) ↔ Ord(w) ∧ v ¹ w (2) 

P̀A Ord(v, w) → a ¹ v, w ↔ a ≤ v (3) 

P̀A Ord(x⊕ y) ↔ Ord(x) ∧Ord(y) ∧ x ¹s y. (4) 

Properties (1)-(3) are straightforward. Property (4) is proved by list induction on x. The base case follows from 12.4.3(11). In the inductive case we have 

Ord((v, w)⊕ y) ⇔ Ord(v, w ⊕ y) (2)⇔ Ord(w ⊕ y) ∧ v ¹ w ⊕ y 

IH,12.4.3(2)⇔ Ord(w) ∧Ord(y) ∧ w ¹s y ∧ v ¹ w ∧ v ¹ y 

(2),12.4.3(12)⇔ Ord(v, w) ∧Ord(y) ∧ v, w ¹s y. 

12\.4.5 Insertion sort. The simplest sorting algorithm is insertion sort . Insertion sort works on a non-empty list by recursively sorting the tail and then inserts the first element into the sorted list. The length of computation is O(L(x)2). 

The insertion function Insert(a, x) takes an ordered list x and yields a new one by inserting a into it. The function satisfies 

P̀A Insert(a, x) ∼ a, x (1) 

P̀A Ord(x) → Ord Insert(a, x) (2) 

and it is defined by list recursion on x as a primitive recursive function: 

Insert(a, 0) = a, 0 Insert(a, v, w) = a, v, w ← a ≤ v Insert(a, v, w) = v, Insert(a,w) ← a \> v. 

The function Isort(x) realizing insertion sort is defined by list recursion as a primitive recursive function: 

Isort(0) = 0 Isort(v, w) = Insert(v, Isort(w)). 

325

We claim that 

P̀A Isort(x) ∼ x (3) 

P̀A Ord Isort(x). (4) 

Property (1) is proved by list induction on x. The base case is straight- forward. In the inductive case when x = v, w we consider two cases. If a ≤ v 

then Insert(a, v, w) def= a, v, w ∼ a, v, w. If a \> v then 

Insert(a, v, w) def= v, Insert(a,w) IH∼ v, a, w ∼ a, v, w. 

As a simple consequence of (1) and 12.4.3(5) we get 

P̀A b ¹ Insert(a, x) ↔ b ≤ a ∧ b ¹ x. (5) 

Property (2) is proved by list induction on x. The base case is straightforward. In the inductive case when x = v, w assume Ord(v, w) and consider two cases. If a ≤ v then we have 

Ord Insert(a, v, w) def⇔ Ord(a, v, w) 12.4.4(2)⇔ Ord(v, w) ∧ a ¹ v, w. 

The last follows from assumptions by 12.4.4(3). If a \> v then we have 

Ord Insert(a, v, w) def⇔ Ord(v, Insert(a,w)) 12.4.4(2)⇔ 

Ord Insert(a,w) ∧ v ¹ Insert(a,w) (5)⇔ Ord Insert(a,w) ∧ v ≤ a ∧ v ¹ w. 

The last follows from assumptions and IH. Property (3) is proved by list induction. The base case is straightforward. 

In the inductive case we have 

Isort(v, w) def= Insert(v, Isort(w)) (1)∼ v, Isort(w) IH∼ v, w. 

Property (4) is proved by list induction. The base case follows from 12.4.4(1). In the inductive case when x = v, w assume Ord(v, w). Then Ord(w) by 12.4.4(2) and we get from IH: 

Ord Isort(w) (2)⇒ Ord Insert(v, Isort(w)) def⇒ Ord Isort(v, w). 

12\.4.6 Merge sort. More efficient sorting algorithm than insertion sort is merge sort . It sorts a list by dividing it into two roughly equal parts. Each part is then recursively sorted and the resulting lists are merged into one list. The length of computation is O(L(x) · log L(x)). 

The function Msplit(x) divides a list into two lists: the length of the first one is at most one more than the length of the second. The function satisfies 

326

P̀A ∃y∃z Msplit(x) = y, z (1) 

P̀A Msplit(x) = y, z → x ∼ y ⊕ z (2) 

P̀A Msplit(x) = y, z → L(x) = L(y) + L(z) ∧ (L(y) = L(z) ∨ L(y) = L(z) + 1) 

(3) 

and it is defined by course of values recursion with measure L(x) as a primitive recursive function: 

Msplit(0) = 0, 0 Msplit(u, 0) = (u, 0), 0 Msplit(u, v, w) = (u, y), v, z ← Msplit(w) = y, z. 

The function Merge(x, y) merges two ordered lists into one list. The function satisfies 

P̀A Merge(x, y) ∼ x⊕ y (4) 

P̀A Ord(x) ∧Ord(y) → Ord Merge(x, y) (5) 

and it is defined by course of values recursion with measure L(x) + L(y) as a primitive recursive function: 

Merge(0, y) = y Merge((v1, w1), 0) = v1, w1 

Merge((v1, w1), v2, w2) = v1,Merge(w1, v2, w2) ← v1 ≤ v2 

Merge((v1, w1), v2, w2) = v2,Merge((v1, w1), w2) ← v1 \> v2. 

Merge sort is realized by the function Msort(x) defined by course of values recursion with measure L(x) as a primitive recursive function: 

Msort(0) = 0 Msort(u, 0) = u, 0 Msort(u, v, w) = Merge(Msort(u, y),Msort(v, z)) ← Msplit(w) = y, z. 

We claim that 

P̀A Msort(x) ∼ x (6) 

P̀A Ord Msort(x). (7) 

Property (1) is proved by measure induction with measure L(x). Property ∀y∀z(2) is proved by the same induction as follows. Take any x, y, and z such that Msplit(x) = y, z and consider three cases. The cases when x = 0 or x = u, 0 are straightforward. So suppose x = u, v, w for some u, v, and w. By (1) there are y1 and z1 such that Msplit(w) = y1, z1. We have 

u, v, w IH∼ u, v, y1 ⊕ z1 ∼ (u, y1)⊕ (v, z1) 

def= y ⊕ z. 

As a simple consequence of (2) and 12.4.2(5) we get 

327

P̀A Msplit(x) = y, z → L(x) = L(y) + L(z). (8) 

Property (3) follows from (8) and from 

P̀A ∀y∀z(Msplit(x) = y, z → L(y) = L(z) ∨ L(y) = L(z) + 1) 

which is proved by measure induction on x with measure L(x). Property (4) is proved by measure induction with measure L(x) + L(y). 

Take any x and y and consider the following cases. The cases when x = 0 or y = 0 are straightforward. So suppose x = v1, w1 and y = v2, w2 for some v1, w1, v2, and w2. If v1 ≤ v2 then we have 

Merge((v1, w1), v2, w2) def= v1,Merge(w1, v2, w2) 

IH∼ ∼ v1, w1 ⊕ (v2, w2) = (v1, w1)⊕ (v2, w2). 

The case when v1 \< v2 has a similar proof. As a simple consequence of (4) and 12.4.3(5) we get 

P̀A a ¹ Merge(x, y) ↔ a ¹ x ∧ a ¹ y. (9) 

Property (5) is proved by measure induction with measure L(x)+L(y). Take any x and y and assume Ord(x) and Ord(y). If x = 0 or y = 0 then the property holds trivially. So suppose x = v1, w1 and y = v2, w2 for some v1, w1, v2, and w2. If v1 ≤ v2 then we have 

Ord Merge((v1, w1), v2, w2) def⇔ Ord(v1,Merge(w1, v2, w2)) 

12\.4.4(2)⇔ Ord Merge(w1, v2, w2) ∧ v1 ¹ Merge(w1, v2, w2) 

(9)⇔ Ord Merge(w1, v2, w2) ∧ v1 ¹ w1 ∧ v1 ¹ v2, w2. 

The last follows from IH and from assumptions by 12.4.4(2) and 12.4.4(3). The case when v1 \< v2 is similar. 

Property (6) is proved by measure induction with measure L(x). Take any x and consider three cases. The cases when x = 0 or x = u, 0 for some u are straightforward. So suppose x = u, v, w for some u, v, and w. By (1) there are y and z such that Msplit(w) = y, z. Note that L(u, y) \< L(x) and L(v, z) \< L(x) by (8). We have 

Msort(u, v, w) def= Merge(Msort(u, y),Msort(v, z)) (4)∼ 

∼ Msort(u, y)⊕Msort(v, z) IH∼ (u, y)⊕ (v, z) ∼ u, v, y ⊕ z (2)∼ u, v, w. 

Property (7) is proved by measure induction with measure L(x). Take any x and consider three cases. The cases when x = 0 or x = u, 0 for some u are straightforward. So suppose x = u, v, w for some u, v, and w. By (1) there are y and z such that Msplit(w) = y, z. Note again that L(u, y) \< L(x) and L(v, z) \< L(x) by (8). We have by IH 

328

Ord Msort(u, y) ∧Ord Msort(v, z) (5)⇒ 

Ord Merge(Msort(u, y),Msort(v, z)) def⇒ Ord Msort(u, v, w). 

12\.4.7 Quicksort. One of the most efficient sorting algorithms is quicksort . It sorts a list by selecting one of its elements called pivot . Then it splits the list into two parts: with elements lesser and/or greater than the pivot. Each part is recursively sorted and the resulting lists together with the pivot are concatenated into one ordered list. The length of computation is O(L(x)2) in the worst case and O(L(x) · log L(x)) on average. 

The function Qsplit(p, x) splits a list x according to the pivot p into two lists: the first one with elements ≤ p and the second with elements ≥ p. The function satisfies 

P̀A ∃y∃zQsplit(p, x) = y, z (1) 

P̀A Qsplit(p, x) = y, z → x ∼ y ⊕ z (2) 

P̀A Qsplit(p, x) = y, z → p º y ∧ p ¹ z (3) 

and it is defined by list recursion on x as a primitive recursive function: 

Qsplit(p, 0) = 0, 0 Qsplit(p, v, w) = (v, y), z ← v ≤ p ∧Qsplit(p, w) = y, z Qsplit(p, v, w) = y, v, z ← v \> p ∧Qsplit(p, w) = y, z. 

As a simple consequence of (2) and 12.4.2(5) we get 

P̀A Qsplit(p, x) = y, z → L(x) = L(y) + L(z). (4) 

Quicksort Qsort(x) is defined by course of values recursion with measure L(x) as a primitive recursive function: 

Qsort(0) = 0 Qsort(p, x) = Qsort(y)⊕ (p, 0)⊕Qsort(z) ← Qsplit(p, x) = y, z. 

We claim that 

P̀A Qsort(x) ∼ x (5) 

P̀A Ord Qsort(x). (6) 

Property (1) is proved by a straightforward list induction. Property ∀y∀z(2) is proved by the same induction as follows. The base case is straight- forward. In the inductive case when x = v, w take any y and z such that Qsplit(p, v, w) = y, z and consider two cases. If v ≤ p then Qsplit(w) = y1, z1 

for some y1 and z1 by (1). We have 

v, w IH∼ v, y1 ⊕ z1 = (v, y1)⊕ z1 

def= y ⊕ z. 

The case when v \> p is similar. Property ∀y∀z(3) is proved by list induction on x. The base case is straightforward. In the inductive case when x = v, w 

329

take any y and z such that Qsplit(p, v, w) = y, z and consider two cases. If v ≤ p then Qsplit(w) = y1, z1 for some y1 and z1 by (1). We get from IH the following 

p º y1 ∧ p ¹ z1 12.4.3(7)⇒ p º v, y1 ∧ p ¹ z1 

def⇒ p º y ∧ p ¹ z. 

The case when v \> p is similar. Property (5) is proved by measure induction with measure L(x). Take 

any x and consider two cases. If x = 0 then the property holds trivially. If x = p, x1 then Qsplit(p, x1) = y, z for some y and z by (1). Note that L(y) \< L(x) and L(z) \< L(x) by (4). We have 

Qsort(p, x1) def= Qsort(y)⊕ (p,Qsort(z)) IH∼ y ⊕ (p, z) ∼ p, y ⊕ z 

(2)∼ p, x1. 

As a simple consequence of (5) and the properties 12.4.3(5)(10) we get 

P̀A a ¹ Qsort(x) ↔ a ¹ x (7) 

P̀A a º Qsort(x) ↔ a º x. (8) 

Property (6) is proved by measure induction with measure L(x). Take any x and consider two cases. If x = 0 then the property holds trivially. If x = p, x1 

then Qsplit(p, x1) = y, z for some y and z by (1). Note again that L(y) \< L(x) and L(z) \< L(x) by (4). We have 

Ord Qsort(p, x1) def⇔ Ord(Qsort(y)⊕ (p,Qsort(z))) 

12\.4.4(4)⇔ Ord Qsort(y) ∧Ord(p,Qsort(z)) ∧Qsort(y) ¹s p,Qsort(z) 

12\.4.4(2),12.4.3(14)⇔ Ord Qsort(y) ∧Ord Qsort(z) ∧ ∧ p ¹ Qsort(z) ∧ p º Qsort(y) ∧Qsort(y) ¹s Qsort(z) 

12\.4.3(15)⇔ Ord Qsort(y) ∧Ord Qsort(z) ∧ p º Qsort(y) ∧ p ¹ Qsort(z). 

Conditions Ord Qsort(y) and Ord Qsort(z) follows from IH and conditions p º Qsort(y) and p ¹ Qsort(z) are simple consequences of (3), (7), and (8). 

12\.5 Applications of Lists 

Finite sets 

12\.5.1 List comparision predicate. The predicate a ≺ x holds if a \< b for every element b of the list x, ie 

P̀Ax a ≺ x ↔ ∀b(b ε x → a \< b). 

The predicate has the following easy to prove properties: 

330

P̀A a ≺ 0 (1) 

P̀A a ≺ v, w ↔ a \< v ∧ a ≺ w (2) 

P̀A a ≺ x → a ¹ x (3) 

P̀A a ≤ b ∧ b ≺ x → a ≺ x. (4) 

12\.5.2 Finite sets. The predicate Set(s) holds if s is a (code of) finite set of natural numbers. The predicate is defined by 

P̀Ax Set(s) ↔ ∀i∀j(i \< j ∧ j \< L(s) → (s)i \< (s)j). 

The predicate has the following easy to prove properties: 

P̀A Set(0) (1) 

P̀A Set(a, s) ↔ Set(s) ∧ a ≺ s (2) 

P̀A Set(a, s) → b ≺ a, s ↔ b \< a (3) 

P̀A Set(a, s) → a 6ε s. (4) 

12\.5.3 Set membership. The set membership predicate x ∈ a has the following basic property 

P̀A Set(s) → a ∈ s ↔ a ε s (1) 

and it is defined by list recursion on s as a primitive recursive predicate: 

a ∈ b, s ← a = b a ∈ b, s ← a \> b ∧ a ∈ s. 

Property (1) is proved by a straightforward list induction on s. 

12\.5.4 Set insertion. The function {a} ∪ s inserts a into the set s. The function satisfies 

P̀A Set(s) → Set({a} ∪ s) (1) 

P̀A Set(s) → b ∈ {a} ∪ s ↔ b = a ∨ b ∈ s (2) 

and it is defined by list recursion on s as a primitive recursive function: 

{a} ∪ 0 = a, 0 {a} ∪ (b, s) = a, b, s ← a \< b {a} ∪ (b, s) = b, s ← a = b {a} ∪ (b, s) = b, {a} ∪ s ← a \> b. 

First note that 

P̀A b ε {a} ∪ s ↔ b = a ∨ b ε s. (3) 

331

Property (3) is proved by list induction on s. The base case is straightforward. In the inductive case when s = c, s1 we consider three cases. If a \< c then we have 

b ε {a} ∪ (c, s1) def⇔ b ε a, c, s1 ⇔ b = a ∨ b ε c, s1. 

If a = c then we have 

b ε {c} ∪ (c, s1) def⇔ b ε c, s1 ⇔ b = c ∨ b ε c, s1. 

If a \> c then we have 

b ε {a} ∪ (c, s1) def⇔ b ε c, {a} ∪ s1 ⇔ b = c ∨ b ε {a} ∪ s1 

IH⇔ ⇔ b = c ∨ b = a ∨ b ε s1 ⇔ b = a ∨ b ε c, s1. 

As a simple consequence of (3) we get 

b ≺ {a} ∪ s ↔ b ≺ a, s. (4) 

Property (1) is proved by list induction on s. The base case is straightfor- ward. In the inductive case, when s = b, s1, assume Set(b, s1) and consider three cases. If a \< b then we have 

Set({a} ∪ (b, s1)) def⇔ Set(a, b, s1) 

12\.5.2(2)⇔ Set(b, s1) ∧ a ≺ b, s1. 

The last follows from assumptions by 12.5.2(3). If a \> b then we have 

Set({a} ∪ (b, s1)) def⇔ Set(b, {a} ∪ s1) 

12\.5.2(2)⇔ Set({a} ∪ s1) ∧ b ≺ {a} ∪ s1 (4)⇔ 

Set({a} ∪ s1) ∧ b ≺ a, s1 12.5.1(2)⇔ Set({a} ∪ s1) ∧ b \< a ∧ b ≺ s1 

The last follows from IH and 12.5.2(2). The case when a = b is trivial. Property (2) is a straighforward consequence of 12.5.3(1), (1), and (3). 

12\.5.5 Set deletion. The function s \\ {a} deletes a from the set s. The function satisfies 

P̀A Set(s) → Set(s \\ {a}) (1) 

P̀A Set(s) → b ∈ s \\ {a} ↔ b ∈ s ∧ b 6= a (2) 

and it is defined by list recursion on s as a primitive recursive function: 

0 \\ {a} = 0 (b, s) \\ {a} = b, s \\ {a} ← b \< a (b, s) \\ {a} = s ← b = a (b, s) \\ {a} = b, s ← b \> a. 

332

First note that 

P̀A Set(s) → b ε s \\ {a} ↔ b ε s ∧ b 6= a. (3) 

Property (3) is proved by list induction on s. The base case is straightforward. In the inductive case, when s = c, s1, assume Set(c, s1) and consider three cases. If c \< a then we have 

b ε (c, s1) \\ {a} def⇔ b ε c, s1 \\ {a} ⇔ b = c ∨ b ε s1 \\ {a} IH⇔ b = c ∨ b ε s1 ∧ b 6= a ⇔ b ε c, s1 ∧ b 6= a. 

If c = a then, since a 6ε s1 by 12.5.2(4), we have 

b ε (a, s1) \\ {a} def⇔ b ε s1 ⇔ b ε a, s1 ∧ b 6= a. 

If c \> a then a 6ε c, s1 by 12.5.2(3) and definition of ≺. We have 

b ε (c, s1) \\ {a} def⇔ b ε c, s1 ⇔ b ε c, s1 ∧ b 6= a. 

As a simple consequence of (3) we get 

Set(s) ∧ b \< a → b ≺ s \\ {a} ↔ b ≺ s. (4) 

Property (1) is proved by list induction on s. The base case is straightfor- ward. In the inductive case, when s = b, s1, assume Set(b, s1) and consider three cases. If b \> a then the property trivially holds by definition. If b = a then the property follows from 12.5.2(2). If b \< a then we have 

Set((b, s1) \\ {a}) def⇔ Set(b, s1 \\ {a}) 12.5.2(2)⇔ Set(s1 \\ {a}) ∧ b ≺ s1 \\ {a} (4)⇔ Set(s1 \\ {a}) ∧ b ≺ s1 

The last follows from IH and 12.5.2(2). Property (2) is a straighforward consequence of 12.5.3(1), (1), and (3). 

Polynomials 

12\.5.6 Polynomials. We will consider polynomials in one variable X with coefficients in N. We say that a number p codes a polynomial P (X): 

P (X) ≡ ∞∑ 

i=0 

ai ·Xi 

if for every number i we have (p)i = ai. The predicate p ∼ q holds if the numbers p and q code the same polyno- 

mial, ie 

333

P̀Ax p ∼ q ↔ ∀i (p)i = (q)i. 

The predicate satisfies 

P̀A p ∼ p (1) 

P̀A p ∼ q → q ∼ p (2) 

P̀A p ∼ q ∧ q ∼ r → p ∼ r (3) 

P̀A p ∼ q → a, p ∼ a, q (4) 

P̀A a, p ∼ b, q ↔ a = b ∧ p ∼ q (5) 

P̀A a, p ∼ 0 ↔ a = 0 ∧ p ∼ 0. (6) 

The denotation function p(x) takes the code p of a polynomial P (X) and an assignment x and returns the value of P (X) when the variable X takes x as its value. The function p(x) is defined by list recursion on p as a primitive recursive function: 

0(x) = 0 (a, p)(x) = a + x · p(x). 

The denotation function satisfies 

p ∼ q ↔ ∀x p(x) = q(x). (7) 

In the sequel we identify polynomials with their codes. 

12\.5.7 Addition of polynomials. The function p+++++++++ q returns the addition of the polynomials p and q. The function satisfies 

P̀A (p+++++++++ q)(x) = p(x) + q(x) (1) 

P̀A p ∼ q ∧ r ∼ s → p+++++++++ r ∼ q+++++++++ s (2) 

and it is defined by list recursion with substitution in parameter as a primitive recursive function: 

0+++++++++ q = q (a, p)+++++++++0 = a, p (a, p)+++++++++(b, q) = a + b, p+++++++++ q. 

Property ∀q(1) is proved by list induction on p. In the base case we have 

(0+++++++++ q)(x) def= q(x) = 0 + q(x) = 0(x) + q(x). 

In the inductive case when p = a, p1 we consider two cases. If q = 0 then 

((a, p1)+++++++++0)(x) def= (a, p1)(x) = (a, p1)(x) + 0 = (a, p1)(x) + 0(x). 

If q = b, q1 then we have 

((a, p1)+++++++++(b, q1))(x) def= ((a + b), p1+++++++++ q1)(x) = (a + b) + x · (p1+++++++++ q1)(x) IH= = (a + b) + x ·(p1(x) + q1(x)) = (a + x · p1(x)) + (b + x · q1(x)) = = (a, p1)(x) + (b, q1)(x). 

334

12\.5.8 Multiplication of polynomials by constants. The function a××××××××× p computes the multiplication of the polynomial p by the constant a. The function satisfies 

P̀A (a××××××××× p)(x) = a · p(x) (1) 

P̀A p ∼ q → a××××××××× p ∼ a××××××××× q (2) 

and it is defined by list recursion as a primitive recursive function: 

a××××××××× 0 = 0 a××××××××× (b, p) = a · b, a××××××××× p. 

Both properties are proved by a straighforward list induction. 

12\.5.9 Multiplication of polynomials. The function p××××××××× q returns the multiplication of the polynomials p and q. The function satisfies 

P̀A (p××××××××× q)(x) = p(x) · q(x) (1) 

P̀A p ∼ q ∧ r ∼ s → p××××××××× r ∼ q××××××××× s (2) 

and it is defined by list recursion as a primitive recursive function: 

0××××××××× q = 0 (a, p)××××××××× q = a××××××××× q+++++++++(0, p××××××××× q). 

Property (1) is proved by list induction on p. In the base case we have 

(0××××××××× q)(x) def= 0(x) = 0 = 0 · q(x) = 0(x) · q(x). 

In the base case when p = a, p1 we have 

((a, p1)××××××××× q)(x) def= (a××××××××× q+++++++++ (0, p1××××××××× q))(x) 12.5.7(1) 

= 

= (a××××××××× q)(x) + (0, p1××××××××× q)(x) = (a××××××××× q)(x) + x · (p1××××××××× q)(x) 12.5.8(1) 

= 

= a · q(x) + x · (p1××××××××× q)(x) IH= a · q(x) + x ·(p1(x) · q(x)) = = (a + x · p1(x)) · q(x) = (a, p1)(x) · q(x). 

12\.6 Exercises 

12\.6.1 Exercise. Prove 

P̀A x ε y ↔ ∃z1∃z2 y = z1 ⊕ (x, z2). (1) 

12\.6.2 Exercise. Prove 

P̀A Map(x⊕ y) = Map(x)⊕Map(y). 

335

12\.6.3 Exercise. Prove 

P̀A k ≤ m ∧m ≤ n → \[k .. m\]⊕ \[m + 1 .. n\] = \[k .. n\]. 

12\.6.4 Exercise. Prove 

P̀A Combine(Ieven(x), Iodd(x)) = x. 

12\.6.5 Exercise. Prove 

P̀A Take(L(x), x⊕ y) = x (1) 

P̀A Drop(L(x), x⊕ y) = y (2) 

P̀A n ≤ L(x) → x = Take(n, x)⊕Drop(n, x) (3) 

P̀A m + n ≤ L(x) → Drop(m + n, x) = Drop(n,Drop(m, x)). (4) 

12\.6.6 Exercise. Prove 

P̀A x 6= 0 ∧ y 6= 0 → Minl(x⊕ y) = min(Minl(x),Minl(y)) 

P̀A x 6= 0 ∧ y 6= 0 → Maxl(x⊕ y) = max(Maxl(x),Maxl(y)). 

12\.6.7 Exercise. Consider the function s1 ∪ s2 defined by 

0 ∪ s2 = s2 

(a1, s1) ∪ 0 = a1, s1 

(a1, s1) ∪ (a2, s2) = a1, s1 ∪ (a2, s2) ← a1 \< a2 

(a1, s1) ∪ (a2, s2) = a1, s1 ∪ s2 ← a1 = a2 

(a1, s1) ∪ (a2, s2) = a2, (a1, s1) ∪ s2 ← a1 \> a2. 

Prove 

P̀A Set(s1) ∧ Set(s2) → Set(s1 ∪ s2) 

P̀A Set(s1) ∧ Set(s2) → a ∈ s1 ∪ s2 ↔ a ∈ s1 ∨ a ∈ s2. 

12\.6.8 Exercise. Consider the function s1 \\ s2 defined by 

0 \\ s2 = 0 (a1, s1) \\ 0 = a1, s1 

(a1, s1) \\ (a2, s2) = a1, s1 \\ (a2, s2) ← a1 \< a2 

(a1, s1) \\ (a2, s2) = s1 \\ s2 ← a1 = a2 

(a1, s1) \\ (a2, s2) = (a1, s1) \\ s2 ← a1 \> a2. 

Prove 

P̀A Set(s1) ∧ Set(s2) → Set(s1 \\ s2) 

P̀A Set(s1) ∧ Set(s2) → a ∈ s1 \\ s2 ↔ a ∈ s1 ∧ a 6∈ s2. 

336

13\. Programs Operating on Trees 

13\.1 Binary Trees 

13\.1.1 Arithmetization of labeled binary trees. We arithmetize binary trees with labels in N by two constructors: 

E = 0, 0 Nd(x, l, r) = 1, x, l, r. 

The predicate Bt(t) holding of codes of binary trees with labels in N is defined by course of values recursion as a primitive recursive predicate: 

Bt(E) Bt Nd(x, l, r) ← Bt(l) ∧ Bt(r). 

We identify labeled binary trees with their codes and from now on we will say the binary tree t instead of the code of the binary tree t. 

13\.1.2 Case analysis on binary trees. We have the following principle of case analysis on binary trees: 

P̀A Bt(t) → t = E ∨ ∃x∃l∃r t = Nd(x, l, r) (1) 

which is proved by a straightforward pair case analysis. 

13\.1.3 Structural induction on binary trees. The formula of structural induction on the binary tree t for φ\[t\] is the following one: 

φ\[E\] ∧ ∀x∀l∀r(φ\[l\] ∧ φ\[r\] → φ\[Nd(x, l, r)\]) → Bt(t) → φ\[t\]. 

In the sequel we will often say shortly the Bt-induction on t instead of the structural induction on the binary tree t. 

13\.1.4 Theorem. We have 

P̀A φ\[E\] ∧ ∀x∀l∀r(φ\[l\] ∧ φ\[r\] → φ\[Nd(x, l, r)\]) → Bt(t) → φ\[t\]. 

Proof. The property is proved by complete induction on t. Take any t and under the assumptions of the claim consider two cases by 13.1.2(1). The case when t = E is trivial. If t = Nd(x, l, r) for some x, l, r then φ\[l\] and φ\[r\] by IH since l \< Nd(x, l, r) and r \< Nd(x, l, r). From this and assumptions we get φ\[Nd(x, l, r)\]. ut

13\.1.5 Structural recursion on binary trees. Initial clauses for clausal definitions with structural recursion on binary trees are of a form 

f(\~y, t, \~z) = α1\[\~y, \~z\] ← t = E 

f(\~y, t, \~z) = α2\[λ̇\~yt\~z.f(\~y, l, \~z), λ̇\~yt\~z.f(\~y, r, \~z); \~y, \~z, x, l, r\] ← t = Nd(x, l, r). 

In the sequel we will often say shortly the Bt-recursion on t instead of the structural recursion on the binary tree t. 

13\.1.6 Membership in binary trees. The predicate x ∈b t holds if x is a label of the binary tree t. The predicate is defined by Bt-recursion on t as a primitive recursive predicate: 

x ∈b Nd(y, l, r) ← x = y x ∈b Nd(y, l, r) ← x 6= y ∧ x ∈b l x ∈b Nd(y, l, r) ← x 6= y ∧ x 6∈b l ∧ x ∈b r. 

The predicate has the following easy to prove properties: 

P̀A x 6∈b E (1) 

P̀A x ∈b Nd(y, l, r) ↔ x = y ∨ x ∈b l ∨ x ∈b r. (2) 

13\.1.7 Size and depth of binary trees. The size function \|t\|b counts the number of labels in the binary tree t. The function is defined by Bt-recursion as a primitive recursive function: 

\|E\|b = 0 \|Nd(x, l, r)\|b = \|l\|b + \|r\|b + 1. 

The depth function Dp(t) yields the length of the longest path from the root to a leaf in the binary tree t. The function is defined by Bt-recursion as a primitive recursive function: 

Dp(E) = 0 Dp Nd(x, l, r) = max(Dp(l),Dp(r)) + 1. 

The functions satisfy 

P̀A Bt(t) → \|t\|b = 0 ↔ t = E (1) 

P̀A Bt(t) → Dp(t) = 0 ↔ t = E (2) 

P̀A Bt(t) → Dp(t) ≤ \|t\|b \< 2Dp(t). (3) 

Properties (1) and (2) are straightforward. Property (3) is proved structural induction on the binary tree t. The base case is straightforward. In the in- ductive case when t = Nd(x, l, r) we have 

Dp Nd(x, l, r) def= max(Dp(l),Dp(r)) + 1 IH≤ max(\|l\|b, \|r\|b) + 1 = 

= max(\|l\|b + 1, \|r\|b + 1) IH≤ max(2Dp(l), 2Dp(r)) = 2max(Dp(l),Dp(r)) \< 

\< 2max(Dp(l),Dp(r))+1 def= 2Dp Nd(x,l,r). 

338

13\.1.8 Reflection function. The reflection function Reflect(t) yields the mirror image of the binary tree t by recursively exchanging left and right subtrees. The function is defined by Bt-recursion as a primitive recursive function: 

Reflect(E) = E Reflect Nd(x, l, r) = Nd(x,Reflect(r),Reflect(l)). 

The function satisfies 

P̀A Bt(t) → Bt Reflect(t) (1) 

P̀A Bt(t) → x ∈b Reflect(t) ↔ x ∈b t (2) 

P̀A Bt(t) → \|Reflect(t)\|b = \|t\|b (3) 

P̀A Bt(t) → Dp Reflect(t) = Dp(t) (4) 

P̀A Bt(t) → Reflect Reflect(t) = t (5) 

P̀A Bt(t1) ∧ Bt(t2) ∧ Reflect(t1) = Reflect(t2) → t1 = t2 (6) 

P̀A Bt(t1) → ∃t2 Reflect(t2) = t1. (7) 

Property (1) is proved by a straightforward Bt-induction. Property (2) is proved by Bt-induction. The base is straightforward and in the inductive case when t = Nd(y, l, r) we have 

x ∈b Reflect Nd(y, l, r) def⇔ x ∈b Nd(y,Reflect(r),Reflect(l)) 13.1.6(2)⇔ 

x = y ∨ x ∈b Reflect(r) ∨ x ∈b Reflect(l) IH⇔ x = y ∨ x ∈b r ∨ x ∈b l 13.1.6(2)⇔ 

x ∈b Nd(y, l, r). 

Properties (3) and (4) are proved by a straightforward Bt-induction. Property (5) is proved by Bt-induction. The base is straightforward and in the inductive case we have 

Reflect Reflect Nd(x, l, r) def= Reflect Nd(x,Reflect(r),Reflect(l)) def= 

= Nd(x,Reflect Reflect(l),Reflect Reflect(r)) IH= Nd(x, l, r). 

Properties (6) and (7) follows from (5). 

13\.1.9 Traversals of binary trees. The functions Preorder(t), Inorder(t), and Postorder(t) collect the labels of a binary tree t into a list in the order corresponding respectively to the preorder, inorder, and postorder traversal of the binary tree t. The functions are defined by Bt-recursion as primitive recursive functions: 

Preorder(E) = 0 PreorderNd(x, l, r) = (x, 0)⊕ Preorder(l)⊕ Preorder(r) 

339

Inorder(E) = 0 InorderNd(x, l, r) = Inorder(l)⊕ (x, 0)⊕ Inorder(r) 

Postorder(E) = 0 PostorderNd(x, l, r) = Postorder(l)⊕ Postorder(r)⊕ (x, 0). 

The following are the basic properties of the traversal functions: 

P̀A Bt(t) → LPreorder(t) = \|t\|b (1) 

P̀A Bt(t) → x ε Preorder(t) ↔ x ∈b t (2) 

P̀A Bt(t) → L Inorder(t) = \|t\|b (3) 

P̀A Bt(t) → x ε Inorder(t) ↔ x ∈b t (4) 

P̀A Bt(t) → LPostorder(t) = \|t\|b (5) 

P̀A Bt(t) → x ε Postorder(t) ↔ x ∈b t. (6) 

Property (1) is proved by Bt-induction. The base case is straighforward and in the inductive case we have 

LPreorder Nd(x, l, r) def= L((x, 0)⊕ Preorder(l)⊕ Preorder(t)) 12.1.9(8) 

= 

= LPreorder(l) + LPreorder(r) + 1 IH= \|l\|b + \|r\|b + 1 = \|Nd(x, l, r)\|b. Property (2) is proved by Bt-induction on t. The base case is straighforward and in the inductive case when t = Nd(y, l, r) we have 

x ε Preorder Nd(y, l, r) def⇔ x ε (y, 0)⊕ Preorder(l)⊕ Preorder(t) ⇔ x = y ∨ x ε Preorder(l) ∨ x ε Preorder(r) IH⇔ x = y ∨ x ∈b l ∨ x ∈b r 

13\.1.6(2)⇔ x ∈b Nd(y, l, r). 

The remaining properties are proved similarly. The relationship between the preorder and postorder traversals is cap- 

tured by the following properties: 

P̀A Bt(t) → Preorder(t) = Rev Postorder Reflect(t) (7) 

P̀A Bt(t) → Postorder(t) = Rev Preorder Reflect(t). (8) 

Property (7) is proved by Bt-induction. The base case is straightforward and in the inductive case we have 

Rev Postorder Reflect Nd(x, l, r) = 

= Rev Postorder Nd(x,Reflect(r),Reflect(l)) def= 

= Rev(Postorder Reflect(r)⊕ Postorder Reflect(l)⊕ (x, 0)) 12.1.13(2) 

= 

= (x, 0)⊕ Rev Postorder Reflect(l)⊕ Rev Postorder Reflect(r) IH= 

= (x, 0)⊕ Preorder(l)⊕ Preorder(r) def= Preorder Nd(x, l, r). 

Property (8) is proved similarly. 

340

13\.1.10 Fast programs for tree traversals. We can save the repeated concatenation in the definitions of the tree traversal functions by keeping the labels in an accumulator. For instance, in case of preorder traversal, we define a binary accumulator function f(t, a) by nested Bt-recursion on t: 

f(E, a) = a f(Nd(x, l, r), a) = x, f(l, f(r, a)) 

and then take the following property as an alternative definition of preorder traversal: 

P̀A Bt(t) → Preorder(t) = f(t, 0). (1) 

In order to see this we need the following property of f : 

P̀A Bt(t) → ∀a f(t, a) = Preorder(t)⊕ a (2) 

which is proved Bt-induction. The base case is straightforward. In the induc- tive case when t = Nd(x, l, r) take any a and we have 

f(Nd(x, l, r), a) def= x, f(l, f(r, a)) IH= x, f(l,Preorder(r)⊕ a) IH= = x,Preorder(l)⊕ Preorder(r)⊕ a = Preorder Nd(x, l, r)⊕ a. 

13\.1.11 Tail recursive tree traversals. We can find a tail recursive im- plementation of preorder traversal (and similarly for inorder and postorder traversals) with the help of the binary function f(s, a) defined by 

f(0, a) = a f((E, s), a) = f(s, a) f((Nd(x, l, r), s), a) = f((r, l,Label(x), s), a) f((Label(x), s), a) = f(s, x, a), 

where Label(x) = 2, x is an auxiliary constructor. Note that this is a definition by course of values recursion with measure m(s, a): 

m1(E) = 1 m1 Nd(x, l, r) = m1(l) + m1(r) + 2 m1 Label(x) = 1 

m(0, a) = 0 m((t, s), a) = m1(t) + m(s, a). 

We can express the relation between Preorder and f by 

P̀A Bt(t) → Preorder(t) = f((t, 0), 0). (1) 

First note that the function f satisfies: 

P̀A Bt(t) → ∀s∀a f((t, s), a) = f(s,Preorder(t)⊕ a). (2) 

341

Property (2) is proved by Bt-induction. In the base case take any s and a. We have 

f((E, s), a) def= f(s, a) = f(s, 0⊕ a) def= f(s,Preorder(E)⊕ a). 

In the inductive case when t = Nd(x, l, r) take any s and a. We have 

f((Nd(x, l, r), s), a) def= f((r, l,Label(x), s), a) IH= 

= f((l,Label(x), s),Preorder(r)⊕ a) IH= 

= f((Label(x), s),Preorder(l)⊕ Preorder(r)⊕ a) def= = f(s, x,Preorder(l)⊕ Preorder(r)⊕ a) = = f(s,Preorder Nd(x, l, r)⊕ a). 

We are now in position to prove (1). Assume Bt(t). We have 

f((t, 0), 0) (2) = f(0,Preorder(t)⊕ 0) = f(0,Preorder(t)) def= Preorder(t). 

13\.1.12 Subtree relation. The predicate t1 Eb t2 holds if the binary tree t1 is a subtree of the binary tree t2. The predicate is defined by Bt-recursion on t2 as a primitive recursive predicate: 

t1 Eb t2 ← t1 = t2 t1 Eb t2 ← t1 6= t2 ∧ t2 = Nd(x2, l2, r2) ∧ t1 Eb l2 t1 Eb t2 ← t1 6= t2 ∧ t2 = Nd(x2, l2, r2) ∧ t1 6Eb l2 ∧ t1 Eb r2. 

The predicate has the following easy to prove properties: 

P̀A t Eb E ↔ t = E (1) 

P̀A t Eb Nd(x, l, r) ↔ t = Nd(x, l, r) ∨ t Eb l ∨ t Eb r. (2) 

13\.1.13 Isomorphic binary trees. The predicate t1 'b t2 holds if the binary trees t1 and t2 are isomorphic. The predicate is defined by Bt-recursion on t1 with substitution in parameter t2 as a primitive recursive predicate: 

E 'b E Nd(x1, l1, r1) 'b Nd(x2, l2, r2) ← l1 'b l2 ∧ r1 'b r2. 

The predicate satisfies 

P̀A Bt(t) → t 'b t (1) 

P̀A Bt(t1) ∧ Bt(t2) ∧ t1 'b t2 → t2 'b t1 (2) 

P̀A Bt(t1) ∧ Bt(t2) ∧ Bt(t3) ∧ t1 'b t2 ∧ t2 'b t3 → t1 'b t3 (3) 

P̀A Bt(t1) ∧ Bt(t2) ∧ t1 'b t2 → \|t1\|b = \|t2\|b (4) 

P̀A Bt(t1) ∧ Bt(t2) ∧ t1 'b t2 → Dp(t1) = Dp(t2) (5) 

P̀A Bt(t1) ∧ Bt(t2) → Reflect(t1) 'b Reflect(t2) ↔ t1 'b t2. (6) 

UNFINISHED 

342

13\.1.14 Counting the labels in binary trees. The function #b(x, t) counts the number of occurrences of the label x in the binary tree t. The function is defined by Bt-recursion on t as a primitive recursive function: 

\#b(x,E) = 0 #b(x,Nd(y, l, r)) = #b(x, l) + #b(x, r) + 1 ← x = y #b(x,Nd(y, l, r)) = #b(x, l) + #b(x, r) ← x 6= y. 

The function satisfies: 

P̀A #b(x,Nd(y, l, r)) = #b(x, l) + #b(x, r) + (x=∗ y) (1) 

P̀A Bt(t) → #b(x, t) \> 0 ↔ x ∈b t (2) 

P̀A Bt(t) → #b(x, t) ≤ \|t\|b (3) 

P̀A Bt(t) → #b(x, t) = \|t\|b ↔ ∀y(y ∈b t → y = x) (4) 

P̀A Bt(t) → #b(x,Reflect(t)) = #b(x, t) (5) 

P̀A Bt(t) → #b(x, t) = #(x,Preorder(t)) (6) 

P̀A Bt(t) → #b(x, t) = #(x, Inorder(t)) (7) 

P̀A Bt(t) → #b(x, t) = #(x,Postorder(t)) (8) 

P̀A Bt(t1) ∧ Bt(t2) ∧ t1 Eb t2 → #b(x, t1) ≤ #b(x, t2). (9) 

Property (1) is straightforward. Property (4) is proved by Bt-induction on t as follows. UNFINISHED 

Property (9) is proved by Bt-induction on t2. The remaining properties are proved by a straightforward Bt-induction on t. 

13\.2 Binary Search Trees 

13\.2.1 Tree comparision predicates. The predicate x ≺ t holds if x is a strict lower bound of the labels of the binary tree t, i.e. 

P̀Ax x ≺ t ↔ ∀y(y ∈b t → x \< y). 

The predicate satisfies 

P̀A x ≺ E (1) 

P̀A x ≺ Nd(y, l, r) ↔ x \< y ∧ x ≺ l ∧ x ≺ r (2) 

P̀A x ≤ y ∧ y ≺ t → x ≺ t. (3) 

The predicate x  t holds if x is a strict upper bound of the labels of the binary tree t, i.e. 

P̀Ax x  t ↔ ∀y(y ∈b t → x \> y). 

The predicate satisfies 

343

P̀A x  E (4) 

P̀A x  Nd(y, l, r) ↔ x \> y ∧ x  l ∧ x  r (5) 

P̀A x ≥ y ∧ y  t → x  t. (6) 

The predicate t1 ≺b t2 holds if the labels of the binary tree t1 are strictly less than the labels of the binary tree t2, i.e. 

P̀Ax t1 ≺b t2 ↔ ∀x1∀x2(x1 ∈b t1 ∧ x2 ∈b t2 → x1 \< x2). 

The predicate satisfies 

P̀A E ≺b t2 (7) 

P̀A Nd(x1, l1, r1) ≺b t2 ↔ x1 ≺ t2 ∧ l1 ≺b t2 ∧ r1 ≺b t2 (8) 

P̀A t1 ≺b E (9) 

P̀A t1 ≺b Nd(x2, l2, r2) ↔ x2 Â t1 ∧ t1 ≺b l2 ∧ t1 ≺b r2 (10) 

P̀A t1 ≺b t2 ∧ x ∈b t1 → x ≺ t2 (11) 

P̀A t1 ≺b t2 ∧ x ∈b t2 → x  t1 (12) 

P̀A x  t1 ∧ x ≺ t2 → t1 ≺b t2. (13) 

13\.2.2 Binary search trees. The predicate Bst(t) holds if t is a binary tree satisfying the following search condition: 

for every nonempty subtree of t each label of its left (right) son is strictly less (greater) than its root label. 

The predicate is defined by 

P̀Ax Bst(t) ↔ Bt(t) ∧ ∀x∀l∀r(Nd(x, l, r) Eb t → x  l ∧ x ≺ r). 

The predicate satisfies 

P̀A Bst(E) (1) 

P̀A Bst Nd(x, l, r) ↔ x  l ∧ x ≺ r ∧ Bst(l) ∧ Bst(r) (2) 

P̀A Bst Nd(x, l, r) ∧ y ≤ x → y 6∈b r (3) 

P̀A Bst Nd(x, l, r) ∧ y ≥ x → y 6∈b l. (4) 

P̀A Bst Nd(x, l, r) → l ≺b r. (5) 

13\.2.3 Membership in binary search trees. The predicate x ∈ t holds if x is a label of the binary search tree t. The predicate satisfies 

P̀A Bst(t) → x ∈ t ↔ x ∈b t (1) 

and it is defined by Bt-recursion on t as a primitive recursive predicate: 

x ∈ Nd(y, l, r) ← x \< y ∧ x ∈ l x ∈ Nd(y, l, r) ← x = y x ∈ Nd(y, l, r) ← x \> y ∧ x ∈ r. 

344

Property (1) is proved by Bt-induction on t. The base is straightforward. In the inductive case, when t = Nd(y, l, r), assume Bst(t), and consider three cases. If x \< y then we have 

x ∈ Nd(y, l, r) def⇔ x ∈ l IH⇔ x ∈b l 

13\.2.2(3)⇔ x = y ∨ x ∈b l ∨ x ∈b r 

13\.1.6(2)⇔ x ∈b Nd(y, l, r). 

The case when x = y is trivial and the case when x \> y is proved similarly. 

13\.2.4 Insertion in binary search trees. The function t ∪ {x} takes a binary search tree t and inserts x into it. The function satisfies 

P̀A Bst(t) → Bst(t ∪ {x}) (1) 

P̀A Bst(t) → y ∈ t ∪ {x} ↔ y ∈ t ∨ y = x (2) 

and it is defined by Bt-recursion on t as a primitive recursive function: 

E ∪ {x} = Nd(x, E, E) Nd(y, l, r) ∪ {x} = Nd(y, l, r ∪ {x}) ← y \< x Nd(y, l, r) ∪ {x} = Nd(y, l, r) ← y = x Nd(y, l, r) ∪ {x} = Nd(y, l ∪ {x}, r) ← y \> x. 

First note that 

P̀A Bt(t) → y ∈b t ∪ {x} ↔ y ∈b t ∨ y = x. (3) 

Property (3) is proved by Bt-induction on t. The base case is straightforward. In the inductive case, when t = Nd(z, l, r), assume Bt Nd(z, l, r) and consider three cases. If z \< x then we have 

y ∈b Nd(z, l, r) ∪ {x} def⇔ y ∈b Nd(z, l, r ∪ {x}) 13.1.6(2)⇔ y = z ∨ y ∈b l ∨ y ∈b r ∪ {x} IH⇔ y = z ∨ y ∈b l ∨ y ∈b r ∨ y = x 

13\.1.6(2)⇔ y ∈b Nd(z, l, r) ∨ y = x. 

The case when z = x is trivial and the case when z \> x is proved similarly. As a simple consequence of (3) we get 

P̀A Bt(t) → y ≺ t ∪ {x} ↔ y ≺ t ∧ y \< x (4) 

P̀A Bt(t) → y  t ∪ {x} ↔ y  t ∧ y \> x. (5) 

Property (1) is proved by Bt-induction on t. The base case is straightfor- ward. In the inductive case when t = Nd(y, l, r) we consider three cases. If y \< x then we have 

Bst(Nd(y, l, r) ∪ {x}) def⇔ Bst Nd(y, l, r ∪ {x}) 13.2.2(2)⇔ y  l ∧ y ≺ r ∪ {x} ∧ Bst(l) ∧ Bst(r ∪ {x}) (4)⇔ y  l ∧ y ≺ r ∧ Bst(l) ∧ Bst(r ∪ {x}). 

345

The last follows from IH and assumptions by 13.2.2(2). The case when y = x is trivial and the case when y \> x is proved similarly. 

Property (2) is a straighforward consequence of 13.2.3(1), (1), and (3). 

13\.2.5 Deletion in binary search trees. The function t \\ {x} takes a binary search tree t and a number x and yields a new binary search tree obtained from t by deleting x from it. The function satitisfies 

P̀A Bst(t) → Bst(t \\ {x}) (1) 

P̀A Bst(t) → y ∈ t \\ {x} ↔ y ∈ t ∧ y 6= x (2) 

and it is defined by Bt-recursion on t as a primitive recursive function: 

E t t2 = t2 Nd(x1, l1, r1) t t2 = Nd(x1, l1, r1 t t2) 

E \\ {x} = E Nd(y, l, r) \\ {x} = Nd(y, l, r \\ {x}) ← y \< x Nd(y, l, r) \\ {x} = l t r ← y = x Nd(y, l, r) \\ {x} = Nd(y, l \\ {x}, r) ← y \> x. 

The auxiliary function t1 t t2 satisfies 

P̀A Bt(t1) → x ∈b t1 t t2 ↔ x ∈b t1 ∨ x ∈b t2 (3) 

P̀A Bt(t1) → x ≺ t1 t t2 ↔ x ≺ t1 ∧ x ≺ t2 (4) 

P̀A Bst(t1) ∧ Bst(t2) ∧ t1 ≺b t2 → Bst(t1 t t2). (5) 

Property (3) is proved by a straightforward Bt-induction on t1. Property (4) is a simple consequence of (3). Property (5) is proved by Bt-induction on t1 with the help of (4). 

Note that 

P̀A Bst(t) → y ∈b t \\ {x} ↔ y ∈b t ∧ y 6= x. (6) 

Property (6) is proved by Bt-induction on t. The base case is straightforward. In the inductive case when t = Nd(z, l, r) we consider three cases. If z \< x then we have 

y ∈b Nd(z, l, r) \\ {x} def⇔ y ∈b Nd(z, l, r \\ {x}) 13.1.6(2)⇔ y = z ∨ y ∈b l ∨ y ∈b r \\ {x} IH⇔ y = z ∨ y ∈b l ∨ y ∈b r ∧ y 6= x 

(∗)⇔ (y = z ∨ y ∈b l ∨ y ∈b r) ∧ y 6= x 

13\.1.6(2)⇔ y ∈b Nd(z, l, r) ∧ y 6= x. 

The step marked by (∗) follows by a simple case analysis on y = x and y 6= x by noting that we have x 6∈b l by 13.2.2(3). The case when z = x follows from (3) by similar arguments. The case when z \> x is left to the reader. 

346

As a simple consequence of (6) we get 

P̀A Bst(t) ∧ y \< x → y ≺ t \\ {x} ↔ y ≺ t (7) 

P̀A Bst(t) ∧ y \> x → y  t \\ {x} ↔ y  t. (8) 

Property (1) is proved by Bt-induction on t. The base case is straightfor- ward. In the inductive case when t = Nd(y, l, r) we consider three cases. If y \< x then we have 

Bst(Nd(y, l, r) \\ {x}) def⇔ Bst Nd(y, l, r \\ {x}) 13.2.2(2)⇔ y  l ∧ y ≺ r \\ {x} ∧ Bst(l) ∧ Bst(r \\ {x}) (7)⇔ y  l ∧ y ≺ r ∧ Bst(l) ∧ Bst(r \\ {x}). 

The last follows from IH and assumptions by 13.2.2(2). If y = x then the claim follows from 13.2.2(5) and (5). The case when y \> x is proved similarly. 

Property (2) is a straighforward consequence of 13.2.3(1), (1), and (6). 

13\.3 Perfectly Balanced Binary Trees 

13\.3.1 Perfectly (size) balanced binary trees. The predicate Pbt(t) holds if t is a binary tree satisfying the following (size) balanced condition: 

for every nonempty subtree of t the size of its left son is at most one more than the size of its right son. 

The predicate is defined by 

P̀Ax Pbt(t) ↔ Bt(t) ∧ ∀x∀l∀r(Nd(x, l, r) Eb t → \|l\|b = \|r\|b ∨ \|l\|b = \|r\|b + 1). 

The predicate satisfies 

P̀A Pbt(E) (1) 

P̀A Pbt Nd(x, l, r) ↔ (\|l\|b = \|r\|b ∨ \|l\|b = \|r\|b + 1) ∧ Pbt(l) ∧ Pbt(r) (2) 

P̀A Pbt(t) → 2Dp(t) ÷ 2 ≤ \|t\|b \< 2Dp(t) (3) 

P̀A Pbt(t1) ∧ Pbt(t2) → t1 'b t2 ↔ \|t1\|b = \|t2\|b. (4) 

Properties (1) and (2) are straightforward. The sharp inequality in (3) fol- lows from 13.1.7(3). The non-sharp inequality is proved by Bt-induction on t. Property ∀t2(4) is proved by Bt-induction on t1. The base case is straight- forward. In the inductive case when t1 = Nd(x1, l1, r1) take any t2 and under the assumptions of the claim we have t2 = Nd(x2, l2, r2) for some x2, l2, and r2. We obtain 

347

Nd(x1, l1, r1) 'b Nd(x2, l2, r2) ⇔ l1 'b l2 ∧ r1 'b r2 IH⇔ 

\|l1\|b = \|l2\|b ∧ \|r1\|b = \|r2\|b (∗)⇔ \|l1\|b + \|r1\|b = \|l2\|b + \|r2\|b ⇔ \|Nd(x1, l1, r1)\|b = \|Nd(x2, l2, r2)\|b. 

The step marked by (∗) follows from (2). 

13\.3.2 Fast indexing in perfectly balanced binary trees. The appli- cation t\[i\] yields the i-th label of the perfectly balanced binary tree t. The function is defined by dyadic recursion on i with substitution in parameter as a primitive recursive function: 

Nd(x, l, r)\[0\] = x Nd(x, l, r)\[i1\] = l\[i\] Nd(x, l, r)\[i2\] = r\[i\]. 

13\.3.3 Fast modification in perfectly balanced binary trees. The function t\[i := y\] modifies the perfectly balanced tree t at the index i to obtain a new value y. The function satisfies 

P̀A Pbt(t) ∧ i \< \|t\|b → \|t\[i := y\]\|b = \|t\|b (1) 

P̀A Pbt(t) ∧ i \< \|t\|b → Pbt(t\[i := y\]) (2) 

P̀A Pbt(t) ∧ i \< \|t\|b → t\[i := y\]\[i\] = y (3) 

P̀A Pbt(t) ∧ i \< \|t\|b ∧ j \< \|t\|b ∧ j 6= i → t\[i := y\]\[j\] = t\[j\] (4) 

and it is defined by dyadic recursion on i with substitution in parameter t as a primitive recursive function: 

Nd(x, l, r)\[0 := y\] = Nd(y, l, r) Nd(x, l, r)\[i1 := y\] = Nd(x, l\[i := y\], r) Nd(x, l, r)\[i2 := y\] = Nd(x, l, r\[i := y\]). 

First note that under the assumptions Pbt(t) and i \< \|t\|b we have t = Nd(x, l, r) for some x, l, and r, and thus 

i \< \|Nd(x, l, r)\|b = \|l\|b + \|r\|b + 1. (5) 

Property ∀t(1) is proved by dyadic induction on i. In the base case we have 

\|Nd(x, l, r)\[0 := y\]\|b def= \|Nd(y, l, r)\|b = \|l\|b + \|r\|b + 1 = \|Nd(x, l, r)\|b. In the inductive case when i = j1 we have j \< \|l\|b by 13.3.1(2) and (5). We get 

\|Nd(x, l, r)\[j1 := y\]\|b def= \|Nd(x, l\[j := y\], r)\|b = \|l\[j := y\]\|b + \|r\|b + 1 IH= = \|l\|b + \|r\|b + 1 = \|Nd(x, l, r)\|b. 

348

The inductive case when i = j2 has a similar proof. Property ∀t(2) is proved by dyadic induction on i. The base case is 

straightforward. In the inductive case when i = j1 we have j \< \|l\|b by 13.3.1(2) and (5). We get 

Pbt(Nd(x, l, r)\[j1 := y\]) def⇔ Pbt Nd(x, l\[j := y\], r) 13.3.1(2)⇔ 

(\|l\[j := y\]\|b = \|r\|b ∨ \|l\[j := y\]\|b = \|r\|b + 1) ∧ Pbt(l\[j := y\]) ∧ Pbt(r) (1)⇔ 

(\|l\|b = \|r\|b ∨ \|l\|b = \|r\|b + 1) ∧ Pbt(l\[j := y\]) ∧ Pbt(r) IH⇔ (\|l\|b = \|r\|b ∨ \|l\|b = \|r\|b + 1) ∧ Pbt(l) ∧ Pbt(r) 

13\.3.1(2)⇔ Pbt Nd(x, l, r). 

The inductive case when i = j2 has a similar proof. Property ∀t(3) is proved by dyadic induction on i. In the base case we 

have 

Nd(x, l, r)\[0 := y\]\[0\] def= Nd(y, l, r)\[0\] = y. 

In the inductive case when i = j1 we have j \< \|l\|b by 13.3.1(2) and (5). We get 

Nd(x, l, r)\[j1 := y\]\[j1\] def= Nd(x, l\[j := y\], r)\[j1\] = l\[j := y\]\[j\] IH= y. 

The inductive case when i = j2 has a similar proof. Property ∀t∀j(4) is proved by dyadic induction on i. In the base case 

when i = 0 take any j 6= 0 and consider two subcases. If j = k1 for some k then we have 

Nd(x, l, r)\[0 := y\]\[k1\] def= Nd(y, l, r)\[k1\] = l\[k\] = Nd(x, l, r)\[k1\]. 

The subcase when j = k2 is similar. In the inductive case when i = i11 first note that i1 \< \|l\|b by 13.3.1(2) and (1). Now take any j 6= i11 such that 

j \< \|Nd(x, l, r)\|b = \|l\|b + \|r\|b + 1 (6) 

and consider three subcases. If j = 0 then we have 

Nd(x, l, r)\[i11 := y\]\[0\] def= Nd(x, l\[i1 := y\], r)\[0\] = x = Nd(x, l, r)\[0\]. 

If j = k1 for some k then k 6= i1 and k \< \|l\|b by 13.3.1(2) and (6). We have 

Nd(x, l, r)\[i11 := y\]\[k1\] def= Nd(x, l\[i1 := y\], r)\[k1\] = l\[i1 := y\]\[k\] IH= 

= l\[k\] = Nd(x, l, r)\[k1\]. 

If j = k2 for some k then we have 

Nd(x, l, r)\[i11 := y\]\[k2\] def= Nd(x, l\[i1 := y\], r)\[k2\] = r\[k\] = Nd(x, l, r)\[k2\]. 

The inductive case when i = i12 has a similar proof. 

349

13\.3.4 Filling function. The function Fill(x, n) creates a perfectly bal- anced tree of size n labelling the nodes by x. The function satisfies 

P̀A \|Fill(x, n)\|b = n (1) 

P̀A Pbt Fill(x, n) (2) 

P̀A i \< n → Fill(x, n)\[i\] = x (3) 

and it is defined by course of values recursion on n as a primitive recursive function: 

Fill(x, 0) = E Fill(x, n1) = Nd(x,Fill(x, n),Fill(x, n)) Fill(x, n2) = Nd(x,Fill(x, n + 1),Fill(x, n)). 

Properties (1), (2), and ∀i(3) are proved by complete induction on n. 

13\.3.5 Insertion of a new first label. The function Insfirst(x, t) increases by one the size of the perfectly balanced tree t by inserting x into the first position. The function satisfies 

P̀A Pbt(t) → \|Insfirst(x, t)\|b = \|t\|b + 1 (1) 

P̀A Pbt(t) → Pbt Insfirst(x, t) (2) 

P̀A Pbt(t) → Insfirst(x, t)\[0\] = x (3) 

P̀A Pbt(t) ∧ i \< \|t\|b → Insfirst(x, t)\[i + 1\] = t\[i\] (4) 

and it is defined by Bt-recursion on t with substitution in parameter x as a primitive recursive function: 

Insfirst(x, E) = Nd(x,E,E) Insfirst(x,Nd(y, l, r)) = Nd(x, Insfirst(y, r), l). 

Property ∀x(1) is proved by Bt-induction on t. In the base case when t = E take any x and we have 

\|Insfirst(x,E)\|b def= \|Nd(x,E,E)\|b = \|E\|b + \|E\|b + 1 = 1 = \|E\|b + 1. 

In the inductive case when t = Nd(y, l, r) take any x and we have 

\|Insfirst(x,Nd(y, l, r))\|b def= \|Nd(x, Insfirst(y, r), l)\|b = 

= \|Insfirst(y, r)\|b + \|l\|b + 1 IH= \|r\|b + 1 + \|l\|b + 1 = \|Nd(y, l, r)\|b + 1. 

Property ∀x(2) is proved by Bt-induction on t. The base case is straight- forward. In the inductive case when t = Nd(y, l, r) take any x and we have 

350

Pbt Insfirst(x,Nd(y, l, r)) def⇔ Pbt Nd(x, Insfirst(y, r), l) 13.3.1(2)⇔ 

(\|Insfirst(y, r)\|b = \|l\|b ∨ \|Insfirst(y, r)\|b = \|l\|b + 1) ∧ ∧ Pbt Insfirst(y, r) ∧ Pbt(l) 

(1)⇔ (\|r\|b + 1 = \|l\|b ∨ \|r\|b + 1 = \|l\|b + 1) ∧ Pbt Insfirst(y, r) ∧ Pbt(l) ⇔ (\|l\|b = \|r\|b ∨ \|l\|b = \|r\|b + 1) ∧ Pbt(r) ∧ Pbt(l) 

13\.3.1(2)⇔ Pbt Nd(y, l, r). 

Property (3) is straighforward. Property ∀i∀x(4) is proved by Bt-induction on t. In the base case there 

is nothing to prove. In the inductive case when t = Nd(y, l, r) take any i and x such that 

i \< \|Nd(y, l, r)\|b = \|l\|b + \|r\|b + 1 (5) 

and consider three cases. If i = 0 then we have 

Insfirst(x,Nd(y, l, r))\[0 + 1\] def= Nd(x, Insfirst(y, r), l)\[1\] = 

= Insfirst(y, r)\[0\] (3) = y = Nd(y, l, r)\[0\]. 

If i = j1 for some j then we have 

Insfirst(x,Nd(y, l, r))\[j1 + 1\] def= Nd(x, Insfirst(y, r), l)\[j2\] = = l\[j\] = Nd(y, l, r)\[j1\]. 

If i = j2 for some j then j \< \|r\|b by 13.3.1(2) and (5). We have 

Insfirst(x,Nd(y, l, r))\[j2 + 1\] def= Nd(x, Insfirst(y, r), l)\[(j + 1)1\] = 

= Insfirst(y, r)\[j + 1\] IH= r\[j\] = Nd(y, l, r)\[j2\]. 

13\.3.6 Deletion of the first label. The function Delfirst(t) decreases by one the size of the nonempty perfectly balanced tree t by removing its first label. The function satisfies 

P̀A Pbt(t) ∧ \|t\|b \> 0 → \|Delfirst(t)\|b = \|t\|b .− 1 (1) 

P̀A Pbt(t) ∧ \|t\|b \> 0 → Pbt Delfirst(t) (2) 

P̀A Pbt(t) ∧ \|t\|b \> 0 ∧ i \< \|t\|b .− 1 → Delfirst(t)\[i\] = t\[i + 1\] (3) 

and it is defined by Bt-recursion as a primitive recursive function: 

Delfirst Nd(x, l, r) = E ← l = E Delfirst Nd(x, l, r) = Nd(x1, r,Delfirst(l)) ← l = Nd(x1, l1, r1). 

Property (1) is proved by Bt-induction on t. In the base case there is nothing to prove. In the inductive case when t = Nd(x, l, r) we consider two cases. If l = E then r = E by 13.3.1(2) and we have 

351

\|Delfirst Nd(x, E, E)\|b def= \|E\|b = 0 = 1 .− 1 = \|Nd(x, E, E)\|b .− 1. 

If l = Nd(x1, l1, r1) for some x1, l1, and r1 then we have 

\|Delfirst Nd(x, l, r)\|b def= \|Nd(x1, r,Delfirst(l))\|b = \|r\|b + \|Delfirst(l)\|b + 1 IH= 

= \|r\|b + \|l\|b .− 1 + 1 = \|Nd(x, l, r)\|b .− 1. 

Property (2) is proved by Bt-induction on t. In the base case there is nothing to prove. In the inductive case when t = Nd(x, l, r) we consider two cases. If l = E then r = E by 13.3.1(2) and the property (2) holds trivially. If l = Nd(x1, l1, r1) for some x1, l1, and r1 then we have 

Pbt Delfirst Nd(x, l, r) def⇔ Pbt Nd(x1, r,Delfirst(l)) 13.3.1(2)⇔ 

(\|r\|b = \|Delfirst(l)\|b ∨ \|r\|b = \|Delfirst(l)\|b + 1) ∧ Pbt(r) ∧ Pbt Delfirst(l) (1)⇔ 

(\|r\|b = \|l\|b .− 1 ∨ \|r\|b = \|l\|b .− 1 + 1) ∧ Pbt(r) ∧ Pbt Delfirst(l) IH⇔ (\|l\|b = \|r\|b ∨ \|l\|b = \|r\|b + 1) ∧ Pbt(r) ∧ Pbt(l) 

13\.3.1(2)⇔ Pbt Nd(x, l, r). 

Property ∀i(3) is proved by Bt-induction on t. In the base case there is nothing to prove. In the inductive case when t = Nd(x, l, r) take any i such that 

i \< \|Nd(x, l, r)\|b .− 1 = \|l\|b + \|r\|b (4) 

and consider two cases. If l = E then r = E by 13.3.1(2) and we have a contradiction by (4). So suppose that l = Nd(x1, l1, r1) for some x1, l1, and r1. We consider three subcases. If i = 0 then 

(Delfirst Nd(x, l, r))\[0\] def= Nd(x1, r,Delfirst(l))\[0\] = x1 = Nd(x, l, r)\[0 + 1\]. 

If i = j1 for some j then we have 

(Delfirst Nd(x, l, r))\[j1\] def= Nd(x1, r,Delfirst(l))\[j1\] = r\[j\] = = Nd(x, l, r)\[j2\] = Nd(x, l, r)\[j1 + 1\]. 

If i = j2 for some j then j \< \|l\|b by 13.3.1(2) and (4). We have 

(Delfirst Nd(x, l, r))\[j2\] def= Nd(x1, r,Delfirst(l))\[j2\] = Delfirst(l)\[j\] IH= = l\[j + 1\] = Nd(x, l, r)\[(j + 1)1\] = Nd(x, l, r)\[j2 + 1\]. 

13\.3.7 Insertion of a new last label. The function Inslast(x, n, t) in- creases by one the size of the perfectly balanced tree t, where \|t\|b = n, by inserting x into a new last position. The function satisfies 

352

P̀A Pbt(t) → \|Inslast(x, \|t\|b, t)\|b = \|t\|b + 1 (1) 

P̀A Pbt(t) → Pbt Inslast(x, \|t\|b, t) (2) 

P̀A Pbt(t) ∧ i \< \|t\|b → Inslast(x, \|t\|b, t)\[i\] = t\[i\] (3) 

P̀A Pbt(t) → Inslast(x, \|t\|b, t)\[\|t\|b\] = x (4) 

and it is defined by dyadic recursion on n with substitution in parameter t as a primitive recursive function: 

Inslast(x, 0, t) = Nd(x,E, E) Inslast(x, n1,Nd(y, l, r)) = Nd(y, Inslast(x, n, l), r) Inslast(x, n2,Nd(y, l, r)) = Nd(y, l, Inslast(x, n, r)). 

Properties (1), (2), ∀i(3), and (4) are proved by Bt-induction on t. 

13\.3.8 Deletion of the last label. The function Dellast(n, t) decreases by one the size of the nonempty perfectly balanced tree t, where \|t\|b = n+1, by removing its last label. The function satisfies 

P̀A Pbt(t) ∧ \|t\|b \> 0 → \|Dellast(\|t\|b .− 1, t)\|b = \|t\|b .− 1 (1) 

P̀A Pbt(t) ∧ \|t\|b \> 0 → Pbt Dellast(\|t\|b .− 1, t) (2) 

P̀A Pbt(t) ∧ \|t\|b \> 0 ∧ i \< \|t\|b .− 1 → Dellast(\|t\|b .− 1, t)\[i\] = t\[i\] (3) 

and it is defined by dyadic recursion on n with substitution in parameter t as a primitive recursive function: 

Dellast(0, t) = E Dellast(n1,Nd(x, l, r)) = Nd(x,Dellast(n, l), r) Dellast(n2,Nd(x, l, r)) = Nd(x, l,Dellast(n, r)). 

Properties (1), (2), and ∀i(3) are proved by Bt-induction on t. 

13\.3.9 Converting lists into perfectly balanced binary trees. The function Ln2pbt(x) takes a list and yields a perfectly balanced tree with members of the list as its labels. The function satisfies 

P̀A \|Ln2pbt(x)\|b = L(x) (1) 

P̀A Pbt Ln2pbt(x) (2) 

P̀A i \< L(x) → Ln2pbt(x)\[i\] = (x)i (3) 

and it is defined by course of values recursion with measure L(x) as a primitive recursive function: 

Split(0) = 0, 0 Split(u, 0) = (u, 0), 0 Split(u, v, w) = (u, y), v, z ← Split(w) = y, z 

Ln2pbt(0) = E Ln2pbt(v, w) = Nd(v,Ln2pbt(y),Ln2pbt(z)) ← Split(w) = y, z. 

353

The auxilliary function Split satisfies: 

P̀A ∃y∃z Split(x) = y, z (4) 

P̀A Split(x) = y, z → L(x) = L(y) + L(z) ∧ (L(y) = L(z) ∨ L(y) = L(z) + 1) 

(5) 

P̀A Split(x) = y, z ∧ 2 · i \< L(x) → (x)2 · i = (y)i (6) 

P̀A Split(x) = y, z ∧ 2 · i + 1 \< L(x) → (x)2 · i+1 = (z)i. (7) 

Properties (4), ∀y∀z(5), ∀y∀z∀i(6), and ∀y∀z∀i(7) are proved by measure induction with measure L(x). 

Property (1) is proved by meausure induction with measure L(x). So take any x and consider two cases. If x = 0 then we have 

\|Ln2pbt(0)\|b def= \|E\|b = 0 = L(0). 

If x = v, w for some v and w then by (4) there exist y and z such that Split(w) = y, z. Note also that L(y) ≤ L(w) and L(z) ≤ L(w) by (5). We have 

\|Ln2pbt(v, w)\|b def= \|Nd(v,Ln2pbt(y),Ln2pbt(z))\|b = 

= \|Ln2pbt(y)\|b + \|Ln2pbt(z)\|b + 1 IH= L(y) + L(z) + 1 (5) = L(w) + 1 = L(v, w). 

Property (2) is proved by measure induction with measure L(x). So take any x and consider two cases. The case when x = 0 is straightforward. So suppose that x = v, w for some v and w. By (4) there exist y and z such that Split(w) = y, z. Note also that L(y) ≤ L(w) and L(z) ≤ L(w) by (5). We have 

Pbt Ln2pbt(v, w) def⇔ Pbt Nd(v,Ln2pbt(y),Ln2pbt(z)) 13.3.1(2)⇔ 

(\|Ln2pbt(y)\|b = \|Ln2pbt(z)\|b ∨ \|Ln2pbt(y)\|b = \|Ln2pbt(z)\|b + 1) ∧ ∧ Pbt Ln2pbt(y) ∧ Pbt Ln2pbt(z) 

(1)⇔ (L(y) = L(z) ∨ L(y) = L(z) + 1) ∧ Pbt Ln2pbt(y) ∧ Pbt Ln2pbt(z). 

The last follows from IH and (5). Property ∀i(3) is proved by measure induction with measure L(x). Take 

any x and i such that i \< L(x). Then x = v, w for some v and w and thus i \< L(v, w) = L(w) + 1. By (4) there exist y and z such that Split(w) = y, z. We consider three cases. If i = 0 then we have 

Ln2pbt(v, w)\[0\] def= Nd(v,Ln2pbt(y),Ln2pbt(z))\[0\] = v = (v, w)\[0\]. 

If i = j1 for some j then j \< L(y) and L(y) ≤ L(w) by (5). We have 

Ln2pbt(v, w)\[j1\] def= Nd(v,Ln2pbt(y),Ln2pbt(z))\[j1\] = 

= Ln2pbt(y)\[j\] IH= y\[j\] (6) = w\[2 · j\] = (v, w)\[j1\]. 

The case when i = j2 is similar. 

354

13\.3.10 Converting perfectly balanced binary trees into lists. The function Pbt2ln(t) takes a perfectly balanced tree and yields a list with labels of the tree as its members. The function satisfies 

P̀A Pbt(t) → LPbt2ln(t) = \|t\|b (1) 

P̀A Pbt(t) ∧ i \< \|t\|b → (Pbt2ln(t))i = t\[i\] (2) 

and it is defined by Bt-recursion as a primitive recursive function: 

Pbt2ln(E) = 0 Pbt2ln Nd(x, l, r) = x,Combine(Pbt2ln(l),Pbt2ln(r)). 

The auxiliary function Combine is defined in Par. 12.2.6. Properties (1) and ∀i(2) are proved by Bt-induction on t. 

355

13\.4 Applications of Trees 

Heaps and Priority Queues 

13\.4.1 Tree comparision predicates. The predicate x º t holds if x is an upper bound of the labels of the binary tree t, i.e. 

P̀Ax x º t ↔ ∀y(y ∈b t → x ≥ y). 

The predicate satisfies 

P̀A x º E (1) 

P̀A x º Nd(y, l, r) ↔ x \> y ∧ x º l ∧ x º r (2) 

P̀A x ≥ y ∧ y º t → x º t. (3) 

13\.4.2 Heaps. The predicate Heap(t) holds if t is a perfectly balanced bi- nary tree satisfying the following heap condition: 

for every nonempty subtree of t each label of its left (right) son is less than its root label. 

The predicate is defined by 

P̀Ax Heap(t) ↔ Pbt(t) ∧ ∀x∀l∀r(Nd(x, l, r) Eb t → x º l ∧ x º r). 

The predicate satisfies 

P̀A Heap(E) (1) 

P̀A Heap Nd(x, l, r) ↔ (\|l\|b = \|r\|b ∨ \|l\|b = \|r\|b + 1) ∧ x º l ∧ x º r ∧Heap(l) ∧Heap(r). 

(2) 

13\.4.3 Priority queues. 

P̀Ax Queue(q) ↔ ∃n∃t(q = n, t ∧Heap(t) ∧ \|t\|b = n). 

P̀Ax Eq = 0, E 

P̀Ax x ∈q q ↔ x ∈b T (q) 

P̀Ax \|q\|q = \|T (q)\|b P̀Ax #q(x, q) = #b(x, T (q)). 

356

13\.4.4 Insertion in priority queues. The function Upheap(n, t, x) takes a heap t of the size n and inserts x into it. The function satisfies 

P̀A Heap(t) → \|Upheap(\|t\|b, t, x)\|b = \|t\|b + 1 (1) 

P̀A Heap(t) → Heap Upheap(\|t\|b, t, x) (2) 

P̀A Heap(t) → #b 

( x,Upheap(\|t\|b, t, x) 

) = #b(x, t) + 1 (3) 

P̀A Heap(t) ∧ y 6= x → #b 

( y,Upheap(\|t\|b, t, x) 

) = #b(y, t) (4) 

and it is defined by dyadic recursion on n with substitution in parameters as a primitive recursive function: 

Upheap(0, E, x) = Nd(x, E, E) Upheap(n1,Nd(y, l, r), x) = Nd(y,Upheap(n, l, x), r) ← x ≤ y Upheap(n1,Nd(y, l, r), x) = Nd(x,Upheap(n, l, y), r) ← x \> y Upheap(n2,Nd(y, l, r), x) = Nd(y, l,Upheap(n, r, x)) ← x ≤ y Upheap(n2,Nd(y, l, r), x) = Nd(x, l,Upheap(n, r, y)) ← x \> y. 

The function Enqueue(q, x) takes a priority queue q and inserts x into it. The function satisfies 

P̀A Queue(q) → \|Enqueue(q, x)\|q = \|q\|q + 1 (5) 

P̀A Queue(q) → Queue Enqueue(q, x) (6) 

P̀A Queue(q) → #q 

( x,Enqueue(q, x) 

) = #q(x, q) + 1 (7) 

P̀A Queue(q) ∧ y 6= x → #q 

( y,Enqueue(q, x) 

) = #q(y, q) (8) 

and it is defined explicitly as a primitive recursive function: 

Enqueue((n, t), x) = n + 1,Upheap(n, t, x). 

Property (1) follows from 

P̀A Pbt(t) → \|Upheap(\|t\|b, t, x)\|b = \|t\|b + 1, (9) 

which is proved by Bt-induction on t with the induction formula ∀x(9). The base case is straightforward. In the inductive case when t = Nd(y, l, r) take any x and consider two cases. If \|l\|b = \|r\|b then \|Nd(y, l, r)\|b = \|l\|b1. We consider two subcases. If x ≤ y then we have 

\|Upheap(\|l\|b1,Nd(y, l, r), x)\|b def= \|Nd(y,Upheap(\|l\|b, l, x), r)\|b = 

= \|Upheap(\|l\|b, l, x)\|b + \|r\|b + 1 IH= \|l\|b + 1 + \|r\|b + 1 = \|Nd(y, l, r)\|b + 1. 

If x \> y then we have 

\|Upheap(\|l\|b1,Nd(y, l, r), x)\|b def= \|Nd(x,Upheap(\|l\|b, l, y), r)\|b = 

= \|Upheap(\|l\|b, l, y)\|b + \|r\|b + 1 IH= \|l\|b + 1 + \|r\|b + 1 = \|Nd(y, l, r)\|b + 1. 

357

The case when \|l\|b = \|r\|b + 1 is similar. Now note that 

P̀A Pbt(t) → y ∈b Upheap(\|t\|b, t, x) ↔ y ∈b t ∨ y = x. (10) 

Property ∀x(10) is proved by Bt-induction on t and is left to the reader. As a simple consequence of (10) we get 

P̀A Pbt(t) → y º Upheap(\|t\|b, t, x) ↔ y º t ∧ y ≥ x. (11) 

Property ∀x(2) is proved by Bt-induction on t. The base case is straight- forward. In the inductive case when t = Nd(y, l, r) take any x and consider two cases. If \|l\|b = \|r\|b then \|Nd(y, l, r)\|b = \|l\|b1. We consider two subcases. If x ≤ y then we have 

Heap Upheap(\|l\|b1,Nd(y, l, r), x) def⇔ Heap Nd(y,Upheap(\|l\|b, l, x), r) 13.4.2(2)⇔ 

(\|Upheap(\|l\|b, l, x)\|b = \|r\|b ∨ \|Upheap(\|l\|b, l, x)\|b = \|r\|b + 1) ∧ y º Upheap(\|l\|b, l, x) ∧ y º r ∧Heap Upheap(\|l\|b, l, x) ∧Heap(r) 

(1),(11)⇔ (\|l\|b + 1 = \|r\|b ∨ \|l\|b + 1 = \|r\|b + 1) ∧ 

y º l ∧ y º r ∧Heap Upheap(\|l\|b, l, x) ∧Heap(r). 

The last follows from IH and assumptions. If x \> y then we have 

Heap Upheap(\|l\|b1,Nd(y, l, r), x) def⇔ Heap Nd(x,Upheap(\|l\|b, l, y), r) 13.4.2(2)⇔ 

(\|Upheap(\|l\|b, l, y)\|b = \|r\|b ∨ \|Upheap(\|l\|b, l, y)\|b = \|r\|b + 1) ∧ x º Upheap(\|l\|b, l, y) ∧ x º r ∧Heap Upheap(\|l\|b, l, y) ∧Heap(r) 

(1),(11)⇔ (\|l\|b + 1 = \|r\|b ∨ \|l\|b + 1 = \|r\|b + 1) ∧ 

x º l ∧ x º r ∧Heap Upheap(\|l\|b, l, y) ∧Heap(r). 

The last follows from IH and assumptions by 13.4.1(3). The case when \|l\|b = \|r\|b + 1 is similar. 

Properties (3) and (4) follows from 

P̀A Pbt(t) → #b 

( y,Upheap(\|t\|b, t, x) 

) = #b(y, t) + (y =∗ x), (12) 

which is proved by Bt-induction on t with the induction formula ∀x(12). The base case is straightforward. In the inductive case when t = Nd(z, l, r) take any x and consider two cases. If \|l\|b = \|r\|b then \|Nd(y, l, r)\|b = \|l\|b1. We consider two subcases. If x ≤ z then we have 

\#b 

( y,Upheap(\|l\|b1,Nd(z, l, r), x) 

) def= 

= #b 

( y,Nd(z,Upheap(\|l\|b, l, x), r) 

) 13.1.14(1) = 

358

= #b 

( y,Upheap(\|l\|b, l, x) 

) + #b(y, r) + (y =∗ z) IH= 

= #b(y, l) + (y =∗ x) + #b(y, r) + (y =∗ z) 13.1.14(1) 

= = #b(y,Nd(z, l, r)) + (y =∗ x). 

If x \> z then we have 

\#b 

( y,Upheap(\|l\|b1,Nd(z, l, r), x) 

) def= 

= #b 

( y,Nd(x,Upheap(\|l\|b, l, z), r) 

) 13.1.14(1) = 

= #b 

( y,Upheap(\|l\|b, l, z) 

) + #b(y, r) + (y =∗ x) IH= 

= #b(y, l) + (y =∗ z) + #b(y, r) + (y =∗ x) 13.1.14(1) 

= = #b(y,Nd(z, l, r)) + (y =∗ x). 

The case when \|l\|b = \|r\|b + 1 is similar. 

13\.4.5 Deletion in priority queues. 

P̀A Heap(t) ∧ t 6= E → \|Downheap(t, x)\|b = \|t\|b (1) 

P̀A Heap(t) ∧ t 6= E → Heap Downheap(t, x) (2) 

Downheap(Nd(y, l, r), x) = Nd(x, l, r) ← l = E Downheap(Nd(y, l, r), x) = Nd(y1,Nd(x, l1, r1), r) ← 

l 6= E ∧ r = E ∧ l = Nd(y1, l1, r1) ∧ x ≤ y1 

Downheap(Nd(y, l, r), x) = Nd(x, l, r) ← l 6= E ∧ r = E ∧ l = Nd(y1, l1, r1) ∧ x \> y1 

Downheap(Nd(y, l, r), x) = Nd(y2, l,Downheap(r, x)) ← l 6= E ∧ r 6= E ∧ Root(l) = y1 ∧ Root(r) = y2 ∧ y1 ≤ y2 ∧ x ≤ y2 

Downheap(Nd(y, l, r), x) = Nd(x, l, r) ← l 6= E ∧ r 6= E ∧ Root(l) = y1 ∧ Root(r) = y2 ∧ y1 ≤ y2 ∧ x \> y2 

Downheap(Nd(y, l, r), x) = Nd(y1,Downheap(l, x), r) ← l 6= E ∧ r 6= E ∧ Root(l) = y1 ∧ Root(r) = y2 ∧ y1 \> y2 ∧ x ≤ y1 

Downheap(Nd(y, l, r), x) = Nd(x, l, r) ← l 6= E ∧ r 6= E ∧ Root(l) = y1 ∧ Root(r) = y2 ∧ y1 \> y2 ∧ x \> y1. 

P̀A Queue(q) ∧ q 6= Eq → \|Dequeue(q)\|q + 1 = \|q\|q (3) 

P̀A Queue(q) ∧ q 6= Eq → Queue Dequeue(q) (4) 

P̀A Queue(q) ∧ q 6= Eq → #q 

( Largest(q),Dequeue(q, x) 

) = #q(x, q) + 1 (5) 

P̀A Queue(q) ∧ q 6= Eq ∧ y 6= Largest(q) → #q 

( y,Dequeue(q, x) 

) = #q(y, q) 

(6) 

Dequeue(1, t) = E Dequeue(n + 1, t) = Downheap(n,Dellast(n, t), t\[n\]) ← n \> 0. 

359

P̀A Bt(t) ∧ t 6= E ∧ y 6= Root(t) → y ∈b Downheap(t, x) ↔ y ∈b t ∨ y = x 

(7) 

P̀A Bt(t) ∧ t 6= E ∧ y º t → y º Downheap(t, x) ↔ y ≥ x (8) 

13\.4.6 Heap sort. 

P̀A Hsort(x) ∼ x (1) 

P̀A Ord Hsort(x). (2) 

360

13\.5 Exercises 

13\.5.1 Exercise. Prove 

P̀A Bt(t) → Inorder(t) = Rev Inorder Reflect(t) 

13\.5.2 Exercise. Save the concatenation in the definition of the function Inorder(t) with the help of an accumulator function and verify your imple- mentation. 

13\.5.3 Exercise. Save the concatenation in the definition of the function Postorder(t) with the help of an accumulator function and verify your im- plementation. 

13\.5.4 Exercise. Find a tail recursive implementation of the function Inorder(t) and verify your implementation. 

13\.5.5 Exercise. Find a tail recursive derivation of the function Postorder(t) and verify your implementation. 

13\.5.6 Exercise. Define a function Subtrees(t) satisfying 

P̀A Bt(t) → t1 ε Subtrees(t) ↔ t1 Eb t. 

Prove that the function has the required property. 

13\.5.7 Exersice. Consider the following implementation of the deletion function t \\ {x}: 

Split Nd(y, l, r) = y, l ← r = E Split Nd(y, l, r) = y, l ← r 6= E ∧ Split(r) = x, t 

t1 t t2 = t2 ← t1 = E t1 t t2 = Nd(x, t, t2) ← t1 6= E ∧ Split(t1) = x, t 

E \\ {x} = E Nd(y, l, r) \\ {x} = Nd(y, l, r \\ {x}) ← y \< x Nd(y, l, r) \\ {x} = l t r ← y = x Nd(y, l, r) \\ {x} = Nd(y, l \\ {x}, r) ← y \> x. 

Prove 

P̀A Bst(t) → Bst(t \\ {x}) P̀A Bst(t) → y ∈ t \\ {x} ↔ y ∈ t ∧ y 6= x. 

Hint. First note that the auxiliary function Split satisfies 

361

P̀A Bt(t1) ∧ t1 6= E → Split(t1) 6= 0 

P̀A Bt(t1) ∧ t1 6= E ∧ Split(t1) = x2, t2 → y ∈b t1 ↔ y = x2 ∨ y ∈b t2 

P̀A Bt(t1) ∧ t1 6= E ∧ Split(t1) = x2, t2 → y ≺ t1 ↔ y \< x2 ∧ y ≺ t2 

P̀A Bst(t1) ∧ t1 6= E ∧ Split(t1) = x2, t2 → x2 Â t2 ∧ Bst(t2). 

362

14\. Programs Operating on Symbolic Expressions 

14\.0.8 Sublists. The predicate x ⊂ y holds if every element of the list x occurs also in the the list y, i.e. 

P̀Ax x ⊂ y → ∀z(z ε x → z ε y). 

The predicate satisfies: 

P̀A 0 ⊂ y (1) 

P̀A v, w ⊂ y ↔ v ε y ∧ w ⊂ y (2) 

P̀A x1 ⊕ x2 ⊂ y ↔ x1 ⊂ y ∧ x2 ⊂ y. (3)

14\.1 Numeric Terms 

14\.1.1 Numeric terms. Numeric terms are formed from variables xi, con- stants n by the numeric operators + (addition) and · (multiplication). 

14\.1.2 Arithmetization of numeric terms. We arithmetize numeric terms with the help of four constructors: 

xi = 0, i n = 1, n t1 +++++++++ t2 = 2, t1, t2 t1 ××××××××× t2 = 3, t1, t2. 

We assign to each numeric term τ a number pτq called the code of τ . The mapping is defined inductively on the structure of numeric terms as follows: 

pxiq = xi (1) pnq = n (2) 

pτ1 + τ2q = pτ1q +++++++++ pτ2q (3) pτ1 · τ2q = pτ1q ××××××××× pτ2q. (4) 

The predicate Term(t) holding of the codes of numeric terms is defined by course of values recursion as a primitive recursive predicate: 

Term(xi) Term(n) Term(t1 +++++++++ t2) ← Term(t1) ∧ Term(t2) Term(t1 ××××××××× t2) ← Term(t1) ∧ Term(t2). 

We identify numeric terms with their codes and from now on we will say the numeric term t instead of the code of the numeric term t. 

14\.1.3 Case analysis on numeric terms. We have the following principle of case analysis on numeric terms: 

P̀A Term(t) → ∃i t = xi ∨ ∃n t = n ∨ ∃t1∃t2 t = t1 +++++++++ t2 ∨ ∃t1∃t2 t = t1 ××××××××× t2 

(1) 

which is proved by a straightforward pair case analysis. 

14\.1.4 Structural induction on numeric terms. The formula of struc- tural induction on the numeric term t for φ\[t\] is the following one: 

∀i φ\[xi\] ∧ ∀nφ\[n\] ∧ ∀t1∀t2(φ\[t1\] ∧ φ\[t2\] → φ\[t1 +++++++++ t2\]) ∧ ∀t1∀t2(φ\[t1\] ∧ φ\[t2\] → φ\[t1 ××××××××× t2\]) → Term(t) → φ\[t\]. 

In the sequel we will often say shortly the Term-induction on t instead of the structural induction on the numeric term t. 

364

14\.1.5 Theorem. We have 

P̀A ∀i φ\[xi\] ∧ ∀nφ\[n\] ∧ ∀t1∀t2(φ\[t1\] ∧ φ\[t2\] → φ\[t1 +++++++++ t2\]) ∧ ∀t1∀t2(φ\[t1\] ∧ φ\[t2\] → φ\[t1 ××××××××× t2\]) → Term(t) → φ\[t\]. 

Proof. The property is proved by complete induction on t. Take any t and under the assumptions of the claim consider the following cases by 14.1.3(1). The case when t = xi or t = n is trivial. The case when t = t1 +++++++++ t2 for some t1, t2 we have φ\[t1\] and φ\[t2\] by IH since t1 \< t1 +++++++++ t2 and t2 \< t1 +++++++++ t2. From this and assumptions we get φ\[t1 +++++++++ t2\]. The case when t = t1 ××××××××× t2 for some t1, t2 is similar. ut 

14\.1.6 Structural recursion on numeric terms. Initial clauses for clausal definitions with structural recursion on numeric terms are of a form 

f(\~y, t, \~z) = α1\[\~y, \~z, i\] ← t = xi 

f(\~y, t, \~z) = α2\[\~y, \~z, n\] ← t = n 

f(\~y, t, \~z) = α3\[λ̇\~yt\~z.f(\~y, ti, \~z); \~y, \~z, t1, t2\] ← t = t1 +++++++++ t2 f(\~y, t, \~z) = α4\[λ̇\~yt\~z.f(\~y, ti, \~z); \~y, \~z, t1, t2\] ← t = t1 ××××××××× t2. 

In the sequel we will often say shortly the Term-recursion on t instead of the structural recursion on the numeric term t. 

14\.1.7 Free variables. The function FV (t) takes a numeric term and re- turns a list of indices of free variables of the term. The function is defined by Term-recursion as a primitive recursive function: 

FV (xi) = i, 0 FV (n) = 0 FV (t1 +++++++++ t2) = FV (t1)⊕ FV (t2) FV (t1 ××××××××× t2) = FV (t1)⊕ FV (t2). 

14\.1.8 Denotation of numeric terms. The denotation function \[\[t\]\]v takes the code t of a numeric term τ and the assignment v which is a list assigning the value (v)i to the variable xi and yields the value of the term τ . The function is defined by Term-recursion on t as a primitive recursive function: 

\[\[xi\]\]v = (v)i 

\[\[n\]\]v = n \[\[t1 +++++++++ t2\]\]v = \[\[t1\]\]v + \[\[t2\]\]v \[\[t1 ××××××××× t2\]\]v = \[\[t1\]\]v ·\[\[t2\]\]v. 

14\.1.9 Coincidence of assignments. The ternary predicate v1 ≡ v2 \[is\] holds if the assignments v1 and v2 coincide on every variable whose index is in the list is, i.e. 

P̀Ax v1 ≡ v2 \[is\] ↔ ∀i(i ε is → (v1)i = (v2)i). 

365

The following holds 

P̀A Term(t) ∧ FV (t) ⊂ is ∧ v1 ≡ v2 \[is\] → \[\[t\]\]v1 = \[\[t\]\]v2 . (1) 

Property (1) is proved by Term-induction on t. For instance, if t = xi then 

\[\[xi\]\]v1 = (v1)i def= (v2)i = \[\[xi\]\]v2 . 

If t = t1 +++++++++ t2 then FV (t1) ⊂ is and FV (t2) ⊂ is by 14.0.8(3) and we obtain 

\[\[t1 +++++++++ t2\]\]v1 = \[\[t1\]\]v1 + \[\[t2\]\]v1 

IH= \[\[t1\]\]v2 + \[\[t2\]\]v2 = \[\[t1 +++++++++ t2\]\]v2 . 

The remaining cases are similar. 

14\.1.10 Postfix machine. Our next task is the proof of correctness of a simple postfix machine for evaluating numeric terms. The machine is repre- sented by the function Run(p, v, s), where p is a list of instructions (program), v is an assignment (environment), and s is a list of values (I/O stack). 

Instructions are defined with the help of four constructors: 

LOAD(i) = 0, i PUSH (n) = 1, n ADD = 2, 0 MULT = 3, 0. 

The predicate Instr(i) holds if i is an instruction of the postfix machine. The predicate is primitive recursive with the following explicit clausal definition: 

Instr LOAD(i) Instr PUSH (n) Instr(ADD) Instr(MULT ). 

The predicate Program(p) holds if p is a list of instructions. The predicate is defined by list recursion as a primitive recursive predicate: 

Program(0) Program(i, p) ← Instr(i) ∧ Program(p). 

Numeric terms are compiled into programs by the function Cmp(t). The function is defined by Term-recursion as a primitive recursive function: 

Cmp(xi) = LOAD(i), 0 Cmp(n) = PUSH (n), 0 Cmp(t1 +++++++++ t2) = Cmp(t1)⊕ Cmp(t2)⊕ (ADD , 0) Cmp(t1 ××××××××× t2) = Cmp(t1)⊕ Cmp(t2)⊕ (MULT , 0). 

The function Run(p, v, s) representing the postfix machine is defined by list recursion on p with substitution in parameter s as a primitive recursive func- tion: 

366

Run(0, v, t, s) = t Run((LOAD(i), p), v, s) = Run(p, v, (v)i, s) Run((PUSH (n), p), v, s) = Run(p, v, n, s) Run((ADD , p), v, t2, t1, s) = Run(p, v, t1 + t2, s) Run((MULT , p), v, t2, t1, s) = Run(p, v, t1 · t2, s). 

Finally, programs of the postfix machine are evaluated by 

P̀Ax Eval(p, v) = Run(p, v, 0). 

The following property expresses the correctness of the evaluation func- tion: 

P̀A Term(t) → Eval(Cmp(t), v) = \[\[t\]\]v. (1) 

To see this we first prove the basic property of the function Run: 

P̀A Term(t) → Run(Cmp(t)⊕ p, v, s) = Run(p, v, \[\[t\]\]v, s). (2) 

Property ∀p∀s(2) is proved by Term-induction on t. In the case when t = xi 

take any p, s and we have 

Run(Cmp(xi)⊕ p, v, s) def= Run((LOAD(i), p), v, s) def= = Run(p, v, (v)i, s) = Run(p, v, \[\[xi\]\]v, s). 

In the case when t = n take any p, s and we have 

Run(Cmp(n)⊕ p, v, s) def= Run((PUSH (n), p), v, s) def= = Run(p, v, n, s) = Run(p, v, \[\[n\]\]v, s). 

In the case when t = t1 +++++++++ t2 take any p, s and we have 

Run(Cmp(t1 +++++++++ t2)⊕ p, v, s) def= 

= Run((Cmp(t1)⊕ Cmp(t2)⊕ (ADD , p)), v, s) IH= 

= Run((Cmp(t2)⊕ (ADD , p)), v, \[\[t1\]\]v, s) IH= 

= Run((ADD , p), v, \[\[t2\]\]v, \[\[t1\]\]v, s) def= = Run(p, v, \[\[t1\]\]v + \[\[t2\]\]v, s) = Run(p, v, \[\[t1 +++++++++ t2\]\]v, s). 

The case when t = t1 ××××××××× t2 has a similar proof. We are now in position to prove (1). Assume Term(t) and we have 

Eval(Cmp(t), v) def= Run(Cmp(t), v, 0) (2) = Run(0, v, \[\[t\]\]v, 0) def= \[\[t\]\]v. 

367

14\.2 Pair Terms 

14\.2.1 Pair terms. Pair terms are formed from variables xi, the constant 0 by the operators H (head), T (tail), x, y (pairing), and the ternary case discrimination function D. 

14\.2.2 Arithmetization of pair terms. We arithmetize pair terms with the help of the following constructors: 

xi = 0, i 0 = 1, 0 H(t) = 2, t T(t) = 3, t t1 ,,,,,,,,, t2 = 4, t1, t2 D(t1, t2, t3) = 5, t1, t2, t3. 

We assign to each pair term τ a number pτq called the code of τ . The mapping is defined inductively on the structure of pair terms: 

pxiq = xi (1) p0q = 0 (2) 

pH(τ)q = H(pτq) (3) pT (τ)q = T(pτq) (4) pτ1, τ2q = pτ1q,,,,,,,,, pτ2q (5) 

pD(τ1, τ2, τ3)q = D(pτ1q, pτ2q, pτ3q). (6) 

The predicate Term(t) holding of the codes of pair terms is defined by course of values recursion as a primitive recursive predicate: 

Term(xi) Term(0) Term H(t) ← Term(t) Term T(t) ← Term(t) Term(t1 ,,,,,,,,, t2) ← Term(t1) ∧ Term(t2) Term D(t1, t2, t3) ← Term(t1) ∧ Term(t2) ∧ Term(t3). 

We identify pair terms with their codes and from now on we will say the pair term t instead of the code of the pair term t. 

14\.2.3 Case analysis on pair terms. We have the following principle of case analysis on pair terms: 

P̀A Term(t) → ∃i t = xi ∨ t = 0 ∨ ∃t1 t = H(t1) ∨ ∃t1 t = T(t1) ∨ ∃t1∃t2 t = t1 ,,,,,,,,, t2 ∨ ∃t1∃t2∃t3 t = D(t1, t2, t3) 

(1) 

which is proved by a straightforward pair case analysis. 

368

14\.2.4 Structural induction on pair terms. The formula of structural induction on the pair term t for φ\[t\] is the following one: 

∀i φ\[xi\] ∧ φ\[0\] ∧ ∀t(φ\[t\] → φ\[H(t)\]) ∧ ∀t(φ\[t\] → φ\[T(t)\]) ∧ ∀t1∀t2(φ\[t1\] ∧ φ\[t2\] → φ\[t1 ,,,,,,,,, t2\]) ∧ ∀t1∀t2∀t3(φ\[t1\] ∧ φ\[t2\] ∧ φ\[t3\] → φ\[D(t1, t2, t3)\]) → Term(t) → φ\[t\]. 

In the sequel we will often say shortly the Term-induction on t instead of the structural induction on the pair term t. 

14\.2.5 Theorem. We have 

P̀A ∀i φ\[xi\] ∧ φ\[0\] ∧ ∀t(φ\[t\] → φ\[H(t)\]) ∧ ∀t(φ\[t\] → φ\[T(t)\]) ∧ ∀t1∀t2(φ\[t1\] ∧ φ\[t2\] → φ\[t1 ,,,,,,,,, t2\]) ∧ ∀t1∀t2∀t3(φ\[t1\] ∧ φ\[t2\] ∧ φ\[t3\] → φ\[D(t1, t2, t3)\]) → Term(t) → φ\[t\]. 

Proof. The property is proved by complete induction on t. Take any t and under the assumptions of the claim consider the following cases by 14.2.3(1). The case when t = xi or t = 0 is trivial. The case when t = t1 ,,,,,,,,, t2 for some t1, t2 we have φ\[t1\] and φ\[t2\] by IH since t1 \< t1 ,,,,,,,,, t2 and t2 \< t1 ,,,,,,,,, t2. From this and assumptions we get φ\[t1 ,,,,,,,,, t2\]. The remaining cases are similar. ut 

14\.2.6 Structural recursion on pair terms. Initial clauses for clausal definitions with structural recursion on pair terms are of a form 

f(\~y, t, \~z) = α1\[\~y, \~z, i\] ← t = xi 

f(\~y, t, \~z) = α2\[\~y, \~z\] ← t = 0 f(\~y, t, \~z) = α3\[λ̇\~yt\~z.f(\~y, t1, \~z); \~y, \~z, t1\] ← t = H(t1) f(\~y, t, \~z) = α4\[λ̇\~yt\~z.f(\~y, t1, \~z); \~y, \~z, t1\] ← t = T(t1) f(\~y, t, \~z) = α5\[λ̇\~yt\~z.f(\~y, ti, \~z); \~y, \~z, t1, t2\] ← t = t1 ,,,,,,,,, t2 f(\~y, t, \~z) = α6\[λ̇\~yt\~z.f(\~y, ti, \~z); \~y, \~z, t1, t2, t3\] ← t = D(t1, t2, t3). 

In the sequel we will often say shortly the Term-recursion on t instead of the structural recursion on the pair term t. 

14\.2.7 Free variables. The function FV (t) takes a pair term and returns a list of indices of free variables of the term. The function is defined by Term-recursion as a primitive recursive function: 

FV (xi) = i, 0 FV (0) = 0 FV H(t) = FV (t) FV T(t) = FV (t) FV (t1 ,,,,,,,,, t2) = FV (t1)⊕ FV (t2) FV D(t1, t2, t3) = FV (t1)⊕ FV (t2)⊕ FV (t3). 

369

14\.2.8 Denotation of pair terms. The denotation function \[\[t\]\]v takes the code t of a pair term τ and the assignment v which is a list assigning the value (v)i to the variable xi and yields the value of the term τ . The function is defined by Term-recursion on t as a primitive recursive function: 

\[\[xi\]\]v = (v)i 

\[\[0\]\]v = 0 \[\[H(t)\]\]v = H(\[\[t\]\]v) \[\[T(t)\]\]v = T (\[\[t\]\]v) \[\[t1 ,,,,,,,,, t2\]\]v = \[\[t1\]\]v, \[\[t2\]\]v \[\[D(t1, t2, t3)\]\]v = D(\[\[t1\]\]v, \[\[t2\]\]v, \[\[t3\]\]v). 

14\.2.9 Coincidence of assignments. Consider the predicate v1 ≡ v2 \[is\] from Par. 14.1.9. The following holds 

P̀A Term(t) ∧ FV (t) ⊂ is ∧ v1 ≡ v2 \[is\] → \[\[t\]\]v1 = \[\[t\]\]v2 . (1) 

Property (1) is proved by Term-induction on t (see the proof of 14.1.9(1)). 

14\.2.10 Postfix machine. Our next task is the proof of correctness of a simple postfix machine for evaluating pair terms. The machine is represented by the function Run(p, v, s), where p is a list of instructions (program), v is an assignment (environment), and s is a list of values (I/O stack). 

Instructions are defined with the help of the following constructors: 

LOAD(i) = 0, i PUSHZ = 1, 0 HEAD = 2, 0 TAIL = 3, 0 PAIR = 4, 0 JUMPZ = 5, 0 JUMP = 6, 0. 

The predicate Instr(i) holds if i is an instruction of the postfix machine. The predicate is primitive recursive with the following explicit clausal definition: 

Instr LOAD(i) Instr(PUSHZ ) Instr(HEAD) Instr(TAIL) Instr(PAIR) Instr(JUMPZ ) Instr(JUMP). 

The predicate Program(p) holds if p is a list of instructions. The predicate is defined by list recursion as a primitive recursive predicate: 

Program(0) Program(i, p) ← Instr(i) ∧ Program(p). 

370

Pair terms are compiled into programs by the function Cmp(t). The function is defined by Term-recursion as a primitive recursive function: 

Cmp(xi) = LOAD(i), 0 Cmp(0) = PUSHZ , 0 Cmp H(t) = Cmp(t)⊕ (HEAD , 0) Cmp T(t) = Cmp(t)⊕ (TAIL, 0) Cmp(t1 ,,,,,,,,, t2) = Cmp(t1)⊕ Cmp(t2)⊕ (PAIR, 0) Cmp D(t1, t2, t3) = p1 ⊕ p2 ⊕ p3 ← 

Cmp(t1) = p1 ∧ JUMPZ (LCmp(t2) + 1),Cmp(t2) = p2 ∧ JUMP LCmp(t3),Cmp(t3) = p3. 

The function Run(p, v, s) representing the postfix machine is defined by course of values recursion with measure L(p) with substitution in param- eter s as a primitive recursive function: 

Run(0, v, t, s) = t Run((LOAD(i), p), v, s) = Run(p, v, (v)i, s) Run((PUSHZ , p), v, s) = Run(p, v, 0, s) Run((HEAD , p), v, t, s) = Run(p, v,H(t), s) Run((TAIL, p), v, t, s) = Run(p, v, T (t), s) Run((PAIR, p), v, t2, t1, s) = Run(p, v, (t1, t2), s) Run((JUMPZ (n), p), v, t, s) = Run(Drop(n, p), v, s) ← t = 0 Run((JUMPZ (n), p), v, t, s) = Run(p, v, s) ← t 6= 0 Run((JUMP(n), p), v, s) = Run(Drop(n, p), v, s). 

Finally, programs of the postfix machine are evaluated by 

P̀Ax Eval(p, v) = Run(p, v, 0). 

The following property expresses the correctness of the evaluation func- tion: 

P̀A Term(t) → Eval(Cmp(t), v) = \[\[t\]\]v. (1) 

To see this we first prove the property of the function Run: 

P̀A Term(t) → Run(Cmp(t)⊕ p, v, s) = Run(p, v, \[\[t\]\]v, s). (2) 

Property ∀p∀s(2) is proved by Term-induction on t. In the case when t = D(t1, t2, t3) take any p, s and we have 

Run(Cmp D(t1, t2, t3)⊕ p, v, s) def= 

= Run ( Cmp(t1)⊕ (JUMPZ (LCmp(t2) + 1),Cmp(t2))⊕ ⊕ (JUMP LCmp(t3),Cmp(t3))⊕ p, v, s 

) IH= 

= Run ( JUMPZ (LCmp(t2) + 1),Cmp(t2)⊕ ⊕ (JUMP LCmp(t3),Cmp(t3))⊕ p, v, \[\[t1\]\]v, s 

) . 

(3) 

371

We consider two subcases. If \[\[t1\]\]v = 0 then we have 

Run(Cmp D(t1, t2, t3)⊕ p, v, s) (3),def 

= 

= Run ( Drop(LCmp(t2) + 1, 

Cmp(t2)⊕ (JUMP LCmp(t3),Cmp(t3))⊕ p, v, s ) 12.6.5(2) 

= 

= Run(Cmp(t3)⊕ p, v, s) IH= Run(p, v, \[\[t3\]\]v, s) = = Run(p, v,D(\[\[t1\]\]v, \[\[t2\]\]v, \[\[t3\]\]v), s) = Run(p, v, \[\[D(t1, t2, t3)\]\]v, s). 

If \[\[t1\]\]v 6= 0 then we have 

Run(Cmp D(t1, t2, t3)⊕ p, v, s) (3),def 

= 

= Run(Cmp(t2)⊕ (JUMP LCmp(t3),Cmp(t3))⊕ p, v, s) IH= 

= Run(JUMP LCmp(t3),Cmp(t3)⊕ p, v, \[\[t2\]\]v, s) def= 

= Run(Drop(JUMP LCmp(t3),Cmp(t3)⊕ p), v, \[\[t2\]\]v, s) 12.6.5(2) 

= = Run(p, v, \[\[t2\]\]v, s) = Run(p, v,D(\[\[t1\]\]v, \[\[t2\]\]v, \[\[t3\]\]v), s) = = Run(p, v, \[\[D(t1, t2, t3)\]\]v, s). 

The remaining cases are left to the reader (see the proof of 14.1.10(2)). We are now in position to prove (1). Assume Term(t) and we have 

Eval(Cmp(t), v) def= Run(Cmp(t), v, 0) (2) = Run(0, v, \[\[t\]\]v, 0) def= \[\[t\]\]v. 

372

14\.3 Propositional Logic 

14\.3.1 Propositional formulas. Propositional formulas are formed from propositional constants \> (true) and ⊥ (falsehood), propositional variables pi 

by the propositional connectives ¬φ (negation), φ1∧φ2 (conjunction), φ1∨φ2 

(disjunction), φ1 → φ2 (implication), and φ1 ↔ φ2 (equivalence). 

14\.3.2 Arithmetization of propositional formulas. We arithmetize pro- positional formulas with the help of the following constructors: 

\>\>\>\>\>\>\>\>\> = 0, 0 ⊥⊥⊥⊥⊥⊥⊥⊥⊥ = 1, 0 pi = 2, i ¬¬¬¬¬¬¬¬¬a = 3, a a ∧∧∧∧∧∧∧∧∧ b = 4, a, b a ∨∨∨∨∨∨∨∨∨ b = 5, a, b a→→→→→→→→→ b = 6, a, b a↔↔↔↔↔↔↔↔↔ b = 7, a, b. 

We assign to each propositional formula φ a number pφq called the code of φ. The mapping is defined inductively on the structure of propositional formulas: 

p\>q =\>\>\>\>\>\>\>\>\> (1) p⊥q =⊥⊥⊥⊥⊥⊥⊥⊥⊥ (2) ppiq = pi (3) 

p¬φq = (¬¬¬¬¬¬¬¬¬pφq) (4) pφ1 ∧ φ2q = (pφ1q ∧∧∧∧∧∧∧∧∧ pφ2q) (5) pφ1 ∨ φ2q = (pφ1q ∨∨∨∨∨∨∨∨∨ pφ2q) (6) 

pφ1 → φ2q = (pφ1q→→→→→→→→→ pφ2q) (7) pφ1 ↔ φ2q = (pφ1q↔↔↔↔↔↔↔↔↔ pφ2q). (8) 

The predicate Form(a) holding of the codes of propositional formulas is defined by course of values recursion as a primitive recursive predicate: 

Form(\>\>\>\>\>\>\>\>\>) Form(⊥⊥⊥⊥⊥⊥⊥⊥⊥) Form(pi) Form(¬¬¬¬¬¬¬¬¬a) ← Form(a) Form(a ∧∧∧∧∧∧∧∧∧ b) ← Form(a) ∧ Form(b) Form(a ∨∨∨∨∨∨∨∨∨ b) ← Form(a) ∧ Form(b) Form(a→→→→→→→→→ b) ← Form(a) ∧ Form(b) Form(a↔↔↔↔↔↔↔↔↔ b) ← Form(a) ∧ Form(b). 

We identify propositional formulas with their codes and from now on we will say the propositional formula a instead of the code of the propositional formula a. 

373

The predicate Lform(as) holds if as is a list of propositional formulas. The predicate is defined by list recursion as a primitive recursive predicate: 

Lform(0) Lform(a, as) ← Form(a) ∧ Lform(as). 

14\.3.3 Case analysis on propositional formulas. We have the following principle of case analysis on propositional formulas: 

P̀A Form(a) → a =\>\>\>\>\>\>\>\>\> ∨ a =⊥⊥⊥⊥⊥⊥⊥⊥⊥ ∨ ∃i a = pi ∨ ∃b a = (¬¬¬¬¬¬¬¬¬b) ∨ ∃b∃c a = (b ∧∧∧∧∧∧∧∧∧ c) ∨ ∃b∃c a = (b ∨∨∨∨∨∨∨∨∨ c) ∨ ∃b∃c a = (b→→→→→→→→→ c) ∨ ∃b∃c a = (b↔↔↔↔↔↔↔↔↔ c), 

(1) 

which is proved by a straightforward pair case analysis. 

14\.3.4 Structural induction on propositional formulas. The formula of structural induction on the propositional formula a for φ\[a\] is the following one: 

φ\[\>\>\>\>\>\>\>\>\>\] ∧ φ\[⊥⊥⊥⊥⊥⊥⊥⊥⊥\] ∧ ∀i φ\[pi\] ∧ ∀a(φ\[a\] → φ\[¬¬¬¬¬¬¬¬¬a\]) ∧ ∀a∀b(φ\[a\] ∧ φ\[b\] → φ\[a ∧∧∧∧∧∧∧∧∧ b\]) ∧ ∀a∀b(φ\[a\] ∧ φ\[b\] → φ\[a ∨∨∨∨∨∨∨∨∨ b\]) ∧ ∀a∀b(φ\[a\] ∧ φ\[b\] → φ\[a→→→→→→→→→ b\]) ∧ ∀a∀b(φ\[a\] ∧ φ\[b\] → φ\[a↔↔↔↔↔↔↔↔↔ b\]) → Form(a) → φ\[a\]. 

In the sequel we will often say shortly the Form-induction on a instead of the structural induction on the propositional formula a. 

14\.3.5 Theorem. We have 

P̀A φ\[\>\>\>\>\>\>\>\>\>\] ∧ φ\[⊥⊥⊥⊥⊥⊥⊥⊥⊥\] ∧ ∀i φ\[pi\] ∧ ∀a(φ\[a\] → φ\[¬¬¬¬¬¬¬¬¬a\]) ∧ ∀a∀b(φ\[a\] ∧ φ\[b\] → φ\[a ∧∧∧∧∧∧∧∧∧ b\]) ∧ ∀a∀b(φ\[a\] ∧ φ\[b\] → φ\[a ∨∨∨∨∨∨∨∨∨ b\]) ∧ ∀a∀b(φ\[a\] ∧ φ\[b\] → φ\[a→→→→→→→→→ b\]) ∧ ∀a∀b(φ\[a\] ∧ φ\[b\] → φ\[a↔↔↔↔↔↔↔↔↔ b\]) → Form(a) → φ\[a\]. 

Proof. The property is proved by complete induction on a. Take any a and under the assumptions of the claim consider the cases according to 14.3.3(1). If a = (b ∧∧∧∧∧∧∧∧∧ b) for some b, c then we have φ\[b\] and φ\[c\] by IH since b \< b ∧∧∧∧∧∧∧∧∧ c and c \< b ∧∧∧∧∧∧∧∧∧ c. From this and assumptions we get φ\[b ∧∧∧∧∧∧∧∧∧ c\]. The remaining cases are similar. ut 

14\.3.6 Structural recursion on propositional formulas. Initial clauses for clausal definitions with structural recursion on propositional formulas are of a form 

f(\~y, a, \~z) = α1\[\~y, \~z\] ← a =\>\>\>\>\>\>\>\>\> f(\~y, a, \~z) = α2\[\~y, \~z\] ← a =⊥⊥⊥⊥⊥⊥⊥⊥⊥ f(\~y, a, \~z) = α3\[\~y, \~z, i\] ← a = pi 

f(\~y, a, \~z) = α4\[λ̇\~ya\~z.f(\~y, b, \~z); \~y, \~z, b\] ← a = (¬¬¬¬¬¬¬¬¬b) 

374

f(\~y, a, \~z) = α5\[λ̇\~ya\~z.f(\~y, b, \~z), λ̇\~ya\~z.f(\~y, c, \~z); \~y, \~z, b, c\] ← a = (b ∧∧∧∧∧∧∧∧∧ c) f(\~y, a, \~z) = α6\[λ̇\~ya\~z.f(\~y, b, \~z), λ̇\~ya\~z.f(\~y, c, \~z); \~y, \~z, b, c\] ← a = (b ∨∨∨∨∨∨∨∨∨ c) f(\~y, a, \~z) = α7\[λ̇\~ya\~z.f(\~y, b, \~z), λ̇\~ya\~z.f(\~y, c, \~z); \~y, \~z, b, c\] ← a = (b→→→→→→→→→ c) f(\~y, a, \~z) = α8\[λ̇\~ya\~z.f(\~y, b, \~z), λ̇\~ya\~z.f(\~y, c, \~z); \~y, \~z, b, c\] ← a = (b↔↔↔↔↔↔↔↔↔ c). 

In the sequel we will often say shortly the Form-recursion on a instead of the structural recursion on the propositional formula a. 

14\.3.7 Propositional size. The function \|a\|p counts the number of propo- sitional connectives and propositional variables in the propositional formula a. The function is defined by Form-recursion as a primitive recursive function: 

\|\>\>\>\>\>\>\>\>\>\|p = 1 \|⊥⊥⊥⊥⊥⊥⊥⊥⊥\|p = 1 \|pi\|p = 1 \|¬¬¬¬¬¬¬¬¬a\|p = \|a\|p + 1 \|a ∧∧∧∧∧∧∧∧∧ b\|p = \|a\|p + \|b\|p + 1 \|a ∨∨∨∨∨∨∨∨∨ b\|p = \|a\|p + \|b\|p + 1 \|a→→→→→→→→→ b\|p = \|a\|p + \|b\|p + 1 \|a↔↔↔↔↔↔↔↔↔ b\|p = \|a\|p + \|b\|p + 1. 

The function ‖as‖p computes the sum of the propositional sizes of for- mulas of the list as. The function is defined by list recursion as a primitive recursive function: 

‖0‖p = 0 ‖a, as‖p = \|a\|p + ‖as‖p. 

14\.3.8 Propositional variables. The predicate Lpvar(as) holds if as is a list of propositional variables, i.e. 

P̀Ax Lpvar(as) ↔ ∀a(a ε as → ∃i a = pi). 

The predicate satisfies the following easy to prove properties: 

P̀A Lpvar(0) (1) 

P̀A Lpvar(a, as) ↔ ∃i a = pi ∧ Lpvar(as). (2) 

The function PV (a) takes a propositional formula and returns a list of indices of propositional variables of the formula. The function is defined by Form-recursion as a primitive recursive function: 

PV (\>\>\>\>\>\>\>\>\>) = 0 PV (⊥⊥⊥⊥⊥⊥⊥⊥⊥) = 0 PV (pi) = i, 0 PV (¬¬¬¬¬¬¬¬¬a) = PV (a) PV (a ∧∧∧∧∧∧∧∧∧ b) = PV (a)⊕ PV (b) PV (a ∨∨∨∨∨∨∨∨∨ b) = PV (a)⊕ PV (b) 

375

PV (a→→→→→→→→→ b) = PV (a)⊕ PV (b) PV (a↔↔↔↔↔↔↔↔↔ b) = PV (a)⊕ PV (b). 

The function PVL(as) returns the list union of indices of the propositional variables of the list of formulas as. The function is defined by list recursion as a primitive recursive function: 

PVL(0) = 0 PVL(a, as) = PV (a)⊕ PVL(as). 

14\.3.9 Truth predicate. The predicate v \|=p a holds if the propositional formula a is true in the propositional valuation v. The predicate is defined by Form-recursion on a as a primitive recursive predicate: 

v \|=p \>\>\>\>\>\>\>\>\> v \|=p pi ← i ε v v \|=p (¬¬¬¬¬¬¬¬¬a) ← v 6\|=p a v \|=p (a ∧∧∧∧∧∧∧∧∧ b) ← v \|=p a ∧ v \|=p b v \|=p (a ∨∨∨∨∨∨∨∨∨ b) ← v \|=p a v \|=p (a ∨∨∨∨∨∨∨∨∨ b) ← v 6\|=p a ∧ v \|=p b v \|=p (a→→→→→→→→→ b) ← v 6\|=p a v \|=p (a→→→→→→→→→ b) ← v \|=p a ∧ v \|=p b v \|=p (a↔↔↔↔↔↔↔↔↔ b) ← v \|=p a ∧ v \|=p b v \|=p (a↔↔↔↔↔↔↔↔↔ b) ← v 6\|=p a ∧ v 6\|=p b. 

The predicate has the following easy to prove properties: 

P̀A v \|=p \>\>\>\>\>\>\>\>\> (1) 

P̀A v 6\|=p ⊥⊥⊥⊥⊥⊥⊥⊥⊥ (2) 

P̀A v \|=p pi ↔ i ε v (3) 

P̀A v \|=p (¬¬¬¬¬¬¬¬¬a) ↔ v 6\|=p a (4) 

P̀A v \|=p (a ∧∧∧∧∧∧∧∧∧ b) ↔ v \|=p a ∧ v \|=p b (5) 

P̀A v \|=p (a ∨∨∨∨∨∨∨∨∨ b) ↔ v \|=p a ∨ v \|=p b (6) 

P̀A v \|=p (a→→→→→→→→→ b) ↔ v \|=p a → v \|=p b (7) 

P̀A v \|=p (a↔↔↔↔↔↔↔↔↔ b) ↔ v \|=p a ↔ v \|=p b. (8) 

14\.3.10 Coincidence of propositional valuations. The ternary predi- cate v1 ≡ v2 \[is\] holds if the propositional valuations v1 and v2 coincide on every propositional variable whose index is in the list is, i.e. 

P̀Ax v1 ≡ v2 \[is\] ↔ ∀i(i ε a → i ε v1 ↔ i ε v2). 

The following holds 

P̀A Form(a) ∧ PV (a) ⊂ is ∧ v1 ≡ v2 \[is\] → v1 \|=p a ↔ v2 \|=p a. (1) 

376

Property (1) is proved by Form-induction on a. For instance, if a = pi then 

v1 \|=p pi 14.3.9(3)⇔ i ε v1 

def⇔ i ε v2 14.3.9(3)⇔ v2 \|=p pi. 

If a = (b ∧∧∧∧∧∧∧∧∧ c) then PV (b) ⊂ is and PV (c) ⊂ is by 14.0.8(3) and we obtain 

v1 \|=p (b ∧∧∧∧∧∧∧∧∧ c) 14.3.9(5)⇔ v1 \|=p b ∧ v1 \|=p c 

IH⇔ v2 \|=p b ∧ v2 \|=p c 

14\.3.9(5)⇔ v2 \|=p (b ∧∧∧∧∧∧∧∧∧ c). 

The remaining cases are similar. 

14\.3.11 Tautologies. A propositional formula a is said to be a tautology, which is written as \|=p a, if it is true in any propositional valuation. The predicate \|=p a has the following explicit definition: 

P̀Ax \|=p a ↔ ∀v v \|=p a. 

14\.3.12 Generalized connectives. The generalized conjunction ∧∧∧ 

(as) is defined by list recursion as a primitive recursive function: 

∧∧∧ (0) =\>\>\>\>\>\>\>\>\>∧∧∧ (a, as) = a ∧∧∧∧∧∧∧∧∧ ∧∧∧ 

(as). 

We have 

P̀A Lform(as) → Form ∧∧∧ 

(as) (1) 

P̀A v \|=p 

∧∧∧ (as) ↔ ∀a(a ε as → v \|=p a) (2) 

P̀A v \|=p 

∧∧∧ (as ⊕ bs) ↔ v \|=p 

∧∧∧ (as) ∧ v \|=p 

∧∧∧ (bs). (3) 

Properties are proved by straightforward list induction. The generalized disjunction 

∨∨∨ (as) is defined by list recursion as a primi- 

tive recursive function: ∨∨∨ 

(0) =⊥⊥⊥⊥⊥⊥⊥⊥⊥∨∨∨ (a, as) = a ∨∨∨∨∨∨∨∨∨ ∨∨∨ 

(as). 

We have 

P̀A Lform(as) → Form ∨∨∨ 

(as) (4) 

P̀A v \|=p 

∨∨∨ (as) ↔ ∃a(a ε as ∧ v \|=p a) (5) 

P̀A v \|=p 

∨∨∨ (as ⊕ bs) ↔ v \|=p 

∨∨∨ (as) ∨ v \|=p 

∨∨∨ (bs). (6) 

Properties are proved by straightforward list induction. 

377

14\.3.13 Propositional sequents. A propositional sequent is an ordered pair 

〈as, bs〉 (1) 

where as and bs are lists of propositional formulas. The list as is called the antecedent of the sequent (1); the list bs its succedent. The meaning of the sequent (1) is the formula 

∧∧∧ (as)→→→→→→→→→ 

∨∨∨ (bs) . (2) 

The sequent (1) is said to be a tautology, which is written as as \|=p bs, if the corresponding formula (2) is. The predicate as \|=p bs has the following explicit definition: 

P̀Ax as \|=p bs ↔ \|=p ( ∧∧∧ 

(as)→→→→→→→→→ ∨∨∨ 

(bs)). 

Propositional sequents which antecedents and succedents consist only of propositional variables are called atomic propositional sequents. 

14\.3.14 Basic properties of propositional sequents. We have 

P̀A \|=p a ↔ 0 \|=p a, 0 (1) 

P̀A as1 ⊕ (a, as2) \|=p bs ↔ a, as1 ⊕ as2 \|=p bs (2) 

P̀A as \|=p bs1 ⊕ (b, bs2) ↔ as \|=p b, bs1 ⊕ bs2 (3) 

P̀A \>\>\>\>\>\>\>\>\>, as \|=p bs ↔ as \|=p bs (4) 

P̀A as \|=p \>\>\>\>\>\>\>\>\>, bs (5) 

P̀A ⊥⊥⊥⊥⊥⊥⊥⊥⊥, as \|=p bs (6) 

P̀A as \|=p ⊥⊥⊥⊥⊥⊥⊥⊥⊥, bs ↔ as \|=p bs (7) 

P̀A pi, as \|=p pi, bs (8) 

P̀A ¬¬¬¬¬¬¬¬¬a, as \|=p bs ↔ as \|=p a, bs (9) 

P̀A as \|=p ¬¬¬¬¬¬¬¬¬a, bs ↔ a, as \|=p bs (10) 

P̀A a ∧∧∧∧∧∧∧∧∧ b, as \|=p bs ↔ a, b, as \|=p bs (11) 

P̀A as \|=p a ∧∧∧∧∧∧∧∧∧ b, bs ↔ as \|=p a, bs ∧ as \|=p b, bs (12) 

P̀A a ∨∨∨∨∨∨∨∨∨ b, as \|=p bs ↔ a, as \|=p bs ∧ b, as \|=p bs (13) 

P̀A as \|=p a ∨∨∨∨∨∨∨∨∨ b, bs ↔ as \|=p a, b, bs (14) 

P̀A a→→→→→→→→→ b, as \|=p bs ↔ as \|=p a, bs ∧ b, as \|=p bs (15) 

P̀A as \|=p a→→→→→→→→→ b, bs ↔ a, as \|=p b, bs (16) 

P̀A a↔↔↔↔↔↔↔↔↔ b, as \|=p bs ↔ as \|=p a, b, bs ∧ a, b, as \|=p bs (17) 

P̀A as \|=p a↔↔↔↔↔↔↔↔↔ b, bs ↔ a, as \|=p b, bs ∧ b, as \|=p a, bs. (18) 

For instance, the property (9) is proved as follows: 

378

¬¬¬¬¬¬¬¬¬a, as \|=p bs def⇔ ∀v v \|=p 

(¬¬¬¬¬¬¬¬¬a ∧∧∧∧∧∧∧∧∧ ∧∧∧ 

(as)→→→→→→→→→ ∨∨∨ 

(bs) )14.3.9(7)⇔ 

∀v ( v \|=p 

(¬¬¬¬¬¬¬¬¬a ∧∧∧∧∧∧∧∧∧ ∧∧∧ 

(as) )→ v \|=p 

∨∨∨ (bs) 

) 14.3.9(5)⇔ 

∀v( v \|=p (¬¬¬¬¬¬¬¬¬a) ∧ v \|=p 

∧∧∧ (as) → v \|=p 

∨∨∨ (bs) 

) 14.3.9(4)⇔ ∀v( 

v 6\|=p a ∧ v \|=p 

∧∧∧ (as) → v \|=p 

∨∨∨ (bs) 

) ⇔ 

∀v( v \|=p 

∧∧∧ (as) → v \|=p a ∨ v \|=p 

∨∨∨ (bs) 

) 14.3.9(6)⇔ 

∀v ( v \|=p 

∧∧∧ (as) → v \|=p 

( a ∨∨∨∨∨∨∨∨∨ 

∨∨∨ (bs) 

)) 14.3.9(7)⇔ 

∀v v \|=p 

(∧∧∧ (as)→→→→→→→→→ a ∨∨∨∨∨∨∨∨∨ 

∨∨∨ (bs) 

)def⇔ as \|=p a, bs. 

The remaining properties are proved similarly. 

14\.3.15 Main lemma for atomic propositional sequents. We have 

P̀A Lpvar(as) ∧ Lpvar(bs) → as \|=p bs ↔ ∃i(pi ε as ∧ pi ε bs). (1) 

First note that the following holds 

P̀A Lpvar(as) → PVL(as) \|=p pi ↔ pi ε as (2) 

P̀A Lpvar(as) → PVL(as) \|=p 

∧∧∧ (as) (3) 

P̀A Lpvar(as) ∧ Lpvar(bs) → PVL(as) \|=p 

∨∨∨ (bs) ↔ ∃i(pi ε as ∧ pi ε bs). 

(4) 

Property (2) is proved by list induction on as. The base case is straightfor- ward. In the inductive case, when as = b, bs, we obtain from assumptions and 14.3.8(2) that b = pj for some j. Thus 

PVL(pj , bs) \|=p pi ⇔ PV (pj)⊕ PVL(bs) \|=p pi ⇔ j,PVL(bs) \|=p pi ⇔ i ε j,PVL(bs) ⇔ i = j ∨ i ε PVL(bs) ⇔ pi = pj ∨ PVL(bs) \|=p pi 

IH⇔ pi = pj ∨ pi ε bs ⇔ pi ε pj , bs. 

Property (3) follows from 

PVL(as) \|=p 

∧∧∧ (as) 

14\.3.12(2)⇔ ∀a(a ε as → PVL(as) \|=p a) ⇔ 

∀i(pi ε as → PVL(as) \|=p pi) (2)⇔ ∀i(pi ε as → pi ε as). 

The last holds trivially. Property (4) is proved similarly. In the proof of the (→)-direction of (1) we get PVL(as) \|=p 

∧∧∧ (as) →∨∨∨ 

(bs) from assumptions and thus PVL(as) \|=p 

∨∨∨ (bs) by (3). The claim now fol- 

lows from (4). The (←)-direction is proved as follows. From assumptions and 

379

12\.6.1(1) we obtain that as = as1 ⊕ (pi, as2) and bs = bs1 ⊕ (pi, bs2) for some i, as1, as2, bs1, and bs2. The claim now follows from 14.3.14(8) since we have 

as1 ⊕ (pi, as2) \|=p bs1 ⊕ (pi, bs2) 14.3.14(2)(3)⇔ pi, as1 ⊕ as2 \|=p pi, bs1 ⊕ bs2. 

14\.3.16 Tautology checker for atomic propositional sequents. Con- sider the predicate Closes(as, bs) defined by list recursion on as as a primitive recursive predicate: 

Closes((a, as), bs) ← a ε bs Closes((a, as), bs) ← a 6ε bs ∧ Closes(as, bs). 

We have 

P̀A Closes(as, bs) ↔ ∃c(c ε as ∧ c ε bs) (1) 

P̀A Lpvar(as) ∧ Lpvar(bs) → Closes(as, bs) ↔ as \|=p bs. (2) 

Property (1) is proved by list induction on as. Property (2) follows from (1) and 14.3.15(1). 

14\.3.17 Auxiliary predicate. The predicate as ⊕ bs \`p cs ⊕ ds satisfies 

P̀A Lform(as) ∧ Lpvar(bs) ∧ Lform(cs) ∧ Lpvar(ds) → as ⊕ bs \`p cs ⊕ ds ↔ as ⊕ bs \|=p cs ⊕ ds 

(1) 

and it is defined by course of values recursion with measure ‖as‖p + ‖cs‖p 

with substitution in parameters as a primitive recursive predicate: 

0⊕ bs \`p 0⊕ ds ← Closes(bs, ds) 0⊕ bs \`p (\>\>\>\>\>\>\>\>\>, cs)⊕ ds 0⊕ bs \`p (⊥⊥⊥⊥⊥⊥⊥⊥⊥, cs)⊕ ds ← 0⊕ bs \`p cs ⊕ ds 0⊕ bs \`p (pi, cs)⊕ ds ← 0⊕ bs \`p cs ⊕ (pi, ds) 0⊕ bs \`p (¬¬¬¬¬¬¬¬¬a, cs)⊕ ds ← (a, 0)⊕ bs \`p cs ⊕ ds 0⊕ bs \`p (a ∧∧∧∧∧∧∧∧∧ b, cs)⊕ ds ← 0⊕ bs \`p (a, cs)⊕ ds ∧ 0⊕ bs \`p (b, cs)⊕ ds 0⊕ bs \`p (a ∨∨∨∨∨∨∨∨∨ b, cs)⊕ ds ← 0⊕ bs \`p (a, b, cs)⊕ ds 0⊕ bs \`p (a→→→→→→→→→ b, cs)⊕ ds ← (a, 0)⊕ bs \`p (b, cs)⊕ ds 0⊕ bs \`p (a↔↔↔↔↔↔↔↔↔ b, cs)⊕ ds ← 

(a, 0)⊕ bs \`p (b, cs)⊕ ds ∧ (b, 0)⊕ bs \`p (a, cs)⊕ ds (\>\>\>\>\>\>\>\>\>, as)⊕ bs \`p cs ⊕ ds ← as ⊕ bs \`p cs ⊕ ds (⊥⊥⊥⊥⊥⊥⊥⊥⊥, as)⊕ bs \`p cs ⊕ ds (pi, as)⊕ bs \`p cs ⊕ ds ← as ⊕ (pi, bs) \`p cs ⊕ ds (¬¬¬¬¬¬¬¬¬a, as)⊕ bs \`p cs ⊕ ds ← as ⊕ bs \`p (a, cs)⊕ ds (a ∧∧∧∧∧∧∧∧∧ b, as)⊕ bs \`p cs ⊕ ds ← (a, b, as)⊕ bs \`p cs ⊕ ds (a ∨∨∨∨∨∨∨∨∨ b, as)⊕ bs \`p cs ⊕ ds ← 

(a, as)⊕ bs \`p cs ⊕ ds ∧ (b, as)⊕ bs \`p cs ⊕ ds (a→→→→→→→→→ b, as)⊕ bs \`p cs ⊕ ds ← 

380

as ⊕ bs \`p (a, cs)⊕ ds ∧ (b, as)⊕ bs \`p cs ⊕ ds (a↔↔↔↔↔↔↔↔↔ b, as)⊕ bs \`p cs ⊕ ds ← 

as ⊕ bs \`p (a, b, cs)⊕ ds ∧ (a, b, as)⊕ bs \`p cs ⊕ ds. 

Property ∀bs∀ds(1) is proved by induction with measure ‖as‖p + ‖cs‖p. So take any as, bs, cs, and ds, and under the assumptions of the claim consider two cases. 

If as = 0 then we consider two subcases. If cs = 0 then we have 

0⊕ bs \`p 0⊕ ds def⇔ Closes(bs, ds) 14.3.16(2)⇔ bs \|=p ds ⇔ 0⊕ bs \|=p 0⊕ ds. 

If cs = a, cs1 for some a and cs1 then we do the case analysis on the structure of the propositional formula a. If a =\>\>\>\>\>\>\>\>\> then the claim follows from 14.3.14(5). If a =⊥⊥⊥⊥⊥⊥⊥⊥⊥ then we have 

0⊕ bs \`p (⊥⊥⊥⊥⊥⊥⊥⊥⊥, cs1)⊕ ds def⇔ 0⊕ bs \`p cs1 ⊕ ds IH⇔ 0⊕ bs \|=p cs1 ⊕ ds 

14\.3.14(7)⇔ 0⊕ bs \|=p (⊥⊥⊥⊥⊥⊥⊥⊥⊥, cs1)⊕ ds. 

If a = pi then we have 

0⊕ bs \`p (pi, cs1)⊕ ds def⇔ 0⊕ bs \`p cs1 ⊕ (pi, ds) IH⇔ 

0⊕ bs \|=p cs1 ⊕ (pi, ds) 14.3.14(3)⇔ 0⊕ bs \|=p (pi, cs1)⊕ ds. 

If a = (¬¬¬¬¬¬¬¬¬b) for some b then we have 

0⊕ bs \`p (¬¬¬¬¬¬¬¬¬b, cs1)⊕ ds def⇔ (b, 0)⊕ bs \`p cs1 ⊕ ds IH⇔ (b, 0)⊕ bs \|=p cs1 ⊕ ds 

14\.3.14(10)⇔ 0⊕ bs \|=p (¬¬¬¬¬¬¬¬¬b, cs1)⊕ ds. 

If a = (b ∧∧∧∧∧∧∧∧∧ c) for some b and c then we have 

0⊕ bs \`p (b ∧∧∧∧∧∧∧∧∧ c, cs1)⊕ ds def⇔ 0⊕ bs \`p (b, cs1)⊕ ds ∧ 0⊕ bs \`p (c, cs1)⊕ ds IH⇔ 0⊕ bs \|=p (b, cs1)⊕ ds ∧ 0⊕ bs \|=p (c, cs1)⊕ ds 

14\.3.14(12)⇔ 0⊕ bs \|=p (b ∧∧∧∧∧∧∧∧∧ c, cs1)⊕ ds. 

If a = (b ∨∨∨∨∨∨∨∨∨ c) for some b and c then we have 

0⊕ bs \`p (b ∨∨∨∨∨∨∨∨∨ c, cs1)⊕ ds def⇔ 0⊕ bs \`p (b, c, cs1)⊕ ds IH⇔ 0⊕ bs \|=p (b, c, cs1)⊕ ds 

14\.3.14(14)⇔ 0⊕ bs \|=p (b ∨∨∨∨∨∨∨∨∨ c, cs1)⊕ ds. 

If a = (b→→→→→→→→→ c) for some b and c then we have 

381

0⊕ bs \`p (b→→→→→→→→→ c, cs1)⊕ ds def⇔ (b, 0)⊕ bs \`p (c, cs1)⊕ ds IH⇔ (b, 0)⊕ bs \|=p (c, cs1)⊕ ds 

14\.3.14(16)⇔ 0⊕ bs \|=p (b→→→→→→→→→ c, cs1)⊕ ds. 

If a = (b↔↔↔↔↔↔↔↔↔ c) for some b and c then we have 

0⊕ bs \`p (b↔↔↔↔↔↔↔↔↔ c, cs1)⊕ ds def⇔ (b, 0)⊕ bs \`p (c, cs1)⊕ ds ∧ (c, 0)⊕ bs \`p (b, cs1)⊕ ds IH⇔ (b, 0)⊕ bs \|=p (c, cs1)⊕ ds ∧ (c, 0)⊕ bs \|=p (b, cs1)⊕ ds 

14\.3.14(18)⇔ 0⊕ bs \|=p (b↔↔↔↔↔↔↔↔↔ c, cs1)⊕ ds. 

If as = a, as1 for some a and as1 then we do the case analysis on the structure of the propositional formula a. If a =\>\>\>\>\>\>\>\>\> then we have 

(\>\>\>\>\>\>\>\>\>, as1)⊕ bs \`p cs ⊕ ds def⇔ as1 ⊕ bs \`p cs ⊕ ds IH⇔ as1 ⊕ bs \|=p cs ⊕ ds 

14\.3.14(4)⇔ (\>\>\>\>\>\>\>\>\>, as1)⊕ bs \|=p cs ⊕ ds. 

If a =⊥⊥⊥⊥⊥⊥⊥⊥⊥ then the claim follows from 14.3.14(6). If a = pi then we have 

(pi, as1)⊕ bs \`p cs ⊕ ds def⇔ as1 ⊕ (pi, bs) \`p cs ⊕ ds IH⇔ as1 ⊕ (pi, bs) \|=p cs ⊕ ds 

14\.3.14(2)⇔ (pi, as1)⊕ bs \|=p cs ⊕ ds. 

If a = (¬¬¬¬¬¬¬¬¬b) for some b then we have 

(¬¬¬¬¬¬¬¬¬b, as1)⊕ bs \`p cs ⊕ ds def⇔ as1 ⊕ bs \`p (b, cs)⊕ ds IH⇔ as1 ⊕ bs \|=p (b, cs)⊕ ds 

14\.3.14(9)⇔ (¬¬¬¬¬¬¬¬¬b, as1)⊕ bs \|=p cs ⊕ ds. 

If a = (b ∧∧∧∧∧∧∧∧∧ c) for some b and c then we have 

(b ∧∧∧∧∧∧∧∧∧ c, as1)⊕ bs \`p cs ⊕ ds def⇔ (b, c, as1)⊕ bs \`p cs ⊕ ds IH⇔ (b, c, as1)⊕ bs \|=p cs ⊕ ds 

14\.3.14(11)⇔ (b ∧∧∧∧∧∧∧∧∧ c, as1)⊕ bs \|=p cs ⊕ ds. 

If a = (b ∨∨∨∨∨∨∨∨∨ c) for some b and c then we have 

(b ∨∨∨∨∨∨∨∨∨ c, as1)⊕ bs \`p cs ⊕ ds def⇔ (b, as1)⊕ bs \`p cs ⊕ ds ∧ (c, as1)⊕ bs \`p cs ⊕ ds IH⇔ (b, as1)⊕ bs \|=p cs ⊕ ds ∧ (c, as1)⊕ bs \|=p cs ⊕ ds 

14\.3.14(13)⇔ (b ∨∨∨∨∨∨∨∨∨ c, as1)⊕ bs \|=p cs ⊕ ds. 

If a = (b→→→→→→→→→ c) for some b and c then we have 

382

(b→→→→→→→→→ c, as1)⊕ bs \`p cs ⊕ ds def⇔ as1 ⊕ bs \`p (b, cs)⊕ ds ∧ (c, as1)⊕ bs \`p cs ⊕ ds IH⇔ as1 ⊕ bs \|=p (b, cs)⊕ ds ∧ (c, as1)⊕ bs \|=p cs ⊕ ds 

14\.3.14(15)⇔ (b→→→→→→→→→ c, as1)⊕ bs \|=p cs ⊕ ds. 

If a = (b↔↔↔↔↔↔↔↔↔ c) for some b and c then we have 

(b↔↔↔↔↔↔↔↔↔ c, as1)⊕ bs \`p cs ⊕ ds def⇔ as1 ⊕ bs \`p (b, c, cs)⊕ ds ∧ (b, c, as1)⊕ bs \`p cs ⊕ ds IH⇔ as1 ⊕ bs \|=p (b, c, cs)⊕ ds ∧ (b, c, as1)⊕ bs \|=p cs ⊕ ds 

14\.3.14(17)⇔ (b↔↔↔↔↔↔↔↔↔ c, as1)⊕ bs \|=p cs ⊕ ds. 

14\.3.18 Tautology checker for propositional sequents. Consider the predicate as \`p bs defined explicitly as a primitive recursive predicate: 

P̀Ax as \`p bs ↔ as ⊕ 0 \`p bs ⊕ 0. 

We have 

P̀A Lform(as) ∧ Lform(bs) → as \`p bs ↔ as \|=p bs. (1) 

Property (1) follows from 14.3.17(1). 

14\.3.19 Tautology checker. Consider the predicate \`p a defined explicitly as a primitive recursive predicate: 

P̀Ax \`p a ↔ 0 \`p a, 0. 

We have 

P̀A Form(a) → \`p a ↔ \|=p a. (1) 

Property (1) follows from 14.3.14(1) and 14.3.18(1). 

383

14\.4 Exercises 

14\.4.1 Exercise. Additive numeric terms are formed from variables and constants by applications of addition. The predicate Term(t) holding of the codes of additive numeric terms is defined by course of values recursion as a primitive recursive predicate: 

Term(xi) Term(n) Term(t1 +++++++++ t2) ← Term(t1) ∧ Term(t2). 

The denotation function \[\[t\]\]v for additive numeric terms is defined by Term- recursion on t as a primitive recursive function: 

\[\[xi\]\]v = (v)i 

\[\[n\]\]v = n \[\[t1 +++++++++ t2\]\]v = \[\[t1\]\]v + \[\[t2\]\]v. 

The predicate Lassoc(t) holds if the additive numeric term t is left associative w.r.t. addition. The predicate is defined by Term-induction as a primitive recursive predicate: 

Lassoc(xi) Lassoc(n) Lassoc(t1 +++++++++ xi) ← Lassoc(t1) Lassoc(t1 +++++++++ n) ← Lassoc(t1). 

Consider the primitive recursive function f(t) defined by course of values recursion with measure m(t): 

f(xi) = xi 

f(n) = n f(t1 +++++++++ xi) = f(t1) +++++++++ xi 

f(t1 +++++++++ n) = f(t1) +++++++++ n f(t1 +++++++++(t2 +++++++++ t3)) = f(t1 +++++++++ t2 +++++++++ t3), 

where 

m(xi) = 1 m(n) = 1 m(t1 +++++++++ t2) = m(t1) + 2 ·m(t2) + 1. 

Prove 

P̀A Term(t) → Term f(t) 

P̀A Term(t) → Lassoc f(t) 

P̀A Term(t) → \[\[f(t)\]\]v = \[\[t\]\]v. 

384

14\.4.2 Exercise. Numeric terms in one variable are formed from the vari- able x and constants by applications of addition and multiplication. The predicate Term(t) holding of the codes of numeric terms in one variable is defined by course of values recursion as a primitive recursive predicate: 

Term(x) Term(n) Term(t1 +++++++++ t2) ← Term(t1) ∧ Term(t2) Term(t1 ××××××××× t2) ← Term(t1) ∧ Term(t2). 

The denotation function \[\[t\]\]x for numeric terms in one variables is defined by Term-recursion on t as a primitive recursive function: 

\[\[x\]\]x = x \[\[n\]\]x = n \[\[t1 +++++++++ t2\]\]x = \[\[t1\]\]x + \[\[t2\]\]x \[\[t1 ××××××××× t2\]\]x = \[\[t1\]\]x ·\[\[t2\]\]x. 

Define the function f(t) translating a numeric term t in one variable into an equivalent polynomial, i.e. 

P̀A Term(t) → f(t)(x) = \[\[t\]\]x. 

Prove that the function has the required property. 

385

386

15\. Programs Operating on Arrays 

15\.1 Basic operations on arrays 

15\.1.1 Arrays. Array predicate. The binary predicate Array(n, a) holds if a is an array 

of the length n. Array indexing. The array indexing function a\[i\] subscribes the array a 

at the index i. Array modification. The array modification function a\[i := x\] modifies 

the array a at the index i to obtain the new value x. The function has the following properties: 

Array(n, a) ∧ i \< n → Array(n, a\[i := x\]) (1) Array(n, a) ∧ i \< n → a\[i := x\]\[i\] = x (2) 

Array(n, a) ∧ i \< n → ∀j(j \< n ∧ j 6= i → a\[i := x\]\[j\] = a\[j\]) . (3) 

New array. The function New(n) creates a new array of the length n. The function has the following property: 

Array(n,New(n)) . (4) 

15\.1.2 Exercise. Define a function Fill(x, n) satisfying 

Array(n,Fill(x, n)) (1) i \< n → Fill(x, n)\[i\] = x . (2) 

Prove that the function has the required properties. Hint. Define Fill(x, n) as follows 

Fill1(x, 0, a) = a Fill1(x, i + 1, a) = Fill1(x, i, a\[i := x\]) Fill(x, n) = Fill1(x, n, New(n)) , 

where the function Fill1(x, i, a) is defined by primitive recursion on i with substitution in parameter a. Prove first the following properties of the auxil- iary function:

Array(n, a) ∧ i ≤ n → Array(n,Fill1(x, i, a)) (3) 

Array(n, a) ∧ i ≤ n ∧ j \< n → (j \< i → Fill1(x, i, a)\[j\] = x) ∧ (j ≥ i → Fill1(x, i, a)\[j\] = a\[j\]) . 

(4) 

15\.1.3 Position. The predicate Pos(x, i, n, a) holds if i \< n and x is the value of the array a at the index i, ie 

Pos(x, i, n, a) ↔ i \< n ∧ a\[i\] = x . 

The predicate has the following properties: 

¬Pos(x, i, 0, a) (1) Pos(x, i, n + 1, a) ↔ i = n ∧ a\[i\] = x ∨ Pos(x, i, n, a) . (2) 

15\.1.4 Array membership. The predicate Ina(x, n, a) holds if there is a number i \< n such that x is the value of the array a at the index i, ie 

Ina(x, n, a) ↔ ∃i(i \< n ∧ a\[i\] = x) . 

The predicate has the following properties: 

Ina(x, n, a) ↔ ∃iPos(x, i, n, a) (1) ¬Ina(x, 0, a) (2) 

Ina(x, n + 1, a) ↔ a\[n\] = x ∨ Ina(x, n, a) . (3) 

15\.1.5 Exercise. Define a function Search(x, n, a) satisfying 

Search(x, n, a) = 0, i → Pos(x, i, n, a) (1) Ina(x, n, a) → ∃iSearch(x, n, a) = 0, i . (2) 

Prove that the function has the required properties. Hint. Define Search(x, n, a) by primitive recursion on n as follows 

Search(x, 0, a) = 0 Search(x, n + 1, a) = 0, n ← a\[n\] = x Search(x, n + 1, a) = Search(x, n, a) ← a\[n\] 6= x 

and prove the properties by the corresponding induction principle. 

15\.1.6 Position (2nd form). The predicate Pos2(x, i, m, n, a) holds if m ≤ i \< n and x is the value of the array a at the index i, ie 

Pos2(x, i, m, n, a) ↔ m ≤ i \< n ∧ a\[i\] = x . 

The predicate has the following properties: 

388

Pos(x, i, n, a) ↔ Pos2(x, i, 0, n, a) (1) m ≤ i \< n ∧ a\[i\] = x → Pos2(x, i, m, n, a) (2) 

m ≥ n → ¬Pos2(x, i, m, n, a) (3) Pos2(x, i, m, n, a) ∧ k ≤ m → Pos2(x, i, k, n, a) (4) Pos2(x, i,m, n, a) ∧ n ≤ k → Pos2(x, i, m, k, a) . (5) 

15\.1.7 Ordered arrays. The predicate Orda(n, a) holds if the first n ele- ments of the array a are ordered in the increasing order, ie 

Orda(n, a) ↔ ∀i∀j(i \< n ∧ j \< n ∧ i \< j → a\[i\] \< a\[j\]) . 

The predicate has the following properties: 

Orda(0, a) (1) Orda(n, a) ∧m ≤ n → Orda(m, a) . (2) 

15\.1.8 Exercise (binary search). Define a function Bsearch(x, n, a) with the complexity O(log(n)) satisfying 

Orda(n, a) → Bsearch(x, n, a) = 0, i ↔ Pos(x, i, n, a) . (1) 

Prove that the function has the required property. Solution. We define Bsearch(x, n, a) as follows 

Bsearch1(x,m, n, a) = 0 ← m ≥ n Bsearch1(x,m, n, a) = Bsearch1(x, k + 1, n, a) ← 

m \< n ∧ (m + n)÷ 2 = k ∧ a\[k\] \< x Bsearch1(x,m, n, a) = 0, k ← 

m \< n ∧ (m + n)÷ 2 = k ∧ a\[k\] = x Bsearch1(x,m, n, a) = Bsearch1(x, m, k, a) ← 

m \< n ∧ (m + n)÷ 2 = k ∧ a\[k\] \> x Bsearch(x, n, a) = Bsearch1(x, 0, n, a) , 

where the auxiliary function Bsearch1(x,m, n, a) is defined by recursion with measure n .−m. The function Bsearch1(x,m, n, a) satisfies: 

Bsearch1(x,m, n, a) = 0, i → Pos2(x, i, m, n, a) (2) Orda(n, a) ∧ Pos2(x, i,m, n, a) → Bsearch1(x, m, n, a) = 0, i . (3) 

Note that the property (1) follows from (2) and (3) by 15.1.6(1). We prove (2) by course of values induction on m and n w.r.t. measure 

n .−m. Take any m and n such that 

Bsearch1(x,m, n, a) = 0, i (4) 

holds and assume 

389

∀m1∀n1(n1 .−m1 \< n .−m → 

Bsearch1(x,m1, n1, a) = 0, i → Pos2(x, i, m1, n1, a)) 

as inductive hypothesis. We wish to prove 

Pos2(x, i, m, n, a) . (5) 

We consider two cases. If m ≥ n then the assumption (4) leads to contra- diction since by definition Bsearch1(x, m, n, a) = 0. So suppose m \< n. Let k := (m + n)÷ 2. Note that we have m ≤ k \< n. We proceed by trichotomy case analysis on a\[k\] and x. If a\[k\] \< x then we have 

Bsearch1(x, k + 1, n, a) def= Bsearch1(x,m, n, a) (4) = 0, i . 

We apply IH to k + 1 and n whereby we obtain that Pos2(x, i, k + 1, n, a) holds. We get (5) by (4). If a\[k\] = x then k = i by definition and we get (5) by (2). If a\[k\] \< x then we have 

Bsearch1(x,m, k, a) def= Bsearch1(x,m, n, a) (4) = 0, i . 

We apply IH to m and k whereby we obtain that Pos2(x, i, m, k, a) holds. We get (5) by (5). 

The proof of (3) is based on the following property of ordered arrays: 

Orda(n, a) ∧ Pos2(x, i,m, n, a) ∧ k \< n → (a\[k\] \< x → Pos2(x, i, k + 1, n, a))∧ (a\[k\] = x → k = i)∧ (a\[k\] \> x → Pos2(x, i, m, k, a)) . 

(6) 

We prove (3) by course of values induction on m and n w.r.t. measure n .−m. Take any m and n such that 

Orda(n, a) ∧ Pos2(x,m, n, a) (7) 

holds and assume 

∀m1∀n1(n1 .−m1 \< n .−m → 

Orda(n1, a) ∧ Pos2(x, i, m1, n1, a) → Bsearch1(x, m1, n1, a) = 0, i) 

as inductive hypothesis. We consider two cases. If m ≥ n then the assumption (7) leads to contradiction by 15.1.6(3). So suppose m \< n. Let k := (m+n)÷2. Note that we have m ≤ k \< n. We proceed by trichotomy case analysis on a\[k\] and x. If a\[k\] \< x then we have 

Bsearch1(x, m, n, a) def= Bsearch1(x, k + 1, n, a) IH(k + 1, n),(6) 

= 0, i . 

390

If a\[k\] = x then we have 

Bsearch1(x,m, n, a) def= 0, k (6) = 0, i . 

If a\[k\] \> x then Orda(k, a) by 15.1.7(2) and we have 

Bsearch1(x,m, n, a) def= Bsearch1(x,m, k, a) IH(m, k),(6) 

= 0, i . 

391

392

16\. Programs Operating on Word Domains

394

17\. Computation of Clausal Programs 

Until now we were interested only in the definability of functions and predi- cates over natural numbers. We will now investigate questions of their effec- tive computability. 

17\.1 Computation over Monadic Numerals 

17\.1.1 Monadic numerals. We recall the notation 

nm ≡ 0 

n︷︸︸︷ ′ . . .′ 

introduced in Par. 8.4.3 for monadic numerals. Monadic numerals are the least class of terms containing the constant 0 and with every term ρ containing also the term ρ′. 

17\.1.2 Generalized terms for monadic numerals. The basic general- ized term for the definition of clausal programs operating over monadic nu- merals is 

Monx(τ, α1\[x\], α2) = z ↔ ∃x(τ = x′ ∧ α1\[x\] = z) ∨ τ = 0 ∧ α2 = z . 

17\.1.3 Monadic clausal definitions. Monadic functions and predicates are defined by monadic clausal definitions. We have two classes of functions, primitive recursive and µ-recursive. 

All primitive recursive functions are provably recursive in PA but not all µ-recursive functions are such. 

17\.1.4 Reductions over monadic numerals. 

Monx(0, α1\[x\], α2) I α2 

Monx(ρ′, α1\[x\], α2) I α1\[ρ\] . 

17\.1.5 Computability of functions defined by monadic clausal defi- nitions. Both primitive recursive and µ-recursive functions can be effectively computed by reductions.

17\.2 Computation over Binary Numerals 

If we were interested only in the effective computability of functions and pred- icates then we would not need more than monadic functions and predicates. Since we are discussing computer programming, we are also interested in the efficiency of computed programs. Monadic computation is exponentially s- lower than it should be. Computationally optimal is the so-called recursion on notation of which binary notation is the most well-known. 

17\.2.1 Binary numerals. Binary numerals are the least set of terms con- taining the constant 0, with every term ρ also the term ρ1, and with every term ρ 6≡ 0 also the term ρ0. Thus the term 00 is not a binary numeral. 

17\.2.2 Generalized terms for binary numerals. The basic generalized terms for clausal programs operating over binary numerals are 

Bin(\[τ = x0; α1\]x, \[τ = x1; α2\]x) D(\[τ \> 0;α1\], \[τ = 0; α2\]) . 

17\.2.3 Binary clausal definitions. Binary functions and predicates are defined by binary clausal definitions. 

17\.2.4 Fast binary arithmetic. Basic operations and comparisons. 

17\.2.5 Binary pairing function. Pb(x, y) 

17\.2.6 Binary projections. Hb(x), Tb(x) 

17\.2.7 Characterization of binary functions and predicates. Binary functions and predicates are exactly the monadic ones. 

17\.2.8 Reductions over binary numerals. 

Bin(\[0 = x0;α1\]x, \[0 = x1; α2\]x) I α1x\[0\] Bin(\[ρ0 = x0; α1\]x, \[ρ0 = x1; α2\]x) I α1x\[ρ\] Bin(\[ρ1 = x0; α1\]x, \[ρ1 = x1; α2\]x) I α2x\[ρ\] 

D(\[0 \> 0; α1\], \[0 = 0; α2\]) I α2 

D(\[ρ0 \> 0;α1\], \[ρ0 = 0;α2\]) I α1 

D(\[ρ1 \> 0;α1\], \[ρ1 = 0;α2\]) I α1 . 

17\.2.9 Computability of binary functions and predicates. Binary functions and predicates are effectively computable by reductions. 

396

17\.2.10 Memory models for binary numerals. Computation is a syn- tactic process which proceeds by the manipulation of concrete objects. In the above discussion the concrete objects were monadic and binary numerals. In any practical implementation of computations over binary numerals on an electronic computer the d numerals will have to be mapped into the memory structures of the computer. 

UNFINISHED Bignums 

17\.3 Computation over Pair Numerals 

Although exponentially more efficient than monadic computation, the binary computation greatly suffers when computing with symbolic (coded) data. 

17\.3.1 Pair numerals. We recall the definition in Par. 1.3.8 of pair numer- als as the least class of terms containing 0 and with every two terms ρ1 and ρ2 also the term (ρ1, ρ2). 

17\.3.2 Generalized term for pair numerals. The basic generalized term for clausal programs operating over pair numerals is 

Pair(\[τ = v, w;α1\]v,w, \[τ = 0; α2\]) . 

17\.3.3 Pair clausal definitions. Pair functions and predicates are defined by pair clausal definitions. 

17\.3.4 Pair arithmetic. Basic operations and comparisons. 

17\.3.5 Characterization of pair functions and predicates. Pair func- tions and predicates are exactly the monadic ones. 

17\.3.6 Reductions over pair numerals. 

Pair(\[0 = v, w; α1\]v,w, \[0 = 0; α2\]) I α2 

Pair(\[(ρ1, ρ2) = v, w;α1\]v,w, \[(ρ1, ρ2) = 0; α2\]) I α1v\[ρ1\]w\[ρ2\] . 

17\.3.7 Computability of pair functions. Pair functions and predicates are effectively computable by reductions. 

17\.3.8 Memory models for pair numerals. The memory model of LISP is natural for the representation of pair numerals. The pair numeral 0 is represented in computer’s memory with, say 32-bit words, by the word 0. The pair numeral (ρ1, ρ2) is represented by a non-zero word interpreted as a pointer to a LISP-cell, i.e. to two adjacent 32-bit words. The first word represents the first projection ρ1 and the second word the second projection ρ2. UNFINISHED 

397

17\.4 Computation over Mixed Numerals 

We can combine the fast computation of numeric functions and predicates defined as binary functions with the gast computation of symbolic functions and predicates defined in pair notations by computing over mixed numerals. 

17\.4.1 Mixed numerals. Mixed numerals are the least set of terms con- taining the constant 0, with every terms ρ1, ρ2 also the terms ρ11 and (ρ1, ρ2), and with every term ρ 6≡ 0 also the term ρ0. Binary and pair numerals are thus proper subsets of mixed numerals. 

In contrast to monadic, binary, and pair numerals, the mixed numerals do not enjoy the unique representation of natural numbers. For instance, the number three is denoted by four mixed numerals which are all different as terms: 

011 (0, 0)1 (01, 0) ((0, 0), 0) . 

17\.4.2 Mixed clausal definitions. Mixed functions and predicates are de- fined by mixed clausal definitions which are constructed from the Bin, Pair , and D generalized terms. 

Mixed clausal definitions clearly define all primitive recursive and µ- recursive functions. 

17\.4.3 Reductions over mixed numerals. Since binary and pair numer- als are a subset of mixed ones, the reductions given in Paragrahps 17.2.8 and 17.3.6 apply also to mixed numerals. A pair (ρ1, ρ2) as an argument of a D generalized term has a natural reduction: 

D(\[(ρ1, ρ2) \> 0; α1\], \[(ρ1, ρ2) = 0; α2\]) I α1 . 

Reductions without conversion between representations are impossible in the following three cases: 

Bin(\[(ρ1, ρ2) = x0;α1\]x, \[(ρ1, ρ2) = x1; α2\]x) I Bin(\[M2B(ρ1, ρ2) = x0; α1\]x, \[M2B(ρ1, ρ2) = x1; α2\]x) 

Pair(\[ρ0 = v, w; α1\]v,w, \[ρ0 = 0;α2\]) I α1v\[H(ρ0)\]w\[T (ρ0)\] Pair(\[ρ1 = v, w; α1\]v,w, \[ρ1 = 0;α2\]) I α1v\[H(ρ1)\]w\[T (ρ1)\] 

where we have denoted by M2B, H, and T three conversion functions which are defined in the following paragraph to operate over mixed numerals. 

17\.4.4 Conversion of mixed to binary numerals. The conversion func- tion M2B takes a mixed numeral into a binary numeral with the same de- notation. The function is defined by recursion on the structure of mixed numerals to satisfy: 

398

M2B(0) ≡ 0 M2B(ρ0) ≡ M2B(ρ)0 M2B(ρ1) ≡ M2B(ρ)1 M2B(ρ1, ρ2) ≡ ρ ⇐ Pb(M2B(ρ1),M2B(ρ2)) I ρ . 

The function is clearly effectively computable. The conversion function H(ρ) takes a mixed numeral and yields a mixed 

numeral with the same denotation as H(ρ). The function T (ρ) is similar. The functions satisfy the following: 

H(0) ≡ 0 H(ρ1, ρ2) ≡ ρ1 

H(ρ0) ≡ ρ1 ⇐ Hb(M2B(ρ)0) I ρ1 

H(ρ1) ≡ ρ1 ⇐ Hb(M2B(ρ)1) I ρ1 

T (0) ≡ 0 T (ρ1, ρ2) ≡ ρ2 

T (ρ0) ≡ ρ1 ⇐ Tb(M2B(ρ)0) I ρ1 

T (ρ1) ≡ ρ1 ⇐ Tb(M2B(ρ)1) I ρ1 

and are clearly effectively computable. 

17\.4.5 Computability of clausal definitions. A clausally defined func- tion f of T is reducible if for all mixed numerals \~ρ we have f(\~ρ) I τ for a mixed numeral τ and T \` f(\~ρ) = τ . 

Let T be an extension of S with a (guarded) clausal definition of f . Assume that all clausally defined functions of S are reducible. 

The mixed functions are computable over mixed numerals. 

17\.4.6 A memory model for mixed pumerals. A mixed numeral can be represented in a memory of an electronic computer with a 32-bit words, by a word whose lowest two bits serve as four tags distinguishing the four kinds of mixed numerals. 

We assign the tag 0 to represent the numerals which are pairs of the form (ρ1, ρ2). A 32-bit number n with the tag 0 (note that n mod 4 = 0) is interpreted as a pointer to a LISP-cell as in Par. 17.3.8. A word n with the tag 1 represents the mixed numeral ρ0 by interpreting the number n− 1 as a pointer to a word representing the mixed numeral ρ. Similarly, a word n with the tag 2 represents the mixed numeral ρ1 by interpreting the number n− 2 as a pointer to a word representing the mixed numeral ρ. Finally, a word n with the tag 3 represents the fourth kind of mixed numerals. Normally this would be the single numeral 0. It is, however, advantageous to utilize the remaining 30-bits of such words to store small natural numbers directly. This means that the word represents the binary numeral denoting n÷ 4. 

399

This representation of mixed numerals can be described purely in the language of logic by defining the class of extended mixed numerals as the smallest class of terms which contains decimal numerals denoting the numbers n such that 

n ≤ 1, 073, 741, 823 = 230 − 1 = 0130 

holds and such that with each two extended mixed numerals ρ1 and ρ2 also the terms ρ10 (provided ρ1 6≡ 0), ρ21, and (ρ1, ρ2) are extended mixed numerals. Figure 17.1 shows the memory representation of the extended mixed numeral (5, 10737418231)01. 

2q 

? 1q 

? 0q 

? 5 3 1q 

? 1073741823 3 

Fig. 17.1. Memory representation of the extended mixed numeral (5, 10737418231)21 

400

18\. Data Types 

Typed programming languages, especially the functional ones, are popular for three reasons: 

1\. types naturally express properties of programs, 2. types permit good memory representation of data and the programs can 

be efficiently compiled, 3. types are indispensable for a natural semantics of higher-order functions 

(functionals). 

The first reason for types is irrelevant for a programming language in- tegrated with its own proof system (such as CL) because the formulas of the language permit a simpler formulation and proofs of much more complex properties than those expressible by typing. The remaining reasons for typing are exteremely important and we discuss the second reason in this chapter and the third one in Chapter 19. 

However, there is a negative side to typing in a complication of syntax and semantics. The usual approach to types is via many-sorted languages and theories. The simple languages and semantics of LISP, PROLOG, and CL are lost. We now propose a type system which enables us both to have and eat the proverbial cake. 

18\.1 Pascal-Style Typing 

Pascal was the first computer programming language whose data types sup- ported good representation in memory. 

18\.1.1 Type predicates. Pascal-style types will be defined in UNFIN- ISHED as codes of certain unary type predicates. By convention we write x : T instead of T (x) and read it as the code of T is the type of x Not every unary predicate is a type predicate. We will introduce in the following para- graphs several kinds of syntactic restrictions on the clauses of type predicates x : T which will guarantee that the value x can be efficiently represented in computer memory.

Extension of a type predicate T is the set numbers x such that x : T holds in the standard model of PA. Intension of T is the set of mixed nu- merals which are canonical terms of type T . This will be precisely defined in UNFINISHED 

UNFINISHED Canonical terms of type T can be efficiently represented in computer memory. In the following we will see that although extensions of two type predicates T1 and T2 may overlap in that there is a mixed numeral ρ such that ρ : T1 and ρ : T2, the intesions are different in that ρ has two different memory representations. 

UNFINISHED typing of generalized terms and of clausal definitions. Additionally, a well-typed function or predicate can be reduced over mixed numerals without the three reductions given in Par. 17.4.3 and which involve conversion of representation. 

18\.1.2 Basic type predicates. Predicates N and Ch with explicit defini- tions 

x : N x : Ch ← x \< 256 

are the basic type predicates. The code of N is the type of natural numbers and the code of Ch is the type of characters. 

In programming practice there will be additional basic types inluding integers and floats. 

18\.1.3 Cartesian type predicates. Suppose that T1, . . . Tn are type pred- icates. The unary type predicate explicitly defined by 

(x1, . . . , xn) : T ← x : T1 ∧ . . . ∧ x : Tn 

is the type predicate of cartesian product of codes of T1, . . . , Tn. UNFINISHED The extension of T are exactly numbers x1, . . . , xn for 

some x1, . . . , xn. those mixed numerals which can be written as n-tuples ρ1, . . . , ρn. 

Memory representation: UNFINISHED 

18\.1.4 List type predicates. Suppose that S is a type predicate. The predicate 

0 : T x, y : T ← x : S ∧ y : T . 

is the type predicate of lists of codes of S. 

18\.1.5 Fixed vector type predicates. Suppose that S is a type predicate and c a constant. The predicate 

0 : T x, y : T ← x : S ∧ y : T . 

402

is the type predicate of lists of codes of S. UNFINISHED typing of definitions 

18\.2 ML-Style Typing 

ML-style polymorphic typing is a higher-order calculus where variables and arguments of predicates can range over types. 

18\.2.1 Type predicates with types as arguments. List types are best viewed as higher-order predicates with types as arguments Instead of viewing type predicates as unary we may permit additional argument. Consider as an example the binary type predicate of lists List : 

0 : List(t) x, y : List(t) ← x :: t ∧ y : List(t) . 

We can view the binary predicate x :: t as a universal typing predicate where the second argument t ranges over type predicates T in such a way that 

x : T ↔ x :: T 

holds. For concrete type predicates t we can then consider x : List(t) to be a 

unary predicate in x. For instance, x : List(N) and x : List(Ch) can be viewed as type predicates which would have to be introduced in Pascal-style typing by two definitions: 

0 : ListN x, y : ListN ← x : ListN ∧ y : ListN 0 : ListCh x, y : ListCh ← x : ListCh ∧ y : ListCh . 

18\.2.2 Example of polymorphic typing. UNFINISHED 

18\.2.3 Vectors. Higher-order type predicates such as x : List(t) do need to have their arguments restricted to types. Consider for instance, the ternary predicate x : V1(n, t) of fixed vectors which for any number n and type t behaves as the Pascal-like type array \[0..n− 1\] of t. 

0 : V1(0, t) x, y : V1(n + 1, t) ← x :: t ∧ y : V1(n, t) . 

UNFINISHED discussion that they are lists but can be mapped into mem- ory in a better way. 

We can now introduce a binary typing predicate x : V2(t) of flexible vectors with the definition 

403

n, x : V2(t) ← x : V1(n, t) . 

UNFINISHED discussion and memory representation UNFINISHED Without ontological commitment to types which would 

get us outside of first-order theories we can treat types as codes of type predicates. Universal functions in recursion theory. Assignment of indices, choices are endless but we will for illustration purposes stick to one type system with good mapping onto memory. 

Higher-order typing even without functionals. We can deal with the prob- lem by intensionality. The value of extensionality is diminished when types are used for intensional reasons such as computation. 

404

19\. Functional Programming

406

20\. Modular Programming

408

10 

1\. J. Barwise. em An Introduction to First-Order Logic. In Handbook of Mathe- matical Logic, J. Barwise ed., North-Holland Publishing Co, 1977. 

2\. UNFINISHED Beth, tableaux 3. G. Boolos and R. Jeffrey, Computability and Logic, Cambridge University Press, 

Cambridge, 1974. 4. M. Davis, Computability and Unsolvability, McGraw Hill, New York, 1958. 5. UNFINISHED Dreben Andrews Aandreaa False lemmas 6. S. Feferman. Theory of Finite Type Related to Mathematical Practice, In Hand- 

book of Mathematical Logic, J. Barwise ed., North-Holland Publishing Co, 1977. 7. UNFINISHED Fitting tableaux 8. UNFINISHED Gentzen 9. K. Gödel, Üeber formal unentscheidbare Sätze der Principia Mathematica und 

verwandter Systeme I, Monatshefte Math. Phys. vol. 38 (1931) pages 173-198. 10. M. J. Gordon, R. Milner, C. P. Wadsworth, Edinburgh LCF. Lecture Notes in 

Computer Science, vol 78. Springer, Berlin 1979. 11. P. Hájek and P. Pudlák. Metamathematics of First-Order Arithmetic. Springer 

Verlag, 1993. 12. J. Herbrand Recherches 13. UNFINISHED Hilbert Ackermann logic 14. R. Milner, A Theory of Type Polymorphism in Programming. J. Comput. Sys- 

tem Sci. 17 (1978) 348-375. 15. J. C. Mitchell. Type Systems for Programming Languages. In Handbook of 

Theoretical Compute Science (vol B), J. van Leeuwen ed., Elsevier 1990. 16. Ch. Okasaki, Breadth-First Numbering: Lessons from a Small Exercise in Al- 

gorithm Design UNFINISHED 17. R. Péter. Konstruktion nichtrekursiver Funktionen. Math. Ann. vol 111 (1935), 

pages 42-60. 18. H. E. Rose. Subrecursion: Functions and Hierarchies. Number 9 in Oxford 

Logic Guides. Clarendon Press, Oxford, 1982. 19. H. Schwichtenberg, Eine Klassifikation der ε0-rekursiven Funktionen, 

Zeitschrift für mathematische Logik und Grundlagen der Mathematik, vol. 17, (1971), pp. 91-74. 

20\. J. R. Shoenfield. Mathematical Logic, Addison-Wesley, 1967. 21. UNFINISHED Smullyan First-order logic 22. UNFINISHED Takeuti, Proof theory 23. A. S. Troelstra. Aspects of Constructive Mathematics. In Handbook of Mathe- 

matical Logic, J. Barwise ed., North-Holland Publishing Co, 1977. 24. P. J. Voda. Subrecursion as a basis for a feasible programming language, in 

L. Pacholski and J. Tiuryn, editors, Proceedings of CSL’94, number 933 in LNCS Springer Verlag, 1995, pages 324-338.

25\. S. S. Wainer. A classification of the ordinal recursive functions, Archiv für mathematische Logik und Grundlagen Forschung, vol. 13, 1970, pp. 136-153. 

410