Foundational
Nonuniform (Co)datatypes
for
Higher-Order Logic
Jasmin Blanchette Fabian Meier Andrei Popescu Dmitriy Traytel
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 |
for
Jasmin Blanchette Fabian Meier Andrei Popescu Dmitriy Traytel
'a list = Nil | Cons 'a ('a list) uniform datatype 1 2 3 4
2
'a list = Nil | Cons 'a ('a list) uniform datatype 1 2 3 4
2
'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
'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
'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
3
Mycroft Okasaki pioneering: optimization techniques bootstrapping implicit recursive slowdown
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
…
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
…
Contribution: enable users of to … define nonuniform (co)datatypes define primitively (co)recursive functions prove theorems by nonuniform (co)induction
4
1 2 3
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
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
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
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
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
new features are reduced to existing features
5
6
Alonzo Church 1940
7
Mike Gordon 1988
+ nonrecursive type definitions
+ Hilbert Choice + nonrecursive constant definitions
T existing type A≠∅ new type U Rep Abs
8
Foundational
for
Higher-Order Logic
Jasmin Blanchette Andrei Popescu Dmitriy Traytel et al. LICS 2012 ITP 2014 ESOP 2015 ICFP 2015 ESOP 2017
9
Blanchette, Hölzl, Lochbihler, Panny, Popescu, Traytel ITP 2014
9
Blanchette, Hölzl, Lochbihler, Panny, Popescu, Traytel ITP 2014
9
Blanchette, Hölzl, Lochbihler, Panny, Popescu, Traytel ITP 2014
9
Blanchette, Hölzl, Lochbihler, Panny, Popescu, Traytel ITP 2014
for
10
'a plist = PNil | PCons 'a (('a × 'a) plist)
11
1 (2,3) ((4,5),(6,7)) 2 1 3 4
'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
'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
'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
'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
'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
'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
'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
'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
'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
2 1 3 4
'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
'a plist
{xs | ok 0 xs}
'a plist0 Rep Abs 2 1 3 4 carve out ‘ok’ powerlists
'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
'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
12
General construction supports:
'a biplist = Nil | Cons1 'a (('a list) biplist) | Cons2 'a (('a × 'a) biplist)
multiple recursive occurrences
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
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
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) ∞
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)
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:
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
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 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
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.
for
Jasmin Blanchette Fabian Meier Andrei Popescu Dmitriy Traytel