Skip to content

Commit

Permalink
rust: Iterate ekore/constants
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhekhorn committed Jan 13, 2025
1 parent 80fe896 commit 5ce8eb3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 46 deletions.
14 changes: 7 additions & 7 deletions crates/ekore/src/anomalous_dimensions/unpolarized/spacelike.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! The unpolarized, space-like anomalous dimensions at various couplings power.
use crate::constants::{
ed2, eu2, PID_NSM, PID_NSM_ED2, PID_NSM_EU2, PID_NSP, PID_NSP_ED2, PID_NSP_EU2, PID_NSV,
ED2, EU2, PID_NSM, PID_NSM_ED2, PID_NSM_EU2, PID_NSP, PID_NSP_ED2, PID_NSP_EU2, PID_NSV,
};
use crate::harmonics::cache::Cache;
use num::complex::Complex;
Expand Down Expand Up @@ -78,18 +78,18 @@ pub fn gamma_ns_qed(

pub fn choose_ns_as_aem1(mode: u16, c: &mut Cache, nf: u8) -> Complex<f64> {
match mode {
PID_NSP_EU2 | PID_NSM_EU2 => eu2 * aem1::gamma_ns(c, nf),
PID_NSP_ED2 | PID_NSM_ED2 => ed2 * aem1::gamma_ns(c, nf),
PID_NSP_EU2 | PID_NSM_EU2 => EU2 * aem1::gamma_ns(c, nf),
PID_NSP_ED2 | PID_NSM_ED2 => ED2 * aem1::gamma_ns(c, nf),
_ => panic!("Unkown non-singlet sector element"),
}
}

pub fn choose_ns_as_as1aem1(mode: u16, c: &mut Cache, nf: u8) -> Complex<f64> {
match mode {
PID_NSP_EU2 => eu2 * as1aem1::gamma_nsp(c, nf),
PID_NSP_ED2 => ed2 * as1aem1::gamma_nsp(c, nf),
PID_NSM_EU2 => eu2 * as1aem1::gamma_nsm(c, nf),
PID_NSM_ED2 => ed2 * as1aem1::gamma_nsm(c, nf),
PID_NSP_EU2 => EU2 * as1aem1::gamma_nsp(c, nf),
PID_NSP_ED2 => ED2 * as1aem1::gamma_nsp(c, nf),
PID_NSM_EU2 => EU2 * as1aem1::gamma_nsm(c, nf),
PID_NSM_ED2 => ED2 * as1aem1::gamma_nsm(c, nf),
_ => panic!("Unkown non-singlet sector element"),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use num::complex::Complex;
use num::Zero;

use crate::constants::{ed2, eu2, uplike_flavors, ChargeCombinations, CF, NC, TR};
use crate::constants::{ChargeCombinations, CF, ED2, EU2, NC, TR};
use crate::harmonics::cache::Cache;

use crate::anomalous_dimensions::unpolarized::spacelike::as1;
Expand All @@ -25,9 +25,8 @@ pub fn gamma_qph(c: &mut Cache, nf: u8) -> Complex<f64> {
///
/// Implements Eq. (2.5) of
pub fn gamma_phph(_c: &mut Cache, nf: u8) -> Complex<f64> {
let nu = uplike_flavors(nf);
let nd = nf - nu;
(4.0 / 3.0 * (NC as f64) * ((nu as f64) * eu2 + (nd as f64) * ed2)).into()
let cc = ChargeCombinations { nf };
(4.0 / 3.0 * (NC as f64) * ((cc.nu() as f64) * EU2 + (cc.nd() as f64) * ED2)).into()
}

/// Compute the leading-order non-singlet QED anomalous dimension
Expand Down Expand Up @@ -117,11 +116,12 @@ mod tests {
let mut c = Cache::new(N);

for nf in 2..7 {
let nu = uplike_flavors(nf);
let nd = nf - nu;
let cc = ChargeCombinations { nf };
assert_approx_eq_cmplx!(
f64,
eu2 * gamma_qph(&mut c, nu) + ed2 * gamma_qph(&mut c, nd) + gamma_phph(&mut c, nf),
EU2 * gamma_qph(&mut c, cc.nu())
+ ED2 * gamma_qph(&mut c, cc.nd())
+ gamma_phph(&mut c, nf),
cmplx!(0., 0.),
epsilon = 2e-6
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
use crate::cmplx;
use num::complex::Complex;

use crate::constants::{
ed2, eu2, uplike_flavors, ChargeCombinations, CA, CF, NC, TR, ZETA2, ZETA3,
};
use crate::constants::{ChargeCombinations, CA, CF, ED2, EU2, NC, TR, ZETA2, ZETA3};
use crate::harmonics::cache::{Cache, K};

/// Compute the $O(a_s^1a_{em}^1)$ photon-quark anomalous dimension.
Expand Down Expand Up @@ -100,9 +98,11 @@ pub fn gamma_gq(c: &mut Cache, nf: u8) -> Complex<f64> {
///
/// Implements Eq. (28) of
pub fn gamma_phph(_c: &mut Cache, nf: u8) -> Complex<f64> {
let nu = uplike_flavors(nf);
let nd = nf - nu;
cmplx!(4.0 * CF * CA * ((nu as f64) * eu2 + (nd as f64) * ed2), 0.)
let cc = ChargeCombinations { nf };
cmplx!(
4.0 * CF * CA * ((cc.nu() as f64) * EU2 + (cc.nd() as f64) * ED2),
0.
)
}

/// Compute the $O(a_s^1a_{em}^1)$ gluon-gluon singlet anomalous dimension.
Expand Down Expand Up @@ -261,14 +261,13 @@ mod tests {
let mut c = Cache::new(N);

for nf in 2..7 {
let nu = uplike_flavors(nf);
let nd = nf - nu;
let cc = ChargeCombinations { nf };
assert_approx_eq_cmplx!(
f64,
eu2 * gamma_qg(&mut c, nu)
+ ed2 * gamma_qg(&mut c, nd)
+ (nu as f64 * eu2 + nd as f64 * ed2) * gamma_phg(&mut c, nf)
+ (nu as f64 * eu2 + nd as f64 * ed2) * gamma_gg(&mut c, nf),
EU2 * gamma_qg(&mut c, cc.nu())
+ ED2 * gamma_qg(&mut c, cc.nd())
+ (cc.nu() as f64 * EU2 + cc.nd() as f64 * ED2) * gamma_phg(&mut c, nf)
+ (cc.nu() as f64 * EU2 + cc.nd() as f64 * ED2) * gamma_gg(&mut c, nf),
cmplx!(0., 0.),
epsilon = 1e-14
);
Expand All @@ -281,14 +280,13 @@ mod tests {
let mut c = Cache::new(N);

for nf in 2..7 {
let nu = uplike_flavors(nf);
let nd = nf - nu;
let cc = ChargeCombinations { nf };
assert_approx_eq_cmplx!(
f64,
eu2 * gamma_qph(&mut c, nu)
+ ed2 * gamma_qph(&mut c, nd)
EU2 * gamma_qph(&mut c, cc.nu())
+ ED2 * gamma_qph(&mut c, cc.nd())
+ gamma_phph(&mut c, nf)
+ (nu as f64 * eu2 + nd as f64 * ed2) * gamma_gph(&mut c, nf),
+ (cc.nu() as f64 * EU2 + cc.nd() as f64 * ED2) * gamma_gph(&mut c, nf),
cmplx!(0., 0.),
epsilon = 1e-14
);
Expand Down
31 changes: 16 additions & 15 deletions crates/ekore/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Global constants.
use std::unimplemented;
/// The number of colors.
///
Expand All @@ -24,12 +23,12 @@ pub const CF: f64 = ((NC * NC - 1) as f64) / ((2 * NC) as f64);
/// Up quark charge square.
///
/// Defaults to $e_u^2 = 4./9$
pub const eu2: f64 = 4. / 9.;
pub const EU2: f64 = 4. / 9.;

/// Down quark charge square.
///
/// Defaults to $e_d^2 = 1./9$
pub const ed2: f64 = 1. / 9.;
pub const ED2: f64 = 1. / 9.;

/// Riemann zeta function at z = 2.
///
Expand All @@ -53,48 +52,50 @@ pub const PID_NSM: u16 = 10201;
/// non-singlet all-valence |PID|.
pub const PID_NSV: u16 = 10200;

/// QED |PID|. Need to give sensible names
/// singlet-like non-singlet up-sector |PID|
pub const PID_NSP_EU2: u16 = 10102;

/// singlet-like non-singlet down-sector |PID|
pub const PID_NSP_ED2: u16 = 10103;

/// valence-like non-singlet up-sector |PID|
pub const PID_NSM_EU2: u16 = 10202;

/// valence-like non-singlet down-sector |PID|
pub const PID_NSM_ED2: u16 = 10203;

/// compute the number of up flavors
pub fn uplike_flavors(nf: u8) -> u8 {
if nf > 6 {
unimplemented!("Selected nf is not implemented")
}
nf / 2
}

/// |QED| electric charge combinations.
pub struct ChargeCombinations {
pub nf: u8,
}

impl ChargeCombinations {
/// Number of up-like flavors.
pub fn nu(&self) -> u8 {
self.nf / 2
}

/// Number of down-like flavors.
pub fn nd(&self) -> u8 {
self.nf - self.nu()
}

/// Electric charge average.
pub fn e2avg(&self) -> f64 {
(self.nu() as f64 * eu2 + self.nd() as f64 * ed2) / (self.nf as f64)
(self.nu() as f64 * EU2 + self.nd() as f64 * ED2) / (self.nf as f64)
}

/// Relative up contribution to charge difference.
pub fn vue2m(&self) -> f64 {
self.nu() as f64 / (self.nf as f64) * (eu2 - ed2)
self.nu() as f64 / (self.nf as f64) * (EU2 - ED2)
}

/// Relative down contribution to charge difference.
pub fn vde2m(&self) -> f64 {
self.nd() as f64 / (self.nf as f64) * (eu2 - ed2)
self.nd() as f64 / (self.nf as f64) * (EU2 - ED2)
}

/// Asymmetric charge combination.
pub fn e2delta(&self) -> f64 {
self.vde2m() - self.vue2m() + self.e2avg()
}
Expand Down

0 comments on commit 5ce8eb3

Please sign in to comment.