• Nu S-Au Găsit Rezultate

Practical Foundations for Programming Languages

N/A
N/A
Protected

Academic year: 2022

Share "Practical Foundations for Programming Languages"

Copied!
516
0
0

Text complet

(1)

Practical Foundations for Programming Languages

Robert Harper

Carnegie Mellon University Spring, 2009

[Draft of October 16, 2009 at 18:42.]

(2)

Copyright c2009 by Robert Harper.

All Rights Reserved.

The electronic version of this work is licensed under the Cre- ative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License. To view a copy of this license, visit

http://creativecommons.org/licenses/by-nc-nd/3.0/us/

or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.

(3)

Preface

This is a working draft of a book on the foundations of programming lan- guages. The central organizing principle of the book is that programming language features may be seen as manifestations of an underlying type structure that governs its syntax and semantics. The emphasis, therefore, is on the concept oftype, which codifies and organizes the computational universe in much the same way that the concept ofset may be seen as an organizing principle for the mathematical universe. The purpose of this book is to explain this remark.

This is very much a work in progress, with major revisions made nearly every day. This means that there may be internal inconsistencies as revi- sions to one part of the book invalidate material at another part. Please bear this in mind!

Corrections, comments, and suggestions are most welcome, and should be sent to the author [email protected].

(4)
(5)

Contents

Preface iii

I Judgements and Rules 1

1 Inductive Definitions 3

1.1 Objects and Judgements . . . 3

1.2 Inference Rules . . . 4

1.3 Derivations. . . 6

1.4 Rule Induction. . . 7

1.5 Iterated and Simultaneous Inductive Definitions . . . 10

1.6 Defining Functions by Rules . . . 12

1.7 Modes . . . 13

1.8 Foundations . . . 14

1.9 Exercises . . . 15

2 Hypothetical Judgements 17 2.1 Derivability . . . 17

2.2 Admissibility . . . 20

2.3 Hypothetical Inductive Definitions . . . 22

2.4 Exercises . . . 23

3 Parametric Judgements 25 3.1 Parameters and Objects. . . 25

3.2 Rule Schemes . . . 26

3.3 Parametric Derivability. . . 27

3.4 Parametric Inductive Definitions . . . 28

3.5 Exercises . . . 30

(6)

vi CONTENTS

4 Transition Systems 31

4.1 Transition Systems . . . 31

4.2 Iterated Transition. . . 32

4.3 Simulation and Bisimulation. . . 33

4.4 Exercises . . . 34

II Levels of Syntax 35 5 Concrete Syntax 37 5.1 Strings Over An Alphabet . . . 37

5.2 Lexical Structure . . . 38

5.3 Context-Free Grammars . . . 42

5.4 Grammatical Structure . . . 43

5.5 Ambiguity . . . 45

5.6 Exercises . . . 46

6 Abstract Syntax Trees 47 6.1 Abtract Syntax Trees . . . 47

6.2 Variables and Substitution . . . 48

6.3 Exercises . . . 51

7 Binding and Scope 53 7.1 Abstract Binding Trees . . . 54

7.1.1 Structural Induction With Binding and Scope. . . 56

7.1.2 Apartness . . . 57

7.1.3 Renaming of Bound Parameters . . . 57

7.1.4 Substitution . . . 58

7.2 Exercises . . . 59

8 Parsing 61 8.1 Parsing Into Abstract Syntax Trees . . . 61

8.2 Parsing Into Abstract Binding Trees. . . 64

8.3 Syntactic Conventions . . . 66

8.4 Exercises . . . 66

III Static and Dynamic Semantics 67 9 Static Semantics 69 9.1 Type System . . . 69

18:42 DRAFT OCTOBER16, 2009

(7)

CONTENTS vii

9.2 Structural Properties . . . 72

9.3 Exercises . . . 74

10 Dynamic Semantics 75 10.1 Structural Semantics . . . 75

10.2 Contextual Semantics . . . 78

10.3 Equational Semantics . . . 80

10.4 Exercises . . . 84

11 Type Safety 85 11.1 Preservation . . . 86

11.2 Progress . . . 86

11.3 Run-Time Errors. . . 88

11.4 Exercises . . . 90

12 Evaluation Semantics 91 12.1 Evaluation Semantics . . . 91

12.2 Relating Transition and Evaluation Semantics. . . 92

12.3 Type Safety, Revisited. . . 94

12.4 Cost Semantics . . . 95

12.5 Environment Semantics . . . 96

12.6 Exercises . . . 97

IV Function Types 99 13 Function Definitions and Values 101 13.1 First-Order Functions . . . 102

13.2 Higher-Order Functions . . . 103

13.3 Evaluation Semantics and Definitional Equivalence . . . 105

13.4 Dynamic Scope . . . 107

13.5 Exercises . . . 109

14 G ¨odel’s System T 111 14.1 Statics . . . 111

14.2 Dynamics . . . 113

14.3 Definability . . . 114

14.4 Non-Definability . . . 116

14.5 Exercises . . . 118

OCTOBER16, 2009 DRAFT 18:42

(8)

viii CONTENTS

15 Plotkin’s PCF 119

15.1 Statics . . . 121

15.2 Dynamics . . . 122

15.3 Definability . . . 124

15.4 Co-Natural Numbers . . . 126

15.5 Exercises . . . 126

V Finite Data Types 127 16 Product Types 129 16.1 Nullary and Binary Products . . . 129

16.2 Finite Products . . . 131

16.3 Primitive and Mutual Recursion . . . 133

16.4 Exercises . . . 134

17 Sum Types 135 17.1 Binary and Nullary Sums . . . 135

17.2 Finite Sums . . . 137

17.3 Uses for Sum Types . . . 139

17.3.1 Void and Unit . . . 139

17.3.2 Booleans . . . 139

17.3.3 Enumerations . . . 140

17.3.4 Options . . . 140

17.4 Exercises . . . 142

18 Pattern Matching 143 18.1 A Pattern Language. . . 144

18.2 Statics . . . 145

18.3 Dynamics . . . 146

18.4 Exhaustiveness and Redundancy . . . 149

18.5 Exercises . . . 152

VI Infinite Data Types 153 19 Inductive and Co-Inductive Types 155 19.1 Motivating Examples . . . 155

19.2 Generic Programming . . . 158

19.2.1 Positive Type Operators . . . 159

19.2.2 Action of a Positive Type Operator . . . 160

18:42 DRAFT OCTOBER16, 2009

(9)

CONTENTS ix

19.3 Static Semantics . . . 161

19.3.1 Types . . . 162

19.3.2 Expressions . . . 163

19.4 Dynamic Semantics . . . 163

19.5 Exercises . . . 164

20 General Recursive Types 165 20.1 Solving Type Isomorphisms . . . 166

20.2 Recursive Data Structures . . . 168

20.3 Self-Reference . . . 169

20.4 Exercises . . . 171

VII Dynamic Types 173 21 The Untypedλ-Calculus 175 21.1 Theλ-Calculus . . . 175

21.2 Definability . . . 177

21.3 Scott’s Theorem . . . 180

21.4 Untyped Means Uni-Typed . . . 181

21.5 Exercises . . . 183

22 Dynamic Typing 185 22.1 Dynamically Typed PCF . . . 185

