Induction principle for proving properties of Int-based ranges of the form a...b by
varying the lower bound.
In the base case, one proves that for any a : Int and b : Int with
b ≤ a, the statement holds for the empty range a...b.
In the step case, one proves that for any a : Int and b : Int, the
statement holds for nonempty ranges a...b if it holds for the smaller range
(a + 1)...b.
The following is an example reproving length_toList_rco.
example (a b : Int) : (a...b).toList.length = (b - a).toNat := by
induction a, b using Int.induct_rco_left
case base =>
simp [Int.toList_rco_eq_nil, List.length_nil, Int.zero_eq_toNat_sub_iff, *]
case step =>
simp only [Int.toList_rco_eq_cons, List.length_cons, *]; omega
Induction principle for proving properties of Int-based ranges of the form a...b by
varying the upper bound.
In the base case, one proves that for any a : Int and b : Int with
b ≤ a, the statement holds for the empty range a...b.
In the step case, one proves that for any a : Int and b : Int, if the
statement holds for a...b, it also holds for the larger range a...(b + 1).
The following is an example reproving length_toList_rco.
example (a b : Int) : (a...b).toList.length = (b - a).toNat := by
induction a, b using Int.induct_rco_right
case base =>
simp only [Int.toList_rco_eq_nil, List.length_nil, Int.zero_eq_toNat_sub_iff, *]
case step a b hle ih =>
rw [Int.toList_rco_eq_append (by omega),
List.length_append, List.length_singleton, Int.add_sub_cancel, ih]
omega
Induction principle for proving properties of Int-based ranges of the form a...=b by
varying the lower bound.
In the base case, one proves that for any a : Int and b : Int with
b < a, the statement holds for the empty range a...=b.
In the step case, one proves that for any a : Int and b : Int, the
statement holds for nonempty ranges a...b if it holds for the smaller range
(a + 1)...=b.
The following is an example reproving length_toList_rcc.
example (a b : Int) : (a...=b).toList.length = (b + 1 - a).toNat := by
induction a, b using Int.induct_rcc_left
case base =>
simp only [Int.toList_rcc_eq_nil, List.length_nil, Int.zero_eq_toNat_sub_iff, *]; omega
case step =>
simp only [Int.toList_rcc_eq_cons, List.length_cons, *]; omega
Induction principle for proving properties of Int-based ranges of the form a...=b by
varying the upper bound.
In the base case, one proves that for any a : Int and b : Int with
b ≤ a, the statement holds for the subsingleton range a...=b.
In the step case, one proves that for any a : Int and b : Int, if the
statement holds for a...=b, it also holds for the larger range a...=(b + 1).
The following is an example reproving length_toList_rcc.
example (a b : Int) : (a...=b).toList.length = (b + 1 - a).toNat := by
induction a, b using Int.induct_rcc_right
case base a b hge =>
by_cases h : b < a
· simp only [Int.toList_rcc_eq_nil, List.length_nil, *]
omega
· have : b = a := by omega
simp only [Int.toList_rcc_eq_singleton, List.length_singleton,
Int.sub_eq_iff_eq_add'.mpr rfl, Int.toNat_one, *]
case step a b hle ih =>
rw [Int.toList_rcc_succ_right_eq_append (by omega), List.length_append,
List.length_singleton, ih] <;> omega
Induction principle for proving properties of Int-based ranges of the form a<...b by
varying the lower bound.
In the base case, one proves that for any a : Int and b : Int with
b ≤ a + 1, the statement holds for the empty range a<...b.
In the step case, one proves that for any a : Int and b : Int, the
statement holds for nonempty ranges a<...b if it holds for the smaller range
(a + 1)<...b.
The following is an example reproving length_toList_roo.
example (a b : Int) : (a<...b).toList.length = (b - a - 1).toNat := by
induction a, b using Int.induct_roo_left
case base =>
simp only [Int.toList_roo_eq_nil, List.length_nil, Int.zero_eq_toNat_sub_iff, *]; omega
case step =>
simp only [Int.toList_roo_eq_cons, List.length_cons, *]; omega
Induction principle for proving properties of Int-based ranges of the form a<...b by
varying the upper bound.
In the base case, one proves that for any a : Int and b : Int with
b ≤ a + 1, the statement holds for the empty range a<...b.
In the step case, one proves that for any a : Int and b : Int, if the
statement holds for a<...b, it also holds for the larger range a<...(b + 1).
The following is an example reproving length_toList_roo.
example (a b : Int) : (a<...b).toList.length = (b - a - 1).toNat := by
induction a, b using Int.induct_roo_right
case base =>
simp only [Int.toList_roo_eq_nil, List.length_nil, *]; omega
case step a b hle ih =>
rw [Int.toList_roo_eq_append (by omega),
List.length_append, List.length_singleton, Int.add_sub_cancel, ih]
omega
Induction principle for proving properties of Int-based ranges of the form a<...=b
by varying the lower bound.
In the base case, one proves that for any a : Int and b : Int with
b ≤ a, the statement holds for the empty range a<...=b.
In the step case, one proves that for any a : Int and b : Int, the
statement holds for nonempty ranges a<...=b if it holds for the smaller range
(a + 1)<...=b.
The following is an example reproving length_toList_roc.
example (a b : Int) : (a<...=b).toList.length = (b - a).toNat := by
induction a, b using Int.induct_roc_left
case base =>
simp only [Int.toList_roc_eq_nil, List.length_nil, Int.zero_eq_toNat_sub_iff, *]
case step =>
simp only [Int.toList_roc_eq_cons, List.length_cons, *]; omega
Induction principle for proving properties of Int-based ranges of the form a<...=b
by varying the upper bound.
In the base case, one proves that for any a : Int and b : Int with
b ≤ a, the statement holds for the empty range a<...=b.
In the step case, one proves that for any a : Int and b : Int, if the
statement holds for a<...=b, it also holds for the larger range a<...=(b + 1).
The following is an example reproving length_toList_roc.
example (a b : Int) : (a<...=b).toList.length = (b - a).toNat := by
induction a, b using Int.induct_roc_right
case base =>
simp only [Int.toList_roc_eq_nil, List.length_nil, Int.zero_eq_toNat_sub_iff, *]
case step a b hle ih =>
rw [Int.toList_roc_eq_append (by omega),
List.length_append, List.length_singleton, Int.add_sub_cancel, ih]
omega