+ Proofs Harnessing SMT solvers for TLA Stephan Merz and Hern an - - PowerPoint PPT Presentation

proofs harnessing smt solvers for tla
SMART_READER_LITE
LIVE PREVIEW

+ Proofs Harnessing SMT solvers for TLA Stephan Merz and Hern an - - PowerPoint PPT Presentation

+ Proofs Harnessing SMT solvers for TLA Stephan Merz and Hern an Vanzetto + Workshop, Paris, France TLA August 27th, 2012 1 Introduction + proof language: TLA Hierarchical proof structure Top-down development: users refine assertions


slide-1
SLIDE 1

Harnessing SMT solvers for TLA

+ Proofs Stephan Merz and Hern´ an Vanzetto TLA

+ Workshop, Paris, France

August 27th, 2012

1

slide-2
SLIDE 2

Introduction

TLA

+ proof language:

Hierarchical proof structure Top-down development: users refine assertions until they are “obvious” Leaf steps verified by automatic backend provers

◮ invoke proof method ◮ cite necessary assumptions and facts ◮ expand definitions

TLA

+ Proof System:

Mechanically checks TLA

+ proofs

Currently proves only non-temporal fragment Supported by the TLA

+ Toolbox

2

slide-3
SLIDE 3

Architecture of TLAPS

3

slide-4
SLIDE 4

Current backend provers

Isabelle/TLA

+

◮ Faithful encoding of TLA

+ over Isabelle’s meta-logic

◮ Calls predefined Isabelle automatic proof methods ◮ Used to certify proofs of other backend provers 4

slide-5
SLIDE 5

Current backend provers

Isabelle/TLA

+

◮ Faithful encoding of TLA

+ over Isabelle’s meta-logic

◮ Calls predefined Isabelle automatic proof methods ◮ Used to certify proofs of other backend provers

Zenon

◮ Tableau prover for first-order logic with equality ◮ Includes extensions for TLA

+ on sets, functions, ...

◮ Backend called by default ; proofs certified by Isabelle 4

slide-6
SLIDE 6

Current backend provers

Isabelle/TLA

+

◮ Faithful encoding of TLA

+ over Isabelle’s meta-logic

◮ Calls predefined Isabelle automatic proof methods ◮ Used to certify proofs of other backend provers

Zenon

◮ Tableau prover for first-order logic with equality ◮ Includes extensions for TLA

+ on sets, functions, ...

◮ Backend called by default ; proofs certified by Isabelle

SimpleArithmetic (obsolete)

◮ Cooper’s algorithm for Presburger arithmetic 4

slide-7
SLIDE 7

Current backend provers

Isabelle/TLA

+

◮ Faithful encoding of TLA

+ over Isabelle’s meta-logic

◮ Calls predefined Isabelle automatic proof methods ◮ Used to certify proofs of other backend provers

Zenon

◮ Tableau prover for first-order logic with equality ◮ Includes extensions for TLA

+ on sets, functions, ...

◮ Backend called by default ; proofs certified by Isabelle

SimpleArithmetic (obsolete)

◮ Cooper’s algorithm for Presburger arithmetic

SMT

◮ Available since the last public version of TLAPS (v1.0) ◮ Based on type inference 4

slide-8
SLIDE 8

Motivation

Typical proof obligations usually contain a mix of arithmetic, sets, functions, which the older backends were not able to handle at once SMT solvers offer a combination of: + First-order reasoning + Decision procedures for other theories (=, linear arithmetic, . . . ) SMT input languages: Based on many-sorted first-order logic Predefined Bool and integer sorts Uninterpreted functions, if-then-else function

5

slide-9
SLIDE 9

Table of Contents

1

Introduction

2

First approach: SMT backend based on type inference

3

Second approach: untyped encoding

4

Experimental results

5

Conclusions

6

slide-10
SLIDE 10

First approach: a backend based on type inference

7

slide-11
SLIDE 11

First approach: a backend based on type inference

Inference algorithm recurses over TLA

+ expressions

◮ Ad-hoc type system for TLA

+ terms

(unspecified type ⊥, integer type, sets, functions, . . . )

7

slide-12
SLIDE 12

First approach: a backend based on type inference

Inference algorithm recurses over TLA

+ expressions

◮ Ad-hoc type system for TLA

+ terms

(unspecified type ⊥, integer type, sets, functions, . . . )

Soundness: incorrect typing can make invalid theorems provable

◮ x /

∈ Int ⇒ x + 0 = x ; (¬¬X) = X

7

slide-13
SLIDE 13

First approach: a backend based on type inference

Inference algorithm recurses over TLA

+ expressions

◮ Ad-hoc type system for TLA

+ terms

(unspecified type ⊥, integer type, sets, functions, . . . )

Soundness: incorrect typing can make invalid theorems provable

◮ x /

∈ Int ⇒ x + 0 = x ; (¬¬X) = X

