Skip to main content

feynkit_graph/
power_counting.rs

1use symbolica::{
2    atom::{Atom, AtomCore, Symbol},
3    function, symbol,
4};
5
6use crate::DiagramError;
7
8/// Momentum power counting shared by FeynKit diagrams and GammaLoop UV analysis.
9///
10/// The momentum head is explicit so consumers share the algorithm without
11/// depending on each other's symbol registries.
12pub trait DOD: AtomCore {
13    /// Rescales momentum of edge `eid`, and computes the leading scaling.
14    fn edge_dod(&self, momentum: Symbol, eid: usize) -> Result<i32, DiagramError> {
15        let arguments = symbol!("feynkit_graph::uv_args___");
16        let scale = symbol!("feynkit_graph::uv_rescale");
17        self.replace(function!(momentum, eid, arguments))
18            .with(function!(momentum, eid, arguments) / scale)
19            .trailing_exponent(scale)
20    }
21
22    /// Rescales all momenta, and computes the leading scaling.
23    fn all_dod(&self, momentum: Symbol) -> Result<i32, DiagramError> {
24        let arguments = symbol!("feynkit_graph::uv_args___");
25        let scale = symbol!("feynkit_graph::uv_rescale");
26        self.replace(function!(momentum, arguments))
27            .with(function!(momentum, arguments) / scale)
28            .replace(function!(symbol!("UFO::P"), arguments))
29            .with(function!(symbol!("UFO::P"), arguments) / scale)
30            .replace(function!(symbol!("UFO::PSlash"), arguments))
31            .with(function!(symbol!("UFO::PSlash"), arguments) / scale)
32            .trailing_exponent(scale)
33    }
34
35    /// Return the negative leading exponent as an inverse UV scale tends to zero.
36    fn trailing_exponent(&self, scale: Symbol) -> Result<i32, DiagramError> {
37        let series = self
38            .series(scale, Atom::Zero, 1)
39            .map_err(|error| DiagramError::UvPowerCounting(error.to_string()))?;
40        let degree = series.get_trailing_exponent();
41        if degree.is_integer()
42            && let Some(value) = degree.numerator().to_i64().and_then(i64::checked_neg)
43            && let Ok(value) = i32::try_from(value)
44        {
45            return Ok(value);
46        }
47        Err(DiagramError::UvPowerCounting(format!(
48            "non-integral or out-of-range scaling exponent {degree}"
49        )))
50    }
51}
52
53impl<T: AtomCore> DOD for T {}
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58
59    #[test]
60    fn test_dod() {
61        let momentum = crate::momentum_symbol();
62        let (e1, e2) = (1, 2);
63        let q1 = function!(momentum, e1, Atom::Zero);
64        let q2 = function!(momentum, e2, Atom::Zero);
65        let atom = (&q1 * &q2 + &q2) / (&q1 * &q1);
66        let atom2 = Atom::num(1) / (&q1 * &q1 + symbol!("feynkit_graph::m"));
67        let atom3 = &q1 * &q2 + &q2;
68
69        assert_eq!(-1, atom.edge_dod(momentum, e1).unwrap());
70        assert_eq!(1, atom.edge_dod(momentum, e2).unwrap());
71        assert_eq!(-2, atom2.edge_dod(momentum, e1).unwrap());
72        assert_eq!(1, atom3.edge_dod(momentum, e1).unwrap());
73        assert_eq!(1, atom3.edge_dod(momentum, e2).unwrap());
74        assert_eq!(2, atom3.all_dod(momentum).unwrap());
75        assert_eq!(0, (&q1 / &q1).all_dod(momentum).unwrap());
76        let ufo = function!(symbol!("UFO::P"), 1, 1) * function!(symbol!("UFO::PSlash"), 2, 1, 1);
77        assert_eq!(2, ufo.all_dod(momentum).unwrap());
78    }
79}