Binary encodings of graphs and positive CNF formulas

Lax689614.Encoding · concepts/Lax689614/Encoding.lean · lax-689614

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

    A graph on nn labeled vertices is encoded by 1n01^n0 followed by its n×nn\times n adjacency matrix in row order. A formula on nn variables with mm clauses is encoded by 1n01m01^n0\,1^m0 followed by the m×nm\times n clause-variable incidence matrix in row order. These encodings retain isolated vertices, unused variables, empty clauses, and repeated clauses. Malformed strings are excluded from the associated languages.

    Concept map
    4 concepts; 6 descendants hidden
    100%
    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Lean source view on GitHub

    1import Lax689614.ArcKayles
    2import Lax689614.PositiveCNF
    3import Lax434930.PolynomialTime
    4
    5/-!
    6---
    7title: Binary encodings of graphs and positive CNF formulas
    8type: definition
    9---
    10A graph on nn labeled vertices is encoded by 1n01^n0 followed by its
    11n×nn\times n adjacency matrix in row order. A formula on nn variables
    12with mm clauses is encoded by 1n01m01^n0\,1^m0 followed by the m×nm\times n
    13clause-variable incidence matrix in row order. These encodings retain
    14isolated vertices, unused variables, empty clauses, and repeated clauses.
    15Malformed strings are excluded from the associated languages.
    16-/
    17
    18namespace Lax689614.Encoding
    19
    20open Lax434930.PolynomialTime
    21
    22structure Graph where
    23 vertices : ℕ
    24 graph : SimpleGraph (Fin vertices)
    25
    26noncomputable def graphWord (G : Graph) : Word := by
    27 classical
    28 exact List.replicate G.vertices true ++ [false] ++
    29 (List.finRange G.vertices).flatMap fun u =>
    30 (List.finRange G.vertices).map fun v => decide (G.graph.Adj u v)
    31
    32def formulaWord (φ : PositiveCNF.Formula) : Word :=
    33 List.replicate φ.nvars true ++ [false] ++
    34 List.replicate φ.clauses.length true ++ [false] ++
    35 φ.clauses.flatMap fun C =>
    36 (List.finRange φ.nvars).map fun x => decide (x ∈ C)
    37
    38def arcKayles : Language :=
    39 {w | ∃ G : Graph, graphWord G = w ∧ ArcKayles.Winning G.graph Finset.univ}
    40
    41def positiveCNF : Language :=
    42 {w | ∃ φ : PositiveCNF.Formula, formulaWord φ = w ∧ PositiveCNF.FirstWins φ}
    43
    44end Lax689614.Encoding
    45

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above.

    Loading discussion…