Skip to content

Commit 0ff2301

Browse files
committed
Init commit
0 parents  commit 0ff2301

File tree

11 files changed

+388
-0
lines changed

11 files changed

+388
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Create Release
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
- 'master'
8+
paths:
9+
- 'lean-toolchain'
10+
11+
jobs:
12+
lean-release-tag:
13+
name: Add Lean release tag
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
steps:
18+
- name: lean-release-tag action
19+
uses: leanprover-community/lean-release-tag@v1
20+
with:
21+
do-release: true
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Lean Action CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
9+
permissions:
10+
contents: read # Read access to repository contents
11+
pages: write # Write access to GitHub Pages
12+
id-token: write # Write access to ID tokens
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: leanprover/lean-action@v1
21+
- uses: leanprover-community/docgen-action@v1

.github/workflows/update.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Update Dependencies
2+
3+
on:
4+
# schedule: # Sets a schedule to trigger the workflow
5+
# - cron: "0 8 * * *" # Every day at 08:00 AM UTC (see https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#schedule)
6+
workflow_dispatch: # Allows the workflow to be triggered manually via the GitHub interface
7+
8+
jobs:
9+
check-for-updates: # Determines which updates to apply.
10+
runs-on: ubuntu-latest
11+
outputs:
12+
is-update-available: ${{ steps.check-for-updates.outputs.is-update-available }}
13+
new-tags: ${{ steps.check-for-updates.outputs.new-tags }}
14+
steps:
15+
- name: Run the action
16+
id: check-for-updates
17+
uses: leanprover-community/mathlib-update-action@v1
18+
# START CONFIGURATION BLOCK 1
19+
# END CONFIGURATION BLOCK 1
20+
do-update: # Runs the upgrade, tests it, and makes a PR/issue/commit.
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: write # Grants permission to push changes to the repository
24+
issues: write # Grants permission to create or update issues
25+
pull-requests: write # Grants permission to create or update pull requests
26+
needs: check-for-updates
27+
if: ${{ needs.check-for-updates.outputs.is-update-available }}
28+
strategy: # Runs for each update discovered by the `check-for-updates` job.
29+
max-parallel: 1 # Ensures that the PRs/issues are created in order.
30+
matrix:
31+
tag: ${{ fromJSON(needs.check-for-updates.outputs.new-tags) }}
32+
steps:
33+
- name: Run the action
34+
id: update-the-repo
35+
uses: leanprover-community/mathlib-update-action/do-update@v1
36+
with:
37+
tag: ${{ matrix.tag }}
38+
# START CONFIGURATION BLOCK 2
39+
on_update_succeeds: pr # Create a pull request if the update succeeds
40+
on_update_fails: issue # Create an issue if the update fails
41+
# END CONFIGURATION BLOCK 2

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.lake

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# RecMath
2+
3+
## GitHub configuration
4+
5+
To set up your new GitHub repository, follow these steps:
6+
7+
* Under your repository name, click **Settings**.
8+
* In the **Actions** section of the sidebar, click "General".
9+
* Check the box **Allow GitHub Actions to create and approve pull requests**.
10+
* Click the **Pages** section of the settings sidebar.
11+
* In the **Source** dropdown menu, select "GitHub Actions".
12+
13+
After following the steps above, you can remove this section from the README file.

RecMath.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import RecMath.Basic

RecMath/Basic.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def hello := "world"

RecMath/Collatz.lean

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
import Mathlib.Tactic
2+
import Mathlib.Logic.Function.Basic
3+
import Mathlib.Data.Nat.Basic
4+
import Mathlib.Data.Nat.ModEq
5+
-- import Mathlib.CategoryTheory.Category.Basic
6+
-- import Mathlib.Combinatorics.Quiver.Basic
7+
import Mathlib.Dynamics.FixedPoints.Basic
8+
import Mathlib.Dynamics.PeriodicPts.Defs
9+
import Mathlib.Dynamics.Flow
10+
import Mathlib.Topology.Defs.Basic
11+
12+
def step (n : Nat) : Nat :=
13+
if Even n then
14+
n / 2
15+
else
16+
3 * n + 1
17+
18+
theorem step.odd_even {n} (h : Odd n) : Even (step n) := by
19+
simp only [step, Nat.not_even_iff_odd.mpr h]
20+
apply Odd.add_odd
21+
· exact Nat.odd_mul.mpr ⟨by decide, h⟩
22+
· decide
23+
24+
theorem step.not_injective : ¬ step.Injective := by
25+
rw [Function.Injective]
26+
push_neg
27+
use 1, 8; decide
28+
29+
theorem step.surjective : step.Surjective := by
30+
intro n
31+
use 2 * n
32+
simp [step]
33+
34+
def step.continuous : Continuous step where
35+
isOpen_preimage := by simp
36+
37+
theorem step.minimalPeriod_one : step.minimalPeriod 1 = 3 := by
38+
apply Function.minimalPeriod_eq_prime <;> decide
39+
40+
theorem step.one_had_period_3 : step.IsPeriodicPt 3 1 := by
41+
decide
42+
43+
theorem step.isPeriodicPt_one : 1 ∈ step.periodicPts := by
44+
rw [Function.mem_periodicPts]
45+
use 3; decide
46+
47+
def step.periodicOrbit_one : Cycle Nat :=
48+
↑(List.map (fun (n : ℕ) => step^[n] 1) (List.range 3))
49+
50+
theorem step.periodicOrbit_one_def : step.periodicOrbit 1 = step.periodicOrbit_one := by
51+
rw [Function.periodicOrbit, step.minimalPeriod_one]
52+
decide
53+
54+
theorem step.fixedZero : step.fixedPoints = {0} := by
55+
rw [Function.fixedPoints]
56+
ext x
57+
constructor
58+
· intro x_fixed
59+
rw [Set.mem_setOf, Function.IsFixedPt, step] at x_fixed
60+
simp
61+
by_cases heven : Even x
62+
· let ⟨r, hx⟩ := heven
63+
rw [if_pos heven, hx, <- mul_two, Nat.mul_div_cancel r (by linarith)] at x_fixed
64+
omega
65+
· rw [if_neg heven] at x_fixed
66+
omega
67+
· simp [Function.IsFixedPt]
68+
rintro rfl
69+
decide
70+
71+
72+
73+
74+
variable {n m : Nat}
75+
76+
def GoesTo (n m : Nat) : Prop :=
77+
∃i, step^[i] n = m
78+
79+
infixr:50 " |=> " => GoesTo
80+
81+
instance GoesTo.Trans : Trans GoesTo GoesTo GoesTo where
82+
trans {α β γ} := by
83+
rintro ⟨ia, rfl⟩ ⟨ib, rfl⟩
84+
exact ⟨ib + ia, Function.iterate_add_apply step ib ia α⟩
85+
86+
def GoesTo.trans : Transitive GoesTo := by intro α β γ αβ βγ; exact GoesTo.Trans.trans αβ βγ
87+
88+
@[refl]
89+
theorem GoesTo.rfl : n |=> n := ⟨0, by simp⟩
90+
theorem GoesTo.reflexive : Reflexive GoesTo := by intro x; rfl
91+
92+
93+
def GoesTo.flow : Flow ℕ ℕ :=
94+
Flow.fromIter step.continuous
95+
96+
theorem GoesTo.even_path : (n * 2) |=> n := ⟨1, by simp [step]⟩
97+
98+
99+
theorem GoesTo.odd_path: n ≡ 4 [MOD 6] -> (n - 1) / 3 |=> n := by
100+
intro hm
101+
have : ¬Even ((n-1)/3) := by
102+
apply Nat.not_even_iff_odd.mpr
103+
apply Nat.odd_iff.mpr
104+
rcases n
105+
case zero => norm_num; contradiction
106+
case succ k =>
107+
· have hm' : k ≡ 3 [MOD 6] := by
108+
apply (Nat.ModEq.add_right_cancel' 1)
109+
rw [Nat.add_one]
110+
simpa
111+
calc (Nat.succ k - 1) / 3 % 2
112+
_ = k / 3 % 2 := by simp
113+
_ = k % 6 / 3 := by
114+
-- rw [Nat.div_mod_eq_mod_mul_div] -- This theorem is gone now :/
115+
sorry
116+
_ = 3 % 6 / 3 := by rw [hm']
117+
_ = 1 := by norm_num
118+
have onelen : 1 ≤ n := by
119+
calc
120+
_ ≤ 4 := by simp
121+
_ = 4 % 6 := by decide
122+
_ = n % 6 := by rw [hm]
123+
_ ≤ n := Nat.mod_le n 6
124+
have three_dvd_n_sub_one : 3 ∣ n - 1 := by
125+
apply (Nat.modEq_iff_dvd' onelen).mp
126+
rw [Nat.ModEq.comm] at hm
127+
apply Nat.ModEq.of_dvd ((by decide): 36) hm
128+
use 1
129+
rw [Function.iterate_one, step, if_neg this, Nat.mul_div_cancel' three_dvd_n_sub_one, Nat.sub_add_cancel onelen]
130+
131+
theorem GoesTo.even_family : ∀k, (n * 2^k) |=> n := by sorry
132+
133+
-- -- Complains that this does not terminate
134+
-- theorem GoesTo.even_family : ∀k, (n * 2^k) |=> n := by
135+
-- rintro (_ | i)
136+
-- · simp; rfl
137+
-- · calc n * 2 ^ Nat.succ i
138+
-- _ = n * 2 ^ i * 2 := by rw [Nat.pow_succ, <- mul_assoc]
139+
-- _ |=> n * 2 ^ i := even_path
140+
-- _ |=> _ := by
141+
-- apply even_family _
142+
143+
theorem GoesTo.odd_family : n ≡ 1 [MOD 6] -> ∀k, (n * 2^(2*k+2) - 1)/3 |=> n := by
144+
intro hn k
145+
have : n * 2 ^ (2 * k + 2) ≡ 4 [MOD 6] := by
146+
rw [<- one_mul 4]
147+
apply Nat.ModEq.mul hn
148+
induction k with
149+
| zero => simp; rfl
150+
| succ i hi =>
151+
calc 2 ^ (2 * Nat.succ i + 2) % 6
152+
_ = 2 ^ (2 * i + 2 + 2) % 6 := by rw [Nat.mul_succ]
153+
_ = (2 ^ (2 * i + 2) * 4) % 6 := by rw [Nat.pow_add]
154+
_ = 4 % 6 * (4 % 6) % 6 := by rw [Nat.mul_mod, hi]
155+
calc (n * 2^(2 * k + 2) - 1) / 3
156+
_ |=> n * 2^(2 * k + 2) := odd_path this
157+
_ |=> n := even_family _
158+
159+
theorem GoesTo.odd_family2 : n ≡ 5 [MOD 6] -> ∀k, (n * 2^(2*k+1) - 1)/3 |=> n := by
160+
intro hn k
161+
calc (n * 2 ^ (2 * k + 1) - 1) / 3
162+
_ |=> n * 2 ^ (2 * k + 1) := by
163+
apply odd_path
164+
rw [Nat.ModEq, ((by decide) : 45 * 2 [MOD 6]), <- Nat.ModEq]
165+
apply Nat.ModEq.mul hn
166+
induction k with
167+
| zero => simp; rfl
168+
| succ i ih =>
169+
calc 2 ^ (2 * i + 2 + 1) % 6
170+
_ = 2 ^ (2 * i + 1) * 2 ^ 2 % 6 := by ring_nf
171+
_ = 2 ^ (2 * i + 1) % 6 * (2 ^ 2 % 6) % 6 := by rw [Nat.mul_mod]
172+
_ = 2 % 6 * (2 ^ 2 % 6) % 6 := by rw [ih]
173+
_ = 2 % 6 := by norm_num
174+
_ |=> n := even_family _

lake-manifest.json

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{"version": "1.1.0",
2+
"packagesDir": ".lake/packages",
3+
"packages":
4+
[{"url": "https://github.com/leanprover-community/mathlib4",
5+
"type": "git",
6+
"subDir": null,
7+
"scope": "leanprover-community",
8+
"rev": "4a2cfa251229e07c20cdfb30efed40a7627fadac",
9+
"name": "mathlib",
10+
"manifestFile": "lake-manifest.json",
11+
"inputRev": "master",
12+
"inherited": false,
13+
"configFile": "lakefile.lean"},
14+
{"url": "https://github.com/leanprover-community/plausible",
15+
"type": "git",
16+
"subDir": null,
17+
"scope": "leanprover-community",
18+
"rev": "240eddc1bb31420fbbc57fe5cc579435c2522493",
19+
"name": "plausible",
20+
"manifestFile": "lake-manifest.json",
21+
"inputRev": "main",
22+
"inherited": true,
23+
"configFile": "lakefile.toml"},
24+
{"url": "https://github.com/leanprover-community/LeanSearchClient",
25+
"type": "git",
26+
"subDir": null,
27+
"scope": "leanprover-community",
28+
"rev": "99657ad92e23804e279f77ea6dbdeebaa1317b98",
29+
"name": "LeanSearchClient",
30+
"manifestFile": "lake-manifest.json",
31+
"inputRev": "main",
32+
"inherited": true,
33+
"configFile": "lakefile.toml"},
34+
{"url": "https://github.com/leanprover-community/import-graph",
35+
"type": "git",
36+
"subDir": null,
37+
"scope": "leanprover-community",
38+
"rev": "dba7fbc707774d1ba830fd44d7f92a717e9bf57f",
39+
"name": "importGraph",
40+
"manifestFile": "lake-manifest.json",
41+
"inputRev": "main",
42+
"inherited": true,
43+
"configFile": "lakefile.toml"},
44+
{"url": "https://github.com/leanprover-community/ProofWidgets4",
45+
"type": "git",
46+
"subDir": null,
47+
"scope": "leanprover-community",
48+
"rev": "6e47cc88cfbf1601ab364e9a4de5f33f13401ff8",
49+
"name": "proofwidgets",
50+
"manifestFile": "lake-manifest.json",
51+
"inputRev": "v0.0.71",
52+
"inherited": true,
53+
"configFile": "lakefile.lean"},
54+
{"url": "https://github.com/leanprover-community/aesop",
55+
"type": "git",
56+
"subDir": null,
57+
"scope": "leanprover-community",
58+
"rev": "3b779e9d1c73837a3764d516d81f942de391b6f0",
59+
"name": "aesop",
60+
"manifestFile": "lake-manifest.json",
61+
"inputRev": "master",
62+
"inherited": true,
63+
"configFile": "lakefile.toml"},
64+
{"url": "https://github.com/leanprover-community/quote4",
65+
"type": "git",
66+
"subDir": null,
67+
"scope": "leanprover-community",
68+
"rev": "f85ad59c9b60647ef736719c23edd4578f723806",
69+
"name": "Qq",
70+
"manifestFile": "lake-manifest.json",
71+
"inputRev": "master",
72+
"inherited": true,
73+
"configFile": "lakefile.toml"},
74+
{"url": "https://github.com/leanprover-community/batteries",
75+
"type": "git",
76+
"subDir": null,
77+
"scope": "leanprover-community",
78+
"rev": "eebfdee629c3f3298929216d61839d4702524d42",
79+
"name": "batteries",
80+
"manifestFile": "lake-manifest.json",
81+
"inputRev": "main",
82+
"inherited": true,
83+
"configFile": "lakefile.toml"},
84+
{"url": "https://github.com/leanprover/lean4-cli",
85+
"type": "git",
86+
"subDir": null,
87+
"scope": "leanprover",
88+
"rev": "cacb481a1eaa4d7d4530a27b606c60923da21caf",
89+
"name": "Cli",
90+
"manifestFile": "lake-manifest.json",
91+
"inputRev": "main",
92+
"inherited": true,
93+
"configFile": "lakefile.toml"}],
94+
"name": "RecMath",
95+
"lakeDir": ".lake"}

lakefile.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name = "RecMath"
2+
version = "0.1.0"
3+
keywords = ["math"]
4+
defaultTargets = ["RecMath"]
5+
6+
[leanOptions]
7+
pp.unicode.fun = true # pretty-prints `fun a ↦ b`
8+
autoImplicit = false
9+
relaxedAutoImplicit = false
10+
weak.linter.mathlibStandardSet = true
11+
maxSynthPendingDepth = 3
12+
13+
[[require]]
14+
name = "mathlib"
15+
scope = "leanprover-community"
16+
17+
[[lean_lib]]
18+
name = "RecMath"

0 commit comments

Comments
 (0)