Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Sequence reductions, introduce relations and costs for characteristic reconstruction

Definition
BodlaenderKloks_CharacteristicOperations

by Soh Kumabe · Nov 28, 2026 · Mathlib 0df444a (Lean v4.33.1)

algorithmsgraph-theorytreewidth

Sequence reductions and their normal forms describe the labels of a characteristic tree. The introduce relations specify how a fresh vertex changes that tree. The function tables and cost expressions give the interfaces for sequence processing, characteristic joins and applying an introduce plan along a path.

Definition code
import Definitions.Def_BodlaenderKloks_CharacteristicTables
import Definitions.Def_BodlaenderKloks_FunctionalMachine
import Definitions.Def_BodlaenderKloks_TreeDecompositionPrograms
import Definitions.Def_EdgeSublinearMWIS_Main_NativeSchemeInterfaces
import Definitions.Def_EdgeSublinearMWIS_Main_NativeWordRAM
import Definitions.Def_Lax228581_Treewidth
import Definitions.Def_Lax689794_GraphWords
import Mathlib.Algebra.BigOperators.Group.Finset.Sigma
import Mathlib.Algebra.BigOperators.Intervals
import Mathlib.Combinatorics.Enumerative.DoubleCounting
import Mathlib.Combinatorics.SimpleGraph.Acyclic
import Mathlib.Combinatorics.SimpleGraph.Connectivity.Connected
import Mathlib.Combinatorics.SimpleGraph.Maps
import Mathlib.Combinatorics.SimpleGraph.Metric
import Mathlib.Data.Finset.Card
import Mathlib.Data.Finset.Image
import Mathlib.Data.Finset.Option
import Mathlib.Data.Finset.Powerset
import Mathlib.Data.Finset.Sigma
import Mathlib.Data.Finset.Sort
import Mathlib.Data.Finset.Sum
import Mathlib.Data.Finset.Union
import Mathlib.Data.List.Basic
import Mathlib.Data.List.Dedup
import Mathlib.Data.List.Forall2
import Mathlib.Data.List.GetD
import Mathlib.Data.List.Induction
import Mathlib.Data.List.Sort
import Mathlib.Data.List.Sublists
import Mathlib.Data.Nat.Lattice
import Mathlib.Data.Set.Basic
import Mathlib.Data.Set.Card
import Mathlib.Logic.Relation
import Mathlib.Order.Interval.Finset.Nat
import Mathlib.Tactic

set_option autoImplicit false
set_option maxRecDepth 12000
set_option maxHeartbeats 3200000

-- Lax689794Proofs.Seq.Stack
section SourceModule3

/-! ### `Lax689794Proofs.Seq.Basic` -/

section

/-!
# Typical sequences (Bodlaender–Kloks, §3): the two reduction operations

Integer sequences are `List ℕ`.  This file defines the two operations of Def. 3.5
(remove a consecutive repetition; the *typical operation*) as one reduction step `Red`,
its reflexive-transitive closure `Reach`, the normal forms `NF` ("no operation possible
any more"), and an index view (`Dup`, `Win`) of the same notions.
-/

namespace Lax689794Proofs.Seq

/-- One reduction step (Def. 3.5): removal of a consecutive repetition, or the typical
operation (delete a non-empty interior all of whose entries lie between its two neighbours). -/
inductive Red : List ℕ → List ℕ → Prop
  | dup (l : List ℕ) (x : ℕ) (r : List ℕ) : Red (l ++ x :: x :: r) (l ++ x :: r)
  | typ (l : List ℕ) (x : ℕ) (m : List ℕ) (y : ℕ) (r : List ℕ) :
      m ≠ [] → (∀ z ∈ m, InR z x y) →
      Red (l ++ x :: (m ++ y :: r)) (l ++ x :: y :: r)

/-- No operation is possible any more. -/
def NF (a : List ℕ) : Prop := ∀ b, ¬ Red a b

/-! ### The index view -/

end Lax689794Proofs.Seq

end

/-! ### `Lax689794Proofs.Seq.Stack` -/

/-!
# The stack algorithm computing the typical sequence

`typical a` is a left fold of `push` over `a`; the intermediate state is always a normal
form.  `push t y` cuts the stack back to the *leftmost* index `i` whose entry `t_i` "sees"
the rest of the stack `t_{i+1}, …` inside the interval spanned by `t_i` and the new entry `y`,
and then appends `y`.
-/

/-! ### Entries of `t.take (i+1) ++ [y]` -/

/-! ### `push` preserves normal forms -/

/-! ### The fixed points of `push` -/

/-! ### Absorption: pushing an entry that the cut index of `y` already sees changes nothing -/

/-! ### Skipping a window -/

end SourceModule3

-- Lax689794Proofs.Chars.Defs
section SourceModule7

namespace Lax689794Proofs.Chars

open Lax689794Proofs.Seq Lax689794Proofs.Trees

/-! ## the characteristic trees -/

namespace CT

mutual
/-- Number of runs. -/
def count : CT → ℕ
  | node _ _ ks => 1 + countL ks
def countL : List CT → ℕ
  | [] => 0
  | k :: ks => count k + countL ks
end

/-! ### join -/

/-! ### introduce -/

/-! ### dominance -/

/-! ### well-formed characteristics -/

end CT

end Lax689794Proofs.Chars

/-! ## the characteristic of a real rooted decomposition -/

end SourceModule7

-- Lax689794Proofs.Seq.Concat
section SourceModule9

/-!
# Concatenation and splits (Lemmas 3.17–3.20, Def. 3.10)

Concatenation `∘ab` of the paper is `a ++ b`.
-/

namespace Lax689794Proofs.Seq

/-! ### Splits (Def. 3.10) -/

/-- The splits of the first type, as a finite set. -/
def splits1 (a : List ℕ) : Finset (List ℕ × List ℕ) :=
  (Finset.Icc 1 a.length).image (fun f => (a.take f, a.drop (f - 1)))

/-- The splits of the second type, as a finite set. -/
def splits2 (a : List ℕ) : Finset (List ℕ × List ℕ) :=
  (Finset.Ico 1 a.length).image (fun f => (a.take f, a.drop f))

/-- All splits of `a` (both types). -/
def splits (a : List ℕ) : Finset (List ℕ × List ℕ) := splits1 a ∪ splits2 a

/-! ### Lemma 3.20 -/

end Lax689794Proofs.Seq

end SourceModule9

-- Lax689794Proofs.Chars.NormGood
section SourceModule28

/-!
# `norm` produces well-formed characteristics (work package C1)

`good_norm : Loc B q → Conn q → Good B (norm q)` — `Loc` is the local part of `Good` that survives relabelling
(labels in `B`, typical non-empty sequences at least `|S|`); the remaining clauses of `Good` (no prunable leaf kid,
single kids change label, strict key order, leaf runs have one entry) are *produced* by `norm`.
`maxEntry_norm_le : maxEntry (norm q) ≤ maxEntry q`.
-/

set_option linter.unusedVariables false

namespace Lax689794Proofs.Chars

open Lax689794Proofs.Seq Lax689794Proofs.Trees

namespace CT

mutual
/-- The local shape invariants of `Good` that do not mention the kids' order or pruning. -/
def Loc (B : Finset ℕ) : CT → Prop
  | node S y ks => S ⊆ B ∧ typical y = y ∧ y ≠ [] ∧ (∀ e ∈ y, S.card ≤ e) ∧ LocL B ks
def LocL (B : Finset ℕ) : List CT → Prop
  | [] => True
  | k :: ks => Loc B k ∧ LocL B ks
end

/-! ## the largest entry -/

end CT

end Lax689794Proofs.Chars

end SourceModule28

-- Lax689794Proofs.Chars.IntroPlansMem
section SourceModule31

/-!
# The options of `introPlans`, as inductively described result sets (work package C4, part 3)

`introPlans v N t` enumerates triples `(path, plan, result)`; only the *results* matter for the exact and typical
layers.  Here the set of results is described by recursive propositions in terms of `Seq.splits` (the enumeration by
`Cut`s and `List.range`s is turned into membership in `splits`):

* `WinR v t r c` — `(r, c)` is the replacement subtree and covered vertex set of a region `W` containing the first
  tree node of the run `t` (`winPlans v 0 t`);
* `KidR v ks kids c` — per kid: leave it, or continue into it;
* `WtopR v t r c` — `W` has its topmost node inside the run (`wtopPlans v t`);
* `AttR v N t r` — a new branch hangs at a node of the run (`attachPlans v N t`);
* `IR v N t r` — the results of `introPlans v N t` (inductive family: at the run, or inside a kid).

`mem_introPlans : (∃ path plan, (path, plan, r) ∈ introPlans v N t) ↔ IR v N t r`.
-/

set_option linter.unusedVariables false

namespace Lax689794Proofs.Chars

open Lax689794Proofs.Seq Lax689794Proofs.Trees CT

/-! ## splits, with indices -/

/-! ## the descriptions -/

mutual
/-- `W` contains the first tree node of the run `t`: the results `(r, c)` of `winPlans v 0 t`. -/
def WinR (v : ℕ) : CT → CT → Finset ℕ → Prop
  | node S y ks, r, c =>
    (∃ d1 d2, (d1, d2) ∈ splits y ∧ r = node (insert v S) (plus1 d1) [node S d2 ks] ∧ c = S) ∨
    (∃ kids cv, KidR v ks kids cv ∧ r = node (insert v S) (plus1 y) kids ∧ c = S ∪ cv)
/-- Per kid: leave it (covering nothing) or let `W` continue into it. -/
def KidR (v : ℕ) : List CT → List CT → Finset ℕ → Prop
  | [], kids, c => kids = [] ∧ c = ∅
  | k :: ks, kids, c => ∃ k' kids' c1 c2, kids = k' :: kids' ∧ c = c1 ∪ c2 ∧
      ((k' = k ∧ c1 = ∅) ∨ WinR v k k' c1) ∧ KidR v ks kids' c2
end

/-- `W`'s topmost node lies inside the run (`wtopPlans`). -/
def WtopR (v : ℕ) : CT → CT → Finset ℕ → Prop
  | node S y ks, r, c => WinR v (node S y ks) r c ∨
      ∃ d1 d2 X, (d1, d2) ∈ splits y ∧ WinR v (node S d2 ks) X c ∧ r = node S d1 [X]

/-- A new branch hangs at a node of the run (`attachPlans`). -/
def AttR (v : ℕ) (N : Finset ℕ) : CT → CT → Prop
  | node S y ks, r => ∃ chain M, (chain, M) ∈ allChains S N ∧
      (r = node S y (ks ++ [pathSubtree v chain M]) ∨
       ∃ d1 d2, (d1, d2) ∈ splits y ∧ r = node S d1 [pathSubtree v chain M, node S d2 ks])

/-- The results of `introPlans v N t`. -/
inductive IR (v : ℕ) (N : Finset ℕ) : CT → CT → Prop
  | top {S : Finset ℕ} {y : List ℕ} {ks : List CT} {r : CT} {c : Finset ℕ} :
      WtopR v (node S y ks) r c → N ⊆ c → IR v N (node S y ks) r
  | att {S : Finset ℕ} {y : List ℕ} {ks : List CT} {r : CT} :
      N ⊆ S → AttR v N (node S y ks) r → IR v N (node S y ks) r
  | kid {S : Finset ℕ} {y : List ℕ} {pre : List CT} {k : CT} {post : List CT} {r' : CT} :
      IR v N k r' → IR v N (node S y (pre ++ k :: post)) (node S y (pre ++ r' :: post))

/-! ## `winPlans` and `kidChoices` -/

/-! ## `wtopPlans` and `attachPlans` -/

/-! ## `introPlans` -/

end Lax689794Proofs.Chars

end SourceModule31

-- Lax689794Proofs.Fun.E1Seq
section SourceModule51

/-!
# E1 (layer A): the typical-sequence stack algorithm and `domB` as F-functions

Ids `128 …`.  `inR`, `allInR`, `cut`, `push`, `typical`, `domB` (the lattice-path recursion, exponential in the length
exactly as the Lean function).
-/

set_option linter.unusedSectionVars false

set_option linter.unusedTactic false

set_option linter.unreachableTactic false

namespace Lax689794Proofs.Fun

namespace E1A

open ToVal Lib1 Lax689794Proofs.Seq

/-- layer A of the E1 table -/
def Δ : ℕ → Option Tm := layerΔ Lib.Δ 128 tbl

end E1A

end Lax689794Proofs.Fun

end SourceModule51

-- Lax689794Proofs.Size.Alph
section SourceModule52

/-!
# Size bounds (P1), part 1: counting trees by their number of runs

`CountCard` counts the well-formed characteristics via the bracket word `enc`; the count there uses the global bound
`count ≤ runBound |B|`.  Here the same injection is used with an arbitrary bound `m` on the number of runs and *no*
`Wf`/`Conn` hypothesis (only `Good B`, `maxEntry ≤ kmax`): the number of such trees is at most
`(2^{2b+2kmax+4})^{2m}` (`ncard_good_le`), and any duplicate-free list of them has at most `cbound b kmax m` elements.
This is what bounds `joinKids` (whose kids are *not* `Wf B`, but are `Good B`).
-/

namespace Lax689794Proofs.Chars

open Lax689794Proofs.Seq Lax689794Proofs.Trees CT

/-- `2^{(2b+2kmax+4)·2m}`: the crude bound on the number of `Good B` trees with entries `≤ kmax` and `≤ m` runs. -/
def cbound (b kmax m : ℕ) : ℕ := 2 ^ ((2 * b + 2 * kmax + 4) * (2 * m))

/-! ## list-length helpers -/

end Lax689794Proofs.Chars

end SourceModule52

-- Lax689794Proofs.Fun.E1
section SourceModule55

/-! ### `Lax689794Proofs.Fun.E1Wit` -/

section

/-!
# E1 (layer B): `witnesses` (the witness positions of the typical sequence)

Ids `137 …`: `allInRP`, `wpush`, `witnessesAux`, `sndF`, `witnesses`.
-/

set_option linter.unusedSectionVars false

set_option linter.unusedTactic false

set_option linter.unreachableTactic false

namespace Lax689794Proofs.Fun

namespace E1B

open ToVal Lib1 Lax689794Proofs.Seq Lax689794Proofs.Chars E1A

/-- layer B of the E1 table -/
def Δ : ℕ → Option Tm := layerΔ E1A.Δ 137 tbl

end E1B

end Lax689794Proofs.Fun

end

/-! ### `Lax689794Proofs.Fun.E1Lat` -/

section

/-!
# E1 (layer C): the lattice dynamic programme `latticeStates` / `ringTypList`

Ids `142 …`.  The functions are the Lean ones (`dedupKey`, `cellOf`, `rowCells`, `latticeRows`, `latticeStates`,
`ringTypList`); the cost is stated in terms of the bounds `4^(L₁+L₂+1)` (number of states of a cell,
`Size/Lattice.lean`) and `2(L₁+L₂)+1` (length of a state's typical sequence), `L₁, L₂` bounding the entries of `a`, `b`.
-/

set_option linter.unusedSectionVars false

set_option linter.unusedTactic false

set_option linter.unreachableTactic false

namespace Lax689794Proofs.Fun

namespace E1C

open ToVal Lib1 Lax689794Proofs.Seq Lax689794Proofs.Chars Lax689794Proofs.Chars.CT E1A E1B

/-- layer C of the E1 table -/
def Δ : ℕ → Option Tm := layerΔ E1B.Δ 142 tbl

/-! ### the size bounds of the cells of the DP (from `Size/Lattice.lean`) -/

end E1C

end Lax689794Proofs.Fun

end

/-! ### `Lax689794Proofs.Fun.E1Path` -/

section

/-!
# E1 (layer D): `findPath`

Ids `154 …`: `subC`, `predDom`, `findPath`, and the pair-argument form `findPathP`.
`findPath sa sb c want` = the first state of `latticeStates sa sb` (in DP order) whose `τ`-sum, minus `c`, is dominated by
`want` (`domB`), returning its lattice path.  Cost: the lattice DP plus (number of states) × (a `domB` run, exponential in
the length of the state's sequence plus `|want|`, exactly as in Lean).
-/

set_option linter.unusedSectionVars false

set_option linter.unusedTactic false

set_option linter.unreachableTactic false

namespace Lax689794Proofs.Fun

namespace E1D

open ToVal Lib1 Lax689794Proofs.Seq Lax689794Proofs.Chars Lax689794Proofs.Chars.CT E1A E1B E1C

/-- layer D (= the whole E1 table, ids `128 … 157`) -/
def Δ : ℕ → Option Tm := layerΔ E1C.Δ 154 tbl

end E1D

end Lax689794Proofs.Fun

end

/-! ### `Lax689794Proofs.Fun.E1` -/

/-!
# E1: the table `e1Tbl` (ids `128 … 157`) and the `Embeds` statements of the sequence layer

`e1Tbl : ℕ → Option Tm` has the functions of layers A–D of `E1Seq / E1Wit / E1Lat / E1Path`;
`e1Δ = Lib.extend e1Tbl = layerΔ Lib.Δ 128 e1Tbl`.  Every `Runs`/`Embeds` theorem of E1 is stated for an arbitrary
extension `Δ'` of the layer table of the file it lives in; `E1.ext : E1D.Δ ⊑ e1Δ` (and hence, by `Ext.trans`, every
layer's table is contained in `e1Δ` and in any larger assembly `layerΔ Lib.Δ 128 (orElseΔ e1Tbl …)`, see
`E1.ext_orElse_left`).

| function | id | file | `Runs` lemma (cost) | unary `Embeds` |
|---|---|---|---|---|
| `Seq.typical` | `fTypical = 134` | `E1Seq` | `typical_runs` `110 (n+1)^3` | `embeds_typical`, `embeds_typical_os` (`osCost 3`) |
| `Seq.cut`, `Seq.push` | `130`, `131` (`132`: `foldl` convention) | `E1Seq` | `cut_runs` `60 (n+1)^2`, `push_runs` `80 (n+1)^2` | — |
| `Seq.domB` | `fDomB = 135` (`fDomBP = 136`, pair) | `E1Seq` | `domB_runs` `60·3^(|a|+|b|)` (exponential, as the Lean recursion) | `embeds_domB` |
| `Chars.witnesses` (`wpush`, `witnessesAux`) | `fWitnesses = 141` (`138`, `139`) | `E1Wit` | `witnesses_runs` `150 (n+1)^3` | `embeds_witnesses`, `_os` |
| `Chars.dedupKey`, `cellOf`, `rowCells`, `latticeRows` | `144, 146, 147, 148` | `E1Lat` | `dedupKey_runs`, `cellOf_runs`, `rowCells_runs`, `latRows_runs` | — |
| `Chars.latticeStates` | `fLatticeStates = 150` | `E1Lat` | `latticeStates_runs` | — |
| `CT.ringTypList` | `fRingTypList = 152` (`fRingTypListP = 153`, pair) | `E1Lat` | `ringTypList_runs` `6000 (|a|+1)(|b|+1)(4^(L₁+L₂+1)+1)^2 (2(L₁+L₂)+3)^2`, entries `≤ L₁, L₂` | `embeds_ringTypList` (`ringCost`, `L = maxOf`) |
| `Chars.findPath` | `fFindPath = 156` (`fFindPathP = 157`, 4-tuple) | `E1Path` | `findPath_runs` (lattice DP + `4^(L+1)` many `domB`s) | `embeds_findPath` (`findPathCost`) |
-/

/-! ### the statements for the assembled table `e1Δ` (use `Embeds.ext` to pass to a larger table) -/

end SourceModule55

-- Lax689794Proofs.Fun.E2
section SourceModule68

/-! ### `Lax689794Proofs.Fun.E2Defs` -/

/-!
# E2: the table `e2Tbl` (ids `160 … 255`) — `norm`, `forgetC`, `joinC`, `domCB` as F-functions

Ids:

| id | function | arguments |
|---|---|---|
| 160 `fVerts` | `CT.verts` | `[c]` |
| 161 `fVertsL` | `CT.vertsL` | `[ks]` |
| 162 `fKeyLe` | `decide (key S a ≤ key S b)` | `[S, a, b]` |
| 163 `fSortKids` | `CT.sortKids` | `[S, ks]` |
| 164 `fKeep` | `CT.keep` | `[S, k]` |
| 165 `fNormNode` | `CT.normF`-shaped `normNode` on the *filtered/normalised* kids | `[S, y, ks]` |
| 166 `fNorm` | `CT.norm` | `[c]` |
| 167 `fNormC` | `norm` with a dummy context (calling convention of `map`) | `[ctx, c]` |
| 168 `fRelE` | `CT.relabel (·.erase x)` (also usable as a `map` callee) | `[x, c]` |
| 169 `fForgetC` | `CT.forgetC` | `[x, c]` |
| 170 `fSubC` | `e - c` (`map` callee) | `[c, e]` |
| 171 `fSubMap` | `d.map (· - c)` (`map` callee) | `[c, d]` |
| 172 `fLeK` | `decide (e ≤ kmax)` | `[kmax, e]` |
| 173 `fAllLe` | `d.all (· ≤ kmax)` | `[kmax, d]` |
| 174 `fJoinYs` | the list `ys` of `joinC` | `[S, kmax, y, y']` |
| 175 `fMkNode` | `node S d kk` (`map` callee, context `(S, kk)`) | `[(S, kk), d]` |
| 176 `fMapKK` | `ys.map (node S · kk)` (`flatMap` callee, context `(S, ys)`) | `[(S, ys), kk]` |
| 177 `fJoinC` | `CT.joinC` | `[kmax, a, b]` |
| 178 `fJoinKids` | `CT.joinKids` | `[kmax, ks, ks']` |
| 179 `fConsTo` | `c :: l` | `[c, l]` |
| 180 `fConsAll` | `rest.map (c :: ·)` (`flatMap` callee, context `rest`) | `[rest, c]` |
| 181 `fDomC` | `CT.domCB` | `[a, b]` |
| 182 `fDomCL` | `CT.domCBL` | `[ks, ks']` |

The function `ringTypList` (E1) is called through an id `rid` that the assembler chooses (`e2Tbl rid`).
-/

/-! ### `Lax689794Proofs.Fun.E2Base` -/

/-!
# arithmetic of tree recursions, size lemmas, `verts`, `keyLe`, `sortKids`

* `wt c = 2·count c - 1`; `tree_step` : the potential argument that turns a per-node cost `C·(m+1)·s^e`
  (`m` = number of kids) into the whole-tree bound `C·wt c·s^e ≤ 2C·count·s^e`;
* `card_verts_le : |verts c| ≤ sz c`, `sz_relE_le`, `sz_norm_le`;
* `verts_runs`, `keyLe_runs`, `sortKids_runs`.
-/

/-! ## potentials -/

/-! ## sizes -/

/-! ## `Ext` plumbing -/

/-! ## `verts` -/

/-! ## `keyLe`, `sortKids` -/

/-! ### `Lax689794Proofs.Fun.E2Sz` -/

/-!
# sizes never grow under `norm`, `relabel (erase ·)`, `filter`, `sort`, `typical`

`sz_norm_le : sz (norm c) ≤ sz c` and the same for `forgetC`.  These make the cost of `norm` and `forgetC` bounds in terms of
the *input* size only.
-/

/-! ### `Lax689794Proofs.Fun.E2Norm` -/

/-!
# `keep`, `normNode`, `norm` as F-functions

* `keep_runs`, `normNode_runs` (cost `3000 (m+1) (s+1)^4`, `m` = number of kids);
* `norm_runs_aux` : `Runs fNorm [toVal c] (toVal (norm c)) (3100 · wt c · (sz c + 1)^4)`, `wt c = 2 count c - 1`
  (the per-node local cost is charged through the potential `tree_step` of `E2Base`);
* `norm_runs` : cost `6200 (s + 1)^5` for `sz c ≤ s`, hypothesis `14000 (s+1)^5 < B`.
-/

/-! ### `Lax689794Proofs.Fun.E2Forget` -/

/-!
# `forgetC` as an F-function

`relE x c = relabel (·.erase x) c` (id 168, also the `map` callee of its own recursion) and `forgetC x c = norm (relE x c)`.
Cost `≤ 7000 (s + 1)^5` for `sz c ≤ s`.
-/

/-! ### `Lax689794Proofs.Fun.E2Join1` -/

/-!
# `joinC`, part 1 — Lean-level facts and the helpers (`subMap`, `allLe`, `joinYs`, `mapKK`, `consAll`)

Notation: `xb nb k = cbound nb k 1 = 2^(4(nb+k+2))` (so `cbound nb k m = (xb nb k)^m`);  `4^(2k+1) ≤ xb`, `k+1 ≤ xb`, `256 ≤ xb`.
-/

/-! ## Lean-level facts -/

/-! ## `Runs` helpers -/

/-! ### `Lax689794Proofs.Fun.E2Join2` -/

/-!
# `joinC` and `joinKids` as F-functions

Cost of `joinC kmax a b` for `Good B0 a`, `Good B0 b`, entries `≤ kmax`, `sz ≤ s`:

    Hb X R0 s a = 8000 (s+1) (X^3)^(count a) + count a · R0,     X = cbound |B0| kmax 1 = 2^(4(|B0|+kmax+2)),

where `R0` bounds the cost of one call of `ringTypList` on entries `≤ kmax` and length `≤ 2 kmax + 1`.
-/

/-! ### `Lax689794Proofs.Fun.E2Dom` -/

/-!
# `domCB` as an F-function (used by `realIntro` / `realJoin`)

`domCB a b` (`DomC`-decision).  Cost `C · wt a` with `C = 60·3^(2L) + 60 s + 300` when every run sequence of `a`, `b` has length `≤ L`
(`CT.RB s L`) and `sz ≤ s`; the exponential factor is `E1A.domB`'s (`60·3^(|y|+|y'|)`, as the Lean recursion).
-/

/-! ### `Lax689794Proofs.Fun.E2` -/

section

/-!
# E2: the assembled interface — table `e2Tbl` (ids 160…182), concrete cost bounds with the E1 functions

`e2Tbl rid` (E2Defs) has the E2 functions; `rid` is the id of `ringTypList` in the assembled table.  With E1's table
(`E1.e1Tbl`, ids `128 … 157`, `ringTypList` at `E1C.fRingTypList = 152`) the combined table is `e12Tbl`.

**How the assembler uses this.**  Every theorem below is stated for an arbitrary table `Δ'` with `hΔ : e2Δ 152 ⊑ Δ'` and
`hE1 : E1.e1Δ ⊑ Δ'` (for the assembly `layerΔ Lib.Δ 128 (orElseΔ e1Tbl (orElseΔ (e2Tbl 152) e3Tbl))`, obtain both by
`Ext.layer_mono (Ext.orElse_left …)` / `Ext.layer_mono (Ext.orElse_right (disj) …)`; `e2Tbl_disj_e1` is the disjointness fact).
The ids are `E2.fNorm = 166`, `E2.fForgetC = 169`, `E2.fJoinC = 177`, `E2.fJoinKids = 178`, `E2.fDomC = 181`, `E2.fKeyLe`, `E2.fSortKids`, `E2.fVerts`.

| Lean function | id | arguments | theorem | cost |
|---|---|---|---|---|
| `CT.norm` | `fNorm` | `[c]` | `norm_runs_e12` | `6200 (s+1)^5`, `sz c ≤ s` |
| `CT.forgetC` | `fForgetC` | `[x, c]` | `forgetC_runs_e12` | `7000 (s+1)^5` |
| `CT.joinC` | `fJoinC` | `[kmax, a, b]` | `joinC_runs_e12` | `14000 (s+1) 2^(48 (|B|+kmax+2)^3)` for `Wf B kmax a, b`, `sz ≤ s` |
| `CT.domCB` | `fDomC` | `[a, b]` | `domC_runs_e12` | `(30 s + 60·3^(2L) + 100)·2 count a`, run sequences `≤ L` |
-/

set_option linter.unusedSectionVars false

set_option linter.unusedTactic false

set_option linter.unreachableTactic false

set_option linter.unusedSimpArgs false

namespace Lax689794Proofs.Fun

namespace E2

open ToVal Lax689794Proofs.Chars Lax689794Proofs.Trees CT Lib1 Lax689794Proofs.Seq

/-! ## the interface with `ringTypList` -/

/-- the cost of one call of `ringTypList` on run sequences with entries `≤ k` and length `≤ 2k + 1` -/
def R0k (k : ℕ) : ℕ := 6000 * (2 * k + 2) ^ 2 * (4 ^ (2 * k + 1) + 1) ^ 2 * (4 * k + 3) ^ 2

/-! ## the pure-arithmetic bound on the `ringTypList` contribution -/

/-! ## the concrete statements -/

/-! ### the `Fits` forms: the hypothesis on `B` is `(cost + 2)^2 < B` (what `Fits B v cost` provides) -/

end E2

end Lax689794Proofs.Fun

end

end SourceModule68

-- Lax689794Proofs.Fun.E5Inst
section SourceModule73

/-! ### `Lax689794Proofs.Fun.E5Util` -/

/-!
# generic arithmetic and size lemmas used by the E5 layers

* sums of per-element costs (`sum_map_le_mul`, `sum_map_const`);
* `sz` of `take / drop / filter / map / append / perm` of lists;
* powers `t ^ d` of `t = s + 1` as atoms (`pw_le`).
-/

/-! ## sums -/

/-! ## powers of `t = s + 1` -/

/-! ## sizes of list operations -/

/-! ## `typical` does not lengthen -/

/-! ## reaching the library / E1 from an extension of `e1Δ` -/

/-! ### `Lax689794Proofs.Fun.E5Ext` -/

/-!
# the external functions E5 calls, as hypotheses

`E5` embeds `analyze … realJoin`; these call functions owned by other work packages:

| function | owner | id | shape of the hypothesis |
|---|---|---|---|
| `CT.norm` | E2 | `166` (`E5.idNorm`) | `Ext5.norm` : `Runs` for `sz c ≤ s`, cost `cNorm s`, plus `sz (norm c) ≤ sz c` |
| `decide (CT.key S a ≤ CT.key S b)` | E2 | `162` (`E5.idKeyLe`) | `Ext5.keyLe` |
| `CT.domCB` | E2 | `181` (`E5.idDomC`) | `Ext5.domC` (precondition `Ext5.PD`) |
| `CT.joinC` | E2 | `177` (`E5.idJoinC`) | `ExtJ` (precondition `PJ`, cost `cJ`) |
| `CT.introPlans` | E3 | passed at run time (first argument of `realIntro`) | `ExtIP` (precondition `PIP`, cost `cIP`) |

The E2 ids are those of the docstring table of `Fun/E2Defs.lean` (contract: the assembler must use them, or re-point
`E5.idNorm …`).  Every hypothesis has the same shape as the corresponding `E2`/`E3` theorem
(`E2.norm_runs`, `E2.keyLe_runs`, …): *for every `B` above the cost, the function runs within the cost*.  The cost functions
are abstract (`ℕ → ℕ` in the size bound `s`), so nothing here depends on the constants of E2/E3.
-/

/-! ### `Lax689794Proofs.Fun.E5A` -/

/-!
# E5 (layer A): small helpers, `AR.char`, `AR.toRT`, `RT.prof`, `RT.char`

Ids `448 …`:

| id | function | arguments |
|---|---|---|
| 448 `fNthD` | `List.getD` | `[xs, i, d]` |
| 449 `fCards` | `ns.map (·.bag.card)` | `[ns]` |
| 450 `fCharAR` | `AR.char` | `[r]` |
| 451 `fCharARL` | `AR.charL` | `[ks]` |
| 452 `fChainToRT` | `AR.chainToRT` | `[ns, ks]` |
| 453 `fToRT` | `AR.toRT` | `[r]` |
| 454 `fToRTL` | `AR.toRTL` | `[ks]` |
| 455 `fProf` | `RT.prof B t` | `[B, t]` |
| 456 `fProfL` | `RT.profL B ks` | `[B, ks]` |
| 457 `fChar` | `RT.char B t` (calls `norm`, id `E5.idNorm`) | `[B, t]` |

Cost shape: every function has cost `κ · (#nodes) · (s+1)^d` where `s` bounds the sizes of the arguments.
-/

/-! ## the terms -/

/-! ## counting runs of an analysis -/

/-! ## the lemmas -/

/-! ### `Lax689794Proofs.Fun.E5B` -/

/-!
# E5 (layer B): `sortAR`, `analyzeNode`, `analyze`

Ids `460 …`:

| id | function | arguments |
|---|---|---|
| 460 `fKeyLeAR` | `decide (key S a.char ≤ key S b.char)` (comparison of `sortAR`) | `[S, a, b]` |
| 461 `fSortAR` | `sortAR` | `[S, ks]` |
| 462 `fPruned` | the predicate `p.2.isLeaf && decide (p.2.S ⊆ S)` | `[S, p]` |
| 463 `fNotPruned` | its negation | `[S, p]` |
| 464 `fFstP` / 465 `fSndP` | `p.1` / `p.2` (`map` callees) | `[_, p]` |
| 466 `fAnalyzeNode` | `analyzeNode` | `[Bd, X, kids]` |
| 467 `fAnalyze` | `analyze` | `[Bd, t]` |
| 468 `fAnalyzeL` | `analyzeL` | `[Bd, ks]` |

The recursion of `analyze` is charged per node: `Runs … fAnalyze … (cA E s · t.size)`.
-/

/-! ## sizes -/

/-! ## the comparison and the sort -/

/-! ### `Lax689794Proofs.Fun.E5C1` -/

/-!
# E5 (layer C1): chain surgery — `dupAfter`, `cutAt`, `addV`, `addJunk`, `branchRT`

Ids `470 …`:

| id | function | arguments |
|---|---|---|
| 470 `fDupAfter` | `dupAfter` | `[i, ns]` |
| 471 `fCutAt` | `cutAt` | `[y, w, c, ns]` |
| 472 `fInRng` | `decide (s ≤ i) && e.elim true (fun e => decide (i ≤ e))` | `[s, e, i]` |
| 473 `fAddVAux` | `addV` with a running index (`addVL`) | `[v, s, e, i, ns]` |
| 474 `fAddV` | `addV` | `[v, s, e, ns]` |
| 475 `fAddJunkAux` | `addJunk` with a running index (`addJunkL`) | `[x, br, i, ns]` |
| 476 `fAddJunk` | `addJunk` | `[x, br, ns]` |
| 477 `fBranchRT` | `branchRT` | `[v, chain, M]` |
| 478 `fNxt` | `l.getD (f + 1) 0`, computed by `drop` (no arithmetic on `f`) | `[f, l]` |

The Lean `mapIdx` is replaced by the recursion with a running index (`addVL`, `addJunkL`; `addV_eq`, `addJunk_eq`).
-/

/-! ## the Lean side: `addV`, `addJunk` with a running index -/

/-! ## the terms -/

/-! ## sizes -/

/-! ## the lemmas -/

/-! ### `Lax689794Proofs.Fun.E5C2` -/

section

/-!
# E5 (layer C2): `processRun`, `applyKids`, `applyOpt`

Ids `480 …`:

| id | function | arguments |
|---|---|---|
| 480 `fMapP1` | `Option.map (· + 1)` | `[o]` |
| 481 `fEndStep` | the `endStep` of `processRun` | `[y, wp, w, ns]` |
| 482 `fPreStep` | the `preStep` of `processRun` | `[y, wp, pre, endS]` |
| 483 `fProcessRun` | `processRun` | `[v, pre, w, r]` |
| 484 `fApplyKids` | `applyKids` | `[v, ps, ks]` |
| 485 `fApplyOpt` | `applyOpt` | `[v, p, k]` |

The Lean `let`/`match` of `processRun` is exposed as `endStepL`, `preStepL` (`processRun_eq`).
Cost: `cPR s · wn w` where `wn` counts the nodes of the region plan.
-/

set_option linter.unusedSectionVars false

set_option linter.unusedTactic false

set_option linter.unreachableTactic false

set_option linter.unusedSimpArgs false

set_option maxRecDepth 100000

namespace Lax689794Proofs.Fun

namespace E5C2

open ToVal Lib1 Lax689794Proofs.Chars Lax689794Proofs.Trees E5 E5A E5C1

/-! ## the Lean side -/

def endStepL (y wp : List ℕ) (w : CT.WPlan) (ns : List CNode) : List CNode × Option ℕ :=
  match w with
  | .endAt c => ((cutAt y wp c ns).1, some (cutAt y wp c ns).2)
  | .whole _ => (ns, none)

/-! ## the terms -/

/-! ## witnesses are small -/

/-! ## sizes of the steps -/

/-! ## region plans: size measure -/

mutual
def wn : CT.WPlan → ℕ
  | .endAt _ => 1
  | .whole ps => 1 + wnL ps
def wnL : List (Option CT.WPlan) → ℕ
  | [] => 0
  | p :: ps => wnO p + wnL ps
def wnO : Option CT.WPlan → ℕ
  | none => 1
  | some p => wn p
end

/-- the local cost bound of `processRun` -/
def cPR (s : ℕ) : ℕ := 3000 * (s + 1) ^ 3

/-! ## sizes of the results -/

/-! ## the lemmas -/

end E5C2

end Lax689794Proofs.Fun

end

/-! ### `Lax689794Proofs.Fun.E5C3` -/

section

/-!
# E5 (layer C3): `applyAt`, `applyRun`, `applyPlan`

Ids `490 …`:

| id | function | arguments |
|---|---|---|
| 490 `fAttCut` | the cut of `applyAt` for an attach plan | `[y, wp, c, ns]` |
| 491 `fApplyAt` | `applyAt` | `[v, p, r]` |
| 492 `fModifyRun` | `modifyNth (applyRun v p rest) i` | `[v, p, rest, i, ks]` |
| 493 `fApplyRun` | `applyRun` | `[v, p, path, r]` |
| 494 `fApplyPlan` | `applyPlan` | `[v, N, Bd, path, p, t]` |

`applyPlan v N Bd path p t = (applyRun v p path (analyze Bd t)).toRT`.
-/

set_option linter.unusedSectionVars false

set_option linter.unusedTactic false

set_option linter.unreachableTactic false

set_option linter.unusedSimpArgs false

set_option maxRecDepth 100000

namespace Lax689794Proofs.Fun

namespace E5C3

open ToVal Lib1 Lax689794Proofs.Chars Lax689794Proofs.Trees E5 E5A E5C1 E5C2

/-! ## the Lean side -/

/-- weight of a plan -/
def wnP : CT.Plan → ℕ
  | .att _ _ _ => 1
  | .top _ w => wn w

/-- local cost of `applyAt` -/
def cAA (s : ℕ) (p : CT.Plan) : ℕ := cPR s * wnP p + 100 * (sz p + 1)

/-! ## the terms -/

/-! ## sizes -/

/-! ## the lemmas -/

end E5C3

end Lax689794Proofs.Fun

end

/-! ### `Lax689794Proofs.Fun.E5R` -/

/-!
# E5 (layer R): `realIntro`

Ids `500 …`:

| id | function | arguments |
|---|---|---|
| 500 `fEntLeY` | `decide (y.foldr max 0 ≤ kmax)` | `[kmax, y]` |
| 501 `fEntLeL` | `decide (CT.maxEntryL ks ≤ kmax)` | `[kmax, ks]` |
| 502 `fEntLe` | `decide (c.maxEntry ≤ kmax)` | `[kmax, c]` |
| 503 `fPredIntro` | the predicate of `realIntro`'s `find?` (context `(target, kmax)`) | `[ctx, r]` |
| 504 `fRealIntro` | `realIntro` (the id of `introPlans` is the first argument) | `[ip, kmax, v, N, Bd, t, target]` |
-/

/-! ## the terms -/

/-! ## `maxEntry ≤ kmax` -/

/-! ### `Lax689794Proofs.Fun.E5D` -/

/-!
# E5 (layer D): `mergeChain`, `mergeAR`, `mergeKids`, `mergeReal`, `realJoin`

Ids `520 …`:

| id | function | arguments |
|---|---|---|
| 520 `fMergeChain` | `mergeChain` | `[na, nb, prev, path]` |
| 521 `fMergeAR` | `mergeAR` | `[a, b, target]` |
| 522 `fMergeKids` | `mergeKids` | `[ka, kb, tk]` |
| 523 `fMergeReal` | `mergeReal` | `[Bd, ta, tb, target]` |
| 524 `fPredJoin` | the predicate `fun d => domCB d target` of `realJoin` (context `target`) | `[target, d]` |
| 525 `fRealJoin` | `realJoin` | `[kmax, Bd, ta, tb, target]` |
| 526 `fFlagI` / 527 `fFlagJ` | the "first visit" flags of `mergeChain` | `[prev, i]` / `[prev, j]` |

The lattice path search is E1's `findPath` (id `E1D.fFindPath = 156`).
-/

/-! ## the Lean side -/

/-! ## the terms -/

/-! ## sizes -/

/-! ## size of the merged analysis -/

/-! ## chain cardinalities and the cost constants -/

/-! ## the lemmas -/

/-! ### `Lax689794Proofs.Fun.E5W` -/

/-!
# E5 (layer W): tuple-argument wrappers and the `Embeds` statements

Ids `530 …` (the functions of `Embeds` take *one* argument, the tuple):

| id | wrapper of | argument tuple |
|---|---|---|
| 530 `fAnalyzeP` | `analyze` | `(Bd, t)` |
| 531 `fCutAtP` | `cutAt` | `(y, w, c, ns)` |
| 532 `fApplyPlanP` | `applyPlan` | `(v, N, Bd, path, p, t)` |
| 533 `fMergeRealP` | `mergeReal` | `(Bd, ta, tb, target)` |
| 534 `fRealIntroP` | `realIntro` | `(ip, kmax, v, N, Bd, t, target)` (`ip` = id of `introPlans`) |
| 535 `fRealJoinP` | `realJoin` | `(kmax, Bd, ta, tb, target)` |

Tuples are right-nested pairs, `(a, b, c) = (a, (b, c))`.  Every `embeds_*` theorem is stated for an arbitrary table
`Δ'` extending `E5W.Δ` (equivalently `e5Δ`, see `E5Tbl`) and the hypothesis records `Ext5` (norm, key, domC),
`ExtIP` (introPlans), `ExtJ` (joinC), which the assembler instantiates by the theorems of WPs E2/E3.
The costs are `κ · (S+1)^d`-shaped in the size `S` of the argument (and, for `realIntro`/`realJoin`, of the list of plans/join
options), plus the symbolic costs of the external functions; see the docstrings.
-/

/-! ## the terms -/

/-! ## costs -/

/-! ## the `Embeds` statements -/

/-! ### `Lax689794Proofs.Fun.E5Tbl` -/

/-!
# E5: the table `e5Tbl` (ids `448 … 535`) and its assembly

`e5Tbl : ℕ → Option Tm` is the union of the layer tables `E5A … E5W` (disjoint ids), `e5Δ = layerΔ e1Δ 448 e5Tbl`
(the E1 functions are contained in it: E5 calls `typical`, `witnesses`, `findPath`).  `E5W.Δ = e5Δ` (`e5_eq`).

**How the assembler uses it.**  Let `T` be the assembled table (`layerΔ Lib.Δ 128 T` the assembled Δ).  If `e1Tbl ⊑ T` and
`e5Tbl ⊑ T` then `e5Δ ⊑ layerΔ Lib.Δ 128 T` (`ext_asm`; `ext_orElse_left/right` for the two usual shapes of `T`), and every
theorem `embeds_* : … Δ' …` of `E5W`, stated for `Δ' ⊒ E5W.Δ`, applies to `Δ' := layerΔ Lib.Δ 128 T`.  External functions:
`CT.norm` (id `E5.idNorm = 166`), `decide (key S a ≤ key S b)` (`E5.idKeyLe = 162`), `CT.domCB` (`E5.idDomC = 181`),
`CT.joinC` (`E5.idJoinC = 177`) come from E2, `CT.introPlans` from E3 (its id is `ExtIP.ip`); they are hypotheses
(`Ext5`, `ExtJ`, `ExtIP` of `E5Ext`).
-/

/-! ### `Lax689794Proofs.Fun.E5Inst` -/

/-!
# E5: discharging the external hypotheses from the theorems of E2 and E3

`E5Ext` states what E5 needs from `norm`, `key`, `domCB`, `joinC` (E2) and `introPlans` (E3) as hypothesis records.  Here they
are *instantiated* by the proved theorems `E2.norm_runs_e12`, `E2.keyLe_runs`, `E2.domC_runs_e12`, `E2.joinC_runs_e12`,
`E3C.introPlans_runs` (with abstract costs equal to the thresholds of those theorems, so that the `Runs` facts are
`Runs.mono`-weakened).  Nothing of E5 depends on this file: it is the glue for the assembler.

* `ext5_e2 L` : `Ext5 Δ'` for every `Δ'` containing `e2Δ 152` and `e1Δ`; `Ext5.PD s a b := RB s L a ∧ RB s L b`
  (run sequences of length `≤ L`).
* `extJ_e2` : `ExtJ Δ'` (`PJ kmax a b := ∃ B0, a.Wf B0 kmax ∧ b.Wf B0 kmax`).
* `extIP_e3 …` : `ExtIP Δ'` (`ip = 325`) from `E3C.introPlans_runs`, for the parameters of that theorem.
-/

/-! ## a worked assembly: E1 + E2 + E3 + E5 -/

end SourceModule73

/-
Source attribution
The treewidth algorithm and its correctness proof are from yuvalyitz/treewidth-lax, commit b6743cf02087f552d8f023581f4718e68c42e444. The word-RAM semantics are from lax-archive/lax-submissions, commit 9394e531cc51cb67a0214bca3f9264dfe97ba5c7, word-ram/. The local streaming header and uniform output bounds extend these sources. Project-local proof tactics have been expanded into ordinary Lean proof steps.


                                 Apache License
                           Version 2.0, January 2004
                        http://www.apache.org/licenses/

   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

   1. Definitions.

      "License" shall mean the terms and conditions for use, reproduction,
      and distribution as defined by Sections 1 through 9 of this document.

      "Licensor" shall mean the copyright owner or entity authorized by
      the copyright owner that is granting the License.

      "Legal Entity" shall mean the union of the acting entity and all
      other entities that control, are controlled by, or are under common
      control with that entity. For the purposes of this definition,
      "control" means (i) the power, direct or indirect, to cause the
      direction or management of such entity, whether by contract or
      otherwise, or (ii) ownership of fifty percent (50%) or more of the
      outstanding shares, or (iii) beneficial ownership of such entity.

      "You" (or "Your") shall mean an individual or Legal Entity
      exercising permissions granted by this License.

      "Source" form shall mean the preferred form for making modifications,
      including but not limited to software source code, documentation
      source, and configuration files.

      "Object" form shall mean any form resulting from mechanical
      transformation or translation of a Source form, including but
      not limited to compiled object code, generated documentation,
      and conversions to other media types.

      "Work" shall mean the work of authorship, whether in Source or
      Object form, made available under the License, as indicated by a
      copyright notice that is included in or attached to the work
      (an example is provided in the Appendix below).

      "Derivative Works" shall mean any work, whether in Source or Object
      form, that is based on (or derived from) the Work and for which the
      editorial revisions, annotations, elaborations, or other modifications
      represent, as a whole, an original work of authorship. For the purposes
      of this License, Derivative Works shall not include works that remain
      separable from, or merely link (or bind by name) to the interfaces of,
      the Work and Derivative Works thereof.

      "Contribution" shall mean any work of authorship, including
      the original version of the Work and any modifications or additions
      to that Work or Derivative Works thereof, that is intentionally
      submitted to Licensor for inclusion in the Work by the copyright owner
      or by an individual or Legal Entity authorized to submit on behalf of
      the copyright owner. For the purposes of this definition, "submitted"
      means any form of electronic, verbal, or written communication sent
      to the Licensor or its representatives, including but not limited to
      communication on electronic mailing lists, source code control systems,
      and issue tracking systems that are managed by, or on behalf of, the
      Licensor for the purpose of discussing and improving the Work, but
      excluding communication that is conspicuously marked or otherwise
      designated in writing by the copyright owner as "Not a Contribution."

      "Contributor" shall mean Licensor and any individual or Legal Entity
      on behalf of whom a Contribution has been received by Licensor and
      subsequently incorporated within the Work.

   2. Grant of Copyright License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      copyright license to reproduce, prepare Derivative Works of,
      publicly display, publicly perform, sublicense, and distribute the
      Work and such Derivative Works in Source or Object form.

   3. Grant of Patent License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      (except as stated in this section) patent license to make, have made,
      use, offer to sell, sell, import, and otherwise transfer the Work,
      where such license applies only to those patent claims licensable
      by such Contributor that are necessarily infringed by their
      Contribution(s) alone or by combination of their Contribution(s)
      with the Work to which such Contribution(s) was submitted. If You
      institute patent litigation against any entity (including a
      cross-claim or counterclaim in a lawsuit) alleging that the Work
      or a Contribution incorporated within the Work constitutes direct
      or contributory patent infringement, then any patent licenses
      granted to You under this License for that Work shall terminate
      as of the date such litigation is filed.

   4. Redistribution. You may reproduce and distribute copies of the
      Work or Derivative Works thereof in any medium, with or without
      modifications, and in Source or Object form, provided that You
      meet the following conditions:

      (a) You must give any other recipients of the Work or
          Derivative Works a copy of this License; and

      (b) You must cause any modified files to carry prominent notices
          stating that You changed the files; and

      (c) You must retain, in the Source form of any Derivative Works
          that You distribute, all copyright, patent, trademark, and
          attribution notices from the Source form of the Work,
          excluding those notices that do not pertain to any part of
          the Derivative Works; and

      (d) If the Work includes a "NOTICE" text file as part of its
          distribution, then any Derivative Works that You distribute must
          include a readable copy of the attribution notices contained
          within such NOTICE file, excluding those notices that do not
          pertain to any part of the Derivative Works, in at least one
          of the following places: within a NOTICE text file distributed
          as part of the Derivative Works; within the Source form or
          documentation, if provided along with the Derivative Works; or,
          within a display generated by the Derivative Works, if and
          wherever such third-party notices normally appear. The contents
          of the NOTICE file are for informational purposes only and
          do not modify the License. You may add Your own attribution
          notices within Derivative Works that You distribute, alongside
          or as an addendum to the NOTICE text from the Work, provided
          that such additional attribution notices cannot be construed
          as modifying the License.

      You may add Your own copyright statement to Your modifications and
      may provide additional or different license terms and conditions
      for use, reproduction, or distribution of Your modifications, or
      for any such Derivative Works as a whole, provided Your use,
      reproduction, and distribution of the Work otherwise complies with
      the conditions stated in this License.

   5. Submission of Contributions. Unless You explicitly state otherwise,
      any Contribution intentionally submitted for inclusion in the Work
      by You to the Licensor shall be under the terms and conditions of
      this License, without any additional terms or conditions.
      Notwithstanding the above, nothing herein shall supersede or modify
      the terms of any separate license agreement you may have executed
      with Licensor regarding such Contributions.

   6. Trademarks. This License does not grant permission to use the trade
      names, trademarks, service marks, or product names of the Licensor,
      except as required for reasonable and customary use in describing the
      origin of the Work and reproducing the content of the NOTICE file.

   7. Disclaimer of Warranty. Unless required by applicable law or
      agreed to in writing, Licensor provides the Work (and each
      Contributor provides its Contributions) on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
      implied, including, without limitation, any warranties or conditions
      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
      PARTICULAR PURPOSE. You are solely responsible for determining the
      appropriateness of using or redistributing the Work and assume any
      risks associated with Your exercise of permissions under this License.

   8. Limitation of Liability. In no event and under no legal theory,
      whether in tort (including negligence), contract, or otherwise,
      unless required by applicable law (such as deliberate and grossly
      negligent acts) or agreed to in writing, shall any Contributor be
      liable to You for damages, including any direct, indirect, special,
      incidental, or consequential damages of any character arising as a
      result of this License or out of the use or inability to use the
      Work (including but not limited to damages for loss of goodwill,
      work stoppage, computer failure or malfunction, or any and all
      other commercial damages or losses), even if such Contributor
      has been advised of the possibility of such damages.

   9. Accepting Warranty or Additional Liability. While redistributing
      the Work or Derivative Works thereof, You may choose to offer,
      and charge a fee for, acceptance of support, warranty, indemnity,
      or other liability obligations and/or rights consistent with this
      License. However, in accepting such obligations, You may act only
      on Your own behalf and on Your sole responsibility, not on behalf
      of any other Contributor, and only if You agree to indemnify,
      defend, and hold each Contributor harmless for any liability
      incurred by, or claims asserted against, such Contributor by reason
      of your accepting any such warranty or additional liability.

   END OF TERMS AND CONDITIONS

   APPENDIX: How to apply the Apache License to your work.

      To apply the Apache License to your work, attach the following
      boilerplate notice, with the fields enclosed by brackets "[]"
      replaced with your own identifying information. (Don't include
      the brackets!)  The text should be enclosed in the appropriate
      comment syntax for the file format. We also recommend that a
      file or class name and description of purpose be included on the
      same "printed page" as the copyright notice for easier
      identification within third-party archives.

   Copyright [yyyy] [name of copyright owner]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

-/
Source
https://github.com/yuvalyitz/treewidth-lax/tree/b6743cf02087f552d8f023581f4718e68c42e444/proofs/Lax689794Proofs

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me