math / data /lean /OAI /LinearAlgebra /Barker /PeriodicModFour.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
2.27 kB
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