import Erdos1135.NumberTheory.Rhin.LiteralRemainder

/-!
# Exact cells for the relaxed Rhin remainder bound

This file is generated by `scripts/generate_rhin_remainder_cells.py`.
The 38 rational cells form a finite exact certificate for a continuous
interval bound; they are not a historical low-frequency phase table.
The cover, raw base `239/1000`, and loss cap `20` are derived exact G8
relaxations for Rhin's printed `Q₆` coefficient `-108`; Rhin does not print
these certificate parameters, and they do not cover Wu's later `-104` variant.

Python emits only the cell data and repetitive proof declarations.  Each
cell inequality and loss bound is proved by Lean's kernel-checked `norm_num`.
No native compiler decision mechanism is used.
-/

namespace Erdos1135
namespace NumberTheory
namespace Rhin

noncomputable section

open scoped BigOperators

set_option exponentiation.threshold 1000
set_option maxRecDepth 10000
set_option maxHeartbeats 1000000

structure RhinCell where
  left : ℚ
  right : ℚ
deriving DecidableEq, Repr

def rhinQ5Rat (x : ℚ) : ℚ := 17 * x ^ 2 - 102 * x + 144
def rhinQ6Rat (x : ℚ) : ℚ := 19 * x ^ 2 - 108 * x + 144

/-- Exact endpoint/vertex upper bounds for the six literal factors on a
cell. -/
def rhinCellMax (c : RhinCell) : Fin 6 → ℚ :=
  ![max |c.left - 3| |c.right - 3|,
    max |c.left - 2| |c.right - 2|,
    max |c.left - 4| |c.right - 4|,
    max |5 * c.left - 12| |5 * c.right - 12|,
    max (max |rhinQ5Rat c.left| |rhinQ5Rat c.right|)
      (if c.left ≤ 3 ∧ 3 ≤ c.right then 9 else 0),
    max (max |rhinQ6Rat c.left| |rhinQ6Rat c.right|)
      (if c.left ≤ 54 / 19 ∧ 54 / 19 ≤ c.right then 180 / 19 else 0)]

def rhinCellExponent (c : RhinCell) (i : Fin 6) : ℕ :=
  if 1 ≤ rhinCellMax c i then
    literalRhinUpperExponent i
  else
    literalRhinLowerExponent i

def rhinCellCost (c : RhinCell) : ℚ :=
  ∏ i : Fin 6, if rhinCellMax c i < 1 then (rhinCellMax c i)⁻¹ else 1

def rhinCellValid (c : RhinCell) : Prop :=
  c.left < c.right ∧
    2 ≤ c.left ∧ c.right ≤ 4 ∧
    (∀ i : Fin 6, 0 < rhinCellMax c i) ∧
    (∏ i : Fin 6, rhinCellMax c i ^ rhinCellExponent c i) <
      (((239 : ℚ) / 1000) * c.left) ^ 1000

theorem rhinCellMax_pos_of_valid
    {c : RhinCell} (hc : rhinCellValid c) (i : Fin 6) :
    0 < rhinCellMax c i := by
  exact hc.2.2.2.1 i

def rhinCell23_00 : RhinCell := ⟨2, 33/16⟩

def rhinCell23_01 : RhinCell := ⟨33/16, 17/8⟩

def rhinCell23_02 : RhinCell := ⟨17/8, 69/32⟩

def rhinCell23_03 : RhinCell := ⟨69/32, 35/16⟩

def rhinCell23_04 : RhinCell := ⟨35/16, 141/64⟩

def rhinCell23_05 : RhinCell := ⟨141/64, 71/32⟩

def rhinCell23_06 : RhinCell := ⟨71/32, 143/64⟩

def rhinCell23_07 : RhinCell := ⟨143/64, 9/4⟩

def rhinCell23_08 : RhinCell := ⟨9/4, 73/32⟩

def rhinCell23_09 : RhinCell := ⟨73/32, 37/16⟩

def rhinCell23_10 : RhinCell := ⟨37/16, 75/32⟩

def rhinCell23_11 : RhinCell := ⟨75/32, 19/8⟩

def rhinCell23_12 : RhinCell := ⟨19/8, 39/16⟩

def rhinCell23_13 : RhinCell := ⟨39/16, 79/32⟩

