dafnycode-translationformal-verification

Is the Dafny to Python code certified? If so, why does not Python have native pre-post options? If not, why translate it?


I have recently started testing with the Dafny to Python compiler dafny build --target:py A.dfy offered in its latest version. I'm not sure if it "works well", because it doesn't generate all the functions I have in Dafny (is this normal?).

However, I have a rather "philosophical" question about the use of translating a Dafny file into a Python file. Essentially, the Dafny code is a "certified" code in the sense that it guarantees that the functions fulfill their properties (if pre, then post); my question is, does the Python code fulfill this same thing?

If the answer is yes, the question is: why is not "certified" code written in Python? I mean why does not Python have some kind of native pre, post and assert (not the assert of Python). If the answer is no, the question is: what is the point of translating "certified" code to a "non-certified" one?


Solution

  • Only the executable code, but not the specifications are compiled. functions are not, whereas function methods are. Check the reference manual for more details on that. If you find that what is documented to work is not in line with what you experience, consider opening a ticket.

    The translation to Python is meant to preserve the semantics of your program. As this process isn't verified, there is no way of knowing that it does do that in all circumstances. Extending a language like Python with the necessary constructs for contracts and writing a verifier for the whole language sounds like a tall order, but this is ultimately a question for the Python community, not us. The point of compilation is that it lets you run your Dafny programs. If we would compile down to Assembly, you probably wouldn't worry about preserving the specifications.