use oxilean_kernel::{BinderInfo, Declaration, Environment, Expr, Level, Name};
use super::types::{
AbelSum, AbelSumComputer, AbelSummableSequence, CesaroSum, CesaroSumComputer,
CesaroSummability, KaramataSlowVariation, PrimeSieve, RegularlyVaryingFn, SummabilityMethod,
TauberianBoundChecker, TauberianCondition, TauberianTheorem,
};
pub fn app(f: Expr, a: Expr) -> Expr {
Expr::App(Box::new(f), Box::new(a))
}
pub fn app2(f: Expr, a: Expr, b: Expr) -> Expr {
app(app(f, a), b)
}
pub fn app3(f: Expr, a: Expr, b: Expr, c: Expr) -> Expr {
app(app2(f, a, b), c)
}
pub fn bvar(n: u32) -> Expr {
Expr::BVar(n)
}
pub fn cst(s: &str) -> Expr {
Expr::Const(Name::str(s), vec![])
}
pub fn prop() -> Expr {
Expr::Sort(Level::zero())
}
pub fn type0() -> Expr {
Expr::Sort(Level::succ(Level::zero()))
}
pub fn pi(bi: BinderInfo, name: &str, dom: Expr, body: Expr) -> Expr {
Expr::Pi(bi, Name::str(name), Box::new(dom), Box::new(body))
}
pub fn arrow(a: Expr, b: Expr) -> Expr {
pi(BinderInfo::Default, "_", a, b)
}
pub fn nat_ty() -> Expr {
cst("Nat")
}
pub fn real_ty() -> Expr {
cst("Real")
}
pub fn bool_ty() -> Expr {
cst("Bool")
}
pub fn add_axiom(
env: &mut Environment,
name: &str,
univ_params: Vec<Name>,
ty: Expr,
) -> Result<(), String> {
env.add(Declaration::Axiom {
name: Name::str(name),
univ_params,
ty,
})
.map_err(|e| format!("add_axiom({name}): {e:?}"))
}
pub fn hardy_littlewood_tauberian_ty() -> Expr {
prop()
}
pub fn hardy_littlewood_two_sided_ty() -> Expr {
prop()
}
pub fn tauberian_condition_ty() -> Expr {
arrow(type0(), prop())
}
pub fn abel_summability_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn one_sided_tauberian_cond_ty() -> Expr {
arrow(type0(), prop())
}
pub fn tauber_original_thm_ty() -> Expr {
prop()
}
pub fn ikehara_tauberian_thm_ty() -> Expr {
prop()
}
pub fn ikehara_no_pole_condition_ty() -> Expr {
prop()
}
pub fn dirichlet_series_coeff_ty() -> Expr {
arrow(nat_ty(), real_ty())
}
pub fn dirichlet_series_function_ty() -> Expr {
arrow(real_ty(), real_ty())
}
pub fn ikehara_wiener_thm_ty() -> Expr {
prop()
}
pub fn partial_sum_asymptotics_ty() -> Expr {
arrow(nat_ty(), real_ty())
}
pub fn karamata_tauberian_thm_ty() -> Expr {
prop()
}
pub fn karamata_abelian_thm_ty() -> Expr {
prop()
}
pub fn karamata_representation_thm_ty() -> Expr {
prop()
}
pub fn karamata_integration_thm_ty() -> Expr {
prop()
}
pub fn wiener_tauberian_thm_ty() -> Expr {
prop()
}
pub fn wiener_lemma_ty() -> Expr {
prop()
}
pub fn span_of_translates_ty() -> Expr {
arrow(type0(), prop())
}
pub fn wiener_algebra_ty() -> Expr {
type0()
}
pub fn bochner_thm_ty() -> Expr {
prop()
}
pub fn tauberian_thm_l1_ty() -> Expr {
prop()
}
pub fn slowly_varying_function_ty() -> Expr {
arrow(type0(), prop())
}
pub fn regularly_varying_function_ty() -> Expr {
arrow(type0(), arrow(real_ty(), prop()))
}
pub fn potter_bound_ty() -> Expr {
prop()
}
pub fn uniform_convergence_thm_ty() -> Expr {
prop()
}
pub fn closure_properties_ty() -> Expr {
prop()
}
pub fn karamata_index_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn tauberian_for_rv_ty() -> Expr {
prop()
}
pub fn abelian_thm_series_ty() -> Expr {
prop()
}
pub fn abelian_thm_laplace_ty() -> Expr {
prop()
}
pub fn abelian_thm_dirichlet_ty() -> Expr {
prop()
}
pub fn cesaro_summability_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn hardy_abel_thm_ty() -> Expr {
prop()
}
pub fn riesz_mean_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn littlewood_tauberian_thm_ty() -> Expr {
prop()
}
pub fn laplace_transform_fn_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn tauberian_for_laplace_ty() -> Expr {
prop()
}
pub fn stieltjes_tauberian_thm_ty() -> Expr {
prop()
}
pub fn hardy_littlewood_maximal_fn_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn laplace_asymptotics_ty() -> Expr {
prop()
}
pub fn monotone_tauberian_cond_ty() -> Expr {
arrow(type0(), prop())
}
pub fn post_widder_inversion_ty() -> Expr {
prop()
}
pub fn prime_number_theorem_taub_ty() -> Expr {
prop()
}
pub fn zeta_no_pole_on_line_ty() -> Expr {
prop()
}
pub fn zeta_simple_pole_at_one_ty() -> Expr {
prop()
}
pub fn chebyshev_psi_asymptotics_ty() -> Expr {
prop()
}
pub fn mertens_theorem_taub_ty() -> Expr {
prop()
}
pub fn prime_gaps_taub_ty() -> Expr {
prop()
}
pub fn dirichlet_pnt_taub_ty() -> Expr {
prop()
}
pub fn bombieri_vinogradov_taub_ty() -> Expr {
prop()
}
pub fn build_tauberian_theory_env(env: &mut Environment) -> Result<(), String> {
add_axiom(
env,
"HardyLittlewoodTauberianThm",
vec![],
hardy_littlewood_tauberian_ty(),
)?;
add_axiom(
env,
"HardyLittlewoodTwoSidedThm",
vec![],
hardy_littlewood_two_sided_ty(),
)?;
add_axiom(env, "TauberianCondition", vec![], tauberian_condition_ty())?;
add_axiom(env, "AbelSummability", vec![], abel_summability_ty())?;
add_axiom(
env,
"OneSidedTauberianCond",
vec![],
one_sided_tauberian_cond_ty(),
)?;
add_axiom(env, "TauberOriginalThm", vec![], tauber_original_thm_ty())?;
add_axiom(
env,
"IkeharaTauberianThm",
vec![],
ikehara_tauberian_thm_ty(),
)?;
add_axiom(
env,
"IkeharaNoPoleCondition",
vec![],
ikehara_no_pole_condition_ty(),
)?;
add_axiom(
env,
"DirichletSeriesCoeff",
vec![],
dirichlet_series_coeff_ty(),
)?;
add_axiom(
env,
"DirichletSeriesFunction",
vec![],
dirichlet_series_function_ty(),
)?;
add_axiom(env, "IkeharaWienerThm", vec![], ikehara_wiener_thm_ty())?;
add_axiom(
env,
"PartialSumAsymptotics",
vec![],
partial_sum_asymptotics_ty(),
)?;
add_axiom(
env,
"KaramataTauberianThm",
vec![],
karamata_tauberian_thm_ty(),
)?;
add_axiom(env, "KaramataAbelianThm", vec![], karamata_abelian_thm_ty())?;
add_axiom(
env,
"KaramataRepresentationThm",
vec![],
karamata_representation_thm_ty(),
)?;
add_axiom(
env,
"KaramataIntegrationThm",
vec![],
karamata_integration_thm_ty(),
)?;
add_axiom(env, "WienerTauberianThm", vec![], wiener_tauberian_thm_ty())?;
add_axiom(env, "WienerLemma", vec![], wiener_lemma_ty())?;
add_axiom(env, "SpanOfTranslates", vec![], span_of_translates_ty())?;
add_axiom(env, "WienerAlgebra", vec![], wiener_algebra_ty())?;
add_axiom(env, "BochnerThm", vec![], bochner_thm_ty())?;
add_axiom(env, "TauberianThmL1", vec![], tauberian_thm_l1_ty())?;
add_axiom(
env,
"SlowlyVaryingFunction",
vec![],
slowly_varying_function_ty(),
)?;
add_axiom(
env,
"RegularlyVaryingFunction",
vec![],
regularly_varying_function_ty(),
)?;
add_axiom(env, "PotterBound", vec![], potter_bound_ty())?;
add_axiom(
env,
"UniformConvergenceThm",
vec![],
uniform_convergence_thm_ty(),
)?;
add_axiom(env, "ClosureProperties", vec![], closure_properties_ty())?;
add_axiom(env, "KaramataIndex", vec![], karamata_index_ty())?;
add_axiom(env, "TauberianForRV", vec![], tauberian_for_rv_ty())?;
add_axiom(env, "AbelianThmSeries", vec![], abelian_thm_series_ty())?;
add_axiom(env, "AbelianThmLaplace", vec![], abelian_thm_laplace_ty())?;
add_axiom(
env,
"AbelianThmDirichlet",
vec![],
abelian_thm_dirichlet_ty(),
)?;
add_axiom(env, "CesaroSummability", vec![], cesaro_summability_ty())?;
add_axiom(env, "HardyAbelThm", vec![], hardy_abel_thm_ty())?;
add_axiom(env, "RiessMean", vec![], riesz_mean_ty())?;
add_axiom(
env,
"LittlewoodTauberianThm",
vec![],
littlewood_tauberian_thm_ty(),
)?;
add_axiom(env, "LaplaceTransformFn", vec![], laplace_transform_fn_ty())?;
add_axiom(
env,
"TauberianForLaplace",
vec![],
tauberian_for_laplace_ty(),
)?;
add_axiom(
env,
"StieltjesTauberianThm",
vec![],
stieltjes_tauberian_thm_ty(),
)?;
add_axiom(
env,
"HardyLittlewoodMaximalFn",
vec![],
hardy_littlewood_maximal_fn_ty(),
)?;
add_axiom(env, "LaplaceAsymptotics", vec![], laplace_asymptotics_ty())?;
add_axiom(
env,
"MonotoneTauberianCond",
vec![],
monotone_tauberian_cond_ty(),
)?;
add_axiom(
env,
"PostWidderInversion",
vec![],
post_widder_inversion_ty(),
)?;
add_axiom(
env,
"PrimeNumberTheoremTaub",
vec![],
prime_number_theorem_taub_ty(),
)?;
add_axiom(env, "ZetaNoPoleonLine", vec![], zeta_no_pole_on_line_ty())?;
add_axiom(
env,
"ZetaSimplePoleAtOne",
vec![],
zeta_simple_pole_at_one_ty(),
)?;
add_axiom(
env,
"ChebyshevPsiAsymptotics",
vec![],
chebyshev_psi_asymptotics_ty(),
)?;
add_axiom(env, "MertensTheoremTaub", vec![], mertens_theorem_taub_ty())?;
add_axiom(env, "PrimeGapsTaub", vec![], prime_gaps_taub_ty())?;
add_axiom(env, "DirichletPNTTaub", vec![], dirichlet_pnt_taub_ty())?;
add_axiom(
env,
"BombierVinogradovTaub",
vec![],
bombieri_vinogradov_taub_ty(),
)?;
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
fn test_env() -> Environment {
let mut env = Environment::new();
build_tauberian_theory_env(&mut env).expect("build_tauberian_theory_env failed");
env
}
#[test]
fn test_hardy_littlewood_and_ikehara_registered() {
let env = test_env();
assert!(env.get(&Name::str("HardyLittlewoodTauberianThm")).is_some());
assert!(env.get(&Name::str("HardyLittlewoodTwoSidedThm")).is_some());
assert!(env.get(&Name::str("TauberOriginalThm")).is_some());
assert!(env.get(&Name::str("IkeharaTauberianThm")).is_some());
assert!(env.get(&Name::str("IkeharaWienerThm")).is_some());
}
#[test]
fn test_karamata_and_wiener_registered() {
let env = test_env();
assert!(env.get(&Name::str("KaramataTauberianThm")).is_some());
assert!(env.get(&Name::str("KaramataAbelianThm")).is_some());
assert!(env.get(&Name::str("KaramataRepresentationThm")).is_some());
assert!(env.get(&Name::str("WienerTauberianThm")).is_some());
assert!(env.get(&Name::str("WienerLemma")).is_some());
assert!(env.get(&Name::str("WienerAlgebra")).is_some());
}
#[test]
fn test_regular_variation_registered() {
let env = test_env();
assert!(env.get(&Name::str("SlowlyVaryingFunction")).is_some());
assert!(env.get(&Name::str("RegularlyVaryingFunction")).is_some());
assert!(env.get(&Name::str("PotterBound")).is_some());
assert!(env.get(&Name::str("UniformConvergenceThm")).is_some());
assert!(env.get(&Name::str("KaramataIndex")).is_some());
}
#[test]
fn test_abelian_and_laplace_registered() {
let env = test_env();
assert!(env.get(&Name::str("AbelianThmSeries")).is_some());
assert!(env.get(&Name::str("AbelianThmLaplace")).is_some());
assert!(env.get(&Name::str("CesaroSummability")).is_some());
assert!(env.get(&Name::str("LittlewoodTauberianThm")).is_some());
assert!(env.get(&Name::str("LaplaceTransformFn")).is_some());
assert!(env.get(&Name::str("TauberianForLaplace")).is_some());
assert!(env.get(&Name::str("PostWidderInversion")).is_some());
}
#[test]
fn test_pnt_applications_registered() {
let env = test_env();
assert!(env.get(&Name::str("PrimeNumberTheoremTaub")).is_some());
assert!(env.get(&Name::str("ZetaNoPoleonLine")).is_some());
assert!(env.get(&Name::str("ZetaSimplePoleAtOne")).is_some());
assert!(env.get(&Name::str("ChebyshevPsiAsymptotics")).is_some());
assert!(env.get(&Name::str("MertensTheoremTaub")).is_some());
assert!(env.get(&Name::str("DirichletPNTTaub")).is_some());
}
#[test]
fn test_abel_summable_sequence() {
let terms: Vec<f64> = (0..20).map(|n| 0.5_f64.powi(n)).collect();
let seq = AbelSummableSequence::new(terms, 2.0);
let gf = seq.generating_function(0.9);
assert!((gf - 1.0 / (1.0 - 0.5 * 0.9)).abs() < 0.01);
assert!(seq.ordinary_sum_matches_abel(0.01));
assert!(seq.tauberian_constant().is_some());
}
#[test]
fn test_regularly_varying_function() {
let rv = RegularlyVaryingFn::new(2.0, 1.0, 1.0);
let ratio = rv.check_rv_property(3.0, 100.0);
assert!((ratio - 9.0).abs() < 1e-6);
assert_eq!(rv.karamata_index(), 2.0);
assert!(!rv.is_slowly_varying());
let sv = RegularlyVaryingFn::new(0.0, 1.0, 1.0);
assert!(sv.is_slowly_varying());
}
#[test]
fn test_prime_sieve_and_pnt() {
let sieve = PrimeSieve::new(1000);
assert_eq!(sieve.prime_counting(100), 25);
assert_eq!(sieve.prime_counting(1000), 168);
let ratio = sieve.pnt_ratio(1000);
assert!(ratio > 1.0 && ratio < 1.3);
let psi = sieve.chebyshev_psi(10);
assert!(psi > 7.0 && psi < 9.0);
}
}
pub fn build_env() -> oxilean_kernel::Environment {
let mut env = oxilean_kernel::Environment::new();
let _ = build_tauberian_theory_env(&mut env);
env
}
pub fn borel_summability_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn riesz_summability_method_ty() -> Expr {
arrow(type0(), arrow(real_ty(), real_ty()))
}
pub fn hausdorff_mean_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn mercerian_thm_ty() -> Expr {
prop()
}
pub fn hausdorff_mercerian_thm_ty() -> Expr {
prop()
}
pub fn summability_hierarchy_ty() -> Expr {
prop()
}
pub fn strong_tauberian_cond_ty() -> Expr {
arrow(type0(), prop())
}
pub fn slow_oscillation_cond_ty() -> Expr {
arrow(type0(), prop())
}
pub fn boundedness_tauberian_cond_ty() -> Expr {
arrow(type0(), prop())
}
pub fn newman_tauberian_thm_ty() -> Expr {
prop()
}
pub fn zagier_newman_proof_ty() -> Expr {
prop()
}
pub fn selberg_delange_method_ty() -> Expr {
prop()
}
pub fn tauberian_remainder_thm_ty() -> Expr {
prop()
}
pub fn effective_tauberian_thm_ty() -> Expr {
prop()
}
pub fn complex_tauberian_condition_ty() -> Expr {
arrow(type0(), prop())
}
pub fn dirichlet_series_abscissa_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn hardy_ramanujan_thm_ty() -> Expr {
prop()
}
pub fn partition_asymptotics_ty() -> Expr {
prop()
}
pub fn rademacher_series_thm_ty() -> Expr {
prop()
}
pub fn circle_method_application_ty() -> Expr {
prop()
}
pub fn warings_theorem_partitions_ty() -> Expr {
prop()
}
pub fn partition_function_growth_ty() -> Expr {
arrow(nat_ty(), real_ty())
}
pub fn de_haan_class_ty() -> Expr {
arrow(type0(), prop())
}
pub fn gamma_variation_ty() -> Expr {
arrow(type0(), prop())
}
pub fn pi_variation_ty() -> Expr {
arrow(type0(), prop())
}
pub fn second_order_regular_variation_ty() -> Expr {
arrow(type0(), arrow(real_ty(), arrow(real_ty(), prop())))
}
pub fn beurling_slowly_varying_fn_ty() -> Expr {
arrow(type0(), prop())
}
pub fn representation_thm_extended_ty() -> Expr {
prop()
}
pub fn tauberian_for_de_haan_ty() -> Expr {
prop()
}
pub fn mellin_tauberian_thm_ty() -> Expr {
prop()
}
pub fn stieltjes_tauberian_extended_ty() -> Expr {
prop()
}
pub fn build_tauberian_theory_ext_env(env: &mut Environment) -> Result<(), String> {
add_axiom(env, "BorelSummability", vec![], borel_summability_ty())?;
add_axiom(
env,
"RieszSummabilityMethod",
vec![],
riesz_summability_method_ty(),
)?;
add_axiom(env, "HausdorffMean", vec![], hausdorff_mean_ty())?;
add_axiom(env, "MercerianThm", vec![], mercerian_thm_ty())?;
add_axiom(
env,
"HausdorffMercerianThm",
vec![],
hausdorff_mercerian_thm_ty(),
)?;
add_axiom(
env,
"SummabilityHierarchy",
vec![],
summability_hierarchy_ty(),
)?;
add_axiom(
env,
"StrongTauberianCond",
vec![],
strong_tauberian_cond_ty(),
)?;
add_axiom(
env,
"SlowOscillationCond",
vec![],
slow_oscillation_cond_ty(),
)?;
add_axiom(
env,
"BoundednessTauberianCond",
vec![],
boundedness_tauberian_cond_ty(),
)?;
add_axiom(env, "NewmanTauberianThm", vec![], newman_tauberian_thm_ty())?;
add_axiom(env, "ZagierNewmanProof", vec![], zagier_newman_proof_ty())?;
add_axiom(
env,
"SelbergDelangeMethod",
vec![],
selberg_delange_method_ty(),
)?;
add_axiom(
env,
"TauberianRemainderThm",
vec![],
tauberian_remainder_thm_ty(),
)?;
add_axiom(
env,
"EffectiveTauberianThm",
vec![],
effective_tauberian_thm_ty(),
)?;
add_axiom(
env,
"ComplexTauberianCondition",
vec![],
complex_tauberian_condition_ty(),
)?;
add_axiom(
env,
"DirichletSeriesAbscissa",
vec![],
dirichlet_series_abscissa_ty(),
)?;
add_axiom(env, "HardyRamanujanThm", vec![], hardy_ramanujan_thm_ty())?;
add_axiom(
env,
"PartitionAsymptotics",
vec![],
partition_asymptotics_ty(),
)?;
add_axiom(
env,
"RademacherSeriesThm",
vec![],
rademacher_series_thm_ty(),
)?;
add_axiom(
env,
"CircleMethodApplication",
vec![],
circle_method_application_ty(),
)?;
add_axiom(
env,
"WaringsTheoremPartitions",
vec![],
warings_theorem_partitions_ty(),
)?;
add_axiom(
env,
"PartitionFunctionGrowth",
vec![],
partition_function_growth_ty(),
)?;
add_axiom(env, "DeHaanClass", vec![], de_haan_class_ty())?;
add_axiom(env, "GammaVariation", vec![], gamma_variation_ty())?;
add_axiom(env, "PiVariation", vec![], pi_variation_ty())?;
add_axiom(
env,
"SecondOrderRegularVariation",
vec![],
second_order_regular_variation_ty(),
)?;
add_axiom(
env,
"BeurlingSlowlyVaryingFn",
vec![],
beurling_slowly_varying_fn_ty(),
)?;
add_axiom(
env,
"RepresentationThmExtended",
vec![],
representation_thm_extended_ty(),
)?;
add_axiom(
env,
"TauberianForDeHaan",
vec![],
tauberian_for_de_haan_ty(),
)?;
add_axiom(env, "MellinTauberianThm", vec![], mellin_tauberian_thm_ty())?;
add_axiom(
env,
"StieltjesTauberianExtended",
vec![],
stieltjes_tauberian_extended_ty(),
)?;
Ok(())
}
#[cfg(test)]
mod tests_ext {
use super::*;
fn test_ext_env() -> Environment {
let mut env = Environment::new();
build_tauberian_theory_env(&mut env).expect("base env failed");
build_tauberian_theory_ext_env(&mut env).expect("ext env failed");
env
}
#[test]
fn test_summability_methods_registered() {
let env = test_ext_env();
assert!(env.get(&Name::str("BorelSummability")).is_some());
assert!(env.get(&Name::str("HausdorffMean")).is_some());
assert!(env.get(&Name::str("MercerianThm")).is_some());
assert!(env.get(&Name::str("SummabilityHierarchy")).is_some());
assert!(env.get(&Name::str("SlowOscillationCond")).is_some());
}
#[test]
fn test_complex_tauberian_registered() {
let env = test_ext_env();
assert!(env.get(&Name::str("NewmanTauberianThm")).is_some());
assert!(env.get(&Name::str("ZagierNewmanProof")).is_some());
assert!(env.get(&Name::str("SelbergDelangeMethod")).is_some());
assert!(env.get(&Name::str("TauberianRemainderThm")).is_some());
assert!(env.get(&Name::str("DirichletSeriesAbscissa")).is_some());
}
#[test]
fn test_hardy_ramanujan_registered() {
let env = test_ext_env();
assert!(env.get(&Name::str("HardyRamanujanThm")).is_some());
assert!(env.get(&Name::str("PartitionAsymptotics")).is_some());
assert!(env.get(&Name::str("RademacherSeriesThm")).is_some());
assert!(env.get(&Name::str("CircleMethodApplication")).is_some());
}
#[test]
fn test_de_haan_registered() {
let env = test_ext_env();
assert!(env.get(&Name::str("DeHaanClass")).is_some());
assert!(env.get(&Name::str("GammaVariation")).is_some());
assert!(env.get(&Name::str("PiVariation")).is_some());
assert!(env.get(&Name::str("SecondOrderRegularVariation")).is_some());
assert!(env.get(&Name::str("BeurlingSlowlyVaryingFn")).is_some());
assert!(env.get(&Name::str("MellinTauberianThm")).is_some());
}
#[test]
fn test_karamata_slow_variation() {
let xs: Vec<f64> = (1..=1000).map(|i| i as f64 * 10.0).collect();
let ls: Vec<f64> = xs.iter().map(|&x| x.ln()).collect();
let ksv = KaramataSlowVariation::new(xs, ls);
let ratio = ksv.slow_variation_ratio(2.0, 5000.0);
assert!(ratio.is_some());
let r = ratio.expect("ratio should be valid");
assert!(r > 0.9 && r < 1.2, "ratio = {r}");
let idx = ksv.estimate_index();
assert!(idx.abs() < 0.2, "index for log should be near 0, got {idx}");
}
#[test]
fn test_cesaro_sum_computer() {
let terms: Vec<f64> = (0..100)
.map(|i| if i % 2 == 0 { 1.0 } else { -1.0 })
.collect();
let comp = CesaroSumComputer::new(terms);
let c1 = comp.cesaro_c1();
let last = c1.last().expect("last should succeed");
assert!((last - 0.5).abs() < 0.05, "C1 mean = {last}");
assert!(comp.appears_cesaro_summable(1, 0.1));
let c2_sum = comp.cesaro_sum(2).expect("cesaro_sum should succeed");
assert!((c2_sum - 0.5).abs() < 0.1, "C2 sum = {c2_sum}");
}
#[test]
fn test_abel_sum_computer() {
let terms: Vec<f64> = (0..5000)
.map(|i| if i % 2 == 0 { 1.0 } else { -1.0 })
.collect();
let comp = AbelSumComputer::new(terms);
let gf = comp.generating_function(0.99);
assert!((gf - 0.5).abs() < 0.05, "f(0.99) = {gf}");
let abel = comp.estimate_abel_sum(0.001);
assert!((abel - 0.5).abs() < 0.05, "Abel sum estimate = {abel}");
let m = comp.one_sided_tauberian_constant();
assert!(m >= 0.0);
}
#[test]
fn test_tauberian_bound_checker() {
let terms: Vec<f64> = (1..=100).map(|n| 1.0 / (n as f64 * n as f64)).collect();
let target = std::f64::consts::PI * std::f64::consts::PI / 6.0;
let checker = TauberianBoundChecker::new(terms.clone(), target);
let m = checker.one_sided_condition();
assert!(m.is_some() && m.expect("m should be valid") < 1e-10);
assert!(checker.littlewood_condition(3, 0.2));
let rem = checker.tauberian_remainder();
assert!(rem < 1.0, "remainder = {rem}");
let bound = checker.boundedness_condition();
assert!(bound < target + 0.1, "bound = {bound}");
let idx = checker.cesaro_convergence_index(0.1);
assert!(idx.is_some());
}
}
#[cfg(test)]
mod tests_tauberian_extra {
use super::*;
#[test]
fn test_cesaro_sum() {
let mut cs = CesaroSum::new(1);
for k in 0..100 {
let term = if k % 2 == 0 { 1.0 } else { -1.0 };
cs.add_term(term);
}
assert!(cs.converges_to(0.5, 0.01));
}
#[test]
fn test_abel_sum() {
let mut abel = AbelSum::new();
for k in 0..20 {
abel.add_coeff(if k % 2 == 0 { 1.0 } else { -1.0 });
}
let val = abel.evaluate_at(0.9);
assert!(val > 0.4 && val < 0.6, "Abel sum near 0.5, got {val}");
}
#[test]
fn test_summability_hierarchy() {
assert!(SummabilityMethod::Cesaro1.stronger_than_ordinary());
assert!(SummabilityMethod::AbelSumm.stronger_than_ordinary());
assert!(!SummabilityMethod::Ordinary.stronger_than_ordinary());
assert!(SummabilityMethod::Cesaro1.is_regular());
}
#[test]
fn test_tauberian_theorem() {
let hl = TauberianTheorem::hardylittlewood();
assert_eq!(hl.summability_from, SummabilityMethod::AbelSumm);
assert_eq!(hl.summability_to, SummabilityMethod::Ordinary);
assert!(hl.is_valid_direction());
}
}