def rhinCell23_14 : RhinCell := ⟨79/32, 5/2⟩

def rhinCell23_15 : RhinCell := ⟨5/2, 81/32⟩

def rhinCell23_16 : RhinCell := ⟨81/32, 41/16⟩

def rhinCell23_17 : RhinCell := ⟨41/16, 83/32⟩

def rhinCell23_18 : RhinCell := ⟨83/32, 21/8⟩

def rhinCell23_19 : RhinCell := ⟨21/8, 43/16⟩

def rhinCell23_20 : RhinCell := ⟨43/16, 11/4⟩

def rhinCell23_21 : RhinCell := ⟨11/4, 3⟩

def rhinCells23 : List RhinCell :=
  [rhinCell23_00,
   rhinCell23_01,
   rhinCell23_02,
   rhinCell23_03,
   rhinCell23_04,
   rhinCell23_05,
   rhinCell23_06,
   rhinCell23_07,
   rhinCell23_08,
   rhinCell23_09,
   rhinCell23_10,
   rhinCell23_11,
   rhinCell23_12,
   rhinCell23_13,
   rhinCell23_14,
   rhinCell23_15,
   rhinCell23_16,
   rhinCell23_17,
   rhinCell23_18,
   rhinCell23_19,
   rhinCell23_20,
   rhinCell23_21]

