AntiArm.lean

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

/-
AntiArm.lean. Chapter 4 section 4.4, the third arm of a flip comparison.

In the two-dimensional diagonal setting of Flip.lean, a unit reader's reading of diag(a, b)
never exceeds the larger of the two variances, and among codes of the same total error a + b
with both parts nonnegative, the reading never exceeds that total. The code that puts the
whole error on the read direction reaches it. That is the anti arm, built to destroy the read
subspace, and the reason a comparison expects it to score worst.
-/
import Mathlib
import DataMiningAsObservation.Flip

namespace DMO.AntiArm

open DMO.Flip

/-- A unit reader reads diag(a, b) as at most the larger variance. -/
theorem readDiag_le_max (a b c s : ℝ) (hcs : c ^ 2 + s ^ 2 = 1) :
    readDiag a b c s ≤ max a b := by
  unfold readDiag
  have h1 : 0 ≤ (max a b - a) * c ^ 2 := mul_nonneg (sub_nonneg.2 (le_max_left a b)) (sq_nonneg c)
  have h2 : 0 ≤ (max a b - b) * s ^ 2 := mul_nonneg (sub_nonneg.2 (le_max_right a b)) (sq_nonneg s)
  have key : a * c ^ 2 + b * s ^ 2
      = max a b * (c ^ 2 + s ^ 2) - ((max a b - a) * c ^ 2 + (max a b - b) * s ^ 2) := by ring
  rw [key, hcs]
  linarith

/-- Among codes with the same total error `T` and nonnegative parts, no reading exceeds `T`. -/
theorem readDiag_le_total (a b c s T : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) (hT : a + b = T)
    (hcs : c ^ 2 + s ^ 2 = 1) : readDiag a b c s ≤ T := by
  refine (readDiag_le_max a b c s hcs).trans ?_
  rw [max_le_iff]
  constructor <;> linarith

/-- **The anti arm.** The code that puts the whole error on the read direction is read as the
whole error, the worst reading any code of that total can receive. -/
theorem anti_arm_worst (T : ℝ) : readDiag T 0 1 0 = T := by
  unfold readDiag
  ring

end DMO.AntiArm