Hitting Set

Lax496464.HittingSet · concepts/Lax496464/HittingSet.lean · lax-496464

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

    An instance consists of a universe {1,…,n}\{1, \dots, n\} and a family F1,…,FmF_1, \dots, F_m of subsets of it; together with an integer kk it asks whether some HH with ∣H∣=k|H| = k meets every set of the family. Hitting Set is the problem the hardness results of this submission reduce from, parameterized by the solution size kk.

    This is the problem [SP8] of Garey and Johnson. It contains Karp's Node Cover (problem 5 of his list) as the case of sets of size two. Karp's own Hitting Set (problem 15) is a different problem: it asks for a set meeting every member of the family in exactly one element.

    The instances considered here are those with 2≤k≤n2 \le k \le n. The lower bound is what the construction of the reduction needs, and the upper bound is a normalization: a hitting set of size exactly kk cannot exist once kk exceeds the universe. Neither restriction costs anything — see the statement of the problem's hardness.

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

    In the paper

    • page 7 of this submission's paper

    Lean source view on GitHub

    1import Lax496464.ParameterizedComplexity
    2import Lax434930.PolynomialTime
    3import Mathlib.Data.List.FinRange
    4import Mathlib.Data.Nat.Bits
    5
    6/-!
    7---
    8title: Hitting Set
    9type: definition
    10---
    11An instance consists of a universe {1,…,n}\{1, \dots, n\} and a family F1,…,FmF_1, \dots, F_m of
    12subsets of it; together with an integer kk it asks whether some HH with ∣H∣=k|H| = k meets
    13every set of the family. Hitting Set is the problem the hardness results of this
    14submission reduce from, parameterized by the solution size kk.
    15
    16This is the problem [SP8] of Garey and Johnson. It contains Karp's *Node Cover* (problem 5
    17of his list) as the case of sets of size two. Karp's own *Hitting Set* (problem 15) is a
    18different problem: it asks for a set meeting every member of the family in exactly one
    19element.
    20
    21The instances considered here are those with 2≤k≤n2 \le k \le n. The lower bound is what the
    22construction of the reduction needs, and the upper bound is a normalization: a hitting
    23set of size exactly kk cannot exist once kk exceeds the universe. Neither restriction
    24costs anything — see the statement of the problem's hardness.
    25
    26# Formalization Notes
    27
    28The family is presented to a machine in the compressed sparse row form that presents a
    29graph to a machine elsewhere in the archive: an array of m+1m+1 offsets cutting a member
    30array into one block per set. The blocks are not required to be sorted and repetitions
    31are not forbidden; leaving those conditions out admits more words and therefore
    32strengthens every claim about programs reading the format. The solution size is the final
    33entry, so that the family occupies the same offsets whether or not it is followed by one.
    34
    35The universe is `Fin n`, counted from zero where the paper counts from one. The
    36construction of the reduction uses an element as an additive offset inside a due date and
    37needs it to be at least one, so it adds one; that is a detail of the construction and not
    38of the problem.
    39
    40The required size is exact, ∣H∣=k|H| = k, as the paper writes it. For a nonempty universe
    41the exact and the "at most" versions are interchangeable, and the exact one is what the
    42construction's target is calibrated against.
    43
    44The universe is required to be no larger than the word: n≤∣x∣n \le |x|. Every reduction of this
    45submission writes an instance of size at least n2n^2, and a word states nn as a single
    46entry, so without the bound a word of five entries could name a universe of a billion
    47elements and no reduction could write its image in time bounded by the length of the word.
    48The bound costs nothing — an element occurring in no set can be deleted and the others
    49renumbered, and the reduction from satisfiability of `HittingSetFromSat` already emits
    50instances with n+mn + m polynomial in the size of its input — and it agrees with the
    51convention that every element of the universe occurs.
    52
    53The binary encoding exists beside the word encoding for the same reason as elsewhere: a
    54claim quantifying over NP is a claim about a Turing machine and hence about bits. It
    55writes the two counts and the solution size, and then each set as its size followed by its
    56members in increasing order. A number is written as its binary digits, least significant
    57first, preceded by their number in unary; that code is prefix-free, so the encoding is
    58injective. The language of Hitting Set is the set of binary words of the instances, with a
    59solution size, that have a hitting set of that size.
    60-/
    61
    62namespace Lax496464.HittingSet
    63
    64open Lax496464.ParameterizedComplexity Lax434930.PolynomialTime
    65
    66/-- An instance of Hitting Set: a universe `Fin n` and a family of `m` subsets of it. The
    67solution size is carried separately, as the parameter. -/
    68structure Instance where
    69 /-- The size `n` of the universe. -/
    70 n : ℕ
    71 /-- The number `m` of sets in the family. -/
    72 m : ℕ
    73 /-- The family `F₁, …, F_m`. -/
    74 F : Fin m → Finset (Fin n)
    75
    76/-- `P` has a hitting set of size exactly `k`. -/
    77def Instance.HasHittingSet (P : Instance) (k : ℕ) : Prop :=
    78 ∃ H : Finset (Fin P.n), H.card = k ∧ ∀ j : Fin P.m, ∃ i ∈ H, i ∈ P.F j
    79
    80/-- The size of the universe declared by a word: its first entry. -/
    81def universeSize (x : List ℕ) : ℕ := x.getD 0 0
    82
    83/-- The number of sets declared by a word: its second entry. -/
    84def setCount (x : List ℕ) : ℕ := x.getD 1 0
    85
    86/-- The `i`-th offset: the `m+1` offsets follow the two header entries. -/
    87def offset (x : List ℕ) (i : ℕ) : ℕ := x.getD (2 + i) 0
    88
    89/-- The `t`-th entry of the member array, which follows the offsets. -/
    90def member (x : List ℕ) (t : ℕ) : ℕ := x.getD (3 + setCount x + t) 0
    91
    92/-- The solution size `k`: the entry following the member array. -/
    93def solutionSize (x : List ℕ) : ℕ :=
    94 x.getD (3 + setCount x + offset x (setCount x)) 0
    95
    96/-- The word `x` encodes the instance `P` with solution size `k`. -/
    97structure Encodes (x : List ℕ) (P : Instance) (k : ℕ) : Prop where
    98 /-- The word declares `P`'s universe. -/
    99 universeSize_eq : universeSize x = P.n
    100 /-- The word declares `P`'s family. -/
    101 setCount_eq : setCount x = P.m
    102 /-- The word is the two header entries, the `m+1` offsets, a member array as long as
    103 the last offset says, and the solution size. -/
    104 length_eq : x.length = 4 + P.m + offset x P.m
    105 /-- The block of the first set begins at the start of the member array. -/
    106 offset_zero : offset x 0 = 0
    107 /-- The offsets are nondecreasing, so they cut the member array into one block per
    108 set. -/
    109 offset_mono : ∀ j < P.m, offset x j ≤ offset x (j + 1)
    110 /-- Every entry of the member array is an element of the universe. -/
    111 member_lt : ∀ t < offset x P.m, member x t < P.n
    112 /-- The block of a set lists exactly its elements. -/
    113 mem_iff : ∀ (j : Fin P.m) (i : Fin P.n),
    114 i ∈ P.F j ↔ ∃ t, offset x j ≤ t ∧ t < offset x (j + 1) ∧ member x t = i
    115 /-- The word declares the solution size. -/
    116 solutionSize_eq : solutionSize x = k
    117 /-- The solution size is at least two and at most the size of the universe. -/
    118 size_bounds : 2 ≤ k ∧ k ≤ P.n
    119 /-- The universe is no larger than the word that presents it. -/
    120 universeSize_le : P.n ≤ x.length
    121
    122/-- The words that encode an instance with its solution size. -/
    123def Instances : Set (List ℕ) := {x | ∃ P k, Encodes x P k}
    124
    125/-- **Hitting Set**, parameterized by the solution size. -/
    126def byK : Problem where
    127 Domain := Instances
    128 Yes x := ∃ P k, Encodes x P k ∧ Instance.HasHittingSet P k
    129 param x := solutionSize x
    130
    131/-- The elements of the `j`-th set, in the order of the universe. -/
    132def Instance.members (P : Instance) (j : Fin P.m) : List (Fin P.n) :=
    133 (List.finRange P.n).filter fun i => decide (i ∈ P.F j)
    134
    135/-- A natural number as a binary word: its digits, least significant first, preceded by
    136their number in unary. -/
    137def encodeNat (n : ℕ) : Word :=
    138 List.replicate n.bits.length true ++ [false] ++ n.bits
    139
    140/-- An instance with its solution size as a binary word: the two counts, the solution
    141size, and then each set as its size followed by its members. -/
    142def encodeInstance (P : Instance) (k : ℕ) : Word :=
    143 encodeNat P.n ++ encodeNat P.m ++ encodeNat k ++
    144 (List.finRange P.m).flatMap fun j =>
    145 encodeNat (P.F j).card ++ (P.members j).flatMap fun i => encodeNat i
    146
    147/-- **Hitting Set** as a language: the binary words of the instances, with a solution size,
    148that have a hitting set of that size. -/
    149def HittingSetLanguage : Language :=
    150 {w | ∃ (P : Instance) (k : ℕ), encodeInstance P k = w ∧ P.HasHittingSet k}
    151
    152end Lax496464.HittingSet
    153
    Formalization Notes

    The family is presented to a machine in the compressed sparse row form that presents a graph to a machine elsewhere in the archive: an array of m+1m+1 offsets cutting a member array into one block per set. The blocks are not required to be sorted and repetitions are not forbidden; leaving those conditions out admits more words and therefore strengthens every claim about programs reading the format. The solution size is the final entry, so that the family occupies the same offsets whether or not it is followed by one.

    The universe is FinnFin n, counted from zero where the paper counts from one. The construction of the reduction uses an element as an additive offset inside a due date and needs it to be at least one, so it adds one; that is a detail of the construction and not of the problem.

    The required size is exact, ∣H∣=k|H| = k, as the paper writes it. For a nonempty universe the exact and the "at most" versions are interchangeable, and the exact one is what the construction's target is calibrated against.

    The universe is required to be no larger than the word: n≤∣x∣n \le |x|. Every reduction of this submission writes an instance of size at least n2n^2, and a word states nn as a single entry, so without the bound a word of five entries could name a universe of a billion elements and no reduction could write its image in time bounded by the length of the word. The bound costs nothing — an element occurring in no set can be deleted and the others renumbered, and the reduction from satisfiability of HittingSetFromSatHittingSetFromSat already emits instances with n+mn + m polynomial in the size of its input — and it agrees with the convention that every element of the universe occurs.

    The binary encoding exists beside the word encoding for the same reason as elsewhere: a claim quantifying over NP is a claim about a Turing machine and hence about bits. It writes the two counts and the solution size, and then each set as its size followed by its members in increasing order. A number is written as its binary digits, least significant first, preceded by their number in unary; that code is prefix-free, so the encoding is injective. The language of Hitting Set is the set of binary words of the instances, with a solution size, that have a hitting set of that size.

    Discussion

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

    Loading discussion…