Add `Tuple` module for use in mathematical-introduction-logic, chapter 1.

finite-set-exercises
Joshua Potter 2023-02-20 18:05:15 -07:00
parent d69dd926da
commit c92dee8e3d
10 changed files with 111 additions and 14 deletions

View File

@ -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

View File

@ -0,0 +1,6 @@
/-
# References
1. Enderton, Herbert B. A Mathematical Introduction to Logic. 2nd ed. San Diego:
Harcourt/Academic Press, 2001.
-/

View File

@ -0,0 +1,9 @@
import Lake
open Lake DSL
package «mathematical-introduction-logic»
@[default_target]
lean_lib «MathematicalIntroductionLogic» {
-- add library configuration options here
}

View File

@ -0,0 +1 @@
leanprover/lean4:nightly-2023-02-12

3
common/Bookshelf.lean Normal file
View File

@ -0,0 +1,3 @@
import Bookshelf.Sequence.Arithmetic
import Bookshelf.Sequence.Geometric
import Bookshelf.Tuple

View File

@ -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.Ring
/--
/--[1]
A 0th-indexed arithmetic sequence.
-/
structure Arithmetic where
@ -10,19 +17,19 @@ structure Arithmetic where
namespace Arithmetic
/--
/--[1]
Returns the value of the `n`th term of an arithmetic sequence.
-/
def termClosed (seq : Arithmetic) (n : Nat) : Int := seq.a₀ + seq.Δ * n
/--
/--[1]
Returns the value of the `n`th term of an arithmetic sequence.
-/
def termRecursive : Arithmetic → Nat → Int
| seq, 0 => seq.a₀
| seq, (n + 1) => seq.Δ + seq.termRecursive n
/--
/--[1]
The recursive definition and closed definitions of an arithmetic sequence are
equivalent.
-/
@ -39,14 +46,14 @@ theorem term_recursive_closed (seq : Arithmetic) (n : Nat)
_ = seq.a₀ + seq.Δ * (n + 1) := by ring
_ = termClosed seq (n + 1) := rfl)
/--
/--[1]
Summation of the first `n` terms of an arithmetic sequence.
-/
def sum : Arithmetic → Nat → Int
| _, 0 => 0
| 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.
--/

View File

@ -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.Ring
/--
/--[1]
A 0th-indexed geometric sequence.
-/
structure Geometric where
@ -10,19 +17,19 @@ structure Geometric where
namespace Geometric
/--
/--[1]
The value of the `n`th term of an geometric sequence.
-/
def termClosed (seq : Geometric) (n : Nat) : Int := seq.a₀ * seq.r ^ n
/--
/--[1]
The value of the `n`th term of an geometric sequence.
-/
def termRecursive : Geometric → Nat → Int
| seq, 0 => seq.a₀
| seq, (n + 1) => seq.r * (seq.termRecursive n)
/--
/--[1]
The recursive definition and closed definitions of a geometric sequence are
equivalent.
-/
@ -39,7 +46,7 @@ theorem term_recursive_closed (seq : Geometric) (n : Nat)
_ = seq.a₀ * seq.r ^ (n + 1) := by ring
_ = seq.termClosed (n + 1) := rfl)
/--
/--[1]
Summation of the first `n` terms of a geometric sequence.
-/
def sum : Geometric → Nat → Int

View File

@ -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

View File

@ -1,2 +0,0 @@
import Sequence.Arithmetic
import Sequence.Geometric

View File

@ -8,5 +8,5 @@ package «Common»
@[default_target]
lean_lib «Common» {
roots := #["Sequence"]
roots := #["Bookshelf"]
}