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 | Cons 'a ('a list) 1 2 3 4 2
uniform datatype 'a list = Nil | Cons 'a ('a list) 1 2 3 4 ∞ uniform codatatype 'a stream = SCons 'a ('a stream) … 1 2 3 4 2
uniform datatype 'a list = Nil | Cons 'a ('a list) 1 2 3 4 ∞ uniform codatatype 'a stream = SCons 'a ('a stream) … 1 2 3 4 nonuniform datatype 'a plist = PNil | PCons 'a (('a × 'a) plist) 1 (2,3) ((4,5),(6,7)) 2
uniform datatype 'a list = Nil | Cons 'a ('a list) 1 2 3 4 ∞ uniform codatatype 'a stream = SCons 'a ('a stream) … 1 2 3 4 nonuniform datatype 'a plist = PNil | PCons 'a (('a × 'a) plist) 1 (2,3) ((4,5),(6,7)) ∞ nonuniform codatatype 'a pstream = PSCons 'a (('a list) pstream) … 1 [2,3,4] [[5],[6,7,8],[9,10]] 2
What are nonuniform types good for? pioneering: optimization techniques Mycroft bootstrapping Okasaki implicit recursive slowdown 3
What are nonuniform types good for? pioneering: optimization techniques Mycroft bootstrapping Okasaki implicit recursive slowdown theory: data structures Bird Paterson Hinze finger trees Matthes Abel Uustalu generalized folds Abbott Altenkirch Ghani advanced (co)iteration … 3
What are nonuniform types good for? pioneering: optimization techniques Mycroft bootstrapping Okasaki implicit recursive slowdown theory: data structures Bird Paterson Hinze finger trees Matthes Abel Uustalu generalized folds Abbott Altenkirch Ghani advanced (co)iteration … practice: proof assistants binders Benton Hur Kennedy McBride balancing lists Danielsson Hirschowitz Maggesi finger trees Naves Spiwack Sozeau … complexity 3
Contribution: enable users of to … define nonuniform (co)datatypes 1 define primitively (co)recursive functions 2 prove theorems by nonuniform (co)induction 3 4
Contribution: enable users of to … define nonuniform (co)datatypes 1 'a tm = Var 'a | App ('a tm) ('a tm) | Lam (('a option) tm) define primitively (co)recursive functions 2 prove theorems by nonuniform (co)induction 3 4
Contribution: enable users of to … define nonuniform (co)datatypes 1 'a tm = Var 'a | App ('a tm) ('a tm) | Lam (('a option) tm) define primitively (co)recursive functions 2 join :: 'a tm tm => 'a tm join (Var t) = t join (App t u) = App (join t) (join u) join (Lam u) = Lam (join (map tm ( λ x. case x of None => Var None | Some y => map tm Some y) u)) subst σ = join ◦ map tm σ prove theorems by nonuniform (co)induction 3 4
Contribution: enable users of to … define nonuniform (co)datatypes 1 'a tm = Var 'a | App ('a tm) ('a tm) | Lam (('a option) tm) define primitively (co)recursive functions 2 join :: 'a tm tm => 'a tm join (Var t) = t join (App t u) = App (join t) (join u) join (Lam u) = Lam (join (map tm ( λ x. case x of None => Var None | Some y => map tm Some y) u)) subst σ = join ◦ map tm σ prove theorems by nonuniform (co)induction 3 subst τ (subst σ s) = subst (subst τ ◦ σ ) s 4
A g d a B u t C o q a n d Contribution: enable users of to … define nonuniform (co)datatypes 1 'a tm = Var 'a | App ('a tm) ('a tm) | Lam (('a option) tm) b u i l t h a v e h a d t h i s define primitively (co)recursive functions 2 o g i c s i n t o t h e i r l join :: 'a tm tm => 'a tm join (Var t) = t s ! f o r d e c a d e join (App t u) = App (join t) (join u) join (Lam u) = Lam (join (map tm ( λ x. case x of None => Var None | Some y => map tm Some y) u)) subst σ = join ◦ map tm σ prove theorems by nonuniform (co)induction 3 subst τ (subst σ s) = subst (subst τ ◦ σ ) s 4
A g d a B u t C o q a n d Contribution: enable users of to … O u r a p p r o a c h i s define nonuniform (co)datatypes 1 'a tm = Var 'a | App ('a tm) ('a tm) | Lam (('a option) tm) f o u n d a t i o n a l b u i l t h a v e h a d t h i s new features are reduced define primitively (co)recursive functions 2 o g i c s i n t o t h e i r l to existing features join :: 'a tm tm => 'a tm join (Var t) = t s ! f o r d e c a d e join (App t u) = App (join t) (join u) join (Lam u) = Lam (join (map tm ( λ x. case x of None => Var None | Some y => map tm Some y) u)) subst σ = join ◦ map tm σ prove theorems by nonuniform (co)induction 3 subst τ (subst σ s) = subst (subst τ ◦ σ ) s 4
Foundations 5
Simple Theory of Types Alonzo Church 1940 types: T = ο | ι | T => T terms: simply typed λ -calculus + few built-in constants 6
Higher-Order Logic Mike Gordon 1988 types: T = ο | ι | T => T | 'a | (T,…,T) κ + nonrecursive type definitions U Rep T A ≠ ∅ existing type new type Abs terms: simply typed λ -calculus + few built-in constants + Hilbert Choice + nonrecursive constant definitions 7
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 8
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 9
Foundational Nonuniform (Co)datatypes for Higher-Order Logic 10
'a plist = PNil | PCons 'a (('a × 'a) plist) 1 (2,3) ((4,5),(6,7)) 1 2 3 4 11
'a plist = PNil | PCons 'a (('a × 'a) plist) 1 (2,3) ((4,5),(6,7)) 1 overapproximate the elements of a powerlist 'a elem = Leaf 'a | Node ('a elem × 'a elem) 2 3 4 11
'a plist = PNil | PCons 'a (('a × 'a) plist) 1 (2,3) ((4,5),(6,7)) 1 overapproximate the elements of a powerlist 'a elem = Leaf 'a | Node ('a elem × 'a elem) 2 3 4 11
'a plist = PNil | PCons 'a (('a × 'a) plist) 1 (2,3) ((4,5),(6,7)) 1 overapproximate the elements of a powerlist 'a elem = Leaf 'a | Node ('a elem × 'a elem) 1 (2,3) ((4,5),(6,7)) 2 3 4 11
'a plist = PNil | PCons 'a (('a × 'a) plist) 1 (2,3) ((4,5),(6,7)) 1 overapproximate the elements of a powerlist 'a elem = Leaf 'a | Node ('a elem × 'a elem) 1 (2,3) ((4,5),(6,7)) ((4,5),6) 2 3 4 11
'a plist = PNil | PCons 'a (('a × 'a) plist) 1 (2,3) ((4,5),(6,7)) 1 overapproximate the elements of a powerlist 'a elem = Leaf 'a | Node ('a elem × 'a elem) 1 (2,3) ((4,5),(6,7)) ((4,5),6) full n l full n r full 0 (Leaf x) full (n + 1) (Node (l, r)) 2 3 4 11
'a plist = PNil | PCons 'a (('a × 'a) plist) 1 (2,3) ((4,5),(6,7)) 1 overapproximate the elements of a powerlist 'a elem = Leaf 'a | Node ('a elem × 'a elem) 1 (2,3) ((4,5),(6,7)) ((4,5),6) full n l full n r full 0 (Leaf x) full (n + 1) (Node (l, r)) 2 overapproximate the set of all powerlists 'a plist 0 = PNil 0 | PCons 0 ('a elem) ('a plist 0 ) 3 4 11
'a plist = PNil | PCons 'a (('a × 'a) plist) 1 (2,3) ((4,5),(6,7)) 1 overapproximate the elements of a powerlist 'a elem = Leaf 'a | Node ('a elem × 'a elem) 1 (2,3) ((4,5),(6,7)) ((4,5),6) full n l full n r full 0 (Leaf x) full (n + 1) (Node (l, r)) 2 overapproximate the set of all powerlists 'a plist 0 = PNil 0 | PCons 0 ('a elem) ('a plist 0 ) 3 4 11
'a plist = PNil | PCons 'a (('a × 'a) plist) 1 (2,3) ((4,5),(6,7)) 1 overapproximate the elements of a powerlist 'a elem = Leaf 'a | Node ('a elem × 'a elem) 1 (2,3) ((4,5),(6,7)) ((4,5),6) full n l full n r full 0 (Leaf x) full (n + 1) (Node (l, r)) 2 overapproximate the set of all powerlists 'a plist 0 = PNil 0 | PCons 0 ('a elem) ('a plist 0 ) 1 (2,3) ((4,5),(6,7)) ((4,5),(6,7)) (2,3) 3 4 11
'a plist = PNil | PCons 'a (('a × 'a) plist) 1 (2,3) ((4,5),(6,7)) 1 overapproximate the elements of a powerlist 'a elem = Leaf 'a | Node ('a elem × 'a elem) 1 (2,3) ((4,5),(6,7)) ((4,5),6) full n l full n r full 0 (Leaf x) full (n + 1) (Node (l, r)) 2 overapproximate the set of all powerlists 'a plist 0 = PNil 0 | PCons 0 ('a elem) ('a plist 0 ) 1 (2,3) ((4,5),(6,7)) ((4,5),(6,7)) (2,3) full n x ok (n + 1) xs ok n PNil 0 ok n (PCons 0 x xs) 3 4 11
'a plist = PNil | PCons 'a (('a × 'a) plist) 1 (2,3) ((4,5),(6,7)) 1 overapproximate the elements of a powerlist 'a elem = Leaf 'a | Node ('a elem × 'a elem) 1 (2,3) ((4,5),(6,7)) ((4,5),6) full n l full n r full 0 (Leaf x) full (n + 1) (Node (l, r)) 2 overapproximate the set of all powerlists 'a plist 0 = PNil 0 | PCons 0 ('a elem) ('a plist 0 ) 1 (2,3) ((4,5),(6,7)) ((4,5),(6,7)) (2,3) full n x ok (n + 1) xs ok n PNil 0 ok n (PCons 0 x xs) 3 carve out ‘ok’ powerlists 4 'a plist 0 Rep 'a plist {xs | ok 0 xs} Abs 11
Recommend
More recommend