Nonuniform (Co)datatypes for Higher-Order Logic Jasmin Blanchette - - PowerPoint PPT Presentation

nonuniform co datatypes
SMART_READER_LITE
LIVE PREVIEW

Nonuniform (Co)datatypes for Higher-Order Logic Jasmin Blanchette - - PowerPoint PPT Presentation

Foundational Nonuniform (Co)datatypes for Higher-Order Logic Jasmin Blanchette Fabian Meier Andrei Popescu Dmitriy Traytel uniform datatype 'a list = Nil | Cons 'a ('a list) 1 2 3 4 2 uniform datatype 'a list = Nil |


slide-1
SLIDE 1

Foundational

Nonuniform (Co)datatypes

for

Higher-Order Logic

Jasmin Blanchette Fabian Meier Andrei Popescu Dmitriy Traytel

slide-2
SLIDE 2

'a list = Nil | Cons 'a ('a list) uniform datatype 1 2 3 4

2

slide-3
SLIDE 3

'a list = Nil | Cons 'a ('a list) uniform datatype 1 2 3 4

2

slide-4
SLIDE 4

'a list = Nil | Cons 'a ('a list) uniform datatype 1 2 3 4 'a stream = SCons 'a ('a stream) uniform codatatype 1 2 3 4 … ∞

2

slide-5
SLIDE 5

'a list = Nil | Cons 'a ('a list) uniform datatype 1 2 3 4 'a plist = PNil | PCons 'a (('a × 'a) plist) nonuniform datatype 1 (2,3) ((4,5),(6,7)) 'a stream = SCons 'a ('a stream) uniform codatatype 1 2 3 4 … ∞

2

slide-6
SLIDE 6

'a list = Nil | Cons 'a ('a list) uniform datatype 1 2 3 4 'a plist = PNil | PCons 'a (('a × 'a) plist) nonuniform datatype 1 (2,3) ((4,5),(6,7)) 'a stream = SCons 'a ('a stream) uniform codatatype 1 2 3 4 … ∞ 'a pstream = PSCons 'a (('a list) pstream) nonuniform codatatype 1 [2,3,4] [[5],[6,7,8],[9,10]] … ∞

2

slide-7
SLIDE 7

What are nonuniform types good for?

3

Mycroft Okasaki pioneering: optimization techniques bootstrapping implicit recursive slowdown

slide-8
SLIDE 8

What are nonuniform types good for?

3

Mycroft Okasaki pioneering: optimization techniques bootstrapping implicit recursive slowdown Bird Paterson Hinze Matthes Abel Uustalu Abbott Altenkirch Ghani theory: data structures finger trees generalized folds advanced (co)iteration

slide-9
SLIDE 9

What are nonuniform types good for?

3

Mycroft Okasaki pioneering: optimization techniques bootstrapping implicit recursive slowdown Benton Hur Kennedy McBride Danielsson Hirschowitz Maggesi Naves Spiwack Sozeau practice: proof assistants binders balancing lists finger trees complexity

Bird Paterson Hinze Matthes Abel Uustalu Abbott Altenkirch Ghani theory: data structures finger trees generalized folds advanced (co)iteration

slide-10
SLIDE 10

Contribution: enable users of to … define nonuniform (co)datatypes define primitively (co)recursive functions prove theorems by nonuniform (co)induction

4

1 2 3

slide-11
SLIDE 11

Contribution: enable users of to … define nonuniform (co)datatypes

'a tm = Var 'a | App ('a tm) ('a tm) | Lam (('a option) tm)

define primitively (co)recursive functions prove theorems by nonuniform (co)induction

4

1 2 3

slide-12
SLIDE 12

Contribution: enable users of to … define nonuniform (co)datatypes

'a tm = Var 'a | App ('a tm) ('a tm) | Lam (('a option) tm)

define primitively (co)recursive functions

join :: 'a tm tm => 'a tm join (Var t) = t join (App t u) = App (join t) (join u) join (Lam u) = Lam (join (maptm

(λx. case x of None => Var None | Some y => maptm Some y) u))

subst σ = join ◦ maptm σ

prove theorems by nonuniform (co)induction

4

1 2 3

slide-13
SLIDE 13

Contribution: enable users of to … define nonuniform (co)datatypes

'a tm = Var 'a | App ('a tm) ('a tm) | Lam (('a option) tm)

define primitively (co)recursive functions

join :: 'a tm tm => 'a tm join (Var t) = t join (App t u) = App (join t) (join u) join (Lam u) = Lam (join (maptm

(λx. case x of None => Var None | Some y => maptm Some y) u))

subst σ = join ◦ maptm σ

prove theorems by nonuniform (co)induction

subst τ (subst σ s) = subst (subst τ ◦ σ) s

4

1 2 3

slide-14
SLIDE 14

Contribution: enable users of to … define nonuniform (co)datatypes

'a tm = Var 'a | App ('a tm) ('a tm) | Lam (('a option) tm)

define primitively (co)recursive functions

join :: 'a tm tm => 'a tm join (Var t) = t join (App t u) = App (join t) (join u) join (Lam u) = Lam (join (maptm

(λx. case x of None => Var None | Some y => maptm Some y) u))

subst σ = join ◦ maptm σ

prove theorems by nonuniform (co)induction

subst τ (subst σ s) = subst (subst τ ◦ σ) s

4

1 2 3

B u t C

  • q

a n d A g d a h a v e h a d t h i s b u i l t i n t

  • t

h e i r l

  • g

i c s f

  • r

d e c a d e s !

slide-15
SLIDE 15

Contribution: enable users of to … define nonuniform (co)datatypes

'a tm = Var 'a | App ('a tm) ('a tm) | Lam (('a option) tm)

define primitively (co)recursive functions

join :: 'a tm tm => 'a tm join (Var t) = t join (App t u) = App (join t) (join u) join (Lam u) = Lam (join (maptm

(λx. case x of None => Var None | Some y => maptm Some y) u))

subst σ = join ◦ maptm σ

prove theorems by nonuniform (co)induction

subst τ (subst σ s) = subst (subst τ ◦ σ) s

4

1 2 3

B u t C

  • q

a n d A g d a h a v e h a d t h i s b u i l t i n t

  • t

h e i r l

  • g

i c s f

  • r

d e c a d e s ! O u r a p p r

  • a

c h i s f

  • u

n d a t i

  • n

a l

new features are reduced to existing features

slide-16
SLIDE 16

5

Foundations

slide-17
SLIDE 17

6

Simple Theory of Types

Alonzo Church 1940

types: T = ο | ι | T => T terms: simply typed λ-calculus + few built-in constants

slide-18
SLIDE 18

7

Higher-Order Logic

Mike Gordon 1988

types: T = ο | ι | T => T | 'a | (T,…,T)κ

+ nonrecursive type definitions

terms: simply typed λ-calculus + few built-in constants

+ Hilbert Choice + nonrecursive constant definitions

T existing type A≠∅ new type U Rep Abs

slide-19
SLIDE 19

8

Foundational

Uniform (Co)datatypes

for

Higher-Order Logic

Jasmin Blanchette Andrei Popescu Dmitriy Traytel et al. LICS 2012 ITP 2014 ESOP 2015 ICFP 2015 ESOP 2017

slide-20
SLIDE 20

9

Blanchette, Hölzl, Lochbihler, Panny, Popescu, Traytel ITP 2014

slide-21
SLIDE 21

9

Blanchette, Hölzl, Lochbihler, Panny, Popescu, Traytel ITP 2014

slide-22
SLIDE 22

9

Blanchette, Hölzl, Lochbihler, Panny, Popescu, Traytel ITP 2014

slide-23
SLIDE 23

9

Blanchette, Hölzl, Lochbihler, Panny, Popescu, Traytel ITP 2014

slide-24
SLIDE 24

Foundational

Nonuniform (Co)datatypes

for

Higher-Order Logic

10

slide-25
SLIDE 25

'a plist = PNil | PCons 'a (('a × 'a) plist)

11

1 (2,3) ((4,5),(6,7)) 2 1 3 4

slide-26
SLIDE 26
  • verapproximate the elements of a powerlist

'a plist = PNil | PCons 'a (('a × 'a) plist)

11

'a elem = Leaf 'a | Node ('a elem × 'a elem) 1 (2,3) ((4,5),(6,7)) 2 1 3 4

slide-27
SLIDE 27
  • verapproximate the elements of a powerlist

'a plist = PNil | PCons 'a (('a × 'a) plist)

11

'a elem = Leaf 'a | Node ('a elem × 'a elem) 1 (2,3) ((4,5),(6,7)) 2 1 3 4

slide-28
SLIDE 28
  • verapproximate the elements of a powerlist

'a plist = PNil | PCons 'a (('a × 'a) plist)

11

'a elem = Leaf 'a | Node ('a elem × 'a elem) 1 (2,3) ((4,5),(6,7)) 1 (2,3) ((4,5),(6,7)) 2 1 3 4

slide-29
SLIDE 29
  • verapproximate the elements of a powerlist

'a plist = PNil | PCons 'a (('a × 'a) plist)

11

'a elem = Leaf 'a | Node ('a elem × 'a elem) 1 (2,3) ((4,5),(6,7)) 1 (2,3) ((4,5),(6,7)) ((4,5),6) 2 1 3 4

slide-30
SLIDE 30
  • verapproximate the elements of a powerlist

'a plist = PNil | PCons 'a (('a × 'a) plist)

11

'a elem = Leaf 'a | Node ('a elem × 'a elem) 1 (2,3) ((4,5),(6,7)) 1 (2,3) ((4,5),(6,7)) ((4,5),6) full n l full n r full (n + 1) (Node (l, r)) full 0 (Leaf x) 2 1 3 4

slide-31
SLIDE 31
  • verapproximate the elements of a powerlist

'a plist = PNil | PCons 'a (('a × 'a) plist)

11

'a elem = Leaf 'a | Node ('a elem × 'a elem) 'a plist0 = PNil0 | PCons0 ('a elem) ('a plist0) 1 (2,3) ((4,5),(6,7)) 1 (2,3) ((4,5),(6,7)) ((4,5),6) full n l full n r full (n + 1) (Node (l, r)) full 0 (Leaf x) 2 1 3 4

  • verapproximate the set of all powerlists
slide-32
SLIDE 32
  • verapproximate the elements of a powerlist

'a plist = PNil | PCons 'a (('a × 'a) plist)

11

'a elem = Leaf 'a | Node ('a elem × 'a elem) 'a plist0 = PNil0 | PCons0 ('a elem) ('a plist0) 1 (2,3) ((4,5),(6,7)) 1 (2,3) ((4,5),(6,7)) ((4,5),6) full n l full n r full (n + 1) (Node (l, r)) full 0 (Leaf x) 2 1 3 4

  • verapproximate the set of all powerlists
slide-33
SLIDE 33
  • verapproximate the elements of a powerlist

'a plist = PNil | PCons 'a (('a × 'a) plist)

11

'a elem = Leaf 'a | Node ('a elem × 'a elem) 'a plist0 = PNil0 | PCons0 ('a elem) ('a plist0) 1 (2,3) ((4,5),(6,7)) 1 (2,3) ((4,5),(6,7)) (2,3) ((4,5),(6,7)) 1 (2,3) ((4,5),(6,7)) ((4,5),6) full n l full n r full (n + 1) (Node (l, r)) full 0 (Leaf x) 2 1 3 4

  • verapproximate the set of all powerlists
slide-34
SLIDE 34
  • verapproximate the elements of a powerlist

'a plist = PNil | PCons 'a (('a × 'a) plist)

11

'a elem = Leaf 'a | Node ('a elem × 'a elem) 'a plist0 = PNil0 | PCons0 ('a elem) ('a plist0) 1 (2,3) ((4,5),(6,7)) 1 (2,3) ((4,5),(6,7)) (2,3) ((4,5),(6,7)) 1 (2,3) ((4,5),(6,7)) ((4,5),6) full n l full n r full (n + 1) (Node (l, r)) full 0 (Leaf x) full n x ok (n + 1) xs

  • k n (PCons0 x xs)
  • k n PNil0

2 1 3 4

  • verapproximate the set of all powerlists
slide-35
SLIDE 35
  • verapproximate the elements of a powerlist

'a plist = PNil | PCons 'a (('a × 'a) plist)

11

'a elem = Leaf 'a | Node ('a elem × 'a elem) 'a plist0 = PNil0 | PCons0 ('a elem) ('a plist0) 1 (2,3) ((4,5),(6,7)) 1 (2,3) ((4,5),(6,7)) (2,3) ((4,5),(6,7)) 1 (2,3) ((4,5),(6,7)) ((4,5),6) full n l full n r full (n + 1) (Node (l, r)) full 0 (Leaf x) full n x ok (n + 1) xs

  • k n (PCons0 x xs)
  • k n PNil0

'a plist

{xs | ok 0 xs}

'a plist0 Rep Abs 2 1 3 4 carve out ‘ok’ powerlists

  • verapproximate the set of all powerlists
slide-36
SLIDE 36
  • verapproximate the elements of a powerlist

'a plist = PNil | PCons 'a (('a × 'a) plist)

11

'a elem = Leaf 'a | Node ('a elem × 'a elem) 'a plist0 = PNil0 | PCons0 ('a elem) ('a plist0) 1 (2,3) ((4,5),(6,7)) 1 (2,3) ((4,5),(6,7)) (2,3) ((4,5),(6,7)) 1 (2,3) ((4,5),(6,7)) ((4,5),6) full n l full n r full (n + 1) (Node (l, r)) full 0 (Leaf x) full n x ok (n + 1) xs

  • k n (PCons0 x xs)
  • k n PNil0

'a plist

{xs | ok 0 xs}

'a plist0 Rep Abs

PCons x xs = Abs (PCons0 (Leaf x) (… (Rep xs)))

2 1 3 4 carve out ‘ok’ powerlists lift constructors

  • verapproximate the set of all powerlists
slide-37
SLIDE 37

12

General construction supports:

'a biplist = Nil | Cons1 'a (('a list) biplist) | Cons2 'a (('a × 'a) biplist)

multiple recursive occurrences

slide-38
SLIDE 38

12

General construction supports:

'a biplist = Nil | Cons1 'a (('a list) biplist) | Cons2 'a (('a × 'a) biplist)

multiple recursive occurrences

('a, 'b) tplist = Nil 'b | Cons 'a (('a × 'a, 'b option) tplist)

multiple type arguments

slide-39
SLIDE 39

12

General construction supports:

'a ptree = Node 'a ('a pforest)
 'a pforest = Nil | Cons ('a ptree) (('a × 'a) pforest)

mutual definitions

'a biplist = Nil | Cons1 'a (('a list) biplist) | Cons2 'a (('a × 'a) biplist)

multiple recursive occurrences

('a, 'b) tplist = Nil 'b | Cons 'a (('a × 'a, 'b option) tplist)

multiple type arguments

slide-40
SLIDE 40

12

General construction supports:

'a ptree = Node 'a ('a pforest)
 'a pforest = Nil | Cons ('a ptree) (('a × 'a) pforest)

mutual definitions

'a biplist = Nil | Cons1 'a (('a list) biplist) | Cons2 'a (('a × 'a) biplist)

multiple recursive occurrences

('a, 'b) tplist = Nil 'b | Cons 'a (('a × 'a, 'b option) tplist)

multiple type arguments codatatypes

'a pstream = PSCons 'a (('a list) pstream) ∞

slide-41
SLIDE 41

12

General construction supports:

'a ptree = Node 'a ('a pforest)
 'a pforest = Nil | Cons ('a ptree) (('a × 'a) pforest)

mutual definitions

'a biplist = Nil | Cons1 'a (('a list) biplist) | Cons2 'a (('a × 'a) biplist)

multiple recursive occurrences

('a, 'b) tplist = Nil 'b | Cons 'a (('a × 'a, 'b option) tplist)

multiple type arguments codatatypes

'a pstream = PSCons 'a (('a list) pstream) ∞

arbitrary bounded natural functors

'a crazy = Crazy 'a ((((('a pstream) fset) crazy) multiset) list)

slide-42
SLIDE 42

Q PNil ∀(x :: 'a) (xs :: ('a × 'a) plist). Q xs → Q (PCons x xs) ∀xs :: 'a plist. Q xs

Nonuniform (Co)induction

13

HOL - a HOstile Logic for nonuniformities:

slide-43
SLIDE 43

Q PNil ∀(x :: 'a) (xs :: ('a × 'a) plist). Q xs → Q (PCons x xs) ∀xs :: 'a plist. Q xs

Nonuniform (Co)induction

13

HOL - a HOstile Logic for nonuniformities: not expressible as a HOL formula with a free variable Q

slide-44
SLIDE 44

Q PNil ∀(x :: 'a) (xs :: ('a × 'a) plist). Q xs → Q (PCons x xs) ∀xs :: 'a plist. Q xs

Nonuniform (Co)induction

13

HOL - a HOstile Logic for nonuniformities: not expressible as a HOL formula with a free variable Q

Our solution: Dynamic proof-producing procedure

For each polymorphic Q and given the polymorphic HOL theorems

  • Q satisfies a weak form of relational parametricity in 'a
  • Q PNil
  • ∀(x :: 'a) (xs :: ('a × 'a) plist). Q xs → Q (PCons x xs)
  • ur tool can prove the HOL theorem ∀xs :: 'a plist. Q xs
slide-45
SLIDE 45

Q PNil ∀(x :: 'a) (xs :: ('a × 'a) plist). Q xs → Q (PCons x xs) ∀xs :: 'a plist. Q xs

Nonuniform (Co)induction

13

HOL - a HOstile Logic for nonuniformities: not expressible as a HOL formula with a free variable Q

Nonuniform (Co)recursion

similar problems similar solutions

Our solution: Dynamic proof-producing procedure

For each polymorphic Q and given the polymorphic HOL theorems

  • Q satisfies a weak form of relational parametricity in 'a
  • Q PNil
  • ∀(x :: 'a) (xs :: ('a × 'a) plist). Q xs → Q (PCons x xs)
  • ur tool can prove the HOL theorem ∀xs :: 'a plist. Q xs
slide-46
SLIDE 46

Take Home Messages

14

It is tempting to introduce a new hot logic/language for each new feature. But this is not always necessary. But it also saves work elsewhere. (keyword: consistency) The foundational path requires work.

slide-47
SLIDE 47

Foundational

Nonuniform (Co)datatypes

for

Higher-Order Logic

Jasmin Blanchette Fabian Meier Andrei Popescu Dmitriy Traytel

Takk! Spurningar?