feynkit_kinematics/
flux.rs1use std::ops::{Add, Mul, Sub};
4
5#[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 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 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}