Well-founded Functions and Extreme Predicates in Dafny: A Tutorial
A recursive function is well defined if its every recursive callcorresponds a decrease in some well-founded order. Such a function issaid to be _terminating_ and is in many applications the standard wayto define a function. A boolean function can also be defined asan extreme solution to a recurrence relation, that is, as a least orgreatest fixpoint of some functor. Such _extreme predicates_ areuseful to encode a set of inductive or coinductive inference rulesand are at the core of many a constructive logic. Theverification-aware programming language Dafny supports bothterminating functions and extreme predicates. This tutorialdescribes the difference in general terms, and then describes novelsyntactic support in Dafny for defining and proving lemmas withextreme predicates. Various examples and considerations are given.Although Dafny's verifier has at its core a first-order SMT solver,Dafny's logical encoding makes it possible to reason about fixpointsin an automated way.