use oxilean_kernel::{BinderInfo, Declaration, Environment, Expr, Level, Name};
use super::types::{
ABCTriple, ArakelovData, ChabautyBound, EllipticCurveArithmetic, FaltingsData, HeightFunction,
MordellWeilData, MordellWeilGroup, NaiveHeightComputer, ProjectiveCurve, SelmerGroupEstimator,
ThueSolver, WeilHeight,
};
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 nat_ty() -> Expr {
cst("Nat")
}
pub fn real_ty() -> Expr {
cst("Real")
}
pub fn int_ty() -> Expr {
cst("Int")
}
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 height_function_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn weil_height_machine_ty() -> Expr {
arrow(type0(), type0())
}
pub fn canonical_height_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn northcott_property_ty() -> Expr {
arrow(type0(), prop())
}
pub fn logarithmic_height_ty() -> Expr {
arrow(nat_ty(), real_ty())
}
pub fn absolute_logarithmic_height_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn height_pairing_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn szpiro_inequality_ty() -> Expr {
prop()
}
pub fn mordell_weil_group_ty() -> Expr {
arrow(type0(), type0())
}
pub fn mordell_weil_theorem_ty() -> Expr {
prop()
}
pub fn mordell_weil_rank_ty() -> Expr {
arrow(type0(), nat_ty())
}
pub fn torsion_subgroup_ty() -> Expr {
arrow(type0(), type0())
}
pub fn weak_mordell_weil_ty() -> Expr {
prop()
}
pub fn descent_procedure_ty() -> Expr {
arrow(type0(), type0())
}
pub fn selmer_group_ty() -> Expr {
arrow(type0(), type0())
}
pub fn shafarevich_tate_group_ty() -> Expr {
arrow(type0(), type0())
}
pub fn faltings_theorem_ty() -> Expr {
prop()
}
pub fn mordell_conjecture_ty() -> Expr {
prop()
}
pub fn curve_genus_ty() -> Expr {
arrow(type0(), nat_ty())
}
pub fn riemann_roch_curve_ty() -> Expr {
prop()
}
pub fn jacobian_variety_ty() -> Expr {
arrow(type0(), type0())
}
pub fn torellis_theorem_ty() -> Expr {
prop()
}
pub fn effective_mordell_ty() -> Expr {
prop()
}
pub fn abc_triple_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), arrow(nat_ty(), prop())))
}
pub fn radical_of_integer_ty() -> Expr {
arrow(nat_ty(), nat_ty())
}
pub fn abc_conjecture_ty() -> Expr {
prop()
}
pub fn abc_quality_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), arrow(nat_ty(), real_ty())))
}
pub fn masser_oesterle_abc_ty() -> Expr {
prop()
}
pub fn abc_implies_fermat_ty() -> Expr {
prop()
}
pub fn langs_conjecture_ty() -> Expr {
prop()
}
pub fn manin_mumford_conjecture_ty() -> Expr {
prop()
}
pub fn raynaud_theorem_ty() -> Expr {
prop()
}
pub fn bogomolov_conjecture_ty() -> Expr {
prop()
}
pub fn equidistribution_ty() -> Expr {
prop()
}
pub fn bombieri_lang_conjecture_ty() -> Expr {
prop()
}
pub fn variety_of_general_type_ty() -> Expr {
arrow(type0(), prop())
}
pub fn kodaira_dimension_ty() -> Expr {
arrow(type0(), int_ty())
}
pub fn zariski_density_ty() -> Expr {
arrow(type0(), arrow(type0(), prop()))
}
pub fn canonical_bundle_ty() -> Expr {
arrow(type0(), type0())
}
pub fn pluricanonical_map_ty() -> Expr {
arrow(type0(), arrow(nat_ty(), type0()))
}
pub fn line_bundle_ty() -> Expr {
arrow(type0(), type0())
}
pub fn ample_line_bundle_ty() -> Expr {
arrow(type0(), prop())
}
pub fn nakai_moishezon_criterion_ty() -> Expr {
prop()
}
pub fn kleiman_criterion_ty() -> Expr {
prop()
}
pub fn seshadri_constant_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn nef_divisor_ty() -> Expr {
arrow(type0(), prop())
}
pub fn big_line_bundle_ty() -> Expr {
arrow(type0(), prop())
}
pub fn volume_of_line_bundle_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn arakelov_divisor_ty() -> Expr {
arrow(type0(), type0())
}
pub fn arithmetic_intersection_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn arakelov_riemann_roch_ty() -> Expr {
prop()
}
pub fn arithmetic_surface_ty() -> Expr {
type0()
}
pub fn greens_function_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn analytic_torsion_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn faltings_height_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn gillet_soule_riemann_roch_ty() -> Expr {
prop()
}
pub fn admissible_metric_ty() -> Expr {
arrow(type0(), prop())
}
pub fn nevanlinna_first_main_thm_ty() -> Expr {
prop()
}
pub fn nevanlinna_second_main_thm_ty() -> Expr {
prop()
}
pub fn nevanlinna_characteristic_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn deficiency_function_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn bloch_ochiai_theorem_ty() -> Expr {
prop()
}
pub fn picard_theorem_ty() -> Expr {
prop()
}
pub fn proximity_function_ty() -> Expr {
arrow(type_0_alias(), real_ty())
}
pub fn type_0_alias() -> Expr {
type0()
}
pub fn counting_function_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn vojta_conjecture_ty() -> Expr {
prop()
}
pub fn diophantine_approximation_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), real_ty()))
}
pub fn roth_theorem_ty() -> Expr {
prop()
}
pub fn neron_tate_height_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn lehmer_conjecture_ty() -> Expr {
prop()
}
pub fn mahler_measure_ty() -> Expr {
arrow(nat_ty(), real_ty())
}
pub fn height_bound_ty() -> Expr {
arrow(type0(), arrow(nat_ty(), prop()))
}
pub fn hasse_principle_ty() -> Expr {
arrow(type0(), prop())
}
pub fn weak_approximation_ty() -> Expr {
arrow(type0(), prop())
}
pub fn strong_approximation_ty() -> Expr {
arrow(type0(), prop())
}
pub fn local_global_principle_ty() -> Expr {
arrow(type0(), prop())
}
pub fn obstruction_to_hasse_ty() -> Expr {
arrow(type0(), type0())
}
pub fn chabauty_coleman_ty() -> Expr {
arrow(type0(), arrow(nat_ty(), prop()))
}
pub fn p_adic_integration_ty() -> Expr {
arrow(type0(), arrow(cst("Complex"), cst("Complex")))
}
pub fn chabauty_bound_value_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), nat_ty()))
}
pub fn twisting_method_ty() -> Expr {
arrow(type0(), arrow(nat_ty(), type0()))
}
pub fn two_descent_ty() -> Expr {
arrow(type0(), type0())
}
pub fn selmer_group_explicit_ty() -> Expr {
arrow(type0(), arrow(nat_ty(), type0()))
}
pub fn visibility_of_selmer_ty() -> Expr {
arrow(type0(), prop())
}
pub fn isogeny_descent_ty() -> Expr {
arrow(type0(), arrow(type0(), type0()))
}
pub fn brauer_group_ty() -> Expr {
arrow(type0(), type0())
}
pub fn brauer_manin_obstruction_ty() -> Expr {
arrow(type0(), prop())
}
pub fn hasse_noether_brauer_ty() -> Expr {
prop()
}
pub fn azumaya_algebra_ty() -> Expr {
arrow(type0(), type0())
}
pub fn vojta_dictionary_ty() -> Expr {
prop()
}
pub fn function_field_analogy_ty() -> Expr {
prop()
}
pub fn mason_stothers_ty() -> Expr {
prop()
}
pub fn baker_method_ty() -> Expr {
arrow(nat_ty(), prop())
}
pub fn thue_equation_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), prop()))
}
pub fn s_unit_equation_ty() -> Expr {
arrow(nat_ty(), prop())
}
pub fn liouville_approximation_ty() -> Expr {
arrow(nat_ty(), real_ty())
}
pub fn subspace_theorem_ty() -> Expr {
prop()
}
pub fn rationally_connected_ty() -> Expr {
arrow(type0(), prop())
}
pub fn bend_and_break_ty() -> Expr {
arrow(type0(), prop())
}
pub fn minimal_model_ty() -> Expr {
arrow(type0(), type0())
}
pub fn fano_variety_ty() -> Expr {
arrow(type0(), prop())
}
pub fn campana_manin_conjecture_ty() -> Expr {
arrow(type0(), prop())
}
pub fn hermitian_line_bundle_arakelov_ty() -> Expr {
arrow(type0(), type0())
}
pub fn arithmetic_chow_group_ty() -> Expr {
arrow(type0(), type0())
}
pub fn zhang_admissible_pairing_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn berkovich_space_ty() -> Expr {
arrow(type0(), type0())
}
pub fn berkovich_analytification_ty() -> Expr {
arrow(type0(), type0())
}
pub fn gaga_non_archimedean_ty() -> Expr {
arrow(type0(), prop())
}
pub fn berkovich_retract_ty() -> Expr {
arrow(type0(), type0())
}
pub fn anabelian_variety_ty() -> Expr {
arrow(type0(), prop())
}
pub fn grothendieck_anabelian_conjecture_ty() -> Expr {
prop()
}
pub fn mochizuki_theorem_ty() -> Expr {
prop()
}
pub fn etale_fundamental_group_ty() -> Expr {
arrow(type0(), type0())
}
pub fn galois_action_ty() -> Expr {
arrow(type0(), type0())
}
pub fn build_diophantine_geometry_env(env: &mut Environment) -> Result<(), String> {
add_axiom(env, "HeightFunction", vec![], height_function_ty())?;
add_axiom(env, "WeilHeightMachine", vec![], weil_height_machine_ty())?;
add_axiom(env, "CanonicalHeight", vec![], canonical_height_ty())?;
add_axiom(env, "NorthcottProperty", vec![], northcott_property_ty())?;
add_axiom(env, "LogarithmicHeight", vec![], logarithmic_height_ty())?;
add_axiom(
env,
"AbsoluteLogarithmicHeight",
vec![],
absolute_logarithmic_height_ty(),
)?;
add_axiom(env, "HeightPairing", vec![], height_pairing_ty())?;
add_axiom(env, "SzpiroInequality", vec![], szpiro_inequality_ty())?;
add_axiom(env, "MordellWeilGroup", vec![], mordell_weil_group_ty())?;
add_axiom(env, "MordellWeilTheorem", vec![], mordell_weil_theorem_ty())?;
add_axiom(env, "MordellWeilRank", vec![], mordell_weil_rank_ty())?;
add_axiom(env, "TorsionSubgroup", vec![], torsion_subgroup_ty())?;
add_axiom(env, "WeakMordellWeil", vec![], weak_mordell_weil_ty())?;
add_axiom(env, "DescentProcedure", vec![], descent_procedure_ty())?;
add_axiom(env, "SelmerGroup", vec![], selmer_group_ty())?;
add_axiom(
env,
"ShafarevichTateGroup",
vec![],
shafarevich_tate_group_ty(),
)?;
add_axiom(env, "FaltingsTheorem", vec![], faltings_theorem_ty())?;
add_axiom(env, "MordellConjecture", vec![], mordell_conjecture_ty())?;
add_axiom(env, "CurveGenus", vec![], curve_genus_ty())?;
add_axiom(env, "RiemannRochCurve", vec![], riemann_roch_curve_ty())?;
add_axiom(env, "JacobianVariety", vec![], jacobian_variety_ty())?;
add_axiom(env, "TorellisTheorem", vec![], torellis_theorem_ty())?;
add_axiom(env, "EffectiveMordell", vec![], effective_mordell_ty())?;
add_axiom(env, "ABCTriple", vec![], abc_triple_ty())?;
add_axiom(env, "RadicalOfInteger", vec![], radical_of_integer_ty())?;
add_axiom(env, "ABCConjecture", vec![], abc_conjecture_ty())?;
add_axiom(env, "ABCQuality", vec![], abc_quality_ty())?;
add_axiom(env, "MasserOesterlaeABC", vec![], masser_oesterle_abc_ty())?;
add_axiom(env, "ABCImpliesFermat", vec![], abc_implies_fermat_ty())?;
add_axiom(env, "LangsConjecture", vec![], langs_conjecture_ty())?;
add_axiom(
env,
"ManinMumfordConjecture",
vec![],
manin_mumford_conjecture_ty(),
)?;
add_axiom(env, "RaynaudTheorem", vec![], raynaud_theorem_ty())?;
add_axiom(
env,
"BogomolovConjecture",
vec![],
bogomolov_conjecture_ty(),
)?;
add_axiom(env, "Equidistribution", vec![], equidistribution_ty())?;
add_axiom(
env,
"BombieriLangConjecture",
vec![],
bombieri_lang_conjecture_ty(),
)?;
add_axiom(
env,
"VarietyOfGeneralType",
vec![],
variety_of_general_type_ty(),
)?;
add_axiom(env, "KodairaDimension", vec![], kodaira_dimension_ty())?;
add_axiom(env, "ZariskiDensity", vec![], zariski_density_ty())?;
add_axiom(env, "CanonicalBundle", vec![], canonical_bundle_ty())?;
add_axiom(env, "PluricanonicalMap", vec![], pluricanonical_map_ty())?;
add_axiom(env, "LineBundle", vec![], line_bundle_ty())?;
add_axiom(env, "AmpleLineBundle", vec![], ample_line_bundle_ty())?;
add_axiom(
env,
"NakaiMoishezonCriterion",
vec![],
nakai_moishezon_criterion_ty(),
)?;
add_axiom(env, "KleimanCriterion", vec![], kleiman_criterion_ty())?;
add_axiom(env, "SeshadriConstant", vec![], seshadri_constant_ty())?;
add_axiom(env, "NefDivisor", vec![], nef_divisor_ty())?;
add_axiom(env, "BigLineBundle", vec![], big_line_bundle_ty())?;
add_axiom(
env,
"VolumeOfLineBundle",
vec![],
volume_of_line_bundle_ty(),
)?;
add_axiom(env, "ArakelovDivisor", vec![], arakelov_divisor_ty())?;
add_axiom(
env,
"ArithmeticIntersection",
vec![],
arithmetic_intersection_ty(),
)?;
add_axiom(
env,
"ArakelovRiemannRoch",
vec![],
arakelov_riemann_roch_ty(),
)?;
add_axiom(env, "ArithmeticSurface", vec![], arithmetic_surface_ty())?;
add_axiom(env, "GreensFunction", vec![], greens_function_ty())?;
add_axiom(env, "AnalyticTorsion", vec![], analytic_torsion_ty())?;
add_axiom(env, "FaltingsHeight", vec![], faltings_height_ty())?;
add_axiom(
env,
"GilletSouleRiemannRoch",
vec![],
gillet_soule_riemann_roch_ty(),
)?;
add_axiom(env, "AdmissibleMetric", vec![], admissible_metric_ty())?;
add_axiom(
env,
"NevanlinnaFirstMainThm",
vec![],
nevanlinna_first_main_thm_ty(),
)?;
add_axiom(
env,
"NevanlinnaSecondMainThm",
vec![],
nevanlinna_second_main_thm_ty(),
)?;
add_axiom(
env,
"NevanlinnaCharacteristic",
vec![],
nevanlinna_characteristic_ty(),
)?;
add_axiom(env, "DeficiencyFunction", vec![], deficiency_function_ty())?;
add_axiom(env, "BlochOchiaiTheorem", vec![], bloch_ochiai_theorem_ty())?;
add_axiom(env, "PicardTheorem", vec![], picard_theorem_ty())?;
add_axiom(env, "ProximityFunction", vec![], proximity_function_ty())?;
add_axiom(env, "CountingFunction", vec![], counting_function_ty())?;
add_axiom(env, "VojtaConjecture", vec![], vojta_conjecture_ty())?;
add_axiom(
env,
"DiophantineApproximation",
vec![],
diophantine_approximation_ty(),
)?;
add_axiom(env, "RothTheorem", vec![], roth_theorem_ty())?;
add_axiom(env, "NeronTateHeight", vec![], neron_tate_height_ty())?;
add_axiom(env, "LehmerConjecture", vec![], lehmer_conjecture_ty())?;
add_axiom(env, "MahlerMeasure", vec![], mahler_measure_ty())?;
add_axiom(env, "HeightBound", vec![], height_bound_ty())?;
add_axiom(env, "HassePrinciple", vec![], hasse_principle_ty())?;
add_axiom(env, "WeakApproximation", vec![], weak_approximation_ty())?;
add_axiom(
env,
"StrongApproximation",
vec![],
strong_approximation_ty(),
)?;
add_axiom(
env,
"LocalGlobalPrinciple",
vec![],
local_global_principle_ty(),
)?;
add_axiom(env, "ObstructionToHasse", vec![], obstruction_to_hasse_ty())?;
add_axiom(env, "ChabautyColeman", vec![], chabauty_coleman_ty())?;
add_axiom(env, "PAdicIntegration", vec![], p_adic_integration_ty())?;
add_axiom(env, "ChabautyBoundValue", vec![], chabauty_bound_value_ty())?;
add_axiom(env, "TwistingMethod", vec![], twisting_method_ty())?;
add_axiom(env, "TwoDescent", vec![], two_descent_ty())?;
add_axiom(
env,
"SelmerGroupExplicit",
vec![],
selmer_group_explicit_ty(),
)?;
add_axiom(env, "VisibilityOfSelmer", vec![], visibility_of_selmer_ty())?;
add_axiom(env, "IsogenyDescent", vec![], isogeny_descent_ty())?;
add_axiom(env, "BrauerGroup", vec![], brauer_group_ty())?;
add_axiom(
env,
"BrauerManinObstruction",
vec![],
brauer_manin_obstruction_ty(),
)?;
add_axiom(env, "HasseNoetherBrauer", vec![], hasse_noether_brauer_ty())?;
add_axiom(env, "AzumayaAlgebra", vec![], azumaya_algebra_ty())?;
add_axiom(env, "VojtaDictionary", vec![], vojta_dictionary_ty())?;
add_axiom(
env,
"FunctionFieldAnalogy",
vec![],
function_field_analogy_ty(),
)?;
add_axiom(env, "MasonStothers", vec![], mason_stothers_ty())?;
add_axiom(env, "BakerMethod", vec![], baker_method_ty())?;
add_axiom(env, "ThueEquation", vec![], thue_equation_ty())?;
add_axiom(env, "SUnitEquation", vec![], s_unit_equation_ty())?;
add_axiom(
env,
"LiouvilleApproximation",
vec![],
liouville_approximation_ty(),
)?;
add_axiom(env, "SubspaceTheorem", vec![], subspace_theorem_ty())?;
add_axiom(
env,
"RationallyConnected",
vec![],
rationally_connected_ty(),
)?;
add_axiom(env, "BendAndBreak", vec![], bend_and_break_ty())?;
add_axiom(env, "MinimalModel", vec![], minimal_model_ty())?;
add_axiom(env, "FanoVariety", vec![], fano_variety_ty())?;
add_axiom(
env,
"CampanaManinConjecture",
vec![],
campana_manin_conjecture_ty(),
)?;
add_axiom(
env,
"HermitianLineBundleArakelov",
vec![],
hermitian_line_bundle_arakelov_ty(),
)?;
add_axiom(
env,
"ArithmeticChowGroup",
vec![],
arithmetic_chow_group_ty(),
)?;
add_axiom(
env,
"ZhangAdmissiblePairing",
vec![],
zhang_admissible_pairing_ty(),
)?;
add_axiom(env, "BerkovichSpace", vec![], berkovich_space_ty())?;
add_axiom(
env,
"BerkovichAnalytification",
vec![],
berkovich_analytification_ty(),
)?;
add_axiom(
env,
"GAGA_NonArchimedean",
vec![],
gaga_non_archimedean_ty(),
)?;
add_axiom(env, "BerkovichRetract", vec![], berkovich_retract_ty())?;
add_axiom(env, "AnabelianVariety", vec![], anabelian_variety_ty())?;
add_axiom(
env,
"GrothendieckAnabelianConjecture",
vec![],
grothendieck_anabelian_conjecture_ty(),
)?;
add_axiom(env, "MochizukiTheorem", vec![], mochizuki_theorem_ty())?;
add_axiom(
env,
"EtaleFundamentalGroup",
vec![],
etale_fundamental_group_ty(),
)?;
add_axiom(env, "GaloisAction", vec![], galois_action_ty())?;
Ok(())
}
pub fn gcd(mut a: u64, mut b: u64) -> u64 {
while b != 0 {
let t = b;
b = a % b;
a = t;
}
a
}
pub fn radical(mut n: u64) -> u64 {
if n == 0 {
return 0;
}
let mut result = 1u64;
let mut d = 2u64;
while d * d <= n {
if n % d == 0 {
result *= d;
while n % d == 0 {
n /= d;
}
}
d += 1;
}
if n > 1 {
result *= n;
}
result
}
#[cfg(test)]
mod tests {
use super::*;
fn test_env() -> Environment {
let mut env = Environment::new();
build_diophantine_geometry_env(&mut env).expect("build_diophantine_geometry_env failed");
env
}
#[test]
fn test_height_functions_registered() {
let env = test_env();
assert!(env.get(&Name::str("HeightFunction")).is_some());
assert!(env.get(&Name::str("WeilHeightMachine")).is_some());
assert!(env.get(&Name::str("CanonicalHeight")).is_some());
assert!(env.get(&Name::str("NorthcottProperty")).is_some());
assert!(env.get(&Name::str("LogarithmicHeight")).is_some());
assert!(env.get(&Name::str("AbsoluteLogarithmicHeight")).is_some());
assert!(env.get(&Name::str("HeightPairing")).is_some());
assert!(env.get(&Name::str("SzpiroInequality")).is_some());
}
#[test]
fn test_mordell_weil_registered() {
let env = test_env();
assert!(env.get(&Name::str("MordellWeilGroup")).is_some());
assert!(env.get(&Name::str("MordellWeilTheorem")).is_some());
assert!(env.get(&Name::str("MordellWeilRank")).is_some());
assert!(env.get(&Name::str("SelmerGroup")).is_some());
assert!(env.get(&Name::str("ShafarevichTateGroup")).is_some());
assert!(env.get(&Name::str("WeakMordellWeil")).is_some());
}
#[test]
fn test_faltings_registered() {
let env = test_env();
assert!(env.get(&Name::str("FaltingsTheorem")).is_some());
assert!(env.get(&Name::str("MordellConjecture")).is_some());
assert!(env.get(&Name::str("CurveGenus")).is_some());
assert!(env.get(&Name::str("JacobianVariety")).is_some());
assert!(env.get(&Name::str("TorellisTheorem")).is_some());
}
#[test]
fn test_abc_conjecture_registered() {
let env = test_env();
assert!(env.get(&Name::str("ABCTriple")).is_some());
assert!(env.get(&Name::str("RadicalOfInteger")).is_some());
assert!(env.get(&Name::str("ABCConjecture")).is_some());
assert!(env.get(&Name::str("ABCQuality")).is_some());
}
#[test]
fn test_arakelov_and_nevanlinna_registered() {
let env = test_env();
assert!(env.get(&Name::str("ArakelovDivisor")).is_some());
assert!(env.get(&Name::str("ArithmeticIntersection")).is_some());
assert!(env.get(&Name::str("FaltingsHeight")).is_some());
assert!(env.get(&Name::str("NevanlinnaFirstMainThm")).is_some());
assert!(env.get(&Name::str("NevanlinnaSecondMainThm")).is_some());
assert!(env.get(&Name::str("VojtaConjecture")).is_some());
assert!(env.get(&Name::str("RothTheorem")).is_some());
}
#[test]
fn test_weil_height_computation() {
let h = WeilHeight::new(vec![3, -4, 0, 5]);
assert_eq!(h.naive_height(), 5);
assert!((h.logarithmic_height() - (5.0_f64).ln()).abs() < 1e-10);
assert!(h.northcott_property_holds());
}
#[test]
fn test_mordell_weil_group_structure() {
let mw = MordellWeilGroup::new(2, vec![2, 6]);
assert_eq!(mw.rank, 2);
assert_eq!(mw.torsion_size(), 12);
assert!(!mw.is_finite());
assert_eq!(mw.num_generators(), 4);
let finite = MordellWeilGroup::new(0, vec![5]);
assert!(finite.is_finite());
assert_eq!(finite.torsion_size(), 5);
}
#[test]
fn test_curve_genus_and_faltings() {
let genus0 = ProjectiveCurve::new(0, "P^1");
let genus1 = ProjectiveCurve::new(1, "Elliptic curve");
let genus2 = ProjectiveCurve::new(2, "Genus-2 curve");
assert!(!genus0.has_finitely_many_rational_points());
assert!(!genus1.has_finitely_many_rational_points());
assert!(genus2.has_finitely_many_rational_points());
assert!(genus0.is_rational());
assert!(genus1.is_elliptic());
assert_eq!(genus2.riemann_roch_dim(4), 3);
}
#[test]
fn test_heights_extended_registered() {
let env = test_env();
assert!(env.get(&Name::str("NeronTateHeight")).is_some());
assert!(env.get(&Name::str("LehmerConjecture")).is_some());
assert!(env.get(&Name::str("MahlerMeasure")).is_some());
assert!(env.get(&Name::str("HeightBound")).is_some());
}
#[test]
fn test_hasse_principle_registered() {
let env = test_env();
assert!(env.get(&Name::str("HassePrinciple")).is_some());
assert!(env.get(&Name::str("WeakApproximation")).is_some());
assert!(env.get(&Name::str("StrongApproximation")).is_some());
assert!(env.get(&Name::str("LocalGlobalPrinciple")).is_some());
assert!(env.get(&Name::str("ObstructionToHasse")).is_some());
}
#[test]
fn test_chabauty_coleman_registered() {
let env = test_env();
assert!(env.get(&Name::str("ChabautyColeman")).is_some());
assert!(env.get(&Name::str("PAdicIntegration")).is_some());
assert!(env.get(&Name::str("ChabautyBoundValue")).is_some());
assert!(env.get(&Name::str("TwistingMethod")).is_some());
}
#[test]
fn test_descent_methods_registered() {
let env = test_env();
assert!(env.get(&Name::str("TwoDescent")).is_some());
assert!(env.get(&Name::str("SelmerGroupExplicit")).is_some());
assert!(env.get(&Name::str("VisibilityOfSelmer")).is_some());
assert!(env.get(&Name::str("IsogenyDescent")).is_some());
}
#[test]
fn test_brauer_manin_registered() {
let env = test_env();
assert!(env.get(&Name::str("BrauerGroup")).is_some());
assert!(env.get(&Name::str("BrauerManinObstruction")).is_some());
assert!(env.get(&Name::str("HasseNoetherBrauer")).is_some());
assert!(env.get(&Name::str("AzumayaAlgebra")).is_some());
}
#[test]
fn test_vojta_function_field_registered() {
let env = test_env();
assert!(env.get(&Name::str("VojtaDictionary")).is_some());
assert!(env.get(&Name::str("FunctionFieldAnalogy")).is_some());
assert!(env.get(&Name::str("MasonStothers")).is_some());
}
#[test]
fn test_integral_points_registered() {
let env = test_env();
assert!(env.get(&Name::str("BakerMethod")).is_some());
assert!(env.get(&Name::str("ThueEquation")).is_some());
assert!(env.get(&Name::str("SUnitEquation")).is_some());
assert!(env.get(&Name::str("LiouvilleApproximation")).is_some());
assert!(env.get(&Name::str("SubspaceTheorem")).is_some());
}
#[test]
fn test_mori_theory_registered() {
let env = test_env();
assert!(env.get(&Name::str("RationallyConnected")).is_some());
assert!(env.get(&Name::str("BendAndBreak")).is_some());
assert!(env.get(&Name::str("MinimalModel")).is_some());
assert!(env.get(&Name::str("FanoVariety")).is_some());
assert!(env.get(&Name::str("CampanaManinConjecture")).is_some());
}
#[test]
fn test_arakelov_extended_registered() {
let env = test_env();
assert!(env.get(&Name::str("HermitianLineBundleArakelov")).is_some());
assert!(env.get(&Name::str("ArithmeticChowGroup")).is_some());
assert!(env.get(&Name::str("ZhangAdmissiblePairing")).is_some());
}
#[test]
fn test_berkovich_registered() {
let env = test_env();
assert!(env.get(&Name::str("BerkovichSpace")).is_some());
assert!(env.get(&Name::str("BerkovichAnalytification")).is_some());
assert!(env.get(&Name::str("GAGA_NonArchimedean")).is_some());
assert!(env.get(&Name::str("BerkovichRetract")).is_some());
}
#[test]
fn test_anabelian_registered() {
let env = test_env();
assert!(env.get(&Name::str("AnabelianVariety")).is_some());
assert!(env
.get(&Name::str("GrothendieckAnabelianConjecture"))
.is_some());
assert!(env.get(&Name::str("MochizukiTheorem")).is_some());
assert!(env.get(&Name::str("EtaleFundamentalGroup")).is_some());
assert!(env.get(&Name::str("GaloisAction")).is_some());
}
#[test]
fn test_naive_height_computer_rust() {
let nh = NaiveHeightComputer::new(vec![3, -4, 5]);
assert_eq!(nh.naive_height(), 5);
assert_eq!(nh.number_of_coords(), 3);
assert!(nh.log_height() > 0.0);
}
#[test]
fn test_chabauty_bound_rust() {
let cb = ChabautyBound::new(3, 1, 5);
assert!(cb.is_applicable());
assert!(cb.point_bound() > 0);
}
#[test]
fn test_thue_solver_rust() {
let ts = ThueSolver::new(vec![1, 0, 0, -2], 6);
assert_eq!(ts.degree(), 3);
let sols = ts.small_solutions(5);
assert!(sols.len() <= 22);
}
#[test]
fn test_selmer_group_estimator_rust() {
let se = SelmerGroupEstimator::new(1, 2);
let bound = se.rank_upper_bound();
assert_eq!(bound, 4);
assert!(!se.is_trivially_trivial());
let trivial = SelmerGroupEstimator::new(0, 0);
assert!(trivial.is_trivially_trivial());
assert_eq!(trivial.rank_upper_bound(), 1);
}
}
#[cfg(test)]
mod tests_diophantine_ext {
use super::*;
#[test]
fn test_height_function() {
let h = HeightFunction::new("Weil height", "Q").with_northcott();
assert!(h.northcott);
let wh = HeightFunction::weil_height_rational(3, 4);
assert!((wh - 4.0f64.ln()).abs() < 1e-10);
let ph = HeightFunction::projective_height(&[3, -5, 2]);
assert!((ph - 5.0).abs() < 1e-10);
}
#[test]
fn test_elliptic_curve_arithmetic() {
let mut ec = EllipticCurveArithmetic::new(-1, 0);
assert!(ec.is_smooth());
assert!(ec.is_on_curve(0, 0));
assert!(ec.is_on_curve(1, 0));
ec.add_rational_point(0, 0);
assert_eq!(ec.rational_points.len(), 1);
}
#[test]
fn test_elliptic_j_invariant() {
let ec = EllipticCurveArithmetic::new(1, 0);
let j = ec.j_invariant().expect("j_invariant should succeed");
assert!((j - (-1728.0)).abs() < 1.0, "j should be -1728, got {j}");
}
#[test]
fn test_mordell_weil() {
let mut mw = MordellWeilData::new("E", "Q")
.with_rank(2)
.with_torsion("Z/2Z");
mw.add_generator("P1");
mw.add_generator("P2");
assert_eq!(mw.mw_rank(), 2);
assert!(mw.structure_theorem().contains("Z^2"));
}
#[test]
fn test_faltings() {
let f = FaltingsData::new("C_4", 4).with_point_count(5);
assert!(f.applies());
assert!(f.finitely_many);
assert!(f.faltings_statement().contains("finitely many"));
let g1 = FaltingsData::new("E", 1);
assert!(!g1.applies());
}
}
#[cfg(test)]
mod tests_diophantine_ext2 {
use super::*;
#[test]
fn test_arakelov_data() {
let mut ad = ArakelovData::new("X/Z").with_arith_degree(2.5);
ad.add_green_value(0.0, 1.0);
ad.add_green_value(1.0, 0.5);
assert!((ad.faltings_height_estimate() - 1.25).abs() < 1e-10);
assert!(ad.noether_formula().contains("Noether"));
}
#[test]
fn test_double_point() {
let ec = EllipticCurveArithmetic::new(-1, 0);
let res = ec.double_point(0, 0);
assert!(res.is_none());
let ec2 = EllipticCurveArithmetic::new(-5, 4);
let res2 = ec2.double_point(1, 0);
assert!(res2.is_none());
}
}