File size: 6,008 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import OAI.LinearAlgebra.CirculantHadamard.Basic

namespace OAI

universe uR

/-!
# From real sign matrices to integer cyclic autocorrelation

The Gram entry is reindexed using translation in `Fin n`. The real/integer
bridge uses the injective coefficient map `β„€ β†’ ℝ`; it does not assume any
classification or any group-ring norm statement.
-/

namespace CirculantHadamard

open scoped BigOperators

variable {n : β„•}

/-- An integer sign row with the full Hadamard Gram equation. -/
def IsIntegerSignRow (h : Fin n β†’ β„€) : Prop :=
  (βˆ€ j, IsSign (h j)) ∧
    rowCirculant h * (rowCirculant h).transpose =
      (n : β„€) β€’ (1 : Matrix (Fin n) (Fin n) β„€)

/-- The Gram entry at `(i,a)` is the cyclic autocorrelation at `a-i`. -/
theorem rowCirculant_gram_apply [NeZero n] {R : Type uR} [CommRing R]
    (h : Fin n β†’ R) (i a : Fin n) :
    (rowCirculant h * (rowCirculant h).transpose) i a =
      βˆ‘ j, h j * h (j - (a - i)) := by
  classical
  let e : Fin n ≃ Fin n :=
    { toFun := fun j => j - i
      invFun := fun j => j + i
      left_inv := fun j => sub_add_cancel j i
      right_inv := fun j => add_sub_cancel_right j i }
  simp only [Matrix.mul_apply, Matrix.transpose_apply, rowCirculant_apply]
  apply Fintype.sum_equiv e
  intro j
  change h (j - i) * h (j - a) = h (j - i) * h ((j - i) - (a - i))
  simp only [sub_sub_sub_cancel_right]

/-- The full Gram equation is exactly the cyclic autocorrelation system. -/
theorem gram_eq_iff_autocorrelation [NeZero n] {R : Type uR} [CommRing R]
    (h : Fin n β†’ R) :
    rowCirculant h * (rowCirculant h).transpose =
        (n : R) β€’ (1 : Matrix (Fin n) (Fin n) R) ↔
      βˆ€ a : Fin n, βˆ‘ j, h j * h (j - a) = if a = 0 then (n : R) else 0 := by
  classical
  constructor
  Β· intro hGram a
    have ha := congrArg (fun M : Matrix (Fin n) (Fin n) R => M 0 a) hGram
    rw [rowCirculant_gram_apply] at ha
    simpa [Matrix.smul_apply, Matrix.one_apply, eq_comm] using ha
  Β· intro hCorr
    ext i a
    rw [rowCirculant_gram_apply, hCorr]
    by_cases hia : i = a
    Β· subst a
      simp
    Β· have hai : a - i β‰  0 := sub_ne_zero.mpr (Ne.symm hia)
      simp [hia, hai, Matrix.smul_apply]

/-- Casting the integer Gram matrix agrees entry by entry with taking the
Gram matrix after casting the row. -/
theorem intCast_gram_apply (h : Fin n β†’ β„€) (i j : Fin n) :
    ((rowCirculant h * (rowCirculant h).transpose) i j : ℝ) =
      (rowCirculant (fun a => (h a : ℝ)) *
        (rowCirculant (fun a => (h a : ℝ))).transpose) i j := by
  simp [Matrix.mul_apply, Matrix.transpose_apply, rowCirculant, Int.cast_sum,
    Int.cast_mul]

private theorem intCast_scaled_identity_apply (i j : Fin n) :
    (((n : β„€) β€’ (1 : Matrix (Fin n) (Fin n) β„€)) i j : ℝ) =
      ((n : ℝ) β€’ (1 : Matrix (Fin n) (Fin n) ℝ)) i j := by
  by_cases hij : i = j <;> simp [Matrix.smul_apply, hij]

