Lean / Reader
Lean reader

lp-bridge-check.lean

481 lines18 declarationsno sorryimports OAI.Optimization.LinearProgramming.Optimization

Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports OAI.Optimization.LinearProgramming.Optimization, which it does not have: you can read it there, but it will not check. Build the project itself to check it.

  1. import OAI.Optimization.LinearProgramming.Optimization
  2. /-!
  3. # My bridge file
  4. Small statements that I derive from the two theorems of the claimant. The kernel
  5. of Lean checks each proof. The file is my own work.
  6. -/
  7. set_option maxHeartbeats 400000
  8. set_option format.width 1000
  9. namespace MobiusOtter
  10. open Matrix
  11. open OAI.Optimization.LinearProgramming
  12. /-! ## 1. The certificate of infeasibility is correct -/
  13. /-- A Farkas certificate excludes a feasible point. -/
  14. theorem certificate_excludes_feasible_point {m d : ℕ} (A : Matrix (Fin m) (Fin d) ℚ)
  15. (b : Fin m → ℚ) {y : Fin m → ℚ} (hy : Certificate A b y) :
  16. ¬ ∃ x, Feasible A b x := by
  17. unfold Certificate at hy
  18. rintro ⟨x, hx⟩
  19. obtain ⟨hy0, hyA, hyb, -⟩ := hy
  20. unfold Feasible at hx
  21. have hle : y ⬝ᵥ (A *ᵥ x) ≤ y ⬝ᵥ b := by
  22. unfold dotProduct
  23. exact Finset.sum_le_sum fun i _ => mul_le_mul_of_nonneg_left (hx i) (hy0 i)
  24. have hzero : y ⬝ᵥ (A *ᵥ x) = 0 := by
  25. rw [dotProduct_mulVec, ← Matrix.mulVec_transpose, hyA]
  26. simp
  27. rw [dotProduct_comm y b] at hle
  28. linarith
  29. /-! ## 2. Feasibility -/
  30. /-- For each rational instance with at least one constraint and one variable, a feasible point
  31. exists or a Farkas certificate exists. -/
  32. theorem feasible_point_or_certificate (m d : ℕ) (hm : 0 < m) (hd : 0 < d)
  33. (A : Matrix (Fin m) (Fin d) ℚ) (b : Fin m → ℚ) :
  34. (∃ x, Feasible A b x) ∨ (∃ y, Certificate A b y) := by
  35. obtain ⟨p, c, e, bC, bE, h⟩ := strongly_polynomial_feasibility
  36. obtain ⟨k, t, -, -, -, hout⟩ := h m d hm hd A b
  37. unfold FeasibilityOutput at hout
  38. rcases hout with ⟨-, h⟩ | ⟨-, h⟩
  39. · exact Or.inl ⟨_, h⟩
  40. · exact Or.inr ⟨_, h⟩
  41. /-! ## 3. Optimization -/
  42. /-- The answer of the optimization program has one of three forms: a certificate of
  43. infeasibility, a primal point with a dual point of the same objective value, or a feasible
  44. point with a ray. -/
  45. theorem optimization_three_answers (m d : ℕ) (hm : 0 < m) (hd : 0 < d)
  46. (A : Matrix (Fin m) (Fin d) ℚ) (b : Fin m → ℚ) (c : Fin d → ℚ) :
  47. (∃ y, Certificate A b y) ∨
  48. (∃ x y value, Feasible A b x ∧ 0 ≤ y ∧ A.transpose *ᵥ y = c ∧
  49. c ⬝ᵥ x = value ∧ b ⬝ᵥ y = value) ∨
  50. (∃ x v, Feasible A b x ∧ A *ᵥ v ≤ 0 ∧ c ⬝ᵥ v = 1) := by
  51. obtain ⟨p, c₀, e, bC, bE, h⟩ := strongly_polynomial_optimization
  52. have h3 : ∃ (k : ℕ) (t : Fin (k + 1) → RAM.State ℚ),
  53. RAM.Trace p (RAM.start [m, d] (lpInput A b ++ List.ofFn c)) k t ∧
  54. k ≤ RAM.polyBound c₀ e (m + d) ∧
  55. (∀ i, RAM.scalarBound
  56. (RAM.polyBound bC bE (RAM.totalBits (lpInput A b ++ List.ofFn c))) (t i)) ∧
  57. OptimizationOutput A b c (t (Fin.last k)) := h m d hm hd A b c
  58. obtain ⟨k, t, -, -, -, hout⟩ := h3
  59. unfold OptimizationOutput at hout
  60. rcases hout with ⟨-, hy⟩ | ⟨-, hx, hy0, hyA, hcv, hbv, -⟩ | ⟨-, hx, hv, hcv⟩
  61. · exact Or.inl ⟨_, hy⟩
  62. · exact Or.inr (Or.inl ⟨_, _, _, hx, hy0, hyA, hcv, hbv⟩)
  63. · exact Or.inr (Or.inr ⟨_, _, hx, hv, hcv⟩)
  64. /-- A feasible point and a ray with `A *ᵥ v ≤ 0` and `c ⬝ᵥ v = 1` give a feasible point for
  65. each nonnegative step length `r`. The objective value is larger by `r`. -/
  66. theorem ray_gives_large_values {m d : ℕ} (A : Matrix (Fin m) (Fin d) ℚ) (b : Fin m → ℚ)
  67. (c : Fin d → ℚ) {x v : Fin d → ℚ} (hx : Feasible A b x) (hv : A *ᵥ v ≤ 0)
  68. (hcv : c ⬝ᵥ v = 1) {r : ℚ} (hr : 0 ≤ r) :
  69. Feasible A b (x + r • v) ∧ c ⬝ᵥ (x + r • v) = c ⬝ᵥ x + r := by
  70. unfold Feasible at hx
  71. constructor
  72. · unfold Feasible
  73. have hA : A *ᵥ (x + r • v) = A *ᵥ x + r • A *ᵥ v := by
  74. rw [Matrix.mulVec_add, Matrix.mulVec_smul]
  75. rw [hA]
  76. intro i
  77. have hvi : (A *ᵥ v) i ≤ (0 : ℚ) := hv i
  78. have h2 := mul_le_mul_of_nonneg_left hvi hr
  79. rw [mul_zero] at h2
  80. show (A *ᵥ x) i + r * (A *ᵥ v) i ≤ b i
  81. linarith [hx i]
  82. · simp only [dotProduct_add, dotProduct_smul, hcv, smul_eq_mul, mul_one]
  83. /-- The duality theorem for rational linear programs, as a consequence. If the problem is
  84. feasible and bounded, then a primal optimum and a dual optimum of the same value exist. -/
  85. theorem duality_of_feasible_bounded (m d : ℕ) (hm : 0 < m) (hd : 0 < d)
  86. (A : Matrix (Fin m) (Fin d) ℚ) (b : Fin m → ℚ) (c : Fin d → ℚ)
  87. (hfeas : ∃ x, Feasible A b x) (hbounded : ∃ M, ∀ x, Feasible A b x → c ⬝ᵥ x ≤ M) :
  88. ∃ x y value, Feasible A b x ∧ 0 ≤ y ∧ A.transpose *ᵥ y = c ∧ c ⬝ᵥ x = value ∧
  89. b ⬝ᵥ y = value ∧ ∀ z, Feasible A b z → c ⬝ᵥ z ≤ value := by
  90. rcases optimization_three_answers m d hm hd A b c with hy | h | h
  91. · obtain ⟨y, hy⟩ := hy
  92. exact absurd hfeas (certificate_excludes_feasible_point A b hy)
  93. · obtain ⟨x, y, value, hx, hy0, hyA, hcv, hbv⟩ := h
  94. refine ⟨x, y, value, hx, hy0, hyA, hcv, hbv, fun z hz => ?_⟩
  95. have h1 : c ⬝ᵥ z = (A *ᵥ z) ⬝ᵥ y := by
  96. rw [← hyA, dotProduct_comm, dotProduct_mulVec, Matrix.vecMul_transpose]
  97. have h2 : (A *ᵥ z) ⬝ᵥ y ≤ b ⬝ᵥ y := by
  98. unfold dotProduct
  99. unfold Feasible at hz
  100. exact Finset.sum_le_sum fun i _ => mul_le_mul_of_nonneg_right (hz i) (hy0 i)
  101. linarith
  102. · obtain ⟨x, v, hx, hv, hcv⟩ := h
  103. obtain ⟨M, hM⟩ := hbounded
  104. have key : ∀ r : ℚ, 0 ≤ r → Feasible A b (x + r • v) ∧ c ⬝ᵥ (x + r • v) = c ⬝ᵥ x + r :=
  105. fun r hr => ray_gives_large_values A b c hx hv hcv hr
  106. obtain ⟨hfeas2, hval⟩ := key (max 0 (M - c ⬝ᵥ x) + 1) (by positivity)
  107. have hle := hM _ hfeas2
  108. rw [hval] at hle
  109. have hmax : M - c ⬝ᵥ x ≤ max 0 (M - c ⬝ᵥ x) := le_max_right _ _
  110. linarith
  111. /-! ## 4. The address registers stay small
  112. The statement of the claimant bounds the bit length of the data registers. It does not
  113. bound the address registers. The results in this section show that each address register
  114. stays below `B + (the number of steps so far)` when the registers start at most `B`. -/
  115. /-- The largest constant that one instruction can write into an address register. -/
  116. def instrAddressConst : RAM.Instr → ℕ
  117. | .addrConst _ n => n
  118. | _ => 0
  119. /-- The largest constant that a program can write into an address register. -/
  120. def programAddressConst : RAM.Program → ℕ
  121. | [] => 0
  122. | i :: p => max (instrAddressConst i) (programAddressConst p)
  123. theorem instrAddressConst_le_mem {i : RAM.Instr} : ∀ {p : RAM.Program}, i ∈ p →
  124. instrAddressConst i ≤ programAddressConst p := by
  125. intro p
  126. induction p with
  127. | nil => intro h; cases h
  128. | cons a p ih =>
  129. intro h
  130. rcases List.mem_cons.mp h with h | h
  131. · subst h
  132. exact le_max_left _ _
  133. · exact le_trans (ih h) (le_max_right _ _)
  134. /-- One step increases no address register beyond `B + 1`, if all address registers are at
  135. most `B` and `B` is at least each constant of the program. -/
  136. theorem step_address_bound {p : RAM.Program} {B : ℕ} (hB : programAddressConst p ≤ B)
  137. {s s' : RAM.State ℚ} (h : RAM.step p s = some s') (hs : ∀ j, s.index j ≤ B) :
  138. ∀ j, s'.index j ≤ B + 1 := by
  139. cases h0 : s.output with
  140. | none =>
  141. cases hi : p[s.pc]? with
  142. | none =>
  143. simp only [RAM.step, h0, hi] at h
  144. exact absurd h (by simp)
  145. | some i =>
  146. simp only [RAM.step, h0, hi] at h
  147. have hiB : instrAddressConst i ≤ B :=
  148. le_trans (instrAddressConst_le_mem (List.mem_of_getElem? hi)) hB
  149. cases i with
  150. | const d q =>
  151. simp only [RAM.execInstr] at h
  152. cases h
  153. intro j
  154. exact (hs j).trans (Nat.le_succ B)
  155. | copy d a =>
  156. simp only [RAM.execInstr] at h
  157. cases h
  158. intro j
  159. exact (hs j).trans (Nat.le_succ B)
  160. | add d a b =>
  161. simp only [RAM.execInstr] at h
  162. cases h
  163. intro j
  164. exact (hs j).trans (Nat.le_succ B)
  165. | sub d a b =>
  166. simp only [RAM.execInstr] at h
  167. cases h
  168. intro j
  169. exact (hs j).trans (Nat.le_succ B)
  170. | mul d a b =>
  171. simp only [RAM.execInstr] at h
  172. cases h
  173. intro j
  174. exact (hs j).trans (Nat.le_succ B)
  175. | div d a b =>
  176. simp only [RAM.execInstr] at h
  177. split at h
  178. · exact absurd h (by simp)
  179. · cases h
  180. intro j
  181. exact (hs j).trans (Nat.le_succ B)
  182. | load d a =>
  183. simp only [RAM.execInstr] at h
  184. cases h
  185. intro j
  186. exact (hs j).trans (Nat.le_succ B)
  187. | store a d =>
  188. simp only [RAM.execInstr] at h
  189. cases h
  190. intro j
  191. exact (hs j).trans (Nat.le_succ B)
  192. | addrConst d n =>
  193. simp only [RAM.execInstr] at h
  194. cases h
  195. simp only [RAM.State.putIndex, Function.update_apply]
  196. simp only [instrAddressConst] at hiB
  197. intro j
  198. split
  199. · omega
  200. · have hj := hs j
  201. omega
  202. | addrCopy d a =>
  203. simp only [RAM.execInstr] at h
  204. cases h
  205. simp only [RAM.State.putIndex, Function.update_apply]
  206. intro j
  207. split
  208. · have ha := hs a
  209. omega
  210. · have hj := hs j
  211. omega
  212. | incr d a =>
  213. simp only [RAM.execInstr] at h
  214. cases h
  215. simp only [RAM.State.putIndex, Function.update_apply]
  216. intro j
  217. split
  218. · have ha := hs a
  219. omega
  220. · have hj := hs j
  221. omega
  222. | decr d a =>
  223. simp only [RAM.execInstr] at h
  224. cases h
  225. simp only [RAM.State.putIndex, Function.update_apply]
  226. intro j
  227. split
  228. · have ha := hs a
  229. omega
  230. · have hj := hs j
  231. omega
  232. | addrLoad d a =>
  233. simp only [RAM.execInstr] at h
  234. cases h
  235. simp only [RAM.State.putIndex, Function.update_apply]
  236. intro j
  237. split
  238. · have ha := hs (s.index a)
  239. omega
  240. · have hj := hs j
  241. omega
  242. | addrStore a d =>
  243. simp only [RAM.execInstr] at h
  244. cases h
  245. simp only [RAM.State.putIndex, Function.update_apply]
  246. intro j
  247. split
  248. · have ha := hs d
  249. omega
  250. · have hj := hs j
  251. omega
  252. | branchLT a b yes no =>
  253. simp only [RAM.execInstr] at h
  254. cases h
  255. intro j
  256. exact (hs j).trans (Nat.le_succ B)
  257. | branchAddrLT a b yes no =>
  258. simp only [RAM.execInstr] at h
  259. cases h
  260. intro j
  261. exact (hs j).trans (Nat.le_succ B)
  262. | jump target =>
  263. simp only [RAM.execInstr] at h
  264. cases h
  265. intro j
  266. exact (hs j).trans (Nat.le_succ B)
  267. | halt tag =>
  268. simp only [RAM.execInstr] at h
  269. cases h
  270. intro j
  271. exact (hs j).trans (Nat.le_succ B)
  272. | some x =>
  273. simp only [RAM.step, h0] at h
  274. exact absurd h (by simp)
  275. /-- Along the steps of a trace, each address register stays below `B + (the number of steps
  276. so far)`. -/
  277. theorem address_bound_of_steps {p : RAM.Program} {k : ℕ} {t : Fin (k + 1) → RAM.State ℚ}
  278. (hstep : ∀ i : Fin k, RAM.step p (t i.castSucc) = some (t i.succ)) {B : ℕ}
  279. (hB : programAddressConst p ≤ B) (h0 : ∀ j, (t 0).index j ≤ B) (i : Fin (k + 1)) (j : ℕ) :
  280. (t i).index j ≤ B + i := by
  281. have key : ∀ (n : ℕ) (hn : n < k + 1) (j : ℕ), (t ⟨n, hn⟩).index j ≤ B + n := by
  282. intro n
  283. induction n with
  284. | zero => intro hn j; simpa using h0 j
  285. | succ n ih =>
  286. intro hn j
  287. have hnk : n < k := Nat.lt_of_succ_lt_succ hn
  288. have hs : RAM.step p (t ⟨n, Nat.lt_succ_of_lt hnk⟩) = some (t ⟨n + 1, hn⟩) :=
  289. hstep ⟨n, hnk⟩
  290. have hprev : ∀ j', (t ⟨n, Nat.lt_succ_of_lt hnk⟩).index j' ≤ B + n :=
  291. fun j' => ih (Nat.lt_succ_of_lt hnk) j'
  292. have hBn : programAddressConst p ≤ B + n := le_trans hB (Nat.le_add_right _ _)
  293. exact (step_address_bound hBn hs hprev j).trans (by omega)
  294. exact key i i.isLt j
  295. /-- The address registers of the start state hold `m`, `d` and zero. -/
  296. theorem start_address_le (m d B : ℕ) (hm : m ≤ B) (hd : d ≤ B) (input : List ℚ) (j : ℕ) :
  297. (RAM.start [m, d] input).index j ≤ B := by
  298. show ([m, d][j]?.getD 0 : ℕ) ≤ B
  299. cases j with
  300. | zero => exact hm
  301. | succ j =>
  302. cases j with
  303. | zero => exact hd
  304. | succ j => simp
  305. /-- In the run of a program from the start state, each address register is at most
  306. `B + (the number of steps so far)`. Here `B` is at least `m`, `d` and each constant of the
  307. program. -/
  308. theorem address_registers_stay_small {m d : ℕ} {input : List ℚ} {p : RAM.Program} {k : ℕ}
  309. {t : Fin (k + 1) → RAM.State ℚ} (htr : RAM.Trace p (RAM.start [m, d] input) k t)
  310. {B : ℕ} (hB : programAddressConst p ≤ B) (hm : m ≤ B) (hd : d ≤ B)
  311. (i : Fin (k + 1)) (j : ℕ) : (t i).index j ≤ B + i := by
  312. unfold RAM.Trace at htr
  313. obtain ⟨h0eq, hstep⟩ := htr
  314. refine address_bound_of_steps hstep hB (fun j => ?_) i j
  315. rw [h0eq]
  316. exact start_address_le m d B hm hd input j
  317. /-- The number of bits of each address register is less than `log2 (B + k) + 1`. -/
  318. theorem address_register_bits {m d : ℕ} {input : List ℚ} {p : RAM.Program} {k : ℕ}
  319. {t : Fin (k + 1) → RAM.State ℚ} (htr : RAM.Trace p (RAM.start [m, d] input) k t)
  320. {B : ℕ} (hB : programAddressConst p ≤ B) (hm : m ≤ B) (hd : d ≤ B)
  321. (i : Fin (k + 1)) (j : ℕ) : Nat.log2 ((t i).index j) < Nat.log2 (B + k) + 1 := by
  322. have h1 : (t i).index j ≤ B + k := by
  323. have h := address_registers_stay_small htr hB hm hd i j
  324. omega
  325. rcases Nat.eq_zero_or_pos ((t i).index j) with hn | hn
  326. · simp [hn]
  327. · rw [Nat.log2_lt hn.ne']
  328. have hmpos : 0 < B + k := lt_of_lt_of_le hn h1
  329. exact lt_of_le_of_lt h1 ((Nat.log2_lt hmpos.ne').mp (Nat.lt_succ_self _))
  330. /-- The feasibility theorem without the abbreviations of the claimant. The number of steps
  331. is at most `c * (m + d + 1) ^ e`. Each data register has at most `bC * (totalBits + 1) ^ bE`
  332. bits. Each address register is at most `max (max m d) (programAddressConst p) + (the number
  333. of steps so far)`. -/
  334. theorem feasibility_explicit (m d : ℕ) (hm : 0 < m) (hd : 0 < d)
  335. (A : Matrix (Fin m) (Fin d) ℚ) (b : Fin m → ℚ) :
  336. ∃ (p : RAM.Program) (c e bC bE : ℕ), ∃ (k : ℕ) (t : Fin (k + 1) → RAM.State ℚ),
  337. RAM.Trace p (RAM.start [m, d] (lpInput A b)) k t ∧
  338. k ≤ c * (m + d + 1) ^ e ∧
  339. (∀ i j, RAM.ratBits ((t i).data j) ≤ bC * (RAM.totalBits (lpInput A b) + 1) ^ bE) ∧
  340. (∀ i j, (t i).index j ≤ max (max m d) (programAddressConst p) + i) ∧
  341. FeasibilityOutput A b (t (Fin.last k)) := by
  342. obtain ⟨p, c, e, bC, bE, h⟩ := strongly_polynomial_feasibility
  343. obtain ⟨k, t, htr, hk, hb, hout⟩ := h m d hm hd A b
  344. refine ⟨p, c, e, bC, bE, k, t, htr, hk, fun i j => hb i j, ?_, hout⟩
  345. exact address_registers_stay_small htr (le_max_right _ _)
  346. (le_trans (le_max_left m d) (le_max_left _ _))
  347. (le_trans (le_max_right m d) (le_max_left _ _))
  348. /-! ## 5. The two statements in plain words
  349. Each restatement in this section does not use the definitions `StronglyPolynomialFeasibility`,
  350. `StronglyPolynomialOptimization`, `Trace`, `polyBound`, `scalarBound`, `ratBits`, `start`,
  351. `readVector`, `Feasible`, `Certificate`, `FeasibilityOutput` and `OptimizationOutput`.
  352. Each proof is the theorem of the claimant itself. Lean accepts a proof only if the
  353. restatement and the statement of the claimant are the same by definition. -/
  354. /-- The input tape holds the rows of `A`, then `b`. -/
  355. theorem lpInput_is {m d : ℕ} (A : Matrix (Fin m) (Fin d) ℚ) (b : Fin m → ℚ) :
  356. lpInput A b = (List.ofFn fun i => List.ofFn (A i)).flatten ++ List.ofFn b := rfl
  357. /-- The bit length of a rational number is 3, plus the binary length of its numerator,
  358. plus the binary length of its denominator. -/
  359. theorem ratBits_is (q : ℚ) :
  360. RAM.ratBits q = 3 + q.num.natAbs.log2 + q.den.log2 := rfl
  361. /-- Feasibility in plain words. One list of instructions `p` and four constants `c`, `e`,
  362. `bC`, `bE` come before all inputs. For each rational instance with `m ≥ 1` constraints and
  363. `d ≥ 1` variables, there is a run of the machine that starts on the input and follows the
  364. program at each step. The run has at most `c * (m + d + 1) ^ e` steps. Each data register
  365. at each step has at most `bC * (totalBits + 1) ^ bE` bits. The last state holds either
  366. (tag 0) a feasible point, or (tag 1) a Farkas certificate with at most `rank A + 1`
  367. nonzero entries. -/
  368. theorem feasibility_in_plain_words :
  369. ∃ (p : List RAM.Instr) (c e bC bE : ℕ), ∀ (m d : ℕ), 0 < m → 0 < d →
  370. ∀ (A : Matrix (Fin m) (Fin d) ℚ) (b : Fin m → ℚ),
  371. ∃ (k : ℕ) (t : Fin (k + 1) → RAM.State ℚ),
  372. ((t 0 = ⟨0, fun i => (lpInput A b)[i]?.getD 0, fun i => [m, d][i]?.getD 0, none⟩ ∧
  373. (∀ i : Fin k, RAM.step p (t i.castSucc) = some (t i.succ))) ∧
  374. k ≤ c * (m + d + 1) ^ e ∧
  375. (∀ (i : Fin (k + 1)) (j : ℕ),
  376. 3 + ((t i).data j).num.natAbs.log2 + ((t i).data j).den.log2 ≤
  377. bC * (RAM.totalBits (lpInput A b) + 1) ^ bE) ∧
  378. (((t (Fin.last k)).output = some 0 ∧
  379. A *ᵥ (fun i => (t (Fin.last k)).data (0 + ↑i)) ≤ b) ∨
  380. ((t (Fin.last k)).output = some 1 ∧
  381. 0 ≤ (fun i : Fin m => (t (Fin.last k)).data (0 + ↑i)) ∧
  382. Aᵀ *ᵥ (fun i : Fin m => (t (Fin.last k)).data (0 + ↑i)) = 0 ∧
  383. b ⬝ᵥ (fun i : Fin m => (t (Fin.last k)).data (0 + ↑i)) < 0 ∧
  384. (Finset.univ.filter fun i : Fin m => (t (Fin.last k)).data (0 + ↑i) ≠ 0).card ≤
  385. A.rank + 1))) :=
  386. strongly_polynomial_feasibility
  387. /-- Optimization in plain words. The form is the same. The input tape holds the rows of
  388. `A`, then `b`, then the objective `obj`. The last state holds one of three answers.
  389. (Tag 0) A Farkas certificate of infeasibility.
  390. (Tag 1) A primal point `x`, a dual point `y` and a common value: `x` is feasible, `y` is
  391. nonnegative, `Aᵀ y = obj`, the objective value of `x` is the common value, `b ⬝ᵥ y` is
  392. the common value, and no feasible point has a larger objective value.
  393. (Tag 2) A feasible point and a ray `v` with `A v ≤ 0` and `obj ⬝ᵥ v = 1`. -/
  394. theorem optimization_in_plain_words :
  395. ∃ (p : List RAM.Instr) (c e bC bE : ℕ), ∀ (m d : ℕ), 0 < m → 0 < d →
  396. ∀ (A : Matrix (Fin m) (Fin d) ℚ) (b : Fin m → ℚ) (obj : Fin d → ℚ),
  397. ∃ (k : ℕ) (t : Fin (k + 1) → RAM.State ℚ),
  398. ((t 0 = ⟨0, fun i => (lpInput A b ++ List.ofFn obj)[i]?.getD 0,
  399. fun i => [m, d][i]?.getD 0, none⟩ ∧
  400. (∀ i : Fin k, RAM.step p (t i.castSucc) = some (t i.succ))) ∧
  401. k ≤ c * (m + d + 1) ^ e ∧
  402. (∀ (i : Fin (k + 1)) (j : ℕ),
  403. 3 + ((t i).data j).num.natAbs.log2 + ((t i).data j).den.log2 ≤
  404. bC * (RAM.totalBits (lpInput A b ++ List.ofFn obj) + 1) ^ bE) ∧
  405. (((t (Fin.last k)).output = some 0 ∧
  406. 0 ≤ (fun i : Fin m => (t (Fin.last k)).data (0 + ↑i)) ∧
  407. Aᵀ *ᵥ (fun i : Fin m => (t (Fin.last k)).data (0 + ↑i)) = 0 ∧
  408. b ⬝ᵥ (fun i : Fin m => (t (Fin.last k)).data (0 + ↑i)) < 0 ∧
  409. (Finset.univ.filter fun i : Fin m => (t (Fin.last k)).data (0 + ↑i) ≠ 0).card ≤
  410. A.rank + 1) ∨
  411. ((t (Fin.last k)).output = some 1 ∧
  412. A *ᵥ (fun i : Fin d => (t (Fin.last k)).data (0 + ↑i)) ≤ b ∧
  413. 0 ≤ (fun i : Fin m => (t (Fin.last k)).data (d + ↑i)) ∧
  414. Aᵀ *ᵥ (fun i : Fin m => (t (Fin.last k)).data (d + ↑i)) = obj ∧
  415. obj ⬝ᵥ (fun i : Fin d => (t (Fin.last k)).data (0 + ↑i)) =
  416. (t (Fin.last k)).data (d + m) ∧
  417. b ⬝ᵥ (fun i : Fin m => (t (Fin.last k)).data (d + ↑i)) =
  418. (t (Fin.last k)).data (d + m) ∧
  419. ∀ z : Fin d → ℚ, A *ᵥ z ≤ b →
  420. obj ⬝ᵥ z ≤ (t (Fin.last k)).data (d + m)) ∨
  421. ((t (Fin.last k)).output = some 2 ∧
  422. A *ᵥ (fun i : Fin d => (t (Fin.last k)).data (0 + ↑i)) ≤ b ∧
  423. A *ᵥ (fun i : Fin d => (t (Fin.last k)).data (d + ↑i)) ≤ 0 ∧
  424. obj ⬝ᵥ (fun i : Fin d => (t (Fin.last k)).data (d + ↑i)) = 1))) :=
  425. strongly_polynomial_optimization
  426. end MobiusOtter
  427. -- Readable form of my two restatements.
  428. #check @MobiusOtter.feasibility_in_plain_words
  429. #check @MobiusOtter.optimization_in_plain_words
  430. -- Axioms of my statements and of the two theorems of the claimant.
  431. #print axioms OAI.Optimization.LinearProgramming.strongly_polynomial_feasibility
  432. #print axioms OAI.Optimization.LinearProgramming.strongly_polynomial_optimization
  433. #print axioms MobiusOtter.certificate_excludes_feasible_point
  434. #print axioms MobiusOtter.feasible_point_or_certificate
  435. #print axioms MobiusOtter.optimization_three_answers
  436. #print axioms MobiusOtter.ray_gives_large_values
  437. #print axioms MobiusOtter.duality_of_feasible_bounded
  438. #print axioms MobiusOtter.step_address_bound
  439. #print axioms MobiusOtter.address_bound_of_steps
  440. #print axioms MobiusOtter.start_address_le
  441. #print axioms MobiusOtter.address_registers_stay_small
  442. #print axioms MobiusOtter.address_register_bits
  443. #print axioms MobiusOtter.feasibility_explicit
  444. #print axioms MobiusOtter.lpInput_is
  445. #print axioms MobiusOtter.ratBits_is
  446. #print axioms MobiusOtter.feasibility_in_plain_words
  447. #print axioms MobiusOtter.optimization_in_plain_words