Taking code from CPDT, I'd like to prove a property for the easy stream ones
, which always return 1
.
CoFixpoint ones : Stream Z := Cons 1 ones.
Also from CPDT, I use this function to retrieve a list from the stream:
Fixpoint approx A (s:Stream A) (n:nat) : list A :=
match n with
| O => nil
| S p => match s with
| Cons h t => h :: approx A t p
end
end.
To get a list of five 1
, e.g.:
Eval compute in approx Z ones 5.
= 1 :: 1 :: 1 :: 1 :: 1 :: nil
: list Z
How do I prove, that for all n
given to approx
, the list will contain only 1
? I'm not even sure how to formulate this. Should I use a help function like nth n list
for lists, that return element number n
from list
? And that
forall (n length : nat), nth n1 (approx Z ones length) = 1
(Or maybe use Zeq
instead of =
.)
Am I heading the right direction?