14.07.2013 Views

Syntactic Finitism in the Metatheory of ... - Yale University

Syntactic Finitism in the Metatheory of ... - Yale University

Syntactic Finitism in the Metatheory of ... - Yale University

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Abstract<br />

<strong>Syntactic</strong> <strong>F<strong>in</strong>itism</strong> <strong>in</strong> <strong>the</strong> Meta<strong>the</strong>ory <strong>of</strong><br />

Programm<strong>in</strong>g Languages<br />

Jeffrey Sarnat<br />

2010<br />

One <strong>of</strong> <strong>the</strong> central goals <strong>of</strong> programm<strong>in</strong>g-language research is to develop math-<br />

ematically sound formal methods for precisely specify<strong>in</strong>g and reason<strong>in</strong>g about <strong>the</strong><br />

behavior <strong>of</strong> programs. However, just as s<strong>of</strong>tware developers sometimes make mis-<br />

takes when programm<strong>in</strong>g, researchers sometimes make mistakes when prov<strong>in</strong>g that<br />

a formal method is ma<strong>the</strong>matically sound. As <strong>the</strong> field <strong>of</strong> programm<strong>in</strong>g-language<br />

research has grown, <strong>the</strong>se pro<strong>of</strong>s have become larger and more complex, and thus<br />

harder to verify on paper. This phenomenon has motivated a great deal <strong>of</strong> research<br />

<strong>in</strong>to <strong>the</strong> development <strong>of</strong> logical systems that provide an automated means to apply—<br />

and verify <strong>the</strong> application <strong>of</strong>—trusted reason<strong>in</strong>g pr<strong>in</strong>ciples to concrete pro<strong>of</strong>s.<br />

The boundary between trusted and untrusted reason<strong>in</strong>g pr<strong>in</strong>ciples is <strong>in</strong>herently<br />

blurry, and different researchers draw <strong>the</strong> l<strong>in</strong>e <strong>in</strong> different places. However, just as cer-<br />

ta<strong>in</strong> pr<strong>in</strong>ciples are widely recognized to allow <strong>the</strong> pro<strong>of</strong>s <strong>of</strong> contradictory statements,<br />

o<strong>the</strong>rs are so uncontroversially ubiquitous <strong>in</strong> practice that <strong>the</strong>y can be considered<br />

beyond reproach. We posit <strong>the</strong> follow<strong>in</strong>g questions: (1) what are <strong>the</strong>se pr<strong>in</strong>ciples<br />

and (2) how much can we do with <strong>the</strong>m?<br />

Although nei<strong>the</strong>r has an uncontroversial answer, <strong>in</strong> this dissertation we propose an<br />

answer to <strong>the</strong> former by describ<strong>in</strong>g a philosophical viewpo<strong>in</strong>t we refer to as syntactic<br />

f<strong>in</strong>itism, <strong>in</strong> which <strong>the</strong> pr<strong>in</strong>ciples <strong>of</strong> case analysis and structural <strong>in</strong>duction on abstract<br />

syntax are viewed as be<strong>in</strong>g a priori justified. We explore <strong>the</strong> latter question us<strong>in</strong>g<br />

some <strong>of</strong> <strong>the</strong> ideas and results from pro<strong>of</strong> <strong>the</strong>ory; along <strong>the</strong> way, we provide a syntacti-


cally f<strong>in</strong>itary account <strong>of</strong> pro<strong>of</strong>s by logical relations, and <strong>in</strong>vestigate <strong>the</strong> consequences<br />

<strong>of</strong> replac<strong>in</strong>g structural <strong>in</strong>duction with well-founded <strong>in</strong>duction on <strong>the</strong> lexicographic<br />

path order<strong>in</strong>g from term rewrit<strong>in</strong>g <strong>the</strong>ory. F<strong>in</strong>ally, we argue that syntactically f<strong>in</strong>i-<br />

tary pro<strong>of</strong>s can be formalized <strong>in</strong> <strong>the</strong> pro<strong>of</strong>s as logic programs paradigm popularized by<br />

<strong>the</strong> pro<strong>of</strong> assistant Twelf; we prove <strong>the</strong> soundness <strong>of</strong> a modular term<strong>in</strong>ation-analysis<br />

that is central to <strong>the</strong> validity <strong>of</strong> this <strong>in</strong>terpretation.<br />

2


<strong>Syntactic</strong> <strong>F<strong>in</strong>itism</strong> <strong>in</strong> <strong>the</strong> Meta<strong>the</strong>ory <strong>of</strong><br />

Programm<strong>in</strong>g Languages<br />

A Dissertation<br />

Presented to <strong>the</strong> Faculty <strong>of</strong> <strong>the</strong> Graduate School<br />

<strong>of</strong><br />

<strong>Yale</strong> <strong>University</strong><br />

<strong>in</strong> Candidacy for <strong>the</strong> Degree <strong>of</strong><br />

Doctor <strong>of</strong> Philosophy<br />

by<br />

Jeffrey Sarnat<br />

Dissertation Director: Carsten Schürmann<br />

May 2010


Copyright c○ 2010 by Jeffrey Sarnat<br />

All rights reserved.<br />

ii


Contents<br />

Acknowledgments v<br />

1 Introduction 1<br />

1.1 Abstract Syntax and Judgments . . . . . . . . . . . . . . . . . . . . . 3<br />

1.2 Case Analysis and Induction . . . . . . . . . . . . . . . . . . . . . . . 6<br />

1.3 Hypo<strong>the</strong>tical Judgments and Bound Variables . . . . . . . . . . . . . 9<br />

1.4 The Role <strong>of</strong> Consistency . . . . . . . . . . . . . . . . . . . . . . . . . 11<br />

1.5 <strong>Syntactic</strong> <strong>F<strong>in</strong>itism</strong> . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14<br />

2 Structural Logical Relations 17<br />

2.1 Normalization <strong>of</strong> <strong>the</strong> Simply Typed λ-calculus . . . . . . . . . . . . . 19<br />

2.2 Normalization <strong>of</strong> Gödel’s T . . . . . . . . . . . . . . . . . . . . . . . . 29<br />

3 Ord<strong>in</strong>al Analysis 35<br />

3.1 An Introduction to Ord<strong>in</strong>als . . . . . . . . . . . . . . . . . . . . . . . 36<br />

3.1.1 Ord<strong>in</strong>al Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . 36<br />

3.1.2 Ord<strong>in</strong>al Notation Systems . . . . . . . . . . . . . . . . . . . . 40<br />

3.2 Ord<strong>in</strong>als <strong>in</strong> Pro<strong>of</strong> Theory . . . . . . . . . . . . . . . . . . . . . . . . . 42<br />

3.2.1 Gentzen’s Theorems . . . . . . . . . . . . . . . . . . . . . . . 42<br />

3.2.2 Ord<strong>in</strong>al Recursive Hierarchies . . . . . . . . . . . . . . . . . . 45<br />

iii


3.2.3 <strong>Syntactic</strong> <strong>F<strong>in</strong>itism</strong> and PA2 . . . . . . . . . . . . . . . . . . . 49<br />

4 Lexicographic Path Induction 53<br />

4.1 The Lexicographic Path Order<strong>in</strong>g . . . . . . . . . . . . . . . . . . . . 55<br />

4.2 The Extraction Pro<strong>of</strong> . . . . . . . . . . . . . . . . . . . . . . . . . . . 58<br />

4.2.1 Pro<strong>of</strong> Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58<br />

4.2.2 Order<strong>in</strong>g Pro<strong>of</strong> Terms . . . . . . . . . . . . . . . . . . . . . . 61<br />

4.2.3 The Normalization Procedure . . . . . . . . . . . . . . . . . . 65<br />

5 Pro<strong>of</strong>s as Logic Programs 71<br />

5.1 Canonical Sp<strong>in</strong>e LF . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75<br />

5.1.1 Terms and Typ<strong>in</strong>g Rules . . . . . . . . . . . . . . . . . . . . . 77<br />

5.1.2 Hereditary Substitutions . . . . . . . . . . . . . . . . . . . . . 82<br />

5.1.3 Eta Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . 89<br />

5.2 Logic Programm<strong>in</strong>g . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98<br />

5.2.1 Mixed Prefix Contexts and Generalized Substitutions . . . . . 98<br />

5.2.2 The Semantics <strong>of</strong> Logic Programm<strong>in</strong>g . . . . . . . . . . . . . . 107<br />

5.2.3 Groundness and Abstract Substitutions . . . . . . . . . . . . . 114<br />

5.2.4 Size Order<strong>in</strong>g . . . . . . . . . . . . . . . . . . . . . . . . . . . 134<br />

5.2.5 The Mode and Term<strong>in</strong>ation Checker . . . . . . . . . . . . . . 148<br />

6 Related Work 174<br />

iv


Acknowledgements<br />

First and foremost, I owe an <strong>in</strong>credible debt <strong>of</strong> gratitude to my advisor, Carsten<br />

Schürmann, whose support for and faith <strong>in</strong> my ideas has been matched only by his<br />

tolerance for idiosyncrasies that would have broken lesser mentors. He has always<br />

treated me as a more <strong>of</strong> a colleague than a student, but has also played <strong>the</strong> unenviable<br />

role <strong>of</strong> concerned parent to my unruly teenager and, <strong>the</strong> (hopefully) less burdensome<br />

role <strong>of</strong> friend.<br />

The start<strong>in</strong>g po<strong>in</strong>t for <strong>the</strong> work <strong>in</strong> this dissertation was an <strong>in</strong>vestigation <strong>in</strong>to <strong>the</strong><br />

nature <strong>of</strong> pro<strong>of</strong>s by logical relations. Dur<strong>in</strong>g my time as an undergraduate, I was<br />

fortunate enough to be <strong>in</strong>troduced to this pro<strong>of</strong> technique <strong>in</strong> two different classes,<br />

one taught by Karl Crary, <strong>the</strong> o<strong>the</strong>r by Richard Statman. Weak normalization for<br />

<strong>the</strong> simply typed λ-calculus was proved as an example <strong>in</strong> both classes, but one<br />

relied on a Kripke-style def<strong>in</strong>ition, complete with quantification over typ<strong>in</strong>g contexts<br />

and various substitution lemmas, whereas <strong>the</strong> o<strong>the</strong>r relied on much less technical<br />

mach<strong>in</strong>ery. One day, my friend and classmate Bor-Yuh Evan Chang suggested that<br />

<strong>the</strong> two <strong>of</strong> us spend some time try<strong>in</strong>g to figure out <strong>the</strong> why one <strong>of</strong> <strong>the</strong>se pro<strong>of</strong>s seemed<br />

so much more complex than <strong>the</strong> o<strong>the</strong>r. We came up with <strong>the</strong> follow<strong>in</strong>g explanation:<br />

<strong>in</strong> <strong>the</strong> simpler pro<strong>of</strong>, every variable’s type is recorded as part <strong>of</strong> its name, whereas<br />

<strong>in</strong> <strong>the</strong> more complex pro<strong>of</strong>, <strong>the</strong> type <strong>of</strong> a variable must be looked up <strong>in</strong> a typ<strong>in</strong>g<br />

context. This simple observation was one <strong>of</strong> many that led to <strong>the</strong> development <strong>of</strong><br />

v


<strong>the</strong> concept <strong>of</strong> structural logical relation, which plays an important role <strong>in</strong> my work.<br />

My graduate career has been unusual <strong>in</strong> that it spanned across two cont<strong>in</strong>ents<br />

and two universities, first <strong>Yale</strong>, <strong>the</strong>n <strong>the</strong> IT <strong>University</strong> <strong>of</strong> Copenhagen. I would like<br />

to thank L<strong>in</strong>da Dobb, Drew McDermott and Vladimir Rokhl<strong>in</strong> for <strong>the</strong>ir essential<br />

help <strong>in</strong> deal<strong>in</strong>g with <strong>the</strong> nontrivial adm<strong>in</strong>istrative issues associated with complet<strong>in</strong>g<br />

<strong>the</strong> last years <strong>of</strong> my dissertation research <strong>in</strong> a foreign country.<br />

Over <strong>the</strong> years, I have benefitted immensely from <strong>the</strong> knowledge and expertise<br />

<strong>of</strong> numerous colleagues on both sides <strong>of</strong> <strong>the</strong> Atlantic. I am especially grateful to<br />

Valery Trifonov for our many enlighten<strong>in</strong>g conversations early <strong>in</strong> my graduate career,<br />

to Adam Poswolsky, whose friendship and technical knowledge provided cont<strong>in</strong>uity<br />

<strong>in</strong> our trip across <strong>the</strong> Atlantic, and to all <strong>of</strong> <strong>the</strong> PLS group at ITU, who always<br />

treated me as though I were one <strong>of</strong> <strong>the</strong>ir own. In particular, I would like to thank<br />

Anders Schack-Nielsen, whose expertise was <strong>of</strong> great help when I was try<strong>in</strong>g to f<strong>in</strong>d<br />

an elegant specification for <strong>the</strong> semantics <strong>of</strong> logic programm<strong>in</strong>g, Søren Debois, for<br />

his helpful comments on an earlier draft <strong>of</strong> this document, and Ge<strong>of</strong>frey Washburn<br />

for not only provid<strong>in</strong>g helpful feedback on my research, but creat<strong>in</strong>g a font that<br />

allows me to typeset <strong>the</strong> symbol g. Beyond <strong>Yale</strong> and ITU, I benefitted immensely<br />

from conversations with Michael Rathjen and Anton Setzer, who were k<strong>in</strong>d enough<br />

to answer some <strong>of</strong> my early questions about ord<strong>in</strong>al analysis, and from an email<br />

exchange with Georg Moser, <strong>in</strong> which some <strong>of</strong> my later questions about large ord<strong>in</strong>als<br />

were answered.<br />

F<strong>in</strong>ally, I am grateful to all <strong>of</strong> my friends, and especially my family, for <strong>the</strong>ir<br />

cont<strong>in</strong>ued lov<strong>in</strong>g support <strong>in</strong> all my endeavors, even when <strong>the</strong>y keep me far from<br />

home.<br />

vi


Chapter 1<br />

Introduction<br />

At its heart, computer science is not as much <strong>the</strong> study <strong>of</strong> computers as it is <strong>the</strong><br />

study <strong>of</strong> problems that computers can be used to solve. But what does it mean for<br />

a problem to be solved with a computer? Simply writ<strong>in</strong>g a program is not enough,<br />

regardless <strong>of</strong> <strong>the</strong> computational paradigm; <strong>the</strong> program must also be correct, and<br />

establish<strong>in</strong>g correctness requires <strong>the</strong> ability to reason, be it formally or <strong>in</strong>formally,<br />

about <strong>the</strong> behavior <strong>of</strong> s<strong>of</strong>tware.<br />

We live <strong>in</strong> a world where it is <strong>in</strong>creas<strong>in</strong>gly common to rely on <strong>the</strong> correctness<br />

<strong>of</strong> computer programs, and where <strong>the</strong> consequences <strong>of</strong> <strong>in</strong>correct programs can range<br />

from <strong>in</strong>convenience to <strong>the</strong> loss <strong>of</strong> life. At <strong>the</strong> same time, <strong>the</strong> programs that we rely<br />

on are becom<strong>in</strong>g <strong>in</strong>creas<strong>in</strong>gly complex, and thus harder to reason about <strong>in</strong>formally.<br />

This phenomenon has motivated a great deal <strong>of</strong> programm<strong>in</strong>g-language research <strong>in</strong>to<br />

<strong>the</strong> development <strong>of</strong> ma<strong>the</strong>matically sound formal methods for precisely specify<strong>in</strong>g<br />

and reason<strong>in</strong>g about <strong>the</strong> behavior <strong>of</strong> programs (e.g. operational semantics, denota-<br />

tional semantics, type systems and Hoare logic), along with practical tools that give<br />

programmers a (semi-) automated means to apply—and verify <strong>the</strong> application <strong>of</strong>—<br />

<strong>the</strong>se techniques to concrete programs (e.g. type checkers, abstract <strong>in</strong>terpretors and<br />

1


model checkers).<br />

However, just as s<strong>of</strong>tware developers sometimes make mistakes when program-<br />

m<strong>in</strong>g, researchers sometimes make mistakes when prov<strong>in</strong>g that a formal method is<br />

ma<strong>the</strong>matically sound. That is, simply writ<strong>in</strong>g a soundness pro<strong>of</strong> is not enough;<br />

<strong>the</strong> pro<strong>of</strong> must also be correct, and establish<strong>in</strong>g <strong>the</strong> correctness <strong>of</strong> a pro<strong>of</strong> requires<br />

<strong>the</strong> ability to reason, be it formally or <strong>in</strong>formally, about <strong>the</strong> applicability <strong>of</strong> trusted<br />

reason<strong>in</strong>g pr<strong>in</strong>ciples. As <strong>the</strong> field <strong>of</strong> programm<strong>in</strong>g-languages research has grown, <strong>the</strong><br />

pro<strong>of</strong>s have become larger and more complex, and thus harder to verify <strong>in</strong>formally.<br />

This phenomenon has motivated a great deal <strong>of</strong> research <strong>in</strong>to <strong>the</strong> development <strong>of</strong><br />

logical systems (e.g. Coq, Isabelle, Agda and Twelf) that allow researchers a (semi-)<br />

automated means to apply—and verify <strong>the</strong> application <strong>of</strong>—trusted reason<strong>in</strong>g pr<strong>in</strong>ci-<br />

ples to concrete pro<strong>of</strong>s. But exactly which reason<strong>in</strong>g pr<strong>in</strong>ciples can be trusted?<br />

This is a deeply philosophical question, whose answer varies from person to per-<br />

son; we do not attempt to answer it here. However, just as certa<strong>in</strong> reason<strong>in</strong>g pr<strong>in</strong>ci-<br />

ples (e.g. <strong>the</strong> unrestricted comprehension axiom <strong>in</strong> naive set <strong>the</strong>ory and type:type <strong>in</strong><br />

type <strong>the</strong>ory) are widely recognized to allow <strong>the</strong> pro<strong>of</strong>s <strong>of</strong> contradictory statements<br />

(e.g. Russel’s paradox, Girard’s paradox), o<strong>the</strong>r reason<strong>in</strong>g pr<strong>in</strong>ciples are so uncon-<br />

troversially ubiquitous <strong>in</strong> practice that <strong>the</strong>y can be considered beyond reproach. We<br />

posit <strong>the</strong> follow<strong>in</strong>g questions: (1) what are <strong>the</strong>se pr<strong>in</strong>ciples and (2) how much can<br />

we do with <strong>the</strong>m? Although nei<strong>the</strong>r has an uncontroversial answer, we propose an<br />

answer to <strong>the</strong> former <strong>in</strong> <strong>the</strong> rema<strong>in</strong>der <strong>of</strong> this section, and explore <strong>the</strong> latter <strong>in</strong> <strong>the</strong><br />

rema<strong>in</strong>der <strong>of</strong> this dissertation.<br />

2


1.1 Abstract Syntax and Judgments<br />

The dear God made <strong>the</strong> whole numbers, everyth<strong>in</strong>g<br />

else is <strong>the</strong> work <strong>of</strong> man.<br />

Leopold Kronecker (attributed <strong>in</strong> [Web93])<br />

quote translated from German by Dirk Schlimm<br />

The tradition called “syntactic”. . . would without<br />

doubt have disappeared <strong>in</strong> one or two more decades,<br />

for want <strong>of</strong> any issue or methodology. The disaster<br />

was averted because <strong>of</strong> computer science – that<br />

great manipulator <strong>of</strong> syntax – which posed it some<br />

very important <strong>the</strong>oretical problems.<br />

Jean-Yves Girard [GLT89]<br />

Syntax is as fundamental to <strong>the</strong> study <strong>of</strong> programm<strong>in</strong>g languages as <strong>the</strong> whole<br />

numbers are to ma<strong>the</strong>matics. Thus, we regard <strong>the</strong> def<strong>in</strong>ition <strong>of</strong> syntactic categories<br />

us<strong>in</strong>g BNF-style notation as be<strong>in</strong>g a priori justified. For example, <strong>the</strong> natural num-<br />

bers (or, if we were to <strong>in</strong>terpret z as a representation <strong>of</strong> <strong>the</strong> number 1, <strong>the</strong> whole<br />

numbers) can be def<strong>in</strong>ed <strong>in</strong> this manner as follows.<br />

Natural Numbers n, m ::= z | s n<br />

The left-hand side <strong>of</strong> this def<strong>in</strong>ition establishes “n” and “m” as stand<strong>in</strong>g for arbitrary<br />

natural numbers; right-hand side allow us to “build up” natural numbers us<strong>in</strong>g <strong>the</strong><br />

term constructors “z” and “s”.<br />

In order to reason about syntax, we need some means to express <strong>the</strong> properties<br />

that syntactic terms may or may not possess. Although <strong>the</strong>re are several ways <strong>of</strong><br />

do<strong>in</strong>g this, perhaps <strong>the</strong> most basic and widespread is to def<strong>in</strong>e judgments us<strong>in</strong>g <strong>in</strong>-<br />

ference rules, a practice that we consider to be a priori justified. For example, we<br />

3


may def<strong>in</strong>e <strong>the</strong> assertion that a particular natural number is even, along with <strong>the</strong><br />

assertion that a particular natural number is odd, as judgments def<strong>in</strong>ed by <strong>the</strong> fol-<br />

low<strong>in</strong>g <strong>in</strong>ference rules.<br />

even(z)<br />

evenz<br />

even(n) odds<br />

odd(s n)<br />

odd(n)<br />

even(s n)<br />

Judgments can also be used to represent computations. For example, we may<br />

def<strong>in</strong>e <strong>the</strong> assertion that <strong>the</strong> natural numbers n0 and n1 sum to <strong>the</strong> number m by<br />

def<strong>in</strong><strong>in</strong>g <strong>the</strong> judgment add(n0; n1; m) us<strong>in</strong>g <strong>the</strong> follow<strong>in</strong>g <strong>in</strong>ference rules.<br />

add(z; n1; n1)<br />

addz<br />

add(n0; n1; m)<br />

add(s n0; n1; s m)<br />

The relationship between <strong>the</strong> Ackermann function’s <strong>in</strong>puts and outputs can be rep-<br />

resented similarly.<br />

ack(z; n1; s n1)<br />

ackz<br />

ack(n0; s z; m) acksz<br />

ack(s n; z; m)<br />

evens<br />

adds<br />

ack(s n0; n1; m) ack(n0; m; m ′ ) ackss<br />

ack(s n0; s n1; m ′ )<br />

In general, <strong>in</strong>ference rules can be used to “build up” derivations <strong>of</strong> judgments<br />

<strong>in</strong> much <strong>the</strong> same way that <strong>the</strong> clauses <strong>of</strong> a BNF-style def<strong>in</strong>ition can be used to<br />

build up syntactic terms. We refer to arbitrary derivations <strong>of</strong> a judgment such<br />

as ack(n0; n1; m) us<strong>in</strong>g <strong>the</strong> notation D : ack(n0; n1; m) (or just D whenever <strong>the</strong><br />

judgment is clear from <strong>the</strong> context), and say that a judgment is <strong>in</strong>habited to mean<br />

that such a derivation exists. We write concrete derivations <strong>of</strong> judgments as trees;<br />

for example, a derivation <strong>of</strong> <strong>the</strong> judgment ack(s z; s z; s (s (s z))) would be written<br />

as follows.<br />

ack(z; s z; s (s z))<br />

ack(s z; z; s (s z))<br />

ackz<br />

acksz<br />

ack(z; s (s z); s (s (s z)))<br />

ack(s z; s z; s (s (s z)))<br />

In general, judgments can be thought <strong>of</strong> as mak<strong>in</strong>g logical assertions, where a<br />

derivation is a f<strong>in</strong>ite witness to an assertion’s validity. That is, ack(s z; s z; s (s (s z)))<br />

4<br />

ackz<br />

ackss


can be thought <strong>of</strong> as be<strong>in</strong>g “true” or “provable” (evident <strong>in</strong> <strong>the</strong> term<strong>in</strong>ology <strong>of</strong><br />

Mart<strong>in</strong>-Löf [ML85]) by virtue <strong>of</strong> <strong>the</strong> fact that it is <strong>in</strong>habited by <strong>the</strong> derivation written<br />

above. Judgments that make logical assertions <strong>of</strong> <strong>the</strong> form “<strong>the</strong> program e evalu-<br />

ates to a value v” are widely and uncontroversially used to specify <strong>the</strong> semantics <strong>of</strong><br />

programm<strong>in</strong>g languages. Such judgmental specifications are referred to as structural<br />

operational semantics [Plo81].<br />

Some judgments fail to def<strong>in</strong>e <strong>in</strong>terest<strong>in</strong>g logical assertions; this, however does<br />

not preclude <strong>the</strong>ir derivations from be<strong>in</strong>g <strong>in</strong>terest<strong>in</strong>g. One such judgment is de-<br />

f<strong>in</strong>ed below; its derivations are isomorphic to <strong>the</strong> natural numbers, as def<strong>in</strong>ed at <strong>the</strong><br />

beg<strong>in</strong>n<strong>in</strong>g <strong>of</strong> this section.<br />

nat<br />

z<br />

nat s<br />

nat<br />

In general, any syntactic category def<strong>in</strong>ed <strong>in</strong> BNF-style notation can be expressed<br />

as a judgment. Similarly, if we broaden our notion <strong>of</strong> BNF-style def<strong>in</strong>ition to allow<br />

syntactic categories that depend on one ano<strong>the</strong>r, we can def<strong>in</strong>e syntactic categories<br />

whose terms are isomorphic to <strong>the</strong> derivations <strong>of</strong> arbitrary judgments. For example,<br />

<strong>the</strong> syntactic categories E n and O n , def<strong>in</strong>ed below, are isomorphic to derivations <strong>of</strong><br />

<strong>the</strong> judgments even(n) and odd(n), respectively.<br />

En ::= evenzz | (evens On ) s n<br />

On ::= (odds En ) s n<br />

Although <strong>the</strong> use <strong>of</strong> dependencies <strong>in</strong> <strong>the</strong> def<strong>in</strong>ition <strong>of</strong> abstract syntax is not partic-<br />

ularly widespread, such def<strong>in</strong>itions are no less justifiable than judgments def<strong>in</strong>ed by<br />

<strong>in</strong>ference rules. Thus, <strong>the</strong> dist<strong>in</strong>ction between syntactic categories and judgments<br />

is essentially a matter <strong>of</strong> notational preference. We refer to this observation as <strong>the</strong><br />

judgments-as-types pr<strong>in</strong>ciple, for reasons that will be made more clear <strong>in</strong> Section 5.1.<br />

5


1.2 Case Analysis and Induction<br />

<strong>Syntactic</strong> categories and judgments are both <strong>in</strong>herently (syntactically) f<strong>in</strong>itary con-<br />

cepts <strong>in</strong> <strong>the</strong> sense that, although <strong>the</strong>re may be unboundedly many natural numbers,<br />

each <strong>in</strong>dividual natural number is constructed from f<strong>in</strong>itely many uses <strong>of</strong> <strong>the</strong> con-<br />

structors z and s, and noth<strong>in</strong>g else. Thus, we are a priori justified not only <strong>in</strong><br />

build<strong>in</strong>g up concrete terms and derivations via <strong>the</strong> application <strong>of</strong> constructors and<br />

<strong>in</strong>ference rules, but <strong>in</strong> tak<strong>in</strong>g apart abstract terms and derivations via case analysis<br />

and transform<strong>in</strong>g <strong>the</strong>m <strong>in</strong>to potentially different types <strong>of</strong> objects via structural <strong>in</strong>-<br />

duction (i.e. well-founded <strong>in</strong>duction on <strong>the</strong> subterm order<strong>in</strong>g). We show an example<br />

<strong>of</strong> such reason<strong>in</strong>g, which <strong>in</strong>cludes a non-trivial case analysis, <strong>in</strong> <strong>the</strong> <strong>the</strong>orem below.<br />

Theorem 1.2.1 If D : add(n0; n1; m) and E : (even(n0)) and even(n1) <strong>the</strong>n<br />

even(m)<br />

Pro<strong>of</strong>: By structural <strong>in</strong>duction on E (n0 and D are equally suitable candidates).<br />

Note that <strong>the</strong> statement <strong>of</strong> <strong>the</strong> <strong>the</strong>orem is shorthand for <strong>the</strong> follow<strong>in</strong>g, more verbose<br />

statement: “For every n0, n1, m, for every D : (add(n0; n1; m)) and for every E :<br />

(even(n0)) and for every F : even(n1) <strong>the</strong>re exists G : (even(m)).<br />

Case:<br />

E =<br />

D =<br />

even(z)<br />

evenz<br />

add(z; n1; n1)<br />

even(n1) given<br />

6<br />

addz


Case:<br />

E =<br />

D =<br />

E0<br />

even(n0)<br />

odd(s n0)<br />

odds<br />

even(s (s n0))<br />

D0<br />

add(n0; n1; m)<br />

add(s n0; n1; s m)<br />

evens<br />

adds<br />

add(s (s n0); n1; s (s m))<br />

even(n1) given<br />

even(m) by IH on E0<br />

odd(s m) by rule odds<br />

even(s (s m)) by rule evens<br />

Informally, Theorem 1.2.1 tells us that <strong>the</strong> given summand <strong>of</strong> two even numbers<br />

is even. However, thus far we have not shown that such a summand must always<br />

exist. We can do so by prov<strong>in</strong>g <strong>the</strong> statement “for every n0, n1, <strong>the</strong>re exists an m<br />

such that add(n0; n1; m),” which, <strong>in</strong> this case follows by a straightforward structural<br />

<strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> n0. Thus, we can th<strong>in</strong>k <strong>of</strong> add as describ<strong>in</strong>g a (total)<br />

function 1 from its first two arguments to its third.<br />

The analogous totality statement for ack—“for every n0, n1, <strong>the</strong>re exists an m<br />

such that ack(n0; n1; m)”—can also be proven by a straightforward <strong>in</strong>duction, not on<br />

1 Technically this only shows that add’s third argument is a potentially nondeterm<strong>in</strong>istic total<br />

function <strong>of</strong> its first two arguments, s<strong>in</strong>ce we have not yet shown that it is unique (although <strong>in</strong><br />

this case, do<strong>in</strong>g so would be straightforward). In this document, we view all functions as be<strong>in</strong>g<br />

potentially nondeterm<strong>in</strong>istic until proven o<strong>the</strong>rwise, and only explicitly prove determ<strong>in</strong>acy when<br />

do<strong>in</strong>g so is germane to <strong>the</strong> discussion at hand.<br />

7<br />

adds


<strong>the</strong> structure <strong>of</strong> n0 or on <strong>the</strong> structure <strong>of</strong> n1, but on <strong>the</strong> lexicographic order<strong>in</strong>g <strong>of</strong> n0<br />

and n1. In general, we consider well-founded <strong>in</strong>duction to be a priori justified on any<br />

order<strong>in</strong>g that we consider <strong>in</strong>tuitively well-founded, such as <strong>the</strong> lexicographic order<strong>in</strong>g<br />

<strong>of</strong> two well-founded order<strong>in</strong>gs. For now, we restrict our attention to <strong>the</strong> subterm<br />

order<strong>in</strong>g on terms/derivations, and <strong>the</strong> lexicographic and simultaneous order<strong>in</strong>gs on<br />

tuples <strong>of</strong> terms/derivations; we will consider both <strong>the</strong> consequences <strong>of</strong> this restriction<br />

<strong>in</strong> Chapter 3, and <strong>the</strong> impact <strong>of</strong> assum<strong>in</strong>g much stronger order<strong>in</strong>g is well-founded <strong>in</strong><br />

Chapter 4.<br />

Recall that lexicographic order<strong>in</strong>gs generalize <strong>the</strong> notion <strong>of</strong> <strong>the</strong> alphabetical or-<br />

der<strong>in</strong>g used to order words <strong>in</strong> dictionaries, and precisely captures <strong>the</strong> notion <strong>of</strong> “tie<br />

breaker” sometimes used to rank sports teams (e.g. teams are ranked first by <strong>the</strong>ir<br />

w<strong>in</strong>-loss record, teams with <strong>the</strong> same record are ranked by <strong>the</strong>ir po<strong>in</strong>t differential,<br />

etc.). More precisely, one tuple is smaller than ano<strong>the</strong>r iff <strong>the</strong> first n elements <strong>of</strong><br />

each are equal <strong>in</strong> size, and <strong>the</strong> (n + 1)th element <strong>of</strong> <strong>the</strong> first is strictly smaller than<br />

<strong>the</strong> (n + 1)th element <strong>of</strong> <strong>the</strong> second. The simultaneous order<strong>in</strong>g can be seen as a<br />

special case <strong>of</strong> <strong>the</strong> lexicographic order<strong>in</strong>g: one tuple simultaneously smaller than<br />

ano<strong>the</strong>r iff every element <strong>of</strong> <strong>the</strong> first is smaller-than or equal-<strong>in</strong>-size to <strong>the</strong> corre-<br />

spond<strong>in</strong>g element <strong>in</strong> <strong>the</strong> second tuple, and moreover at least one <strong>of</strong> <strong>the</strong>se <strong>in</strong>equalities<br />

is strict. The simultaneous order<strong>in</strong>g can be generalized to be commutative: one tu-<br />

ple is smaller than ano<strong>the</strong>r iff <strong>the</strong> elements <strong>of</strong> <strong>the</strong> first can be permuted such that<br />

<strong>the</strong> result<strong>in</strong>g tuple is smaller than <strong>the</strong> second accord<strong>in</strong>g to <strong>the</strong> ord<strong>in</strong>ary simultane-<br />

ous order<strong>in</strong>g. Strictly speak<strong>in</strong>g this commutative generalization is unnecessary: any<br />

<strong>the</strong>orem whose <strong>in</strong>ductive pro<strong>of</strong> uses <strong>the</strong> natural sum order<strong>in</strong>g on an n-tuple <strong>of</strong> deriva-<br />

tions can, <strong>in</strong> pr<strong>in</strong>ciple, be transformed <strong>in</strong>to n! mutually <strong>in</strong>ductive <strong>the</strong>orems whose<br />

pro<strong>of</strong>s use <strong>the</strong> conventional simultaneous order<strong>in</strong>g.<br />

8


In terms <strong>of</strong> ord<strong>in</strong>al arithmetic, <strong>the</strong> lexicographic order<strong>in</strong>g def<strong>in</strong>es ord<strong>in</strong>al multi-<br />

plication; <strong>the</strong> significance <strong>of</strong> this observation will be expounded upon <strong>in</strong> Chapter 3.<br />

1.3 Hypo<strong>the</strong>tical Judgments and Bound Variables<br />

Consider <strong>the</strong> syntactic category τ, def<strong>in</strong>ed below.<br />

σ, τ ::= o | σ ⇒ τ<br />

For now we wish to th<strong>in</strong>k <strong>of</strong> τ as def<strong>in</strong><strong>in</strong>g propositions, where o is an empty propo-<br />

sition, and σ ⇒ τ is an implication. We have seen that judgments can be used to<br />

def<strong>in</strong>e logical assertions such as “<strong>the</strong> natural number n is even”; <strong>the</strong>y can also be<br />

used to def<strong>in</strong>e assertions <strong>of</strong> a more transparently logical nature, such as “<strong>the</strong> formula<br />

τ is provable.” We give an example <strong>of</strong> a natural deduction style pro<strong>of</strong> system by <strong>the</strong><br />

hypo<strong>the</strong>tical judgment ⊢ τ nd with <strong>the</strong> follow<strong>in</strong>g <strong>in</strong>ference rules.<br />

⊢ σ nd<br />

.<br />

⊢ τ nd<br />

x σ<br />

⊢ σ ⇒ τ nd<br />

lam x σ<br />

⊢ σ ⇒ τ nd ⊢ σ nd app<br />

⊢ τ nd<br />

Informally, <strong>the</strong> rule lamxσ can be applied to a derivation conta<strong>in</strong><strong>in</strong>g any number <strong>of</strong><br />

free uses <strong>of</strong> <strong>the</strong> <strong>in</strong>ference rule x σ , where we regard <strong>the</strong> exact choice <strong>of</strong> <strong>the</strong> name x σ<br />

as be<strong>in</strong>g irrelevant to <strong>the</strong> identity <strong>of</strong> <strong>the</strong> result<strong>in</strong>g derivation. In o<strong>the</strong>r words, we can<br />

view <strong>the</strong> rule lamx σ as b<strong>in</strong>d<strong>in</strong>g <strong>the</strong> <strong>in</strong>ference-rule variable xσ . In general, we view<br />

variables as holes that can be filled with arbitrary derivations, thus justify<strong>in</strong>g <strong>the</strong><br />

follow<strong>in</strong>g pr<strong>in</strong>ciple <strong>of</strong> substitution: given a derivation D : ( ⊢ τ nd) that conta<strong>in</strong>s<br />

some number <strong>of</strong> free occurrences <strong>of</strong> <strong>the</strong> <strong>in</strong>ference-rule variable x σ , and a derivation<br />

E : ( ⊢ σ nd), <strong>the</strong>re exists a derivation <strong>of</strong> ⊢ τ nd, written D[E/x σ ], <strong>in</strong> which all<br />

9


occurrences <strong>of</strong> x σ <strong>in</strong> D have been replaced by E. Given <strong>the</strong> mach<strong>in</strong>ery described<br />

thus far, we ei<strong>the</strong>r view <strong>the</strong> (capture-avoid<strong>in</strong>g) substitution pr<strong>in</strong>ciple (and thus <strong>the</strong><br />

notation D[E/x σ ]) as be<strong>in</strong>g a priori justified, or as a <strong>the</strong>orem that must be proven<br />

by <strong>in</strong>duction (where D[E/x σ ] = F would be formulated judgmentally). In this doc-<br />

ument, we adopt <strong>the</strong> former view for <strong>the</strong> sake <strong>of</strong> convenience, although our results<br />

do not depend on this <strong>in</strong> any essential way.<br />

We can also def<strong>in</strong>e natural deduction style pro<strong>of</strong>s us<strong>in</strong>g BNF-style notation.<br />

e τ ::= x τ | (lam x σ . e τ ) σ⇒τ | (app e σ⇒τ<br />

1<br />

If we th<strong>in</strong>k <strong>of</strong> τ as def<strong>in</strong><strong>in</strong>g types ra<strong>the</strong>r than propositions, e τ clearly def<strong>in</strong>es <strong>the</strong><br />

well-typed terms <strong>of</strong> <strong>the</strong> simply typed λ-calculus. For example, we can def<strong>in</strong>e <strong>the</strong><br />

notion <strong>of</strong> s<strong>in</strong>gle- and multi-step reduction by β-contraction and η-expansion us<strong>in</strong>g<br />

<strong>the</strong> follow<strong>in</strong>g judgments (where we omit type superscripts where <strong>the</strong>y are easily<br />

<strong>in</strong>ferred or irrelevant).<br />

red-beta<br />

app (lam x τ . e σ 1) e τ 2 −→ e σ 1[e τ 2/x τ ]<br />

app e σ⇒τ<br />

1<br />

e σ⇒τ<br />

1<br />

−→ e ′σ⇒τ<br />

1<br />

e σ 2 −→ app e ′σ⇒τ<br />

1<br />

e τ −→ ∗ e τ<br />

e σ 2<br />

cong-app1<br />

e σ −→ e ′σ<br />

e σ 2 )τ<br />

exp-eta<br />

e σ⇒τ −→ lam x τ .app e σ⇒τ x σ<br />

app e σ⇒τ<br />

1<br />

lam x τ . e σ −→ lam x τ . e ′σ<br />

reds-refl<br />

e τ 1 −→ e τ 2<br />

e τ 1 −→ ∗ e τ 3<br />

e σ 2 −→ e ′σ<br />

2<br />

e σ 2 −→ app e σ⇒τ<br />

1<br />

cong-lam x σ<br />

e τ 2 −→ ∗ e τ 3 reds-trans<br />

e ′σ<br />

2<br />

cong-app1<br />

Alternatively, −→ and −→ ∗ can be thought <strong>of</strong> as def<strong>in</strong><strong>in</strong>g reductions on derivations<br />

<strong>of</strong> ⊢ τ nd. In o<strong>the</strong>r words, <strong>the</strong> judgments-as-types pr<strong>in</strong>ciple can be viewed as a<br />

generalization <strong>of</strong> <strong>the</strong> pro<strong>of</strong>s-as-programs pr<strong>in</strong>ciple <strong>of</strong> <strong>the</strong> Curry-Howard isomorphism.<br />

We view <strong>the</strong> follow<strong>in</strong>g <strong>the</strong>orem as be<strong>in</strong>g valid under ei<strong>the</strong>r <strong>in</strong>terpretation.<br />

10


Theorem 1.3.1 (Congruence <strong>of</strong> Multistep Reduction)<br />

1. If e τ −→ ∗ e ′τ <strong>the</strong>n lam x σ .e −→ ∗ lam x σ .e ′τ<br />

2. If e σ⇒τ<br />

1<br />

−→ ∗ e ′σ⇒τ<br />

1<br />

and eσ 2 −→ ∗ e ′σ<br />

2 <strong>the</strong>n (app eσ⇒τ 1<br />

e σ 2) −→ ∗ (app e σ⇒τ<br />

1<br />

Pro<strong>of</strong>: 1 is by straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> <strong>the</strong> given derivation; 2 is<br />

by straightforward simultaneous <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> <strong>the</strong> given derivations.<br />

<br />

At times, we will f<strong>in</strong>d it convenient to reason about whe<strong>the</strong>r a variable occurs<br />

freely with<strong>in</strong> a term or derivation. In general, we write <strong>the</strong> judgmental specification<br />

<strong>of</strong> such a judgment along <strong>the</strong> l<strong>in</strong>es <strong>of</strong> x τ ∈ F V (e τ ), although <strong>in</strong> practice we do not<br />

specify <strong>the</strong> <strong>in</strong>ference for such judgments for <strong>the</strong> sake <strong>of</strong> brevity.<br />

1.4 The Role <strong>of</strong> Consistency<br />

In some ways, our goals are similar <strong>in</strong> spirit to <strong>the</strong> goals <strong>of</strong> Hilbert’s program. Orig-<br />

<strong>in</strong>ally proposed by <strong>the</strong> ma<strong>the</strong>matician David Hilbert <strong>in</strong> <strong>the</strong> early 20th century,<br />

Hilbert’s program aimed to provide an axiomatic formalization <strong>of</strong> all ma<strong>the</strong>mati-<br />

cal reason<strong>in</strong>g and to justify <strong>the</strong> consistency <strong>of</strong> this axiomatization us<strong>in</strong>g only f<strong>in</strong>itary<br />

methods similar <strong>in</strong> spirit to <strong>the</strong> notion <strong>of</strong> syntactically f<strong>in</strong>itary methods outl<strong>in</strong>ed<br />

above. Informally, a logic is consistent whenever its pro<strong>of</strong> <strong>the</strong>ory is somehow nontriv-<br />

ial <strong>in</strong> a mean<strong>in</strong>gful way. Because we are <strong>in</strong>terested <strong>in</strong> formaliz<strong>in</strong>g <strong>in</strong>formal concepts,<br />

it seems prudent to consider how <strong>the</strong> notion <strong>of</strong> consistency might be made precise.<br />

Perhaps <strong>the</strong> most common way to demonstrate that a logic is consistent is to show<br />

that it is “free from contradiction”; i.e. , that <strong>the</strong>re can be no pro<strong>of</strong> <strong>of</strong> a formula<br />

such as F ∧ ¬F or z = s z. This def<strong>in</strong>ition is somewhat unsatisfy<strong>in</strong>g, because it<br />

relies on specific logical connectives that may or may not exist with<strong>in</strong> <strong>the</strong> formalism<br />

11<br />

e ′σ<br />

2 )


under consideration. However, this notion can be generalized somewhat: a logic is<br />

consistent if, and only if, <strong>the</strong>re is at least one formula that cannot be proved. This<br />

notion <strong>of</strong> absolute consistency usually follows as a corollary from a normalization<br />

<strong>the</strong>orem <strong>of</strong> some k<strong>in</strong>d, such as cut elim<strong>in</strong>ation: first it is shown that all pro<strong>of</strong>s can<br />

be normalized, <strong>the</strong>n it is shown by case analysis that <strong>the</strong>re are no normal pro<strong>of</strong>s <strong>of</strong><br />

a particular formula. Most <strong>of</strong> <strong>the</strong> time, absolute consistency captures what we mean<br />

by consistency. Unfortunately, this is not always <strong>the</strong> case.<br />

Consider <strong>the</strong> (propositional) logic whose only atomic formula is true, and whose<br />

only logical connective is implication (under <strong>the</strong> Curry-Howard <strong>in</strong>terpretation, this<br />

would be <strong>the</strong> simply-typed λ-calculus with a constant at base type). Every formula<br />

<strong>in</strong> this logic is provable, and yet <strong>the</strong> pro<strong>of</strong>s <strong>the</strong>mselves are not without mean<strong>in</strong>g;<br />

several conservative extensions <strong>of</strong> this logic are consistent <strong>in</strong> <strong>the</strong> absolute sense, and<br />

moreover, <strong>the</strong> pro<strong>of</strong> terms <strong>of</strong> this logic can be normalized. Unfortunately, nei<strong>the</strong>r <strong>of</strong><br />

<strong>the</strong>se observations br<strong>in</strong>gs us any closer to a uniform def<strong>in</strong>ition <strong>of</strong> consistency.<br />

Consider an <strong>in</strong>consistent logic, such as naive set <strong>the</strong>ory, whose syntactic category<br />

<strong>of</strong> formulas we denote (<strong>in</strong> this paragraph only) us<strong>in</strong>g F . We can def<strong>in</strong>e <strong>the</strong> formulas<br />

<strong>of</strong> a new logic by a BNF-style equation <strong>of</strong> <strong>the</strong> form G ::= F | ⊥ (where ⊥ is<br />

not a formula <strong>in</strong> F ), whose pro<strong>of</strong> rules are those <strong>of</strong> naive set <strong>the</strong>ory. Clearly, <strong>the</strong><br />

newly result<strong>in</strong>g logic is an “absolutely consistent,” conservative extension <strong>of</strong> naive<br />

set <strong>the</strong>ory. And yet we consider nei<strong>the</strong>r naive set <strong>the</strong>ory, nor this trivial conservative<br />

extension, to be consistent <strong>in</strong> any useful sense.<br />

Def<strong>in</strong><strong>in</strong>g a logic to be consistent whenever its pro<strong>of</strong> <strong>the</strong>ory admits some sort <strong>of</strong><br />

normalization <strong>the</strong>orem is similarly problematic. Consider, for example, a consistent<br />

first-order <strong>the</strong>ory, such as Heyt<strong>in</strong>g Arithmetic or <strong>the</strong> algebraic <strong>the</strong>ory <strong>of</strong> groups,<br />

whose syntactic category <strong>of</strong> formulas we denote (<strong>in</strong> this paragraph only) us<strong>in</strong>g F . If<br />

we were to add a “normal” pro<strong>of</strong> rule <strong>of</strong> <strong>the</strong> form<br />

12


⊢ F<br />

<strong>the</strong>n <strong>the</strong> result<strong>in</strong>g logic would clearly be <strong>in</strong>consistent <strong>in</strong> any reasonable sense <strong>of</strong> <strong>the</strong><br />

word. And yet, every pro<strong>of</strong> <strong>in</strong> <strong>the</strong> result<strong>in</strong>g logic can be “reduced” to a “normal”<br />

pro<strong>of</strong>; namely, <strong>the</strong> pro<strong>of</strong> that consists entirely <strong>of</strong> an application <strong>of</strong> <strong>the</strong> rule foo.<br />

foo<br />

In general, we argue that any attempt to precisely def<strong>in</strong>e logical consistency<br />

will be fraught with exceptions. Thus, we eschew a precise def<strong>in</strong>ition <strong>in</strong> favor <strong>of</strong><br />

an <strong>in</strong>formal test, orig<strong>in</strong>ally employed by Supreme Court Justice Potter Stewart to<br />

help clarify a somewhat different concept: we may not be able to precisely def<strong>in</strong>e<br />

consistency, but we know it when we see it.<br />

Although Hilbert’s program successfully spawned a great deal <strong>of</strong> pioneer<strong>in</strong>g re-<br />

search <strong>in</strong>to <strong>the</strong> foundations <strong>of</strong> ma<strong>the</strong>matics, its goals were eventually shown to be<br />

unobta<strong>in</strong>able: <strong>in</strong> 1931, Kurt Gödel published his now famous <strong>in</strong>completeness <strong>the</strong>o-<br />

rems, <strong>the</strong> second <strong>of</strong> which shows that no consistent logical formalism that is capable<br />

<strong>of</strong> express<strong>in</strong>g certa<strong>in</strong> very basic arithmetical truths can be used to prove its own con-<br />

sistency, let alone <strong>the</strong> consistency <strong>of</strong> more powerful logic. Although Gödel’s orig<strong>in</strong>al<br />

result was phrased <strong>in</strong> terms <strong>of</strong> absolute consistency, we claim that it applies to any<br />

reasonable <strong>in</strong>terpretation <strong>of</strong> <strong>the</strong> word.<br />

It follows that any consistency pro<strong>of</strong> must rely, ei<strong>the</strong>r implicitly or explicitly, on<br />

assumptions that are at least as strong as <strong>the</strong> statement be<strong>in</strong>g proven. Although<br />

this means that it is not possible to prove consistency <strong>of</strong> any <strong>in</strong>terest<strong>in</strong>g logic out-<br />

right, consistency pro<strong>of</strong>s can be usefully thought <strong>of</strong> as reduc<strong>in</strong>g one set <strong>of</strong> possibly<br />

questionable assumptions to ano<strong>the</strong>r set <strong>of</strong> more <strong>in</strong>tuitively trustworthy assumptions.<br />

13


1.5 <strong>Syntactic</strong> <strong>F<strong>in</strong>itism</strong><br />

We have argued that <strong>the</strong> syntactically f<strong>in</strong>itary reason<strong>in</strong>g pr<strong>in</strong>ciples outl<strong>in</strong>ed thus<br />

far—that is, <strong>the</strong> ability to form terms and derivations via <strong>the</strong> application <strong>of</strong> <strong>in</strong>fer-<br />

ence rules and to transform <strong>the</strong>m <strong>in</strong>to different types <strong>of</strong> objects via case analysis and<br />

<strong>in</strong>duction—characterize a reasonable lower bound on <strong>the</strong> forms <strong>of</strong> reason<strong>in</strong>g used<br />

by programm<strong>in</strong>g-languages researchers. Our goal is to better understand <strong>the</strong> foun-<br />

dational expressivity <strong>of</strong> <strong>the</strong>se pr<strong>in</strong>ciples; that is, <strong>in</strong> which situations does syntactic<br />

f<strong>in</strong>itism suffice, and <strong>in</strong> which situations is it absolutely necessary to employ more<br />

powerful forms <strong>of</strong> reason<strong>in</strong>g?<br />

Through <strong>the</strong> lens <strong>of</strong> <strong>the</strong> Curry-Howard isomorphism, any typed λ-calculus can be<br />

viewed as a logic, and thus any meta<strong>the</strong>orem about one can be viewed as an equivalent<br />

meta<strong>the</strong>orem about <strong>the</strong> o<strong>the</strong>r. Consistency pro<strong>of</strong>s can provide a sort <strong>of</strong> benchmark<br />

for <strong>the</strong> expressivity <strong>of</strong> pro<strong>of</strong>-<strong>the</strong>oretic assumptions; <strong>the</strong>refore it makes sense for us to<br />

<strong>in</strong>vestigate syntactic f<strong>in</strong>itism with regards to <strong>the</strong> k<strong>in</strong>ds <strong>of</strong> meta<strong>the</strong>orems about typed<br />

lambda calculi that, via Curry-Howard, imply consistency. Although examples <strong>of</strong><br />

such meta<strong>the</strong>orems abound, <strong>the</strong> most obvious are normalization <strong>the</strong>orems. One <strong>of</strong><br />

<strong>the</strong> most widely used class <strong>of</strong> ma<strong>the</strong>matical structures for prov<strong>in</strong>g normalization<br />

<strong>the</strong>orems, and consistency meta-<strong>the</strong>orems <strong>in</strong> general, is <strong>the</strong> class <strong>of</strong> logical relations.<br />

Logical relations are usually def<strong>in</strong>ed as an <strong>in</strong>f<strong>in</strong>ite family <strong>of</strong> <strong>in</strong>f<strong>in</strong>ite sets, and thus<br />

would appear to be <strong>in</strong>compatible with syntactic f<strong>in</strong>itism; however, <strong>in</strong> Chapter 2, we<br />

will give a f<strong>in</strong>itary characterization <strong>of</strong> logical relations that we refer to as structural<br />

logical relations.<br />

It should be noted that <strong>the</strong> existence <strong>of</strong> structural logical relations does not mean<br />

that syntactic f<strong>in</strong>itism can always be used to prove consistency outright; ra<strong>the</strong>r,<br />

structural logical relations are syntactically f<strong>in</strong>itary reductions from one consistency<br />

14


<strong>the</strong>orem to ano<strong>the</strong>r <strong>in</strong> much <strong>the</strong> same way that Karp reductions are polynomial-time<br />

reductions from <strong>the</strong> computational complexity <strong>of</strong> one class <strong>of</strong> decision problems to<br />

ano<strong>the</strong>r. However, <strong>the</strong> question still rema<strong>in</strong>s as to when syntactic f<strong>in</strong>itism can be<br />

used to prove consistency outright. Just as f<strong>in</strong>itism is sometimes considered to be<br />

formalized by <strong>the</strong> first-order <strong>the</strong>ory PA1 (i.e. Peano arithmetic where <strong>the</strong> pr<strong>in</strong>ciple <strong>of</strong><br />

<strong>in</strong>duction is restricted to Σ1-formulas), <strong>in</strong> Chapter 3, we will argue that syntactically<br />

f<strong>in</strong>itary pro<strong>of</strong>s can, <strong>in</strong> pr<strong>in</strong>ciple, be formalized <strong>in</strong> PA2 (i.e. Peano arithmetic where<br />

<strong>the</strong> pr<strong>in</strong>ciple <strong>of</strong> <strong>in</strong>duction is restricted to Σ2-formulas, or, equivalently, PA1 extended<br />

with a notion <strong>of</strong> transf<strong>in</strong>ite <strong>in</strong>duction up to ω ω ). Thus, us<strong>in</strong>g some <strong>of</strong> <strong>the</strong> ideas and<br />

results from pro<strong>of</strong> <strong>the</strong>ory, which will also be discussed <strong>in</strong> Chapter 3, syntactic f<strong>in</strong>itism<br />

can be associated with <strong>the</strong> pro<strong>of</strong>-<strong>the</strong>oretic ord<strong>in</strong>al ωωω .<br />

In Chapter 4, we will <strong>in</strong>vestigate <strong>the</strong> impact <strong>of</strong> extend<strong>in</strong>g our notion <strong>of</strong> syntactic<br />

f<strong>in</strong>itism from <strong>in</strong>duction on order<strong>in</strong>gs built up from subterm order<strong>in</strong>gs to <strong>in</strong>duction on<br />

those same order<strong>in</strong>gs built up from <strong>the</strong> much stronger lexicographic path order<strong>in</strong>g <strong>of</strong><br />

term rewrit<strong>in</strong>g fame. We will see that us<strong>in</strong>g <strong>the</strong> lexicographic path order<strong>in</strong>g <strong>in</strong> this<br />

context allows us to prove much more powerful <strong>the</strong>orems than would be possible <strong>in</strong><br />

<strong>the</strong> context <strong>of</strong> term rewrit<strong>in</strong>g.<br />

F<strong>in</strong>ally, we are also <strong>in</strong>terested <strong>in</strong> formaliz<strong>in</strong>g <strong>the</strong> notion <strong>of</strong> syntactic f<strong>in</strong>itism us<strong>in</strong>g<br />

methods that are more <strong>in</strong> <strong>the</strong> spirit <strong>of</strong> syntactic f<strong>in</strong>itism than PA2. We regard LF<br />

[HHP87] as provid<strong>in</strong>g a uniform means to express judgments, and <strong>the</strong> pro<strong>of</strong>s-as-<br />

logic-programs paradigm popularized by <strong>the</strong> pro<strong>of</strong> assistant Twelf [PS99] as a more<br />

syntactic formalization <strong>of</strong> syntactic f<strong>in</strong>itism than PA2. In Chapter 5, we will attempt<br />

to justify this paradigm as a valid <strong>in</strong>terpretation <strong>of</strong> syntactic f<strong>in</strong>itism, and present a<br />

syntactically f<strong>in</strong>itary specification for <strong>the</strong> semantics <strong>of</strong> logic programm<strong>in</strong>g; we <strong>the</strong>n<br />

prove, us<strong>in</strong>g syntactically f<strong>in</strong>itary methods extended by a pr<strong>in</strong>ciple <strong>of</strong> well-founded<br />

<strong>in</strong>duction, <strong>the</strong> soundness <strong>of</strong> a modular, judgmentally-specified mode/term<strong>in</strong>ation-<br />

15


analysis that is central to <strong>the</strong> <strong>in</strong>terpretation <strong>of</strong> logic programs as syntactically f<strong>in</strong>itary<br />

pro<strong>of</strong>s.<br />

In Chapter 6 we conclude by discuss<strong>in</strong>g related and future work. All <strong>of</strong> <strong>the</strong> <strong>the</strong>o-<br />

rems <strong>in</strong> Chapter 2 have been formalized <strong>in</strong> Twelf (see http://www.twelf.org/slr),<br />

and all <strong>of</strong> <strong>the</strong> <strong>the</strong>orems <strong>in</strong> Chapter 4 have been formalized <strong>in</strong> a prototypical extension<br />

<strong>of</strong> Twelf (see http://www.twelf.org/lpo).<br />

16


Chapter 2<br />

Structural Logical Relations<br />

A pro<strong>of</strong> by logical relations (also sometimes referred to as Tait’s method) relies on an<br />

<strong>in</strong>terpretation <strong>of</strong> types as relations between objects. On paper, <strong>the</strong>se <strong>in</strong>terpretations<br />

are usually formulated <strong>in</strong> set <strong>the</strong>ory. Consider <strong>the</strong> simply typed λ-calculus, as def<strong>in</strong>ed<br />

<strong>in</strong> Section 1.3. Given some property <strong>of</strong> expressions that we wish to reason about (e.g.<br />

reducibility to a normal form), a unary logical relation [τ ] would be def<strong>in</strong>ed as <strong>the</strong><br />

smallest set satisfy<strong>in</strong>g <strong>the</strong> follow<strong>in</strong>g conditions.<br />

e o ∈ [o] iff e o has <strong>the</strong> desired property<br />

e σ⇒τ ∈ [σ ⇒ τ ] iff for all e σ 2, if e2 ∈ [σ ] <strong>the</strong>n app e σ⇒τ e σ 2 ∈ [τ ]<br />

The hallmark characteristic <strong>of</strong> a logical relation is <strong>the</strong> def<strong>in</strong>ition at function types:<br />

functions are <strong>in</strong> <strong>the</strong> relation if <strong>the</strong>y map related arguments to related results. A<br />

pro<strong>of</strong> by logical relations typically proceeds <strong>in</strong> two stages: first, it is shown, usually<br />

by <strong>in</strong>duction on τ, that e τ ∈ [τ ] implies e τ has <strong>the</strong> desired property (we refer to this<br />

as <strong>the</strong> Escape Lemma); <strong>the</strong>n it is shown, usually by <strong>in</strong>duction on e τ that, for every<br />

e <strong>of</strong> type τ, e ∈ [τ ] (this is <strong>of</strong>ten referred to as <strong>the</strong> Fundamental Theorem or Basic<br />

Lemma). The desired <strong>the</strong>orem is <strong>the</strong>n a direct consequence <strong>of</strong> modus ponens.<br />

17


Tak<strong>in</strong>g a step back, we notice that <strong>the</strong> set-<strong>the</strong>oretic characterization <strong>of</strong> logical<br />

relation relies on <strong>the</strong> follow<strong>in</strong>g concepts: structural <strong>in</strong>duction on τ and e τ , <strong>the</strong> ability<br />

to express a desired property about λ-calculus terms, and connectives “for all” and<br />

“if ... <strong>the</strong>n.” Logical relations are typically formulated with <strong>the</strong> understand<strong>in</strong>g that<br />

<strong>the</strong>se concepts all live on <strong>the</strong> same level. The idea <strong>of</strong> structural logical relations [SS08]<br />

is to separate <strong>the</strong>se concepts <strong>in</strong> such a way that we only need to employ syntactically<br />

f<strong>in</strong>itary reason<strong>in</strong>g: <strong>in</strong>duction and case analysis on types and terms takes place on <strong>the</strong><br />

meta-level (as usual), whereas logical connectives and properties about λ-calculus<br />

terms will be represented by an assertion logic, whose formulas and pro<strong>of</strong> <strong>the</strong>ory can<br />

be described syntactically.<br />

A paper pro<strong>of</strong> <strong>of</strong> weak normalization for <strong>the</strong> simply typed λ-calculus us<strong>in</strong>g a<br />

conventional, set-<strong>the</strong>oretic notion <strong>of</strong> logical relation can be found <strong>in</strong> [Pfe92]. A<br />

pro<strong>of</strong> us<strong>in</strong>g structural logical relations for <strong>the</strong> same property is described <strong>in</strong> [SS08].<br />

We recount this pro<strong>of</strong> and extended it to Gödel’s T here.<br />

The overall structure <strong>of</strong> a pro<strong>of</strong> by structural logical relations is much like its more<br />

conventional set-<strong>the</strong>oretic counterpart: <strong>the</strong> Escape Lemma is proved by <strong>in</strong>duction<br />

on types, and <strong>the</strong> Fundamental Theorem is proved by <strong>in</strong>duction on terms (although,<br />

unlike conventionally def<strong>in</strong>ed logical relations, prov<strong>in</strong>g <strong>the</strong> Fundamental Theorem for<br />

a structural logical relation does not require def<strong>in</strong><strong>in</strong>g or reason<strong>in</strong>g about simultaneous<br />

substitutions). However, structural logical relations require prov<strong>in</strong>g one <strong>the</strong>orem,<br />

which we refer to as Extraction, that demonstrates <strong>the</strong> consistency <strong>of</strong> <strong>the</strong> assertion<br />

logic; although conventional pro<strong>of</strong>s us<strong>in</strong>g logical relations do not require an explicit<br />

pro<strong>of</strong> <strong>of</strong> <strong>the</strong> Extraction Theorem, we argue that this is because <strong>the</strong> act <strong>of</strong> def<strong>in</strong><strong>in</strong>g<br />

a conventional logical relation requires such a consistency <strong>the</strong>orem to be implicitly<br />

assumed.<br />

18


2.1 Normalization <strong>of</strong> <strong>the</strong> Simply Typed λ-calculus<br />

We are <strong>in</strong>terested <strong>in</strong> prov<strong>in</strong>g weak normalization for <strong>the</strong> notion <strong>of</strong> βη conversion<br />

def<strong>in</strong>ed <strong>in</strong> 1.3. We def<strong>in</strong>e two judgments for canonical and atomic forms <strong>of</strong> well-<br />

typed terms e τ , written judgmentally as e τ ⇑ and e τ ⇓.<br />

e o ⇓ can-o<br />

e o ⇑<br />

u<br />

x σ ⇓<br />

.<br />

e τ ⇑<br />

can-arr x,u<br />

lam x σ . e τ ⇑<br />

e σ⇒τ<br />

1 ⇓ e σ 2 ⇑<br />

atm app<br />

app e σ⇒τ<br />

1 e σ 2 ⇓<br />

Informally, canonical forms are normal <strong>in</strong> <strong>the</strong> sense that <strong>the</strong>y are β-short and η-long,<br />

whereas atomic terms are variables applied to some number <strong>of</strong> canonical terms. It<br />

should be noted that, although any term <strong>of</strong> <strong>the</strong> form e σ⇒τ , can always η-expanded to<br />

(lam x σ .app e σ⇒τ x σ ), if e σ⇒τ is canonical <strong>the</strong>n (lam x σ .app e σ⇒τ x σ ) will β-reduce<br />

back to e σ⇒τ . Thus, although canonical terms can always be reduced, <strong>the</strong>y can never<br />

be reduced <strong>in</strong> an <strong>in</strong>terest<strong>in</strong>g way.<br />

We aim to prove a <strong>the</strong>orem <strong>of</strong> <strong>the</strong> form “for all e τ , e τ reduces to a canonical<br />

term.” Although it is straightforward express <strong>the</strong> property “e τ reduces to a canon-<br />

ical term” syntactically (i.e. by def<strong>in</strong><strong>in</strong>g a judgment whose sole <strong>in</strong>ference rule has<br />

premisses <strong>of</strong> <strong>the</strong> form e τ −→ ∗ e ′τ and e ′τ ⇑), this alone is not enough to capture<br />

<strong>the</strong> potentially-nested logical connectives used to def<strong>in</strong>e a logical relation. Thus, we<br />

def<strong>in</strong>e an assertion logic that is expressive enough to describe both <strong>the</strong> logical connec-<br />

tives and, us<strong>in</strong>g atomic formulas, <strong>the</strong> property “can be converted to canonical form.”<br />

19


The formulas <strong>of</strong> <strong>the</strong> assertion logic for our example are def<strong>in</strong>ed by <strong>the</strong> follow<strong>in</strong>g.<br />

Formulas F, G ::= hc τ (e τ ) | ha τ (e τ ) | wh τ (e τ 1 , eτ 2 ) | F ⊃ G | ∀xτ .F<br />

Predicates P, Q ::= F | (x τ .P )<br />

Informally, we th<strong>in</strong>k <strong>of</strong> hc τ (e τ ) as mean<strong>in</strong>g “e τ ” has a normal form, ha τ (e τ )<br />

as mean<strong>in</strong>g “e τ has an atomic form” and wh τ (e τ 1, e τ 2) as mean<strong>in</strong>g “e τ 1 weak head<br />

reduces to e τ 2”; <strong>the</strong> logical connectives are <strong>in</strong>tuitionistic. In general, we will omit<br />

type superscripts from expressions and formulas when <strong>the</strong>y can easily be <strong>in</strong>ferred<br />

from <strong>the</strong> context, or when <strong>the</strong>y are irrelevent (e.g. hc τ (app e1 e2) or hc(app e σ⇒τ<br />

1<br />

<strong>in</strong>stead <strong>of</strong> hc τ ((app e σ⇒τ<br />

1 e σ 2) τ )). A predicate is a formula with some number <strong>of</strong><br />

dist<strong>in</strong>guished bound variables that can be thought <strong>of</strong> as place-holders for arbitrary<br />

λ-calculus terms; if P is <strong>of</strong> <strong>the</strong> form x τ .P ′ , <strong>the</strong>n we write P (e τ ) to mean P ′ [e τ /x τ ].<br />

We formalize <strong>the</strong> notion <strong>of</strong> provability us<strong>in</strong>g sequents <strong>of</strong> <strong>the</strong> form Ψ ⊢ F , where<br />

Ψ is <strong>the</strong> notion <strong>of</strong> context def<strong>in</strong>ed below. We depart slightly from convention by<br />

us<strong>in</strong>g Ψ to keep track <strong>of</strong> not only which logical hypo<strong>the</strong>ses may be used freely <strong>in</strong> <strong>the</strong><br />

deduction <strong>of</strong> a sequent, but also which free λ-calculus variables may be used <strong>in</strong> <strong>the</strong><br />

deduction as well. Some <strong>of</strong> <strong>the</strong>se variables are meant to represent arbitrary λ-calculus<br />

terms (i.e. <strong>the</strong>y are eigenvariables), and some are meant to represent arbitrary λ-<br />

calculus variables (e.g. <strong>the</strong>y can be assumed to be atomic). We dist<strong>in</strong>guish <strong>the</strong> latter<br />

from <strong>the</strong> former by add<strong>in</strong>g a flag, vxτ , to <strong>the</strong> context. We also depart slightly from<br />

convention by attach<strong>in</strong>g names to <strong>the</strong> logical hypo<strong>the</strong>ses <strong>in</strong> Ψ. Although do<strong>in</strong>g so is<br />

not useful <strong>in</strong> present<strong>in</strong>g <strong>the</strong> pro<strong>of</strong> rules, it simplifies <strong>the</strong> presentation <strong>of</strong> pro<strong>of</strong> terms<br />

(i.e. <strong>the</strong> pro<strong>of</strong> rules <strong>in</strong> BNF-style notation), which will be useful <strong>in</strong> Chapter 4. To<br />

this end, we assume <strong>the</strong> existence <strong>of</strong> a (dependent) syntactic category <strong>of</strong> hypo<strong>the</strong>ses,<br />

whose only elements are hypo<strong>the</strong>tical variables that we denote generically by h F .<br />

Contexts Ψ ::= · | Ψ, h F | Ψ, x τ | v xτ<br />

20<br />

e σ 2)


In order for Ψ to be well formed, we require that each variable x τ or h F occurs <strong>in</strong><br />

Ψ at most once; this condition can typically be satisfied by tacitly renam<strong>in</strong>g bound<br />

variables. We sometimes abuse notation by writ<strong>in</strong>g Ψ, Ψ ′ for <strong>the</strong> concatenation <strong>of</strong><br />

two contexts. We write Ψ ⊇ Ψ ′ if Ψ can be obta<strong>in</strong>ed from Ψ ′ by delet<strong>in</strong>g some<br />

number <strong>of</strong> declarations (we omit <strong>the</strong> <strong>in</strong>ference rules for ⊇ for <strong>the</strong> sake <strong>of</strong> brevity).<br />

Our rules are formulated <strong>in</strong> <strong>the</strong> style <strong>of</strong> Pfenn<strong>in</strong>g [Pfe95], itself similar to G3i <strong>of</strong><br />

[TS00]; <strong>the</strong> exact formulation <strong>of</strong> rules is immaterial to <strong>the</strong> applicability <strong>of</strong> our tech-<br />

nique, although we feel that this presentation corresponds to an especially natural<br />

notion <strong>of</strong> pro<strong>of</strong> term. We depart slightly from convention by denot<strong>in</strong>g <strong>the</strong> occurrence<br />

<strong>of</strong> F <strong>in</strong> Ψ us<strong>in</strong>g <strong>the</strong> premiss h F ∈ Ψ (which can be expressed us<strong>in</strong>g <strong>in</strong>ference rules <strong>in</strong><br />

<strong>the</strong> obvious way), ra<strong>the</strong>r than writ<strong>in</strong>g Ψ as Ψ ′ , h F , Ψ ′′ ; we feel that this presentation<br />

makes <strong>the</strong> pro<strong>of</strong> rules easier to read. The pro<strong>of</strong> rules for <strong>the</strong> assertion logic are writ-<br />

ten below.<br />

Ψ ⊢ ha τ2⇒τ1 (e1) Ψ ⊢ hc τ2 (e2) ha-app<br />

Ψ ⊢ ha τ1 (app e1 e2)<br />

Ψ ⊢ wh o (e, e ′ ) Ψ ⊢ hc o (e ′ ) hc-wh<br />

Ψ ⊢ hc o (e)<br />

Ψ ⊢ wh τ (app (lam x. e1) e2, e1[e2/x])<br />

Ψ, x τ , v xτ<br />

Ψ, h F ⊢ G impr<br />

Ψ ⊢ F ⊃ G<br />

Ψ ⊢ ∀x τ .F<br />

⊢ F allr<br />

Ψ, x σ , v xσ<br />

Ψ ⊢ ha o (e) hc-atm<br />

Ψ ⊢ hc o (e)<br />

wh-beta<br />

⊢ hc τ (app e x) hc-arr<br />

Ψ ⊢ hc σ⇒τ (e)<br />

x τ ∈ Ψ v xτ<br />

∈ Ψ ha-var<br />

Ψ ⊢ ha τ (x τ )<br />

Ψ ⊢ wh τ2⇒τ1 (e1, e ′ 1)<br />

Ψ ⊢ wh τ1 (app e1 e2, app e ′ 1 e2)<br />

Ψ ⊢ F1 Ψ, h F 2 ⊢ G h ′F1⊃F2 ∈ Ψ impl<br />

Ψ ⊢ G<br />

Ψ, h F [eτ /x τ ] ⊢ G h ′∀x τ .F ∈ Ψ alll<br />

Ψ ⊢ G<br />

h F ∈ Ψ axiom<br />

Ψ ⊢ F<br />

wh-app<br />

We consider <strong>the</strong> rules hc-arr, impr, impl, allr and alll to be b<strong>in</strong>ders for <strong>the</strong> variables<br />

<strong>in</strong>troduced <strong>in</strong> <strong>the</strong> contexts <strong>of</strong> <strong>the</strong>ir subderivations. The <strong>in</strong>formal description <strong>of</strong> <strong>the</strong><br />

mean<strong>in</strong>gs <strong>of</strong> <strong>the</strong> atomic formulas is justified by Lemma 2.1.2.<br />

21


Several <strong>of</strong> <strong>the</strong> pro<strong>of</strong>s <strong>in</strong> this section are by <strong>in</strong>duction over terms and derivations<br />

that can potentially conta<strong>in</strong> free variables. Sometimes, especially when we are <strong>in</strong>-<br />

duct<strong>in</strong>g over multiple different syntactic categories, we will need to be able to express<br />

<strong>the</strong> relationship between <strong>the</strong> free variables <strong>of</strong> different syntactic categories. For ex-<br />

ample, <strong>the</strong> below def<strong>in</strong>ition <strong>of</strong> variable contexts and compatible derivations <strong>of</strong> e τ ⇑<br />

will be useful <strong>in</strong> <strong>the</strong> pro<strong>of</strong> <strong>of</strong> Lemma 2.1.2.<br />

Def<strong>in</strong>ition 2.1.1 (Variable Contexts, Compatible Canonicity Derivations)<br />

We say that Ψ is a variable context iff <strong>the</strong> follow<strong>in</strong>g judgment is <strong>in</strong>habited.<br />

· varctx<br />

Ψ varctx<br />

Ψ, x τ , v xτ<br />

varctx<br />

We say that a derivation <strong>of</strong> <strong>the</strong> form D : (e τ ⇑) or D : (e τ ⇓) is compatible with a<br />

context Ψ iff for every free <strong>in</strong>ference-rule variable u xτ ⇓ <strong>in</strong> D, x τ ∈ Ψ and v x τ<br />

∈ Ψ.<br />

The notion <strong>of</strong> compatible canonicity derivation can easily be formulated judgmentally;<br />

we omit this def<strong>in</strong>ition for <strong>the</strong> sake <strong>of</strong> brevity.<br />

Lemma 2.1.2 (Extraction on Cut-Free Pro<strong>of</strong>s) For all Ψ, if Ψ is a variable<br />

context <strong>the</strong>n:<br />

1. for all D : (Ψ ⊢ hc τ (e)) <strong>the</strong>re exists e such that e −→ ∗ e ′ and E : (e ′ ⇑) and E<br />

is compatible with Ψ<br />

2. for all D : (Ψ ⊢ ha τ (e)) <strong>the</strong>re exists e such that e −→ ∗ e ′ and E : (e ′ ⇓) and E<br />

is compatible with Ψ<br />

3. for all D : (Ψ ⊢ wh τ (e1, e2)) <strong>the</strong>re exists E : (e1 −→ e2) and E is compatible<br />

with Ψ<br />

Pro<strong>of</strong>: By mutual <strong>in</strong>duction on D <strong>in</strong> each case, us<strong>in</strong>g Theorem 1.3.1. <br />

22


For practical reasons we will work with <strong>the</strong> assertion logic with cut. The judgment<br />

Ψ ⊢ cut<br />

F is def<strong>in</strong>ed by <strong>in</strong>ference rules similar to <strong>the</strong> ones above except with ⊢ cut<br />

<strong>in</strong>stead<br />

<strong>of</strong> ⊢, plus one additional rule.<br />

Ψ ⊢ cut<br />

F Ψ, h F ⊢ cut<br />

G<br />

cut<br />

Ψ ⊢ cut<br />

G<br />

The rules for def<strong>in</strong><strong>in</strong>g <strong>the</strong> atomic formulas P vary for each structural logical relation.<br />

We show later <strong>in</strong> <strong>the</strong> paper that <strong>the</strong> choice <strong>of</strong> <strong>in</strong>ference rules cannot be arbitrary:<br />

<strong>the</strong>y must preserve some form <strong>of</strong> cut-elim<strong>in</strong>ation property <strong>of</strong> <strong>the</strong> sequent-calculus <strong>in</strong><br />

order to apply Lemma 2.1.2 <strong>in</strong> <strong>the</strong> pro<strong>of</strong> <strong>of</strong> Extraction.<br />

Return<strong>in</strong>g to <strong>the</strong> def<strong>in</strong>ition <strong>of</strong> structural logical relations, we can now def<strong>in</strong>e <strong>the</strong><br />

logical relation judgmentally, <strong>in</strong> terms <strong>of</strong> a (unary) logical predicate.<br />

[o] = (x o .hc(x o ))<br />

[σ ] = Pσ [τ ] = Pτ<br />

[(σ ⇒ τ)] = (x σ⇒τ .∀y σ .Pσ(y σ ) ⊃ Pτ(app x σ⇒τ y σ ))<br />

We are justified <strong>in</strong> treat<strong>in</strong>g [τ ] = P as a function by <strong>the</strong> follow<strong>in</strong>g lemma.<br />

Lemma 2.1.3 (Existence, Uniqueness <strong>of</strong> Logical Relation Predicate)<br />

1. For every τ, <strong>the</strong>re exists a predicate x τ .F such that [τ ] = x τ .F<br />

2. If [τ ] = P and [τ ] = P ′ <strong>the</strong>n P = P ′<br />

Pro<strong>of</strong>: Each case is by a straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> τ. <br />

Thus, e τ ∈ [τ ] and [τ ]e τ can both be viewed as shorthand for <strong>the</strong> formula F [e τ /x τ ]<br />

where [τ ] = x τ .F .<br />

Our structural logical relations argument is structured as follows.<br />

1. For all τ, ⊢ cut<br />

[τ ](e τ ) ⊃ hc(e τ ). (Escape Lemma)<br />

23


2. For all eτ <strong>the</strong>re exists D : (· ⊢ cut<br />

[τ ](eτ )). (Fundamental Theorem)<br />

3. If ⊢ cut<br />

hc(e τ ) <strong>the</strong>n <strong>the</strong>re exists e ′τ<br />

such that e τ −→ ∗ e ′τ and e ′τ ⇑. (Extraction)<br />

Note <strong>the</strong> dist<strong>in</strong>ction between <strong>the</strong> statement <strong>of</strong> 3 and Lemma 2.1.2; <strong>in</strong> order to bridge<br />

<strong>the</strong> gap between <strong>the</strong> two, we will need to prove some sort <strong>of</strong> cut-elim<strong>in</strong>ation result.<br />

Lemma 2.1.4 (Escape)<br />

1. For all contexts Ψ and types τ, <strong>the</strong>re exists D : Ψ ⊢ cut<br />

2. For all contexts Ψ and types τ, <strong>the</strong>re D : Ψ ⊢ cut<br />

Pro<strong>of</strong>: By mutual <strong>in</strong>duction on τ.<br />

∀x τ .[τ ](x τ ) ⊃ hc(x τ )<br />

∀x τ .ha(x τ ) ⊃ [τ ](x τ )<br />

Case: τ = o. Direct, by reason<strong>in</strong>g us<strong>in</strong>g <strong>the</strong> def<strong>in</strong>ition <strong>of</strong> [τ ] and rules allr, impr and<br />

axiom <strong>in</strong> 1, and <strong>the</strong> same rules plus ha-var and hc-atm.<br />

Case: τ = τ2 ⇒ τ1. By <strong>in</strong>duction hypo<strong>the</strong>sis, we can obta<strong>in</strong> derivations <strong>of</strong> <strong>the</strong> follow-<br />

<strong>in</strong>g sequents.<br />

Ψ ⊢ cut<br />

Ψ ⊢ cut<br />

Ψ ⊢ cut<br />

Ψ ⊢ cut<br />

∀x τ1 . [τ1 ](x τ1 ) ⊃ hc(x τ1 ) (2.1)<br />

∀x τ1 . ha(x τ1 ) ⊃ [τ1 ](x τ1 ) (2.2)<br />

∀x τ2 . [τ2 ](x τ2 ) ⊃ hc(x τ2 ) (2.3)<br />

∀x τ2 . ha(x τ2 ) ⊃ [τ2 ](x τ2 ) (2.4)<br />

1. Follows by <strong>in</strong>duction hypo<strong>the</strong>ses (2.1) and (2.4), us<strong>in</strong>g <strong>the</strong> def<strong>in</strong>ition <strong>of</strong> [τ ] and<br />

rules allr, impr, alll, impl, cut, and hc-arr.<br />

2. Follows by <strong>in</strong>duction hypo<strong>the</strong>ses (2.2) and (2.3), us<strong>in</strong>g rules allR, impR, allL,<br />

cut, and ha-app.<br />

24


The follow<strong>in</strong>g lemma will be needed to prove <strong>the</strong> Fundamental Theorem.<br />

Lemma 2.1.5 (Closure Under Weak Head Expansion) For all contexts Ψ and<br />

for all types τ, <strong>the</strong>re exists D : Ψ ⊢ cut<br />

Pro<strong>of</strong>: By <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> τ.<br />

∀x τ . ∀y τ . wh(x τ , y τ ) ⊃ [τ ](y τ ) ⊃ [τ ](x τ )<br />

Case: τ = o. Direct, by <strong>the</strong> def<strong>in</strong>ition <strong>of</strong> [τ ] and rules allr, impr, axiom, and hc-wh.<br />

Case: τ = τ2 ⇒ τ1. By <strong>in</strong>duction hypo<strong>the</strong>sis, we can obta<strong>in</strong> a derivation <strong>of</strong><br />

Ψ ⊢ cut<br />

∀x τ1 . ∀e ′τ1 . wh τ1 (e, e ′ ) ⊃ [τ1 ](e ′ ) ⊃ [τ1 ](e)<br />

The claim follows from <strong>the</strong> def<strong>in</strong>ition <strong>of</strong> [τ ] and rules allr, impr, alll, impl, cut,<br />

and wh-app.<br />

The statement <strong>of</strong> <strong>the</strong> Fundamental Theorem does not rely on lift<strong>in</strong>g <strong>the</strong> notion <strong>of</strong><br />

logical relations to simultaneous substitutions, but it does rely on lift<strong>in</strong>g <strong>the</strong> notion <strong>of</strong><br />

logical relation to contexts, which plays a similar role <strong>in</strong> <strong>the</strong> pro<strong>of</strong> <strong>of</strong> <strong>the</strong> fundamental<br />

<strong>the</strong>orem as <strong>the</strong> notion <strong>of</strong> variable context played <strong>in</strong> <strong>the</strong> pro<strong>of</strong> <strong>of</strong> Lemma 2.1.2.<br />

Def<strong>in</strong>ition 2.1.6 (Contexts <strong>in</strong> <strong>the</strong> LR, Compatible λ-Calculus Terms) We say<br />

that Ψ is <strong>in</strong> <strong>the</strong> logical relation iff <strong>the</strong> follow<strong>in</strong>g judgment is <strong>in</strong>habited.<br />

· <strong>in</strong>LR<br />

Ψ <strong>in</strong>LR [τ ] = P<br />

(Ψ, x τ , h P (xτ ) ) <strong>in</strong>LR<br />

We say that an expression e τ is compatible with Ψ iff all <strong>of</strong> <strong>the</strong> free variables <strong>in</strong> e τ<br />

are declared <strong>in</strong> Ψ. This notion <strong>of</strong> compatible expression can be def<strong>in</strong>ed judgmentally,<br />

although we omit its def<strong>in</strong>ition for <strong>the</strong> sake <strong>of</strong> brevity.<br />

25


Theorem 2.1.7 (Fundamental) For every e τ and for every Ψ, if Ψ is <strong>in</strong> <strong>the</strong> logical<br />

relation and eτ is compatible with Ψ <strong>the</strong>n [τ ] = P and Ψ ⊢ cut<br />

P (eτ )<br />

Pro<strong>of</strong>:<br />

Case: x τ<br />

Ψ <strong>in</strong>LR and x τ is compatible with Ψ given<br />

x τ ∈ Ψ by def <strong>of</strong> compatibility<br />

h P (xτ ) ∈ Ψ and [τ ] = P<br />

Case: lam x σ .e τ<br />

by a straightforward <strong>in</strong>duction on Ψ <strong>in</strong>LR us<strong>in</strong>g x τ ∈ Ψ<br />

Ψ <strong>in</strong>LR and e τ is compatible with Ψ given<br />

[σ ] = Pσ<br />

by Lemma 2.1.3<br />

(Ψ, x σ , h Pσ(xσ ) ) <strong>in</strong>LR by rule<br />

e τ is compatible with Ψ, x σ , h Pσ(xσ ) by def <strong>of</strong> compatibility<br />

Ψ, x σ , Pσ(x σ ) ⊢ cut<br />

Pτ(e τ ) and [τ ] = Pτ<br />

by IH<br />

Ψ, xσ , Pσ(xσ ) ⊢ cut<br />

wh(app (lamxσ .eτ ) xσ , eτ ) by rule wh-beta<br />

Ψ, xσ , Pσ(xσ ) ⊢ cut<br />

∀yτ . ∀y ′τ . wh(yτ , y ′τ ) ⊃ Pτ(y ′τ ) ⊃ Pτ(y τ ) by Lemma 2.1.5<br />

Ψ ⊢ cut<br />

∀y σ .Pσ(y σ ) ⊃ Pτ(app (lam x σ .e τ ) y σ )<br />

[τ ](lamx σ .e τ ) = ∀y σ .Pσ(y σ ) ⊃ Pτ(app (lam x σ .e τ ) y σ )<br />

Case: app e σ⇒τ<br />

1<br />

e σ 2<br />

by rules allr, impr, cut, alll impl and axiom<br />

and <strong>the</strong> renamability <strong>of</strong> bound variables<br />

Ψ <strong>in</strong>LR and app e σ⇒τ<br />

1 e σ 2 is compatible with Ψ given<br />

26


Ψ ⊢ P1(e σ⇒τ<br />

1 ) and [σ ⇒ τ ] = P1 by IH on e1<br />

P1 = (x σ⇒τ .∀y σ .Pσ(y σ ) ⊃ Pτ(app x σ⇒τ y σ ))<br />

and [σ ] = Pσ and [τ ] = Pτ<br />

Ψ ⊢ P2(e σ 2) and [σ ] = Pσ<br />

P2 = Pσ<br />

by <strong>in</strong>version on [σ ⇒ τ ]<br />

by IH on e2<br />

by Lemma 2.1.3<br />

Ψ ⊢ Pτ(app e σ⇒τ<br />

1 e σ 2) by rules cut, foralll, impl and axiom<br />

Thus far, we have shown that for any well-typed e τ , we can produce a derivation <strong>of</strong><br />

· ⊢ cut<br />

hc(eτ ) by apply<strong>in</strong>g <strong>the</strong> Fundamental Theorem, followed by <strong>the</strong> Escape Lemma,<br />

followed by applications <strong>of</strong> <strong>the</strong> rules cut, foralll, and impl. However, we are not yet<br />

done: Lemma 2.1.2 requires <strong>the</strong> pro<strong>of</strong> <strong>of</strong> hc τ (e) to be cut-free; that is, <strong>the</strong> assertion<br />

logic must be consistent. If we were will<strong>in</strong>g to accept <strong>the</strong> consistency <strong>of</strong> <strong>the</strong> assertion<br />

logic a priori, <strong>the</strong>n we would be done. However, <strong>in</strong> this example, no additional<br />

assumptions are necessary: we are able to prove cut elim<strong>in</strong>ation directly, us<strong>in</strong>g <strong>the</strong><br />

syntactically f<strong>in</strong>itary procedure outl<strong>in</strong>ed <strong>in</strong> [Pfe95]. First, we prove that cut is an<br />

admissible rule <strong>in</strong> <strong>the</strong> cut-free sequent calculus, <strong>the</strong>n use this admissibility lemma to<br />

prove full cut elim<strong>in</strong>ation.<br />

It should be noted that, <strong>in</strong> <strong>the</strong> pro<strong>of</strong> <strong>the</strong> follow<strong>in</strong>g Lemma 2.1.8, we consider a<br />

formula <strong>of</strong> <strong>the</strong> form F [e τ /x τ ] to be a subterm <strong>of</strong> ∀x τ .F , despite <strong>the</strong> fact that e τ<br />

may <strong>in</strong> fact be considerably larger than x τ . We justify this heret<strong>of</strong>ore undiscussed<br />

property <strong>of</strong> <strong>the</strong> subterm order<strong>in</strong>g by not<strong>in</strong>g that, although λ-calculus terms may<br />

occur <strong>in</strong>side <strong>of</strong> formulas, <strong>the</strong> reverse does not hold, and thus λ-calculus terms cannot<br />

mean<strong>in</strong>gfully impact <strong>the</strong> structure <strong>of</strong> a formula. In general, we only consider <strong>the</strong><br />

terms from one syntactic category to be taken <strong>in</strong>to consideration when consider<strong>in</strong>g<br />

<strong>the</strong> size <strong>of</strong> terms from ano<strong>the</strong>r syntactic category when <strong>the</strong> two syntactic categories<br />

27


are mutually-recursive. This assumption is made more ma<strong>the</strong>matically precise <strong>in</strong><br />

Example 5.2.42.<br />

Lemma 2.1.8 (Cut Admissibility) If D : (Ψ ⊢ F ) and E : (Ψ, h F ⊢ G) <strong>the</strong>n<br />

Ψ ⊢ G<br />

Pro<strong>of</strong>: By <strong>in</strong>duction on <strong>the</strong> lexicographic order<strong>in</strong>g <strong>of</strong> F , followed by <strong>the</strong> simulta-<br />

neous order<strong>in</strong>g on <strong>the</strong> structure <strong>of</strong> D and E. See [Pfe95] for details. Because <strong>the</strong><br />

only pro<strong>of</strong> rules for atomic formulas are all right-rules, <strong>the</strong> extra cases <strong>in</strong>troduced<br />

by our atomic propositions all fall <strong>in</strong>to <strong>the</strong> category <strong>of</strong> (easy) “right commutative<br />

conversions.’ <br />

Theorem 2.1.9 (Cut-elim<strong>in</strong>ation) For any Ψ, and for any D : (Ψ ⊢ cut<br />

exists E : (Ψ ⊢ F )<br />

F ) <strong>the</strong>re<br />

Pro<strong>of</strong>: By straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> D, us<strong>in</strong>g Lemma 2.1.8. <br />

Corollary 2.1.10 (Extraction) If · ⊢ cut<br />

e ′ and e ′ ⇑<br />

hc τ (e) <strong>the</strong>n <strong>the</strong>re exists e ′ such that e −→ ∗<br />

Pro<strong>of</strong>: By Theorem 2.1.9 and Lemma 2.1.2 <br />

The follow<strong>in</strong>g <strong>the</strong>orem summarizes all <strong>the</strong> work we have done so far. It shows<br />

that <strong>the</strong> simply typed λ-calculus is weakly normaliz<strong>in</strong>g.<br />

Theorem 2.1.11 (Weak Normalization) For any τ and for any (closed) e τ , <strong>the</strong>re<br />

exists e ′τ , such that e ′τ ⇑ and e τ −→ ∗ e ′τ .<br />

Pro<strong>of</strong>: Direct, by Theorem 2.1.7, Lemma 2.1.4, <strong>the</strong> rules cut, alll, impl, axiom and<br />

Corollary 2.1.10. <br />

28


2.2 Normalization <strong>of</strong> Gödel’s T<br />

Pro<strong>of</strong>s by logical relations are popular <strong>in</strong> large part because <strong>the</strong>y tend to scale well.<br />

We believe that structural logical relations preserve this property. Here, we extend<br />

our pro<strong>of</strong> <strong>of</strong> weak normalization to Gödel’s T, an extension <strong>of</strong> <strong>the</strong> simply-typed λ-<br />

calculus with terms for express<strong>in</strong>g natural numbers (i.e. zero and successor), and<br />

primitive recursion operator for each type τ. 1<br />

e τ ::= . . . | z o | (s (e o )) o | (rτ (e1 τ ) (e2 τ⇒o⇒τ ) (e3 o )) τ<br />

We will see that <strong>the</strong> def<strong>in</strong>ition <strong>of</strong> <strong>the</strong> logical relation is unchanged, as are most <strong>of</strong><br />

<strong>the</strong> <strong>the</strong>orems; however, <strong>in</strong> order to prove <strong>the</strong> Fundamental Theorem, we will need a<br />

pro<strong>of</strong>-<strong>the</strong>oretically non-trivial extension to <strong>the</strong> assertion logic.<br />

The new reduction rules for Gödel’s T are def<strong>in</strong>ed below. As usual, we omit type<br />

superscripts when <strong>the</strong>y are easily <strong>in</strong>ferred or irrelevent.<br />

e o −→ e ′o<br />

red-s<br />

s e o −→ s e ′o<br />

rτ (e2 τ ) (e3 τ⇒o⇒τ ) (z o ) −→ e τ 2<br />

rτ e1 e2 (s e3) −→ app (app e2 (rτ e1 e2 e3)) e3<br />

e1 −→ e ′ 1<br />

rτ e1 e2 e3 −→ rτ e ′ 1 e2 e3<br />

red-rc1<br />

e3 −→ e ′ 3<br />

rτ e1 e2 e3 −→ rτ e1 e2 e ′ 3<br />

e2 −→ e ′ 2<br />

red-rs<br />

red-rz<br />

rτ e1 e2 e3 −→ rτ e1 e ′ 2 e3<br />

The def<strong>in</strong>ition <strong>of</strong> canonical and atomic forms must be updated for <strong>the</strong> new expres-<br />

sions.<br />

z o ⇑<br />

can-z<br />

e o ⇑ can-s<br />

s e o ⇑<br />

red-rc3<br />

e τ 1 ⇑ e τ⇒o⇒τ<br />

2 ⇑ e o 3 ⇓ atm-r<br />

rτ (e1 τ ) (e2 τ⇒o⇒τ ) (e3 o ) ⇓<br />

1 This is a slight abuse <strong>of</strong> term<strong>in</strong>ology: Gödel actually referred to someth<strong>in</strong>g computationally<br />

equivalent to <strong>the</strong>se terms as computable functions <strong>of</strong> f<strong>in</strong>ite type, whereas his <strong>the</strong>ory “T” was a<br />

quantifier-free logic whose atomic formulas were equations between computable functions <strong>of</strong> f<strong>in</strong>ite<br />

type [Göd58]. We justify ourselves by not<strong>in</strong>g that <strong>the</strong> normalization <strong>of</strong> <strong>the</strong> former implies <strong>the</strong><br />

consistency <strong>of</strong> <strong>the</strong> latter, and vice versa.<br />

29<br />

red-rc2


The def<strong>in</strong>ition <strong>of</strong> multi-step reduction is unchanged, although we need to add <strong>the</strong><br />

follow<strong>in</strong>g additional cases to <strong>the</strong> congruence <strong>the</strong>orem (Theorem 1.3.1).<br />

Theorem 2.2.1 (Congruence <strong>of</strong> Multistep Reduction)<br />

. . .<br />

3. If e o −→ ∗ e ′o <strong>the</strong>n s e o −→ ∗ s e ′o<br />

4. If e1 −→ ∗ e1 and e2 −→ ∗ e2 and e3 −→ ∗ e3 <strong>the</strong>n rτ e1 e2 e3 −→ ∗ rτ e ′ 1 e ′ 2 e ′ 3<br />

Pro<strong>of</strong>: The statement and pro<strong>of</strong>s <strong>of</strong> 1 and 2 are <strong>the</strong> same as Theorem 1.3.1. 3 is<br />

by straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> <strong>the</strong> given derivation, and 4 is by<br />

straightforward simultaneous <strong>in</strong>duction on <strong>the</strong> structures <strong>of</strong> <strong>the</strong> given derivations. <br />

The def<strong>in</strong>ition <strong>of</strong> [τ ] for Gödel’s T is identical to <strong>the</strong> judgment def<strong>in</strong>ed <strong>in</strong> Sec-<br />

tion 2.1 for <strong>the</strong> simply typed λ-calculus, as are <strong>the</strong> pro<strong>of</strong>s <strong>of</strong> Lemma 2.1.3, <strong>the</strong> Escape<br />

Lemma and Closure Under Weak Head Expansion, even though <strong>the</strong> notion <strong>of</strong> weak<br />

head reduction must be expanded with <strong>the</strong> follow<strong>in</strong>g rules.<br />

Ψ ⊢ wh(e3, e ′ 3)<br />

Ψ ⊢ wh(rτ e1 e2 e3, rτ e1 e2 e ′ 3)<br />

wh-rc<br />

Ψ ⊢ wh((rτ e1 e2 z o ), e1)<br />

Ψ ⊢ wh((rτ e1 e2 (s e3)), (app (app e2 (rτ e1 e2 e3)) e3))<br />

However, <strong>in</strong> order to prove <strong>the</strong> Fundamental Theorem, we will need to make an<br />

extension to <strong>the</strong> assertion logic <strong>of</strong> non-trivial pro<strong>of</strong>-<strong>the</strong>oretic strength <strong>in</strong> <strong>the</strong> form <strong>of</strong><br />

<strong>the</strong> follow<strong>in</strong>g left-rule for hc o .<br />

Ψ ⊢ cut<br />

P (zo ) Ψ, xo , hP (xo ) cut<br />

⊢ P (s xo ) Ψ, xo , hha(xo ) cut<br />

⊢<br />

wh-rs<br />

P (x o )<br />

Ψ, xo , yo , h wh(xo ,yo )<br />

1 , h P (yo )<br />

2 ⊢ cut<br />

P (xo ) Ψ, hP (eo ) cut<br />

⊢ F h ′hco (eo ) ∈ Ψ<br />

Ψ ⊢ cut<br />

F<br />

30<br />

wh-rz<br />

hcl


The rule hcl can be thought <strong>of</strong> as def<strong>in</strong><strong>in</strong>g a catamorphism-like <strong>in</strong>duction pr<strong>in</strong>ciple,<br />

not on types or terms, but on pro<strong>of</strong>s <strong>of</strong> hc o (e): <strong>the</strong> predicate P plays <strong>the</strong> role <strong>of</strong><br />

<strong>in</strong>duction hypo<strong>the</strong>sis, and for each <strong>of</strong> <strong>the</strong> right rules that can be used to prove<br />

hc o (e o )—hc-z, hc-s, hc-atm and hc-wh—hcl has a m<strong>in</strong>or premiss that plays <strong>the</strong> role<br />

<strong>of</strong> <strong>in</strong>duction case (we refer to Ψ, h P (eo ) ⊢ F as <strong>the</strong> major premiss). In o<strong>the</strong>r words, <strong>the</strong><br />

atomic predicate-symbol hc o can be thought <strong>of</strong> as an <strong>in</strong>ductive def<strong>in</strong>ition <strong>in</strong> <strong>the</strong> style<br />

<strong>of</strong> Mart<strong>in</strong>-Löf [ML71]. This should not come as a great surprise: <strong>in</strong> order to reason<br />

about a λ-calculus with primitive recursion, we use an assertion logic with a notion <strong>of</strong><br />

iteration. In <strong>the</strong> absence <strong>of</strong> pairs, iteration and primitive recursion aren’t obviously<br />

<strong>the</strong> same th<strong>in</strong>g, so it should also come as no surprise that we f<strong>in</strong>d it convenient to<br />

augment <strong>the</strong> assertion logic with conjunction.<br />

Ψ, h F ⊢ cut<br />

Formulas F, G ::= . . . | F ∧ G<br />

G h ′F ∧G ∈ Ψ andr1<br />

Ψ ⊢ cut<br />

F ∧ G<br />

Ψ ⊢ cut<br />

F Ψ ⊢ cut<br />

G<br />

andr<br />

Ψ ⊢ cut<br />

F ∧ G<br />

Ψ, h G ⊢ cut<br />

G h ′F ∧G ∈ Ψ andr2<br />

Ψ ⊢ cut<br />

F ∧ G<br />

The fundamental <strong>the</strong>orem is mostly <strong>the</strong> same as before, but with some new cases,<br />

one <strong>of</strong> which relies on <strong>the</strong> Escape Lemma. For <strong>the</strong> sake <strong>of</strong> convenience, we prove that<br />

weaken<strong>in</strong>g is an admissible rule for <strong>the</strong> assertion logic; <strong>the</strong> o<strong>the</strong>r structural rules will<br />

be useful <strong>in</strong> Chapter 4.<br />

Lemma 2.2.2 (Structural Rules for <strong>the</strong> Assertion Logic)<br />

(Weaken<strong>in</strong>g) If D : (Ψ ⊢ cut<br />

F ) and E : (Ψ ′ ⊇ Ψ) <strong>the</strong>n Ψ ′ ⊢ cut<br />

(Exchange) If Ψ, hG , h ′G′ , Ψ ′ ⊢ cut<br />

F <strong>the</strong>n Ψ, h ′G′ , hG , Ψ ′ ⊢ cut<br />

F<br />

(Contraction) If Ψ0, hG , Ψ1, h ′G , Ψ2 ⊢ cut<br />

F <strong>the</strong>n Ψ0, hG , Ψ1, Ψ2 ⊢ cut<br />

Ψ0, Ψ1, h ′G , Ψ2 ⊢ cut<br />

F<br />

31<br />

F<br />

G and


(Substitution) If Ψ, xτ , Ψ ′ ⊢ cut<br />

F and fv(eτ ) ⊆ Ψ <strong>the</strong>n Ψ, Ψ ′ [eτ /x] ⊢ cut<br />

G[eτ /xτ ]<br />

Pro<strong>of</strong>: Weaken<strong>in</strong>g is by straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> D, where <strong>the</strong><br />

axiom case is proven by a straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> E; Exchange,<br />

contraction and substitution are straightforward <strong>in</strong>ductions on <strong>the</strong> given derivations.<br />

<br />

Recall that def<strong>in</strong>itions <strong>of</strong> Ψ <strong>in</strong>LR and <strong>the</strong> compatibility <strong>of</strong> e τ with Ψ have not<br />

changed from Def<strong>in</strong>ition 2.1.6.<br />

Theorem 2.2.3 (Fundamental) For every e τ and for every Ψ, if Ψ is <strong>in</strong> <strong>the</strong> logical<br />

relation and eτ is compatible with Ψ <strong>the</strong>n [τ ] = P and Ψ ⊢ cut<br />

P (eτ )<br />

Pro<strong>of</strong>: Exactly <strong>the</strong> same as Theorem 2.1.7 (i.e. by <strong>in</strong>duction on e τ ), but with new<br />

cases. We show <strong>the</strong>m below.<br />

Case: z o<br />

Ψ <strong>in</strong>LR and z o is compatible with Ψ given<br />

[o] = x o .hc(x o ) by def <strong>of</strong> [o]<br />

Ψ ⊢ cut<br />

hc(zo ) by rule hc-z<br />

Case: s e o<br />

Ψ <strong>in</strong>LR and s e o is compatible with Ψ given<br />

e o is compatible with Ψ by def <strong>of</strong> compatible<br />

Ψ ⊢ cut<br />

P (eo ) and [o] = P by IH on e<br />

P = x o .hc(x o ) by <strong>in</strong>version on [o]<br />

Ψ ⊢ cut<br />

hc(s eo ) by rule hc-s<br />

32


Case: rτ (e1 τ ) (e2 τ⇒o⇒τ ) (e3 o )<br />

Ψ <strong>in</strong>LR and rτ (e1 τ ) (e2 τ⇒o⇒τ ) (e3 o ) is compatible with Ψ given<br />

D1 : (Ψ ⊢ cut<br />

P1(eτ 1)) and [τ ] = P1<br />

D2 : (Ψ ⊢ cut<br />

by IH on e τ 1<br />

P2(eτ⇒o⇒τ 2 )) and [τ ⇒ o ⇒ τ ] = P2 by IH on eτ⇒o⇒τ 2<br />

P2 = xτ⇒o⇒τ 2 .∀xτ 1.Pτ(xτ 1) ⊃ ∀xo 3.hc(xo 3) ⊃ Pτ(app (app xτ⇒o⇒τ 2<br />

and [τ ] = Pτ<br />

P1 = Pτ<br />

E0 : (Ψ, h ′hc(e3) ⊢ cut<br />

E1 : (Ψ ⊢ cut<br />

E2 : (Ψ ⊢ cut<br />

E3 : (Ψ ⊢ cut<br />

∀x τ .∀y τ .wh(x τ , y τ ) ⊃ Pτ(y τ ) ⊃ Pτ(x τ ))<br />

x τ 1) x o 3)<br />

by <strong>in</strong>version on [τ ⇒ o ⇒ τ ] = P2<br />

by Lemma 2.1.3<br />

by Lemma 2.1.5<br />

∀x τ .Pτ(x τ ) ⊃ hc(x τ )) by Lemma 2.1.4 (1)<br />

∀x τ .ha(x τ ) ⊃ Pτ(x τ )) by Lemma 2.1.4 (2)<br />

∀x τ⇒o⇒τ .P2(x τ⇒o⇒τ ) ⊃ hc(x τ⇒o⇒τ )) by Lemma 2.1.4 (1)<br />

let P = x o .(Pτ(rτ (e1 τ ) (e2 τ⇒o⇒τ ) (x o )) ∧ hc(x o )) (convenient def<strong>in</strong>ition)<br />

Ψ, h ′hc(e3) cut<br />

⊢ P (zo )<br />

Ψ, h ′hc(eo 3 ) , x o , h P (xo ) ⊢ cut<br />

Ψ, h ′hc(eo 3 ) , x o , h ha(xo ) ⊢ cut<br />

P (s x o )<br />

by rules andr, cut, alll, impl, axiom, wh-rz, hc-z<br />

and Lemma 2.2.2 on E0 and D1<br />

by rules andr, cut, alll, impl, andl1, andl2, axiom, hc-s<br />

P (x o )<br />

Ψ, h ′hc(eo 3 ) , xo , yo , h wh(xo ,yo)<br />

1 , h P (yo )<br />

2 ⊢ cut<br />

P (xo )<br />

and Lemma 2.2.2 on E0 and D2<br />

by rules andr, cut, alll, impl, ha-r, hc-atm<br />

and Lemma 2.2.2 on E1, D1, E3, D2 and E2<br />

by rules andr, cut, alll, impl, wh-rc, axiom, andl1, hc-wh, andl2<br />

33<br />

and Lemma 2.2.2 on E0


Ψ, h ′hc(eo 3 ) , h P (eo 3 ) ⊢ cut<br />

Pτ(rτ (e1 τ ) (e2 τ⇒o⇒τ ) (e3 o ))<br />

Ψ, h ′hc(eo 3 ) ⊢ cut<br />

Ψ ⊢ cut<br />

Ψ ⊢ cut<br />

by rules andl1 and axiom<br />

Pτ(rτ (e1 τ ) (e2 τ⇒o⇒τ ) (e3 o )) by rule hcl<br />

hc(e o 3) by IH on e o 3<br />

by IH on e o 3 and def <strong>of</strong> [o]<br />

Pτ(rτ (e1 τ ) (e2 τ⇒o⇒τ ) (e3 o )) by rule cut<br />

As before, all that rema<strong>in</strong>s to be proven is <strong>the</strong> Extraction <strong>the</strong>orem for <strong>the</strong> assertion<br />

logic. However, as we shall see <strong>in</strong> Chapter 3, <strong>the</strong> syntactically f<strong>in</strong>itary methods<br />

that we have considered thus far are simply too weak to prove such a <strong>the</strong>orem. In<br />

Chapter 4, we will see how syntactic f<strong>in</strong>itism can be extended such that this difficulty<br />

can be overcome.<br />

34


Chapter 3<br />

Ord<strong>in</strong>al Analysis<br />

In <strong>the</strong> previous chapter, we demonstrated that structural logical relations can be<br />

viewed as syntactically f<strong>in</strong>itary reductions from one sort <strong>of</strong> consistency <strong>the</strong>orem (e.g.<br />

normalization for a typed λ-calculus) to ano<strong>the</strong>r (<strong>the</strong> extraction <strong>the</strong>orem for an<br />

assertion logic with cut). In <strong>the</strong> case <strong>of</strong> <strong>the</strong> simply typed λ-calculus, syntactically<br />

f<strong>in</strong>itary methods are enough to prove <strong>the</strong> relevant extraction <strong>the</strong>orem directly, and<br />

thus normalization can be proved outright. In general this is not always be <strong>the</strong> case.<br />

For example, we have seen that structural logical relations can be used to perform a<br />

similar reduction for Gödel’s T, but, as we shall see, <strong>the</strong> syntactically f<strong>in</strong>itary methods<br />

outl<strong>in</strong>ed thus far are simply too pro<strong>of</strong>-<strong>the</strong>oretically weak to prove <strong>the</strong> normalization<br />

<strong>of</strong> Gödel’s T outright. We will demonstrate this po<strong>in</strong>t semi-formally, us<strong>in</strong>g some <strong>of</strong><br />

<strong>the</strong> ideas and results from <strong>the</strong> branch <strong>of</strong> pro<strong>of</strong> <strong>the</strong>ory known as ord<strong>in</strong>al analysis, <strong>in</strong><br />

which consistency <strong>the</strong>orems are f<strong>in</strong>itistically reduced to well-order<strong>in</strong>g <strong>the</strong>orems for<br />

natural systems <strong>of</strong> ord<strong>in</strong>al notations (see [Rat06] for a good <strong>in</strong>troduction to <strong>the</strong> field).<br />

Many <strong>of</strong> <strong>the</strong> <strong>the</strong>orems <strong>in</strong> this chapter employ techniques that go well beyond what<br />

we consider to be syntactically f<strong>in</strong>itary, although we will attempt to rema<strong>in</strong> as true<br />

to <strong>the</strong> spirit <strong>of</strong> syntactic f<strong>in</strong>itism as possible.<br />

35


3.1 An Introduction to Ord<strong>in</strong>als<br />

In ma<strong>the</strong>matics, as <strong>in</strong> l<strong>in</strong>guistics, <strong>the</strong> dist<strong>in</strong>ction between card<strong>in</strong>al and ord<strong>in</strong>al num-<br />

bers is <strong>the</strong> dist<strong>in</strong>ction between quantity and order; <strong>in</strong> English, <strong>the</strong> words one, two<br />

and three are card<strong>in</strong>al numbers, whereas first, second and third are ord<strong>in</strong>al numbers.<br />

In ma<strong>the</strong>matics, <strong>the</strong> dist<strong>in</strong>ction is somewhat analogous; card<strong>in</strong>al numbers denote<br />

size, whereas ord<strong>in</strong>al numbers denote well-order<strong>in</strong>gs.<br />

Below we <strong>in</strong>formally describe <strong>the</strong> <strong>in</strong>tuition beh<strong>in</strong>d some <strong>of</strong> <strong>the</strong> basic ord<strong>in</strong>als, and<br />

ord<strong>in</strong>al operations, that we consider important for this dissertation. A more formal<br />

development <strong>of</strong> much <strong>of</strong> this material can be found <strong>in</strong> [Gal91], or, alternatively, nearly<br />

any textbook on set <strong>the</strong>ory or pro<strong>of</strong> <strong>the</strong>ory (e.g. [Kun80, TS00]).<br />

3.1.1 Ord<strong>in</strong>al Arithmetic<br />

Consider <strong>the</strong> syntactic category <strong>of</strong> even and odd natural numbers, as def<strong>in</strong>ed below.<br />

Even Numbers E ::= zero | plustwoeven E<br />

Odd Numbers O ::= one | plustwoodd O<br />

Natural Numbers with Parity N ::= E | O<br />

Clearly, <strong>the</strong> syntactic categories E, O, N, and n (def<strong>in</strong>ed <strong>in</strong> Section 1.1) all have<br />

<strong>the</strong> same card<strong>in</strong>ality, s<strong>in</strong>ce <strong>the</strong>re are obvious bijections between each <strong>of</strong> <strong>the</strong>m. In<br />

particular, N can be viewed as a natural alternative to n: <strong>the</strong> two syntactic categories<br />

are clearly <strong>in</strong>tended to represent <strong>the</strong> same concept. Under <strong>the</strong> subterm order<strong>in</strong>gs<br />

for n, E and O—written


order-types and ord<strong>in</strong>als with <strong>the</strong> same names.<br />

Consider <strong>the</strong> follow<strong>in</strong>g order<strong>in</strong>g relation


one as though it were <strong>the</strong> o<strong>the</strong>r for <strong>the</strong> sake <strong>of</strong> convenience). However, this analogy<br />

only takes us so far: <strong>in</strong> general, ord<strong>in</strong>al addition is not commutative. For example,<br />

1 + ω is equal to ω (consider <strong>the</strong> bijective, order-preserv<strong>in</strong>g function that maps <strong>in</strong>l 〈〉<br />

to z, and <strong>in</strong>r n to s n), but ω + 1 is not.<br />

Every ord<strong>in</strong>al which is nei<strong>the</strong>r 0 nor a successor ord<strong>in</strong>al (i.e. can be written α+1)<br />

is def<strong>in</strong>ed to be a limit ord<strong>in</strong>al. In general, every limit ord<strong>in</strong>al can be described as<br />

smallest ord<strong>in</strong>al that is strictly larger than every element <strong>of</strong> a strictly <strong>in</strong>creas<strong>in</strong>g,<br />

<strong>in</strong>f<strong>in</strong>ite sequence <strong>of</strong> ord<strong>in</strong>als. For example, <strong>the</strong> ord<strong>in</strong>al ω is <strong>the</strong> limit <strong>of</strong> <strong>the</strong> sequence<br />

0, 1, 2, . . .; <strong>the</strong> ord<strong>in</strong>al ω +ω is <strong>the</strong> limit <strong>of</strong> <strong>the</strong> sequence ω, ω +1, ω +2, . . .; <strong>the</strong> ord<strong>in</strong>al<br />

ω + ω + ω is <strong>the</strong> limit <strong>of</strong> <strong>the</strong> sequence ω + ω, ω + ω + 1, ω + ω + 2, . . .; etcetera. In<br />

general each limit ord<strong>in</strong>al can be associated with a canonical fundamental sequence 1<br />

, although <strong>the</strong> exact def<strong>in</strong>ition <strong>of</strong> fundamental sequence varies depend<strong>in</strong>g on <strong>the</strong><br />

presentation; we write <strong>the</strong> nth element <strong>of</strong> <strong>the</strong> fundamental sequence for α as α[n].<br />

We have already seen what <strong>the</strong> fundamental sequences look like for ω, ω+ω, ω+ω+ω,<br />

etc. The notion <strong>of</strong> ord<strong>in</strong>al multiplication will allow us to def<strong>in</strong>e <strong>the</strong> ord<strong>in</strong>al ω · ω,<br />

n times<br />

<br />

whose fundamental sequence is def<strong>in</strong>ed as (ω · ω)[n] = ω + . . . + ω = ω · n.<br />

The ord<strong>in</strong>ary, arithmetic notion <strong>of</strong> multiplication can be def<strong>in</strong>ed <strong>in</strong> terms <strong>of</strong> re-<br />

peated addition. The same is true for ord<strong>in</strong>al multiplication, but we prefer to de-<br />

scribe its behavior as a primitive notion. Given any two syntactic categories A and<br />

B, we can def<strong>in</strong>e a syntactic category whose sole term constructor is 〈A; B〉; such<br />

a construction is analogous to <strong>the</strong> product-type A × B. We can use <strong>the</strong> notion <strong>of</strong><br />

lexicographic order<strong>in</strong>g, discussed <strong>in</strong> Section 1.2, to lift well-order<strong>in</strong>gs


<strong>the</strong> judgments below.<br />

A


We f<strong>in</strong>d it useful to def<strong>in</strong>e <strong>the</strong> iterated exponentiation function ωn as follows.<br />

ω0 = 1<br />

ωn+1 = ω ωn<br />

This def<strong>in</strong>ition is more or less standard, except that some authors prefer to def<strong>in</strong>e<br />

ω0 to be 0 or ω. Regardless <strong>of</strong> <strong>the</strong> convention adopted, <strong>the</strong> function that maps n to<br />

ωn can be used as <strong>the</strong> fundamental sequence for an ord<strong>in</strong>al that is usually denoted<br />

by <strong>the</strong> symbol ε0, which will be discussed <strong>in</strong> greater detail <strong>in</strong> subsequent sections.<br />

3.1.2 Ord<strong>in</strong>al Notation Systems<br />

An ord<strong>in</strong>al notation system is essentially just a syntactic category coupled with a<br />

transitive, total, well-founded order<strong>in</strong>g, whose terms are <strong>in</strong>tended to give names<br />

to ord<strong>in</strong>als. We do not require that <strong>the</strong> well-foundedness <strong>of</strong> such an order<strong>in</strong>g to be<br />

proven outright, although we do require that <strong>the</strong> totality, transitivity and decidability<br />

<strong>of</strong> <strong>the</strong> order<strong>in</strong>g can be proven us<strong>in</strong>g syntactically-f<strong>in</strong>itary methods.<br />

For example, we have already seen how <strong>the</strong> terms <strong>of</strong> <strong>the</strong> syntactic categories n,<br />

E, and O, coupled with <strong>the</strong> subterm order<strong>in</strong>gs


paradox. Thus, every ord<strong>in</strong>al notation system is necessarily <strong>in</strong>complete.<br />

The follow<strong>in</strong>g <strong>the</strong>orem, due to Georg Cantor, is useful <strong>in</strong> help<strong>in</strong>g us to def<strong>in</strong>e<br />

ord<strong>in</strong>al notation systems.<br />

Theorem 3.1.1 (Cantor Normal Form) For every non-zero ord<strong>in</strong>al α, <strong>the</strong>re ex-<br />

ist ord<strong>in</strong>als α1 . . . αn such that α ≥ α1 ≥ . . . ≥ αn and α = ω α1 + . . . + ω αn<br />

Note that <strong>the</strong> Cantor Normal Form <strong>the</strong>orem does not contradict <strong>the</strong> Burali-Forti<br />

paradox; us<strong>in</strong>g symbols for 0, ord<strong>in</strong>al addition, and ord<strong>in</strong>al exponentiation at base<br />

ω, we can def<strong>in</strong>e a notation system for any ord<strong>in</strong>al α whose representation <strong>in</strong> Cantor<br />

normal form (CNF), satisfies α > α1 ≥ . . . ≥ αn (although <strong>the</strong> notion <strong>of</strong> equality over<br />

<strong>the</strong> ord<strong>in</strong>als <strong>in</strong> this notation system is more nuanced than just syntactic equality).<br />

However, such an ord<strong>in</strong>al notation system cannot represent any <strong>of</strong> <strong>the</strong> ε-numbers, that<br />

is ord<strong>in</strong>als that are fixed-po<strong>in</strong>ts <strong>of</strong> <strong>the</strong> equation α = ω α . In fact, <strong>the</strong> order-type for<br />

this notation system is <strong>the</strong> smallest ε-number, ε0. The ord<strong>in</strong>al ε0 plays an important<br />

role <strong>in</strong> <strong>the</strong> pro<strong>of</strong>-<strong>the</strong>oretic analysis <strong>of</strong> number <strong>the</strong>ory, described <strong>in</strong> Section 3.2.1.<br />

However, <strong>the</strong>re is noth<strong>in</strong>g to stop us from add<strong>in</strong>g a symbol for ε0 to <strong>the</strong> ord<strong>in</strong>al<br />

notation system described above: <strong>the</strong> result<strong>in</strong>g notation system would have order<br />

type ε1, i.e. <strong>the</strong> next-smallest fixed-po<strong>in</strong>t <strong>of</strong> α = ω α after ε0. Similarly, if we <strong>the</strong>n<br />

add a symbol for ε1, <strong>the</strong> result<strong>in</strong>g ord<strong>in</strong>al notation system would have order-type ε2,<br />

and so forth and so on. Add<strong>in</strong>g all <strong>of</strong> <strong>the</strong> symbols εn, where n is a f<strong>in</strong>ite ord<strong>in</strong>al,<br />

would result <strong>in</strong> an ord<strong>in</strong>al notation system whose order-type is εω. Add<strong>in</strong>g a symbol<br />

for εωwould have order type εω+1, and so forth and so on. But what about <strong>the</strong><br />

ord<strong>in</strong>als that are fixed-po<strong>in</strong>ts <strong>of</strong> <strong>the</strong> equation α = εα?<br />

Clearly we can cont<strong>in</strong>ue this process <strong>in</strong>def<strong>in</strong>itely. To this end, we can def<strong>in</strong>e <strong>the</strong><br />

(b<strong>in</strong>ary) Veblen function ϕα(β) (sometimes written ϕ(α, β)) <strong>in</strong>formally, as follows.<br />

We def<strong>in</strong>e ϕ0(β) to be ω β and ϕα+1 is <strong>the</strong> function that iterates over <strong>the</strong> fixed-po<strong>in</strong>ts<br />

41


<strong>of</strong> ϕα. Thus, we can write εα as ϕ1(α). If α is a limit ord<strong>in</strong>al, <strong>the</strong>n ϕα is function<br />

that iterates over <strong>the</strong> ord<strong>in</strong>als that are fixed po<strong>in</strong>ts <strong>of</strong> all <strong>of</strong> <strong>the</strong> functions <strong>of</strong> <strong>the</strong><br />

form ϕα ′, where α′ < α. We can, us<strong>in</strong>g a symbol for <strong>the</strong> Veblen function, along<br />

with symbols for 0 and ord<strong>in</strong>al addition, def<strong>in</strong>e an ord<strong>in</strong>al notation system which is<br />

much more expressive than anyth<strong>in</strong>g we have considered thus far. The order-type<br />

<strong>of</strong> this ord<strong>in</strong>al notation system is referred to as <strong>the</strong> Feferman-Schütte ord<strong>in</strong>al, and<br />

is typically denoted us<strong>in</strong>g <strong>the</strong> symbol Γ0 (see [Gal91] for a more formal development<br />

<strong>of</strong> <strong>the</strong> ord<strong>in</strong>als up to Γ0). The Veblen function can be generalized to operate on n<br />

arguments, for some fixed number n ≥ 2; <strong>the</strong> supremum <strong>of</strong> <strong>the</strong> order-types <strong>of</strong> <strong>the</strong><br />

result<strong>in</strong>g ord<strong>in</strong>al-notation systems is referred to as <strong>the</strong> small Veblen ord<strong>in</strong>al [Mos04].<br />

The small Veblen ord<strong>in</strong>al is <strong>the</strong> largest ord<strong>in</strong>al that we are <strong>in</strong>terested <strong>in</strong> for <strong>the</strong><br />

purposes <strong>of</strong> this dissertation.<br />

3.2 Ord<strong>in</strong>als <strong>in</strong> Pro<strong>of</strong> Theory<br />

Given an ord<strong>in</strong>al notation system O, whose order type is α, <strong>the</strong> pr<strong>in</strong>ciple <strong>of</strong> transf<strong>in</strong>ite<br />

<strong>in</strong>duction up to α is <strong>the</strong> pr<strong>in</strong>ciple <strong>of</strong> well-founded <strong>in</strong>duction applied to <strong>the</strong> well-<br />

order<strong>in</strong>g <strong>of</strong> O, but not <strong>the</strong> order-type <strong>of</strong> O itself (e.g. <strong>the</strong> pr<strong>in</strong>ciple <strong>of</strong> transf<strong>in</strong>ite<br />

<strong>in</strong>duction up to ω is just <strong>the</strong> ord<strong>in</strong>ary pr<strong>in</strong>ciple <strong>of</strong> ma<strong>the</strong>matical <strong>in</strong>duction). Note that<br />

we do not necessarily consider <strong>the</strong> pr<strong>in</strong>ciple <strong>of</strong> transf<strong>in</strong>ite <strong>in</strong>duction to be syntactically<br />

f<strong>in</strong>itary, but we can consider <strong>the</strong> effect <strong>of</strong> extend<strong>in</strong>g syntactically f<strong>in</strong>itary reason<strong>in</strong>g<br />

with transf<strong>in</strong>ite <strong>in</strong>duction.<br />

3.2.1 Gentzen’s Theorems<br />

This sort <strong>of</strong> consideration is well precedented. As we have already discussed, it is<br />

a consequence <strong>of</strong> Gödel’s second <strong>in</strong>completeness <strong>the</strong>orem that, <strong>in</strong> general, pro<strong>of</strong>s<br />

42


<strong>of</strong> logical consistency reduce one set <strong>of</strong> pro<strong>of</strong>-<strong>the</strong>oretic assumptions to ano<strong>the</strong>r. In<br />

1936 Gerhard Gentzen published a consistency pro<strong>of</strong> for a natural-deduction style<br />

formulation <strong>of</strong> classical first-order arithmetic, us<strong>in</strong>g a comb<strong>in</strong>ation <strong>of</strong> f<strong>in</strong>itary methods<br />

and transf<strong>in</strong>ite <strong>in</strong>duction up to ε0 (us<strong>in</strong>g an ord<strong>in</strong>al-notation system based on lists<br />

<strong>of</strong> numbers) [Gen36]. In 1938, Gentzen presented a ref<strong>in</strong>ed version <strong>of</strong> this result,<br />

this time for a sequent calculus formulation <strong>of</strong> first-order arithmetic and us<strong>in</strong>g <strong>the</strong><br />

ord<strong>in</strong>al notation system for ε0 based on CNF described <strong>in</strong> Section 3.1.2 [Gen38].<br />

Both pro<strong>of</strong>s proceed roughly as follows: us<strong>in</strong>g f<strong>in</strong>itary methods, any pro<strong>of</strong> <strong>of</strong> a<br />

contradiction ( ⊢ 1 = 2 <strong>in</strong> [Gen36], · ⊢ · <strong>in</strong> [Gen38]) can be assigned an ord<strong>in</strong>al<br />

measure, and, aga<strong>in</strong> us<strong>in</strong>g f<strong>in</strong>itary methods, any such pro<strong>of</strong> can be reduced <strong>in</strong> such<br />

a way that this ord<strong>in</strong>al measure decreases; thus, by transf<strong>in</strong>ite <strong>in</strong>duction, any pro<strong>of</strong><br />

<strong>of</strong> a contradictory statement can be reduced to a pro<strong>of</strong> <strong>of</strong> size 0, and it can easily<br />

be seen via case-analysis that no such pro<strong>of</strong> exists. Gentzen argued that f<strong>in</strong>itary<br />

methods must be considered valid beyond any reasonable doubt, mean<strong>in</strong>g that <strong>the</strong><br />

consistency <strong>of</strong> arithmetic can be reduced to believ<strong>in</strong>g <strong>in</strong> <strong>the</strong> pr<strong>in</strong>ciple <strong>of</strong> transf<strong>in</strong>ite<br />

<strong>in</strong>duction up to ε0.<br />

Gentzen did not provide a formal system to capture what he meant by “f<strong>in</strong>i-<br />

tary methods,” but from his description it is clear that he was referr<strong>in</strong>g to a small,<br />

constructive subset <strong>of</strong> <strong>the</strong> pr<strong>in</strong>ciples formalized by first-order arithmetic. In <strong>the</strong> <strong>in</strong>-<br />

terven<strong>in</strong>g years, it has been argued, most prom<strong>in</strong>ently by Tait, that <strong>the</strong> concept <strong>of</strong><br />

f<strong>in</strong>itism is captured by <strong>the</strong> quantifier-free <strong>the</strong>ory <strong>of</strong> primitive recursive arithmetic,<br />

PRA [Tai81] (although [Rat06] observes that Gentzen’s results can be formalized <strong>in</strong><br />

terms <strong>of</strong> elementary recursive arithmetic, which is even weaker than PRA). In general,<br />

Gentzen’s formulations <strong>of</strong> classical first-order arithmetic are essentially equivalent to<br />

<strong>the</strong> formal system now referred to as Peano arithmetic (PA), and, every <strong>the</strong>orem<br />

<strong>of</strong> PRA can be proven <strong>in</strong> a fragment <strong>of</strong> Peano arithmetic, PA1, where <strong>in</strong>duction is<br />

43


estricted to Σ1-predicates (and, as it turns out, vice-versa [Par66, M<strong>in</strong>73a]).<br />

Def<strong>in</strong>ition 3.2.1 (Fragments <strong>of</strong> Peano Arithmetic) The system PAn is <strong>the</strong> usual<br />

first-order formulation <strong>of</strong> Peano arithmetic <strong>in</strong> which <strong>the</strong> <strong>in</strong>duction schema is re-<br />

stricted to Σn (or, equivalently, Πn) formulas when written <strong>in</strong> prenex normal form.<br />

Thus, Gentzen’s 1936 and 1938 results can be summarized as follows, where<br />

TI1(ε0) is <strong>the</strong> pr<strong>in</strong>ciple <strong>of</strong> transf<strong>in</strong>ite <strong>in</strong>duction up to ε0 restricted to Σ1-predicates,<br />

and CON(PA) is <strong>the</strong> encod<strong>in</strong>g <strong>of</strong> <strong>the</strong> statement “Peano arithmetic is consistent”<br />

with<strong>in</strong> PA.<br />

PA1 + TI1(ε0) ⊢ CON(PA)<br />

Thus, by Gödel’s second <strong>in</strong>completeness <strong>the</strong>orem, if we believe that PA is consistent,<br />

<strong>the</strong>n we must also believe <strong>the</strong> follow<strong>in</strong>g.<br />

PA TI1(ε0)<br />

In 1943, Gentzen proved, aga<strong>in</strong> us<strong>in</strong>g only f<strong>in</strong>itary methods, that for any ord<strong>in</strong>al<br />

α that is strictly smaller than ε0, <strong>the</strong> pr<strong>in</strong>ciple <strong>of</strong> transf<strong>in</strong>ite <strong>in</strong>duction up to ω α on<br />

formulas <strong>of</strong> degree n can be replaced with <strong>the</strong> pr<strong>in</strong>ciple <strong>of</strong> transf<strong>in</strong>ite <strong>in</strong>duction up to<br />

α on formulas <strong>of</strong> degree n+1 [Gen69c] (Gentzen def<strong>in</strong>ed <strong>the</strong> degree <strong>of</strong> a formula to be<br />

<strong>the</strong> total number <strong>of</strong> logical connectives, although it has been shown that this result<br />

holds even when “degree” is def<strong>in</strong>ed to be <strong>the</strong> number <strong>of</strong> quantifier-alternations <strong>the</strong><br />

formula has <strong>in</strong> prenex normal form; see Theorem 3.2.6). Thus, by <strong>in</strong>duction on <strong>the</strong><br />

structure <strong>of</strong> α (as represented <strong>in</strong> CNF), <strong>the</strong> pr<strong>in</strong>ciple <strong>of</strong> transf<strong>in</strong>ite <strong>in</strong>duction up to<br />

any fixed ord<strong>in</strong>al α < ε0 is an admissible rule <strong>in</strong> first-order arithmetic. This result<br />

can be summarized as follows.<br />

PA ⊢ TI1(< ε0)<br />

In o<strong>the</strong>r words, by <strong>the</strong> 1936 and 1938 results, ε0 is an upper bound on <strong>the</strong><br />

provable well-order<strong>in</strong>gs <strong>of</strong> first-order arithmetic, and by <strong>the</strong> 1943 result, this bound<br />

44


is precise. Thus, <strong>the</strong> ord<strong>in</strong>al ε0 is sometimes referred to as <strong>the</strong> pro<strong>of</strong> <strong>the</strong>oretic ord<strong>in</strong>al<br />

<strong>of</strong> arithmetic. The branch <strong>of</strong> pro<strong>of</strong> <strong>the</strong>ory known as ord<strong>in</strong>al analysis concerns itself<br />

primarily with f<strong>in</strong>d<strong>in</strong>g <strong>the</strong> pro<strong>of</strong> <strong>the</strong>oretic ord<strong>in</strong>als <strong>of</strong> various logical <strong>the</strong>ories, where<br />

<strong>the</strong> expressivity <strong>of</strong> different <strong>the</strong>ories can usually be accurately compared <strong>in</strong> terms<br />

<strong>of</strong> <strong>the</strong> size <strong>of</strong> <strong>the</strong>ir pro<strong>of</strong> <strong>the</strong>oretic ord<strong>in</strong>als. However, we do have to be careful:<br />

<strong>the</strong> def<strong>in</strong>ition <strong>of</strong> a pro<strong>of</strong>-<strong>the</strong>oretic ord<strong>in</strong>al for a given <strong>the</strong>ory depends on <strong>the</strong> ord<strong>in</strong>al<br />

notation system used, although this is rarely a complication for any natural 2 ord<strong>in</strong>al<br />

notation system. [Rat07]<br />

3.2.2 Ord<strong>in</strong>al Recursive Hierarchies<br />

In Section 1.2, we saw how structural <strong>in</strong>duction can be used to prove <strong>the</strong> totality <strong>of</strong><br />

functions such as add, and how <strong>in</strong>duction on a lexicographic order<strong>in</strong>g can be used<br />

to prove <strong>the</strong> totality <strong>of</strong> functions such as ack; <strong>the</strong> <strong>in</strong>duction order<strong>in</strong>gs used <strong>in</strong> <strong>the</strong>se<br />

pro<strong>of</strong>s have order type ω and ω 2 , respectively. In general, <strong>the</strong> pr<strong>in</strong>ciple <strong>of</strong> transf<strong>in</strong>ite<br />

<strong>in</strong>duction up to α can also be used to prove <strong>the</strong> totality <strong>of</strong> functions; we refer to such<br />

an application <strong>of</strong> transf<strong>in</strong>ite <strong>in</strong>duction up to α as transf<strong>in</strong>ite recursion up to α.<br />

We def<strong>in</strong>e two ord<strong>in</strong>al-recursive hierarchies <strong>of</strong> functions below. Recall that we<br />

write α[n] for <strong>the</strong> nth element <strong>of</strong> <strong>the</strong> limit ord<strong>in</strong>al α’s fundamental sequence.<br />

Def<strong>in</strong>ition 3.2.2 (Fast Grow<strong>in</strong>g Hierarchy) For a given ord<strong>in</strong>al notation sys-<br />

tem <strong>of</strong> order-type α, we def<strong>in</strong>e <strong>the</strong> fast-grow<strong>in</strong>g hierarchy at Fα to be <strong>the</strong> class <strong>of</strong><br />

number-<strong>the</strong>oretic functions fβ def<strong>in</strong>ed by transf<strong>in</strong>ite recursion up to α.<br />

2 As with <strong>the</strong> notion <strong>of</strong> “consistent logic,” we cannot def<strong>in</strong>e what it means for an ord<strong>in</strong>al notation<br />

system to be “natural,” but we know it when we see it. For example, it is possible to use an ord<strong>in</strong>al<br />

notation system <strong>of</strong> order type ω 2 to prove <strong>the</strong> consistency <strong>of</strong> PA; this order<strong>in</strong>g would make direct<br />

reference to <strong>the</strong> first order predicate “<strong>the</strong> Gödel number<strong>in</strong>g <strong>of</strong> F is provable <strong>in</strong> PA” <strong>in</strong> such a<br />

way that <strong>the</strong> <strong>the</strong> consistency <strong>of</strong> PA is directly implied by <strong>the</strong> well-foundedness <strong>of</strong> this order<strong>in</strong>g<br />

[Rob65, Rat07]. We do not consider such an ord<strong>in</strong>al notation system to be natural.<br />

45


f0(n) = s n<br />

fβ+1(n) =<br />

n times<br />

<br />

(fβ ◦ . . . ◦ fβ)(n)<br />

fβ(n) = f β[n](n) if β is a limit ord<strong>in</strong>al<br />

where ◦ denotes function composition, and <strong>the</strong> ellipses can be elim<strong>in</strong>ated by def<strong>in</strong><strong>in</strong>g<br />

an auxiliary function that is primitive recursive on n.<br />

Def<strong>in</strong>ition 3.2.3 (Hardy Hierarchy) For a given ord<strong>in</strong>al notation system <strong>of</strong> order-<br />

type α, we def<strong>in</strong>e <strong>the</strong> Hardy hierarchy at Hα to be <strong>the</strong> class <strong>of</strong> number-<strong>the</strong>oretic<br />

functions hβ def<strong>in</strong>ed by transf<strong>in</strong>ite recursion up to α.<br />

h0(n) = n<br />

hβ+1(n) = hβ(s n)<br />

hβ(n) = h β[n](n) if β is a limit ord<strong>in</strong>al<br />

Although <strong>the</strong> def<strong>in</strong>itions <strong>of</strong> <strong>the</strong> fast grow<strong>in</strong>g and Hardy hierarchies depend on <strong>the</strong><br />

exact def<strong>in</strong>ition <strong>of</strong> fundamental sequence, for <strong>the</strong> ord<strong>in</strong>als up to ε0 (and, to a lesser<br />

extent, Γ0) <strong>the</strong> def<strong>in</strong>ition <strong>of</strong> fundamental sequence is standard.<br />

It is worth mention<strong>in</strong>g that <strong>the</strong> function that maps n to ack(n, n) (as def<strong>in</strong>ed<br />

<strong>in</strong> Section 1.2) grows roughly at <strong>the</strong> same rate as fω and hωω (folklore), and that<br />

<strong>the</strong> Ackermann function “grows faster” than any primitive recursive function (also<br />

folklore; see [Sza93] for a syntactically f<strong>in</strong>itary pro<strong>of</strong>) <strong>in</strong> <strong>the</strong> follow<strong>in</strong>g sense.<br />

Def<strong>in</strong>ition 3.2.4 We say that a number-<strong>the</strong>oretic function f majorizes <strong>the</strong> number-<br />

<strong>the</strong>oretic function g iff <strong>the</strong>re exists some n such that, for every m > n, f(m) > g(m).<br />

The follow<strong>in</strong>g <strong>the</strong>orem demonstrates some <strong>in</strong>terest<strong>in</strong>g properties <strong>of</strong> <strong>the</strong> Hardy<br />

and fast grow<strong>in</strong>g hierarchies.<br />

46


Theorem 3.2.5 For any α < ε0<br />

1. for any n, fα(n) = hω α(n)<br />

2. for any n, m, if n < m <strong>the</strong>n hα(n) < hα(m) and fα(n) < fα(m)<br />

3. for any β if β < α <strong>the</strong>n hα majorizes hβ, and fα majorizes fβ<br />

Pro<strong>of</strong>: Each is by transf<strong>in</strong>ite <strong>in</strong>duction up to α. See [BW87] for details. <br />

In Section 1.2, we saw that functions can be def<strong>in</strong>ed syntactically by first giv-<br />

<strong>in</strong>g judgmental def<strong>in</strong>itions <strong>of</strong> <strong>the</strong>ir def<strong>in</strong><strong>in</strong>g equations, <strong>the</strong>n by us<strong>in</strong>g case analysis<br />

and <strong>in</strong>duction to prove totality. In first-order <strong>the</strong>ories, such as Peano arithmetic,<br />

<strong>the</strong> provably functions are characterized similarly. A function f can be repre-<br />

sented by an atomic predicate-symbol Pf, where f’s def<strong>in</strong><strong>in</strong>g equations f(<strong>in</strong>puts) =<br />

outputs are axioms (usually expressible as Horn clauses) for formulas <strong>of</strong> <strong>the</strong> form<br />

Pf〈<strong>in</strong>puts; outputs〉; <strong>in</strong> general Pf need not be atomic so long as its prenex normal<br />

form is at most Σ1, and <strong>the</strong> def<strong>in</strong><strong>in</strong>g equations for f need not be axioms, so long<br />

as Pf〈<strong>in</strong>puts; outputs〉 is provable iff f(<strong>in</strong>puts) = outputs. For example, addition<br />

(def<strong>in</strong>ed judgmentally <strong>in</strong> Section 1.1) could be represented <strong>in</strong> Peano arithmetic by a<br />

tertiary atomic predicate symbol add, whose axioms would be ∀x.∀y.add(z; x; x) and<br />

∀x1.∀x2.∀y.add(x1; x2; y) ⊃ add(s x1; x2; s y); similarly, <strong>the</strong> function 3×x could <strong>the</strong>n<br />

be represented by <strong>the</strong> b<strong>in</strong>ary predicate x.y.∃y ′ .add(x; x; y ′ ) ∧ add(x; y ′ ; y). Given<br />

such a representation, we say that f is provably total <strong>in</strong> a first order <strong>the</strong>ory iff <strong>the</strong><br />

formula ∀<strong>in</strong>puts.∃outputs.Pf〈<strong>in</strong>puts; outputs〉 can be proved.<br />

Ord<strong>in</strong>al recursive hierarchies can sometimes be used to characterize <strong>the</strong> provably<br />

total functions <strong>of</strong> a given logical <strong>the</strong>ory, where ord<strong>in</strong>al notation systems can ei<strong>the</strong>r<br />

be def<strong>in</strong>ed to be part <strong>of</strong> <strong>the</strong> term-algebra for <strong>the</strong> logic, or else are def<strong>in</strong>ed <strong>in</strong> terms <strong>of</strong><br />

Gödel-number<strong>in</strong>g. The follow<strong>in</strong>g statements provide examples. Recall <strong>the</strong> def<strong>in</strong>ition<br />

47


<strong>of</strong> ωn from <strong>the</strong> end <strong>of</strong> Section 3.1.1. Note that <strong>the</strong> pr<strong>in</strong>ciple TI1(ω) is equivalent to<br />

<strong>the</strong> ord<strong>in</strong>ary pr<strong>in</strong>ciple <strong>of</strong> ma<strong>the</strong>matical <strong>in</strong>duction restricted to Σ1-formulas (e.g. PA1<br />

+ TI1(ω) = PA1).<br />

Theorem 3.2.6 (Ord<strong>in</strong>al Hierarchies and Fragments <strong>of</strong> PA)<br />

1. [BW87]<br />

(a) For every α < ε0, fα and hα are provably total <strong>in</strong> PA.<br />

(b) If f is a provably total function <strong>in</strong> PA, <strong>the</strong>n f is majorized by both hε0<br />

and fε0.<br />

2. [M<strong>in</strong>73a, CR91]<br />

(a) For every n, PA1 + TI1(ωn+2) ⊢ CON(P An+2)<br />

(b) For every n, PAn+1 ⊢ TI1(ωn+1)<br />

3. [CR91]<br />

(a) [Par66] For every α < ωn+1, fα and hωα are provably total <strong>in</strong> PAn+1.<br />

(b) If f is a provably total function <strong>in</strong> PAn+1, <strong>the</strong>n f is majorized by both<br />

fωn+1 and hωn+2.<br />

4. [M<strong>in</strong>73a, CR91] For any α < ε0, (PAn+2 + TI1(α)) can prove <strong>the</strong> same <strong>the</strong>o-<br />

rems as (PAn+1 + TI1(ω α ))<br />

Pro<strong>of</strong>: The pro<strong>of</strong>s are nontrivial. Some <strong>of</strong> <strong>the</strong>m (e.g. [BW87, CR91]) make essential<br />

use <strong>of</strong> <strong>the</strong> <strong>in</strong>f<strong>in</strong>itary <strong>in</strong>ference rule known as <strong>the</strong> ω-rule, popularized by Kurt Schütte.<br />

⊢ P (0) ⊢ P (1) ⊢ P (2) . . . ω-rule<br />

⊢ ∀x.P (x)<br />

48


Although this practice appears on <strong>the</strong> surface to be outside <strong>of</strong> <strong>the</strong> realm <strong>of</strong> <strong>the</strong><br />

f<strong>in</strong>itary, <strong>in</strong>f<strong>in</strong>itary pro<strong>of</strong>-<strong>the</strong>oretic analyses can, <strong>in</strong> general, be given (syntactically)<br />

f<strong>in</strong>itary presentations [Buc91]. <br />

The above <strong>the</strong>orem, comb<strong>in</strong>ed with <strong>the</strong> one below, will have <strong>in</strong>terest<strong>in</strong>g conse-<br />

quences with regards to <strong>the</strong> provability <strong>of</strong> <strong>the</strong> Extraction <strong>the</strong>orem for <strong>the</strong> assertion<br />

logic def<strong>in</strong>ed <strong>in</strong> Section 2.2.<br />

Theorem 3.2.7 (Gödel’s T and ε0)<br />

1. For every e τ <strong>in</strong> Gödel’s T, <strong>the</strong> function that normalizes e τ is ε0-recursive.<br />

2. For every number-<strong>the</strong>oretic function f that is provably total <strong>in</strong> PA, f can be<br />

represented as a term <strong>in</strong> Gödel’s T.<br />

Pro<strong>of</strong>: 1 can be proved by a non-trivial assignment <strong>of</strong> ord<strong>in</strong>als smaller than ε0 to<br />

terms [How70, Sch77] (<strong>the</strong> former is for a formulation <strong>of</strong> Gödel’s T similar to ours,<br />

<strong>the</strong> latter is <strong>in</strong> terms <strong>of</strong> comb<strong>in</strong>ators). 2 follows from a double-negation translation<br />

from classical first-order arithmetic <strong>in</strong>to <strong>in</strong>tuitionistic first-order arithmetic followed<br />

by Gödel’s Dialectica [Göd58] transformation; see [AF98] for more detail. <br />

3.2.3 <strong>Syntactic</strong> <strong>F<strong>in</strong>itism</strong> and PA2<br />

In Chapter 1, we argued that <strong>the</strong> notions <strong>of</strong> abstract syntax and hypo<strong>the</strong>tical judg-<br />

ment should be granted <strong>the</strong> same epistemic status by programm<strong>in</strong>g languages re-<br />

searchers as <strong>the</strong> natural numbers are granted by ma<strong>the</strong>maticians. However, strictly<br />

speak<strong>in</strong>g, <strong>the</strong> difference between <strong>the</strong> former and <strong>the</strong> latter is a matter <strong>of</strong> conve-<br />

nience, ra<strong>the</strong>r than expressivity. In general, abstract syntax trees and derivations<br />

can be represented by natural numbers via primitive recursive Gödel number<strong>in</strong>gs.<br />

49


Thus, manipulat<strong>in</strong>g well-formed terms and derivation trees via case-analysis and <strong>the</strong><br />

application <strong>of</strong> <strong>in</strong>ference rules can be formalized <strong>in</strong> PA1.<br />

We have taken <strong>the</strong> perspective that substitutions on higher-order derivations are<br />

a priori well-def<strong>in</strong>ed, or, alternatively, can be proven to be well-def<strong>in</strong>ed us<strong>in</strong>g syntac-<br />

tically f<strong>in</strong>itary methods. When manipulat<strong>in</strong>g <strong>the</strong> Gödel number<strong>in</strong>gs <strong>of</strong> hypo<strong>the</strong>tical<br />

judgments, we have no choice: substitution must be def<strong>in</strong>ed and reasoned about ex-<br />

plicitly. Fortunately, substitution is, <strong>in</strong> general, a primitive recursive operation, and<br />

thus can also be formalized <strong>in</strong> terms <strong>of</strong> Gödel numbers with<strong>in</strong> PA1.<br />

In general, we view <strong>the</strong> concept <strong>of</strong> <strong>in</strong>duction to be syntactically f<strong>in</strong>itary only<br />

when it is used to transform arbitrary terms/derivations <strong>of</strong> given syntactic cate-<br />

gories/judgments <strong>in</strong>to terms and derivations <strong>of</strong> potentially different forms. In o<strong>the</strong>r<br />

words, syntactically f<strong>in</strong>itary <strong>in</strong>ductions def<strong>in</strong>e functions from tuples <strong>of</strong> derivations to<br />

tuples <strong>of</strong> derivations. In <strong>the</strong> language <strong>of</strong> first-order arithmetic, this would correspond<br />

to prov<strong>in</strong>g a sentence <strong>of</strong> <strong>the</strong> follow<strong>in</strong>g form.<br />

∀x.x is a Gödel number<strong>in</strong>g for (D1, . . . , Dn) ⊃ ∃y.y is a Gödel number<strong>in</strong>g for (E1, . . . , Em)<br />

In general, such pro<strong>of</strong>s follow by <strong>in</strong>duction on x with an <strong>in</strong>duction hypo<strong>the</strong>sis <strong>of</strong> <strong>the</strong><br />

follow<strong>in</strong>g form, which is classically equivalent to a Σ1-predicate.<br />

x.(x is a Gödel number<strong>in</strong>g for (D1, . . . , Dn) ⊃ ∃y.y is a Gödel number<strong>in</strong>g for (E1, . . . , Em))<br />

Every pro<strong>of</strong> <strong>of</strong> every <strong>the</strong>orem <strong>in</strong> Chapters 1, 2, 4 and 5 follow this template, albeit<br />

for potentially different <strong>in</strong>stances <strong>of</strong> <strong>the</strong> <strong>in</strong>duction pr<strong>in</strong>ciple. Thus far, we have only<br />

allowed syntactically f<strong>in</strong>itary pro<strong>of</strong>s to use <strong>in</strong>duction metrics to be built up from<br />

lexicographic order<strong>in</strong>gs 3 applied subterm order<strong>in</strong>gs. Subterm order<strong>in</strong>gs have order-<br />

type at most ω, and lexicographic order<strong>in</strong>gs correspond to ord<strong>in</strong>al multiplication,<br />

3 Recall that any use <strong>of</strong> <strong>the</strong> simultaneous order<strong>in</strong>g can be replaced with a use <strong>of</strong> <strong>the</strong> lexicographic<br />

order<strong>in</strong>g.<br />

50


mean<strong>in</strong>g that any one syntactically f<strong>in</strong>itary pro<strong>of</strong> may use an <strong>in</strong>duction pr<strong>in</strong>ciple <strong>of</strong><br />

<strong>the</strong> form TI1(ω n ), and thus <strong>the</strong> class <strong>of</strong> syntactically f<strong>in</strong>itary pro<strong>of</strong>s use an <strong>in</strong>duction<br />

pr<strong>in</strong>ciple no stronger than TI1(ω ω ). This characterizes all <strong>of</strong> <strong>the</strong> pro<strong>of</strong>s <strong>of</strong> all <strong>of</strong> <strong>the</strong><br />

<strong>the</strong>orems <strong>in</strong> Chapter 2 and Chapter 5, save Theorem 5.2.62, which is modular <strong>in</strong> <strong>the</strong><br />

order type <strong>of</strong> its <strong>in</strong>duction metric. Thus, all such pro<strong>of</strong>s can be formalized <strong>in</strong> <strong>the</strong><br />

system PA1 + TI1(ω ω ).<br />

By Theorem 3.2.6, PA1 + TI1(ω ω ) is equivalent to PA2, which has a pro<strong>of</strong>-<br />

<strong>the</strong>oretic ord<strong>in</strong>al ωωω . With this <strong>in</strong> m<strong>in</strong>d, we can use Gödel’s second <strong>in</strong>completeness<br />

<strong>the</strong>orem along with some <strong>of</strong> <strong>the</strong> <strong>the</strong>orems <strong>of</strong> Section 3.2.2 to prove <strong>the</strong> follow<strong>in</strong>g<br />

<strong>the</strong>orem.<br />

Theorem 3.2.8 (The Outer Limits <strong>of</strong> <strong>Syntactic</strong> <strong>F<strong>in</strong>itism</strong>) The follow<strong>in</strong>g state-<br />

ments are true for <strong>the</strong> notion <strong>of</strong> syntactic f<strong>in</strong>itism <strong>in</strong> which <strong>in</strong>duction is restricted to<br />

lexicographic order<strong>in</strong>gs built from subterm order<strong>in</strong>gs.<br />

1. Any pro<strong>of</strong> <strong>of</strong> <strong>the</strong> consistency <strong>of</strong> first-order arithmetic is not syntactically f<strong>in</strong>i-<br />

tary.<br />

2. The function that realizes any syntactically f<strong>in</strong>itary pro<strong>of</strong> is majorized by h ω ω ω<br />

and fω ω.<br />

3. <strong>Syntactic</strong>ally f<strong>in</strong>itary methods cannot be used to provide a pro<strong>of</strong> <strong>of</strong> weak nor-<br />

malization for Gödel’s T.<br />

4. <strong>Syntactic</strong>ally f<strong>in</strong>itary methods cannot be used to provide a pro<strong>of</strong> <strong>of</strong> <strong>the</strong> Extrac-<br />

tion <strong>the</strong>orem for <strong>the</strong> assertion logic <strong>of</strong> Section 2.2.<br />

Pro<strong>of</strong>: 1 follows directly from Gödel’s second <strong>in</strong>completeness <strong>the</strong>orem. 2 is a direct<br />

application <strong>of</strong> Theorem 3.2.6. 3 follows from 2, Theorem 3.2.6 and Theorem 3.2.7. 4<br />

follows from 3 and <strong>the</strong> Fundamental Theorem and Escape Lemma <strong>of</strong> Section 2.2. <br />

51


In Chapter 4 we will see how extend<strong>in</strong>g <strong>the</strong> notion <strong>of</strong> syntactic f<strong>in</strong>itism to a<br />

stronger order<strong>in</strong>g can be used to overcome <strong>the</strong> limitations enumerated by Theo-<br />

rem 3.2.8.<br />

52


Chapter 4<br />

Lexicographic Path Induction<br />

Programm<strong>in</strong>g languages <strong>the</strong>ory is full <strong>of</strong> problems that reduce to prov<strong>in</strong>g <strong>the</strong> consis-<br />

tency <strong>of</strong> a logic. Although <strong>the</strong> pr<strong>in</strong>ciple <strong>of</strong> transf<strong>in</strong>ite <strong>in</strong>duction is rout<strong>in</strong>ely employed<br />

by logicians <strong>in</strong> prov<strong>in</strong>g such <strong>the</strong>orems, it is rarely used by programm<strong>in</strong>g languages re-<br />

searchers, who <strong>of</strong>ten prefer alternatives such as pro<strong>of</strong>s by logical relations and model<br />

<strong>the</strong>oretic constructions.<br />

This phenomenon can be expla<strong>in</strong>ed at least <strong>in</strong> part by <strong>the</strong> fact that ord<strong>in</strong>als<br />

can be notoriously tricky to work with, and are usually quite <strong>in</strong>convenient to def<strong>in</strong>e<br />

and manipulate syntactically (this is <strong>in</strong> large part due to <strong>the</strong> fact that most ord<strong>in</strong>al<br />

notation systems rely on a notion <strong>of</strong> equality that it much more sophisticated than<br />

syntactic equality). The Burali-Forti paradox illustrates that any ord<strong>in</strong>al notation<br />

system is necessarily <strong>in</strong>complete, and <strong>in</strong> practice, as ord<strong>in</strong>als get bigger, <strong>the</strong> notation<br />

systems needed to describe <strong>the</strong>m become more complex.<br />

In contrast, <strong>the</strong> lexicographic path order<strong>in</strong>g (LPO) is powerful (its order type<br />

approaches <strong>the</strong> small Veblen ord<strong>in</strong>al[DO88, Mos04]), is well understood by computer<br />

scientists and is easy to def<strong>in</strong>e and reason about syntactically. Fur<strong>the</strong>rmore, it has<br />

been used to prove <strong>the</strong> term<strong>in</strong>ation <strong>of</strong> term rewrit<strong>in</strong>g systems (TRSs) for decades,<br />

53


where, ironically, its considerable pro<strong>of</strong>-<strong>the</strong>oretic strength cannot be fully harnessed.<br />

In this chapter, we consider <strong>the</strong> effect <strong>of</strong> extend<strong>in</strong>g <strong>the</strong> notion <strong>of</strong> syntactic f<strong>in</strong>itism<br />

to allow <strong>in</strong>duction on <strong>the</strong> lexicographic path order<strong>in</strong>g, <strong>in</strong> much <strong>the</strong> same way that<br />

Gentzen considered <strong>the</strong> effect <strong>of</strong> extend<strong>in</strong>g <strong>the</strong> notion <strong>of</strong> f<strong>in</strong>itism to allow transf<strong>in</strong>ite<br />

<strong>in</strong>duction up to ε0.<br />

The LPO is more than strong enough to prove <strong>the</strong>orems such as cut elim<strong>in</strong>ation<br />

for Peano Arithmetic, Heyt<strong>in</strong>g Arithmetic, and weak normalization for Gödel’s T.<br />

Various cut-elim<strong>in</strong>ation and normalization procedures can <strong>of</strong>ten be expressed as term<br />

rewrit<strong>in</strong>g systems. Thus, one might hope to prove <strong>the</strong> weak normalization <strong>of</strong> Gödel’s<br />

T, or cut elim<strong>in</strong>ation for Heyt<strong>in</strong>g Arithmetic us<strong>in</strong>g <strong>the</strong> lexicographic path order<strong>in</strong>g<br />

to show <strong>the</strong> term<strong>in</strong>ation <strong>of</strong> such a TRS.<br />

However, this is impossible. The length <strong>of</strong> <strong>the</strong> reduction sequences <strong>in</strong> any TRS<br />

whose term<strong>in</strong>ation can be proven us<strong>in</strong>g <strong>the</strong> LPO are majorized by <strong>the</strong> Hardy hierar-<br />

chy at ω ωω<br />

(or, equivalently, <strong>the</strong> fast grow<strong>in</strong>g hierarchy at ω ω ) [Wei95]; because all<br />

<strong>of</strong> <strong>the</strong> functions from <strong>the</strong> Hardy hierarchy (and fast grow<strong>in</strong>g hierarchy) at ord<strong>in</strong>als<br />

less than ε0 can be implemented <strong>in</strong> Gödel’s T, <strong>the</strong> normalization <strong>of</strong> Gödel’s T cannot<br />

be proved by formulat<strong>in</strong>g it as a TRS whose term<strong>in</strong>ation is shown us<strong>in</strong>g <strong>the</strong> LPO.<br />

Moreover, if <strong>the</strong> rules <strong>of</strong> a TRS can be shown to be reduc<strong>in</strong>g us<strong>in</strong>g <strong>the</strong> LPO, <strong>the</strong>n <strong>the</strong><br />

result<strong>in</strong>g term<strong>in</strong>ation pro<strong>of</strong> can be modified modified such that it is valid <strong>in</strong> a frag-<br />

ment <strong>of</strong> Peano Arithmetic where <strong>in</strong>duction is restricted to Π2-predicates (i.e. PA2)<br />

[Buc95]. By Gödel’s second <strong>in</strong>completeness <strong>the</strong>orem, one cannot prove <strong>the</strong> consis-<br />

tency <strong>of</strong> arithmetic from with<strong>in</strong> a fragment <strong>of</strong> arithmetic, <strong>the</strong>refore a cut-elim<strong>in</strong>ation<br />

procedure for arithmetic cannot be shown to be term<strong>in</strong>at<strong>in</strong>g by formulat<strong>in</strong>g as a TRS<br />

whose rules are reduc<strong>in</strong>g accord<strong>in</strong>g to <strong>the</strong> LPO.<br />

However, it is possible to harness <strong>the</strong> strength <strong>of</strong> <strong>the</strong> LPO as an <strong>in</strong>duction pr<strong>in</strong>ci-<br />

ple that we call lexicographic path <strong>in</strong>duction, which comb<strong>in</strong>es <strong>the</strong> comfort <strong>of</strong> structural<br />

54


<strong>in</strong>duction with <strong>the</strong> expressive strength <strong>of</strong> transf<strong>in</strong>ite <strong>in</strong>duction. In [SS09], a novel con-<br />

sistency pro<strong>of</strong> by lexicographic path <strong>in</strong>duction was given for an <strong>in</strong>tuitionistic <strong>the</strong>ory<br />

<strong>of</strong> <strong>in</strong>ductive def<strong>in</strong>itions, based on <strong>the</strong> system by Mart<strong>in</strong>-Löf [ML71] that <strong>in</strong>spired<br />

<strong>the</strong> def<strong>in</strong>ition <strong>of</strong> <strong>in</strong>ductive types <strong>in</strong> type <strong>the</strong>ory [Dyb91, PM93], and several sequent<br />

calculi <strong>in</strong> <strong>the</strong> programm<strong>in</strong>g languages literature [MM00, MT03, Bro06, GMN08], and<br />

can be <strong>in</strong>stantiated to a version <strong>of</strong> Heyt<strong>in</strong>g Arithmetic. Here, we apply <strong>the</strong> same tech-<br />

nique to prove <strong>the</strong> extraction <strong>the</strong>orem for <strong>the</strong> assertion logic described <strong>in</strong> Section 2.2,<br />

thus complet<strong>in</strong>g <strong>the</strong> pro<strong>of</strong> <strong>of</strong> <strong>the</strong> weak normalization <strong>of</strong> Gödel’s T. This pro<strong>of</strong> has<br />

been formalized <strong>in</strong> a prototypical extension <strong>of</strong> Twelf (http://www.twelf.org/lpo/)<br />

provid<strong>in</strong>g empirical evidence for <strong>the</strong> usefulness <strong>of</strong> lexicographic path <strong>in</strong>duction.<br />

4.1 The Lexicographic Path Order<strong>in</strong>g<br />

The lexicographic path order<strong>in</strong>g (LPO) provides a modular way <strong>of</strong> specify<strong>in</strong>g order-<br />

<strong>in</strong>gs on f<strong>in</strong>ite labeled trees whose constructors have fixed arity.<br />

Given a f<strong>in</strong>ite signature Σ <strong>of</strong> fixed arity constructors (not to be confused with<br />

<strong>the</strong> notion <strong>of</strong> signature to be <strong>in</strong>troduced <strong>in</strong> Chapter 5), whose elements we denote<br />

generically by <strong>the</strong> letters f and g, labeled trees are def<strong>in</strong>ed formally as follows<br />

Labeled Trees s, t ::= f(s1, . . . , sn)<br />

where <strong>the</strong> arity <strong>of</strong> f, denoted #f, is n for n ≥ 0, and (s1, . . . , sn) is <strong>in</strong>formal shorthand<br />

for a list <strong>of</strong> length n whose (dependent) BNF-style def<strong>in</strong>ition we omit for <strong>the</strong> sake <strong>of</strong><br />

readability. We use Σ n to denote <strong>the</strong> constructors <strong>of</strong> Σ <strong>of</strong> arity n. Although signatures<br />

can <strong>in</strong> pr<strong>in</strong>ciple be <strong>in</strong>f<strong>in</strong>ite, all <strong>of</strong> <strong>the</strong> signatures considered <strong>in</strong> this dissertation are<br />

f<strong>in</strong>ite. In pr<strong>in</strong>ciple, <strong>the</strong> labeled trees described by a signature Σ could be def<strong>in</strong>ed<br />

55


us<strong>in</strong>g a non-dependent, non-hypo<strong>the</strong>tical BNF-style def<strong>in</strong>ition.<br />

Def<strong>in</strong>ition 4.1.1 (Lexicographic Path Order<strong>in</strong>g) Given a precedence relation<br />

< on Σ we def<strong>in</strong>e


(Big head) If s = f(s1 , . . . , sn), g1 < f, . . . , gm < f and t is built up from s1 , . . . , sn<br />

and g1 , . . . , gm <strong>the</strong>n t


4.2 The Extraction Pro<strong>of</strong><br />

We give now <strong>the</strong> pro<strong>of</strong> <strong>of</strong> <strong>the</strong> Extraction Theorem, where we reason about derivations<br />

<strong>of</strong> <strong>the</strong> form D : (· ⊢ cut<br />

hc(e τ )) us<strong>in</strong>g lexicographic path <strong>in</strong>duction. Although pro<strong>of</strong><br />

terms are <strong>in</strong> a sense f<strong>in</strong>ite trees, we do not apply lexicographic path <strong>in</strong>duction to <strong>the</strong>m<br />

directly because pro<strong>of</strong> terms conta<strong>in</strong> <strong>in</strong>formation that we do not consider relevant<br />

to <strong>the</strong> size <strong>of</strong> a pro<strong>of</strong>. Instead, we apply <strong>the</strong> pr<strong>in</strong>ciple to skeletons <strong>of</strong> pro<strong>of</strong> trees,<br />

which will be def<strong>in</strong>ed <strong>in</strong> 4.2.2; lexicographic path <strong>in</strong>duction on skeletons subsumes<br />

structural <strong>in</strong>duction on pro<strong>of</strong> trees.<br />

In many ways, our pro<strong>of</strong> follows <strong>the</strong> same general structure as Gentzen’s later<br />

pro<strong>of</strong> <strong>of</strong> <strong>the</strong> consistency <strong>of</strong> arithmetic [Gen38], and <strong>the</strong> Howard [How70] and Schütte<br />

[Sch77] pro<strong>of</strong>s <strong>of</strong> normalization for Gödel’s T. All <strong>in</strong>volve assign<strong>in</strong>g well-founded<br />

order<strong>in</strong>gs to pro<strong>of</strong> trees/λ-calculus terms (ɛ0 for Gentzen, Howard and Schütte, <strong>the</strong><br />

LPO here) and all unfold <strong>in</strong>ductions all-at-once, ra<strong>the</strong>r than one-at-a-time. Like<br />

Gentzen’s pro<strong>of</strong>, we demonstrate normalization for a restricted class <strong>of</strong> sequents<br />

(· ⊢ cut<br />

· for Gentzen, Ψ ⊢ cut<br />

hc(e τ ) whenever Ψ varctx here). Our pro<strong>of</strong> differs from<br />

<strong>the</strong> o<strong>the</strong>rs <strong>in</strong> that lexicographic path <strong>in</strong>duction is applied directly to skeletons <strong>of</strong><br />

pro<strong>of</strong> terms, whereas <strong>in</strong> Gentzen’s, Howard’s and Schütte’s pro<strong>of</strong>s, <strong>the</strong> assignment<br />

<strong>of</strong> ord<strong>in</strong>als to pro<strong>of</strong>s/λ-calculus terms is very complex. This discrepancy shouldn’t<br />

be too surpris<strong>in</strong>g: <strong>the</strong> order type <strong>of</strong> <strong>the</strong> lexicographic path order<strong>in</strong>g approaches <strong>the</strong><br />

small Veblen ord<strong>in</strong>al [DO88, Mos04], which is MUCH larger than ɛ0; it is <strong>of</strong>ten <strong>the</strong><br />

case that us<strong>in</strong>g stronger-than-necessary assumptions leads to simpler pro<strong>of</strong>s.<br />

4.2.1 Pro<strong>of</strong> Terms<br />

In order to def<strong>in</strong>e our pro<strong>of</strong>, we f<strong>in</strong>d it convenient to manipulate pro<strong>of</strong> terms written<br />

<strong>in</strong> BNF-style, as def<strong>in</strong>ed below. As we have already seen, <strong>the</strong> dist<strong>in</strong>ction between<br />

58


<strong>the</strong> two styles <strong>of</strong> def<strong>in</strong>ition is largely a matter <strong>of</strong> notational preference. As usual, we<br />

will omit dependency superscripts when <strong>the</strong>y are easily <strong>in</strong>ferred or irrelevent.<br />

C F , D F , E F ::= (axiom h F ) F | (cut C F (h F .D G )) G | (andr C F D G ) F ∧G |<br />

(andl1 (h F1 .C G ) h ′F1∧F2 ) G | (andl2 (h F2 .C G ) h ′F1∧F2 ) G |<br />

(impr (h F .C G )) F ⊃G | (impl C F1 (h F2 .D G ) h ′F1⊃F2 ) G |<br />

(allr (x τ .C F )) ∀xτ F | (alll (h F [t τ /x τ ] .C G ) h ′∀x τ .F ) G | hc-z hc(z o ) |<br />

(hc-s C hc(eo ) ) hc(s e o ) | (hc-arr (x τ .v x τ<br />

.C hc(app eτ⇒σ x τ ) )) hc(e τ⇒σ ) |<br />

(hc-wh C wh(eo ,e ′o ) D hc(e ′o ) ) hc(e o ) | (hc-atm C ha(e o ) ) hc(e o ) |<br />

(hcl D P (zo )<br />

0<br />

(x o .h P (xo ) .D P (s x o )<br />

1<br />

(x o .y o .h wh(xo ,y o )<br />

1<br />

.h P (yo )<br />

2<br />

) (xo .hha(xo ) P (x<br />

.D o )<br />

2<br />

.D P (xo )<br />

3<br />

) (h P (eo ) .E F ) h ′hc(e o ) ) F |<br />

(ha-var xτ vxτ ) ha(xτ ) | (ha-app Chaσ⇒τ (e) Dhcσ (e ′ ) ) haτ (app e e ′ ) |<br />

(ha-r C hcτ⇒o⇒τ (e1) D hc τ (e2) E ha o (e3) ) ha τ (rτ e1 e2 e3) |<br />

wh-beta wh(app (lam x. e1) e2,e1[e2/x]) |<br />

(wh-app C wh(e1,e ′ 1 ) ) wh(app e1 e2,app e ′ 1 e2) |<br />

wh-rz wh((rτ e1 e2 z o ),e1) |<br />

wh-rs wh((rτ e1 e2 (s e3)),(app (app e2 (rτ e1 e2 e3)) e3)) |<br />

(wh-rc C wh(e3,e ′ 3 ) ) wh(rτ e1 e2 e3,rτ e1 e2 e ′ 3 )<br />

The follow<strong>in</strong>g def<strong>in</strong>ition helps us to summarize <strong>the</strong> equivalence between <strong>the</strong> pro<strong>of</strong><br />

terms as written above, and derivation trees.<br />

Def<strong>in</strong>ition 4.2.1 (Compatible Pro<strong>of</strong> Terms) A pro<strong>of</strong> term C F is compatible<br />

with Ψ iff every free x τ , v xτ<br />

and h F is declared <strong>in</strong> Ψ. This notion <strong>of</strong> compatibil-<br />

ity can be formalized us<strong>in</strong>g a judgment <strong>of</strong> <strong>the</strong> form Ψ ⊢ C F ; we omit <strong>the</strong> <strong>in</strong>ference<br />

rules for <strong>the</strong> sake <strong>of</strong> brevity.<br />

Lemma 4.2.2 Every derivation D : (Ψ ⊢ cut<br />

compatible with Ψ, and vice versa.<br />

F ) is isomorphic to some D F which is<br />

Pro<strong>of</strong>: By straightforward <strong>in</strong>duction. <br />

59<br />

)


Lemma 4.2.2 justifies treat<strong>in</strong>g pro<strong>of</strong> terms D : (Ψ ⊢ F ) and pro<strong>of</strong> derivations that<br />

satisfy Ψ ⊢ D F <strong>in</strong>terchangeably, without loss <strong>of</strong> generality.<br />

The follow<strong>in</strong>g def<strong>in</strong>ition plays an important role <strong>in</strong> our pro<strong>of</strong> <strong>of</strong> extraction.<br />

Def<strong>in</strong>ition 4.2.3 (Right Normal) We say that a derivation D : (Ψ ⊢ cut<br />

F ) (or <strong>the</strong><br />

equivalent pro<strong>of</strong> term D F ) is right normal iff it conta<strong>in</strong>s only right-rules. We can<br />

formulate <strong>the</strong> concept <strong>of</strong> right normal judgmentally, but omit its <strong>in</strong>ference rules for<br />

<strong>the</strong> sake <strong>of</strong> brevity.<br />

We are <strong>in</strong>terested mostly <strong>in</strong> right-normal pro<strong>of</strong>s <strong>of</strong> atomic formulas for <strong>the</strong> sake <strong>of</strong><br />

our pro<strong>of</strong> <strong>of</strong> <strong>the</strong> Extraction <strong>the</strong>orem. The follow<strong>in</strong>g lemma helps expla<strong>in</strong> why we are<br />

justified <strong>in</strong> th<strong>in</strong>k<strong>in</strong>g <strong>of</strong> <strong>the</strong> rule hcl as be<strong>in</strong>g an iterator over (right-normal) pro<strong>of</strong> <strong>of</strong><br />

hc(e τ ).<br />

Lemma 4.2.4 (Fold<strong>in</strong>g Right-Normal Pro<strong>of</strong>s) For every right-normal C : (Ψ ⊢ cut<br />

hc(e τ )) and every D0 : (Ψ ⊢ cut<br />

D2 : (Ψ, x o , h ha(xo ) ⊢ cut<br />

P (z o )) and D1 : (Ψ, x o , h P (xo ) ⊢ cut<br />

P (xo )) and D3 : (Ψ, xo , yo , h wh(xo ,yo )<br />

1 , h P (yo )<br />

2<br />

⊢ cut<br />

P (s x o )) and<br />

P (x o )) <strong>the</strong>re<br />

exists E : (Ψ ⊢ P (e τ )) such that E is built up us<strong>in</strong>g only <strong>in</strong>stances <strong>of</strong> D0, D1, D2 and<br />

D3 under substitutions, and <strong>the</strong> cut rule.<br />

Pro<strong>of</strong>: By straightforward <strong>in</strong>duction on C. The pro<strong>of</strong> can be realized by a function<br />

on pro<strong>of</strong> terms, which can be expressed us<strong>in</strong>g <strong>the</strong> follow<strong>in</strong>g judgment.<br />

fold-hc C D0 (x.h.D1) (x.h.D2) (x.y.h1.h2.D3) = E<br />

60


We def<strong>in</strong>e <strong>the</strong> <strong>in</strong>ference rules for fold-hc below.<br />

fold-hc hc-z D0 (x.h.D1) (x.h.D2) (x.y.h1.h2.D3) = D0<br />

fold-hc C D0 (x.h.D1) (x.h.D2) (x.y.h1.h2.D3) = E<br />

fold-hc (hc-s C hc(e) ) D0 (x.h.D1) (x.h.D2) (x.y.h1.h2.D3) = cut E (h.D1[e/x])<br />

fold-hc (hc-atm C ha(e) ) D0 (x.h.D1) (x.h.D2) (x.y.h1.h2.D3) = cut C ha(e) (h.D2[e/x])<br />

fold-hc C hc(e′ )<br />

1<br />

D0 (x.h.D1) (x.h.D2) (x.y.h1.h2.D3) = E<br />

fold-hc (hc-wh C wh(e,e′ )<br />

0 Chce′ 1 ) D0 (x.h.D1) (x.h.D2) (x.y.h1.h2.D3)<br />

= cut C wh(e,e′ )<br />

0 (h0.cut E (h1.D3[e/x][e ′ /y]))<br />

The pro<strong>of</strong> that fold-hc is a function (i.e. its effectiveness lemma) has essentially <strong>the</strong><br />

same structure as <strong>the</strong> pro<strong>of</strong> that fold-hc is meant to represent. <br />

4.2.2 Order<strong>in</strong>g Pro<strong>of</strong> Terms<br />

Although pro<strong>of</strong> terms conta<strong>in</strong> <strong>the</strong> same amount <strong>of</strong> <strong>in</strong>formation as pro<strong>of</strong> trees, we do<br />

not consider all <strong>of</strong> this <strong>in</strong>formation to be relevant to <strong>the</strong> size <strong>of</strong> pro<strong>of</strong>s. In particular,<br />

we do not consider <strong>the</strong> “size” <strong>of</strong> hypo<strong>the</strong>ses or λ-calculus terms to be relevant, nor,<br />

with <strong>the</strong> notable exception <strong>of</strong> cut, do we consider formulas or predicates relevant.<br />

We also do not consider dependency <strong>in</strong>formation to be relevant to <strong>the</strong> size <strong>of</strong> pro<strong>of</strong><br />

terms. Therefore, we map pro<strong>of</strong> terms <strong>in</strong>to labeled trees, called skeletons, which are<br />

obta<strong>in</strong>ed from pro<strong>of</strong> terms by stripp<strong>in</strong>g spurious <strong>in</strong>formation. Because we consider<br />

<strong>the</strong> size <strong>of</strong> cut-formulas to be relevant to <strong>the</strong> size <strong>of</strong> pro<strong>of</strong>s (as is <strong>of</strong>ten <strong>the</strong> case <strong>in</strong> cut-<br />

elim<strong>in</strong>ation-like <strong>the</strong>orems), skeletons are def<strong>in</strong>ed for formulas as well. The signature<br />

Σ for skeletons is def<strong>in</strong>ed as follows. Note <strong>the</strong> use <strong>of</strong> <strong>the</strong> sans-serif font to dist<strong>in</strong>guish<br />

61


skeletons from pro<strong>of</strong> terms.<br />

Σ 0 = hc, ha, wh, axiom, hc-z, ha-var, wh-beta, wh-rz, wh-rs<br />

Σ 1 = all, andl1, andl2, impr, allr, alll, hc-s, hc-arr, hc-atm, wh-app, wh-rc<br />

Σ 2 = and, imp, andr, impl, hc-wh, ha-app<br />

Σ 3 = cut, ha-r<br />

Σ 5 = hcl<br />

We def<strong>in</strong>e <strong>the</strong> stripp<strong>in</strong>g functions [F ] = s and [C F ] = s below. As usual, we view<br />

<strong>the</strong> system <strong>of</strong> equations as shorthand for a judgmental def<strong>in</strong>ition, whose <strong>in</strong>terpreta-<br />

tion as a determ<strong>in</strong>istic function follows from a straightforward <strong>in</strong>duction.<br />

62


[hc(e τ )] = hc [ha(e τ )] = ha<br />

[wh(e τ , e ′τ )] = wh [F ∧ G] = and([F], [G])<br />

[F ⊃ G] = imp([F], [G]) [∀x τ .F ] = all([F ])<br />

[axiom h] = axiom [cut C F (h F .D)] = cut([F ], [C ], [D ])<br />

[andr C D ] = andr([C ], [D ]) [[andl1 (h.C) h ′ ] = andl1([C ])<br />

[andl2 (h.C) h ′ ] = andl2([C ]) [impr (h.C)] = impr([C ])<br />

[impl C (h.D) h ′ ] = impl([C ], [D ]) [allr x τ .C ] = allr([C ])<br />

[alll (h.C) h ′ ] = alll([C ]) [hc-z] = hc-z<br />

[hc-s C ] = hc-s([C ]) [hc-arrx.v.C ] = hc-arr([C ])<br />

[hc-wh C D ] = hc-wh([C ], [D ]) [hc-atm C ] = hc-atm([C ])<br />

[ha-var x v ] = ha-var [ha-app C D ] = ha-app([C ], [D ])<br />

[ha-r C D E ] = ha-r([C ], [D ], [E ]) [[wh-beta] = wh-beta<br />

[wh-app C ] = wh-app([C ]) [wh-rz] = wh-rz<br />

[wh-rs] = wh-rs [wh-rc C ] = wh-rc([C ])<br />

[hcl D0 (x.h.D1) (x.h.D2) (x.y.h1.h2.D3) (h.E) h ′ ] = hcl([D0 ], [D1 ], [D2 ], [D3 ], [E ])<br />

We def<strong>in</strong>e <strong>the</strong> precedence order<strong>in</strong>g on skeletons as follows, which will <strong>the</strong>n be<br />

lifted to an order<strong>in</strong>g on f<strong>in</strong>ite trees via <strong>the</strong> lexicographic path order<strong>in</strong>g. Note that we<br />

adopt <strong>the</strong> standard dist<strong>in</strong>ction between atomic and compound formulas, which will<br />

play an important role <strong>in</strong> our pro<strong>of</strong>; to elim<strong>in</strong>ate <strong>the</strong> possibility <strong>of</strong> any ambiguity, we<br />

63


formalize this notion us<strong>in</strong>g <strong>the</strong> judgments below.<br />

hc τ (e) atomic ha τ (e) atomic wh τ (e, e ′ ) atomic<br />

F ∧ G compound F ⊃ G compound ∀x τ .F compound<br />

Def<strong>in</strong>ition 4.2.5 (Skeleton Order<strong>in</strong>g) We def<strong>in</strong>e < as <strong>the</strong> least transitive order-<br />

<strong>in</strong>g on <strong>the</strong> elements <strong>of</strong> Σ satisfy<strong>in</strong>g all <strong>of</strong> <strong>the</strong> follow<strong>in</strong>g:<br />

1. If f corresponds to an atomic formula (i.e. it is one <strong>of</strong> hc, ha or wh) and g<br />

corresponds to a logical connective (i.e. it is <strong>of</strong> <strong>the</strong> form and, imp or all) <strong>the</strong>n<br />

f < g<br />

2. If f corresponds to a formula, and g corresponds to a pro<strong>of</strong> rule, <strong>the</strong>n f < g<br />

3. If f corresponds to a right-rule or a compound left-rule <strong>the</strong>n f < cut<br />

4. cut < hcl<br />

5. If f corresponds to an atomic right-rule, <strong>the</strong>n f < axiom<br />


3. For every C, every t and every x, [C ] = [C[t/x]]<br />

Pro<strong>of</strong>: Each case is straightforward by structural <strong>in</strong>duction; both 1 and 2 are <strong>in</strong>-<br />

stances <strong>of</strong> <strong>the</strong> big head pr<strong>in</strong>ciple. <br />

Because <strong>the</strong> LPO has <strong>the</strong> subterm property, and because skeletons conta<strong>in</strong> most <strong>of</strong><br />

<strong>the</strong> structural <strong>in</strong>formation <strong>of</strong> pro<strong>of</strong> terms, all <strong>of</strong> <strong>the</strong> <strong>in</strong>stances <strong>of</strong> structural <strong>in</strong>duction<br />

on C <strong>in</strong> this chapter can be replaced by lexicographic path <strong>in</strong>duction on [C ].<br />

4.2.3 The Normalization Procedure<br />

Our pro<strong>of</strong> is structured as follows. Consider Ψ ⊢ C F , where Ψ is a variable context<br />

(see Def<strong>in</strong>ition 2.1.1) and F is an atomic formula: our goal is to f<strong>in</strong>d a right normal<br />

form for C F . In this situation, C F must ei<strong>the</strong>r be an atomic right rule applied<br />

to subderivations C F0<br />

0 , . . . , C Fn<br />

n , where each Fi is also atomic, or C F is <strong>of</strong> <strong>the</strong> form<br />

cut D G h G .E F . In <strong>the</strong> former case, we right-normalize C F1<br />

1 , . . . , C Fn<br />

n and apply <strong>the</strong><br />

same atomic right rule to <strong>the</strong> result. In <strong>the</strong> latter case, we must f<strong>in</strong>d a pro<strong>of</strong> term C ′F<br />

which is smaller than C F , and right-normalize C ′F by <strong>in</strong>duction. In this case, <strong>the</strong><br />

calculation <strong>of</strong> C ′F depends on whe<strong>the</strong>r <strong>the</strong> cut-formula G is atomic or compound.<br />

Observe that, if G is atomic, <strong>the</strong>n, by <strong>in</strong>duction, we can right-normalize D G <strong>in</strong>to<br />

D ′G ; C ′ is obta<strong>in</strong>ed by elim<strong>in</strong>at<strong>in</strong>g all uses <strong>of</strong> h G from h G .E F , mak<strong>in</strong>g use <strong>of</strong> D ′G and<br />

Lemma 4.2.4. If G is compound, we perform what is essentially a small-step version<br />

<strong>of</strong> <strong>the</strong> cut-admissibility pro<strong>of</strong> <strong>in</strong> [Pfe95], where, for reasons that will be expla<strong>in</strong>ed<br />

later, we must be careful to avoid any “commutative conversions” for hcl.<br />

In <strong>the</strong> follow<strong>in</strong>g lemmas, note that apply<strong>in</strong>g <strong>the</strong> structural properties such weak-<br />

en<strong>in</strong>g and exchange (see Lemma 2.2.2) to a derivation <strong>of</strong> Ψ ⊢ C F will result <strong>in</strong> a<br />

derivation <strong>of</strong> Ψ ′ ⊢ C F , where <strong>the</strong> underly<strong>in</strong>g structure <strong>of</strong> C F is unchanged.<br />

65


Lemma 4.2.7 (Atomic Cut Reduction) For every C F and h F .D G , if F is atomic<br />

and C F is right-normal and Ψ ⊢ C F and Ψ, h F ⊢ D G , <strong>the</strong>n <strong>the</strong>re exists E G such that<br />

Ψ ⊢ E G and [E G ]≤lpo [D G ].<br />

Pro<strong>of</strong>: By structural <strong>in</strong>duction on D G . Most cases are straightforward, <strong>of</strong>ten us<strong>in</strong>g<br />

weaken<strong>in</strong>g and exchange before apply<strong>in</strong>g <strong>the</strong> <strong>in</strong>duction hypo<strong>the</strong>sis, and us<strong>in</strong>g mono-<br />

tonicity <strong>of</strong>


We list some representative cases <strong>of</strong> redA’s <strong>in</strong>ference rules below.<br />

redA C F (h F .axiom h F ) = C F<br />

redA C F (h F .axiom h ′G ) = axiom h ′G<br />

redA C hc(eτ ) (h hc(e τ ) .D0) = D ′ 0 redA Chc(eτ ) (h hc(e τ ) .D1) = D ′ 1<br />

redA Chc(eτ ) (hhc(eτ ) .D2) = D ′ 2 redA Chc(eτ ) (hhc(eτ ) .D3) = D ′ 3<br />

redA Chc(eτ ) (hhc(eτ ) .DG 4 ) = D ′G<br />

4<br />

fold-hc Chc(eτ )<br />

D0 (x.h ′ .D ′ 1 ) (x.h′ .D ′ 2 ) (x.y.h1.h2.D ′ 3 ) = EP (eτ )<br />

redA C hc(eτ ) (h hc(e τ ) .hcl D0 (x.h ′ .D1) (x.h ′ .D2) (x.y.h1.h2.D3) (h ′P (eτ ) .D G 4 ) h hc(eτ ) )<br />

= cut E P (eτ ) (h ′P (e τ ) .D ′G<br />

4 )<br />

redA C F (h F .D0) = D ′ 0 redA CF (h F .D1) = D ′ 1<br />

redA C F (h F .D2) = D ′ 2 redA CF (h F .D3) = D ′ 3<br />

redA C F (h F .D G 4<br />

) = D′G<br />

4<br />

redA C F (h F .hcl D0 (x.h ′ .D1) (x.h ′ .D2) (x.y.h1.h2.D3) (h ′P (eτ ) .D G 4 ) h ′′hc(eτ ) )<br />

= hcl D ′ 0 (x.h′ .D ′ 1 ) (x.h′ .D ′ 2 ) (x.y.h1.h2.D ′ 3 ) (h′P (eτ ) .D ′G<br />

4 ) h ′′hc(eτ )<br />

The follow<strong>in</strong>g def<strong>in</strong>ition will play an important role <strong>in</strong> show<strong>in</strong>g that compound<br />

cuts can be reduced: because we will only need to reduce such pro<strong>of</strong> terms <strong>in</strong> contexts<br />

that only conta<strong>in</strong> compound formulas, we will not be forced to consider so-called left-<br />

commutative conversions on hcl. The significance <strong>of</strong> this fact will be expounded upon<br />

<strong>in</strong> <strong>the</strong> pro<strong>of</strong> <strong>of</strong> Lemma 4.2.9.<br />

Def<strong>in</strong>ition 4.2.8 (Compound Context) A context Ψ is compound iff, for every<br />

h F ∈ Ψ, F is a compound formula. This can be formalized judgmentally us<strong>in</strong>g <strong>the</strong><br />

<strong>in</strong>ference rules below.<br />

· compound Ψ, x τ compound<br />

Ψ compound<br />

Ψ, v xτ<br />

compound<br />

Ψ compound<br />

Ψ, x τ compound<br />

Ψ compound F compound<br />

67<br />

Ψ, h F compound


Lemma 4.2.9 (Compound Cut Reduction) If Ψ compound and Ψ ⊢ cut C F (h F .D G )<br />

<strong>the</strong>n <strong>the</strong>re exists an E G such that Ψ ⊢ E G and [E F ]


If C F or D G is a compound cut, we apply <strong>the</strong> <strong>in</strong>duction hypo<strong>the</strong>sis and mono-<br />

tonicity <strong>of</strong>


Pro<strong>of</strong>: By lexicographic path <strong>in</strong>duction on [C F ]. The extraction <strong>the</strong>orem can be<br />

realized by a function on pro<strong>of</strong> terms, which can be expressed as <strong>the</strong> follow<strong>in</strong>g judg-<br />

ment.<br />

extract C F = D F<br />

We give some representative cases <strong>of</strong> <strong>the</strong> <strong>in</strong>ference rules for extract below.<br />

F compound redC (cut C F (h F .D)) = E extract E = E ′<br />

extract (cut C F (h F .D)) = E ′<br />

F atomic redA C F (h F .D) = E extract E = E ′<br />

extract C = C ′ extract D = D ′<br />

extract (hc-wh C D) = (hc-wh C ′ D ′ )<br />

extract (cut C F (h F .D)) = E ′<br />

extract C = D<br />

extract (hc-arr x.v.C) = (hc-arr x.v.D)<br />

extract C1 = C ′ 1 extract C2 = C ′ 2 extract C3 = C ′ 3<br />

extract (ha-r C1 C2 C3) = (ha-r C ′ 1 C ′ 2 C ′ 3)<br />

70


Chapter 5<br />

Pro<strong>of</strong>s as Logic Programs<br />

In Section 3.2.3, we saw that any syntactically f<strong>in</strong>itary pro<strong>of</strong> can be represented as a<br />

number-<strong>the</strong>oretic function that is provably total <strong>in</strong> a fragment <strong>of</strong> Peano Arithmetic.<br />

Although this characterization is useful for calculat<strong>in</strong>g bounds on <strong>the</strong> expressivity<br />

<strong>of</strong> syntactic f<strong>in</strong>itism—fragments <strong>of</strong> first-order arithmetic have been well studied by<br />

pro<strong>of</strong> <strong>the</strong>orists—it is not a very satisfy<strong>in</strong>g formalization. This is partly due to <strong>the</strong><br />

fact that Peano Arithmetic is a classical <strong>the</strong>ory 1 , although <strong>in</strong> pr<strong>in</strong>ciple this compla<strong>in</strong>t<br />

can be ameliorated by not<strong>in</strong>g that <strong>the</strong> provably total functions <strong>of</strong> Heyt<strong>in</strong>g and Peano<br />

arithmetic are one and <strong>the</strong> same. More fundamentally, Gödel number<strong>in</strong>g is simply<br />

too clumsy a tool to represent basic syntactic manipulations with <strong>the</strong> gracefulness<br />

<strong>the</strong>y deserve.<br />

In this chapter, we aim to give a more syntactic formalization <strong>of</strong> <strong>the</strong> nature <strong>of</strong><br />

syntactically f<strong>in</strong>itary pro<strong>of</strong>s. We beg<strong>in</strong> with <strong>the</strong> aforementioned observation: syntac-<br />

tically f<strong>in</strong>itary pro<strong>of</strong>s are all essentially first-order functions from tuples <strong>of</strong> derivations<br />

to tuples <strong>of</strong> derivations. The def<strong>in</strong><strong>in</strong>g equations for such functions can be represented<br />

1 <strong>Syntactic</strong> f<strong>in</strong>itism is <strong>in</strong>tended characterize a lower bound on <strong>the</strong> reason<strong>in</strong>g pr<strong>in</strong>ciples generally<br />

accepted by programm<strong>in</strong>g languages researchers, many <strong>of</strong> whom consider <strong>the</strong> law <strong>of</strong> excluded middle<br />

to be controversial.<br />

71


judgmentally <strong>in</strong> <strong>the</strong> same manner as any o<strong>the</strong>r function; we have already seen several<br />

examples <strong>in</strong> Chapter 4. Recall that we consider a judgment J〈<strong>in</strong>puts; outputs〉—<br />

where <strong>in</strong>puts and outputs are names for <strong>the</strong> syntactic categories that J depends<br />

on—to represent a function from <strong>in</strong>puts to outputs if, and only if, it passes <strong>the</strong><br />

follow<strong>in</strong>g test: given concrete terms t<strong>in</strong> from <strong>the</strong> syntactic categories <strong>of</strong> <strong>in</strong>puts, we<br />

can always f<strong>in</strong>d a concrete terms tout from <strong>the</strong> syntactic categories <strong>of</strong> outputs and a<br />

derivation <strong>of</strong> D : J〈t<strong>in</strong>; tout〉. One especially natural way to f<strong>in</strong>d tout and D given t<strong>in</strong><br />

is to perform a depth-first search on derivations.<br />

For example, given <strong>the</strong> <strong>in</strong>puts s z and s z for <strong>the</strong> judgment ack def<strong>in</strong>ed <strong>in</strong> Sec-<br />

tion 1.2, we might represent <strong>the</strong> search problem “can we f<strong>in</strong>d an n such that ack(s z; s z; n)<br />

is <strong>in</strong>habited?” us<strong>in</strong>g <strong>the</strong> follow<strong>in</strong>g notation.<br />

D : ack(s z; s z; n )<br />

Intuitively, boxes are <strong>in</strong>tended to represent holes <strong>in</strong> <strong>the</strong> derivation, where depth-first<br />

search is used to fill <strong>the</strong>m. We can model <strong>the</strong>se holes us<strong>in</strong>g hypo<strong>the</strong>tical variables<br />

that we refer to as logic variables.<br />

Of <strong>the</strong> <strong>in</strong>ference rules for ack, only <strong>the</strong> rule ackss can possibly be used to fill<br />

a hole <strong>of</strong> <strong>the</strong> above form. We proceed by fill<strong>in</strong>g <strong>in</strong> D with ackss, result<strong>in</strong>g <strong>in</strong> a<br />

derivation with some new holes.<br />

D0 : (ack(s z; z; m )) D1 : (ack(z; m ; n ))<br />

ack(s z; s z; n )<br />

We proceed by consider<strong>in</strong>g <strong>the</strong> left-most derivation hole D0 . Here, <strong>the</strong> only eligible<br />

rule is acksz; us<strong>in</strong>g it results <strong>in</strong> <strong>the</strong> search state represented below. In this particular<br />

situation, we could have just as easily proceeded by fill<strong>in</strong>g D1 , but we consider<br />

do<strong>in</strong>g so to be ill-advised because one <strong>of</strong> its <strong>in</strong>put arguments is a logic variable. In<br />

general, we only require search to be well-behaved when all <strong>of</strong> <strong>the</strong> <strong>in</strong>put arguments<br />

to a judgment are ground terms (i.e. <strong>the</strong>y do not conta<strong>in</strong> logic variables); this will<br />

72<br />

ackss


e remarked upon fur<strong>the</strong>r <strong>in</strong> Section 5.2.4. In <strong>the</strong> case <strong>of</strong> ack, if search follows <strong>the</strong><br />

strategy <strong>of</strong> always consider<strong>in</strong>g <strong>the</strong> left-most derivation hole, <strong>the</strong>n that hole’s <strong>in</strong>put<br />

arguments are guaranteed to be ground. We say that judgments with this property<br />

are well moded, <strong>the</strong> significance <strong>of</strong> which will be discussed subsequently.<br />

D ′ 0<br />

: (ack(z; s z; m ))<br />

acksz<br />

ack(s z; z; m ) D1 : (ack(z; m ; n ))<br />

ack(s z; s z; n )<br />

At this po<strong>in</strong>t, we aga<strong>in</strong> attempt to fill <strong>the</strong> leftmost derivation hole, this time us<strong>in</strong>g<br />

<strong>the</strong> <strong>in</strong>ference rule ackz. In do<strong>in</strong>g so, we f<strong>in</strong>d a concrete <strong>in</strong>stantiation for <strong>the</strong> logic<br />

variable m by unify<strong>in</strong>g it with s s z.<br />

ack(z; s z; s s z)<br />

ackz<br />

acksz<br />

ack(s z; z; s s z) D1 : (ack(z; s s z; n ))<br />

ack(s z; s z; n )<br />

We are now able to fill <strong>the</strong> rema<strong>in</strong><strong>in</strong>g subgoal, whose <strong>in</strong>put arguments have been<br />

grounded by <strong>the</strong> substitution <strong>of</strong> s s z for m. We fill this goal with <strong>the</strong> only rule that<br />

can be applied, ackz, thus complet<strong>in</strong>g our search.<br />

ack(z; s z; s s z)<br />

ack(s z; z; s s z)<br />

ackz<br />

acksz<br />

ack(s z; s z; s s s z)<br />

ack(z; s s z; s s s z)<br />

Clearly, <strong>the</strong> search procedure sketched above, when generalized to work on ar-<br />

bitrary judgments, can be used to implement any computable function; for exam-<br />

ple, perform<strong>in</strong>g search on a judgmentally-specified big-step structural operational<br />

semantics is a particularly natural way to def<strong>in</strong>e an <strong>in</strong>terpretor. We refer to this<br />

computational paradigm as logic programm<strong>in</strong>g, where judgments such as ack are<br />

logic programs and search problems such as D : ack(s z; s z; n ) are queries. Our<br />

notion <strong>of</strong> logic program differs somewhat from <strong>the</strong> standard: usually, logic programs<br />

are atomic predicates <strong>in</strong> first order logic whose axioms are Horn clauses, where queries<br />

73<br />

ackz<br />

ackss<br />

ackss<br />

ackss


are expressed <strong>in</strong> terms <strong>of</strong> pro<strong>of</strong> search on Σ1 formulas.We justify ourselves by not-<br />

<strong>in</strong>g that Horn clauses can be naturally be represented <strong>in</strong> terms <strong>of</strong> judgments, where<br />

depth-first search on derivations us<strong>in</strong>g logic variables faithfully models pro<strong>of</strong>-search<br />

for <strong>the</strong> correspond<strong>in</strong>g Σ1 formulas. Thus, we sometimes abuse term<strong>in</strong>ology by re-<br />

ferr<strong>in</strong>g to depth-first search over judgments as pro<strong>of</strong> search. We can use <strong>the</strong> logic<br />

programm<strong>in</strong>g <strong>in</strong>terpretation <strong>of</strong> judgments to help us characterize <strong>the</strong> provably total<br />

functions <strong>of</strong> syntactic f<strong>in</strong>itism. We proceed as follows.<br />

In Section 5.1, we def<strong>in</strong>e a particular syntactic category whose terms can be used<br />

to adequately represent arbitrary derivations <strong>of</strong> arbitrary judgments. We refer to such<br />

a syntactic category as a logical framework; <strong>the</strong> logical framework we are most <strong>in</strong>ter-<br />

ested <strong>in</strong> is LF [HHP87], although, for reasons that will be discussed later, we present<br />

a sp<strong>in</strong>e-calculus/Herbel<strong>in</strong>-style[CP03, Her95] variant <strong>of</strong> Canonical LF[HL07]. In Sec-<br />

tion 5.2, we def<strong>in</strong>e a big-step operational semantics for pro<strong>of</strong> search over <strong>the</strong> terms <strong>of</strong><br />

<strong>the</strong> logical framework, thus provid<strong>in</strong>g a syntactic specification for <strong>the</strong> notion <strong>of</strong> logic<br />

programm<strong>in</strong>g. However, not all logic programs are total functions: <strong>the</strong>y must be<br />

well-moded, term<strong>in</strong>at<strong>in</strong>g and cover all cases. In Section 5.2.5, we carve out a subset<br />

<strong>of</strong> well-behaved logic programs by judgmentally specify<strong>in</strong>g an algorithm—<strong>in</strong>spired by<br />

<strong>the</strong> one sketched <strong>in</strong> [RP96, Roh96]—that can guarantee <strong>the</strong> well-modedness and ter-<br />

m<strong>in</strong>ation <strong>of</strong> pro<strong>of</strong> search. The mode/term<strong>in</strong>ation analysis is modular <strong>in</strong> <strong>the</strong> order<strong>in</strong>g<br />

used on LF terms, mean<strong>in</strong>g that it can, <strong>in</strong> pr<strong>in</strong>ciple, capture syntactically f<strong>in</strong>itary<br />

reason<strong>in</strong>g based on both <strong>the</strong> subterm order<strong>in</strong>g and lexicographic path order<strong>in</strong>g. We<br />

prove <strong>the</strong> correctness <strong>of</strong> <strong>the</strong> mode/term<strong>in</strong>ation checker us<strong>in</strong>g syntactically f<strong>in</strong>itary<br />

methods extended by a pr<strong>in</strong>ciple <strong>of</strong> well-founded <strong>in</strong>duction based on this modular<br />

order<strong>in</strong>g. We leave a syntactic characterization <strong>of</strong> a coverage checker, such as [SP03],<br />

to future work.<br />

74


5.1 Canonical Sp<strong>in</strong>e LF<br />

In Section 1.1, we saw how BNF-style equations can be used to def<strong>in</strong>e syntactic<br />

categories, where each clause <strong>of</strong> a def<strong>in</strong>ition specifies both <strong>the</strong> name <strong>of</strong> a term con-<br />

structor, and <strong>the</strong> syntactic categories that <strong>the</strong> term constructor can be applied to.<br />

Informally, if we th<strong>in</strong>k <strong>of</strong> syntactic categories as be<strong>in</strong>g atomic types, <strong>the</strong> applicability<br />

<strong>of</strong> term constructors can be captured by <strong>the</strong> notion <strong>of</strong> function-type. This observa-<br />

tion <strong>in</strong>spires us to view <strong>the</strong> follow<strong>in</strong>g type-<strong>the</strong>ory <strong>in</strong>spired def<strong>in</strong>ition <strong>of</strong> <strong>the</strong> natural<br />

numbers as be<strong>in</strong>g noth<strong>in</strong>g more than a notational variation on <strong>the</strong> usual BNF-style<br />

def<strong>in</strong>ition.<br />

nat : type<br />

z : nat<br />

s : nat → nat<br />

We have also seen that, by allow<strong>in</strong>g syntactic categories to depend on one an-<br />

o<strong>the</strong>r, any judgment that can be def<strong>in</strong>ed us<strong>in</strong>g <strong>in</strong>ference rules can also be def<strong>in</strong>ed<br />

us<strong>in</strong>g BNF-style def<strong>in</strong>itions. We refer to this observation as <strong>the</strong> judgments-as-types<br />

pr<strong>in</strong>ciple because, <strong>in</strong> general, judgments and (dependent) syntactic categories can<br />

be expressed us<strong>in</strong>g type-<strong>the</strong>oretic declarations like <strong>the</strong> one above, extended with de-<br />

pendent types. For example, we view <strong>the</strong> follow<strong>in</strong>g def<strong>in</strong>ition as be<strong>in</strong>g noth<strong>in</strong>g more<br />

than a notational variation on <strong>the</strong> usual def<strong>in</strong>itions <strong>of</strong> <strong>the</strong> judgments (or, alterna-<br />

tively, syntactic categories) even(n) and odd(n) (or, alternatively, E n and O n ).<br />

even : nat → type<br />

odd : nat → type<br />

evenz : even z<br />

evens : Πn:nat. odd n → even(s n)<br />

odds : Πn:nat. even n → odd(s n)<br />

In Section 1.3, we <strong>in</strong>troduced <strong>the</strong> concept <strong>of</strong> hypo<strong>the</strong>tical judgment, where <strong>in</strong>fer-<br />

75


ence rules and term constructors can b<strong>in</strong>d variables, and and hypo<strong>the</strong>tical judgments<br />

(such as ⊢ τ nd) are equivalent to syntactic categories (such as e τ ). We express such<br />

hypo<strong>the</strong>tical def<strong>in</strong>itions <strong>in</strong> type-<strong>the</strong>oretic notation us<strong>in</strong>g higher-order types, where<br />

functions <strong>of</strong> type → and Π can do no more than perform substitutions for bound<br />

variables. We def<strong>in</strong>e <strong>the</strong> syntactic categories τ and e τ us<strong>in</strong>g this notation below.<br />

tp : type<br />

o : tp<br />

⇒: tp → tp → tp. (we treat ⇒ as an <strong>in</strong>fix operator)<br />

exp : Πt1:tp.Πt2:tp.((exp t1) → (exp t2)) → exp (t1 ⇒ t2)<br />

app : Πt1:tp.Πt2:tp.(exp (t1 ⇒ t2)) → (exp t1) → (exp t2)<br />

We denote variable-b<strong>in</strong>d<strong>in</strong>g functions us<strong>in</strong>g λ-notation, mean<strong>in</strong>g that <strong>the</strong> term ex-<br />

pressed <strong>in</strong> BNF-style notation as (lam x o .x o ) o⇒o would be expressed <strong>in</strong> type-<strong>the</strong>ory<br />

<strong>in</strong>spired notation as lam o o (λx:o.x), which can be accurately represented by a term<br />

<strong>of</strong> <strong>the</strong> same name <strong>in</strong> a dependently-typed λ-calculus with constants <strong>of</strong> <strong>the</strong> appropriate<br />

types.<br />

This leads us to <strong>the</strong> follow<strong>in</strong>g observation. Given a dependently-typed λ-calculus,<br />

it should be straightforward to adequately encode judgments as types and <strong>in</strong>ference<br />

rules as constants, such that every derivation is isomorphic to a canonical λ-calculus<br />

term <strong>of</strong> <strong>the</strong> appropriate type. The logical framework LF [HHP87] is just such a<br />

λ-calculus, where canonical forms are β-short and η-long. The pro<strong>of</strong> that every LF<br />

term can be converted to a canonical form <strong>in</strong>volves a nontrivial pro<strong>of</strong> by logical<br />

relations [HP05]. Although we have seen <strong>in</strong> Chapter 2 that logical relations pro<strong>of</strong>s<br />

are compatible with syntactic f<strong>in</strong>itism, convert<strong>in</strong>g express<strong>in</strong>g this result <strong>in</strong> terms<br />

<strong>of</strong> structural logical relations would be prohibitively complex for <strong>the</strong> purpose <strong>of</strong><br />

def<strong>in</strong><strong>in</strong>g pro<strong>of</strong> search. Instead, we rely on a formalization <strong>of</strong> LF similar to canonical<br />

LF [HL07], whose meta<strong>the</strong>ory is clearly syntactically f<strong>in</strong>itary. Here, we def<strong>in</strong>e a<br />

76


sp<strong>in</strong>e calculus variation <strong>of</strong> canonical LF because we feel that this formulation leads<br />

to a more natural account <strong>of</strong> pro<strong>of</strong> search. We provide a technical treatment <strong>of</strong><br />

<strong>the</strong> meta<strong>the</strong>ory canonical sp<strong>in</strong>e LF, closely mirror<strong>in</strong>g <strong>the</strong> technical development <strong>of</strong><br />

canonical LF <strong>in</strong> [HL07], <strong>in</strong> <strong>the</strong> follow<strong>in</strong>g subsections. We will not formally address<br />

<strong>the</strong> issue <strong>of</strong> prov<strong>in</strong>g adequacy <strong>the</strong>orems for this formulation; <strong>in</strong>stead we defer to <strong>the</strong><br />

treatment provided <strong>in</strong> <strong>the</strong> aforementioned references.<br />

5.1.1 Terms and Typ<strong>in</strong>g Rules<br />

Below, we present <strong>the</strong> abstract syntax for a sp<strong>in</strong>e-calculus [CP03] variation <strong>of</strong> canon-<br />

ical LF [HL07]. This presentation closely mimics <strong>the</strong> way that LF is represented<br />

<strong>in</strong>ternally by <strong>the</strong> programm<strong>in</strong>g language Twelf, and simplifies <strong>the</strong> presentation <strong>of</strong><br />

pro<strong>of</strong>-search for LF terms <strong>in</strong> Section 5.2. It should also be noted that this presenta-<br />

tion <strong>of</strong> LF closely resembles <strong>the</strong> cut-free pro<strong>of</strong> terms for Herbel<strong>in</strong>’s LJT [Her95], and<br />

so we adopt some <strong>of</strong> his notational conventions.<br />

K<strong>in</strong>ds K, L ::= type | Πx:A.K<br />

Type Families A, B ::= a M | Πx:A.B<br />

Canonical Terms M, N ::= x M | c M | λx:A.M<br />

Canonical Sp<strong>in</strong>es M, N ::= · | N :: M<br />

Contexts Γ ::= · | Γ, x:A<br />

Signatures Σ ::= · | Σ, a:K | Σ, c:A<br />

Note that, unlike <strong>the</strong> presentation <strong>of</strong> canonical LF <strong>in</strong> [HL07], we <strong>in</strong>clude type-labels<br />

on λ-abstractions; although <strong>the</strong>se type-labels are unnecessary, hav<strong>in</strong>g <strong>the</strong>m makes<br />

<strong>the</strong> specification <strong>of</strong> <strong>the</strong> mode/term<strong>in</strong>ation checker somewhat simpler.<br />

For convenience, we use <strong>the</strong> letter h to stand for heads <strong>of</strong> terms (i.e. ei<strong>the</strong>r x or<br />

c).A term that would be written as h M0 . . . Mn <strong>in</strong> conventional presentations <strong>of</strong> LF<br />

would be written as h (M0 :: . . . :: Mn :: ·) here (although we sometimes write <strong>the</strong><br />

77


former as shorthand for <strong>the</strong> latter). For any syntactic category E among K, A, M<br />

and Γ, we write x ∈ F V (E) to refer to <strong>the</strong> judgment that characterizes when x<br />

occurs freely <strong>in</strong> E, and write x#E to refer to <strong>the</strong> judgment that characterizes when<br />

x is not among <strong>the</strong> free variables <strong>of</strong> E (we <strong>in</strong>herit this convention from [HL07]). We<br />

sometimes write Πx:A.B as A → B when x#B holds. In general, we require x#Γ<br />

to hold <strong>in</strong> order for Γ, x:A to be well-formed; this side condition can typically be<br />

satisfied by <strong>the</strong> tacit renam<strong>in</strong>g <strong>of</strong> bound variables. Similarly, we require that each<br />

term- or family-level constant may be declared at most once <strong>in</strong> Σ.<br />

We use <strong>the</strong> notion <strong>of</strong> simple types to help def<strong>in</strong>e hereditary substitutions; although<br />

we reuse <strong>the</strong> symbols σ and τ, <strong>the</strong> simple types def<strong>in</strong>ed below not to be confused<br />

with <strong>the</strong> similar notion <strong>of</strong> types def<strong>in</strong>ed <strong>in</strong> Section1.3.<br />

Simple Types τ, σ ::= a | τ → σ<br />

The mapp<strong>in</strong>g <strong>of</strong> type-families to simple types is straightforward.<br />

(a M) − = a<br />

(Πx:A.B) − = (A − ) → (B − )<br />

We def<strong>in</strong>e <strong>the</strong> notion <strong>of</strong> head for type families and simple types below.<br />

Clearly, for every A, hd(A) = hd(A − ).<br />

hd(a M) = a<br />

hd(Πx:A.B) = hd(B)<br />

hd(a) = a<br />

hd(τ → σ) = hd(σ)<br />

78


An LF specification is parameterized not only by a signature Σ (not to be con-<br />

fused with <strong>the</strong> notion <strong>of</strong> signature from Chapter 4), but also by a (decidable) b<strong>in</strong>ary<br />

subord<strong>in</strong>ation relation, ⊑, on <strong>the</strong> family-level constants <strong>in</strong> Σ; we lift ⊑ to arbitrary<br />

families by writ<strong>in</strong>g A ⊑ B as shorthand for hd(A) ⊑ hd(B). Intuitively, A ⊑ B holds<br />

whenever terms <strong>of</strong> type A can occur <strong>in</strong>side <strong>of</strong> terms <strong>of</strong> type B. The typ<strong>in</strong>g, well-<br />

formedness and substitution judgments for LF are listed along with <strong>the</strong>ir <strong>in</strong>formal<br />

mean<strong>in</strong>gs below.<br />

Γ ⊢Σ,⊑ K : k<strong>in</strong>d K is a valid k<strong>in</strong>d<br />

Γ ⊢Σ,⊑ A : K A is a family <strong>of</strong> k<strong>in</strong>d K<br />

Γ; K ⊢Σ,⊑ M : K ′ M is a sp<strong>in</strong>e that transforms <strong>the</strong> k<strong>in</strong>d K <strong>in</strong>to K ′<br />

Γ ⊢Σ,⊑ M : A M is a term <strong>of</strong> type A<br />

Γ; A ⊢Σ,⊑ M : B M is a sp<strong>in</strong>e that transforms A <strong>in</strong>to B<br />

⊢Σ,⊑ Γ : ctx Γ is a valid context<br />

⊢⊑ Σ : sig Σ is a valid signature<br />

[M/x]τ K = K ′ substitut<strong>in</strong>g M for x <strong>in</strong> K results <strong>in</strong> K ′<br />

[M/x]τ A = A ′ substitut<strong>in</strong>g M for x <strong>in</strong> A results <strong>in</strong> A ′<br />

[M/x]τ N = N ′ substitut<strong>in</strong>g M for x <strong>in</strong> N results <strong>in</strong> N ′<br />

[M/x]τ M = M ′ substitut<strong>in</strong>g M for x <strong>in</strong> M results <strong>in</strong> M ′<br />

[M/x]τ Γ = Γ ′ substitut<strong>in</strong>g M for x <strong>in</strong> Γ results <strong>in</strong> Γ ′<br />

reduceτ (M, M) = N apply<strong>in</strong>g each element <strong>of</strong> <strong>the</strong> sp<strong>in</strong>e M to M results <strong>in</strong> N<br />

All <strong>of</strong> <strong>the</strong> typ<strong>in</strong>g rules for k<strong>in</strong>ds, families, sp<strong>in</strong>es and terms have a premiss <strong>of</strong> <strong>the</strong> form<br />

⊢Σ,⊑ Γ : ctx; we will not explicitly write this premiss for <strong>the</strong> sake <strong>of</strong> readability. We<br />

beg<strong>in</strong> specify<strong>in</strong>g <strong>the</strong> <strong>in</strong>ference rules for <strong>the</strong>se judgments below.<br />

Γ ⊢Σ,⊑ type : k<strong>in</strong>d<br />

KIND-TYPE<br />

Γ ⊢Σ,⊑ A : type Γ, x:A ⊢Σ,⊑ K : k<strong>in</strong>d KIND-PI<br />

Γ ⊢Σ,⊑ Πx:A.K : k<strong>in</strong>d<br />

79


Γ ⊢Σ,⊑ A : type Γ, x:A ⊢Σ,⊑ B : type hd(A) ⊑ hd(B) FAM-PI<br />

Γ ⊢Σ,⊑ Πx:A.B : type<br />

a:K <strong>in</strong> Σ Γ; K ⊢Σ,⊑ M : type FAM-ATM<br />

Γ ⊢Σ,⊑ a M : type<br />

Γ; K ⊢Σ,⊑ · : K<br />

FAM-LIST-NIL<br />

Γ ⊢Σ,⊑ M : A [M/x] A −K = K ′ Γ; K ′ ⊢Σ,⊑ M : L FAM-LIST-CONS<br />

Γ; Πx:A.K ⊢Σ,⊑ M :: M : L<br />

Γ ⊢Σ,⊑ A : type Γ, x:A ⊢Σ,⊑ M : B TERM-LAM<br />

Γ ⊢Σ,⊑ λx:A.M : Πx:A.B<br />

x:A <strong>in</strong> Γ Γ; A ⊢Σ,⊑ M : a N TERM-ATM-V<br />

Γ ⊢Σ,⊑ x M : a N<br />

c:A <strong>in</strong> Σ Γ; A ⊢Σ,⊑ M : a N TERM-ATM-C<br />

Γ ⊢Σ,⊑ c M : a N<br />

Γ; A ⊢Σ,⊑ · : A<br />

Γ ⊢Σ,⊑ M : A [M/x] A −B = B ′ Γ; B ′ ⊢Σ,⊑ M : A ′<br />

⊢⊑ · : sig<br />

⊢Σ,⊑ · : ctx<br />

Γ; Πx:A.B ⊢Σ,⊑ M :: M : A ′<br />

SIG-EMPTY<br />

TERM-LIST-NIL<br />

TERM-LIST-CONS<br />

⊢⊑ Σ : sig Γ ⊢Σ,⊑ A : type c#Σ SIG-TERM<br />

⊢⊑ Σ, c:A : sig<br />

⊢⊑ Σ : sig Γ ⊢Σ,⊑ K : k<strong>in</strong>d a#Σ SIG-FAM<br />

⊢⊑ Σ, a:K : sig<br />

CTX-EMPTY<br />

⊢Σ,⊑ Γ : ctx Γ ⊢Σ,⊑ A : type x#Γ<br />

⊢Σ,⊑ Γ, x:A : ctx<br />

The notion <strong>of</strong> hereditary substitution [M/x]τE = E ′ def<strong>in</strong>ed below is not to be<br />

confused with <strong>the</strong> ord<strong>in</strong>ary substitutions used <strong>in</strong> earlier chapters; our sp<strong>in</strong>e calculus<br />

has <strong>the</strong> flavor <strong>of</strong> a cut-free sequent calculus, and perform<strong>in</strong>g a hereditary substitution<br />

is ak<strong>in</strong> to us<strong>in</strong>g cut as an admissible rule. In particular, hereditary substitutions can<br />

be viewed as partial functions on arbitrary syntactic categories, and as total functions<br />

on well-formed syntactic categories. We def<strong>in</strong>e hereditary substitution judgmentally<br />

80


elow.<br />

h#x [M/x]τ N = N ′<br />

[M/x]τ h N = h N ′<br />

[M/x]τ type = type<br />

[M/x]τ M = N<br />

[M/x]τ a M = a N<br />

[M/x]τ N = N ′<br />

[M/x]τ A = A ′<br />

[M/x]τ K = K ′ x#y<br />

[M/x]τ Πy:A.K = Πy:A ′ .K ′<br />

[M/x]τ A = A ′<br />

[M/x]τ a N = a N ′<br />

[M/x]τ A = A ′<br />

[M/x]τ · = ·<br />

[M/x]τ B = B ′ x#y<br />

[M/x]τ Πy:A.B = Πy:A ′ .B ′<br />

[M/x]τ N = N ′ reduceτ (M, N ′ ) = M ′<br />

[M/x]τ N = N ′ x#y<br />

[M/x]τ λy:A.N = λy:A ′ .N ′<br />

[M/x]τ N = N ′<br />

[N/x]τ M = M ′ reduceσ(M ′ , N) = N ′<br />

reduceτ→σ(λx:A.M, N :: N) = N ′<br />

[M/x]τ · = ·<br />

[M/x]τ Γ = Γ ′<br />

[M/x]τ x N = M ′<br />

[M/x]τ N = N ′<br />

[M/x]τ N :: N = N ′ :: N ′<br />

reduceτ (M, ·) = M<br />

[M/x]τ A = B x#y y#M<br />

[M/x]τ Γ, y:A = Γ ′ , y:B<br />

The subord<strong>in</strong>ation ⊑ relation specified along with <strong>the</strong> signature Σ;we expect this<br />

specification to be both syntactic and decidable. Just as some signatures are consid-<br />

ered ill-formed, some subord<strong>in</strong>ation relations also considered ill-formed. We def<strong>in</strong>e<br />

well-formed subord<strong>in</strong>ation relations <strong>in</strong> <strong>the</strong> style <strong>of</strong> [HL07], as opposed to [Vir99]),<br />

below, although <strong>the</strong> dist<strong>in</strong>ction between <strong>the</strong>se two approaches does not affect our<br />

presentation.<br />

Def<strong>in</strong>ition 5.1.1 (Subord<strong>in</strong>ation Relation) Given Σ, <strong>the</strong> subord<strong>in</strong>ation relation<br />

⊑ is well formed iff it satisfies all <strong>of</strong> <strong>the</strong> follow<strong>in</strong>g properties:<br />

1. ⊢⊑ Σ : sig<br />

2. For all a:Πx:A1 . . . Πx:An. type <strong>in</strong> Σ, hd(Ai)⊑a (for all i ∈ 1, . . . , n)<br />

3. ⊑is reflexive<br />

81


4. ⊑is transitive<br />

Note that condition 2 can be expressed judgmentally (i.e. without <strong>the</strong> use <strong>of</strong> ellipses);<br />

we omit this characterization for <strong>the</strong> sake <strong>of</strong> readability.<br />

We write ⊏ for <strong>the</strong> strict portion <strong>of</strong> ⊑ (i.e. a ⊏ b iff a ⊑ b and b ⊑ a) and ≡ for<br />

<strong>the</strong> reflexive portion <strong>of</strong> ⊑ (i.e. a ≡ b iff a ⊑ b and b ⊑ a). We say that a and b are<br />

mutually recursive whenever a ≡ b.<br />

Although we follow [HL07] by view<strong>in</strong>g ⊑ as part <strong>of</strong> an LF specification, <strong>in</strong> practice<br />

<strong>the</strong> “strongest subord<strong>in</strong>ation relation” can be computed from Σ. From now on, we<br />

will always assume that fixed, well-formed specifications <strong>of</strong> ⊑ and Σ have been given;<br />

thus, for <strong>the</strong> sake <strong>of</strong> readability, we will use ⊢ <strong>in</strong> place <strong>of</strong> ⊢Σ,⊑ whenever <strong>the</strong>re is no<br />

ambiguity.<br />

5.1.2 Hereditary Substitutions<br />

Here, as <strong>in</strong> canonical LF, hereditary substitutions play <strong>the</strong> dual role <strong>of</strong> substitution<br />

and normalization. In this section, we prove that Hereditary substitutions are applied<br />

to well-formed terms are well behaved.<br />

Lemma 5.1.2 (Decidability <strong>of</strong> Substitution)<br />

1. For any E <strong>in</strong> {K, A, M, M, Γ}, for every M, x and τ <strong>the</strong>re ei<strong>the</strong>r exists an E ′<br />

such that [M/x]τE = E ′ or no such E ′ exists<br />

2. For every M, M and τ ei<strong>the</strong>r <strong>the</strong>re exists an N such that reduceτ(M, M) = N<br />

or no such N exists<br />

Pro<strong>of</strong>: By mutual <strong>in</strong>duction: τ followed by E for 1, and τ followed by M for 2. <br />

Lemma 5.1.3 (Uniqueness <strong>of</strong> Substitutions and Formation)<br />

82


1. For any E <strong>in</strong> {K, A, M, M} if [M/x]τE = E ′ and [M/x]τE = E ′′ <strong>the</strong>n E ′ = E ′′<br />

2. If reduceτ(M, M) = N and reduceτ(M, M) = N ′ <strong>the</strong>n N = N ′<br />

3. If Γ ⊢ A : K and Γ ⊢ A : K ′ <strong>the</strong>n K = K ′<br />

4. If Γ ⊢ M : A and Γ ⊢ M : B <strong>the</strong>n A = B<br />

5. If Γ; A ⊢ M : P and Γ; A ⊢ M : P ′ <strong>the</strong>n P = P ′<br />

Pro<strong>of</strong>: By straightforward mutual <strong>in</strong>ductions on <strong>the</strong> structures <strong>of</strong> <strong>the</strong> given deriva-<br />

tions. <br />

Lemma 5.1.4 (Substitutions Preserve Freshness)<br />

1. Given E among {K, A, M, M}, if [M/x]τE = E ′ and y#M and y#E <strong>the</strong>n<br />

y#E ′<br />

2. If reduceτ(M, M) = N and x#M and x#M <strong>the</strong>n x#N<br />

Pro<strong>of</strong>: By straightforward mutual <strong>in</strong>duction on <strong>the</strong> given substitution derivations.<br />

<br />

Lemma 5.1.5 (Contexts Conta<strong>in</strong> Free Variables) If x#Γ <strong>the</strong>n:<br />

1. if Γ ⊢ K : k<strong>in</strong>d <strong>the</strong>n x#K<br />

2. if Γ; K ⊢ M : K ′ <strong>the</strong>n x#K and x#M and x#K ′<br />

3. if Γ ⊢ A : type <strong>the</strong>n x#A<br />

4. if Γ; A ⊢ M : B <strong>the</strong>n x#A and and x#M and x#B<br />

5. if Γ ⊢ M : A <strong>the</strong>n x#M and x#A<br />

83


Pro<strong>of</strong>: By straightforward mutual <strong>in</strong>duction on <strong>the</strong> given typ<strong>in</strong>g derivations, us<strong>in</strong>g<br />

Lemma 5.1.4 <strong>in</strong> <strong>the</strong> TERM-LIST-CONS and FAM-LIST-CONS cases. <br />

Lemma 5.1.6 (Weaken<strong>in</strong>g for Typ<strong>in</strong>g)<br />

1. If Γ, Γ ′ ⊢ M : A and Γ ⊢ B : type <strong>the</strong>n Γ, x:B, Γ ′ ⊢ M : A<br />

2. If Γ, Γ ′ ⊢ A : K and Γ ⊢ B : type <strong>the</strong>n Γ, x:B, Γ ′ ⊢ A : K<br />

3. If Γ, Γ ′ ; A ⊢ M : A ′ and Γ ⊢ B : type <strong>the</strong>n Γ, x:B, Γ ′ ; A ⊢ M : A ′<br />

4. If Γ, Γ ′ ; K ⊢ M : K ′ and Γ ⊢ B : type <strong>the</strong>n Γ, x:B, Γ ′ ; K ⊢ M : K ′<br />

Pro<strong>of</strong>: By straightforward mutual <strong>in</strong>ductions. <br />

Streng<strong>the</strong>n<strong>in</strong>g isn’t used to prove <strong>the</strong> substitution lemma, but it will be useful<br />

later on.<br />

Lemma 5.1.7 (Streng<strong>the</strong>n<strong>in</strong>g for Typ<strong>in</strong>g)<br />

1. If Γ, x:B, Γ ′ ⊢ M : A and x#Γ ′ and x#M <strong>the</strong>n Γ, Γ ′ ⊢ M : B<br />

2. If Γ, x:B, Γ ′ ⊢ A : K and x#Γ ′ <strong>the</strong>n Γ, Γ ′ ⊢ A : K<br />

3. If Γ, x:B, Γ ′ ; A ⊢ M : A ′ and x#Γ ′ and x#M <strong>the</strong>n Γ, Γ ′ ; A ⊢ M : A ′<br />

4. If Γ, x:B, Γ ′ ; K ⊢ M : K ′ and x#Γ ′ and x#K and x#M <strong>the</strong>n Γ, Γ ′ ; K ⊢ M : K ′<br />

Pro<strong>of</strong>: By straightforward mutual <strong>in</strong>ductions, us<strong>in</strong>g Lemma 5.1.4 <strong>in</strong> 3 and 4. <br />

Lemma 5.1.8 (Vacuous Substitutions) Given M, x, τ and E among {K, A, M, M},<br />

if x#E <strong>the</strong>n [M/x]τE = E<br />

Pro<strong>of</strong>: By <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> E. <br />

84


Lemma 5.1.9 (Substitutions Consume Variables) Given M, x, τ and E among<br />

{K, A, M, M}, if [M/x]τE = E ′ and x#M <strong>the</strong>n x#E ′<br />

Pro<strong>of</strong>: By <strong>in</strong>duction <strong>the</strong> given substitution derivation. <br />

Lemma 5.1.10 (Erasure is Invariant Under Substitutions) If [M/x]τA = A ′<br />

<strong>the</strong>n A − = A ′−<br />

Pro<strong>of</strong>: By straightforward <strong>in</strong>duction over <strong>the</strong> structure <strong>of</strong> <strong>the</strong> substitution deriva-<br />

tion. <br />

The follow<strong>in</strong>g lemma can be thought <strong>of</strong> both as a k<strong>in</strong>d <strong>of</strong> commutativity lemma<br />

for hereditary substitutions, and form <strong>of</strong> Church-Rosser.<br />

Lemma 5.1.11 (Composition <strong>of</strong> Substitutions)<br />

1. For all E <strong>in</strong> {K, A, M, M}, if D : ([M2/x]τ2E1 = E) and E : ([M0/x0]τ0E1 = E ′ 1)<br />

and F : ([M0/x0]τ0M2 = M ′ 2) and x#x0 and x#M0 and x#M2 <strong>the</strong>n <strong>the</strong>re exists<br />

and E ′ such that [M0/x0]τ0E = E ′ and [M ′ 2/x]τ2E ′ 1 = E ′<br />

2. If D : (reduceτ2(M1, M2) = M ′ ) and E : ([M0/x0]τ0M1 = M ′ 1) and F : ([M0/x0]τ0M2 =<br />

M ′ 2) and x0#M0 <strong>the</strong>n <strong>the</strong>re exists an M ′ such that reduceτ0(M ′ 1, M ′ 2) = M ′ and<br />

[M0/x0]τ0M = M ′<br />

Pro<strong>of</strong>: By mutual <strong>in</strong>duction on <strong>the</strong> (commutative generalization <strong>of</strong>) <strong>the</strong> simulta-<br />

neous order<strong>in</strong>g <strong>of</strong> τ0 and τ2, followed by D. Most <strong>of</strong> <strong>the</strong> cases are straightforward;<br />

however <strong>the</strong> cases <strong>in</strong> 1 where E1 = x0 M1 and E1 = x M1 are somewhat tricky, as is<br />

<strong>the</strong> substitution case <strong>of</strong> 2. We show <strong>the</strong>m here.<br />

1.<br />

85


2.<br />

Case:<br />

Case:<br />

D =<br />

E =<br />

D0<br />

[M2/x]τ2 M1 = M<br />

D1<br />

reduceτ2 (M2, M) = M<br />

[M2/x]τ2 x M1 = M<br />

E0<br />

[M0/x0]τ0 M1 = M ′ 1<br />

[M0/x0]τ0 x M1 = x M ′ 1<br />

[M0/x0]τ0 M2 = M ′ 2 and x#M0 and x#x0 and x#M ′ 2<br />

x#x0<br />

given<br />

[M0/x0]τ0 M = M ′ and [M ′ 2 /x]τ2 M = M ′ by IH 1 on τ0, τ2 and D0<br />

reduceτ2 (M ′ 2 , M ′ ) = M ′ and [M0/x0]τ0 M = M ′ by IH 2 on τ0, τ2 and D1<br />

[M ′ 2 /x]τ2 x M ′ 1 = M ′ by rule<br />

D =<br />

E =<br />

E0<br />

[M0/x0]τ0 M1 = M ′ 1<br />

D0<br />

[M2/x]τ2 M1 = M x#x0<br />

[M2/x]τ2 x0 M1 = x0 M<br />

E1<br />

reduceτ0 (M0, M ′ 1 ) = M ′ 1<br />

[M0/x0]τ0 x0 M1 = M ′ 1<br />

[M0/x0]τ0 M2 = M ′ 2 and x#M0 and x#x0 and x#M ′ 2<br />

given<br />

[M0/x0]τ0 M = M ′ and [M ′ 2 /x]τ2 M ′ 1 = M ′ by IH 1 on τ0, τ2 and E1<br />

[M ′ 2 /x]τ2 M0 = M0<br />

by lemma 5.1.8<br />

reduceτ0 (M0, M ′ ) = M ′ and [M ′ 2 /x]τ2 M ′ 1 = M ′ by IH 2 on τ2, τ0 and D0<br />

[M0/x0]τ0 x0 M1 = M ′ by rule<br />

86


Case:<br />

x0#M0<br />

x0#M ′ 2<br />

D =<br />

E =<br />

F =<br />

D0<br />

[M2/x]τ2 M1 = N<br />

D1<br />

reduceσ2 (N, M2) = M<br />

reduceτ2→σ(λx:A1.M1, M2 :: M2) = M<br />

E0<br />

[M0/x0]τ0 A1 = A ′ 1<br />

E1<br />

[M0/x0]τ0 M1 = M ′ 1<br />

[M0/x0]τ0 λx:A1.M1 = λx:A ′ 1.M ′ 1<br />

F0<br />

[M0/x0]τ0 M2 = M ′ 2<br />

F1<br />

[M0/x0]τ0 M2 = M ′ 2<br />

[M0/x0]τ0 M2 :: M2 = M ′ 2 :: M ′ 2<br />

x#x0<br />

given<br />

by Lemma 5.1.9<br />

[M0/x0]τ0 N = N ′ and [M ′ 2 /x]τ2 M ′ 1 = N ′ by IH 1 on τ0, τ2 and D0<br />

reduceσ2 (N ′ , M ′ 2 ) = M ′ and [M0/x0]τ0 M = M ′ by IH 2 on σ2, τ0 and D1<br />

We are now ready to show that hereditary substitutions are total functions on<br />

well-formed syntactic categories.<br />

Theorem 5.1.12 (Hereditary Substitutions)<br />

1. If Γ; A ⊢ M : B and Γ ⊢ M : A and A − = τ <strong>the</strong>n reduceτ(M, M) = M ′ and<br />

Γ ⊢ M ′ : B<br />

2. If Γ0 ⊢ M : A and A − = τ <strong>the</strong>n:<br />

(a) If ⊢ Γ0, x:A, Γ1 : ctx <strong>the</strong>n [M/x]τΓ1 = Γ ′ 1 and ⊢ Γ0, Γ ′ 1 : ctx<br />

87


(b) If Γ0, x:A, Γ1 ⊢ K : k<strong>in</strong>d and [M/x]τΓ1 = Γ ′ 1 <strong>the</strong>n [M/x]τK = K ′ and Γ0, Γ ′ 1 ⊢ K ′ : ki<br />

(c) If Γ0, x:A, Γ1 ⊢ B : type and [M/x]τΓ1 = Γ ′ 1 <strong>the</strong>n [M/x]τB = B ′ and Γ0, Γ ′ 1 ⊢ B ′ : type<br />

(d) If Γ0, x:A, Γ1; K ⊢ M : type and [M/x]τΓ1 = Γ ′ 1 and [M/x]τK = K ′ <strong>the</strong>n<br />

[M/x]τM = M ′ and Γ0, Γ ′ 1; K ′ ⊢ M ′ : type<br />

(e) If Γ0, x:A, Γ1 ⊢ N : B and [M/x]τΓ1 = Γ ′ 1 <strong>the</strong>n [M/x]τN = N ′ and [M/x]τB = B ′<br />

and Γ0, Γ ′ 1 ⊢ N ′ : B ′<br />

(f) If Γ0, x:A, Γ1; B ⊢ M : a N and [M/x]τΓ1 = Γ ′ 1 and [M/x]τB = B ′ <strong>the</strong>n<br />

[M/x]τM = M ′ and [M/x]τN = N ′ and Γ0, Γ ′ 1; B ′ ⊢ M ′ : a N ′<br />

Pro<strong>of</strong>: By simultaneous <strong>in</strong>duction on τ followed by Γ; A ⊢ M : a N for 1, and τ<br />

followed by <strong>the</strong> typ<strong>in</strong>g derivation <strong>of</strong> <strong>the</strong> syntactic category be<strong>in</strong>g substituted <strong>in</strong>to<br />

for 2. In 1, <strong>the</strong> τ → σ case uses Uniqueness <strong>of</strong> Substitutions and Formation. In<br />

2, <strong>the</strong> FAM-ATM and TERM-ATM-C cases use <strong>the</strong> Vacuous Substitution Lemma;<br />

<strong>the</strong> FAM-LIST-NIL and TERM-LIST-NIL cases are direct; <strong>the</strong> FAM-LIST-CONS<br />

and TERM-LIST-CONS cases use Composition <strong>of</strong> Substitutions and Uniqueness <strong>of</strong><br />

Substitutions; and <strong>the</strong> non-trivial TERM-ATM-V case uses Weaken<strong>in</strong>g for Typ<strong>in</strong>g<br />

(repeated <strong>in</strong>ductively on Γ ′ 1). All o<strong>the</strong>r cases are straightforward. <br />

The follow<strong>in</strong>g lemma is a useful corollary to <strong>the</strong> Hereditary substitution <strong>the</strong>orem.<br />

Lemma 5.1.13 (Regularity for Typ<strong>in</strong>g)<br />

1. If ⊢⊑ Σ : sig and a:K ∈ Σ <strong>the</strong>n · ⊢ K : k<strong>in</strong>d<br />

2. If ⊢⊑ Σ : sig and c:A ∈ Σ <strong>the</strong>n · ⊢ A : type<br />

3. If ⊢ Γ : ctx and x:A ∈ Γ <strong>the</strong>n Γ ⊢ A : type<br />

4. If Γ ⊢ K : k<strong>in</strong>d and Γ; K ⊢ M : K ′ <strong>the</strong>n Γ ⊢ K : k<strong>in</strong>d<br />

88


5. If Γ ⊢ A : K <strong>the</strong>n Γ ⊢ K : k<strong>in</strong>d<br />

6. If Γ ⊢ A : type and Γ; A ⊢ M : B <strong>the</strong>n Γ ⊢ B : type<br />

7. If Γ ⊢ M : A <strong>the</strong>n Γ ⊢ A : type<br />

Pro<strong>of</strong>: By straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> <strong>the</strong> given typ<strong>in</strong>g deriva-<br />

tions.1 and 2 require an analog <strong>of</strong> Weaken<strong>in</strong>g for Typ<strong>in</strong>g for signatures, 3 uses Weak-<br />

en<strong>in</strong>g for Typ<strong>in</strong>g, 4 and 6 use Theorem 5.1.12. <br />

5.1.3 Eta Expansion<br />

Unlike <strong>the</strong> conventionally def<strong>in</strong>ed λ-calculi, here heads (i.e. constants and vari-<br />

ables) are not considered first-class expressions. However, any given head can be<br />

η-expanded <strong>in</strong>to a first-class term. We f<strong>in</strong>d <strong>the</strong> notion <strong>of</strong> sp<strong>in</strong>e concatenation, de-<br />

f<strong>in</strong>ed below, useful for def<strong>in</strong><strong>in</strong>g this notion <strong>of</strong> expansion.<br />

(·)@M = M :: ·<br />

M@· = M<br />

N@M = M<br />

(N :: N)@M = N :: M<br />

M@N = M ′ M ′ @N = N ′<br />

M@(N :: N) = N ′<br />

Lemma 5.1.14 (Empty Concatenation) For every M, (·)@M = M<br />

Pro<strong>of</strong>: By a straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> M <br />

Lemma 5.1.15 (Sp<strong>in</strong>es Are Concatenatable)<br />

1. For every M and M <strong>the</strong>re exists N s.t. M@M = N<br />

2. For every M0 and M1 <strong>the</strong>re exists N s.t. M0@M1 = N<br />

Pro<strong>of</strong>: 1 follows by straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> M; 2 follows by<br />

straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> M1, us<strong>in</strong>g 1. <br />

89


Lemma 5.1.16 (Uniqueness <strong>of</strong> Concatenation)<br />

1. If M@M = N and M@M = N ′ <strong>the</strong>n N = N ′<br />

2. If M0@M1 = N and M0@M1 = N ′ <strong>the</strong>n N = N ′<br />

Pro<strong>of</strong>: 1 follows by straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> M; 2 follows by<br />

straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> M1, us<strong>in</strong>g 1. <br />

Lemma 5.1.17 (Concatenation Preserves Freshness)<br />

1. If M0@M1 = N <strong>the</strong>n (x#M0 and x#M1) iff x#N<br />

2. If M0@M1 = N <strong>the</strong>n (x#M0 and x#M1) iff x#N<br />

Pro<strong>of</strong>: 1 is by straightforward <strong>in</strong>duction on M0, 2 is by straightforward <strong>in</strong>duction<br />

on M1 us<strong>in</strong>g 1. <br />

Lemma 5.1.18 (Sp<strong>in</strong>e Concatenation Substitution)<br />

1. If [M/x]τN = N ′ and [M/x]τN = N ′ and N@N = M <strong>the</strong>n <strong>the</strong>re exists M ′ s.t.<br />

[M/x]τM = M ′ and N@N ′ = M ′<br />

2. If [M/x]τN0 = N ′ 0 and [M/x]τN1 = N ′ 1 and N0@N1 = N <strong>the</strong>n <strong>the</strong>re exists M<br />

such that [M/x]τN = M and N ′ 0@N ′ 1 = M<br />

Pro<strong>of</strong>: 1 follows by a straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> N, and 2 follows<br />

by a straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> N1, us<strong>in</strong>g 1. <br />

Lemma 5.1.19 (Sp<strong>in</strong>e Concatenation Typ<strong>in</strong>g)<br />

1. If Γ; A ⊢ M : Πx:B1.B2 and Γ ⊢ M : B1 and [M/x] B −<br />

1 B2 = B and M@M =<br />

M ′ <strong>the</strong>n Γ; A ⊢ M ′ : B<br />

90


2. If Γ; A ⊢ M : A ′ and Γ; A ′ ⊢ N : B and M@N = M ′ <strong>the</strong>n Γ; A ⊢ M ′ : B<br />

Pro<strong>of</strong>: 1 follows by a straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> M, 2 follows<br />

from a straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> N, us<strong>in</strong>g 1. <br />

We are now ready to def<strong>in</strong>e expansion.<br />

Def<strong>in</strong>ition 5.1.20 (Expansion) Expansion is implemented as a function on heads,<br />

types and sp<strong>in</strong>es, us<strong>in</strong>g <strong>the</strong> judgment expand h (A; M) = M, whose rules are def<strong>in</strong>ed<br />

below.<br />

expand h (a M; N) = h N<br />

expand x (A; ·) = N x#N N@N = M expand h (B; M) = M<br />

expand h (Πx:A.B; N) = λx:A.M<br />

Theorem 5.1.25 summarizes <strong>the</strong> <strong>in</strong>tuitive mean<strong>in</strong>g <strong>of</strong> expand.<br />

As usual, we show that <strong>the</strong> judgment expand h (A; M) = N can be viewed as a<br />

(determ<strong>in</strong>istic) function by means <strong>of</strong> case analysis and <strong>in</strong>duction.<br />

Lemma 5.1.21 (Existence, Uniqueness <strong>of</strong> Eta Expansion)<br />

1. For every h, M and A, <strong>the</strong>re exists an M such that expand h (A; M) = M<br />

2. If expand h (A; M) = M and expand h (A; M) = M ′ <strong>the</strong>n M = M ′<br />

Pro<strong>of</strong>: Both are by straightforward <strong>in</strong>ductions on A − . In 1’s <strong>in</strong>duction step, <strong>the</strong><br />

freshness condition can always be satisfied by <strong>the</strong> renam<strong>in</strong>g <strong>of</strong> bound variables; 2’s<br />

<strong>in</strong>duction step uses Lemma 5.1.16 <br />

Lemma 5.1.22 (Expansion Preserves Freshness)<br />

1. If D : (expand h (A; M) = M) and x#h and x#M <strong>the</strong>n x#M<br />

2. If D : (expand h (A; M) = M) and x#M <strong>the</strong>n x#h and x#M<br />

91


Pro<strong>of</strong>: Both cases are by straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> D us<strong>in</strong>g<br />

5.1.17. <br />

Lemma 5.1.23 (Trivial Substitution on Eta Expansion)<br />

If D : (expand h (A; M) = M) and x#h and [N/x]τA = A ′ and [N/x]τM = M ′ <strong>the</strong>n<br />

[N/x]τM = M ′ and expand h (A ′ ; M ′ ) = M ′ .<br />

Pro<strong>of</strong>: By straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> D, us<strong>in</strong>g Lemma 5.1.18. <br />

Lemma 5.1.24 (Undo<strong>in</strong>g Concatenation <strong>in</strong> Reduction)<br />

If D : (Γ; A ⊢ M0 : Πx:B1.B2) and E : (Γ ⊢ M : A) and Γ ⊢ M1 : B1 and F :<br />

M0@M1 = M and G : (reduceA −(M, M) = N) <strong>the</strong>n reduceA −(M, M0) = λx:B1.N ′<br />

and [M1/x] B −<br />

1 N ′ = N<br />

Pro<strong>of</strong>: By <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> M0; <strong>the</strong> reason<strong>in</strong>g is straightforward, but<br />

<strong>the</strong> case analysis is not. We show both cases below.<br />

Case:<br />

D =<br />

E =<br />

Γ; Πx:B1.B2 ⊢ · : Πx:B1.B2<br />

E0<br />

Γ ⊢ B1 : type<br />

E1<br />

Γ, x:B1 ⊢ M : B2<br />

Γ ⊢ λx:B1.M : Πx:B1.B2<br />

F = · @M1 = M1 :: ·<br />

G =<br />

G0<br />

[M1/x] B −<br />

1<br />

reduce −<br />

B1 →B− 2<br />

TERM-LIST-NIL<br />

TERM-LAM<br />

M = N reduce −<br />

B (N, ·) = N<br />

2<br />

(λx:B1.M, M1 :: ·) = N ′<br />

reduceτ(λx:B1.M, ·) = λx:B1.M by rule<br />

[M1/x] −<br />

B M = N given (G0)<br />

1<br />

92


Case:<br />

D =<br />

E =<br />

F =<br />

G =<br />

Γ ⊢ M ′ : A ′ 2<br />

D0<br />

Γ ⊢ M0 : A1<br />

D1<br />

[M0/x] −<br />

A<br />

A2 = A<br />

1<br />

′ 2<br />

Γ; Πy:A1.A2 ⊢ M0 :: M0 : Πx:B1.B2<br />

E0<br />

Γ ⊢ A1 : type<br />

E1<br />

Γ, y:A1 ⊢ M : A2<br />

Γ ⊢ λy:A1.M : Πy:A1.A2<br />

G0<br />

[M0/y] −<br />

A M = M<br />

1<br />

′<br />

F0<br />

M0@M1 = M<br />

(M0 :: M0)@M1 = M0 :: M<br />

reduce −<br />

A1 →A− 2<br />

reduce A −<br />

2 (M ′ , M0) = λx:B1.N ′<br />

D2<br />

Γ; A ′ 2 ⊢ M0 : Πx:B1.B2<br />

G1<br />

TERM-LAM<br />

reduce −<br />

A (M<br />

2<br />

′ , M) = N<br />

(λy:A1.M, M0 :: M) = N<br />

by Theorem 5.1.12 and Lemma 5.1.3<br />

and [M1/x] B 1 −N ′ = N by IH on M0<br />

reduce A −<br />

1 →A−<br />

2 (λy:A1.M, M0 :: M0) = λx:B1.N ′ by rule<br />

Theorem 5.1.25 (Soundness <strong>of</strong> Eta Expansion)<br />

1. If h:A ∈ Γ or h:A ∈ Σ and Γ; A ⊢ M : B and D : (expand h (B; M) = M) <strong>the</strong>n<br />

Γ ⊢ M : B<br />

2. If expand x (B; ·) = M <strong>the</strong>n:<br />

(a) if D : (Γ ⊢ K : k<strong>in</strong>d) <strong>the</strong>n [M/x]B−K = K<br />

93


(b) if D : (Γ; K ⊢ N : K ′ ) <strong>the</strong>n [M/x]B−N = N<br />

(c) if D : (Γ ⊢ A : type) <strong>the</strong>n [M/x]B−A = A<br />

(d) if D : (Γ; A ⊢ N : A ′ ) <strong>the</strong>n [M/x]B−N = N<br />

(e) if D : (Γ ⊢ N : A) <strong>the</strong>n [M/x]B−N = N<br />

3. If D : (expand h (B; M0) = M) and E : (Γ; B ⊢ M1 : a N) and F : (M0@M1 =<br />

M) <strong>the</strong>n reduceB −(M, M1) = h M<br />

4. If Γ ⊢ N : A and Γ; A ⊢ M : B and x#A and x#M and x#B and D : expand x (B; M) =<br />

M <strong>the</strong>n reduceA−(N, M) = M ′ ′<br />

and [N/x]A−M = M<br />

Pro<strong>of</strong>: By mutual <strong>in</strong>duction. 2 is by <strong>in</strong>duction on B − followed by <strong>the</strong> structure <strong>of</strong><br />

<strong>the</strong> th<strong>in</strong>g be<strong>in</strong>g substituted <strong>in</strong>to, 3 is by <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> B − followed by<br />

M0, and all <strong>of</strong> <strong>the</strong> o<strong>the</strong>r cases are by <strong>in</strong>duction B − followed by a dummy order<strong>in</strong>g.<br />

We show some representative cases below. <br />

1.<br />

Case:<br />

D =<br />

D0<br />

expand x (B1; ·) = M1 x#M M@M1 = M2<br />

expand h (Πx:B1.B2; M) = λx:B1.M<br />

h:A ∈ Γ or h:A ∈ Σ and Γ; A ⊢ M : Πx:B1.B2<br />

D1<br />

expand h (B2; M2) = M<br />

given<br />

Γ ⊢ Πx:B1.B2 : type by Regularity for Typ<strong>in</strong>g<br />

Γ ⊢ B1 : type and Γ, x:B1 ⊢ B2 : type by <strong>in</strong>version for typ<strong>in</strong>g<br />

Γ; B1 ⊢ · : B1<br />

Γ, x:B1 ⊢ M1 : B1<br />

[M1/x] B −<br />

1 B2 = B2<br />

94<br />

by rule (TERM-LIST-NIL)<br />

by IH 1 on B − 1<br />

by IH 2 on B − 1


2.<br />

3.<br />

Case:<br />

Case:<br />

Γ, x:B1; A ⊢ M : Πx:B1.B2<br />

Γ, x:B1; A ⊢ M2 : B2<br />

Γ, x:B1 ⊢ M : B2<br />

Γ ⊢ λx:B1.M : Πx:B1.B2<br />

D =<br />

D0<br />

Γ ⊢ N : A1<br />

D1<br />

[N/y] −<br />

A<br />

A2 = A<br />

1<br />

′ 2<br />

Γ; Πy:A1.A2 ⊢ N :: N : A ′ 1<br />

by Weaken<strong>in</strong>g for Typ<strong>in</strong>g<br />

by Lemma 5.1.18<br />

by IH 1 on B − 2<br />

by rule (TERM-LAM )<br />

D2<br />

Γ; A ′ 2 ⊢ N : A′ 1<br />

TERM-LIST-CONS<br />

expand h (B; ·) = M given<br />

[M/x]B −N = N by IH 2 on B− and N<br />

[M/x]B −N = N by IH 2 on B− and N<br />

[M/x]B−(N :: N) = N :: N by rule<br />

D =<br />

expand x (B; ·) = M<br />

x:B <strong>in</strong> Γ<br />

D0<br />

Γ; B ⊢ M : a N<br />

Γ ⊢ x M : a N<br />

TERM-ATM-V<br />

[M/x]B −M = M by IH 2 on B− and M<br />

Γ; B ⊢ · : B by rule (TERM-LIST-NIL)<br />

M@· = M by rule<br />

reduceB −(M, M) = x M by IH 3 on B− and M<br />

[M/x]B−x M = x M by rule<br />

95


4.<br />

Case:<br />

D =<br />

E =<br />

D0<br />

expand x (B1; ·) = M0<br />

E0<br />

Γ ⊢ M1 : B1<br />

[M1/x] B −<br />

1 M0 = M0<br />

Γ; B1 ⊢ · : B1<br />

reduce B −<br />

1 (M1, ·) = M1<br />

x#B1<br />

x#M0<br />

D1<br />

M0@M0 = M<br />

expand h (Πx:B1.B2; M0) = λx:B1.M<br />

E1<br />

[M1/x] −<br />

B<br />

B2 = B<br />

1<br />

′ 2<br />

Γ; Πx:B1.B2 ⊢ M1 :: M1 : a N0<br />

F =<br />

F0<br />

M0@M1 = M ′ 0<br />

E2<br />

Γ; B ′ 2 ⊢ M1 : a N0<br />

F1<br />

M ′ 0 @M1 = N<br />

M0@(M1 :: M1) = N<br />

D2<br />

expand h (B2; M) = M<br />

TERM-LIST-CONS<br />

by Lemma 5.1.8<br />

by rule (TERM-LIST-NIL)<br />

by rule<br />

by <strong>the</strong> well-formedness <strong>of</strong> Πx:B1.B2<br />

[M1/x] B −<br />

1 M0 = M1 by IH 4 on B − 1 and Lemma 5.1.3<br />

[M1/x] B −<br />

1 M = M ′ 0<br />

by Lemma 5.1.18 and Lemma 5.1.16<br />

expand h (B ′ 2; M ′ 0) = M ′ and [M1/x] B −<br />

1 M = M ′ by Lemma 5.1.23<br />

B ′−<br />

2 = B − 2 by Lemma 5.1.10<br />

reduce B ′−<br />

2 (M ′ , M1) = h N by IH 3 on B ′−<br />

2 and M1<br />

reduce B −<br />

1 →B−<br />

2 (λx:B1.M, M1 :: M1) = h N by rule<br />

96


Case:<br />

D0<br />

expand y (B1; ·) = M1 y#M<br />

Γ ⊢ N : A and Γ; A ⊢ M : Πy:B1.B2<br />

and x#A and x#M and x#Πy:B1.B2<br />

Γ, y:B1; B1 ⊢ · : B1<br />

Γ, y:B1 ⊢ M1 : B1<br />

Γ, y:B1; A ⊢ M : Πy:B1.B2<br />

D1<br />

M@M1 = M2<br />

expand x (Πy:B1.B2; M) = λy:B1.M<br />

D2<br />

expand x (B2; M2) = M<br />

given<br />

by rule (TERM-LIST-NIL)<br />

by IH 1 on B − 1<br />

by Weaken<strong>in</strong>g for Typ<strong>in</strong>g<br />

Γ ⊢ A : type by Regularity for Typ<strong>in</strong>g<br />

Γ ⊢ Πy:B1.B2 : type by Regularity for Typ<strong>in</strong>g<br />

Γ, y:B1 ⊢ B2 : type by <strong>in</strong>version for typ<strong>in</strong>g<br />

[M1/y] B −<br />

1 B2 = B2<br />

Γ, y:B1; A ⊢ M2 : B2<br />

by IH 2 on B − 1<br />

by Lemma 5.1.19<br />

x#y by <strong>the</strong> renamability <strong>of</strong> bound variables<br />

x#B1 and x#B2<br />

x#M1<br />

x#M2<br />

by def <strong>of</strong> fresh<br />

by Lemma 5.1.22<br />

by Lemma 5.1.17<br />

reduceA −(N, M2) = M ′ and [N/x]A −M = M ′ by IH 4 on B − 2<br />

Γ, y:B1 ⊢ N : A by Weaken<strong>in</strong>g for Typ<strong>in</strong>g<br />

′′<br />

reduceA−(N, M) = λy:B1.M<br />

and [M1/x] B −<br />

1 M ′′ = M ′ by Lemma 5.1.24<br />

Γ ⊢ λy:B1.M ′′ : Πy:B1.B2<br />

by Theorem 5.1.12 and Lemma 5.1.3<br />

[M1/x] B −<br />

1 M ′′ = M ′′ by IH 2 on B − 1<br />

97


M ′′ = M ′ by Lemma 5.1.3<br />

reduceA −(N, M2) = λy:B1.M ′ by equality<br />

[N/x]A −B1 = B1<br />

by Lemma 5.1.8<br />

[N/x]A −λy:B1.M = λy:B1.M ′ by rule<br />

5.2 Logic Programm<strong>in</strong>g<br />

At <strong>the</strong> beg<strong>in</strong>n<strong>in</strong>g <strong>of</strong> this chapter, we sketched a search procedure for f<strong>in</strong>d<strong>in</strong>g a deriva-<br />

tion <strong>of</strong> a given judgment. In this section, we will formalize this idea by describ<strong>in</strong>g a<br />

procedure that f<strong>in</strong>ds LF terms <strong>of</strong> a given LF type.<br />

5.2.1 Mixed Prefix Contexts and Generalized Substitutions<br />

In order to def<strong>in</strong>e pro<strong>of</strong> search, we need some way to model logic variables. One<br />

possibility would be to def<strong>in</strong>e logic variables us<strong>in</strong>g contextual modal type <strong>the</strong>ory<br />

[NPP08], but this would <strong>in</strong>volve a non-trivial extension to our sp<strong>in</strong>e calculus pre-<br />

sentation <strong>of</strong> canonical LF. Instead, we model logic variables us<strong>in</strong>g ord<strong>in</strong>ary LF vari-<br />

ables, but we have to be careful. If y is considered a logic variable <strong>in</strong> a query <strong>of</strong><br />

<strong>the</strong> form Γ, y:B ⊢ ? : Πx:A1.A2 (i.e. y is a placeholder for an as-<strong>of</strong>-yet unde-<br />

term<strong>in</strong>ed LF term), <strong>the</strong>n we expect pro<strong>of</strong> search to proceed by solv<strong>in</strong>g <strong>the</strong> query<br />

Γ, y:B, x:A1 ⊢ ? : A2. But, unlike y, x is not <strong>in</strong>tended to serve as a placeholder<br />

for anyth<strong>in</strong>g; it is an actual variable that will be bound by a λ. In o<strong>the</strong>r words x<br />

and y are very different k<strong>in</strong>ds <strong>of</strong> variables, and need to be treated as such. To this<br />

end, we express queries <strong>in</strong> terms <strong>of</strong> LF contexts that have been augmented with flags<br />

to dist<strong>in</strong>guish <strong>the</strong> two notions <strong>of</strong> variable. Such augmented contexts are known as<br />

mixed-prefix contexts [Mil92b] and have previously been used <strong>in</strong> a sett<strong>in</strong>g similar to<br />

98


this one <strong>in</strong> [RP96, Roh96].<br />

Mixed-prefix Context ∆ ::= · | ∆, ∀x:A | ∆, ∃x:A<br />

Intuitively, existentially-quantified variables can be thought <strong>of</strong> as logic variables, and<br />

universally quantified variables can be thought <strong>of</strong> as actual variables. As with ordi-<br />

nary LF contexts, we assume that all variable declarations <strong>in</strong> a mixed prefix context<br />

are unique; this can typically be achieved by <strong>the</strong> tacit renam<strong>in</strong>g <strong>of</strong> bound variables.<br />

Likewise, we assume that generalized substitutions act on any given variable at most<br />

once. A mixed-prefix context can be converted to an ord<strong>in</strong>ary context us<strong>in</strong>g |∆|, and<br />

an ord<strong>in</strong>ary context can be converted to a mixed-prefix context us<strong>in</strong>g ∃Γ and ∀Γ.<br />

|·| = ·<br />

|∆, ∀x:A| = |∆|, x:A<br />

|∆, ∃x:A| = |∆|, x:A<br />

∀(·) = ·<br />

∀(Γ, x:A) = (∀Γ), ∀x:A<br />

∃(·) = ·<br />

∃(Γ, x:A) = (∃Γ), ∃x:A<br />

We say that a mixed prefix context is raised if all <strong>of</strong> its existentially quantified<br />

variables occur at <strong>the</strong> beg<strong>in</strong>n<strong>in</strong>g <strong>of</strong> <strong>the</strong> context. We formalize this concept, which<br />

will be useful later sections, with <strong>the</strong> judgment below.<br />

⊢ ∃Γ raised<br />

⊢ ∆ raised<br />

⊢ ∆, ∀x:A raised<br />

The notion <strong>of</strong> logic variable <strong>in</strong>stantiation is captured by <strong>the</strong> notion <strong>of</strong> generalized<br />

99


substitution, def<strong>in</strong>ed below.<br />

Generalized Substitutions θ ::= · | θ, y/x | θ, M:A/x<br />

Generalized substitutions can be applied to LF variables, terms, sp<strong>in</strong>es, type families<br />

and k<strong>in</strong>ds. Apply<strong>in</strong>g generalized substitutions to LF variables yields ei<strong>the</strong>r a variable<br />

(<strong>in</strong> <strong>the</strong> case <strong>of</strong> universally quantified variables), or a term with its type (<strong>in</strong> <strong>the</strong> case <strong>of</strong><br />

existentially quantified variables). We present <strong>the</strong> def<strong>in</strong><strong>in</strong>g equations for generalizes<br />

substitution below. Note that, as usual, <strong>the</strong>se equations should be viewed as be<strong>in</strong>g<br />

noth<strong>in</strong>g more than a more compact notation for <strong>in</strong>ference rules. Although generalized<br />

substitution application is decidable, it may, <strong>in</strong> general, be undef<strong>in</strong>ed.<br />

(θ, M:A/x) x = M:A<br />

(θ, M:A/x) y = (θ)y if y = x<br />

(θ, y/x) x = y<br />

(θ, y/x) x ′ = (θ)x ′ if x ′ = x<br />

θ (c M) = c N if θM = N<br />

⎧<br />

⎪⎨ y N<br />

if θ x = y and θM = N<br />

θ (x M) =<br />

⎪⎩ reduceA−(M, N)<br />

if θ x = M:A and θM = N<br />

θ (λx:A.M) = λy:B.N if θA = B and (θ, y/x)M = N and y#θ<br />

θ (·) = ·<br />

θ(M :: M) = N :: N if θM = N and θM = N<br />

θ (a M) = a N if θM = N<br />

θ (Πx:A.B) = Πy:A ′ .B ′ if θA = A ′ and (θ, y/x)B = B ′ and y#θ<br />

θ (type) = type<br />

θ (Πx:A.K) = Πy:A ′ .K ′ if θA = A ′ and (θ, y/x)K = K ′ and y#θ<br />

100


The typ<strong>in</strong>g rules for generalized substitutions are def<strong>in</strong>ed below.<br />

· ⊢ · : ·<br />

gsub-nil<br />

∆ ′ ⊢ θ : ∆ θA = A ′<br />

∆ ′ ⊢ θ : ∆ θA = A ′<br />

∆ ′ , ∀y:A ′ ⊢ θ, y/x : ∆, ∀x:A<br />

|∆ ′ | ⊢ M : A ′<br />

∆ ′ ⊢ θ, M:A ′ /x : ∆, ∃x:A<br />

∆ ′ ⊢ θ : ∆ |∆ ′ | ⊢ A : type gsub-weak<br />

∆ ′ , ∃x:A ⊢ θ : ∆<br />

|∆ ′ | ⊢ A ′ : type gsub-avar<br />

gsub-evar<br />

We proceed by prov<strong>in</strong>g some useful properties <strong>of</strong> generalized substitutions.<br />

Lemma 5.2.1 (Typ<strong>in</strong>g Inversion for Generalized Substitutions)<br />

1. If ∆ ′ ⊢ θ : ∆, ∀x:A <strong>the</strong>n θ = θ0, y/x and ∆ ′ = ∆ ′ 0, ∀y:A ′ , ∃Γ and ∆ ′ 0 ⊢ θ0 : ∆<br />

and θ0A = A ′<br />

2. If ∆ ′ ⊢ θ, y/x : ∆ <strong>the</strong>n ∆ = ∆0, ∀x:A and ∆ ′ = ∆ ′ 0, ∀y:A ′ , ∃Γ and ∆ ′ 0 ⊢ θ : ∆0<br />

and θ0A = A ′ and |∆ ′ 0| ⊢ A ′ : type<br />

3. If ∆ ′ , ∀y:A ′ ⊢ θ : ∆ <strong>the</strong>n θ = θ0, y/x and ∆ = ∆0, ∀x:A and ∆ ′ ⊢ θ0 : ∆0 and<br />

θ0A = A ′ and |∆ ′ | ⊢ A ′ : type.<br />

4. If ∆ ′ ⊢ θ : ∆, ∃x:A <strong>the</strong>n θ = θ0, M:A ′ /x and ∆ ′ ⊢ θ : ∆ and θ0A = A ′ and<br />

|∆ ′ | ⊢ M : A ′<br />

5. If ∆ ′ ⊢ θ, M:A/x : ∆ <strong>the</strong>n ∆ = ∆0, ∃x:A and ∆ ′ ⊢ θ : ∆0 and |∆ ′ | ⊢ M : A<br />

6. If ∆ ′ , ∃y:A ⊢ θ : ∆ <strong>the</strong>n ∆ ′ ⊢ θ : ∆ and |∆ ′ | ⊢ A : type<br />

7. If ∆ ′ ⊢ θ : · <strong>the</strong>n θ = · and ∆ ′ = ∃Γ<br />

8. If ∆ ′ ⊢ · : ∆ <strong>the</strong>n ∆ = · and ∆ ′ = ∃Γ<br />

9. If · ⊢ θ : ∆ <strong>the</strong>n ∆ = · and θ = ·<br />

101


Pro<strong>of</strong>: 1, 2, 4, 5, 7 and 8 are by straightforward <strong>in</strong>ductions on <strong>the</strong> structures <strong>of</strong> <strong>the</strong><br />

given typ<strong>in</strong>g derivations; <strong>the</strong> o<strong>the</strong>rs are direct, by cases. <br />

Lemma 5.2.2 (Properties <strong>of</strong> Generalized Substitutions) Let E be any <strong>of</strong><br />

{K, A, M, M}<br />

1. If θE = E ′ and θE = E ′′ <strong>the</strong>n E ′ = E ′′<br />

2. If (θ, X/x, Y/y)E = E ′ and x#y, where X = x ′ or X = M:A and Y = y ′ or<br />

y = N:A <strong>the</strong>n (θ, Y/y, X/x)E = E ′<br />

3. If x#E and ei<strong>the</strong>r (θ, y/x)E = E ′ or (θ, M:A/x)E = E ′ <strong>the</strong>n θE = E ′<br />

4. If <strong>the</strong> free variables <strong>of</strong> E are among x1, . . . , xn, <strong>the</strong>n (θ, x1/x1, . . . , xn/xn)E =<br />

E<br />

5. If x#θ and θE = E ′ <strong>the</strong>n x#E ′<br />

Pro<strong>of</strong>: By straightforward <strong>in</strong>ductions over <strong>the</strong> given derivations <strong>of</strong> generalized sub-<br />

stitution application. Note that 4 can be described judgmentally, but that we use<br />

<strong>the</strong> more <strong>in</strong>formal ellipses for <strong>the</strong> sake <strong>of</strong> readability. <br />

Lemma 5.2.3 (Generalized and Hereditary Substitutions Commute) Let E<br />

be any <strong>of</strong> {K, A, M, M}<br />

1. If D : [M/x]τE = E ′ and (θ, y/x)E = E0 and θM = M0 <strong>the</strong>n <strong>the</strong>re exists some<br />

E ′ 0 s.t. [M0/y]τE0 = E ′ 0 and θE ′ = E ′ 0<br />

2. If D : reduceτ(M, N) = N ′ and θM = M0 and θN = N0 <strong>the</strong>n <strong>the</strong>re exists<br />

some N ′ 0 s.t. reduceτ(M0, N0) = N ′ 0 and θN ′ = N ′ 0.<br />

Pro<strong>of</strong>: By mutual <strong>in</strong>duction D. We show some representative cases below.<br />

102


1.<br />

2.<br />

Case:<br />

Case:<br />

D =<br />

D0<br />

[M/x]τ N = N ′<br />

D1<br />

reduceτ (M, N ′ ) = N ′<br />

[M/x]τ x N = N ′<br />

(θ, y/x) (x N) = y N0 and (θ, y/x) M = M0<br />

(θ, y/x) N = N0<br />

reduceτ(M0, N0) = N ′ 0 and θN ′ = N ′ 0<br />

[M0/y]τy N0 = N ′ 0<br />

D =<br />

D0<br />

[M/x]τ A = A ′<br />

given<br />

by <strong>in</strong>version on gsub application<br />

D1<br />

[M/x]τ B = B ′ x#z<br />

[M/x]τ Πz:A.B = Πz:A ′ .B ′<br />

(θ, y/x) Πz:A.B = Πz0:A0.B0 and (θ, y/x)M = M0<br />

(θ, y/x)A = A0 and (θ, y/x, z0/z)B = B0<br />

[M0/y]τA0 = A ′ 0 and θA ′ = A ′ 0<br />

(θ, z0/z, y/x)B = B0<br />

[M0/y]τB0 = B ′ 0 and (θ, z0/z)B ′ = B ′ 0<br />

[M0/y]τΠz0:A0.B0 = Πz0:A ′ 0.B ′ 0<br />

θΠz:A ′ .B ′ = Πz0:A ′ 0.B ′ 0<br />

103<br />

by IH 2 on D1<br />

by rule<br />

given<br />

by <strong>in</strong>version on gsub application<br />

by IH 1 on D0<br />

by Lemma 5.2.2<br />

by IH 1 on D1<br />

by rule<br />

by rule


Case:<br />

D =<br />

D0<br />

[N/x]τ M = M ′<br />

D1<br />

reduceβ(M ′ , N) = N ′<br />

reduceτ→β(λx:A.M, N :: N) = N ′<br />

θ(λx:A.M) = λy:A0.M0 and θ(N :: N) = N0 :: N0<br />

θA = A0 and (θ, y/x)M = M0 and θN = N0 and θN = N0<br />

[N0/x]τM0 = M ′ 0 and θM ′ = M ′ 0<br />

reduceτ(M ′ 0, N0) = N ′ 0 and θN ′ = N ′ 0<br />

reduceτ→β(λy:A0.M0, N0 :: N0) = N ′ 0<br />

given<br />

by <strong>in</strong>version on gsub application<br />

by IH 1 on D0<br />

by IH 2 on D1<br />

by rule<br />

Lemma 5.2.4 (Generalized Substitutions are Simultaneous) If A − = τ and<br />

E is any <strong>of</strong> {K, A, M, M} (θ, M ′ :A/x)E0 = E ′ and (θ, y/x)E0 = E <strong>the</strong>n [M ′ /y]τE =<br />

E ′<br />

Pro<strong>of</strong>: By straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> E0, us<strong>in</strong>g Lemma 5.2.3<br />

clause 2. <br />

Lemma 5.2.5 (Weaken<strong>in</strong>g for Generalized Substitutions) For E <strong>in</strong> {K, A, M, M},<br />

if y#E and θE = E ′ <strong>the</strong>n (θ, y/x)E = E ′ and (θ, M:B/x)E = E ′<br />

Pro<strong>of</strong>: By a straightforward <strong>in</strong>duction on <strong>the</strong> derivation <strong>of</strong> θE = E ′ ; note that x#θ<br />

must hold <strong>in</strong> order for θ, y/x and θ, M:A/x to be well formed. <br />

Lemma 5.2.6 (Generalized Substitutions on Variables) If D : ∆ ′ ⊢ θ : ∆<br />

<strong>the</strong>n:<br />

1. If ∀x:A ∈ ∆ <strong>the</strong>n θx = y and θA = B and ∀y:B ∈ ∆ ′<br />

104


2. If ∃x:A ∈ ∆ <strong>the</strong>n θx = M:B and θA = B and |∆ ′ | ⊢ M : B<br />

3. If ∀x:A ∈ ∆ and ∀y:B ∈ ∆ and x#y <strong>the</strong>n θx#θy<br />

Pro<strong>of</strong>: Each follows from a straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> D, us<strong>in</strong>g<br />

Lemma 5.2.5 for both 1 and 2, and Weaken<strong>in</strong>g for Typ<strong>in</strong>g <strong>in</strong> 2. 3 uses <strong>the</strong> fact that<br />

mixed prefix contexts cannot conta<strong>in</strong> duplicate variable-name declarations. <br />

Lemma 5.2.7 (Generalized Substitutions) If ∆ ′ ⊢ θ : ∆ <strong>the</strong>n:<br />

1. if ⊢ |∆| : ctx <strong>the</strong>n ⊢ |∆ ′ | : ctx<br />

2. if D : |∆| ⊢ K : k<strong>in</strong>d <strong>the</strong>n θK = K ′ and |∆ ′ | ⊢ A ′ : k<strong>in</strong>d<br />

3. if D : |∆|; A ⊢ M : type and θA = A ′ <strong>the</strong>n θM = M ′ and |∆ ′ |; A ′ ⊢ M ′ : type<br />

4. if D : |∆| ⊢ A : type <strong>the</strong>n θA = A ′ and |∆ ′ | ⊢ A ′ : type<br />

5. if D : |∆|; A ⊢ M : B and θA = A ′ <strong>the</strong>n θM = M ′ and θB = B ′ and<br />

|∆ ′ |; A ′ ⊢ M ′ : B ′<br />

6. if D : |∆| ⊢ M : A <strong>the</strong>n θM = M ′ and θA = A ′ and |∆ ′ | ⊢ M ′ : A ′<br />

Pro<strong>of</strong>: 1 is by <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> ∆ ′ ⊢ θ : ∆; 2-6 are by mutual <strong>in</strong>ductions<br />

on <strong>the</strong> structure <strong>of</strong> D. The non-trivial TERM-ATM-V case uses Theorem 5.1.12;<br />

<strong>the</strong> FAM-LIST-CONS and TERM-LIST-CONS cases use Lemma 5.2.3. <br />

Def<strong>in</strong>ition 5.2.8 (Composition <strong>of</strong> Generalized substitutions) Generalized sub-<br />

stitutions can be composed as follows.<br />

θ ◦ · = θ<br />

(θ, z/y) ◦ (θ ′ , y/x) = (θ ◦ θ ′ ), z/x<br />

(θ, M:A/z) ◦ (θ ′ , y ′ /x) = θ ′ ◦ (θ ′ , y/x) if y#z and θ ′ y = y ′<br />

θ ◦ (θ ′ , M:A/x) = (θ ◦ θ ′ ), N:B/x if θM = N and θA = B<br />

105


Lemma 5.2.9 (Composition <strong>of</strong> Generalized Substitutions) Let E be any <strong>of</strong><br />

{K, A, M, M}<br />

1. If θ2 ◦ θ1 = θ <strong>the</strong>n<br />

(a) θ2(θ1 x) = y iff θx = y<br />

(b) θ2(θ1 x) = M:A iff θx = M:A<br />

(c) θ2(θ1E) = E ′ iff θE = E ′ where E is any <strong>of</strong> {K, A, M, M}<br />

2. If ∆ ′′ ⊢ θ2 : ∆ ′ and ∆ ′ ⊢ θ1 : ∆ <strong>the</strong>n <strong>the</strong>re exists some θ s.t. θ2 ◦ θ1 = θ and<br />

∆ ′′ ⊢ θ : ∆<br />

3. If θ0 ◦ θ1 = θ and θ0 ◦ θ1 = θ ′ <strong>the</strong>n θ = θ ′<br />

Pro<strong>of</strong>: 1 (a) and (b) follow by a straightforward <strong>in</strong>duction on <strong>the</strong> derivation <strong>of</strong><br />

θ2 ◦ θ1 = θ, whereas 1 (c) follows by <strong>in</strong>duction on E. 2 follows by <strong>in</strong>duction on <strong>the</strong><br />

natural sum <strong>of</strong> θ1 and θ2, us<strong>in</strong>g Lemma 5.2.1. 3 is by straightforward <strong>in</strong>duction on<br />

<strong>the</strong> derivation <strong>of</strong> θ0 ◦ θ1. <br />

Lemma 5.2.10 (Generalized Substitutions and Eta)<br />

1. If D : M@M = N and θM = M ′ and θM = M ′ <strong>the</strong>n <strong>the</strong>re exists N ′ s.t.<br />

M ′ @M ′ = N and θN = N ′<br />

2. If D : expand h (A; M) = N and x#h x#A and x#M <strong>the</strong>n x#M<br />

3. If D : expand x (A; M) = M0 and θx = y and θA = B and θM = N <strong>the</strong>n <strong>the</strong>re<br />

exists an N0 s.t. θM0 = N0 and expand y (B; N) = N0<br />

Pro<strong>of</strong>: By straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> D. 1 and 2 are self-<br />

conta<strong>in</strong>ed (i.e. <strong>the</strong> <strong>in</strong>duction is not mutual), whereas 3 uses 1 and 2. We show<br />

<strong>the</strong> <strong>in</strong>duction step for 3 below.<br />

106


D =<br />

D0<br />

expand z (A1; ·) = M z#M<br />

D1<br />

M@M = M ′<br />

expand x (Πz:A1.A2; M) = λz:A1.M0<br />

D2<br />

expand x (A2; M ′ ) = M0<br />

θx = y and θ(Πz:A1.A2) = Πz ′ :B1.B2 and θM = N given<br />

x#z by renamability <strong>of</strong> bound variables<br />

θA1 = B1 and (θ, z ′ /z)A2 = B2 and z ′ #θ by <strong>in</strong>version on gsub app<br />

z ′ #N by Lemma 5.2.2 no. 5<br />

θ· = · by rule<br />

expand x (B1; ·) = N and θM = N by IH 3 on D0<br />

N@N = N ′ and θM ′ = N ′ by IH 1 on D1<br />

(θ, z ′ /z)M0 = N0 and expand x (B2; N ′ ) = N0<br />

(θ)λz:A1.M0 = λz ′ :B1.N0<br />

expand x (Πz ′ :B1.B2; N) = λz ′ :B1.N0<br />

5.2.2 The Semantics <strong>of</strong> Logic Programm<strong>in</strong>g<br />

by IH 3 on D1<br />

by def <strong>of</strong> gsub app<br />

by rule<br />

Given LF terms M and N that are well-formed <strong>in</strong> <strong>the</strong> mixed-prefix context ∆, it is<br />

natural to ask whe<strong>the</strong>r <strong>the</strong>re is some <strong>in</strong>stantiation <strong>in</strong> <strong>the</strong> logic variables <strong>of</strong> ∆ such<br />

that M and N are <strong>in</strong>dist<strong>in</strong>guishable. We refer to such a problem as a unification<br />

equation, which we write ∆ ⊢ M • = N. The solution to such an equation is a unifier,<br />

which we def<strong>in</strong>e below. Unification will play an important role <strong>in</strong> def<strong>in</strong><strong>in</strong>g pro<strong>of</strong><br />

search.<br />

Def<strong>in</strong>ition 5.2.11 (Unifiers) ∆ ′ ⊢ θ : ∆ is a unifier (or solution) for <strong>the</strong> unifica-<br />

107


tion equation ∆ ⊢ E • = E ′ (for any E <strong>in</strong> {A, M, M, K}) iff θE = E ′′ and θE ′ = E ′′<br />

and E is well-formed <strong>in</strong> |∆|. A unifier ∆ ′ ⊢ θ : ∆ is a most general unifier for <strong>the</strong><br />

equation ∆ ⊢ E • = E ′ iff, for all unifiers ∆ ′′ ⊢ θ ′ : ∆, <strong>the</strong>re exists ∆ ′′ ⊢ θ ′′ : ∆ ′ s.t.<br />

θ ′′ ◦ θ = θ ′ . We sometimes refer to θ as be<strong>in</strong>g a (most general) unifier when θ’s type<br />

is clear from <strong>the</strong> context.<br />

Unfortunately, unification is an undecidable problem for LF terms, and <strong>the</strong> ex-<br />

istence <strong>of</strong> a solution to a unification equation does not guarantee <strong>the</strong> existence <strong>of</strong> a<br />

most general unifier. However, <strong>the</strong>re are algorithms that can solve a decidable subset<br />

<strong>of</strong> <strong>the</strong> unification equations for LF, known as higher-order pattern match<strong>in</strong>g for which<br />

<strong>the</strong> existence <strong>of</strong> a unifier implies <strong>the</strong> existence <strong>of</strong> a most general unifier[Mil91]. We<br />

assume that we are given <strong>the</strong> judgmental specification <strong>of</strong> such an algorithm, written<br />

here as unify(∆ ⊢ E • = E ′ ) ∆′<br />

=⇒ θ when <strong>the</strong> algorithm succeeds <strong>in</strong> f<strong>in</strong>d<strong>in</strong>g a most<br />

general unifier ∆ ′ ⊢ θ : ∆ for E and E ′ , and unify(∆ ⊢ E • = E ′ ) =⇒ fail when <strong>the</strong><br />

algorithm fails to f<strong>in</strong>d such a unifier. We view <strong>the</strong> follow<strong>in</strong>g proposition as part <strong>of</strong><br />

<strong>the</strong> specification <strong>of</strong> unification. Its pro<strong>of</strong> should be syntactically f<strong>in</strong>itary.<br />

Proposition 5.2.12 (Decidability, Well-Formedness <strong>of</strong> Unification) For ev-<br />

ery E <strong>in</strong> {M, M, A, K}<br />

1. ei<strong>the</strong>r unify(∆ ⊢ E • = E ′ ) ∆′<br />

=⇒ θ or unify(∆ ⊢ E • = E ′ ) =⇒ fail<br />

2. If unify(∆ ⊢ E • = E ′ ) ∆′<br />

=⇒ θ <strong>the</strong>n ∆ ′ ⊢ θ : ∆ and ⊢ ∆ ′ raised and θ is a<br />

(most general) 2 unifier for E and E ′ .<br />

It should be noted that, although we do not require <strong>the</strong> unification algorithm to<br />

be complete (<strong>in</strong>deed, no such algorithm exists), we do expect it to be nontrivial <strong>in</strong><br />

2 The fact that θ is most general will not be used <strong>in</strong> any <strong>of</strong> our <strong>the</strong>orems; thus, we do not have<br />

to worry about <strong>the</strong> quantifier alternations <strong>in</strong>troduced by <strong>the</strong> notion <strong>of</strong> most general unifier tak<strong>in</strong>g<br />

us out <strong>of</strong> <strong>the</strong> realm <strong>of</strong> <strong>the</strong> syntactically f<strong>in</strong>itary.<br />

108


that it is capable <strong>of</strong> decid<strong>in</strong>g an <strong>in</strong>terest<strong>in</strong>g subset <strong>of</strong> unification problems, such as<br />

higher-order pattern match<strong>in</strong>g.<br />

Below we <strong>in</strong>troduce <strong>the</strong> notion <strong>of</strong> pro<strong>of</strong> search on LF terms as a model <strong>of</strong> computa-<br />

tion. That is, given a mixed-prefix context ∆ and a goal type A (possibly conta<strong>in</strong><strong>in</strong>g<br />

some logic variables), is it possible to f<strong>in</strong>d a term M and a generalized substitution<br />

θ such that ∆ ′ ⊢ θ : ∆ and ∆ ′ ⊢ M : θA? Such a search problem is referred to as a<br />

query, which we write ∆ ⊢ ? : A. In practice, queries performed on atomic-types<br />

are <strong>the</strong> most <strong>in</strong>terest<strong>in</strong>g. This is because family-level constants can be thought <strong>of</strong> as<br />

def<strong>in</strong><strong>in</strong>g relations, where <strong>the</strong> terms M1, . . . , Mn are “related” whenever a M1 . . . Mn<br />

is <strong>in</strong>habited. If we consider some elements <strong>of</strong> <strong>the</strong>se relations to be <strong>in</strong>puts and o<strong>the</strong>rs<br />

to be outputs, LF type-families can provide convenient notations for functions. We<br />

refer to <strong>the</strong> classification <strong>of</strong> <strong>the</strong> <strong>in</strong>put and output arguments for a family-level con-<br />

stant as its mode declaration. Mode declarations are provided by <strong>the</strong> user (i.e. at <strong>the</strong><br />

same level as <strong>the</strong> declaration <strong>of</strong> <strong>the</strong> signature Σ and <strong>the</strong> subord<strong>in</strong>ation relation ⊑),<br />

and every family-level constant that we wish to <strong>in</strong>terpret as a logic program must be<br />

given such a classification. Arguments that are classified as <strong>in</strong>puts are said to have<br />

positive mode and arguments that are classified as outputs are said to have negative<br />

mode.<br />

More precisely, if a:K ∈ Σ, <strong>the</strong>n K must have <strong>the</strong> form Πx0:A0. . . . Πxn:An.type;<br />

a mode declaration for a consists <strong>of</strong> a user-level assignment <strong>of</strong> positive or negative<br />

to each i <strong>in</strong> 0, . . . , n with <strong>the</strong> follow<strong>in</strong>g restriction: if i has positive mode and j has<br />

negative mode, <strong>the</strong>n xj#Ai (that is, <strong>the</strong> types <strong>of</strong> <strong>in</strong>puts cannot depend on <strong>the</strong> types<br />

<strong>of</strong> outputs). If a has a mode declaration, and <strong>the</strong> atomic type a M is well formed,<br />

<strong>the</strong>n M = M0 :: . . . :: Mn :: ·. We can <strong>the</strong>n partition <strong>the</strong> sp<strong>in</strong>e M <strong>in</strong>to two sp<strong>in</strong>es,<br />

<strong>in</strong>puts a (M) and outputs a (M), where Mi is <strong>in</strong> <strong>in</strong>puts a (M) iff i is has positive mode,<br />

and Mi is <strong>in</strong> outputs a (M) iff i has negative mode. Formally, we consider <strong>in</strong>puts<br />

109


and outputs to be user-specified syntactically f<strong>in</strong>itary functions. It should be noted<br />

that <strong>the</strong> fact that <strong>in</strong>put arguments cannot depend on out put arguments guarantees<br />

that both <strong>in</strong>puts a (M) and outputs a (M) are well-formed whenever M is. Thus, we<br />

assume <strong>the</strong> follow<strong>in</strong>g properties hold.<br />

Lemma 5.2.13 (Inputs and Outputs)<br />

1. <strong>in</strong>puts a (M) = <strong>in</strong>puts a (N) and outputs a (N) = outputs a (M) iff N = M<br />

2. If θM = N <strong>the</strong>n θ(<strong>in</strong>puts a (M)) = <strong>in</strong>puts a (N) and θ(outputs a (M)) =<br />

outputs a (N)<br />

Pro<strong>of</strong>: Direct, by <strong>the</strong> def<strong>in</strong>itions <strong>of</strong> <strong>in</strong>puts and outputs. <br />

It should be noted that it is possible for a mode declaration to be <strong>in</strong>valid; that<br />

is, <strong>the</strong> term-level constants <strong>in</strong> Σ may not respect <strong>the</strong> mode declarations given by <strong>the</strong><br />

user. We postpone discuss<strong>in</strong>g mode check<strong>in</strong>g until section 5.2.5.<br />

We are f<strong>in</strong>ally ready to def<strong>in</strong>e <strong>the</strong> semantics <strong>of</strong> pro<strong>of</strong> search. The judgment<br />

fillTerm(∆0 ⊢ ? : A0)<br />

θ<br />

=⇒ 〈∆; M; A〉 formalizes <strong>the</strong> notion <strong>of</strong> search for terms: it<br />

can be thought <strong>of</strong> as be<strong>in</strong>g recursive on <strong>the</strong> structure <strong>of</strong> A0, where <strong>in</strong> <strong>the</strong> base case—<br />

i.e. A0 = a N—it nondeterm<strong>in</strong>istically chooses ei<strong>the</strong>r a variable or constant whose<br />

type has head a, <strong>the</strong>n searches for a sp<strong>in</strong>e. The judgment fillHead(∆; Σ; a) =⇒ h:A<br />

formalizes <strong>the</strong> nondeterm<strong>in</strong>istic choice <strong>of</strong> a variable or constant whose type A satisfies<br />

hd(A) = a: it can be thought <strong>of</strong> as be<strong>in</strong>g recursive on <strong>the</strong> structure <strong>of</strong> Σ and ∆. The<br />

judgment fillSp<strong>in</strong>e(∆0; A0 ⊢ ? : a N0) =⇒ 〈∆; A; M; a N〉 <strong>the</strong> formalizes notion<br />

<strong>of</strong> search for sp<strong>in</strong>es: it can be thought <strong>of</strong> as be<strong>in</strong>g recursive on <strong>the</strong> structure <strong>of</strong><br />

A0 For each <strong>of</strong> <strong>the</strong>se judgments, <strong>the</strong> syntactic categories to <strong>the</strong> left <strong>of</strong> <strong>the</strong> arrow<br />

can be thought <strong>of</strong> as <strong>in</strong>puts, and everyth<strong>in</strong>g else as outputs. The <strong>in</strong>tuition beh<strong>in</strong>d<br />

each judgment is made more precise by Lemma 5.2.14 below. In essence, we are<br />

θ<br />

110


formaliz<strong>in</strong>g <strong>the</strong> logic-programm<strong>in</strong>g <strong>in</strong>terpretation <strong>of</strong> judgments and <strong>in</strong>ference rules<br />

(here implemented as LF types and terms) us<strong>in</strong>g judgments and <strong>in</strong>ference rules that,<br />

<strong>in</strong>tuitively, can be <strong>in</strong>terpreted as logic programs. This sort <strong>of</strong> circularity is <strong>in</strong>evitable<br />

<strong>in</strong> all foundational <strong>in</strong>vestigations, and ultimately must be justified by <strong>in</strong>tuition.<br />

unify(∆0 ⊢ <strong>in</strong>puts a (N1) • = <strong>in</strong>puts a (N0)) ∆<br />

=⇒ θ θ(a N1) = a N fs-atm<br />

fillSp<strong>in</strong>e(∆0; a N1 ⊢ ? : a N0) =⇒ 〈∆; a N; · ; a N〉<br />

fillSp<strong>in</strong>e(∆0, ∃x0:A0; B0 ⊢ ? : a N0) θ,M:A/x0<br />

=⇒ 〈∆; B ′ ; M; a N〉 (θ, x/x0)B0 = B fs-pi<br />

fillSp<strong>in</strong>e(∆0; Πx0:A0.B0 ⊢ ? : a N0) =⇒ 〈∆; (Πx:A.B); (M :: M); a N〉<br />

fillSp<strong>in</strong>e(∆; B0 ⊢ ? : a N0) =⇒ 〈∆; B; M; a N〉 θA0 = A<br />

fillTerm(∆ ⊢ ?<br />

θ<br />

: A)<br />

′<br />

=⇒ 〈∆ ′ ; M ′ ; A ′ 〉 θ ′ M = M ′ θ ′ B = B ′ θ ′ a N = a N ′<br />

fillSp<strong>in</strong>e(∆0; A0 → B0 ⊢ ? : a N0) θ′ ◦θ<br />

=⇒ 〈∆ ′ ; A ′ → B ′ ; (M ′ :: M ′ ); a N ′ 〉<br />

∀x:A ∈ ∆ hd(A) = a<br />

fillHead(∆; Σ ′ ; a) =⇒ x:A<br />

fh-v<br />

θ<br />

θ<br />

θ<br />

c:A ∈ Σ ′ hd(A) = a<br />

fillHead(∆; Σ ′ ; a) =⇒ c:A<br />

fillHead(∆; Σ; a) =⇒ h:A0 fillSp<strong>in</strong>e(∆0; A0 ⊢ ? : a N0) =⇒ 〈∆; A; M; a N〉<br />

θ(a N0) = a N ′ unify(∆ ⊢ outputsa (N) • = outputsa (N ′ )) ∆′<br />

=⇒ θ ′<br />

θ ′ M = M ′ θ ′ N ′ = N ′′<br />

fillTerm(∆0 ⊢ ? : a N0) θ′ ◦θ<br />

=⇒ 〈∆ ′ ; h M ′ ; a N ′′ 〉<br />

fillTerm(∆0, ∀x0:A0 ⊢ ? : B0) θ,x/x0<br />

=⇒ 〈∆, ∀x:A; M; B〉<br />

fillTerm(∆0 ⊢ ? : Πx0:A0.B0)<br />

θ<br />

=⇒ 〈∆; λx:A.M; Πx:A.B〉<br />

We th<strong>in</strong>k <strong>of</strong> <strong>the</strong> rule fs-pi as hav<strong>in</strong>g <strong>the</strong> implicit side condition that x occurs freely<br />

with<strong>in</strong> B0 (i.e. Πx:A.B cannot be written as A → B), which we omit both for <strong>the</strong><br />

sake <strong>of</strong> brevity. In essence, <strong>the</strong> difference between fs-pi and fs-arr is <strong>the</strong> difference<br />

between creat<strong>in</strong>g a subgoal to be found via pro<strong>of</strong> search, and creat<strong>in</strong>g a logic variable<br />

to be <strong>in</strong>stantiated via unification; <strong>the</strong>se rules are <strong>in</strong>spired by <strong>the</strong> Πl and →l rules <strong>of</strong><br />

<strong>the</strong> system U <strong>of</strong> [PW90].<br />

111<br />

θ<br />

fh-c<br />

ft-pi<br />

fs-arr<br />

ft-atm


It should be noted that <strong>the</strong> above semantics for pro<strong>of</strong> search is mode aware; that<br />

is, <strong>the</strong> mode declarations given by <strong>the</strong> user affect <strong>the</strong> semantics <strong>of</strong> pro<strong>of</strong> search.<br />

This is a departure from what is actually implemented <strong>in</strong> o<strong>the</strong>r accounts <strong>of</strong> Logic<br />

Programm<strong>in</strong>g based on LF [PW90, Pfe91, RP96, PS98], where unification would be<br />

<strong>in</strong>voked only <strong>in</strong> <strong>the</strong> fs-atm rule, and on all <strong>of</strong> N0 and N1 ra<strong>the</strong>r than just <strong>the</strong> <strong>in</strong>put<br />

arguments. This simplifies <strong>the</strong> development <strong>of</strong> <strong>the</strong> meta<strong>the</strong>ory <strong>of</strong> logic programm<strong>in</strong>g:<br />

to do o<strong>the</strong>rwise would require us to specify a unification algorithm that postpones<br />

unsolvable unification problems as constra<strong>in</strong>ts, which would, <strong>in</strong> order to prove <strong>the</strong><br />

analog <strong>of</strong> Lemma 5.2.14, require a development <strong>of</strong> LF where <strong>the</strong> typ<strong>in</strong>g rules are<br />

parameterized by equality constra<strong>in</strong>ts (see [Ree09] for a detailed sketch <strong>of</strong> what<br />

would be <strong>in</strong>volved). The mode-awareness <strong>of</strong> our semantics does not mean<strong>in</strong>gfully<br />

affect <strong>the</strong> execution <strong>of</strong> any <strong>of</strong> <strong>the</strong> programs considered <strong>in</strong> this dissertation.<br />

Lemma 5.2.14 (Soundness <strong>of</strong> Fill<strong>in</strong>g)<br />

1. If D : fillSp<strong>in</strong>e(∆0; A0 ⊢ ? : a N0) =⇒ 〈∆; A; M; a N〉 and |∆0| ⊢ A0 : type<br />

θ<br />

and |∆0| ⊢ a N0 : type <strong>the</strong>n ∆ ⊢ θ : ∆0 and ⊢ ∆ raised and θA0 = A and<br />

θ(<strong>in</strong>puts a (N0)) = <strong>in</strong>puts a (N) and |∆|; A ⊢ M : a N<br />

2. If D : fillTerm(∆0 ⊢ ? : A0)<br />

θ<br />

=⇒ 〈∆; M; A〉 and |∆0| ⊢ A0 : type <strong>the</strong>n<br />

∆ ⊢ θ : ∆0 and ⊢ ∆ raised and θA0 = A and |∆| ⊢ M : A<br />

Pro<strong>of</strong>: By mutual <strong>in</strong>ductions on <strong>the</strong> structure <strong>of</strong> D. We show some representative<br />

cases below.<br />

Case:<br />

D =<br />

D0<br />

fillSp<strong>in</strong>e(∆0, ∃x0:A0; B0 ⊢ ? : a N0) θ,M:A/x0<br />

=⇒ 〈∆; B ′ ; M; a N〉 (θ, x/x0)B0 = B<br />

fillSp<strong>in</strong>e(∆0; Πx0:A0.B0 ⊢ ? : a N0) =⇒ 〈∆; (Πx:A.B); (M :: M); a N〉<br />

112<br />

θ<br />

fs-pi


Case:<br />

|∆0| ⊢ Πx:A0.B0 : type and |∆0| ⊢ a N0 : type given<br />

|∆0| ⊢ A0 : type and |∆0|, x0:A0 ⊢ B0 : type by <strong>in</strong>version for typ<strong>in</strong>g<br />

|∆0|, x0:A0 ⊢ a N0 : type by weaken<strong>in</strong>g for typ<strong>in</strong>g<br />

∆ ⊢ (θ, M:A/x0) : ∆0, ∃x0:A0 and ⊢ ∆ raised<br />

and (θ, M:A/x0)B0 = B ′ and (θ, M:A/x0)<strong>in</strong>puts a (N0) = <strong>in</strong>puts a (N)<br />

and |∆|; B ′ ⊢ M : a N by IH on D0<br />

|∆| ⊢ M : A and θA0 = A and ∆ ⊢ θ : ∆0<br />

by Lemma 5.2.1<br />

θ (Πx0:A0.B0) = Πx:A.B by rule<br />

x#a N0<br />

by Lemma 5.1.5<br />

θ(<strong>in</strong>puts a (N0)) = <strong>in</strong>puts a (N) by Lemma 5.2.2, clause 3<br />

[M/x]A −B = B′ by Lemma 5.2.4 and Lemma 5.2.2 clause 1<br />

|∆|; Πx:A.B ⊢ M :: M : a N by rule<br />

D =<br />

D0<br />

fillTerm(∆0, ∀x0:A0 ⊢ ? : B0) θ,x/x0<br />

=⇒ 〈∆, ∀x:A; M; B〉<br />

fillTerm(∆0 ⊢ ? : Πx0:A0.B0)<br />

θ<br />

=⇒ 〈∆; (λx:A.M); (Πx:A.B)〉<br />

|∆0| ⊢ Πx0:A0.B0 : type given<br />

|∆0| ⊢ A0 : type and |∆0|, x0:A0 ⊢ B0 : type by <strong>in</strong>version on typ<strong>in</strong>g<br />

∆, ∀x:A ⊢ θ, x/x0 : ∆0, ∀x0:A0 and ⊢ ∆, ∀x:A raised<br />

and (θ, x/x0)B0 = B and |∆, ∀x:A| ⊢ M : B by IH on D0<br />

∆ ⊢ θ : ∆0 and θA0 = A by Lemma 5.2.1<br />

⊢ ∆ raised by <strong>in</strong>version on raised<br />

θ(Πx0:A0.B0) = Πx:A.B by rule<br />

|∆| ⊢ A : type by Lemmas 5.2.7 and 5.2.2<br />

|∆| ⊢ λx:A.M : Πx:A.B<br />

113<br />

ft-pi


5.2.3 Groundness and Abstract Substitutions<br />

We are <strong>in</strong>terested <strong>in</strong> identify<strong>in</strong>g a subset <strong>of</strong> well-behaved logic programs for <strong>the</strong><br />

purpose <strong>of</strong> prov<strong>in</strong>g <strong>the</strong>ir term<strong>in</strong>ation. In order to prove <strong>the</strong> term<strong>in</strong>ation <strong>of</strong> a query,<br />

it we will need to be able to def<strong>in</strong>e a size metric on goal formulas, where <strong>the</strong> “size”<br />

<strong>of</strong> a logic variable is considered <strong>in</strong>f<strong>in</strong>ite, s<strong>in</strong>ce it can be replaced with any term.<br />

To this end, we say that a term or sp<strong>in</strong>e is ground iff it conta<strong>in</strong>s no existentially-<br />

quantified variables, exclud<strong>in</strong>g any that may occur <strong>in</strong> <strong>the</strong> type-labels <strong>of</strong> λ-abstractions<br />

(we do not consider type labels to <strong>in</strong>fluence <strong>the</strong> sizes <strong>of</strong> terms). This concept is<br />

formalized judgmentally below.<br />

∆, ∀x:A ⊢ M g<br />

∆ ⊢ λx:A.M g<br />

∆ ⊢ · g<br />

(h:A ∈ Σ or ∀h:A ∈ ∆) ∆ ⊢ M g<br />

∆ ⊢ h M g<br />

∆ ⊢ M g ∆ ⊢ M g<br />

∆ ⊢ M :: M g<br />

Logic programm<strong>in</strong>g can be thought <strong>of</strong> as giv<strong>in</strong>g a computational <strong>in</strong>terpretation to<br />

relations; a program consists <strong>of</strong> search<strong>in</strong>g for <strong>the</strong> <strong>in</strong>habitants <strong>of</strong> a specified relation.<br />

The mode checker is, <strong>in</strong> essence, an abstract <strong>in</strong>terpretation that tells us when <strong>the</strong><br />

elements <strong>of</strong> <strong>the</strong> relation are treated consistently as <strong>the</strong> <strong>in</strong>puts to, or outputs from, a<br />

function. We can th<strong>in</strong>k <strong>of</strong> generalized substitutions as be<strong>in</strong>g <strong>the</strong> value returned by<br />

a successful query. As is typically <strong>the</strong> case with abstract <strong>in</strong>terpretation, we need to<br />

def<strong>in</strong>e an abstract doma<strong>in</strong> <strong>of</strong> values. To this end, we def<strong>in</strong>e abstract substitutions <strong>in</strong><br />

<strong>the</strong> same manner as <strong>in</strong> [RP96] below.<br />

Abstract Substitutions η ::= · | η, ∀x:A | η, ∃ ? x:A | η, ∃ g x:A<br />

114


In one sense are just mixed prefix contexts with a flag that determ<strong>in</strong>es which existen-<br />

tial variables are assumed to be ground. In ano<strong>the</strong>r sense, abstract substitutions can<br />

be thought <strong>of</strong> as sets <strong>of</strong> generalized substitutions that obey <strong>the</strong>se flags. In <strong>the</strong> first<br />

sense, <strong>the</strong> judgment ∆ ⊢ θ : η, whose rules are listed below, is merely a ref<strong>in</strong>ement<br />

to <strong>the</strong> typ<strong>in</strong>g rules for generalized substitutions. In <strong>the</strong> second sense, ∆ ⊢ θ : η can<br />

be thought <strong>of</strong> as mean<strong>in</strong>g “θ ∈ η.”<br />

· ⊢ · : ·<br />

∆ ⊢ θ : η θA = B |∆| ⊢ B : type<br />

∆, ∀y:B ⊢ θ, y/x : η, ∀x:A<br />

∆ ⊢ θ : η θA = B |∆| ⊢ M : B ∆ ⊢ M g<br />

∆ ⊢ θ, M:B/x : η, ∃ g x:A<br />

∆ ⊢ θ : η θA = B |∆| ⊢ M : B ∃y:B ∈ ∆ expand y (B; ·) = M<br />

∆ ⊢ θ, M:B/x : η, ∃ ? x:A<br />

∆ ⊢ θ : η θA = B |∆| ⊢ M : B ∆ ⊢ M g<br />

∆ ⊢ θ, M:B/x : η, ∃ ? x:A<br />

∆ ⊢ θ : η |∆| ⊢ A : type<br />

∆, ∃x:A ⊢ θ : η<br />

We should note that <strong>the</strong> judgment ∆ ⊢ θ : η requires that θ be well-behaved <strong>in</strong> that<br />

it can only map existential variables to terms which are ei<strong>the</strong>r ground, or <strong>the</strong> eta-<br />

expansion <strong>of</strong> ano<strong>the</strong>r existential variable; bak<strong>in</strong>g this <strong>in</strong>variant <strong>in</strong>to this judgment<br />

simplifies <strong>the</strong> development <strong>of</strong> <strong>the</strong> meta<strong>the</strong>ory <strong>of</strong> <strong>the</strong> mode-checker.<br />

If ∆ ′ ⊢ θ : ∆ <strong>the</strong>n we say that η approximates θ if ∆ ′ ⊢ θ : η, whenever ∆ ′ is<br />

ei<strong>the</strong>r arbitrary, or clear from <strong>the</strong> context.<br />

We can convert between mixed prefix contexts and abstract substitutions <strong>in</strong> <strong>the</strong><br />

obvious ways: η∆ assigns <strong>the</strong> “unknown” flag to each existential variable <strong>in</strong> ∆, and ∆η<br />

strips <strong>the</strong> flags <strong>in</strong> η. Under <strong>the</strong> set-<strong>in</strong>terpretation <strong>of</strong> η, ∆η tells us <strong>the</strong> doma<strong>in</strong> <strong>of</strong> <strong>the</strong><br />

generalized substitutions <strong>in</strong> η, and η∆ def<strong>in</strong>es <strong>the</strong> set <strong>of</strong> all well-behaved generalized<br />

substitutions whose doma<strong>in</strong> is ∆. Both <strong>in</strong>terpretations are reflected <strong>in</strong> Lemma 5.2.16.<br />

115


∆· = ·<br />

∆η,∀x:A = ∆η, ∀x:A<br />

∆ η,∃ ? x:A = ∆η, ∃x:A<br />

∆ η,∃ g x:A = ∆η, ∃x:A<br />

η· = ·<br />

η∆,∀x:A = (η∆), ∀x:A<br />

η∆,∃x:A = (η∆), ∃ ? x:A<br />

An abstract substitution can be converted to an ord<strong>in</strong>ary LF context <strong>in</strong> much<br />

<strong>the</strong> same way that a mixed prefix context can.<br />

|·| = ·<br />

|η, ∀x:A| = |η|, x:A<br />

|η, ∃ ? x:A| = |η|, x:A<br />

|η, ∃ g x:A| = |η|, x:A<br />

The notion <strong>of</strong> groundness for abstract substitutions is <strong>the</strong> same as for mixed prefix<br />

contexts, but with <strong>the</strong> follow<strong>in</strong>g extra rule, which, under <strong>the</strong> set <strong>in</strong>terpretation <strong>of</strong> η,<br />

says that for every θ <strong>in</strong> η, θM is ground. This is justified by Lemma 5.2.16.<br />

∃ g x:A ∈ η η ⊢ M g<br />

η ⊢ x M g<br />

We also f<strong>in</strong>d it useful to def<strong>in</strong>e <strong>the</strong> judgment η ′ ⊢ θ : η. If we <strong>in</strong>terpret abstract<br />

substitutions as contexts, <strong>the</strong>n <strong>the</strong> <strong>in</strong>terpretation <strong>of</strong> <strong>the</strong> judgment is straightforward.<br />

If we <strong>in</strong>terpret abstract substitutions as sets, <strong>the</strong>n we can th<strong>in</strong>k <strong>of</strong> η ′ ⊢ θ : η as say<strong>in</strong>g<br />

116


that, for any θ ′ <strong>in</strong> η ′ , θ ′ ◦ θ is <strong>in</strong> η.<br />

· ⊢ · : ·<br />

η ′ ⊢ θ : η θA = B |η ′ | ⊢ B : type<br />

η ′ , ∀y:B ⊢ θ, y/x : η, ∀x:A<br />

η ′ ⊢ θ : η θA = B |η ′ | ⊢ M : B η ′ ⊢ M g<br />

η ′ ⊢ θ, M:B/x : η, ∃ g x:A<br />

η ′ ⊢ θ : η θA = B |η ′ | ⊢ M : B ∃ ? y:B ∈ η ′ expand y (B; ·) = M<br />

η ′ ⊢ θ, M:B/x : η, ∃ ? x:A<br />

η ′ ⊢ θ : η θA = B |η ′ | ⊢ M : B η ′ ⊢ M g<br />

Lemma 5.2.15<br />

η ′ ⊢ θ, M:B/x : η, ∃ ? x:A<br />

1. For every ∆, |∆| = |η∆|<br />

2. For every η, |η| = |∆η|<br />

η ′ ⊢ θ : η |η ′ | ⊢ A : type<br />

η ′ , ∃x:A ⊢ θ : η<br />

Pro<strong>of</strong>: By straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> <strong>the</strong> given mixed-prefix con-<br />

text or abstract substitution. <br />

Lemma 5.2.16 (Abstract and Generalized Substitutions)<br />

1. If ∆ ′ ⊢ θ : ∆ <strong>the</strong>n ∆ ′ ⊢ θ : η∆<br />

2. If ∆ ′ ⊢ θ : η <strong>the</strong>n η∆ ′ ⊢ θ : η<br />

3. If ∆ ′ ⊢ θ : η <strong>the</strong>n ∆ ⊢ θ : ∆η<br />

4. If η ′ ⊢ θ : η <strong>the</strong>n ∆η ′ ⊢ θ : ∆η<br />

Pro<strong>of</strong>: Each is by straightforward <strong>in</strong>duction on <strong>the</strong> given derivation, us<strong>in</strong>g Lemma 5.2.15.<br />

<br />

117


Lemma 5.2.17 (Abstract Inclusion) If ∆ ′ ⊢ θ : ∆ and ∆ ′ ⊢ θ : η <strong>the</strong>n ∆η = ∆<br />

Pro<strong>of</strong>: By a straightforward <strong>in</strong>duction on ei<strong>the</strong>r <strong>of</strong> <strong>the</strong> typ<strong>in</strong>g derivations. <br />

Lemma 5.2.18 (Weaken<strong>in</strong>g for Groundness)<br />

1. If ∆ can be obta<strong>in</strong>ed from ∆ ′ by delet<strong>in</strong>g some number <strong>of</strong> declarations <strong>the</strong>n:<br />

(a) If ∆ ⊢ M g <strong>the</strong>n ∆ ′ ⊢ M g<br />

(b) If ∆ ⊢ M g <strong>the</strong>n ∆ ′ ⊢ M g<br />

2. If η can be obta<strong>in</strong>ed from η ′ by delet<strong>in</strong>g some number <strong>of</strong> declarations <strong>the</strong>n:<br />

(a) If η ⊢ M g <strong>the</strong>n η ′ ⊢ M g<br />

(b) If η ⊢ M g <strong>the</strong>n η ′ ⊢ M g<br />

Pro<strong>of</strong>: By straightforward simultaneous <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> <strong>the</strong> given<br />

groundness derivation. <br />

Lemma 5.2.19 (Hereditary Substitutions Preserve Groundness)<br />

1. If ∆ ⊢ M g <strong>the</strong>n:<br />

(a) If ∆ ⊢ M g and reduceτ(M, M) = N <strong>the</strong>n ∆ ⊢ N g<br />

(b) If ∆ ⊢ M ′ g and [M/x]τM ′ = N <strong>the</strong>n ∆ ⊢ M ′ g<br />

(c) If ∆ ⊢ M g and [M/x]τM = N <strong>the</strong>n ∆ ⊢ N g<br />

(d) If ∆ ⊢ A g and [M/x]τA = B <strong>the</strong>n ∆ ⊢ B g<br />

2. If η ⊢ M g <strong>the</strong>n:<br />

(a) If η ⊢ M g and reduceτ(M, M) = N <strong>the</strong>n η ⊢ N g<br />

(b) If η ⊢ M ′ g and [M/x]τM ′ = N <strong>the</strong>n η ⊢ M ′ g<br />

118


(c) If η ⊢ M g and [M/x]τM = N <strong>the</strong>n η ⊢ N g<br />

(d) If η ⊢ A g and [M/x]τA = B <strong>the</strong>n η ⊢ B g<br />

Pro<strong>of</strong>: 1 is by straightforward simultaneous <strong>in</strong>duction on <strong>the</strong> derivation <strong>of</strong> <strong>the</strong> given<br />

hereditary substitution, us<strong>in</strong>g Lemma 5.2.18; 2 analogous. <br />

Lemma 5.2.20 (Generalized Substitutions Preserve Groundness)<br />

1. If ∆ ′ ⊢ θ : ∆ <strong>the</strong>n:<br />

(a) If ∆ ⊢ M g and θM = N <strong>the</strong>n ∆ ′ ⊢ N g<br />

(b) If ∆ ⊢ M g and θM = N <strong>the</strong>n ∆ ′ ⊢ N g<br />

2. If ∆ ⊢ θ : η <strong>the</strong>n:<br />

(a) η ⊢ M g and θM = N <strong>the</strong>n ∆ ⊢ N g<br />

(b) η ⊢ M g and θM = N <strong>the</strong>n ∆ ⊢ N g<br />

3. If η ′ ⊢ θ : η <strong>the</strong>n:<br />

(a) η ⊢ M g and θM = N <strong>the</strong>n η ′ ⊢ N g<br />

(b) η ⊢ M g and θM = N <strong>the</strong>n η ′ ⊢ N g<br />

Pro<strong>of</strong>: 1 is by straightforward <strong>in</strong>duction on <strong>the</strong> derivation <strong>of</strong> <strong>the</strong> given hereditary<br />

substitution, us<strong>in</strong>g Lemma 5.2.19. 2 and 3 are analogous.<br />

Lemma 5.2.21 (Expansion and Groundness) If D : expand h (A; M) = M <strong>the</strong>n:<br />

1. if ∆ ⊢ M g and h = c or (h = x and ∀x:B ∈ ∆) <strong>the</strong>n ∆ ⊢ M g<br />

2. if η ⊢ M g and h = c or (h = x and ei<strong>the</strong>r ∀x:B ∈ ∆ or ∃x:B ∈ ∆) <strong>the</strong>n<br />

η ⊢ M g<br />

119


Pro<strong>of</strong>: Each case is by straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> D. <br />

Lemma 5.2.22 (Groundness <strong>of</strong> Inputs and Outputs)<br />

1. ∆ ⊢ M g iff ∆ ⊢ <strong>in</strong>puts a (M) g and ∆ ⊢ outputs a (M) g<br />

2. ∆ ⊢ M g iff ∆ ⊢ <strong>in</strong>puts a (M) g and ∆ ⊢ outputs a (M) g<br />

Pro<strong>of</strong>: Direct, by def<strong>in</strong>ition <strong>of</strong> <strong>in</strong>puts and outputs. <br />

Given a well-typed generalized substitution θ, it may be <strong>the</strong> case that θ is ap-<br />

proximated by more than one η; for example, if ∆ ⊢ θ : η, ∃ g x:A, η ′ <strong>the</strong>n ∆ ⊢ θ :<br />

η, ∃ ? x:A, η ′ .<br />

Lemma 5.2.23 (Subtyp<strong>in</strong>g for Abstract Substitutions)<br />

1. If ∆ ⊢ θ : η0, ∃ g x:A, η1 <strong>the</strong>n ∆ ⊢ θ : η0, ∃ ? x:A, η1<br />

2. If η ⊢ θ : η0, ∃ g x:A, η1 <strong>the</strong>n η ⊢ θ : η0, ∃ ? x:A, η1<br />

3. If η0, ∃ ? x:A, η1 ⊢ θ : η <strong>the</strong>n η0, ∃ g x:A, η1 ⊢ θ : η<br />

Given two abstract substitutions η and η ′ which approximate <strong>the</strong> same substitu-<br />

tion θ, we can conclude that any existentially-quantified variable which is marked as<br />

ground <strong>in</strong> ei<strong>the</strong>r η or η ′ must be ground. Thus, we def<strong>in</strong>e η ⊓ η ′ as <strong>the</strong> meet <strong>of</strong> <strong>the</strong><br />

groundness <strong>in</strong>formation <strong>in</strong> η and η ′ ; under <strong>the</strong> set <strong>in</strong>terpretation, we can th<strong>in</strong>k <strong>of</strong> ⊓<br />

120


as <strong>in</strong>tersection.<br />

Lemma 5.2.24 (Properties <strong>of</strong> ⊓)<br />

· ⊓ · = ·<br />

(η, ∀x:A) ⊓ (η ′ , ∀x:A) = (η ⊓ η ′ ), ∀x:A<br />

(η, ∃ ? x:A) ⊓ (η ′ , ∃ ? x:A) = (η ⊓ η ′ ), ∃ ? x:A<br />

(η, ∃ g x:A) ⊓ (η ′ , ∃ ? x:A) = (η ⊓ η ′ ), ∃ g x:A<br />

(η, ∃ ? x:A) ⊓ (η ′ , ∃ g x:A) = (η ⊓ η ′ ), ∃ g x:A<br />

(η, ∃ g x:A) ⊓ (η ′ , ∃ g x:A) = (η ⊓ η ′ ), ∃ g x:A<br />

1. (a) If η ⊢ M g <strong>the</strong>n η ⊓ η ′ ⊢ M g<br />

(b) If η ⊢ M g <strong>the</strong>n η ⊓ η ′ ⊢ M g<br />

2. If η = η0, η1 and η ′ = η ′ 0, η ′ 1 <strong>the</strong>n η ⊓ η ′ = η ′′ iff η ′′ = η ′′<br />

0, η ′′<br />

1 and η0 ⊓ η ′ 0 = η ′′<br />

0<br />

and η1 ⊓ η ′ 1 = η ′′<br />

1<br />

3. η = η ⊓ η<br />

4. η ⊓ η ′ = η ′ ⊓ η<br />

5. If η ⊓ η∆ = η ′ <strong>the</strong>n η ′ = η<br />

Pro<strong>of</strong>: 1 is by a straightforward simultaneous <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> g; <strong>the</strong><br />

o<strong>the</strong>rs are by <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> η <br />

Lemma 5.2.25 (Soundness <strong>of</strong> ⊓)<br />

1. If ∆ ⊢ θ : η and ∆ ⊢ θ : η ′ <strong>the</strong>n ∆ ⊢ θ : η ⊓ η ′<br />

121


2. If η0 ⊢ θ : η1 and η0 ⊢ θ : η ′ 1 <strong>the</strong>n η0 ⊢ θ : η1 ⊓ η ′ 1<br />

3. If η0 ⊢ θ : η1 and η ′ 0 ⊢ θ : η1 <strong>the</strong>n η0 ⊓ η ′ 0 ⊢ θ : η1<br />

4. If η0 ⊢ θ : η1 and η ′ 0 ⊢ θ : η ′ 1 <strong>the</strong>n η0 ⊓ η ′ 0 ⊢ θ : η1 ⊓ η ′ 1<br />

Pro<strong>of</strong>: Each case is by straightforward <strong>in</strong>duction on one <strong>of</strong> <strong>the</strong> given typ<strong>in</strong>g deriva-<br />

tions. <br />

The notion <strong>of</strong> a pattern sp<strong>in</strong>e, <strong>in</strong>spired by a similar def<strong>in</strong>ition <strong>in</strong> [Roh96] will be<br />

important <strong>in</strong> our discussion <strong>of</strong> <strong>the</strong> properties <strong>of</strong> unification and <strong>in</strong> <strong>the</strong> def<strong>in</strong>ition <strong>of</strong><br />

<strong>the</strong> mode/term<strong>in</strong>ation checker. We def<strong>in</strong>e pattern sp<strong>in</strong>es judgmentally below. Note<br />

that, unlike most <strong>of</strong> our judgments, ∆ ⊢ M pattern and η ⊢ M pattern can be<br />

<strong>in</strong>habited when ∆ and η are ill-formed, and moreover, M may conta<strong>in</strong> free variable<br />

not declared <strong>in</strong> ∆ or η.<br />

∆ ⊢ · pattern<br />

η ⊢ · pattern<br />

Lemma 5.2.26 (Patterns are Ground)<br />

1. If ∆ ⊢ M pattern <strong>the</strong>n ∆ ⊢ M g<br />

2. If η ⊢ M pattern <strong>the</strong>n η ⊢ M g<br />

∀x:A ∈ ∆ expand x (A; ·) = M x#M ∆ ⊢ M pattern<br />

∆ ⊢ M :: M pattern<br />

∀x:A ∈ η expand x (A; ·) = M x#M η ⊢ M pattern<br />

η ⊢ M :: M pattern<br />

Pro<strong>of</strong>: By straightforward <strong>in</strong>duction on <strong>the</strong> given derivations, us<strong>in</strong>g Lemma 5.2.21.<br />

<br />

Lemma 5.2.27 (Pattern Conversion)<br />

1. If ∆ ⊢ M pattern <strong>the</strong>n η∆ ⊢ M pattern<br />

122


2. If η ⊢ M pattern <strong>the</strong>n ∆η ⊢ M pattern<br />

Pro<strong>of</strong>: Each case is by a straightforward <strong>in</strong>duction on <strong>the</strong> given derivation. <br />

Lemma 5.2.28 (Weaken<strong>in</strong>g for Patterns)<br />

1. If ∆ ⊢ M pattern <strong>the</strong>n ∆ ′ , ∆ ⊢ M pattern<br />

2. If η ⊢ M pattern <strong>the</strong>n η ′ , η ⊢ M pattern<br />

Pro<strong>of</strong>: By <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> <strong>the</strong> given derivations. <br />

Lemma 5.2.29 (Pattern Freshness)<br />

1. If x#∆ and ∆ ⊢ M pattern <strong>the</strong>n x#M<br />

2. If x#η and η ⊢ M pattern <strong>the</strong>n x#M<br />

3. If x#M and ∆, ∀x:A, ∆ ′ ⊢ M pattern <strong>the</strong>n ∆, ∆ ′ ⊢ M pattern<br />

4. If x#M and η, ∀x:A, η ′ ⊢ M pattern <strong>the</strong>n η, η ′ ⊢ M pattern<br />

Pro<strong>of</strong>: Each case is by straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> M, us<strong>in</strong>g<br />

Lemma 5.1.22 <strong>in</strong> 1 and 2 <br />

Lemma 5.2.30 (Substitution Splitt<strong>in</strong>g)<br />

1. If D : (∆ ′ ⊢ θ : ∆0, ∆1) <strong>the</strong>n ∆ ′ = ∆ ′ 0, ∆ ′ 1 and θ = θ0, θ1 and ∆ ′ 0 ⊢ θ0 : ∆0<br />

2. If D : (∆ ⊢ θ : η0, η1) <strong>the</strong>n ∆ = ∆0, ∆1 and θ = θ0, θ1 and ∆0 ⊢ θ0 : η0<br />

3. If D : (η ′ ⊢ θ : η0, η1) <strong>the</strong>n η = η ′ 0, η ′ 1 and θ = θ0, θ1 and η ′ 0 ⊢ θ0 : η0<br />

Pro<strong>of</strong>: Each case is by a straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> D. <br />

Lemma 5.2.31 (Abstract Substitutions on Variables)<br />

123


1. If D : (∆ ⊢ θ : η) <strong>the</strong>n:<br />

(a) If ∀x:A ∈ η <strong>the</strong>n θx = y, and θA = B and ∀y:B ∈ ∆<br />

(b) If ∃ ? x:A ∈ η <strong>the</strong>n θx = M:B and θA = B and |∆| ⊢ M : B<br />

(c) If ∃ g x:A ∈ η <strong>the</strong>n θx = M:B and θA = B and |∆| ⊢ M : B and ∆ ⊢ M g<br />

(d) If ∀x:A ∈ η and ∀y:B ∈ η and x#y <strong>the</strong>n θx#θy<br />

2. If D : (η ′ ⊢ θ : η) <strong>the</strong>n:<br />

(a) If ∀x:A ∈ η <strong>the</strong>n θx = y, and θA = B and ∀y:B ∈ η ′<br />

(b) If ∃ ? x:A ∈ η <strong>the</strong>n θx = M:B and θA = B and |η ′ | ⊢ M : B<br />

(c) If ∃ g x:A ∈ η <strong>the</strong>n θx = M:B and θA = B and |η ′ | ⊢ M : B and η ′ ⊢ M g<br />

(d) If ∀x:A ∈ η and ∀y:B ∈ η and x#y <strong>the</strong>n θx#θy<br />

Pro<strong>of</strong>: Analogous to Lemma 5.2.6. Each case is by <strong>in</strong>duction on D. All cases use<br />

Lemma 5.2.5, <strong>the</strong> (b) and (c) cases use Weaken<strong>in</strong>g for Typ<strong>in</strong>g and <strong>the</strong> (c) cases uses<br />

Weaken<strong>in</strong>g for Groundness. The (d) cases use <strong>the</strong> fact that mixed-prefix contexts<br />

and abstract substitutions cannot conta<strong>in</strong> duplicate variable name declarations.<br />

Lemma 5.2.32 (Properties <strong>of</strong> Split Substitutions)<br />

1. If D : (∆ ′ 0, ∆ ′ 1 ⊢ θ0, θ1 : ∆0, ∆1) and ∆ ′ 0 ⊢ θ0 : ∆0 <strong>the</strong>n:<br />

(a) If ∆ ′′<br />

0 ⊢ θ0 : ∆0 <strong>the</strong>n ∆ ′′<br />

0, ∆ ′ 1 ⊢ θ0, θ1 : ∆0, ∆1<br />

(b) If ∀x:A ∈ ∆1 <strong>the</strong>n θx = y and θA = B and ∀y:B ∈ ∆ ′ 1<br />

2. If D : (∆ ′ 0, ∆ ′ 1 ⊢ θ0, θ1 : η0, η1) and ∆ ′ 0 ⊢ θ0 : η0 <strong>the</strong>n:<br />

(a) If ∆ ′′<br />

0 ⊢ θ0 : η0 <strong>the</strong>n ∆ ′′<br />

0, ∆ ′ 1 ⊢ θ0, θ1 : η0, η1<br />

124


(b) If ∀x:A ∈ η1 <strong>the</strong>n θx = y and θA = B and ∀y:B ∈ ∆ ′ 1<br />

3. If D : (η ′ 0, η ′ 1 ⊢ θ0, θ1 : η0, η1) and η ′ 0 ⊢ θ0 : η0 <strong>the</strong>n:<br />

(a) If η ′′<br />

0 ⊢ θ0 : η0 <strong>the</strong>n η ′′<br />

0, η ′ 1 ⊢ θ0, θ1 : η0, η1<br />

(b) If ∀x:A ∈ η1 <strong>the</strong>n θx = y and θA = B and ∀y:B ∈ η ′ 1<br />

Pro<strong>of</strong>: Each case is by straightforward <strong>in</strong>duction on D; <strong>the</strong> (b) cases use weaken<strong>in</strong>g<br />

for Typ<strong>in</strong>g and Lemma 5.2.2.<br />

Lemma 5.2.33 (Substitutions Respect Patterns)<br />

1. If ∆ ′ ⊢ θ : ∆ <strong>the</strong>n:<br />

(a) If ∀x:A ∈ ∆ and x#M and ∆ ⊢ M pattern <strong>the</strong>n θx#θM<br />

(b) If ∆ = ∆0, ∆1 and ∆ ′ = ∆ ′ 0, ∆ ′ 1 and θ = θ0, θ1 and ∆ ′ 0 ⊢ θ0 : ∆0 and<br />

∆1 ⊢ M pattern and θM = N <strong>the</strong>n ∆1 ⊢ N pattern<br />

2. If ∆ ⊢ θ : η <strong>the</strong>n:<br />

(a) If ∀x:A ∈ η and x#M and η ⊢ M pattern <strong>the</strong>n θx#θM<br />

(b) If η = η0, η1 and ∆ = ∆0, ∆1 and θ = θ0, θ1 and ∆0 ⊢ θ0 : η0 and<br />

η1 ⊢ M pattern and θM = N <strong>the</strong>n ∆1 ⊢ N pattern<br />

3. If η ′ ⊢ θ : η <strong>the</strong>n:<br />

(a) If ∀x:A ∈ η and x#M and η ⊢ M pattern <strong>the</strong>n θx#θM<br />

(b) If η = η0, η1 and ∆ ′ = ∆ ′ 0, ∆ ′ 1 and θ = θ0, θ1 and η ′ 0 ⊢ θ0 : η0 and<br />

η1 ⊢ M pattern and θM = N <strong>the</strong>n η ′ 1 ⊢ N pattern<br />

125


Pro<strong>of</strong>: The (a) cases are all by <strong>in</strong>duction on <strong>the</strong> given derivation <strong>of</strong> pattern,<br />

us<strong>in</strong>g Lemmas 5.1.22, Lemma 5.2.10, ei<strong>the</strong>r Lemma 5.2.6 or Lemma 5.2.31, and<br />

Lemma 5.2.10. The (b) cases are also by <strong>in</strong>duction on <strong>the</strong> given derivation <strong>of</strong><br />

pattern, us<strong>in</strong>g Lemma 5.2.32, <strong>the</strong> appropriate part (a) and Lemma 5.2.10. <br />

Lemma 5.2.34 (Streng<strong>the</strong>n<strong>in</strong>g for Groundness)<br />

1. If ∆ can be obta<strong>in</strong>ed from ∆ ′ by delet<strong>in</strong>g some number <strong>of</strong> declarations <strong>the</strong>n:<br />

(a) if |∆| ⊢ M : A and ∆ ′ ⊢ M g <strong>the</strong>n ∆ ⊢ M g<br />

(b) if |∆|; A ⊢ M : B and ∆ ′ ⊢ M g <strong>the</strong>n ∆ ⊢ M g<br />

2. If η can be obta<strong>in</strong>ed from η ′ by delet<strong>in</strong>g some number <strong>of</strong> declarations <strong>the</strong>n:<br />

(a) if |η| ⊢ M : A and η ′ ⊢ M g <strong>the</strong>n η ⊢ M g<br />

(b) if |η|; A ⊢ M : B and η ′ ⊢ M g <strong>the</strong>n η ⊢ M g<br />

Pro<strong>of</strong>: 1 is by a straightforward simultaneous <strong>in</strong>duction over <strong>the</strong> structure <strong>of</strong> <strong>the</strong><br />

given typ<strong>in</strong>g derivations. 2 is analogous.<br />

In some <strong>in</strong>stances, we can reason backwards about <strong>the</strong> behavior <strong>of</strong> generalized<br />

substitutions with respect to groundness <strong>in</strong>formation. For example, if it is known<br />

that θM is a ground term, <strong>the</strong>n it must be <strong>the</strong> case that, for every logic variable<br />

x that occurs rigidly <strong>in</strong> M, θx is ground. Thus, given ∆ and M, we can use this<br />

observation def<strong>in</strong>e an abstract-substitution that characterizes <strong>the</strong> set <strong>of</strong> generalized<br />

substitutions that ground M. We write this judgment ∆ ⊢ M g=⇒ η, and specify<br />

its rules (taken directly from [Roh96]) below.<br />

126


∆, ∀x:A ⊢ M g=⇒ η, ∀x:A<br />

∆ ⊢ λx:A.M g=⇒ η<br />

c:A ∈ Σ ∆ ⊢ M g=⇒ η<br />

∆ ⊢ c M g=⇒ η<br />

∀x:∈∆ ∆ ⊢ M g=⇒ η<br />

∆ ⊢ x M g=⇒ η<br />

∆ ′ ⊢ M pattern |∆, ∃x:A, ∆ ′ |; A ⊢ M : a N<br />

∆, ∃x:A, ∆ ′ ⊢ x M g=⇒ η∆, ∃ g x:A, η∆ ′<br />

∆, ∃x:A, ∆ ′ ⊢ x M g=⇒ η∆, ∃ ? x:A, η∆ ′<br />

∆ ⊢ · g=⇒ η∆<br />

∆ ⊢ M g=⇒ η ∆ ⊢ M g=⇒ η ′<br />

∆ ⊢ M :: M g=⇒ (η ⊓ η ′ )<br />

We lift<strong>in</strong>g this judgment to abstract substitutions below.<br />

η, ∀x:A ⊢ M g=⇒ η ′ , ∀x:A<br />

η ⊢ λx:A.M g=⇒ η ′<br />

η1 ⊢ M pattern |η0, ∃ ? x:A, η1|; A ⊢ M : a N<br />

η0, ∃ ? x:A, η1 ⊢ x M g=⇒ η0, ∃ g x:A, η1<br />

∃ g x:A ∈ η<br />

η ⊢ x M g=⇒ η η ⊢ · g=⇒ η<br />

∀x:A ∈ η η ⊢ M g=⇒ η ′<br />

η ⊢ x M g=⇒ η ′<br />

η0, ∃ ? x:A, η1 ⊢ x M g=⇒ η0, ∃ ? x:A, η1<br />

η ⊢ M g=⇒ η ′<br />

Lemma 5.2.35 (Groundness Inversion for Patterns)<br />

η ⊢ M g=⇒ η ′′<br />

η ⊢ M :: M g=⇒ η ′ ⊓ η ′′<br />

If ∆ and ∆ ′ are disjo<strong>in</strong>t and D : (|∆| ⊢ M : A) and E : (reduceA −(M, N) = M ′ )<br />

and F : (∆ ′ ⊢ N pattern) and ∆, ∆ ′ ⊢ M ′ g <strong>the</strong>n ∆ ⊢ M g.<br />

Pro<strong>of</strong>: By <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> E.<br />

127


Case:<br />

Case:<br />

F =<br />

E =<br />

D =<br />

∀x:A ∈ ∆ ′ , ∀x:A, ∆ ′′<br />

D0<br />

|∆| ⊢ A1 : type<br />

E0<br />

[N/x] −<br />

A M = N<br />

1<br />

′<br />

D1<br />

|∆, ∀x:A1| ⊢ M : A2<br />

|∆| ⊢ λx:A1.M : Πx:A1.A2<br />

reduce −<br />

A1 →A− 2<br />

F0<br />

E1<br />

reduce −<br />

A (N<br />

2<br />

′ , N) = M ′<br />

(λx:A1.M, N :: N) = M ′<br />

expand x (A; ·) = N x#N<br />

∆ ′ , ∀x:A, ∆ ′′ ⊢ N :: N pattern<br />

F1<br />

∆ ′ , ∀x:A, ∆ ′′ ⊢ N pattern<br />

Note that <strong>the</strong> x <strong>in</strong> λx:A1.M and <strong>the</strong> x <strong>in</strong> ∆ ′ , ∀x:A, ∆ ′′ can be assumed to be<br />

<strong>the</strong> same, by <strong>the</strong> renamability <strong>of</strong> bound variables and <strong>the</strong> fact that x doesn’t<br />

occur <strong>in</strong> ∆.<br />

∆ is disjo<strong>in</strong>t from ∆ ′ , ∀x:A, ∆ ′′<br />

and ∆, ∆ ′ , ∀x:A, ∆ ′′ ⊢ M ′ g given<br />

|∆|, x:A1 ⊢ N : A1<br />

by Theorem 5.1.25<br />

[N/x] −<br />

A M = M by Theorem 5.1.25<br />

1<br />

N ′ = M by Lemma 5.1.3<br />

∆ ′ , ∆ ′′ ⊢ N pattern by Lemma 5.2.29<br />

∆, ∀x:A1 ⊢ M g by IH on E1<br />

∆ ⊢ λx:A1.M g by rule<br />

∆ disjo<strong>in</strong>t from ∆ ′ and |∆| ⊢ M : A<br />

E = reduceτ (M, ·) = M<br />

128


and ∆ ′ ⊢ · pattern and ∆, ∆ ′ ⊢ M g given<br />

∆ ⊢ M g by Lemma 5.2.34<br />

Lemma 5.2.36 (Reason<strong>in</strong>g Backwards About Groundness)<br />

1. If ∆ ′ ⊢ θ : ∆ <strong>the</strong>n:<br />

(a) if D : (∆ ⊢ M g=⇒ η) and θM = N and ∆ ′ ⊢ N g <strong>the</strong>n ∆ ⊢ θ : η<br />

(b) If D : (∆ ⊢ M g=⇒ η) and θM = N and ∆ ′ ⊢ N g <strong>the</strong>n ∆ ⊢ θ : η<br />

2. If ∆ ⊢ θ : η <strong>the</strong>n:<br />

(a) if D : (η ⊢ M g=⇒ η ′ ) and θM = N and ∆ ⊢ N g <strong>the</strong>n ∆ ⊢ θ : η ′<br />

(b) If D : (η ⊢ M g=⇒ η ′ ) and θM = N and ∆ ⊢ N g <strong>the</strong>n ∆ ⊢ θ : η ′<br />

Pro<strong>of</strong>: Each case is by simultaneous <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> D, where <strong>the</strong><br />

pro<strong>of</strong>s for 1 and 2 are essentially <strong>the</strong> same. We show <strong>the</strong> <strong>in</strong>terest<strong>in</strong>g cases <strong>of</strong> 2 below.<br />

1.<br />

Case:<br />

D =<br />

D0<br />

η1 ⊢ M pattern<br />

D1<br />

|η0, ∃ ? x:A, η1|; A ⊢ M : a N<br />

η0, ∃ ? x:A, η1 ⊢ x M g=⇒ η0, ∃ g x:A, η1<br />

∆ ⊢ θ : η0, ∃ ? x:A, η1 and θ(x M) = N and ∆ ⊢ N g given<br />

θx = N0:B and θA = B by Lemma 5.2.31<br />

θM = N0 and reduceB −(N0, N0) = N by <strong>in</strong>version on gsub app<br />

∆ = ∆0, ∆1 and θ = θ0, M:B/x, θ1 and ∆0 ⊢ θ ′ 0 : η0, ∃ ? x:A<br />

129<br />

<br />

by Lemma 5.2.30


2.<br />

Case:<br />

θ ′ 0 = θ0, N0:B/x and |∆0| ⊢ M : B and ∆0 ⊢ θ0 : η0<br />

by <strong>in</strong>version on abs sub typ<strong>in</strong>g and Lemma 5.2.2<br />

∆1 ⊢ N0 pattern by Lemma 5.2.33<br />

∆0 ⊢ N0 g by Lemma 5.2.35<br />

∆0 ⊢ θ0 : η0, ∃ g x:A by rule<br />

∆ ⊢ θ : η0, ∃ g x:A, η1<br />

D =<br />

D0<br />

η ⊢ M g=⇒ η ′<br />

D1<br />

η ⊢ M g=⇒ η ′′<br />

η ⊢ M :: M g=⇒ η ′ ⊓ η ′′<br />

by Lemma 5.2.32<br />

∆ ⊢ θ : η and θ(M :: M) = N :: N ′ and ∆ ⊢ N :: N g given<br />

θM = N and θM = N by <strong>in</strong>version on gsub app<br />

∆ ⊢ N g and ∆ ⊢ N g by <strong>in</strong>version on groundness<br />

∆ ⊢ θ : η ′ by IH on D0<br />

∆ ⊢ θ : η ′′ by IH on D1<br />

∆ ⊢ θ : η ′ ⊓ η ′′ by Lemma 5.2.25<br />

Lemma 5.2.37 (Ground Terms Yield Trivial Information)<br />

1. (a) If ∆ ⊢ M g and ∆ ⊢ M g=⇒ η <strong>the</strong>n η = η∆<br />

(b) If ∆ ⊢ M g and ∆ ⊢ M g=⇒ η <strong>the</strong>n η = η∆<br />

2. (a) If η ⊢ M g and η ⊢ M g=⇒ η ′ <strong>the</strong>n η ′ = η<br />

(b) If η ⊢ M g and η ⊢ M g=⇒ η ′ <strong>the</strong>n η ′ = η<br />

130


Pro<strong>of</strong>: 1 is by straightforward simultaneous <strong>in</strong>duction on <strong>the</strong> given derivation <strong>of</strong><br />

groundness, us<strong>in</strong>g Lemma 5.2.24; 2 is analogous. <br />

The follow<strong>in</strong>g lemma plays a crucial role <strong>in</strong> <strong>the</strong> soundness <strong>of</strong> our term<strong>in</strong>ation/mode<br />

checker.<br />

Lemma 5.2.38 (Abstract Unification)<br />

1. If ∆ ′ ⊢ θ : ∆ <strong>the</strong>n:<br />

(a) if D : (∆ ⊢ M g=⇒ η) and θM = M ′ <strong>the</strong>n ∆ ′ ⊢ M ′ g=⇒ η ′ and<br />

η ⊢ θ : η ′<br />

(b) if D : (∆ ⊢ M g=⇒ η) and θM = M ′ <strong>the</strong>n ∆ ′ ⊢ M ′ g=⇒ η ′ and<br />

η ⊢ θ : η ′<br />

2. If ∆ ⊢ θ : η <strong>the</strong>n:<br />

(a) if D : (η ⊢ M g=⇒ η ′ ) and θM = M ′ <strong>the</strong>n ∆ ⊢ M ′ g=⇒ η ′′ and<br />

η ′′ ⊢ θ : η ′<br />

(b) if D : η ⊢ M g=⇒ η ′ and θM = M ′ <strong>the</strong>n ∆ ⊢ M ′ g=⇒ η ′′ and η ′′ ⊢ θ : η ′<br />

3. If η ′ 0 ⊢ θ : η0 <strong>the</strong>n:<br />

(a) If D : (η0 ⊢ M g=⇒ η1) and θM = M ′ <strong>the</strong>n η ′ 0 ⊢ M ′ g=⇒ η ′ 1 and<br />

η ′ 1 ⊢ θ : η1<br />

(b) If D : (η0 ⊢ M g=⇒ η1) and θM = M ′ <strong>the</strong>n η ′ 0 ⊢ M ′ g=⇒ η ′ 1 and<br />

η ′ 1 ⊢ θ : η1<br />

Pro<strong>of</strong>: Each numbered case is by simultaneous <strong>in</strong>duction on D, where <strong>the</strong> reason<strong>in</strong>g<br />

is essentially <strong>the</strong> same each time. We show <strong>the</strong> <strong>in</strong>terest<strong>in</strong>g cases <strong>of</strong> 2 below.<br />

131


1(a)<br />

Case:<br />

D =<br />

D0<br />

η1 ⊢ M pattern<br />

D1<br />

|η0, ∃ ? x:A, η1|; A ⊢ M : a N<br />

η0, ∃ ? x:A, η1 ⊢ x M g=⇒ η0, ∃ g x:A, η1<br />

∆ ⊢ θ : η0, ∃ ? x:A, η1 and θ(x M) = M ′ given<br />

θx = N:B and θM = M ′ and reduceB −(N, M ′ ) = M ′<br />

by <strong>in</strong>version on gsub app<br />

∆ = ∆0, ∆1 and θ = θ ′ 0, θ1 and ∆0 ⊢ θ ′ 0 : η0, ∃ ? x:A by Lemma 5.2.30<br />

θ ′ 0 = θ0, N:B/x and ∆0 ⊢ θ0 : η0 and |∆0| ⊢ N : B and θA = B<br />

and ei<strong>the</strong>r ∆0 ⊢ N g or (∃y:B ∈ ∆0 and expand y (B; ·) = N)<br />

by <strong>in</strong>version on abs sub typ<strong>in</strong>g<br />

Assume ∆0 ⊢ N g Case 1<br />

let η ′′ = η∆<br />

∆1 ⊢ M ′ pattern by Lemma 5.2.33<br />

∆ ⊢ M ′ pattern by Lemma 5.2.28<br />

∆ ⊢ M ′ g by Lemma 5.2.26<br />

∆ ⊢ M ′ g by Lemma 5.2.20<br />

∆ ⊢ M ′ g=⇒ η ′′ by Lemma 5.2.37<br />

∆0 ⊢ (θ0, N:B/x) : (η0, ∃ g x:A) by rule<br />

∆ ⊢ θ : η0, ∃ g x:A, η1<br />

η ′′ ⊢ θ : η0, ∃ g x:A, η1<br />

by Lemma 5.2.32<br />

by Lemma 5.2.16<br />

Assume ∃y:B ∈ ∆0 and expand y (B; ·) = N Case 2<br />

N = y M ′ by Theorem 5.1.25 and Lemma 5.1.3<br />

∆0 = ∆ ′ 0, ∃y:B, ∆ ′′<br />

0<br />

132<br />

by <strong>in</strong>version on ∃y:B ∈ ∆0


1(b)<br />

Case:<br />

Let η ′′ = η∆ ′ 0 , ∃gy:B, η∆ ′′ , η∆1 0<br />

∆1 ⊢ M ′ pattern by Lemma 5.2.33<br />

∆ ′′<br />

0, ∆1 ⊢ M ′ pattern by Lemma 5.2.28<br />

η∆ ′′<br />

0 , η∆1 ⊢ M ′ pattern by Lemma 5.2.27<br />

∆ ⊢ θ : ∆ η0,∃ ? x:A,η1<br />

θ(a N) = a N ′ and |∆|; B ⊢ M ′ : a N ′<br />

By Lemma 5.2.16<br />

by Lemma 5.2.7 and Lemma 5.2.2<br />

∆ ⊢ M ′ g=⇒ η ′′ by rule<br />

η∆0 ⊢ θ0 : η0<br />

by Lemma 5.2.16<br />

η∆ ′ 0 , ∃g y:B, η∆ ′′<br />

0 ⊢ θ0 : η0 by Lemma 5.2.23<br />

η∆ ′ 0 , ∃g y:B, η∆ ′′<br />

0<br />

⊢ N g by Lemma 5.2.21<br />

η∆ ′ 0 , ∃g y:B, η∆ ′′<br />

0 ⊢ (θ0, N:B) : η0, ∃ g x:A by rule<br />

η ′′ ⊢ θ ′′ : η0, ∃ g x:A, η1<br />

D =<br />

D0<br />

η ⊢ M g=⇒ η ′ 0<br />

D1<br />

η ⊢ M g=⇒ η ′ 1<br />

η ⊢ M :: M g=⇒ η ′ 0 ⊓ η ′ 1<br />

by Lemma 5.2.32<br />

∆ ⊢ θ : η and θ(M :: M) = M ′ :: M ′ given<br />

θM = M ′ and θM = θM ′ by <strong>in</strong>version on gsub app<br />

∆ ⊢ M ′ g=⇒ η ′′<br />

0 and η ′′<br />

0 ⊢ θ : η ′ 0<br />

∆ ⊢ M ′ g=⇒ η ′′<br />

1 and η ′′<br />

1 ⊢ θ : η ′ 1<br />

∆ ⊢ M ′ :: M ′ g=⇒ η ′′<br />

0 ⊓ η ′′<br />

1<br />

η ′′<br />

0 ⊓ η ′′<br />

1 ⊢ θ : η ′ 0 ⊓ η ′ 1<br />

133<br />

by IH 1 on D0<br />

by IH 2 on D1<br />

by rule<br />

by Lemma 5.2.24


Lemma 5.2.39 (Weaken<strong>in</strong>g for Ground Implication)<br />

1. If |∆| ⊢ A : type <strong>the</strong>n:<br />

(a) if D : (∆, ∆ ′ ⊢ M g=⇒ η) <strong>the</strong>n η = η0, η1 and ∆0, ∀x:A, ∆1 ⊢ M g=⇒<br />

η0, ∀x:A, η1 and ∆0, ∃x:A, ∆1 ⊢ M g=⇒ η0, ∃ ? x:A, η1<br />

(b) if D : (∆, ∆ ′ ⊢ M g=⇒ η) <strong>the</strong>n η = η0, η1 and ∆0, ∀x:A, ∆1 ⊢ M g=⇒<br />

η0, ∀x:A, η1 and ∆0, ∃x:A, ∆1 ⊢ M g=⇒ η0, ∃ ? x:A, η1<br />

2. If |η0| ⊢ A : type <strong>the</strong>n:<br />

(a) if D : (η0, η1 ⊢ M g=⇒ η ′ ) <strong>the</strong>n η = η ′ 0, η ′ 1 and η0, ∀x:A, η1 ⊢ M g=⇒<br />

η ′ 0, ∀x:A, η ′ 1 and η0, ∃ ? x:A, η1 ⊢ M g=⇒ η ′ 0, ∃ ? x:A, η ′ 1 and η0, ∃ g x:A, η1 ⊢<br />

M g=⇒ η ′ 0, ∃ g x:A, η ′ 1<br />

(b) if D : (η0, η1 ⊢ M g=⇒ η ′ ) <strong>the</strong>n η = η ′ 0, η ′ 1 and η0, ∀x:A, η1 ⊢ M g=⇒<br />

η ′ 0, ∀x:A, η ′ 1 and η0, ∃ ? x:A, η1 ⊢ M g=⇒ η ′ 0, ∃ ? x:A, η ′ 1 and η0, ∃ g x:A, η1 ⊢<br />

M g=⇒ η ′ 0, ∃ g x:A, η ′ 1<br />

Pro<strong>of</strong>: Each case is by straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> D; <strong>the</strong> (b) cases<br />

use <strong>the</strong> (a) cases, and <strong>the</strong> (a) cases use Lemma 5.2.24. <br />

5.2.4 Size Order<strong>in</strong>g<br />

In general, f<strong>in</strong>d<strong>in</strong>g a solution to a query us<strong>in</strong>g fillTerm will, via <strong>the</strong> fs-arr case <strong>of</strong><br />

fillSp<strong>in</strong>e, requires <strong>the</strong> solution <strong>of</strong> some number <strong>of</strong> subgoals. In order to know that<br />

this process term<strong>in</strong>ates, we need to know that every subgoal is, <strong>in</strong> some sense, smaller<br />

than <strong>the</strong> goal that spawned it. For example, any goal <strong>of</strong> <strong>the</strong> form add z M N should<br />

be considered smaller than any subgoal <strong>of</strong> <strong>the</strong> form add (s z) M ′ N ′ , given that z is<br />

considered smaller than s z. Thus, given some well-founded order<strong>in</strong>g on LF-terms, it<br />

134


should be possible to prove <strong>the</strong> term<strong>in</strong>ation <strong>of</strong> pro<strong>of</strong>-search based on this order<strong>in</strong>g.<br />

However, we do need to be careful. Consider pro<strong>of</strong> search on <strong>the</strong> follow<strong>in</strong>g signature,<br />

where <strong>the</strong> sole argument to p is moded positive.<br />

. . . , p:nat → type,<br />

f : Πx:nat.(p x) → (p (s x))<br />

It would be tempt<strong>in</strong>g to conclude that any well-typed query <strong>of</strong> <strong>the</strong> form ∆ ⊢<br />

? : p M will term<strong>in</strong>ate (unsuccessfully, as we have omitted any base case for p),<br />

s<strong>in</strong>ce it seems as though x should always be smaller than s x. However, this sort<br />

<strong>of</strong> reason<strong>in</strong>g is <strong>in</strong>valid when query<strong>in</strong>g for non-ground terms. For example, <strong>the</strong> (ill-<br />

moded) query ·, ∃y:nat ⊢ ? : p y will not term<strong>in</strong>ate <strong>in</strong> our semantics (nor would an<br />

equivalent example <strong>in</strong> Prolog), because each subgoal generated by fillSp<strong>in</strong>e will,<br />

after unification, be essentially <strong>the</strong> same as <strong>the</strong> orig<strong>in</strong>al goal before unification. Our<br />

mode/term<strong>in</strong>ation checker will rule out such bad queries by guarantee<strong>in</strong>g that <strong>in</strong>put<br />

arguments are always ground before fillTerm is called, mean<strong>in</strong>g that our notion <strong>of</strong><br />

well-founded order<strong>in</strong>g on LF terms need only be def<strong>in</strong>ed on ground terms.<br />

To this end, we assume <strong>the</strong> existence <strong>of</strong> a semantic doma<strong>in</strong> S that comes equipped<br />

with a notion <strong>of</strong> well-founded order<strong>in</strong>g (<strong>the</strong> semantic order<strong>in</strong>g), and a semantic map-<br />

p<strong>in</strong>g, written [M ] ∆, that maps terms M that are both well-typed and ground <strong>in</strong><br />

∆ to elements <strong>of</strong> S. For example, S could be <strong>the</strong> term-algebra correspond<strong>in</strong>g to <strong>the</strong><br />

natural numbers, where [M ] ∆ counts <strong>the</strong> number <strong>of</strong> constants and variables <strong>in</strong><br />

M. Although we use <strong>the</strong> word “semantic” here, it should be noted that S, [M ] ∆,<br />

semantic equality and <strong>the</strong> semantic order<strong>in</strong>g should be def<strong>in</strong>ed us<strong>in</strong>g <strong>the</strong> same syn-<br />

tactic mach<strong>in</strong>ery as elsewhere <strong>in</strong> this <strong>the</strong>sis, although we treat <strong>the</strong> well-foundedness<br />

<strong>of</strong> <strong>the</strong> semantic order<strong>in</strong>g as an axiomatic assumption. We list some <strong>of</strong> properties that<br />

we expect <strong>of</strong> a semantic doma<strong>in</strong> and <strong>the</strong> semantic mapp<strong>in</strong>g below.<br />

135


Def<strong>in</strong>ition 5.2.40 (Semantic Doma<strong>in</strong>) A syntactic category S is a semantic do-<br />

ma<strong>in</strong> iff <strong>the</strong>re exist <strong>the</strong> b<strong>in</strong>ary relation < on <strong>the</strong> elements <strong>of</strong> S, and <strong>the</strong> partial-<br />

function [−] (−) from terms and mixed-prefix contexts to elements <strong>of</strong> S that satisfy<br />

<strong>the</strong> follow<strong>in</strong>g properties.<br />

1. (Semantic Order<strong>in</strong>g)


to sp<strong>in</strong>es [M ] A; ∆ are def<strong>in</strong>ed judgmentally below. Note that <strong>the</strong> relation ≡ holds<br />

whenever two type-families are mutually recursive; its use <strong>in</strong> <strong>the</strong> sp<strong>in</strong>e stripp<strong>in</strong>g func-<br />

tion is motivated by considerations discussed <strong>in</strong> Section 2.1.<br />

[M ] ∆, ∀x:A = n<br />

[λx:A.M ] ∆ = n<br />

[·] a N; ∆ = z<br />

∀x:A ∈ ∆ [[M ] A; ∆ = n<br />

[x M ] ∆ = s n<br />

c:A ∈ Σ [[M ] A; ∆ = n<br />

[c M ] ∆ = s n<br />

hd(A) ≡ hd(B) [[M ] ∆ = n0 [M ] B; ∆ = n1 add(n0; n1; n)<br />

[M :: M ] Πx:A.B; ∆ = n<br />

hd(A) ≡ hd(B) [[M ] B; ∆ = n<br />

[M :: M ] Πx:A.B; ∆ = n<br />

The pro<strong>of</strong> that this forms a valid semantic doma<strong>in</strong> is straightforward.<br />

Each semantic doma<strong>in</strong> gives rise to an <strong>in</strong>duction pr<strong>in</strong>ciple over LF terms. For <strong>the</strong><br />

rema<strong>in</strong>der <strong>of</strong> this section, we assume that <strong>the</strong> choice <strong>of</strong> semantic doma<strong>in</strong> S is fixed,<br />

although we choose to leave it abstract for now. Later we will consider <strong>the</strong> impact<br />

that <strong>the</strong> strength <strong>of</strong> <strong>the</strong> semantic order<strong>in</strong>g has on our term<strong>in</strong>ation argument.<br />

The semantic doma<strong>in</strong> gives us a well-founded order<strong>in</strong>g on LF terms, but, <strong>in</strong> gen-<br />

eral, it is build up more complex well-founded order<strong>in</strong>gs from simpler ones; for exam-<br />

ple lexicographic order<strong>in</strong>gs have already been used several times <strong>in</strong> this document.<br />

Thus, if <strong>the</strong> Ackermann function is encoded <strong>in</strong> LF as ack:nat → nat → nat → type,<br />

<strong>the</strong>n it should be possible to specify that any query <strong>of</strong> <strong>the</strong> form ∆ ⊢ ? : ack M1 M2 M3<br />

is smaller than any query <strong>of</strong> <strong>the</strong> form ∆ ′ ⊢ ? : ack N1 N2 N3 whenever ei<strong>the</strong>r<br />

[∆] M1


<strong>the</strong> empty measure and <strong>the</strong> commutative version <strong>of</strong> <strong>the</strong> simultaneous order<strong>in</strong>g, we<br />

omit <strong>the</strong>ir specifications for <strong>the</strong> sake <strong>of</strong> simplicity.<br />

We lift <strong>the</strong> notions <strong>of</strong> typ<strong>in</strong>g, groundness and generalized substitutions to termi-<br />

nation measures <strong>in</strong> <strong>the</strong> straightforward way. We list <strong>the</strong> names and descriptions <strong>of</strong><br />

<strong>the</strong> relevant judgments <strong>in</strong> <strong>the</strong> table below, but omit <strong>the</strong>ir <strong>in</strong>ference rules for <strong>the</strong> sake<br />

<strong>of</strong> brevity.<br />

Γ ⊢ O wellTyped every M <strong>in</strong> O satisfies Γ ⊢ M : A<br />

∆ ⊢ O g every M <strong>in</strong> O satisfies ∆ ⊢ M g<br />

η ⊢ O g every M <strong>in</strong> O satisfies η ⊢ M g<br />

θ O = O ′ apply<strong>in</strong>g θ to every M <strong>in</strong> O results <strong>in</strong> O ′<br />

Def<strong>in</strong>ition 5.2.43 (Measure Functions) For each family constant a:K <strong>in</strong> Σ, <strong>the</strong><br />

user must specify a determ<strong>in</strong>istic function measurea M = O which is total whenever<br />

·; K ⊢ M : type. Moreover, <strong>the</strong> function must satisfy <strong>the</strong> follow<strong>in</strong>g properties.<br />

1. if M ∈ O, <strong>the</strong>n M ∈ <strong>in</strong>puts a (M)<br />

2. measurea is parametric <strong>in</strong> M<br />

For example, measureack (M0 :: M1 :: M2 :: ·) = lex〈M0; M1〉, for every M0, M1 and<br />

M2.<br />

We compare <strong>the</strong> size <strong>of</strong> term<strong>in</strong>ation measures O1 and O2, us<strong>in</strong>g <strong>the</strong> judgments<br />

〈∆1; O1〉


〈O1; ∆〉


2. =o is a transitive, symmetric and if |∆| ⊢ O wellTyped and ∆ ⊢ O g <strong>the</strong>n<br />

〈∆; O〉 =o 〈∆; O〉<br />

3. If 〈∆; O〉 =o 〈∆; O〉 and ∆ can be obta<strong>in</strong>ed from ∆ ′ by delet<strong>in</strong>g some number<br />

<strong>of</strong> declarations <strong>the</strong>n 〈∆; O〉 =o 〈∆ ′ ; O〉<br />

4. If 〈O1; ∆1〉 =o 〈O ′ 1; ∆ ′ 1〉 and 〈O2; ∆2〉 =o 〈O ′ 2; ∆ ′ 2〉 and 〈O1; ∆1〉


assume that a M is bigger than b N, provided we make such assumptions consistently;<br />

we keep track <strong>of</strong> this by assign<strong>in</strong>g a tie-break<strong>in</strong>g natural number tba to each a <strong>in</strong> Σ.<br />

Term<strong>in</strong>ation Vectors V ::= 〈a; 〈O; ∆〉; m〉<br />

Term<strong>in</strong>ation vectors are computed from goals us<strong>in</strong>g <strong>the</strong> (determ<strong>in</strong>istic) function<br />

size∆(A). As usual, we view <strong>the</strong> def<strong>in</strong><strong>in</strong>g equations <strong>of</strong> size∆(A) as shorthand<br />

for a judgmental whose totality is witnessed by an <strong>in</strong>ductive pro<strong>of</strong>, <strong>in</strong> this case on<br />

<strong>the</strong> structure <strong>of</strong> A.<br />

size∆(a M) = 〈a; 〈measurea M; ∆〉; tba〉<br />

size∆(Πx:A.B) = V if size∆,∀x:A(B) = V<br />

Term<strong>in</strong>ation vectors are strictly ordered (lexicographically) by <strong>the</strong> relation


Term<strong>in</strong>ation vectors give us a well-founded order<strong>in</strong>g on queries whose <strong>in</strong>put ar-<br />

guments are ground, which will play an important role <strong>in</strong> prov<strong>in</strong>g that <strong>the</strong> ex-<br />

ecution <strong>of</strong> a mode/term<strong>in</strong>ation checked logic program term<strong>in</strong>ates. However, <strong>the</strong><br />

mode/term<strong>in</strong>ation checker reasons about logic programs statically, and thus must be<br />

able to reach conclusions <strong>of</strong> <strong>the</strong> form “although O1 and O2 may not be ground, given<br />

any θ such that θO1 and θO2 are both ground, it must be <strong>the</strong> case that θO1 is smaller<br />

than θO2.” To this end, we def<strong>in</strong>e a notion <strong>of</strong> order<strong>in</strong>g formulas. Although we reuse<br />

<strong>the</strong> letters F and G <strong>in</strong> def<strong>in</strong><strong>in</strong>g order<strong>in</strong>g formulas, <strong>the</strong>y are not to be confused with<br />

<strong>the</strong> formulas from <strong>the</strong> assertion logics from Chapter 2 and Chapter 4.<br />

Order<strong>in</strong>g Formulas F, G ::= ⊤ | O1 ≺ O2 | O1 O2 | O1 ≈ O2 | ∇x:A.F | F ∧ G<br />

Order<strong>in</strong>g Contexts Φ ::= · | Φ, F<br />

We use a sequent calculus provability judgment <strong>of</strong> <strong>the</strong> form ∆; Φ ⊢ F to mean that<br />

<strong>the</strong> formula F is a logical consequence <strong>of</strong> <strong>the</strong> formulas <strong>in</strong> Φ, and we expect sequents<br />

such as ∃x:nat; · ⊢ x ≺ s x to be provable. This is because, for any ground M <strong>of</strong> type<br />

nat, <strong>the</strong> <strong>in</strong>equality 〈·; M〉


ecause we expect ground formulas to be valid whenever <strong>the</strong>y are provable, <strong>the</strong><br />

sequent calculus must be sound with respect to <strong>the</strong> semantic doma<strong>in</strong>; we make this<br />

precise <strong>in</strong> Def<strong>in</strong>ition 5.2.47. As with <strong>the</strong> semantic doma<strong>in</strong>, we leave <strong>the</strong> exact for-<br />

mulation <strong>of</strong> <strong>the</strong> rules for <strong>the</strong> sequent calculus abstract, although an example <strong>of</strong> one<br />

which is compatible with <strong>the</strong> semantic doma<strong>in</strong> <strong>of</strong> Example 5.2.42 can be found <strong>in</strong><br />

[Pie05]; we leave <strong>the</strong> formal specification and implementation <strong>of</strong> a sequent calculus<br />

which is compatible with <strong>the</strong> semantic doma<strong>in</strong> <strong>of</strong> Example 5.2.41 to future work,<br />

although a prototype <strong>of</strong> an implementation <strong>of</strong> <strong>the</strong> Twelf term<strong>in</strong>ation checker based<br />

on one candidate is available from http://www.twelf.org/lpo/.<br />

We lift <strong>the</strong> notion <strong>of</strong> wellTyped, g and generalized substitution application to<br />

order<strong>in</strong>g formulas and order<strong>in</strong>g contexts, <strong>the</strong> rules <strong>of</strong> which are straightforward, but<br />

made precise below.<br />

Γ ⊢ ⊤ wellTyped<br />

Γ ⊢ O1 wellTyped Γ ⊢ O2 wellTyped<br />

Γ ⊢ (O1 O2) wellTyped<br />

Γ, x:A ⊢ F wellTyped<br />

Γ ⊢ (∇x:A.F ) wellTyped<br />

Γ ⊢ (·) wellTyped<br />

∆ ⊢ ⊤ g<br />

∆ ⊢ O1 g ∆ ⊢ O2 g<br />

∆ ⊢ (O1 ≈ O2) g<br />

Γ ⊢ O1 wellTyped Γ ⊢ O2 wellTyped<br />

Γ ⊢ (O1 ≺ O2) wellTyped<br />

Γ ⊢ O1 wellTyped Γ ⊢ O2 wellTyped<br />

Γ ⊢ (O1 ≈ O2) wellTyped<br />

Γ ⊢ F wellTyped Γ ⊢ G wellTyped<br />

Γ ⊢ F ∧ G wellTyped<br />

Γ ⊢ Φ wellTyped Γ ⊢ F wellTyped<br />

∆ ⊢ O1 g ∆ ⊢ O2 g<br />

∆ ⊢ (O1 ≺ O2) g<br />

∆ ⊢ (·) g<br />

Γ ⊢ (Φ, F ) wellTyped<br />

∆, ∀x:A ⊢ F g<br />

∆ ⊢ (∇x:A.F ) g<br />

∆ ⊢ Φ g ∆ ⊢ F g<br />

143<br />

∆ ⊢ (Φ, F ) g<br />

∆ ⊢ O1 g ∆ ⊢ O2 g<br />

∆ ⊢ (O1 O2) g<br />

∆ ⊢ F g ∆ ⊢ G g<br />

∆ ⊢ F ∧ G g


η ⊢ ⊤ g<br />

η ⊢ O1 g η ⊢ O2 g<br />

η ⊢ (O1 ≈ O2) g<br />

θ⊤ = ⊤<br />

η ⊢ O1 g η ⊢ O2 g<br />

η ⊢ (O1 ≺ O2) g<br />

η ⊢ (·) g<br />

η, ∀x:A ⊢ F g<br />

η ⊢ (∇x:A.F ) g<br />

η ⊢ Φ g η ⊢ F g<br />

η ⊢ (Φ, F ) g<br />

η ⊢ O1 g η ⊢ O2 g<br />

η ⊢ (O1 O2) g<br />

η ⊢ F g η ⊢ G g<br />

η ⊢ F ∧ G g<br />

θ (O1 ≺ O2) = O ′ 1 ≺ O′ 2 if θ O1 = O ′ 1 and θO2 = O ′ 2<br />

θ (O1 O2) = O ′ 1 O′ 2 if θ O1 = O ′ 1 and θO2 = O ′ 2<br />

θ (O1 ≈ O2) = O ′ 1 ≈ O′ 2 if θ O1 = O ′ 1 and θO2 = O ′ 2<br />

θ (∇x:A.F ) = ∇y:B.G if θA = B and (θ, y/x)F = G<br />

θ(F ∧ G) = F ′ ∧ G ′ if θF = F ′ and θG = G ′<br />

θ (·) = ·<br />

θ (Φ, F ) = Φ ′ , G if θΦ = Φ ′ and θF = G<br />

Def<strong>in</strong>ition 5.2.47 (Soundness <strong>of</strong> Denotations and Pro<strong>of</strong>s) Given <strong>the</strong> notion<br />

<strong>of</strong> valid <strong>in</strong>duced by a given semantic doma<strong>in</strong>, we say that <strong>the</strong> judgment ∆; Φ ⊢ F is<br />

sound iff <strong>the</strong> follow<strong>in</strong>g propositions hold.<br />

1. If ∆; Φ ⊢ F and ∆ can be obta<strong>in</strong>ed from ∆ ′ by delet<strong>in</strong>g some number <strong>of</strong> decla-<br />

rations <strong>the</strong>n ∆ ′ ; Φ ⊢ F<br />

2. If ∆; Φ ⊢ F and ∆ ⊢ Φ wellTyped and ∆ ⊢ F wellTyped and ∆ ′ ⊢ θ : ∆ and<br />

θF = F ′ and θΦ = Φ ′ <strong>the</strong>n ∆ ′ ; Φ ′ ⊢ F ′<br />

3. If ∆; Φ ⊢ F and ∆ ⊢ Φ wellTyped and ∆ ⊢ Φ g and ∆ ⊢ Φ valid and<br />

∆ ⊢ F wellTyped and ∆ ⊢ F g <strong>the</strong>n ∆ ⊢ F valid<br />

Sometimes it is useful to know that solved goals always satisfy certa<strong>in</strong> <strong>in</strong>variants.<br />

For example, once <strong>the</strong> goal add M0 M1 M2 is solved, we should know that <strong>the</strong> <strong>in</strong>variant<br />

144


M1 M2 is valid. In general, for each a:K <strong>in</strong> Σ, <strong>the</strong> user must def<strong>in</strong>e <strong>the</strong> parametric<br />

function redInva that maps sp<strong>in</strong>es <strong>of</strong> <strong>the</strong> appropriate length to formulas (i.e. if K =<br />

Πx1:A1. . . . Πxn:An.type <strong>the</strong>n redInva (M1 :: . . . :: Mn :: ·) is built up from M1 . . . Mn<br />

uniformly without regards to <strong>the</strong> structure <strong>of</strong> each Mi). Reduction <strong>in</strong>variants satisfy<br />

<strong>the</strong> follow<strong>in</strong>g properties.<br />

Lemma 5.2.48 (Reduction Invariants)<br />

1. If Γ ⊢ a M : type <strong>the</strong>n Γ ⊢ redInva M wellTyped<br />

2. If θ(a M) = a M ′ and redInva M = F <strong>the</strong>n θF = F ′ and redInva M ′ = F ′<br />

3. If ∆ ⊢ a M g <strong>the</strong>n ∆ ⊢ redInva M g<br />

4. If η ⊢ a M g <strong>the</strong>n η ⊢ redInva M g<br />

Pro<strong>of</strong>: Direct, by <strong>the</strong> def<strong>in</strong>ition <strong>of</strong> redInva. <br />

The follow<strong>in</strong>g lemmas lift some <strong>of</strong> <strong>the</strong> useful properties <strong>of</strong> LF terms and sp<strong>in</strong>es<br />

to measures, order<strong>in</strong>g formulas and contexts.<br />

Lemma 5.2.49 (Gen. Substitutions on Measures, Formulas, Contexts)<br />

1. (a) If θO = O ′ and θO = O ′′ <strong>the</strong>n O ′ = O ′′<br />

(b) If θF = F ′ and θF = F ′′ <strong>the</strong>n F ′ = F ′′<br />

(c) If θΦ = Φ ′ and θΦ = Φ ′′ <strong>the</strong>n Φ ′ = Φ ′′<br />

2. If ∆ ′ ⊢ θ : ∆ <strong>the</strong>n:<br />

(a) If |∆| ⊢ O wellTyped <strong>the</strong>n θO = O ′ and |∆ ′ | ⊢ O ′ wellTyped<br />

(b) If |∆| ⊢ F wellTyped <strong>the</strong>n θF = F ′ and |∆ ′ | ⊢ F ′ wellTyped<br />

(c) If |∆| ⊢ Φ wellTyped <strong>the</strong>n θΦ = Φ ′ and |∆ ′ | ⊢ Φ ′ wellTyped<br />

145


Pro<strong>of</strong>: Each case <strong>in</strong> 1 is by straightforward <strong>in</strong>duction on <strong>the</strong> derivation <strong>of</strong> ei-<br />

<strong>the</strong>r generalized substitution application. 1(c) uses 1(b), 1(b) uses 1(a), 1(a) uses<br />

Lemma 5.2.2. Each case <strong>in</strong> 2 is by straightforward <strong>in</strong>duction on <strong>the</strong> given typ<strong>in</strong>g<br />

derivation; 2(c) uses 2(b), 2(b) uses 2(a) and 2(a) uses Lemma 5.2.7. <br />

Lemma 5.2.50 (Weaken<strong>in</strong>g for Measures, Formulas, Contexts)<br />

If Γ ⊢ A : type and x#A <strong>the</strong>n:<br />

1. if Γ, Γ ′ ⊢ O wellTyped <strong>the</strong>n Γ, x:A, Γ ′ ⊢ O wellTyped<br />

2. if Γ, Γ ′ ⊢ F wellTyped <strong>the</strong>n Γ, x:A, Γ ′ ⊢ F wellTyped<br />

3. if Γ, Γ ′ ⊢ Φ wellTyped <strong>the</strong>n Γ, x:A, Γ ′ ⊢ Φ wellTyped<br />

Pro<strong>of</strong>: By <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> <strong>the</strong> given typ<strong>in</strong>g derivation; 3 uses 2, 2 uses<br />

1, and 1 uses Lemma 5.1.6. <br />

Lemma 5.2.51 (Weaken<strong>in</strong>g for Ground On Measures, Formulas, Contexts)<br />

1. If ∆ can be obta<strong>in</strong>ed from ∆ ′ by delet<strong>in</strong>g some number <strong>of</strong> declarations <strong>the</strong>n:<br />

(a) If ∆ ⊢ O g <strong>the</strong>n ∆ ′ ⊢ O g<br />

(b) If ∆ ⊢ F g <strong>the</strong>n ∆ ′ ⊢ F g<br />

(c) If ∆ ⊢ Φ g <strong>the</strong>n ∆ ′ ⊢ Φ g<br />

2. If η can be obta<strong>in</strong>ed from η ′ by delet<strong>in</strong>g some number <strong>of</strong> declarations <strong>the</strong>n:<br />

(a) If η ⊢ O g <strong>the</strong>n η ′ ⊢ O g<br />

(b) If η ⊢ F g <strong>the</strong>n η ′ ⊢ F g<br />

(c) If η ⊢ Φ g <strong>the</strong>n η ′ ⊢ Φ g<br />

146


Pro<strong>of</strong>: By straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> <strong>the</strong> given groundness deriva-<br />

tions. Each (c) case uses <strong>the</strong> correspond<strong>in</strong>g (b) case, each (b) case uses <strong>the</strong> corre-<br />

spond<strong>in</strong>g (a) case, and each (a) case uses Lemma 5.2.18. <br />

Lemma 5.2.52 (Preservation <strong>of</strong> Ground on Measures, Formulas, Contexts)<br />

1. If ∆ ′ ⊢ θ : ∆ <strong>the</strong>n:<br />

(a) If ∆ ⊢ O g and θO = O ′ <strong>the</strong>n ∆ ′ ⊢ O ′ g<br />

(b) If ∆ ⊢ F g and θF = F ′ <strong>the</strong>n ∆ ′ ⊢ F ′ g<br />

(c) If ∆ ⊢ Φ g and θΦ = Φ ′ <strong>the</strong>n ∆ ′ ⊢ Φ ′ g<br />

2. If ∆ ⊢ θ : η <strong>the</strong>n:<br />

(a) η ⊢ O g and θO = O ′ <strong>the</strong>n ∆ ⊢ O ′ g<br />

(b) η ⊢ F g and θF = F ′ <strong>the</strong>n ∆ ⊢ F ′ g<br />

(c) η ⊢ Φ g and θΦ = Φ ′ <strong>the</strong>n ∆ ⊢ Φ ′ g<br />

3. If η ′ ⊢ θ : η <strong>the</strong>n:<br />

(a) η ⊢ O g and θO = O ′ <strong>the</strong>n η ′ ⊢ O ′ g<br />

(b) η ⊢ F g and θF = F ′ <strong>the</strong>n η ′ ⊢ F ′ g<br />

(c) η ⊢ Φ g and θΦ = Φ ′ <strong>the</strong>n η ′ ⊢ Φ ′ g<br />

Pro<strong>of</strong>: Each case is by a straightforward <strong>in</strong>duction on <strong>the</strong> given derivation <strong>of</strong> ground-<br />

ness. Each (c) case uses <strong>the</strong> correspond<strong>in</strong>g (b) case, each (b) case uses <strong>the</strong> corre-<br />

spond<strong>in</strong>g (a) case, and each (a) case uses Lemma 5.2.20. <br />

Lemma 5.2.53 (Substitution for Validity) If ∆ ′ ⊢ θ : ∆ <strong>the</strong>n:<br />

147


1. if |∆| ⊢ F wellTyped and ∆ ⊢ F g and ∆ ⊢ F valid and θF = F ′ <strong>the</strong>n<br />

∆ ′ ⊢ F ′ valid<br />

2. if |∆| ⊢ Φ wellTyped and ∆ ⊢ Φ g and ∆ ⊢ Φ valid and θΦ = Φ ′ <strong>the</strong>n<br />

∆ ′ ⊢ Φ ′ valid<br />

Pro<strong>of</strong>: By straightforward <strong>in</strong>duction on <strong>the</strong> derivation <strong>of</strong> valid; 1 uses Lemma 5.2.45<br />

and 2 uses 1. <br />

Lemma 5.2.54 (Weaken<strong>in</strong>g for Validity) If ∆ can be obta<strong>in</strong>ed from ∆ ′ by delet-<br />

<strong>in</strong>g some number <strong>of</strong> declarations, <strong>the</strong>n:<br />

1. if ∆ ⊢ F valid <strong>the</strong>n ∆ ′ ⊢ F valid<br />

2. if ∆ ⊢ Φ valid <strong>the</strong>n ∆ ′ ⊢ Φ valid<br />

Pro<strong>of</strong>: By straightforward <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> valid; 1 uses Lemma 5.2.45<br />

and 2 uses 1. <br />

5.2.5 The Mode and Term<strong>in</strong>ation Checker<br />

We are now ready to def<strong>in</strong>e <strong>the</strong> mode/term<strong>in</strong>ation checker. We will f<strong>in</strong>d it useful to<br />

make lists <strong>of</strong> LF types; we abuse notation slightly by overload<strong>in</strong>g <strong>the</strong> notation used<br />

for sp<strong>in</strong>es.<br />

Type Lists A, B ::= · | A :: A<br />

We say that Γ ⊢ A wellTyped if every A <strong>in</strong> A is well typed.<br />

Γ ⊢ · wellTyped<br />

Γ ⊢ A : type Γ ⊢ A wellTyped<br />

Γ ⊢ A :: A wellTyped<br />

We lift generalized substitution application analogously. The follow<strong>in</strong>g lemma lifts<br />

some <strong>of</strong> <strong>the</strong> useful properties <strong>of</strong> LF types to type lists.<br />

148


Lemma 5.2.55 (Type Lists)<br />

1. If Γ, Γ ′ ⊢ A wellTyped and Γ ⊢ B : type <strong>the</strong>n Γ, x:A, Γ ′ ⊢ A wellTyped<br />

2. If θA = A ′ and θA = A ′′ <strong>the</strong>n A ′ = A ′′<br />

3. If x#A and (θ, y/x)A = A ′ or (θ, M:B/x)A = A ′ <strong>the</strong>n θA = A ′<br />

4. If ∆ ′ ⊢ θ : ∆ and |∆| ⊢ A wellTyped <strong>the</strong>n θA = A ′ and |∆ ′ | ⊢ A wellTyped<br />

Below we def<strong>in</strong>e <strong>the</strong> mode/term<strong>in</strong>ation checker for Twelf. We assume that we<br />

are given a semantic doma<strong>in</strong> S and a sequent calculus ∆; Φ ⊢ F which is sound with<br />

respect to S. The mode/term<strong>in</strong>ation checker is specified judgmentally below, and is<br />

<strong>in</strong>spired by <strong>the</strong> mode and term<strong>in</strong>ation check<strong>in</strong>g algorithms sketched <strong>in</strong> [RP96, Roh96]<br />

and <strong>the</strong> reduces check<strong>in</strong>g algorithm specified <strong>in</strong> [Pie05]. In o<strong>the</strong>r words, it is essen-<br />

tially a syntactic specification for <strong>the</strong> comb<strong>in</strong>ation <strong>of</strong> <strong>the</strong> mode, term<strong>in</strong>ation and<br />

reduces checkers implemented <strong>in</strong> Twelf, which has been used to formally verify <strong>the</strong><br />

correctness <strong>of</strong> all <strong>the</strong> pro<strong>of</strong>s <strong>in</strong> Chapter 2 (where SS is def<strong>in</strong>ed <strong>in</strong> Example 5.2.42<br />

and ∆; Ψ ⊢ is <strong>the</strong> sequent calculus specified <strong>in</strong> [Pie05]) and <strong>in</strong> Chapter 4 (where<br />

SS is a generalization <strong>of</strong> <strong>the</strong> one def<strong>in</strong>ed <strong>in</strong> Example 5.2.41 and <strong>the</strong> formal spec-<br />

ification <strong>of</strong> ∆; F ⊢ is left to future work); see http://www.twelf.org/slr and<br />

http://www.twelf.org/lpo for <strong>the</strong> source files. We do not require that <strong>the</strong> notion<br />

<strong>of</strong> provability for ∆; Φ ⊢ F be decidable, but if it is, <strong>the</strong>n so is mode/term<strong>in</strong>ation<br />

check<strong>in</strong>g.<br />

The judgment ⊢ Σ ′ tc a should be read as say<strong>in</strong>g “a is a mode/term<strong>in</strong>ation-<br />

checked logic program <strong>in</strong> <strong>the</strong> signature Σ ′ ” (where Σ ′ should be thought <strong>of</strong> as a<br />

subset <strong>of</strong> <strong>the</strong> given LF signature Σ). Similarly, ∆ ⊢ ∆ ′ tc a should be read as “a is a<br />

mode/term<strong>in</strong>ation-checked logic program <strong>in</strong> <strong>the</strong> context ∆ ′ (which should be thought<br />

<strong>of</strong> as a subset <strong>of</strong> ∆)”; η ⊢ η ′ tc a is <strong>the</strong> lift<strong>in</strong>g <strong>of</strong> ∆ ⊢ ∆ ′ tc a to abstract substitutions.<br />

149


All <strong>the</strong>se judgments can be <strong>in</strong>terpreted functionally by <strong>in</strong>duction/recursion on <strong>the</strong><br />

structure <strong>of</strong> Σ ′ , ∆ ′ and η ′ , respectively. In general, a logic-program a might call<br />

ano<strong>the</strong>r logic-program b. If a and b are mutually recursive, <strong>the</strong>n b ≡ a must hold, <strong>in</strong><br />

which case <strong>the</strong> aforementioned judgments will mode/term<strong>in</strong>ation-check b explicitly.<br />

If a can call b, but not vice-versa, <strong>the</strong>n b ⊏ a must hold, <strong>in</strong> which case b will only be<br />

mode/term<strong>in</strong>ation-checked when we consider <strong>the</strong> well-behavedness <strong>of</strong> <strong>the</strong> program<br />

clauses <strong>of</strong> a that call b.<br />

η ⊢ · tc a<br />

⊢ · tc a<br />

∆ ⊢ · tc a<br />

⊢ Σ ′ tc a<br />

⊢ Σ ′ , b:K tc a<br />

hd(A) ≡ a ⊢ Σ ′ tc a<br />

⊢ Σ ′ , c:A tc a<br />

hd(A) ≡ a ⊢ Σ ′ tc a · ⊢ A okD ·<br />

∆ ⊢ ∆ ′ tc a<br />

⊢ Σ ′ , c:A tc a<br />

∆ ⊢ ∆ ′ , ∃x:A tc a<br />

hd(A) ≡ a ∆ ⊢ ∆ ′ tc a<br />

∆ ⊢ ∆ ′ , ∀x:A tc a<br />

hd(A) ≡ a ∆ ⊢ ∆ ′ tc a ∆ ⊢ A okD ·<br />

η ⊢ η ′ tc a<br />

η ⊢ η ′ , ∃ ? x:A tc a<br />

∆ ⊢ ∆ ′ , ∀x:A tc a<br />

η ⊢ η ′ tc a<br />

η ⊢ η ′ , ∃ g x:A tc a<br />

hd(A) ≡ a η ⊢ η ′ tc a η ⊢ A okD ·<br />

η ⊢ η ′ , ∀x:A tc a<br />

hd(A) ≡ a η ⊢ η ′ tc a<br />

η ⊢ η ′ , ∀x:A tc a<br />

The judgment ∆ ⊢ A okG can be thought <strong>of</strong> as say<strong>in</strong>g “perform<strong>in</strong>g search on<br />

<strong>the</strong> mode-compatible query ∆ ⊢ ? : A is guaranteed to term<strong>in</strong>ate.” Similarly, <strong>the</strong><br />

judgment η ⊢ A okG can be thought <strong>of</strong> as say<strong>in</strong>g that, for every θ approximated by<br />

η, query<strong>in</strong>g <strong>the</strong> goal formula θA will term<strong>in</strong>ate. Both judgments can be <strong>in</strong>terpreted<br />

functionally by <strong>in</strong>duction/recursion on A.<br />

150


|∆| ⊢ A : type ∆, ∀x:A ⊢ B okG<br />

∆ ⊢ Πx:A.B okG<br />

|∆| ⊢ a M : type ⊢ Σ tc a ∆ ⊢ ∆ tc a ∆ ⊢ <strong>in</strong>puts a (M) g<br />

∆ ⊢ a M okG<br />

|η| ⊢ A : type η, ∀x:A ⊢ B okG<br />

η ⊢ Πx:A.B okG<br />

|η| ⊢ a M : type ⊢ Σ tc a η ⊢ η tc a η ⊢ <strong>in</strong>puts a (M) g<br />

η ⊢ a M okG<br />

The judgment ∆ ⊢ A okD A can be thought <strong>of</strong> as say<strong>in</strong>g that <strong>the</strong> program<br />

declaration A, when used to solve any goal whose head matches A, will term<strong>in</strong>ate, as<br />

will solv<strong>in</strong>g <strong>the</strong> left-over subgoals A. This judgment is lifted to abstract substitutions<br />

<strong>in</strong> <strong>the</strong> usual way (i.e. by replac<strong>in</strong>g ∆ with η). Both judgments can be <strong>in</strong>terpreted<br />

functionally by <strong>in</strong>duction/recursion on A.<br />

|∆| ⊢ A : type ∆, ∃x:A ⊢ B okD A x ∈ F V (B)<br />

∆ ⊢ Πx:A.B okD A<br />

∆ ⊢ B okD A :: A<br />

∆ ⊢ A → B okD A<br />

∆ ⊢ <strong>in</strong>puts a (M) g=⇒ η η ⊢ <strong>in</strong>puts a (M) g η; · ⊢ A okSGs a M<br />

∆ ⊢ a M okD A<br />

|η| ⊢ A : type η, ∃ ? x:A ⊢ B okD A x ∈ F V (B)<br />

η ⊢ Πx:A.B okD A<br />

η ⊢ <strong>in</strong>puts a (M) g=⇒ η ′<br />

η ⊢ B okD A :: A<br />

η ⊢ A → B okD A<br />

η ′ ⊢ <strong>in</strong>puts a (M) g η ′ ; · ⊢ A okSGs a M<br />

η ⊢ a M okD A<br />

The judgment ∆; Φ ⊢ A okSGs a M means that, if <strong>the</strong> reduction <strong>in</strong>variants Φ are<br />

valid <strong>in</strong> ∆, <strong>the</strong>n solv<strong>in</strong>g all <strong>of</strong> <strong>the</strong> subgoals <strong>of</strong> a M <strong>in</strong> A one-at-a-time, <strong>in</strong> order, will<br />

term<strong>in</strong>ate. This is also lifted to generalized substitutions <strong>in</strong> <strong>the</strong> usual way. These<br />

151


judgments can be <strong>in</strong>terpreted functionally by <strong>in</strong>duction/recursion on A.<br />

|∆| ⊢ a M : type ∆ ⊢ outputs a (M) g ∆; Φ ⊢ redInva M<br />

η; Φ ⊢ · okSGs a M<br />

|∆| ⊢ A : type ∆; Φ ⊢ A okSG a M =⇒ 〈η; F 〉 η; Φ, F ⊢ A okSGs a M<br />

∆; Φ ⊢ A :: A okSGs a M<br />

|η| ⊢ a M : type η ⊢ outputs a (M) g ∆η; Φ ⊢ redInva M<br />

η; Φ ⊢ · okSGs a M<br />

|∆| ⊢ A : type η; Φ ⊢ A okSG a M =⇒ 〈η ′ ; F 〉 η ′ ; Φ, F ⊢ A okSGs a M<br />

η; Φ ⊢ A :: A okSGs a M<br />

The judgment ∆; Φ ⊢ A okSG a M =⇒ 〈Φ; F 〉 means that, if Φ is assumed to<br />

be valid <strong>in</strong> ∆, <strong>the</strong>n A can be shown to be an “ok” goal which is smaller than a M,<br />

and moreover, when A has been successfully solved, <strong>the</strong> output-substitution will be<br />

approximated by η, and <strong>the</strong> <strong>in</strong>variant F will be valid <strong>in</strong> <strong>the</strong> output-context. This<br />

judgment is lifted to η <strong>in</strong> usual way. Both judgments can be <strong>in</strong>terpreted functionally<br />

152


y <strong>in</strong>duction/recursion on A.<br />

hd(A) ≡ a |∆| ⊢ A : type ∆, ∀x:A ⊢ A okD ·<br />

∆, ∀x:A; Φ ⊢ B okSG a M =⇒ 〈η, ∀x:A; F 〉<br />

∆; Φ ⊢ Πx:A.B okSG a M =⇒ 〈η; ∇x:A.F 〉<br />

hd(A) ≡ a |∆| ⊢ A : type ∆, ∀x:A; Φ ⊢ B okSG a M =⇒ 〈η, ∀x:A; F 〉<br />

∆; Φ ⊢ Πx:A.B okSG a M =⇒ 〈η; ∇x:A.F 〉<br />

b ≡ a tbb ≥ tba ∆ ⊢ <strong>in</strong>puts b (N) g<br />

∆; Φ ⊢ measureb N ≺ measurea M ∆ ⊢ outputs b (N) g=⇒ η<br />

∆; Φ ⊢ b N okSG a M =⇒ 〈η; redInvb N〉<br />

b ≡ a tbb < tba ∆ ⊢ <strong>in</strong>puts b (N) g<br />

∆; Φ ⊢ measureb N measurea M ∆ ⊢ outputs b (N) g=⇒ η<br />

∆; Φ ⊢ b N okSG a M =⇒ 〈η; redInvb N〉<br />

b ⊏ a ∆ ⊢ <strong>in</strong>puts b (N) g ⊢ Σ tc b ∆ ⊢ ∆ tc b ∆ ⊢ outputs b (N) g=⇒ η<br />

∆; Φ ⊢ b N okSG a M =⇒ 〈η; redInvb N〉<br />

153


hd(A) ≡ a |η| ⊢ A : type η, ∀x:A ⊢ A okD ·<br />

η, ∀x:A; Φ ⊢ B okSG a M =⇒ 〈η ′ , ∀x:A; F 〉<br />

η; Φ ⊢ Πx:A.B okSG a M =⇒ 〈η ′ ; ∇x:A.F 〉<br />

hd(A) ≡ a |η| ⊢ A : type η, ∀x:A; Φ ⊢ B okSG a M =⇒ 〈η ′ , ∀x:A; F 〉<br />

η; Φ ⊢ Πx:A.B okSG a M =⇒ 〈η ′ ; ∇x:A.F 〉<br />

b ≡ a tbb ≥ tba η ⊢ <strong>in</strong>puts b (N) g ∆η; Φ ⊢ measureb N ≺ measurea M<br />

η ⊢ outputs b (M) g=⇒ η ′ η ′ ⊢ redInvb N g<br />

η; Φ ⊢ b N okSG a M =⇒ 〈η ′ ; redInvb N〉<br />

b ≡ a tbb < tba η ⊢ <strong>in</strong>puts b (N) g ∆η; Φ ⊢ measureb N measurea M<br />

η ⊢ outputs b (M) g=⇒ η ′ η ′ ⊢ redInvb N g<br />

η; Φ ⊢ b N okSG a M =⇒ 〈η ′ ; redInvb N〉<br />

b ⊏ a η ⊢ <strong>in</strong>puts b (N) g ⊢ Σ tc b η ⊢ η tc b<br />

η ⊢ outputs b (M) g=⇒ η ′ η ′ ⊢ redInvb N g<br />

η; Φ ⊢ b N okSG a M =⇒ 〈η ′ ; redInvb N〉<br />

F<strong>in</strong>ally, we use <strong>the</strong> judgment ∆ ⊢ A solved to say that <strong>the</strong> output <strong>of</strong> solv<strong>in</strong>g a<br />

query was successful.<br />

∆, ∀x:A ⊢ B solved<br />

∆ ⊢ Πx:A.B solved<br />

|∆| ⊢ a M : type ∆ ⊢ M g ∆ ⊢ redInva M valid<br />

∆ ⊢ a M solved<br />

Lemma 5.2.56 (OK Goals are Well Typed) If ∆ ⊢ A okG <strong>the</strong>n |∆| ⊢ A : type<br />

Pro<strong>of</strong>: By a straightforward <strong>in</strong>duction over <strong>the</strong> given derivation. <br />

Lemma 5.2.57 (Substitutions Preserve Well-Modedness)<br />

1. If D : (∆0 ⊢ a tc ∆0, ∆1) and ∆ ′ 0 ⊢ θ0 : ∆0 and ∆ ′ 0, ∆ ′ 1 ⊢ θ0, θ1 : ∆0, ∆1 <strong>the</strong>n<br />

∆ ′ 0 ⊢ a tc ∆ ′ 0, ∆ ′ 1<br />

154


2. If D : (∆ ⊢ A okD B) and ∆ ′ ⊢ θ : ∆ and θA = A ′ and θB = B ′ <strong>the</strong>n<br />

∆ ′ ⊢ A ′ okD B ′<br />

3. If D : (η; Φ ⊢ A okSGs a M) and η ′ ⊢ θ : η and |η| ⊢ Φ wellTyped and θΦ = Φ ′<br />

and θA = A ′ and θ(a M) = a M ′ <strong>the</strong>n η ′ ; Φ ′ ⊢ A ′ okSGs a M ′<br />

4. If D : (η0; Φ ⊢ A okSG a M =⇒ 〈η1; F 〉) and η ′ 0 ⊢ θ : η0 and |η0| ⊢ Φ wellTyped<br />

and θΦ = Φ ′ and θA = A ′ and θ(a M) = a M ′ and θP = P ′ <strong>the</strong>n <strong>the</strong>re exists<br />

η ′ 1 s.t. η ′ 0; Φ ′ ⊢ A ′ okSG a M ′ =⇒ 〈η ′ 1; P ′ 〉 and η ′ 1 ⊢ θ : η1<br />

5. If D : (η ⊢ A okD B) and η ′ ⊢ θ : η and θA = A ′ and θB = B ′ <strong>the</strong>n<br />

η ′ ⊢ A ′ okD B ′<br />

6. If D : (η0 ⊢ a tc η0, η1) and η ′ 0, η ′ 1 ⊢ θ0, θ1 : η0, η1 and η ′ 0 ⊢ θ0 : η0 <strong>the</strong>n<br />

η ′ 0 ⊢ a tc η ′ 0, η ′ 1<br />

7. If D : (η0; Φ ⊢ A okSG a M =⇒ 〈η1; F 〉) and ∆ ⊢ θ : η0 and |η0| ⊢ Φ wellTyped<br />

and θΦ = Φ ′ and θA = A ′ and θ(a M) = a M ′ and θF = F ′ <strong>the</strong>n <strong>the</strong>re exists<br />

η ′ 1 s.t. ∆; Φ ′ ⊢ A ′ okSG a M ′ =⇒ 〈η ′ 1; P ′ 〉 and η ′ 1 ⊢ θ : η1<br />

8. If D : (η; Φ ⊢ A okSGs a M) and ∆ ⊢ θ : η and |η| ⊢ Φ wellTyped and θΦ = Φ ′<br />

and θA = A ′ and θ(a M) = a M ′ <strong>the</strong>n ∆; Φ ′ ⊢ A ′ okSGs a M ′<br />

9. If D : (η0 ⊢ a tc η0, η1) and ∆0, ∆1 ⊢ θ0, θ1 : η0, η1 and ∆0 ⊢ θ0 : η0 <strong>the</strong>n<br />

∆0 ⊢ a tc ∆0, ∆1<br />

Pro<strong>of</strong>: By mutual <strong>in</strong>duction on D; most <strong>of</strong> <strong>the</strong> work is done by Lemma 5.2.38,<br />

Lemma 5.2.20 and Def<strong>in</strong>ition 5.2.47. <br />

Lemma 5.2.58 (Weaken<strong>in</strong>g for Mode Check<strong>in</strong>g)<br />

1. If ∆ ⊢ ∆ ′ tc a and |∆| ⊢ B : type <strong>the</strong>n:<br />

155


(a) ∆, ∃x:B ⊢ ∆ ′ tc a<br />

(b) if hd(B) ≡ a <strong>the</strong>n ∆, ∀x:B ⊢ ∆ ′ tc a<br />

2. If ∆0, ∆1 ⊢ A okD A and |∆0| ⊢ B : type <strong>the</strong>n:<br />

(a) ∆0, ∃x:B, ∆1 ⊢ A okD A<br />

(b) if hd(B) ≡ hd(A) <strong>the</strong>n ∆0, ∀x:B, ∆1 ⊢ A okD A<br />

3. If η0, η1; Φ ⊢ A okSGs a M and |η0| ⊢ B : type <strong>the</strong>n:<br />

(a) η0, ∃ ? x:B, η1; Φ ⊢ A okSGs a M<br />

(b) if hd(B) ≡ hd(A) <strong>the</strong>n η0, ∀x:B, η1; Φ ⊢ A okSGs a M<br />

4. If η0, η1; Φ ⊢ A okSG a M =⇒ 〈η ′ ; F 〉 and |η0| ⊢ B : type <strong>the</strong>n:<br />

(a) η ′ = η ′ 0, η ′ 1 and η0, ∃ ? x:B, η1; Φ ⊢ A okSG a N =⇒ 〈η ′ 0, ∀x:B, η ′ 1; F 〉<br />

(b) if hd(B) ≡ hd(A) <strong>the</strong>n η ′ = η ′ 0, η ′ 1 and η0, ∀x:B, η1; Φ ⊢ A okSG a N =⇒<br />

〈η ′ 0, ∀x:B, η ′ 1; F 〉<br />

5. If η0, η1 ⊢ A okD A and |η0| ⊢ B : type <strong>the</strong>n:<br />

(a) η0, ∃ ? x:B, η1 ⊢ A okD A<br />

(b) if hd(B) ≡ hd(A) <strong>the</strong>n η0, ∀x:B, η1 ⊢ A okD A<br />

6. If η0, η1 ⊢ η ′ tc a and |η0| ⊢ B : type <strong>the</strong>n:<br />

(a) η0, ∃ ? x:B, η1 ⊢ η ′ tc a<br />

(b) if hd(B) ≡ a <strong>the</strong>n η0, ∀x:B, η1 ⊢ η ′ tc a<br />

Pro<strong>of</strong>: By simultaneous <strong>in</strong>duction, us<strong>in</strong>g most <strong>of</strong> <strong>the</strong> weaken<strong>in</strong>g lemmas proven thus<br />

far and <strong>the</strong> def<strong>in</strong>ition <strong>of</strong> a sound sequent calculus. <br />

156


Lemma 5.2.59 (Term<strong>in</strong>ation Check<strong>in</strong>g Mutually Recursive Types)<br />

If a ≡ b <strong>the</strong>n:<br />

1. if ⊢ Σ tc a <strong>the</strong>n ⊢ Σ tc b<br />

2. if ∆ ⊢ ∆ ′ tc a <strong>the</strong>n ∆ ⊢ ∆ ′ tc a<br />

3. if η ⊢ η ′ tc a <strong>the</strong>n η ⊢ η ′ tc a<br />

Pro<strong>of</strong>: Each case is by straightforward <strong>in</strong>duction on <strong>the</strong> given derivation. <br />

We are almost ready to beg<strong>in</strong> <strong>the</strong> pro<strong>of</strong> <strong>of</strong> <strong>the</strong> soundness <strong>of</strong> <strong>the</strong> term<strong>in</strong>ation/mode<br />

checker. The statement <strong>of</strong> <strong>the</strong> <strong>the</strong>orem will along <strong>the</strong> l<strong>in</strong>es <strong>of</strong> “for all term<strong>in</strong>a-<br />

tion checked queries ∆ ⊢ ? : A, ei<strong>the</strong>r <strong>the</strong>re exists θ, ∆ ′ , M and A ′ such that<br />

fillTerm(∆ ⊢ ? : A)<br />

θ<br />

=⇒ 〈∆ ′ ; M; A ′ 〉 or no such θ, ∆ ′ , M and A ′ exist.” Al-<br />

though this statement is nontrivial when <strong>in</strong>terpreted <strong>in</strong>tuitionistically (as has been<br />

our convention throughout this dissertation), <strong>in</strong>terpreted classically it is a direct con-<br />

sequence <strong>of</strong> <strong>the</strong> law <strong>of</strong> excluded middle. However, we f<strong>in</strong>d it advantageous for <strong>the</strong><br />

<strong>the</strong>orem to be phrased <strong>in</strong> such a way that it is nontrivial when viewed ei<strong>the</strong>r way.<br />

To this end, we def<strong>in</strong>e <strong>the</strong> judgment failTerm (along with <strong>the</strong> helper-judgments<br />

failHeads and failSp<strong>in</strong>e) that characterize when a query is known to fail.<br />

157


failHeadsΣ;∆〈∆ ⊢ ? : a M〉<br />

failTerm(∆ ⊢ ? : a M)<br />

failHeadsΣ ′ ;∆ ′〈∆ ⊢ ? : a M〉<br />

failHeadsΣ ′ ;∆ ′ ,∃x:A〈∆ ⊢ ? : a M〉<br />

failTerm(∆, ∀x:A ⊢ ? : B)<br />

failTerm(∆ ⊢ ? : Πx:A.B)<br />

hd(A) = a failHeadsΣ ′ ;∆ ′〈∆ ⊢ ? : a N〉<br />

failHeadsΣ ′ ;∆ ′ ,∀x:A〈∆ ⊢ ? : a N〉<br />

hd(A) = a failSp<strong>in</strong>e(∆; A ⊢ ? : a N) failHeadsΣ ′ ;∆ ′〈∆ ⊢ ? : a N〉<br />

failHeadsΣ ′ ;∆ ′ ,∀x:A〈∆ ⊢ ? : a N〉<br />

hd(A) = a fillSp<strong>in</strong>e(∆; A ⊢ ? : a N)<br />

θ<br />

=⇒ 〈∆ ′′ ; A ′ ; M; a N ′ 〉 θ(a N) = a N ′′<br />

unify(∆ ′′ ⊢ outputsa (N ′ ) • = outputsa (N ′′ )) =⇒ fail failHeadsΣ ′ ;∆ ′〈∆ ⊢ ? : a N〉<br />

failHeadsΣ ′ ;∆ ′〈∆ ⊢ ? : a M〉<br />

failHeadsΣ ′ ,a:K;·〈∆ ⊢ ? : a M〉<br />

failHeadsΣ ′ ;∆ ′ ,∀x:A〈∆ ⊢ ? : a N〉<br />

hd(A) = a failHeadsΣ ′ ;·〈∆ ⊢ ? : a N〉<br />

failHeadsΣ ′ ,c:A;·〈∆ ⊢ ? : a N〉<br />

hd(A) = a failSp<strong>in</strong>e(∆; A ⊢ ? : a N) failHeadsΣ ′ ;·〈∆ ⊢ ? : a N〉<br />

failHeadsΣ ′ ,c:A;·〈∆ ⊢ ? : a N〉<br />

hd(A) = a fillSp<strong>in</strong>e(∆; A ⊢ ? : a N)<br />

θ<br />

=⇒ 〈∆ ′′ ; A ′ ; M; a N ′ 〉 θ(a N) = a N ′′<br />

unify(∆ ′′ ⊢ outputs a (N ′ ) • = outputs a (N ′′ )) =⇒ fail failHeadsΣ ′ ;·〈∆ ⊢ ? : a N〉<br />

failHeads·;·〈∆ ⊢ ? : a N〉<br />

failHeadsΣ ′ ,c:A;·〈∆ ⊢ ? : a N〉<br />

unify(∆ ⊢ <strong>in</strong>puts a (M) • = <strong>in</strong>puts a (N)) =⇒ fail<br />

failSp<strong>in</strong>e(∆; a M ⊢ ? : a N)<br />

x ∈ F V (B) failSp<strong>in</strong>e(∆, ∃x:A; B ⊢ ? : a N)<br />

failSp<strong>in</strong>e(∆; Πx:A.B ⊢ ? : a N)<br />

θ<br />

fillSp<strong>in</strong>e(∆; B ⊢ ? : a N) =⇒ 〈∆ ′ ; B; M; a N ′ 〉 θA = A ′ failSp<strong>in</strong>e(∆ ′ ; A ′ ⊢ ? : a N ′ )<br />

failSp<strong>in</strong>e(∆; A → B ⊢ ? : a N)<br />

In <strong>the</strong> follow<strong>in</strong>g lemma, note that false is <strong>the</strong> judgment with no <strong>in</strong>ference rules.<br />

Lemma 5.2.60 (Soundness <strong>of</strong> Failure)<br />

1. If failTerm(∆ ⊢ ? : A) and fillTerm(∆ ⊢ ? : A)<br />

158<br />

θ<br />

=⇒ 〈∆ ′ ; M; A ′ 〉 <strong>the</strong>n


false.<br />

2. If failHeads∆0;Σ0〈∆0, ∆1 ⊢ ? : a N〉 and Σ = Σ0, Σ1 and fillHead(∆0; Σ0; a N) =⇒<br />

h:A and fillTerm(∆0, ∆1 ⊢ ? : a N)<br />

θ<br />

=⇒ 〈∆ ′ ; h M; a N ′ 〉 <strong>the</strong>n false.<br />

3. If failSp<strong>in</strong>e(∆; A ⊢ ? : a N) and fillSp<strong>in</strong>e(∆; A ⊢ ? : a N)<br />

<strong>the</strong>n false.<br />

θ<br />

=⇒ 〈∆ ′ ; A ′ ; M; a N ′ 〉<br />

Pro<strong>of</strong>: By a straightforward mutual <strong>in</strong>duction on <strong>the</strong> given derivation <strong>of</strong> failure. <br />

A query is term<strong>in</strong>at<strong>in</strong>g if it ei<strong>the</strong>r succeeds (i.e. fillTerm is <strong>in</strong>habited) or can<br />

be shown to exhaustively fail (i.e. failTerm is <strong>in</strong>habited); this is formalized <strong>in</strong><br />

<strong>the</strong> judgments below. Because our term<strong>in</strong>ation pro<strong>of</strong> will rely on successful queries<br />

satisfy<strong>in</strong>g certa<strong>in</strong> <strong>in</strong>variants, we <strong>in</strong>clude <strong>the</strong>se <strong>in</strong>variants <strong>in</strong> <strong>the</strong> def<strong>in</strong>ition <strong>the</strong> judg-<br />

ments. The judgment (∆ ⊢ ? : A) term<strong>in</strong>atesSatisfy<strong>in</strong>g 〈η; F 〉 means that <strong>the</strong><br />

query ∆ ⊢ ? : A term<strong>in</strong>ates, and, moreover, if it term<strong>in</strong>ates successfully, <strong>the</strong>n F<br />

is well formed <strong>in</strong> <strong>the</strong> output context and η approximates <strong>the</strong> output substitution.<br />

The judgment (∆; A ⊢ ? : a M) ; A term<strong>in</strong>ates means that <strong>the</strong> process <strong>of</strong> solv<strong>in</strong>g<br />

<strong>the</strong> sp<strong>in</strong>e-query (∆; A ⊢ ? : a M) along with <strong>the</strong> left-over subgoals <strong>in</strong> A termi-<br />

nates. The judgment (∆ ⊢ ? : a N) term<strong>in</strong>atesUs<strong>in</strong>g 〈∆ ′ ; Σ ′ 〉 means that <strong>the</strong><br />

query ∆ ⊢ ? : a N term<strong>in</strong>ates when potential heads are restricted to ∆ ′ and Σ ′ .<br />

159


fillTerm(∆ ⊢ ? : A)<br />

θ<br />

=⇒ 〈∆ ′ ; M; A ′ 〉 ∆ ′ ⊢ A ′ solved<br />

(∆ ⊢ ? : A) term<strong>in</strong>ates<br />

failHeads∆ ′ ;Σ ′〈∆ ⊢ ? : a N〉<br />

(∆ ⊢ ? : a N) term<strong>in</strong>atesUs<strong>in</strong>g 〈∆ ′ ; Σ ′ 〉<br />

fillTerm(∆ ⊢ ? : a N)<br />

fillTerm(∆ ⊢ ? : A)<br />

failTerm(∆ ⊢ ? : A)<br />

(∆ ⊢ ? : A) term<strong>in</strong>ates<br />

θ<br />

=⇒ 〈∆ ′′ ; M; a N ′ 〉 ∆ ′′ ⊢ a N ′ solved<br />

(∆ ⊢ ? : a N) term<strong>in</strong>atesUs<strong>in</strong>g 〈∆ ′ ; Σ ′ 〉<br />

θ<br />

=⇒ 〈∆ ′ ; M; A ′ 〉 ∆ ′ ⊢ A ′ solved ∆ ′ ⊢ θ : η<br />

∆η = ∆ θF = F ′ |∆ ′ | ⊢ F ′ wellTyped ∆ ′ ⊢ F ′ g ∆ ′ ⊢ F ′ valid<br />

(∆ ⊢ ? : A) term<strong>in</strong>atesSatisfy<strong>in</strong>g 〈η; F 〉<br />

failTerm(∆ ⊢ ? : A)<br />

(∆ ⊢ ? : A) term<strong>in</strong>atesSatisfy<strong>in</strong>g 〈η; F 〉<br />

fillSp<strong>in</strong>e(∆; A ⊢ ? : a N)<br />

θ<br />

=⇒ 〈∆ ′ ; A ′ ; M; a N ′ 〉 θA = A ′<br />

|∆| ⊢ Φ wellTyped ∆ ⊢ Φ g ∆ ⊢ Φ valid ∆ ′ ; Φ ⊢ A ′ okSGs a N ′<br />

(∆; A ⊢ ? : a N) ; A term<strong>in</strong>ates<br />

failSp<strong>in</strong>e(∆; A ⊢ ? : a N)<br />

(∆; A ⊢ ? : a N) ; A term<strong>in</strong>ates<br />

We are f<strong>in</strong>ally ready to beg<strong>in</strong> our pro<strong>of</strong> <strong>of</strong> term<strong>in</strong>ation. Most <strong>of</strong> <strong>the</strong> reason<strong>in</strong>g will<br />

be by <strong>in</strong>duction on <strong>the</strong> structure <strong>of</strong> various derivations, as usual. However, we will<br />

also <strong>in</strong>duct on term<strong>in</strong>ation vectors V = size∆(A) under <strong>the</strong> order<strong>in</strong>g


3. If ∆ ⊢ A okG and size∆(A) = V <strong>the</strong>n V =v V .<br />

Pro<strong>of</strong>: Note <strong>the</strong> dist<strong>in</strong>ction between syntactic equality, =, and <strong>the</strong> judgmentally<br />

def<strong>in</strong>ed notion <strong>of</strong> equality =v. 1 is by a straightforward <strong>in</strong>duction on <strong>the</strong> given<br />

derivation, us<strong>in</strong>g Lemma 5.2.45. 2 is by straightforward <strong>in</strong>duction on A. 3 is a direct<br />

corollary to 1 and 2. <br />

We are now ready to prove <strong>the</strong> soundness <strong>of</strong> <strong>the</strong> mode/term<strong>in</strong>ation checker. If<br />

this pro<strong>of</strong> were to be realized by a function, <strong>the</strong> function could be rightly viewed as<br />

an <strong>in</strong>terpretor for logic programs.<br />

Theorem 5.2.62 (Soundness <strong>of</strong> The Mode/Term<strong>in</strong>ation Checker)<br />

1. If D : (∆ ⊢ A okG) and size∆(A) = V and V =v V <strong>the</strong>n (∆ ⊢ ? :<br />

A) term<strong>in</strong>ates<br />

2. If D : (∆0, ∆1 ⊢ ∆0 tc a) and E : ( ⊢ Σ0 tc a) and Σ = Σ0, Σ1 and F :<br />

(∆0, ∆1 ⊢ a N okG) and V = size∆0,∆1(a N) and V =v V <strong>the</strong>n (∆0, ∆1 ⊢ ? :<br />

a N) term<strong>in</strong>atesUs<strong>in</strong>g 〈∆0; Σ0〉<br />

3. If D : (∆ ⊢ A okD A) and |∆| ⊢ A : type and |∆| ⊢ A wellTyped and E : (∆ ⊢<br />

a N okG) and hd(A) = a and size∆(a N) = V and V =v V <strong>the</strong>n (∆; A ⊢ ? :<br />

a N) ; A term<strong>in</strong>ates<br />

4. If D : (∆; Φ ⊢ A okSG a M =⇒ 〈η; F 〉) and |∆| ⊢ A : type and |∆| ⊢ Φ wellTyped<br />

and ∆ ⊢ Φ g and ∆ ⊢ Φ valid and E : ∆ ⊢ a M okG and size∆(a N) = V<br />

and V =v V <strong>the</strong>n (∆ ⊢ ? : A) term<strong>in</strong>atesSatisfy<strong>in</strong>g 〈η; F 〉<br />

Pro<strong>of</strong>: By mutual <strong>in</strong>duction on a lexicographic order<strong>in</strong>g built up from three under-<br />

ly<strong>in</strong>g order<strong>in</strong>gs: term<strong>in</strong>ation vector ordered by


s s s z ordered structurally 3 , and a simultaneous order<strong>in</strong>g <strong>of</strong> two terms or derivations,<br />

each <strong>of</strong> which is ordered structurally. 1 is ordered by V , followed by s s s z, followed<br />

by <strong>the</strong> simultaneous order<strong>in</strong>g <strong>of</strong> A and A. 2 is ordered by V , followed by s s z, fol-<br />

lowed by <strong>the</strong> simultaneous order<strong>in</strong>g <strong>of</strong> D and E. 3 is ordered by V , followed by s z,<br />

followed by <strong>the</strong> simultaneous order<strong>in</strong>g <strong>of</strong> D and D. 4 is ordered by V , followed by<br />

z followed by <strong>the</strong> simultaneous order<strong>in</strong>g <strong>of</strong> D and D. We show all <strong>of</strong> <strong>the</strong> cases for<br />

1 and 3, and some representative cases <strong>of</strong> 4. 2 is a tedious exercise <strong>in</strong> case analysis,<br />

but is o<strong>the</strong>rwise mostly straightforward; it uses IH 3, Lemma 5.2.7, Def<strong>in</strong>ition 5.2.47,<br />

Proposition 5.2.12, Lemma 5.2.48, Lemma 5.2.20 and Lemma 5.2.53.<br />

1.<br />

Case:<br />

D =<br />

D0<br />

|∆| ⊢ a M : type<br />

D1<br />

⊢ Σ tc a<br />

D2<br />

∆ ⊢ ∆ tc a<br />

∆ ⊢ a M okG<br />

D3<br />

∆ ⊢ <strong>in</strong>puts a (M) g<br />

size∆(a M) = V and V =v V given<br />

(∆ ⊢ ? : a M) term<strong>in</strong>atesUs<strong>in</strong>g 〈·; ·〉 by IH 2 on V, s s z, D2 and D1<br />

ei<strong>the</strong>r failHeads·;·〈∆ ⊢ ? : a M〉<br />

or (fillTerm(∆ ⊢ ? : a M)<br />

θ<br />

=⇒ 〈∆ ′′ ; M; a N ′ 〉 and ∆ ′′ ⊢ a M ′ solved)<br />

by <strong>in</strong>version on term<strong>in</strong>atesUs<strong>in</strong>g<br />

assume failHeads·;·〈∆ ⊢ ? : a M〉 Case 1<br />

(∆ ⊢ ? : a M) term<strong>in</strong>ates by rule<br />

assume fillTerm(∆ ⊢ ? : a M)<br />

θ<br />

=⇒ 〈∆ ′′ ; M; a N ′ 〉 and ∆ ′′ ⊢ a M ′ solved<br />

Case 2<br />

(∆ ⊢ ? : a M) term<strong>in</strong>ates by rule<br />

3 This is equivalent to us<strong>in</strong>g <strong>the</strong> f<strong>in</strong>ite ord<strong>in</strong>al 4.<br />

162


Case:<br />

D =<br />

D0<br />

|∆| ⊢ A : type<br />

∆ ⊢ Πx:A.B okG<br />

D1<br />

∆, ∀x:A ⊢ B okG<br />

size∆(Πx:A.B) = V and V =v V given<br />

V = size∆,∀x:a(B) by <strong>in</strong>version on size<br />

size∆,∀x:A(B)


3.<br />

Case:<br />

D =<br />

D0<br />

∆ ⊢ B okD A :: A<br />

∆ ⊢ A → B okD A<br />

|∆| ⊢ A → B : type and |∆| ⊢ A wellTyped and ∆ ⊢ a N okG<br />

and hd(A → B) = a and size∆(a N) = V and V =v V given<br />

|∆| ⊢ A : type<br />

and |∆|, x:A ⊢ B : type where x#B by <strong>in</strong>version for typ<strong>in</strong>g<br />

|∆| ⊢ B : type by Lemma 5.1.7<br />

|∆| ⊢ A :: A wellTyped by rule<br />

hd(A → B) = hd(B) by <strong>in</strong>version on hd<br />

(∆; B ⊢ ? : a N) ; (A :: A) term<strong>in</strong>ates by IH 2 on V , s s z, D0 and D0<br />

ei<strong>the</strong>r failSp<strong>in</strong>e(∆; B ⊢ ? : a N)A :: A<br />

or (fillSp<strong>in</strong>e(∆; B ⊢ ? : a N)<br />

θ<br />

=⇒ 〈∆ ′ ; B ′ ; M; a N ′ 〉<br />

and θ(A :: A) = A ′ :: A ′ and |∆ ′ | ⊢ Φ wellTyped and ∆ ′ ⊢ Φ g<br />

and ∆ ′ ⊢ Φ valid and ∆ ′ ; Φ ⊢ A ′ :: A ′ okSGs a N ′ )<br />

by <strong>in</strong>version on term<strong>in</strong>ates<br />

assume failSp<strong>in</strong>e(∆; B ⊢ ? : a N) Case 1<br />

failSp<strong>in</strong>e(∆; A → B ⊢ ? : a N) by rule<br />

(∆; A → B ⊢ ? : a N) ; A term<strong>in</strong>ates by rule<br />

assume fillSp<strong>in</strong>e(∆; B ⊢ ? : a N)<br />

θ<br />

=⇒ 〈∆ ′ ; B ′ ; M; a N ′ 〉<br />

and θ(A :: A) = A ′′ :: A ′ and |∆ ′ | ⊢ Φ wellTyped and ∆ ′ ⊢ Φ g<br />

and ∆ ′ ⊢ Φ valid and ∆ ′ ; Φ ⊢ A ′ :: A ′ okSGs a N ′ Case 2<br />

|∆| ⊢ a N : type and ⊢ Σ tc a<br />

164


and ∆ ⊢ ∆ tc a and ∆ ⊢ <strong>in</strong>puts a (N) g by <strong>in</strong>version on okG<br />

∆ ′ ⊢ θ : ∆ and ⊢ ∆ ′ raised<br />

and θB = B ′ and θ(<strong>in</strong>puts a (N)) = <strong>in</strong>puts a (N ′ )<br />

and |∆|; B ′ ⊢ M : a N ′ by Lemma 5.2.14<br />

θA = A ′ and θA = A ′ by <strong>in</strong>version on gsub app<br />

|∆ ′ | ⊢ A ′ : type and ∆ ′ ; Φ ⊢ A ′ okSG a N ′ =⇒ 〈η; F 〉<br />

and C : η; Φ, F ⊢ A ′ okSGs a N ′ by <strong>in</strong>version on okSGs<br />

|∆ ′ | ⊢ a N ′ : type by Corollary 5.1.13<br />

∆ ′ ⊢ ∆ ′ tc a by Lemma 5.2.57<br />

∆ ′ ⊢ (<strong>in</strong>puts a (N ′ )) g by Lemma 5.2.52<br />

∆ ′ ⊢ a N ′ okG by rule<br />

size∆ ′(a N ′ ) = V ′ and V ′ =v V ′ by Lemma 5.2.61<br />

〈∆; <strong>in</strong>puts a (N)〉 =o 〈∆ ′ ; <strong>in</strong>puts a (N ′ )〉 by Lemma 5.2.45<br />

V =v V ′ by def <strong>of</strong> size and =v<br />

(∆ ′ ⊢ ? : A ′ ) term<strong>in</strong>atesSatisfy<strong>in</strong>g 〈η; F 〉 by IH 4 on V ′ , z, C and C<br />

ei<strong>the</strong>r failTerm(∆ ′ ⊢ ? : A ′ )<br />

or (fillTerm(∆ ′ ⊢ ? : A ′ )<br />

θ ′<br />

=⇒ 〈∆ ′′ ; M ′ ; A ′′ 〉<br />

and ∆ ′′ ⊢ A ′′ solved and ∆ ′′ ⊢ θ ′ : η and ∆η = ∆ ′<br />

and θ ′ F = F ′ and |∆ ′ | ⊢ F ′ wellTyped<br />

and ∆ ′ ⊢ F ′ g and ∆ ′ ⊢ F ′ valid) by <strong>in</strong>version on term<strong>in</strong>atesSatisfy<strong>in</strong>g<br />

assume failTerm(∆ ′ ⊢ ? : A ′ ) Case 2.1<br />

failSp<strong>in</strong>e(∆; A → B ⊢ ? : a N) by rule<br />

(∆; A → B ⊢ ? : a N) ; A term<strong>in</strong>ates by rule<br />

assume fillTerm(∆ ′ ⊢ ? : A ′ )<br />

θ ′<br />

=⇒ 〈∆ ′′ ; M ′ ; A ′′ 〉<br />

and ∆ ′′ ⊢ A ′′ solved and ∆ ′′ ⊢ θ ′ : η and ∆η = ∆ ′<br />

165


Case:<br />

and θ ′ F = F ′ and |∆ ′ | ⊢ F ′ wellTyped<br />

and ∆ ′ ⊢ F ′ g and ∆ ′ ⊢ F ′ valid Case 2.2<br />

∆ ′′ ⊢ θ ′ : ∆ ′ and ⊢ ∆ ′′ raised<br />

and θ ′ A ′ = A ′′ and |∆ ′′ | ⊢ M ′ : A ′′ by Lemma 5.2.14<br />

θ(a N ′ ) = a N ′′ and |∆ ′′ | ⊢ a N ′′ : type by Lemma 5.2.7<br />

|∆ ′ | ⊢ B ′ : type by Lemmas 5.2.7 and 5.2.2<br />

θ ′ B ′ = B ′′ and |∆ ′′ | ⊢ B ′′ : type by Lemma 5.2.7<br />

θM = M ′ and |∆ ′′ |; B ′′ ⊢ M ′ : a N ′′ by Lemma 5.2.7<br />

θ ′ ◦ θ = θ ′′ by Lemma 5.2.9<br />

fillSp<strong>in</strong>e(∆; A → B ⊢ ? : a N) θ′′<br />

=⇒ 〈∆ ′′ ; A ′′ → B ′′ ; M ′ :: M ′ ; a N ′′ 〉 by rule<br />

|∆ ′ | ⊢ A ′ wellTyped by Lemma 5.2.55 (twice)<br />

θ ′ A ′ = A ′′ and |∆ ′′ | ⊢ A ′′ wellTyped by Lemma 5.2.55<br />

θ ′′ A = A ′′ by Lemma 5.2.55<br />

θ ′ Φ = Φ ′ and |∆ ′′ | ⊢ Φ ′ wellTyped by Lemma 5.2.49<br />

∆ ′′ ⊢ Φ ′ g by Lemma 5.2.52<br />

∆ ′′ ⊢ Φ ′ valid by Lemma 5.2.53<br />

∆ ′′ ; Φ ′ ⊢ A ′′ okSGs a N ′′ by Lemma 5.2.57<br />

(∆; A → B ⊢ ? : a N) ; A term<strong>in</strong>ates by rule<br />

D =<br />

D0<br />

|∆| ⊢ A : type<br />

D1<br />

∆, ∃x:A ⊢ B okD A x ∈ F V (B)<br />

∆ ⊢ Πx:A.B okD A<br />

|∆| ⊢ Πx:A.B : type and |∆| ⊢ A wellTyped<br />

and ∆ ⊢ a N okG and hd(Πx:A.B) = a<br />

and size∆(a N) = V and V =v V given<br />

|∆| ⊢ A : type and |∆, ∃x:A| ⊢ B : type by <strong>in</strong>version for typ<strong>in</strong>g<br />

166


|∆|, x:A ⊢ A wellTyped by Lemma 5.2.55<br />

|∆| ⊢ a N : type and ⊢ Σ tc a<br />

and ∆ ⊢ ∆ tc a and ∆ ⊢ <strong>in</strong>puts a (N) g by <strong>in</strong>version on okG<br />

|∆|, x:A ⊢ a N : type by Lemma 5.1.6<br />

∆, ∃x:A ⊢ ∆ tc a by Lemma 5.2.58<br />

∆, ∃x:A ⊢ ∆, ∃x:A tc a by rule<br />

∆, ∃x:A ⊢ <strong>in</strong>puts a (N) g by Lemma 5.2.51<br />

∆, ∃x:A ⊢ a N okG by rule<br />

hd(Πx:A.B) = hd(B) by <strong>in</strong>version on hd<br />

〈∆; <strong>in</strong>puts a (N)〉 =o 〈∆, ∃x:A; <strong>in</strong>puts a (N)〉 by Lemma 5.2.45 (twice)<br />

size∆,∃x:A(a N) = V ′ and V ′ =v V ′ by Lemma 5.2.61<br />

V =v V ′ by def <strong>of</strong> size and =v<br />

(∆, ∃x:A; B ⊢ ? : a N) ; A term<strong>in</strong>ates by IH 3 on V’, s z, D1 and D1<br />

ei<strong>the</strong>r failSp<strong>in</strong>e(∆, ∃x:A; B ⊢ ? : a N)<br />

or (fillSp<strong>in</strong>e(∆, ∃x:A; B ⊢ ? : a N)<br />

θ<br />

=⇒ 〈∆ ′ ; B ′ ; M; a N ′ 〉<br />

and θA = A ′ and |∆ ′ | ⊢ Φ wellTyped and ∆ ′ ⊢ Φ g<br />

and ∆ ′ ⊢ Φ valid and ∆ ′ ; Φ ⊢ A ′ okSGs a N ′ )<br />

by <strong>in</strong>version on term<strong>in</strong>ates<br />

assume failSp<strong>in</strong>e(∆, ∃x:A; B ⊢ ? : a N) Case 1<br />

failSp<strong>in</strong>e(∆; Πx:A.B ⊢ ? : a N) by rule<br />

(∆; Πx:A.B ⊢ ? : a N) ; A term<strong>in</strong>ates by rule<br />

assume fillSp<strong>in</strong>e(∆, ∃x:A; B ⊢ ? : a N)<br />

and θA = A ′ and |∆ ′ | ⊢ Φ wellTyped and ∆ ′ ⊢ Φ g<br />

θ<br />

=⇒ 〈∆ ′ ; B ′ ; M; a N ′ 〉<br />

and ∆ ′ ⊢ Φ valid and ∆ ′ ; Φ ⊢ A ′ okSGs a N ′ ) Case 2<br />

∆ ′ ⊢ θ : ∆, ∃x:A and ⊢ ∆ ′ raised and θB = B ′<br />

167


Case:<br />

and θ(<strong>in</strong>puts a (N)) = <strong>in</strong>puts a (N ′ )<br />

and |∆|; B ′ ⊢ M : a N ′ by Lemma 5.2.14<br />

θ = θ ′ , M:A ′ /x and ∆ ′ ⊢ θ ′ : ∆<br />

and θ ′ A = A ′ and |∆ ′ | ⊢ M : A ′ by Lemma 5.2.1<br />

∆ ′ , ∀y:A ′ ⊢ θ ′ , y/x : ∆ ′ , ∀x:A by rule<br />

(θ, y/x)B = B ′′ and |∆ ′ |, x:A ′ ⊢ B ′′ : type by Lemma 5.2.7<br />

fillSp<strong>in</strong>e(∆; Πx:A.B ⊢ ? : a N) θ′<br />

=⇒ 〈∆ ′ ; Πy:A ′ .B ′′ ; M :: M; a N ′ 〉 by rule<br />

x#A by <strong>the</strong> renamability <strong>of</strong> bound variables<br />

θ ′ A = A ′ by Lemma 5.2.55<br />

(∆; Πx:A.B ⊢ ? : a N) ; A term<strong>in</strong>ates by rule<br />

D =<br />

D0<br />

∆ ⊢ <strong>in</strong>puts a (M) g=⇒ η<br />

D1<br />

η ⊢ <strong>in</strong>puts a (M) g<br />

∆ ⊢ a M okD A<br />

|∆| ⊢ a M : type and |∆| ⊢ A wellTyped and<br />

D2<br />

η; · ⊢ A okSGs a M<br />

∆ ⊢ a N okG and size∆(a N = V ) and V =v V given<br />

|∆| ⊢ a M : type and ⊢ Σ tc a<br />

and ∆ ⊢ ∆ tc a and ∆ ⊢ <strong>in</strong>puts a (N) g by <strong>in</strong>version on okG<br />

ei<strong>the</strong>r unify(∆ ⊢ <strong>in</strong>puts a (M) • = <strong>in</strong>puts a (N)) =⇒ fail<br />

or unify(∆ ⊢ <strong>in</strong>putsa (M) • = <strong>in</strong>putsa (N)) ∆′<br />

=⇒ θ by Proposition 5.2.12<br />

assume unify(∆ ⊢ <strong>in</strong>puts a (N) • = <strong>in</strong>puts a (M)) =⇒ fail Case 1<br />

failSp<strong>in</strong>e(∆; a M ⊢ ? : a N) by rule<br />

(∆; a M ⊢ ? : a N) ; A term<strong>in</strong>ates by rule<br />

assume unify(∆ ⊢ <strong>in</strong>putsa (M) • = <strong>in</strong>putsa (N)) ∆′<br />

=⇒ θ Case 2<br />

∆ ′ ⊢ θ : ∆ and ⊢ ∆ ′ raised<br />

168


4.<br />

Case:<br />

and θ unifies <strong>in</strong>puts a (M) and <strong>in</strong>puts a (N) by Proposition 5.2.12<br />

θ(a M) = a M ′ and |∆| ⊢ a M ′ : type by Lemma 5.2.7<br />

θM = M ′ by <strong>in</strong>version on gsub app<br />

fillSp<strong>in</strong>e(∆; a M ⊢ ? : a N)<br />

θ<br />

=⇒ 〈∆ ′ ; a M ′ ; (·); a M ′ 〉 by rule<br />

θA = A ′ and |∆ ′ | ⊢ A ′ wellTyped by Lemma 5.2.55<br />

θ(a N) = a N ′ and |∆| ⊢ a N ′ : type by Lemma 5.2.7<br />

θN = N ′ by <strong>in</strong>version on gsub app<br />

<strong>in</strong>puts a (M ′ ) = <strong>in</strong>puts a (N ′ ) by def <strong>of</strong> unifier<br />

∆ ′ ⊢ <strong>in</strong>puts a (N ′ ) g by Lemma 5.2.20<br />

∆ ′ ⊢ <strong>in</strong>puts a (M ′ ) g by equality<br />

∆ ′ ⊢ θ : η by Lemma 5.2.36<br />

θ· = · by rule<br />

∆; · ⊢ A ′ okSGs a M ′<br />

|∆ ′ | ⊢ · wellTyped by rule<br />

∆ ′ ⊢ · valid by rule<br />

∆ ′ ⊢ · g by rule<br />

(∆; a M ⊢ ? : a N) ; A term<strong>in</strong>ates by rule<br />

D =<br />

D0 : (hd(A) ≡ a) D1 : (|∆| ⊢ A : type) D2 : (∆, ∀x:A ⊢ A okD ·)<br />

D3 : (∆, ∀x:A; Φ ⊢ B okSG a M =⇒ 〈η, ∀x:A; F 〉)<br />

∆; Φ ⊢ Πx:A.B okSG a M =⇒ 〈η; ∇x:A.F 〉<br />

|∆| ⊢ Πx:A.B : type and |∆| ⊢ Φ wellTyped<br />

and ∆ ⊢ Φ g and ∆ ⊢ Φ valid<br />

169


and ∆ ⊢ a M okG and size∆(a M) = V and V =v V given<br />

|∆| ⊢ A : type and |∆|, x:A ⊢ B : type by <strong>in</strong>version for typ<strong>in</strong>g<br />

|∆, ∀x:A| ⊢ Φ wellTyped by Lemma 5.2.50<br />

∆, ∀x:A ⊢ Φ g by Lemma 5.2.51<br />

∆, ∀x:A ⊢ Φ g by Lemma 5.2.54<br />

|∆| ⊢ a M : type and ⊢ Σ tc a<br />

and ∆ ⊢ ∆ tc a and ∆ ⊢ <strong>in</strong>puts a (M) g by <strong>in</strong>version on okG<br />

|∆|, x:A ⊢ a M : type by Lemma 5.1.6<br />

∆, ∀x:A ⊢ ∆ tc a by Lemma 5.2.58<br />

∆, ∀x:A ⊢ ∆, ∀x:A tc a by rule<br />

∆, ∀x:A ⊢ <strong>in</strong>puts a (M) g by Lemma 5.2.18<br />

∆, ∀x:A ⊢ a M okG by rule<br />

|∆| ⊢ measurea M wellTyped by Lemma 5.2.44<br />

∆ ⊢ measurea M g by Lemma 5.2.44<br />

〈measurea M; ∆〉 =o 〈measurea M; ∆〉 by Lemma 5.2.45<br />

〈measurea M; ∆〉 =o 〈measurea M; ∆, ∀x:A〉 by Lemma 5.2.45<br />

size∆,∀x:A(a M) = V ′ and V ′ =v V ′ by Lemma 5.2.61<br />

V =v V ′ by def <strong>of</strong> size and def <strong>of</strong> =v<br />

(∆, ∀x:A ⊢ ? : B) term<strong>in</strong>atesSatisfy<strong>in</strong>g 〈η, ∀x:A; F 〉<br />

ei<strong>the</strong>r failTerm(∆, ∀x:A ⊢ ? : B)<br />

or (fillTerm(∆, ∀x:A ⊢ ? : B) ∆′<br />

=⇒ 〈θ; M; B ′ 〉<br />

by IH 4 on V ′ , z D3 and D3<br />

and ∆ ′ ⊢ B ′ solved and ∆ ′ ⊢ θ : η, ∀x:A and ∆η = ∆, ∀x:A<br />

and θF = F ′ and |∆ ′ | ⊢ F wellTyped and ∆ ′ ⊢ F g and ∆ ′ ⊢ F valid)<br />

by <strong>in</strong>version on term<strong>in</strong>atesSatisfy<strong>in</strong>g<br />

assume failTerm(∆, ∀x:A ⊢ ? : B) Case 1<br />

170


Case:<br />

failTerm(∆ ⊢ ? : Πx:A.B) by rule<br />

(∆ ⊢ ? : Πx:A.B) term<strong>in</strong>atesSatisfy<strong>in</strong>g 〈η; F 〉 by rule<br />

assume fillTerm(∆, ∀x:A ⊢ ? : B) ∆′<br />

=⇒ 〈θ; M; B ′ 〉<br />

and ∆ ′ ⊢ B ′ solved and ∆ ′ ⊢ θ : η, ∀x:A and ∆η = ∆, ∀x:A<br />

and θF = F ′ and |∆ ′ | ⊢ F wellTyped<br />

and ∆ ′ ⊢ F g and ∆ ′ ⊢ F valid Case 2<br />

∆ ′ ⊢ θ : ∆, ∀x:A and ⊢ ∆ ′ raised and θB = B ′<br />

and θ(<strong>in</strong>puts a (M) = <strong>in</strong>puts a (M ′ )) and |∆ ′ | ⊢ M : B ′ by Lemma 5.2.14<br />

∆ ′ = ∆ ′′ , ∀y:A ′ , ∃Γ and θ = θ ′ , y/x and θA = A ′<br />

and ∆ ′′ ⊢ θ ′ : ∆ by Lemma 5.2.1<br />

∆ ′ = ∆ ′′ , ∀y:A ′ by <strong>in</strong>version on raised<br />

fillTerm(∆ ⊢ ? : Πx:A.B)<br />

θ ′<br />

=⇒ 〈∆ ′′ ; λy:A ′ .M; Πy:A ′ .B ′ 〉 by rule<br />

∆ ′′ ⊢ Πy:A ′ .B ′ solved by rule<br />

η = η ′ , ∀x:A and ∆η ′ = ∆ by <strong>in</strong>version on ∆η<br />

∆ ′′ ⊢ θ ′ : η ′ by <strong>in</strong>version on abs sub typ<strong>in</strong>g<br />

θ ′ (∇x:A.F ) = ∇y:A ′ .F ′ by rule<br />

|∆ ′′ | ⊢ ∇y:A ′ .F ′ wellTyped by rule<br />

∆ ′′ ⊢ ∇y:A ′ .F ′ g by rule<br />

∆ ′′ ⊢ ∇y:A ′ .F ′ valid by rule<br />

(∆ ⊢ ? : Πx:A.B) term<strong>in</strong>atesSatisfy<strong>in</strong>g 〈η; F 〉 by rule<br />

D =<br />

b ≡ a tbb ≥ tba ∆ ⊢ <strong>in</strong>puts b (N) g<br />

∆; Φ ⊢ measureb N ≺ measurea M ∆ ⊢ outputs b (N) g=⇒ η<br />

∆; Φ ⊢ b N okSG a M =⇒ 〈η; redInvb N〉<br />

171


|∆| ⊢ b N : type and |∆| ⊢ Φ wellTyped and ∆ ⊢ Φ g<br />

and ∆ ⊢ Φ valid and ∆ ⊢ a M okG<br />

and size∆(a M) = V and V =v V given<br />

|∆| ⊢ a M : type and ⊢ Σ tc a<br />

and ∆ ⊢ ∆ tc a and ∆ ⊢ <strong>in</strong>puts a (M) g by <strong>in</strong>version on okG<br />

⊢ Σ tc b and ∆ ⊢ ∆ tc b by Lemma 5.2.59<br />

∆ ⊢ b N okG by rule<br />

size∆(b N) = V ′ and V ′ =v V ′ by Lemma 5.2.61<br />

V = 〈a; 〈<strong>in</strong>puts a (M); ∆〉; tba〉 by <strong>in</strong>version on size<br />

V ′ = 〈b; 〈<strong>in</strong>puts b (M); ∆〉; tbb〉 by <strong>in</strong>version on size<br />

|∆| ⊢ (measurea M) wellTyped by Lemma 5.2.44<br />

∆ ⊢ (measurea M) g Lemma 5.2.44<br />

|∆| ⊢ (measureb N) wellTyped Lemma 5.2.44<br />

∆ ⊢ (measureb N) g Lemma 5.2.44<br />

|∆| ⊢ (measureb N ≺ measurea M) wellTyped by rule<br />

∆ ⊢ (measureb N ≺ measurea M) g by rule<br />

∆ ⊢ (measureb N ≺ measurea M) valid by Def<strong>in</strong>ition 5.2.47<br />

〈∆; measureb N〉


fillTerm(∆ ⊢ ? : b N)<br />

∆ ⊢ θ : ∆ ′ and ⊢ ∆ ′ raised<br />

θ<br />

=⇒ 〈∆ ′ ; M; b N ′ 〉 and ∆ ′ ⊢ b N ′ solved Case 2<br />

and θ(b N) = b N ′ and |∆| ⊢ M : a N ′ by Lemma 5.2.14<br />

θN = N ′ by <strong>in</strong>version on gsub application<br />

|∆ ′ | ⊢ b N ′ : type and ∆ ′ ⊢ b N ′ g<br />

and ∆ ′ ⊢ redInvb N ′ valid by <strong>in</strong>version on solved<br />

∆ ′ ⊢ outputs b (N ′ ) g by Lemma 5.2.22<br />

∆ ′ ⊢ θ : η by Lemma 5.2.36<br />

∆η = ∆ by Lemma 5.2.17<br />

θ(redInvb N) = redInvb N ′ by Lemma 5.2.48<br />

|∆ ′ | ⊢ (redInvb N ′ ) wellTyped by Lemma 5.2.48<br />

∆ ′ ⊢ (redInvb N ′ ) g by Lemma 5.2.48<br />

(∆ ⊢ ? : b N) term<strong>in</strong>atesSatisfy<strong>in</strong>g 〈η; redInvb N〉 by rule<br />

The pro<strong>of</strong> <strong>of</strong> Theorem 5.2.62 relies only on syntactically f<strong>in</strong>itary methods, plus <strong>the</strong><br />

pr<strong>in</strong>ciple <strong>of</strong> well-founded <strong>in</strong>duction over <strong>the</strong> order<strong>in</strong>g


Chapter 6<br />

Related Work<br />

The philosophical viewpo<strong>in</strong>t beh<strong>in</strong>d <strong>the</strong> notion <strong>of</strong> syntactic f<strong>in</strong>itism described <strong>in</strong> this<br />

document is well precedented. With <strong>the</strong> possible exception <strong>of</strong> <strong>the</strong> status <strong>of</strong> lexico-<br />

graphic order<strong>in</strong>gs, <strong>the</strong> difference between f<strong>in</strong>itism and syntactic f<strong>in</strong>itism is more or less<br />

than <strong>the</strong> difference between <strong>the</strong> doma<strong>in</strong> <strong>in</strong> which <strong>the</strong>y are applied—ma<strong>the</strong>matics for<br />

<strong>the</strong> former, programm<strong>in</strong>g languages research for <strong>the</strong> latter. The concept <strong>of</strong> f<strong>in</strong>itism <strong>in</strong><br />

ma<strong>the</strong>matics goes at least as far back as Kroenecker, and <strong>in</strong> <strong>the</strong> context <strong>of</strong> program-<br />

m<strong>in</strong>g languages research, strik<strong>in</strong>gly many meta<strong>the</strong>orems have syntactically f<strong>in</strong>itary<br />

pro<strong>of</strong>s, <strong>in</strong>clud<strong>in</strong>g most confluence and type safety results (see [LCH07] for a syntac-<br />

tically f<strong>in</strong>itary pro<strong>of</strong> <strong>of</strong> type safety for a significant subset <strong>of</strong> Standard ML).<br />

We do not claim to be <strong>the</strong> first to characterize a logical relation <strong>in</strong> terms <strong>of</strong> <strong>the</strong><br />

provability <strong>of</strong> a logical predicate. Indeed <strong>the</strong> idea goes back to Tait’s orig<strong>in</strong>al paper<br />

[Tai67]. However, to our knowledge, <strong>the</strong> use <strong>of</strong> an assertion logic for <strong>the</strong> purpose <strong>of</strong><br />

giv<strong>in</strong>g a f<strong>in</strong>itary account <strong>of</strong> such pro<strong>of</strong>s is novel. Structural logical relations are espe-<br />

cially well suited for be<strong>in</strong>g formalized under <strong>the</strong> pro<strong>of</strong>s as logic programs discipl<strong>in</strong>e,<br />

and make <strong>the</strong> pro<strong>of</strong>-<strong>the</strong>oretic assumptions that a particular pro<strong>of</strong> is based on ex-<br />

plicit. Formulat<strong>in</strong>g conventional logical relations pro<strong>of</strong>s can usually be accomplished<br />

174


<strong>in</strong> type <strong>the</strong>ories with strong notion <strong>of</strong> <strong>in</strong>ductive def<strong>in</strong>ition (e.g. Coq or Lego) under<br />

<strong>the</strong> pro<strong>of</strong>s as (functional) programs discipl<strong>in</strong>e [Alt93, BW97, DX06], although <strong>the</strong>se<br />

formalizations are not <strong>in</strong> <strong>the</strong> spirit <strong>of</strong> f<strong>in</strong>itism. There, <strong>the</strong> necessary pro<strong>of</strong>-<strong>the</strong>oretic<br />

assumptions are implicitly assumed by <strong>the</strong> type <strong>the</strong>ory itself, <strong>of</strong>ten <strong>in</strong> <strong>the</strong> form <strong>of</strong> im-<br />

predicative reason<strong>in</strong>g which is beyond <strong>the</strong> state <strong>of</strong> <strong>the</strong> art <strong>of</strong> ord<strong>in</strong>al analysis [Rat06].<br />

Pro<strong>of</strong>s by logical relations are popular <strong>in</strong> large part because <strong>the</strong>y tend to scale well;<br />

structural logical relations appear to preserve this property [SS08].<br />

Our application <strong>of</strong> <strong>the</strong> ideas and results from ord<strong>in</strong>al analysis (<strong>the</strong> branch <strong>of</strong> pro<strong>of</strong><br />

<strong>the</strong>ory created by Gentzen’s sem<strong>in</strong>al work [Gen36, Gen38, Gen43]) to identify <strong>the</strong><br />

ord<strong>in</strong>al ω ωω<br />

with <strong>the</strong> concept <strong>of</strong> syntactic f<strong>in</strong>itism is precedented by, and justified us-<br />

<strong>in</strong>g, <strong>the</strong> classification <strong>of</strong> primitive recursive arithmetic and ord<strong>in</strong>al recursive functions<br />

<strong>in</strong> terms <strong>of</strong> fragments <strong>of</strong> Peano arithmetic. This program was <strong>in</strong>itiated by [Gen43],<br />

and ref<strong>in</strong>ed substantially by Parsons [Par66, Par70] and M<strong>in</strong>ts [M<strong>in</strong>73a, M<strong>in</strong>73b]. A<br />

research program similar <strong>in</strong> spirit has been carried out for fragments <strong>of</strong>, and exten-<br />

sions to, Mart<strong>in</strong>-Löfs, type <strong>the</strong>ory [ML84], which is a formalization <strong>of</strong> ma<strong>the</strong>matical<br />

reason<strong>in</strong>g that that has been justified by extensive philosophical arguments, and<br />

serves as <strong>the</strong> foundation for <strong>the</strong> pro<strong>of</strong> assistant Agda [Nor07], which is used by many<br />

programm<strong>in</strong>g languages researchers. Overviews <strong>of</strong> this program can be found <strong>in</strong><br />

[Set08, Kah02].<br />

We have demonstrated that lexicographic path <strong>in</strong>duction is a suitable replacement<br />

for transf<strong>in</strong>ite <strong>in</strong>duction <strong>in</strong> at least some sett<strong>in</strong>gs. We are not <strong>the</strong> first to prove <strong>the</strong><br />

consistency <strong>of</strong> a logic us<strong>in</strong>g an order<strong>in</strong>g from term rewrit<strong>in</strong>g <strong>the</strong>ory: [DP98, Bit99,<br />

Urb01] show <strong>the</strong> strong normalization <strong>of</strong> cut-elim<strong>in</strong>ation for different formulations <strong>of</strong><br />

first-order logic us<strong>in</strong>g ei<strong>the</strong>r <strong>the</strong> multiset path order<strong>in</strong>g or lexicographic path order<strong>in</strong>g.<br />

However, because <strong>the</strong>se results rely on prov<strong>in</strong>g term<strong>in</strong>ation <strong>of</strong> term rewrit<strong>in</strong>g systems,<br />

<strong>the</strong>y cannot be scaled to arithmetic (by Gödel’s second <strong>in</strong>completeness <strong>the</strong>orem and<br />

175


[Buc95]).<br />

Several o<strong>the</strong>r logics from <strong>the</strong> programm<strong>in</strong>g languages literature formulate <strong>the</strong><br />

notion <strong>of</strong> <strong>in</strong>duction def<strong>in</strong>ed <strong>in</strong> [ML71], which <strong>in</strong>spired <strong>the</strong> <strong>the</strong> rule hcl. The pro<strong>of</strong>s<br />

<strong>of</strong> consistency for FOλ∆ N [MM00], L<strong>in</strong>c [MT03], and G [GMN08] all rely on (con-<br />

ventional) logical relations; <strong>the</strong> pro<strong>of</strong> <strong>of</strong> consistency for LKID [Bro06] uses model<br />

<strong>the</strong>ory. We are optimistic that many <strong>of</strong> <strong>the</strong>se systems can be proven consistent us<strong>in</strong>g<br />

f<strong>in</strong>itary reason<strong>in</strong>g extended with lexicographic path <strong>in</strong>duction. However, <strong>the</strong> pro<strong>of</strong><br />

<strong>the</strong>oretic strength <strong>of</strong> Mart<strong>in</strong>-Löf’s fulls <strong>in</strong>tuitionistic <strong>the</strong>ory <strong>of</strong> iterated <strong>in</strong>ductive def-<br />

<strong>in</strong>itions exceeds that <strong>of</strong> <strong>the</strong> small Veblen ord<strong>in</strong>al ([ML71], section 10), and thus its<br />

consistency cannot be proven by lexicographic path <strong>in</strong>duction. We leave whe<strong>the</strong>r our<br />

technique scales to any useful logics or type <strong>the</strong>ories whose pro<strong>of</strong>-<strong>the</strong>oretic ord<strong>in</strong>al is<br />

greater than ε0, but smaller than <strong>the</strong> small Veblen ord<strong>in</strong>al, to future work.<br />

Our <strong>in</strong>terpretation <strong>of</strong> syntactically f<strong>in</strong>itary pro<strong>of</strong>s as total logic programs is well<br />

precedented, most prom<strong>in</strong>ently by <strong>the</strong> pro<strong>of</strong> assistant Twelf [PS99, HC05]. How-<br />

ever, until now, a pro<strong>of</strong> <strong>of</strong> <strong>the</strong> soundness <strong>of</strong> a mode/term<strong>in</strong>ation checker for logic<br />

programm<strong>in</strong>g on LF terms has only been sketched [RP96, Roh96, Pie05]. We leave<br />

a syntactically f<strong>in</strong>itary characterization <strong>of</strong> a coverage check<strong>in</strong>g, such as [SP03], and<br />

thus a complete account <strong>of</strong> pro<strong>of</strong>s-as-logic-programs to future work. The pro<strong>of</strong> assis-<br />

tant Abella [Gac08, GMN08] allows for reason<strong>in</strong>g very much <strong>in</strong> <strong>the</strong> spirit <strong>of</strong> syntactic<br />

f<strong>in</strong>itism, us<strong>in</strong>g a variation <strong>of</strong> FOλ∆ N [MM00] as a logical framework. In Abella, logic<br />

programm<strong>in</strong>g is used to help facilitate f<strong>in</strong>d<strong>in</strong>g meta<strong>the</strong>orems.<br />

Our presentation <strong>of</strong> <strong>the</strong> semantics <strong>of</strong> logic programm<strong>in</strong>g differs sharply from <strong>the</strong><br />

accounts <strong>in</strong> [Pfe91, RP96, Roh96], where pro<strong>of</strong>-search is expressed as a small-step re-<br />

duction on formulas <strong>in</strong> a unification logic, coupled with an explicit cont<strong>in</strong>uation stack.<br />

Our def<strong>in</strong>ition <strong>of</strong> pro<strong>of</strong> search over LF terms is more rem<strong>in</strong>iscent <strong>of</strong> <strong>the</strong> account given<br />

<strong>in</strong> [PW90], although our treatment <strong>of</strong> logic variables differs substantially. Our pro-<br />

176


cedure is also somewhat similar to <strong>the</strong> procedure def<strong>in</strong>ed over first-order Hereditary<br />

Harrop formulas [MNPS91] def<strong>in</strong>ed <strong>in</strong> [Nad93] [Cer98], although <strong>the</strong>ir treatments do<br />

not deal with dependent types. As far as we are aware, our use <strong>of</strong> mode <strong>in</strong>formation<br />

to specify <strong>the</strong> semantics <strong>of</strong> pro<strong>of</strong> search over LF terms is novel.<br />

<strong>Syntactic</strong>ally f<strong>in</strong>itary pro<strong>of</strong>s can also be accounted for <strong>in</strong> a functional program-<br />

m<strong>in</strong>g paradigm. The system that is perhaps most philosophically compatible with<br />

syntactic f<strong>in</strong>itism is M + 2 <strong>of</strong> [Sch00], whose meta<strong>the</strong>oretic development focuses more<br />

on coverage analysis than on term<strong>in</strong>ation. A somewhat more unconventional system<br />

can be found <strong>in</strong> [DPS97], <strong>in</strong> which abstract syntax is by terms <strong>in</strong> a modal λ-calculus<br />

with a primitive-recursion operator, although this system is unable to represent de-<br />

pendencies.<br />

Our work fits <strong>in</strong>to <strong>the</strong> larger paradigm <strong>of</strong> programm<strong>in</strong>g us<strong>in</strong>g judgments and<br />

derivations. O<strong>the</strong>r work along <strong>the</strong>se l<strong>in</strong>es <strong>in</strong>clude [Mil92a, CU04] <strong>in</strong> <strong>the</strong> logic pro-<br />

gramm<strong>in</strong>g paradigm, and [SPS04, Pos08, Pie08, LZH08] <strong>in</strong> <strong>the</strong> functional program-<br />

m<strong>in</strong>g paradigm, although <strong>the</strong> system described <strong>in</strong> [LZH08] is notable for its reliance<br />

on <strong>in</strong>f<strong>in</strong>itary rules.<br />

177


Bibliography<br />

[AF98] Jeremy Avigad and Solomon Feferman. Gödel’s functional (“Dialectica”)<br />

<strong>in</strong>terpretation. In S. Buss, editor, The Handbook <strong>of</strong> Pro<strong>of</strong> Theory, pages<br />

337–405. North-Holland, 1998.<br />

[Alt93] Thorsten Altenkirch. A formalization <strong>of</strong> <strong>the</strong> strong normalization pro<strong>of</strong><br />

for System F <strong>in</strong> LEGO. In M. Bezem and J.F. Groote, editors, Proceed-<br />

<strong>in</strong>gs <strong>of</strong> <strong>the</strong> International Conference on Typed Lambda Calculi and Appli-<br />

cations, pages 13–28, Utrecht, The Ne<strong>the</strong>rlands, March 1993. Spr<strong>in</strong>ger-<br />

Verlag LNCS 664.<br />

[Bit99] Elias Tahhan Bittar. Strong normalization pro<strong>of</strong>s for cut-elim<strong>in</strong>ation <strong>in</strong><br />

Gentzen’s sequent calculi. In Proceed<strong>in</strong>gs <strong>of</strong> <strong>the</strong> Symposium: Algebra<br />

and Computer Science. Helena Rasiowa <strong>in</strong> memoriam, volume 46, pages<br />

179–225. Banach Center Publications, 1999.<br />

[Bro06] James Bro<strong>the</strong>rston. Sequent Calculus Pro<strong>of</strong> Systems for Inductive Defi-<br />

nitions. PhD <strong>the</strong>sis, <strong>University</strong> <strong>of</strong> Ed<strong>in</strong>burgh, November 2006.<br />

[Buc91] Wilfried Buchholz. Notation systems for <strong>in</strong>f<strong>in</strong>itary derivations. Archive<br />

for Ma<strong>the</strong>matical Logic, 30(5–6):277–296, 1991.<br />

178


[Buc95] Wilfried Buchholz. Pro<strong>of</strong>-<strong>the</strong>oretic analysis <strong>of</strong> term<strong>in</strong>ation pro<strong>of</strong>s. Ann.<br />

Pure Appl. Logic, 75(1-2):57–65, 1995.<br />

[BW87] Wilfried Buchholz and Stan Wa<strong>in</strong>er. Provably computable functions and<br />

<strong>the</strong> fast grow<strong>in</strong>g hierarchy. In S. Simpson, editor, Logic and Comb<strong>in</strong>a-<br />

torics, volume 65 <strong>of</strong> Contemporary Ma<strong>the</strong>matics, pages 179–198. Ameri-<br />

can Ma<strong>the</strong>matical Society, 1987.<br />

[BW97] B. Barras and B. Werner. Coq <strong>in</strong> Coq. Soumis, 1997.<br />

[Cer98] Iliano Cervesato. Pro<strong>of</strong>-<strong>the</strong>oretic foundation <strong>of</strong> compilation <strong>in</strong> logic pro-<br />

gramm<strong>in</strong>g languages. In J. Jaffar, editor, Proceed<strong>in</strong>gs <strong>of</strong> <strong>the</strong> 1998 Jo<strong>in</strong>t<br />

International Conference and Symposium on Logic Programm<strong>in</strong>g (JIC-<br />

SLP’98), pages 115–129, Manchester, UK, June 1998. MIT Press.<br />

[CP03] Iliano Cervesato and Frank Pfenn<strong>in</strong>g. A l<strong>in</strong>ear sp<strong>in</strong>e calculus. Journal <strong>of</strong><br />

Logic and Computation, 13(5):639–688, 2003.<br />

[CR91] Walter A. Carnielli and Michael Rathjen. Hydrae and subsystems <strong>of</strong> arith-<br />

metic. Technical report, Institut fr Ma<strong>the</strong>matische Logik und Grundla-<br />

genforschung Universitt Mnster, 1991.<br />

[CU04] James Cheney and Christian Urban. Alpha-prolog: a logic programm<strong>in</strong>g<br />

language with names, b<strong>in</strong>d<strong>in</strong>g and alpha-equivalence. In ICLP, 2004.<br />

[DM79] Nachum Dershowitz and Zohar Manna. Prov<strong>in</strong>g term<strong>in</strong>ation with multi-<br />

set order<strong>in</strong>gs. Communications <strong>of</strong> <strong>the</strong> ACM, 22(8):465–476, 1979.<br />

[DO88] Nachum Dershowitz and Mitsuhiro Okada. Pro<strong>of</strong>-<strong>the</strong>oretic techniques for<br />

term rewrit<strong>in</strong>g <strong>the</strong>ory. In LICS, pages 104–111. IEEE Computer Society,<br />

1988.<br />

179


[DP98] Roy Dyckh<strong>of</strong>f and Luis P<strong>in</strong>to. Cut-elim<strong>in</strong>ation and a permutation-free<br />

sequent calculus for <strong>in</strong>tuitionistic logic. Studia Logica, 60(1):107–118,<br />

1998.<br />

[DPS97] Joëlle Despeyroux, Frank Pfenn<strong>in</strong>g, and Carsten Schürmann. Primitive<br />

recursion for higher-order abstract syntax. In R. H<strong>in</strong>dley, editor, Pro-<br />

ceed<strong>in</strong>gs <strong>of</strong> <strong>the</strong> Third International Conference on Typed Lambda Calculus<br />

and Applications (TLCA’97), pages 147–163, Nancy, France, April 1997.<br />

Spr<strong>in</strong>ger-Verlag LNCS. An extended version is available as Technical<br />

Report CMU-CS-96-172, Carnegie Mellon <strong>University</strong>.<br />

[DX06] Kev<strong>in</strong> Donnelly and Hongwei Xi. A formalization <strong>of</strong> strong normalization<br />

for simply-typed lambda calculus and System F. In Alberto Momigliano<br />

and Brigitte Pientka, editors, Proceed<strong>in</strong>gs <strong>of</strong> Workshop on Logical Frame-<br />

works and Meta-Languages: Theory and Practice, pages 109–125, Seattle,<br />

WA, August 2006. Elsevier, ENTCS 174, Issue 5.<br />

[Dyb91] Peter Dybjer. Inductive sets and families <strong>in</strong> Mart<strong>in</strong>-Löf’s type <strong>the</strong>ory<br />

and <strong>the</strong>ir set-<strong>the</strong>oretic semantics. In Logical Frameworks, pages 280–306.<br />

Cambridge <strong>University</strong> Press, 1991.<br />

[Gac08] Andrew Gacek. The Abella <strong>in</strong>teractive <strong>the</strong>orem prover (system descrip-<br />

tion). In A. Armando, P. Baumgartner, and G. Dowek, editors, Proceed-<br />

<strong>in</strong>gs <strong>of</strong> IJCAR 2008, volume 5195 <strong>of</strong> Lecture Notes <strong>in</strong> Artificial Intelli-<br />

gence, pages 154–161. Spr<strong>in</strong>ger, August 2008.<br />

[Gal91] Jean H. Gallier. What’s so special about Kruskal’s <strong>the</strong>orem and <strong>the</strong><br />

ord<strong>in</strong>al Γ 0 ? A survey <strong>of</strong> some results <strong>in</strong> pro<strong>of</strong> <strong>the</strong>ory. Ann. Pure Appl.<br />

Logic, 53(3):199–260, 1991.<br />

180


[Gen36] Gerhard Gentzen. Die widerspruchsfreiheit der re<strong>in</strong>en zahlen<strong>the</strong>orie.<br />

Ma<strong>the</strong>matische Annalen, pages 493–565, 1936. Translated to English as<br />

[Gen69a].<br />

[Gen38] Gerhard Gentzen. Neue fassung des widerspruchsfreiheitsbeweises fur die<br />

re<strong>in</strong>e zahlen<strong>the</strong>orie. Forschung zur Logik und zur Grundlegung der exacten<br />

Wissenschaften, 4:19–44, 1938. Translated to English as [Gen69b].<br />

[Gen43] Gerhard Gentzen. Beweisbarkeit und unbeweisbarkeit von anfangsfallen<br />

der transf<strong>in</strong>iten <strong>in</strong>duktion <strong>in</strong> der re<strong>in</strong>en zahlen<strong>the</strong>orie. Ma<strong>the</strong>matische<br />

Annalen, 119:140–161, 1943. Translated to English as [Gen69c].<br />

[Gen69a] Gerhard Gentzen. The consistency <strong>of</strong> elementary number <strong>the</strong>ory. In<br />

Szabo [Sza69], pages 493–565. English translation <strong>of</strong> [Gen36].<br />

[Gen69b] Gerhard Gentzen. New version <strong>of</strong> <strong>the</strong> consistency pro<strong>of</strong> for elementary<br />

number <strong>the</strong>ory. In Szabo [Sza69], pages 252–286. English translation <strong>of</strong><br />

[Gen38].<br />

[Gen69c] Gerhard Gentzen. Provability and nonprovability <strong>of</strong> restricted transf<strong>in</strong>ite<br />

<strong>in</strong>ductio<strong>in</strong> <strong>in</strong> elementary number <strong>the</strong>ory. In Szabo [Sza69], pages 287–308.<br />

English translation <strong>of</strong> [Gen43].<br />

[GLT89] Jean-Yves Girard, Yves Lafont, and Paul Taylor. Pro<strong>of</strong>s and Types, vol-<br />

ume 7 <strong>of</strong> Cambridge Tracts <strong>in</strong> Theoretical Computer Science. Cambridge<br />

<strong>University</strong> Press, Cambridge, 1989.<br />

[GMN08] Andrew Gacek, Dale Miller, and Gopalan Nadathur. Comb<strong>in</strong><strong>in</strong>g generic<br />

judgments with recursive def<strong>in</strong>itions. In F. Pfenn<strong>in</strong>g, editor, Proceed<strong>in</strong>gs<br />

<strong>of</strong> LICS 2008, pages 33–44. IEEE Computer Society, June 2008.<br />

181


[Göd58] Kurt Gödel. Über e<strong>in</strong>e bisher noch nicht benutzte erweiterung des f<strong>in</strong>iten<br />

standpunktes. Dialectica, 12:280–287, 1958. Translated to English as<br />

[Göd94].<br />

[Göd94] Kurt Gödel. On an extension <strong>of</strong> f<strong>in</strong>itary methods which has not yet<br />

been used. In Solomon Feferman et al., editor, Kurt Gödel: Collected<br />

Works: Volume II, volume II, pages 271–280. Oxford <strong>University</strong> Press,<br />

1994. English translation <strong>of</strong> [Göd58].<br />

[HC05] Robert Harper and Karl Crary. How to believe a Twelf pro<strong>of</strong>. avalaible<br />

from http://www.cs.cmu.edu/~rwh/papers/how/believe-twelf.pdf,<br />

May 2005.<br />

[Her95] Hugo Herbel<strong>in</strong>. A lambda-calculus structure isomorphic to Gentzen-style<br />

sequent calculus structure. In Leszek Pacholski and Jerzy Tiuryn, ed-<br />

itors, Computer Science Logic, 8th International Workshop, CSL ’94,<br />

Kazimierz, Poland, September 25-30, 1994, Selected Papers, volume 933<br />

<strong>of</strong> Lecture Notes <strong>in</strong> Computer Science, pages 61–75. Spr<strong>in</strong>ger, 1995.<br />

[HHP87] Robert Harper, Furio Honsell, and Gordon Plotk<strong>in</strong>. A framework for<br />

def<strong>in</strong><strong>in</strong>g logics. In Symposium on Logic <strong>in</strong> Computer Science, pages 194–<br />

204. IEEE, June 1987. An extended and revised version is available as<br />

Technical Report CMU-CS-89-173, School <strong>of</strong> Computer Science, Carnegie<br />

Mellon <strong>University</strong>.<br />

[HK91] Bernard R. Hodgson and Clement F. Kent. A survey <strong>of</strong> ord<strong>in</strong>al <strong>in</strong>terpre-<br />

tations <strong>of</strong> type epsilon0for term<strong>in</strong>ation <strong>of</strong> rewrit<strong>in</strong>g systems. In Proceed-<br />

<strong>in</strong>gs <strong>of</strong> <strong>the</strong> 2nd International CTRS Workshop on Conditional and Typed<br />

Rewrit<strong>in</strong>g Systems, pages 137–142, London, UK, 1991. Spr<strong>in</strong>ger-Verlag.<br />

182


[HL07] Robert Harper and Daniel R. Licata. Mechaniz<strong>in</strong>g meta<strong>the</strong>ory <strong>in</strong> a logical<br />

framework. Journal <strong>of</strong> Functional Programm<strong>in</strong>g, 2007.<br />

[How70] W. A. Howard. Assignment <strong>of</strong> ord<strong>in</strong>als to terms for primitive recursive<br />

functions <strong>of</strong> f<strong>in</strong>ite type. In A.K<strong>in</strong>o, J. Myhill, and R. E. Vesley, editors,<br />

Intuitionism and Pro<strong>of</strong> Theory, pages 443–458. North-Holland, 1970.<br />

[HP05] Robert Harper and Frank Pfenn<strong>in</strong>g. On equivalence and canonical forms<br />

<strong>in</strong> <strong>the</strong> lf type <strong>the</strong>ory. Transactions on Computational Logic, 6:61–101,<br />

January 2005.<br />

[Kah02] Re<strong>in</strong>hard Kahle. Ma<strong>the</strong>matical pro<strong>of</strong> <strong>the</strong>ory <strong>in</strong> <strong>the</strong> light <strong>of</strong> ord<strong>in</strong>al anal-<br />

ysis. Syn<strong>the</strong>se, 133(1–2):237–255, October 2002.<br />

[KL80] Sam Kam<strong>in</strong> and Jean-Jacques Levy. Attemps for generalis<strong>in</strong>g <strong>the</strong> recur-<br />

sive path order<strong>in</strong>gs. Unpublished lecture notes, 1980.<br />

[Kun80] Kenneth Kunen. Set Theory: An Introduction to Independence Pro<strong>of</strong>s,<br />

volume 102 <strong>of</strong> Studies <strong>in</strong> Logic and <strong>the</strong> Foundations <strong>of</strong> Ma<strong>the</strong>matics.<br />

North-Holland, 1980.<br />

[LCH07] Daniel K. Lee, Karl Crary, and Robert Harper. Towards a mechanized<br />

meta<strong>the</strong>ory <strong>of</strong> standard ml. In POPL ’07: Proceed<strong>in</strong>gs <strong>of</strong> <strong>the</strong> 34th an-<br />

nual ACM SIGPLAN-SIGACT symposium on Pr<strong>in</strong>ciples <strong>of</strong> programm<strong>in</strong>g<br />

languages, pages 173–184, New York, NY, USA, 2007. ACM Press.<br />

[LZH08] Daniel R. Licata, Noam Zeilberger, and Robert Harper. Focus<strong>in</strong>g on b<strong>in</strong>d-<br />

<strong>in</strong>g and computation. In LICS, pages 241–252. IEEE Computer Society,<br />

2008.<br />

183


[Mil91] Dale Miller. A logic programm<strong>in</strong>g language with lambda-abstraction,<br />

function variables, and simple unification. Journal <strong>of</strong> Logic and Compu-<br />

tation, 1(4):497–536, 1991.<br />

[Mil92a] Dale Miller. Abstract syntax and logic programm<strong>in</strong>g. In Proceed<strong>in</strong>gs <strong>of</strong><br />

<strong>the</strong> First and Second Russian Conferences on Logic Programm<strong>in</strong>g, pages<br />

322–337, Irkutsk and St. Petersburg, Russia, 1992. Spr<strong>in</strong>ger-Verlag LNAI<br />

592.<br />

[Mil92b] Dale Miller. Unification under a mixed prefix. Journal <strong>of</strong> Symbolic Com-<br />

putation, 14:321–358, 1992.<br />

[M<strong>in</strong>73a] G. E. M<strong>in</strong>ts. Exact estimates <strong>of</strong> <strong>the</strong> provability <strong>of</strong> transf<strong>in</strong>ite <strong>in</strong>duction<br />

<strong>in</strong> <strong>the</strong> <strong>in</strong>itial segments <strong>of</strong> arithmetic. Journal <strong>of</strong> Ma<strong>the</strong>matical Sciences,<br />

1(1):85–91, January 1973.<br />

[M<strong>in</strong>73b] G.E. M<strong>in</strong>ts. Quantifier-free and one-quantifier systems. Journal <strong>of</strong> Math-<br />

ematical Sciences, 1(1):85–91, January 1973.<br />

[ML71] Per Mart<strong>in</strong>-Löf. Hauptsatz for <strong>the</strong> <strong>in</strong>tuitionistic <strong>the</strong>ory <strong>of</strong> iterated <strong>in</strong>-<br />

ductive def<strong>in</strong>itions. In J.E. Fenstad, editor, Proceed<strong>in</strong>gs <strong>of</strong> <strong>the</strong> Second<br />

Scand<strong>in</strong>avian Logic Symposium. North Holland, 1971.<br />

[ML84] Per Mart<strong>in</strong>-Löf. Intuitionistic Type Theory. Biblioplois, Napoli, 1984.<br />

Notes <strong>of</strong> Giowanni Samb<strong>in</strong> on a series <strong>of</strong> lectues given <strong>in</strong> Padova.<br />

[ML85] Per Mart<strong>in</strong>-Löf. On <strong>the</strong> mean<strong>in</strong>gs <strong>of</strong> <strong>the</strong> logical constants and <strong>the</strong> justifi-<br />

cations <strong>of</strong> <strong>the</strong> logical laws. Technical Report 2, Scuola di Specializzazione<br />

<strong>in</strong> Logica Matematica, Dipartimento di Matematica, Università di Siena,<br />

1985.<br />

184


[MM00] Raymond McDowell and Dale Miller. Cut-elim<strong>in</strong>ation for a logic with<br />

def<strong>in</strong>itions and <strong>in</strong>duction. Theoretical Computer Science, 232(1-2):91–<br />

119, 2000.<br />

[MNPS91] Dale Miller, Gopalan Nadathur, Frank Pfenn<strong>in</strong>g, and Andre Scedrov.<br />

Uniform pro<strong>of</strong>s as a foundation for logic programm<strong>in</strong>g. Annals <strong>of</strong> Pure<br />

and Applied Logic, 51:125–157, 1991.<br />

[Mos04] Ingo Lepper Georg Moser. Why ord<strong>in</strong>als are good for you. In ESSLLI<br />

2003 - Course Material II, volume 6 <strong>of</strong> Collegium Logicum, pages 1–65.<br />

The Kurt Gödel Society, 2004.<br />

[MT03] Alberto Momigliano and Alwen Tiu. Induction and co-<strong>in</strong>duction <strong>in</strong> se-<br />

quent calculus. In Stefano Berardi, Mario Coppo, and Ferruccio Dami-<br />

ani, editors, TYPES, volume 3085 <strong>of</strong> Lecture Notes <strong>in</strong> Computer Science,<br />

pages 293–308. Spr<strong>in</strong>ger, 2003.<br />

[Nad93] Gopalan Nadathur. A pro<strong>of</strong> procedure for <strong>the</strong> logic <strong>of</strong> hereditary Harrop<br />

formulas. Journal <strong>of</strong> Automated Reason<strong>in</strong>g, 11(1):115–145, August 1993.<br />

[Nor07] Ulf Norell. Towards a practical programm<strong>in</strong>g language based on dependent<br />

type <strong>the</strong>ory. PhD <strong>the</strong>sis, Chalmers <strong>University</strong> <strong>of</strong> Technology, September<br />

2007.<br />

[NPP08] Aleksandar Nanevski, Frank Pfenn<strong>in</strong>g, and Brigitte Pientka. Contextual<br />

modal type <strong>the</strong>ory. ACM Transactions on Computal Logic, 9(3):1–49,<br />

2008.<br />

[Par66] Charles Parsons. Ord<strong>in</strong>al recursion <strong>in</strong> partial systems <strong>of</strong> number <strong>the</strong>ory.<br />

Notices <strong>of</strong> <strong>the</strong> American Ma<strong>the</strong>matical Society, 13:857–858, 1966.<br />

185


[Par70] Charles Parsons. On a number <strong>the</strong>oretic choice schema and its relation to<br />

<strong>in</strong>duction. In A. K<strong>in</strong>o, J. Myhill, and R. E. Vesley, editors, Intuitionism<br />

and Pro<strong>of</strong> Theory, pages 459–473. North-Holland, 1970.<br />

[Pfe91] Frank Pfenn<strong>in</strong>g. Logic programm<strong>in</strong>g <strong>in</strong> <strong>the</strong> LF logical framework. In<br />

Gérard Huet and Gordon Plotk<strong>in</strong>, editors, Logical Frameworks, pages<br />

149–181. Cambridge <strong>University</strong> Press, 1991.<br />

[Pfe92] Frank Pfenn<strong>in</strong>g. Computation and deduction. Unpublished lecture notes,<br />

277 pp. Revised May 1994, April 1996, May 1992.<br />

[Pfe95] Frank Pfenn<strong>in</strong>g. Structural cut elim<strong>in</strong>ation. In D. Kozen, editor, Pro-<br />

ceed<strong>in</strong>gs <strong>of</strong> <strong>the</strong> Tenth Annual Symposium on Logic <strong>in</strong> Computer Science,<br />

pages 156–166, San Diego, California, June 1995. IEEE Computer Soci-<br />

ety.<br />

[Pie05] Brigitte Pientka. Verify<strong>in</strong>g term<strong>in</strong>ation and reduction properties about<br />

higher-order logic programs. Journal <strong>of</strong> Automated Reason<strong>in</strong>g, 34(2):179–<br />

207, 2005.<br />

[Pie08] Brigitte Pientka. A type-<strong>the</strong>oretic foundation for programm<strong>in</strong>g with<br />

higher-order abstract syntax and first-class substitutions. In 35th Annual<br />

ACM Symposium on Pr<strong>in</strong>ciples <strong>of</strong> Programm<strong>in</strong>g Languages (POPL’08),<br />

pages 371–382. ACM, 2008.<br />

[Plo81] Gordon D. Plotk<strong>in</strong>. A structural approach to operational semantics. Tech-<br />

nical Report DAIMI FN-19, Computer Science Department, Aarhus Uni-<br />

versity, Aarhus, Denmark, September 1981.<br />

[PM93] C. Paul<strong>in</strong>-Mohr<strong>in</strong>g. Inductive Def<strong>in</strong>itions <strong>in</strong> <strong>the</strong> System Coq - Rules<br />

and Properties. In M. Bezem and J.-F. Groote, editors, Proceed<strong>in</strong>gs <strong>of</strong><br />

186


<strong>the</strong> conference Typed Lambda Calculi and Applications, number 664 <strong>in</strong><br />

Lecture Notes <strong>in</strong> Computer Science, 1993. LIP research report 92-49.<br />

[Pos08] Adam Poswolsky. Functional Programm<strong>in</strong>g with Logical Frameworks: The<br />

Delph<strong>in</strong> Project. PhD <strong>the</strong>sis, <strong>Yale</strong> <strong>University</strong>, December 2008.<br />

[PS98] Frank Pfenn<strong>in</strong>g and Carsten Schürmann. Twelf User’s Guide, 1.2 edi-<br />

tion, September 1998. Available as Technical Report CMU-CS-98-173,<br />

Carnegie Mellon <strong>University</strong>.<br />

[PS99] Frank Pfenn<strong>in</strong>g and Carsten Schürmann. System description: Twelf — a<br />

meta-logical framework for deductive systems. In H. Ganz<strong>in</strong>ger, editor,<br />

Proceed<strong>in</strong>gs <strong>of</strong> <strong>the</strong> 16th International Conference on Automated Deduc-<br />

tion (CADE-16), pages 202–206, Trento, Italy, July 1999. Spr<strong>in</strong>ger-Verlag<br />

LNAI 1632.<br />

[PW90] David Pym and L<strong>in</strong>coln Wallen. Investigations <strong>in</strong>to pro<strong>of</strong>-search <strong>in</strong> a<br />

system <strong>of</strong> first-order dependent function types. In M.E. Stickel, editor,<br />

10th International Conference on Automated Deduction, pages 236–250,<br />

Kaiserslautern, Germany, July 1990. Spr<strong>in</strong>ger-Verlag LNCS 449.<br />

[Rat06] Michael Rathjen. The art <strong>of</strong> ord<strong>in</strong>al analysis. In Proceed<strong>in</strong>gs <strong>of</strong> <strong>the</strong> Inter-<br />

national Congress <strong>of</strong> Ma<strong>the</strong>maticians, volume II, pages 45–69. European<br />

Ma<strong>the</strong>matical Society, 2006.<br />

[Rat07] Michael Rathjen. Theories and ord<strong>in</strong>als: Ord<strong>in</strong>al analysis. In Computa-<br />

tion and Logic <strong>in</strong> <strong>the</strong> Real World, volume 4497/2007 <strong>of</strong> Lecture Notes <strong>in</strong><br />

Computer Science, pages 632–637. Spr<strong>in</strong>ger Berl<strong>in</strong> / Heidelberg, 2007.<br />

[Ree09] Jason Reed. Higher-order constra<strong>in</strong>t simplification <strong>in</strong> dependent type<br />

<strong>the</strong>ory. In LFMTP ’09: Proceed<strong>in</strong>gs <strong>of</strong> <strong>the</strong> Fourth International Workshop<br />

187


on Logical Frameworks and Meta-Languages, pages 49–56, New York, NY,<br />

USA, 2009. ACM.<br />

[Rob65] Joel W. Robb<strong>in</strong>. Subrecursive Hierarchies. PhD <strong>the</strong>sis, Pr<strong>in</strong>ceton Uni-<br />

versity, April 1965.<br />

[Roh96] Ekkehard Rohwedder. Verify<strong>in</strong>g <strong>the</strong> meta-<strong>the</strong>ory <strong>of</strong> deductive systems.<br />

Unpublished draft, 1996.<br />

[RP96] Ekkehard Rohwedder and Frank Pfenn<strong>in</strong>g. Mode and term<strong>in</strong>ation check-<br />

<strong>in</strong>g for higher-order logic programs. In Hanne Riis Nielson, editor, Pro-<br />

ceed<strong>in</strong>gs <strong>of</strong> <strong>the</strong> European Symposium on Programm<strong>in</strong>g, pages 296–310,<br />

L<strong>in</strong>köp<strong>in</strong>g, Sweden, April 1996. Spr<strong>in</strong>ger-Verlag LNCS 1058.<br />

[Sch77] K. Schütte. Pro<strong>of</strong> Theory. Spr<strong>in</strong>ger-Verlag, 1977.<br />

[Sch00] Carsten Schürmann. Automat<strong>in</strong>g <strong>the</strong> Meta-Theory <strong>of</strong> Deductive Systems.<br />

PhD <strong>the</strong>sis, Carnegie Mellon <strong>University</strong>, 2000. CMU-CS-00-146.<br />

[Set08] Anton Setzer. Pro<strong>of</strong> <strong>the</strong>ory and Mart<strong>in</strong>-Löf Type Theory. In P.; Bourdeau<br />

M.; He<strong>in</strong>zmann G. Atten, M. v.; Bold<strong>in</strong>i, editor, One Hundred Years <strong>of</strong><br />

Intuitionism (1907 – 2007), pages 257 – 279. Birkhäuser, 2008.<br />

[SP03] Carsten Schürmann and Frank Pfenn<strong>in</strong>g. A coverage check<strong>in</strong>g algorithm<br />

for LF. In David Bas<strong>in</strong> and Burkhart Wolff, editors, Procced<strong>in</strong>gs <strong>of</strong> Theo-<br />

rem Prov<strong>in</strong>g <strong>in</strong> Higher Order Logics (TPHOLs ’03), volume LNCS-2758,<br />

Rome, Italy, 2003. Spr<strong>in</strong>ger Verlag.<br />

[SPS04] Carsten Schürmann, Adam Poswolsky, and Jeffrey Sarnat. The ∇-<br />

calculus. Functional programm<strong>in</strong>g with higher-order encod<strong>in</strong>gs. Technical<br />

Report YALEU/DCS/TR-1272, <strong>Yale</strong> <strong>University</strong>, October 2004.<br />

188


[SS08] Carsten Schürmann and Jeffrey Sarnat. Structural logical relations. In<br />

F. Pfenn<strong>in</strong>g, editor, Proceed<strong>in</strong>gs <strong>of</strong> LICS 2008, pages 69–80. IEEE Com-<br />

puter Society, June 2008.<br />

[SS09] Jeffrey Sarnat and Carsten Schürmann. Lexicographic path <strong>in</strong>duction.<br />

In TLCA ’09: Proceed<strong>in</strong>gs <strong>of</strong> <strong>the</strong> 9th International Conference on Typed<br />

Lambda Calculi and Applications, pages 279–293, Berl<strong>in</strong>, Heidelberg,<br />

2009. Spr<strong>in</strong>ger-Verlag.<br />

[Sza69] M. E. Szabo, editor. The Collected Papers <strong>of</strong> Gerhard Gentzen. North-<br />

Holland, Amsterdam, 1969.<br />

[Sza93] Nora Szasz. A mach<strong>in</strong>e checked pro<strong>of</strong> that ackermann’s function is not<br />

primitive recursive. In G. Plotk<strong>in</strong> G. Huet, editor, Logical Environments,<br />

pages 317–338. Cambridge <strong>University</strong> Press, 1993.<br />

[Tai67] W. W. Tait. Intensional <strong>in</strong>terpretation <strong>of</strong> functionals <strong>of</strong> f<strong>in</strong>ite type I.<br />

Journal <strong>of</strong> Symbolic Logic, 32:198–212, 1967.<br />

[Tai81] W. W. Tait. <strong>F<strong>in</strong>itism</strong>. Journal <strong>of</strong> Philosophy, 78(9):524–546, September<br />

1981.<br />

[TS00] A.S. Troelstra and H. Schwichtenberg. Basic Pro<strong>of</strong> Theory. Number 43<br />

<strong>in</strong> Cambridge Tracts <strong>in</strong> Theoretical Computer Science. Cambridge Uni-<br />

versity Press, second edition, 2000.<br />

[Urb01] Christian Urban. Strong normalisation for a Gentzen-like cut-elim<strong>in</strong>ation<br />

procedure. In Proceed<strong>in</strong>gs <strong>of</strong> <strong>the</strong> 5th International Conference on Typed<br />

Lambda Calculi and Applications, pages 415–42, May 2001.<br />

189


[Vir99] Roberto Virga. Higher-Order Rewrit<strong>in</strong>g with Dependent Types. PhD <strong>the</strong>-<br />

sis, Department <strong>of</strong> Ma<strong>the</strong>matical Sciences, Carnegie Mellon <strong>University</strong>,<br />

1999.<br />

[Web93] H. Weber. Leopold Kronecker. Jahresbericht der Deutschen<br />

Ma<strong>the</strong>matiker-Vere<strong>in</strong>igung, 2:5–31, 1893.<br />

[Wei95] Andreas Weiermann. Term<strong>in</strong>ation pro<strong>of</strong>s for term rewrit<strong>in</strong>g systems by<br />

lexicographic path order<strong>in</strong>gs imply multiply recursive derivation lengths.<br />

Theoretical Computer Science, 139(1-2):355–362, 1995.<br />

190

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!