Documentation

CslibFrontier.Computability.Complexity.Classes.FPRAS

Fully polynomial randomized approximation schemes #

A fully polynomial randomized approximation scheme (FPRAS) for a counting function f : α → ℕ is a randomized algorithm that, given an instance x, a relative error ε and a failure probability δ, outputs an estimate within relative error ε of f x with probability at least 1 - δ, in time polynomial in the length of x, in 1 / ε and in log (1 / δ) Karp, Luby and Madras, Jerrum, Valiant and Vazirani, Mitzenmacher and Upfal, Section 11.2, Definition 11.2.

Cslib.Complexity.IsFPRAS enc f A parameterizes the relative error as ε = 1 / p and the failure probability as δ = 2 ^ (-t), for natural numbers p and t both written in unary. A running time polynomial in the length of the encoded input (x, p, t) is then exactly a running time polynomial in |x|, 1 / ε and log (1 / δ). The three requirements stay separate:

The relative-error condition is multiplicative, so it forces an exact answer on instances with f x = 0 (Cslib.Complexity.ApproxWithin.num_eq_zero). Cslib.Complexity.IsFPRAS.approx gives the guarantee in the usual form for real ε > 0 and δ > 0, running A on p = ⌈1 / ε⌉ and t = ⌈log₂ ⌈1 / δ⌉⌉.

Main definitions #

Main results #

References #

The rational estimate num / den is within relative error 1 / p of the count c: the denominator is positive and |num / den - c| ≤ c / p.

theorem Cslib.Complexity.ApproxWithin.num_eq_zero {p num den : ℕ} (h : ApproxWithin 0 p num den) :
num = 0

A zero count must be estimated exactly: the numerator is zero.

def Cslib.Complexity.IsFPRAS {α : Type} (enc : α ↪ List Bool) (f : α → ℕ) (A : α → ℕ → ℕ → ProbComp (ℕ × ℕ)) :

A fully polynomial randomized approximation scheme for the counting function f, on instances encoded by enc. The algorithm A x p t receives the instance x, the inverse relative error p (so ε = 1 / p) and the confidence t (so δ = 2 ^ (-t)), with p and t in unary. It is a strict probabilistic polynomial-time program on the encoded triple (x, p, t), outputs a pair (num, den) in binary, and for p > 0 its estimate num / den is within relative error 1 / p of f x with probability at least 1 - (1 / 2) ^ t.

def Cslib.Complexity.FPRAS {α : Type} (enc : α ↪ List Bool) :
Set (α → ℕ)

The counting functions with a fully polynomial randomized approximation scheme, on instances encoded by enc.

theorem Cslib.Complexity.IsFPRAS.approx {α : Type} {enc : α ↪ List Bool} {f : α → ℕ} {A : α → ℕ → ℕ → ProbComp (ℕ × ℕ)} (hA : IsFPRAS enc f A) (x : α) {ε δ : ℝ} (hε : 0 < ε) (hδ : 0 < δ) :
1 - δ ≤ ((A x ⌈ε⁻¹⌉₊ (Nat.clog 2 ⌈δ⁻¹⌉₊)).eval.toOuterMeasure {out : ℕ × ℕ | 0 < out.2 ∧ |↑out.1 / ↑out.2 - ↑(f x)| ≤ ε * ↑(f x)}).toReal

The guarantee for real parameters. Run with p = ⌈1 / ε⌉ and t = ⌈log₂ ⌈1 / δ⌉⌉, an FPRAS outputs an estimate within relative error ε of f x with probability at least 1 - δ. Since p < 1 / ε + 1, and t < log₂ (1 / δ) + 2 when δ ≤ 1, the running time is polynomial in |x|, 1 / ε and log (1 / δ).