Documentation

Complexity.Foundations.Data.BitString.Threshold

Threshold, majority and symmetric Boolean functions #

The threshold function threshold n j says that at least j of n bits are true, and majority (majority, at least half) and strict majority (strictMajority, more than half) are threshold functions. On an arbitrary finite set of voting indices, BitString.strictMajorityOn chooses false on a tie. A Boolean function is symmetric when it depends only on the weight of its input (BooleanFunction.IsSymmetric), and then it factors through the weight (BooleanFunction.IsSymmetric.exists_eq_comp_weight) Jukna, Chapter 1.

Main definitions #

Main results #

References #

def Cslib.BitString.strictMajorityOn {ι : Type u_1} (s : Finset ι) (vote : ι → Bool) :

Strict majority of the coordinates in s, choosing false on a tie.

Instances For
    theorem Cslib.BitString.card_filter_eq_le_half_of_strictMajorityOn_ne {ι : Type u_1} (s : Finset ι) (vote : ι → Bool) (bit : Bool) (h : strictMajorityOn s vote ≠ bit) :
    {i ∈ s | vote i = bit}.card ≤ s.card / 2

    If strict majority is wrong, at most half of the votes are correct.

    @[simp]
    theorem Cslib.BitString.strictMajorityOn_const {ι : Type u_1} (s : Finset ι) (hs : s.Nonempty) (bit : Bool) :
    (strictMajorityOn s fun (x : ι) => bit) = bit

    A nonempty constant vote has its constant value.

    The threshold function Th^n_j on n bits: whether at least j of them are true.

    Instances For

      The majority function on n bits: whether at least half of them are true, that is, the threshold function Th^n_⌈n/2⌉.

      Instances For

        The strict majority function on n bits: whether more than half of them are true, so that a tie is false. It is the threshold function Th^n_{⌊n/2⌋+1}.

        Instances For
          theorem Cslib.threshold_apply {n : ℕ} (j : ℕ) (x : BitString n) :

          threshold n j x is the decision of j ≤ weight x.

          The threshold function Th^n_j is true exactly when at least j bits are true.

          Threshold functions are monotone.

          @[simp]

          With cutoff 0, the threshold function is the constant true.

          theorem Cslib.threshold_eq_false_of_lt {n j : ℕ} (h : n < j) (x : BitString n) :

          With a cutoff above n, the threshold function is the constant false.

          theorem Cslib.threshold_one_right {n : ℕ} (x : BitString n) :
          threshold n 1 x = decide (∃ (i : Fin n), x i = true)

          With cutoff 1, the threshold function is the disjunction.

          theorem Cslib.threshold_self {n : ℕ} (x : BitString n) :
          threshold n n x = decide (∀ (i : Fin n), x i = true)

          With cutoff n, the threshold function is the conjunction.

          Majority is true exactly when at least ⌈n/2⌉ = (n + 1) / 2 bits are true.

          Strict majority is true exactly when more than n / 2 bits are true.

          Strict majority is false exactly when at most n / 2 bits are true.

          Strict majority on all coordinates agrees with the finite-set operation.

          theorem Cslib.le_card_ne_of_strictMajority_ne {n : ℕ} {x : BitString n} {y : Bool} (h : strictMajority n x ≠ y) :
          n - n / 2 ≤ {i : Fin n | x i ≠ y}.card

          If the strict majority of n bits is not y, at least n - n / 2 differ from y.

          theorem Cslib.strictMajority_not {n : ℕ} (x : BitString n) :
          (strictMajority n fun (i : Fin n) => !x i) = !majority n x

          Strict majority of the negated bits is the negation of majority: fewer than half of the bits are true exactly when not at least half of them are.

          A Boolean function is symmetric when it depends only on the weight of its input.

          Instances For
            theorem Cslib.BooleanFunction.IsSymmetric.exists_eq_comp_weight {n : ℕ} {f : BooleanFunction n} (hf : f.IsSymmetric) :
            ∃ (a : ℕ → Bool), ∀ (x : Fin n → Bool), a (BitString.weight x) = f x

            A symmetric function factors through the weight.

            Threshold functions are symmetric.

            Majority is symmetric.

            Strict majority is symmetric.