File size: 2,265 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 | import OAI.LinearAlgebra.Barker.Model
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.Ring
namespace OAI
namespace CirculantHadamard.Barker
open scoped BigOperators
def negativeBit {n : β} (h : Fin n β β€) (j : Fin n) : β€ :=
if h j = -1 then 1 else 0
theorem sign_eq_one_sub_two_bit {n : β} (h : Fin n β β€)
(hs : β j, IsSign (h j)) (j : Fin n) :
h j = 1 - 2 * negativeBit h j := by
rcases hs j with hj | hj <;> norm_num [negativeBit, hj]
def cyclicSubtractEquiv {n : β} [NeZero n] (a : Fin n) : Fin n β Fin n where
toFun j := j - a
invFun j := j + a
left_inv j := sub_add_cancel j a
right_inv j := add_sub_cancel_right j a
theorem sum_negativeBit_shift {n : β} [NeZero n] (h : Fin n β β€) (a : Fin n) :
(β j, negativeBit h (j - a)) = β j, negativeBit h j := by
exact (cyclicSubtractEquiv a).sum_comp (negativeBit h)
theorem periodic_bit_identity {n : β} [NeZero n] (h : Fin n β β€)
(hs : β j, IsSign (h j)) (a : Fin n) :
periodic h a = (n : β€) + 4 *
((β j, negativeBit h j * negativeBit h (j - a)) - β j, negativeBit h j) := by
have hterm (j : Fin n) : h j * h (j - a) =
1 - 2 * negativeBit h j - 2 * negativeBit h (j - a) +
4 * (negativeBit h j * negativeBit h (j - a)) := by
rw [sign_eq_one_sub_two_bit h hs j, sign_eq_one_sub_two_bit h hs (j - a)]
ring
calc
periodic h a = β j : Fin n,
(1 - 2 * negativeBit h j - 2 * negativeBit h (j - a) +
4 * (negativeBit h j * negativeBit h (j - a))) := by
unfold periodic
exact Finset.sum_congr rfl (fun j _ => hterm j)
_ = (n : β€) - 2 * (β j, negativeBit h j) -
2 * (β j, negativeBit h (j - a)) +
4 * (β j, negativeBit h j * negativeBit h (j - a)) := by
simp only [Finset.sum_add_distrib, Finset.sum_sub_distrib, β Finset.mul_sum]
simp
_ = _ := by rw [sum_negativeBit_shift]; ring
theorem periodic_mod_four {n : β} [NeZero n] (h : Fin n β β€)
(hs : β j, IsSign (h j)) (a : Fin n) :
(4 : β€) β£ periodic h a - (n : β€) := by
refine β¨(β j, negativeBit h j * negativeBit h (j - a)) -
β j, negativeBit h j, ?_β©
rw [periodic_bit_identity h hs a]
ring
end CirculantHadamard.Barker
end OAI
|