Compositional Computational Reflection Gregory Malecha Adam - - PowerPoint PPT Presentation

compositional computational reflection
SMART_READER_LITE
LIVE PREVIEW

Compositional Computational Reflection Gregory Malecha Adam - - PowerPoint PPT Presentation

Compositional Computational Reflection Gregory Malecha Adam Chlipala Thomas Braibant gmalecha@cs.harvard.edu Harvard SEAS MIT CSAIL Inria July 17, 2014 MirrorShard (ITP14) 1 / 13 Program Verification in Bedrock [Chl11] Imperative


slide-1
SLIDE 1

Compositional Computational Reflection

Gregory Malecha Adam Chlipala Thomas Braibant gmalecha@cs.harvard.edu

Harvard SEAS MIT CSAIL Inria

July 17, 2014

MirrorShard (ITP’14) 1 / 13

slide-2
SLIDE 2

Program Verification in Bedrock [Chl11]

Imperative Program

bfunction "length"("x", "n") [lengthS] "n" ← 0;; [ ∀ ls, PRE[V] sll ls (V "x") POST[R] ⌈ R = V "n" + length ls ⌉ ∗ sll ls (V "x")] While (”x” = 0) { ”n” ← ”n” + 1; ; ”x” ← ”x” + 4; ; ”x” ← ∗”x” }; ; Return "n"

Hints / Theorems

Def sll : list W → W → HProp := ... Thm nil_fwd : ∀ ls (p : W), p = 0 → sll ls p ⊢ ⌈ ls = nil ⌉.

  • Proof. ..

Qed. Thm cons_fwd : ∀ ls (p : W), p = 0 → sll ls p ⊢ ∃ x, ∃ ls’, ⌈ ls = x :: ls’ ⌉ ∗ ∃ p’, p → (x, p’) ∗ sll ls’ p’.

  • Proof. ..

Qed. Thm sllMOk : moduleOk sllM.

  • Proof. vcgen; abstract (sep hints; finish). Qed.

Bedrock MirrorShard (ITP’14) 2 / 13

slide-3
SLIDE 3

Program Verification in Bedrock [Chl11]

Imperative Program

bfunction "length"("x", "n") [lengthS] "n" ← 0;; [ ∀ ls, PRE[V] sll ls (V "x") POST[R] ⌈ R = V "n" + length ls ⌉ ∗ sll ls (V "x")] While (”x” = 0) { ”n” ← ”n” + 1; ; ”x” ← ”x” + 4; ; ”x” ← ∗”x” }; ; Return "n"

Hints / Theorems

Def sll : list W → W → HProp := ... Thm nil_fwd : ∀ ls (p : W), p = 0 → sll ls p ⊢ ⌈ ls = nil ⌉.

  • Proof. ..

Qed. Thm cons_fwd : ∀ ls (p : W), p = 0 → sll ls p ⊢ ∃ x, ∃ ls’, ⌈ ls = x :: ls’ ⌉ ∗ ∃ p’, p → (x, p’) ∗ sll ls’ p’.

  • Proof. ..

Qed. Thm sllMOk : moduleOk sllM.

  • Proof. vcgen; abstract (sep hints; finish). Qed.

VC-gen

Bedrock MirrorShard (ITP’14) 2 / 13

slide-4
SLIDE 4

Program Verification in Bedrock [Chl11]

Imperative Program

bfunction "length"("x", "n") [lengthS] "n" ← 0;; [ ∀ ls, PRE[V] sll ls (V "x") POST[R] ⌈ R = V "n" + length ls ⌉ ∗ sll ls (V "x")] While (”x” = 0) { ”n” ← ”n” + 1; ; ”x” ← ”x” + 4; ; ”x” ← ∗”x” }; ; Return "n"

Hints / Theorems

Def sll : list W → W → HProp := ... Thm nil_fwd : ∀ ls (p : W), p = 0 → sll ls p ⊢ ⌈ ls = nil ⌉.

  • Proof. ..

Qed. Thm cons_fwd : ∀ ls (p : W), p = 0 → sll ls p ⊢ ∃ x, ∃ ls’, ⌈ ls = x :: ls’ ⌉ ∗ ∃ p’, p → (x, p’) ∗ sll ls’ p’.

  • Proof. ..

Qed. Thm sllMOk : moduleOk sllM.

  • Proof. vcgen; abstract (sep hints; finish). Qed.

VC-gen HO

Bedrock MirrorShard (ITP’14) 2 / 13

slide-5
SLIDE 5

Program Verification in Bedrock [Chl11]

Imperative Program

