Programming with Dependent Types in Coq

Size: px
Start display at page:

Download "Programming with Dependent Types in Coq"

Transcription

1 Programming with Dependent Types in Coq Matthieu Sozeau LRI, Univ. Paris-Sud - Démons Team & INRIA Saclay - ProVal Project PPS Seminar February 26th 2009 Paris, France

2 Coq A higher-order, polymorphic logic: A (P Q : A Prop), ( x, P x Q x) x, P x Q x x y : N, x + y = y + x

3 Coq A higher-order, polymorphic logic: A (P Q : A Prop), ( x, P x Q x) x, P x Q x x y : N, x + y = y + x A purely functional programming language with dependent types: (λ A (x : A), x) : A, A A div : (a : nat) (b : nat b 0), { (q, r) : nat nat a = b q + r r < b }

4 Coq A higher-order, polymorphic logic: A (P Q : A Prop), ( x, P x Q x) x, P x Q x x y : N, x + y = y + x A purely functional programming language with dependent types: (λ A (x : A), x) : A, A A div : (a : nat) (b : nat b 0), { (q, r) : nat nat a = b q + r r < b } Problem: writing such programs is difficult.

5 Programming with tactics Lemma eucl dev : n, n > 0 m : nat, { (q, r) : nat nat n > r m = q n + r }. Proof. intros b H a; pattern a; apply gt wf rec; intros n H0. elim (le gt dec b n). intro lebn. case (H0 (n - b)); auto with arith. intros [q r] [g e]. (S q, r); simpl; auto with arith. elim plus assoc. elim e; auto with arith. intros gtbn. (0, n); simpl; auto with arith. Qed.

6 Programming directly λ b (H : b > 0) a, gt wf rec a (λ n, { (q, r) : nat nat b > r n = q b + r}) (λ n (H0 : Π m : nat, n > m { (q, r) : nat nat b > r m = q b + r}), sumbool rec (λ : {b n} + {b > n}, { (q, r) : nat nat b > r n = q b + r}) (λ lebn : b n, let (x, x0) := H0 (n - b) (lt minus n b lebn H) in (let (q, r) as p return ((let (q, r) := p in b > r n - b = q b + r) { (q, r) : nat nat b > r n = q b + r}) := x in λ y : b > r n - b = q b + r, match y with conj g e elt (eq ind (b + (q b + r)) (λ n0, b > r n = n0) (eq ind (n - b) (λ n0, b > r n = b + n0) (conj g (le plus minus b n lebn)) (q b + r) e) (b + q b + r) (plus assoc b (q b) r)) end) x0) (λ gtbn : b > n, elt (conj gtbn refl)) (le gt dec b n))

7 Thesis We can write programs as usual and still give them rich types.

8 The Big Picture

9 The Big Picture

10 The Big Picture

11 The Big Picture

12 The Big Picture

13 The Big Picture

14 The Big Picture

15 The Big Picture

16 1 Russell Subset Coercions: A Simple Idea Metatheory Interpretation in Coq 2 Program Extensions Hello World 3 Finger Trees Finger Trees in Haskell Dependent Finger Trees Specializations Ropes Random-access sequences 4 Conclusion 7 / 50

17 A simple idea Definition The set {x : T P } is the set of objects in T verifying property P. Useful for specifying, widely used in mathematics ; Links object and property. 8 / 50

18 From Predicate subtyping... PVS Specialized typing algorithm for subset types, generating Type-checking conditions. t : T P [t/x] t : { x : T P } t : { x : T P } t : T 9 / 50

19 From Predicate subtyping... PVS Specialized typing algorithm for subset types, generating Type-checking conditions. + Practical success ; t : T P [t/x] t : { x : T P } t : { x : T P } t : T 9 / 50

20 From Predicate subtyping... PVS Specialized typing algorithm for subset types, generating Type-checking conditions. + Practical success ; No strong safety guarantee in PVS. t : T P [t/x] t : { x : T P } t : { x : T P } t : T 9 / 50

21 From Predicate subtyping... PVS Specialized typing algorithm for subset types, generating Type-checking conditions. + Practical success ; No strong safety guarantee in PVS. t : T p : P [t/x] elt t p : { x : T P } t : { x : T P } σ 1 t : T 9 / 50

22 ... to Subset Coercions 1 A property-irrelevant language (Russell) with decidable typing Γ t : { x : T P } Γ t : T Γ t : T Γ, x : T P : Prop Γ t : { x : T P } 10 / 50

23 ... to Subset Coercions 1 A property-irrelevant language (Russell) with decidable typing 2 A total interpretation to Coq terms with holes Γ t : { x : T P } Γ σ 1 t : T Γ t : T Γ, x : T P : Prop Γ?P [t/x] : P [t/x] Γ elt t? P [t/x] : { x : T P } 10 / 50

24 ... to Subset Coercions 1 A property-irrelevant language (Russell) with decidable typing 2 A total interpretation to Coq terms with holes 3 A mechanism to turn the holes into proof obligations and manage them. Γ t : { x : T P } Γ σ 1 t : T Γ t : T Γ, x : T P : Prop Γ p : P [t/x] Γ elt t p : { x : T P } 10 / 50

25 Russell typing and coercion Calculus of Constructions with Γ t : U Γ U β T : s Γ t : T 11 / 50

26 Russell typing and coercion Calculus of Constructions with Γ t : U Γ U T : s Γ t : T Γ T β U : s Γ T U : s 11 / 50

27 Russell typing and coercion Calculus of Constructions with Γ t : U Γ U T : s Γ t : T Γ T β U : s Γ T U : s Γ U V : Set Γ, x : U P : Prop Γ { x : U P } V : Set Γ U V : Set Γ, x : V P : Prop Γ U { x : V P } : Set 11 / 50

28 Russell typing and coercion Calculus of Constructions with Γ t : U Γ U T : s Γ t : T Γ T β U : s Γ T U : s Γ U V : Set Γ, x : U P : Prop Γ { x : U P } V : Set Γ U V : Set Γ, x : V P : Prop Γ U { x : V P } : Set Example Γ 0 : N Γ N { x : N x 0 } : Set Γ 0 : { x : N x 0 } Γ? : / 50

29 Russell typing and coercion Calculus of Constructions with Γ t : U Γ U T : s Γ t : T Γ T β U : s Γ T U : s Γ U V : Set Γ, x : U P : Prop Γ { x : U P } V : Set Γ U V : Set Γ, x : V P : Prop Γ U { x : V P } : Set Γ U T : s 1 Γ, x : U V W : s 2 Γ Πx : T.V Πx : U.W : s 2 Γ S T : s Γ T U : s Γ S U : s 11 / 50

30 Russell typing and coercion Calculus of Constructions with Γ t : U Γ U T : s Γ t : T Γ T β U : s Γ T U : s Γ U V : Set Γ, x : U P : Prop Γ { x : U P } V : Set Γ U V : Set Γ, x : V P : Prop Γ U { x : V P } : Set Γ U T : s 1 Γ, x : U V W : s 2 Γ Πx : T.V Πx : U.W : s 2 Γ S T : s Γ T U : s Γ S U : s is symmetric! 11 / 50

31 Metatheory Theorem (Subject Reduction) If Γ t : T and t β u then Γ u : T Using the TPOSR technique due to Robin Adams. 12 / 50

32 Metatheory Theorem (Subject Reduction) If Γ t : T and t β u then Γ u : T Using the TPOSR technique due to Robin Adams. Theorem (Decidability of type checking and type inference) Γ t : T is decidable. 12 / 50

33 From Russell to Coq The target system : CIC with metavariables Γ? t : T Γ? p : P [t/x] Γ? elt T,P t p : { x : T P } Γ? t : { x : T P } Γ? σ 1 t : T Γ? t : { x : T P } Γ? σ 2 t : P [σ 1 t/x] Γ? P : Prop Γ?? Γ P : P We build an interpretation Γ from Russell to CIC? terms. 13 / 50

34 From Russell to Coq The target system : CIC with metavariables Γ? t : T Γ? p : P [t/x] Γ? elt T,P t p : { x : T P } Γ? t : { x : T P } Γ? σ 1 t : T Γ? t : { x : T P } Γ? σ 2 t : P [σ 1 t/x] Γ? P : Prop Γ?? Γ P : P We build an interpretation Γ from Russell to CIC? terms. Our goal: proving soundness If Γ t : T then Γ? t Γ : T Γ. 13 / 50

35 Deriving explicit coercions: Γ? c : T U Interpretation of coercions If Γ T U : s then there exists c so that Γ? c : T U. 14 / 50

36 Deriving explicit coercions: Γ? c : T U Interpretation of coercions If Γ T U : s then there exists c so that Γ? c : T U. Γ? T β U : s Γ? : T U 14 / 50

37 Deriving explicit coercions: Γ? c : T U Interpretation of coercions If Γ T U : s then there exists c so that Γ? c : T U. Γ? T β U : s Γ? : T U 14 / 50

38 Deriving explicit coercions: Γ? c : T U Interpretation of coercions If Γ T U : s then there exists c so that Γ? c : T U. Γ? Γ? T β U : s Γ? : T U : { x : T P } T 14 / 50

39 Deriving explicit coercions: Γ? c : T U Interpretation of coercions If Γ T U : s then there exists c so that Γ? c : T U. Γ? T β U : s Γ? : T U Γ? σ 1 : { x : T P } T 14 / 50

40 Deriving explicit coercions: Γ? c : T U Interpretation of coercions If Γ T U : s then there exists c so that Γ? c : T U. Γ? T β U : s Γ? : T U Γ? σ 1 : { x : T P } T Γ? : T { x : T P } 14 / 50

41 Deriving explicit coercions: Γ? c : T U Interpretation of coercions If Γ T U : s then there exists c so that Γ? c : T U. Γ? T β U : s Γ? : T U Γ? σ 1 : { x : T P } T Γ? elt? P Γ,x:T [ /x] : T { x : T P } 14 / 50

42 Deriving explicit coercions: Γ? c : T U Interpretation of coercions If Γ T U : s then there exists c so that Γ? c : T U. Γ? T β U : s Γ? : T U Γ? σ 1 : { x : T P } T Γ? elt? P Γ,x:T [ /x] : T { x : T P } Example Γ? 0 : N Γ? elt? 0 : N { x : N x 0 } Γ? elt 0? 0 0 : { x : N x 0 } 14 / 50

43 Interpretation of terms: Γ Example (Application) Γ f : T Γ T Πx : V.W : s Γ u : U Γ U V : s Γ (f u) : W [u/x] f u Γ = let π = coerce Γ T (Πx : V.W ) in let c = coerce Γ U V in (π[ f Γ ]) (c[ u Γ ]) Theorem (Soundness) If Γ t : T then Γ? t Γ : T Γ. 15 / 50

44 Theoretical matters...? s equational theory: { (β) (λx : X.e) v e[v/x] β-rules (σ i ) σ i (elt E,P e 1 e 2 ) e i } Coq 16 / 50

