Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Instances For
Instances For
Induction principle for proving properties of Nat-based ranges of the form a...b by
varying the lower bound.
In the base case, one proves that for any a : Nat and b : Nat with
b ≤ a, the statement holds for the empty range a...b.
In the step case, one proves that for any a : Nat and b : Nat, 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 : Nat) : (a...b).toList.length = b - a := by
induction a, b using Nat.induct_rco_left
case base =>
simp only [Nat.toList_rco_eq_nil, List.length_nil, Nat.sub_eq_zero_of_le, *]
case step =>
simp only [Nat.toList_rco_eq_cons, List.length_cons, *]; omega
Induction principle for proving properties of Nat-based ranges of the form a...b by
varying the upper bound.
In the base case, one proves that for any a : Nat and b : Nat with
b ≤ a, the statement holds for the empty range a...b.
In the step case, one proves that for any a : Nat and b : Nat, 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 : Nat) : (a...b).toList.length = b - a := by
induction a, b using Nat.induct_rco_right
case base =>
simp only [Nat.toList_rco_eq_nil, List.length_nil, Nat.sub_eq_zero_of_le, *]
case step a b hle ih =>
rw [Nat.toList_rco_eq_append (by omega),
List.length_append, List.length_singleton, Nat.add_sub_cancel, ih]
omega
Induction principle for proving properties of Nat-based ranges of the form a...=b by
varying the lower bound.
In the base case, one proves that for any a : Nat and b : Nat with
b < a, the statement holds for the empty range a...=b.
In the step case, one proves that for any a : Nat and b : Nat, 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 : Nat) : (a...=b).toList.length = b + 1 - a := by
induction a, b using Nat.induct_rcc_left
case base =>
simp only [Nat.toList_rcc_eq_nil, List.length_nil, *]; omega
case step =>
simp only [Nat.toList_rcc_eq_cons, List.length_cons, *]; omega
Induction principle for proving properties of Nat-based ranges of the form a...=b by
varying the upper bound.
In the base case, one proves that for any a : Nat and b : Nat with
b ≤ a, the statement holds for the subsingleton range a...=b.
In the step case, one proves that for any a : Nat and b : Nat, 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 : Nat) : (a...=b).toList.length = b + 1 - a := by
induction a, b using Nat.induct_rcc_right
case base a b hge =>
by_cases h : b < a
· simp only [Nat.toList_rcc_eq_nil, List.length_nil, *]
omega
· have : b = a := by omega
simp only [Nat.toList_rcc_eq_singleton, List.length_singleton,
Nat.add_sub_cancel_left, *]
case step a b hle ih =>
rw [Nat.toList_rcc_succ_right_eq_append (by omega), List.length_append,
List.length_singleton, ih] <;> omega
Induction principle for proving properties of Nat-based ranges of the form a<...b by
varying the lower bound.
In the base case, one proves that for any a : Nat and b : Nat with
b ≤ a + 1, the statement holds for the empty range a<...b.
In the step case, one proves that for any a : Nat and b : Nat, 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 : Nat) : (a<...b).toList.length = b - a - 1 := by
induction a, b using Nat.induct_roo_left
case base =>
simp only [Nat.toList_roo_eq_nil, List.length_nil, *]; omega
case step =>
simp only [Nat.toList_roo_eq_cons, List.length_cons, *]; omega
Induction principle for proving properties of Nat-based ranges of the form a<...b by
varying the upper bound.
In the base case, one proves that for any a : Nat and b : Nat with
b ≤ a + 1, the statement holds for the empty range a<...b.
In the step case, one proves that for any a : Nat and b : Nat, 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 : Nat) : (a<...b).toList.length = b - a - 1 := by
induction a, b using Nat.induct_roo_right
case base =>
simp only [Nat.toList_roo_eq_nil, List.length_nil, *]; omega
case step a b hle ih =>
rw [Nat.toList_roo_eq_append (by omega),
List.length_append, List.length_singleton, Nat.add_sub_cancel, ih]
omega
Induction principle for proving properties of Nat-based ranges of the form a<...=b
by varying the lower bound.
In the base case, one proves that for any a : Nat and b : Nat with
b ≤ a, the statement holds for the empty range a<...=b.
In the step case, one proves that for any a : Nat and b : Nat, 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 : Nat) : (a<...=b).toList.length = b - a := by
induction a, b using Nat.induct_roc_left
case base =>
simp only [Nat.toList_roc_eq_nil, List.length_nil, *]; omega
case step =>
simp only [Nat.toList_roc_eq_cons, List.length_cons, *]; omega
Induction principle for proving properties of Nat-based ranges of the form a<...=b
by varying the upper bound.
In the base case, one proves that for any a : Nat and b : Nat with
b ≤ a, the statement holds for the empty range a<...=b.
In the step case, one proves that for any a : Nat and b : Nat, 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 : Nat) : (a<...=b).toList.length = b - a := by
induction a, b using Nat.induct_roc_right
case base =>
simp only [Nat.toList_roc_eq_nil, List.length_nil, *]; omega
case step a b hle ih =>
rw [Nat.toList_roc_eq_append (by omega),
List.length_append, List.length_singleton, Nat.add_sub_cancel, ih]
omega