Lectures onType Theory
Chapter 67
Chapter 67Optional

Bar Recursion, Choice, and Program Extraction

Prerequisites. Direct starred prerequisites: Chapter 66. No later core chapter depends on this route.

A finite product can resolve every continuation before it returns. Countable choice does not come with a last question. A counterexample functional may inspect one more proposed choice than any bound fixed before the functional is run. The required recursion must therefore discover its stopping point from the counterexample while remaining total.

The selected solution has three parts. Finite products of selection functions perform the backward calculation. Their explicitly controlled infinite product satisfies Spector’s equations. Restricted Spector bar recursion implements the same equations in the total continuous functionals, where continuity and bar induction justify totality. No later core chapter depends on this route.

The higher-type arithmetic used here

The finite types are generated by ρ,τ::=Nρτ. Finite products and finite sequences are conservative codings. Put deg(N)=0,deg(ρτ)=max{deg(ρ)+1,deg(τ)}. The phrase finite type means a member of this hierarchy; it does not mean a type with finitely many elements. The Boolean set used in examples is finite and discrete, while NN is a finite type with infinitely many inhabitants.

Definition 67.1 — The arithmetic interface

The theory WE-HAω has variables and quantifiers at every finite type, the System T constants and equations, equality at type N, and induction on N for every formula of the language. Higher-type equality is defined extensionally from equality at N. Full extensionality is replaced by the quantifier-free rule A0s=ρtA0r[s]=τr[t](QF-ER), where A0 is quantifier-free, s,t:ρ, and r[x]:τ. The classical theory WE-PAω adds excluded middle. Quantifier-free choice is the scheme QF-AC:(xρyτ.A0(x,y))Fρτx.A0(x,Fx).

The shared rule schema in chapter 66 explains the Dialectica clauses, but that chapter proves its direct soundness theorem only for first-order HA. It does not prove the higher-type theorem used here. The weakly extensional base and its functional-interpretation soundness are therefore an explicit imported boundary [Koh98].

Fix a formula A(n,x), and write AN for its chosen negative translation. Countable choice and its negative form are different formulas: ACN: (nx.A(n,x))fn.A(n,fn),cACN: (n¬¬x.AN(n,x))¬¬fn.AN(n,fn). For a quantifier-free matrix, AN=A. The remaining logical principle is double-negation shift DNSN:(n.¬¬B(n))¬¬n.B(n). Work in WE-HAω+ACN. Then DNSN derives cACN: apply DNSN to B(n)x.AN(n,x), then use intuitionistic countable choice inside the final double negation. This is the exact logical reduction realized below [Pow13].

Finite choice as backward calculation

Fix types X,R. The selection type is JRX:=(XR)X. A selection function ε:JRX receives a continuation p:XR and returns an element of X. In a Dialectica argument, p is a proposed counterexample response, not necessarily a numerical score.

Definition 67.2 — Binary and finite products

Let ε:JRX, δ:JRY, and q:X×YR. Define the applied binary product by bq(x):=δ(λy.q(x,y)),aq:=ε(λx.q(x,bq(x))),(εδ)(q):=(aq,bq(aq)). For each i<m, let εi:JRXi. Define the right-associated finite product Pm by P0(q)=,Pm+1(ε0,ε)(q)=(aq,Pm(ε)(qaq)), where qx(y):=q(x,y),aq:=ε0(λx.q(x,Pm(ε)(qx))).

The continuation for the first choice contains the entire later product. Replacing it by xq(x,0,,0) changes the choice problem.

Example 67.3 — Three Boolean decisions

