Hello, community.
I have the following specification:
problem nonRecursiveFibonacci (in n: ℤ) : ℤ {
requires: {n ≥ 0}
ensures: {(∃l : seq(ℤ))(length l = n + 1 ∧ isFibonacciSequence(l) ∧ l !! (length (n-1)) = result)
}
predicate isFibonacciSequence (l: seq(ℤ)) {
(length l > 0 ⇒ l !! 0 = 0) ∧
(length l > 1 ⇒ l !! 1 = 1) ∧
(∀i : ℤ)(2 ≤ i < length l ⇒ l !! i = l !! (i - 1) + l !! (i - 2))
}
In the specification, I can reference the output value with the name **result, **and :
means “is of type”.
Then, I would have to implelment the function:
nonRecursiveFibonacci :: Int -> Int
In my attempts, any route I choose goes into recursion; any hints regarding a non-recursive definition ?
Is there any standard reference, of course perhaps not using that same notation, but using other kind of formalism, where I can see how can I derive a Haskell definition from a specification, or hints about using this one to think about the problem ?
As I do not have any experience so far with this kind of stuff, guidance would be greatly appreciated.