45 Theoretical matters...? s equational theory: { (β) (λx : X.e) v e[v/x] β-rules (σ i ) σ i (elt E,P e 1 e 2 ) e i } Coq { (η) (λx : X.e x) e if x / FV(e) η-rules (SP) elt E,P (σ 1 e) (σ 2 e) e 16 / 50

46 Theoretical matters...? s equational theory: { (β) (λx : X.e) v e[v/x] β-rules (σ i ) σ i (elt E,P e 1 e 2 ) e i } Coq { (η) (λx : X.e x) e if x / FV(e) η-rules (SP) elt E,P (σ 1 e) (σ 2 e) e Proof Irrelevance elt E,P t p elt E,P t p if t t 16 / 50

47 Theoretical matters...? s equational theory: { (β) (λx : X.e) v e[v/x] β-rules (σ i ) σ i (elt E,P e 1 e 2 ) e i } Coq { (η) (λx : X.e x) e if x / FV(e) η-rules (SP) elt E,P (σ 1 e) (σ 2 e) e Proof Irrelevance elt E,P t p elt E,P t p if t t... have practical effects Difficulty to reason on code: t u t Γ Coq u Γ. 16 / 50

48 1 Russell Subset Coercions: A Simple Idea Metatheory Interpretation in Coq 2 Program Extensions Hello World 3 Finger Trees Finger Trees in Haskell Dependent Finger Trees Specializations Ropes Random-access sequences 4 Conclusion 17 / 50

49 The Program vernacular Replaces the Program tactic by Catherine Parent. 18 / 50

50 The Program vernacular Replaces the Program tactic by Catherine Parent. Architecture Wrap around Coq s vernacular commands (Definition, Fixpoint, Lemma,... ). 18 / 50

51 The Program vernacular Replaces the Program tactic by Catherine Parent. Architecture Wrap around Coq s vernacular commands (Definition, Fixpoint, Lemma,... ). 1 Use the Coq parser ; Program Definition f : T := t. 18 / 50

52 The Program vernacular Replaces the Program tactic by Catherine Parent. Architecture Wrap around Coq s vernacular commands (Definition, Fixpoint, Lemma,... ). 1 Use the Coq parser ; 2 Typecheck Γ t : T and generate Γ? t Γ : T Γ ; Program Definition f : T Γ := t Γ. 18 / 50

53 The Program vernacular Replaces the Program tactic by Catherine Parent. Architecture Wrap around Coq s vernacular commands (Definition, Fixpoint, Lemma,... ). 1 Use the Coq parser ; 2 Typecheck Γ t : T and generate Γ? t Γ : T Γ ; 3 Interactive proof of the obligations ; Program Definition f : T Γ := t Γ + obligations. 18 / 50

54 The Program vernacular Replaces the Program tactic by Catherine Parent. Architecture Wrap around Coq s vernacular commands (Definition, Fixpoint, Lemma,... ). 1 Use the Coq parser ; 2 Typecheck Γ t : T and generate Γ? t Γ : T Γ ; 3 Interactive proof of the obligations ; 4 Final definition. Definition f : T Γ := t Γ + obligations. 18 / 50

55 Sugar Obligations Unresolved implicits ( ) are turned into obligations, à la refine. Bang! = (False rect ) where False rect : A : Type, False A. It corresponds to ML s assert(false). match x with 0! n end 19 / 50

56 Sugar Obligations Unresolved implicits ( ) are turned into obligations, à la refine. Bang! = (False rect ) where False rect : A : Type, False A. It corresponds to ML s assert(false). match x with 0! n end Destruction Let let p := t in e = match t with p e end. p can be an arbitrary pattern. 19 / 50

57 Recursion Support for well-founded recursion and measures. Program Fixpoint f (a : N) {wf < a} : N := b. 20 / 50

58 Recursion Support for well-founded recursion and measures. Program Fixpoint f (a : N) {wf < a} : N := b. a : N f : {x : N x < a} N b : N 20 / 50

59 Hello World: Euclidean division DEMO 21 / 50

60 Pattern-matching revisited Put logic into the terms. Let e : N: match e return T with S n t 1 0 t 2 end 22 / 50

61 Pattern-matching revisited Put logic into the terms. Let e : N: match e as t return t = e T with S n fun (H : S n = e) t 1 0 fun (H : 0 = e) t 2 end (refl equal e) 22 / 50

62 Pattern-matching revisited Put logic into the terms. Further refinements Each branch typed only once ; Let e : N: match e as t return t = e T with S (S n) fun (H : S (S n) = e) t 1 n fun (H : n = e) t 2 end (refl equal e) 22 / 50

63 Pattern-matching revisited Put logic into the terms. Further refinements Each branch typed only once ; Let e : N: match e as t return t = e T with S (S n) fun (H : S (S n) = e) t 1 S 0 fun (H : S 0 = e) t 2 0 fun (H : 0 = e) t 2 end (refl equal e) 22 / 50

64 Pattern-matching revisited Put logic into the terms. Further refinements Each branch typed only once ; Add inequalities for intersecting patterns ; Let e : N: match e as t return t = e T with S (S n) fun (H : S (S n) = e) t 1 n fun (H : n = e) let H : n, n S (S n ) in t 2 end (refl equal e) 22 / 50

65 Pattern-matching revisited Put logic into the terms. Further refinements Each branch typed only once ; Add inequalities for intersecting patterns ; Generalized to dependent inductive types. Let e : vector n: match e return T with vnil t 1 vcons x n v t 2 end 22 / 50

66 Pattern-matching revisited Put logic into the terms. Further refinements Each branch typed only once ; Add inequalities for intersecting patterns ; Generalized to dependent inductive types. Let e : vector n: match e as t in vector n return n = n JMeq t e T with vnil fun (H : 0 = n)(hv : JMeq vnil e) t 1 vcons x n v fun (H : S n = n) (Hv : JMeq (vcons x n v ) e) t 2 end (refl equal n)(jmeq refl e) 22 / 50

67 1 Russell Subset Coercions: A Simple Idea Metatheory Interpretation in Coq 2 Program Extensions Hello World 3 Finger Trees Finger Trees in Haskell Dependent Finger Trees Specializations Ropes Random-access sequences 4 Conclusion 23 / 50

68 Dependent Finger Trees A complex datastructure, with a reference implementation in Haskell (Hinze & Paterson, JFP 2006). Using Program and type classes, we construct a faithful port which is proved safe (terminating and invariant preserving). 24 / 50

69 Dependent Finger Trees A complex datastructure, with a reference implementation in Haskell (Hinze & Paterson, JFP 2006). Using Program and type classes, we construct a faithful port which is proved safe (terminating and invariant preserving). Through dependent types, it provides guarantees to be used by higher-level structures. 24 / 50

70 Dependent Finger Trees A complex datastructure, with a reference implementation in Haskell (Hinze & Paterson, JFP 2006). Using Program and type classes, we construct a faithful port which is proved safe (terminating and invariant preserving). Through dependent types, it provides guarantees to be used by higher-level structures. Instantiated to (safe) ropes whose extraction has reasonnable performance. 24 / 50

71 A quick tour of Finger Trees A Simple General Purpose Data Structure (Hinze & Paterson, JFP 2006) Purely functional, nested datatype Parameterized data structure Efficient deque operations, concatenation and splitting 25 / 50

72 The Big Finger Tree Picture data Digit a = One a Two a a Three a a a Four a a a a data Node a = Node2 a a Node3 a a a

73 The Big Finger Tree Picture data Digit a = One a Two a a Three a a a Four a a a a data Node a = Node2 a a Node3 a a a data FingerTree a = Empty Single a Deep (Digit a) (FingerTree (Node a)) (Digit a) Two Two Deep Deep Empty Three One Node2 Node3 Node2

74 Operating on a Finger Tree add left :: a FingerTree a FingerTree a add left a Empty = Single a add left a (Single b) = Deep (One a) Empty (One b) add left a (Deep pr m sf ) =... Deep Three Empty Three C D E F G H 27 / 50

75 Operating on a Finger Tree add left :: a FingerTree a FingerTree a add left a Empty = Single a add left a (Single b) = Deep (One a) Empty (One b) add left a (Deep pr m sf ) =... Deep Four Empty Three B C D E F G H 27 / 50

76 Operating on a Finger Tree add left :: a FingerTree a FingerTree a add left a Empty = Single a add left a (Single b) = Deep (One a) Empty (One b) add left a (Deep pr m sf ) =... Deep Two Single Three A B F G H Node3 C D E 27 / 50

77 Adding cached measures class Monoid v Measured v a where :: a v

78 Adding cached measures class Monoid v Measured v a where :: a v instance (Measured v a) Measured v (Digit a) where

79 Adding cached measures class Monoid v Measured v a where :: a v instance (Measured v a) Measured v (Digit a) where data Node v a = Node2 v a a Node3 v a a a data FingerTree v a = Empty Single a Deep v (Digit a) (FingerTree v (Node v a)) (Digit a) Node2 a b a b Two Deep a g Empty ε Node3 c d e c d e One Node2 f g f g

80 Outline 1 Russell Subset Coercions: A Simple Idea Metatheory Interpretation in Coq 2 Program Extensions Hello World 3 Finger Trees Finger Trees in Haskell Dependent Finger Trees Specializations Ropes Random-access sequences 4 Conclusion 29 / 50

81 Why do this? Generally useful, non-trivial structure Abstraction and specification power needed to ensure coherence of measures 30 / 50

82 Digits Variable A : Type. Inductive digit : Type := One : A digit Two : A A digit Three : A A A digit Four : A A A A digit. Definition full x := match x with Four True False end. 31 / 50

83 Digits cont d Program Definition add digit left (a : A) (d : digit full d) : digit := match d with One x Two a x Two x y Three a x y Three x y z Four a x y z Four! end. 32 / 50

84 Nodes Variables (v : Type) (mono : monoid v). Variables (A : Type) (measure : A v). 33 / 50

85 Nodes Variables (v : Type) (mono : monoid v). Variables (A : Type) (measure : A v). Inductive node : Type := Node2 : x y, { s : v s = x y } node Node3 : x y z, { s : v s = x y z } node. 33 / 50

86 Nodes Variables (v : Type) (mono : monoid v). Variables (A : Type) (measure : A v). Inductive node : Type := Node2 : x y, { s : v s = x y } node Node3 : x y z, { s : v s = x y z } node. Program Definition node2 (x y : A) : node := Node2 x y ( x y ). Program Definition node measure (n : node) : v := match n with Node2 s s Node3 s s end. 33 / 50

87 Dependent Finger Trees Inductive fingertree (A : Type) : Type := Empty : fingertree A Single : x : A, fingertree A Deep : (l : digit A) (m : v), fingertree (node A) (r : digit A), fingertree A. node : (A : Type) (measure : A v), Type 34 / 50

88 Dependent Finger Trees Inductive fingertree (A : Type) (measure : A v) : Type := Empty : fingertree A measure Single : x : A, fingertree A measure Deep : (l : digit A) (m : v), fingertree (node A measure) (node measure A measure) (r : digit A), fingertree A measure. node : (A : Type) (measure : A v), Type node measure A (measure : A v) : node A measure v 34 / 50

89 Dependent Finger Trees Inductive fingertree (A : Type) (measure : A v) : v Type := Empty : fingertree A measure ε Single : x : A, fingertree A measure (measure x) Deep : (l : digit A) (m : v), fingertree (node A measure) (node measure A measure) m (r : digit A), fingertree A measure (digit measure measure l m digit measure measure r). 34 / 50

90 Adding to the left fix add left A (measure : A v) (a : A) (s : v) (t : fingertree measure s) {struct t} : fingertree measure (measure a s) := 35 / 50

91 Adding to the left fix add left A (measure : A v) (a : A) (s : v) (t : fingertree measure s) {struct t} : fingertree measure (measure a s) := match t with Empty Single a measure a = measure a ε Single b Deep (One a) Empty (One b) Deep pr st t sf end. 35 / 50

92 Adding to the left fix add left A (measure : A v) (a : A) (s : v) (t : fingertree measure s) {struct t} : fingertree measure (measure a s) := match t with Empty Single a measure a = measure a ε Single b Deep (One a) Empty (One b) Deep pr st t sf match pr with Four b c d e let sub := add left (node3 measure c d e) t in Deep (Two a b) sub sf x Deep (add digit left a pr) t sf end end. 35 / 50

93 Two hundred lines, one hundred obligations concatenation def app (A : Type) (measure : A v) (xs : v) (x : fingertree measure xs) (ys : v) (y : fingertree measure ys) : fingertree measure (xs ys). 36 / 50

94 Splitting nodes def splitnode (p : v bool) (i : v) (n : node A measure) : { (l, x, r) : option (digit A) A option (digit A) let ls := option digit measure measure l in let rs := option digit measure measure r in node measure n = ls x rs (l = None p (i ls) = false) (r = None p (i ls x ) = true)} :=... Program Definition split node (p : v bool) i (n : node A) : { (l, x, r) : option (digit A) A option (digit A) n = l x r (l = None p (i l ) = false) (r = None p (i l x ) = true)} := / 50

95 Summary We proved that all the functions from the original paper: are terminating and total respect the measures respect the invariants given in the paper Haskell Program Lines L.o.C. Obls L.o.P. app auto split FingerTree n.a / 50

96 Summary We proved that all the functions from the original paper: are terminating and total respect the measures respect the invariants given in the paper Haskell Program Lines L.o.C. Obls L.o.P. app auto split FingerTree n.a. 400 Non-dependent interface, specializations A version with modules for a better extraction to OCaml 38 / 50

97 Outline 1 Russell Subset Coercions: A Simple Idea Metatheory Interpretation in Coq 2 Program Extensions Hello World 3 Finger Trees Finger Trees in Haskell Dependent Finger Trees Specializations Ropes Random-access sequences 4 Conclusion 39 / 50

98 Ropes on top of Finger Trees Ingredients: A := string int int (substrings) v := int (the length, computationally relevant) measure (str, start, len) := len mono := (0, +) Implement substring, get 40 / 50

99 Ropes on top of Finger Trees Ingredients: A := string int int (substrings) v := int (the length, computationally relevant) measure (str, start, len) := len mono := (0, +) Implement substring, get Extracted code comparable to an optimized rope implementation. 40 / 50

100 Ropes on top of Finger Trees Ingredients: A := string int int (substrings) v := int (the length, computationally relevant) measure (str, start, len) := len mono := (0, +) Implement substring, get Extracted code comparable to an optimized rope implementation. Relies on implicit invariants of the monoid, measure and code. 40 / 50

101 Certified Sequences: the monoid def below i := { x : nat x < i }. def v := { i : nat & (below i A) }. 41 / 50

102 Certified Sequences: the monoid def below i := { x : nat x < i }. def v := { i : nat & (below i A) }. def epsilon : v := 0 (fun!). def append (n, fx) (m, fy) : v := (n + m) (fun i if lt ge dec i n then fx i else fy (i - n)). 41 / 50

103 Instantiation def measure (x : A) : v := 1 (fun x). def seq (x : v) := fingertree seqmonoid measure x. 42 / 50

104 Instantiation def measure (x : A) : v := 1 (fun x). def seq (x : v) := fingertree seqmonoid measure x. tail n f : seq (n f ) seq (pred n (fun i f (S i))) app n fx m fy : seq (n fx) seq (m fy) seq (n + m (fun i if lt ge dec i n then fx i else fy (i - n))) 42 / 50

105 The sequence and its operations fix make (i : nat) (v : A) { struct i } : seq (i (fun v)). 43 / 50

106 The sequence and its operations fix make (i : nat) (v : A) { struct i } : seq (i (fun v)). def get (i : nat) (m : below i A) (x : seq (i m)) (j : below i) : { value : A value = m j }. 43 / 50

107 The sequence and its operations fix make (i : nat) (v : A) { struct i } : seq (i (fun v)). def get (i : nat) (m : below i A) (x : seq (i m)) (j : below i) : { value : A value = m j }. def set (i : nat) (m : below i A) (x : seq (i m)) (j : below i) (value : A) : seq (i (fun idx if idx = j then value else m idx)). 43 / 50

108 The sequence and its operations fix make (i : nat) (v : A) { struct i } : seq (i (fun v)). def get (i : nat) (m : below i A) (x : seq (i m)) (j : below i) : { value : A value = m j }. def set (i : nat) (m : below i A) (x : seq (i m)) (j : below i) (value : A) : seq (i (fun idx if idx = j then value else m idx)). Modularity: only the specifications are used! Efficiency: Irrelevance of m currently not specified 43 / 50

109 Theorems for free! Program Lemma get set i m (x : seq (i m)) (j : below i) (value : A) : value = get (set x j value) j. Program Lemma get set diff i m (x : seq (i m)) (j : below i) (value : A) (k : below i) : j k get x k = get (set x j value) k. 44 / 50

110 Summary A certified implementation of Finger Trees and random-access sequences. Program scales, thanks to the phase distinction. Typeclasses to solve the overloading issues. 45 / 50

111 1 Russell Subset Coercions: A Simple Idea Metatheory Interpretation in Coq 2 Program Extensions Hello World 3 Finger Trees Finger Trees in Haskell Dependent Finger Trees Specializations Ropes Random-access sequences 4 Conclusion 46 / 50

112 Our contributions We studied a more flexible programming language, Russell, providing a new formal justification of Predicate subtyping à la PVS, in a system with proof terms. 47 / 50

113 Our contributions We studied a more flexible programming language, Russell, providing a new formal justification of Predicate subtyping à la PVS, in a system with proof terms. We implemented the Program tool to ease programming in Coq using the full language ( 10k lines of OCaml). 47 / 50

114 Our contributions We studied a more flexible programming language, Russell, providing a new formal justification of Predicate subtyping à la PVS, in a system with proof terms. We implemented the Program tool to ease programming in Coq using the full language ( 10k lines of OCaml). We experimented it on a verified implementation of Finger Trees and ropes ( 4k lines of literate Coq). 47 / 50

115 Dissemination A methodology to build certified code in Coq, distributed since 2005: Already experimented by others, e.g. the Ynot project (Nanevsky, Morrisett & Birkedal) implementing Hoare Type Theory on top of Coq. Independent of the theory, can be ported to other systems: Matita (by Enrico Tassi), Agda, Epigram. 48 / 50

116 Ongoing and future work We hinted at the important foundational issues with η-rules and proof-irrelevance that need to be solved (with Benjamin Werner). Automation for discharging proof-obligations (Sean Wilson at Edinburgh). Handling truly dependent pattern-matching by an elaboration. 49 / 50

117 The End Programming with Dependent Types in Coq Matthieu Sozeau LRI, Univ. Paris-Sud - Démons Team & INRIA Saclay - ProVal Project PPS Seminar February 26th 2009 Paris, France Try 8.2!

Program-ing in Coq. Matthieu Sozeau under the direction of Christine Paulin-Mohring

Program-ing in Coq. Matthieu Sozeau under the direction of Christine Paulin-Mohring Program-ing in Coq Matthieu Sozeau under the direction of Christine Paulin-Mohring LRI, Univ. Paris-Sud - Démons Team & INRIA Saclay - ProVal Project Foundations of Programming seminar February 15th 2008

More information

Interactive Theorem Provers

Interactive Theorem Provers Interactive Theorem Provers from the perspective of Isabelle/Isar Makarius Wenzel Univ. Paris-Sud, LRI July 2014 = Isabelle λ β Isar α 1 Introduction Notable ITP systems LISP based: ACL2 http://www.cs.utexas.edu/users/moore/acl2

More information

Nunchaku: Flexible Model Finding for Higher-Order Logic

Nunchaku: Flexible Model Finding for Higher-Order Logic Nunchaku: Flexible Model Finding for Higher-Order Logic Simon Cruanes, Jasmin Blanchette, Andrew Reynolds Veridis, Inria Nancy https://cedeela.fr/~simon/ April 7th, 2016 1 / 21 Summary Introduction Nunchaku

More information

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications NICTA Advanced Course Theorem Proving Principles, Techniques, Applications λ 1 CONTENT Intro & motivation, getting started with Isabelle Foundations & Principles Lambda Calculus Higher Order Logic, natural

More information

Univalence for Free. Matthieu Sozeau Joint work with Nicolas Tabareau - INRIA. GT Types & Réalisabilité March 13th 2013

Univalence for Free. Matthieu Sozeau Joint work with Nicolas Tabareau - INRIA. GT Types & Réalisabilité March 13th 2013 Univalence for Free Matthieu Sozeau Joint work with Nicolas Tabareau - INRIA Project Team πr 2 INRIA Rocquencourt & PPS, Paris 7 University GT Types & Réalisabilité March 13th 2013 Univalence for Free

More information

A New Look At Generalized Rewriting in Type Theory

A New Look At Generalized Rewriting in Type Theory A New Look At Generalized Rewriting in Type Theory Matthieu Sozeau Harvard University TYPES 09 May 13th 2009 Aussois, France Generalized Rewriting Equational reasoning x = y - x + 1 ==> y + 1 Logical reasoning

More information

A New Look at Generalized Rewriting in Type Theory

A New Look at Generalized Rewriting in Type Theory A New Look at Generalized Rewriting in Type Theory Matthieu Sozeau Harvard University 1st Coq Workshop August 21th 2009 Munich, Germany Generalized Rewriting Equational reasoning x = y - x + 1 ==> y +

More information

Structuring the verification of heap-manipulating programs

Structuring the verification of heap-manipulating programs Structuring the verification of heap-manipulating programs Aleksandar Nanevski (IMDEA Madrid) Viktor Vafeiadis (MSR / Univ. of Cambridge) Josh Berdine (MSR Cambridge) Hoare/Separation Logic Hoare logic

More information

Examples for program extraction in Higher-Order Logic

Examples for program extraction in Higher-Order Logic Examples for program extraction in Higher-Order Logic Stefan Berghofer October 10, 2011 Contents 1 Auxiliary lemmas used in program extraction examples 1 2 Quotient and remainder 2 3 Greatest common divisor

More information

Discrete Mathematics Review

Discrete Mathematics Review CS 1813 Discrete Mathematics Discrete Mathematics Review or Yes, the Final Will Be Comprehensive 1 Truth Tables for Logical Operators P Q P Q False False False P Q False P Q False P Q True P Q True P True

More information

Imperative Insertion Sort

Imperative Insertion Sort Imperative Insertion Sort Christian Sternagel October 11, 2017 Contents 1 Looping Constructs for Imperative HOL 1 1.1 While Loops............................ 1 1.2 For Loops.............................

More information

Using the Prover I: Lee Pike. June 3, NASA Langley Formal Methods Group Using the Prover I:

Using the Prover I: Lee Pike. June 3, NASA Langley Formal Methods Group Using the Prover I: Basic Basic NASA Langley Formal Methods Group lee.s.pike@nasa.gov June 3, 2005 Basic Sequents Basic Sequent semantics: The conjunction of the antecedents above the turnstile implies the disjunction of

More information

CS294-9 September 14, 2006 Adam Chlipala UC Berkeley

CS294-9 September 14, 2006 Adam Chlipala UC Berkeley Interactive Computer Theorem Proving Lecture 4: Inductively- Defined Predicates CS294-9 September 14, 2006 Adam Chlipala UC Berkeley 1 Administrivia The course registration database has been updated so

More information

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications. Gerwin Klein Formal Methods

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications. Gerwin Klein Formal Methods NICTA Advanced Course Theorem Proving Principles, Techniques, Applications Gerwin Klein Formal Methods 1 ORGANISATORIALS When Mon 14:00 15:30 Wed 10:30 12:00 7 weeks ends Mon, 20.9.2004 Exceptions Mon

More information

Beyond First-Order Logic

Beyond First-Order Logic Beyond First-Order Logic Software Formal Verification Maria João Frade Departmento de Informática Universidade do Minho 2008/2009 Maria João Frade (DI-UM) Beyond First-Order Logic MFES 2008/09 1 / 37 FOL

More information

VeriML: Typed Computation of Logical Terms inside a Language with Effects

VeriML: Typed Computation of Logical Terms inside a Language with Effects VeriML: Typed Computation of Logical Terms inside a Language with Effects Antonis Stampoulis Zhong Shao Department of Computer Science, Yale University ICFP 2010 Proof assistants are becoming popular in

More information

Reasoning with Higher-Order Abstract Syntax and Contexts: A Comparison

Reasoning with Higher-Order Abstract Syntax and Contexts: A Comparison 1 Reasoning with Higher-Order Abstract Syntax and Contexts: A Comparison Amy Felty University of Ottawa July 13, 2010 Joint work with Brigitte Pientka, McGill University 2 Comparing Systems We focus on

More information

Programming Languages Fall 2013

Programming Languages Fall 2013 Programming Languages Fall 2013 Lecture 11: Subtyping Prof Liang Huang huang@qccscunyedu Big Picture Part I: Fundamentals Functional Programming and Basic Haskell Proof by Induction and Structural Induction

More information

Modeling Ontological Structures with Type Classes in Coq

Modeling Ontological Structures with Type Classes in Coq Modeling Ontological Structures with Type Classes in Coq Richard Dapoigny 1 Patrick Barlatier 1 1 LISTIC/Polytech Savoie University of Savoie, Annecy, (FRANCE) Cite as: Dapoigny, R., Barlatier, P. Modeling

More information

Automating Interactive Theorem Proving with Coq and Ltac. by Oron Propp and Alex Sekula Mentored by Drew Haven PRIMES

Automating Interactive Theorem Proving with Coq and Ltac. by Oron Propp and Alex Sekula Mentored by Drew Haven PRIMES Automating Interactive Theorem Proving with Coq and Ltac by Oron Propp and Alex Sekula Mentored by Drew Haven PRIMES Motivation Math is usually written by hand, checked by other mathematicians Verifying

More information

Universe Polymorphism in Coq

Universe Polymorphism in Coq Universe Polymorphism in Coq Matthieu Sozeau 1,2 and Nicolas Tabareau 1,3 1 Inria πr 2 and Ascola teams 2 PPS, Univ Paris Diderot 3 Laboratoire d Informatique de Nantes Altantique (LINA) firstname.surname@inria.fr

More information

Gerwin Klein, June Andronick, Ramana Kumar S2/2016

Gerwin Klein, June Andronick, Ramana Kumar S2/2016 COMP4161: Advanced Topics in Software Verification {} Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au Content Intro & motivation, getting started [1] Foundations & Principles Lambda

More information

Limitations of OCAML records

Limitations of OCAML records Limitations of OCAML records The record types must be declared before they are used; a label e can belong to only one record type (otherwise fun x x.e) would have several incompatible types; we cannot

More information

Hoare Logic: Reasoning About Imperative Programs

Hoare Logic: Reasoning About Imperative Programs Hoare Logic: Reasoning About Imperative Programs COMP1600 / COMP6260 Dirk Pattinson Australian National University Semester 2, 2018 Programming Paradigms Functional. (Haskell, SML, OCaml,... ) main paradigm:

More information

EDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach

EDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach EDA045F: Program Analysis LECTURE 10: TYPES 1 Christoph Reichenbach In the last lecture... Performance Counters Challenges in Dynamic Performance Analysis Taint Analysis Binary Instrumentation 2 / 44 Types

More information

A Principled approach to Ornamentation in ML

A Principled approach to Ornamentation in ML 0 0 A Principled approach to Ornamentation in ML THOMAS WILLIAMS, Inria DIDIER RÉMY, Inria Ornaments are a way to describe changes in datatype definitions reorganizing, adding, or dropping some pieces

More information

Notes from Yesterday s Discussion. Big Picture. CIS 500 Software Foundations Fall November 1. Some lessons.

Notes from Yesterday s  Discussion. Big Picture. CIS 500 Software Foundations Fall November 1. Some lessons. CIS 500 Software Foundations Fall 2006 Notes from Yesterday s Email Discussion November 1 Some lessons This is generally a crunch-time in the semester Slow down a little and give people a chance to catch

More information

Classical Program Logics: Hoare Logic, Weakest Liberal Preconditions

Classical Program Logics: Hoare Logic, Weakest Liberal Preconditions Chapter 1 Classical Program Logics: Hoare Logic, Weakest Liberal Preconditions 1.1 The IMP Language IMP is a programming language with an extensible syntax that was developed in the late 1960s. We will

More information

Verified Characteristic Formulae for CakeML. Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 18, 2017

Verified Characteristic Formulae for CakeML. Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 18, 2017 Verified Characteristic Formulae for CakeML Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 18, 2017 CakeML Has: references, modules, datatypes, exceptions, a FFI,... Doesn t have:

More information

Outline. A recursive function follows the structure of inductively-defined data.

Outline. A recursive function follows the structure of inductively-defined data. Outline A recursive function follows the structure of inductively-defined data. With lists as our example, we shall study 1. inductive definitions (to specify data) 2. recursive functions (to process data)

More information

Depending on equations

Depending on equations Depending on equations A proof-relevant framework for unification in dependent type theory Jesper Cockx DistriNet KU Leuven 3 September 2017 Unification for dependent types Unification is used for many

More information

Introduction to lambda calculus Part 6

Introduction to lambda calculus Part 6 Introduction to lambda calculus Part 6 Antti-Juhani Kaijanaho 2017-02-16 1 Untyped lambda calculus 2 Typed lambda calculi 2.1 Dynamically typed lambda calculus with integers 2.2 A model of Lisp 2.3 Simply

More information

M a s t e r r e s e a rc h I n t e r n s h i p. Formalisation of Ground Inference Systems in a Proof Assistant

M a s t e r r e s e a rc h I n t e r n s h i p. Formalisation of Ground Inference Systems in a Proof Assistant M a s t e r r e s e a rc h I n t e r n s h i p Master Thesis Formalisation of Ground Inference Systems in a Proof Assistant Domain: Data Structures and Algorithms - Logic in Computer Science Author: Mathias

More information

The Tortoise and the Hare Algorithm

The Tortoise and the Hare Algorithm The Tortoise and the Hare Algorithm Peter Gammie October 11, 2017 Abstract We formalize the Tortoise and Hare cycle-finding algorithm ascribed to Floyd by Knuth (1981, p7, exercise 6), and an improved

More information

CIS 500: Software Foundations

CIS 500: Software Foundations CIS 500: Software Foundations Midterm I October 3, 2017 Directions: This exam booklet contains both the standard and advanced track questions. Questions with no annotation are for both tracks. Other questions

More information

The TLA + proof system

The TLA + proof system The TLA + proof system Stephan Merz Kaustuv Chaudhuri, Damien Doligez, Leslie Lamport INRIA Nancy & INRIA-MSR Joint Centre, France Amir Pnueli Memorial Symposium New York University, May 8, 2010 Stephan

More information

A General Method for the Proof of Theorems on Tail-recursive Functions

A General Method for the Proof of Theorems on Tail-recursive Functions A General Method for the Proof of Theorems on Tail-recursive Functions Pasquale Noce Security Certification Specialist at Arjo Systems - Gep S.p.A. pasquale dot noce dot lavoro at gmail dot com pasquale

More information

Rules and derivations in an elementary logic course arxiv: v1 [cs.lo] 7 Jan 2016

Rules and derivations in an elementary logic course arxiv: v1 [cs.lo] 7 Jan 2016 Rules and derivations in an elementary logic course arxiv:160101483v1 [cslo] 7 Jan 2016 Gilles Dowek Inria, 23 avenue d Italie, CS 81321, 75214 Paris Cedex 13, France gillesdowek@inriafr When teaching

More information

Cylindrical Algebraic Decomposition in Coq

Cylindrical Algebraic Decomposition in Coq Cylindrical Algebraic Decomposition in Coq MAP 2010 - Logroño 13-16 November 2010 Assia Mahboubi INRIA Microsoft Research Joint Centre (France) INRIA Saclay Île-de-France École Polytechnique, Palaiseau

More information

Functional Data Structures

Functional Data Structures Functional Data Structures with Isabelle/HOL Tobias Nipkow Fakultät für Informatik Technische Universität München 2017-2-3 1 Part II Functional Data Structures 2 Chapter 1 Binary Trees 3 1 Binary Trees

More information

Typed Arithmetic Expressions

Typed Arithmetic Expressions Typed Arithmetic Expressions CS 550 Programming Languages Jeremy Johnson TAPL Chapters 3 and 5 1 Types and Safety Evaluation rules provide operational semantics for programming languages. The rules provide

More information

Propositional and Predicate Logic - V

Propositional and Predicate Logic - V Propositional and Predicate Logic - V Petr Gregor KTIML MFF UK WS 2016/2017 Petr Gregor (KTIML MFF UK) Propositional and Predicate Logic - V WS 2016/2017 1 / 21 Formal proof systems Hilbert s calculus

More information

Analyse et Conception Formelle. Lesson 4. Proofs with a proof assistant

Analyse et Conception Formelle. Lesson 4. Proofs with a proof assistant Analyse et Conception Formelle Lesson 4 Proofs with a proof assistant T. Genet (ISTIC/IRISA) ACF-4 1 / 26 Prove logic formulas... to prove programs fun nth:: "nat => a list => a" where "nth 0 (x#_)=x"

More information

Type Soundness for Path Polymorphism

Type Soundness for Path Polymorphism Type Soundness for Path Polymorphism Andrés Ezequiel Viso 1,2 joint work with Eduardo Bonelli 1,3 and Mauricio Ayala-Rincón 4 1 CONICET, Argentina 2 Departamento de Computación, FCEyN, UBA, Argentina 3

More information

Programming Languages and Types

Programming Languages and Types Programming Languages and Types Klaus Ostermann based on slides by Benjamin C. Pierce Subtyping Motivation With our usual typing rule for applications the term is not well typed. ` t 1 : T 11!T 12 ` t

More information

Syntax and semantics of a GPU kernel programming language

Syntax and semantics of a GPU kernel programming language Syntax and semantics of a GPU kernel programming language John Wickerson April 17, 2016 Abstract This document accompanies the article The Design and Implementation of a Verification Technique for GPU

More information

The L Machines are very high-level, in two senses:

The L Machines are very high-level, in two senses: What is a Computer? State of the machine. CMPSCI 630: Programming Languages An Abstract Machine for Control Spring 2009 (with thanks to Robert Harper) Internal registers, memory, etc. Initial and final

More information

Recursion and Intro to Coq

Recursion and Intro to Coq L02-1 Recursion and Intro to Coq Armando Solar Lezama Computer Science and Artificial Intelligence Laboratory M.I.T. With content from Arvind and Adam Chlipala. Used with permission. September 21, 2015

More information

The syntactic guard condition of Coq

The syntactic guard condition of Coq The syntactic guard condition of Coq Bruno Barras February 2, 2010 Overview 1 Theory Basic criterion Extensions 2 Algorithm Efficiency 3 Discussion 4 Attic A short history of the syntactic guard criterion

More information

Sri vidya college of engineering and technology

Sri vidya college of engineering and technology Unit I FINITE AUTOMATA 1. Define hypothesis. The formal proof can be using deductive proof and inductive proof. The deductive proof consists of sequence of statements given with logical reasoning in order

More information

The Calculus of Inductive Constructions

The Calculus of Inductive Constructions The Calculus of Inductive Constructions Hugo Herbelin 10th Oregon Programming Languages Summer School Eugene, Oregon, June 16-July 1, 2011 1 Outline - A bit of history, leading to the Calculus of Inductive

More information

Representations of Boolean Functions in Constructive Type Theory

Representations of Boolean Functions in Constructive Type Theory Saarland University Faculty of Natural Sciences and Technology I Department of Computer Science Bachelor s Program in Computer Science Bachelor s Thesis Representations of Boolean Functions in Constructive

More information

hal , version 1-21 Oct 2009

hal , version 1-21 Oct 2009 ON SKOLEMISING ZERMELO S SET THEORY ALEXANDRE MIQUEL Abstract. We give a Skolemised presentation of Zermelo s set theory (with notations for comprehension, powerset, etc.) and show that this presentation

More information

Static Program Analysis

Static Program Analysis Static Program Analysis Xiangyu Zhang The slides are compiled from Alex Aiken s Michael D. Ernst s Sorin Lerner s A Scary Outline Type-based analysis Data-flow analysis Abstract interpretation Theorem

More information

The Tortoise and the Hare Algorithm

The Tortoise and the Hare Algorithm The Tortoise and the Hare Algorithm Peter Gammie April 17, 2016 Abstract We formalize the Tortoise and Hare cycle-finding algorithm ascribed to Floyd by Knuth (1981, p7, exercise 6), and an improved version

More information

Information Flow Inference for ML

Information Flow Inference for ML POPL 02 INRIA Rocquencourt Projet Cristal Francois.Pottier@inria.fr http://cristal.inria.fr/~fpottier/ Vincent.Simonet@inria.fr http://cristal.inria.fr/~simonet/ Information flow analysis account number

More information

Iris: Higher-Order Concurrent Separation Logic. Lecture 6: Case Study: foldr

Iris: Higher-Order Concurrent Separation Logic. Lecture 6: Case Study: foldr 1 Iris: Higher-Order Concurrent Separation Logic Lecture 6: Case Study: foldr Lars Birkedal Aarhus University, Denmark November 10, 2017 2 Overview Earlier: Operational Semantics of λ ref,conc e, (h, e)

More information

Reasoning About Imperative Programs. COS 441 Slides 10b

Reasoning About Imperative Programs. COS 441 Slides 10b Reasoning About Imperative Programs COS 441 Slides 10b Last time Hoare Logic: { P } C { Q } Agenda If P is true in the initial state s. And C in state s evaluates to s. Then Q must be true in s. Program

More information

Review. Principles of Programming Languages. Equality. The Diamond Property. The Church-Rosser Theorem. Corollaries. CSE 230: Winter 2007

Review. Principles of Programming Languages. Equality. The Diamond Property. The Church-Rosser Theorem. Corollaries. CSE 230: Winter 2007 CSE 230: Winter 2007 Principles of Programming Languages Lecture 12: The λ-calculus Ranjit Jhala UC San Diego Review The lambda calculus is a calculus of functions: e := x λx. e e 1 e 2 Several evaluation

More information

Normalization by Evaluation

Normalization by Evaluation Normalization by Evaluation Andreas Abel Department of Computer Science and Engineering Chalmers and Gothenburg University PhD Seminar in Mathematical Engineering EAFIT University, Medellin, Colombia 9

More information

An axiom free Coq proof of Kruskal s tree theorem

An axiom free Coq proof of Kruskal s tree theorem An axiom free Coq proof of Kruskal s tree theorem Dominique Larchey-Wendling TYPES team LORIA CNRS Nancy, France http://www.loria.fr/~larchey/kruskal Dagstuhl Seminar 16031, January 2016 1 Well Quasi Orders

More information

CSE 505, Fall 2009, Midterm Examination 5 November Please do not turn the page until everyone is ready.

CSE 505, Fall 2009, Midterm Examination 5 November Please do not turn the page until everyone is ready. CSE 505, Fall 2009, Midterm Examination 5 November 2009 Please do not turn the page until everyone is ready Rules: The exam is closed-book, closed-note, except for one side of one 85x11in piece of paper

More information

Induction on Failing Derivations

Induction on Failing Derivations Induction on Failing Derivations Technical Report PL-Sep13 September 2013, with addenda from Spring 2016 ay Ligatti Department of Computer Science and Engineering University of South Florida Abstract A

More information

The Coq Proof Assistant

The Coq Proof Assistant The Coq Proof Assistant Bow-Yaw Wang Institute of Information Science Academia Sinica, Taiwan October 15, 2018 Bow-Yaw Wang (Academia Sinica) The Coq Proof Assistant October 15, 2018 1 / 59 Outline 1 The

More information

(Type) Constraints. Solving constraints Type inference

(Type) Constraints. Solving constraints Type inference A (quick) tour of ML F (Graphic) Types (Type) Constraints Solving constraints Type inference Type Soundness A Fully Graphical Presentation of ML F Didier Rémy & Boris Yakobowski Didier Le Botlan INRIA

More information

Roy L. Crole. Operational Semantics Abstract Machines and Correctness. University of Leicester, UK

Roy L. Crole. Operational Semantics Abstract Machines and Correctness. University of Leicester, UK Midlands Graduate School, University of Birmingham, April 2008 1 Operational Semantics Abstract Machines and Correctness Roy L. Crole University of Leicester, UK Midlands Graduate School, University of

More information

The LCF Approach to Theorem Proving

The LCF Approach to Theorem Proving The LCF Approach to Theorem Proving 1 The LCF Approach to Theorem Proving John Harrison Intel Corporation Ideas and historical context Key ideas of LCF Equational logic example More about HOL Light Programming

More information

Extending higher-order logic with predicate subtyping: application to PVS

Extending higher-order logic with predicate subtyping: application to PVS Extending higher-order logic with predicate subtyping: application to PVS Frédéric Gilbert To cite this version: Frédéric Gilbert. Extending higher-order logic with predicate subtyping: application to

More information

The Algebra of Infinite Sequences: Notations and Formalization

The Algebra of Infinite Sequences: Notations and Formalization The Algebra of Infinite Sequences: Notations and Formalization Nachum Dershowitz 1, Jean-Pierre Jouannaud 2,3, and Qian Wang 2 1 School of Computer Science, Tel Aviv University, Ramat Aviv, Israel 2 School

More information

Lecture Notes on Data Abstraction

Lecture Notes on Data Abstraction Lecture Notes on Data Abstraction 15-814: Types and Programming Languages Frank Pfenning Lecture 14 October 23, 2018 1 Introduction Since we have moved from the pure λ-calculus to functional programming

More information

Landau Symbols. Manuel Eberl. November 28, 2018

Landau Symbols. Manuel Eberl. November 28, 2018 Landau Symbols Manuel Eberl November 28, 2018 Contents 1 Sorting and grouping factors 1 2 Decision procedure for real functions 4 2.1 Eventual non-negativity/non-zeroness............. 4 2.2 Rewriting Landau

More information

A Certified Denotational Abstract Interpreter (Proof Pearl)

A Certified Denotational Abstract Interpreter (Proof Pearl) A Certified Denotational Abstract Interpreter (Proof Pearl) David Pichardie INRIA Rennes David Cachera IRISA / ENS Cachan (Bretagne) Static Analysis Static Analysis Static analysis by abstract interpretation

More information

Write your own Theorem Prover

Write your own Theorem Prover Write your own Theorem Prover Phil Scott 27 October 2016 Phil Scott Write your own Theorem Prover 27 October 2016 1 / 31 Introduction We ll work through a toy LCF style theorem prover for classical propositional

More information

Simply Typed Lambda Calculus

Simply Typed Lambda Calculus Simply Typed Lambda Calculus Language (ver1) Lambda calculus with boolean values t ::= x variable x : T.t abstraction tt application true false boolean values if ttt conditional expression Values v ::=

More information

3 Propositional Logic

3 Propositional Logic 3 Propositional Logic 3.1 Syntax 3.2 Semantics 3.3 Equivalence and Normal Forms 3.4 Proof Procedures 3.5 Properties Propositional Logic (25th October 2007) 1 3.1 Syntax Definition 3.0 An alphabet Σ consists

More information

CMSC 631 Program Analysis and Understanding Fall Type Systems

CMSC 631 Program Analysis and Understanding Fall Type Systems Program Analysis and Understanding Fall 2017 Type Systems Type Systems A type system is a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according

More information

λ Slide 1 Content Exercises from last time λ-calculus COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification

λ Slide 1 Content Exercises from last time λ-calculus COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification Content COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification Toby Murray, June Andronick, Gerwin Klein λ Slide 1 Intro & motivation, getting started [1] Foundations & Principles Lambda

More information

Meta-Reasoning in a Concurrent Logical Framework

Meta-Reasoning in a Concurrent Logical Framework Meta-Reasoning in a Concurrent Logical Framework Iliano Cervesato and Jorge Luis Sacchini Carnegie Mellon University Chalmers University, 16 Oct 2013 Iliano Cervesato and Jorge Luis Sacchini Meta-Reasoning

More information

Subtyping and Intersection Types Revisited

Subtyping and Intersection Types Revisited Subtyping and Intersection Types Revisited Frank Pfenning Carnegie Mellon University International Conference on Functional Programming (ICFP 07) Freiburg, Germany, October 1-3, 2007 Joint work with Rowan

More information

Type Inference. For the Simply-Typed Lambda Calculus. Peter Thiemann, Manuel Geffken. Albert-Ludwigs-Universität Freiburg. University of Freiburg

Type Inference. For the Simply-Typed Lambda Calculus. Peter Thiemann, Manuel Geffken. Albert-Ludwigs-Universität Freiburg. University of Freiburg Type Inference For the Simply-Typed Lambda Calculus Albert-Ludwigs-Universität Freiburg Peter Thiemann, Manuel Geffken University of Freiburg 24. Januar 2013 Outline 1 Introduction 2 Applied Lambda Calculus

More information

Operational Semantics

Operational Semantics Operational Semantics Semantics and applications to verification Xavier Rival École Normale Supérieure Xavier Rival Operational Semantics 1 / 50 Program of this first lecture Operational semantics Mathematical

More information

Reasoning about Trace Properties of Higher-order Programs

Reasoning about Trace Properties of Higher-order Programs Reasoning about Trace Properties of Higher-order Programs Limin Jia Joint work with Deepak Garg and Anupam Datta CyLab University Goal: Compositional security S 1 ψ 1 + ϕ S 2 ψ 2! Do S 1 + S 2 satisfy

More information

logical verification lecture program extraction and prop2

logical verification lecture program extraction and prop2 logical verification lecture 7 2017-05-04 program extraction and prop2 overview program extraction program extraction: examples verified programs: alternative approach formulas of prop2 terminology proofs

More information

Computer Algebra in Coq using reflection

Computer Algebra in Coq using reflection , 2 Computer Algebra in using reflection INRIA, team Marelle and Éducation Nationale 26-07-2012 Automatization in proof assistants, 2 From Computer Algebra Systems to Proof Assistants : certified computations.

More information

Formalising the Completeness Theorem of Classical Propositional Logic in Agda (Proof Pearl)

Formalising the Completeness Theorem of Classical Propositional Logic in Agda (Proof Pearl) Formalising the Completeness Theorem of Classical Propositional Logic in Agda (Proof Pearl) Leran Cai, Ambrus Kaposi, and Thorsten Altenkirch University of Nottingham {psylc5, psxak8, psztxa}@nottingham.ac.uk

More information

CSE505, Fall 2012, Final Examination December 10, 2012

CSE505, Fall 2012, Final Examination December 10, 2012 CSE505, Fall 2012, Final Examination December 10, 2012 Rules: The exam is closed-book, closed-notes, except for one side of one 8.5x11in piece of paper. Please stop promptly at 12:20. You can rip apart

More information

Typing λ-terms. Types. Typed λ-terms. Base Types. The Typing Relation. Advanced Formal Methods. Lecture 3: Simply Typed Lambda calculus

Typing λ-terms. Types. Typed λ-terms. Base Types. The Typing Relation. Advanced Formal Methods. Lecture 3: Simply Typed Lambda calculus Course 2D1453, 200607 Advanced Formal Methods Lecture 3: Simply Typed Lambda calculus Mads Dam KTH/CSC Some material from B. Pierce: TAPL + some from G. Klein, NICTA Typing λterms The uptyped λcalculus

More information

A Machine Checked Model of Idempotent MGU Axioms For a List of Equational Constraints

A Machine Checked Model of Idempotent MGU Axioms For a List of Equational Constraints A Machine Checked Model of Idempotent MGU Axioms For a List of Equational Constraints Sunil Kothari, James Caldwell Department of Computer Science, University of Wyoming, USA Machine checked proofs of

More information

Propositional logic. First order logic. Alexander Clark. Autumn 2014

Propositional logic. First order logic. Alexander Clark. Autumn 2014 Propositional logic First order logic Alexander Clark Autumn 2014 Formal Logic Logical arguments are valid because of their form. Formal languages are devised to express exactly that relevant form and

More information

Finite Automata Theory and Formal Languages TMV027/DIT321 LP Recap: Logic, Sets, Relations, Functions

Finite Automata Theory and Formal Languages TMV027/DIT321 LP Recap: Logic, Sets, Relations, Functions Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2017 Formal proofs; Simple/strong induction; Mutual induction; Inductively defined sets; Recursively defined functions. Lecture 3 Ana Bove

More information

Notes on Inductive Sets and Induction

Notes on Inductive Sets and Induction Notes on Inductive Sets and Induction Finite Automata Theory and Formal Languages TMV027/DIT21 Ana Bove, March 15th 2018 Contents 1 Induction over the Natural Numbers 2 1.1 Mathematical (Simple) Induction........................

More information

Inductive Predicates

Inductive Predicates Inductive Predicates Gert Smolka, Saarland University June 12, 2017 We introduce inductive predicates as they are accommodated in Coq s type theory. Our prime example is the ordering predicate for numbers,

More information

Software Engineering

Software Engineering Software Engineering Lecture 07: Design by Contract Peter Thiemann University of Freiburg, Germany 02.06.2014 Table of Contents Design by Contract Contracts for Procedural Programs Contracts for Object-Oriented

More information

Cylindrical Algebraic Decomposition in Coq

Cylindrical Algebraic Decomposition in Coq Cylindrical Algebraic Decomposition in Coq MAP 2010 - Logroño 13-16 November 2010 Assia Mahboubi INRIA Microsoft Research Joint Centre (France) INRIA Saclay Île-de-France École Polytechnique, Palaiseau

More information

CS411 Notes 3 Induction and Recursion

CS411 Notes 3 Induction and Recursion CS411 Notes 3 Induction and Recursion A. Demers 5 Feb 2001 These notes present inductive techniques for defining sets and subsets, for defining functions over sets, and for proving that a property holds

More information

The Locally Nameless Representation

The Locally Nameless Representation Noname manuscript No. (will be inserted by the editor) The Locally Nameless Representation Arthur Charguéraud Received: date / Accepted: date Abstract This paper provides an introduction to the locally

More information

An Introduction to Proof Assistants

An Introduction to Proof Assistants An Introduction to Proof Assistants Patrick Schnider Student Seminar in Combinatorics: Mathematical Software, ETH Zürich 1 Motivation The development of proof assistants was motivated by the use of computers

More information

Coinductive big-step operational semantics

Coinductive big-step operational semantics Coinductive big-step operational semantics Xavier Leroy a, Hervé Grall b a INRIA Paris-Rocquencourt Domaine de Voluceau, B.P. 105, 78153 Le Chesnay, France b École des Mines de Nantes La Chantrerie, 4,

More information

Hoare Logic I. Introduction to Deductive Program Verification. Simple Imperative Programming Language. Hoare Logic. Meaning of Hoare Triples

Hoare Logic I. Introduction to Deductive Program Verification. Simple Imperative Programming Language. Hoare Logic. Meaning of Hoare Triples Hoare Logic I Introduction to Deductive Program Verification Işıl Dillig Program Spec Deductive verifier FOL formula Theorem prover valid contingent Example specs: safety (no crashes), absence of arithmetic

More information

CIS 500: Software Foundations

CIS 500: Software Foundations CIS 500: Software Foundations Solutions Final Exam December 15, 2017 1. Inductive relations (11 points) Complete the definition at the bottom of the page of an Inductive relation count that relates a list

More information