AttributeType.lean
Lean 4 source, lean/DataMiningAsObservation/AttributeType.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.
/-
AttributeType.lean. Chapter 2 section 2.1, the attribute types.
A measurement scale declares which transformations of a column do not change its meaning.
A ratio scale permits a positive rescaling, an interval scale an affine map with positive
slope, an ordinal scale a strictly increasing map, and a nominal scale any injective
relabelling. The four classes are nested in that order, a rescaling preserves ratios, and
an affine map preserves ratios of differences.
-/
import Mathlib
namespace DMO.AttributeType
/-- A positive rescaling, the ratio scale's permitted transformation. -/
def IsScale (f : ℝ → ℝ) : Prop := ∃ c > 0, ∀ x, f x = c * x
/-- An affine map with positive slope, the interval scale's. -/
def IsAffine (f : ℝ → ℝ) : Prop := ∃ c > 0, ∃ b, ∀ x, f x = c * x + b
/-- **A rescaling is affine.** -/
theorem scale_affine {f : ℝ → ℝ} (h : IsScale f) : IsAffine f := by
obtain ⟨c, hc, hf⟩ := h
exact ⟨c, hc, 0, fun x => by rw [hf, add_zero]⟩
/-- **An affine map with positive slope is strictly increasing.** -/
theorem affine_strictMono {f : ℝ → ℝ} (h : IsAffine f) : StrictMono f := by
obtain ⟨c, hc, b, hf⟩ := h
intro x y hxy
rw [hf, hf]
linarith [mul_lt_mul_of_pos_left hxy hc]
/-- **A strictly increasing map is an injective relabelling.** -/
theorem strictMono_injective {f : ℝ → ℝ} (h : StrictMono f) : Function.Injective f :=
h.injective
/-- **A rescaling preserves ratios.** -/
theorem scale_preserves_ratio {f : ℝ → ℝ} (h : IsScale f) (x y : ℝ) : f x / f y = x / y := by
obtain ⟨c, hc, hf⟩ := h
rw [hf, hf, mul_div_mul_left _ _ hc.ne']
/-- **An affine map preserves ratios of differences.** -/
theorem affine_preserves_difference_ratio {f : ℝ → ℝ} (h : IsAffine f) (x y z t : ℝ) :
(f x - f y) / (f z - f t) = (x - y) / (z - t) := by
obtain ⟨c, hc, b, hf⟩ := h
simp only [hf]
rw [show c * x + b - (c * y + b) = c * (x - y) by ring,
show c * z + b - (c * t + b) = c * (z - t) by ring, mul_div_mul_left _ _ hc.ne']
end DMO.AttributeType