bfunction "length"("x", "n") [lengthS] "n" ← 0;; [ ∀ ls, PRE[V] sll ls (V "x") POST[R] ⌈ R = V "n" + length ls ⌉ ∗ sll ls (V "x")] While (”x” = 0) { ”n” ← ”n” + 1; ; ”x” ← ”x” + 4; ; ”x” ← ∗”x” }; ; Return "n"

Hints / Theorems

Def sll : list W → W → HProp := ... Thm nil_fwd : ∀ ls (p : W), p = 0 → sll ls p ⊢ ⌈ ls = nil ⌉.

  • Proof. ..

Qed. Thm cons_fwd : ∀ ls (p : W), p = 0 → sll ls p ⊢ ∃ x, ∃ ls’, ⌈ ls = x :: ls’ ⌉ ∗ ∃ p’, p → (x, p’) ∗ sll ls’ p’.

  • Proof. ..

Qed. Thm sllMOk : moduleOk sllM.

  • Proof. vcgen; abstract (sep hints; finish). Qed.

VC-gen HO Sym Exec

Bedrock MirrorShard (ITP’14) 2 / 13

slide-6
SLIDE 6

Program Verification in Bedrock [Chl11]

Imperative Program

bfunction "length"("x", "n") [lengthS] "n" ← 0;; [ ∀ ls, PRE[V] sll ls (V "x") POST[R] ⌈ R = V "n" + length ls ⌉ ∗ sll ls (V "x")] While (”x” = 0) { ”n” ← ”n” + 1; ; ”x” ← ”x” + 4; ; ”x” ← ∗”x” }; ; Return "n"

Hints / Theorems

Def sll : list W → W → HProp := ... Thm nil_fwd : ∀ ls (p : W), p = 0 → sll ls p ⊢ ⌈ ls = nil ⌉.

  • Proof. ..

Qed. Thm cons_fwd : ∀ ls (p : W), p = 0 → sll ls p ⊢ ∃ x, ∃ ls’, ⌈ ls = x :: ls’ ⌉ ∗ ∃ p’, p → (x, p’) ∗ sll ls’ p’.

  • Proof. ..

Qed. Thm sllMOk : moduleOk sllM.

  • Proof. vcgen; abstract (sep hints; finish). Qed.

VC-gen HO Sym Exec HO

Bedrock MirrorShard (ITP’14) 2 / 13

slide-7
SLIDE 7

Program Verification in Bedrock [Chl11]

Imperative Program

bfunction "length"("x", "n") [lengthS] "n" ← 0;; [ ∀ ls, PRE[V] sll ls (V "x") POST[R] ⌈ R = V "n" + length ls ⌉ ∗ sll ls (V "x")] While (”x” = 0) { ”n” ← ”n” + 1; ; ”x” ← ”x” + 4; ; ”x” ← ∗”x” }; ; Return "n"

Hints / Theorems

Def sll : list W → W → HProp := ... Thm nil_fwd : ∀ ls (p : W), p = 0 → sll ls p ⊢ ⌈ ls = nil ⌉.

  • Proof. ..

Qed. Thm cons_fwd : ∀ ls (p : W), p = 0 → sll ls p ⊢ ∃ x, ∃ ls’, ⌈ ls = x :: ls’ ⌉ ∗ ∃ p’, p → (x, p’) ∗ sll ls’ p’.

  • Proof. ..

Qed. Thm sllMOk : moduleOk sllM.

  • Proof. vcgen; abstract (sep hints; finish). Qed.

VC-gen HO Sym Exec HO Entailment

Bedrock MirrorShard (ITP’14) 2 / 13

slide-8
SLIDE 8

Program Verification in Bedrock [Chl11]

Imperative Program

bfunction "length"("x", "n") [lengthS] "n" ← 0;; [ ∀ ls, PRE[V] sll ls (V "x") POST[R] ⌈ R = V "n" + length ls ⌉ ∗ sll ls (V "x")] While (”x” = 0) { ”n” ← ”n” + 1; ; ”x” ← ”x” + 4; ; ”x” ← ∗”x” }; ; Return "n"

Hints / Theorems

Def sll : list W → W → HProp := ... Thm nil_fwd : ∀ ls (p : W), p = 0 → sll ls p ⊢ ⌈ ls = nil ⌉.

  • Proof. ..

Qed. Thm cons_fwd : ∀ ls (p : W), p = 0 → sll ls p ⊢ ∃ x, ∃ ls’, ⌈ ls = x :: ls’ ⌉ ∗ ∃ p’, p → (x, p’) ∗ sll ls’ p’.

  • Proof. ..

Qed. Thm sllMOk : moduleOk sllM.

  • Proof. vcgen; abstract (sep hints; finish). Qed.

VC-gen HO Sym Exec HO Entailment

Bedrock MirrorShard (ITP’14) 2 / 13

slide-9
SLIDE 9

Ltac-based Symbolic Execution

bfunction "length"("x", "n") [lengthS] "n" ← 0;; [ ∀ ls, PRE[V] sll ls (V "x") POST[R] ⌈ R = V "n" + length ls ⌉ ∗ sll ls (V "x")] While ("x" = 0) { "n" ← "n" + 1;; "x" ← "x" + 4;; "x" ← ∗ "x" };; Return "n"

Ltac Automation

Ltac sym_eval := repeat first [ eapply step_read ; side_condition | ... | autorewrite with lemmas ].

P′′′ ⊢ R {P′′′}c4{R} ... {P′′}c3; c4{R} ... {P′}c2; c3; c4{R} ... {P}c1; c2; c3; c4{R} Coq’s tactic language

Bedrock MirrorShard (ITP’14) 3 / 13

slide-10
SLIDE 10

Ltac-based Symbolic Execution

bfunction "length"("x", "n") [lengthS] "n" ← 0;; [ ∀ ls, PRE[V] sll ls (V "x") POST[R] ⌈ R = V "n" + length ls ⌉ ∗ sll ls (V "x")] While ("x" = 0) { "n" ← "n" + 1;; "x" ← "x" + 4;; "x" ← ∗ "x" };; Return "n"

Ltac Automation

Ltac sym_eval := repeat first [ eapply step_read ; side_condition | ... | autorewrite with lemmas ].

P′′′ ⊢ R {P′′′}c4{R} ... {P′′}c3; c4{R} ... {P′}c2; c3; c4{R} ... {P}c1; c2; c3; c4{R}

assume x = 0

c1

Bedrock MirrorShard (ITP’14) 3 / 13

slide-11
SLIDE 11

Ltac-based Symbolic Execution

bfunction "length"("x", "n") [lengthS] "n" ← 0;; [ ∀ ls, PRE[V] sll ls (V "x") POST[R] ⌈ R = V "n" + length ls ⌉ ∗ sll ls (V "x")] While ("x" = 0) { "n" ← "n" + 1;; "x" ← "x" + 4;; "x" ← ∗ "x" };; Return "n"

Ltac Automation

Ltac sym_eval := repeat first [ eapply step_read ; side_condition | ... | autorewrite with lemmas ].

P′′′ ⊢ R {P′′′}c4{R} ... {P′′}c3; c4{R} ... {P′}c2; c3; c4{R} ... {P}c1; c2; c3; c4{R}

assume x = 0

c1

n ← n + 1

c2

Bedrock MirrorShard (ITP’14) 3 / 13

slide-12
SLIDE 12

Ltac-based Symbolic Execution

bfunction "length"("x", "n") [lengthS] "n" ← 0;; [ ∀ ls, PRE[V] sll ls (V "x") POST[R] ⌈ R = V "n" + length ls ⌉ ∗ sll ls (V "x")] While ("x" = 0) { "n" ← "n" + 1;; "x" ← "x" + 4;; "x" ← ∗ "x" };; Return "n"

Ltac Automation

Ltac sym_eval := repeat first [ eapply step_read ; side_condition | ... | autorewrite with lemmas ].

P′′′ ⊢ R {P′′′}c4{R} ... {P′′}c3; c4{R} ... {P′}c2; c3; c4{R} ... {P}c1; c2; c3; c4{R}

assume x = 0

c1

n ← n + 1

c2

x ← x + 4

c3

Bedrock MirrorShard (ITP’14) 3 / 13

slide-13
SLIDE 13

Ltac-based Symbolic Execution

bfunction "length"("x", "n") [lengthS] "n" ← 0;; [ ∀ ls, PRE[V] sll ls (V "x") POST[R] ⌈ R = V "n" + length ls ⌉ ∗ sll ls (V "x")] While ("x" = 0) { "n" ← "n" + 1;; "x" ← "x" + 4;; "x" ← ∗ "x" };; Return "n"

Ltac Automation

Ltac sym_eval := repeat first [ eapply step_read ; side_condition | ... | autorewrite with lemmas ].

P′′′ ⊢ R {P′′′}c4{R} ... {P′′}c3; c4{R} ... {P′}c2; c3; c4{R} ... {P}c1; c2; c3; c4{R}

assume x = 0

c1

n ← n + 1

c2

x ← x + 4

c3

x ← ∗x

c4 ≫5x the problem size!

Bedrock MirrorShard (ITP’14) 3 / 13

slide-14
SLIDE 14

Computational Reflection [Bou97]

Write a function & prove it sound. c1 c2 c3 c4 P ∧ Q P′ ∧ Q′

Computational Reflection MirrorShard (ITP’14) 4 / 13

slide-15
SLIDE 15

Computational Reflection [Bou97]

Write a function & prove it sound. c1 c2 c3 c4 P ∧ Q P′ ∧ Q′ seval

Computational Reflection MirrorShard (ITP’14) 4 / 13

slide-16
SLIDE 16

Computational Reflection [Bou97]

Write a function & prove it sound. c1 c2 c3 c4 P ∧ Q P′ ∧ Q′ seval

Syntactic Semantic

p ::= X# | p1 ∧ p2 | True

Computational Reflection MirrorShard (ITP’14) 4 / 13

slide-17
SLIDE 17

Computational Reflection [Bou97]

Write a function & prove it sound. c1 c2 c3 c4 P ∧ Q P′ ∧ Q′ seval

Syntactic Semantic

denote denote XP′∧ XQ′ p ::= X# | p1 ∧ p2 | True XP∧ XQ

Computational Reflection MirrorShard (ITP’14) 4 / 13

slide-18
SLIDE 18

Computational Reflection [Bou97]

Write a function & prove it sound. c1 c2 c3 c4 P ∧ Q P′ ∧ Q′ seval

Syntactic Semantic

denote denote XP′∧ XQ′ seval sound p ::= X# | p1 ∧ p2 | True XP∧ XQ

Computational Reflection MirrorShard (ITP’14) 4 / 13

slide-19
SLIDE 19

Computational Reflection [Bou97]

Write a function & prove it sound. Refl XP′∧ XQ′ = XP′∧ XQ′

Conv

seval(XP∧ XQ)(c1; ..) = XP′∧ XQ′ . . . P′ ∧ Q′ ⊢ R XP′∧ XQ′ ⊢ R

Sound

{XP∧ XQ}c1; ..{R}

Conv

{P ∧ Q}c1; ..{R} c1 c2 c3 c4 P ∧ Q P′ ∧ Q′ seval

Syntactic Semantic

denote denote XP′∧ XQ′ seval sound p ::= X# | p1 ∧ p2 | True XP∧ XQ Returned to the user

Computational Reflection MirrorShard (ITP’14) 4 / 13

slide-20
SLIDE 20

Reflective Symbolic Execution

Ind prop := True | p ∧ q Def p prop := match p with | P ∧ Q ⇒ Pprop ∧ Qprop | ... ⇒ ... Fix seval (p : prop) (c : list cmd) := match c with | nil ⇒ p | Read x y :: c ⇒ seval (eval_read p x y) c | ... ⇒ ... end Thm seval_sound : ∀ p c q, seval p c = q → {q} c {q}.

  • Proof. ..

Qed.

seval

Computational Reflection MirrorShard (ITP’14) 5 / 13

slide-21
SLIDE 21

Reflective Symbolic Execution

Ind prop := True | p ∧ q | e1→e2 Def p prop := match p with | P ∧ Q ⇒ Pprop ∧ Qprop | ... ⇒ ... Fix seval (p : prop) (c : list cmd) := match c with | nil ⇒ p | Read x y :: c ⇒ seval (eval_read p x y) c | ... ⇒ ... end Thm seval_sound : ∀ p c q, seval p c = q → {q} c {q}.

  • Proof. ..

Qed.

seval Side conditions?

Computational Reflection MirrorShard (ITP’14) 5 / 13

slide-22
SLIDE 22

Reflective Symbolic Execution

Ind arith := ... | e1 + e2 | e1 − e2 Ind prop := True | p ∧ q | e1→e2 Def p prop := match p with | P ∧ Q ⇒ Pprop ∧ Qprop | ... ⇒ ... Fix seval (p : prop) (c : list cmd) := match c with | nil ⇒ p | Read x y :: c ⇒ seval (eval_read p x y) c | ... ⇒ ... end Thm seval_sound : ∀ p c q, seval p c = q → {q} c {q}.

  • Proof. ..

Qed.

seval arith Side conditions?

Computational Reflection MirrorShard (ITP’14) 5 / 13

slide-23
SLIDE 23

Reflective Symbolic Execution

Ind arith := ... | e1 + e2 | e1 − e2 Ind lists := ... | e1 :: e2 | nil Ind prop := True | p ∧ q | e1→e2 | llist e1 e2 Def p prop := match p with | P ∧ Q ⇒ Pprop ∧ Qprop | ... ⇒ ... Fix seval (p : prop) (c : list cmd) := match c with | nil ⇒ p | Read x y :: c ⇒ seval (eval_read p x y) c | ... ⇒ ... end Thm seval_sound : ∀ p c q, seval p c = q → {q} c {q}.

  • Proof. ..

Qed.

seval arith list predicates Side conditions?

Computational Reflection MirrorShard (ITP’14) 5 / 13

slide-24
SLIDE 24

Compositional Syntax

Numbers Lists Logic

Syntactic Semantic

prop lists arith

Compositional Computational Reflection MirrorShard (ITP’14) 6 / 13

slide-25
SLIDE 25

Compositional Syntax

Simple core language

Ind typ := Typ (key : K). Ind expr := Call (key : K) (args : list expr) | Var (idx : N) Ind prop := p ∧ q | True | ∃t p

Types Terms Logic

Syntactic Semantic

prop expr type

Compositional Computational Reflection MirrorShard (ITP’14) 6 / 13

slide-26
SLIDE 26

Compositional Syntax

Simple core language Extensible via environments

Ind typ := Typ (key : K). Ind expr := Call (key : K) (args : list expr) | Var (idx : N) Ind prop := p ∧ q | True | ∃t p

Types Terms Logic

Syntactic Semantic

prop expr type ext ext ext

Compositional Computational Reflection MirrorShard (ITP’14) 6 / 13

slide-27
SLIDE 27

Compositional Syntax

Simple core language Extensible via environments

Ind typ := Typ (key : K). Ind expr := Call (key : K) (args : list expr) | Var (idx : N) Ind prop := p ∧ q | True | ∃t p

Types Terms Logic

Syntactic Semantic

prop expr type ext ext ext denote ts fs e t : typD ts t

function environment type environment return type

Compositional Computational Reflection MirrorShard (ITP’14) 6 / 13

slide-28
SLIDE 28

Reasoning with Environments

Specialized Syntax

Def prove_zero e : bool := match e with | Plus l r ⇒ .... Thm prove_zero_sound : ∀ e, prove_arith e = true → arithD e = 0.

Generic Syntax

Def prove_zero e : bool := match e with | App ? [ l ; r ] ⇒ .... Thm prove_zero_sound : ∀ ts fs e, prove_arith e = true → denote ts fs e T? = 0.

Compositional Computational Reflection MirrorShard (ITP’14) 7 / 13

slide-29
SLIDE 29

Reasoning with Environments

Specialized Syntax

Def prove_zero e : bool := match e with | Plus l r ⇒ .... Thm prove_zero_sound : ∀ e, prove_arith e = true → arithD e = 0.

Generic Syntax

Def prove_zero e : bool := match e with | App ? [ l ; r ] ⇒ .... Thm prove_zero_sound : ∀ ts fs e, prove_arith e = true → denote ts fs e T? = 0.

τ1 τ2 τ . . . Where is N?

Compositional Computational Reflection MirrorShard (ITP’14) 7 / 13

slide-30
SLIDE 30

Reasoning with Environments

Specialized Syntax

Def prove_zero e : bool := match e with | Plus l r ⇒ .... Thm prove_zero_sound : ∀ e, prove_arith e = true → arithD e = 0.

Generic Syntax

Def prove_zero e : bool := match e with | App ? [ l ; r ] ⇒ .... Thm prove_zero_sound : ∀ ts fs e, prove_arith e = true → denote ts fs e T1 = 0.

Z N R Arith τ1 τ2 τ . . . Where is N?

Compositional Computational Reflection MirrorShard (ITP’14) 7 / 13

slide-31
SLIDE 31

Reasoning with Environments

Specialized Syntax

Def prove_zero e : bool := match e with | Plus l r ⇒ .... Thm prove_zero_sound : ∀ e, prove_arith e = true → arithD e = 0.

Generic Syntax

Def prove_zero e : bool := match e with | App ? [ l ; r ] ⇒ .... Thm prove_zero_sound : ∀ ts fs e, prove_arith e = true → denote ts fs e T1 = 0.

? N ? Arith τ1 τ2 τ . . .

Compositional Computational Reflection MirrorShard (ITP’14) 7 / 13

slide-32
SLIDE 32

Reasoning with Environments

Specialized Syntax

Def prove_zero e : bool := match e with | Plus l r ⇒ .... Thm prove_zero_sound : ∀ e, prove_arith e = true → arithD e = 0.

Generic Syntax

Def prove_zero e : bool := match e with | App ? [ l ; r ] ⇒ .... Thm prove_zero_sound : ∀ ts fs e, tcarith | = ts → prove_arith e = true → denote ts fs e T1 = 0.

? N ? Arith τ1 τ2 τ . . .

Compositional Computational Reflection MirrorShard (ITP’14) 7 / 13

slide-33
SLIDE 33

Reasoning with Environments

Specialized Syntax

Def prove_zero e : bool := match e with | Plus l r ⇒ .... Thm prove_zero_sound : ∀ e, prove_arith e = true → arithD e = 0.

Generic Syntax

Def prove_zero e : bool := match e with | App ? [ l ; r ] ⇒ .... Thm prove_zero_sound : ∀ ts fs e, let ts := ts ⊕ tcarith in prove_arith e = true → denote ts fs e T1 = 0.

? N ? Arith τ1 τ2 τ . . . τ1 N τ . . . ⊕ ≡

Compositional Computational Reflection MirrorShard (ITP’14) 7 / 13

slide-34
SLIDE 34

Reasoning with Environments

Specialized Syntax

Def prove_zero e : bool := match e with | Plus l r ⇒ .... Thm prove_zero_sound : ∀ e, prove_arith e = true → arithD e = 0.

Generic Syntax

Def prove_zero e : bool := match e with | App 1 [ l ; r ] ⇒ .... Thm prove_zero_sound : ∀ ts fs e, let ts := ts ⊕ tcarith in let fs := fs ⊕ fcarith in prove_arith e = true → denote ts fs e T1 = 0.

? N ? Arith τ1 τ2 τ . . . τ1 N τ . . . ⊕ ≡ ? T1→T1→T1,+ ? F1 F2 F... F1 T1→T1→T1,+ F... ⊕ ≡

Compositional Computational Reflection MirrorShard (ITP’14) 7 / 13

slide-35
SLIDE 35

Semantic Composition

Thm arith_zero_sound : ∀ ts’ fs’, let ts := ts’ ⊕ tcarith in let fs := fs’ ⊕ fcarith in ∀ e, arith_zero hs goal = true → denote ts fs e T0 = 0.

  • Proof. ...

Qed. Thm list_nil_sound : ∀ ts’ fs’, let ts := ts’ ⊕ tclist in let fs := fs’ ⊕ fclist in ∀ e, list_nil e = true → denote ts fs e T0 = nil.

  • Proof. ...

Qed.

List Arith list N N ? ? N ?

Compositional Computational Reflection MirrorShard (ITP’14) 8 / 13

slide-36
SLIDE 36

Semantic Composition

Thm arith_zero_sound : ∀ ts’ fs’, let ts := ts’ ⊕ tcarith in let fs := fs’ ⊕ fcarith in ∀ e, arith_zero hs goal = true → denote ts fs e T0 = 0.

  • Proof. ...

Qed. Thm list_nil_sound : ∀ ts’ fs’, let ts := ts’ ⊕ tclist in let fs := fs’ ⊕ fclist in ∀ e, list_nil e = true → denote ts fs e T0 = nil.

  • Proof. ...

Qed.

List Arith list N N ? ? N ? list N N ? ⊕ ≡

Compositional Computational Reflection MirrorShard (ITP’14) 8 / 13

slide-37
SLIDE 37

Semantic Composition

Thm arith_zero_sound : ∀ ts’ fs’, let ts := ts’ ⊕ tcarith in let fs := fs’ ⊕ fcarith in ∀ e, arith_zero hs goal = true → denote ts fs e T0 = 0.

  • Proof. ...

Qed. Thm list_nil_sound : ∀ ts’ fs’, let ts := ts’ ⊕ tclist in let fs := fs’ ⊕ fclist in ∀ e, list_nil e = true → denote ts fs e T0 = nil.

  • Proof. ...

Qed.

Arith List ? N ? list N N ? list N N ? ⊕ ≡ (ts ⊕ tclist) ⊕ tcarith (ts ⊕ tcarith) ⊕ tclist

Compositional Computational Reflection MirrorShard (ITP’14) 8 / 13

slide-38
SLIDE 38

Semantic Composition

Thm arith_zero_sound : ∀ ts’ fs’, let ts := ts’ ⊕ tcarith in let fs := fs’ ⊕ fcarith in ∀ e, arith_zero hs goal = true → denote ts fs e T0 = 0.

  • Proof. ...

Qed. Thm list_nil_sound : ∀ ts’ fs’, let ts := ts’ ⊕ tclist in let fs := fs’ ⊕ fclist in ∀ e, list_nil e = true → denote ts fs e T0 = nil.

  • Proof. ...

Qed.

List Arith list N N ? ? N ? list N N ? ⊕ ≡ (ts ⊕ tclist) ⊕ tcarith (ts ⊕ tcarith) ⊕ tclist Symmetric composition Canonical environments No casts!

Compositional Computational Reflection MirrorShard (ITP’14) 8 / 13

slide-39
SLIDE 39

Compositional Symbolic Execution

Compose provers with compatible constraints Parameterize seval by provers for side-conditions seval arith list

Compositional Computational Reflection MirrorShard (ITP’14) 9 / 13

