Documentation

CslibFrontier.Computability.PropertyTesting.DenseGraph.Basic

Property testing in the dense graph model #

In the dense graph model of Goldreich, Goldwasser and Ron a tester for graphs on the vertex set Fin n accesses the graph only through its adjacency matrix: it asks whether two vertices are adjacent and receives one bit Goldreich, Chapter 8. Here a tester is a probabilistic oracle program (Tester n, a ProbOracleComp) that tosses private coins and asks vertex-pair queries adaptively; it runs against the deterministic adjacency oracle of the graph (adjOracle), and acceptProb T G is the probability that it outputs true.

The distance between two graphs on the same finite vertex set is the number of vertex pairs on which they differ (editDist, the number of edges of their symmetric difference). A graph is ε-far from a property P when every graph with property P differs from it in more than ε n² pairs (IsFar). Goldreich normalizes by the n² ordered entries of the adjacency matrix, each changed pair accounting for two entries, so his distance ε corresponds to IsFar G P (ε / 2) here. A one-sided tester (IsOneSidedTester) makes at most q queries on every run, accepts every graph with the property with probability one and accepts every ε-far graph with probability at most 1 / 3; a family of properties is OneSidedTestable with query bound q if every proximity ε > 0 and every number of vertices admits a one-sided tester with q ε queries, independent of n. Goldreich restricts property testing to graph properties that are invariant under graph isomorphism. The definitions IsOneSidedTester and OneSidedTestable here do not require isomorphism invariance, allowing arbitrary predicates P : SimpleGraph (Fin n) → Prop; this is a harmless generalization that specializes to isomorphism-invariant properties.

The far notion is related to Mathlib's deletion distance: an ε-far graph is ε n²-delete-far (IsFar.deleteFar), in particular ε-far from triangle-free in the sense of SimpleGraph.FarFromTriangleFree (IsFar.farFromTriangleFree); conversely, for a property that is closed under taking subgraphs, deletion distance more than ε n² implies ε-far (isFar_of_deleteFar, isFar_of_farFromTriangleFree).

Repetition (OracleComp.repeatAll) runs independent copies of a tester and accepts when all of them accept; its acceptance probability is the power of the single-run acceptance probability (acceptProb_repeatAll). This turns a perfectly complete q-query test that rejects far graphs with probability at least δ into a one-sided tester after k runs with 2 ≤ δ k (isOneSidedTester_repeatAll).

This file bounds queries only; it makes no claim about running time.

Main definitions #

Main results #

References #

@[reducible, inline]

Vertex-pair queries: the query (u, v) is answered by one bit, whether u and v are adjacent.

@[reducible, inline]

A tester for graphs on Fin n: a probabilistic oracle program that asks vertex-pair queries and outputs true (accept) or false (reject).

noncomputable def Cslib.DenseGraphTesting.adjOracle {V : Type} (G : SimpleGraph V) (q : V × V) :

The adjacency oracle of a graph: it answers the query (u, v) deterministically with whether u and v are adjacent.

noncomputable def Cslib.DenseGraphTesting.acceptProb {n : ℕ} (T : Tester n) (G : SimpleGraph (Fin n)) :

The probability that the tester T accepts the graph G, with its coins uniform and its queries answered by the adjacency oracle of G.

The adjacency oracle answers the query (u, v) with the adjacency bit.

noncomputable def Cslib.DenseGraphTesting.editDist {V : Type u_1} [Finite V] (G H : SimpleGraph V) :

The edit distance of two graphs on the same finite vertex set: the number of vertex pairs that are an edge of exactly one of them. The finite vertex type ensures that Nat.card counts differing pairs rather than returning 0 on an infinite symmetric difference.

def Cslib.DenseGraphTesting.IsFar {V : Type u_1} [Fintype V] (G : SimpleGraph V) (P : SimpleGraph V → Prop) (ε : ℝ) :

G is ε-far from the property P: every graph with property P differs from G in more than ε n² vertex pairs, where n is the number of vertices.

structure Cslib.DenseGraphTesting.IsOneSidedTester {n : ℕ} (T : Tester n) (P : SimpleGraph (Fin n) → Prop) (ε : ℝ) (q : ℕ) :

T is a one-sided tester for the property P of graphs on Fin n with proximity ε and query bound q: every run asks at most q vertex-pair queries, every graph with property P is accepted with probability one, and every graph ε-far from P is accepted with probability at most 1 / 3. The property P need not be isomorphism-invariant: this generalizes Goldreich's definition, which restricts to invariant graph properties.

The family of graph properties P n (one for each number n of vertices) is one-sided testable with query bound q: for every proximity ε > 0 and every n there is a one-sided tester for P n with proximity ε asking at most q ε queries, a bound independent of n. The properties P n need not be isomorphism-invariant; this harmlessly generalizes Goldreich's definition.

theorem Cslib.DenseGraphTesting.isFar_iff {V : Type u_1} [Fintype V] {G : SimpleGraph V} {P : SimpleGraph V → Prop} {ε : ℝ} :
IsFar G P ε ↔ ∀ (H : SimpleGraph V), P H → ε * ↑(Fintype.card V ^ 2) < ↑(editDist G H)
theorem Cslib.DenseGraphTesting.oneSidedTestable_iff {P : (n : ℕ) → SimpleGraph (Fin n) → Prop} {q : ℝ → ℕ} :
OneSidedTestable P q ↔ ∀ (ε : ℝ), 0 < ε → ∀ (n : ℕ), ∃ (T : Tester n), IsOneSidedTester T (P n) ε (q ε)

Edit distance #

@[simp]
theorem Cslib.DenseGraphTesting.editDist_eq_zero {V : Type u_1} [Finite V] {G H : SimpleGraph V} :
editDist G H = 0 ↔ G = H
@[simp]
theorem Cslib.DenseGraphTesting.editDist_comap_equiv {V : Type u_1} [Finite V] {W : Type u_2} [Finite W] (e : V ≃ W) (G H : SimpleGraph W) :

Relabelling both graphs by the same bijection preserves their edit distance.

On a finite vertex set the edit distance is the size of the symmetric difference of the edge sets.

theorem Cslib.DenseGraphTesting.editDist_deleteEdges {V : Type u_1} [Fintype V] (G : SimpleGraph V) [DecidableRel G.Adj] {s : Finset (Sym2 V)} (hs : s ⊆ G.edgeFinset) :
editDist G (G.deleteEdges ↑s) = s.card

Deleting a set s of edges of G changes exactly the pairs in s.

Far graphs and deletion distance #

theorem Cslib.DenseGraphTesting.not_isFar_of_property {V : Type u_1} [Fintype V] {G : SimpleGraph V} {P : SimpleGraph V → Prop} (hG : P G) {ε : ℝ} (hε : 0 ≤ ε) :
¬IsFar G P ε

A graph with property P is not ε-far from P for any ε ≥ 0.

theorem Cslib.DenseGraphTesting.IsFar.deleteFar {V : Type u_1} [Fintype V] {G : SimpleGraph V} [DecidableRel G.Adj] {P : SimpleGraph V → Prop} {ε : ℝ} (h : IsFar G P ε) :
G.DeleteFar P (ε * ↑(Fintype.card V ^ 2))

An ε-far graph is ε n²-delete-far: at least ε n² edges must be deleted to reach the property.

A graph ε-far from triangle-free is ε-far from triangle-free in the sense of Mathlib's triangle removal lemma.

theorem Cslib.DenseGraphTesting.isFar_of_deleteFar {V : Type u_1} [Fintype V] {G : SimpleGraph V} [DecidableRel G.Adj] {P : SimpleGraph V → Prop} (hP : ∀ ⦃H H' : SimpleGraph V⦄, H ≤ H' → P H' → P H) {ε r : ℝ} (h : G.DeleteFar P r) (hr : ε * ↑(Fintype.card V ^ 2) < r) :
IsFar G P ε

For a property closed under taking subgraphs, more than ε n² deletion distance implies ε-far: the edges of G that a graph H with the property lacks can be deleted from G, and the result is a subgraph of H.

theorem Cslib.DenseGraphTesting.isFar_of_farFromTriangleFree {V : Type u_1} [Fintype V] {G : SimpleGraph V} [DecidableRel G.Adj] [Nonempty V] {ε ε' : ℝ} (h : G.FarFromTriangleFree ε') (hεε' : ε < ε') :
IsFar G (fun (H : SimpleGraph V) => H.CliqueFree 3) ε

On a nonempty vertex set, being ε'-far from triangle-free in the sense of Mathlib implies being ε-far from triangle-free for every ε < ε'.

Queries and repetition #

Ask whether the vertices u and v are adjacent.

The adjacency oracle answers a pair query with the adjacency bit.

A one-sided tester never rejects a graph with the property.

Independent repetition multiplies acceptance probabilities.

k repetitions of a q-query tester ask at most q k queries.

theorem Cslib.DenseGraphTesting.isOneSidedTester_repeatAll {n : ℕ} {T : Tester n} {P : SimpleGraph (Fin n) → Prop} {ε δ : ℝ} {q k : ℕ} (hq : ProbOracleComp.IsQueryBounded T q) (hacc : ∀ (G : SimpleGraph (Fin n)), P G → acceptProb T G = 1) (hrej : ∀ (G : SimpleGraph (Fin n)), IsFar G P ε → acceptProb T G ≤ 1 - δ) (hk : 2 ≤ δ * ↑k) :

Amplification: if the q-query tester T accepts every graph with property P with probability one and accepts every ε-far graph with probability at most 1 - δ, then k independent repetitions with 2 ≤ δ k form a one-sided tester with q k queries.