/-- The real coefficient embedding preserves and reflects the entire Gram
identity, including the diagonal value. -/
theorem gram_intCast_iff (h : Fin n β†’ β„€) :
    rowCirculant (fun a => (h a : ℝ)) *
        (rowCirculant (fun a => (h a : ℝ))).transpose =
        (n : ℝ) β€’ (1 : Matrix (Fin n) (Fin n) ℝ) ↔
      rowCirculant h * (rowCirculant h).transpose =
        (n : β„€) β€’ (1 : Matrix (Fin n) (Fin n) β„€) := by
  constructor
  Β· intro hGram
    ext i j
    apply Int.cast_injective (Ξ± := ℝ)
    rw [intCast_gram_apply, intCast_scaled_identity_apply]
    exact congrArg (fun M : Matrix (Fin n) (Fin n) ℝ => M i j) hGram
  Β· intro hGram
    ext i j
    rw [← intCast_gram_apply, ← intCast_scaled_identity_apply]
    exact congrArg (fun M : Matrix (Fin n) (Fin n) β„€ => (M i j : ℝ)) hGram

/-- Every integer sign row gives the actual real circulant Hadamard matrix. -/
theorem IsIntegerSignRow.exists_real {h : Fin n β†’ β„€} (hh : IsIntegerSignRow h) :
    ExistsRealCirculantHadamard n := by
  refine ⟨rowCirculant (fun a => (h a : ℝ)), rowCirculant_isCirculant _, ?_,
    (gram_intCast_iff h).mpr hh.2⟩
  intro i j
  rcases hh.1 (j - i) with hpos | hneg
  Β· left
    simp only [rowCirculant_apply, hpos, Int.cast_one]
  Β· right
    simp only [rowCirculant_apply, hneg, Int.cast_neg, Int.cast_one]

/-- A real sign matrix determines an integer sign row without approximation. -/
theorem ExistsRealCirculantHadamard.exists_integerSignRow [NeZero n]
    (hH : ExistsRealCirculantHadamard n) : βˆƒ h : Fin n β†’ β„€, IsIntegerSignRow h := by
  classical
  rcases hH with ⟨H, ⟨h, hrow⟩, hsign, hGram⟩
  have hsignRow : βˆ€ j, IsSign (h j) := by
    intro j
    simpa only [hrow, sub_zero] using hsign 0 j
  let z : Fin n β†’ β„€ := fun j => if h j = 1 then 1 else -1
  have hzcast : βˆ€ j, (z j : ℝ) = h j := by
    intro j
    by_cases hj : h j = 1
    Β· simp [z, hj]
    Β· have hneg := (hsignRow j).resolve_left hj
      simp only [z, ite_eq_right hj, Int.cast_neg, Int.cast_one, hneg]
  have hzsign : βˆ€ j, IsSign (z j) := by
    intro j
    dsimp [z, IsSign]
    split_ifs <;> simp
  have hzH : rowCirculant (fun j => (z j : ℝ)) = H := by
    ext i j
    rw [rowCirculant_apply, hzcast, hrow]
  refine ⟨z, hzsign, (gram_intCast_iff z).mp ?_⟩
  simpa only [hzH] using hGram

/-- Equivalence between the public real matrix problem and integer sign rows. -/
theorem integerSignRow_iff_real [NeZero n] :
    (βˆƒ h : Fin n β†’ β„€, IsIntegerSignRow h) ↔ ExistsRealCirculantHadamard n := by
  constructor
  · rintro ⟨h, hh⟩
    exact hh.exists_real
  Β· exact ExistsRealCirculantHadamard.exists_integerSignRow

/-- A direct integer autocorrelation presentation of the real matrix problem. -/
theorem existsReal_iff_integer_autocorrelation [NeZero n] :
    ExistsRealCirculantHadamard n ↔
      βˆƒ h : Fin n β†’ β„€, (βˆ€ j, IsSign (h j)) ∧
        βˆ€ a : Fin n, βˆ‘ j, h j * h (j - a) = if a = 0 then (n : β„€) else 0 := by
  rw [← integerSignRow_iff_real]
  simp only [IsIntegerSignRow, gram_eq_iff_autocorrelation]

end CirculantHadamard

end OAI