22.2 Critique of Dynamic Typing . . . 189

22.3 Hybrid Typing. . . 190

22.4 Optimization of Dynamic Typing . . . 192

22.5 Static “Versus” Dynamic Typing . . . 194

22.6 Dynamic Typing From Recursive Types . . . 195

22.7 Exercises . . . 196

VIII Variable Types 197 23 Girard’s System F 199 23.1 SystemF . . . 200

23.2 Polymorphic Definability . . . 203

23.2.1 Products and Sums . . . 204

23.2.2 Natural Numbers . . . 205

23.3 Parametricity . . . 206

23.4 Restricted Forms of Polymorphism . . . 207

OCTOBER16, 2009 DRAFT 18:42

(10)

x CONTENTS

23.4.1 Predicative Fragment. . . 207

23.4.2 Prenex Fragment . . . 208

23.4.3 Rank-Restricted Fragments . . . 210

23.5 Exercises . . . 211

24 Abstract Types 213 24.1 Existential Types . . . 214

24.1.1 Static Semantics . . . 214

24.1.2 Dynamic Semantics. . . 215

24.1.3 Safety. . . 216

24.2 Data Abstraction Via Existentials . . . 216

24.3 Definability of Existentials . . . 218

24.4 Representation Independence . . . 219

24.5 Exercises . . . 221

25 Constructors and Kinds 223 25.1 Statics . . . 224

25.2 Adding Constructors and Kinds . . . 226

25.3 Substitution . . . 228

25.4 Exercises . . . 231

26 Indexed Families of Types 233 26.1 Type Families . . . 233

26.2 Exercises . . . 233

IX Control Effects 235 27 Control Stacks 237 27.1 Machine Definition . . . 237

27.2 Safety . . . 240

27.3 Correctness of the Control Machine. . . 241

27.3.1 Completeness . . . 242

27.3.2 Soundness . . . 243

27.4 Exercises . . . 244

28 Exceptions 245 28.1 Failures . . . 245

28.2 Exceptions . . . 247

28.3 Exercises . . . 250

18:42 DRAFT OCTOBER16, 2009

(11)

CONTENTS xi

29 Continuations 251

29.1 Informal Overview . . . 251

29.2 Semantics of Continuations . . . 253

29.3 Coroutines . . . 255

29.4 Exercises . . . 259

X Types and Propositions 261 30 Constructive Logic 263 30.1 Constructive Semantics. . . 264

30.2 Constructive Logic . . . 265

30.2.1 Rules of Provability. . . 266

30.2.2 Rules of Proof . . . 268

30.3 Propositions as Types . . . 269

30.4 Exercises . . . 271

31 Classical Logic 273 31.1 Classical Logic . . . 274

31.2 Deriving Elimination Forms . . . 279

31.3 Dynamics of Proofs . . . 280

31.4 Exercises . . . 281

XI Subtyping 283 32 Subtyping 285 32.1 Subsumption. . . 286

32.2 Varieties of Subtyping . . . 286

32.2.1 Numeric Types . . . 286

32.2.2 Product Types . . . 287

32.2.3 Sum Types . . . 289

32.3 Variance . . . 290

32.3.1 Product Types . . . 290

32.3.2 Sum Types . . . 290

32.3.3 Function Types . . . 291

32.3.4 Recursive Types. . . 292

32.4 Safety for Subtyping . . . 294

32.5 Exercises . . . 297

OCTOBER16, 2009 DRAFT 18:42

(12)

xii CONTENTS

33 Singleton and Dependent Kinds 299

33.1 Informal Overview . . . 300

XII Symbols 303 34 Symbols 305 34.1 Statics . . . 305

34.2 Scoped Dynamics . . . 307

34.3 Unscoped Dynamics . . . 308

34.4 Safety . . . 309

34.5 Exercises . . . 310

35 Fluid Binding 311 35.1 Statics . . . 311

35.2 Dynamics . . . 312

35.3 Type Safety. . . 314

35.4 Subtleties of Fluid Binding . . . 315

35.5 Dynamic Fluids . . . 317

35.6 Exercises . . . 318

36 Dynamic Classification 319 36.1 Statics . . . 320

36.2 Dynamics . . . 321

36.3 Defining Classification . . . 322

36.4 Exercises . . . 323

XIII Storage Effects 325 37 Reynolds’s IA 327 37.1 Commands. . . 328

37.1.1 Statics . . . 329

37.1.2 Dynamics . . . 330

37.1.3 Safety. . . 331

37.2 Some Programming Idioms . . . 333

37.3 References to Assignables . . . 334

37.4 Typed Commands and Assignables. . . 336

37.5 Exercises . . . 337

18:42 DRAFT OCTOBER16, 2009

(13)

CONTENTS xiii

38 Mutable Cells 339

38.1 Modal Formulation . . . 341

38.1.1 Syntax . . . 341

38.1.2 Statics . . . 342

38.1.3 Dynamics . . . 343

38.2 Integral Formulation . . . 344

38.2.1 Statics . . . 345

38.2.2 Dynamics . . . 345

38.3 Safety . . . 346

38.4 Integral versus Modal Formulation . . . 348

38.5 Exercises . . . 350

XIV Laziness 351 39 Eagerness and Laziness 353 39.1 Eager and Lazy Dynamics . . . 353

39.2 Eager and Lazy Types . . . 356

39.3 Self-Reference . . . 357

39.4 Suspension Type . . . 358

39.5 Exercises . . . 360

40 Lazy Evaluation 361 40.1 Need Dynamics . . . 362

40.2 Safety . . . 365

40.3 Lazy Data Structures . . . 367

40.4 Suspensions By Need . . . 369

40.5 Exercises . . . 369

XV Parallelism 371 41 Speculation 373 41.1 Speculative Evaluation . . . 373

41.2 Speculative Parallelism . . . 374

41.3 Exercises . . . 376

42 Work-Efficient Parallelism 377 42.1 Nested Parallelism . . . 377

42.2 Cost Semantics . . . 380

42.3 Vector Parallelism . . . 384

OCTOBER16, 2009 DRAFT 18:42

(14)

xiv CONTENTS

42.4 Provable Implementations . . . 386

42.5 Exercises . . . 389

XVI Concurrency 391 43 Process Calculus 393 43.1 Actions and Events . . . 394

43.2 Concurrent Interaction . . . 395

43.3 Replication . . . 397

43.4 Private Channels . . . 399

43.5 Synchronous Communication . . . 400

43.6 Polyadic Communication . . . 401

43.7 Mutable Cells as Processes . . . 402

43.8 Asynchronous Communication . . . 403

43.9 Definability of Input Choice . . . 405

43.10Exercises . . . 407

44 Monadic Concurrency 409 44.1 Framework. . . 409

44.2 Input/Output . . . 412

44.3 Mutable Cells . . . 412

44.4 Futures . . . 415

44.5 Fork and Join . . . 417

44.6 Synchronization . . . 418

44.7 Excercises . . . 420

XVII Modularity 421 45 Separate Compilation and Linking 423 45.1 Linking and Substitution . . . 423

45.2 Exercises . . . 423

46 Basic Modules 425

47 Parameterized Modules 427

18:42 DRAFT OCTOBER16, 2009

(15)

CONTENTS xv

XVIII Modalities 429

48 Monads 431

