Theorem: jacobiTheta₂_functional_equation
File: Mathlib/NumberTheory/ModularForms/JacobiTheta/TwoVariable.lean

tactic: rcases le_or_lt (im τ) 0 with hτ | hτ
state_before: z τ : ℂ
⊢ jacobiTheta₂ z τ = 1 / (-I * τ) ^ (1 / 2) * cexp (-↑π * I * z ^ 2 / τ) * jacobiTheta₂ (z / τ) (-1 / τ)
state_after: case inl
z τ : ℂ
hτ : τ.im ≤ 0
⊢ jacobiTheta₂ z τ = 1 / (-I * τ) ^ (1 / 2) * cexp (-↑π * I * z ^ 2 / τ) * jacobiTheta₂ (z / τ) (-1 / τ)

case inr
z τ : ℂ
hτ : 0 < τ.im
⊢ jacobiTheta₂ z τ = 1 / (-I * τ) ^ (1 / 2) * cexp (-↑π * I * z ^ 2 / τ) * jacobiTheta₂ (z / τ) (-1 / τ)

tactic: unfold jacobiTheta₂ jacobiTheta₂_term
state_before: case inr
z τ : ℂ
hτ : 0 < τ.im
⊢ jacobiTheta₂ z τ = 1 / (-I * τ) ^ (1 / 2) * cexp (-↑π * I * z ^ 2 / τ) * jacobiTheta₂ (z / τ) (-1 / τ)
state_after: case inr
z τ : ℂ
hτ : 0 < τ.im
⊢ ∑' (n : ℤ), cexp (2 * ↑π * I * ↑n * z + ↑π * I * ↑n ^ 2 * τ) =
    1 / (-I * τ) ^ (1 / 2) * cexp (-↑π * I * z ^ 2 / τ) *
      ∑' (n : ℤ), cexp (2 * ↑π * I * ↑n * (z / τ) + ↑π * I * ↑n ^ 2 * (-1 / τ))

tactic: have h0 : τ ≠ 0 := by contrapose! hτ; rw [hτ, zero_im]
state_before: case inr
z τ : ℂ
hτ : 0 < τ.im
⊢ ∑' (n : ℤ), cexp (2 * ↑π * I * ↑n * z + ↑π * I * ↑n ^ 2 * τ) =
    1 / (-I * τ) ^ (1 / 2) * cexp (-↑π * I * z ^ 2 / τ) *
      ∑' (n : ℤ), cexp (2 * ↑π * I * ↑n * (z / τ) + ↑π * I * ↑n ^ 2 * (-1 / τ))
state_after: case inr
z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
⊢ ∑' (n : ℤ), cexp (2 * ↑π * I * ↑n * z + ↑π * I * ↑n ^ 2 * τ) =
    1 / (-I * τ) ^ (1 / 2) * cexp (-↑π * I * z ^ 2 / τ) *
      ∑' (n : ℤ), cexp (2 * ↑π * I * ↑n * (z / τ) + ↑π * I * ↑n ^ 2 * (-1 / τ))

tactic: have h2 : 0 < (-I * τ).re := by
  simpa only [neg_mul, neg_re, mul_re, I_re, zero_mul, I_im, one_mul, zero_sub, neg_neg] using hτ
state_before: case inr
z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
⊢ ∑' (n : ℤ), cexp (2 * ↑π * I * ↑n * z + ↑π * I * ↑n ^ 2 * τ) =
    1 / (-I * τ) ^ (1 / 2) * cexp (-↑π * I * z ^ 2 / τ) *
      ∑' (n : ℤ), cexp (2 * ↑π * I * ↑n * (z / τ) + ↑π * I * ↑n ^ 2 * (-1 / τ))
state_after: case inr
z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
h2 : 0 < (-I * τ).re
⊢ ∑' (n : ℤ), cexp (2 * ↑π * I * ↑n * z + ↑π * I * ↑n ^ 2 * τ) =
    1 / (-I * τ) ^ (1 / 2) * cexp (-↑π * I * z ^ 2 / τ) *
      ∑' (n : ℤ), cexp (2 * ↑π * I * ↑n * (z / τ) + ↑π * I * ↑n ^ 2 * (-1 / τ))