private theorem rhinCell23_00_valid : rhinCellValid rhinCell23_00 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_00]
  · norm_num [rhinCell23_00]
  · norm_num [rhinCell23_00]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_00, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_00, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_00_cost_le : rhinCellCost rhinCell23_00 ≤ 20 := by
  norm_num [rhinCell23_00, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_01_valid : rhinCellValid rhinCell23_01 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_01]
  · norm_num [rhinCell23_01]
  · norm_num [rhinCell23_01]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_01, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_01, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_01_cost_le : rhinCellCost rhinCell23_01 ≤ 20 := by
  norm_num [rhinCell23_01, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_02_valid : rhinCellValid rhinCell23_02 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_02]
  · norm_num [rhinCell23_02]
  · norm_num [rhinCell23_02]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_02, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_02, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_02_cost_le : rhinCellCost rhinCell23_02 ≤ 20 := by
  norm_num [rhinCell23_02, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_03_valid : rhinCellValid rhinCell23_03 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_03]
  · norm_num [rhinCell23_03]
  · norm_num [rhinCell23_03]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_03, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_03, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_03_cost_le : rhinCellCost rhinCell23_03 ≤ 20 := by
  norm_num [rhinCell23_03, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_04_valid : rhinCellValid rhinCell23_04 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_04]
  · norm_num [rhinCell23_04]
  · norm_num [rhinCell23_04]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_04, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_04, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_04_cost_le : rhinCellCost rhinCell23_04 ≤ 20 := by
  norm_num [rhinCell23_04, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_05_valid : rhinCellValid rhinCell23_05 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_05]
  · norm_num [rhinCell23_05]
  · norm_num [rhinCell23_05]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_05, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_05, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_05_cost_le : rhinCellCost rhinCell23_05 ≤ 20 := by
  norm_num [rhinCell23_05, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_06_valid : rhinCellValid rhinCell23_06 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_06]
  · norm_num [rhinCell23_06]
  · norm_num [rhinCell23_06]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_06, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_06, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_06_cost_le : rhinCellCost rhinCell23_06 ≤ 20 := by
  norm_num [rhinCell23_06, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_07_valid : rhinCellValid rhinCell23_07 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_07]
  · norm_num [rhinCell23_07]
  · norm_num [rhinCell23_07]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_07, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_07, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_07_cost_le : rhinCellCost rhinCell23_07 ≤ 20 := by
  norm_num [rhinCell23_07, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_08_valid : rhinCellValid rhinCell23_08 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_08]
  · norm_num [rhinCell23_08]
  · norm_num [rhinCell23_08]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_08, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_08, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_08_cost_le : rhinCellCost rhinCell23_08 ≤ 20 := by
  norm_num [rhinCell23_08, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_09_valid : rhinCellValid rhinCell23_09 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_09]
  · norm_num [rhinCell23_09]
  · norm_num [rhinCell23_09]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_09, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_09, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_09_cost_le : rhinCellCost rhinCell23_09 ≤ 20 := by
  norm_num [rhinCell23_09, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_10_valid : rhinCellValid rhinCell23_10 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_10]
  · norm_num [rhinCell23_10]
  · norm_num [rhinCell23_10]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_10, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_10, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_10_cost_le : rhinCellCost rhinCell23_10 ≤ 20 := by
  norm_num [rhinCell23_10, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_11_valid : rhinCellValid rhinCell23_11 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_11]
  · norm_num [rhinCell23_11]
  · norm_num [rhinCell23_11]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_11, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_11, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_11_cost_le : rhinCellCost rhinCell23_11 ≤ 20 := by
  norm_num [rhinCell23_11, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_12_valid : rhinCellValid rhinCell23_12 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_12]
  · norm_num [rhinCell23_12]
  · norm_num [rhinCell23_12]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_12, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_12, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_12_cost_le : rhinCellCost rhinCell23_12 ≤ 20 := by
  norm_num [rhinCell23_12, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_13_valid : rhinCellValid rhinCell23_13 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_13]
  · norm_num [rhinCell23_13]
  · norm_num [rhinCell23_13]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_13, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_13, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_13_cost_le : rhinCellCost rhinCell23_13 ≤ 20 := by
  norm_num [rhinCell23_13, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_14_valid : rhinCellValid rhinCell23_14 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_14]
  · norm_num [rhinCell23_14]
  · norm_num [rhinCell23_14]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_14, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_14, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_14_cost_le : rhinCellCost rhinCell23_14 ≤ 20 := by
  norm_num [rhinCell23_14, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_15_valid : rhinCellValid rhinCell23_15 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_15]
  · norm_num [rhinCell23_15]
  · norm_num [rhinCell23_15]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_15, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_15, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_15_cost_le : rhinCellCost rhinCell23_15 ≤ 20 := by
  norm_num [rhinCell23_15, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_16_valid : rhinCellValid rhinCell23_16 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_16]
  · norm_num [rhinCell23_16]
  · norm_num [rhinCell23_16]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_16, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_16, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_16_cost_le : rhinCellCost rhinCell23_16 ≤ 20 := by
  norm_num [rhinCell23_16, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_17_valid : rhinCellValid rhinCell23_17 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_17]
  · norm_num [rhinCell23_17]
  · norm_num [rhinCell23_17]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_17, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_17, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_17_cost_le : rhinCellCost rhinCell23_17 ≤ 20 := by
  norm_num [rhinCell23_17, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_18_valid : rhinCellValid rhinCell23_18 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_18]
  · norm_num [rhinCell23_18]
  · norm_num [rhinCell23_18]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_18, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_18, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_18_cost_le : rhinCellCost rhinCell23_18 ≤ 20 := by
  norm_num [rhinCell23_18, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_19_valid : rhinCellValid rhinCell23_19 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_19]
  · norm_num [rhinCell23_19]
  · norm_num [rhinCell23_19]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_19, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_19, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_19_cost_le : rhinCellCost rhinCell23_19 ≤ 20 := by
  norm_num [rhinCell23_19, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_20_valid : rhinCellValid rhinCell23_20 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_20]
  · norm_num [rhinCell23_20]
  · norm_num [rhinCell23_20]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_20, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_20, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_20_cost_le : rhinCellCost rhinCell23_20 ≤ 20 := by
  norm_num [rhinCell23_20, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell23_21_valid : rhinCellValid rhinCell23_21 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell23_21]
  · norm_num [rhinCell23_21]
  · norm_num [rhinCell23_21]
  · intro i
    fin_cases i <;> norm_num [rhinCell23_21, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell23_21, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell23_21_cost_le : rhinCellCost rhinCell23_21 ≤ 20 := by
  norm_num [rhinCell23_21, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCells23_forall :
    List.Forall rhinCellValid rhinCells23 := by
  simpa only [rhinCells23, List.Forall] using
    And.intro rhinCell23_00_valid (And.intro rhinCell23_01_valid (And.intro rhinCell23_02_valid (And.intro rhinCell23_03_valid (And.intro rhinCell23_04_valid (And.intro rhinCell23_05_valid (And.intro rhinCell23_06_valid (And.intro rhinCell23_07_valid (And.intro rhinCell23_08_valid (And.intro rhinCell23_09_valid (And.intro rhinCell23_10_valid (And.intro rhinCell23_11_valid (And.intro rhinCell23_12_valid (And.intro rhinCell23_13_valid (And.intro rhinCell23_14_valid (And.intro rhinCell23_15_valid (And.intro rhinCell23_16_valid (And.intro rhinCell23_17_valid (And.intro rhinCell23_18_valid (And.intro rhinCell23_19_valid (And.intro rhinCell23_20_valid (rhinCell23_21_valid)))))))))))))))))))))

private theorem rhinCells23_cost_forall :
    List.Forall (fun c ↦ rhinCellCost c ≤ 20) rhinCells23 := by
  simpa only [rhinCells23, List.Forall] using
    And.intro rhinCell23_00_cost_le (And.intro rhinCell23_01_cost_le (And.intro rhinCell23_02_cost_le (And.intro rhinCell23_03_cost_le (And.intro rhinCell23_04_cost_le (And.intro rhinCell23_05_cost_le (And.intro rhinCell23_06_cost_le (And.intro rhinCell23_07_cost_le (And.intro rhinCell23_08_cost_le (And.intro rhinCell23_09_cost_le (And.intro rhinCell23_10_cost_le (And.intro rhinCell23_11_cost_le (And.intro rhinCell23_12_cost_le (And.intro rhinCell23_13_cost_le (And.intro rhinCell23_14_cost_le (And.intro rhinCell23_15_cost_le (And.intro rhinCell23_16_cost_le (And.intro rhinCell23_17_cost_le (And.intro rhinCell23_18_cost_le (And.intro rhinCell23_19_cost_le (And.intro rhinCell23_20_cost_le (rhinCell23_21_cost_le)))))))))))))))))))))

theorem rhinCells23_valid :
    ∀ c ∈ rhinCells23, rhinCellValid c :=
  List.forall_iff_forall_mem.mp rhinCells23_forall

theorem rhinCells23_cost_le :
    ∀ c ∈ rhinCells23, rhinCellCost c ≤ 20 :=
  List.forall_iff_forall_mem.mp rhinCells23_cost_forall

def rhinCell34_00 : RhinCell := ⟨3, 13/4⟩

def rhinCell34_01 : RhinCell := ⟨13/4, 27/8⟩

def rhinCell34_02 : RhinCell := ⟨27/8, 55/16⟩

def rhinCell34_03 : RhinCell := ⟨55/16, 7/2⟩

def rhinCell34_04 : RhinCell := ⟨7/2, 57/16⟩

def rhinCell34_05 : RhinCell := ⟨57/16, 115/32⟩

def rhinCell34_06 : RhinCell := ⟨115/32, 29/8⟩

def rhinCell34_07 : RhinCell := ⟨29/8, 117/32⟩

def rhinCell34_08 : RhinCell := ⟨117/32, 59/16⟩

def rhinCell34_09 : RhinCell := ⟨59/16, 119/32⟩

def rhinCell34_10 : RhinCell := ⟨119/32, 15/4⟩

def rhinCell34_11 : RhinCell := ⟨15/4, 121/32⟩

def rhinCell34_12 : RhinCell := ⟨121/32, 61/16⟩

def rhinCell34_13 : RhinCell := ⟨61/16, 123/32⟩

def rhinCell34_14 : RhinCell := ⟨123/32, 31/8⟩

def rhinCell34_15 : RhinCell := ⟨31/8, 4⟩

def rhinCells34 : List RhinCell :=
  [rhinCell34_00,
   rhinCell34_01,
   rhinCell34_02,
   rhinCell34_03,
   rhinCell34_04,
   rhinCell34_05,
   rhinCell34_06,
   rhinCell34_07,
   rhinCell34_08,
   rhinCell34_09,
   rhinCell34_10,
   rhinCell34_11,
   rhinCell34_12,
   rhinCell34_13,
   rhinCell34_14,
   rhinCell34_15]

private theorem rhinCell34_00_valid : rhinCellValid rhinCell34_00 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell34_00]
  · norm_num [rhinCell34_00]
  · norm_num [rhinCell34_00]
  · intro i
    fin_cases i <;> norm_num [rhinCell34_00, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell34_00, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell34_00_cost_le : rhinCellCost rhinCell34_00 ≤ 20 := by
  norm_num [rhinCell34_00, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell34_01_valid : rhinCellValid rhinCell34_01 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell34_01]
  · norm_num [rhinCell34_01]
  · norm_num [rhinCell34_01]
  · intro i
    fin_cases i <;> norm_num [rhinCell34_01, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell34_01, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell34_01_cost_le : rhinCellCost rhinCell34_01 ≤ 20 := by
  norm_num [rhinCell34_01, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell34_02_valid : rhinCellValid rhinCell34_02 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell34_02]
  · norm_num [rhinCell34_02]
  · norm_num [rhinCell34_02]
  · intro i
    fin_cases i <;> norm_num [rhinCell34_02, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell34_02, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell34_02_cost_le : rhinCellCost rhinCell34_02 ≤ 20 := by
  norm_num [rhinCell34_02, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell34_03_valid : rhinCellValid rhinCell34_03 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell34_03]
  · norm_num [rhinCell34_03]
  · norm_num [rhinCell34_03]
  · intro i
    fin_cases i <;> norm_num [rhinCell34_03, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell34_03, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell34_03_cost_le : rhinCellCost rhinCell34_03 ≤ 20 := by
  norm_num [rhinCell34_03, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell34_04_valid : rhinCellValid rhinCell34_04 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell34_04]
  · norm_num [rhinCell34_04]
  · norm_num [rhinCell34_04]
  · intro i
    fin_cases i <;> norm_num [rhinCell34_04, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell34_04, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell34_04_cost_le : rhinCellCost rhinCell34_04 ≤ 20 := by
  norm_num [rhinCell34_04, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell34_05_valid : rhinCellValid rhinCell34_05 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell34_05]
  · norm_num [rhinCell34_05]
  · norm_num [rhinCell34_05]
  · intro i
    fin_cases i <;> norm_num [rhinCell34_05, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell34_05, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell34_05_cost_le : rhinCellCost rhinCell34_05 ≤ 20 := by
  norm_num [rhinCell34_05, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell34_06_valid : rhinCellValid rhinCell34_06 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell34_06]
  · norm_num [rhinCell34_06]
  · norm_num [rhinCell34_06]
  · intro i
    fin_cases i <;> norm_num [rhinCell34_06, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell34_06, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell34_06_cost_le : rhinCellCost rhinCell34_06 ≤ 20 := by
  norm_num [rhinCell34_06, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell34_07_valid : rhinCellValid rhinCell34_07 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell34_07]
  · norm_num [rhinCell34_07]
  · norm_num [rhinCell34_07]
  · intro i
    fin_cases i <;> norm_num [rhinCell34_07, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell34_07, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell34_07_cost_le : rhinCellCost rhinCell34_07 ≤ 20 := by
  norm_num [rhinCell34_07, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell34_08_valid : rhinCellValid rhinCell34_08 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell34_08]
  · norm_num [rhinCell34_08]
  · norm_num [rhinCell34_08]
  · intro i
    fin_cases i <;> norm_num [rhinCell34_08, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell34_08, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell34_08_cost_le : rhinCellCost rhinCell34_08 ≤ 20 := by
  norm_num [rhinCell34_08, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell34_09_valid : rhinCellValid rhinCell34_09 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell34_09]
  · norm_num [rhinCell34_09]
  · norm_num [rhinCell34_09]
  · intro i
    fin_cases i <;> norm_num [rhinCell34_09, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell34_09, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell34_09_cost_le : rhinCellCost rhinCell34_09 ≤ 20 := by
  norm_num [rhinCell34_09, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell34_10_valid : rhinCellValid rhinCell34_10 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell34_10]
  · norm_num [rhinCell34_10]
  · norm_num [rhinCell34_10]
  · intro i
    fin_cases i <;> norm_num [rhinCell34_10, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell34_10, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell34_10_cost_le : rhinCellCost rhinCell34_10 ≤ 20 := by
  norm_num [rhinCell34_10, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell34_11_valid : rhinCellValid rhinCell34_11 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell34_11]
  · norm_num [rhinCell34_11]
  · norm_num [rhinCell34_11]
  · intro i
    fin_cases i <;> norm_num [rhinCell34_11, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell34_11, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell34_11_cost_le : rhinCellCost rhinCell34_11 ≤ 20 := by
  norm_num [rhinCell34_11, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell34_12_valid : rhinCellValid rhinCell34_12 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell34_12]
  · norm_num [rhinCell34_12]
  · norm_num [rhinCell34_12]
  · intro i
    fin_cases i <;> norm_num [rhinCell34_12, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell34_12, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell34_12_cost_le : rhinCellCost rhinCell34_12 ≤ 20 := by
  norm_num [rhinCell34_12, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell34_13_valid : rhinCellValid rhinCell34_13 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell34_13]
  · norm_num [rhinCell34_13]
  · norm_num [rhinCell34_13]
  · intro i
    fin_cases i <;> norm_num [rhinCell34_13, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell34_13, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell34_13_cost_le : rhinCellCost rhinCell34_13 ≤ 20 := by
  norm_num [rhinCell34_13, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell34_14_valid : rhinCellValid rhinCell34_14 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell34_14]
  · norm_num [rhinCell34_14]
  · norm_num [rhinCell34_14]
  · intro i
    fin_cases i <;> norm_num [rhinCell34_14, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell34_14, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell34_14_cost_le : rhinCellCost rhinCell34_14 ≤ 20 := by
  norm_num [rhinCell34_14, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCell34_15_valid : rhinCellValid rhinCell34_15 := by
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · norm_num [rhinCell34_15]
  · norm_num [rhinCell34_15]
  · norm_num [rhinCell34_15]
  · intro i
    fin_cases i <;> norm_num [rhinCell34_15, rhinCellMax,
      rhinQ5Rat, rhinQ6Rat]
  · norm_num [rhinCell34_15, rhinCellMax, rhinCellExponent,
      rhinQ5Rat, rhinQ6Rat, literalRhinUpperExponent,
      literalRhinLowerExponent, Fin.prod_univ_succ]

private theorem rhinCell34_15_cost_le : rhinCellCost rhinCell34_15 ≤ 20 := by
  norm_num [rhinCell34_15, rhinCellCost, rhinCellMax, rhinQ5Rat, rhinQ6Rat,
    Fin.prod_univ_succ, Matrix.vecCons, Matrix.vecEmpty]

private theorem rhinCells34_forall :
    List.Forall rhinCellValid rhinCells34 := by
  simpa only [rhinCells34, List.Forall] using
    And.intro rhinCell34_00_valid (And.intro rhinCell34_01_valid (And.intro rhinCell34_02_valid (And.intro rhinCell34_03_valid (And.intro rhinCell34_04_valid (And.intro rhinCell34_05_valid (And.intro rhinCell34_06_valid (And.intro rhinCell34_07_valid (And.intro rhinCell34_08_valid (And.intro rhinCell34_09_valid (And.intro rhinCell34_10_valid (And.intro rhinCell34_11_valid (And.intro rhinCell34_12_valid (And.intro rhinCell34_13_valid (And.intro rhinCell34_14_valid (rhinCell34_15_valid)))))))))))))))

private theorem rhinCells34_cost_forall :
    List.Forall (fun c ↦ rhinCellCost c ≤ 20) rhinCells34 := by
  simpa only [rhinCells34, List.Forall] using
    And.intro rhinCell34_00_cost_le (And.intro rhinCell34_01_cost_le (And.intro rhinCell34_02_cost_le (And.intro rhinCell34_03_cost_le (And.intro rhinCell34_04_cost_le (And.intro rhinCell34_05_cost_le (And.intro rhinCell34_06_cost_le (And.intro rhinCell34_07_cost_le (And.intro rhinCell34_08_cost_le (And.intro rhinCell34_09_cost_le (And.intro rhinCell34_10_cost_le (And.intro rhinCell34_11_cost_le (And.intro rhinCell34_12_cost_le (And.intro rhinCell34_13_cost_le (And.intro rhinCell34_14_cost_le (rhinCell34_15_cost_le)))))))))))))))

theorem rhinCells34_valid :
    ∀ c ∈ rhinCells34, rhinCellValid c :=
  List.forall_iff_forall_mem.mp rhinCells34_forall

theorem rhinCells34_cost_le :
    ∀ c ∈ rhinCells34, rhinCellCost c ≤ 20 :=
  List.forall_iff_forall_mem.mp rhinCells34_cost_forall

/-- A compact computable condition that a nonempty cell list is contiguous
with the stated outer endpoints. -/
def rhinCellChain (a b : ℚ) : List RhinCell → Prop
  | [] => False
  | c :: cs =>
      c.left = a ∧ c.left < c.right ∧
        match cs with
        | [] => c.right = b
        | _ => rhinCellChain c.right b cs

private theorem rhinCells23_chain : rhinCellChain 2 3 rhinCells23 := by
  norm_num [rhinCellChain, rhinCells23,
    rhinCell23_00, rhinCell23_01, rhinCell23_02, rhinCell23_03,
    rhinCell23_04, rhinCell23_05, rhinCell23_06, rhinCell23_07,
    rhinCell23_08, rhinCell23_09, rhinCell23_10, rhinCell23_11,
    rhinCell23_12, rhinCell23_13, rhinCell23_14, rhinCell23_15,
    rhinCell23_16, rhinCell23_17, rhinCell23_18, rhinCell23_19,
    rhinCell23_20, rhinCell23_21]

private theorem rhinCells34_chain : rhinCellChain 3 4 rhinCells34 := by
  norm_num [rhinCellChain, rhinCells34,
    rhinCell34_00, rhinCell34_01, rhinCell34_02, rhinCell34_03,
    rhinCell34_04, rhinCell34_05, rhinCell34_06, rhinCell34_07,
    rhinCell34_08, rhinCell34_09, rhinCell34_10, rhinCell34_11,
    rhinCell34_12, rhinCell34_13, rhinCell34_14, rhinCell34_15]

theorem exists_cell_of_chain
    {a b : ℚ} {cells : List RhinCell}
    (hchain : rhinCellChain a b cells)
    {x : ℝ} (hax : (a : ℝ) ≤ x) (hxb : x ≤ (b : ℝ)) :
    ∃ c ∈ cells, (c.left : ℝ) ≤ x ∧ x ≤ (c.right : ℝ) := by
  induction cells generalizing a with
  | nil => simp [rhinCellChain] at hchain
  | cons c cs ih =>
      rcases hchain with ⟨hcLeft, hcLt, hrest⟩
      cases cs with
      | nil =>
          refine ⟨c, by simp, ?_, ?_⟩
          · simpa only [hcLeft] using hax
          · simpa only [hrest] using hxb
      | cons d ds =>
          by_cases hxc : x ≤ (c.right : ℝ)
          · refine ⟨c, by simp, ?_, hxc⟩
            simpa only [hcLeft] using hax
          · obtain ⟨cell, hmem, hcell⟩ := ih hrest
              (le_of_not_ge hxc)
            exact ⟨cell, List.mem_cons_of_mem c hmem, hcell⟩

theorem exists_rhinCell23 {x : ℝ} (hx : x ∈ Set.Icc (2 : ℝ) 3) :
    ∃ c ∈ rhinCells23, (c.left : ℝ) ≤ x ∧ x ≤ (c.right : ℝ) :=
  exists_cell_of_chain rhinCells23_chain hx.1 hx.2

theorem exists_rhinCell34 {x : ℝ} (hx : x ∈ Set.Icc (3 : ℝ) 4) :
    ∃ c ∈ rhinCells34, (c.left : ℝ) ≤ x ∧ x ≤ (c.right : ℝ) :=
  exists_cell_of_chain rhinCells34_chain hx.1 hx.2

/-- The derived relaxed raw base gives the integer G8 contraction witness
`13` after the later base-three LCM factor is included.  This exact
certificate is distinct from Rhin's printed exponent `13.3`. -/
theorem rhinRelaxedRateCertificate :
    (72 : ℚ) * ((3 : ℚ) * (239 / 1000)) ^ 13 < 1 ∧
      (13 : ℚ) ≤ 133 / 10 := by
  norm_num

end

end Rhin
end NumberTheory
end Erdos1135
