Ask HN: What's the difference between a specification and an implementation?

https://news.ycombinator.com/item?id=33018665
by cloogshicer • 4 years ago
2 11 4 years ago

I'm a developer trying to learn more about formal methods.

I don't understand the precise difference between a specification and an implementation.

For example, in this video about formal verification [1], the person gives a recursive definition of Fibonacci as the specification:

    function Fib(n: nat): nat {
        if n < 2 then n else Fib(n-2) + Fib(n-1)
    }
And then they proceed to implement it with a loop, to make it actually fast and usable.

My question is now: What exactly makes the above a specification? Isn't this just another implementation (a very slow one)?

Is every specification also an implementation? Is every implementation also a specification?

From my current understanding (which is probably wrong) the answer is Yes for both.

You could say they are not the same, because specifications don't have to be complete. But to that I'd answer: many implementations are also not complete, i.e. they have undefined behavior. Isn't a specification just another implementation at a higher level of abstraction?

I just don't understand what the formal difference between the two is.

[1] Basics of specification and verification: https://www.youtube.com/watch?v=J0FGb6PyO_k&t=574s

Related Stories

Loading related stories...

Source preview

news.ycombinator.com