How do you import part of the standard library in Coq?
- How do you import
Nat
specifically? - Why is reporting
Nat
not required to use+
?
I did the warmup exercise of proving commutativity of addition in Coq, as described here. I have a verbose solution in Appendix A of this question.
I added a slightly modified version of Lemma comm_plus
in Nick Dattani's answer to the buffer.
This isn't the entire proof. coqtop
(via Proof-General) refuses to advance past Nat.add_0_r
.
Theorem comm_plus_truenat: forall a b, a + b = b + a.
Proof.
intros. induction a.
- simpl.
symmetry.
apply Nat.add_0_r.
Qed
Attempting to run this incomplete proof produces the error Error: The reference Nat.add_0_r was not found in the current environment.
.
This makes sense, I haven't imported the Nat
library.
However, adding Require Nat.
, adding Import Nat.
, and adding both all produce the same error message.
How does one import Nat
(or another part of the standard library)?
I'm also curious why the theorem which uses +
, wasn't rejected.
Appendix A:
verbose, extremely naive proof of commutativity of natural number addition in Coq.
Inductive nat : Set :=
| O : nat
| S : nat -> nat .
Fixpoint plus (a b : nat) {struct a} : nat :=
match a with
| O => b
| S a'' => S (plus a'' b)
end.
Theorem comm_plus: forall (a b : nat), plus a b = plus b a.
Proof.
induction a.
intros.
simpl.
unfold plus.
induction b.
tauto.
simpl.
simpl in IHb.
f_equal.
tauto.
intros.
simpl.
rewrite IHa.
induction b.
simpl.
tauto.
simpl.
f_equal.
tauto.
Qed.
```