slide-40
SLIDE 40

Compositional Symbolic Execution

Compose provers with compatible constraints Parameterize seval by provers for side-conditions seval arith list autorewrite 1s 1s

Compositional Computational Reflection MirrorShard (ITP’14) 9 / 13

slide-41
SLIDE 41

Compositional Symbolic Execution

Compose provers with compatible constraints Parameterize seval by provers for side-conditions seval arith list predicates

Compositional Computational Reflection MirrorShard (ITP’14) 9 / 13

slide-42
SLIDE 42

Generic (Reflective) Extension

Abstraction enables generic, reusable procedures. → Avoid boiler-plate automation & proofs! autorewrite – rewrite with a collection of lemmas

Def sll : list W → W → HProp := ... Thm nil_fwd : ∀ ls (p : W), p = 0 → sll ls p = ⇒ ⌈ ls = nil ⌉.

  • Proof. ..

Qed. Thm cons_fwd : ∀ ls (p : W), p = 0 → sll ls p = ⇒ ∃ x, ∃ ls’, ⌈ ls = x :: ls’ ⌉ ∗ ∃ p’, p → (x, p’) ∗ sll ls’ p’.

  • Proof. ..

Qed. Thm sllMOk : moduleOk sllM.

  • Proof. vcgen; abstract (sep hints; finish). Qed.

Generic Extension MirrorShard (ITP’14) 10 / 13

slide-43
SLIDE 43

Generic (Reflective) Extension

Abstraction enables generic, reusable procedures. → Avoid boiler-plate automation & proofs! autorewrite – rewrite with a collection of lemmas

Def sll : list W → W → HProp := ... Thm nil_fwd : ∀ ls (p : W), p = 0 → sll ls p = ⇒ ⌈ ls = nil ⌉.

  • Proof. ..

Qed. Thm cons_fwd : ∀ ls (p : W), p = 0 → sll ls p = ⇒ ∃ x, ∃ ls’, ⌈ ls = x :: ls’ ⌉ ∗ ∃ p’, p → (x, p’) ∗ sll ls’ p’.

  • Proof. ..

Qed. Thm sllMOk : moduleOk sllM.

  • Proof. vcgen; abstract (sep hints; finish). Qed.

Hint Database Constructed automatically

Generic Extension MirrorShard (ITP’14) 10 / 13

slide-44
SLIDE 44

Generic (Reflective) Extension

Abstraction enables generic, reusable procedures. → Avoid boiler-plate automation & proofs! autorewrite – rewrite with a collection of lemmas

Def sll : list W → W → HProp := ... Thm nil_fwd : ∀ ls (p : W), p = 0 → sll ls p = ⇒ ⌈ ls = nil ⌉.

  • Proof. ..

Qed. Thm cons_fwd : ∀ ls (p : W), p = 0 → sll ls p = ⇒ ∃ x, ∃ ls’, ⌈ ls = x :: ls’ ⌉ ∗ ∃ p’, p → (x, p’) ∗ sll ls’ p’.

  • Proof. ..

Qed. Thm sllMOk : moduleOk sllM.

  • Proof. vcgen; abstract (sep hints; finish). Qed.

Hint Database rewrite all rewrite all sound

Generic Extension MirrorShard (ITP’14) 10 / 13

slide-45
SLIDE 45

Generic (Reflective) Extension

Abstraction enables generic, reusable procedures. → Avoid boiler-plate automation & proofs! autorewrite – rewrite with a collection of lemmas

Def sll : list W → W → HProp := ... Thm nil_fwd : ∀ ls (p : W), p = 0 → sll ls p = ⇒ ⌈ ls = nil ⌉.

  • Proof. ..

Qed. Thm cons_fwd : ∀ ls (p : W), p = 0 → sll ls p = ⇒ ∃ x, ∃ ls’, ⌈ ls = x :: ls’ ⌉ ∗ ∃ p’, p → (x, p’) ∗ sll ls’ p’.

  • Proof. ..

Qed. Thm sllMOk : moduleOk sllM.

  • Proof. vcgen; abstract (sep hints; finish). Qed.

Hint Database rewrite all rewrite all sound

Generic Extension MirrorShard (ITP’14) 10 / 13

slide-46
SLIDE 46

Compositional Symbolic Execution

Compose provers with compatible constraints Parameterize seval by provers for side-conditions seval arith list predicates

Generic Extension MirrorShard (ITP’14) 11 / 13

slide-47
SLIDE 47

Compositional Symbolic Execution

Compose provers with compatible constraints Parameterize seval by provers for side-conditions Include predicate unfolding hints seval arith list predicates end-to-end 0.3s 6x faster!

