Use induction/cases tactics where it makes sense.
parent
7847cf1afe
commit
87c1fb2a24
|
@ -27,17 +27,16 @@ The recursive definition and closed definitions of an arithmetic sequence are
|
||||||
equivalent.
|
equivalent.
|
||||||
-/
|
-/
|
||||||
theorem term_recursive_closed (seq : Arithmetic) (n : Nat)
|
theorem term_recursive_closed (seq : Arithmetic) (n : Nat)
|
||||||
: seq.termRecursive n = seq.termClosed n :=
|
: seq.termRecursive n = seq.termClosed n := by
|
||||||
Nat.recOn
|
induction n with
|
||||||
n
|
| zero => unfold termRecursive termClosed; norm_num
|
||||||
(by unfold termRecursive termClosed; norm_num)
|
| succ n ih => calc
|
||||||
(fun n ih => calc
|
|
||||||
termRecursive seq (Nat.succ n)
|
termRecursive seq (Nat.succ n)
|
||||||
= seq.Δ + seq.termRecursive n := rfl
|
= seq.Δ + seq.termRecursive n := rfl
|
||||||
_ = seq.Δ + seq.termClosed n := by rw [ih]
|
_ = seq.Δ + seq.termClosed n := by rw [ih]
|
||||||
_ = seq.Δ + (seq.a₀ + seq.Δ * n) := rfl
|
_ = seq.Δ + (seq.a₀ + seq.Δ * n) := rfl
|
||||||
_ = seq.a₀ + seq.Δ * (n + 1) := by ring
|
_ = seq.a₀ + seq.Δ * (n + 1) := by ring
|
||||||
_ = termClosed seq (n + 1) := rfl)
|
_ = termClosed seq (n + 1) := rfl
|
||||||
|
|
||||||
/--[1]
|
/--[1]
|
||||||
Summation of the first `n` terms of an arithmetic sequence.
|
Summation of the first `n` terms of an arithmetic sequence.
|
||||||
|
@ -46,21 +45,4 @@ def sum : Arithmetic → Nat → Int
|
||||||
| _, 0 => 0
|
| _, 0 => 0
|
||||||
| seq, (n + 1) => seq.termClosed n + seq.sum n
|
| seq, (n + 1) => seq.termClosed n + seq.sum n
|
||||||
|
|
||||||
/--[1]
|
|
||||||
The closed formula of the summation of the first `n` terms of an arithmetic
|
|
||||||
series.
|
|
||||||
--/
|
|
||||||
theorem sum_closed_formula (seq : Arithmetic) (n : Nat)
|
|
||||||
: seq.sum n = (n / 2) * (seq.a₀ + seq.termClosed (n - 1)) :=
|
|
||||||
Nat.recOn
|
|
||||||
n
|
|
||||||
(by unfold sum termClosed; norm_num)
|
|
||||||
(fun n ih => calc
|
|
||||||
sum seq n.succ
|
|
||||||
= seq.termClosed n + seq.sum n := rfl
|
|
||||||
_ = seq.termClosed n + (n / 2 * (seq.a₀ + seq.termClosed (n - 1))) := by rw [ih]
|
|
||||||
_ = seq.a₀ + seq.Δ * n + (n / 2 * (seq.a₀ + (seq.a₀ + seq.Δ * ↑(n - 1)))) := rfl
|
|
||||||
-- TODO: To continue, need to find how to deal with division.
|
|
||||||
_ = ↑(n + 1) / 2 * (seq.a₀ + seq.termClosed n) := by sorry)
|
|
||||||
|
|
||||||
end Arithmetic
|
end Arithmetic
|
||||||
|
|
|
@ -27,17 +27,16 @@ The recursive definition and closed definitions of a geometric sequence are
|
||||||
equivalent.
|
equivalent.
|
||||||
-/
|
-/
|
||||||
theorem term_recursive_closed (seq : Geometric) (n : Nat)
|
theorem term_recursive_closed (seq : Geometric) (n : Nat)
|
||||||
: seq.termRecursive n = seq.termClosed n :=
|
: seq.termRecursive n = seq.termClosed n := by
|
||||||
Nat.recOn
|
induction n with
|
||||||
n
|
| zero => unfold termClosed termRecursive; norm_num
|
||||||
(by unfold termClosed termRecursive; norm_num)
|
| succ n ih => calc
|
||||||
(fun n ih => calc
|
|
||||||
seq.termRecursive (n + 1)
|
seq.termRecursive (n + 1)
|
||||||
= seq.r * (seq.termRecursive n) := rfl
|
= seq.r * (seq.termRecursive n) := rfl
|
||||||
_ = seq.r * (seq.termClosed n) := by rw [ih]
|
_ = seq.r * (seq.termClosed n) := by rw [ih]
|
||||||
_ = seq.r * (seq.a₀ * seq.r ^ n) := rfl
|
_ = seq.r * (seq.a₀ * seq.r ^ n) := rfl
|
||||||
_ = seq.a₀ * seq.r ^ (n + 1) := by ring
|
_ = seq.a₀ * seq.r ^ (n + 1) := by ring
|
||||||
_ = seq.termClosed (n + 1) := rfl)
|
_ = seq.termClosed (n + 1) := rfl
|
||||||
|
|
||||||
/--[1]
|
/--[1]
|
||||||
Summation of the first `n` terms of a geometric sequence.
|
Summation of the first `n` terms of a geometric sequence.
|
||||||
|
|
|
@ -133,11 +133,10 @@ theorem self_concat_nil_eq_self (t : Tuple α m) : concat t t[] = t :=
|
||||||
/--
|
/--
|
||||||
Concatenating `nil` with a `Tuple` yields the `Tuple`.
|
Concatenating `nil` with a `Tuple` yields the `Tuple`.
|
||||||
-/
|
-/
|
||||||
theorem nil_concat_self_eq_self (t : Tuple α m) : concat t[] t = t :=
|
theorem nil_concat_self_eq_self (t : Tuple α m) : concat t[] t = t := by
|
||||||
Tuple.recOn
|
induction t with
|
||||||
t
|
| nil => unfold concat; simp
|
||||||
(by unfold concat; simp)
|
| @snoc n as a ih =>
|
||||||
(@fun n as a ih => by
|
|
||||||
unfold concat
|
unfold concat
|
||||||
rw [ih]
|
rw [ih]
|
||||||
suffices HEq (snoc (cast (_ : Tuple α n = Tuple α (0 + n)) as) a) ↑(snoc as a)
|
suffices HEq (snoc (cast (_ : Tuple α n = Tuple α (0 + n)) as) a) ↑(snoc as a)
|
||||||
|
@ -153,7 +152,7 @@ theorem nil_concat_self_eq_self (t : Tuple α m) : concat t[] t = t :=
|
||||||
(snoc (cast (_ : Tuple α n = Tuple α (0 + n)) as) a)
|
(snoc (cast (_ : Tuple α n = Tuple α (0 + n)) as) a)
|
||||||
(cast h (snoc as a)))
|
(cast h (snoc as a)))
|
||||||
(show Tuple α (n + 1) = Tuple α (0 + (n + 1)) by simp)
|
(show Tuple α (n + 1) = Tuple α (0 + (n + 1)) by simp)
|
||||||
h₁)
|
h₁
|
||||||
|
|
||||||
/--
|
/--
|
||||||
Concatenating a `Tuple` to a nonempty `Tuple` moves `concat` calls closer to
|
Concatenating a `Tuple` to a nonempty `Tuple` moves `concat` calls closer to
|
||||||
|
@ -166,11 +165,11 @@ theorem concat_snoc_snoc_concat {bs : Tuple α n}
|
||||||
/--
|
/--
|
||||||
`snoc` is equivalent to concatenating the `init` and `last` element together.
|
`snoc` is equivalent to concatenating the `init` and `last` element together.
|
||||||
-/
|
-/
|
||||||
theorem snoc_eq_init_concat_last (as : Tuple α m) : snoc as a = concat as t[a] :=
|
theorem snoc_eq_init_concat_last (as : Tuple α m)
|
||||||
Tuple.casesOn (motive := fun _ t => snoc t a = concat t t[a])
|
: snoc as a = concat as t[a] := by
|
||||||
as
|
cases as with
|
||||||
rfl
|
| nil => rfl
|
||||||
(fun _ _ => by simp; unfold concat concat; rfl)
|
| snoc _ _ => simp; unfold concat concat; rfl
|
||||||
|
|
||||||
-- ========================================
|
-- ========================================
|
||||||
-- Initial sequences
|
-- Initial sequences
|
||||||
|
@ -196,10 +195,10 @@ def take (t : Tuple α n) (k : Nat) : Tuple α (min n k) :=
|
||||||
/--
|
/--
|
||||||
Taking no entries from any `Tuple` should yield an empty one.
|
Taking no entries from any `Tuple` should yield an empty one.
|
||||||
-/
|
-/
|
||||||
theorem self_take_zero_eq_nil (t : Tuple α n) : take t 0 = @nil α :=
|
theorem self_take_zero_eq_nil (t : Tuple α n) : take t 0 = @nil α := by
|
||||||
Tuple.recOn (motive := fun _ t => take t 0 = @nil α) t
|
induction t with
|
||||||
(by simp; rfl)
|
| nil => simp; rfl
|
||||||
(fun as a ih => by unfold take; simp; rw [ih]; simp)
|
| snoc as a ih => unfold take; simp; rw [ih]; simp
|
||||||
|
|
||||||
/--
|
/--
|
||||||
Taking any number of entries from an empty `Tuple` should yield an empty one.
|
Taking any number of entries from an empty `Tuple` should yield an empty one.
|
||||||
|
@ -210,10 +209,10 @@ theorem nil_take_zero_eq_nil (k : Nat) : (take (@nil α) k) = @nil α := by
|
||||||
/--
|
/--
|
||||||
Taking `n` entries from a `Tuple` of size `n` should yield the same `Tuple`.
|
Taking `n` entries from a `Tuple` of size `n` should yield the same `Tuple`.
|
||||||
-/
|
-/
|
||||||
theorem self_take_size_eq_self (t : Tuple α n) : take t n = t :=
|
theorem self_take_size_eq_self (t : Tuple α n) : take t n = t := by
|
||||||
Tuple.casesOn (motive := fun x t => take t x = t) t
|
cases t with
|
||||||
(by simp; rfl)
|
| nil => simp; rfl
|
||||||
(fun as a => by unfold take; simp)
|
| snoc as a => unfold take; simp
|
||||||
|
|
||||||
/--
|
/--
|
||||||
Taking all but the last entry of a `Tuple` is the same result, regardless of the
|
Taking all but the last entry of a `Tuple` is the same result, regardless of the
|
||||||
|
@ -229,7 +228,11 @@ Taking `n` elements from a tuple of size `n + 1` is the same as invoking `init`.
|
||||||
-/
|
-/
|
||||||
theorem init_eq_take_pred (t : Tuple α (n + 1)) : take t n = init t :=
|
theorem init_eq_take_pred (t : Tuple α (n + 1)) : take t n = init t :=
|
||||||
match t with
|
match t with
|
||||||
| snoc as a => by unfold init take; simp; rw [self_take_size_eq_self]; simp
|
| snoc as a => by
|
||||||
|
unfold init take
|
||||||
|
simp
|
||||||
|
rw [self_take_size_eq_self]
|
||||||
|
simp
|
||||||
|
|
||||||
/--
|
/--
|
||||||
If two `Tuple`s are equal, then any initial sequences of those two `Tuple`s are
|
If two `Tuple`s are equal, then any initial sequences of those two `Tuple`s are
|
||||||
|
@ -244,16 +247,15 @@ Given a `Tuple` of size `k`, concatenating an arbitrary `Tuple` and taking `k`
|
||||||
elements yields the original `Tuple`.
|
elements yields the original `Tuple`.
|
||||||
-/
|
-/
|
||||||
theorem eq_take_concat {t₁ : Tuple α m} {t₂ : Tuple α n}
|
theorem eq_take_concat {t₁ : Tuple α m} {t₂ : Tuple α n}
|
||||||
: take (concat t₁ t₂) m = t₁ :=
|
: take (concat t₁ t₂) m = t₁ := by
|
||||||
Tuple.recOn
|
induction t₂ with
|
||||||
(motive := fun x t => take (concat t₁ t) m = t₁) t₂
|
| nil => simp; rw [self_concat_nil_eq_self, self_take_size_eq_self]
|
||||||
(by simp; rw [self_concat_nil_eq_self, self_take_size_eq_self])
|
| @snoc n' as a ih =>
|
||||||
(@fun n' as a ih => by
|
|
||||||
simp
|
simp
|
||||||
rw [concat_snoc_snoc_concat]
|
rw [concat_snoc_snoc_concat]
|
||||||
unfold take
|
unfold take
|
||||||
simp
|
simp
|
||||||
rw [ih]
|
rw [ih]
|
||||||
simp)
|
simp
|
||||||
|
|
||||||
end Tuple
|
end Tuple
|
||||||
|
|
|
@ -66,18 +66,18 @@ theorem norm_snoc_nil_nil_eq_nil : @norm α 0 0 (snoc x[] t[]) = t[] := by
|
||||||
Normalization elimates `snoc` when the `snd` component is `nil`.
|
Normalization elimates `snoc` when the `snd` component is `nil`.
|
||||||
-/
|
-/
|
||||||
theorem norm_snoc_nil_elim {t : XTuple α (p, q)}
|
theorem norm_snoc_nil_elim {t : XTuple α (p, q)}
|
||||||
: norm (snoc t t[]) = norm t :=
|
: norm (snoc t t[]) = norm t := by
|
||||||
XTuple.casesOn t
|
cases t with
|
||||||
(motive := fun _ t => norm (snoc t t[]) = norm t)
|
| nil => simp; unfold norm norm; rfl
|
||||||
(by simp; unfold norm norm; rfl)
|
| snoc tf tl =>
|
||||||
(fun tf tl => by
|
|
||||||
simp
|
simp
|
||||||
conv => lhs; unfold norm)
|
conv => lhs; unfold norm
|
||||||
|
|
||||||
/--
|
/--
|
||||||
Normalization eliminates `snoc` when the `fst` component is `nil`.
|
Normalization eliminates `snoc` when the `fst` component is `nil`.
|
||||||
-/
|
-/
|
||||||
theorem norm_nil_snoc_elim {ts : Tuple α n} : norm (snoc x[] ts) = cast (by simp) ts := by
|
theorem norm_nil_snoc_elim {ts : Tuple α n}
|
||||||
|
: norm (snoc x[] ts) = cast (by simp) ts := by
|
||||||
unfold norm norm
|
unfold norm norm
|
||||||
rw [Tuple.nil_concat_self_eq_self]
|
rw [Tuple.nil_concat_self_eq_self]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue