low level code and high level theorems
play

Low-Level Code and High-Level Theorems Sascha Bhme Technische - PowerPoint PPT Presentation

Low-Level Code and High-Level Theorems Sascha Bhme Technische Universitt Mnchen, Germany Joint work with Eyad Alkassar 1 , Ernie Cohen 2 , Kurt Mehlhorn 3 and Christine Rizkallah 3 1 Universitt des Saarlandes, Germany 2 European Microsoft


  1. Low-Level Code and High-Level Theorems Sascha Böhme Technische Universität München, Germany Joint work with Eyad Alkassar 1 , Ernie Cohen 2 , Kurt Mehlhorn 3 and Christine Rizkallah 3 1 Universität des Saarlandes, Germany 2 European Microsoft Innovation Center, Aachen, Germany 3 Max-Planck-Institut für Informatik, Saarbrücken, Germany 1

  2. C code 2

  3. program C code verification 2

  4. theorem program C code verification 2

  5. interactive theorem theorem prover program C code verification 2

  6. interactive theorem theorem prover program C code verification 2

  7. Isabelle/HOL interactive theorem theorem prover program C code verification VCC 2

  8. VCC: ◮ assertional verifier for full C ◮ first-order logic as specification language ◮ fully automatic thanks to Boogie and Z3 ◮ specification by code annotations ◮ function contracts, object invariants ◮ ghost code, ghost functions 3

  9. VCC: ◮ assertional verifier for full C ◮ first-order logic as specification language ◮ fully automatic thanks to Boogie and Z3 ◮ specification by code annotations ◮ function contracts, object invariants ◮ ghost code, ghost functions Isabelle/HOL: ◮ interactive theorem prover for higher-order logic ◮ rich set of formalized mathematics ◮ various automated provers 3

  10. Isabelle/HOL interactive theorem theorem prover program C code verification VCC 4

  11. Isabelle/HOL interactive theorem theorem prover LEDA graph algorithms program C code verification VCC 4

  12. LEDA graph algorithms 4

  13. 5

  14. Programmers 5

  15. Social programmers Graph 5

  16. Pair programming Matching 5

  17. Optimal pair programming Maximum cardinality matching 5

  18. Definitions Matching: ◮ a graph ◮ no edge is incident to another edge 6

  19. Definitions Matching: ◮ a graph ◮ no edge is incident to another edge Odd-set cover: ◮ labeling of nodes ◮ every edge is incident to a node labeled 1 or connects two nodes labeled i (with i ≥ 2) 6

  20. Optimal pair programming Maximum cardinality matching 7

  21. Certificate Odd-set cover 1 0 1 0 2 2 1 2 0 7

  22. Theorem The maximum cardinality of a graph matching is � ⌊ n i / 2 ⌋ n 1 + i ≥ 2 where n i is the number of nodes labeled i by an odd-set cover. 8

  23. LEDA graph algorithms 9

  24. Isabelle/HOL interactive theorem theorem prover LEDA graph algorithms program C code verification VCC 9

  25. LEDA graph algorithms program C code verification VCC 9

  26. Maximum Cardinality Matching Checker C Code 10

  27. Maximum Cardinality Matching Checker C Code Given: ◮ graph G ◮ graph M (maximum cardinality matching) ◮ labeling OSC (odd-set cover) 10

  28. Maximum Cardinality Matching Checker C Code Given: ◮ graph G ◮ graph M (maximum cardinality matching) ◮ labeling OSC (odd-set cover) Check: ◮ M is a matching ◮ M is a subset of G ◮ OSC is an odd-set cover of G ◮ M is maximal wrt. G and OSC 10

  29. Maximum Cardinality Matching Checker C Code Given: ◮ graph G ◮ graph M (maximum cardinality matching) ◮ labeling OSC (odd-set cover) Check: ◮ M is a matching ◮ M is a subset of G ◮ OSC is an odd-set cover of G ◮ M is maximal wrt. G and OSC Implementation: ◮ straightforward 10

  30. Maximum Cardinality Matching Checker Specification struct graph { edge * es; unsigned n_edges, n_nodes; } 11

  31. Maximum Cardinality Matching Checker Specification struct graph { edge * es; unsigned n_edges, n_nodes; invariant( ∀ (unsigned e; e < n_edges − → es[e].s < n_nodes ∧ es[e].t < n_nodes ∧ es[e].s � = es[e].t)) } 11

  32. Maximum Cardinality Matching Checker Specification struct graph { edge * es; unsigned n_edges, n_nodes; invariant( ∀ (unsigned e; e < n_edges − → es[e].s < n_nodes ∧ es[e].t < n_nodes ∧ es[e].s � = es[e].t)) } spec(bool spec_is_osc(graph * G, unsigned * osc) returns(... ∧ ∀ (unsigned e; e < G->n_edges − → osc[G->es[e].s] = 1 ∨ osc[G->es[e].t] = 1 ∨ (osc[G->es[e].t] = osc[G->es[e].s] ∧ osc[G->es[e].t] > 1)));) 11

  33. What is proved? check(G, M, osc) = true ← → |M| = n 1 + � i ≥ 2 ⌊ n i / 2 ⌋ 12

  34. What is proved? check(G, M, osc) = true ← → |M| = n 1 + � i ≥ 2 ⌊ n i / 2 ⌋ What is missing? |M| = n 1 + � i ≥ 2 ⌊ n i / 2 ⌋ − → ( ∀ M’. is_matching(M’) ∧ is_subset(G,M’) − → |M’| ≤ |M|) 12

  35. What is proved? check(G, M, osc) = true ← → |M| = n 1 + � i ≥ 2 ⌊ n i / 2 ⌋ What is missing? |M| = n 1 + � i ≥ 2 ⌊ n i / 2 ⌋ − → ( ∀ M’. is_matching(M’) ∧ is_subset(G,M’) − → |M’| ≤ |M|) VCC: ◮ good at low-level code verification ◮ not much support for high-level proofs 12

  36. What is proved? check(G, M, osc) = true ← → |M| = n 1 + � i ≥ 2 ⌊ n i / 2 ⌋ What is missing? |M| = n 1 + � i ≥ 2 ⌊ n i / 2 ⌋ − → ( ∀ M’. is_matching(M’) ∧ is_subset(G,M’) − → |M’| ≤ |M|) VCC: ◮ good at low-level code verification ◮ not much support for high-level proofs Requires abstraction! 12

  37. LEDA graph algorithms program C code verification VCC 13

  38. Isabelle/HOL interactive theorem theorem prover LEDA graph algorithms program C code verification VCC 13

  39. Isabelle/HOL interactive theorem theorem prover program C code verification VCC 13

  40. 14

  41. Isabelle/HOL VCC 14

  42. Isabelle/HOL VCC concrete assert(p(x)); property 14

  43. Isabelle/HOL VCC abstract spec(bool P(X) returns(...);) property concrete assert(p(x)); property 14

  44. Isabelle/HOL VCC abstract spec(bool P(X) returns(...);) property spec(void P_equivalence(x) ensures(p(x) ⇐ ⇒ P(abs(x)));) concrete assert(p(x)); property 14

  45. Isabelle/HOL VCC abstract spec(bool P(X) returns(...);) property spec(void P_holds(X) ensures(P(X));) spec(void P_equivalence(x) ensures(p(x) ⇐ ⇒ P(abs(x)));) concrete assert(p(x)); property 14

  46. Isabelle/HOL formal definition P where “P(X) = . . . ” theorem P_holds: “P(X)” � proof � proof VCC abstract spec(bool P(X) returns(...);) property spec(void P_holds(X) ensures(P(X));) spec(void P_equivalence(x) ensures(p(x) ⇐ ⇒ P(abs(x)));) concrete assert(p(x)); property 14

  47. Maximum Cardinality Matching Checker VCC 15

  48. Maximum Cardinality Matching Checker VCC struct abs_graph { abs_edge es[mathint]; mathint n_edges, n_nodes; }; 15

  49. Maximum Cardinality Matching Checker VCC struct abs_graph { abs_edge es[mathint]; mathint n_edges, n_nodes; }; spec(abs_graph abs_g(graph * G) ensures(...);) 15

  50. Maximum Cardinality Matching Checker VCC struct abs_graph { abs_edge es[mathint]; mathint n_edges, n_nodes; }; spec(abs_graph abs_g(graph * G) ensures(...);) spec(bool abs_is_osc(abs_graph G, abs_fun osc) ensures(...);) 15

  51. Maximum Cardinality Matching Checker VCC struct abs_graph { abs_edge es[mathint]; mathint n_edges, n_nodes; }; spec(abs_graph abs_g(graph * G) ensures(...);) spec(bool abs_is_osc(abs_graph G, abs_fun osc) ensures(...);) void is_osc_equivalence(graph * G, unsigned * osc) ensures( spec_is_osc(G, osc) ⇐ ⇒ abs_is_osc(abs_g(G), abs_f(osc))); 15

  52. Maximum Cardinality Matching Checker Isabelle/HOL 16

  53. Maximum Cardinality Matching Checker Isabelle/HOL record abs_graph = es :: int ⇒ abs_edge n_edges, n_nodes :: int 16

  54. Maximum Cardinality Matching Checker Isabelle/HOL record abs_graph = es :: int ⇒ abs_edge n_edges, n_nodes :: int definition abs_is_osc where “abs_is_osc G osc = (. . . ∧ ( ∀ e. 0 ≤ e ∧ e < n_edges G − → osc (s (es G e)) = 1 ∨ osc (t (es G e)) = 1 ∨ (osc (t (es G e)) = osc (s (es G e)) ∧ osc (t (es G e)) > 1)))” 16

  55. Maximum Cardinality Matching Checker Isabelle/HOL record abs_graph = es :: int ⇒ abs_edge n_edges, n_nodes :: int definition abs_is_osc where “abs_is_osc G osc = (. . . ∧ ( ∀ e. 0 ≤ e ∧ e < n_edges G − → osc (s (es G e)) = 1 ∨ osc (t (es G e)) = 1 ∨ (osc (t (es G e)) = osc (s (es G e)) ∧ osc (t (es G e)) > 1)))” theorem “|M| = n 1 + � i ≥ 2 ⌊ n i / 2 ⌋ − → ( ∀ M’. is_matching(M’) ∧ is_subset(G,M’) − → |M’| ≤ |M|)” � proof � 16

  56. Combination of VCC and Isabelle/HOL ◮ combines the best of both worlds ◮ low-level code verification with VCC ◮ high-level mathematical reasoning with Isabelle/HOL ◮ sound combination ◮ clean separation of concepts 17

  57. Isabelle/HOL interactive theorem theorem prover program C code verification VCC 18

  58. Isabelle/HOL interactive theorem theorem prover LEDA graph algorithms program C code verification VCC 18

Recommend


More recommend