tactic: calc
_ = ∑' n : ℤ, cexp (-π * (-I * τ) * ↑n ^ 2 + 2 * π * (I * z) * ↑n) :=
  tsum_congr (fun n ↦ by ring_nf)
_ = 1 / (-I * τ) ^ (1 / 2 : ℂ) * ∑' (n : ℤ), cexp (-π / (-I * τ) * (n + I * (I * z)) ^ 2) := by
  rw [tsum_exp_neg_quadratic h2]
_ = 1 / (-I * τ) ^ (1 / 2 : ℂ) * cexp (π * I * (-1 / τ) * z ^ 2) *
    ∑' (n : ℤ), cexp (2 * π * I * n * (z / τ) + π * I * n ^ 2 * (-1 / τ)) := by
  simp_rw [mul_assoc _ (cexp _), ← tsum_mul_left (a := cexp _), ← Complex.exp_add]
  congr 2 with n : 1; congr 1
  field_simp [I_ne_zero]
  ring_nf
  simp_rw [I_sq, I_pow_four]
  ring_nf
_ = _ := by
  congr 3
  ring
state_before: case inr
z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
h2 : 0 < (-I * τ).re
⊢ ∑' (n : ℤ), cexp (2 * ↑π * I * ↑n * z + ↑π * I * ↑n ^ 2 * τ) =
    1 / (-I * τ) ^ (1 / 2) * cexp (-↑π * I * z ^ 2 / τ) *
      ∑' (n : ℤ), cexp (2 * ↑π * I * ↑n * (z / τ) + ↑π * I * ↑n ^ 2 * (-1 / τ))
state_after: no goals

tactic: have : (-1 / τ).im ≤ 0 := by
  rw [neg_div, neg_im, one_div, inv_im, neg_nonpos]
  exact div_nonneg (neg_nonneg.mpr hτ) (normSq_nonneg τ)
state_before: case inl
z τ : ℂ
hτ : τ.im ≤ 0
⊢ jacobiTheta₂ z τ = 1 / (-I * τ) ^ (1 / 2) * cexp (-↑π * I * z ^ 2 / τ) * jacobiTheta₂ (z / τ) (-1 / τ)
state_after: case inl
z τ : ℂ
hτ : τ.im ≤ 0
this : (-1 / τ).im ≤ 0
⊢ jacobiTheta₂ z τ = 1 / (-I * τ) ^ (1 / 2) * cexp (-↑π * I * z ^ 2 / τ) * jacobiTheta₂ (z / τ) (-1 / τ)

tactic: rw [jacobiTheta₂_undef z hτ, jacobiTheta₂_undef _ this, mul_zero]
state_before: case inl
z τ : ℂ
hτ : τ.im ≤ 0
this : (-1 / τ).im ≤ 0
⊢ jacobiTheta₂ z τ = 1 / (-I * τ) ^ (1 / 2) * cexp (-↑π * I * z ^ 2 / τ) * jacobiTheta₂ (z / τ) (-1 / τ)
state_after: no goals

tactic: rw [neg_div, neg_im, one_div, inv_im, neg_nonpos]
state_before: z τ : ℂ
hτ : τ.im ≤ 0
⊢ (-1 / τ).im ≤ 0
state_after: z τ : ℂ
hτ : τ.im ≤ 0
⊢ 0 ≤ -τ.im / normSq τ

tactic: exact div_nonneg (neg_nonneg.mpr hτ) (normSq_nonneg τ)
state_before: z τ : ℂ
hτ : τ.im ≤ 0
⊢ 0 ≤ -τ.im / normSq τ
state_after: no goals

tactic: contrapose! hτ
state_before: z τ : ℂ
hτ : 0 < τ.im
⊢ τ ≠ 0
state_after: z τ : ℂ
hτ : τ = 0
⊢ τ.im ≤ 0

tactic: rw [hτ, zero_im]
state_before: z τ : ℂ
hτ : τ = 0
⊢ τ.im ≤ 0
state_after: no goals

tactic: simpa only [neg_mul, neg_re, mul_re, I_re, zero_mul, I_im, one_mul, zero_sub, neg_neg] using hτ
state_before: z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
⊢ 0 < (-I * τ).re
state_after: no goals

