I have wrote this Inductive predicate and part of the proof for its (strong) specification:
Inductive SumPairs : (nat*nat) -> list (nat*nat) -> Prop :=
| sp_base : SumPairs (0,0) nil
| sp_step : forall (l0:list (nat*nat)) (n0 n1: nat) (y:(nat*nat)), SumPairs (n0,n1) l0 -> SumPairs ((n0+(fst y)),(n1+(snd y))) (cons y l0).
Theorem sumPairs_correct : forall (l:list (nat*nat)), { n: nat | SumPairs (n,n) l }.
Proof.
...
The thing is I don't think the theorem is correct because Coq doesn’t accept something like {n0 n1: nat | ...}
. Is there a way to fix that or am I thinking wrong?
I think the predicate SumPairs
is correct, but since I'm not sure, here's an example of how it should work: input [(1,2),(3,4)]
, expected output [3,7]
You could put a pair in the result, e.g.:
However, for this particular task, it is actually better to just use a plain functional program:
This definition is easier to read, to understand and to modify than the first version. Note that you can still use Coq to reason about the function: