Phase distribution, von Mises distribution, concentration parameter and Bessel functions of the closure-phase approximation
DefinitionArxiv1909_04681_BasicObjects of Sections 2-3 and Appendices A-B of Christian and Psaltis (arXiv:1909.04681v2).
- Error functions. and .
- Modified Bessel functions (eq. 34). For an integer and real , . The coefficient of in this series is when with (eqs. 35-36), and for every other integer . The ansatz of eq. (38) is .
- Phase distribution of one baseline (eq. 1). For visibility amplitude , noise and ,
exactly as printed. 4. Von Mises density (eq. 3). . 5. Curvature ratio (eqs. 4, 8). For a function with expansion at , the ratio , where and . 6. Concentration parameter (eqs. 13, 14). , and its approximation . 7. Closure phase (eqs. 22, 24, 25). The convolution ; the printed coefficients ; and the printed mixture distribution , . 8. Noise-dominated approximation (eq. 30). .
Formalization Note Eqs. (24) and (25) print twice and omit ; the definitions use . Eq. (1) is kept with the printed prefactor , although it integrates to over a period; the only statement that uses it (eq. 13) involves only the ratio , which does not depend on the prefactor. is defined as the actual coefficient of , so it vanishes when or is odd, where the printed formula (36) is not meaningful.
import Mathlib
/-!
Christian and Psaltis, *Interferometric Closure Phase Uncertainties in the Low Signal-to-Noise
Ratio Regime*, arXiv:1909.04681v2 (2020): the single-baseline phase distribution (eq. 1), the von
Mises distribution (eq. 3), the moment-matched concentration parameter (eqs. 4-13) and its
approximation (eq. 14) of Section 2; the triple convolution and the mixture distribution
(eqs. 22-25) of Section 3; the noise-dominated approximation (eq. 30) of Appendix A; and the
modified Bessel functions of the first kind with their series coefficients (eqs. 34-38) of
Appendix B.
-/
noncomputable section
namespace Arxiv1909_04681
open Real
/-- The error function `Erf`, used in eqs. (1), (5)-(7) and (13):
`Erf x = (2 / √π) ∫₀ˣ e^{-t²} dt`. -/
def erf (x : ℝ) : ℝ :=
2 / Real.sqrt Real.pi * ∫ t in (0 : ℝ)..x, Real.exp (-t ^ 2)
/-- The complementary error function `Erfc x = 1 - Erf x`, used in eqs. (7) and (13). -/
def erfc (x : ℝ) : ℝ := 1 - erf x
/-- Appendix B, eq. (34): the modified Bessel function of the first kind of integer order `n ≥ 0`,
`I_n(z) = (z/2)^n ∑_{k ≥ 0} (z²/4)^k / (k! (n+k)!)` (the series converges for every real `z`). -/
def besselI (n : ℕ) (z : ℝ) : ℝ :=
(z / 2) ^ n * ∑' k : ℕ, (z ^ 2 / 4) ^ k / ((Nat.factorial k : ℝ) * (Nat.factorial (n + k) : ℝ))
/-- Appendix B, eqs. (35)-(36): `C_{j,n}`, the coefficient of `z^j` in the power series of `I_n`,
equal to `2^{-j} [((j-n)/2)! ((j+n)/2)!]^{-1}` when `j = n + 2k` for some `k ∈ ℕ`, and `0` for
every other integer `j` (no such power occurs in the series). -/
def besselCoeff (j : ℤ) (n : ℕ) : ℝ :=
if (n : ℤ) ≤ j ∧ Even (j - n) then
1 / ((2 : ℝ) ^ j.toNat * ((Nat.factorial ((j - n) / 2).toNat : ℝ) *
(Nat.factorial ((j + n) / 2).toNat : ℝ)))
else 0
/-- Appendix B, eq. (38): the ansatz `Ĩ₄(z) = A I₀(z) + B I₁(z)/z + C I₀(z)/z² + D I₁(z)/z³`. -/
def besselI4Tilde (A B C D z : ℝ) : ℝ :=
A * besselI 0 z + B * besselI 1 z / z + C * besselI 0 z / z ^ 2 + D * besselI 1 z / z ^ 3
/-- Section 2, eq. (1): the phase distribution `P(φ)` of a single baseline with visibility
amplitude `V` and noise `σ`, `SNR = V/σ`, exactly as printed (prefactor `e^{-SNR²/2}/(4πσ)`):
`P(φ) = e^{-SNR²/2}/(4πσ) · (√(2π) SNR cos φ e^{SNR² cos² φ / 2} {Erf[SNR cos φ/√2] + 1} + 2)`. -/
def truePhaseDensity (V σ phi : ℝ) : ℝ :=
Real.exp (-(V / σ) ^ 2 / 2) / (4 * Real.pi * σ) *
(Real.sqrt (2 * Real.pi) * (V / σ) * Real.cos phi *
Real.exp ((V / σ) ^ 2 * Real.cos phi ^ 2 / 2) *
(erf ((V / σ) * Real.cos phi / Real.sqrt 2) + 1) + 2)
/-- Section 2, eq. (3): the von Mises density with location `μ` and concentration `κ`,
`vM(μ, κ, x) = e^{κ cos(x - μ)} / (2π I₀(κ))`. -/
def vonMises (μ κ x : ℝ) : ℝ :=
Real.exp (κ * Real.cos (x - μ)) / (2 * Real.pi * besselI 0 κ)
/-- Section 2, eqs. (4), (7), (8), (11): for an expansion `f(φ) = f₀ + f₂ φ² + O(φ³)` at `φ = 0`,
the ratio `f₂ / f₀` of the second-order to the zeroth-order coefficient, with the Taylor
coefficients `f₀ = f(0)` and `f₂ = f''(0)/2`. -/
def curvatureRatio (f : ℝ → ℝ) : ℝ :=
(iteratedDeriv 2 f 0 / 2) / f 0
/-- Section 2, eq. (13): the moment-matched von Mises concentration parameter `κ(SNR)`,
`κ = -SNR / {√(2π) SNR e^{SNR²/2} [Erf(SNR/√2) + 1] + 2}
× {-2 SNR + √(2π) e^{SNR²/2} (1 + SNR²) [Erfc(SNR/√2) - 2]}`. -/
def kappaOfSNR (S : ℝ) : ℝ :=
-(S / (Real.sqrt (2 * Real.pi) * S * Real.exp (S ^ 2 / 2) * (erf (S / Real.sqrt 2) + 1) + 2)) *
(-2 * S + Real.sqrt (2 * Real.pi) * Real.exp (S ^ 2 / 2) * (1 + S ^ 2) *
(erfc (S / Real.sqrt 2) - 2))
/-- Section 2, eq. (14): the approximation
`κ(SNR) ≈ √(π/2) SNR / (1 + √(π/2) SNR) + SNR²`. -/
def kappaApprox (S : ℝ) : ℝ :=
Real.sqrt (Real.pi / 2) * S / (1 + Real.sqrt (Real.pi / 2) * S) + S ^ 2
/-- Section 3, eq. (22): the convolution of three von Mises densities,
`G(x) = ∫₀^{2π} ∫₀^{2π} vM(μ₁,κ₁,θ) vM(μ₂,κ₂,φ-θ) vM(μ₃,κ₃,x-φ) dθ dφ`. -/
def vonMisesTripleConv (μ₁ μ₂ μ₃ κ₁ κ₂ κ₃ x : ℝ) : ℝ :=
∫ phi in (0 : ℝ)..(2 * Real.pi), ∫ θ in (0 : ℝ)..(2 * Real.pi),
vonMises μ₁ κ₁ θ * vonMises μ₂ κ₂ (phi - θ) * vonMises μ₃ κ₃ (x - phi)
/-- Section 3, eq. (24), as printed with the repeated factor `I_n(κ₁)` read as `I_n(κ₂)`:
`G̃_n = I_n(κ₁) I_n(κ₂) I_n(κ₃) / ((2π)³ I₀(κ₁) I₀(κ₂) I₀(κ₃))`, for `n ≥ 0`. -/
def mixtureFourierCoeff (κ₁ κ₂ κ₃ : ℝ) (n : ℕ) : ℝ :=
besselI n κ₁ * besselI n κ₂ * besselI n κ₃ /
((2 * Real.pi) ^ 3 * (besselI 0 κ₁ * besselI 0 κ₂ * besselI 0 κ₃))
/-- Section 3, eq. (25), the mixture distribution as printed (with `I_n(κ₂)` for the repeated
`I_n(κ₁)`): `1/(2π)³ + ∑_{n ≥ 1} G̃_n · 2 cos[n(x - c₀)]`, with `c₀ = μ₁ + μ₂ + μ₃`. -/
def mixtureDensity (μ₁ μ₂ μ₃ κ₁ κ₂ κ₃ x : ℝ) : ℝ :=
1 / (2 * Real.pi) ^ 3 +
∑' n : ℕ, mixtureFourierCoeff κ₁ κ₂ κ₃ (n + 1) *
(2 * Real.cos (((n + 1 : ℕ) : ℝ) * (x - (μ₁ + μ₂ + μ₃))))
/-- Appendix A, eq. (30): the noise-dominated approximation of the phase distribution,
`P_a(φ) = 1/(2π) + SNR cos φ / √(8π)`. -/
def noiseApprox (S phi : ℝ) : ℝ :=
1 / (2 * Real.pi) + S / Real.sqrt (8 * Real.pi) * Real.cos phi
end Arxiv1909_04681
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
erf defines, for every real , the function
The integral is oriented, so for it equals and is negative. No hypotheses are placed on .
erfc defines, for every real ,
with as above.
besselI defines, for a natural number (including ) and any real ,
- The sum is an unconditional infinite sum, with the convention that a non-summable series is assigned the value . For every real this series is absolutely summable, so the convention is never triggered.
- The conventions apply. Hence , and for .
- Only real arguments and non-negative integer orders are covered.
besselCoeff defines, for an integer (possibly negative) and a natural number , a real number :
- In the first case , and and are non-negative integers, so the formula involves no truncation.
- Every negative , every , and every with odd gives .
- The definition stands alone. Nothing in the code states a relation between and the series for .
besselI4Tilde defines, for arbitrary real parameters and real ,
with as defined above.
- The parameters are free inputs. Nothing ties them to any particular values or to .
- Division by zero is assigned the value . So at the last three terms are each , and .
truePhaseDensity defines, for arbitrary reals , , , a quantity . Write . Then
- There are no sign or positivity constraints. and may be zero or negative, and is any real number.
- Division by zero yields . So when , both and the prefactor become , and .
- When the prefactor is negative.
- The code asserts nothing about being non-negative, integrating to , or being a probability density.
vonMises defines, for arbitrary reals (location), (concentration) and ,
with the series defined above.
- is not restricted. It may be zero or negative.
- Since for every real , the denominator never vanishes.
- No claim of normalization is made in the code.
curvatureRatio defines, for an arbitrary function ,
Here is computed as the derivative of the derivative function evaluated at .
- No hypotheses are placed on : no differentiability, no Taylor-expansion form, no condition .
- At any point where is not differentiable, its derivative is taken to be , and likewise for . So for not twice differentiable near , the numerator may be a junk value (often ).
- If , then by the division-by-zero convention.
kappaOfSNR defines, for any real ,
- With the definition of above, the last bracket equals .
- is unrestricted and may be negative or zero; .
- If the first denominator vanishes, that fraction is taken to be .
- Nothing in the code relates to , to , or to .
kappaApprox defines, for any real ,
- is unrestricted.
- At the denominator vanishes, the fraction is taken to be , and the value is .
- No relationship to is asserted.
vonMisesTripleConv defines, for arbitrary reals and ,
- The inner integral is over and the outer integral over , both over the interval .
- The integrand is continuous, so both integrals are genuine. The convention assigning to non-integrable integrands is not triggered.
- The concentrations are unrestricted reals.
mixtureFourierCoeff defines, for arbitrary reals and a natural number ,
- In particular .
- The denominator never vanishes, because each .
- No locations enter.
mixtureDensity defines, for arbitrary reals and , writing ,
with as in mixtureFourierCoeff.
- The constant term equals .
- The infinite sum is an unconditional sum. If the series were not summable, the sum would be taken to be .
- No relationship between and (the triple convolution) is asserted.
noiseApprox defines, for arbitrary reals and ,
- is unrestricted in sign and size.
- No relationship to (
truePhaseDensity) is asserted.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.