# Documentation

Mathlib.Topology.MetricSpace.PiNat

# Topological study of spaces Π (n : ℕ), E n#

When E n are topological spaces, the space Π (n : ℕ), E n is naturally a topological space (with the product topology). When E n are uniform spaces, it also inherits a uniform structure. However, it does not inherit a canonical metric space structure of the E n. Nevertheless, one can put a noncanonical metric space structure (or rather, several of them). This is done in this file.

## Main definitions and results #

One can define a combinatorial distance on Π (n : ℕ), E n, as follows:

• PiNat.cylinder x n is the set of points y with x i = y i for i < n.
• PiNat.firstDiff x y is the first index at which x i ≠ y i.
• PiNat.dist x y is equal to (1/2) ^ (firstDiff x y). It defines a distance on Π (n : ℕ), E n, compatible with the topology when the E n have the discrete topology.
• PiNat.metricSpace: the metric space structure, given by this distance. Not registered as an instance. This space is a complete metric space.
• PiNat.metricSpaceOfDiscreteUniformity: the same metric space structure, but adjusting the uniformity defeqness when the E n already have the discrete uniformity. Not registered as an instance
• PiNat.metricSpaceNatNat: the particular case of ℕ → ℕ, not registered as an instance.

These results are used to construct continuous functions on Π n, E n:

• PiNat.exists_retraction_of_isClosed: given a nonempty closed subset s of Π (n : ℕ), E n, there exists a retraction onto s, i.e., a continuous map from the whole space to s restricting to the identity on s.
• exists_nat_nat_continuous_surjective_of_completeSpace: given any nonempty complete metric space with second-countable topology, there exists a continuous surjection from ℕ → ℕ onto this space.

One can also put distances on Π (i : ι), E i when the spaces E i are metric spaces (not discrete in general), and ι is countable.

• PiCountable.dist is the distance on Π i, E i given by dist x y = ∑' i, min (1/2)^(encode i) (dist (x i) (y i)).
• PiCountable.metricSpace is the corresponding metric space structure, adjusted so that the uniformity is definitionally the product uniformity. Not registered as an instance.

### The firstDiff function #

@[irreducible]
def PiNat.firstDiff {E : Type u_2} (x : (n : ) → E n) (y : (n : ) → E n) :

In a product space Π n, E n, then firstDiff x y is the first index at which x and y differ. If x = y, then by convention we set firstDiff x x = 0.

Instances For
theorem PiNat.firstDiff_def {E : Type u_2} (x : (n : ) → E n) (y : (n : ) → E n) :
= if h : x y then Nat.find (_ : a, x a y a) else 0
theorem PiNat.apply_firstDiff_ne {E : Type u_1} {x : (n : ) → E n} {y : (n : ) → E n} (h : x y) :
x () y ()
theorem PiNat.apply_eq_of_lt_firstDiff {E : Type u_1} {x : (n : ) → E n} {y : (n : ) → E n} {n : } (hn : n < ) :
x n = y n
theorem PiNat.firstDiff_comm {E : Type u_1} (x : (n : ) → E n) (y : (n : ) → E n) :
=
theorem PiNat.min_firstDiff_le {E : Type u_1} (x : (n : ) → E n) (y : (n : ) → E n) (z : (n : ) → E n) (h : x z) :
min () ()

### Cylinders #

def PiNat.cylinder {E : Type u_1} (x : (n : ) → E n) (n : ) :
Set ((n : ) → E n)

In a product space Π n, E n, the cylinder set of length n around x, denoted cylinder x n, is the set of sequences y that coincide with x on the first n symbols, i.e., such that y i = x i for all i < n.

Instances For
theorem PiNat.cylinder_eq_pi {E : Type u_1} (x : (n : ) → E n) (n : ) :
= Set.pi ↑() fun i => {x i}
@[simp]
theorem PiNat.cylinder_zero {E : Type u_1} (x : (n : ) → E n) :
= Set.univ
theorem PiNat.cylinder_anti {E : Type u_1} (x : (n : ) → E n) {m : } {n : } (h : m n) :
@[simp]
theorem PiNat.mem_cylinder_iff {E : Type u_1} {x : (n : ) → E n} {y : (n : ) → E n} {n : } :
y ∀ (i : ), i < ny i = x i
theorem PiNat.self_mem_cylinder {E : Type u_1} (x : (n : ) → E n) (n : ) :
x
theorem PiNat.mem_cylinder_iff_eq {E : Type u_1} {x : (n : ) → E n} {y : (n : ) → E n} {n : } :
y =
theorem PiNat.mem_cylinder_comm {E : Type u_1} (x : (n : ) → E n) (y : (n : ) → E n) (n : ) :
y x
theorem PiNat.mem_cylinder_iff_le_firstDiff {E : Type u_1} {x : (n : ) → E n} {y : (n : ) → E n} (hne : x y) (i : ) :
x i
theorem PiNat.mem_cylinder_firstDiff {E : Type u_1} (x : (n : ) → E n) (y : (n : ) → E n) :
x
theorem PiNat.cylinder_eq_cylinder_of_le_firstDiff {E : Type u_1} (x : (n : ) → E n) (y : (n : ) → E n) {n : } (hn : n ) :
=
theorem PiNat.iUnion_cylinder_update {E : Type u_1} (x : (n : ) → E n) (n : ) :
⋃ (k : E n), PiNat.cylinder () (n + 1) =
theorem PiNat.update_mem_cylinder {E : Type u_1} (x : (n : ) → E n) (n : ) (y : E n) :
def PiNat.res {α : Type u_2} (x : α) :
List α

