1
1
/-
2
2
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
3
3
Released under Apache 2.0 license as described in the file LICENSE.
4
- Authors: Jeremy Avigad
4
+ Authors: Jeremy Avigad, Benjamin Davidson
5
5
6
6
The `even` and `odd` predicates on the natural numbers.
7
7
-/
@@ -19,8 +19,8 @@ theorem even_iff {n : ℕ} : even n ↔ n % 2 = 0 :=
19
19
⟨λ ⟨m, hm⟩, by simp [hm], λ h, ⟨n / 2 , (mod_add_div n 2 ).symm.trans (by simp [h])⟩⟩
20
20
21
21
theorem odd_iff {n : ℕ} : odd n ↔ n % 2 = 1 :=
22
- ⟨λ ⟨m, hm⟩, by { rw [hm, add_mod], norm_num } ,
23
- λ h, ⟨n / 2 , (mod_add_div n 2 ).symm.trans (by { rw h, abel } )⟩⟩
22
+ ⟨λ ⟨m, hm⟩, by norm_num [hm, add_mod],
23
+ λ h, ⟨n / 2 , (mod_add_div n 2 ).symm.trans (by rw [ h, add_comm] )⟩⟩
24
24
25
25
lemma not_even_iff {n : ℕ} : ¬ even n ↔ n % 2 = 1 :=
26
26
by rw [even_iff, mod_two_ne_zero]
@@ -86,32 +86,46 @@ begin
86
86
exact @modeq.modeq_add _ _ 1 _ 1 h₁ h₂
87
87
end
88
88
89
- theorem even.add {m n : ℕ} (hm : even m) (hn : even n) : even (m + n) :=
89
+ theorem even.add_even {m n : ℕ} (hm : even m) (hn : even n) : even (m + n) :=
90
90
even_add.2 $ by simp only [*]
91
91
92
+ theorem even_add' {m n : ℕ} : even (m + n) ↔ (odd m ↔ odd n) :=
93
+ by rw [even_add, even_iff_not_odd, even_iff_not_odd, not_iff_not]
94
+
95
+ theorem odd.add_odd {m n : ℕ} (hm : odd m) (hn : odd n) : even (m + n) :=
96
+ even_add'.2 $ by simp only [*]
97
+
92
98
@[simp] theorem not_even_bit1 (n : ℕ) : ¬ even (bit1 n) :=
93
99
by simp [bit1] with parity_simps
94
100
95
- lemma two_not_dvd_two_mul_add_one (a : ℕ) : ¬(2 ∣ 2 * a + 1 ) :=
101
+ lemma two_not_dvd_two_mul_add_one (n : ℕ) : ¬(2 ∣ 2 * n + 1 ) :=
96
102
begin
97
- convert not_even_bit1 a ,
98
- exact two_mul a ,
103
+ convert not_even_bit1 n ,
104
+ exact two_mul n ,
99
105
end
100
106
101
- lemma two_not_dvd_two_mul_sub_one : Π {a : ℕ} (w : 0 < a ), ¬(2 ∣ 2 * a - 1 )
102
- | (a+ 1 ) _ := two_not_dvd_two_mul_add_one a
107
+ lemma two_not_dvd_two_mul_sub_one : Π {n : ℕ} (w : 0 < n ), ¬(2 ∣ 2 * n - 1 ) | (n + 1 ) _ :=
108
+ two_not_dvd_two_mul_add_one n
103
109
104
110
@[parity_simps] theorem even_sub {m n : ℕ} (h : n ≤ m) : even (m - n) ↔ (even m ↔ even n) :=
105
111
begin
106
112
conv { to_rhs, rw [←nat.sub_add_cancel h, even_add] },
107
113
by_cases h : even n; simp [h]
108
114
end
109
115
110
- theorem even.sub {m n : ℕ} (hm : even m) (hn : even n) : even (m - n) :=
116
+ theorem even.sub_even {m n : ℕ} (hm : even m) (hn : even n) : even (m - n) :=
111
117
(le_total n m).elim
112
118
(λ h, by simp only [even_sub h, *])
113
119
(λ h, by simp only [sub_eq_zero_of_le h, even_zero])
114
120
121
+ theorem even_sub' {m n : ℕ} (h : n ≤ m) : even (m - n) ↔ (odd m ↔ odd n) :=
122
+ by rw [even_sub h, even_iff_not_odd, even_iff_not_odd, not_iff_not]
123
+
124
+ theorem odd.sub_odd {m n : ℕ} (hm : odd m) (hn : odd n) : even (m - n) :=
125
+ (le_total n m).elim
126
+ (λ h, by simp only [even_sub' h, *])
127
+ (λ h, by simp only [sub_eq_zero_of_le h, even_zero])
128
+
115
129
@[parity_simps] theorem even_succ {n : ℕ} : even (succ n) ↔ ¬ even n :=
116
130
by rw [succ_eq_add_one, even_add]; simp [not_even_one]
117
131
@@ -130,10 +144,47 @@ if and only if `m` is even and `n` is positive. -/
130
144
@[parity_simps] theorem even_pow {m n : ℕ} : even (m^n) ↔ even m ∧ n ≠ 0 :=
131
145
by { induction n with n ih; simp [*, pow_succ', even_mul], tauto }
132
146
133
- lemma even_div {a b : ℕ} : even (a / b ) ↔ a % (2 * b ) / b = 0 :=
147
+ lemma even_div {m n : ℕ} : even (m / n ) ↔ m % (2 * n ) / n = 0 :=
134
148
by rw [even_iff_two_dvd, dvd_iff_mod_eq_zero, nat.div_mod_eq_mod_mul_div, mul_comm]
135
149
136
- theorem neg_one_pow_eq_one_iff_even {α : Type *} [ring α] {n : ℕ} (h1 : (-1 : α) ≠ 1 ):
150
+ @[parity_simps] theorem odd_add {m n : ℕ} : odd (m + n) ↔ (odd m ↔ even n) :=
151
+ begin
152
+ by_contra hnot,
153
+ rw [not_iff, ← even_iff_not_odd, even_add, odd_iff_not_even, ← not_iff] at hnot,
154
+ exact (iff_not_self _).mp hnot,
155
+ end
156
+
157
+ theorem odd.add_even {m n : ℕ} (hm : odd m) (hn : even n) : odd (m + n) :=
158
+ odd_add.2 $ by simp only [*]
159
+
160
+ theorem odd_add' {m n : ℕ} : odd (m + n) ↔ (odd n ↔ even m) :=
161
+ by rw [add_comm, odd_add]
162
+
163
+ theorem even.add_odd {m n : ℕ} (hm : even m) (hn : odd n) : odd (m + n) :=
164
+ odd_add'.2 $ by simp only [*]
165
+
166
+ @[parity_simps] theorem odd_sub {m n : ℕ} (h : n ≤ m) : odd (m - n) ↔ (odd m ↔ even n) :=
167
+ begin
168
+ by_contra hnot,
169
+ rw [not_iff, ← even_iff_not_odd, even_sub h, odd_iff_not_even, ← not_iff] at hnot,
170
+ exact (iff_not_self _).mp hnot,
171
+ end
172
+
173
+ theorem odd.sub_even {m n : ℕ} (h : n ≤ m) (hm : odd m) (hn : even n) : odd (m - n) :=
174
+ (odd_sub h).mpr (iff_of_true hm hn)
175
+
176
+ theorem odd_sub' {m n : ℕ} (h : n ≤ m) : odd (m - n) ↔ (odd n ↔ even m) :=
177
+ begin
178
+ by_contra hnot,
179
+ rw [not_iff, ← even_iff_not_odd, even_sub h, odd_iff_not_even, ← not_iff,
180
+ @iff.comm _ (even n)] at hnot,
181
+ exact (iff_not_self _).mp hnot,
182
+ end
183
+
184
+ theorem even.sub_odd {m n : ℕ} (h : n ≤ m) (hm : even m) (hn : odd n) : odd (m - n) :=
185
+ (odd_sub' h).mpr (iff_of_true hn hm)
186
+
187
+ theorem neg_one_pow_eq_one_iff_even {α : Type *} [ring α] {n : ℕ} (h1 : (-1 : α) ≠ 1 ) :
137
188
(-1 : α) ^ n = 1 ↔ even n :=
138
189
⟨λ h, n.mod_two_eq_zero_or_one.elim (dvd_iff_mod_eq_zero _ _).2
139
190
(λ hn, by rw [neg_one_pow_eq_pow_mod_two, hn, pow_one] at h; exact (h1 h).elim),
0 commit comments