48.1 The Lax Modality . . . 432

48.2 Exceptions . . . 433

48.3 Derived Forms. . . 435

48.4 Monadic Programming . . . 436

48.5 Exercises . . . 438

49 Comonads 439 49.1 A Comonadic Framework . . . 440

49.2 Comonadic Effects . . . 443

49.2.1 Exceptions . . . 443

49.2.2 Fluid Binding . . . 445

49.3 Exercises . . . 447

XIX Equivalence 449 50 Equational Reasoning for T 451 50.1 Observational Equivalence. . . 452

50.2 Extensional Equivalence . . . 456

50.3 Extensional and Observational Equivalence Coincide . . . . 457

50.4 Some Laws of Equivalence . . . 460

50.4.1 General Laws . . . 461

50.4.2 Extensionality Laws . . . 461

50.4.3 Induction Law . . . 462

50.5 Exercises . . . 462

51 Equational Reasoning for PCF 463 51.1 Observational Equivalence. . . 463

51.2 Extensional Equivalence . . . 464

51.3 Extensional and Observational Equivalence Coincide . . . . 465

51.4 Compactness. . . 468

51.5 Co-Natural Numbers . . . 471

51.6 Exercises . . . 473

52 Parametricity 475 52.1 Overview. . . 475

52.2 Observational Equivalence. . . 476

52.3 Logical Equivalence. . . 478

OCTOBER16, 2009 DRAFT 18:42

(16)

xvi CONTENTS

52.4 Parametricity Properties . . . 484

52.5 Exercises . . . 487

XX Working Drafts of Chapters 489 A Polarization 491 A.1 Polarization . . . 492

A.2 Focusing . . . 493

A.3 Statics . . . 494

A.4 Dynamics . . . 497

A.5 Safety . . . 498

A.6 Definability . . . 499

A.7 Exercises . . . 499

18:42 DRAFT OCTOBER16, 2009

(17)

Part I

Judgements and Rules

(18)
(19)

Chapter 1

Inductive Definitions

Inductive definitions are an indispensable tool in the study of program- ming languages. In this chapter we will develop the basic framework of inductive definitions, and give some examples of their use.

1.1 Objects and Judgements

We start with the notion of ajudgement, orassertion, about anobjectof study.

We shall make use of many forms of judgement, including examples such as these:

nnat nis a natural number n= n1+n2 nis the sum ofn1andn2 aast ais an abstract syntax tree τtype τis a type

e :τ expressionehas typeτ e ⇓v expressionehas valuev

A judgement states that one or more objects have a property or stand in some relation to one another. The property or relation itself is called ajudge- ment form, and the judgement that an object or objects have that property or stand in that relation is said to be an instanceof that judgement form.

A judgement form is also called apredicate, and the objects constituting an instance are itssubjects.

We will use the meta-variablePto stand for an unspecified judgement form, and the meta-variables a, b, and c to stand for unspecified objects.

We write a Pfor the judgement asserting that Pholds ofa. When it is not important to stress the subject of the judgement, we write J to stand for

(20)

4 1.2 Inference Rules an unspecified judgement. For particular judgement forms, we freely use prefix, infix, or mixfix notation, as illustrated by the above examples, in order to enhance readability.

We are being intentionally vague about the universe of objects that may be involved in an inductive definition. The rough-and-ready rule is that any sort of finite construction of objects from other objects is permissible.

In particular, we shall make frequent use of the construction of compos- ite objects of the form o(a1, . . . ,an), where a1, . . . , an are objects and o is ann-argument operator. This construction includes as a special case the formation ofn-tuples,(a1, . . . ,an), in which the tupling operator is left im- plicit. (In Chapters 6 and 7 we will formalize these and richer forms of objects, called abstract syntax trees.)

1.2 Inference Rules

Aninductive definitionof a judgement form consists of a collection ofrules of the form

J1 . . . Jk

J (1.1)

in whichJ andJ1, . . . , Jk are all judgements of the form being defined. The judgements above the horizontal line are called the premises of the rule, and the judgement below the line is called itsconclusion. If a rule has no premises (that is, whenkis zero), the rule is called anaxiom; otherwise it is called aproper rule.

An inference rule may be read as stating that the premises are suffi- cientfor the conclusion: to show J, it is enough to show J1, . . . ,Jk. When k is zero, a rule states that its conclusion holds unconditionally. Bear in mind that there may be, in general, many rules with the same conclusion, each specifying sufficient conditions for the conclusion. Consequently, if the conclusion of a rule holds, then it is not necessary that the premises hold, for it might have been derived by another rule.

For example, the following rules constitute an inductive definition of the judgementanat:

zeronat (1.2a)

anat

succ(a)nat (1.2b)

These rules specify that a nat holds whenever either a is zero, or a is succ(b) whereb nat. Taking these rules to be exhaustive, it follows that

18:42 DRAFT OCTOBER16, 2009

(21)

1.2 Inference Rules 5 anatiffais a natural number written in unary.

Similarly, the following rules constitute an inductive definition of the judgementatree:

emptytree (1.3a)

a1tree a2 tree

node(a1;a2)tree (1.3b) These rules specify thatatreeholds if eitheraisempty, oraisnode(a1;a2), where a1 treeanda2 tree. Taking these to be exhaustive, these rules state thatais a binary tree, which is to say it is either empty, or a node consisting of two children, each of which is also a binary tree.

The judgementa=b natdefining equality ofa natandb natis induc- tively defined by the following rules:

zero=zeronat (1.4a)

a=bnat

succ(a)=succ(b)nat (1.4b) In each of the preceding examples we have made use of a notational convention for specifying an infinite family of rules by a finite number of patterns, or rule schemes. For example, Rule (1.2b) is a rule scheme that determines one rule, called aninstanceof the rule scheme, for each choice of object a in the rule. We will rely on context to determine whether a rule is stated for aspecificobject, a, or is instead intended as a rule scheme specifying a rule for each choice of objects in the rule. (In Chapter 3 we will remove this ambiguity by introducing parameterization of rules by objects.)

A collection of rules is considered to define thestrongestjudgement that isclosed under, orrespects, those rules. To be closed under the rules simply means that the rules are sufficientto show the validity of a judgement: J holdsif there is a way to obtain it using the given rules. To be thestrongest judgement closed under the rules means that the rules are also necessary:

J holdsonly if there is a way to obtain it by applying the rules. The suffi- ciency of the rules means that we may show that J holds byderivingit by composing rules. Their necessity means that we may reason about it using rule induction.

OCTOBER16, 2009 DRAFT 18:42

(22)

6 1.3 Derivations

1.3 Derivations

To show that an inductively defined judgement holds, it is enough to ex- hibit aderivationof it. A derivation of a judgement is a finite composition of rules, starting with axioms and ending with that judgement. It may be thought of as a tree in which each node is a rule whose children are deriva- tions of its premises. We sometimes say that a derivation ofJisevidencefor the validity of an inductively defined judgementJ.

We usually depict derivations as trees with the conclusion at the bot- tom, and with the children of a node corresponding to a rule appearing above it as evidence for the premises of that rule. Thus, if

J1 . . . Jk J

is an inference rule and∇1, . . . ,∇kare derivations of its premises, then

1 . . . ∇k

J (1.5)

