Add `Tuple` module for use in mathematical-introduction-logic, chapter 1.
parent
d69dd926da
commit
c92dee8e3d
|
@ -0,0 +1,7 @@
|
||||||
|
/-
|
||||||
|
# References
|
||||||
|
|
||||||
|
1. Enderton, Herbert B. A Mathematical Introduction to Logic. 2nd ed. San Diego:
|
||||||
|
Harcourt/Academic Press, 2001.
|
||||||
|
-/
|
||||||
|
import MathematicalIntroductionLogic.Chapter0
|
|
@ -0,0 +1,6 @@
|
||||||
|
/-
|
||||||
|
# References
|
||||||
|
|
||||||
|
1. Enderton, Herbert B. A Mathematical Introduction to Logic. 2nd ed. San Diego:
|
||||||
|
Harcourt/Academic Press, 2001.
|
||||||
|
-/
|
|
@ -0,0 +1,9 @@
|
||||||
|
import Lake
|
||||||
|
open Lake DSL
|
||||||
|
|
||||||
|
package «mathematical-introduction-logic»
|
||||||
|
|
||||||
|
@[default_target]
|
||||||
|
lean_lib «MathematicalIntroductionLogic» {
|
||||||
|
-- add library configuration options here
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
leanprover/lean4:nightly-2023-02-12
|
|
@ -0,0 +1,3 @@
|
||||||
|
import Bookshelf.Sequence.Arithmetic
|
||||||
|
import Bookshelf.Sequence.Geometric
|
||||||
|
import Bookshelf.Tuple
|
|
@ -1,7 +1,14 @@
|
||||||
|
/-
|
||||||
|
# References
|
||||||
|
|
||||||
|
1. Levin, Oscar. Discrete Mathematics: An Open Introduction. 3rd ed., n.d.
|
||||||
|
https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf.
|
||||||
|
-/
|
||||||
|
|
||||||
import Mathlib.Tactic.NormNum
|
import Mathlib.Tactic.NormNum
|
||||||
import Mathlib.Tactic.Ring
|
import Mathlib.Tactic.Ring
|
||||||
|
|
||||||
/--
|
/--[1]
|
||||||
A 0th-indexed arithmetic sequence.
|
A 0th-indexed arithmetic sequence.
|
||||||
-/
|
-/
|
||||||
structure Arithmetic where
|
structure Arithmetic where
|
||||||
|
@ -10,19 +17,19 @@ structure Arithmetic where
|
||||||
|
|
||||||
namespace Arithmetic
|
namespace Arithmetic
|
||||||
|
|
||||||
/--
|
/--[1]
|
||||||
Returns the value of the `n`th term of an arithmetic sequence.
|
Returns the value of the `n`th term of an arithmetic sequence.
|
||||||
-/
|
-/
|
||||||
def termClosed (seq : Arithmetic) (n : Nat) : Int := seq.a₀ + seq.Δ * n
|
def termClosed (seq : Arithmetic) (n : Nat) : Int := seq.a₀ + seq.Δ * n
|
||||||
|
|
||||||
/--
|
/--[1]
|
||||||
Returns the value of the `n`th term of an arithmetic sequence.
|
Returns the value of the `n`th term of an arithmetic sequence.
|
||||||
-/
|
-/
|
||||||
def termRecursive : Arithmetic → Nat → Int
|
def termRecursive : Arithmetic → Nat → Int
|
||||||
| seq, 0 => seq.a₀
|
| seq, 0 => seq.a₀
|
||||||
| seq, (n + 1) => seq.Δ + seq.termRecursive n
|
| seq, (n + 1) => seq.Δ + seq.termRecursive n
|
||||||
|
|
||||||
/--
|
/--[1]
|
||||||
The recursive definition and closed definitions of an arithmetic sequence are
|
The recursive definition and closed definitions of an arithmetic sequence are
|
||||||
equivalent.
|
equivalent.
|
||||||
-/
|
-/
|
||||||
|
@ -39,14 +46,14 @@ theorem term_recursive_closed (seq : Arithmetic) (n : Nat)
|
||||||
_ = 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]
|
||||||
Summation of the first `n` terms of an arithmetic sequence.
|
Summation of the first `n` terms of an arithmetic sequence.
|
||||||
-/
|
-/
|
||||||
def sum : Arithmetic → Nat → Int
|
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
|
The closed formula of the summation of the first `n` terms of an arithmetic
|
||||||
series.
|
series.
|
||||||
--/
|
--/
|
|
@ -1,7 +1,14 @@
|
||||||
|
/-
|
||||||
|
# References
|
||||||
|
|
||||||
|
1. Levin, Oscar. Discrete Mathematics: An Open Introduction. 3rd ed., n.d.
|
||||||
|
https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf.
|
||||||
|
-/
|
||||||
|
|
||||||
import Mathlib.Tactic.NormNum
|
import Mathlib.Tactic.NormNum
|
||||||
import Mathlib.Tactic.Ring
|
import Mathlib.Tactic.Ring
|
||||||
|
|
||||||
/--
|
/--[1]
|
||||||
A 0th-indexed geometric sequence.
|
A 0th-indexed geometric sequence.
|
||||||
-/
|
-/
|
||||||
structure Geometric where
|
structure Geometric where
|
||||||
|
@ -10,19 +17,19 @@ structure Geometric where
|
||||||
|
|
||||||
namespace Geometric
|
namespace Geometric
|
||||||
|
|
||||||
/--
|
/--[1]
|
||||||
The value of the `n`th term of an geometric sequence.
|
The value of the `n`th term of an geometric sequence.
|
||||||
-/
|
-/
|
||||||
def termClosed (seq : Geometric) (n : Nat) : Int := seq.a₀ * seq.r ^ n
|
def termClosed (seq : Geometric) (n : Nat) : Int := seq.a₀ * seq.r ^ n
|
||||||
|
|
||||||
/--
|
/--[1]
|
||||||
The value of the `n`th term of an geometric sequence.
|
The value of the `n`th term of an geometric sequence.
|
||||||
-/
|
-/
|
||||||
def termRecursive : Geometric → Nat → Int
|
def termRecursive : Geometric → Nat → Int
|
||||||
| seq, 0 => seq.a₀
|
| seq, 0 => seq.a₀
|
||||||
| seq, (n + 1) => seq.r * (seq.termRecursive n)
|
| seq, (n + 1) => seq.r * (seq.termRecursive n)
|
||||||
|
|
||||||
/--
|
/--[1]
|
||||||
The recursive definition and closed definitions of a geometric sequence are
|
The recursive definition and closed definitions of a geometric sequence are
|
||||||
equivalent.
|
equivalent.
|
||||||
-/
|
-/
|
||||||
|
@ -39,7 +46,7 @@ theorem term_recursive_closed (seq : Geometric) (n : Nat)
|
||||||
_ = 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]
|
||||||
Summation of the first `n` terms of a geometric sequence.
|
Summation of the first `n` terms of a geometric sequence.
|
||||||
-/
|
-/
|
||||||
def sum : Geometric → Nat → Int
|
def sum : Geometric → Nat → Int
|
|
@ -0,0 +1,59 @@
|
||||||
|
/-
|
||||||
|
# References
|
||||||
|
|
||||||
|
1. Enderton, Herbert B. A Mathematical Introduction to Logic. 2nd ed. San Diego:
|
||||||
|
Harcourt/Academic Press, 2001.
|
||||||
|
-/
|
||||||
|
|
||||||
|
import Mathlib.Tactic.Ring
|
||||||
|
|
||||||
|
universe u
|
||||||
|
|
||||||
|
/--[1]
|
||||||
|
An n-tuple is defined recursively as:
|
||||||
|
|
||||||
|
⟨x₁, ..., xₙ₊₁⟩ = ⟨⟨x₁, ..., xₙ⟩, xₙ₊₁⟩
|
||||||
|
|
||||||
|
As [1] notes, it is also useful to define ⟨x⟩ = x.
|
||||||
|
--/
|
||||||
|
inductive Tuple (α : Type u) : Nat → Type u where
|
||||||
|
| nil : Tuple α 0
|
||||||
|
| cons : {n : Nat} → Tuple α n → α → Tuple α (n + 1)
|
||||||
|
|
||||||
|
syntax (priority := high) "⟨" term,+ "⟩" : term
|
||||||
|
|
||||||
|
macro_rules
|
||||||
|
| `(⟨$x⟩) => `(Tuple.cons Tuple.nil $x)
|
||||||
|
| `(⟨$xs:term,*, $x⟩) => `(Tuple.cons ⟨$xs,*⟩ $x)
|
||||||
|
|
||||||
|
namespace Tuple
|
||||||
|
|
||||||
|
/--
|
||||||
|
Returns the value at the nth-index of the given tuple.
|
||||||
|
-/
|
||||||
|
def index (t : Tuple α n) (m : Nat) : 1 ≤ m ∧ m ≤ n → α := by
|
||||||
|
intro h
|
||||||
|
cases t
|
||||||
|
· case nil =>
|
||||||
|
have ff : 1 ≤ 0 := Nat.le_trans h.left h.right
|
||||||
|
ring_nf at ff
|
||||||
|
exact False.elim ff
|
||||||
|
. case cons n' init last =>
|
||||||
|
by_cases k : m = n' + 1
|
||||||
|
· exact last
|
||||||
|
· exact index init m (And.intro h.left (by
|
||||||
|
have h₂ : m + 1 ≤ n' + 1 := Nat.lt_of_le_of_ne h.right k
|
||||||
|
norm_num at h₂
|
||||||
|
exact h₂))
|
||||||
|
|
||||||
|
-- TODO: Prove the following theorem
|
||||||
|
|
||||||
|
theorem eq_by_index (t₁ t₂ : Tuple α n)
|
||||||
|
: (t₁ = t₂) ↔ (∀ i : Nat, 1 ≤ i ∧ i ≤ n → index t₁ i = index t₂ i) := by
|
||||||
|
apply Iff.intro
|
||||||
|
· sorry
|
||||||
|
· sorry
|
||||||
|
|
||||||
|
-- TODO: [1] Lemma 0A
|
||||||
|
|
||||||
|
end Tuple
|
|
@ -1,2 +0,0 @@
|
||||||
import Sequence.Arithmetic
|
|
||||||
import Sequence.Geometric
|
|
|
@ -8,5 +8,5 @@ package «Common»
|
||||||
|
|
||||||
@[default_target]
|
@[default_target]
|
||||||
lean_lib «Common» {
|
lean_lib «Common» {
|
||||||
roots := #["Sequence"]
|
roots := #["Bookshelf"]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue