use oxilean_kernel::{BinderInfo, Declaration, Environment, Expr, Level, Name};
use super::types::{
CechCohomologyData, ComplexOfSheaves, DerivePushforward, FinitePresheaf, FiniteSite,
FormalComplex, Germ, GlobalSectionsComputation, LeraySpectralSequence, MicrosupportData,
OpenNode, PerverseSheafFilter, PresheafSheafification, SheafOnSite, SheafQuantization,
};
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 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 bvar(n: u32) -> Expr {
Expr::BVar(n)
}
pub fn nat_ty() -> Expr {
cst("Nat")
}
pub fn int_ty() -> Expr {
cst("Int")
}
pub fn ring_ty() -> Expr {
cst("Ring")
}
pub fn space_ty() -> Expr {
cst("TopologicalSpace")
}
pub fn category_ty() -> Expr {
cst("Category")
}
pub fn set_of(ty: Expr) -> Expr {
app(cst("Set"), ty)
}
pub fn presheaf_ty() -> Expr {
arrow(space_ty(), arrow(category_ty(), type0()))
}
pub fn sheaf_ty() -> Expr {
arrow(space_ty(), arrow(category_ty(), type0()))
}
pub fn is_sheaf_ty() -> Expr {
pi(
BinderInfo::Default,
"X",
space_ty(),
pi(
BinderInfo::Default,
"C",
category_ty(),
arrow(app2(cst("Presheaf"), bvar(1), bvar(0)), prop()),
),
)
}
pub fn constant_sheaf_ty() -> Expr {
arrow(space_ty(), arrow(type0(), type0()))
}
pub fn structure_sheaf_ty() -> Expr {
arrow(space_ty(), type0())
}
pub fn sheaf_of_modules_ty() -> Expr {
arrow(type0(), arrow(ring_ty(), type0()))
}
pub fn stalk_ty() -> Expr {
pi(
BinderInfo::Default,
"X",
space_ty(),
pi(
BinderInfo::Default,
"C",
category_ty(),
arrow(
app2(cst("Presheaf"), bvar(1), bvar(0)),
arrow(bvar(2), type0()),
),
),
)
}
pub fn section_ty() -> Expr {
pi(
BinderInfo::Default,
"X",
space_ty(),
pi(
BinderInfo::Default,
"C",
category_ty(),
arrow(
app2(cst("Presheaf"), bvar(1), bvar(0)),
arrow(app(cst("OpenSet"), bvar(2)), type0()),
),
),
)
}
pub fn germ_ty() -> Expr {
pi(
BinderInfo::Default,
"X",
space_ty(),
pi(
BinderInfo::Default,
"C",
category_ty(),
arrow(
app2(cst("Presheaf"), bvar(1), bvar(0)),
arrow(bvar(2), type0()),
),
),
)
}
pub fn restriction_map_ty() -> Expr {
arrow(type0(), arrow(prop(), type0()))
}
pub fn global_section_ty() -> Expr {
pi(
BinderInfo::Default,
"X",
space_ty(),
pi(
BinderInfo::Default,
"C",
category_ty(),
arrow(app2(cst("Sheaf"), bvar(1), bvar(0)), type0()),
),
)
}
pub fn sheafification_ty() -> Expr {
pi(
BinderInfo::Default,
"X",
space_ty(),
pi(
BinderInfo::Default,
"C",
category_ty(),
arrow(
app2(cst("Presheaf"), bvar(1), bvar(0)),
app2(cst("Sheaf"), bvar(2), bvar(1)),
),
),
)
}
pub fn sheafification_unit_ty() -> Expr {
pi(
BinderInfo::Default,
"X",
space_ty(),
pi(
BinderInfo::Default,
"C",
category_ty(),
pi(
BinderInfo::Default,
"F",
app2(cst("Presheaf"), bvar(1), bvar(0)),
prop(),
),
),
)
}
pub fn sheafification_preserves_stalk_ty() -> Expr {
pi(
BinderInfo::Default,
"X",
space_ty(),
pi(
BinderInfo::Default,
"F",
app2(cst("Presheaf"), bvar(0), cst("Category")),
arrow(bvar(1), prop()),
),
)
}
pub fn direct_image_ty() -> Expr {
pi(
BinderInfo::Default,
"X",
space_ty(),
pi(
BinderInfo::Default,
"Y",
space_ty(),
arrow(
arrow(bvar(1), bvar(0)),
arrow(
app2(cst("Sheaf"), bvar(2), category_ty()),
app2(cst("Sheaf"), bvar(2), category_ty()),
),
),
),
)
}
pub fn inverse_image_ty() -> Expr {
pi(
BinderInfo::Default,
"X",
space_ty(),
pi(
BinderInfo::Default,
"Y",
space_ty(),
arrow(
arrow(bvar(1), bvar(0)),
arrow(
app2(cst("Sheaf"), bvar(1), category_ty()),
app2(cst("Sheaf"), bvar(2), category_ty()),
),
),
),
)
}
pub fn direct_image_adjunction_ty() -> Expr {
pi(
BinderInfo::Default,
"X",
space_ty(),
pi(
BinderInfo::Default,
"Y",
space_ty(),
arrow(arrow(bvar(1), bvar(0)), prop()),
),
)
}
pub fn proper_base_change_ty() -> Expr {
pi(
BinderInfo::Default,
"X",
space_ty(),
pi(
BinderInfo::Default,
"Y",
space_ty(),
arrow(arrow(bvar(1), bvar(0)), prop()),
),
)
}
pub fn sheaf_cohomology_ty() -> Expr {
arrow(nat_ty(), arrow(space_ty(), arrow(type0(), type0())))
}
pub fn cech_cohomology_ty() -> Expr {
arrow(nat_ty(), arrow(space_ty(), arrow(type0(), type0())))
}
pub fn long_exact_cohomology_ty() -> Expr {
arrow(type0(), arrow(type0(), arrow(type0(), prop())))
}
pub fn flabby_resolution_ty() -> Expr {
arrow(type0(), type0())
}
pub fn godement_resolution_ty() -> Expr {
arrow(type0(), type0())
}
pub fn kunneth_formula_ty() -> Expr {
arrow(space_ty(), arrow(space_ty(), arrow(type0(), prop())))
}
pub fn derived_category_ty() -> Expr {
arrow(space_ty(), arrow(category_ty(), category_ty()))
}
pub fn derived_pushforward_ty() -> Expr {
pi(
BinderInfo::Default,
"X",
space_ty(),
pi(
BinderInfo::Default,
"Y",
space_ty(),
arrow(
arrow(bvar(1), bvar(0)),
arrow(
app2(cst("DerivedCategory"), bvar(2), cst("Category")),
app2(cst("DerivedCategory"), bvar(2), cst("Category")),
),
),
),
)
}
pub fn derived_pullback_ty() -> Expr {
pi(
BinderInfo::Default,
"X",
space_ty(),
pi(
BinderInfo::Default,
"Y",
space_ty(),
arrow(
arrow(bvar(1), bvar(0)),
arrow(
app2(cst("DerivedCategory"), bvar(1), cst("Category")),
app2(cst("DerivedCategory"), bvar(2), cst("Category")),
),
),
),
)
}
pub fn verdier_duality_ty() -> Expr {
pi(
BinderInfo::Default,
"X",
space_ty(),
arrow(
app2(cst("DerivedCategory"), bvar(0), cst("Category")),
app2(cst("DerivedCategory"), bvar(1), cst("Category")),
),
)
}
pub fn six_functors_ty() -> Expr {
pi(
BinderInfo::Default,
"X",
space_ty(),
pi(
BinderInfo::Default,
"Y",
space_ty(),
arrow(arrow(bvar(1), bvar(0)), prop()),
),
)
}
pub fn d_module_ty() -> Expr {
arrow(type0(), type0())
}
pub fn holonomic_d_module_ty() -> Expr {
arrow(cst("DModule"), prop())
}
pub fn riemann_hilbert_ty() -> Expr {
arrow(type0(), arrow(type0(), prop()))
}
pub fn bernstein_sato_ty() -> Expr {
arrow(type0(), prop())
}
pub fn perverse_sheaf_ty() -> Expr {
arrow(space_ty(), type0())
}
pub fn intersection_cohomology_ty() -> Expr {
arrow(space_ty(), arrow(nat_ty(), type0()))
}
pub fn bbd_decomposition_ty() -> Expr {
pi(
BinderInfo::Default,
"X",
space_ty(),
pi(
BinderInfo::Default,
"Y",
space_ty(),
arrow(arrow(bvar(1), bvar(0)), prop()),
),
)
}
pub fn middle_perversity_ty() -> Expr {
arrow(nat_ty(), nat_ty())
}
pub fn poincare_duality_ic_ty() -> Expr {
arrow(space_ty(), arrow(nat_ty(), prop()))
}
pub fn etale_cohomology_ty() -> Expr {
arrow(nat_ty(), arrow(type0(), arrow(type0(), type0())))
}
pub fn l_adic_cohomology_ty() -> Expr {
arrow(nat_ty(), arrow(type0(), type0()))
}
pub fn weil_conjectures_ty() -> Expr {
arrow(type0(), prop())
}
pub fn etale_fundamental_group_ty() -> Expr {
arrow(type0(), type0())
}
pub fn grothendieck_purity_ty() -> Expr {
arrow(type0(), arrow(nat_ty(), prop()))
}
pub fn grothendieck_topology_ty() -> Expr {
arrow(category_ty(), type0())
}
pub fn site_ty() -> Expr {
type0()
}
pub fn sheaf_on_site_ty() -> Expr {
arrow(site_ty(), arrow(category_ty(), type0()))
}
pub fn descent_data_ty() -> Expr {
arrow(site_ty(), arrow(type0(), prop()))
}
pub fn sheafification_on_site_ty() -> Expr {
arrow(site_ty(), arrow(category_ty(), arrow(type0(), type0())))
}
pub fn topos_of_sheaves_ty() -> Expr {
arrow(site_ty(), type0())
}
pub fn t_structure_ty() -> Expr {
arrow(category_ty(), prop())
}
pub fn heart_of_t_structure_ty() -> Expr {
arrow(prop(), category_ty())
}
pub fn perversity_function_ty() -> Expr {
arrow(nat_ty(), int_ty())
}
pub fn bbd_purity_ty() -> Expr {
arrow(prop(), prop())
}
pub fn constructible_sheaf_ty() -> Expr {
arrow(space_ty(), arrow(type0(), type0()))
}
pub fn characteristic_variety_ty() -> Expr {
arrow(cst("DModule"), type0())
}
pub fn l_adic_sheaf_ty() -> Expr {
arrow(type0(), type0())
}
pub fn frobenius_endomorphism_ty() -> Expr {
arrow(type0(), type0())
}
pub fn weight_filtration_ty() -> Expr {
arrow(type0(), type0())
}
pub fn microsupport_ty() -> Expr {
arrow(type0(), type0())
}
pub fn microlocal_propagation_ty() -> Expr {
arrow(type0(), prop())
}
pub fn microlocal_morse_inequality_ty() -> Expr {
arrow(type0(), arrow(type0(), prop()))
}
pub fn fukaya_category_ty() -> Expr {
arrow(type0(), type0())
}
pub fn homological_mirror_symmetry_ty() -> Expr {
arrow(type0(), arrow(type0(), prop()))
}
pub fn floer_cohomology_ty() -> Expr {
arrow(type0(), arrow(type0(), type0()))
}
pub fn factorization_algebra_ty() -> Expr {
arrow(space_ty(), type0())
}
pub fn topological_field_theory_ty() -> Expr {
arrow(nat_ty(), type0())
}
pub fn cobordism_hypothesis_ty() -> Expr {
arrow(nat_ty(), prop())
}
pub fn condensed_set_ty() -> Expr {
type0()
}
pub fn condensed_abelian_group_ty() -> Expr {
type0()
}
pub fn solid_abelian_group_ty() -> Expr {
arrow(type0(), prop())
}
pub fn pyknotic_object_ty() -> Expr {
arrow(type0(), type0())
}
pub fn topos_ty() -> Expr {
type0()
}
pub fn geometric_morphism_ty() -> Expr {
arrow(type0(), arrow(type0(), type0()))
}
pub fn infinity_topos_ty() -> Expr {
type0()
}
pub fn higher_sheaf_ty() -> Expr {
arrow(type0(), arrow(nat_ty(), type0()))
}
pub fn lurie_hypercovering_ty() -> Expr {
arrow(type0(), arrow(type0(), prop()))
}
pub fn sheaves_on_stratified_space_ty() -> Expr {
arrow(space_ty(), arrow(type0(), type0()))
}
pub fn exit_path_category_ty() -> Expr {
arrow(type0(), category_ty())
}
pub fn locally_constant_sheaf_ty() -> Expr {
arrow(space_ty(), type0())
}
pub fn build_sheaf_theory_env(env: &mut Environment) {
let axioms: &[(&str, Expr)] = &[
("TopologicalSpace", type0()),
("Category", type0()),
("OpenSet", arrow(space_ty(), type0())),
("Ring", type0()),
("Group", type0()),
("AbelianGroup", type0()),
("Set", arrow(type0(), type0())),
("DModule", type0()),
("Presheaf", presheaf_ty()),
("Sheaf", sheaf_ty()),
("IsSheaf", is_sheaf_ty()),
("ConstantSheaf", constant_sheaf_ty()),
("StructureSheaf", structure_sheaf_ty()),
("SheafOfModules", sheaf_of_modules_ty()),
("Stalk", stalk_ty()),
("Section", section_ty()),
("Germ", germ_ty()),
("RestrictionMap", restriction_map_ty()),
("GlobalSection", global_section_ty()),
("Sheafification", sheafification_ty()),
("sheafification_unit", sheafification_unit_ty()),
(
"sheafification_preserves_stalk",
sheafification_preserves_stalk_ty(),
),
("DirectImage", direct_image_ty()),
("InverseImage", inverse_image_ty()),
("direct_image_adjunction", direct_image_adjunction_ty()),
("proper_base_change", proper_base_change_ty()),
("SheafCohomology", sheaf_cohomology_ty()),
("CechCohomology", cech_cohomology_ty()),
("long_exact_cohomology", long_exact_cohomology_ty()),
("FlabbyResolution", flabby_resolution_ty()),
("GodementResolution", godement_resolution_ty()),
("kunneth_formula", kunneth_formula_ty()),
("DerivedCategory", derived_category_ty()),
("DerivedPushforward", derived_pushforward_ty()),
("DerivedPullback", derived_pullback_ty()),
("VerdierDuality", verdier_duality_ty()),
("six_functors", six_functors_ty()),
("d_module", d_module_ty()),
("HolonomicDModule", holonomic_d_module_ty()),
("riemann_hilbert", riemann_hilbert_ty()),
("bernstein_sato", bernstein_sato_ty()),
("PerverseSheaf", perverse_sheaf_ty()),
("IntersectionCohomology", intersection_cohomology_ty()),
("bbd_decomposition", bbd_decomposition_ty()),
("MiddlePerversity", middle_perversity_ty()),
("poincare_duality_ic", poincare_duality_ic_ty()),
("EtaleCohomology", etale_cohomology_ty()),
("lAdicCohomology", l_adic_cohomology_ty()),
("weil_conjectures", weil_conjectures_ty()),
("EtaleFundamentalGroup", etale_fundamental_group_ty()),
("grothendieck_purity", grothendieck_purity_ty()),
("GrothendieckTopology", grothendieck_topology_ty()),
("Site", site_ty()),
("SheafOnSiteType", sheaf_on_site_ty()),
("DescentData", descent_data_ty()),
("sheafification_on_site", sheafification_on_site_ty()),
("ToposOfSheaves", topos_of_sheaves_ty()),
("TStructure", t_structure_ty()),
("HeartOfTStructure", heart_of_t_structure_ty()),
("PerversityFunction", perversity_function_ty()),
("BBDPurity", bbd_purity_ty()),
("ConstructibleSheaf", constructible_sheaf_ty()),
("CharacteristicVariety", characteristic_variety_ty()),
("LAdicSheaf", l_adic_sheaf_ty()),
("FrobeniusEndomorphism", frobenius_endomorphism_ty()),
("WeightFiltration", weight_filtration_ty()),
("Microsupport", microsupport_ty()),
("microlocal_propagation", microlocal_propagation_ty()),
(
"microlocal_morse_inequality",
microlocal_morse_inequality_ty(),
),
("FukayaCategory", fukaya_category_ty()),
(
"homological_mirror_symmetry",
homological_mirror_symmetry_ty(),
),
("FloerCohomology", floer_cohomology_ty()),
("FactorizationAlgebra", factorization_algebra_ty()),
("TopologicalFieldTheory", topological_field_theory_ty()),
("cobordism_hypothesis", cobordism_hypothesis_ty()),
("CondensedSet", condensed_set_ty()),
("CondensedAbelianGroup", condensed_abelian_group_ty()),
("SolidAbelianGroup", solid_abelian_group_ty()),
("PyknoticObject", pyknotic_object_ty()),
("Topos", topos_ty()),
("GeometricMorphism", geometric_morphism_ty()),
("InfinityTopos", infinity_topos_ty()),
("HigherSheaf", higher_sheaf_ty()),
("lurie_hypercovering", lurie_hypercovering_ty()),
("SheavesOnStratifiedSpace", sheaves_on_stratified_space_ty()),
("ExitPathCategory", exit_path_category_ty()),
("LocallyConstantSheaf", locally_constant_sheaf_ty()),
];
for (name, ty) in axioms {
env.add(Declaration::Axiom {
name: Name::str(*name),
univ_params: vec![],
ty: ty.clone(),
})
.ok();
}
}
pub fn cech_h0_dimension(presheaf: &FinitePresheaf, u: usize, v: usize, uv: usize) -> usize {
let dim_u = presheaf.section_dims[u];
let dim_v = presheaf.section_dims[v];
let dim_uv = presheaf.section_dims[uv];
let _ = dim_uv;
let mut compatible = 0;
for i in 0..dim_u {
let mut eu = vec![0i64; dim_u];
eu[i] = 1;
for j in 0..dim_v {
let mut ev = vec![0i64; dim_v];
ev[j] = 1;
if presheaf.check_compatibility(u, v, uv, &eu, &ev) {
compatible += 1;
}
}
}
compatible
}
pub fn intersection_euler_characteristic(betti_numbers: &[usize]) -> i64 {
betti_numbers
.iter()
.enumerate()
.map(|(k, &b)| if k % 2 == 0 { b as i64 } else { -(b as i64) })
.sum()
}
pub fn check_poincare_duality_ic(betti_numbers: &[usize]) -> bool {
let total = betti_numbers.len();
for k in 0..total {
let dual_k = if total > k { total - 1 - k } else { 0 };
if k < dual_k && betti_numbers[k] != betti_numbers[dual_k] {
return false;
}
}
true
}
pub fn middle_perversity(codim: u32) -> u32 {
if codim == 0 {
0
} else {
(codim - 1) / 2
}
}
pub fn check_support_condition(complex: &FormalComplex, codim: u32) -> bool {
let threshold = -(codim as i32) + middle_perversity(codim) as i32;
for (i, &d) in complex.cohomology.iter().enumerate() {
let k = complex.min_degree + i as i32;
if d > 0 && k > threshold {
return false;
}
}
true
}
pub fn leray_e2_degeneration(
base_cohomology: &[usize],
higher_direct_images: &[Vec<usize>],
) -> Vec<usize> {
if higher_direct_images.is_empty() {
return base_cohomology.to_vec();
}
let n_base = base_cohomology.len();
let n_fiber = higher_direct_images.len();
let total_len = n_base + n_fiber - 1;
let mut result = vec![0usize; total_len];
for (p, &hp) in base_cohomology.iter().enumerate() {
for (q, hq_vec) in higher_direct_images.iter().enumerate() {
let hq = if p < hq_vec.len() { hq_vec[p] } else { 0 };
let k = p + q;
if k < total_len {
result[k] += hp * hq;
}
}
}
result
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_build_sheaf_theory_env_populates() {
let mut env = Environment::new();
build_sheaf_theory_env(&mut env);
assert!(env.get(&Name::str("Sheaf")).is_some());
assert!(env.get(&Name::str("Presheaf")).is_some());
assert!(env.get(&Name::str("Sheafification")).is_some());
assert!(env.get(&Name::str("SheafCohomology")).is_some());
assert!(env.get(&Name::str("VerdierDuality")).is_some());
assert!(env.get(&Name::str("riemann_hilbert")).is_some());
assert!(env.get(&Name::str("weil_conjectures")).is_some());
assert!(env.get(&Name::str("bbd_decomposition")).is_some());
assert!(env.get(&Name::str("EtaleCohomology")).is_some());
}
#[test]
fn test_finite_presheaf_restriction() {
let nodes = vec![
OpenNode::new(0, "U"),
OpenNode::new(1, "V"),
OpenNode::new(2, "U∩V"),
];
let dims = vec![1, 1, 1];
let mut psh = FinitePresheaf::new(nodes, dims);
psh.add_restriction(0, 2, vec![vec![1]]);
psh.add_restriction(1, 2, vec![vec![1]]);
assert!(psh.check_compatibility(0, 1, 2, &[2], &[2]));
assert!(!psh.check_compatibility(0, 1, 2, &[1], &[2]));
}
#[test]
fn test_cech_h0_dimension() {
let nodes = vec![
OpenNode::new(0, "U"),
OpenNode::new(1, "V"),
OpenNode::new(2, "U∩V"),
];
let dims = vec![1, 1, 1];
let mut psh = FinitePresheaf::new(nodes, dims);
psh.add_restriction(0, 2, vec![vec![1]]);
psh.add_restriction(1, 2, vec![vec![1]]);
let dim = cech_h0_dimension(&psh, 0, 1, 2);
assert_eq!(dim, 1, "H0 should be 1-dimensional for constant sheaf");
}
#[test]
fn test_formal_complex_shift() {
let c = FormalComplex::new(0, vec![1, 0, 1]);
assert_eq!(c.euler_characteristic(), 2);
let shifted = c.shift(1);
assert_eq!(shifted.min_degree, -1);
assert_eq!(shifted.euler_characteristic(), -2);
}
#[test]
fn test_formal_complex_lowest_degree() {
let c = FormalComplex::new(-2, vec![0, 0, 1, 2]);
assert_eq!(c.lowest_nonzero_degree(), Some(0));
let empty = FormalComplex::new(0, vec![0, 0, 0]);
assert_eq!(empty.lowest_nonzero_degree(), None);
}
#[test]
fn test_intersection_euler_characteristic() {
let betti = [1, 0, 1, 0, 1];
assert_eq!(intersection_euler_characteristic(&betti), 3);
}
#[test]
fn test_poincare_duality_ic() {
assert!(check_poincare_duality_ic(&[1, 0, 1, 0, 1]));
assert!(!check_poincare_duality_ic(&[1, 2, 1, 0, 1]));
}
#[test]
fn test_middle_perversity() {
assert_eq!(middle_perversity(0), 0);
assert_eq!(middle_perversity(1), 0);
assert_eq!(middle_perversity(2), 0);
assert_eq!(middle_perversity(3), 1);
assert_eq!(middle_perversity(4), 1);
assert_eq!(middle_perversity(5), 2);
}
#[test]
fn test_axiom_types_wellformed() {
let ty1 = presheaf_ty();
assert!(matches!(ty1, Expr::Pi(_, _, _, _)));
let ty2 = sheaf_cohomology_ty();
assert!(matches!(ty2, Expr::Pi(_, _, _, _)));
let ty3 = verdier_duality_ty();
assert!(matches!(ty3, Expr::Pi(_, _, _, _)));
let ty4 = etale_cohomology_ty();
assert!(matches!(ty4, Expr::Pi(_, _, _, _)));
}
#[test]
fn test_extended_axiom_registration() {
let mut env = Environment::new();
build_sheaf_theory_env(&mut env);
assert!(env.get(&Name::str("GrothendieckTopology")).is_some());
assert!(env.get(&Name::str("SheafOnSiteType")).is_some());
assert!(env.get(&Name::str("ToposOfSheaves")).is_some());
assert!(env.get(&Name::str("TStructure")).is_some());
assert!(env.get(&Name::str("ConstructibleSheaf")).is_some());
assert!(env.get(&Name::str("LAdicSheaf")).is_some());
assert!(env.get(&Name::str("Microsupport")).is_some());
assert!(env.get(&Name::str("FukayaCategory")).is_some());
assert!(env.get(&Name::str("homological_mirror_symmetry")).is_some());
assert!(env.get(&Name::str("FactorizationAlgebra")).is_some());
assert!(env.get(&Name::str("cobordism_hypothesis")).is_some());
assert!(env.get(&Name::str("CondensedSet")).is_some());
assert!(env.get(&Name::str("SolidAbelianGroup")).is_some());
assert!(env.get(&Name::str("InfinityTopos")).is_some());
assert!(env.get(&Name::str("lurie_hypercovering")).is_some());
assert!(env.get(&Name::str("ExitPathCategory")).is_some());
assert!(env.get(&Name::str("LocallyConstantSheaf")).is_some());
}
#[test]
fn test_sheaf_on_site_basic() {
let mut site = FiniteSite::new(3);
site.add_morphism(0, 2);
site.add_morphism(1, 2);
site.add_cover(0, vec![0]);
site.add_cover(1, vec![1]);
site.add_cover(2, vec![0, 1]);
let section_dims = vec![1, 1, 1];
let mut sheaf = SheafOnSite::new(site, section_dims);
sheaf.add_restriction(0, 2, vec![vec![1]]);
sheaf.add_restriction(1, 2, vec![vec![1]]);
assert_eq!(sheaf.total_covers(), 3);
let r = sheaf.restrict(0, 2, &[3]);
assert_eq!(r, Some(vec![3]));
}
#[test]
fn test_sheaf_on_site_condition() {
let mut site = FiniteSite::new(3);
site.add_morphism(0, 2);
site.add_morphism(1, 2);
let section_dims = vec![1, 1, 1];
let mut sheaf = SheafOnSite::new(site, section_dims);
sheaf.add_restriction(0, 2, vec![vec![1]]);
sheaf.add_restriction(1, 2, vec![vec![1]]);
let sections = vec![vec![5i64], vec![5i64]];
assert!(sheaf.check_sheaf_condition(&[0, 1], §ions));
let sections2 = vec![vec![5i64], vec![6i64]];
assert!(!sheaf.check_sheaf_condition(&[0, 1], §ions2));
}
#[test]
fn test_presheaf_sheafification() {
let nodes = vec![
OpenNode::new(0, "U"),
OpenNode::new(1, "V"),
OpenNode::new(2, "UV"),
];
let dims = vec![1, 1, 1];
let mut psh = FinitePresheaf::new(nodes, dims);
psh.add_restriction(0, 2, vec![vec![1]]);
psh.add_restriction(1, 2, vec![vec![1]]);
let mut sheafifier = PresheafSheafification::new(psh);
assert_eq!(sheafifier.iterations, 0);
sheafifier.apply_plus();
assert_eq!(sheafifier.iterations, 1);
sheafifier.apply_plus();
assert_eq!(sheafifier.iterations, 2);
assert_eq!(sheafifier.sheafified_dim(0), 1);
assert_eq!(sheafifier.sheafified_dim(2), 1);
assert!(sheafifier.is_sheaf_for_mv_cover(0, 1, 2));
}
#[test]
fn test_derive_pushforward_kunneth() {
let source = FormalComplex::new(0, vec![1, 2, 1]);
let target = FormalComplex::new(0, vec![1, 1]);
let fiber = FormalComplex::new(0, vec![1, 1]);
let dpf = DerivePushforward::new(source, target, fiber);
let kunneth = dpf.kunneth_cohomology();
assert_eq!(kunneth.cohomology, vec![1, 2, 1]);
assert!(dpf.verify_euler_multiplicativity());
}
#[test]
fn test_perverse_sheaf_filter() {
let supp = FormalComplex::new(-3, vec![1]);
let cosupp = FormalComplex::new(-1, vec![1]);
let filter = PerverseSheafFilter::new(vec![2], vec![supp], vec![cosupp]);
assert!(filter.satisfies_support_condition());
assert!(filter.satisfies_cosupport_condition());
assert!(filter.is_perverse());
assert_eq!(filter.num_perverse_strata(), 1);
}
#[test]
fn test_leray_e2_degeneration() {
let base = vec![1usize, 1];
let higher_direct_images = vec![vec![1, 1]];
let result = leray_e2_degeneration(&base, &higher_direct_images);
assert_eq!(result.len(), 2);
assert_eq!(result[0], 1);
assert_eq!(result[1], 1);
}
#[test]
fn test_extended_axiom_types_wellformed() {
let ty1 = grothendieck_topology_ty();
assert!(matches!(ty1, Expr::Pi(_, _, _, _)));
let ty2 = fukaya_category_ty();
assert!(matches!(ty2, Expr::Pi(_, _, _, _)));
let ty3 = condensed_set_ty();
assert!(matches!(ty3, Expr::Sort(_)));
let ty4 = infinity_topos_ty();
assert!(matches!(ty4, Expr::Sort(_)));
let ty5 = cobordism_hypothesis_ty();
assert!(matches!(ty5, Expr::Pi(_, _, _, _)));
let ty6 = exit_path_category_ty();
assert!(matches!(ty6, Expr::Pi(_, _, _, _)));
}
}
#[cfg(test)]
mod tests_sheaf_ext {
use super::*;
#[test]
fn test_cech_cohomology() {
let mut cd =
CechCohomologyData::new(vec!["U1".to_string(), "U2".to_string()], "constant sheaf Z");
cd.add_section(0, 1.0);
cd.add_cocycle(0, 1, 1.0);
assert!(cd.is_acyclic_cover());
assert_eq!(cd.h0_dimension(), 1);
}
#[test]
fn test_complex_of_sheaves() {
let mut cs = ComplexOfSheaves::new("IC_X").bounded();
cs.add_cohomology_degree(-2);
cs.add_cohomology_degree(0);
assert_eq!(cs.amplitude(), Some((-2, 0)));
assert!(!cs.is_single_sheaf());
assert!(cs.check_perversity_condition(2));
}
#[test]
fn test_leray_spectral_sequence() {
let mut lss = LeraySpectralSequence::new("S^2", "S^3", "Z").set_degenerates_at_e2();
lss.set_e2(0, 0, 1);
lss.set_e2(0, 1, 1);
assert_eq!(lss.total_cohomology_rank(0), 1);
assert_eq!(lss.total_cohomology_rank(1), 1);
}
#[test]
fn test_microsupport() {
let ms = MicrosupportData::new("L_x", "T*_x X")
.lagrangian()
.with_char_variety("char(M)");
assert!(ms.is_lagrangian);
assert!(ms.involutivity_theorem().contains("Lagrangian"));
}
#[test]
fn test_cocycle_condition() {
let mut cd = CechCohomologyData::new(
vec!["U1".to_string(), "U2".to_string(), "U3".to_string()],
"line bundle",
);
cd.add_cocycle(0, 1, 2.0);
cd.add_cocycle(1, 2, 3.0);
cd.add_cocycle(0, 2, 6.0);
assert!(cd.satisfies_cocycle_condition(1e-10));
}
}
#[cfg(test)]
mod tests_sheaf_ext2 {
use super::*;
#[test]
fn test_sheaf_quantization() {
let sq = SheafQuantization::new("T*_x X", "delta_x")
.unique()
.with_local_system_rank(1);
assert!(sq.is_unique);
assert!(sq.quantization_condition().contains("T*_x X"));
}
#[test]
fn test_global_sections() {
let mut gs = GlobalSectionsComputation::new(3, 3, 1);
gs.set_vertex(0, 1.0);
gs.set_vertex(1, 1.0);
gs.set_vertex(2, 1.0);
gs.add_edge_restriction(0, 1, 1.0);
gs.add_edge_restriction(1, 2, 1.0);
assert!(gs.is_global_section(1e-10));
assert_eq!(gs.euler_characteristic(), 1);
}
#[test]
fn test_global_sections_not() {
let mut gs = GlobalSectionsComputation::new(2, 1, 0);
gs.set_vertex(0, 1.0);
gs.set_vertex(1, 2.0);
gs.add_edge_restriction(0, 1, 1.5);
assert!(!gs.is_global_section(1e-10));
}
}