Quotients of Bounded Natural Functors Basil Frer Andreas Lochbihler - - PowerPoint PPT Presentation

quotients of bounded natural functors
SMART_READER_LITE
LIVE PREVIEW

Quotients of Bounded Natural Functors Basil Frer Andreas Lochbihler - - PowerPoint PPT Presentation

Quotients of Bounded Natural Functors Basil Frer Andreas Lochbihler Joshua Schneider Dmitriy Traytel 1 Dramatis personae Isabelle HOL = Andreas Dmitriy Isabelle Isabelle Expert Working Formalizer Proof


slide-1
SLIDE 1

Quotients of Bounded Natural Functors

Basil Fürer Andreas Lochbihler Joshua Schneider Dmitriy Traytel

1

slide-2
SLIDE 2

Dramatis personae

λ → ∀

=

Isabelle

β α

HOL

Andreas Dmitriy Isabelle Isabelle Expert Working Formalizer Proof Assistant and Narrator

The characters and incidents portrayed and the names used herein are fictitious and any re- semblance to the names, character, or history of any person is coincidental and unintentional.

2

slide-3
SLIDE 3

A formalization problem

datatype a re = Atom a | Alt (a re) (a re) | Conc (a re) (a re) | Star (a re)

3

slide-4
SLIDE 4

A formalization problem

datatype a re = Atom a | Alt (a re) (a re) | Conc (a re) (a re) | Star (a re) datatype ldl = Prop string | And ldl ldl | Neg ldl | Match (ldl re)

3

slide-5
SLIDE 5

A formalization problem

datatype a re = Atom a | Alt (a re) (a re) | Conc (a re) (a re) | Star (a re) inductive ∼ACI where Alt (Alt r s) t ∼ACI Alt r (Alt s t) Alt r s ∼ACI Alt s r Alt r r ∼ACI r r ∼ACI r’ s ∼ACI s’ Alt r s ∼ACI Alt r’ s’ r ∼ACI r’ s ∼ACI s’ Conc r s ∼ACI Conc r’ s’ r ∼ACI r’ Star r ∼ACI Star r’ r ∼ACI r r ∼ACI s s ∼ACI r r ∼ACI s s ∼ACI t r ∼ACI t datatype ldl = Prop string | And ldl ldl | Neg ldl | Match (ldl re)

3

slide-6
SLIDE 6

A formalization problem

datatype a re = Atom a | Alt (a re) (a re) | Conc (a re) (a re) | Star (a re) inductive ∼ACI where Alt (Alt r s) t ∼ACI Alt r (Alt s t) Alt r s ∼ACI Alt s r Alt r r ∼ACI r r ∼ACI r’ s ∼ACI s’ Alt r s ∼ACI Alt r’ s’ r ∼ACI r’ s ∼ACI s’ Conc r s ∼ACI Conc r’ s’ r ∼ACI r’ Star r ∼ACI Star r’ r ∼ACI r r ∼ACI s s ∼ACI r r ∼ACI s s ∼ACI t r ∼ACI t quotient_type a reACI = a re/ ∼ACI datatype ldl = Prop string | And ldl ldl | Neg ldl | Match (ldl reACI)

3

slide-7
SLIDE 7

A formalization problem

datatype a re = Atom a | Alt (a re) (a re) | Conc (a re) (a re) | Star (a re) inductive ∼ACI where Alt (Alt r s) t ∼ACI Alt r (Alt s t) Alt r s ∼ACI Alt s r Alt r r ∼ACI r r ∼ACI r’ s ∼ACI s’ Alt r s ∼ACI Alt r’ s’ r ∼ACI r’ s ∼ACI s’ Conc r s ∼ACI Conc r’ s’ r ∼ACI r’ Star r ∼ACI Star r’ r ∼ACI r r ∼ACI s s ∼ACI r r ∼ACI s s ∼ACI t r ∼ACI t quotient_type a reACI = a re/ ∼ACI datatype ldl = Prop string | And ldl ldl | Neg ldl | Match (ldl reACI) Unsupported recursive occurrence

  • f type ldl via type constructor

reACI in type expression ldl reACI. Use the bnf command to register reACI as a bounded natural functor to allow nested (co)recursion through it.

3

slide-8
SLIDE 8

Interlude: Contribution

Identified sufficient conditions on when quotients of BNFs are BNFs

Relevant for (co)datatypes, relational parametricity, refinement

4

slide-9
SLIDE 9

Interlude: Contribution