Generic Extension MirrorShard (ITP’14) 11 / 13

slide-48
SLIDE 48

Related Work

“Intensional” Theories (e.g. Coq, Agda)

1

Simple Types [GW07] – Similar term representation

2

AAC Tactics, ROmega, field, ring [BP11, GM05, Les11] – reflective procedures

3

Posteriori Simulation [CCGHRGZ13] – Faster computation

4

Mtac [ZDK+13] – Coq extension (proof-generating)

5

SSreflect [GM10] – Coq library (proof-generating)

Recap MirrorShard (ITP’14) 12 / 13

slide-49
SLIDE 49

Related Work

“Intensional” Theories (e.g. Coq, Agda)

1

Simple Types [GW07] – Similar term representation

2

AAC Tactics, ROmega, field, ring [BP11, GM05, Les11] – reflective procedures

3

Posteriori Simulation [CCGHRGZ13] – Faster computation

4

Mtac [ZDK+13] – Coq extension (proof-generating)

5

SSreflect [GM10] – Coq library (proof-generating)

“Extensional” Theories

1

VeriML [SS10], NuPrl

2

LF

Internalized judgemental equality

Recap MirrorShard (ITP’14) 12 / 13

slide-50
SLIDE 50

Recap

bfunction "length"("x", "n") [lengthS] "n" ← 0;; [ ∀ ls, PRE[V] sll ls (V "x") POST[R] ⌈ R = V "n" + length ls ⌉ ∗ sll ls (V "x")] While ("x" = 0) { "n" ← "n" + 1;; "x" ← "x" + 4;; "x" ← ∗ "x" };; Return "n" Def sll : list W → W → HProp := ... Thm nil_fwd : ∀ ls (p : W), p = 0 → sll ls p = ⇒ ⌈ ls = nil ⌉.

  • Proof. ..

Qed. Thm cons_fwd : ∀ ls (p : W), p = 0 → sll ls p = ⇒ ∃ x, ∃ ls’, ⌈ ls = x :: ls’ ⌉ ∗ ∃ p’, p → (x, p’) ∗ sll ls’ p’.

  • Proof. ..

Qed.

seval ⊕ entailment ⊕ rewriting ⊕ lemmas ⊕ provers

Thm sllMOk : moduleOk sllM.

  • Proof. vcgen; abstract (sep hints; finish). Qed.

https://github.com/gmalecha/mirror-shard https://github.com/gmalecha/bedrock-mirror-shard

MirrorCore @ Coq Workshop

Recap MirrorShard (ITP’14) 13 / 13

slide-51
SLIDE 51

References I

Samuel Boutin. Using reflection to build efficient and certified decision procedures. In Proc. TACS, 1997. Thomas Braibant and Damien Pous. Tactics for reasoning modulo AC in Coq. In Proc. CPP, 2011. Guillaume Claret, Lourdes Carmen Gonzlez Huesca, Yann Rgis-Gianas, and Beta Ziliani. Lightweight proof by reflection using a posteriori simulation of effectful computation. In Sandrine Blazy, Christine Paulin-Mohring, and David Pichardie, editors, Interactive Theorem Proving, volume 7998 of Lecture Notes in Computer Science, pages 67–83. Springer Berlin Heidelberg, 2013. Adam Chlipala. Mostly-automated verification of low-level programs in computational separation logic. In Proc. PLDI, pages 234–245. ACM, 2011.

  • B. Gr´

egoire and A. Mahboubi. Proving equalities in a commutative ring done right in Coq. In Proc. TPHOLs, 2005. Georges Gonthier and Assia Mahboubi. An introduction to small scale reflection in Coq. Journal of Formalized Reasoning, 3(2):95–152, 2010. Franois Garillot and Benjamin Werner. Simple types in type theory: Deep and shallow encodings. In Theorem Proving in Higher Order Logics, volume 4732 of LNCS, pages 368–382. Springer Berlin Heidelberg, 2007. References MirrorShard (ITP’14) 14 / 13

slide-52
SLIDE 52

References II

St´ ephane Lescuyer. Formalisation et d´ eveloppement d’une tactique r´ eflexive pour la d´ emonstration automatique en Coq. Th` ese de doctorat, Universit´ e Paris-Sud, January 2011. Antonis Stampoulis and Zhong Shao. VeriML: typed computation of logical terms inside a language with effects. In Proc. ICFP, pages 333–344. ACM, 2010. Beta Ziliani, Derek Dreyer, Neel Krishnaswami, Aleksandar Nanevski, and Viktor Vafeiadis. Mtac: A monad for typed tactic programming in Coq. In Proc. ICFP, 2013. References MirrorShard (ITP’14) 15 / 13