File size: 4,460 Bytes
4a56cd6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | import OAI.Algorithms.SubexponentialSAT.LeanCompat
namespace OAI.Algorithms
/-!
# Consecutive binomial matrices
The matrix with entries choose (A + d) j factors into a lower
unitriangular Pascal matrix and an upper unitriangular translation matrix.
The upper factor is explicitly zero below the diagonal: natural subtraction
alone would give the wrong entries there.
All identities are obtained by casting integer-valued binomial coefficients,
so the determinant calculation remains valid in arbitrary characteristic.
-/
namespace SubexponentialSAT.BinomialMatrix
open scoped BigOperators
/-- The consecutive-integer binomial evaluation matrix. -/
def B (K : Type*) [Semiring K] (A R : β) : Matrix (Fin R) (Fin R) K :=
fun d j => ((A + d.val).choose j.val : K)
/-- The lower unitriangular Pascal matrix. -/
def L (K : Type*) [Semiring K] (R : β) : Matrix (Fin R) (Fin R) K :=
fun d s => (d.val.choose s.val : K)
/-- The upper unitriangular translation matrix, with explicit zero extension. -/
def U (K : Type*) [Semiring K] (A R : β) : Matrix (Fin R) (Fin R) K :=
fun s j => if s.val β€ j.val then (A.choose (j.val - s.val) : K) else 0
@[simp] theorem B_apply (K : Type*) [Semiring K] (A R : β) (d j : Fin R) :
B K A R d j = ((A + d.val).choose j.val : K) := rfl
@[simp] theorem L_apply (K : Type*) [Semiring K] (R : β) (d s : Fin R) :
L K R d s = (d.val.choose s.val : K) := rfl
@[simp] theorem U_apply (K : Type*) [Semiring K] (A R : β) (s j : Fin R) :
U K A R s j =
if s.val β€ j.val then (A.choose (j.val - s.val) : K) else 0 := rfl
/-- Vandermonde convolution, extended by zero to any range containing j. -/
theorem choose_add_sum (A d j R : β) (hj : j < R) :
(A + d).choose j =
β s β Finset.range R, d.choose s *
(if s β€ j then A.choose (j - s) else 0) := by
calc
(A + d).choose j =
β s β Finset.range (j + 1), d.choose s * A.choose (j - s) := by
rw [Nat.add_comm A d, Nat.add_choose_eq]
exact Finset.Nat.sum_antidiagonal_eq_sum_range_succ
(fun s t => d.choose s * A.choose t) j
_ = β s β Finset.range (j + 1), d.choose s *
(if s β€ j then A.choose (j - s) else 0) := by
apply Finset.sum_congr rfl
intro s hs
rw [ite_eq_left (Nat.le_of_lt_succ (Finset.mem_range.mp hs))]
_ = β s β Finset.range R, d.choose s *
(if s β€ j then A.choose (j - s) else 0) := by
apply Finset.sum_subset (Finset.range_mono (Nat.succ_le_of_lt hj))
intro s _ hs
have hsj : Β¬s β€ j := fun h =>
hs (Finset.mem_range.mpr (Nat.lt_succ_of_le h))
simp [hsj]
/-- The factorization is valid already over an arbitrary semiring. -/
theorem factorization (K : Type*) [Semiring K] (A R : β) :
B K A R = L K R * U K A R := by
ext d j
change ((A + d.val).choose j.val : K) =
β s : Fin R, (d.val.choose s.val : K) *
(if s.val β€ j.val then (A.choose (j.val - s.val) : K) else 0)
rw [Fin.sum_univ_eq_sum_range (fun s : β => (d.val.choose s : K) *
(if s β€ j.val then (A.choose (j.val - s) : K) else 0)) R]
simpa only [Nat.cast_sum, Nat.cast_mul, Nat.cast_ite, Nat.cast_zero] using
congrArg (fun n : β => (n : K)) (choose_add_sum A d.val j.val R j.isLt)
theorem L_lowerTriangular (K : Type*) [Semiring K] (R : β) :
(L K R).BlockTriangular OrderDual.toDual := by
intro i j hij
have h : i.val < j.val := hij
simp [L, Nat.choose_eq_zero_of_lt h]
theorem U_upperTriangular (K : Type*) [Semiring K] (A R : β) :
(U K A R).BlockTriangular id := by
intro i j hij
have h : Β¬i.val β€ j.val := Nat.not_le_of_lt hij
simp [U, h]
@[simp] theorem det_L (K : Type*) [CommRing K] (R : β) :
(L K R).det = 1 := by
rw [Matrix.det_of_isLowerTriangular _ (L_lowerTriangular K R)]
simp [L]
@[simp] theorem det_U (K : Type*) [CommRing K] (A R : β) :
(U K A R).det = 1 := by
rw [Matrix.det_of_isUpperTriangular (U_upperTriangular K A R)]
simp [U]
/-- Consecutive binomial evaluation has determinant one in every
commutative ring, with no characteristic or size restriction. -/
@[simp] theorem det_B (K : Type*) [CommRing K] (A R : β) :
(B K A R).det = 1 := by
rw [factorization, Matrix.det_mul, det_L, det_U, one_mul]
/-- In particular, the determinant is exactly one over the integers. -/
theorem det_B_int (A R : β) : (B β€ A R).det = 1 :=
det_B β€ A R
end SubexponentialSAT.BinomialMatrix
end OAI.Algorithms
|