In the case where E has constant value α, the cylinder cylinder x n can be identified with the element of List α consisting of the first n entries of x. See cylinder_eq_res. We call this list res x n, the restriction of x to n.

Equations
Instances For
@[simp]
theorem PiNat.res_zero {α : Type u_2} (x : α) :
= []
@[simp]
theorem PiNat.res_succ {α : Type u_2} (x : α) (n : ) :
PiNat.res x () = x n ::
@[simp]
theorem PiNat.res_length {α : Type u_2} (x : α) (n : ) :
theorem PiNat.res_eq_res {α : Type u_2} {x : α} {y : α} {n : } :
= ∀ ⦃m : ⦄, m < nx m = y m

The restrictions of x and y to n are equal if and only if x m = y m for all m < n.

theorem PiNat.res_injective {α : Type u_2} :
theorem PiNat.cylinder_eq_res {α : Type u_2} (x : α) (n : ) :
= {y | = }

cylinder x n is equal to the set of sequences y with the same restriction to n as x.

### A distance function on Π n, E n#

We define a distance function on Π n, E n, given by dist x y = (1/2)^n where n is the first index at which x and y differ. When each E n has the discrete topology, this distance will define the right topology on the product space. We do not record a global Dist instance nor a MetricSpace instance, as other distances may be used on these spaces, but we register them as local instances in this section.

def PiNat.dist {E : Type u_1} :
Dist ((n : ) → E n)

The distance function on a product space Π n, E n, given by dist x y = (1/2)^n where n is the first index at which x and y differ.

Instances For
theorem PiNat.dist_eq_of_ne {E : Type u_1} {x : (n : ) → E n} {y : (n : ) → E n} (h : x y) :
dist x y = (1 / 2) ^
theorem PiNat.dist_self {E : Type u_1} (x : (n : ) → E n) :
dist x x = 0
theorem PiNat.dist_comm {E : Type u_1} (x : (n : ) → E n) (y : (n : ) → E n) :
dist x y = dist y x
theorem PiNat.dist_nonneg {E : Type u_1} (x : (n : ) → E n) (y : (n : ) → E n) :
0 dist x y
theorem PiNat.dist_triangle_nonarch {E : Type u_1} (x : (n : ) → E n) (y : (n : ) → E n) (z : (n : ) → E n) :
dist x z max (dist x y) (dist y z)
theorem PiNat.dist_triangle {E : Type u_1} (x : (n : ) → E n) (y : (n : ) → E n) (z : (n : ) → E n) :
dist x z dist x y + dist y z
theorem PiNat.eq_of_dist_eq_zero {E : Type u_1} (x : (n : ) → E n) (y : (n : ) → E n) (hxy : dist x y = 0) :
x = y
theorem PiNat.mem_cylinder_iff_dist_le {E : Type u_1} {x : (n : ) → E n} {y : (n : ) → E n} {n : } :
y dist y x (1 / 2) ^ n
theorem PiNat.apply_eq_of_dist_lt {E : Type u_1} {x : (n : ) → E n} {y : (n : ) → E n} {n : } (h : dist x y < (1 / 2) ^ n) {i : } (hi : i n) :
x i = y i
theorem PiNat.lipschitz_with_one_iff_forall_dist_image_le_of_mem_cylinder {E : Type u_1} {α : Type u_2} {f : ((n : ) → E n) → α} :
(∀ (x y : (n : ) → E n), dist (f x) (f y) dist x y) ∀ (x y : (n : ) → E n) (n : ), y dist (f x) (f y) (1 / 2) ^ n

A function to a pseudo-metric-space is 1-Lipschitz if and only if points in the same cylinder of length n are sent to points within distance (1/2)^n. Not expressed using LipschitzWith as we don't have a metric space structure

theorem PiNat.isOpen_cylinder (E : Type u_1) [(n : ) → TopologicalSpace (E n)] [∀ (n : ), DiscreteTopology (E n)] (x : (n : ) → E n) (n : ) :
theorem PiNat.isTopologicalBasis_cylinders (E : Type u_1) [(n : ) → TopologicalSpace (E n)] [∀ (n : ), DiscreteTopology (E n)] :
theorem PiNat.isOpen_iff_dist {E : Type u_1} [(n : ) → TopologicalSpace (E n)] [∀ (n : ), DiscreteTopology (E n)] (s : Set ((n : ) → E n)) :
∀ (x : (n : ) → E n), x sε, ε > 0 ∀ (y : (n : ) → E n), dist x y < εy s
def PiNat.metricSpace {E : Type u_1} [(n : ) → TopologicalSpace (E n)] [∀ (n : ), DiscreteTopology (E n)] :
MetricSpace ((n : ) → E n)

Metric space structure on Π (n : ℕ), E n when the spaces E n have the discrete topology, where the distance is given by dist x y = (1/2)^n, where n is the smallest index where x and y differ. Not registered as a global instance by default. Warning: this definition makes sure that the topology is defeq to the original product topology, but it does not take care of a possible uniformity. If the E n have a uniform structure, then there will be two non-defeq uniform structures on Π n, E n, the product one and the one coming from the metric structure. In this case, use metricSpaceOfDiscreteUniformity instead.

Instances For
def PiNat.metricSpaceOfDiscreteUniformity {E : Type u_2} [(n : ) → UniformSpace (E n)] (h : ∀ (n : ), uniformity (E n) = Filter.principal idRel) :
MetricSpace ((n : ) → E n)

Metric space structure on Π (n : ℕ), E n when the spaces E n have the discrete uniformity, where the distance is given by dist x y = (1/2)^n, where n is the smallest index where x and y differ. Not registered as a global instance by default.

Instances For

Metric space structure on ℕ → ℕ where the distance is given by dist x y = (1/2)^n, where n is the smallest index where x and y differ. Not registered as a global instance by default.

Instances For
theorem PiNat.completeSpace {E : Type u_1} [(n : ) → TopologicalSpace (E n)] [∀ (n : ), DiscreteTopology (E n)] :
CompleteSpace ((n : ) → E n)

### Retractions inside product spaces #

We show that, in a space Π (n : ℕ), E n where each E n is discrete, there is a retraction on any closed nonempty subset s, i.e., a continuous map f from the whole space to s restricting to the identity on s. The map f is defined as follows. For x ∈ s, let f x = x. Otherwise, consider the longest prefix w that x shares with an element of s, and let f x = z_w where z_w is an element of s starting with w.

theorem PiNat.exists_disjoint_cylinder {E : Type u_1} [(n : ) → TopologicalSpace (E n)] [∀ (n : ), DiscreteTopology (E n)] {s : Set ((n : ) → E n)} (hs : ) {x : (n : ) → E n} (hx : ¬x s) :
n, Disjoint s ()
def PiNat.shortestPrefixDiff {E : Type u_2} (x : (n : ) → E n) (s : Set ((n : ) → E n)) :

Given a point x in a product space Π (n : ℕ), E n, and s a subset of this space, then shortestPrefixDiff x s if the smallest n for which there is no element of s having the same prefix of length n as x. If there is no such n, then use 0 by convention.

Instances For
theorem PiNat.firstDiff_lt_shortestPrefixDiff {E : Type u_1} [(n : ) → TopologicalSpace (E n)] [∀ (n : ), DiscreteTopology (E n)] {s : Set ((n : ) → E n)} (hs : ) {x : (n : ) → E n} {y : (n : ) → E n} (hx : ¬x s) (hy : y s) :
theorem PiNat.shortestPrefixDiff_pos {E : Type u_1} [(n : ) → TopologicalSpace (E n)] [∀ (n : ), DiscreteTopology (E n)] {s : Set ((n : ) → E n)} (hs : ) (hne : ) {x : (n : ) → E n} (hx : ¬x s) :
def PiNat.longestPrefix {E : Type u_2} (x : (n : ) → E n) (s : Set ((n : ) → E n)) :

Given a point x in a product space Π (n : ℕ), E n, and s a subset of this space, then longestPrefix x s if the largest n for which there is an element of s having the same prefix of length n as x. If there is no such n, use 0 by convention.

