Pipeline.lean

Lean 4 source, lean/DataMiningAsObservation/Pipeline.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.

/-
Pipeline.lean. Equation 12.1, the retrieval-augmented pipeline as a chain of observers.

A pipeline composes stages. Whatever one stage declares the same, every later stage and the
pipeline as a whole declare the same, since a later stage sees only the earlier stage's
output. For linear stages the rank of the composition is at most the rank of any stage, so
the pipeline's read subspace is no larger than its narrowest stage's. Both hold for every
stage, differentiable or not.
-/
import Mathlib

namespace DMO.Pipeline

/-- **Equation 12.1, first line.** A quotient declared by a stage is inherited by the pipeline.
If the stage `f` sends two inputs to the same output, so does the pipeline `g ∘ f`. -/
theorem quotient_inherited {α β γ : Type*} (f : α → β) (g : β → γ) (x x' : α)
    (h : f x = f x') : (g ∘ f) x = (g ∘ f) x' := by
  simp [Function.comp, h]

/-- The inheritance runs through any number of later stages. -/
theorem quotient_inherited_chain {α β γ δ : Type*} (f : α → β) (g : β → γ) (h : γ → δ)
    (x x' : α) (hf : f x = f x') : (h ∘ g ∘ f) x = (h ∘ g ∘ f) x' := by
  simp [Function.comp, hf]

universe u v

variable {K : Type u} {V W U : Type v} [Field K] [AddCommGroup V] [Module K V] [AddCommGroup W]
  [Module K W] [AddCommGroup U] [Module K U]

/-- **Equation 12.1, second line.** The rank of a composition is at most the rank of the
earlier stage. -/
theorem rank_comp_le_first (f : V →ₗ[K] W) (g : W →ₗ[K] U) :
    LinearMap.rank (g.comp f) ≤ LinearMap.rank f :=
  LinearMap.rank_comp_le_right f g

/-- The rank of a composition is at most the rank of the later stage. -/
theorem rank_comp_le_second (f : V →ₗ[K] W) (g : W →ₗ[K] U) :
    LinearMap.rank (g.comp f) ≤ LinearMap.rank g :=
  LinearMap.rank_comp_le_left f g

end DMO.Pipeline