Cyclic abduction of inductive safety & termination preconditions - - PowerPoint PPT Presentation

cyclic abduction of inductive safety termination
SMART_READER_LITE
LIVE PREVIEW

Cyclic abduction of inductive safety & termination preconditions - - PowerPoint PPT Presentation

Cyclic abduction of inductive safety & termination preconditions James Brotherston University College London LIX Colloquium, Tues 5 Nov 2013 Joint work with Nikos Gorogiannis (Middlesex) 1/ 27 Part I Introduction and motivations 2/ 27


slide-1
SLIDE 1

Cyclic abduction of inductive safety & termination preconditions

James Brotherston

University College London

LIX Colloquium, Tues 5 Nov 2013 Joint work with Nikos Gorogiannis (Middlesex)

1/ 27

slide-2
SLIDE 2

Part I Introduction and motivations

2/ 27

slide-3
SLIDE 3

Introduction

  • Classical CS questions: is my program memory-safe, and

does it terminate?

3/ 27

slide-4
SLIDE 4

Introduction

  • Classical CS questions: is my program memory-safe, and

does it terminate?

  • Refined version: is my program safe and/or terminating,

given that it satisfies some precondition?

3/ 27

slide-5
SLIDE 5

Introduction

  • Classical CS questions: is my program memory-safe, and

does it terminate?

  • Refined version: is my program safe and/or terminating,

given that it satisfies some precondition?

  • Even more refined version: can we find a reasonable

precondition under which my program is safe and/or terminating?

3/ 27

slide-6
SLIDE 6

Introduction

  • Classical CS questions: is my program memory-safe, and

does it terminate?

  • Refined version: is my program safe and/or terminating,

given that it satisfies some precondition?

  • Even more refined version: can we find a reasonable

precondition under which my program is safe and/or terminating?

  • In this talk, we focus on this last question, using inductive

definitions in separation logic to describe preconditions.

3/ 27

slide-7
SLIDE 7

A simple example

Consider the following list traversal program: while x = nil do x = x.next od; Which preconditions guarantee safe termination?

4/ 27

slide-8
SLIDE 8

A simple example

Consider the following list traversal program: while x = nil do x = x.next od; Which preconditions guarantee safe termination? x = nil

4/ 27

slide-9
SLIDE 9

A simple example

Consider the following list traversal program: while x = nil do x = x.next od; Which preconditions guarantee safe termination? x = nil x → nil

4/ 27

slide-10
SLIDE 10

A simple example

Consider the following list traversal program: while x = nil do x = x.next od; Which preconditions guarantee safe termination? x = nil x → nil x → x′ ∗ x′ → nil . . .

4/ 27

slide-11
SLIDE 11

A simple example

Consider the following list traversal program: while x = nil do x = x.next od; Which preconditions guarantee safe termination? x = nil x → nil x → x′ ∗ x′ → nil . . . Most general solution is an acyclic linked list, given by x = nil ⇒ list(x) x = nil ∗ x → y ∗ list(y) ⇒ list(x)

4/ 27

slide-12
SLIDE 12

  • le in automated verification
  • A number of automatic verifiers employ separation logic to

analyse industrial code (e.g. SpaceInvader, SLAyer)

5/ 27

slide-13
SLIDE 13

  • le in automated verification
  • A number of automatic verifiers employ separation logic to

analyse industrial code (e.g. SpaceInvader, SLAyer)

  • These analysers rely on inductive predicates to describe

data structures manipulated by programs (lists, trees etc.)

5/ 27

slide-14
SLIDE 14

  • le in automated verification
  • A number of automatic verifiers employ separation logic to

analyse industrial code (e.g. SpaceInvader, SLAyer)

  • These analysers rely on inductive predicates to describe

data structures manipulated by programs (lists, trees etc.)

  • Presently, these tools are limited to a few hard-wired such
  • definitions. . .

5/ 27

slide-15
SLIDE 15

  • le in automated verification
  • A number of automatic verifiers employ separation logic to

analyse industrial code (e.g. SpaceInvader, SLAyer)

  • These analysers rely on inductive predicates to describe

data structures manipulated by programs (lists, trees etc.)

  • Presently, these tools are limited to a few hard-wired such
  • definitions. . .
  • . . . which means they must fail, or ask for advice, when

encountering a “foreign” data structure.

5/ 27

slide-16
SLIDE 16

  • le in automated verification
  • A number of automatic verifiers employ separation logic to

analyse industrial code (e.g. SpaceInvader, SLAyer)

  • These analysers rely on inductive predicates to describe

data structures manipulated by programs (lists, trees etc.)

  • Presently, these tools are limited to a few hard-wired such
  • definitions. . .
  • . . . which means they must fail, or ask for advice, when

encountering a “foreign” data structure.

  • It would be nice if we could automatically infer the

definitions of these data structures.

5/ 27

slide-17
SLIDE 17

Abduction

Proposed by Charles Peirce in the late C19th as a pragmatic process of formulating scientific hypotheses:

6/ 27

slide-18
SLIDE 18

Abduction

Proposed by Charles Peirce in the late C19th as a pragmatic process of formulating scientific hypotheses: . . . the hypothesis cannot be admitted, even as a hypothesis, unless it be supposed that it would account for the facts or some of them.

6/ 27

slide-19
SLIDE 19

Abduction

Proposed by Charles Peirce in the late C19th as a pragmatic process of formulating scientific hypotheses: . . . the hypothesis cannot be admitted, even as a hypothesis, unless it be supposed that it would account for the facts or some of them. The form of inference, therefore, is this:

6/ 27

slide-20
SLIDE 20

Abduction

Proposed by Charles Peirce in the late C19th as a pragmatic process of formulating scientific hypotheses: . . . the hypothesis cannot be admitted, even as a hypothesis, unless it be supposed that it would account for the facts or some of them. The form of inference, therefore, is this: The surprising fact, C, is observed;

6/ 27

slide-21
SLIDE 21

Abduction

Proposed by Charles Peirce in the late C19th as a pragmatic process of formulating scientific hypotheses: . . . the hypothesis cannot be admitted, even as a hypothesis, unless it be supposed that it would account for the facts or some of them. The form of inference, therefore, is this: The surprising fact, C, is observed; But if A were true, C would be a matter of course,

