Skip to content

Commit

Permalink
adding Sm1e, Sm1o, Sm21e, Sm21o implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tgiani committed Sep 4, 2024
1 parent e79f008 commit e57e891
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
4 changes: 2 additions & 2 deletions crates/dekoder/src/eko.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl EKO {
pub fn write(&self, dst: PathBuf) -> Result<()> {
self.assert_working_dir()?;
// create writer
let dst_file = File::create(&dst)?;
let dst_file = File::create(dst)?;
let dst_file = BufWriter::with_capacity(TAR_WRITER_CAPACITY, dst_file);
let mut ar = tar::Builder::new(dst_file);
// do it!
Expand All @@ -101,7 +101,7 @@ impl EKO {

/// Extract tar file from `src` to `dst`.
pub fn extract(src: PathBuf, dst: PathBuf) -> Result<Self> {
let mut ar = tar::Archive::new(File::open(&src)?);
let mut ar = tar::Archive::new(File::open(src)?);
ar.unpack(&dst)?;
Self::load_opened(dst)
}
Expand Down
12 changes: 12 additions & 0 deletions crates/ekore/src/harmonics/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@ pub enum K {
S3mh,
/// $g_3(N)$
G3,
/// $S_{-1}(N)$ even moments
Sm1e,
/// $S_{-1}(N)$ odd moments
Sm1o,
/// $S_{-2}(N)$ even moments
Sm2e,
/// $S_{-2}(N)$ odd moments
Sm2o,
/// $S_{-2,1}(N)$ even moments
Sm21e,
/// $S_{-2,1}(N)$ odd moments
Sm21o,
}

/// Hold all cached values.
Expand Down Expand Up @@ -78,8 +86,12 @@ impl Cache {
K::S2mh => w2::S2((self.n - 1.) / 2.),
K::S3mh => w3::S3((self.n - 1.) / 2.),
K::G3 => g_functions::g3(self.n, self.get(K::S1)),
K::Sm1e => w1::Sm1e(self.get(K::S1), self.get(K::S1h)),
K::Sm1o => w1::Sm1o(self.get(K::S1), self.get(K::S1mh)),
K::Sm2e => w2::Sm2e(self.get(K::S2), self.get(K::S2h)),
K::Sm2o => w2::Sm2o(self.get(K::S2), self.get(K::S2mh)),
K::Sm21e => w3::Sm21e(self.n, self.get(K::S1), self.get(K::Sm1e)),
K::Sm21o => w3::Sm21o(self.n, self.get(K::S1), self.get(K::Sm1o)),
};
// insert
self.m.insert(k, val);
Expand Down
10 changes: 10 additions & 0 deletions crates/ekore/src/harmonics/w1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,13 @@ use crate::harmonics::polygamma::cern_polygamma;
pub fn S1(N: Complex<f64>) -> Complex<f64> {
cern_polygamma(N + 1.0, 0) + 0.577_215_664_901_532_9
}

/// Analytic continuation of harmonic sum $S_{-1}(N)$ for even moments.
pub fn Sm1e(hS1: Complex<f64>, hS1h: Complex<f64>) -> Complex<f64> {
hS1h - hS1
}

/// Analytic continuation of harmonic sum $S_{-1}(N)$ for odd moments.
pub fn Sm1o(hS1: Complex<f64>, hS1mh: Complex<f64>) -> Complex<f64> {
hS1mh - hS1
}
16 changes: 15 additions & 1 deletion crates/ekore/src/harmonics/w3.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! Harmonic sums of weight 3.
use num::complex::Complex;
use std::f64::consts::LN_2;

use crate::constants::ZETA3;
use crate::constants::{ZETA2, ZETA3};
use crate::harmonics::g_functions::g3;
use crate::harmonics::polygamma::cern_polygamma;

/// Compute the harmonic sum $S_3(N)$.
Expand All @@ -11,3 +13,15 @@ use crate::harmonics::polygamma::cern_polygamma;
pub fn S3(N: Complex<f64>) -> Complex<f64> {
0.5 * cern_polygamma(N + 1.0, 2) + ZETA3
}

/// Analytic continuation of harmonic sum $S_{-2,1}(N)$ for even moments.
pub fn Sm21e(N: Complex<f64>, hS1: Complex<f64>, hSm1: Complex<f64>) -> Complex<f64> {
let eta = 1.;
-eta * g3(N + 1., hS1 + 1. / (N + 1.)) + ZETA2 * hSm1 - 5. / 8. * ZETA3 + ZETA2 * LN_2
}

/// Analytic continuation of harmonic sum $S_{-2,1}(N)$ for odd moments.
pub fn Sm21o(N: Complex<f64>, hS1: Complex<f64>, hSm1: Complex<f64>) -> Complex<f64> {
let eta = -1.;
-eta * g3(N + 1., hS1 + 1. / (N + 1.)) + ZETA2 * hSm1 - 5. / 8. * ZETA3 + ZETA2 * LN_2
}

0 comments on commit e57e891

Please sign in to comment.