Identified sufficient conditions on when quotients of BNFs are BNFs

Relevant for (co)datatypes, relational parametricity, refinement

Automated BNF preservation proofs via lift_bnf command in

λ → ∀

=

Isabelle

β α

HOL 4

slide-10
SLIDE 10

Datatype recursion worries

Unsupported recursive occurrence

  • f type ldl via type constructor

reACI in type expression ldl reACI. Use the bnf command to register reACI as a bounded natural functor to allow nested (co)recursion through it.

5

slide-11
SLIDE 11

Datatype recursion worries

Unsupported recursive occurrence

  • f type ldl via type constructor

reACI in type expression ldl reACI. Use the bnf command to register reACI as a bounded natural functor to allow nested (co)recursion through it. datatype bad = C (bad set) | ... C :: bad set ⇒ bad injective

5

slide-12
SLIDE 12

Datatype recursion worries

Unsupported recursive occurrence

  • f type ldl via type constructor

reACI in type expression ldl reACI. Use the bnf command to register reACI as a bounded natural functor to allow nested (co)recursion through it. datatype bad = C (bad set) | ... C :: bad set ⇒ bad injective

λ → ∀

=

Isabelle

β α

HOL

Datatypes may recurse

  • nly through BNFs

5

slide-13
SLIDE 13

Bounded Natural Functors (BNF)

A F(A)

1 2 3 [] [1] [2,3] [3,3] [1,2,3]

F

6

slide-14
SLIDE 14

Bounded Natural Functors (BNF)

A F(A)

1 2 3 [] [1] [2,3] [3,3] [1,2,3]

B F(B)

a b [] [a] [b,b] [a,b,b] [a,b]

F F

6

slide-15
SLIDE 15

Bounded Natural Functors (BNF)

A F(A)

1 2 3 [] [1] [2,3] [3,3] [1,2,3]

B F(B)

a b [] [a] [b,b] [a,b,b] [a,b]

F F f mapF f Functor mapF id = id mapF g ◦ mapF f = mapF (g ◦ f)

6

slide-16
SLIDE 16

Bounded Natural Functors (BNF)

A F(A)

1 2 3 [] [1] [2,3] [3,3] [1,2,3]

B F(B)

a b [] [a] [b,b] [a,b,b] [a,b]

F F f mapF f setF Functor mapF id = id mapF g ◦ mapF f = mapF (g ◦ f) Bound |setF x| < ℵ

6

slide-17
SLIDE 17

Bounded Natural Functors (BNF)

A F(A)

1 2 3 [] [1] [2,3] [3,3] [1,2,3]

B F(B)

a b [] [a] [b,b] [a,b,b] [a,b]

F F f mapF f setF Functor mapF id = id mapF g ◦ mapF f = mapF (g ◦ f) Bound |setF x| < ℵ Natural setF (mapF f x) = f〈setF x〉 ∀x ∈ setF x. f x = g x mapF f x = mapF g x

6

slide-18
SLIDE 18

Bounded Natural Functors (BNF)

A F(A)

1 2 3 [] [1] [2,3] [3,3] [1,2,3]

B F(B)

a b [] [a] [b,b] [a,b,b] [a,b]

F F f mapF f setF Functor mapF id = id mapF g ◦ mapF f = mapF (g ◦ f) Bound |setF x| < ℵ Natural setF (mapF f x) = f〈setF x〉 ∀x ∈ setF x. f x = g x mapF f x = mapF g x F(

  • A) =
  • F〈A〉

6

slide-19
SLIDE 19

Bounded Natural Functors (BNF)

A F(A)

1 2 3 [] [1] [2,3] [3,3] [1,2,3]

B F(B)

a b [] [a] [b,b] [a,b,b] [a,b]

F F f mapF f setF Functor mapF id = id mapF g ◦ mapF f = mapF (g ◦ f) Bound |setF x| < ℵ Natural setF (mapF f x) = f〈setF x〉 ∀x ∈ setF x. f x = g x mapF f x = mapF g x F(

  • A) =
  • F〈A〉

R relF R Relator (x,y) ∈ relF R = ∃z ∈ F(R). mapF π1 z = x ∧ mapF π2 z = y relF R • relF S = relF (R • S)

6

slide-20
SLIDE 20

Closure properties of BNF

Basic BNFs Derived BNFs Non-BNFs _ + _ _ × _ τ ⇒ _ _ set _ ⇒ τ

7

slide-21
SLIDE 21

Closure properties of BNF

