Programs extracted from proofs: efficiency aspects Helmut - - PowerPoint PPT Presentation

programs extracted from proofs efficiency aspects
SMART_READER_LITE
LIVE PREVIEW

Programs extracted from proofs: efficiency aspects Helmut - - PowerPoint PPT Presentation

Programs extracted from proofs: efficiency aspects Helmut Schwichtenberg Mathematisches Institut, LMU, M unchen National Institute of Informatics, Tokyo, Japan, 31 March 2010 Helmut Schwichtenberg Programs extracted from proofs: efficiency


slide-1
SLIDE 1

Programs extracted from proofs: efficiency aspects

Helmut Schwichtenberg

Mathematisches Institut, LMU, M¨ unchen

National Institute of Informatics, Tokyo, Japan, 31 March 2010

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-2
SLIDE 2

Code carrying proof

◮ “Proof carrying code” (Necula) reversed. ◮ Allows machine check of the source proofs: no logical errors. ◮ Important: efficiency aspects. ◮ Here: (i) CPS, (ii) streams.

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-3
SLIDE 3

Brouwer-Heyting-Kolmogorov interpretation

◮ Kolmogorov (1932) proposed to view a formula A as a

computational problem, of type τ(A), the type of a potential solution or “realizer” (Kleene, Kreisel) of A.

◮ τ(A) should be the type of the term (or “program”) to be

extracted from a proof of A.

◮ Formally, we assign to every formula A an object τ(A) (a type

  • r the nulltype symbol ◦).

◮ In case τ(A) = ◦ proofs of A have no computational content;

such formulas A are called computationally irrelevant (c.i.); the other ones computationally relevant (c.r.).

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-4
SLIDE 4

Extraction of programs or of terms?

◮ In Coq, Agda, Isabelle, Nuprl: extraction of programs. ◮ Here this is split up: proof → term → program. ◮ Reason: for terms one can give a formal soundness proof,

which is machine checkable.

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-5
SLIDE 5

Classical logic: ∃-free fragment of minimal logic

Minimal logic:

◮ →, ∀. ◮ Natural deduction style (rules →±, ∀±). ◮ ⊥ propositional variable. Define ¬A := A → ⊥.

Classical logic: add stability axioms. ¬¬Rt → Rt, The (constructive) connectives ∃, ∨ can be defined inductively.

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-6
SLIDE 6

∃-proofs using induction

Induction step in ∃-proof: ∃xPx → ∃xP′x. In the ∃-free fragment prove instead ∀x(P′x → ⊥) → ∀x(Px → ⊥). View ⊥ as placeholder for the final goal.

◮ “If we would know how to reach from P′x the final goal ⊥,

then we also know how to reach it from Px.”

◮ Expect: tail recursive (continuation passing style) program.

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-7
SLIDE 7

A-translation (Dragalin, Friedman), refined

Some classes of formulas:

◮ D definite: R, P, I → D, ∀xD ∈ D. ◮ G goal: I, ⊥, R → G, D0 → G ∈ G (D0 quant.-free definite). ◮ R relevant definite: ⊥, G → R, ∀xR ∈ R. ◮ I irrelevant goal: P, D → I, ∀xI ∈ I.

Let AF := A[⊥ := F], ¬A := A → F, ¬⊥A := A → ⊥.

Lemma (Ishihara 2000, U.Berger & Buchholz & H.S. 2002)

There are derivations from F → ⊥ and F → P of DF → D, G → ¬⊥¬⊥G F, ¬⊥¬RF → R, I → I F.

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-8
SLIDE 8

An open problem

Recall: ⊢i DF → D for definite formulas D. Problem: Characterize the class of formulas D such that ⊢i DF → D. D is too small: let S := ∀x(((Qx → F) → F) → Qx), D := (∀xQx → ⊥) → ⊥. Then ⊢i (S → D)F → S → D, but S → D / ∈ D.

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-9
SLIDE 9

Extraction from classical existence proofs

Theorem (BBS2002)

Assume that for definite formulas D and a goal formula G(y) we have a derivation M˜

∃ of

  • D → ∀y(G(y) → ⊥) → ⊥.

Assume that all prime formulas P in DF, G F(y) are c.i. and “invariant”. Then from assumptions F → P we can derive

  • DF → G F(et(M′

˜ ∃)t1 . . . tns),

where M′

˜ ∃ is the result of substituting ∃yG F(y) for ⊥ in M˜ ∃, and

t1, . . . , tn and s are determined by D1, . . . , Dn and G.

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-10
SLIDE 10

Example: Point of increase

∀n∃G∀f (f 0 ≤ n → Gf ≤ n ∧ f (Gf ) ≤ f (Gf + 1)). Extracted terms (Minlog output for direct proof / CPS proof): [n0](Rec nat=>(nat=>nat)=>nat)n0([f2]0) ([n2,G3,f4][if (f4 1<f4 0) (Succ(G3([n5]f4(Succ n5)))) 0]) [n0](Rec nat=>(((nat=>nat)=>nat)=>(nat=>nat)=>nat)=> (nat=>nat)=>nat)n0 ([h2]h2([f4]0)) ([n2,p3,h4]p3([G6]h4([f8][if (f8 1<f8 0) (Succ(G6([n9]f8(Succ n9)))) 0]))) ([G2]G2)

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-11
SLIDE 11

Finitary algebras as non-flat Scott information systems

◮ An algebra ι is given by its constructors. ◮ Examples:

0N, SN→N for N (unary natural numbers), 1C, SC→C , SC→C

1

for C (Cantor algebra), 0D (axiom) and CD→D→D (rule) for D (derivations).

◮ Examples of “tokens” (∗: special symbol; no information):

Sn0 (n ≥ 0), S2∗ (in N), S0S1S0S01, S0S1S0S0∗ (in C), C(C0∗)(C∗0) (in D).

◮ A token is total if it contains no ∗. ◮ In D: total token ∼ finite (well-founded) derivation.

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-12
SLIDE 12

Finitary algebras: consistency, entailment, ideals

By example. For D (derivations):

◮ {C0∗, C∗0} is “consistent”, written C0∗ ↑ C∗0. ◮ {C0∗, C∗0} ⊢ C00 (“entails”). ◮ Ideals: consistent and “deductively closed” sets of tokens.

Examples of ideals:

◮ {C0∗, C∗∗}. ◮ {C00, C0∗, C∗0, C∗∗}, and generally the deductive closure of

a finite (well-founded) derivation.

◮ {C∗∗, C(C∗∗)∗, C∗(C∗∗), C(C∗∗)(C∗∗), . . . } (“cototal”). ◮ Locally correct, but possibly non well-founded derivations

(Mints 1978). An ideal x is cototal if every constructor tree P(∗) ∈ x has a “predecessor” P(C ∗ ) ∈ x.

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-13
SLIDE 13

Tokens and entailment for N

  • S∗

❅ ❅ ❅

  • S0
  • S(S∗)

❅ ❅ ❅

  • S(S0)
  • S(S(S∗))

❅ ❅ ❅

  • S(S(S0))
  • ...

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-14
SLIDE 14

Why non-flat?

◮ Continuous maps f : |N| → |N| (see below) are monotone:

x ⊆ y → fx ⊆ fy.

◮ Easy: every constructor gives rise to a continuous function. ◮ Want: constructors have disjoint ranges and are injective

(cf. the Peano axioms Sx = 0 and Sx = Sy → x = y).

◮ This holds for non-flat algebras, but not for flat ones:

  • S0
  • S(S0)

. . . There constructors must be strict (i.e., C x∅ y = ∅), hence In C: S1∅ = ∅ = S2∅, In D: C∅{0} = ∅ = C{0}∅.

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-15
SLIDE 15

The Scott-Ershov model of partial continuous functionals

◮ Let A = (A, ConA, ⊢A), B = (B, ConB, ⊢B) be information

systems (Scott). Function space: A → B := (C, Con, ⊢), with C := ConA × B, {(Ui, bi)}i∈I ∈ Con := ∀J⊆I(

  • j∈J

Uj ∈ ConA → {bj}j∈J ∈ ConB), {(Ui, bi)}i∈I ⊢ (U, b) := ({ bi | U ⊢A Ui } ⊢B b).

◮ Partial continuous functionals of type ρ: the ideals in Cρ.

Cι := (Tokι, Conι, ⊢ι), Cρ→σ := Cρ → Cσ. |Cρ| := set of ideals in Cρ.

◮ f ∈ |Cρ|: limit of formal neighborhoods U ∈ Conρ→σ. ◮ f ∈ |Cρ| computable: r.e. limit.

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-16
SLIDE 16

A common extension T+ of G¨

  • dels’s T and Plotkin’s PCF

◮ Terms of T+ are built from (typed) variables and constants

(constructors C or defined constants D, see below): M, N ::= xρ | Cρ | Dρ | (λxρMσ)ρ→σ | (Mρ→σNρ)σ.

◮ Every defined constant D comes with a system of

computation rules D Pi( yi) = Mi with FV(Mi) ⊆ yi.

Pi( yi): “constructor patterns”, i.e., lists of applicative terms built from constructors and distinct variables, with each constructor C occurring in a context C P (of base type). We assume that Pi and Pj for i = j are non-unifiable. Examples:

◮ Predecessor P: N → N, defined by P0 = 0, P(Sn) = n, ◮ G¨

  • del’s primitive recursion operators

