Documentation

CslibFrontier.Computability.Complexity.Problems.TwoSAT.Layout

The layout of encoded formulas #

A formula is encoded (Cslib.Complexity.encCNF) by three levels of framed lists: the clauses, their literals, and the binary digits of each variable followed by the polarity. Unfolding the frames gives a flat layout (Cslib.Complexity.TwoSAT.encCNF_eq_flatMap): each clause is the bits of its literals followed by false, and a literal (v, b) is a group of eight bits for each binary digit d of v, seven markers true followed by d, then the ten bits [true, true, true, false, true, true, true, b, true, false] (Cslib.Complexity.TwoSAT.literalBits). A machine reading the encoding by position can thus tell a literal from the end of its clause by the first bit, a digit from the end of the variable by the fourth bit of a group, and read the digit or the polarity from the eighth.

The positions are handled with Cslib.Complexity.TwoSAT.InfixAt w p u, which says that the word u occurs in w at position p.

Main definitions #

Main results #

The bits of a literal (v, b) in an encoded formula: the binary digits of v, each after seven markers, then the end of the digits, the polarity and the end of the literal.

Instances For

    The bits of a clause in an encoded formula: its literals, then false.

    Instances For

      The flat layout of an encoded formula.

      Positions #

      The word u occurs in w at the position p.

      Instances For
        theorem Cslib.Complexity.TwoSAT.InfixAt.append {w u v : List Bool} {p : ℕ} :
        InfixAt w p (u ++ v) ↔ InfixAt w p u ∧ InfixAt w (p + u.length) v
        theorem Cslib.Complexity.TwoSAT.InfixAt.flatMap {w : List Bool} {p : ℕ} {α : Type u_1} {L : List α} {f : α → List Bool} (h : InfixAt w p (List.flatMap f L)) {i : ℕ} (hi : i < L.length) :
        InfixAt w (p + (List.map (fun (a : α) => (f a).length) (List.take i L)).sum) (f L[i])

        The word of an element of a list, in the concatenation of the words of the elements.

        theorem Cslib.Complexity.TwoSAT.InfixAt.getElem? {w u : List Bool} {p : ℕ} (h : InfixAt w p u) {q : ℕ} (hq : q < u.length) :
        w[p + q]? = u[q]?

        The bit at an offset.

        theorem Cslib.Complexity.TwoSAT.InfixAt.literal_digit {w : List Bool} {p v : ℕ} {b : Bool} (h : InfixAt w p (literalBits v b)) {k : ℕ} (hk : k < v.bits.length) :
        w[p + 8 * k]? = some true ∧ w[p + 8 * k + 3]? = some true ∧ w[p + 8 * k + 7]? = some v.bits[k]

        A digit of a literal: the group of the digit k of v starts at 8 * k, its fourth bit is a marker and its eighth bit is the digit.

        theorem Cslib.Complexity.TwoSAT.InfixAt.literal_end {w : List Bool} {p v : ℕ} {b : Bool} (h : InfixAt w p (literalBits v b)) :

        The end of a literal: after the groups of the digits, the fourth bit is false and the eighth bit is the polarity; the literal ends ten bits after the digits.

        theorem Cslib.Complexity.TwoSAT.InfixAt.clause_literal {w : List Bool} {p : ℕ} {c : Logic.PL.Clause ℕ} (h : InfixAt w p (clauseBits c)) {j : ℕ} (hj : j < List.length c) :
        InfixAt w (p + (List.map (fun (l : Logic.PL.Literal ℕ) => (literalBits l.1 l.2).length) (List.take j c)).sum) (literalBits c[j].1 c[j].2)

        A literal of a clause, at the offset of the literals before it.

        The end of a clause: false after all its literals.

        The position of the clause i in an encoded formula.

        Instances For

          The clauses of an encoded formula, at their positions.

          The encoding ends after the last clause.

          The clause i + 1 starts after the clause i.

          theorem Cslib.Complexity.TwoSAT.InfixAt.le_length {w u : List Bool} {p : ℕ} (h : InfixAt w p u) (hu : u ≠ []) :

          A nonempty word occurring in w ends within w.

          A literal starts with a marker.

          The literals ls occur at the position p, followed by the end of their clause.

          Instances For

            The end of a clause is false.

            theorem Cslib.Complexity.TwoSAT.LitsAt.cons {w : List Bool} {p : ℕ} {l : Logic.PL.Literal ℕ} {ls : Logic.PL.Clause ℕ} (h : LitsAt w p (l :: ls)) :
            InfixAt w p (literalBits l.1 l.2) ∧ LitsAt w (p + (literalBits l.1 l.2).length) ls

            A literal, then the rest of the clause.

            theorem Cslib.Complexity.TwoSAT.LitsAt.le_length {w : List Bool} {p : ℕ} {ls : Logic.PL.Clause ℕ} (h : LitsAt w p ls) :
            p + (List.flatMap (fun (l : Logic.PL.Literal ℕ) => literalBits l.1 l.2) ls).length + 1 ≤ w.length

            A clause ends within the word.

            The clauses cs occur at the position p, up to the end of the word.

            Instances For

              The word ends after the clauses.

              A clause, then the rest.

              The clauses of an encoded formula occur from its start.

              theorem Cslib.Complexity.TwoSAT.set_getD_self {regs : List ℕ} {i : ℕ} (hi : i < regs.length) :
              regs.set i (regs.getD i 0) = regs

              Overwriting a register with its own value changes nothing.