Basic BNFs Derived BNFs Non-BNFs _ + _ _ × _ τ ⇒ _ _ set _ ⇒ τ composition

unit + _ × _

datatypes

_ list

codatatypes

_ stream

subtypes∗

_ balanced-tree

∗Conditions apply.

7

slide-22
SLIDE 22

Viewing reACI as a subtype

fun nfACI :: a re ⇒ a re where ... lemma r ∼ACI s ←→ nfACI r = nfACI s 〈proof 〉 typedef a reACI = {nfACI r | r :: a re}

  • NF

by auto

8

slide-23
SLIDE 23

Viewing reACI as a subtype

fun nfACI :: a re ⇒ a re where ... lemma r ∼ACI s ←→ nfACI r = nfACI s 〈proof 〉 typedef a reACI = {nfACI r | r :: a re}

  • NF

by auto lift_bnf a reACI

  • 1. s ∈ NF −→ mapre f s ∈ NF
  • 2. ...

8

slide-24
SLIDE 24

Viewing reACI as a subtype

fun nfACI :: a re ⇒ a re where ... lemma r ∼ACI s ←→ nfACI r = nfACI s 〈proof 〉 typedef a reACI = {nfACI r | r :: a re}

  • NF

by auto lift_bnf a reACI

  • 1. s ∈ NF −→ mapre f s ∈ NF
  • 2. ...

unlikely for non-injective f

8

slide-25
SLIDE 25

Viewing reACI as a subtype

fun nfACI :: a re ⇒ a re where ... lemma r ∼ACI s ←→ nfACI r = nfACI s 〈proof 〉 typedef a reACI = {nfACI r | r :: a re}

  • NF

by auto lift_bnf a reACI

  • 1. s ∈ NF −→ mapre f s ∈ NF
  • 2. ...

unlikely for non-injective f

Quotients can be viewed as subtypes via representatives but we cannot lift the BNF structure along this view.

8

slide-26
SLIDE 26

Quotients of Polynomial Functors

F(A) F(B)

Data Types as Quotients of Polynomial Functors

Jeremy Avigad

Department of Philosophy, Carnegie Mellon University, Pittsburgh, PA, USA http://www.andrew.cmu.edu/user/avigad/ avigad@cmu.edu

Mario Carneiro

Department of Philosophy, Carnegie Mellon University, Pittsburgh, PA, USA di.gama@gmail.com

Simon Hudon

Department of Philosophy, Carnegie Mellon University, Pittsburgh, PA, USA https://www.cmu.edu/dietrich/philosophy/people/postdoc-fellows/simon-hudon%20.html simon.hudon@gmail.com

Abstract

A broad class of data types, including arbitrary nestings of inductive types, coinductive types, and quotients, can be represented as quotients of polynomial functors. This provides perspicuous ways

  • f constructing them and reasoning about them in an interactive theorem prover.

[] [1,2] [2,1] [1] [3,2] [2,3] [] [T,F] [F,T] [T] [T,T]

9

slide-27
SLIDE 27

Quotients of Polynomial Functors

F(A) F(B)

Data Types as Quotients of Polynomial Functors

Jeremy Avigad

Department of Philosophy, Carnegie Mellon University, Pittsburgh, PA, USA http://www.andrew.cmu.edu/user/avigad/ avigad@cmu.edu

Mario Carneiro

Department of Philosophy, Carnegie Mellon University, Pittsburgh, PA, USA di.gama@gmail.com

Simon Hudon

Department of Philosophy, Carnegie Mellon University, Pittsburgh, PA, USA https://www.cmu.edu/dietrich/philosophy/people/postdoc-fellows/simon-hudon%20.html simon.hudon@gmail.com

Abstract

A broad class of data types, including arbitrary nestings of inductive types, coinductive types, and quotients, can be represented as quotients of polynomial functors. This provides perspicuous ways

  • f constructing them and reasoning about them in an interactive theorem prover.

[] [1,2] [2,1] [1] [3,2] [2,3] [] [T,F] [F,T] [T] [T,T]

/∼

/∼

9

slide-28
SLIDE 28

Quotients of Polynomial Functors

F(A) F(B)

Data Types as Quotients of Polynomial Functors

Jeremy Avigad

Department of Philosophy, Carnegie Mellon University, Pittsburgh, PA, USA http://www.andrew.cmu.edu/user/avigad/ avigad@cmu.edu

Mario Carneiro

Department of Philosophy, Carnegie Mellon University, Pittsburgh, PA, USA di.gama@gmail.com

Simon Hudon

