Skip to main content

feynkit_kinematics/
flux.rs

1//! Initial-state normalization shared by symbolic and numerical calculations.
2
3use std::ops::{Add, Mul, Sub};
4
5/// The denominator multiplying an invariant squared matrix element.
6///
7/// Decays use `2 E` in the frame where the rate is measured. Scattering uses
8/// `4 sqrt((p1.p2)^2 - m1^2 m2^2)`. Spin/color averages, final-state symmetry
9/// factors and unit conversions belong to the caller.
10#[derive(Clone, Debug)]
11pub enum InitialStateFlux<T> {
12    Decay {
13        energy: T,
14    },
15    Scattering {
16        momentum_dot: T,
17        mass_squared_product: T,
18    },
19}
20
21impl<T> InitialStateFlux<T>
22where
23    T: Clone + Add<Output = T> + Mul<Output = T> + Sub<Output = T>,
24{
25    /// Evaluate using the scalar's square-root operation.
26    ///
27    /// Supplying this operation keeps symbolic branch assumptions with
28    /// Symbolica and numerical precision with the caller's scalar type.
29    /// Inputs must describe physical incoming states; no threshold clipping
30    /// or absolute-value replacement is performed.
31    pub fn denominator(self, sqrt: impl FnOnce(T) -> T) -> T {
32        match self {
33            Self::Decay { energy } => energy.clone() + energy,
34            Self::Scattering {
35                momentum_dot,
36                mass_squared_product,
37            } => {
38                // The Kallen form removes the rational 1/4 inside the root
39                // for massless symbolic kinematics, leaving sqrt(s^2).
40                let twice_dot = momentum_dot.clone() + momentum_dot;
41                let twice_mass_product = mass_squared_product.clone() + mass_squared_product;
42                let root = sqrt(
43                    twice_dot.clone() * twice_dot
44                        - (twice_mass_product.clone() + twice_mass_product),
45                );
46                root.clone() + root
47            }
48        }
49    }
50}
51
52#[cfg(test)]
53mod tests {
54    use super::InitialStateFlux;
55    use crate::FourMomentum;
56    use symbolica::{
57        atom::{Atom, AtomCore},
58        parse,
59    };
60
61    #[test]
62    fn massive_massless_and_decay_flux_agree_across_scalar_types() {
63        let first = FourMomentum::from_args(5.0, 0.0, 0.0, 4.0);
64        let second = FourMomentum::from_args(13.0, 0.0, 0.0, -12.0);
65        let flux = InitialStateFlux::Scattering {
66            momentum_dot: first.dot(&second),
67            mass_squared_product: first.mass_squared() * second.mass_squared(),
68        }
69        .denominator(f64::sqrt);
70        assert_eq!(flux, 448.0);
71        assert_eq!(first.flux(Some(&second)), flux);
72        assert_eq!(first.flux(None), 10.0);
73        let symbolic = InitialStateFlux::Scattering {
74            momentum_dot: Atom::num(113),
75            mass_squared_product: Atom::num(225),
76        }
77        .denominator(|x| x.sqrt());
78        assert_eq!(symbolic, Atom::num(448));
79        assert_eq!(
80            InitialStateFlux::Scattering {
81                momentum_dot: 50.0,
82                mass_squared_product: 0.0
83            }
84            .denominator(f64::sqrt),
85            200.0
86        );
87        assert_eq!(
88            InitialStateFlux::Decay {
89                energy: parse!("E")
90            }
91            .denominator(|x| x.sqrt()),
92            parse!("2*E")
93        );
94        assert_eq!(
95            InitialStateFlux::Decay { energy: 13.0 }.denominator(f64::sqrt),
96            26.0
97        );
98    }
99}