Section nat_experiment Fixpoint plus nat nat nat match with plus end F

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
Section nat_experiment.
Fixpoint plus (n:nat)(m:nat) : nat :=
match n with
| 0 => m
| S(n') => S (plus n' m)
end.
Fixpoint mult (n:nat)(m:nat) : nat :=
match n with
| 0 => 0
| S(n') => plus m (mult n' m)
end.
Lemma plus_0_l: forall n:nat, plus 0 n = n.
Proof.
simpl.
reflexivity.
Qed.
Lemma plus_0_r: forall n:nat, plus n 0 = n.
Proof.
intros.
induction n.
reflexivity.
simpl.
rewrite -> IHn.
reflexivity.
Qed.
Lemma plus_0_r_2: forall n:nat, plus n 0 = n.
Proof.
intros.
destruct n.
reflexivity.
auto.
Qed.
Lemma plus_0: forall n:nat, plus n 0 = plus 0 n.
Proof.
intros.
rewrite -> plus_0_l.
rewrite -> plus_0_r_2.
reflexivity.
Qed.
Notation "x + y" := (plus x y)
(at level 50, left associativity)
: nat_scope.
Lemma plus_s: forall n m, n+S(m) = S(n+m).
Proof.
intros.
destruct n.
simpl.
reflexivity.
simpl.
auto.
Qed.
Theorem plus_commutative: forall n m, (plus n m) = (plus m n).
Proof.
intros n m.
induction m.
rewrite -> plus_0.
reflexivity.
simpl.
rewrite <- IHm.
rewrite <- plus_s.
reflexivity.
Qed.
Theorem plus_associative: forall n m p, (n+m)+p = n+(m+p).
Proof.
intros n m p.
induction n.
trivial.
simpl.
rewrite <- plus_commutative.
rewrite <- IHn.
rewrite <- plus_commutative.
reflexivity.
Qed.
Lemma plus_ass_com: forall n m p, n + (m+p) = n + (p+m).
Proof.
intros.
induction n.
simpl.
rewrite -> plus_commutative.
reflexivity.
simpl.
rewrite -> IHn.
reflexivity.
Qed.
Lemma mult_0_r: forall n, mult n 0 = 0.
Proof.
auto.
Qed.
Lemma mult_0_l: forall n, mult 0 n = 0.
Proof.
auto.
Qed.
Lemma mult_s_l: forall n m, mult (S m) n = n + mult m n.
Proof.
trivial.
Qed.
Lemma mult_1_r: forall n, mult n 1 = n.
Proof.
induction n.
rewrite -> mult_0_l.
reflexivity.
simpl.
rewrite IHn.
reflexivity.
Qed.
Lemma mult_s_r: forall n m, mult n (S m) = n + mult n m.
Proof.
intros n m.
induction n.
rewrite -> mult_0_l.
rewrite -> mult_0_l.
simpl.
reflexivity.
simpl.
rewrite -> IHn.
rewrite -> plus_commutative.
rewrite -> plus_associative.
rewrite -> plus_ass_com.
reflexivity.
Qed.
Theorem mult_commutative: forall n m, (mult n m) = (mult m n).
Proof.
intros.
induction n.
rewrite -> mult_0_r.
rewrite -> mult_0_l.
reflexivity.
rewrite -> mult_s_l.
rewrite -> IHn.
rewrite -> mult_s_r.
reflexivity.
Qed.
End nat_experiment.