Skip to content

Commit fdd06fb

Browse files
committed
Reorganize project + Populate List.induction_right
1 parent 29e2145 commit fdd06fb

19 files changed

Lines changed: 75 additions & 3094 deletions

.github/workflows/create-release.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

.github/workflows/lean_action_ci.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@ on:
55
pull_request:
66
workflow_dispatch:
77

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-
148
jobs:
159
build:
1610
runs-on: ubuntu-latest
1711

1812
steps:
1913
- uses: actions/checkout@v4
2014
- uses: leanprover/lean-action@v1
21-
- uses: leanprover-community/docgen-action@v1
15+
with:
16+
directory: TraceTheory

.github/workflows/update.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/.lake
1+
/*.pdf

README.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

TraceTheory/.gitignore

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

TraceTheory/TraceTheory.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- This module serves as the root of the `TraceTheory` library.
2+
-- Import modules here that should be built as part of the library.
3+
import TraceTheory.Basic

TraceTheory/TraceTheory/Basic.lean

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
namespace List
2+
3+
/--
4+
This theorem provides an induction principle for lists where the inductive step
5+
appends an element to the right (i.e., builds lists by snoc rather than cons).
6+
The intuition is that, instead of the usual head recursion, we want to prove a property
7+
for all lists by showing:
8+
- the property holds for the empty list, and
9+
- if it holds for a list `l`, then it holds for `l ++ [a]` for any `a`.
10+
-/
11+
theorem induction_right {α : Type u} {P : List α → Prop}
12+
(h_nil : P [])
13+
(h_snoc : ∀ (l : List α) (a : α), P l → P (l ++ [a])) :
14+
∀ l : List α, P l := by
15+
/-
16+
We want to prove P l for all lists l, using right induction.
17+
However, Lean's built-in induction on lists is left-sided (on cons), not right-sided (on snoc).
18+
To overcome this, we use a classic strengthening technique:
19+
instead of proving just P l, we prove a stronger property
20+
Q l := ∀ k, P k → P (k ++ l)
21+
This means: if we know P holds for any prefix k, then it also holds for k ++ l.
22+
Proving Q l for all l is strictly stronger than just P l, but it allows us to perform induction on l (using cons),
23+
and at the end, we recover the original goal by taking k = [].
24+
-/
25+
intro l
26+
let Q := fun (l : List α) => ∀ (k : List α), P k → P (k ++ l)
27+
-- Base case: l = []. We must show Q []: ∀ k, P k → P (k ++ []).
28+
have h_base : Q [] := by
29+
intro k hk
30+
-- In this case, k ++ [] = k, so P (k ++ []) = P k, which is exactly hk.
31+
rw [List.append_nil]
32+
exact hk
33+
-- Inductive step: assume Q l', show Q (a :: l') for any a.
34+
have h_step : ∀ (a : α) (l' : List α), Q l' → Q (a :: l') := by
35+
intros a l' IH k hk
36+
/-
37+
Goal: P (k ++ (a :: l')) given P k.
38+
Observe: k ++ (a :: l') = (k ++ [a]) ++ l'.
39+
By the snoc hypothesis, from P k we get P (k ++ [a]).
40+
By the induction hypothesis (IH), from P (k ++ [a]) we get P ((k ++ [a]) ++ l').
41+
Thus, we chain these two steps to get the result.
42+
-/
43+
have hka : P (k ++ [a]) := h_snoc k a hk
44+
have : k ++ (a :: l') = (k ++ [a]) ++ l' := by simp [List.append_assoc]
45+
rw [this]
46+
exact IH (k ++ [a]) hka
47+
-- Now, by induction on l (using the usual left induction), we get Q l for all l.
48+
have hQ : ∀ l, Q l := by
49+
intro l'
50+
induction l' with
51+
| nil => exact h_base
52+
| cons a l'' IH => exact h_step a l'' IH
53+
-- Finally, to recover the original goal, specialize to k = [] and use h_nil : P [].
54+
exact hQ l [] h_nil
55+
56+
end List

TraceTheory/lake-manifest.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{"version": "1.1.0",
2+
"packagesDir": ".lake/packages",
3+
"packages": [],
4+
"name": "TraceTheory",
5+
"lakeDir": ".lake"}

TraceTheory/lakefile.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name = "TraceTheory"
2+
version = "0.1.0"
3+
defaultTargets = ["TraceTheory"]
4+
5+
[[lean_lib]]
6+
name = "TraceTheory"

0 commit comments

Comments
 (0)