Undecidability of Higher-Order Unification Formalised in Coq Simon - - PowerPoint PPT Presentation

undecidability of higher order unification formalised in
SMART_READER_LITE
LIVE PREVIEW

Undecidability of Higher-Order Unification Formalised in Coq Simon - - PowerPoint PPT Presentation

Undecidability of Higher-Order Unification Formalised in Coq Simon Spies, Yannick Forster 20 January 2020 CPP20 saarland university computer science Definition Undecidability Fragments Discussion Extending the Coq Library of


slide-1
SLIDE 1

Undecidability of Higher-Order Unification Formalised in Coq

Simon Spies, Yannick Forster 20 January 2020 CPP’20

computer science

saarland

university

slide-2
SLIDE 2

2 Definition Undecidability Fragments Discussion

Extending the Coq Library of Undecidable Problems

TM H10 PCP wCBV Library of Undecidable Problems1 + U Higher-Order Unification

1For an overview of the library see the talk at 4pm on Saturday at CoqPL

slide-3
SLIDE 3

3 Definition Undecidability Fragments Discussion

Higher-Order Unification in Action

slide-4
SLIDE 4

3 Definition Undecidability Fragments Discussion

Higher-Order Unification in Action

slide-5
SLIDE 5

3 Definition Undecidability Fragments Discussion

Higher-Order Unification in Action

slide-6
SLIDE 6

3 Definition Undecidability Fragments Discussion

Higher-Order Unification in Action

slide-7
SLIDE 7

4 Definition Undecidability Fragments Discussion

Higher-Order Unification in Theory

Instance P : N → P ⊢ (∀n. P n)

?

= (∀n. n + 0 = n) : P containing constants, bound variables, free variables, and types.

slide-8
SLIDE 8

4 Definition Undecidability Fragments Discussion

Higher-Order Unification in Theory

Instance P : N → P ⊢ (∀n. P n)

?

= (∀n. n + 0 = n) : P containing constants, bound variables, free variables, and types. Solution The substitution (λn.n + 0 = n)/P since (∀n. (λn.n + 0 = n) n) ≡β (∀n. n + 0 = n)

slide-9
SLIDE 9

5 Definition Undecidability Fragments Discussion

Why is this hard?

slide-10
SLIDE 10

5 Definition Undecidability Fragments Discussion

Why is this hard?

slide-11
SLIDE 11

5 Definition Undecidability Fragments Discussion

Why is this hard?

slide-12
SLIDE 12

6 Definition Undecidability Fragments Discussion

Overview

slide-13
SLIDE 13

6 Definition Undecidability Fragments Discussion

Overview

Huet (1973)

PCP U3+k PCP Post-correspondence problem

slide-14
SLIDE 14

6 Definition Undecidability Fragments Discussion

Overview

Huet (1973)

PCP U3+k

Goldfarb (1981)

H10 U2 H10 Hilbert’s tenth problem PCP Post-correspondence problem

slide-15
SLIDE 15

6 Definition Undecidability Fragments Discussion

Overview

Huet (1973)

PCP U3+k

Goldfarb (1981)

H10 U2

Dowek (2001)

H10 U H10 Hilbert’s tenth problem PCP Post-correspondence problem

slide-16
SLIDE 16

6 Definition Undecidability Fragments Discussion

Overview

Huet (1973)

PCP U3+k

Goldfarb (1981)

H10 U2

Dowek (2001)

H10 U Our Contributions

  • 1. Coq formalisation
  • 2. Simplification of Goldfarb’s

proof

  • 3. Simplification of Huet’s proof
  • 4. Same Calculus

H10 Hilbert’s tenth problem PCP Post-correspondence problem

slide-17
SLIDE 17

7 Definition Undecidability Fragments Discussion

Simply-Typed λ-Calculus

s, t ::= x | c | λx.s | s t (c : C) A, B ::= α | A → B Γ, ∆ ::= x1 : A1, . . . , xn : An Equality: β-equivalence s ≡β t Substitution: capture-avoiding s[σ] Typing: Curry-style Γ ⊢ s : A

slide-18
SLIDE 18

8 Definition Undecidability Fragments Discussion

Higher-Order Unification U (Γ ⊢ s

?

= t : A)

slide-19
SLIDE 19

8 Definition Undecidability Fragments Discussion

Higher-Order Unification U (Γ ⊢ s

?

= t : A) := ∃σ s[σ] ≡β t[σ]

slide-20
SLIDE 20

8 Definition Undecidability Fragments Discussion

Higher-Order Unification U (Γ ⊢ s

?

= t : A) := ∃σ∆. ∆ ⊢ σ : Γ and s[σ] ≡β t[σ]

where ∆ ⊢ σ : Γ := ∀(x : A) ∈ Γ. ∆ ⊢ σx : A

slide-21
SLIDE 21

9 Definition Undecidability Fragments Discussion

Traditional Undecidability

TM H10 PCP wCBV U Higher-Order Unification Undecidable Problems P undec. iff there is no TM deciding P P Q iff there is a TM computable function f such that ∀x. P(x) iff Q(f(x))

slide-22
SLIDE 22

10 Definition Undecidability Fragments Discussion

Synthetic Undecidabililty

TM H10 PCP wCBV U Higher-Order Unification Undecidable Problems P undec. iff TM P P Q iff there is a Coq function f such that ∀x. P(x) iff Q(f(x))

slide-23
SLIDE 23

11 Definition Undecidability Fragments Discussion

Reduction

H10

  • U
slide-24
SLIDE 24

11 Definition Undecidability Fragments Discussion

Reduction

H10

  • SU
  • U

SU ({Γ ⊢ si

?

= ti : Ai | i = 1, . . . , n}) := ∃σ∆. ∆ ⊢ σ : Γ and ∀i. si[σ] ≡β ti[σ]

slide-25
SLIDE 25

12 Definition Undecidability Fragments Discussion

Hilbert’s tenth problem

Diophantine Equations d ::= x ˙ = 1 | x + y ˙ = z | x · y ˙ = z θ x ˙ = 1 iff θx = 1 θ x + y ˙ = z iff θx + θy = θz θ x · y ˙ = z iff θx · θy = θz

slide-26
SLIDE 26

12 Definition Undecidability Fragments Discussion

Hilbert’s tenth problem H10(D) := ∃θ.∀d ∈ D. θ d

Diophantine Equations d ::= x ˙ = 1 | x + y ˙ = z | x · y ˙ = z θ x ˙ = 1 iff θx = 1 θ x + y ˙ = z iff θx + θy = θz θ x · y ˙ = z iff θx · θy = θz

slide-27
SLIDE 27

13 Definition Undecidability Fragments Discussion

H10 → SU following Dowek (2001)

H10 SU

slide-28
SLIDE 28

13 Definition Undecidability Fragments Discussion

H10 → SU following Dowek (2001)

H10(D) iff SU(f(D))

slide-29
SLIDE 29

13 Definition Undecidability Fragments Discussion

H10 → SU following Dowek (2001)

H10(D) iff SU(f(D))

where f is given by f(x ˙ = 1) := x

?

= 1cn f(x + y ˙ = z) := x ⊕ y

?

= z f(x · y ˙ = z) := x ⊗ y

?

= z and for every variable x a characteristic equation CN x. Church Numerals ncn := λaf.fn a ⊕ faithful ⊗ faithful

slide-30
SLIDE 30

14 Definition Undecidability Fragments Discussion

Fragments

x ⊕ y

?

= z λaf.x (y a f) f

?

= z where x, y, z : α → (α → α) → α

slide-31
SLIDE 31

14 Definition Undecidability Fragments Discussion

Fragments

Third-Order Unification x ⊕ y

?

= z λaf.x (y a f) f

?

= z where x, y, z : α → (α → α) → α

slide-32
SLIDE 32

14 Definition Undecidability Fragments Discussion

Fragments

First-Order Unification g u a

?

= g a v g a v

?

= w g u a

?

= u Third-Order Unification x ⊕ y

?

= z λaf.x (y a f) f

?

= z where g : α → α → α a : α x, y, z : α → (α → α) → α u, v, w : α

slide-33
SLIDE 33

14 Definition Undecidability Fragments Discussion

Fragments

First-Order Unification g u a

?

= g a v g a v

?

= w g u a

?

= u Second-Order Unification g a

?

= h a h a