Department of Philosophy, Carnegie Mellon University, Pittsburgh, PA, USA https://www.cmu.edu/dietrich/philosophy/people/postdoc-fellows/simon-hudon%20.html simon.hudon@gmail.com

Abstract

A broad class of data types, including arbitrary nestings of inductive types, coinductive types, and quotients, can be represented as quotients of polynomial functors. This provides perspicuous ways

  • f constructing them and reasoning about them in an interactive theorem prover.

[] [1,2] [2,1] [1] [3,2] [2,3] [] [T,F] [F,T] [T] [T,T]

/∼

/∼ mapF f x ∼ y −→ mapF f x ∼ mapF f y

9

slide-29
SLIDE 29

Quotients of Polynomial Functors

F(A) F(B)

Data Types as Quotients of Polynomial Functors

Jeremy Avigad

Department of Philosophy, Carnegie Mellon University, Pittsburgh, PA, USA http://www.andrew.cmu.edu/user/avigad/ avigad@cmu.edu

Mario Carneiro

Department of Philosophy, Carnegie Mellon University, Pittsburgh, PA, USA di.gama@gmail.com

Simon Hudon

Department of Philosophy, Carnegie Mellon University, Pittsburgh, PA, USA https://www.cmu.edu/dietrich/philosophy/people/postdoc-fellows/simon-hudon%20.html simon.hudon@gmail.com

Abstract

A broad class of data types, including arbitrary nestings of inductive types, coinductive types, and quotients, can be represented as quotients of polynomial functors. This provides perspicuous ways

  • f constructing them and reasoning about them in an interactive theorem prover.

[] [1,2] [2,1] [1] [3,2] [2,3] [] [T,F] [F,T] [T] [T,T]

/∼

/∼ mapF f x ∼ y −→ setF x = setF y x ∼ y −→ mapF f x ∼ mapF f y

9

slide-30
SLIDE 30

Quotients of Polynomial Functors

F(A) F(B)

Data Types as Quotients of Polynomial Functors

Jeremy Avigad

Department of Philosophy, Carnegie Mellon University, Pittsburgh, PA, USA http://www.andrew.cmu.edu/user/avigad/ avigad@cmu.edu

Mario Carneiro

Department of Philosophy, Carnegie Mellon University, Pittsburgh, PA, USA di.gama@gmail.com

Simon Hudon

Department of Philosophy, Carnegie Mellon University, Pittsburgh, PA, USA https://www.cmu.edu/dietrich/philosophy/people/postdoc-fellows/simon-hudon%20.html simon.hudon@gmail.com

Abstract

A broad class of data types, including arbitrary nestings of inductive types, coinductive types, and quotients, can be represented as quotients of polynomial functors. This provides perspicuous ways

  • f constructing them and reasoning about them in an interactive theorem prover.

[] [1,2] [2,1] [1] [3,2] [2,3] [] [T,F] [F,T] [T] [T,T]

/∼

/∼ mapF f x ∼ y −→ setF x = setF y x ∼ y −→ mapF f x ∼ mapF f y ∼ preserves wide intersections ∼ preserves weak pullbacks

9

slide-31
SLIDE 31

Distinct Lists

[] [a] [b,b] [a,b,b] [a,b]

10

slide-32
SLIDE 32

Distinct Lists

[] [a] [b,b] [a,b,b] [a,b] [] [a] [a,b]

typedef a dlist = {xs :: a list | distinct xs}

10

slide-33
SLIDE 33

Distinct Lists

[] [a] [b,b] [a,b,b] [a,b] [] [a] [a,b]

typedef a dlist = {xs :: a list | distinct xs}

[a,a] map (λ_. a)

10

slide-34
SLIDE 34

Distinct Lists

[] [a] [b,b] [a,b,b] [a,b] [] [a] [a,b]

typedef a dlist = {xs :: a list | distinct xs}

[a,a] map (λ_. a) [] [a] [b,b] [a,b,b] [a,b]

quotient_type a dlist = a list / (λxs ys. remdups xs = remdups ys

  • ∼dlist

)

10

slide-35
SLIDE 35

Distinct Lists

[] [a] [b,b] [a,b,b] [a,b] [] [a] [a,b]

typedef a dlist = {xs :: a list | distinct xs}

[a,a] map (λ_. a) [] [a] [b,b] [a,b,b] [a,b]

quotient_type a dlist = a list / (λxs ys. remdups xs = remdups ys

  • ∼dlist

)

