Decoding rational LP certificates
Lax263307.RegisteredLP · concepts/Lax263307/RegisteredLP.lean · lax-263307
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
Decode the tagged certificate produced by the registered rational LP solver: an optimal primal-dual pair, an infeasibility certificate, or an unboundedness certificate.
Concept map
Lean source view on GitHub
| 1 | import Lax109476.PolynomialTimeSolver |
| 2 | |
| 3 | /-! |
| 4 | --- |
| 5 | title: Decoding rational LP certificates |
| 6 | type: definition |
| 7 | --- |
| 8 | Decode the tagged certificate produced by the registered rational LP |
| 9 | solver: an optimal primal-dual pair, an infeasibility certificate, or an |
| 10 | unboundedness certificate. |
| 11 | |
| 12 | # Formalization notes |
| 13 | |
| 14 | The parser reads canonical sign-numerator-denominator triples and returns |
| 15 | the unconsumed suffix. `certificate` applies a supplied solver and returns |
| 16 | the decoded certificate, using a fixed fallback when parsing fails. |
| 17 | Correctness of the chosen solver and the fact that its output parses are |
| 18 | proved in the proof package. |
| 19 | -/ |
| 20 | |
| 21 | namespace Lax263307.RegisteredLP |
| 22 | |
| 23 | open Lax109476.LinearProgram Lax109476.RationalCertificates Lax109476.RationalEncoding |
| 24 | |
| 25 | def value (sign num den : ℕ) : ℚ := |
| 26 | if sign = 1 then -(num : ℚ) / den else (num : ℚ) / den |
| 27 | |
| 28 | def rational : List ℕ → Option (ℚ × List ℕ) |
| 29 | | sign :: num :: den :: rest => some (value sign num den, rest) |
| 30 | | _ => none |
| 31 | |
| 32 | def vector : ℕ → List ℕ → Option (List ℚ × List ℕ) |
| 33 | | 0, input => some ([], input) |
| 34 | | n + 1, input => (rational input).bind fun qr => |
| 35 | (vector n qr.2).map fun tail => (qr.1 :: tail.1, tail.2) |
| 36 | |
| 37 | def vectorFunction (n : ℕ) (input : List ℕ) : Option ((Fin n → ℚ) × List ℕ) := |
| 38 | (vector n input).map fun result => (fun i => result.1.getD i.val 0, result.2) |
| 39 | |
| 40 | def parse (m n : ℕ) : List ℕ → Option (Certificate m n × List ℕ) |
| 41 | | 0 :: rest => (vectorFunction n rest).bind fun zr => |
| 42 | (vectorFunction m zr.2).map fun yr => (.optimal zr.1 yr.1, yr.2) |
| 43 | | 1 :: rest => (vectorFunction m rest).map fun yr => (.infeasible yr.1, yr.2) |
| 44 | | 2 :: rest => (vectorFunction n rest).bind fun zr => |
| 45 | (vectorFunction n zr.2).map fun dr => (.unbounded zr.1 dr.1, dr.2) |
| 46 | | _ => none |
| 47 | |
| 48 | def certificate {m n : ℕ} (solve : List ℕ → List ℕ) (P : Program ℚ m n) : Certificate m n := |
| 49 | ((parse m n (solve (encodeProgram P))).map Prod.fst).getD (.infeasible 0) |
| 50 | |
| 51 | end Lax263307.RegisteredLP |
| 52 |
Formalization notes
The parser reads canonical sign-numerator-denominator triples and returns the unconsumed suffix. applies a supplied solver and returns the decoded certificate, using a fixed fallback when parsing fails. Correctness of the chosen solver and the fact that its output parses are proved in the proof package.
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments