1import Mathlib.Tactic
2import Mathlib.Analysis.Calculus.Deriv.Add
3import Mathlib.Analysis.Calculus.Deriv.Mul
4import Mathlib.LinearAlgebra.Matrix.Block
5import Mathlib.LinearAlgebra.Matrix.Rank
6
7/-!
8# Four raters: the residuals' Jacobian minor (Proposition 6b)
9
10Source: `paper/gold_calibration_second_grader.md` §8, Proposition 6(b): the residuals' `6 × 15`
11Jacobian in the centred moments has rank 6 wherever `c₁₂c₁₃ ≠ 0`, model or not; on the columns
12`(c₂₄, c₃₄, k₁₂₄, k₁₃₄, k₂₃₄, k₁₂₃₄)` the minor is lower triangular with determinant
13`-c₁₂⁴c₁₃²`.
14
15The fifteen coordinates are taken as free real variables
16`z = (p₁, p₂, p₃, p₄, c₁₂, c₁₃, c₁₄, c₂₃, c₂₄, c₃₄, k₁₂₃, k₁₂₄, k₁₃₄, k₂₃₄, k₁₂₃₄)`
17(indices `0..14`). Each residual is the note's equality written as left side minus right side, in
18the order that makes the minor lower triangular. The Jacobian entries are computed by Lean as
19partial derivatives (`deriv` along coordinate lines), not entered by hand.
20-/
21
22namespace FeedbackChannel.RatersJacobian
23
24/-- The six residuals:
25`c₁₃c₂₄ - c₁₄c₂₃`, `c₁₂c₃₄ - c₁₃c₂₄`, `k₁₂₃c₁₄ - k₁₂₄c₁₃`, `k₁₂₃c₁₄ - k₁₃₄c₁₂`,
26`k₁₂₃c₂₄ - k₂₃₄c₁₂`, `(k₁₂₃₄ - c₁₂c₃₄)c₁₂ - k₁₂₃k₁₂₄`. -/
27def resid (z : Fin 15 → ℝ) : Fin 6 → ℝ :=
28 ![z 5 * z 8 - z 6 * z 7,
29 z 4 * z 9 - z 5 * z 8,
30 z 10 * z 6 - z 11 * z 5,
31 z 10 * z 6 - z 12 * z 4,
32 z 10 * z 8 - z 13 * z 4,
33 (z 14 - z 4 * z 9) * z 4 - z 10 * z 11]
34
35/-- The `6 × 15` Jacobian of the residuals: entry `(r, j)` is the partial derivative of residual
36`r` in coordinate `j` at `z`. -/
37noncomputable def jac (z : Fin 15 → ℝ) : Matrix (Fin 6) (Fin 15) ℝ :=
38 Matrix.of fun r j => deriv (fun t => resid (Function.update z j t) r) (z j)
39
40/-- The columns `c₂₄, c₃₄, k₁₂₄, k₁₃₄, k₂₃₄, k₁₂₃₄`. -/
41def cols : Fin 6 → Fin 15 := ![8, 9, 11, 12, 13, 14]
42
43/-- The `6 × 6` minor on those columns. -/
44noncomputable def minor (z : Fin 15 → ℝ) : Matrix (Fin 6) (Fin 6) ℝ := (jac z).submatrix id cols
45
46/-- The minor, entry by entry (computed, lower triangular). -/
47theorem minor_eq (z : Fin 15 → ℝ) :
48 minor z = !![z 5, 0, 0, 0, 0, 0;
49 -z 5, z 4, 0, 0, 0, 0;
50 0, 0, -z 5, 0, 0, 0;
51 0, 0, 0, -z 4, 0, 0;
52 z 10, 0, 0, 0, -z 4, 0;
53 0, -z 4 ^ 2, -z 10, 0, 0, z 4] := by
54 ext r c
55 fin_cases r <;> fin_cases c <;>
56 (simp [minor, jac, resid, cols, Function.update_apply]; try ring)
57
58/-- **Proposition 6(b), determinant.** At every point (model or not) the minor has determinant
59`-c₁₂⁴ c₁₃²`. -/
60theorem minor_det (z : Fin 15 → ℝ) : (minor z).det = -(z 4) ^ 4 * (z 5) ^ 2 := by
61 rw [minor_eq, Matrix.det_of_isLowerTriangular]
62 · simp [Fin.prod_univ_six]
63 ring
64 · intro i j hij
65 rw [OrderDual.toDual_lt_toDual] at hij
66 fin_cases i <;> fin_cases j <;> simp_all
67
68/-- **Proposition 6(b), rank.** Wherever `c₁₂ c₁₃ ≠ 0` the residuals' `6 × 15` Jacobian has
69rank 6. -/
70theorem jac_rank (z : Fin 15 → ℝ) (h : z 4 * z 5 ≠ 0) : (jac z).rank = 6 := by
71 have h4 : z 4 ≠ 0 := left_ne_zero_of_mul h
72 have h5 : z 5 ≠ 0 := right_ne_zero_of_mul h
73 apply le_antisymm
74 · simpa using Matrix.rank_le_card_height (jac z)
75 · have hdet : (minor z).det ≠ 0 := by
76 rw [minor_det]; simp [h4, h5]
77 have hunit : IsUnit (minor z) :=
78 (Matrix.isUnit_iff_isUnit_det _).2 (isUnit_iff_ne_zero.2 hdet)
79 have h6 : (minor z).rank = 6 := by
80 simpa using Matrix.rank_of_isUnit (minor z) hunit
81 have hle : (minor z).rank ≤ (jac z).rank := Matrix.rank_submatrix_le (jac z) id cols
82 omega
83
84end FeedbackChannel.RatersJacobian