I was trying to write a function whose type is forall n, option (n = 1).
I choose option as an altertnative to reflect avoiding giving the proof of the negative case. So Some plays the role ReflectT and holds the proof, while None doesn't hold the negative proof.
Definition is_1 n: bool:=
match n with
1 => true |
_ => false
end.
Lemma is_1_complete : forall n, is_1 n = true -> n = 1.
intros.
destruct n. simpl in H. discriminate.
destruct n. reflexivity.
simpl in H. discriminate.
Qed.
Lemma a_nat_is_1_or_not: forall n, option (n = 1).
intros.
cut (is_1 n = true -> n = 1).
-
intros.
destruct n. exact None.
destruct n. simpl in H. exact (Some (H (eq_refl))).
exact None.
-
exact (is_1_complete n).
Qed.
I've done with tactics. a_nat_is_1_or_not is the proof. And I thought I can do this writing the definition directly, so I tried.
Definition a_nat_is_1_or_not' n: option (n = 1) :=
match is_1 n with
true => Some (is_1_complete n eq_refl)
| false => None
end.
But Coq saids
Error:
In environment
n : nat
The term "eq_refl" has type "is_1 n = is_1 n"
while it is expected to have type "is_1 n = true" (cannot unify "is_1 n" and
"true").
It seems is_1 n cannot be unified to true in true case of the pattern matching of itself.
So I tried a more trivial example.
Definition every_true_is_I x: x = I :=
match x with
I => eq_refl
end.
It works.
What is the difference between a_nat_is_1_or_not' and every_truer_is_I?
Am I missing something? What can I do for writing a valid definition of forall n, is_1 n = true -> n = 1.?