tactic: ring_nf
state_before: z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
h2 : 0 < (-I * τ).re
n : ℤ
⊢ cexp (2 * ↑π * I * ↑n * z + ↑π * I * ↑n ^ 2 * τ) = cexp (-↑π * (-I * τ) * ↑n ^ 2 + 2 * ↑π * (I * z) * ↑n)
state_after: no goals

tactic: rw [tsum_exp_neg_quadratic h2]
state_before: z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
h2 : 0 < (-I * τ).re
⊢ ∑' (n : ℤ), cexp (-↑π * (-I * τ) * ↑n ^ 2 + 2 * ↑π * (I * z) * ↑n) =
    1 / (-I * τ) ^ (1 / 2) * ∑' (n : ℤ), cexp (-↑π / (-I * τ) * (↑n + I * (I * z)) ^ 2)
state_after: no goals

tactic: simp_rw [mul_assoc _ (cexp _), ← tsum_mul_left (a := cexp _), ← Complex.exp_add]
state_before: z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
h2 : 0 < (-I * τ).re
⊢ 1 / (-I * τ) ^ (1 / 2) * ∑' (n : ℤ), cexp (-↑π / (-I * τ) * (↑n + I * (I * z)) ^ 2) =
    1 / (-I * τ) ^ (1 / 2) * cexp (↑π * I * (-1 / τ) * z ^ 2) *
      ∑' (n : ℤ), cexp (2 * ↑π * I * ↑n * (z / τ) + ↑π * I * ↑n ^ 2 * (-1 / τ))
state_after: z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
h2 : 0 < (-I * τ).re
⊢ 1 / (-I * τ) ^ (1 / 2) * ∑' (n : ℤ), cexp (-↑π / (-I * τ) * (↑n + I * (I * z)) ^ 2) =
    1 / (-I * τ) ^ (1 / 2) *
      ∑' (x : ℤ), cexp (↑π * I * (-1 / τ) * z ^ 2 + (2 * ↑π * I * ↑x * (z / τ) + ↑π * I * ↑x ^ 2 * (-1 / τ)))

tactic: congr 2 with n : 1
state_before: z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
h2 : 0 < (-I * τ).re
⊢ 1 / (-I * τ) ^ (1 / 2) * ∑' (n : ℤ), cexp (-↑π / (-I * τ) * (↑n + I * (I * z)) ^ 2) =
    1 / (-I * τ) ^ (1 / 2) *
      ∑' (x : ℤ), cexp (↑π * I * (-1 / τ) * z ^ 2 + (2 * ↑π * I * ↑x * (z / τ) + ↑π * I * ↑x ^ 2 * (-1 / τ)))
state_after: case e_a.e_f.h
z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
h2 : 0 < (-I * τ).re
n : ℤ
⊢ cexp (-↑π / (-I * τ) * (↑n + I * (I * z)) ^ 2) =
    cexp (↑π * I * (-1 / τ) * z ^ 2 + (2 * ↑π * I * ↑n * (z / τ) + ↑π * I * ↑n ^ 2 * (-1 / τ)))

tactic: congr 1
state_before: case e_a.e_f.h
z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
h2 : 0 < (-I * τ).re
n : ℤ
⊢ cexp (-↑π / (-I * τ) * (↑n + I * (I * z)) ^ 2) =
    cexp (↑π * I * (-1 / τ) * z ^ 2 + (2 * ↑π * I * ↑n * (z / τ) + ↑π * I * ↑n ^ 2 * (-1 / τ)))
state_after: case e_a.e_f.h.e_z
z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
h2 : 0 < (-I * τ).re
n : ℤ
⊢ -↑π / (-I * τ) * (↑n + I * (I * z)) ^ 2 =
    ↑π * I * (-1 / τ) * z ^ 2 + (2 * ↑π * I * ↑n * (z / τ) + ↑π * I * ↑n ^ 2 * (-1 / τ))

tactic: field_simp [I_ne_zero]
state_before: case e_a.e_f.h.e_z
z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
h2 : 0 < (-I * τ).re
n : ℤ
⊢ -↑π / (-I * τ) * (↑n + I * (I * z)) ^ 2 =
    ↑π * I * (-1 / τ) * z ^ 2 + (2 * ↑π * I * ↑n * (z / τ) + ↑π * I * ↑n ^ 2 * (-1 / τ))
state_after: case e_a.e_f.h.e_z
z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
h2 : 0 < (-I * τ).re
n : ℤ
⊢ ↑π * (↑n + I * (I * z)) ^ 2 * (τ * τ) =
    (-(↑π * I * z ^ 2 * τ) + (2 * ↑π * I * ↑n * z + -(↑π * I * ↑n ^ 2)) * τ) * (I * τ)

tactic: ring_nf
state_before: case e_a.e_f.h.e_z
z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
h2 : 0 < (-I * τ).re
n : ℤ
⊢ ↑π * (↑n + I * (I * z)) ^ 2 * (τ * τ) =
    (-(↑π * I * z ^ 2 * τ) + (2 * ↑π * I * ↑n * z + -(↑π * I * ↑n ^ 2)) * τ) * (I * τ)
state_after: case e_a.e_f.h.e_z
z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
h2 : 0 < (-I * τ).re
n : ℤ
⊢ ↑π * ↑n * I ^ 2 * z * τ ^ 2 * 2 + ↑π * ↑n ^ 2 * τ ^ 2 + ↑π * I ^ 4 * z ^ 2 * τ ^ 2 =
    ↑π * ↑n * I ^ 2 * z * τ ^ 2 * 2 + (-(↑π * ↑n ^ 2 * I ^ 2 * τ ^ 2) - ↑π * I ^ 2 * z ^ 2 * τ ^ 2)

tactic: simp_rw [I_sq, I_pow_four]
state_before: case e_a.e_f.h.e_z
z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
h2 : 0 < (-I * τ).re
n : ℤ
⊢ ↑π * ↑n * I ^ 2 * z * τ ^ 2 * 2 + ↑π * ↑n ^ 2 * τ ^ 2 + ↑π * I ^ 4 * z ^ 2 * τ ^ 2 =
    ↑π * ↑n * I ^ 2 * z * τ ^ 2 * 2 + (-(↑π * ↑n ^ 2 * I ^ 2 * τ ^ 2) - ↑π * I ^ 2 * z ^ 2 * τ ^ 2)
state_after: case e_a.e_f.h.e_z
z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
h2 : 0 < (-I * τ).re
n : ℤ
⊢ ↑π * ↑n * -1 * z * τ ^ 2 * 2 + ↑π * ↑n ^ 2 * τ ^ 2 + ↑π * 1 * z ^ 2 * τ ^ 2 =
    ↑π * ↑n * -1 * z * τ ^ 2 * 2 + (-(↑π * ↑n ^ 2 * -1 * τ ^ 2) - ↑π * -1 * z ^ 2 * τ ^ 2)

tactic: ring_nf
state_before: case e_a.e_f.h.e_z
z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
h2 : 0 < (-I * τ).re
n : ℤ
⊢ ↑π * ↑n * -1 * z * τ ^ 2 * 2 + ↑π * ↑n ^ 2 * τ ^ 2 + ↑π * 1 * z ^ 2 * τ ^ 2 =
    ↑π * ↑n * -1 * z * τ ^ 2 * 2 + (-(↑π * ↑n ^ 2 * -1 * τ ^ 2) - ↑π * -1 * z ^ 2 * τ ^ 2)
state_after: no goals

tactic: congr 3
state_before: z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
h2 : 0 < (-I * τ).re
⊢ 1 / (-I * τ) ^ (1 / 2) * cexp (↑π * I * (-1 / τ) * z ^ 2) *
      ∑' (n : ℤ), cexp (2 * ↑π * I * ↑n * (z / τ) + ↑π * I * ↑n ^ 2 * (-1 / τ)) =
    1 / (-I * τ) ^ (1 / 2) * cexp (-↑π * I * z ^ 2 / τ) *
      ∑' (n : ℤ), cexp (2 * ↑π * I * ↑n * (z / τ) + ↑π * I * ↑n ^ 2 * (-1 / τ))
state_after: case e_a.e_a.e_z
z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
h2 : 0 < (-I * τ).re
⊢ ↑π * I * (-1 / τ) * z ^ 2 = -↑π * I * z ^ 2 / τ

tactic: ring
state_before: case e_a.e_a.e_z
z τ : ℂ
hτ : 0 < τ.im
h0 : τ ≠ 0
h2 : 0 < (-I * τ).re
⊢ ↑π * I * (-1 / τ) * z ^ 2 = -↑π * I * z ^ 2 / τ
state_after: no goals