Binary-size encoding of rational linear programs
Lax109476.RationalEncoding · concepts/Lax109476/RationalEncoding.lean · lax-109476
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
An LP input word begins with its number of inequalities and variables , followed by the matrix in row order, the vector , and the vector . A rational is encoded by its numerator sign, numerator magnitude, and positive denominator, in reduced form. Solution words begin with an outcome tag and contain the corresponding rational certificate coordinates.
Concept map
Lean source view on GitHub
| 1 | import Lax109476.RationalCertificates |
| 2 | import Lax759944.RamPolytime |
| 3 | |
| 4 | /-! |
| 5 | --- |
| 6 | title: Binary-size encoding of rational linear programs |
| 7 | type: definition |
| 8 | --- |
| 9 | An LP input word begins with its number of inequalities and variables |
| 10 | , followed by the matrix in row order, the vector , and the vector . |
| 11 | A rational is encoded by its numerator sign, numerator magnitude, and |
| 12 | positive denominator, in reduced form. Solution words begin with an outcome |
| 13 | tag and contain the corresponding rational certificate coordinates. |
| 14 | |
| 15 | # Formalization notes |
| 16 | |
| 17 | The input sign is zero for nonnegative numerators and one for negative |
| 18 | numerators. Output tags zero, one, and two mean optimal, infeasible, and |
| 19 | unbounded. Dimensions are supplied by the input, so witness vectors have |
| 20 | fixed known lengths. Each rational keeps its exact denominator. |
| 21 | |
| 22 | The imported `RamPolytime` predicate uses binary word-list size, a single |
| 23 | uniform program, polynomial bounds on sufficient word length and executed |
| 24 | instructions, and correctness at every sufficiently large word length on |
| 25 | Lax808846's registered RAM. Its specified physical tape is length-prefixed. |
| 26 | Malformed logical inputs have no prescribed output, but the solver function |
| 27 | is total. No new machine model or abstract running-time annotation is introduced. |
| 28 | -/ |
| 29 | |
| 30 | namespace Lax109476.RationalEncoding |
| 31 | |
| 32 | open Lax109476.LinearProgram Lax109476.RationalCertificates |
| 33 | |
| 34 | /-- Encode a reduced rational by sign, magnitude, and denominator. -/ |
| 35 | def encodeRational (q : ℚ) : List ℕ := |
| 36 | [if q.num < 0 then 1 else 0, q.num.natAbs, q.den] |
| 37 | |
| 38 | /-- Encode all coordinates of a rational vector in index order. -/ |
| 39 | def encodeVector {n : ℕ} (x : Fin n → ℚ) : List ℕ := |
| 40 | (List.ofFn x).flatMap encodeRational |
| 41 | |
| 42 | /-- Encode dimensions, row-major coefficients, row bounds, and objective. -/ |
| 43 | def encodeProgram {m n : ℕ} (P : Program ℚ m n) : List ℕ := |
| 44 | [m, n] ++ (List.ofFn fun i => List.ofFn (P.A i)).flatten.flatMap encodeRational ++ |
| 45 | encodeVector P.b ++ encodeVector P.c |
| 46 | |
| 47 | /-- Encode the outcome tag and all rational certificate coordinates. -/ |
| 48 | def encodeCertificate {m n : ℕ} : Certificate m n → List ℕ |
| 49 | | .optimal x y => [0] ++ encodeVector x ++ encodeVector y |
| 50 | | .infeasible y => [1] ++ encodeVector y |
| 51 | | .unbounded x d => [2] ++ encodeVector x ++ encodeVector d |
| 52 | |
| 53 | end Lax109476.RationalEncoding |
| 54 |
Formalization notes
The input sign is zero for nonnegative numerators and one for negative numerators. Output tags zero, one, and two mean optimal, infeasible, and unbounded. Dimensions are supplied by the input, so witness vectors have fixed known lengths. Each rational keeps its exact denominator.
The imported predicate uses binary word-list size, a single uniform program, polynomial bounds on sufficient word length and executed instructions, and correctness at every sufficiently large word length on Lax808846's registered RAM. Its specified physical tape is length-prefixed. Malformed logical inputs have no prescribed output, but the solver function is total. No new machine model or abstract running-time annotation is introduced.
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments