Hi,
I'm trying to implement this fibonacci funtion:
fib : Nat -> Nat
fib = fst . fib2
where
fib2 : Nat -> (Nat, Nat)
fib2 Z = (1, 1)
fib2 (S Z) = (1, 2)
fib2 n@(S k) =
let (a,b) = fib2 ((n `div` 2) - 1)
c = a + b in
if isEven n then (a*a + b*b, c*c - a*a) else (c*c - a*a, b*b + c*c)
but Idris2 is complaining that ((n `div` 2) - 1) could be negative:
Error: While processing right hand side of fib2. Can't find an implementation for Neg Nat.
Shouldn't Idris figure out that given any n in this case, that expression can't be negative?
Or is there any way to let it know?
Thanks
tony