use crate::integrity::kir::k_running_max;
pub fn lil_envelope(diffusion: f64, t_s: f64) -> f64 {
if t_s <= std::f64::consts::E {
return 0.0;
}
let llt = t_s.ln().ln();
if llt <= 0.0 {
return 0.0;
}
(2.0 * diffusion * t_s * llt).sqrt()
}
pub fn hpl_dominates_lil(diffusion: f64, t_s: f64, ir: f64) -> bool {
let hpl_leg = k_running_max(ir) * (diffusion * t_s).sqrt();
hpl_leg >= lil_envelope(diffusion, t_s)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn envelope_diverges_no_finite_worst_case() {
let d = 1e-24;
let mut prev = 0.0;
for &t in &[100.0, 1e4, 1e6, 1e8, 1e10] {
let e = lil_envelope(d, t);
assert!(e > prev, "LIL envelope must diverge (t={t})");
prev = e;
}
}
#[test]
fn envelope_is_zero_below_threshold() {
assert_eq!(lil_envelope(1e-24, 1.0), 0.0);
assert_eq!(lil_envelope(1e-24, 2.0), 0.0); assert!(lil_envelope(1e-24, 100.0) > 0.0);
}
#[test]
fn tightening_ir_makes_hpl_dominate_the_as_envelope() {
let d = 1e-24;
let t = 1e6;
assert!(!hpl_dominates_lil(d, t, 1e-1)); assert!(hpl_dominates_lil(d, t, 1e-9)); }
}