Decoding rational LP certificates

Lax263307.RegisteredLP · concepts/Lax263307/RegisteredLP.lean · lax-263307

definition

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Natural 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
    10 concepts; 3 descendants hidden
    100%
    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Lean source view on GitHub

    1import Lax109476.PolynomialTimeSolver
    2
    3/-!
    4---
    5title: Decoding rational LP certificates
    6type: definition
    7---
    8Decode the tagged certificate produced by the registered rational LP
    9solver: an optimal primal-dual pair, an infeasibility certificate, or an
    10unboundedness certificate.
    11
    12# Formalization notes
    13
    14The parser reads canonical sign-numerator-denominator triples and returns
    15the unconsumed suffix. `certificate` applies a supplied solver and returns
    16the decoded certificate, using a fixed fallback when parsing fails.
    17Correctness of the chosen solver and the fact that its output parses are
    18proved in the proof package.
    19-/
    20
    21namespace Lax263307.RegisteredLP
    22
    23open Lax109476.LinearProgram Lax109476.RationalCertificates Lax109476.RationalEncoding
    24
    25def value (sign num den : ℕ) : ℚ :=
    26 if sign = 1 then -(num : ℚ) / den else (num : ℚ) / den
    27
    28def rational : List ℕ → Option (ℚ × List ℕ)
    29 | sign :: num :: den :: rest => some (value sign num den, rest)
    30 | _ => none
    31
    32def 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
    37def 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
    40def 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
    48def 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
    51end Lax263307.RegisteredLP
    52
    Formalization notes

    The parser reads canonical sign-numerator-denominator triples and returns the unconsumed suffix. certificatecertificate 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.

    Loading discussion…