Make an Embedding's back map the exact inverse of emb

118eb9c9Claude · 6d agoparent 5bdcd988files
Review finding: Embedding only required back (emb i) = some i, which
allows back to map a second tape onto a used one; such a lift would
overwrite a tape the docs call untouched. Add emb_back, so back j = some
i only when emb i = j, and prove it for castLE and skipOne.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Diff

1 files changed +21 -1
@@ -18,11 +18,14 @@
1818 namespace PvsNP
1919
2020 /-- How the tapes of a `k + 1`-tape machine sit among `k' + 1` tapes: `emb` places each small tape,
21-and `back` recognises the places (`none` for a tape the small machine does not use). -/
21+and `back` recognises the places (`none` for a tape the small machine does not use). The two laws
22+make `back` exactly the inverse of `emb` on its image, so `emb` is injective and every tape outside
23+the image is left alone. -/
2224 structure Embedding (k k' : Nat) where
2325 emb : Fin (k + 1) → Fin (k' + 1)
2426 back : Fin (k' + 1) → Option (Fin (k + 1))
2527 back_emb : ∀ i, back (emb i) = some i
28+ emb_back : ∀ j i, back j = some i → emb i = j
2629
2730 namespace Embedding
2831
@@ -31,6 +34,10 @@
3134 emb i := ⟨i.val, by omega⟩
3235 back j := if hj : j.val < k + 1 then some ⟨j.val, hj⟩ else none
3336 back_emb i := by simp [i.isLt]
37+ emb_back j i h := by
38+ split at h
39+ · cases h; rfl
40+ · cases h
3441
3542 /-- Tape `0` stays; tape `i + 1` becomes tape `i + 2`. Tape `1` is not used. -/
3643 def skipOne {k k' : Nat} (h : k + 1 ≤ k') : Embedding k k' where
@@ -48,6 +55,19 @@
4855 have h3 : i.val + 1 - 1 < k + 1 := by omega
4956 simp only [hi, h1, h2, h3, ↓reduceIte, ↓reduceDIte, Option.some.injEq]
5057 exact Fin.ext (by simp)
58+ emb_back j i h := by
59+ apply Fin.ext
60+ by_cases h0 : j.val = 0
61+ · simp only [h0, ↓reduceIte, Option.some.injEq] at h
62+ subst h; simp [h0]
63+ · by_cases h1 : j.val = 1
64+ · simp [h1] at h
65+ · simp only [h0, h1, ↓reduceIte] at h
66+ split at h
67+ · cases h
68+ have : j.val - 1 ≠ 0 := by omega
69+ simp [this]; omega
70+ · cases h
5171
5272 end Embedding
5373