6/ 27

slide-22
SLIDE 22

Abduction

Proposed by Charles Peirce in the late C19th as a pragmatic process of formulating scientific hypotheses: . . . the hypothesis cannot be admitted, even as a hypothesis, unless it be supposed that it would account for the facts or some of them. The form of inference, therefore, is this: The surprising fact, C, is observed; But if A were true, C would be a matter of course, Hence, there is reason to suspect that A is true. (Peirce, Pragmatism and Abduction, 1903)

6/ 27

slide-23
SLIDE 23

Abduction

Proposed by Charles Peirce in the late C19th as a pragmatic process of formulating scientific hypotheses: . . . the hypothesis cannot be admitted, even as a hypothesis, unless it be supposed that it would account for the facts or some of them. The form of inference, therefore, is this: The surprising fact, C, is observed; But if A were true, C would be a matter of course, Hence, there is reason to suspect that A is true. (Peirce, Pragmatism and Abduction, 1903) Our aim is to abduce a precondition or “hypothesis” that would justify the “surprising fact” of program safety / termination.

6/ 27

slide-24
SLIDE 24

Overview of our approach

  • Our approach builds on the cyclic termination proofs in
  • J. Brotherston, R. Bornat and C. Calcagno.

Cyclic proofs of program termination in separation logic. In Proceedings of POPL, 2008.

7/ 27

slide-25
SLIDE 25

Overview of our approach

  • Our approach builds on the cyclic termination proofs in
  • J. Brotherston, R. Bornat and C. Calcagno.

Cyclic proofs of program termination in separation logic. In Proceedings of POPL, 2008.

  • Given a program, we search for a cyclic proof that the

program has the desired property.

7/ 27

slide-26
SLIDE 26

Overview of our approach

  • Our approach builds on the cyclic termination proofs in
  • J. Brotherston, R. Bornat and C. Calcagno.

Cyclic proofs of program termination in separation logic. In Proceedings of POPL, 2008.

  • Given a program, we search for a cyclic proof that the

program has the desired property.

  • When we inevitably get stuck, we are allowed to abduce

(i.e. guess) definitions to help us out.

7/ 27

slide-27
SLIDE 27

Overview of our approach

  • Our approach builds on the cyclic termination proofs in
  • J. Brotherston, R. Bornat and C. Calcagno.

Cyclic proofs of program termination in separation logic. In Proceedings of POPL, 2008.

  • Given a program, we search for a cyclic proof that the

program has the desired property.

  • When we inevitably get stuck, we are allowed to abduce

(i.e. guess) definitions to help us out.

  • We employ lots of heuristics to help the search process.

7/ 27

slide-28
SLIDE 28

Overview of our approach

  • Our approach builds on the cyclic termination proofs in
  • J. Brotherston, R. Bornat and C. Calcagno.

Cyclic proofs of program termination in separation logic. In Proceedings of POPL, 2008.

  • Given a program, we search for a cyclic proof that the

program has the desired property.

  • When we inevitably get stuck, we are allowed to abduce

(i.e. guess) definitions to help us out.

  • We employ lots of heuristics to help the search process.
  • Tool, Caber, implemented on top of cyclic theorem prover

Cyclist:

  • J. Brotherston, N. Gorogiannis, and R.L. Petersen.

A generic cyclic theorem prover. In APLAS 2012.

7/ 27

slide-29
SLIDE 29

Part II Cyclic safety and termination proofs

8/ 27

slide-30
SLIDE 30

Syntax of programs

  • Expressions are either a variable or nil.

9/ 27

slide-31
SLIDE 31

Syntax of programs

  • Expressions are either a variable or nil.
  • Branching conditions B and commands C are given by

B ::= ⋆ | E = E | E = E C ::= ǫ | x := E; C | x := E.f; C | E.f := E; C | free(E); C | x := new(); C | if B then C fi; C | whileB do C od; C

9/ 27

slide-32
SLIDE 32

Syntax of programs

  • Expressions are either a variable or nil.
  • Branching conditions B and commands C are given by

B ::= ⋆ | E = E | E = E C ::= ǫ | x := E; C | x := E.f; C | E.f := E; C | free(E); C | x := new(); C | if B then C fi; C | whileB do C od; C where E ranges over expressions, x over variables, n over field names and j over N.

9/ 27

slide-33
SLIDE 33

Syntax of programs

  • Expressions are either a variable or nil.
  • Branching conditions B and commands C are given by

B ::= ⋆ | E = E | E = E C ::= ǫ | x := E; C | x := E.f; C | E.f := E; C | free(E); C | x := new(); C | if B then C fi; C | whileB do C od; C where E ranges over expressions, x over variables, n over field names and j over N.

  • A program is given by fields n1, . . . , nk; C where each ni

is a field name and C a command.

9/ 27

slide-34
SLIDE 34

Semantics of programs

  • A program state is either fault or a triple (C, s, h), where
  • C is a command;

10/ 27

slide-35
SLIDE 35

Semantics of programs

  • A program state is either fault or a triple (C, s, h), where
  • C is a command;
  • s : Var → Val is a stack;

10/ 27

slide-36
SLIDE 36

Semantics of programs

  • A program state is either fault or a triple (C, s, h), where
  • C is a command;
  • s : Var → Val is a stack;
  • h : Loc ⇀fin Val is a heap (we write ◦ for union of disjoint

heaps).

10/ 27

slide-37
SLIDE 37

Semantics of programs

  • A program state is either fault or a triple (C, s, h), where
  • C is a command;
  • s : Var → Val is a stack;
  • h : Loc ⇀fin Val is a heap (we write ◦ for union of disjoint

heaps).

  • (C, s, h) is called safe if there is no computation sequence

(C, s, h) ∗ fault. And (C, s, h) ↓ means there is no infinite computation sequence (C, s, h) . . .

10/ 27

slide-38
SLIDE 38

