@@ -71,51 +71,52 @@ the upwards induction step `p i → p (i + 1)` and the downwards induction step
71
71
72
72
It is used as the default induction principle for the `induction` tactic.
73
73
-/
74
- @[elab_as_elim, induction_eliminator] protected lemma induction_on {p : ℤ → Prop } (i : ℤ)
75
- (hz : p 0 ) (hp : ∀ i : ℕ, p i → p (i + 1 )) (hn : ∀ i : ℕ, p (-i) → p (-i - 1 )) : p i := by
74
+ @[elab_as_elim, induction_eliminator] protected lemma induction_on {motive : ℤ → Prop } (i : ℤ)
75
+ (zero : motive 0 ) (succ : ∀ i : ℕ, motive i → motive (i + 1 ))
76
+ (pred : ∀ i : ℕ, motive (-i) → motive (-i - 1 )) : motive i := by
76
77
cases i with
77
78
| ofNat i =>
78
79
induction i with
79
- | zero => exact hz
80
- | succ i ih => exact hp _ ih
80
+ | zero => exact zero
81
+ | succ i ih => exact succ _ ih
81
82
| negSucc i =>
82
- suffices ∀ n : ℕ, p (-n) from this (i + 1 )
83
+ suffices ∀ n : ℕ, motive (-n) from this (i + 1 )
83
84
intro n; induction n with
84
- | zero => simp [hz ]
85
- | succ n ih => simpa [natCast_succ, Int.neg_add, Int.sub_eq_add_neg] using hn _ ih
85
+ | zero => simp [zero ]
86
+ | succ n ih => simpa [natCast_succ, Int.neg_add, Int.sub_eq_add_neg] using pred _ ih
86
87
87
88
section inductionOn'
88
89
89
- variable {C : ℤ → Sort *} (z b : ℤ)
90
- (H0 : C b) (Hs : ∀ k, b ≤ k → C k → C (k + 1 )) (Hp : ∀ k ≤ b, C k → C (k - 1 ))
90
+ variable {motive : ℤ → Sort *} (z b : ℤ) (zero : motive b )
91
+ (succ : ∀ k, b ≤ k → motive k → motive (k + 1 )) (pred : ∀ k ≤ b, motive k → motive (k - 1 ))
91
92
92
93
/-- Inductively define a function on `ℤ` by defining it at `b`, for the `succ` of a number greater
93
94
than `b`, and the `pred` of a number less than `b`. -/
94
- @[elab_as_elim] protected def inductionOn' : C z :=
95
- cast (congrArg C <| show b + (z - b) = z by rw [Int.add_comm, z.sub_add_cancel b]) <|
95
+ @[elab_as_elim] protected def inductionOn' : motive z :=
96
+ cast (congrArg motive <| show b + (z - b) = z by rw [Int.add_comm, z.sub_add_cancel b]) <|
96
97
match z - b with
97
98
| .ofNat n => pos n
98
99
| .negSucc n => neg n
99
100
where
100
101
/-- The positive case of `Int.inductionOn'`. -/
101
- pos : ∀ n : ℕ, C (b + n)
102
- | 0 => cast (by simp) H0
102
+ pos : ∀ n : ℕ, motive (b + n)
103
+ | 0 => cast (by simp) zero
103
104
| n+1 => cast (by rw [Int.add_assoc]; rfl) <|
104
- Hs _ (Int.le_add_of_nonneg_right (natCast_nonneg _)) (pos n)
105
+ succ _ (Int.le_add_of_nonneg_right (natCast_nonneg _)) (pos n)
105
106
/-- The negative case of `Int.inductionOn'`. -/
106
- neg : ∀ n : ℕ, C (b + -[n+1 ])
107
- | 0 => Hp _ Int.le_rfl H0
107
+ neg : ∀ n : ℕ, motive (b + -[n+1 ])
108
+ | 0 => pred _ Int.le_rfl zero
108
109
| n+1 => by
109
- refine cast (by rw [Int.add_sub_assoc]; rfl) (Hp _ (Int.le_of_lt ?_) (neg n))
110
+ refine cast (by rw [Int.add_sub_assoc]; rfl) (pred _ (Int.le_of_lt ?_) (neg n))
110
111
omega
111
112
112
- variable {z b H0 Hs Hp }
113
+ variable {z b zero succ pred }
113
114
114
- lemma inductionOn'_self : b.inductionOn' b H0 Hs Hp = H0 :=
115
+ lemma inductionOn'_self : b.inductionOn' b zero succ pred = zero :=
115
116
cast_eq_iff_heq.mpr <| .symm <| by rw [b.sub_self, ← cast_eq_iff_heq]; rfl
116
117
117
118
lemma inductionOn'_sub_one (hz : z ≤ b) :
118
- (z - 1 ).inductionOn' b H0 Hs Hp = Hp z hz (z.inductionOn' b H0 Hs Hp ) := by
119
+ (z - 1 ).inductionOn' b zero succ pred = pred z hz (z.inductionOn' b zero succ pred ) := by
119
120
apply cast_eq_iff_heq.mpr
120
121
obtain ⟨n, hn⟩ := Int.eq_negSucc_of_lt_zero (show z - 1 - b < 0 by omega)
121
122
rw [hn]
@@ -133,35 +134,38 @@ lemma inductionOn'_sub_one (hz : z ≤ b) :
133
134
end inductionOn'
134
135
135
136
/-- Inductively define a function on `ℤ` by defining it on `ℕ` and extending it from `n` to `-n`. -/
136
- @[elab_as_elim] protected def negInduction {C : ℤ → Sort *} (nat : ∀ n : ℕ, C n)
137
- (neg : (∀ n : ℕ, C n) → ∀ n : ℕ, C (-n)) : ∀ n : ℤ, C n
137
+ @[elab_as_elim] protected def negInduction {motive : ℤ → Sort *} (nat : ∀ n : ℕ, motive n)
138
+ (neg : (∀ n : ℕ, motive n) → ∀ n : ℕ, motive (-n)) : ∀ n : ℤ, motive n
138
139
| .ofNat n => nat n
139
140
| .negSucc n => neg nat <| n + 1
140
141
141
142
/-- See `Int.inductionOn'` for an induction in both directions. -/
142
- protected lemma le_induction {P : ℤ → Prop } {m : ℤ} (h0 : P m)
143
- (h1 : ∀ n : ℤ, m ≤ n → P n → P (n + 1 )) (n : ℤ) : m ≤ n → P n := by
144
- refine Int.inductionOn' n m ?_ ?_ ?_
143
+ @[elab_as_elim]
144
+ protected lemma le_induction {m : ℤ} {motive : ∀ n, m ≤ n → Prop } (base : motive m m.le_refl)
145
+ (succ : ∀ n hmn, motive n hmn → motive (n + 1 ) (le_add_one hmn)) : ∀ n hmn, motive n hmn := by
146
+ refine fun n ↦ Int.inductionOn' n m ?_ ?_ ?_
145
147
· intro
146
- exact h0
148
+ exact base
147
149
· intro k hle hi _
148
- exact h1 k hle (hi hle)
150
+ exact succ k hle (hi hle)
149
151
· intro k hle _ hle'
150
152
omega
151
153
152
154
/-- See `Int.inductionOn'` for an induction in both directions. -/
153
- protected theorem le_induction_down {P : ℤ → Prop } {m : ℤ} (h0 : P m)
154
- (h1 : ∀ n : ℤ, n ≤ m → P n → P (n - 1 )) (n : ℤ) : n ≤ m → P n :=
155
- Int.inductionOn' n m (fun _ ↦ h0) (fun k hle _ hle' ↦ by omega)
156
- fun k hle hi _ ↦ h1 k hle (hi hle)
155
+ @[elab_as_elim]
156
+ protected lemma le_induction_down {m : ℤ} {motive : ∀ n, n ≤ m → Prop } (base : motive m m.le_refl)
157
+ (pred : ∀ n hmn, motive n hmn → motive (n - 1 ) (by omega)) : ∀ n hmn, motive n hmn := fun n ↦
158
+ Int.inductionOn' n m (fun _ ↦ base) (fun k hle _ hle' ↦ by omega)
159
+ fun k hle hi _ ↦ pred k hle (hi hle)
157
160
158
161
section strongRec
159
162
160
- variable {P : ℤ → Sort *} (lt : ∀ n < m, P n) (ge : ∀ n ≥ m, (∀ k < n, P k) → P n)
163
+ variable {motive : ℤ → Sort *} (lt : ∀ n < m, motive n)
164
+ (ge : ∀ n ≥ m, (∀ k < n, motive k) → motive n)
161
165
162
166
/-- A strong recursor for `Int` that specifies explicit values for integers below a threshold,
163
167
and is analogous to `Nat.strongRec` for integers on or above the threshold. -/
164
- @[elab_as_elim] protected def strongRec (n : ℤ) : P n := by
168
+ @[elab_as_elim] protected def strongRec (n : ℤ) : motive n := by
165
169
refine if hnm : n < m then lt n hnm else ge n (by omega) (n.inductionOn' m lt ?_ ?_)
166
170
· intro _n _ ih l _
167
171
exact if hlm : l < m then lt l hlm else ge l (by omega) fun k _ ↦ ih k (by omega)
0 commit comments