math / data /lean /OAI /Analysis /Calculus /Current /Divergence.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
16.9 kB
import OAI.Analysis.Calculus.Current.Holomorphic
/-! Differential ingredients for the wave-current divergence calculation.
The Gaussian pair is defined by its actual scalar expression. The calculus
lemmas take ordinary derivative certificates for input curves; they do not
assume the weighted conservation identity to be proved.
-/
namespace OAI.Analysis.Calculus.Current
noncomputable section
def squaredDistance {d : β„•} (W : Fin d β†’ β„‚) (v : Fin d β†’ ℝ) : ℝ :=
βˆ‘ i, β€–W i - (v i : β„‚)β€– ^ 2
def gaussianLog {d : β„•} (ΞΊ ΞΊ' : ℝ) (v v' : Fin d β†’ ℝ)
(y : ℝ) (W : Fin d β†’ β„‚) : ℝ :=
-(d : ℝ) * Real.log y -
y / 2 * (ΞΊ * squaredDistance W v + ΞΊ' * squaredDistance W v')
/-- The pair weight `N` of equation (current-gaussian-pair), on `y > 0`. -/
def gaussianPair {d : β„•} (ΞΊ ΞΊ' : ℝ) (v v' : Fin d β†’ ℝ)
(y : ℝ) (W : Fin d β†’ β„‚) : ℝ := Real.exp (gaussianLog ΞΊ ΞΊ' v v' y W)
theorem gaussianPair_formula {d : β„•} (ΞΊ ΞΊ' : ℝ) (v v' : Fin d β†’ ℝ)
(y : ℝ) (hy : 0 < y) (W : Fin d β†’ β„‚) :
gaussianPair κ κ' v v' y W = (y ^ d)⁻¹ *
Real.exp (-(y / 2 * (ΞΊ * squaredDistance W v + ΞΊ' * squaredDistance W v'))) := by
unfold gaussianPair gaussianLog
rw [sub_eq_add_neg, Real.exp_add]
congr 1
rw [neg_mul, Real.exp_neg, Real.exp_nat_mul, Real.exp_log hy]
theorem gaussianPair_pos {d : β„•} (ΞΊ ΞΊ' : ℝ) (v v' : Fin d β†’ ℝ)
(y : ℝ) (W : Fin d β†’ β„‚) : 0 < gaussianPair ΞΊ ΞΊ' v v' y W :=
Real.exp_pos _
/-- Differentiate the exact Euclidean squared distance along an arbitrary real curve. -/
theorem hasDerivAt_squaredDistance {d : β„•} (W : ℝ β†’ Fin d β†’ β„‚)
(W' : Fin d β†’ β„‚) (v : Fin d β†’ ℝ) (t : ℝ)
(hW : βˆ€ i, HasDerivAt (fun s => W s i) (W' i) t) :
HasDerivAt (fun s => squaredDistance (W s) v)
(βˆ‘ i, 2 * inner ℝ (W t i - (v i : β„‚)) (W' i)) t := by
exact HasDerivAt.fun_sum fun i _ => ((hW i).sub_const (v i : β„‚)).norm_sq
/-- Ordinary derivative of the exact logarithmic Gaussian pair. -/
theorem hasDerivAt_gaussianLog {d : β„•} (ΞΊ ΞΊ' : ℝ) (v v' : Fin d β†’ ℝ)
(y : ℝ β†’ ℝ) (y' : ℝ) (W : ℝ β†’ Fin d β†’ β„‚) (W' : Fin d β†’ β„‚) (t : ℝ)
(hy : HasDerivAt y y' t) (hy0 : y t β‰  0)
(hW : βˆ€ i, HasDerivAt (fun s => W s i) (W' i) t) :
HasDerivAt (fun s => gaussianLog ΞΊ ΞΊ' v v' (y s) (W s))
(-(d : ℝ) * (y' / y t) -
((y' / 2) * (ΞΊ * squaredDistance (W t) v + ΞΊ' * squaredDistance (W t) v') +
y t / 2 *
(ΞΊ * (βˆ‘ i, 2 * inner ℝ (W t i - (v i : β„‚)) (W' i)) +
ΞΊ' * (βˆ‘ i, 2 * inner ℝ (W t i - (v' i : β„‚)) (W' i))))) t := by
exact ((hy.log hy0).const_mul (-(d : ℝ))).sub
((hy.div_const 2).mul
(((hasDerivAt_squaredDistance W W' v t hW).const_mul ΞΊ).add
((hasDerivAt_squaredDistance W W' v' t hW).const_mul ΞΊ')))
/-- Ordinary derivative of the exact Gaussian pair. -/
theorem hasDerivAt_gaussianPair {d : β„•} (ΞΊ ΞΊ' : ℝ) (v v' : Fin d β†’ ℝ)
(y : ℝ β†’ ℝ) (y' : ℝ) (W : ℝ β†’ Fin d β†’ β„‚) (W' : Fin d β†’ β„‚) (t : ℝ)
(hy : HasDerivAt y y' t) (hy0 : y t β‰  0)
(hW : βˆ€ i, HasDerivAt (fun s => W s i) (W' i) t) :
HasDerivAt (fun s => gaussianPair ΞΊ ΞΊ' v v' (y s) (W s))
(gaussianPair ΞΊ ΞΊ' v v' (y t) (W t) *
(-(d : ℝ) * (y' / y t) -
((y' / 2) * (ΞΊ * squaredDistance (W t) v + ΞΊ' * squaredDistance (W t) v') +
y t / 2 *
(ΞΊ * (βˆ‘ i, 2 * inner ℝ (W t i - (v i : β„‚)) (W' i)) +
ΞΊ' * (βˆ‘ i, 2 * inner ℝ (W t i - (v' i : β„‚)) (W' i)))))) t := by
exact (hasDerivAt_gaussianLog ΞΊ ΞΊ' v v' y y' W W' t hy hy0 hW).exp
/-- A real line in the actual complex imaginary-coordinate space. -/
def imaginaryLine {d : β„•} (z h : Index d β†’ β„‚) (t : ℝ) : Index d β†’ β„‚ :=
fun a => z a + (t : β„‚) * h a
@[simp] theorem imaginaryLine_zero {d : β„•} (z h : Index d β†’ β„‚) :
imaginaryLine z h 0 = z := by
funext a
simp [imaginaryLine]
theorem hasDerivAt_imaginaryLine {d : β„•} (z h : Index d β†’ β„‚) (a : Index d) :
HasDerivAt (fun t : ℝ => imaginaryLine z h t a) (h a) 0 := by
have hc : HasDerivAt (fun t : β„‚ => z a + t * h a) (h a) (0 : β„‚) := by
simpa using ((hasDerivAt_id (0 : β„‚)).mul_const (h a)).const_add (z a)
exact hc.comp_ofReal
private theorem hasDerivAt_complex_norm {f : ℝ β†’ β„‚} {f' : β„‚} {t : ℝ}
(hf : HasDerivAt f f' t) (h0 : f t β‰  0) :
HasDerivAt (fun s => β€–f sβ€–) (inner ℝ (f t) f' / β€–f tβ€–) t := by
have hh := hf.norm_sq.sqrt (pow_ne_zero 2 (norm_ne_zero_iff.mpr h0))
convert hh using 1
Β· funext s
simp
Β· simp
ring
def radiusSlope {d : β„•} (z h : Index d β†’ β„‚) : ℝ :=
inner ℝ (z none) (h none) / β€–z noneβ€–
def ratioSlope {d : β„•} (z h : Index d β†’ β„‚) : Fin d β†’ β„‚ :=
fun i => (h (some (some i)) * z none - z (some (some i)) * h none) / z none ^ 2
theorem hasDerivAt_radius_line {d : β„•} (z h : Index d β†’ β„‚) (hY : z none β‰  0) :
HasDerivAt (fun t => β€–imaginaryLine z h t noneβ€–) (radiusSlope z h) 0 := by
simpa [imaginaryLine, radiusSlope] using
hasDerivAt_complex_norm (hasDerivAt_imaginaryLine z h none)
(by simpa [imaginaryLine] using hY)
theorem hasDerivAt_ratio_line {d : β„•} (z h : Index d β†’ β„‚) (hY : z none β‰  0)
(i : Fin d) :
HasDerivAt (fun t => ratio (imaginaryLine z h t) i) (ratioSlope z h i) 0 := by
have hc (a : Index d) : HasDerivAt (fun t : β„‚ => z a + t * h a) (h a) (0 : β„‚) := by
simpa using ((hasDerivAt_id (0 : β„‚)).mul_const (h a)).const_add (z a)
have hh := ((hc (some (some i))).div (hc none) (by simpa using hY)).comp_ofReal
simpa [ratio, imaginaryLine, ratioSlope] using hh
/-- The actual scalar field `N` on the imaginary coordinates. -/
def gaussianField {d : β„•} (ΞΊ ΞΊ' : ℝ) (v v' : Fin d β†’ ℝ) (z : Index d β†’ β„‚) : ℝ :=
gaussianPair ΞΊ ΞΊ' v v' β€–z noneβ€– (ratio z)
/-- Explicit directional derivative of `log N` in the actual imaginary coordinates. -/
def gaussianLogSlope {d : β„•} (ΞΊ ΞΊ' : ℝ) (v v' : Fin d β†’ ℝ)
(z h : Index d β†’ β„‚) : ℝ :=
-(d : ℝ) * (radiusSlope z h / β€–z noneβ€–) -
((radiusSlope z h / 2) *
(ΞΊ * squaredDistance (ratio z) v + ΞΊ' * squaredDistance (ratio z) v') +
β€–z noneβ€– / 2 *
(ΞΊ * (βˆ‘ i, 2 * inner ℝ (ratio z i - (v i : β„‚)) (ratioSlope z h i)) +
ΞΊ' * (βˆ‘ i, 2 * inner ℝ (ratio z i - (v' i : β„‚)) (ratioSlope z h i))))
/-- Every real directional derivative of the exact Gaussian field is verified. -/
theorem hasDerivAt_gaussianField_line {d : β„•} (ΞΊ ΞΊ' : ℝ) (v v' : Fin d β†’ ℝ)
(z h : Index d β†’ β„‚) (hY : z none β‰  0) :
HasDerivAt (fun t => gaussianField ΞΊ ΞΊ' v v' (imaginaryLine z h t))
(gaussianField ΞΊ ΞΊ' v v' z * gaussianLogSlope ΞΊ ΞΊ' v v' z h) 0 := by
have hh := hasDerivAt_gaussianPair ΞΊ ΞΊ' v v'
(fun t => β€–imaginaryLine z h t noneβ€–) (radiusSlope z h)
(fun t => ratio (imaginaryLine z h t)) (ratioSlope z h) 0
(hasDerivAt_radius_line z h hY)
(by simpa [imaginaryLine] using norm_ne_zero_iff.mpr hY)
(hasDerivAt_ratio_line z h hY)
simpa only [gaussianField, gaussianLogSlope, imaginaryLine_zero] using hh
/-- The two real directional derivatives that form `βˆ‘ conj(Vₐ) barDₐ`.
The equivalence with the coordinate sum is real linearity of the differential. -/
def barDirectional {d : β„•} (f : (Index d β†’ β„‚) β†’ ℝ) (z V : Index d β†’ β„‚) : β„‚ :=
((deriv (fun t => f (imaginaryLine z V t)) 0 : ℝ) : β„‚) +
Complex.I * ((deriv (fun t => f (imaginaryLine z (fun a => Complex.I * V a) t)) 0 : ℝ) : β„‚)
theorem gaussianField_barDirectional {d : β„•} (ΞΊ ΞΊ' : ℝ) (v v' : Fin d β†’ ℝ)
(z V : Index d β†’ β„‚) (hY : z none β‰  0) :
barDirectional (gaussianField ΞΊ ΞΊ' v v') z V =
(gaussianField ΞΊ ΞΊ' v v' z : β„‚) *
((gaussianLogSlope ΞΊ ΞΊ' v v' z V : β„‚) +
Complex.I * (gaussianLogSlope ΞΊ ΞΊ' v v' z (fun a => Complex.I * V a) : β„‚)) := by
unfold barDirectional
rw [(hasDerivAt_gaussianField_line ΞΊ ΞΊ' v v' z V hY).deriv,
(hasDerivAt_gaussianField_line ΞΊ ΞΊ' v v' z (fun a => Complex.I * V a) hY).deriv]
push_cast
ring
theorem complex_inner_pair (a b : β„‚) :
(inner ℝ a b : β„‚) + Complex.I * (inner ℝ a (Complex.I * b) : β„‚) = a * star b := by
apply Complex.ext <;> simp <;> ring
def distanceSlope {d : β„•} (W h : Fin d β†’ β„‚) (v : Fin d β†’ ℝ) : ℝ :=
βˆ‘ i, 2 * inner ℝ (W i - (v i : β„‚)) (h i)
theorem distanceSlope_pair {d : β„•} (W h : Fin d β†’ β„‚) (v : Fin d β†’ ℝ) :
(distanceSlope W h v : β„‚) +
Complex.I * (distanceSlope W (fun i => Complex.I * h i) v : β„‚) =
2 * βˆ‘ i, (W i - (v i : β„‚)) * star (h i) := by
simp only [distanceSlope, Complex.ofReal_sum, Complex.ofReal_mul,
Complex.ofReal_ofNat, Finset.mul_sum]
rw [← Finset.sum_add_distrib]
apply Finset.sum_congr rfl
intro i _
linear_combination (2 : β„‚) * complex_inner_pair (W i - (v i : β„‚)) (h i)
def energySlope {d : β„•} (y : ℝ) (W : Fin d β†’ β„‚) (y' : ℝ)
(W' : Fin d β†’ β„‚) (v : Fin d β†’ ℝ) : ℝ :=
y' * squaredDistance W v + y * distanceSlope W W' v
theorem energySlope_pair {d : β„•} (y y₁ yβ‚‚ : ℝ) (W h : Fin d β†’ β„‚) (v : Fin d β†’ ℝ) :
(energySlope y W y₁ h v : β„‚) +
Complex.I * (energySlope y W yβ‚‚ (fun i => Complex.I * h i) v : β„‚) =
((y₁ : β„‚) + Complex.I * (yβ‚‚ : β„‚)) * (squaredDistance W v : β„‚) +
(y : β„‚) * (2 * βˆ‘ i, (W i - (v i : β„‚)) * star (h i)) := by
have hd := distanceSlope_pair W h v
simp only [energySlope, Complex.ofReal_add, Complex.ofReal_mul]
linear_combination (y : β„‚) * hd
theorem ratioSlope_I {d : β„•} (z h : Index d β†’ β„‚) (i : Fin d) :
ratioSlope z (fun a => Complex.I * h a) i = Complex.I * ratioSlope z h i := by
unfold ratioSlope
ring
theorem radiusSlope_pair {d : β„•} (z h : Index d β†’ β„‚) :
(radiusSlope z h : β„‚) +
Complex.I * (radiusSlope z (fun a => Complex.I * h a) : β„‚) =
z none * star (h none) / (β€–z noneβ€– : β„‚) := by
unfold radiusSlope
push_cast
rw [← mul_div_assoc, ← add_div, complex_inner_pair]
theorem ratioSlope_tangentVector {d : β„•} (z : Index d β†’ β„‚) (hY : z none β‰  0)
(v : Fin d β†’ ℝ) (i : Fin d) :
ratioSlope z (tangentVector (fun i => (v i : β„‚)) (ratio z)) i =
((v i : β„‚) - ratio z i) / (2 * z none) := by
simp only [ratioSlope, tangentVector, ratio]
field_simp
ring
theorem radiusSlope_tangentVector_pair {d : β„•} (z : Index d β†’ β„‚)
(v : Fin d β†’ ℝ) :
(radiusSlope z (tangentVector (fun i => (v i : β„‚)) (ratio z)) : β„‚) +
Complex.I * (radiusSlope z
(fun a => Complex.I * tangentVector (fun i => (v i : β„‚)) (ratio z) a) : β„‚) =
z none / (β€–z noneβ€– : β„‚) := by
rw [radiusSlope_pair]
simp [tangentVector]
theorem norm_square_eq_mul_star (z : β„‚) : (β€–zβ€– : β„‚) ^ 2 = z * star z := by
rw [← Complex.ofReal_pow]
apply Complex.ext <;> simp [Complex.sq_norm, Complex.normSq_apply] ; ring
theorem norm_div_star (Y : β„‚) (hY : Y β‰  0) :
(β€–Yβ€– : β„‚) / star Y = Y / (β€–Yβ€– : β„‚) := by
have hn : (β€–Yβ€– : β„‚) β‰  0 := by exact_mod_cast norm_ne_zero_iff.mpr hY
have hs : star Y β‰  0 := star_ne_zero.mpr hY
apply (div_eq_div_iff hs hn).mpr
simpa only [← pow_two] using norm_square_eq_mul_star Y
theorem squaredDistance_coe {d : β„•} (W : Fin d β†’ β„‚) (v : Fin d β†’ ℝ) :
(squaredDistance W v : β„‚) =
βˆ‘ i, (W i - (v i : β„‚)) * star (W i - (v i : β„‚)) := by
simp only [squaredDistance, Complex.ofReal_sum, Complex.ofReal_pow]
apply Finset.sum_congr rfl
intro i _
exact norm_square_eq_mul_star _
private theorem gaussian_energy_cancellation {d : β„•} (Y : β„‚) (hY : Y β‰  0)
(W : Fin d β†’ β„‚) (v w : Fin d β†’ ℝ) :
(Y / (β€–Yβ€– : β„‚)) * (squaredDistance W w : β„‚) +
(β€–Yβ€– : β„‚) * (2 * βˆ‘ i, (W i - (w i : β„‚)) *
star (((v i : β„‚) - W i) / (2 * Y))) =
(Y / (β€–Yβ€– : β„‚)) * βˆ‘ i, (W i - (w i : β„‚)) * ((v i : β„‚) - (w i : β„‚)) := by
rw [squaredDistance_coe]
simp only [Finset.mul_sum]
rw [← Finset.sum_add_distrib]
apply Finset.sum_congr rfl
intro i _
have hs : star Y β‰  0 := star_ne_zero.mpr hY
have hc : (β€–Yβ€– : β„‚) * (2 * ((W i - (w i : β„‚)) *
star (((v i : β„‚) - W i) / (2 * Y)))) =
((β€–Yβ€– : β„‚) / star Y) * (W i - (w i : β„‚)) * ((v i : β„‚) - star (W i)) := by
simp only [star_divβ‚€, star_sub, star_mul, star_ofNat, Complex.star_def,
Complex.conj_ofReal]
field_simp
rw [hc, norm_div_star Y hY]
simp only [star_sub, Complex.star_def, Complex.conj_ofReal]
ring
/-- The Gaussian directional cancellation in equation (gaussian-directional-identity),
written using the two actual real differential components already proved above. -/
theorem gaussian_energy_tangent_pair {d : β„•} (z : Index d β†’ β„‚) (hY : z none β‰  0)
(v w : Fin d β†’ ℝ) :
let V := tangentVector (fun i => (v i : β„‚)) (ratio z)
(energySlope β€–z noneβ€– (ratio z) (radiusSlope z V) (ratioSlope z V) w : β„‚) +
Complex.I * (energySlope β€–z noneβ€– (ratio z)
(radiusSlope z (fun a => Complex.I * V a))
(ratioSlope z (fun a => Complex.I * V a)) w : β„‚) =
(z none / (β€–z noneβ€– : β„‚)) *
βˆ‘ i, (ratio z i - (w i : β„‚)) * ((v i : β„‚) - (w i : β„‚)) := by
dsimp only
rw [funext (ratioSlope_I z (tangentVector (fun i => (v i : β„‚)) (ratio z)))]
rw [energySlope_pair, radiusSlope_tangentVector_pair]
simp_rw [ratioSlope_tangentVector z hY]
exact gaussian_energy_cancellation (z none) hY (ratio z) v w
theorem gaussianLogSlope_energy {d : β„•} (ΞΊ ΞΊ' : ℝ) (v v' : Fin d β†’ ℝ)
(z h : Index d β†’ β„‚) :
gaussianLogSlope ΞΊ ΞΊ' v v' z h =
-(d : ℝ) * (radiusSlope z h / β€–z noneβ€–) -
(ΞΊ * energySlope β€–z noneβ€– (ratio z) (radiusSlope z h) (ratioSlope z h) v +
ΞΊ' * energySlope β€–z noneβ€– (ratio z) (radiusSlope z h) (ratioSlope z h) v') / 2 := by
unfold gaussianLogSlope energySlope distanceSlope
ring
theorem gaussian_energy_tangent_pair_phase {d : β„•} (z : Index d β†’ β„‚)
(hY : z none β‰  0) (v w : Fin d β†’ ℝ) :
let V := tangentVector (fun i => (v i : β„‚)) (ratio z)
(energySlope β€–z noneβ€– (ratio z) (radiusSlope z V) (ratioSlope z V) w : β„‚) +
Complex.I * (energySlope β€–z noneβ€– (ratio z)
(radiusSlope z (fun a => Complex.I * V a))
(ratioSlope z (fun a => Complex.I * V a)) w : β„‚) =
-2 * (z none / (β€–z noneβ€– : β„‚)) *
(βˆ‘ a, phaseRow (fun i => (w i : β„‚)) a * V a) := by
dsimp only
rw [gaussian_energy_tangent_pair z hY, phase_polarization]
have hs : (βˆ‘ i, ((w i : β„‚) - ratio z i) * ((w i : β„‚) - (v i : β„‚))) =
βˆ‘ i, (ratio z i - (w i : β„‚)) * ((v i : β„‚) - (w i : β„‚)) := by
apply Finset.sum_congr rfl
intro i _
ring
rw [hs]
ring
/-- The full logarithmic Gaussian directional identity, for two distinct modes. -/
theorem gaussianLogSlope_tangent_pair {d : β„•} (ΞΊ ΞΊ' : ℝ) (v v' : Fin d β†’ ℝ)
(z : Index d β†’ β„‚) (hY : z none β‰  0) :
let V := tangentVector (fun i => (v i : β„‚)) (ratio z)
(gaussianLogSlope ΞΊ ΞΊ' v v' z V : β„‚) +
Complex.I * (gaussianLogSlope ΞΊ ΞΊ' v v' z (fun a => Complex.I * V a) : β„‚) =
(z none / (β€–z noneβ€– : β„‚)) *
(-(d : β„‚) / (β€–z noneβ€– : β„‚) +
(ΞΊ' : β„‚) * βˆ‘ a, phaseRow (fun i => (v' i : β„‚)) a * V a) := by
dsimp only
have hr := radiusSlope_tangentVector_pair z v
have hv := gaussian_energy_tangent_pair_phase z hY v v
have hv' := gaussian_energy_tangent_pair_phase z hY v v'
dsimp only at hv hv'
rw [phase_tangent] at hv
simp only [mul_zero] at hv
simp only [gaussianLogSlope_energy, Complex.ofReal_sub, Complex.ofReal_mul,
Complex.ofReal_neg, Complex.ofReal_natCast, Complex.ofReal_div,
Complex.ofReal_add, Complex.ofReal_ofNat]
linear_combination (-(d : β„‚) / (β€–z noneβ€– : β„‚)) * hr -
((ΞΊ : β„‚) / 2) * hv - ((ΞΊ' : β„‚) / 2) * hv'
/-- Equation (current-log-derivative) applied to the exact scalar Gaussian field. -/
theorem gaussianField_tangent_derivative {d : β„•} (ΞΊ ΞΊ' : ℝ) (v v' : Fin d β†’ ℝ)
(z : Index d β†’ β„‚) (hY : z none β‰  0) :
let V := tangentVector (fun i => (v i : β„‚)) (ratio z)
barDirectional (gaussianField ΞΊ ΞΊ' v v') z V =
(gaussianField ΞΊ ΞΊ' v v' z : β„‚) * (z none / (β€–z noneβ€– : β„‚)) *
(-(d : β„‚) / (β€–z noneβ€– : β„‚) +
(ΞΊ' : β„‚) * βˆ‘ a, phaseRow (fun i => (v' i : β„‚)) a * V a) := by
dsimp only
rw [gaussianField_barDirectional ΞΊ ΞΊ' v v' z _ hY,
gaussianLogSlope_tangent_pair ΞΊ ΞΊ' v v' z hY]
ring
end
end OAI.Analysis.Calculus.Current