Semantics of programs

  • A program state is either fault or a triple (C, s, h), where
  • C is a command;
  • s : Var → Val is a stack;
  • h : Loc ⇀fin Val is a heap (we write ◦ for union of disjoint

heaps).

  • (C, s, h) is called safe if there is no computation sequence

(C, s, h) ∗ fault. And (C, s, h) ↓ means there is no infinite computation sequence (C, s, h) . . . Proposition (Safety / termination monotonicity) If (C, s, h) is safe and h ◦ h′ defined then (C, s, h ◦ h′) is safe. If (C, s, h) ↓ and h ◦ h′ defined then (C, s, h ◦ h′) ↓.

10/ 27

slide-39
SLIDE 39

Preconditions

  • Formulas F are given by

F ::= E = E | E = E | emp | E → E | PE | F ∗ F where P ranges over predicate symbols (of appropriate arity).

11/ 27

slide-40
SLIDE 40

Preconditions

  • Formulas F are given by

F ::= E = E | E = E | emp | E → E | PE | F ∗ F where P ranges over predicate symbols (of appropriate arity).

  • An inductive rule for predicate P is a rule of the form

F ⇒ Pt

11/ 27

slide-41
SLIDE 41

Preconditions

  • Formulas F are given by

F ::= E = E | E = E | emp | E → E | PE | F ∗ F where P ranges over predicate symbols (of appropriate arity).

  • An inductive rule for predicate P is a rule of the form

F ⇒ Pt

  • Semantics given by standard forcing relation s, h |

=Φ F

11/ 27

slide-42
SLIDE 42

Proof rules

  • We write proof judgements of the form

F ⊢ C where F is a formula and C a command.

12/ 27

slide-43
SLIDE 43

Proof rules

  • We write proof judgements of the form

F ⊢ C where F is a formula and C a command.

  • Symbolic execution rules capture the effect of commands.

12/ 27

slide-44
SLIDE 44

Proof rules

  • We write proof judgements of the form

F ⊢ C where F is a formula and C a command.

  • Symbolic execution rules capture the effect of commands.
  • E.g., if C is x := E.f; C′, we have the symbolic execution

rule: x = Ef[x′/x] ∗ (F ∗ E → E)[x′/x] ⊢ C′ |E| ≥ f F ∗ E → E ⊢ C

12/ 27

slide-45
SLIDE 45

Proof rules

  • We write proof judgements of the form

F ⊢ C where F is a formula and C a command.

  • Symbolic execution rules capture the effect of commands.
  • E.g., if C is x := E.f; C′, we have the symbolic execution

rule: x = Ef[x′/x] ∗ (F ∗ E → E)[x′/x] ⊢ C′ |E| ≥ f F ∗ E → E ⊢ C (Here, f ∈ N and Ef is the fth element of E. The variable x′ is a fresh variable used to record the “old value” of x.)

12/ 27

slide-46
SLIDE 46

Proof rules (contd.)

  • We also have logical rules affecting the precondition, e.g.:

F ⊢ C Π′ ⊆ Π (Frame) F ∗ G ⊢ C

13/ 27

slide-47
SLIDE 47

Proof rules (contd.)

  • We also have logical rules affecting the precondition, e.g.:

F ⊢ C Π′ ⊆ Π (Frame) F ∗ G ⊢ C

  • The inductive rules for a predicate P determine its

unfolding rule.

13/ 27

slide-48
SLIDE 48

Proof rules (contd.)

  • We also have logical rules affecting the precondition, e.g.:

F ⊢ C Π′ ⊆ Π (Frame) F ∗ G ⊢ C

  • The inductive rules for a predicate P determine its

unfolding rule. E.g., define “binary tree” predicate bt by x = nil ⇒ bt(x) x = nil ∗ x → (y, z) ∗ bt(y) ∗ bt(z) ⇒ bt(x)

13/ 27

slide-49
SLIDE 49

Proof rules (contd.)

  • We also have logical rules affecting the precondition, e.g.:

F ⊢ C Π′ ⊆ Π (Frame) F ∗ G ⊢ C

  • The inductive rules for a predicate P determine its

unfolding rule. E.g., define “binary tree” predicate bt by x = nil ⇒ bt(x) x = nil ∗ x → (y, z) ∗ bt(y) ∗ bt(z) ⇒ bt(x) This gives the unfolding rule: F ∗ u = nil ⊢ C F ∗ u = nil ∗ u → (y, z) ∗ bt(y) ∗ bt(z) ⊢ C F ∗ bt(u) ⊢ C

13/ 27

slide-50
SLIDE 50

Cyclic proofs

  • A cyclic pre-proof is a derivation tree with back-links:
  • · · · •

(Inference)

  • (Axiom)
  • 14/ 27
slide-51
SLIDE 51

Cyclic proofs

  • A cyclic pre-proof is a derivation tree with back-links:
  • · · · •

(Inference)

  • (Axiom)
  • Safety proof condition: there are infinitely many symbolic

executions on every infinite path.

14/ 27

slide-52
SLIDE 52

Cyclic proofs

  • A cyclic pre-proof is a derivation tree with back-links:
  • · · · •

(Inference)

  • (Axiom)
  • Safety proof condition: there are infinitely many symbolic

executions on every infinite path.

  • Termination condition: some inductive predicate is

unfolded infinitely often on every infinite path.

14/ 27

slide-53
SLIDE 53

Soundness

Theorem Fix rule set Φ, and program C, and suppose there is a cyclic proof P of F ⊢ C. Let stack s and heap h satisfy s, h | =Φ F.

15/ 27

slide-54
SLIDE 54

Soundness

Theorem Fix rule set Φ, and program C, and suppose there is a cyclic proof P of F ⊢ C. Let stack s and heap h satisfy s, h | =Φ F.

  • If P satisfies the safety condition, (C, s, h) is safe;

15/ 27

slide-55
SLIDE 55

Soundness

Theorem Fix rule set Φ, and program C, and suppose there is a cyclic proof P of F ⊢ C. Let stack s and heap h satisfy s, h | =Φ F.

  • If P satisfies the safety condition, (C, s, h) is safe;
  • If P satisfies the termination condition, (C, s, h) ↓.

15/ 27