is a derivation of its conclusion. In particular, ifk=0, then the node has no children.

For example, this is a derivation ofsucc(succ(succ(zero)))nat:

zeronat succ(zero)nat succ(succ(zero))nat succ(succ(succ(zero)))nat .

(1.6)

Similarly, here is a derivation ofnode(node(empty;empty);empty)tree:

emptytree emptytree

node(empty;empty)tree emptytree node(node(empty;empty);empty)tree .

(1.7)

To show that an inductively defined judgement is derivable we need only find a derivation for it. There are two main methods for finding derivations, calledforward chaining, orbottom-up construction, andbackward chaining, ortop-down construction. Forward chaining starts with the axioms and works forward towards the desired conclusion, whereas backward

18:42 DRAFT OCTOBER16, 2009

(23)

1.4 Rule Induction 7 chaining starts with the desired conclusion and works backwards towards the axioms.

More precisely, forward chaining search maintains a set of derivable judgements, and continually extends this set by adding to it the conclusion of any rule all of whose premises are in that set. Initially, the set is empty;

the process terminates when the desired judgement occurs in the set. As- suming that all rules are considered at every stage, forward chaining will eventually find a derivation of any derivable judgement, but it is impos- sible (in general) to decide algorithmically when to stop extending the set and conclude that the desired judgement is not derivable. We may go on and on adding more judgements to the derivable set without ever achiev- ing the intended goal. It is a matter of understanding the global properties of the rules to determine that a given judgement is not derivable.

Forward chaining is undirected in the sense that it does not take ac- count of the end goal when deciding how to proceed at each step. In contrast, backward chaining is goal-directed. Backward chaining search maintains a queue of current goals, judgements whose derivations are to be sought. Initially, this set consists solely of the judgement we wish to de- rive. At each stage, we remove a judgement from the queue, and consider all rules whose conclusion is that judgement. For each such rule, we add the premises of that rule to the back of the queue, and continue. If there is more than one such rule, this process must be repeated, with the same start- ing queue, for each candidate rule. The process terminates whenever the queue is empty, all goals having been achieved; any pending consideration of candidate rules along the way may be discarded. As with forward chain- ing, backward chaining will eventually find a derivation of any derivable judgement, but there is, in general, no algorithmic method for determining in general whether the current goal is derivable. If it is not, we may futilely add more and more judgements to the goal set, never reaching a point at which all goals have been satisfied.

1.4 Rule Induction

Since an inductive definition specifies the strongestjudgement closed un- der a collection of rules, we may reason about them byrule induction. The principle of rule induction states that to show that a propertyP holds of a judgement J whenever J is derivable, it is enough to show thatP isclosed under, orrespects, the rules defining J. WritingP(J)to mean that the prop-

OCTOBER16, 2009 DRAFT 18:42

(24)

8 1.4 Rule Induction

ertyPholds of the judgement J, we say thatPrespects the rule J1 . . . Jk

J

ifP(J)holds wheneverP(J1), . . . ,P(Jk). The assumptionsP(J1), . . . ,P(Jk) are called theinductive hypotheses, andP(J)is called theinductive conclusion, of the inference.

In practice the premises and conclusion of the rule involve objects that are universally quantified in the inductive step corresponding to that rule.

Thus to show that a propertyP is closed under a rule of the form a1J1 . . . ak Jk

aJ ,

we must show that for every a, a1, . . . , ak, if P(a1J1), . . . , P(ak Jk), then P(aJ).

The principle of rule induction is simply the expression of the defini- tion of an inductively defined judgement form as thestrongestjudgement form closed under the rules comprising the definition. This means that the judgement form is both (a) closed under those rules, and (b) sufficient for any other property also closed under those rules. The former property means that a derivation is evidence for the validity of a judgement; the latter means that we may reason about an inductively defined judgement form by rule induction.

IfP(J) is closed under a set of rules defining a judgement form, then so is the conjunction ofPwith the judgement itself. This means that when showingP to be closed under a rule, we may inductively assume not only thatP(Ji)holds for each of the premises Ji, but also that Ji itself holds as well. We shall generally take advantage of this without explicit mentioning that we are doing so.

When specialized to Rules (1.2), the principle of rule induction states that to showP(anat)wheneveranat, it is enough to show:

1. P(zeronat).

2. for everya, ifP(a nat), thenP(succ(a)nat).

This is just the familiar principle ofmathematical inductionarising as a spe- cial case of rule induction. The first condition is called thebasis of the in- duction, and the second is called theinductive step.

Similarly, rule induction for Rules (1.3) states that to show P(atree) wheneveratree, it is enough to show

18:42 DRAFT OCTOBER16, 2009

(25)

1.4 Rule Induction 9

1. P(emptytree).

2. for everya1anda2, ifP(a1 tree)andP(a2tree), thenP(node(a1;a2)tree). This is called the principle oftree induction, and is once again an instance of rule induction.

As a simple example of a proof by rule induction, let us prove that nat- ural number equality as defined by Rules (1.4) is reflexive:

Lemma 1.1. If anat, then a=anat.

Proof. By rule induction on Rules (1.2):

Rule(1.2a) Applying Rule (1.4a) we obtainzero=zeronat.

Rule(1.2b) Assume thata =a nat. It follows thatsucc(a)=succ(a)nat by an application of Rule (1.4b).

As another example of the use of rule induction, we may show that the predecessor of a natural number is also a natural number. While this may seem self-evident, the point of the example is to show how to derive this from first principles.

Lemma 1.2. Ifsucc(a)nat, then anat.

Proof. It is instructive to re-state the lemma in a form more suitable for inductive proof: ifbnatandbissucc(a)for somea, thenanat. We proceed by rule induction on Rules (1.2).

Rule(1.2a) Vacuously true, sincezerois not of the formsucc(−).

Rule(1.2b) We have thatbissucc(b0), and we may assume both that the lemma holds forb0and thatb0 nat. The result follows directly, since if succ(b0)=succ(a)for somea, thenaisb0.

Similarly, let us show that the successor operation is injective.

Lemma 1.3. Ifsucc(a1)=succ(a2)nat, then a1 =a2nat.

OCTOBER16, 2009 DRAFT 18:42

(26)

10 1.5 Iterated and Simultaneous Inductive Definitions Proof. It is instructive to re-state the lemma in a form more directly amenable to proof by rule induction. We are to show that ifb1=b2 natthen if b1 is succ(a1)andb2 issucc(a2), then a1= a2 nat. We proceed by rule induc- tion on Rules (1.4):

Rule(1.4a) Vacuously true, sincezerois not of the formsucc(−).

Rule(1.4b) Assuming the result forb1 =b2nat, and hence that the premise b1 =b2 natholds as well, we are to show that ifsucc(b1)issucc(a1) andsucc(b2)issucc(a2), thena1= a2nat. Under these assumptions we have b1 is a1 and b2 isa2, and so a1 =a2 nat is just the premise of the rule. (We make no use of the inductive hypothesis to complete this step of the proof.)

Both proofs rely on some natural assumptions about the universe of objects; see Section1.8on page14for further discussion.

1.5 Iterated and Simultaneous Inductive Definitions

Inductive definitions are often iterated, meaning that one inductive defi- nition builds on top of another. In an iterated inductive definition the premises of a rule

J1 . . . Jk J

