Example
keyword, which contained some statements about the behavior of a certain function applied to a specific set of arguments. Using the definition of a function, Coq simplifies the expression and checks its left and right parts for equality. Theorem plus_O_n: forall n: nat, 0 + n = n. Proof. simpl. reflexivity. Qed.
reflexivity
command implicitly simplifies both sides of an expression before comparing.simpl
and reflexivity
are examples of tactics. The main goal of tactics is to tell Coq how to check the correctness of the necessary statements. There is a rather narrow circle of problems whose correctness can be automatically proved. Prove that 2 + 2 = 4:Coq <Lemma using_auto: 2 + 2 = 4. 1 subgoal ============================ 2 + 2 = 4 using_auto <Proof. auto. Qed. Proof completed. auto. using_auto is defined
intros
tacticsn
”) and hypotheses (for example, “let a = b
”). The intros
tactic allows intros
to transfer quantifiers and hypotheses from statements to the context of current arguments. Let us prove that the result of multiplying the left of any natural number by zero is zero:Theorem mult_zero: forall n: nat, 0 * n = 0. Proof. intros n. reflexivity. Qed.
Theorem plus_id_example: forall nm: nat, n = m -> n + m = m + n.
n
and m
, this theorem speaks of narrower properties that take place for n = m
. Since n
and m
are arbitrary numbers, we cannot use simplification for the proof. Instead, we will prove that replacing m
with n
in the condition (assuming n = m
), we obtain the correct identity. The tactic that tells Coq to make this change is called rewrite
:Proof. intros n m. intros H. rewrite -> H. reflexivity. Qed.
Source: https://habr.com/ru/post/182936/
All Articles