Safe types: ⊥, set(⊥), set(set(⊥)), . . . Typing hypotheses are available facts of the form x ≈ exp and ∀ y ∈ S : f ( y) ≈ exp with ≈ ∈ {=, ∈ , ⊆}

7

slide-14
SLIDE 14

First approach: a backend based on type inference

Well-typed TLA

+ formulas are translated to SMT input formats

Basic TLA

+ expressions contain only operators that have a

direct representation in SMT formats (logical, arithm. and ifs) Sets, functions, records, tuples encoded as uninterpreted functions

Example

x :: Z ⊢ x ∈ Int ⇒ x + 0 = x − → x + 0 = x a :: ⊥ ; S,T :: set(⊥) ⊢ a ∈ S ∪ T − → S(a) ∨ T(a) Type information for variables usually provided by type invariants

8

slide-15
SLIDE 15

Toy example

axiom NatInduction ≡ assume new P( ), P(0), ∀n ∈ Nat : P(n) ⇒ P(n + 1) prove ∀n ∈ Nat : P(n)

9

slide-16
SLIDE 16

Toy example

axiom NatInduction ≡ assume new P( ), P(0), ∀n ∈ Nat : P(n) ⇒ P(n + 1) prove ∀n ∈ Nat : P(n) theorem GeneralNatInduction ≡ assume new P( ), ∀n ∈ Nat : P(n) ∈ boolean, (typing hypothesis) ∀n ∈ Nat : (∀m ∈ 0..(n − 1) : P(m)) ⇒ P(n) prove ∀n ∈ Nat : P(n)

  • 1. define Q(n) ≡ ∀m ∈ 0..n : P(m)
  • 11. Q(0)

by SMT

  • 12. ∀n ∈ Nat : Q(n) ⇒ Q(n + 1) by SMT
  • 13. ∀n ∈ Nat : Q(n)

by 11, 12, NatInduction,SMT

  • 14. qed

by 13, SMT

9

slide-17
SLIDE 17

Second approach: untyped encoding

10

slide-18
SLIDE 18

Second approach: untyped encoding

TLA

+ terms are mapped to a unique SMT sort U

Operators are uninterpreted functions or predicates

◮ union : U × U → U

in : U × U → Bool

Operators’ semantics are defined axiomatically

◮ Axiom for ∪:

∀x, S, T : U. (x ∈ S ∪ T) = (x ∈ S ∨ x ∈ T)

◮ Primitive operators (∈, f [x], domain) are left uninterpreted

Functions are related to its argument by apply : U × U → U

10

slide-19
SLIDE 19

Encoding arithmetic

Arithmetic expressions are lifted to elements on sort U Embedding function φ : Int → U (uninterpreted and injective) 42 is encoded as φ(42) x ∈ Int is encoded as ∃n : Int. x = φ(n)

11

slide-20
SLIDE 20

Encoding arithmetic

Arithmetic expressions are lifted to elements on sort U Embedding function φ : Int → U (uninterpreted and injective) 42 is encoded as φ(42) x ∈ Int is encoded as ∃n : Int. x = φ(n) Arithmetic operators are homomorphically embedded using φ +U : U × U → U Axiom for +: ∀m, n : Int. φ(m) +U φ(n) = φ(m + n)

Example

∀x ∈ Int : x + 0 = x − → ∀x : U. (∃n : Int. x = φ(n)) ⇒ x +U φ(0) = x

11

slide-21
SLIDE 21

Normalisation: removing non-basic operators

1 Grounding expressions: rewrite based on operator semantics ◮ [

[x ∈ e] ] ≡ [ [x] ] ∈ [ [e] ] [ [e1 ∨ e2] ] ≡ [ [e1] ] ∨ [ [e2] ]

◮ [

[x ∈ e1 ∪ e2] ] ≡ [ [x ∈ e1 ∨ x ∈ e2] ]

◮ [

[S ⊆ T] ] ≡ [ [∀x : x ∈ S ⇒ x ∈ T] ]

12

slide-22
SLIDE 22

Normalisation: removing non-basic operators

1 Grounding expressions: rewrite based on operator semantics ◮ [

[x ∈ e] ] ≡ [ [x] ] ∈ [ [e] ] [ [e1 ∨ e2] ] ≡ [ [e1] ] ∨ [ [e2] ]

◮ [

[x ∈ e1 ∪ e2] ] ≡ [ [x ∈ e1 ∨ x ∈ e2] ]

◮ [

[S ⊆ T] ] ≡ [ [∀x : x ∈ S ⇒ x ∈ T] ]

2 Disambiguation of equalities by inferred kinds ◮ [

[S = T] ] ≡ ∀x : [ [x ∈ S ⇔ x ∈ T] ] (when S, T are sets)

◮ S = {a} ∪ {}

− → ∀x : x ∈ S ⇔ x = a ∨ false

12

slide-23
SLIDE 23

Normalisation: removing non-basic operators

1 Grounding expressions: rewrite based on operator semantics ◮ [

[x ∈ e] ] ≡ [ [x] ] ∈ [ [e] ] [ [e1 ∨ e2] ] ≡ [ [e1] ] ∨ [ [e2] ]

◮ [

[x ∈ e1 ∪ e2] ] ≡ [ [x ∈ e1 ∨ x ∈ e2] ]

◮ [

[S ⊆ T] ] ≡ [ [∀x : x ∈ S ⇒ x ∈ T] ]

2 Disambiguation of equalities by inferred kinds ◮ [

[S = T] ] ≡ ∀x : [ [x ∈ S ⇔ x ∈ T] ] (when S, T are sets)

◮ S = {a} ∪ {}

− → ∀x : x ∈ S ⇔ x = a ∨ false

3 Term-rewriting of top-level equalities ◮ assume T = {1,2}

prove T ⊆ Int − → ∀x : (x = 1 ∨ x = 2) ⇒ x ∈ Int

12

slide-24
SLIDE 24

Normalisation: removing non-basic operators

1 Grounding expressions: rewrite based on operator semantics ◮ [

[x ∈ e] ] ≡ [ [x] ] ∈ [ [e] ] [ [e1 ∨ e2] ] ≡ [ [e1] ] ∨ [ [e2] ]

◮ [

[x ∈ e1 ∪ e2] ] ≡ [ [x ∈ e1 ∨ x ∈ e2] ]

◮ [

[S ⊆ T] ] ≡ [ [∀x : x ∈ S ⇒ x ∈ T] ]

2 Disambiguation of equalities by inferred kinds ◮ [

[S = T] ] ≡ ∀x : [ [x ∈ S ⇔ x ∈ T] ] (when S, T are sets)

◮ S = {a} ∪ {}

− → ∀x : x ∈ S ⇔ x = a ∨ false

3 Term-rewriting of top-level equalities ◮ assume T = {1,2}

prove T ⊆ Int − → ∀x : (x = 1 ∨ x = 2) ⇒ x ∈ Int

4 Abstraction of non-basic operators ◮ ∀a : P({a}∪{}) ⇔ P({a}) −

→ ∀a, s1, s2 : ∧ s1 = {a} ∪ {} ∧ s2 = {a} ⇒ P(s1) ⇔ P(s2)

12

slide-25
SLIDE 25

Experimental results

N-process Bakery algorithm

◮ includes some basic arithmetic

Memoir security architecture

◮ mostly based on records

Module Cardinality of finite sets Original Typed-SMT/Z3 Untyped-SMT/Z3 size time size time size time Bakery 120 15.66 3 2.76 4 0.67 Memoir 424 7.31 14 5.08 14 1.11 Cardinality 185 2.12

  • 54

0.88

(length = number of non-trivial proof-obligations ; time in seconds)

  • Original = proof using Zenon, Isabelle/TLA

+, SimpleArithmetic

13

slide-26
SLIDE 26

Conclusions

Typed encoding Untyped encoding Handled fragment first-order logic, sets, functions, records, tuples no sets of sets choose operator Efficiency scales well for large formulas more quantifiers Type inference may fail for valid obli- gations delegated to the solver may require logically unnecessary typing hy- potheses no need of typing hy- potheses ; preferred by users Soundness analysis non-trivial ; relies on type inference immediate ; all axioms are theorems

14

slide-27
SLIDE 27

Future work

Work in progress: Merge both encodings Based on the untyped encoding Instantiate arithmetic expressions using type information Future work: Adapt this translation to use ATPs with arithmetic (Spass+LA) Interpret the solvers output and certify it with Isabelle/TLA

+

15

slide-28
SLIDE 28

Example: how the SMT solver use the axioms

Consider the TLA

+ proof obligation

∀x ∈ Int : x + 0 = x which is translated as ∀x : U. (∃n : Int. x = φ(n)) ⇒ x +U φ(0) = x. By Skolemization, the solver introduces a new constant, say n, of sort Int, such that x = φ(n). It can then reason as follows: x +U φ(0) = φ(n) +U φ(0) (x = φ(n)) = φ(n + 0) (by axiom of +U) = φ(n) (by the SMT arithmetic procedure) = x (x = φ(n))

16

slide-29
SLIDE 29

Encoding of choose

1 Any expression choose x : P(x) can be abstracted to a new

variable s, for which the following equality is asserted: s = choose x : P(x)

2 Use of the following TLA

+ theorem to ground the expression

y = (choose x : P(x)) ⇒

  • (∃x : P(x)) ⇒ P(y)
  • 3 Determinacy of choose . For every pair of expressions

choose x : P(x) and choose x : Q(x) that appear in the proof obligation, we add the following axiom: (∀x : P(x) ⇔ Q(x)) ⇒ (choose x : P(x)) = (choose x : Q(x))

17