✓ ∼dlist preserves wide intersections ✓ xs ∼dlist ys −→ set xs = set ys ✓ ∼dlist preserves weak pullbacks

10

slide-36
SLIDE 36

Terminated Lazy Lists

codatatype a llist = LNil | LCons a (a llist)

[] [a] [b,b] [a,b,... [a,b]

11

slide-37
SLIDE 37

Terminated Lazy Lists

codatatype a llist = LNil | LCons a (a llist)

[] [a] [b,b] [a,b,... [a,b]

codatatype (a, b) tllist = TLNil b | TLCons a ((a, b) tllist)

[]α[]ε [a]α [b,b]β [a,b,... [a,b]γ [a,b]β

11

slide-38
SLIDE 38

Terminated Lazy Lists

codatatype a llist = LNil | LCons a (a llist)

[] [a] [b,b] [a,b,... [a,b]

codatatype (a, b) tllist = TLNil b | TLCons a ((a, b) tllist)

α β ε δ γ

×

[]α[]ε [a]α [b,b]β [a,b,... [a,b]γ [a,b]β

11

slide-39
SLIDE 39

Terminated Lazy Lists

codatatype a llist = LNil | LCons a (a llist)

[] [a] [b,b] [a,b,... [a,b]

codatatype (a, b) tllist = TLNil b | TLCons a ((a, b) tllist)

α β ε δ γ

×

[]α[]ε [a]α [b,b]β [a,b,... [a,b]γ [a,b]β

11

slide-40
SLIDE 40

Terminated Lazy Lists

codatatype a llist = LNil | LCons a (a llist)

[] [a] [b,b] [a,b,... [a,b]

codatatype (a, b) tllist = TLNil b | TLCons a ((a, b) tllist)

α β ε δ γ

×

[]α[]ε [a]α [b,b]β [a,b,... [a,b]γ [a,b]β

11

slide-41
SLIDE 41

Terminated Lazy Lists

codatatype a llist = LNil | LCons a (a llist)

[] [a] [b,b] [a,b,... [a,b]

codatatype (a, b) tllist = TLNil b | TLCons a ((a, b) tllist)

α β ε δ γ

×

[]α[]ε [a]α [b,b]β [a,b,... [a,b]γ [a,b]β

11

slide-42
SLIDE 42

Terminated Lazy Lists

codatatype a llist = LNil | LCons a (a llist)

[] [a] [b,b] [a,b,... [a,b] α β ε δ γ

×

[]α[]ε [a]α [b,b]β [a,b,... [a,b]γ [a,b]β

quotient_type (a, b) tllist = a llist × b / (λ(xs,α) (ys,β). xs = ys ∧ (|xs| < ∞ −→ α = β)

  • ∼tllist

)

11

slide-43
SLIDE 43

Terminated Lazy Lists

codatatype a llist = LNil | LCons a (a llist)

[] [a] [b,b] [a,b,... [a,b] α β ε δ γ

×

[]α[]ε [a]α [b,b]β [a,b,... [a,b]γ [a,b]β

quotient_type (a, b) tllist = a llist × b / (λ(xs,α) (ys,β). xs = ys ∧ (|xs| < ∞ −→ α = β)

  • ∼tllist

) (xs,α) ∼tllist (ys,β) −→ {α} = {β} (xs,α) ∼tllist (ys,β) −→ setllist xs = setllist ys ∼tllist preserves wide intersections ∼tllist preserves weak pullbacks

11

slide-44
SLIDE 44

Terminated Lazy Lists

codatatype a llist = LNil | LCons a (a llist)

[] [a] [b,b] [a,b,... [a,b] α β ε δ γ

×

[]α[]ε [a]α [b,b]β [a,b,... [a,b]γ [a,b]β

quotient_type (a, b) tllist = a llist × b / (λ(xs,α) (ys,β). xs = ys ∧ (|xs| < ∞ −→ α = β)

  • ∼tllist

)

✗ (xs,α) ∼tllist (ys,β) −→ {α} = {β} ✓ (xs,α) ∼tllist (ys,β) −→ setllist xs = setllist ys ✓ ∼tllist preserves wide intersections ✓ ∼tllist preserves weak pullbacks

11

slide-45
SLIDE 45

How to correct?

F(A)

[] [1] [2] [3] [1,2] [2,2]

12

slide-46
SLIDE 46

How to correct?

F(A)

[] [1] [2] [3] [1,2] [2,2]

/∼

12

slide-47
SLIDE 47

How to correct?

F(A) F({None} ∪ Some[A]) F(Some[A]) datatype a option = None | Some a

[] [1] [2] [3] [1,2] [2,2]

mapF Some

[] [S 1] [S 2] [S 3] [None] [S 1, S 2] [S 2, S 2] [None, S 2]

/∼

12

slide-48
SLIDE 48

How to correct?

F(A) F({None} ∪ Some[A]) F(Some[A]) datatype a option = None | Some a

[] [1] [2] [3] [1,2] [2,2]

mapF Some

[] [S 1] [S 2] [S 3] [None] [S 1, S 2] [S 2, S 2] [None, S 2]

/∼

/∼

12

slide-49
SLIDE 49

How to correct?

F(A) F({None} ∪ Some[A]) F(Some[A]) datatype a option = None | Some a

[] [1] [2] [3] [1,2] [2,2]

mapF Some

[] [S 1] [S 2] [S 3] [None] [S 1, S 2] [S 2, S 2] [None, S 2]

/∼

/∼

setF/∼ [x]∼ =

  • y∈[mapF Some x]∼

{a. Some a ∈ setF y}

12

slide-50
SLIDE 50

Preservation theorem

BNF F with equivalence relation ∼ ∼ preserves wide intersections A = {} ∧

  • A = {} −→

[A]∼|A ∈ F〈A〉

F〈A〉

∼ weakly preserve pullbacks R • S = {} −→ relF R • ∼ • relF S ⊆ ∼ • relF (R • S) • ∼

13

slide-51
SLIDE 51

Preservation theorem

BNF F with equivalence relation ∼ ∼ preserves wide intersections A = {} ∧

  • A = {} −→

[A]∼|A ∈ F〈A〉

F〈A〉

∼ weakly preserve pullbacks R • S = {} −→ relF R • ∼ • relF S ⊆ ∼ • relF (R • S) • ∼ yields BNF for F/∼ mapF/∼ f [x]∼ = [mapF f x]∼ setF/∼ [x]∼ =

  • y∈[mapF Some x]∼

{a. Some a ∈ setF y} ([x]∼[y]∼) ∈ relF/∼ R ←→ (mapF Some x,mapF Some y) ∈ (∼ • relF (reloption R) • ∼)

13

slide-52
SLIDE 52

lift_bnf in action

codatatype a llist = LNil | LCons a (a llist) definition ∼tllist:: a llist × b ⇒ a llist × b ⇒ bool where (xs,α) ∼tllist (ys,β) ←→ xs = ys ∧ (|xs| < ∞ −→ α = β) quotient_type (a,b) tllist = a llist × b / ∼tllist lift_bnf (a,b) tllist

14

slide-53
SLIDE 53

lift_bnf in action

codatatype a llist = LNil | LCons a (a llist) definition ∼tllist:: a llist × b ⇒ a llist × b ⇒ bool where (xs,α) ∼tllist (ys,β) ←→ xs = ys ∧ (|xs| < ∞ −→ α = β) quotient_type (a,b) tllist = a llist × b / ∼tllist lift_bnf (a,b) tllist

  • 1. A • A’ = ⊥ −→ B • B’ = ⊥ −→

rel× (relllist A) B • ∼tllist • rel× (relllist A’) B’ ≤ ∼tllist • rel× (relllist (A • A’)) (B • B’) • ∼tllist

  • 2. S = {} −→
  • S = {} −→
  • A∈S

{x. ∃y. y ∼tllist x ∧ setllist (π1 y) ⊆ A} ⊆ {x. ∃y. y ∼tllist x ∧ setllist (π1 y) ⊆

  • S}
  • 3. S = {} −→
  • S = {} −→
  • A∈S

{x. ∃y. y ∼tllist x ∧ π2 y ∈ A} ⊆ {x. ∃y. y ∼tllist x ∧ π2 y ∈

  • S}

14

slide-54
SLIDE 54

lift_bnf in action

codatatype a llist = LNil | LCons a (a llist) definition ∼tllist:: a llist × b ⇒ a llist × b ⇒ bool where (xs,α) ∼tllist (ys,β) ←→ xs = ys ∧ (|xs| < ∞ −→ α = β) quotient_type (a,b) tllist = a llist × b / ∼tllist lift_bnf (a,b) tllist subgoal by (auto 0 4 simp: ∼tllist _def ...) subgoal by (auto simp: ∼tllist _def) subgoal by (auto 6 0 simp: ∼tllist _def) done

14

slide-55
SLIDE 55

lift_bnf in action

codatatype a llist = LNil | LCons a (a llist) definition ∼tllist:: a llist × b ⇒ a llist × b ⇒ bool where (xs,α) ∼tllist (ys,β) ←→ xs = ys ∧ (|xs| < ∞ −→ α = β) quotient_type (a,b) tllist = a llist × b / ∼tllist lift_bnf (a,b) tllist subgoal by (auto 0 4 simp: ∼tllist _def ...) subgoal by (auto simp: ∼tllist _def) subgoal by (auto 6 0 simp: ∼tllist _def) done datatype foo = E | C ((foo, foo) tllist)

14

slide-56
SLIDE 56

x y y’ z relF R ∼ relF S

15

slide-57
SLIDE 57

x y y’ z relF R ∼ relF S u ∈ F(R) mapF π1 mapF π2

15

slide-58
SLIDE 58

x y y’ z relF R ∼ relF S u ∈ F(R) v ∈ F(S) mapF π1 mapF π2 map

F

π

1

mapF π2

15

slide-59
SLIDE 59

x y y’ z relF R ∼ relF S u ∈ F(R) v ∈ F(S) mapF π1 mapF π2 map

F

π

1

mapF π2 w ∗ ∗

15

slide-60
SLIDE 60

x y y’ z relF R ∼ relF S u ∈ F(R) v ∈ F(S) mapF π1 mapF π2 map

F

π

1

mapF π2 w u’ ∈ F(R) ∗ ∗ mapF π2 ∼

15

slide-61
SLIDE 61

x y y’ z relF R ∼ relF S u ∈ F(R) v ∈ F(S) mapF π1 mapF π2 map

F

π

1

mapF π2 w u’ ∈ F(R) v’ ∈ F(S) ∗ ∗ mapF π2 mapF π1 ∼ ∼

15

slide-62
SLIDE 62

x y y’ z relF R ∼ relF S u ∈ F(R) v ∈ F(S) mapF π1 mapF π2 map

F

π

1

mapF π2 w x’ u’ ∈ F(R) v’ ∈ F(S) ∗ ∗ mapF π2 m a p

F

π

1

mapF π1 ∼ ∼ ∼

15

slide-63
SLIDE 63

x y y’ z relF R ∼ relF S u ∈ F(R) v ∈ F(S) mapF π1 mapF π2 map

F

π

1

mapF π2 w x’ z’ u’ ∈ F(R) v’ ∈ F(S) ∗ ∗ mapF π2 m a p

F

π

1

mapF π1 m a p

F

π

2

∼ ∼ ∼ ∼

15

slide-64
SLIDE 64

x y y’ z relF R ∼ relF S u ∈ F(R) v ∈ F(S) mapF π1 mapF π2 map

F

π

1

mapF π2 w x’ z’ relF R relF S u’ ∈ F(R) v’ ∈ F(S) ∗ ∗ mapF π2 m a p

F

π

1

mapF π1 m a p

F

π

2

∼ ∼ ∼ ∼

15

slide-65
SLIDE 65

x y y’ z relF R ∼ relF S u ∈ F(R) v ∈ F(S) mapF π1 mapF π2 map

F

π

1

mapF π2 w x’ z’ relF R relF S u’ ∈ F(R) v’ ∈ F(S) ∗ ∗ mapF π2 m a p

F

π

1

mapF π1 m a p

F

π

2

∼ ∼ ∼ ∼ relF (R • S)

15

slide-66
SLIDE 66

Subdistributivity via rewrite relation

Sufficient conditions: BNF F with equivalence relation ∼ x ∼ y −→ mapF f x ∼ mapF f y ∧ setF x = setF y

16

slide-67
SLIDE 67

Subdistributivity via rewrite relation

Sufficient conditions: BNF F with equivalence relation ∼ x ∼ y −→ mapF f x ∼ mapF f y ∧ setF x = setF y Rewrite relation over-approximates ∼ confluent: x y z w

∗ ∗ ∗ ∗

and factors through projections: x x’ y’ y mapF πi ∼

16

slide-68
SLIDE 68

Subdistributivity via rewrite relation

Sufficient conditions: BNF F with equivalence relation ∼ x ∼ y −→ mapF f x ∼ mapF f y ∧ setF x = setF y Rewrite relation over-approximates ∼ confluent: x y z w

∗ ∗ ∗ ∗

and factors through projections: x x’ y’ y mapF πi ∼ Distinct lists: xs · ys xs · [x] · ys if x ∈ ys Proof effort: 50% shorter (58 instead of 126 lines)

16

slide-69
SLIDE 69

a reACI is a BNF

inductive ACI where r ACI r’ s ACI s’ Alt r s ACI Alt r’ s’ r ACI r’ s ACI s’ Conc r s ACI Conc r’ s’ r ACI r’ Star r ACI Star r’ r ACI r r ACI Alt r r Alt r s ACI Alt s r Alt (Alt r s) t ACI Alt r (Alt s t) Alt r (Alt s t) ACI Alt (Alt r s) t

17

slide-70
SLIDE 70

a reACI is a BNF

inductive ACI where r ACI r’ s ACI s’ Alt r s ACI Alt r’ s’ r ACI r’ s ACI s’ Conc r s ACI Conc r’ s’ r ACI r’ Star r ACI Star r’ r ACI r r ACI Alt r r Alt r s ACI Alt s r Alt (Alt r s) t ACI Alt r (Alt s t) Alt r (Alt s t) ACI Alt (Alt r s) t (ACI ∪ −1

ACI)∗ = (∼ACI)

ACI is confluent mapre π1r ACI s −→ ∃t. t ∼ACI r ∧ s = mapre π1t mapre π2 r ACI s −→ ∃t. t ∼ACI r ∧ s = mapre π2 t

17

slide-71
SLIDE 71

a reACI is a BNF

inductive ACI where r ACI r’ s ACI s’ Alt r s ACI Alt r’ s’ r ACI r’ s ACI s’ Conc r s ACI Conc r’ s’ r ACI r’ Star r ACI Star r’ r ACI r r ACI Alt r r Alt r s ACI Alt s r Alt (Alt r s) t ACI Alt r (Alt s t) Alt r (Alt s t) ACI Alt (Alt r s) t (ACI ∪ −1

ACI)∗ = (∼ACI)

ACI is confluent mapre π1r ACI s −→ ∃t. t ∼ACI r ∧ s = mapre π1t mapre π2 r ACI s −→ ∃t. t ∼ACI r ∧ s = mapre π2 t lift_bnf a reACI 〈proof 〉

17

slide-72
SLIDE 72

a reACI is a BNF

inductive ACI where r ACI r’ s ACI s’ Alt r s ACI Alt r’ s’ r ACI r’ s ACI s’ Conc r s ACI Conc r’ s’ r ACI r’ Star r ACI Star r’ r ACI r r ACI Alt r r Alt r s ACI Alt s r Alt (Alt r s) t ACI Alt r (Alt s t) Alt r (Alt s t) ACI Alt (Alt r s) t (ACI ∪ −1

ACI)∗ = (∼ACI)

ACI is confluent mapre π1r ACI s −→ ∃t. t ∼ACI r ∧ s = mapre π1t mapre π2 r ACI s −→ ∃t. t ∼ACI r ∧ s = mapre π2 t lift_bnf a reACI 〈proof 〉 datatype ldl = Prop string | And ldl ldl | Neg ldl | Match (ldl reACI)

17

slide-73
SLIDE 73

Epilogue lift_bnf

part of Isabelle2020 1600 lines of Isabelle/ML generation of transfer rules

18

slide-74
SLIDE 74

Epilogue lift_bnf

part of Isabelle2020 1600 lines of Isabelle/ML generation of transfer rules

Applications

(co)datatypes Lifting and Transfer QPF

18

slide-75
SLIDE 75

Epilogue lift_bnf

part of Isabelle2020 1600 lines of Isabelle/ML generation of transfer rules

Applications

(co)datatypes Lifting and Transfer QPF

Limitations

terms modulo α-equivalence

[Blanchette, Gheri, Popescu, T., POPL’19]

signed multisets

[Blanchette, Fleury, T., FSCD’16]

18

slide-76
SLIDE 76

Epilogue lift_bnf

part of Isabelle2020 1600 lines of Isabelle/ML generation of transfer rules

Applications

(co)datatypes Lifting and Transfer QPF

Limitations

terms modulo α-equivalence

[Blanchette, Gheri, Popescu, T., POPL’19]

signed multisets

[Blanchette, Fleury, T., FSCD’16]

Future Work

partial quotients generalizations of BNFs

[L., S., ITP’18] [Blanchette, Gheri, Popescu, T., POPL’19]

18

slide-77
SLIDE 77

Quotients of Bounded Natural Functors

Basil Fürer Andreas Lochbihler Joshua Schneider Dmitriy Traytel

merci! questions?

19