Let every Xi be {0,1}. Put q(x0,x1,x2)=4x0+2x1+x2, and resolve ties in favor of zero. Selectors ε0,ε2 maximize their continuations, whereas ε1 minimizes. Backward evaluation gives bx0,x1=lastmaximizingselector1,cx0(x1):=q(x0,x1,bx0,x1),ε1(cx0)=stageonecomparison0,d(x0):=q(x0,0,1)=4x0+1,ε0(d)=stagezerocomparison1. Consequently P3(ε0,ε1,ε2)(q)=thethreeselectedcoordinates(1,0,1),q(1,0,1)=5. The calculation examines two alternatives at each continuation. It does not enumerate the eight triples simultaneously.

Lemma 67.4 — Finite product equations

Let α=Pm(ε)(q). For each i<m, define pi(x):=q(α(0),,α(i1),x,Pmi1(εi+1,,εm1)(qi,x)), where qi,x fixes the displayed prefix and x. Then α(i)=εi(pi),pi(α(i))=q(α).

Proof of Lemma 67.4 — Finite product equations

Proof. Induct on m. At m=0 there is no coordinate. At m+1, the definition gives α(0)=ε0(p0), and substitution into the same definition gives p0(α(0))=q(α). Fix i+1<m+1. The tail of α is the product of ε1,,εm against qα(0). The induction hypothesis at tail coordinate i gives both required equations, and restoring the fixed first coordinate changes qα(0) back to q. ◻

Theorem 67.5 — Finite DNS and finite choice

For each i<m, suppose AiD=xXiyR.Ai(x,y). The Dialectica obligation for finite DNS has the form (εpi<m.Ai(εi(pi),pi(εi(pi))))(qαi<m.Ai(α(i),q(α))). The witness is α=Pm(ε)(q), with the continuations from lemma 67.4. Hence the same product interprets the negative translation of finite choice.

Proof of Theorem 67.5 — Finite DNS and finite choice

Proof. Fix q, take α=Pm(ε)(q), and take the tuple p from lemma 67.4. The premise at coordinate i is Ai(εi(pi),pi(εi(pi))). The two product equations rewrite its arguments to α(i) and q(α), which is the required conclusion. The finite-choice consequence first applies this finite DNS instance to the finitely many existential matrices and then uses intuitionistic finite choice. ◻

This is the equation-level proof of the primary finite-product result [EOP11].

For a complete finite-choice instance, put Ai(x,y)x=ci, where (c0,c1,c2)=(1,0,1). Take each εi to be the constant selector ci. For every challenger q, the product returns (1,0,1), and each premise and conclusion reduces to ci=ci. This example is logically complete but computationally degenerate. The score calculation in example 67.3 shows the continuation dependence hidden by constant selectors.

Proposition 67.6 — Exact finite-type level

Let Tn extend the type-zero fragment T0 by recursors whose result types have degree at most n. Let Pn extend T0 by finite-product functionals at types of degree at most n. For every X,R: PX,R is definable in T0+RXXN,Tn+1 defines Pn,RX is definable in T0+PX,XN,Pn defines Tn,RXX is definable in T0+PX,XN,Pn defines Tn+1. Thus Pn and Tn+1 are interdefinable. The product at level n matches recursion one level higher, not recursion at the same level.

Proof of Proposition 67.6 — Exact finite-type level

Proof. The first construction recurses over a continuation state of type XXN. The second makes a product write the successive states of an X-valued recursor into an XN register. The third uses selection functions over XX, which raises the result-type degree once. ◻

These are precisely Theorems 18, 19, and 21 and Corollary 22 of the finite-product source [EOP11].

Exercise 67.1

★★☆ Repeat example 67.3 for q(x0,x1,x2)=3x0+x1+5x2. Display every continuation. Then reverse only the tie convention of ε0 and determine whether the tuple changes. (Half a page.)

Why no uniform truncation suffices

Proposition 67.7 — No uniform coordinate horizon

Suppose X contains distinct points 0X,1X. For every m, a continuous functional qm:XNN exists whose value is not determined by coordinates below m.

Proof of Proposition 67.7 — No uniform coordinate horizon

Proof. Define qm(α)=1 when α(m)=1X, and zero otherwise. The functional inspects one coordinate, so it is continuous. Streams that agree below m and differ at m receive different values. ◻