slide-56
SLIDE 56

Soundness

Theorem Fix rule set Φ, and program C, and suppose there is a cyclic proof P of F ⊢ C. Let stack s and heap h satisfy s, h | =Φ F.

  • If P satisfies the safety condition, (C, s, h) is safe;
  • If P satisfies the termination condition, (C, s, h) ↓.

Proof. Inductive argument over proofs.

15/ 27

slide-57
SLIDE 57

Part III Cyclic abduction

16/ 27

slide-58
SLIDE 58

Problem statement

  • Initial problem: Given program C with input variables x,

find inductive rules Φ such that Px ⊢ C is valid wrt. Φ. where P is a fresh predicate symbol, and “valid” may have either a safety or a termination interpretation.

17/ 27

slide-59
SLIDE 59

Problem statement

  • Initial problem: Given program C with input variables x,

find inductive rules Φ such that Px ⊢ C is valid wrt. Φ. where P is a fresh predicate symbol, and “valid” may have either a safety or a termination interpretation.

  • General problem: Given inductive rules Φ and subgoal

F ⊢ C, find inductive rules Φ′ such that F ⊢ C is valid wrt. Φ ∪ Φ′

17/ 27

slide-60
SLIDE 60

Problem statement

  • Initial problem: Given program C with input variables x,

find inductive rules Φ such that Px ⊢ C is valid wrt. Φ. where P is a fresh predicate symbol, and “valid” may have either a safety or a termination interpretation.

  • General problem: Given inductive rules Φ and subgoal

F ⊢ C, find inductive rules Φ′ such that F ⊢ C is valid wrt. Φ ∪ Φ′

  • Our approach: search for a cyclic safety/termination proof
  • f F ⊢ C, inventing inductive rules as necessary.

17/ 27

slide-61
SLIDE 61

Principia abductica (I)

Principle I (Proof search priorities) Priority 1: apply axiom rule

18/ 27

slide-62
SLIDE 62

Principia abductica (I)

Principle I (Proof search priorities) Priority 1: apply axiom rule Priority 2: form backlink

18/ 27

slide-63
SLIDE 63

Principia abductica (I)

Principle I (Proof search priorities) Priority 1: apply axiom rule Priority 2: form backlink Priority 3: apply symbolic execution

18/ 27

slide-64
SLIDE 64

Principia abductica (I)

Principle I (Proof search priorities) Priority 1: apply axiom rule Priority 2: form backlink Priority 3: apply symbolic execution Principle II (Guessing things)

  • In order to serve Priorities 2 and 3 we are allowed to apply

logical rules and/or abduce inductive rules.

18/ 27

slide-65
SLIDE 65

Principia abductica (I)

Principle I (Proof search priorities) Priority 1: apply axiom rule Priority 2: form backlink Priority 3: apply symbolic execution Principle II (Guessing things)

  • In order to serve Priorities 2 and 3 we are allowed to apply

logical rules and/or abduce inductive rules.

  • We may only abduce rules for undefined predicates.

18/ 27

slide-66
SLIDE 66

Principia abductica (I)

Principle I (Proof search priorities) Priority 1: apply axiom rule Priority 2: form backlink Priority 3: apply symbolic execution Principle II (Guessing things)

  • In order to serve Priorities 2 and 3 we are allowed to apply

logical rules and/or abduce inductive rules.

  • We may only abduce rules for undefined predicates.
  • When we abduce rules for a predicate P in the current

subgoal, we immediately unfold that predicate in the subgoal.

18/ 27

slide-67
SLIDE 67

Principia abductica (I)

Principle I (Proof search priorities) Priority 1: apply axiom rule Priority 2: form backlink Priority 3: apply symbolic execution Principle II (Guessing things)

  • In order to serve Priorities 2 and 3 we are allowed to apply

logical rules and/or abduce inductive rules.

  • We may only abduce rules for undefined predicates.
  • When we abduce rules for a predicate P in the current

subgoal, we immediately unfold that predicate in the subgoal. (We write A(P) for a combined abduction-and-unfold step.)

18/ 27

slide-68
SLIDE 68

Principia abductica (II)

When forming back-links, we need to avoid:

  • violating the soundness condition on cyclic proofs;

19/ 27

slide-69
SLIDE 69

Principia abductica (II)

When forming back-links, we need to avoid:

  • violating the soundness condition on cyclic proofs;
  • abducing trivially inconsistent definitions like Px ⇒ Px:

Px ⊢ 0 A(P) Px ⊢ 0

19/ 27

slide-70
SLIDE 70

Principia abductica (II)

When forming back-links, we need to avoid:

  • violating the soundness condition on cyclic proofs;
  • abducing trivially inconsistent definitions like Px ⇒ Px:

Px ⊢ 0 A(P) Px ⊢ 0 Principle III (Avoidance tactic) We may not form a backlink yielding an infinite path that violates the safety condition, even if searching for a termination proof.

19/ 27

slide-71
SLIDE 71

Principia abductica (II)

When forming back-links, we need to avoid:

  • violating the soundness condition on cyclic proofs;
  • abducing trivially inconsistent definitions like Px ⇒ Px:

Px ⊢ 0 A(P) Px ⊢ 0 Principle III (Avoidance tactic) We may not form a backlink yielding an infinite path that violates the safety condition, even if searching for a termination proof. We can use a model checker to enforce Principle III.

19/ 27

slide-72
SLIDE 72

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ

P0(x) ⊢ 0

20/ 27

slide-73
SLIDE 73

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x)

P0(x) ⊢ 0

20/ 27

slide-74
SLIDE 74

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x)

x = nil ∗ P1(x) ⊢ 0 x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-75
SLIDE 75

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x)

x = nil ∗ P1(x) ⊢ 5

while

x = nil ∗ P1(x) ⊢ 0 x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-76
SLIDE 76

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x)

ǫ

x = nil ∗ P1(x) ⊢ 5

while

x = nil ∗ P1(x) ⊢ 0 x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-77
SLIDE 77

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x)

ǫ

x = nil ∗ P1(x) ⊢ 5

while

x = nil ∗ P1(x) ⊢ 0 x = nil ∗ P2(x) ⊢ 1

while

x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-78
SLIDE 78

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x)

ǫ

x = nil ∗ P1(x) ⊢ 5

while

x = nil ∗ P1(x) ⊢ 0 x = nil ∗ P2(x) ⊢ 2 x = nil ∗ P2(x) ⊢ 4

if

x = nil ∗ P2(x) ⊢ 1

while

x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-79
SLIDE 79

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x)

ǫ

x = nil ∗ P1(x) ⊢ 5

while

x = nil ∗ P1(x) ⊢ 0 x = nil ∗ P2(x) ⊢ 2 x = nil ∗ P2(x) ⊢ 4

if

x = nil ∗ P2(x) ⊢ 1

while

x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-80
SLIDE 80

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x)

ǫ

x = nil ∗ P1(x) ⊢ 5

while

x = nil ∗ P1(x) ⊢ 0 x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 2

A(P2)

x = nil ∗ P2(x) ⊢ 2 x = nil ∗ P2(x) ⊢ 4

if

x = nil ∗ P2(x) ⊢ 1

while

x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-81
SLIDE 81

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x)

ǫ

x = nil ∗ P1(x) ⊢ 5

while

x = nil ∗ P1(x) ⊢ 0 x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 2

A(P2)

x = nil ∗ P2(x) ⊢ 2 x = nil ∗ P2(x) ⊢ 4

if

x = nil ∗ P2(x) ⊢ 1

while

x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-82
SLIDE 82

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x)

ǫ

x = nil ∗ P1(x) ⊢ 5

while

x = nil ∗ P1(x) ⊢ 0 x′ = nil∗ x′ → (x, z) ∗ P3(x′, x, z) ⊢ 0

x := x.l

x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 2

A(P2)

x = nil ∗ P2(x) ⊢ 2 x = nil ∗ P2(x) ⊢ 4

if

x = nil ∗ P2(x) ⊢ 1

while

x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-83
SLIDE 83

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z)

ǫ

x = nil ∗ P1(x) ⊢ 5

while

x = nil ∗ P1(x) ⊢ 0 x′ = nil∗ x′ → (x, z) ∗ P3(x′, x, z) ⊢ 0

x := x.l

x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 2

A(P2)

x = nil ∗ P2(x) ⊢ 2 x = nil ∗ P2(x) ⊢ 4

if

x = nil ∗ P2(x) ⊢ 1

while

x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-84
SLIDE 84

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z)

ǫ

x = nil ∗ P1(x) ⊢ 5

while

x = nil ∗ P1(x) ⊢ 0 x′ = nil∗ x′ → (x, z) ∗ P0(x) ∗ P4(x′, x, z) ⊢ 0

A(P3)

x′ = nil∗ x′ → (x, z) ∗ P3(x′, x, z) ⊢ 0

x := x.l

x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 2

A(P2)

x = nil ∗ P2(x) ⊢ 2 x = nil ∗ P2(x) ⊢ 4

if

x = nil ∗ P2(x) ⊢ 1

while

x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-85
SLIDE 85

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z)

ǫ

x = nil ∗ P1(x) ⊢ 5

while

x = nil ∗ P1(x) ⊢ 0 P0(x) ⊢ 0

(Frame)

x′ = nil∗ x′ → (x, z) ∗ P0(x) ∗ P4(x′, x, z) ⊢ 0

A(P3)

x′ = nil∗ x′ → (x, z) ∗ P3(x′, x, z) ⊢ 0

x := x.l

x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 2

A(P2)

x = nil ∗ P2(x) ⊢ 2 x = nil ∗ P2(x) ⊢ 4

if

x = nil ∗ P2(x) ⊢ 1

while

x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-86
SLIDE 86

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z)

ǫ

x = nil ∗ P1(x) ⊢ 5

while

x = nil ∗ P1(x) ⊢ 0 P0(x) ⊢ 0

(Frame)

x′ = nil∗ x′ → (x, z) ∗ P0(x) ∗ P4(x′, x, z) ⊢ 0

A(P3)

x′ = nil∗ x′ → (x, z) ∗ P3(x′, x, z) ⊢ 0

x := x.l

x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 2

A(P2)

x = nil ∗ P2(x) ⊢ 2 x = nil ∗ P2(x) ⊢ 4

if

x = nil ∗ P2(x) ⊢ 1

while

x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-87
SLIDE 87

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z)

ǫ

x = nil ∗ P1(x) ⊢ 5

while

x = nil ∗ P1(x) ⊢ 0 P0(x) ⊢ 0

(Frame)

x′ = nil∗ x′ → (x, z) ∗ P0(x) ∗ P4(x′, x, z) ⊢ 0

A(P3)

x′ = nil∗ x′ → (x, z) ∗ P3(x′, x, z) ⊢ 0

x := x.l

x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 2

A(P2)

x = nil ∗ P2(x) ⊢ 2 x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 4

(P2)

x = nil ∗ P2(x) ⊢ 4

if

x = nil ∗ P2(x) ⊢ 1

while

x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-88
SLIDE 88

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z)

ǫ

x = nil ∗ P1(x) ⊢ 5

while

x = nil ∗ P1(x) ⊢ 0 P0(x) ⊢ 0

(Frame)

x′ = nil∗ x′ → (x, z) ∗ P0(x) ∗ P4(x′, x, z) ⊢ 0

A(P3)

x′ = nil∗ x′ → (x, z) ∗ P3(x′, x, z) ⊢ 0

x := x.l

x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 2

A(P2)

x = nil ∗ P2(x) ⊢ 2 x′ = nil∗ x′ → (y, x) ∗ P3(x′, y, x) ⊢ 0

x := x.r

x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 4

(P2)

x = nil ∗ P2(x) ⊢ 4

if

x = nil ∗ P2(x) ⊢ 1

while

x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-89
SLIDE 89

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z)

ǫ

x = nil ∗ P1(x) ⊢ 5

while

x = nil ∗ P1(x) ⊢ 0 P0(x) ⊢ 0

(Frame)

x′ = nil∗ x′ → (x, z) ∗ P0(x) ∗ P4(x′, x, z) ⊢ 0

A(P3)

x′ = nil∗ x′ → (x, z) ∗ P3(x′, x, z) ⊢ 0

x := x.l

x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 2

A(P2)

x = nil ∗ P2(x) ⊢ 2 x′ = nil∗ x′ → (y, x) ∗ P3(x′, y, x) ⊢ 0

x := x.r

x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 4

(P2)

x = nil ∗ P2(x) ⊢ 4

if

x = nil ∗ P2(x) ⊢ 1

while

x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-90
SLIDE 90

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z)

ǫ

x = nil ∗ P1(x) ⊢ 5

while

x = nil ∗ P1(x) ⊢ 0 P0(x) ⊢ 0

(Frame)

x′ = nil∗ x′ → (x, z) ∗ P0(x) ∗ P4(x′, x, z) ⊢ 0

A(P3)

x′ = nil∗ x′ → (x, z) ∗ P3(x′, x, z) ⊢ 0

x := x.l

x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 2

A(P2)

x = nil ∗ P2(x) ⊢ 2 x′ = nil∗ x′ → (y, x) ∗ P0(y) ∗ P4(x′, y, x) ⊢ 0

(P3)

x′ = nil∗ x′ → (y, x) ∗ P3(x′, y, x) ⊢ 0

x := x.r

x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 4

(P2)

x = nil ∗ P2(x) ⊢ 4

if

x = nil ∗ P2(x) ⊢ 1

while

x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-91
SLIDE 91

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z) P0(z) ∗ P5(x, y, z) ⇒ P4(x, y, z)

ǫ

x = nil ∗ P1(x) ⊢ 5

while

x = nil ∗ P1(x) ⊢ 0 P0(x) ⊢ 0

(Frame)

x′ = nil∗ x′ → (x, z) ∗ P0(x) ∗ P4(x′, x, z) ⊢ 0

A(P3)

x′ = nil∗ x′ → (x, z) ∗ P3(x′, x, z) ⊢ 0

x := x.l

x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 2

A(P2)

x = nil ∗ P2(x) ⊢ 2 x′ = nil∗ x′ → (y, x) ∗ P0(y) ∗ P4(x′, y, x) ⊢ 0

(P3)

x′ = nil∗ x′ → (y, x) ∗ P3(x′, y, x) ⊢ 0

x := x.r

x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 4

(P2)

x = nil ∗ P2(x) ⊢ 4

if

x = nil ∗ P2(x) ⊢ 1

while

x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-92
SLIDE 92

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z) P0(z) ∗ P5(x, y, z) ⇒ P4(x, y, z)

ǫ

x = nil ∗ P1(x) ⊢ 5

while

x = nil ∗ P1(x) ⊢ 0 P0(x) ⊢ 0

(Frame)

x′ = nil∗ x′ → (x, z) ∗ P0(x) ∗ P4(x′, x, z) ⊢ 0

A(P3)

x′ = nil∗ x′ → (x, z) ∗ P3(x′, x, z) ⊢ 0

x := x.l

x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 2

A(P2)

x = nil ∗ P2(x) ⊢ 2 x′ = nil∗ x′ → (y, x) ∗ P0(y) ∗ P0(x) ∗ P5(x′, y, x) ⊢ 0

A(P4)

x′ = nil∗ x′ → (y, x) ∗ P0(y) ∗ P4(x′, y, x) ⊢ 0

(P3)

x′ = nil∗ x′ → (y, x) ∗ P3(x′, y, x) ⊢ 0

x := x.r

x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 4

(P2)

x = nil ∗ P2(x) ⊢ 4

if

x = nil ∗ P2(x) ⊢ 1

while

x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-93
SLIDE 93

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z) P0(z) ∗ P5(x, y, z) ⇒ P4(x, y, z)

ǫ

x = nil ∗ P1(x) ⊢ 5

while

x = nil ∗ P1(x) ⊢ 0 P0(x) ⊢ 0

(Frame)

x′ = nil∗ x′ → (x, z) ∗ P0(x) ∗ P4(x′, x, z) ⊢ 0

A(P3)

x′ = nil∗ x′ → (x, z) ∗ P3(x′, x, z) ⊢ 0

x := x.l

x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 2

A(P2)

x = nil ∗ P2(x) ⊢ 2 P0(x) ⊢ 0

(Frame)

x′ = nil∗ x′ → (y, x) ∗ P0(y) ∗ P0(x) ∗ P5(x′, y, x) ⊢ 0

A(P4)

x′ = nil∗ x′ → (y, x) ∗ P0(y) ∗ P4(x′, y, x) ⊢ 0

(P3)

x′ = nil∗ x′ → (y, x) ∗ P3(x′, y, x) ⊢ 0

x := x.r

x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 4

(P2)

x = nil ∗ P2(x) ⊢ 4

if

x = nil ∗ P2(x) ⊢ 1

while

x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-94
SLIDE 94

Worked example: binary tree search

0 : while (x = nil){ 1 : if(⋆) 2 : x := x.l 3 : else 4 : x := x.r } 5 : ǫ x = nil ∗ P1(x) ⇒ P0(x) x = nil ∗ P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z) P0(z) ∗ P5(x, y, z) ⇒ P4(x, y, z)

ǫ

x = nil ∗ P1(x) ⊢ 5

while

x = nil ∗ P1(x) ⊢ 0 P0(x) ⊢ 0

(Frame)

x′ = nil∗ x′ → (x, z) ∗ P0(x) ∗ P4(x′, x, z) ⊢ 0

A(P3)

x′ = nil∗ x′ → (x, z) ∗ P3(x′, x, z) ⊢ 0

x := x.l

x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 2

A(P2)

x = nil ∗ P2(x) ⊢ 2 P0(x) ⊢ 0

(Frame)

x′ = nil∗ x′ → (y, x) ∗ P0(y) ∗ P0(x) ∗ P5(x′, y, x) ⊢ 0

A(P4)

x′ = nil∗ x′ → (y, x) ∗ P0(y) ∗ P4(x′, y, x) ⊢ 0

(P3)

x′ = nil∗ x′ → (y, x) ∗ P3(x′, y, x) ⊢ 0

x := x.r

x = nil∗ x → (y, z) ∗ P3(x, y, z) ⊢ 4

(P2)

x = nil ∗ P2(x) ⊢ 4

if

x = nil ∗ P2(x) ⊢ 1

while

x = nil ∗ P2(x) ⊢ 0

A(P0)

P0(x) ⊢ 0

20/ 27

slide-95
SLIDE 95

Simplifying inductive rule sets

x = nil : P1(x) ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z) P0(z) ∗ P5(x, y, z) ⇒ P4(x, y, z)

21/ 27

slide-96
SLIDE 96

Simplifying inductive rule sets

  • instantiate undefined predicates to emp;

x = nil : P1(x) ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z) P0(z) ∗ P5(x, y, z) ⇒ P4(x, y, z)

21/ 27

slide-97
SLIDE 97

Simplifying inductive rule sets

  • instantiate undefined predicates to emp;

x = nil : P1(x) ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z) P0(z) ∗ P5(x, y, z) ⇒ P4(x, y, z) = ⇒ x = nil : emp ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z) P0(z) ⇒ P4(x, y, z)

21/ 27

slide-98
SLIDE 98

Simplifying inductive rule sets

  • instantiate undefined predicates to emp;
  • eliminate redundant parameters;

x = nil : P1(x) ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z) P0(z) ∗ P5(x, y, z) ⇒ P4(x, y, z) = ⇒ x = nil : emp ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z) P0(z) ⇒ P4(x, y, z)

21/ 27

slide-99
SLIDE 99

Simplifying inductive rule sets

  • instantiate undefined predicates to emp;
  • eliminate redundant parameters;

x = nil : P1(x) ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z) P0(z) ∗ P5(x, y, z) ⇒ P4(x, y, z) = ⇒ x = nil : emp ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z) P0(z) ⇒ P4(x, y, z) ⇓ x = nil : emp ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y) ⇒ P2(x) P0(y) ∗ P4(z) ⇒ P3(x, y) P0(z) ⇒ P4(z)

21/ 27

slide-100
SLIDE 100

Simplifying inductive rule sets

  • instantiate undefined predicates to emp;
  • eliminate redundant parameters;
  • inline single-clause predicates.

x = nil : P1(x) ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z) P0(z) ∗ P5(x, y, z) ⇒ P4(x, y, z) = ⇒ x = nil : emp ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z) P0(z) ⇒ P4(x, y, z) ⇓ x = nil : emp ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y) ⇒ P2(x) P0(y) ∗ P4(z) ⇒ P3(x, y) P0(z) ⇒ P4(z)

21/ 27

slide-101
SLIDE 101

Simplifying inductive rule sets

  • instantiate undefined predicates to emp;
  • eliminate redundant parameters;
  • inline single-clause predicates.

x = nil : P1(x) ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z) P0(z) ∗ P5(x, y, z) ⇒ P4(x, y, z) = ⇒ x = nil : emp ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z) P0(z) ⇒ P4(x, y, z) ⇓ x = nil : emp ⇒ P0(x) x = nil : x → (y, z) ∗ P0(y) ∗ P0(z) ⇒ P0(x) ⇐ = x = nil : emp ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y) ⇒ P2(x) P0(y) ∗ P4(z) ⇒ P3(x, y) P0(z) ⇒ P4(z)

21/ 27

slide-102
SLIDE 102

Simplifying inductive rule sets

  • instantiate undefined predicates to emp;
  • eliminate redundant parameters;
  • inline single-clause predicates.

x = nil : P1(x) ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z) P0(z) ∗ P5(x, y, z) ⇒ P4(x, y, z) = ⇒ x = nil : emp ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z) P0(z) ⇒ P4(x, y, z) ⇓ (nil-terminated binary tree) x = nil : emp ⇒ P0(x) x = nil : x → (y, z) ∗ P0(y) ∗ P0(z) ⇒ P0(x) ⇐ = x = nil : emp ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y) ⇒ P2(x) P0(y) ∗ P4(z) ⇒ P3(x, y) P0(z) ⇒ P4(z)

21/ 27

slide-103
SLIDE 103

Simplifying inductive rule sets

  • instantiate undefined predicates to emp;
  • eliminate redundant parameters;
  • inline single-clause predicates.
  • remove unsatisfiable clauses (not shown)

x = nil : P1(x) ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z) P0(z) ∗ P5(x, y, z) ⇒ P4(x, y, z) = ⇒ x = nil : emp ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y, z) ⇒ P2(x) P0(y) ∗ P4(x, y, z) ⇒ P3(x, y, z) P0(z) ⇒ P4(x, y, z) ⇓ (nil-terminated binary tree) x = nil : emp ⇒ P0(x) x = nil : x → (y, z) ∗ P0(y) ∗ P0(z) ⇒ P0(x) ⇐ = x = nil : emp ⇒ P0(x) x = nil : P2(x) ⇒ P0(x) x → (y, z) ∗ P3(x, y) ⇒ P2(x) P0(y) ∗ P4(z) ⇒ P3(x, y) P0(z) ⇒ P4(z)

21/ 27

slide-104
SLIDE 104

Part IV Challenges and subtleties

22/ 27

slide-105
SLIDE 105

Evaluating solution quality

  • Backtracking search can yield different solutions.

23/ 27

slide-106
SLIDE 106

Evaluating solution quality

  • Backtracking search can yield different solutions.
  • We can decide whether a predicate is satisfiable

23/ 27

slide-107
SLIDE 107

Evaluating solution quality

  • Backtracking search can yield different solutions.
  • We can decide whether a predicate is satisfiable
  • J. Brotherston, C. Fuhs, N, Gorogiannis and J. Navarro Perez.

A decision procedure for satisfiability of inductive predicates in separation logic. Submitted.

23/ 27

slide-108
SLIDE 108

Evaluating solution quality

  • Backtracking search can yield different solutions.
  • We can decide whether a predicate is satisfiable
  • J. Brotherston, C. Fuhs, N, Gorogiannis and J. Navarro Perez.

A decision procedure for satisfiability of inductive predicates in separation logic. Submitted.

  • Comparing predicates via entailment (⊢) is not practical.

23/ 27

slide-109
SLIDE 109

Evaluating solution quality

  • Backtracking search can yield different solutions.
  • We can decide whether a predicate is satisfiable
  • J. Brotherston, C. Fuhs, N, Gorogiannis and J. Navarro Perez.

A decision procedure for satisfiability of inductive predicates in separation logic. Submitted.

  • Comparing predicates via entailment (⊢) is not practical.
  • Currently we use a simple grading scheme for predicate

quality.

23/ 27

slide-110
SLIDE 110

Evaluating solution quality

  • Backtracking search can yield different solutions.
  • We can decide whether a predicate is satisfiable
  • J. Brotherston, C. Fuhs, N, Gorogiannis and J. Navarro Perez.

A decision procedure for satisfiability of inductive predicates in separation logic. Submitted.

  • Comparing predicates via entailment (⊢) is not practical.
  • Currently we use a simple grading scheme for predicate

quality.

  • We can simplify predicates and replay the proof to improve

quality, sometimes.

23/ 27

slide-111
SLIDE 111

Experimental results

Program LOC Time Depth Quality Term. List traverse 3 20 3 A

  • List insert

14 8 7 B

  • List copy

12 8 B

  • List append

10 12 5 B

  • Delete last from list

16 12 9 B

  • Filter list

21 48 11 C

  • Dispose list

5 4 5 A

  • Reverse list

7 8 7 A

  • Cyclic list traverse

5 4 5 A

  • Binary tree search

7 8 4 A

  • Binary tree insert

18 4 7 B

  • List of lists traverse

7 8 5 B

  • Traverse even-length list

4 8 4 A

  • Traverse odd-length list

4 4 4 A

  • Ternary tree search

10 8 5 A

  • Conditional diverge

3 4 3 B × Traverse list of trees 11 12 6 B

  • Traverse tree of lists

17 68 7 A

  • Traverse list twice

8 64 9 B

  • 24/ 27
slide-112
SLIDE 112

Problem: initial variable assignment

  • Consider a local variable assignment y := x at line 0. In

the proof we get y = x ∗ Px ⊢ 1 y := x Px ⊢ 0

25/ 27

slide-113
SLIDE 113

Problem: initial variable assignment

  • Consider a local variable assignment y := x at line 0. In

the proof we get y = x ∗ Px ⊢ 1 y := x Px ⊢ 0

  • The equality y = x might prevent back-links later, so we

have to deal with it somehow.

25/ 27

slide-114
SLIDE 114

Problem: initial variable assignment

  • Consider a local variable assignment y := x at line 0. In

the proof we get y = x ∗ Px ⊢ 1 y := x Px ⊢ 0

  • The equality y = x might prevent back-links later, so we

have to deal with it somehow.

  • But there are lots of choices!

25/ 27

slide-115
SLIDE 115

Problem: initial variable assignment

  • Consider a local variable assignment y := x at line 0. In

the proof we get y = x ∗ Px ⊢ 1 y := x Px ⊢ 0

  • The equality y = x might prevent back-links later, so we

have to deal with it somehow.

  • But there are lots of choices!
  • Currently our standard approach is to generalise P to

include y, which helps us abduce e.g. cyclic lists.

25/ 27

slide-116
SLIDE 116

Problem: initial variable assignment

  • Consider a local variable assignment y := x at line 0. In

the proof we get y = x ∗ Px ⊢ 1 y := x Px ⊢ 0

  • The equality y = x might prevent back-links later, so we

have to deal with it somehow.

  • But there are lots of choices!
  • Currently our standard approach is to generalise P to

include y, which helps us abduce e.g. cyclic lists.

  • In principle, we could also use the control flow graph of the

program to help us decide what to do.

25/ 27

slide-117
SLIDE 117

Problem: abstraction

  • The abstraction problem is inherited from program

analysis in general.

26/ 27

slide-118
SLIDE 118

Problem: abstraction

  • The abstraction problem is inherited from program

analysis in general.

  • Here it shows up in the need for lemmas:

Π : F ∗ list(x) ⊢ i x → y ⊢ list(x) (Cut) Π : F ∗ x → y ⊢ i

26/ 27

slide-119
SLIDE 119

Problem: abstraction

  • The abstraction problem is inherited from program

analysis in general.

  • Here it shows up in the need for lemmas:

Π : F ∗ list(x) ⊢ i x → y ⊢ list(x) (Cut) Π : F ∗ x → y ⊢ i

  • Our tool has a limited abstraction capability, mainly based
  • n existentially quantifying variables modified by loops.

26/ 27

slide-120
SLIDE 120

Problem: abstraction

  • The abstraction problem is inherited from program

analysis in general.

  • Here it shows up in the need for lemmas:

Π : F ∗ list(x) ⊢ i x → y ⊢ list(x) (Cut) Π : F ∗ x → y ⊢ i

  • Our tool has a limited abstraction capability, mainly based
  • n existentially quantifying variables modified by loops.
  • Lemma speculation is a well known problem in inductive

theorem proving. In our setting, where parts of the lemma may be undefined, it is harder still!

26/ 27

slide-121
SLIDE 121

Problem: abstraction

  • The abstraction problem is inherited from program

analysis in general.

  • Here it shows up in the need for lemmas:

Π : F ∗ list(x) ⊢ i x → y ⊢ list(x) (Cut) Π : F ∗ x → y ⊢ i

  • Our tool has a limited abstraction capability, mainly based
  • n existentially quantifying variables modified by loops.
  • Lemma speculation is a well known problem in inductive

theorem proving. In our setting, where parts of the lemma may be undefined, it is harder still!

  • Cyclist gives us an entailment prover which could be used

to prove conjectured lemmas.

26/ 27

slide-122
SLIDE 122

Thanks for listening!

Get Caber / Cyclist online (source / virtual machine image): google “cyclist theorem prover”.

  • J. Brotherston and N, Gorogiannis.

Cyclic abduction of inductive safety and termination preconditions. Submitted.

27/ 27