may be instances of either a previously defined judgement form, or the judgement form being defined. For example, the following rules, define the judgementaliststating thatais a list of natural numbers.

nillist (1.8a)

anat blist

cons(a;b)list (1.8b)

The first premise of Rule (1.8b) is an instance of the judgement form anat, which was defined previously, whereas the premiseblistis an instance of the judgement form being defined by these rules.

Frequently two or more judgements are defined at once by a simulta- neous inductive definition. A simultaneous inductive definition consists of a

18:42 DRAFT OCTOBER16, 2009

(27)

1.5 Iterated and Simultaneous Inductive Definitions 11 set of rules for deriving instances of several different judgement forms, any of which may appear as the premise of any rule. Since the rules defining each judgement form may involve any of the others, none of the judgement forms may be taken to be defined prior to the others. Instead one must un- derstand that all of the judgement forms are being defined at once by the entire collection of rules. The judgement forms defined by these rules are, as before, the strongest judgement forms that are closed under the rules.

Therefore the principle of proof by rule induction continues to apply, albeit in a form that allows us to prove a property of each of the defined judge- ment forms simultaneously.

For example, consider the following rules, which constitute a simulta- neous inductive definition of the judgements a even, stating that a is an even natural number, andaodd, stating thatais an odd natural number:

zeroeven (1.9a)

aodd

succ(a)even (1.9b)

aeven

succ(a)odd (1.9c)

The principle of rule induction for these rules states that to show simul- taneously thatP(aeven)wheneveraevenandP(aodd)wheneveraodd, it is enough to show the following:

1. P(zeroeven);

2. ifP(aodd), thenP(succ(a)even); 3. ifP(aeven), thenP(succ(a)odd).

As a simple example, we may use simultaneous rule induction to prove that (1) ifa even, thena nat, and (2) ifa odd, then a nat. That is, we define the property P by (1)P(aeven)iff a nat, and (2) P(aodd)iff a nat. The principle of rule induction for Rules (1.9) states that it is sufficient to show the following facts:

1. zeronat, which is derivable by Rule (1.2a).

2. Ifanat, thensucc(a)nat, which is derivable by Rule (1.2b).

3. Ifanat, thensucc(a)nat, which is also derivable by Rule (1.2b).

OCTOBER16, 2009 DRAFT 18:42

(28)

12 1.6 Defining Functions by Rules

1.6 Defining Functions by Rules

A common use of inductive definitions is to define a function by giving an inductive definition of itsgraphrelating inputs to outputs, and then show- ing that the relation uniquely determines the outputs for given inputs. For example, we may define the addition function on natural numbers as the relationsum(a;b;c), with the intended meaning thatcis the sum ofaandb, as follows:

bnat

sum(zero;b;b) (1.10a) sum(a;b;c)

sum(succ(a);b;succ(c)) (1.10b) The rules define a ternary (three-place) relation,sum(a;b;c), among natural numbersa, b, andc. We may show thatcis determined bya andbin this relation.

Theorem 1.4. For every a natand b nat, there exists a unique c nat such that sum(a;b;c).

Proof. The proof decomposes into two parts:

1. (Existence) Ifanatandbnat, then there existscnatsuch thatsum(a;b;c). 2. (Uniqueness) Ifa nat,bnat,cnat,c0 nat,sum(a;b;c), andsum(a;b;c0),

thenc=c0 nat.

For existence, letP(anat)be the proposition if b natthen there exists c nat such thatsum(a;b;c). We prove that ifanatthenP(anat)by rule induction on Rules (1.2). We have two cases to consider:

Rule(1.2a) We are to show P(zeronat). Assuming b natand takingcto beb, we obtainsum(zero;b;c)by Rule (1.10a).

Rule(1.2b) AssumingP(anat), we are to showP(succ(a)nat). That is, we assume that ifb natthen there existscsuch thatsum(a;b;c), and are to show that ifb0 nat, then there existsc0such thatsum(succ(a);b0;c0). To this end, suppose thatb0 nat. Then by induction there existscsuch thatsum(a;b0;c). Takingc0 =succ(c), and applying Rule (1.10b), we obtainsum(succ(a);b0;c0), as required.

For uniqueness, we prove thatifsum(a;b;c1), then ifsum(a;b;c2), then c1= c2 nat by rule induction based on Rules (1.10).

18:42 DRAFT OCTOBER16, 2009

(29)

1.7 Modes 13 Rule(1.10a) We have a = zero and c1 = b. By an inner induction on the same rules, we may show that ifsum(zero;b;c2), thenc2isb. By Lemma1.1on page9we obtainb=bnat.

Rule(1.10b) We have thata=succ(a0)andc1 =succ(c01), wheresum(a0;b;c01). By an inner induction on the same rules, we may show that ifsum(a;b;c2), then c2 =succ(c02) nat where sum(a0;b;c02). By the outer inductive hypothesisc01 =c02natand soc1 =c2nat.

1.7 Modes

The statement that one or more arguments of a judgement is (perhaps uniquely) determined by its other arguments is called a mode specification for that judgement. For example, we have shown that every two natural numbers have a sum according to Rules (1.10). This fact may be restated as a mode specification by saying that the judgement sum(a;b;c) hasmode (∀,∀,∃). The notation arises from the form of the proposition it expresses: for all a nat and for all b nat, there exists c nat such thatsum(a;b;c). If we wish to further specify that cisuniquelydetermined by a andb, we would say that the judgement sum(a;b;c) has mode (∀,∀,∃!), corresponding to the propositionfor all a natand for all b nat, there exists a unique c natsuch that sum(a;b;c). If we wish only to specify that the sum is unique, if it exists, then we would say that the addition judgement has mode(∀,∀,∃1), cor- responding to the propositionfor all anatand for all bnatthere exists at most one cnatsuch thatsum(a;b;c).

As these examples illustrate, a given judgement may satisfy several dif- ferent mode specifications. In general the universally quantified arguments are to be thought of as the inputsof the judgement, and the existentially quantified arguments are to be thought of as itsoutputs. We usually try to arrange things so that the outputs come after the inputs, but it is not es- sential that we do so. For example, addition also has the mode(∀,∃1,∀), stating that the sum and the first addend uniquely determine the second addend, if there is any such addend at all. Put in other terms, this says that addition of natural numbers has a (partial) inverse, namely subtraction.

We could equally well show that addition has mode (∃1,∀,∀), which is just another way of stating that addition of natural numbers has a partial inverse.

OCTOBER16, 2009 DRAFT 18:42

(30)

14 1.8 Foundations Often there is an intended, or principal, mode of a given judgement, which we often foreshadow by our choice of notation. For example, when giving an inductive definition of a function, we often use equations to in- dicate the intended input and output relationships. For example, we may re-state the inductive definition of addition (given by Rules (1.10)) using equations:

anat

a+zero=anat (1.11a)

a+b=cnat

a+succ(b)=succ(c)nat (1.11b) When using this notation we tacitly incur the obligation to prove that the mode of the judgement is such that the object on the right-hand side of the equations is determined as a function of those on the left. Having done so, we abuse notation, writinga+bfor the uniquecsuch thata+b= cnat.

1.8 Foundations