Instances For
theorem PiNat.firstDiff_le_longestPrefix {E : Type u_1} [(n : ) → TopologicalSpace (E n)] [∀ (n : ), DiscreteTopology (E n)] {s : Set ((n : ) → E n)} (hs : ) {x : (n : ) → E n} {y : (n : ) → E n} (hx : ¬x s) (hy : y s) :
theorem PiNat.inter_cylinder_longestPrefix_nonempty {E : Type u_1} [(n : ) → TopologicalSpace (E n)] [∀ (n : ), DiscreteTopology (E n)] {s : Set ((n : ) → E n)} (hs : ) (hne : ) (x : (n : ) → E n) :
theorem PiNat.disjoint_cylinder_of_longestPrefix_lt {E : Type u_1} [(n : ) → TopologicalSpace (E n)] [∀ (n : ), DiscreteTopology (E n)] {s : Set ((n : ) → E n)} (hs : ) {x : (n : ) → E n} (hx : ¬x s) {n : } (hn : < n) :
theorem PiNat.cylinder_longestPrefix_eq_of_longestPrefix_lt_firstDiff {E : Type u_1} [(n : ) → TopologicalSpace (E n)] [∀ (n : ), DiscreteTopology (E n)] {x : (n : ) → E n} {y : (n : ) → E n} {s : Set ((n : ) → E n)} (hs : ) (hne : ) (H : ) (xs : ¬x s) (ys : ¬y s) :
=

If two points x, y coincide up to length n, and the longest common prefix of x with s is strictly shorter than n, then the longest common prefix of y with s is the same, and both cylinders of this length based at x and y coincide.

theorem PiNat.exists_lipschitz_retraction_of_isClosed {E : Type u_1} [(n : ) → TopologicalSpace (E n)] [∀ (n : ), DiscreteTopology (E n)] {s : Set ((n : ) → E n)} (hs : ) (hne : ) :
f, (∀ (x : (n : ) → E n), x sf x = x) = s

Given a closed nonempty subset s of Π (n : ℕ), E n, there exists a Lipschitz retraction onto this set, i.e., a Lipschitz map with range equal to s, equal to the identity on s.

theorem PiNat.exists_retraction_of_isClosed {E : Type u_1} [(n : ) → TopologicalSpace (E n)] [∀ (n : ), DiscreteTopology (E n)] {s : Set ((n : ) → E n)} (hs : ) (hne : ) :
f, (∀ (x : (n : ) → E n), x sf x = x) = s

Given a closed nonempty subset s of Π (n : ℕ), E n, there exists a retraction onto this set, i.e., a continuous map with range equal to s, equal to the identity on s.

theorem PiNat.exists_retraction_subtype_of_isClosed {E : Type u_1} [(n : ) → TopologicalSpace (E n)] [∀ (n : ), DiscreteTopology (E n)] {s : Set ((n : ) → E n)} (hs : ) (hne : ) :
f, (∀ (x : s), f x = x)
theorem exists_nat_nat_continuous_surjective_of_completeSpace (α : Type u_2) [] [] [] :
f,

Any nonempty complete second countable metric space is the continuous image of the fundamental space ℕ → ℕ. For a version of this theorem in the context of Polish spaces, see exists_nat_nat_continuous_surjective_of_polishSpace.

### Products of (possibly non-discrete) metric spaces #

def PiCountable.dist {ι : Type u_2} [] {F : ιType u_3} [(i : ι) → MetricSpace (F i)] :
Dist ((i : ι) → F i)

Given a countable family of metric spaces, one may put a distance on their product Π i, E i. It is highly non-canonical, though, and therefore not registered as a global instance. The distance we use here is dist x y = ∑' i, min (1/2)^(encode i) (dist (x i) (y i)).

Instances For
theorem PiCountable.dist_eq_tsum {ι : Type u_2} [] {F : ιType u_3} [(i : ι) → MetricSpace (F i)] (x : (i : ι) → F i) (y : (i : ι) → F i) :
dist x y = ∑' (i : ι), min ((1 / 2) ^ ) (dist (x i) (y i))
theorem PiCountable.dist_summable {ι : Type u_2} [] {F : ιType u_3} [(i : ι) → MetricSpace (F i)] (x : (i : ι) → F i) (y : (i : ι) → F i) :
Summable fun i => min ((1 / 2) ^ ) (dist (x i) (y i))
theorem PiCountable.min_dist_le_dist_pi {ι : Type u_2} [] {F : ιType u_3} [(i : ι) → MetricSpace (F i)] (x : (i : ι) → F i) (y : (i : ι) → F i) (i : ι) :
min ((1 / 2) ^ ) (dist (x i) (y i)) dist x y
theorem PiCountable.dist_le_dist_pi_of_dist_lt {ι : Type u_2} [] {F : ιType u_3} [(i : ι) → MetricSpace (F i)] {x : (i : ι) → F i} {y : (i : ι) → F i} {i : ι} (h : dist x y < (1 / 2) ^ ) :
dist (x i) (y i) dist x y
def PiCountable.metricSpace {ι : Type u_2} [] {F : ιType u_3} [(i : ι) → MetricSpace (F i)] :
MetricSpace ((i : ι) → F i)

Given a countable family of metric spaces, one may put a distance on their product Π i, E i, defining the right topology and uniform structure. It is highly non-canonical, though, and therefore not registered as a global instance. The distance we use here is dist x y = ∑' n, min (1/2)^(encode i) (dist (x n) (y n)).

Instances For