Refinement from recursion to loop? #6052
Unanswered
mschwerhoff
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Does Dafny provide any refinement constructs, in the spirit of "module B refines module A", for replacing a recursive implementation with a loop?
As illustration, consider the following simple example with two implementations of the Fibonacci function:
The loop-based bottom-up computation implicitly refines the recursive top-down computation, via appropriate invariants and postconditions. However, I'm wondering if more specific language support would simplify proving such refinements.
For example, although not an issue in the simple case of Fibonacci: the recursive function could have additional preconditions that check certain well-definedness properties (e.g. that numbers and indices are in certain ranges, that objects are not null, that sequences are not empty or of certain length), and in the current "implicit refinement" prove as illustrated above, these would most likely have to be duplicated by the loop invariant.
Thoughts and suggestions are welcome :-)
Beta Was this translation helpful? Give feedback.
All reactions