An inductively judgement form, such asa nat, may be seen as isolating a class of objects,a, satisfying criteria specified by a collection of rules. While intuitively clear, this description is vague in that it does not specify what sorts of things may appear as the subjects of a judgement. Just what isa?

And what, exactly, are the objectszeroandsucc(a)used in the definition of the judgementanat? More generally, what sorts of objects are permissi- ble in an inductive definition?

One answer to these questions is to fix in advance a particular set,U, to serve as theuniverse of discourseover which all judgements are defined. The universe must be rich enough to contain all objects of interest, and must be specified clearly enough to avoid concerns about its existence. Standard practice is to defineUto be a particular set that can be shown to exist using the standard axioms of set theory, and to specify how the various objects of interest are constructed as elements of this set.

But what should we demand of U to serve as a suitable universe of discourse? At the very least it should includelabeled finitary trees, which are trees of finite height each of whose nodes has finitely many children and is labeled with an operatordrawn from some infinite set. An object such assucc(succ(zero)) is a finitary tree with nodes labeledzerohaving no children and nodes labeledsucchaving one child. Similarly, a finite tuple (a1, . . . ,an) may be thought of as a tree whose node is labeled by an n- tuple operator. Finitary trees will suffice for our work, but it is common

18:42 DRAFT OCTOBER16, 2009

(31)

1.9 Exercises 15 to consider alsoregular trees, which are finitary trees in which a child of a node may also be an ancestor of it, andinfinitary trees, which admit nodes with infinitely many children,.

The standard way to show that the universe,U, exists (that is, is prop- erly defined) is to construct it explicitly from the axioms of set theory. This requires that we fix the representation of trees as particular sets, using well- known, but notoriously unenlightening, methods.1 Instead we shall simply take it as given that this can be done, and takeU to be a suitably rich uni- verse including at least the finitary trees. In particular we assume that U comes equipped with operations that allow us to construct finitary trees as elements ofU, and to deconstruct such elements ofU into an operator and finitely many children.

The advantage of working within set theory is that it settles any wor- ries about the existence of the universe, U. However, it is important to keep in mind that accepting the axioms of set theory is far more dubious, foundationally speaking, than just accepting the existence of finitary trees without recourse to encoding them as sets. Moreover, there is a significant disadvantage to working with sets, namely that abstract sets have no in- trinsic computational content, and hence are of no use to implementation.

Yet it is intuitively clear that finitary trees can be readily implemented on a computer by means that have nothing to do with their set-theoretic encod- ings. Thus we are better off just takingU as our starting point, from both a foundational and computational perspective.

1.9 Exercises

1. Give an inductive definition of the judgementmax(a;b;c), whereanat, bnat, andcnat, with the meaning thatcis the larger ofaandb. Prove that this judgement has the mode(∀,∀,∃!).

2. Consider the following rules, which define the height of a binary tree as the judgementhgt(a;b).

hgt(empty;zero) (1.12a) hgt(a1;b1) hgt(a2;b2) max(b1;b2;b)

hgt(node(a1;a2);succ(b)) (1.12b)

1Perhaps you have seen the definition of the natural number 0 as the empty set,∅, and the numbern+1 as the setn∪ {n}, or the definition of the ordered pairha,bias the set {a,{a,b} }. Similar coding tricks can be used to represent any finitary tree.

OCTOBER16, 2009 DRAFT 18:42

(32)

16 1.9 Exercises Prove by tree induction that the judgement hgthas the mode(∀,∃), with inputs being binary trees and outputs being natural numbers.

3. Give an inductive definition of the judgement “∇is a derivation ofJ”

for an inductively defined judgement Jof your choice.

4. Give an inductive definition of the forward-chaining and backward- chaining search strategies.

18:42 DRAFT OCTOBER16, 2009

(33)

Chapter 2

Hypothetical Judgements

Acategoricaljudgement is an unconditional assertion about some object of the universe. The inductively defined judgements given in Chapter 1are all categorical. A hypothetical judgement expresses an entailment between one or more hypothesesand a conclusion. We will consider two notions of entailment, called derivabilityand admissibility. Derivability expresses the stronger of the two forms of entailment, namely that the conclusion may be deduced directly from the hypotheses by composing rules. Admissibility expresses the weaker form, that the conclusion is derivable from the rules whenever the hypotheses are also derivable. Both forms of entailment en- joy the samestructuralproperties that characterize conditional reasoning.

One consequence of these properties is that derivability is stronger than admissibility (but the converse fails, in general). We then generalize the concept of an inductive definition to admit rules that have not only cat- egorical, but also hypothetical, judgements as premises. Using these we may enrich the rules with new axioms that are available for use within a specified premise of a rule.

2.1 Derivability

For a given set, R, of rules, we define thederivability judgement, written J1, . . . ,Jk `R K, where eachJi andKare categorical, to mean that we may deriveKfrom theexpansionR[J1, . . . ,Jk]of the rulesRwith the additional axioms

J1 . . .

Jk .

(34)

18 2.1 Derivability That is, we treat thehypotheses, orantecedents, of the judgement, J1, . . . ,Jn astemporary axioms, and derive theconclusion, orconsequent, by composing rules in R. That is, evidence for a hypothetical judgement consists of a derivation of the conclusion from the hypotheses using the rules inR.

We use capital Greek letters, frequentlyΓor∆, to stand for a finite col- lection of basic judgements, and writeR[Γ] for the expansion of R with an axiom corresponding to each judgement inΓ. The judgementΓ `R K means thatK is derivable from rules R[Γ]. We sometimes write `R Γ to mean that `R J for each judgement J in Γ. The derivability judgement J1, . . . ,Jn`R Jis sometimes expressed by saying that the rule

J1 . . . Jn

J (2.1)

isderivablefrom the rulesR.

For example, consider the derivability judgement

anat`(1.2)succ(succ(a))nat (2.2)

relative to Rules (1.2). This judgement is valid foranychoice of objecta, as evidenced by the derivation

anat succ(a)nat

succ(succ(a))nat , (2.3)

which composes Rules (1.2), starting witha natas an axiom, and ending with succ(succ(a)) nat. Equivalently, the validity of (2.2) may also be expressed by stating that the rule

anat

succ(succ(a))nat (2.4)

is derivable from Rules (1.2).

It follows directly from the definition of derivability that it is stable un- der extension with new rules.

Theorem 2.1(Uniformity). IfΓ`R J, thenΓ`R∪R0 J.

Proof. Any derivation ofJfromR[Γ]is also a derivation from(R ∪ R0)[Γ], since the presence of additional rules does not influence the validity of the derivation.

18:42 DRAFT OCTOBER16, 2009

(35)

2.1 Derivability 19 Derivability enjoys a number ofstructural propertiesthat follow from its definition, independently of the rules,R, in question.

Reflexivity Every judgement is a consequence of itself: Γ,J `R J. Each hypothesis justifies itself as conclusion.

Weakening If Γ `R J, then Γ,K `R J. Entailment is not influenced by unexercised options.

Exchange IfΓ1,J1,J22 `R J, thenΓ1,J2,J12 `R J. The relative ordering of the axioms is immaterial.

Contraction IfΓ,J,J `R K, thenΓ,J `R K. We may use a hypothesis as many times as we like in a derivation.

Transitivity IfΓ,K `R J and Γ `R K, thenΓ `R J. If we replace an ax- iom by a derivation of it, the result is a derivation of its consequent without that hypothesis.

