use oxilean_kernel::{BinderInfo, Declaration, Environment, Expr, Level, Name};
use super::types::{
BRSTData, BetaFunctionRG, BrstComplex, ConformalFieldTheory2D, CorrelationFunctionLattice,
FeynmanDiagram, FeynmanDiagramEvaluator, FiniteFockSpace, KleinGordonField, OpeTable,
PathIntegralData, QftComplex, ScatteringAmplitude, VirasoroCommutator, YangMillsTheory,
};
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 real_ty() -> Expr {
cst("Real")
}
pub fn nat_ty() -> Expr {
cst("Nat")
}
pub fn int_ty() -> Expr {
cst("Int")
}
pub fn complex_ty() -> Expr {
cst("Complex")
}
pub fn list_ty(t: Expr) -> Expr {
app(cst("List"), t)
}
pub fn fock_space_ty() -> Expr {
type0()
}
pub fn fock_state_ty() -> Expr {
arrow(cst("FockSpace"), type0())
}
pub fn occupation_number_ty() -> Expr {
arrow(cst("Mode"), nat_ty())
}
pub fn creation_op_ty() -> Expr {
arrow(cst("Mode"), arrow(cst("FockSpace"), cst("FockSpace")))
}
pub fn annihilation_op_ty() -> Expr {
arrow(cst("Mode"), arrow(cst("FockSpace"), cst("FockSpace")))
}
pub fn number_op_ty() -> Expr {
arrow(cst("Mode"), arrow(cst("FockSpace"), cst("FockSpace")))
}
pub fn ccr_ty() -> Expr {
arrow(cst("Mode"), arrow(cst("Mode"), prop()))
}
pub fn car_ty() -> Expr {
arrow(cst("Mode"), arrow(cst("Mode"), prop()))
}
pub fn vacuum_state_ty() -> Expr {
cst("FockSpace")
}
pub fn annihilates_vacuum_ty() -> Expr {
arrow(cst("Mode"), prop())
}
pub fn scalar_field_ty() -> Expr {
arrow(cst("Spacetime"), real_ty())
}
pub fn klein_gordon_eq_ty() -> Expr {
arrow(arrow(cst("Spacetime"), real_ty()), arrow(real_ty(), prop()))
}
pub fn scalar_qft_lagrangian_ty() -> Expr {
arrow(arrow(cst("Spacetime"), real_ty()), real_ty())
}
pub fn momentum_mode_ty() -> Expr {
arrow(cst("FourMomentum"), cst("Mode"))
}
pub fn field_expansion_ty() -> Expr {
arrow(arrow(cst("Spacetime"), real_ty()), prop())
}
pub fn propagator_ty() -> Expr {
arrow(cst("Spacetime"), arrow(cst("Spacetime"), complex_ty()))
}
pub fn time_ordering_ty() -> Expr {
arrow(cst("FockSpace"), arrow(cst("FockSpace"), cst("FockSpace")))
}
pub fn path_integral_ty() -> Expr {
arrow(
arrow(arrow(cst("Spacetime"), real_ty()), real_ty()),
complex_ty(),
)
}
pub fn generating_functional_ty() -> Expr {
arrow(arrow(cst("Spacetime"), real_ty()), complex_ty())
}
pub fn connected_green_fn_ty() -> Expr {
arrow(nat_ty(), arrow(list_ty(cst("Spacetime")), complex_ty()))
}
pub fn lattice_path_integral_ty() -> Expr {
arrow(nat_ty(), arrow(real_ty(), complex_ty()))
}
pub fn wick_rotation_ty() -> Expr {
arrow(cst("Spacetime"), cst("Spacetime"))
}
pub fn euclidean_action_ty() -> Expr {
arrow(arrow(cst("Spacetime"), real_ty()), real_ty())
}
pub fn feynman_diagram_ty() -> Expr {
type0()
}
pub fn external_leg_ty() -> Expr {
arrow(cst("FeynmanDiagram"), arrow(cst("Mode"), prop()))
}
pub fn internal_vertex_ty() -> Expr {
arrow(cst("FeynmanDiagram"), arrow(cst("Spacetime"), prop()))
}
pub fn propagator_edge_ty() -> Expr {
arrow(
cst("FeynmanDiagram"),
arrow(cst("Spacetime"), arrow(cst("Spacetime"), prop())),
)
}
pub fn symmetry_factor_ty() -> Expr {
arrow(cst("FeynmanDiagram"), nat_ty())
}
pub fn diagram_amplitude_ty() -> Expr {
arrow(cst("FeynmanDiagram"), complex_ty())
}
pub fn loop_order_ty() -> Expr {
arrow(cst("FeynmanDiagram"), nat_ty())
}
pub fn uv_divergence_ty() -> Expr {
arrow(cst("FeynmanDiagram"), prop())
}
pub fn regularized_amplitude_ty() -> Expr {
arrow(cst("FeynmanDiagram"), arrow(real_ty(), complex_ty()))
}
pub fn counter_term_ty() -> Expr {
arrow(
arrow(cst("Spacetime"), real_ty()),
arrow(cst("Spacetime"), real_ty()),
)
}
pub fn renormalization_group_ty() -> Expr {
arrow(real_ty(), real_ty())
}
pub fn beta_function_ty() -> Expr {
arrow(real_ty(), real_ty())
}
pub fn asymptotic_freedom_ty() -> Expr {
arrow(arrow(real_ty(), real_ty()), prop())
}
pub fn wilsonian_eft_ty() -> Expr {
arrow(real_ty(), type0())
}
pub fn ghost_field_ty() -> Expr {
arrow(cst("Spacetime"), cst("GrassmannAlgebra"))
}
pub fn brst_operator_ty() -> Expr {
arrow(cst("FockSpace"), cst("FockSpace"))
}
pub fn brst_nilpotent_ty() -> Expr {
arrow(arrow(cst("FockSpace"), cst("FockSpace")), prop())
}
pub fn brst_cohomology_ty() -> Expr {
arrow(arrow(cst("FockSpace"), cst("FockSpace")), type0())
}
pub fn gauge_fixing_ty() -> Expr {
arrow(cst("GaugeField"), arrow(cst("FeynmanDiagram"), prop()))
}
pub fn faddeev_popov_det_ty() -> Expr {
arrow(cst("GaugeField"), complex_ty())
}
pub fn gauge_group_ty() -> Expr {
type0()
}
pub fn gauge_field_ty() -> Expr {
arrow(cst("Spacetime"), cst("LieAlgebra"))
}
pub fn field_strength_ty() -> Expr {
arrow(
arrow(cst("Spacetime"), cst("LieAlgebra")),
arrow(cst("Spacetime"), arrow(cst("Spacetime"), cst("LieAlgebra"))),
)
}
pub fn yang_mills_lagrangian_ty() -> Expr {
arrow(arrow(cst("Spacetime"), cst("LieAlgebra")), real_ty())
}
pub fn gauge_transformation_ty() -> Expr {
arrow(
cst("GaugeGroup"),
arrow(
arrow(cst("Spacetime"), cst("LieAlgebra")),
arrow(cst("Spacetime"), cst("LieAlgebra")),
),
)
}
pub fn gauge_invariant_ty() -> Expr {
arrow(
arrow(arrow(cst("Spacetime"), cst("LieAlgebra")), prop()),
prop(),
)
}
pub fn wilson_line_ty() -> Expr {
arrow(
arrow(cst("Spacetime"), cst("LieAlgebra")),
arrow(cst("Path"), complex_ty()),
)
}
pub fn field_symmetry_ty() -> Expr {
arrow(
arrow(cst("Spacetime"), real_ty()),
arrow(cst("Spacetime"), real_ty()),
)
}
pub fn conserved_current_ty() -> Expr {
arrow(
arrow(
arrow(cst("Spacetime"), real_ty()),
arrow(cst("Spacetime"), real_ty()),
),
arrow(cst("Spacetime"), cst("FourVector")),
)
}
pub fn current_conservation_ty() -> Expr {
arrow(
arrow(
arrow(
arrow(cst("Spacetime"), real_ty()),
arrow(cst("Spacetime"), real_ty()),
),
arrow(cst("Spacetime"), cst("FourVector")),
),
prop(),
)
}
pub fn noether_charge_ty() -> Expr {
arrow(arrow(cst("Spacetime"), cst("FourVector")), real_ty())
}
pub fn noether_theorem_ty() -> Expr {
arrow(
arrow(
arrow(cst("Spacetime"), real_ty()),
arrow(cst("Spacetime"), real_ty()),
),
arrow(arrow(cst("Spacetime"), cst("FourVector")), prop()),
)
}
pub fn energy_momentum_tensor_ty() -> Expr {
arrow(
arrow(cst("Spacetime"), real_ty()),
arrow(cst("Spacetime"), arrow(cst("Spacetime"), real_ty())),
)
}
pub fn ward_identity_ty() -> Expr {
arrow(arrow(cst("Spacetime"), cst("LieAlgebra")), prop())
}
pub fn vertex_function_ty() -> Expr {
arrow(nat_ty(), arrow(list_ty(cst("Spacetime")), complex_ty()))
}
pub fn slavnov_taylor_identity_ty() -> Expr {
arrow(
arrow(cst("Spacetime"), cst("LieAlgebra")),
arrow(arrow(cst("FockSpace"), cst("FockSpace")), prop()),
)
}
pub fn lsz_reduction_ty() -> Expr {
arrow(
arrow(nat_ty(), arrow(list_ty(cst("Spacetime")), complex_ty())),
arrow(cst("SMatrix"), prop()),
)
}
pub fn charge_conjugation_ty() -> Expr {
arrow(cst("FockSpace"), cst("FockSpace"))
}
pub fn parity_transformation_ty() -> Expr {
arrow(cst("FockSpace"), cst("FockSpace"))
}
pub fn time_reversal_ty() -> Expr {
arrow(cst("FockSpace"), cst("FockSpace"))
}
pub fn cpt_operator_ty() -> Expr {
arrow(cst("FockSpace"), cst("FockSpace"))
}
pub fn cpt_theorem_ty() -> Expr {
arrow(arrow(cst("FockSpace"), cst("FockSpace")), prop())
}
pub fn spin_statistics_theorem_ty() -> Expr {
arrow(nat_ty(), prop())
}
pub fn lorentz_covariance_ty() -> Expr {
arrow(arrow(cst("FockSpace"), cst("FockSpace")), prop())
}
pub fn wightman_field_ty() -> Expr {
arrow(cst("Spacetime"), cst("HilbertOp"))
}
pub fn poincare_covariance_ty() -> Expr {
arrow(arrow(cst("Spacetime"), cst("HilbertOp")), prop())
}
pub fn wightman_locality_ty() -> Expr {
arrow(
arrow(cst("Spacetime"), cst("HilbertOp")),
arrow(arrow(cst("Spacetime"), cst("HilbertOp")), prop()),
)
}
pub fn spectrum_condition_ty() -> Expr {
prop()
}
pub fn wightman_positivity_ty() -> Expr {
arrow(arrow(cst("Spacetime"), cst("HilbertOp")), prop())
}
pub fn wightman_distribution_ty() -> Expr {
arrow(list_ty(cst("Spacetime")), complex_ty())
}
pub fn reconstruction_theorem_ty() -> Expr {
arrow(
arrow(list_ty(cst("Spacetime")), complex_ty()),
arrow(arrow(cst("Spacetime"), cst("HilbertOp")), prop()),
)
}
pub fn local_algebra_ty() -> Expr {
arrow(cst("SpacetimeRegion"), cst("CStarAlgebra"))
}
pub fn isotony_ty() -> Expr {
arrow(arrow(cst("SpacetimeRegion"), cst("CStarAlgebra")), prop())
}
pub fn haag_kastler_causality_ty() -> Expr {
arrow(arrow(cst("SpacetimeRegion"), cst("CStarAlgebra")), prop())
}
pub fn haag_duality_ty() -> Expr {
arrow(arrow(cst("SpacetimeRegion"), cst("CStarAlgebra")), prop())
}
pub fn reeh_schlieder_theorem_ty() -> Expr {
arrow(arrow(cst("SpacetimeRegion"), cst("CStarAlgebra")), prop())
}
pub fn forest_formula_ty() -> Expr {
arrow(cst("FeynmanDiagram"), complex_ty())
}
pub fn subtraction_operator_ty() -> Expr {
arrow(cst("FeynmanDiagram"), arrow(cst("FeynmanDiagram"), prop()))
}
pub fn bphz_renormalized_ty() -> Expr {
arrow(cst("FeynmanDiagram"), complex_ty())
}
pub fn dim_reg_amplitude_ty() -> Expr {
arrow(cst("FeynmanDiagram"), arrow(real_ty(), complex_ty()))
}
pub fn epsilon_pole_ty() -> Expr {
arrow(cst("FeynmanDiagram"), arrow(nat_ty(), complex_ty()))
}
pub fn msbar_scheme_ty() -> Expr {
arrow(cst("FeynmanDiagram"), complex_ty())
}
pub fn rg_fixed_point_ty() -> Expr {
arrow(arrow(real_ty(), real_ty()), arrow(real_ty(), prop()))
}
pub fn universality_class_ty() -> Expr {
arrow(arrow(real_ty(), real_ty()), type0())
}
pub fn critical_exponent_ty() -> Expr {
arrow(type0(), real_ty())
}
pub fn schwinger_dyson_eq_ty() -> Expr {
arrow(
arrow(nat_ty(), arrow(list_ty(cst("Spacetime")), complex_ty())),
prop(),
)
}
pub fn self_energy_fn_ty() -> Expr {
arrow(cst("Spacetime"), complex_ty())
}
pub fn dressed_propagator_ty() -> Expr {
arrow(
arrow(cst("Spacetime"), complex_ty()),
arrow(cst("Spacetime"), arrow(cst("Spacetime"), complex_ty())),
)
}
pub fn in_lsz_state_ty() -> Expr {
arrow(cst("Mode"), arrow(cst("FockSpace"), prop()))
}
pub fn out_lsz_state_ty() -> Expr {
arrow(cst("Mode"), arrow(cst("FockSpace"), prop()))
}
pub fn factorization_theorem_ty() -> Expr {
arrow(cst("FeynmanDiagram"), prop())
}
pub fn infrared_safe_ty() -> Expr {
arrow(cst("Observable"), prop())
}
pub fn ope_coefficient_ty() -> Expr {
arrow(
arrow(cst("Spacetime"), cst("HilbertOp")),
arrow(
arrow(cst("Spacetime"), cst("HilbertOp")),
arrow(
arrow(cst("Spacetime"), cst("HilbertOp")),
arrow(real_ty(), complex_ty()),
),
),
)
}
pub fn operator_product_expansion_ty() -> Expr {
arrow(
arrow(cst("Spacetime"), cst("HilbertOp")),
arrow(arrow(cst("Spacetime"), cst("HilbertOp")), prop()),
)
}
pub fn conformal_primary_ty() -> Expr {
arrow(
arrow(cst("Spacetime"), cst("HilbertOp")),
arrow(real_ty(), prop()),
)
}
pub fn virasoro_generator_ty() -> Expr {
arrow(int_ty(), arrow(cst("FockSpace"), cst("FockSpace")))
}
pub fn virasoro_algebra_relation_ty() -> Expr {
arrow(int_ty(), arrow(int_ty(), arrow(real_ty(), prop())))
}
pub fn central_charge_ty() -> Expr {
real_ty()
}
pub fn c_theorem_ty() -> Expr {
arrow(real_ty(), arrow(real_ty(), prop()))
}
pub fn modular_invariance_ty() -> Expr {
arrow(arrow(complex_ty(), complex_ty()), prop())
}
pub fn conformal_bootstrap_ty() -> Expr {
arrow(real_ty(), prop())
}
pub fn chern_simons_action_ty() -> Expr {
arrow(
arrow(cst("Spacetime"), cst("LieAlgebra")),
arrow(real_ty(), real_ty()),
)
}
pub fn bf_action_ty() -> Expr {
arrow(
arrow(cst("Spacetime"), cst("LieAlgebra")),
arrow(arrow(cst("Spacetime"), cst("LieAlgebra")), real_ty()),
)
}
pub fn tqft_functor_ty() -> Expr {
arrow(arrow(cst("SpacetimeRegion"), cst("CStarAlgebra")), prop())
}
pub fn linking_number_ty() -> Expr {
arrow(cst("Path"), arrow(cst("Path"), int_ty()))
}
pub fn jones_polynomial_ty() -> Expr {
arrow(cst("Path"), arrow(int_ty(), complex_ty()))
}
pub fn lattice_action_ty() -> Expr {
arrow(nat_ty(), arrow(real_ty(), real_ty()))
}
pub fn lattice_green_fn_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), arrow(real_ty(), complex_ty())))
}
pub fn instanton_solution_ty() -> Expr {
arrow(
arrow(cst("Spacetime"), cst("LieAlgebra")),
arrow(nat_ty(), prop()),
)
}
pub fn instanton_action_ty() -> Expr {
arrow(nat_ty(), real_ty())
}
pub fn seiberg_witten_curve_ty() -> Expr {
arrow(real_ty(), arrow(complex_ty(), prop()))
}
pub fn prepotential_sw_ty() -> Expr {
arrow(real_ty(), complex_ty())
}
pub fn build_quantum_field_theory_env() -> Environment {
let mut env = Environment::new();
let axioms: &[(&str, Expr)] = &[
("Mode", type0()),
("Spacetime", type0()),
("FourMomentum", type0()),
("FourVector", type0()),
("LieAlgebra", type0()),
("GaugeField", type0()),
("GaugeGroup", type0()),
("GrassmannAlgebra", type0()),
("SMatrix", type0()),
("Path", type0()),
("HilbertOp", type0()),
("SpacetimeRegion", type0()),
("CStarAlgebra", type0()),
("Observable", type0()),
("FockSpace", fock_space_ty()),
("FockState", fock_state_ty()),
("OccupationNumber", occupation_number_ty()),
("CreationOp", creation_op_ty()),
("AnnihilationOp", annihilation_op_ty()),
("NumberOp", number_op_ty()),
("CanonicalCommutationRelation", ccr_ty()),
("CanonicalAnticommutationRelation", car_ty()),
("VacuumState", vacuum_state_ty()),
("AnnihilatesVacuum", annihilates_vacuum_ty()),
("ScalarField", scalar_field_ty()),
("KleinGordonEq", klein_gordon_eq_ty()),
("ScalarQFTLagrangian", scalar_qft_lagrangian_ty()),
("MomentumMode", momentum_mode_ty()),
("FieldExpansion", field_expansion_ty()),
("FeynmanPropagator", propagator_ty()),
("TimeOrdering", time_ordering_ty()),
("PathIntegral", path_integral_ty()),
("GeneratingFunctional", generating_functional_ty()),
("ConnectedGreenFn", connected_green_fn_ty()),
("LatticePathIntegral", lattice_path_integral_ty()),
("WickRotation", wick_rotation_ty()),
("EuclideanAction", euclidean_action_ty()),
("FeynmanDiagram", feynman_diagram_ty()),
("ExternalLeg", external_leg_ty()),
("InternalVertex", internal_vertex_ty()),
("PropagatorEdge", propagator_edge_ty()),
("SymmetryFactor", symmetry_factor_ty()),
("DiagramAmplitude", diagram_amplitude_ty()),
("LoopOrder", loop_order_ty()),
("UVDivergence", uv_divergence_ty()),
("RegularizedAmplitude", regularized_amplitude_ty()),
("CounterTerm", counter_term_ty()),
("RenormalizationGroup", renormalization_group_ty()),
("BetaFunction", beta_function_ty()),
("AsymptoticFreedom", asymptotic_freedom_ty()),
("WilsonianEFT", wilsonian_eft_ty()),
("GhostField", ghost_field_ty()),
("BRSTOperator", brst_operator_ty()),
("BRSTNilpotent", brst_nilpotent_ty()),
("BRSTCohomology", brst_cohomology_ty()),
("GaugeFixing", gauge_fixing_ty()),
("FaddeevPopovDet", faddeev_popov_det_ty()),
("GaugeGroup_t", gauge_group_ty()),
("GaugeField_t", gauge_field_ty()),
("FieldStrength", field_strength_ty()),
("YangMillsLagrangian", yang_mills_lagrangian_ty()),
("GaugeTransformation", gauge_transformation_ty()),
("GaugeInvariant", gauge_invariant_ty()),
("WilsonLine", wilson_line_ty()),
("FieldSymmetry", field_symmetry_ty()),
("ConservedCurrent", conserved_current_ty()),
("CurrentConservation", current_conservation_ty()),
("NoetherCharge", noether_charge_ty()),
("noether_theorem", noether_theorem_ty()),
("EnergyMomentumTensor", energy_momentum_tensor_ty()),
("WardIdentity", ward_identity_ty()),
("VertexFunction", vertex_function_ty()),
("SlavnovTaylorIdentity", slavnov_taylor_identity_ty()),
("LSZReductionFormula", lsz_reduction_ty()),
("ChargeConjugation", charge_conjugation_ty()),
("ParityTransformation", parity_transformation_ty()),
("TimeReversal", time_reversal_ty()),
("CPTOperator", cpt_operator_ty()),
("cpt_theorem", cpt_theorem_ty()),
("spin_statistics_theorem", spin_statistics_theorem_ty()),
("LorentzCovariance", lorentz_covariance_ty()),
("HbarConstant", real_ty()),
("SpeedOfLight", real_ty()),
("ElementaryCharge", real_ty()),
("CouplingConstantQED", real_ty()),
("CouplingConstantQCD", real_ty()),
("WightmanField", wightman_field_ty()),
("PoincareCovariance", poincare_covariance_ty()),
("WightmanLocality", wightman_locality_ty()),
("SpectrumCondition", spectrum_condition_ty()),
("WightmanPositivity", wightman_positivity_ty()),
("WightmanDistribution", wightman_distribution_ty()),
("ReconstructionTheorem", reconstruction_theorem_ty()),
("LocalAlgebra", local_algebra_ty()),
("Isotony", isotony_ty()),
("HaagKastlerCausality", haag_kastler_causality_ty()),
("HaagDuality", haag_duality_ty()),
("ReehSchliederTheorem", reeh_schlieder_theorem_ty()),
("ForestFormula", forest_formula_ty()),
("SubtractionOperator", subtraction_operator_ty()),
("BphzRenormalized", bphz_renormalized_ty()),
("DimRegAmplitude", dim_reg_amplitude_ty()),
("EpsilonPole", epsilon_pole_ty()),
("MSbarScheme", msbar_scheme_ty()),
("RGFixedPoint", rg_fixed_point_ty()),
("UniversalityClass", universality_class_ty()),
("CriticalExponent", critical_exponent_ty()),
("SchwingerDysonEq", schwinger_dyson_eq_ty()),
("SelfEnergyFunction", self_energy_fn_ty()),
("DressedPropagator", dressed_propagator_ty()),
("InLSZState", in_lsz_state_ty()),
("OutLSZState", out_lsz_state_ty()),
("FactorizationTheorem", factorization_theorem_ty()),
("InfraredSafe", infrared_safe_ty()),
("OPECoefficient", ope_coefficient_ty()),
("OperatorProductExpansion", operator_product_expansion_ty()),
("ConformalPrimary", conformal_primary_ty()),
("VirasoroGenerator", virasoro_generator_ty()),
("VirasoroAlgebraRelation", virasoro_algebra_relation_ty()),
("CentralCharge", central_charge_ty()),
("cTheorem", c_theorem_ty()),
("ModularInvariance", modular_invariance_ty()),
("ConformalBootstrap", conformal_bootstrap_ty()),
("ChernSimonsAction", chern_simons_action_ty()),
("BFAction", bf_action_ty()),
("TQFTFunctor", tqft_functor_ty()),
("LinkingNumber", linking_number_ty()),
("JonesPolynomial", jones_polynomial_ty()),
("LatticeAction", lattice_action_ty()),
("LatticeGreenFn", lattice_green_fn_ty()),
("InstantonSolution", instanton_solution_ty()),
("InstantonAction", instanton_action_ty()),
("SeibergWittenCurve", seiberg_witten_curve_ty()),
("PrepotentialSW", prepotential_sw_ty()),
];
for (name, ty) in axioms {
env.add(Declaration::Axiom {
name: Name::str(*name),
univ_params: vec![],
ty: ty.clone(),
})
.ok();
}
env
}
pub fn running_coupling_phi4(g0: f64, mu: f64, mu0: f64) -> f64 {
use std::f64::consts::PI;
let log_ratio = (mu / mu0).ln();
let denominator = 1.0 - (3.0 * g0) / (16.0 * PI * PI) * log_ratio;
if denominator.abs() < 1e-15 {
f64::INFINITY
} else {
g0 / denominator
}
}
pub fn beta_function_phi4(g: f64) -> f64 {
use std::f64::consts::PI;
3.0 * g * g / (16.0 * PI * PI)
}
pub fn running_coupling_qed(alpha0: f64, mu: f64, m_electron: f64) -> f64 {
use std::f64::consts::PI;
let log_ratio = (mu * mu / (m_electron * m_electron)).ln();
let denominator = 1.0 - (alpha0 / (3.0 * PI)) * log_ratio;
if denominator.abs() < 1e-15 {
f64::INFINITY
} else {
alpha0 / denominator
}
}
pub fn check_ward_identity(k: &[f64; 4], amplitude: &[QftComplex; 4]) -> f64 {
let k_mu = k[0] * amplitude[0].re
- k[1] * amplitude[1].re
- k[2] * amplitude[2].re
- k[3] * amplitude[3].re;
k_mu.abs()
}
pub fn check_cpt_invariance(h: &[[QftComplex; 2]; 2], theta: &[[QftComplex; 2]; 2]) -> bool {
let mut th = [[QftComplex::zero(); 2]; 2];
let mut ht = [[QftComplex::zero(); 2]; 2];
for i in 0..2 {
for j in 0..2 {
for k in 0..2 {
th[i][j] = th[i][j].add(&theta[i][k].mul(&h[k][j]));
ht[i][j] = ht[i][j].add(&h[i][k].mul(&theta[k][j]));
}
}
}
for i in 0..2 {
for j in 0..2 {
if (th[i][j].re - ht[i][j].re).abs() > 1e-10 {
return false;
}
if (th[i][j].im - ht[i][j].im).abs() > 1e-10 {
return false;
}
}
}
true
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_build_env_succeeds() {
let env = build_quantum_field_theory_env();
let _ = env;
}
#[test]
fn test_fock_vacuum_creation_annihilation() {
let vac = FiniteFockSpace::vacuum(3, false);
assert_eq!(vac.total_number(), 0);
let (state1, norm1) = vac.create(1).expect("create should succeed");
assert_eq!(state1.occupations[1], 1);
assert!((norm1 - 1.0).abs() < 1e-12);
let (state2, norm2) = state1.create(1).expect("create should succeed");
assert_eq!(state2.occupations[1], 2);
assert!((norm2 - 2.0f64.sqrt()).abs() < 1e-12);
let (state3, norm3) = state2.annihilate(1).expect("annihilate should succeed");
assert_eq!(state3.occupations[1], 1);
assert!((norm3 - 2.0f64.sqrt()).abs() < 1e-12);
}
#[test]
fn test_fermionic_pauli_exclusion() {
let vac = FiniteFockSpace::vacuum(2, true);
let (state1, _) = vac.create(0).expect("create should succeed");
assert_eq!(state1.occupations[0], 1);
assert!(state1.create(0).is_none());
}
#[test]
fn test_vacuum_annihilation_gives_none() {
let vac = FiniteFockSpace::vacuum(3, false);
assert!(vac.annihilate(0).is_none());
assert!(vac.annihilate(2).is_none());
}
#[test]
fn test_klein_gordon_hamiltonian_zero_field() {
let field = KleinGordonField::new(8, 0.25, 1.0);
let h = field.hamiltonian();
assert!(
h.abs() < 1e-15,
"Zero field should have zero Hamiltonian: {h}"
);
}
#[test]
fn test_klein_gordon_energy_conservation() {
let mut field = KleinGordonField::new(16, 0.1, 0.5);
field.phi[0] = 0.1;
field.pi[0] = 0.0;
let h0 = field.hamiltonian();
for _ in 0..100 {
field.step(0.01);
}
let h1 = field.hamiltonian();
assert!(
(h1 - h0).abs() / (h0 + 1e-30) < 5e-3,
"Energy should be approximately conserved: h0={h0}, h1={h1}"
);
}
#[test]
fn test_feynman_diagram_loop_number() {
let tree = FeynmanDiagram::new(4, 1, 0);
assert_eq!(tree.loop_number(), 0);
let one_loop = FeynmanDiagram::new(4, 2, 3);
assert_eq!(one_loop.loop_number(), 2);
}
#[test]
fn test_running_coupling_phi4_increases() {
let g0 = 0.1;
let mu0 = 1.0;
let g_low = running_coupling_phi4(g0, 0.5, mu0);
let g_high = running_coupling_phi4(g0, 2.0, mu0);
assert!(g_high > g0, "φ⁴ coupling should grow with scale");
assert!(g_low < g0, "φ⁴ coupling should decrease at lower scale");
}
#[test]
fn test_brst_nilpotency_trivial() {
let complex = BrstComplex::new(vec![2, 3, 2]);
let v = vec![1.0, 0.5];
assert!(complex.check_nilpotency(0, &v));
}
#[test]
fn test_build_env_extended_axioms() {
let env = build_quantum_field_theory_env();
let _ = env;
}
#[test]
fn test_feynman_evaluator_propagator_on_shell() {
let eval = FeynmanDiagramEvaluator::new(0.1, 1.0);
let prop = eval.propagator(2.0, 1e-3);
let denom_sq = 1.0 + 1e-6;
let expected_re = eval.propagator(2.0, 1e-3).re;
assert!((expected_re - 1e-3 / denom_sq).abs() < 1e-10);
assert!(prop.abs() > 0.0);
}
#[test]
fn test_feynman_evaluator_vertex() {
let eval = FeynmanDiagramEvaluator::new(0.5, 1.0);
let v = eval.vertex();
assert!((v.re).abs() < 1e-15);
assert!((v.im + 0.5).abs() < 1e-15);
}
#[test]
fn test_feynman_evaluator_tree_amplitude() {
let eval = FeynmanDiagramEvaluator::new(0.1, 1.0);
let m = eval.tree_amplitude_2to2();
assert!((m.re).abs() < 1e-15);
assert!((m.im + 0.1).abs() < 1e-15);
}
#[test]
fn test_beta_function_rg_qcd() {
let rg = BetaFunctionRG::new(3, 6, 0);
assert!(rg.is_asymptotically_free());
let b0 = rg.b0_coefficient();
assert!((b0 - 7.0).abs() < 1e-10);
}
#[test]
fn test_beta_function_rg_not_af() {
let rg = BetaFunctionRG::new(3, 20, 0);
assert!(!rg.is_asymptotically_free());
}
#[test]
fn test_beta_function_rg_running_coupling_af() {
let rg = BetaFunctionRG::new(3, 3, 0);
assert!(rg.is_asymptotically_free());
let g0 = 1.0;
let g_high = rg.running_coupling(g0, 10.0, 1.0);
let g_low = rg.running_coupling(g0, 0.1, 1.0);
assert!(g_high < g0, "AF: coupling decreases at higher scale");
assert!(g_low > g0, "AF: coupling increases at lower scale");
}
#[test]
fn test_ising_lattice_ferromagnetic_energy() {
let lat = CorrelationFunctionLattice::new_ferromagnetic(4, 0.5);
let e = lat.energy();
assert!((e + 32.0).abs() < 1e-10);
}
#[test]
fn test_ising_lattice_magnetization() {
let lat = CorrelationFunctionLattice::new_ferromagnetic(4, 0.5);
let m = lat.magnetization();
assert!((m - 1.0).abs() < 1e-10);
}
#[test]
fn test_ising_lattice_two_point_correlation() {
let lat = CorrelationFunctionLattice::new_ferromagnetic(4, 0.5);
let corr = lat.two_point_correlation(2);
assert!((corr - 1.0).abs() < 1e-10);
}
#[test]
fn test_ising_lattice_metropolis_step() {
let mut lat = CorrelationFunctionLattice::new_ferromagnetic(8, 10.0);
let mut rng = 12345u64;
for _ in 0..100 {
lat.metropolis_step(&mut rng);
}
let m = lat.magnetization().abs();
assert!(m > 0.5, "Expected high magnetization at low T: {m}");
}
#[test]
fn test_ope_table_basic() {
let mut ope = OpeTable::new();
let identity = ope.add_operator("I", 0.0);
let sigma = ope.add_operator("σ", 0.125);
let epsilon = ope.add_operator("ε", 1.0);
ope.set_coefficient(sigma, sigma, identity, 1.0);
ope.set_coefficient(sigma, sigma, epsilon, 1.0);
assert!((ope.get_coefficient(sigma, sigma, identity) - 1.0).abs() < 1e-15);
assert!((ope.get_coefficient(sigma, sigma, epsilon) - 1.0).abs() < 1e-15);
assert!((ope.get_coefficient(epsilon, epsilon, sigma)).abs() < 1e-15);
assert!((ope.dimensions[identity]).abs() < 1e-15);
assert!((ope.dimensions[sigma] - 0.125).abs() < 1e-15);
}
#[test]
fn test_ope_crossing_residual_consistent() {
let mut ope = OpeTable::new();
let i = ope.add_operator("I", 0.0);
let s = ope.add_operator("sigma", 0.125);
let e = ope.add_operator("eps", 1.0);
ope.set_coefficient(s, s, i, 1.0);
ope.set_coefficient(s, s, e, 0.5);
ope.set_coefficient(i, i, i, 1.0);
let residual = ope.crossing_residual(s, s, i, i);
assert!((residual - 1.0).abs() < 1e-12);
}
#[test]
fn test_virasoro_commutator_basic() {
let vir = VirasoroCommutator::new(1.0);
let (coeff, idx, anomaly) = vir.commutator(2, -2);
assert!((coeff - 4.0).abs() < 1e-12);
assert_eq!(idx, 0);
assert!((anomaly - 0.5).abs() < 1e-12);
}
#[test]
fn test_virasoro_commutator_no_anomaly_offdiag() {
let vir = VirasoroCommutator::new(26.0);
let (coeff, idx, anomaly) = vir.commutator(1, 2);
assert!((coeff - (-1.0)).abs() < 1e-12);
assert_eq!(idx, 3);
assert!(anomaly.abs() < 1e-15);
}
#[test]
fn test_virasoro_jacobi_identity() {
let vir = VirasoroCommutator::new(1.0);
assert!(vir.check_jacobi(1, 2, -3));
assert!(vir.check_jacobi(3, -1, -2));
assert!(vir.check_jacobi(0, 1, -1));
}
#[test]
fn test_virasoro_witt_limit() {
let (coeff, idx) = VirasoroCommutator::witt_commutator(3, -1);
assert!((coeff - 4.0).abs() < 1e-12);
assert_eq!(idx, 2);
}
#[test]
fn test_one_loop_bubble_approx() {
let eval = FeynmanDiagramEvaluator::new(0.1, 1.0);
let correction = eval.one_loop_bubble_approx(100.0);
assert!(correction.abs() > 0.0);
}
}
#[cfg(test)]
mod tests_qft_ext {
use super::*;
#[test]
fn test_path_integral() {
let mut pi = PathIntegralData::new("phi^4", 4);
pi.add_coupling("lambda", 0.1);
assert!(pi.power_counting_renormalizable(0.0));
assert_eq!(pi.superficial_divergence(1, 2), 0);
assert!(pi.partition_function_description().contains("phi^4"));
}
#[test]
fn test_yang_mills_asymptotic_freedom() {
let qcd = YangMillsTheory::new("SU(3)", 3, 1.0).with_flavors(6);
assert!(qcd.asymptotically_free);
assert!((qcd.beta0() - 7.0).abs() < 1e-10);
assert_eq!(qcd.dual_coxeter_number(), 3);
}
#[test]
fn test_yang_mills_not_af() {
let qcd = YangMillsTheory::new("SU(2)", 2, 1.0).with_flavors(12);
assert!(!qcd.asymptotically_free);
}
#[test]
fn test_cft_ising() {
let ising = ConformalFieldTheory2D::ising();
assert!((ising.central_charge - 0.5).abs() < 1e-10);
assert!(ising.is_rational);
assert_eq!(ising.primary_operators.len(), 3);
let exp = ising.character_exponent(0.0);
assert!((exp + 0.5 / 24.0).abs() < 1e-10);
}
}
#[cfg(test)]
mod tests_qft_ext2 {
use super::*;
#[test]
fn test_brst_data() {
let mut brst = BRSTData::new();
brst.add_state("|photon, +>", 0);
brst.add_state("|photon, ->", 0);
brst.add_state("|ghost>", 1);
brst.add_state("|antighost>", -1);
assert!(brst.is_nilpotent());
assert_eq!(brst.physical_ghost_zero().len(), 2);
assert!(brst.cohomology_description().contains("2 physical"));
}
#[test]
fn test_running_coupling() {
let ym = YangMillsTheory::new("SU(3)", 3, 1.0).with_flavors(0);
let g2 = ym.running_coupling_squared(10.0, 1.0);
assert!(g2 < 1.0, "Running coupling should decrease: {g2}");
}
}
#[cfg(test)]
mod tests_qft_ext3 {
use super::*;
#[test]
fn test_scattering_amplitude() {
let amp = ScatteringAmplitude::new("2→2 massless", 4)
.with_mandelstam(100.0, -50.0, -50.0)
.with_tree_amplitude(1.5);
assert!(amp.crossing_satisfied(0.0, 1e-10));
assert!(amp.parke_taylor_description().contains("4 gluons"));
}
}