Documentation

CslibFrontier.Foundations.Computability.DistinctValues

Enumerating the distinct values of a sequence of partial outputs #

A sequence f : ℕ → Option β lists, possibly with repetitions and gaps, the elements of its range {b | ∃ n, f n = some b}. Typically f n decodes n as a program and a time bound and reports the output of the program if it halts in time, so the range is a computably enumerable set. Nat.distinctValues f n lists the distinct values among f 0, …, f (n - 1) in order of first appearance, and Nat.nthDistinctValue f i is the i-th distinct value of the whole sequence, found by an unbounded search over n. When the range is finite, every element has an index below the size of the range. When f depends primitive recursively on a parameter, both are computable in the parameter: this is the enumeration step in counting arguments of Kolmogorov complexity, which describe an element of a computably enumerable set by its index.

Main definitions #

Main results #

def Nat.distinctValues {β : Type u_2} [DecidableEq β] (f : ℕ → Option β) :
ℕ → List β

The distinct values among f 0, …, f (n - 1), in order of first appearance. The body is exposed so that concrete lists can be evaluated by decide.

@[simp]
theorem Nat.distinctValues_zero {β : Type u_2} [DecidableEq β] (f : ℕ → Option β) :
theorem Nat.distinctValues_prefix {β : Type u_2} [DecidableEq β] (f : ℕ → Option β) {m n : ℕ} (h : m ≤ n) :

The lists of distinct values grow by extension.

theorem Nat.mem_distinctValues {β : Type u_2} [DecidableEq β] {f : ℕ → Option β} {n : ℕ} {b : β} :
b ∈ distinctValues f n ↔ ∃ j < n, f j = some b

The distinct values up to n are the values f j = some b with j < n.

theorem Nat.nodup_distinctValues {β : Type u_2} [DecidableEq β] (f : ℕ → Option β) (n : ℕ) :
theorem Nat.length_distinctValues_le_ncard {β : Type u_2} [DecidableEq β] {f : ℕ → Option β} (hf : {b : β | ∃ (n : ℕ), f n = some b}.Finite) (n : ℕ) :
(distinctValues f n).length ≤ {b : β | ∃ (n : ℕ), f n = some b}.ncard

For a finite range, the lists of distinct values are no longer than the range.

theorem Nat.exists_length_distinctValues_eq_ncard {β : Type u_2} [DecidableEq β] {f : ℕ → Option β} (hf : {b : β | ∃ (n : ℕ), f n = some b}.Finite) :
∃ (N : ℕ), (distinctValues f N).length = {b : β | ∃ (n : ℕ), f n = some b}.ncard

For a finite range, the list of distinct values eventually contains the whole range.

def Nat.nthDistinctValue {β : Type u_2} [DecidableEq β] (f : ℕ → Option β) (i : ℕ) :
Part β

The i-th distinct value of the sequence f, in order of first appearance: the search for a bound n such that distinctValues f n has an i-th entry.

theorem Nat.mem_nthDistinctValue_iff {β : Type u_2} [DecidableEq β] {f : ℕ → Option β} {i : ℕ} {b : β} :
b ∈ nthDistinctValue f i ↔ ∃ (n : ℕ), (distinctValues f n)[i]? = some b
theorem Nat.exists_eq_some_of_mem_nthDistinctValue {β : Type u_2} [DecidableEq β] {f : ℕ → Option β} {i : ℕ} {b : β} (h : b ∈ nthDistinctValue f i) :
∃ (n : ℕ), f n = some b

The distinct values of f are in its range.

theorem Nat.lt_ncard_of_mem_nthDistinctValue {β : Type u_2} [DecidableEq β] {f : ℕ → Option β} (hf : {b : β | ∃ (n : ℕ), f n = some b}.Finite) {i : ℕ} {b : β} (h : b ∈ nthDistinctValue f i) :
i < {b : β | ∃ (n : ℕ), f n = some b}.ncard

For a finite range, the indices of the distinct values are below the size of the range.

theorem Nat.exists_mem_nthDistinctValue_of_finite {β : Type u_2} [DecidableEq β] {f : ℕ → Option β} (hf : {b : β | ∃ (n : ℕ), f n = some b}.Finite) {b : β} {n : ℕ} (hb : f n = some b) :
∃ i < {b : β | ∃ (n : ℕ), f n = some b}.ncard, b ∈ nthDistinctValue f i

For a finite range, every element of the range is the i-th distinct value for some i below the size of the range.

theorem Primrec.distinctValues {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] [DecidableEq β] {f : α → ℕ → Option β} (hf : Primrec₂ f) :
Primrec₂ fun (a : α) (n : ℕ) => Nat.distinctValues (f a) n

The distinct values of a sequence depending primitive recursively on a parameter are primitive recursive in the parameter and the bound.

theorem Partrec.nthDistinctValue {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] [DecidableEq β] {f : α → ℕ → Option β} (hf : Primrec₂ f) :
Partrec₂ fun (a : α) (i : ℕ) => Nat.nthDistinctValue (f a) i

The i-th distinct value of a sequence depending primitive recursively on a parameter is partial recursive in the parameter and i.