These properties may be summarized by saying that the derivability hypothetical judgement isstructural.

Theorem 2.2. For any rule set, R, the derivability judgementΓ `R J is struc- tural.

Proof. Reflexivity follows directly from the meaning of derivability. Weak- ening follows directly from uniformity. Exchange and contraction follow from the treatment of the rules,R, as a finite set, for which order does not matter and replication is immaterial. Transitivity is proved by rule induc- tion on the first premise.

In view of the structural properties of exchange and contraction, we re- gard the hypotheses,Γ, of a derivability judgement as a finite set of assump- tions, so that the order and multiplicity of hypotheses does not matter. In particular, when writingΓ as the unionΓ1Γ2 of two sets of hypotheses, a hypothesis may occur inbothΓ1andΓ2. This is obvious whenΓ1andΓ2are given, but when decomposing a givenΓinto two parts, it is well to remem- ber that the same hypothesis may occur in both parts of the decomposition.

OCTOBER16, 2009 DRAFT 18:42

(36)

20 2.2 Admissibility

2.2 Admissibility

Admissibility, writtenΓ |=R J, is a weaker form of hypothetical judgement stating that`R Γimplies`R J. That is, the conclusion J is derivable from rules R whenever the assumptions Γ are all derivable from rules R. In particular if any of the hypotheses arenotderivable relative toR, then the judgement is vacuously true. The admissibility judgement J1, . . . ,Jn |=R J is sometimes expressed by stating that the rule,

J1 . . . Jn

J ,

(2.5) isadmissiblerelative to the rules inR.

For example, the admissibility judgement

succ(a)nat|=(1.2) anat (2.6) is valid, because any derivation ofsucc(a)natfrom Rules (1.2) must con- tain a sub-derivation ofa natfrom the same rules, which justifies the con- clusion. The validity of (2.6) may equivalently be expressed by stating that the rule

succ(a)nat

anat (2.7)

is admissible for Rules (1.2).

In contrast to derivability the admissibility judgement isnotstable un- der extension to the rules. For example, if we enrich Rules (1.2) with the axiom

succ(junk)nat (2.8)

(wherejunk is some object for whichjunk nat is not derivable), then the admissibility (2.6) is invalid. This is because Rule (2.8) has no premises, and there is no composition of rules derivingjunk nat. Admissibility is as sensitive to which rules are absentfrom an inductive definition as it is to which rules arepresentin it.

The structural properties of derivability given by Theorem2.2 on the preceding page ensure that derivability is stronger than admissibility.

Theorem 2.3. IfΓ`R J, thenΓ|=R J.

Proof. Repeated application of the transitivity of derivability shows that if Γ`R Jand`RΓ, then`R J.

18:42 DRAFT OCTOBER16, 2009

(37)

2.2 Admissibility 21 To see that the converse fails, observe that there is no composition of rules such that

succ(junk)nat`(1.2)junknat, yet the admissibility judgement

succ(junk)nat|=(1.2)junknat

holds vacuously.

Evidence for admissibility may be thought of as a mathematical func- tion transforming derivations∇1, . . . ,∇nof the hypotheses into a deriva- tion ∇ of the consequent. Therefore, the admissibility judgement enjoys the same structural properties as derivability, and hence is a form of hypo- thetical judgement:

Reflexivity IfJis derivable from the original rules, thenJis derivable from the original rules: J |=R J.

Weakening If J is derivable from the original rules assuming that each of the judgements inΓare derivable from these rules, thenJmust also be derivable assuming thatΓand alsoKare derivable from the original rules: ifΓ|=R J, thenΓ,K|=R J.

Exchange The order of assumptions in an iterated implication does not matter.

Contraction Assuming the same thing twice is the same as assuming it once.

Transitivity IfΓ,K|=R JandΓ|=RK, thenΓ|=R J. If the assumptionKis used, then we may instead appeal to the assumed derivability ofK.

Theorem 2.4. The admissibility judgementΓ|=R J is structural.

Proof. Follows immediately from the definition of admissibility as stating that if the hypotheses are derivable relative toR, then so is the conclusion.

Just as with derivability, we may, in view of the properties of exchange and contraction, regard the hypotheses,Γ, of an admissibility judgement as a finite set, for which order and multiplicity does not matter.

OCTOBER16, 2009 DRAFT 18:42

(38)

22 2.3 Hypothetical Inductive Definitions

2.3 Hypothetical Inductive Definitions

It is useful to enrich the concept of an inductive definition to permit rules with derivability judgements as premises and conclusions. Doing so per- mits us to introducelocal hypothesesthat apply only in the derivation of a particular premise, and also allows us to constrain inferences based on the global hypothesesin effect at the point where the rule is applied.

Ahypothetical inductive definition consists of a collection ofhypothetical rulesof the form

Γ Γ1` J1 . . . Γ Γn` Jn

Γ` J . (2.9)

The hypothesesΓ are theglobal hypothesesof the rule, and the hypotheses Γi are thelocal hypothesesof theith premise of the rule. Informally, this rule states thatJ is a derivable consequence ofΓwhenever eachJiis a derivable consequence ofΓ, augmented with the additional hypothesesΓi. Thus, one way to show that J is derivable fromΓ is to show, in turn, that each Ji is derivable from Γ Γi. The derivation of each premise involves a “context switch” in which we extend the global hypotheses with the local hypothe- ses of that premise, establishing a new set of global hypotheses for use within that derivation.

Often a hypothetical rule is given for each choice of global context, with- out restriction. In that case the rule is said to be pure, because it applies irrespective of the context in which it is used. A pure rule, being stated uniformly for all global contexts, may be given inimplicitform, as follows:

Γ1` J1 . . . Γn` Jn

J . (2.10)

This formulation omits explicit mention of the global context in order to focus attention on the local aspects of the inference.

Sometimes it is necessary to restrict the global context of an inference, so that it applies only if a specifiedside conditionis satisfied. Such rules are said to beimpure. Impure rules generally have the form

Γ Γ1 ` J1 . . . Γ Γn ` Jn Ψ

Γ` J , (2.11)

where the condition, Ψ, limits the applicability of this rule to situations in which it is true. For example, Ψ may restrict the global context of the inference to be empty, so that no instances involving global hypotheses are permissible.

18:42 DRAFT OCTOBER16, 2009

(39)

2.4 Exercises 23 A hypothetical inductive definition is to be regarded as an ordinary in- ductive definition of a formal derivability judgement Γ ` J consisting of a finite set of basic judgements, Γ, and a basic judgement, J. A collection of hypothetical rules, R, defines thestrongestformal derivability judgement closed under rules R, which, by a slight abuse of notation, we write as Γ`R J.

Since Γ `R J is the strongest judgement closed under R, the princi- ple ofhypothetical rule inductionis valid for reasoning about it. Specifically, to show that P(Γ ` J)whenever Γ `R J, it is enough to show, for each rule (2.9) inR,

ifP(Γ Γ1` J1)and . . . andP(Γ Γn ` Jn), thenP(Γ` J).

This is just a restatement of the principle of rule induction given in Chap- ter1, specialized to the formal derivability judgementΓ` J.

In many cases we wish to ensure that the formal derivability relation defined by a collection of hypothetical rules is structural. This amounts to showing that the followingstructural rulesbe admissible:

Γ,J ` J (2.12a)