?

= h (h a) Third-Order Unification x ⊕ y

?

= z λaf.x (y a f) f

?

= z where g : α → α → α a : α x, y, z : α → (α → α) → α u, v, w : α h : α → α

slide-34
SLIDE 34

15 Definition Undecidability Fragments Discussion

Nth-Order Unification Un (Γ ⊢n s

?

= t : A) := ∃σ∆. ∆ ⊢n σ : Γ and s[σ] ≡β t[σ]

where ∆ ⊢n σ : Γ := ∀(x : A) ∈ Γ. ∆ ⊢n σx : A

slide-35
SLIDE 35

16 Definition Undecidability Fragments Discussion

Conservativity

Conservativity Un id Un+k id U for n ≥ 1, k ≥ 0 Corollary U1 id U2 id U2+k id U

slide-36
SLIDE 36

17 Definition Undecidability Fragments Discussion

Second-Order Undecidability following Goldfarb (1981)

H10 U2

with constants g : α → α → α and a : α.

slide-37
SLIDE 37

18 Definition Undecidability Fragments Discussion

Goldfarb Numerals

ncn ncn := λaf.fn a to ngn ngn := λa.Sn a where S := g a with g : α → α → α and a : α

slide-38
SLIDE 38

18 Definition Undecidability Fragments Discussion

Goldfarb Numerals

ncn ncn := λaf.fn a to ngn ngn := λa.Sn a where S := g a with g : α → α → α and a : α Operations ✓ addition ✓ characteristic equation ✗ multiplication s ⊗ t := λaf.s a (λb.t b f)

  • 3rd-order
slide-39
SLIDE 39

19 Definition Undecidability Fragments Discussion

Multiplication

Following Goldfarb (1981), the equation x · y ˙ = z is encoded as λuv.Gxyz (g (g (z u) (x v)) a) u v

?

= λuv.g (g u v) (Gxyz a (y u) (S v)) where Gxyz : α → α → α → α and x, y, z : α → α Why? Explanation in the paper.

slide-40
SLIDE 40

20 Definition Undecidability Fragments Discussion

Contributions in the context of the library

TM H10 U2 U2+k U

Library Goldfarb Conservativity Recall P undec. iff TM P P Q iff there is a Coq function f such that ∀x. P(x) iff Q(f(x))

slide-41
SLIDE 41

21 Definition Undecidability Fragments Discussion

  • Furthermore. . .

First-Order Unification U1 is decidable Simplifying Huet (1973) PCP U3 simplified to MPCP U3 Techniques for treating constants similar to Statman (1981) U{g,a}

2

U{g}

2

U{g}

3

U∅

3

U, SU, Un, and SUn are enumerable Future Work Decidability of monadic 2nd-order unification; Farmer (1988) Huet’s unification procedure; Huet (1975)

slide-42
SLIDE 42

22 Definition Undecidability Fragments Discussion

Formalisation

Details De Bruijn indices Normalisation for the STLC Constant Replacement Meta Theory of the STLC Coq Code Unification 3000 Undecidability 450 Second-Order 1000 Other 3000 Total 7450 Tools ♥ Autosubst 2 used for generating terms and substitution ♥ Equations used for defining first-order unification algorithm ♥ Setoid Rewriting used for reasoning about β-equivalence

slide-43
SLIDE 43

23 Definition Undecidability Fragments Discussion

Coq Library of Undecidable Problems

TM H10 U2 U2+k U PCP wCBV + ??? Your Contribution Library under uds-psl on Github and 4pm on Saturday at CoqPL

slide-44
SLIDE 44

24 Definition Undecidability Fragments Discussion

References I

Dowek, G.

  • 2001. Higher-order unification and matching. Handbook of automated reasoning,

2:1009–1062. Farmer, W. M.

  • 1988. A unification algorithm for second-order monadic terms. Annals of Pure and applied

Logic, 39(2):131–174. Forster, Y., D. Kirst, and G. Smolka

  • 2019. On synthetic undecidability in Coq, with an application to the Entscheidungsproblem.

In International Conference on Certified Programs and Proofs. Goldfarb, W. D.

  • 1981. The undecidability of the second-order unification problem. Theoretical Computer

Science, 13:225–230.

slide-45
SLIDE 45

25 Definition Undecidability Fragments Discussion

References II

Huet, G. P.

  • 1973. The undecidability of unification in third order logic. Information and control,

22(3):257–267. Huet, G. P.

  • 1975. A unification algorithm for typed λ-calculus. Theoretical Computer Science,

1(1):27–57. Snyder, W. and J. H. Gallier

  • 1989. Higher order unification revisited: Complete sets of transformations. Technical

Reports (CIS), P. 778. Statman, R.

  • 1981. On the existence of closed terms in the typed λ calculus II: Transformations of

unification problems. Theoretical Computer Science, 15(3):329–338.

slide-46
SLIDE 46

26

Characteristic Equation

Iteration fulfills fn(fa) = f(fna) We can show: Let s be normal. λaf.s (f a) f ≡β λaf.f (s a f) iff s = ncn for some n : N where ncn := λaf.fn a. Characteristic Equation CN x := λaf.x (f a) f

?

= λaf.f (x a f)

slide-47
SLIDE 47

27

SU U

SU(E) iff U(f(E))

Proof.

Pick f := {Γ ⊢ si

?

= ti : Ai | i = 1, . . . , n} →

Γ ⊢ λh.h s1 · · · sn

?

= λh.h t1 · · · tn : A

where A = (A1 → · · · → An → α) → α. Follows with: h u1 · · · un ≡β h v1 · · · vn iff ∀i. ui ≡β vi

slide-48
SLIDE 48

28

Multiplication

Multiplication sequence (0, 0), (n, 1), (2n, 2), · · · , (m · n, m) generated by m · n = p iff ∃X. (0, 0) :: map step X = X + +[(p, m)] where step(a, i) := (a + n, i + 1).

slide-49
SLIDE 49

29

Modified Post Correspondence Problem — MPCP

Given l0 r0 and l1 r1 · · · ln rn

1 n

Find Ordering

i1, . . . , ik

Such that l0li1 · · · lik = r0ri1 · · · rik

slide-50
SLIDE 50

30

Simplification of Huet’s Proof

Original

λu1u0h.h (f l0 · · · ln) (f u1 · · · u1)

?

= λu1u0h.h (f l0 · · · ln) (u1 (d u1)) where f : (α → α)n+1 → α → α and d : (α → α) → α. vs.

Simplification

λu1u0.l0 (f l0 · · · ln)

?

= λu1u0.r0 (f r0 · · · rn) where f : (α → α)n+1 → α → α.

slide-51
SLIDE 51

31

Meta Theory of STLC

Small Challenges If h s ≡β h t, then s ≡β t. If s ≻ s′ and isLam(head s′) then isLam(head s). If s t ≻∗ v then s ≻∗ s′, t ≻∗ t′, and v = s′ t′ for some s′, t′

  • r s ≻∗ λx.s′ and isLam (head s) for some s′.

If s1 s2 ≡β t1 t2, isVar (head s1), and isVar (head t1), then s1 ≡β t1 and s2 ≡β t2. List Operations S t nil t = t (s :: S) t = s (S t) s T s nil = s s (t :: T) = (T s) t ΛX. s Λnil. s = s Λx :: X. s = λx.ΛX. s

slide-52
SLIDE 52

32

Conservativity — Un ⊆ U

Let Γ ⊢n s

?

= t : A. s[σ] ≡β t[σ] for some Σ ⊢n σ : Γ iff s[σ] ≡β t[σ] for some ∆ ⊢ σ : Γ

Proof Sketch.

Replace free variables and constants not of order n with first-order terms. For example, x : (α → α) → α is replaced by λx1.z where z : α and g : α → α → α is replaced by λx1x2.z. Normalise the result.

slide-53
SLIDE 53

33

Adding Constants

UC

n UD n

if C ⊆ D

Proof Sketch.

Replace constants d ∈ D − C with first-order terms, see conservativity.

slide-54
SLIDE 54

34

Removing Constans

UD

n UC n

if C ⊆ D and ∀d ∈ C. ord (Ωd) < n

Proof Sketch.

Let C = {g} and D = {a, g}. g x

?

= g a where x : α

  • λxa.g (x xa)

?

= λxa.g xa where x : α → α