The proposition refutes a uniform truncation of all continuous challengers. It does not by itself prove that System T cannot realize DNS; such a nondefinability theorem needs a semantic separation argument not developed here. What the proposition forces locally is a control functional whose value is consulted during the recursion.

The explicitly controlled product

Let X be a discrete type with a distinguished point 0X. Write X for finite lists. For a stream α:XN, its prefix of length n is [α](n). Write sx for list append, sα for prefixing a stream, and 0 for the constant 0X-stream. For q:XNR, put qs(β):=q(sβ).

Definition 67.8 — Simple explicitly controlled product

Let εn:JRX be a sequence of selectors, and let l:RN. The functional epsn,l(ε):(XNR)XN satisfies epsn,l(ε)(q)={0,l(q(0))<n,cepsn+1,l(ε)(qc),l(q(0))n, where c:=εn(λx.q(xepsn+1,l(ε)(qx))). The root stream is α:=eps0,l(ε)(q).

The strict inequality is part of the interface. Equality takes the recursive branch. This is the simple product of the primary source, not its later history-sensitive dependent variant [EO14].

Lemma 67.9 — Prefix factorization

For α=eps0,l(ε)(q) and every i, α=[α](i)epsi,l(ε)(q[α](i)).

Proof of Lemma 67.9 — Prefix factorization

Proof. Induct on i. At zero the equation is the definition of α. Assume the factorization at i. If l(q[α](i)(0))<i, the recursive call is 0, so α=[α](i)0. The same value of q occurs after one more zero, and the strict inequality implies l(q[α](i+1)(0))<i+1; the call at i+1 is also zero. If the inequality fails, one unfolding writes a head c=α(i) and the tail call at i+1. In both cases the factorization at i+1 follows. ◻

This is the full two-case induction of Lemma 3.2 [EO14].

Theorem 67.10 — Controlled-product equations

Define pi(x):=q[α](i)x(epsi+1,l(ε)(q[α](i)x)). If il(q(α)), then α(i)=εi(pi),pi(α(i))=q(α).

Proof of Theorem 67.10 — Controlled-product equations

Proof. First prove that the call at stage i takes the recursive branch. If it stopped, then l(q[α](i)(0))<i. Prefix factorization would give α=[α](i)0, hence i>l(q[α](i)(0))=prefixfactorizationl(q(α))i, a contradiction. One unfolding therefore gives α(i)=εi(pi). Prefix factorization at i+1 gives pi(α(i))=definitionofthecontinuationq([α](i)α(i)epsi+1,l(ε)(q[α](i+1)))=lemma67.9,successorstageq(α). ◻

The hypothesis and contradiction are exactly those of Theorem 3.8 [EO14].

Exercise 67.2

★★☆ Let l(r)=r, and suppose a call at depth two has q(0)=2. Unfold the printed strict test and the mutant test l(q(0))2. Show which side of the first controlled-product equation can change. (Half a page.)

Dependent control and restricted Spector recursion

Restricted Spector recursion lets the selector depend on the finite history. For sX and β:XN, define the prefix-preserving update put(s,β)(i):={s(i),i<|s|,β(i),i|s|. Unlike list prefixing, put does not shift the tail indices.

Definition 67.11 — Dependent explicitly controlled product

For history-sensitive selectors εs:JRX, define EPSs,l(ε)(q)={0,l(q(0))<|s|,cEPSsc,l(ε)(qc),l(q(0))|s|, where c:=εs(λx.q(xEPSsx,l(ε)(qx))).

This is Definition 3.11 of the arXiv source. Its course-of-values adapter proves that the simple product defines the dependent product by a System T term [EO14].

Definition 67.12 — Restricted Spector recursor

Let δs:(XXN)X, and let ω:XNN. Restricted Spector recursion satisfies SBRsω(δ)={put(s,0),ω(put(s,0))<|s|,put(s,SBRscω(δ)),ω(put(s,0))|s|, where c:=δs(λx.SBRsxω(δ)).

The result preserves s definitionally: [SBRsω(δ)](|s|)=s. In the recursive branch, the child already preserves sc, so applying put(s,) changes no coordinate. The source writes this operation with its update symbol; the explicit definition above prevents it from being mistaken for shifting concatenation. This is the special recursor in Definition 3.17 [EO14].

Theorem 67.13 — The controlled product defines SBR

At the selected homogeneous types, dependent EPS defines restricted SBR by a System T adapter. The adapter preserves both defining equations.

Proof of Theorem 67.13 — The controlled product defines SBR

Proof. Take R=XN×N, l=π2, and qsω(β):=(sβ,ω(sβ)),δ~s(P):=δs(λx.π1(Px)). Define SBRsω(δ):=sEPSsπ2(δ~)(qsω). The base tests agree because π2(qsω(0))=ω(s0)=ω(put(s,0)). In the recursive branch, π1 removes the numerical control before the continuation reaches δs. The identities s(xβ)=(sx)β,(qsω)x=qsxω make the selected heads equal and turn the recursive EPS call into the child SBR call. The outer shifting prefix then agrees with the prefix-preserving update in the SBR equation because the child stream already preserves sx. ◻

These are the full adapters of Theorem 3.18 [EO14].

The reverse comparison uses the source’s relativized bar induction, not the decidable two-predicate principle used for semantic totality below. For predicates S,P on X, write αS for n.S([α](n)). The scheme BIrel concludes P([]) from S([]),αS.n.P([α](n)),sS.((x.(S(sx)P(sx)))P(s)).

Theorem 67.14 — Conditional reverse definability

Over E-HAω+SPEC+BIrel, restricted SBR defines the simple controlled product, and hence defines dependent EPS through the System T course-of-values adapter. Thus EPS and SBR are interdefinable at the selected finite types under these named principles.

Proof of Theorem 67.14 — Conditional reverse definability

Proof. The sourced reverse route has four steps. First, restricted SBR defines the general bar recursor BRsω(ϕ)(q)={qs(0),ω(put(s,0))<|s|,ϕs(λx.BRsxω(ϕ)(q)),otherwise. That adapter is Powell’s external edge in the comparison. The direct primitive-recursive equivalence between dependent EPS and SBR alone does not give the return from the dependent product to the simple product used here. Second, bar induction and Spector’s condition define the explicitly controlled product of quantifiers EPQ from BR. Third, the simple quantifier product is the history-independent instance of EPQ. Fourth, bar induction defines the simple selection product from that quantifier product. Finally Theorem 3.13 defines dependent EPS from the simple product.

The two uses of BIrel are hypotheses, not System T programs. The source records them in Theorems 3.7 and 3.16 and leaves their removal open; its Theorems 3.13 and 3.18 prove only the forward direction used in theorem 67.13. ◻

Powell proves the direct dependent-EPS/SBR equivalence in Example 9.5 and Theorem 9.6(a)[Pow13]. The conditional return to the simple product follows the comparison route in Escardó and Oliva[EO14].

Exercise 67.3

★★★ Unfold the adapter in theorem 67.13 at a prefix s of length two. Give the types of qsω, l, δ~s, its argument P, and the selected c. Verify the shifting-prefix identity and the final prefix-preservation step used in the recursive branch. (One page.)

Totality from continuity and bar induction

The semantic model is the hierarchy of total continuous functionals: every object is total, and each observation of a higher-type output depends on a finite observation of its input. Put α^n:=put([α](n),0).

Lemma 67.15 — Spector's condition

For every total continuous ω:XNN, αn. ω(α^n)<n.

Proof of Lemma 67.15 — Spector's condition

Proof. Continuity at α gives a number k such that streams agreeing with α below k receive the same value. Choose n>max{k,ω(α)}. Then ω(α^n)=continuityatthefixedstreamω(α)<n. The witness depends on α and ω; it is not a uniform recursion depth. ◻

This principle is SPEC in the primary comparison [EO14].

The totality proof assumes the following decidable form of bar induction. For predicates D,Q on X, (BIdec)αn.D([α](n))s.(D(s)¬D(s)),s.(D(s)Q(s))s.((x.Q(sx))Q(s))Q([]). The bar D and inductive predicate Q are distinct. Combining them would delete the premise that a stopping prefix has a total value. This decidable bar-induction boundary is explicit in the primary theorem map [Pow13].

Theorem 67.16 — Totality of restricted Spector recursion

In the total continuous functionals, assume BIdec. If ω and every δs are total continuous functionals, then SBR[]ω(δ) is total. The EPS term obtained from theorem 67.14 is total under the same semantic hypotheses.

Proof of Theorem 67.16 — Totality of restricted Spector recursion

Proof. Define D(s):=ω(put(s,0))<|s|,Q(s):=SBRsω(δ) has a total value. Spector’s condition makes D a bar, and comparison of natural numbers makes D(s) decidable. If D(s), the base equation returns put(s,0), so Q(s).

For the inductive premise, fix s and assume Q(sx) for every total x:X. The map xSBRsxω(δ) is then a total continuation. Totality of δs gives a total selected value c, and the assumption at sc gives a total recursive result. Thus Q(s) in the recursive branch; the base branch was handled above. The rule BIdec gives Q([]). Transport along the sourced reverse adapter gives the EPS claim. This proves semantic totality, not strong normalization of the bare equations. ◻

Exercise 67.4

★★☆ For streams of naturals, let ω(α)=α(0)+1. Give an explicit stopping witness n for each α. Then consider the discontinuous specification that returns the first zero index and returns zero when no zero occurs. Identify the unavailable premise in lemma 67.15. (Half a page.)

Spector’s equations and countable choice

Theorem 67.17 — Spector equations

Let q:XNR and ω:XNN be total continuous functionals, and let εn:JRX. There are α:XN and pn:XR such that, for every nω(α), α(n)=εn(pn),pn(α(n))=q(α).

Proof of Theorem 67.17 — Spector equations

Proof. Use R=R×N, q(β):=(q(β),ω(β)),l:=π2,εn(P):=εn(λx.π1(Px)). Apply theorem 67.10 to q,l,ε, and write its continuation as pn:XR. Define pn:=π1pn. Since l(q(α))=ω(α), the theorem applies at every nω(α). Projection of its two equations gives the required equations. The adjustment εn is necessary: the original selector expects an R-valued continuation, not an R×N-valued one. ◻

This is Corollary 3.9 [EO14].

Theorem 67.18 — Selected choice interpretation

Let C(a) be a formula of WE-PAω. From a derivation WE-PAω+QF-AC+ACNC(a) one can extract a closed term t of WE-HAω+SBR such that WE-HAω+SBRy.|CN(a)|yt(a). In particular, restricted SBR realizes DNSN, hence the displayed cACN. Semantic totality is relative to the total continuous functionals and BIdec.

Proof of Theorem 67.18 — Selected choice interpretation

Proof. Negative translation sends the classical derivation into the weakly extensional intuitionistic base. The functional-interpretation induction handles its logical rules, arithmetic equations, induction, and quantifier-free choice. The new DNS case requires a sequence f, counterexample continuations pn, and the index n=ω(f). Theorem 67.17 gives f(n)=εn(pn),pn(f(n))=q(f), which are exactly the two substitutions in the Dialectica matrix of DNS. The logical reduction at the end of section 67.1 then handles cACN. Theorem 67.16 gives totality of the new functional; all other extracted constants belong to System T. ◻

The exact imported metatheorem is Powell’s Theorem 4.4; its accompanying remark records that verification in the weakly extensional base requires the formalization cited there, rather than Spector’s extensional argument alone [Pow13]. Spector’s original Section 10 gives the restricted one-unknown construction. Sections 12.2 and 12.3 of the printed paper were completed by its editor, Georg Kreisel [Spe62].

Exercise 67.5

★★★ For quantifier-free A(n,x), derive cACN from DNS and intuitionistic countable choice. Then mark the selector, outcome functional, control, selected sequence, and continuations in theorem 67.17. Explain why a product with a horizon fixed before ω is received cannot perform this construction. (One page.)

Finite evidence from the pigeonhole extraction

The pinned Agda development proves, under a Friedman A-translation, that every Boolean stream has a constant infinite subsequence. Its finite specialization erases the proof component to the executable type Two×ListN. The archive has seven named streams a1,,a7 and six named executable examples. The Agda type of the first is the displayed product above. Its defining equation in the archived module is

example1 = pigeon-program a6 2

The request 2 means that the returned list has length three. Its acceptance check requires three strictly increasing indices and verifies that all three entries of a6 at those indices equal the returned Boolean. The dependent theorem in FinitePigeon.agda proves this specification before PigeonProgram.agda erases the proof component. The archived sources are Agda from 2011; this edition records no fresh typecheck under an unavailable historical toolchain.

The selection-function, BBC, and modified-bar-recursion modules are alternative realizers of the shift principle. They do not prove equality with the restricted SBR interface fixed here. The project page also records that the three realizer modules disable Agda’s termination checker [Esc11].

The book-owned Kappa corpus in artifacts/ch67-bar-choice-replay/ implements the applied binary product, the three-stage calculation, and a fuel-bounded specialization of dependent EPS. The bound makes it a finite executable shadow, not an implementation of infinite bar recursion. Its strict and non-strict stopping variants return different four-entry traces, so the mutation checks the equation that the chapter uses.

Nearby recursors are not interchangeable

The implicitly controlled product has no explicit length test. Continuity of the outcome functional instead bounds the demanded recursive calls. In the primary comparison it realizes a J-shift by modified realizability, while the explicit product realizes DNS by Dialectica.

Modified bar recursion returns a different object and satisfies different equations. Its equivalence with an implicitly controlled product does not change theorem 67.18. Escardó and Oliva’s comparison separates the arrows that require BIrel, SPEC, or continuity; one cannot erase those annotations when moving between recursors [EO14].

Finally, a finite run concerns one extracted term at one input. Semantic totality quantifies over all total inputs in the chosen continuous model. Neither observation proves the other.

Chapter seminar

None of these problems is a prerequisite for a later core chapter.

Suggested first pass.

Start with the prefix proof and the executable stopping mutation; then compare the two recursor interfaces.

Exercise 67.6

★★☆ Reconstruct theorem 67.10 from prefix factorization. Your proof must display the contradiction that rules out the stopping branch and the calculation of pi(α(i)). (One page.)

Exercise 67.7

★★☆ Let a proposed control return zero when its input stream contains a zero and one otherwise. Show that it is discontinuous at the all-one stream. Explain why lemma 67.15 no longer gives a bar for this control. (Half a page.)

Exercise 67.8

★★★ Make a ledger of the arrows EPSSBR and SBREPS. For each arrow, record its adapter, base theory, and uses of BIrel or SPEC. Give one sentence explaining why theorem 67.13 does not prove the converse. (One page.)

Exercise 67.9

★★★ Practical project.bar-choice-replay Run the Kappa corpus and reproduce all four named cases. Add a fourth finite selector with a policy different from stage three, calculate its result before running, and extend the oracle. Apply the strict-to-non-strict mutation and record the unchanged input that detects it. Finally inspect Examples.agda and state the precise property that a normalized pigeon-program a6 2 result must pass. Separate what the Kappa run, the archived Agda types, and theorem 67.16 establish.

Search the book

Type to search the local edition.