Γ` J

Γ,K` J (2.12b)

Γ` K Γ,K` J

Γ` J (2.12c)

In the common case that the rules of a hypothetical inductive definition are pure, the structural rules (2.12b) and (2.12c) may be easily shown ad- missible by rule induction. However, it is typically necessary to include Rule (2.12a) explicitly, perhaps in a restricted form, to ensure reflexivity.

2.4 Exercises

1. Prove that if all rules in a hypothetical inductive definition are pure, then the structural rules of weakening (Rule (2.12b)) and transitivity (Rule (2.12c)) are admissible.

2. DefineΓ0 `Γto mean thatΓ0 ` Ji for eachJi inΓ. Show thatΓ ` J iff wheneverΓ0 `Γ, it follows thatΓ0 ` J.Hint: from left to right, appeal to transitivity of entailment; from right to left, consider the case of Γ0 =Γ.

OCTOBER16, 2009 DRAFT 18:42

(40)

24 2.4 Exercises 3. Show that it is dangerous to permit admissibility judgements in the premise of a rule.Hint: show that using such rules one may “define”

an inconsistent judgement form J for which we have a J iff it isnot the case thata J.

18:42 DRAFT OCTOBER16, 2009

(41)

Chapter 3

Parametric Judgements

Basic judgements express properties of objects of the universe of discourse.

Hypothetical judgements express entailments between judgements, or rea- soning under hypotheses.Parametricjudgements express entailments among properties of objects involvingparameters, abstract symbols serving as atomic objects in an expanded universe.

Parameters have a variety of uses: as atomic symbols with no properties other than their identity, and as variables given meaning by substitution, the replacement of a parameter by an object. We shall make frequent use of parametric judgements throughout this book. Parametric inductive defini- tions, which generalize hypothetical inductive definitions to permit intro- duction of parameters in an inference, are of particular importance in our work.

3.1 Parameters and Objects

We assume given an infinite set ofparameters, which we will consider to be abstract atomic objects that are distinct from all other objects and that can be distinguished from one another (that is, we can tell whether any two given parameters are the same or different).1It follows that if we are given an object possibly containing a parameter, x, we can rename x to another parameter,x0, within that object.

To account for parameters we consider the family U[X]of expansions of the universe of discourse with parameters drawn from the finite setX.

1Parameters are sometimes calledsymbols, atoms, ornamesto emphasize their atomic, featureless character.

(42)

26 3.2 Rule Schemes (The expansion U[] may be identified with the universe, U, of finitary trees discussed in Chapter 1.) The elements of U[X] are finitary trees in which the parameters,X, may occur as leaves. We assume that parameters are distinct from operators so that there can be no confusion between a parameter and an operator that has no children.

Expansion of the universe is monotone in that ifX ⊆ Y, thenU[X] ⊆ U[Y], for a tree possibly involving parameters fromX is surely a tree possi- bly involving parameters fromY. A bijectionπ :X ↔ X0between param- eter sets induces a renamingπ : U[X] ↔ U[X0]that, intuitively, replaces each occurrence ofx ∈ X byπ(x) ∈ X0 in any element ofU[X], yielding an element ofU[X0].

3.2 Rule Schemes

The concept of an inductive definition extends naturally to any fixed ex- pansion of the universe by parameters, X. A collection of rules defined over the expansionU[X]determines the strongest judgement over that ex- pansion closed under these rules. Extending the notation of Chapter2, we write Γ `XR J to mean that J is derivable from R[Γ] over the expansion U[X].

It is often useful to consider rules that are defined over anarbitraryex- pansion of the universe by parameters. Recall Rule (1.2b) from Chapter1:

anat

succ(a)nat (3.1)

As discussed in Chapter1, this is actually arule schemethat stands for an infinite family of rules, called itsinstances, one for each choice of elementa of the universe,U. We extend the concept of rule scheme so that it applies to any expansion of the universe by parameters, so that for each choice of X, we obtain a family of instances of the rule scheme, one for each element aof the expansionU[X].

We will generally gloss over the distinction between a rule and a rule scheme, so that for example Rules (1.2) may be considered over any expan- sion of the universe by parameters without explicit mention. A collection of such rules defines the strongest judgement over a given expansion closed under all instances of the rule schemes over this expansion. Consequently, we may reason by rule induction as described in Chapter 1over any ex- pansion of the universe by simply reading the rules as applying to objects in that expansion.

18:42 DRAFT OCTOBER16, 2009

(43)

3.3 Parametric Derivability 27

3.3 Parametric Derivability

It will be useful to consider a generalizatiion of the derivability judgement that specifies the parameters, as well as the hypotheses, of a judgement. To a first approximation, theparametric derivabilityjudgement

X |Γ`R J (3.2)

means simply thatΓ `XR J. That is, the judgement J is derivable from hy- potheses Γ over the expansionU[X]. For example, the parametric judge- ment

{x} |xnat`(1.2)succ(succ(x))nat (3.3) is valid with respect to Rules (1.2), because the judgementsucc(succ(x))nat is derivable from the assumption x nat in the expansion of the universe with parameterx.

This is the rough-and-ready interpretation of the parametric judgement.

However, the full meaning is slightly stronger than that. In addition to the condition just specified, we also demand that the judgement hold for all renamings of the parameters X, so that the validity of the judgement cannot depend on the exact choice of parameters. To ensure this we define the meaning of the parametric judgement (3.2) to be given by the following condition:

π:X ↔ X0 πΓ`Xπ0RπJ.

Evidence for the judgement (3.2) consists of aparametric derivation,∇X0, of the judgementπJfrom rulesπR[πΓ]for some bijectionπ:X ↔ X0.

For example, judgement (3.3) is valid with respect to Rules (1.2) since, for everyx0, the judgement

succ(succ(x0))nat

is derivable from Rules (1.2) expanded with the axiomx0 nat. Evidence for this consists of the parametric derivation,∇x0,

x0 nat succ(x0)nat succ(succ(x0))nat

(3.4)

composed of Rules (1.2) and the axiomx0nat.

Parametric derivability enjoys two structural properties in addition to those enjoyed by the derivability judgement itself:

OCTOBER16, 2009 DRAFT 18:42

Referințe

DOCUMENTE SIMILARE

For the calibration of the connection between the integral intensity of the band “amide I” and the acetylation degree, five mixes were prepared with different proportions of

We also show here how reachability rules (based on matching logic) can be used to give operational semantics to programming languages.. In Section 3 we introduce the semantics of

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {.

It leads to change of oil characteristics and consequently to change of parameters describing viscous elastic fluids Assume that structure of initial model does not change by

In order to test Hap_Eu biocompatibility, the effect of europium substituted hydroxyapatite nanocristalline powders with different x Eu on cell viability and proliferation

The Wiener [7] index is the first reported distance based topological index and is defined as half sum of the distances between all the pairs of vertices in a molecular graph..

Using more formal diagnostics, we do show that the unification proposed by Schwenter (2006) holds. However, it is not surface manifestations like animacy and specificity that

The diagnostic accuracy of US could be improved in combination with CEUS (65.3% vs 83.7%). The diagnostic accuracy of the GB wall thickening type was higher than the mass forming