Documentation

CslibFrontier.Computability.PropertyTesting.Monotonicity.Basic

Violated edges and the distance to monotone Boolean functions #

A Boolean function f : (ι → Bool) → Bool on the cube is monotone (Mathlib's Monotone, for the coordinatewise order with false < true) exactly when it does not decrease along any edge of the cube, the edge in direction i joining update x i false to update x i true (BitString.monotone_iff_forall_update_le). The violated edges of f in direction i (BitString.violatedEdges f i) are those along which f decreases, listed by their lower endpoints; f is monotone exactly when it has none (monotone_iff_forall_violatedEdges_eq_empty). BitString.distMonotone f is the least Hamming distance from f to a monotone function, and BitString.relDistMonotone f that distance divided by the 2 ^ n points of the cube, n being the number of coordinates; f is ε-far from monotone in the sense of Goldreich, Goldwasser, Lehman, Ron and Samorodnitsky when ε ≤ relDistMonotone f (BitString.le_relDistMonotone_iff).

BitString.sortAlong i f sorts the values of f along every edge in direction i: the lower endpoint gets the smaller value and the upper endpoint the larger. This is the operator that swaps the values at the endpoints of every violated edge of the i-th slice Roughgarden, §8.3.1. It changes f at exactly the 2 |A_i| endpoints of the violated edges in direction i (BitString.hammingDist_sortAlong), it leaves none in that direction (BitString.violatedEdges_sortAlong_self), and, the Key Claim of the source's proof, it does not increase the number of violated edges in any direction (BitString.card_violatedEdges_sortAlong_le). Its proof compares, on every square spanned by the directions i and j, the violations of the two j-edges before and after sorting along i; this is a check of the 16 labellings of the square. Sorting along every direction in turn therefore gives a monotone function within Hamming distance 2 Σ_i |A_i| of f (BitString.exists_monotone_hammingDist_le, BitString.distMonotone_le_two_mul_sum). Conversely every violated edge has an endpoint on which f differs from a nearest monotone function, and the violated edges in one direction are disjoint, so |A_i| ≤ distMonotone f (BitString.card_violatedEdges_le_distMonotone).

Normalized by the n 2 ^ (n - 1) edges of the cube (BitString.violatedEdgeFraction), this is the combinatorial core of the edge tester's analysis Roughgarden, Theorem 8.2: the relative distance to monotone is at most n times the fraction of violated edges (BitString.relDistMonotone_le_card_mul_violatedEdgeFraction), so a function ε-far from monotone has at least an ε / n fraction of violated edges (BitString.div_card_le_violatedEdgeFraction). The tester itself is in CslibFrontier.Computability.PropertyTesting.Monotonicity.EdgeTester.

The results are stated for any finite index type ι, in particular for Fin n.

Main definitions #

Main results #

References #

Monotonicity along edges #

theorem Cslib.BitString.monotone_iff_forall_update_le {ι : Type u_1} [Finite ι] [DecidableEq ι] {β : Type u_2} [Preorder β] {f : (ι → Bool) → β} :
Monotone f ↔ ∀ (x : ι → Bool) (i : ι), f (Function.update x i false) ≤ f (Function.update x i true)

A function on a finite cube is monotone exactly when it does not decrease along any edge: for every point x and direction i, its value at update x i false is at most its value at update x i true.

Violated edges #

def Cslib.BitString.violatedEdges {ι : Type u_1} [DecidableEq ι] [Fintype ι] (f : (ι → Bool) → Bool) (i : ι) :
Finset (ι → Bool)

The violated edges of f in direction i, listed by their lower endpoints: the points x with x i = false such that f x = true and f (update x i true) = false. The edges in direction i are the 2 ^ (n - 1) pairs (x, update x i true) with x i = false.

theorem Cslib.BitString.mem_violatedEdges {ι : Type u_1} [DecidableEq ι] [Fintype ι] {f : (ι → Bool) → Bool} {i : ι} {x : ι → Bool} :
theorem Cslib.BitString.monotone_iff_forall_violatedEdges_eq_empty {ι : Type u_1} [DecidableEq ι] [Fintype ι] {f : (ι → Bool) → Bool} :
Monotone f ↔ ∀ (i : ι), violatedEdges f i = ∅

A Boolean function is monotone exactly when it has no violated edge in any direction.

Sorting along a direction #

def Cslib.BitString.sortAlong {ι : Type u_1} [DecidableEq ι] (i : ι) (f : (ι → Bool) → Bool) (x : ι → Bool) :

Sorting along direction i: on every edge in direction i, the lower endpoint gets the smaller and the upper endpoint the larger of the two values of f. On a violated edge this swaps the two values, and elsewhere it changes nothing Roughgarden, §8.3.1.

@[simp]
theorem Cslib.BitString.sortAlong_update_false {ι : Type u_1} [DecidableEq ι] (i : ι) (f : (ι → Bool) → Bool) (x : ι → Bool) :

At the lower endpoint of an edge, sorting takes the smaller value.

@[simp]
theorem Cslib.BitString.sortAlong_update_true {ι : Type u_1} [DecidableEq ι] (i : ι) (f : (ι → Bool) → Bool) (x : ι → Bool) :

At the upper endpoint of an edge, sorting takes the larger value.

theorem Cslib.BitString.card_endpoints_violatedEdges {ι : Type u_1} [DecidableEq ι] [Fintype ι] (f : (ι → Bool) → Bool) (i : ι) :

The endpoints of the violated edges in direction i, the points x such that f decreases along the edge in direction i through x, number 2 |A_i|.

theorem Cslib.BitString.hammingDist_sortAlong {ι : Type u_1} [DecidableEq ι] [Fintype ι] (f : (ι → Bool) → Bool) (i : ι) :

Sorting along i changes f at exactly the 2 |A_i| endpoints of its violated edges in direction i.

theorem Cslib.BitString.violatedEdges_sortAlong_self {ι : Type u_1} [DecidableEq ι] [Fintype ι] (f : (ι → Bool) → Bool) (i : ι) :

After sorting along i, no edge in direction i is violated.

theorem Cslib.BitString.card_violatedEdges_sortAlong_le {ι : Type u_1} [DecidableEq ι] [Fintype ι] (f : (ι → Bool) → Bool) (i j : ι) :

The Key Claim Roughgarden, §8.3.1: sorting along any direction i does not increase the number of violated edges in any direction j.

theorem Cslib.BitString.violatedEdges_sortAlong_eq_empty {ι : Type u_1} [DecidableEq ι] [Fintype ι] {f : (ι → Bool) → Bool} {j : ι} (h : violatedEdges f j = ∅) (i : ι) :

Sorting along one direction keeps every direction without violated edges free of them; in particular it keeps a monotone function monotone.

theorem Cslib.BitString.exists_monotone_hammingDist_le {ι : Type u_1} [DecidableEq ι] [Fintype ι] (f : (ι → Bool) → Bool) :
∃ (g : (ι → Bool) → Bool), Monotone g ∧ hammingDist f g ≤ 2 * ∑ i : ι, (violatedEdges f i).card

Every Boolean function is within 2 Σ_i |A_i| of a monotone function, where A_i are its violated edges in direction i Roughgarden, proof of Theorem 8.2: sort along every direction in turn.

Distance to monotone #

noncomputable def Cslib.BitString.distMonotone {ι : Type u_1} [DecidableEq ι] [Fintype ι] (f : (ι → Bool) → Bool) :

The distance to monotone of f: the least Hamming distance from f to a monotone Boolean function, that is, the least number of points at which f must be changed to make it monotone.

theorem Cslib.BitString.distMonotone_le {ι : Type u_1} [DecidableEq ι] [Fintype ι] {f g : (ι → Bool) → Bool} (hg : Monotone g) :

The distance to monotone is at most the distance to any monotone function.

theorem Cslib.BitString.exists_monotone_hammingDist_eq_distMonotone {ι : Type u_1} [DecidableEq ι] [Fintype ι] (f : (ι → Bool) → Bool) :
∃ (g : (ι → Bool) → Bool), Monotone g ∧ hammingDist f g = distMonotone f

The distance to monotone is attained by a monotone function.

theorem Cslib.BitString.distMonotone_eq_zero_iff {ι : Type u_1} [DecidableEq ι] [Fintype ι] {f : (ι → Bool) → Bool} :

The distance to monotone vanishes exactly on monotone functions.

theorem Cslib.BitString.distMonotone_le_two_mul_sum {ι : Type u_1} [DecidableEq ι] [Fintype ι] (f : (ι → Bool) → Bool) :
distMonotone f ≤ 2 * ∑ i : ι, (violatedEdges f i).card

The distance to monotone is at most twice the number of violated edges.

theorem Cslib.BitString.card_violatedEdges_le_hammingDist_of_forall_update_le {ι : Type u_1} [DecidableEq ι] [Fintype ι] {f g : (ι → Bool) → Bool} {i : ι} (hg : ∀ (x : ι → Bool), g (Function.update x i false) ≤ g (Function.update x i true)) :

Every violated i-edge of f contributes a distinct disagreement with any function g that is nondecreasing along direction i.

theorem Cslib.BitString.card_violatedEdges_le_distMonotone {ι : Type u_1} [DecidableEq ι] [Fintype ι] (f : (ι → Bool) → Bool) (i : ι) :

Every violated edge has an endpoint on which f differs from a nearest monotone function, and the violated edges in one direction are disjoint, so |A_i| ≤ distMonotone f.

noncomputable def Cslib.BitString.relDistMonotone {ι : Type u_1} [DecidableEq ι] [Fintype ι] (f : (ι → Bool) → Bool) :

The relative distance to monotone of f: the distance to monotone divided by the 2 ^ n points of the cube. A function is ε-far from monotone when ε ≤ relDistMonotone f.

theorem Cslib.BitString.le_relDistMonotone_iff {ι : Type u_1} [DecidableEq ι] [Fintype ι] {f : (ι → Bool) → Bool} {ε : ℝ} :
ε ≤ relDistMonotone f ↔ ∀ (g : (ι → Bool) → Bool), Monotone g → ε ≤ ↑(hammingDist f g) / 2 ^ Fintype.card ι

ε ≤ relDistMonotone f says that f is ε-far from monotone: every monotone function differs from f on at least an ε fraction of the cube.

theorem Cslib.BitString.relDistMonotone_of_monotone {ι : Type u_1} [DecidableEq ι] [Fintype ι] {f : (ι → Bool) → Bool} (hf : Monotone f) :

Monotone functions are at relative distance 0 from monotone.

The fraction of violated edges #

noncomputable def Cslib.BitString.violatedEdgeFraction {ι : Type u_1} [DecidableEq ι] [Fintype ι] (f : (ι → Bool) → Bool) :

The fraction of violated edges of f: the number of violated edges divided by the n 2 ^ (n - 1) edges of the cube, written 2 Σ_i |A_i| / (n 2 ^ n). It is 0 for n = 0.

theorem Cslib.BitString.violatedEdgeFraction_eq {ι : Type u_1} [DecidableEq ι] [Fintype ι] (f : (ι → Bool) → Bool) :
violatedEdgeFraction f = (2 * ∑ i : ι, ↑(violatedEdges f i).card) / (↑(Fintype.card ι) * 2 ^ Fintype.card ι)

The relative distance to monotone is at most n times the fraction of violated edges Roughgarden, proof of Theorem 8.2.

theorem Cslib.BitString.div_card_le_violatedEdgeFraction {ι : Type u_1} [DecidableEq ι] [Fintype ι] {f : (ι → Bool) → Bool} {ε : ℝ} (hε : ε ≤ relDistMonotone f) :

An ε-far function has at least an ε / n fraction of violated edges Roughgarden, proof of Theorem 8.2. For n = 0 both sides are 0.