N : N → τ → (N → τ → τ) → τ with computation rules

R0fg = f , R(Sn)fg = gn(Rnfg), and

◮ the least-fixed-point operators Yρ of type (ρ → ρ) → ρ

defined by the computation rule Yρf = f (Yρf ).

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-17
SLIDE 17

Corecursion operators

Recall Rτ

N : N → τ → (N → τ → τ) → τ with computation rules

R0fg = f , R(Sn)fg = gn(Rnfg). Corecursion operators:

coRτ N : τ → (τ → U + τ) → N, coRτ C : τ → (τ → U + τ + τ) → C, coRτ D : τ → (τ → U + τ × τ) → D.

Conversion:

coRτ NNM → [case MN of 0 | λn(S(coRτ NnM))], coRτ CNM → [case MN of 1 | λn(S0(coRτ CnM)) | λn(S1(coRτ CnM))], coRτ DNM → [case MN of 0D | λx,y(CD→D→D(coRτ DxM, coRτ DyM))].

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-18
SLIDE 18

Denotational semantics

For every closed term λ

xM of type

ρ → σ we inductively define a set [ [λ

xM]

] of tokens of type ρ → σ. Ui ⊢ b ( U, b) ∈ [ [λ

xxi]

] (V ), ( U, V , c) ∈ [ [λ

xM]

] ( U, V ) ⊆ [ [λ

xN]

] ( U, c) ∈ [ [λ

x(MN)]

] (A). For every constructor C and defined constant D:

  • V ⊢

b∗ ( U, V , C b∗) ∈ [ [λ

xC]

] (C), ( U, V , b) ∈ [ [λ

x, yM]

]

  • W ⊢

P( V ) ( U, W , b) ∈ [ [λ

xD]

] (D), with one rule (D) for every computation rule D P( y ) = M. Note: ( U, b) denotes (U1, . . . (Un, b) . . . ), ( U, V ) ⊆ [ [λ

xM]

] means ( U, b) ∈ [ [λ

xM]

] for all b ∈ V .

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-19
SLIDE 19

Theorem

◮ For every term M, [

xM]

] is an ideal.

◮ If a term M converts to M′ by βη-conversion or application of

a computation rule, then [ [M] ] = [ [M′] ]. Let [ [M] ]

u

  • x :=
  • U⊆

u

[ [M] ]

  • U
  • x

with [ [M] ]

  • U
  • x := { b | (

U, b) ∈ [ [λ

xM]

] }. A consequence of (A) is continuity of application: c ∈ [ [MN] ]

u

  • x ↔ ∃V ⊆[

[N] ]

u

  • x((V , c) ∈ [

[M] ]

u

  • x).

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-20
SLIDE 20

Inductive and coinductive definitions

◮ Computational content of Ir, with I inductively defined:

what was neeeded to put r into I.

◮ Example: Even is inductively defined by the clauses

Even(0), ∀n(Even(n) → Even(S(Sn))). A generation tree for Even(6) consists of a single branch with nodes Even(0), Even(2), Even(4) and Even(6).

◮ Computational content of Jr, with J coinductively defined:

how to continue after putting r into J.

◮ Example: St (“t is a stream”) is coinductively defined by the

clause St → t = nil ∨ St0 ∨ St1.

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-21
SLIDE 21

An abstract theory of sets of nodes

Nodes a, b, c are total ideals in C, viewed as lists of 0, 1. Let t be a variable of an unspecified type α (“set of nodes”). Language:

◮ a relation of arity (C, α), written a ∈ t, ◮ a function of type α → C → α, written ta, and ◮ a function of type C → α → α, written at.

Define Tree(t) := ∀a∈t∀n≤|a| an ∈ t “t is downward closed”, Inf(t) := ∀n∃a∈t |a| = n “t is infinite”, UEU(t) := ∀n∃m≥n∀a,b∈t(|a| = |b| = m → an = bn) “t satisfies the uniform effective uniqueness condition”, Cta := ∃n≥|a|∀b∈t(|b| = n → b|a| = a) “a covers the paths in t”.

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-22
SLIDE 22

Axioms

b ∈ ta ↔ ab ∈ t, ab ∈ at ↔ b ∈ t, ∃t∀a(a ∈ t ↔ A) for A Σ-formula. Define Rt := Tree(t) ∧ Inf(t) ∧ UEU(t) “t is a real”.

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-23
SLIDE 23

Properties

Covering nodes are in t: Tree(t) → Inf(t) → Cta → a ∈ t. Covering nodes are “fertile”: Tree(t) → Inf(t) → Cta → Inf(ta). The uniform effective uniqueness property is inherited to ta: UEU(t) → UEU(ta).

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-24
SLIDE 24

Nodes covering the paths in t can be extended

Lemma

Tree(t) → Inf(t) → UEU(t) → Cta → Ct(a0) ∨ Ct(a1).

Proof.

Let t be an infinite tree. Assume UEU(t) and Cta. Then we have n ≥ |a| such that ∀b∈t(|b| = n → a b). By UEU(t) for n + 1 we have m ≥ n + 1 such that ∀b,c∈t(|b| = |c| = m → b(n + 1) = c(n + 1)). Since t is infinite we have b ∈ t such that |b| = m. Then bn ∈ t since t is a tree and m ≥ n + 1, hence a bn by assumption. Let i := (b)|a|. We show Ct(ai). Take m. Clearly m ≥ |ai|. Let c ∈ t with |c| = m. We show ai c. Since |b| = |c| = m we have b(|a| + 1) = c(|a| + 1). Hence ai = b(|a| + 1) = c(|a| + 1) c.

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-25
SLIDE 25

Computational content

  • f the proof for

Tree(t) → Inf(t) → UEU(t) → Cta → Ct(a0) ∨ Ct(a1). Relative to realizers for its assumptions on t. Let inft and ueut be witnesses for t’s infinity and UEU(t), i.e., for all k inft(k) ∈ t ∧ |inft(k)| = k, |a| = |b| = ueut(k) → ak = bk. Given a, let n witness Cta. Let m := ueut(n + 1) and b := inft(m). Then i := (b)|a| determines which of the two alternatives is proved. In each case m is the required witness for Ct(ai). Hence ht(a, inft, ueut, n) =

  • inl(m)

if (b)|a| = 0, inr(m) if (b)|a| = 1.

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-26
SLIDE 26

Computational and non-computational logical connectives

Idea: fine tune the computational content of proofs, by switching

  • n and off the computational effect of logical connectives.

◮ Example: in ∀n(Even(n) → Even(S(Sn))) only the premise

Even(n) should be computationally relevant, not the ∀n.

◮ Following Ulrich Berger (1993) we distinguish between a

computational ∀c and non-computational (“uniform”) ∀nc.

◮ Similarly: →c and →nc.

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-27
SLIDE 27

We coinductively define a predicate S of arity (α) by the clause ∀nc

t (St →c t = nil ∨ St0 ∨ St1).

The greatest-fixed-point (or coinduction) axiom for S is ∀nc

t (Qt →c ∀nc t (Qt →c t = nil ∨ Qt0 ∨ Qt1) →c St).

The types are, with ι := τ(St) = C, τ := τ(Qt): ι → U + ι + ι (type of destructor for C), τ → (τ → U + τ + τ) → ι (type of corecursion operator coRτ

ι ).

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-28
SLIDE 28

Lemma

∀nc

t (Rt →c St).

Proof.

Use coinduction with R for Q. Suffices: Rt → Rt0 ∨ Rt1. From Rt we obtain UEU(t). Since Rt and Ct(nil), by “covering nodes extend” Ct0 or Ct1. Assume for example Ct0. Then Rt0, since Tree(t0) ∧ Inf(t0) ∧ UEU(t0) (cf. “properties” above). Extracted term: recall Rt := Tree(t) ∧ Inf(t) ∧ UEU(t). Hence τ(Rt) = ρ := (N → C) × (N → N).

coRρ C(inft, ueut)ρgρ→U+ρ+ρ t

, with gt defined from ht by “weakening”.

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-29
SLIDE 29

Conclusion

◮ Classical existence proofs by induction: tail recursion (CPS). ◮ Terms in T+ (⊃ T, PCF): denotational semantics. ◮ Witnesses of coinductively defined predicates: cototal ideals. ◮ Example: abstract real → stream, from ⊢ ∀nc t (Rt →c St).

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects

slide-30
SLIDE 30

References

◮ U. Berger, W. Buchholz and H.S., Refined program extraction

from classical proofs. APAL 114 (2002).

◮ U. Berger, From coinductive proofs to exact real arithmetic.

CSL 2009.

◮ J. Berger and H. Ishihara, Brouwer’s fan theorem and unique

existence in constructive analysis. MLQ 51 (2005).

◮ T. Coquand and P. Schuster, On paths and points. In prep. ◮ H. Ishihara, A note on the G¨

  • del-Gentzen translation.

Mathematical Logic Quarterly 46 (2000).

◮ D. Ratiu and H.S., Decorating proofs. To appear, Mints

volume (S. Feferman and W. Sieg, eds.), 2010.

◮ H.S., A direct proof of the equivalence between Brouwer’s fan

theorem and K¨

  • nig’s lemma with a uniqueness hypothesis.

JUCS 11 (2005).

Helmut Schwichtenberg Programs extracted from proofs: efficiency aspects