Skip to main content

alkahest_cas/
lib.rs

1pub mod acausal;
2pub mod algebra;
3pub mod ball;
4pub mod calculus;
5pub mod dae;
6pub mod deriv;
7pub mod diff;
8pub mod errors;
9pub mod flint;
10pub mod horner;
11pub mod hybrid;
12pub mod integrate;
13pub mod jit;
14pub mod kernel;
15// V3-3 — First-order logic / FOFormula
16pub mod logic;
17// V2-6 — LLL + PSLQ (PSLQ in `numeric`)
18pub mod lattice;
19pub mod lean;
20pub mod matrix;
21// V2-1 — Modular / CRT framework
22pub mod modular;
23// V3-1 — Integer number theory (`fmpz` helpers)
24pub mod number_theory;
25pub mod numeric;
26pub mod ode;
27pub mod parse;
28pub mod pattern;
29pub mod poly;
30// V2-9 — CAD / real QE
31#[cfg(feature = "groebner")]
32pub mod ideal;
33pub mod primitive;
34pub mod real;
35pub mod simplify;
36#[cfg(feature = "groebner")]
37pub mod solver;
38// V2-13 — Differential algebra / Rosenfeld–Gröbner
39#[cfg(feature = "groebner")]
40pub mod diffalg;
41// V2-10 — Gosper / creative telescoping (WZ certificates)
42pub mod stablehlo;
43pub mod sum;
44
45pub use acausal::{capacitor, resistor, voltage_source, Component, Port, System};
46pub use calculus::{limit, series, LimitDirection, LimitError, Series, SeriesError};
47pub use dae::{pantelides, DaeError, PantelidesResult, DAE};
48pub use deriv::{DerivationLog, DerivedExpr, RewriteStep, SideCondition};
49#[allow(deprecated)]
50pub use diff::{diff, diff_forward, grad, DiffError, DualValue, ForwardDiffError};
51pub use flint::{FlintInteger, FlintPoly};
52pub use hybrid::{Event, GuardStructure, HybridODE};
53pub use integrate::{integrate, IntegrationError};
54#[allow(deprecated)]
55pub use kernel::{
56    expr_contains_noncommutative_symbol, load_from, mult_tree_is_commutative, open_persistent,
57    render_latex, render_unicode, save_to, subs, Domain, ExprData, ExprDisplay, ExprId, ExprPool,
58    IoError, PoolPersistError,
59};
60pub use logic::{
61    dpll_sat, formula_from_expr, satisfiable, BoolClause, BoolLit, Formula, LogicError,
62    Satisfiability,
63};
64pub use real::{cad_lift, cad_project, decide, decide_expr, CadError, QeResult};
65// V2-6 — LLL + integer relations (augmented lattice heuristic)
66pub use lattice::{
67    lattice_reduce_rows, lattice_reduce_rows_with_delta, validate_lll_rows, LatticeError,
68};
69pub use matrix::{
70    characteristic_polynomial_lambda_minus_m, diagonalize, eigenvalues, eigenvectors, hermite_form,
71    hermite_form_poly, jacobian, smith_form, smith_form_poly, EigenError, IntegerMatrix, Matrix,
72    MatrixError, NormalFormError, PolyMatrixQ, RatUniPoly,
73};
74pub use numeric::{guess_integer_relation, PslqError};
75pub use ode::{
76    lower_to_first_order,
77    sensitivity::{adjoint_system, sensitivity_system, AdjointSystem, SensitivitySystem},
78    OdeError, ScalarODE, ODE,
79};
80pub use parse::{parse, ParseError};
81pub use pattern::{match_pattern, Pattern, Substitution};
82pub use poly::{
83    factor_multivariate_z, factor_univariate_mod_p, factor_univariate_z, poly_normal, real_roots,
84    real_roots_symbolic, refine_root, resultant, sparse_interpolate, sparse_interpolate_univariate,
85    subresultant_prs, ConversionError, FactorError, MultiPoly, MultiPolyFactorization,
86    RationalFunction, RealRootError, ResultantError, RootInterval, SparseInterpError, UniPoly,
87    UniPolyFactorModP, UniPolyFactorization,
88};
89
90// Phase 24 — Horner form
91pub use horner::{emit_horner_c, horner};
92pub use simplify::rulesets::{log_exp_rules, log_exp_rules_safe, trig_rules};
93pub use simplify::{
94    rules_for_config, simplify, simplify_egraph, simplify_egraph_with, simplify_expanded,
95    simplify_with, DepthCost, EgraphConfig, EgraphCost, NoncommutativeCost, OpCost, PatternRule,
96    RewriteRule, SimplifyConfig, SizeCost, StabilityCost,
97};
98pub use sum::{
99    gosper_certificate, gosper_normal_form, hypergeom_ratio, product_definite, product_indefinite,
100    rsolve, solve_linear_recurrence_homogeneous, sum_definite, sum_indefinite, verify_wz_pair,
101    LinearRecurrenceError, ProductError, RatFunc, RecurrenceSolution, RsolveError, SumError,
102    WzPair,
103};
104
105// Phase 21 — JIT
106pub use jit::{compile, compile_jit_only, eval_interp, jit_available, CompiledFn, JitError};
107
108// V5-2 — StableHLO/XLA bridge
109pub use stablehlo::emit_stablehlo;
110
111// V5-3 — NVPTX JIT backend
112#[cfg(feature = "cuda")]
113pub use jit::{compile_cuda, CudaCompiledFn, CudaError};
114
115// Phase 22 — Ball arithmetic
116pub use ball::{AcbBall, ArbBall, IntervalEval, DEFAULT_PREC};
117
118// Phase 23 — Parallel simplification
119#[cfg(feature = "parallel")]
120pub use simplify::parallel::{simplify_par, simplify_par_with_config};
121
122// V5-11 — Gröbner basis
123#[cfg(feature = "groebner")]
124pub use poly::groebner::{compute_groebner_basis_f5, GbPoly, GroebnerBasis, MonomialOrder};
125
126pub use errors::AlkahestError;
127pub use lean::emit_lean_expr as emit_lean;
128// V2-1 — Modular / CRT framework
129#[cfg(feature = "groebner")]
130pub use diffalg::{
131    dae_index_reduce, rosenfeld_groebner, rosenfeld_groebner_algebraic,
132    rosenfeld_groebner_with_options, DaeIndexReduction, DiffAlgError, DifferentialIdeal,
133    DifferentialRanking, DifferentialRing, RegularDifferentialChain, RosenfeldGroebnerResult,
134};
135#[cfg(feature = "groebner")]
136pub use ideal::{primary_decomposition, radical, PrimaryComponent, PrimaryDecompositionError};
137pub use modular::{
138    is_prime, lift_crt, mignotte_bound, rational_reconstruction, reduce_mod, select_lucky_prime,
139    ModularError, ModularValue, MultiPolyFp,
140};
141pub use number_theory::{
142    discrete_log, factorint, isprime, jacobi_symbol, nextprime, nthroot_mod, totient,
143    NumberTheoryError, QuadraticDirichlet,
144};
145pub use primitive::{Capabilities, CoverageReport, CoverageRow, Primitive, PrimitiveRegistry};
146#[cfg(feature = "groebner")]
147pub use solver::{
148    diophantine, expr_to_gbpoly, extract_regular_chain_from_basis, main_variable_recursive,
149    solve_numerical, solve_polynomial_system, triangularize, CertifiedPoint, DiophantineError,
150    DiophantineSolution, HomotopyError, HomotopyOpts, RegularChain, Solution, SolutionSet,
151    SolverError,
152};
153
154pub fn version() -> &'static str {
155    env!("CARGO_PKG_VERSION")
156}
157
158/// Stable 1.0 API surface (V1-8).
159///
160/// Items in this module are covered by the Alkahest semver promise: any
161/// backwards-incompatible change to a symbol re-exported here requires a
162/// major-version bump (`2.0`).  Everything else in `alkahest_core::*` —
163/// including the top-level re-exports kept for backwards compatibility —
164/// is considered experimental unless it also appears below.
165///
166/// See `README.md` ("Stability") for the full policy.
167pub mod stable {
168    pub use crate::algebra::{
169        clifford_orthogonal_rules, imag_unit_atom, pauli_product_rules, PauliSpinAlgebraRule,
170    };
171    pub use crate::calculus::{limit, series, LimitDirection, LimitError, Series, SeriesError};
172    pub use crate::dae::{pantelides, DaeError, DAE};
173    pub use crate::diff::{diff, diff_forward, grad, DiffError};
174    #[cfg(feature = "groebner")]
175    pub use crate::diffalg::{
176        dae_index_reduce, rosenfeld_groebner, rosenfeld_groebner_algebraic,
177        rosenfeld_groebner_with_options, DaeIndexReduction, DiffAlgError, DifferentialIdeal,
178        DifferentialRanking, DifferentialRing, RegularDifferentialChain, RosenfeldGroebnerResult,
179    };
180    pub use crate::errors::AlkahestError;
181    #[cfg(feature = "groebner")]
182    pub use crate::ideal::{
183        primary_decomposition, radical, PrimaryComponent, PrimaryDecompositionError,
184    };
185    pub use crate::integrate::{integrate, IntegrationError};
186    pub use crate::jit::{compile, CompiledFn, JitError};
187    #[cfg(feature = "cuda")]
188    pub use crate::jit::{compile_cuda, CudaCompiledFn, CudaError};
189    #[allow(deprecated)]
190    pub use crate::kernel::pool_persist::PoolPersistError;
191    pub use crate::kernel::pool_persist::{load_from, open_persistent, save_to, IoError};
192    pub use crate::kernel::{
193        expr_contains_noncommutative_symbol, mult_tree_is_commutative, render_latex,
194        render_unicode, subs, Domain, ExprData, ExprDisplay, ExprId, ExprPool,
195    };
196    pub use crate::lattice::{
197        lattice_reduce_rows, lattice_reduce_rows_with_delta, validate_lll_rows, LatticeError,
198    };
199    pub use crate::lean::emit_lean_expr as emit_lean;
200    pub use crate::logic::{
201        dpll_sat, formula_from_expr, satisfiable, BoolClause, BoolLit, Formula, LogicError,
202        Satisfiability,
203    };
204    pub use crate::matrix::{
205        characteristic_polynomial_lambda_minus_m, diagonalize, eigenvalues, eigenvectors,
206        hermite_form, hermite_form_poly, jacobian, smith_form, smith_form_poly, EigenError,
207        IntegerMatrix, Matrix, MatrixError, NormalFormError, PolyMatrixQ, RatUniPoly,
208    };
209    pub use crate::number_theory::{
210        discrete_log, factorint, isprime, jacobi_symbol, nextprime, nthroot_mod, totient,
211        NumberTheoryError, QuadraticDirichlet,
212    };
213    pub use crate::numeric::{guess_integer_relation, PslqError};
214    pub use crate::ode::{lower_to_first_order, OdeError, ScalarODE, ODE};
215    pub use crate::parse::{parse, ParseError};
216    pub use crate::pattern::{match_pattern, Pattern, Substitution};
217    pub use crate::poly::{
218        factor_multivariate_z, factor_univariate_mod_p, factor_univariate_z, poly_normal,
219        real_roots, real_roots_symbolic, refine_root, resultant, sparse_interpolate,
220        sparse_interpolate_univariate, subresultant_prs, ConversionError, FactorError, MultiPoly,
221        MultiPolyFactorization, RationalFunction, RealRootError, ResultantError, RootInterval,
222        SparseInterpError, UniPoly, UniPolyFactorModP, UniPolyFactorization,
223    };
224    pub use crate::primitive::{Primitive, PrimitiveRegistry};
225    pub use crate::real::{cad_lift, cad_project, decide, decide_expr, CadError, QeResult};
226    pub use crate::simplify::{
227        simplify, simplify_egraph, simplify_egraph_with, simplify_with, DepthCost, EgraphConfig,
228        EgraphCost, NoncommutativeCost, OpCost, SimplifyConfig, SizeCost, StabilityCost,
229    };
230    #[cfg(feature = "groebner")]
231    pub use crate::solver::{
232        diophantine, expr_to_gbpoly, extract_regular_chain_from_basis, main_variable_recursive,
233        solve_numerical, solve_polynomial_system, triangularize, CertifiedPoint, DiophantineError,
234        DiophantineSolution, HomotopyError, HomotopyOpts, RegularChain, Solution, SolutionSet,
235        SolverError,
236    };
237    pub use crate::stablehlo::emit_stablehlo;
238    pub use crate::sum::{
239        gosper_certificate, gosper_normal_form, hypergeom_ratio, product_definite,
240        product_indefinite, rsolve, solve_linear_recurrence_homogeneous, sum_definite,
241        sum_indefinite, verify_wz_pair, LinearRecurrenceError, ProductError, RatFunc,
242        RecurrenceSolution, RsolveError, SumError, WzPair,
243    };
244    pub use crate::version;
245}
246
247/// Experimental surface — may change without a major-version bump (V1-8).
248///
249/// Anything here is subject to redesign.  Pin a point-release if you rely
250/// on it.
251pub mod experimental {
252    pub use crate::acausal::{capacitor, resistor, voltage_source, Component, Port, System};
253    pub use crate::ball::{AcbBall, ArbBall, IntervalEval};
254    pub use crate::deriv::{DerivationLog, DerivedExpr, RewriteStep, SideCondition};
255    pub use crate::horner::{emit_horner_c, horner};
256    pub use crate::hybrid::{Event, GuardStructure, HybridODE};
257    pub use crate::lean::emit_lean_expr as emit_lean;
258    pub use crate::modular::{
259        is_prime, lift_crt, mignotte_bound, rational_reconstruction, reduce_mod,
260        select_lucky_prime, ModularError, ModularValue, MultiPolyFp,
261    };
262    pub use crate::numeric::{guess_integer_relation, PslqError};
263    pub use crate::ode::sensitivity::{
264        adjoint_system, sensitivity_system, AdjointSystem, SensitivitySystem,
265    };
266    pub use crate::poly::{sparse_interpolate, sparse_interpolate_univariate, SparseInterpError};
267    pub use crate::simplify::{simplify_egraph, simplify_expanded};
268    pub use crate::stablehlo::emit_stablehlo;
269
270    #[cfg(feature = "parallel")]
271    pub use crate::simplify::parallel::{simplify_par, simplify_par_with_config};
272
273    #[cfg(feature = "groebner-cuda")]
274    pub use crate::poly::groebner::GpuGroebnerError;
275    #[cfg(feature = "groebner")]
276    pub use crate::poly::groebner::{
277        compute_groebner_basis_f5, GbPoly, GroebnerBasis, MonomialOrder,
278    };
279}