|
|
|
|
|
by turbinerneiter
2263 days ago
|
|
How does this formal specification look like? From my naive standpoint:
input, output, side-effect, time [no_sideffect, 1ms]
fn increment(int i) -> int:
return i + 1
What this is missing is a formal statement that says "increases the value of the input by one" -> except you accept the function body as formal statement.Thanks for all the answers here, I guess I'm going to look for some more reading material. |
|
Normally, you wouldn't take the function body as a formal statement, and would have a separate formal specification instead. In the example of increment, the formal specification is no simpler and no more useful than the implementation itself, but this is usually not the case.
Imagine e.g. that the following specification describes the desired behavior of a function f:
The OS developer would write something the code below to implement this specification. Does this C implementation conform to the specification? It's not all that easy to tell. But if the program is actually correct, then Floyd-Hoare logic [1] allows you to go through the program line-by-line and produce a proof that for any integer i and variable x', the following holds: meaning that if the statement x'=f(x') is ever executed in an environment where x' has an integer value i > 0, then after this line is executed, the result stored in x' will satisfy the specification above.[1] https://en.wikipedia.org/wiki/Hoare_logic