diff --git a/crates/eko/src/lib.rs b/crates/eko/src/lib.rs index 9f99a7e30..4e6347494 100644 --- a/crates/eko/src/lib.rs +++ b/crates/eko/src/lib.rs @@ -96,8 +96,8 @@ pub unsafe extern "C" fn rust_quad_ker_qcd(u: f64, rargs: *mut c_void) -> f64 { (args.py)( raw.re.as_ptr(), raw.im.as_ptr(), - c.n.re, - c.n.im, + c.n().re, + c.n().im, jac.re, jac.im, args.order_qcd, diff --git a/crates/ekore/src/anomalous_dimensions/unpolarized/spacelike/as1.rs b/crates/ekore/src/anomalous_dimensions/unpolarized/spacelike/as1.rs index 7882227d3..5b5fc6ee6 100644 --- a/crates/ekore/src/anomalous_dimensions/unpolarized/spacelike/as1.rs +++ b/crates/ekore/src/anomalous_dimensions/unpolarized/spacelike/as1.rs @@ -9,7 +9,7 @@ use crate::harmonics::cache::{Cache, K}; /// /// Implements Eq. (3.4) of [\[Moch:2004pa\]][crate::bib::Moch2004pa]. pub fn gamma_ns(c: &mut Cache, _nf: u8) -> Complex { - let N = c.n; + let N = c.n(); let S1 = c.get(K::S1); let gamma = -(3.0 - 4.0 * S1 + 2.0 / N / (N + 1.0)); CF * gamma @@ -19,7 +19,7 @@ pub fn gamma_ns(c: &mut Cache, _nf: u8) -> Complex { /// /// Implements Eq. (3.5) of [\[Vogt:2004mw\]](crate::bib::Vogt2004mw). pub fn gamma_qg(c: &mut Cache, nf: u8) -> Complex { - let N = c.n; + let N = c.n(); let gamma = -(N.powu(2) + N + 2.0) / (N * (N + 1.0) * (N + 2.0)); 2.0 * TR * 2.0 * (nf as f64) * gamma } @@ -28,7 +28,7 @@ pub fn gamma_qg(c: &mut Cache, nf: u8) -> Complex { /// /// Implements Eq. (3.5) of [\[Vogt:2004mw\]](crate::bib::Vogt2004mw). pub fn gamma_gq(c: &mut Cache, _nf: u8) -> Complex { - let N = c.n; + let N = c.n(); let gamma = -(N.powu(2) + N + 2.0) / (N * (N + 1.0) * (N - 1.0)); 2.0 * CF * gamma } @@ -37,7 +37,7 @@ pub fn gamma_gq(c: &mut Cache, _nf: u8) -> Complex { /// /// Implements Eq. (3.5) of [\[Vogt:2004mw\]](crate::bib::Vogt2004mw). pub fn gamma_gg(c: &mut Cache, nf: u8) -> Complex { - let N = c.n; + let N = c.n(); let S1 = c.get(K::S1); let gamma = S1 - 1.0 / N / (N - 1.0) - 1.0 / (N + 1.0) / (N + 2.0); CA * (4.0 * gamma - 11.0 / 3.0) + 4.0 / 3.0 * TR * (nf as f64) diff --git a/crates/ekore/src/anomalous_dimensions/unpolarized/spacelike/as2.rs b/crates/ekore/src/anomalous_dimensions/unpolarized/spacelike/as2.rs index 195f69fec..857034ab8 100644 --- a/crates/ekore/src/anomalous_dimensions/unpolarized/spacelike/as2.rs +++ b/crates/ekore/src/anomalous_dimensions/unpolarized/spacelike/as2.rs @@ -10,7 +10,7 @@ use crate::harmonics::cache::{Cache, K}; /// /// Implements Eq. (3.6) of [\[Moch:2004pa\]][crate::bib::Moch2004pa]. pub fn gamma_nsm(c: &mut Cache, nf: u8) -> Complex { - let N = c.n; + let N = c.n(); let S1 = c.get(K::S1); let S2 = c.get(K::S2); let Sp1m = c.get(K::S1mh); @@ -50,7 +50,7 @@ pub fn gamma_nsm(c: &mut Cache, nf: u8) -> Complex { /// /// Implements Eq. (3.5) of [\[Moch:2004pa\]][crate::bib::Moch2004pa]. pub fn gamma_nsp(c: &mut Cache, nf: u8) -> Complex { - let N = c.n; + let N = c.n(); let S1 = c.get(K::S1); let S2 = c.get(K::S2); let Sp1p = c.get(K::S1h); @@ -90,7 +90,7 @@ pub fn gamma_nsp(c: &mut Cache, nf: u8) -> Complex { /// /// Implements Eq. (3.6) of [\[Vogt:2004mw\]][crate::bib::Vogt2004mw]. pub fn gamma_ps(c: &mut Cache, nf: u8) -> Complex { - let N = c.n; + let N = c.n(); let gqqps1_nfcf = (-4. * (2. + N * (5. + N)) * (4. + N * (4. + N * (7. + 5. * N)))) / ((-1. + N) * N.powu(3) * (1. + N).powu(3) * (2. + N).powu(2)); 2.0 * TR * (nf as f64) * CF * gqqps1_nfcf @@ -100,7 +100,7 @@ pub fn gamma_ps(c: &mut Cache, nf: u8) -> Complex { /// /// Implements Eq. (3.7) of [\[Vogt:2004mw\]][crate::bib::Vogt2004mw]. pub fn gamma_qg(c: &mut Cache, nf: u8) -> Complex { - let N = c.n; + let N = c.n(); let S1 = c.get(K::S1); let S2 = c.get(K::S2); let Sp2p = c.get(K::S2h); @@ -128,7 +128,7 @@ pub fn gamma_qg(c: &mut Cache, nf: u8) -> Complex { /// /// Implements Eq. (3.8) of [\[Vogt:2004mw\]][crate::bib::Vogt2004mw]. pub fn gamma_gq(c: &mut Cache, nf: u8) -> Complex { - let N = c.n; + let N = c.n(); let S1 = c.get(K::S1); let S2 = c.get(K::S2); let Sp2p = c.get(K::S2h); @@ -164,7 +164,7 @@ pub fn gamma_gq(c: &mut Cache, nf: u8) -> Complex { /// /// Implements Eq. (3.9) of [\[Vogt:2004mw\]][crate::bib::Vogt2004mw]. pub fn gamma_gg(c: &mut Cache, nf: u8) -> Complex { - let N = c.n; + let N = c.n(); let S1 = c.get(K::S1); let Sp1p = c.get(K::S1h); let Sp2p = c.get(K::S2h); diff --git a/crates/ekore/src/anomalous_dimensions/unpolarized/spacelike/as3.rs b/crates/ekore/src/anomalous_dimensions/unpolarized/spacelike/as3.rs index e9506b2ea..d491db0e9 100644 --- a/crates/ekore/src/anomalous_dimensions/unpolarized/spacelike/as3.rs +++ b/crates/ekore/src/anomalous_dimensions/unpolarized/spacelike/as3.rs @@ -11,7 +11,7 @@ use crate::harmonics::cache::{Cache, K}; /// /// Implements Eq. (3.8) of [\[Moch:2004pa\]][crate::bib::Moch2004pa]. pub fn gamma_nsm(c: &mut Cache, nf: u8) -> Complex { - let N = c.n; + let N = c.n(); let S1 = c.get(K::S1); let S2 = c.get(K::S2); let S3 = c.get(K::S3); @@ -68,7 +68,7 @@ pub fn gamma_nsm(c: &mut Cache, nf: u8) -> Complex { /// /// Implements Eq. (3.7) of [\[Moch:2004pa\]][crate::bib::Moch2004pa]. pub fn gamma_nsp(c: &mut Cache, nf: u8) -> Complex { - let N = c.n; + let N = c.n(); let S1 = c.get(K::S1); let S2 = c.get(K::S2); let S3 = c.get(K::S3); @@ -125,7 +125,7 @@ pub fn gamma_nsp(c: &mut Cache, nf: u8) -> Complex { /// /// Implements Eq. (3.9) of [\[Moch:2004pa\]][crate::bib::Moch2004pa]. pub fn gamma_nsv(c: &mut Cache, nf: u8) -> Complex { - let N = c.n; + let N = c.n(); let S1 = c.get(K::S1); let S2 = c.get(K::S2); let S3 = c.get(K::S3); @@ -162,7 +162,7 @@ pub fn gamma_nsv(c: &mut Cache, nf: u8) -> Complex { /// /// Implements Eq. (3.10) of [\[Vogt:2004mw\]][crate::bib::Vogt2004mw]. pub fn gamma_ps(c: &mut Cache, nf: u8) -> Complex { - let N = c.n; + let N = c.n(); let S1 = c.get(K::S1); let S2 = c.get(K::S2); let S3 = c.get(K::S3); @@ -218,7 +218,7 @@ pub fn gamma_ps(c: &mut Cache, nf: u8) -> Complex { /// /// Implements Eq. (3.11) of [\[Vogt:2004mw\]][crate::bib::Vogt2004mw]. pub fn gamma_qg(c: &mut Cache, nf: u8) -> Complex { - let N = c.n; + let N = c.n(); let S1 = c.get(K::S1); let S2 = c.get(K::S2); let S3 = c.get(K::S3); @@ -275,7 +275,7 @@ pub fn gamma_qg(c: &mut Cache, nf: u8) -> Complex { /// /// Implements Eq. (3.12) of [\[Vogt:2004mw\]][crate::bib::Vogt2004mw]. pub fn gamma_gq(c: &mut Cache, nf: u8) -> Complex { - let N = c.n; + let N = c.n(); let S1 = c.get(K::S1); let S2 = c.get(K::S2); let S3 = c.get(K::S3); @@ -348,7 +348,7 @@ pub fn gamma_gq(c: &mut Cache, nf: u8) -> Complex { /// /// Implements Eq. (3.13) of [\[Vogt:2004mw\]][crate::bib::Vogt2004mw]. pub fn gamma_gg(c: &mut Cache, nf: u8) -> Complex { - let N = c.n; + let N = c.n(); let S1 = c.get(K::S1); let S2 = c.get(K::S2); let S3 = c.get(K::S3); diff --git a/crates/ekore/src/harmonics/cache.rs b/crates/ekore/src/harmonics/cache.rs index eb2a9090b..d8f66b595 100644 --- a/crates/ekore/src/harmonics/cache.rs +++ b/crates/ekore/src/harmonics/cache.rs @@ -35,7 +35,7 @@ pub enum K { /// Hold all cached values. pub struct Cache { /// Mellin N - pub n: Complex, + n: Complex, /// Mapping m: HashMap>, } @@ -49,6 +49,11 @@ impl Cache { } } + /// Get Mellin N. + pub fn n(&self) -> Complex { + Complex::new(self.n.re, self.n.im) + } + /// Retrieve an element. pub fn get(&mut self, k: K) -> Complex { let val = self.m.get(&k); @@ -94,11 +99,21 @@ pub fn recursive_harmonic_sum( #[cfg(test)] mod tests { - use crate::harmonics::cache::recursive_harmonic_sum; + use super::*; use crate::harmonics::{w1, w2, w3, w4}; use crate::{assert_approx_eq_cmplx, cmplx}; use num::complex::Complex; + #[test] + fn n() { + let n = cmplx!(1., 0.); + let c = Cache::new(n); + let mut m = c.n(); + m += cmplx!(1., 0.); + assert_approx_eq_cmplx!(f64, c.n(), n); + assert_approx_eq_cmplx!(f64, m, cmplx!(2., 0.)); + } + #[test] fn test_recursive_harmonic_sum() { const SX: [fn(Complex) -> Complex; 4] = [w1::S1, w2::S2, w3::S3, w4::S4]; diff --git a/crates/ekore/src/operator_matrix_elements/unpolarized/spacelike/as1.rs b/crates/ekore/src/operator_matrix_elements/unpolarized/spacelike/as1.rs index 0e5145d61..c2409d2d9 100644 --- a/crates/ekore/src/operator_matrix_elements/unpolarized/spacelike/as1.rs +++ b/crates/ekore/src/operator_matrix_elements/unpolarized/spacelike/as1.rs @@ -11,7 +11,7 @@ use crate::harmonics::cache::{Cache, K}; /// /// Implements Eq. (20a) of [\[Ball:2015tna\]](crate::bib::Ball2015tna). pub fn A_hh(c: &mut Cache, _nf: u8, L: f64) -> Complex { - let N = c.n; + let N = c.n(); let S1m = c.get(K::S1) - 1. / N; let S2m = c.get(K::S2) - 1. / N.powu(2); let ahh_l = (2. + N - 3. * N.powu(2)) / (N * (1. + N)) + 4. * S1m; @@ -30,7 +30,7 @@ pub fn A_hh(c: &mut Cache, _nf: u8, L: f64) -> Complex { /// /// Implements Eq. (20b) of [\[Ball:2015tna\]](crate::bib::Ball2015tna). pub fn A_gh(c: &mut Cache, _nf: u8, L: f64) -> Complex { - let N = c.n; + let N = c.n(); let agh_l1 = (2. + N + N.powu(2)) / (N * (N.powu(2) - 1.)); let agh_l0 = (-4. + 2. * N + N.powu(2) * (15. + N * (3. + N - N.powu(2)))) / (N * (N.powu(2) - 1.)).powu(2); @@ -41,7 +41,7 @@ pub fn A_gh(c: &mut Cache, _nf: u8, L: f64) -> Complex { /// /// Implements Eq. (B.2) of [\[Buza:1996wv\]](crate::bib::Buza1996wv). pub fn A_hg(c: &mut Cache, _nf: u8, L: f64) -> Complex { - let N = c.n; + let N = c.n(); let den = 1. / (N * (N + 1.) * (2. + N)); let num = 2. * (2. + N + N.powu(2)); num * den * L diff --git a/crates/ekore/src/operator_matrix_elements/unpolarized/spacelike/as2.rs b/crates/ekore/src/operator_matrix_elements/unpolarized/spacelike/as2.rs index 0e176c282..7fee55609 100644 --- a/crates/ekore/src/operator_matrix_elements/unpolarized/spacelike/as2.rs +++ b/crates/ekore/src/operator_matrix_elements/unpolarized/spacelike/as2.rs @@ -13,7 +13,7 @@ use crate::operator_matrix_elements::unpolarized::spacelike::as1; /// |NNLO| light-light non-singlet |OME|. /// It is given in Eq.() of pub fn A_qq_ns(c: &mut Cache, _nf: u8, L: f64) -> Complex { - let N = c.n; + let N = c.n(); let S1 = c.get(K::S1); let S2 = c.get(K::S2); let S3 = c.get(K::S3); @@ -44,7 +44,7 @@ pub fn A_qq_ns(c: &mut Cache, _nf: u8, L: f64) -> Complex { /// |NNLO| heavy-light pure-singlet |OME| /// It is given in Eq.() of pub fn A_hq_ps(c: &mut Cache, _nf: u8, L: f64) -> Complex { - let N = c.n; + let N = c.n(); let S2 = c.get(K::S1); let F1M = 1.0 / (N - 1.0) * (ZETA2 - (S2 - 1.0 / N.powu(2))); let F11 = 1.0 / (N + 1.0) * (ZETA2 - (S2 + 1.0 / (N + 1.0).powu(2))); diff --git a/crates/ekore/src/util.rs b/crates/ekore/src/util.rs index 8d98f25b0..0d815bc98 100644 --- a/crates/ekore/src/util.rs +++ b/crates/ekore/src/util.rs @@ -13,18 +13,15 @@ macro_rules! cmplx { #[macro_export] macro_rules! assert_approx_eq_cmplx { ($size:ty, $ref:expr, $target:expr) => { - use float_cmp::assert_approx_eq; - assert_approx_eq!($size, $ref.re, $target.re); - assert_approx_eq!($size, $ref.im, $target.im); + float_cmp::assert_approx_eq!($size, $ref.re, $target.re); + float_cmp::assert_approx_eq!($size, $ref.im, $target.im); }; ($size:ty, $ref:expr, $target:expr, ulps=$ulps:expr) => { - use float_cmp::assert_approx_eq; - assert_approx_eq!($size, $ref.re, $target.re, ulps = $ulps); - assert_approx_eq!($size, $ref.im, $target.im, ulps = $ulps); + float_cmp::assert_approx_eq!($size, $ref.re, $target.re, ulps = $ulps); + float_cmp::assert_approx_eq!($size, $ref.im, $target.im, ulps = $ulps); }; ($size:ty, $ref:expr, $target:expr, epsilon=$epsilon:expr) => { - use float_cmp::assert_approx_eq; - assert_approx_eq!($size, $ref.re, $target.re, epsilon = $epsilon); - assert_approx_eq!($size, $ref.im, $target.im, epsilon = $epsilon); + float_cmp::assert_approx_eq!($size, $ref.re, $target.re, epsilon = $epsilon); + float_cmp::assert_approx_eq!($size, $ref.im, $target.im, epsilon = $epsilon); }; }