Presentation is loading. Please wait.

Presentation is loading. Please wait.

Coinduction in a language and verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond IFIP WG 2.3 meeting Seattle,

Similar presentations


Presentation on theme: "Coinduction in a language and verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond IFIP WG 2.3 meeting Seattle,"— Presentation transcript:

1 Coinduction in a language and verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond IFIP WG 2.3 meeting Seattle, WA, USA 16 July 2012

2 How to add coinductive features, like coinductive datatypes corecursive functions copredicates coinductive proofs in a programming language supported by a program verifier

3 datatype List = Nil | Cons(int, List); Defined by least fixpoint That is, List is the smallest set L such that: Nil  L  x,a x  int  a  L  Cons( x, a ) L Gives rise to finite structures

4 codatatype Stream = Nil | Cons(int, Stream); Defined by largest fixpoint That is, Stream is the largest set S such that: Nil  S  x,a x  int  a  S  Cons( x, a ) S Gives rise to possibly infinite structures

5 One view (e.g., category theory, Charity) is that: Inductive datatypes put emphasis on constructors Nil : ()  List Cons : int  List  List Coinductive datatypes put emphasis on destructors head : Stream  int tail : Stream  Stream Another view (e.g., Coq) puts emphasis on constructors for both, and allows destructors to be defined for both

6 function Append(a: List, b: List): List { match a case Nil => b case Cons(h, t) => Cons(h, Append(t, b)) } Well-defined? Yes, if the function terminates Termination implies a unique fixpoint

7 function Upward(n: int): Stream { Cons(n, Upward(n+1)) } Well-defined? Yes, if corecursive calls are guarded Unique fixpoint? My conclusion: when functions are defined by computations, no need to distinguish between functions and cofunctions

8 (Co)recursive calls, not (co)recursive functions function F(n: nat): Stream decreases (n+4)/5 * 5 - n; { if n % 5 == 0 then Cons(n, F(n+1)) else F(n+1) } Corecursive call Recursive call

9 predicate P(x: T) { E } is the same as: function P(x: T): bool { E } Recursive calls must be terminating copredicate C(x: T) { E } defines C to be the largest boolean function satisfying  x C (x) = E. Corecursive calls must be in positive positions

10 Induction principle:  n P(n) =  n (  k k < n  P(k))  P(n) Appealing to the inductive hypothesis is like making a recursive call “Manual” proofs by induction can be done in code Induction hypothesis from the induction principle can be inserted heuristically

11 Showing that an inductive-datatype value satisfies a property can be proved by induction Equality of two inductive-datatype values can be proved by induction

12 Coinduction principle for a copredicate copredicate C(x: T) { Body[C](x) } is: for any predicate Q, Q(a)  (  s Q(s)  Body[Q](s) )  C(a) Inventing and using the predicate Q is a bit like inventing and using a loop invariant

13 function Up(n: nat): Stream { Cons(n+1, Up(n+1)) } copredicate Pos(s: Stream) { s.head > 0  Pos(s.tail) } To prove Pos(Up(k)), choose Q(s) :=  n s = Up (n) and then prove: Q(Up(k)) (  s Q(s)  s.head > 0  Q(s.tail) )

14 Showing that a coinductive-datatype value satisfies a property can be proved using the coinduction principle Equality of two coinductive-datatype values can be proved by bisimulation (where one has to invent a relation R)

15 Proving a property can be done by bisimilarity Pos(a) ≡ Map(a, x x>0) = True() where copredicate Pos(s) { s.head > 0  Pos(s.tail)) } function Map(s, F) { Cons(F(s.head), Map(s.tail)) } function True() { Cons(true, True()) } Can bisimilarity be proved via property proofs?

16 comethod ? cowhile, coinvariant ?

17 A semantic notion of guarded, analogous to the semantic notion of well-founded Symmetry between predicate and copredicate ? Predicates are special cases of functions, which are defined computationally Copredicates are defined declaratively More natural language features to prove copredicates? How to do “manual” proofs by coinduction? What language features to support programmer- supplied relation R to prove bisimulation?


Download ppt "Coinduction in a language and verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond IFIP WG 2.3 meeting Seattle,"

Similar presentations


Ads by Google