1 / 17

Coinduction in a language and verifier

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. Question. How to add coinductive features , like coinductive datatypes c orecursive functions

kimberly
Télécharger la présentation

Coinduction in a language and verifier

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

  3. Inductive datatypes 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. Coinductivedatatypes 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. Constructors and destructors • One view (e.g., category theory, Charity) is that: • Inductive datatypes put emphasis on constructors • Nil : ()  List • Cons : int List  List • Coinductivedatatypes 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. Recursion function Append(a: List, b: List): List{match acase Nil => bcaseCons(h, t) => Cons(h, Append(t, b))} • Well-defined? • Yes, if the function terminates • Termination implies a unique fixpoint

  7. Corecursion 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. Combining recursion and corecursion • (Co)recursive calls,not (co)recursive functions function F(n: nat): Stream decreases (n+4)/5 * 5- n; { ifn % 5 == 0thenCons(n, F(n+1))else F(n+1) } Corecursive call Recursive call

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

  10. Inductive proofs • 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. Properties and equality, induction • 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. Coinductive proofs • Coinduction principle for a copredicatecopredicate 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. Example: Coinductive proof • function Up(n: nat): Stream{ Cons(n+1, Up(n+1)) } • copredicatePos(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. Properties and equality, induction • 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. Properties and bisimilarity • Proving a property can be done by bisimilarity • Pos(a)≡Map(a, x• x>0) = True()wherecopredicatePos(s) { s.head > 0  Pos(s.tail)) }functionMap(s, F) { Cons(F(s.head), Map(s.tail)) }functionTrue() { Cons(true, True()) } • Can bisimilarity be proved via property proofs?

  16. Manual coinductive proofs • comethod? • cowhile, coinvariant?

  17. Things I want to understand better • 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?

More Related