Lean migration cleanup: collapse FixedHeight struct into FiniteHeightLattice typeclass
The fable-based migration left a two-layer design (a standalone `FixedHeight α h` struct, height carried as a type index, plus a `FiniteHeightLattice` wrapper). This collapses it to the single `FiniteHeightLattice` typeclass (height as a plain field, `⊥`/`⊤` via `extends Bot`/`Top`), and fixes the fallout so the whole project builds again (`lake build` green). - Lattice: repair `FixedHeight.bot_le` (compute the `▸` motive via a forward `rw`, drop the leftover `fh.length_longestChain`) and the `bot_le` alias. - Isomorphism: transport rewritten directly onto `FiniteHeightLattice`, taking the source as an instance argument. - Lattice/Prod, AboveBelow: `FixedHeight`-producing def + wrapper instance collapsed into one `FiniteHeightLattice` instance. `head`/`last` proofs use term-mode `congrArg` to bridge the `Bot`/`Top` defeq through the under-construction instance projection (where `rw`+`rfl` cannot). - Lattice/IterProd: `fixedHeight` recursion now yields a `FiniteHeightLattice` (no height index, so the `.cast (by ring)` reassociations vanish); `bot_fixedHeight` reprojected onto the def's own `.bot`. - Lattice/FiniteMap: `fixedHeight`/`bot_contains_bots` go through transport with the IterProd instance resolved by typeclass search; `punitFixedHeight` replaced by the `PUnit` instance. - Analysis/Forward/Lattices: `botV` uses `⊥` instead of the deleted `FiniteHeightLattice.bot` accessor. - Analysis/Sign: `num` case used unimported `ring`; the goal is a pure ℕ→ℤ cast identity, closed with `norm_cast`. Also fixes the missing `show` in `AboveBelow.monotone₂_of_strict` that left un-beta-reduced redexes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,41 +1,16 @@
|
||||
/-
|
||||
Port of `Fixedpoint.agda`.
|
||||
|
||||
Same gas-based algorithm: iterate `f` starting at the chain-bottom `⊥`; since
|
||||
the lattice has fixed height `h`, a fixed point must be reached within `h + 1`
|
||||
steps, or we would build a `<`-chain longer than the longest one. We
|
||||
deliberately do *not* use mathlib's `OrderHom.lfp` (different proof approach,
|
||||
and not computable).
|
||||
|
||||
As in Agda — where the module took `{{flA : IsFiniteHeightLattice A h …}}` —
|
||||
the finite-height structure arrives by instance resolution
|
||||
(`[FiniteHeightLattice α]`); only `f` and its monotonicity are explicit.
|
||||
|
||||
Correspondence:
|
||||
doStep ↦ Spa.Fixedpoint.doStep (the chain argument now carries
|
||||
`a₁ = ⊥` and its length in the
|
||||
`LTSeries` structure itself)
|
||||
fix ↦ Spa.Fixedpoint.fix
|
||||
aᶠ ↦ Spa.Fixedpoint.aFix
|
||||
aᶠ≈faᶠ ↦ Spa.Fixedpoint.aFix_eq
|
||||
stepPreservesLess ↦ Spa.Fixedpoint.doStep_le
|
||||
aᶠ≼ ↦ Spa.Fixedpoint.aFix_le
|
||||
-/
|
||||
import Spa.Lattice
|
||||
|
||||
namespace Spa.Fixedpoint
|
||||
|
||||
open FiniteHeightLattice (height fixedHeight)
|
||||
open FiniteHeightLattice (height)
|
||||
|
||||
variable {α : Type*} [Lattice α] [DecidableEq α] [FiniteHeightLattice α]
|
||||
|
||||
/-- Agda: `doStep`. `g` is gas; the invariant `c.length + g = h + 1` guarantees
|
||||
that when gas runs out the chain contradicts boundedness. -/
|
||||
def doStep (f : α → α) (hf : Monotone f) :
|
||||
∀ (g : ℕ) (c : LTSeries α), c.length + g = height (α := α) + 1 →
|
||||
c.last ≤ f c.last → {a : α // a = f a}
|
||||
| 0, c, hlen, _ =>
|
||||
absurd ((fixedHeight (α := α)).bounded c) (by omega)
|
||||
absurd (FiniteHeightLattice.chains_bounded c) (by omega)
|
||||
| g + 1, c, hlen, hle =>
|
||||
if heq : c.last = f c.last then
|
||||
⟨c.last, heq⟩
|
||||
@@ -44,29 +19,25 @@ def doStep (f : α → α) (hf : Monotone f) :
|
||||
(by simp [RelSeries.snoc]; omega)
|
||||
(by rw [RelSeries.last_snoc]; exact hf hle)
|
||||
|
||||
/-- Agda: `fix`. Start iterating from `⊥`. -/
|
||||
def fix (f : α → α) (hf : Monotone f) : {a : α // a = f a} :=
|
||||
doStep f hf (height (α := α) + 1) (RelSeries.singleton _ (FiniteHeightLattice.bot α))
|
||||
doStep f hf (height (α := α) + 1) (RelSeries.singleton _ ⊥)
|
||||
(by simp)
|
||||
(by simpa [RelSeries.last_singleton]
|
||||
using FiniteHeightLattice.bot_le α (f (FiniteHeightLattice.bot α)))
|
||||
using FiniteHeightLattice.bot_le α (f ⊥))
|
||||
|
||||
/-- Agda: `aᶠ`. -/
|
||||
def aFix (f : α → α) (hf : Monotone f) : α :=
|
||||
(fix f hf).1
|
||||
|
||||
/-- Agda: `aᶠ≈faᶠ`. -/
|
||||
theorem aFix_eq (f : α → α) (hf : Monotone f) :
|
||||
aFix f hf = f (aFix f hf) :=
|
||||
(fix f hf).2
|
||||
|
||||
/-- Agda: `stepPreservesLess` — iteration stays below any fixed point. -/
|
||||
theorem doStep_le (f : α → α) (hf : Monotone f)
|
||||
{b : α} (hb : b = f b) :
|
||||
∀ (g : ℕ) (c : LTSeries α) (hlen : c.length + g = height (α := α) + 1)
|
||||
(hle : c.last ≤ f c.last), c.last ≤ b →
|
||||
(doStep f hf g c hlen hle : α) ≤ b
|
||||
| 0, c, hlen, _ => fun _ => absurd ((fixedHeight (α := α)).bounded c) (by omega)
|
||||
| 0, c, hlen, _ => fun _ => absurd (FiniteHeightLattice.chains_bounded c) (by omega)
|
||||
| g + 1, c, hlen, hle => fun hcb => by
|
||||
rw [doStep]
|
||||
split
|
||||
@@ -74,7 +45,6 @@ theorem doStep_le (f : α → α) (hf : Monotone f)
|
||||
· exact doStep_le f hf hb g _ _ _
|
||||
(by rw [RelSeries.last_snoc]; exact le_of_le_of_eq (hf hcb) hb.symm)
|
||||
|
||||
/-- Agda: `aᶠ≼` — `aFix` is below every fixed point of `f`. -/
|
||||
theorem aFix_le (f : α → α) (hf : Monotone f)
|
||||
{a : α} (ha : a = f a) : aFix f hf ≤ a :=
|
||||
doStep_le f hf ha _ _ _ _ (by simpa using FiniteHeightLattice.bot_le α a)
|
||||
|
||||
Reference in New Issue
Block a user