Skip to main content

logicaffeine_kernel/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![doc = include_str!("../README.md")]
3
4mod annotation;
5pub mod bitvector;
6pub mod cc;
7#[cfg(feature = "serde")]
8pub mod certificate;
9mod context;
10mod conversion_session;
11pub mod dag;
12pub mod elaborate;
13mod error;
14pub mod eval;
15pub mod field_algebra;
16pub mod inductive_compile;
17pub mod interface;
18pub mod lia;
19pub mod omega;
20pub mod positivity;
21pub mod prelude;
22pub mod recheck;
23pub mod recursor;
24mod reduction;
25mod reflection;
26pub mod reify;
27pub mod ring;
28pub mod simp;
29mod structure_eta;
30pub mod tactic_cert;
31pub mod tactics;
32mod term;
33pub mod termination;
34mod type_checker;
35pub mod word_ring;
36
37pub use context::{reconcile_block_params, DEFAULT_INSTANCE_PRIORITY};
38pub use context::{Context, MutualInductive, StructInfo};
39pub use error::{KernelError, KernelResult, MeaningChange};
40pub use eval::{
41    eval_bool, eval_bool_tree, native_compile_bool, native_compile_decide, native_decide,
42};
43pub use inductive_compile::{NestedDecl, NestedInfo};
44pub use structure_eta::StructureRefusal;
45// `normalize` is the BEST-EFFORT face: it returns a `Term` and so cannot report that a reduction
46// never finished. `normalize_checked` is the honest one — it distinguishes a real normal form from
47// a δ-CYCLE (no normal form exists), an exhausted step budget, and a term too deep to walk. Any
48// caller that can carry an error should prefer it.
49/// The transparent carrier's payload: a binder's kind, or where a subterm came from.
50pub use annotation::{Annotation, Provenance, SourcePosition};
51pub use elaborate::{
52    auto_bind_implicits, bind_self_recursion, elaborate, elaborate_anon_ctor, elaborate_app,
53    elaborate_app_against, elaborate_dot, elaborate_in, fill_match_motives, instantiate,
54    resolve_coercion, resolve_instance, surface_elaborate, surface_elaborate_against, unify,
55    unify_in, MetaCtx, ParamKind, ANON_CTOR_MARKER, DOT_MARKER,
56};
57pub use logicaffeine_base::BigInt;
58pub use recheck::{double_check, recheck, DoubleCheck, Incomplete, IncompleteKind, ReCheckError};
59pub use recursor::derive_recursor;
60/// Whether a verdict depended on kernel work that stopped for want of a resource: a conversion
61/// that says "not equal" decided nothing when one of its reductions ran out of budget.
62pub use reduction::{discard_resource_stops, observe_resource_stops};
63pub use reduction::{normalize, normalize_checked, Unreduced};
64pub use reify::VarInterner;
65pub use term::{
66    instantiate_universes, int_lit, lit_bigint, resolve_const_levels, ConstError, Literal, Term,
67    Universe,
68};
69pub use type_checker::{infer_type, instantiate_codomain, is_subtype, substitute};
70
71/// Definitional equality of two terms — exposed for tests that pin conversion
72/// behaviour (structure eta, proof irrelevance) directly.
73pub fn defeq_for_test(ctx: &Context, a: &Term, b: &Term) -> bool {
74    type_checker::def_eq(ctx, a, b)
75}
76
77/// Strict-positivity check of a constructor type — exposed so tests can pin the
78/// paradox fence (negative occurrences rejected, positive functional fields
79/// accepted) directly.
80pub fn check_positivity_for_test(
81    inductive: &str,
82    constructor: &str,
83    ty: &Term,
84) -> KernelResult<()> {
85    positivity::check_positivity(inductive, constructor, ty)
86}
87
88/// The δ-transparency axis (Lean's `TransparencyMode`): `normalize_at`/`normalize_checked_at` keep
89/// an `@[irreducible]` constant folded with its body intact, while `normalize` stays the kernel's
90/// own always-unfolding setting.
91pub use reduction::{normalize_at, normalize_checked_at, Transparency};
92
93pub mod term_store;
94
95/// The `@[simp]` registry's compiled rule — `Context::simp_rules`/`simp_rules_for` hand these to
96/// whatever does the rewriting, already destructured into `∀x̄. lhs ⟶ rhs`.
97pub use context::SimpRule;
98
99/// Lean's reducibility axis, declared per constant — `Context::is_irreducible` is the predicate
100/// `reduction::Transparency::Excluding` is looking for.
101pub use context::Reducibility;
102
103/// Lean's `#print axioms`, as a function — what a proof transitively rests on, and whether any of
104/// it is an admission rather than an assumption. Lives in `prelude` (beside the trusted base it is
105/// the complement of) and is surfaced here because it is not optional: the REPL, the certificate
106/// re-checker and `logicaffeine_proof`'s verdicts must all read the same closure.
107pub use prelude::{
108    axiom_dependencies, axiom_dependencies_given, axiom_dependencies_of, foreign_axiom_note,
109    is_admitted_axiom, AxiomUsage, ADMITTED_AXIOMS, FOREIGN_AXIOMS,
110};
111
112/// The elaborator's reduction face: `@[irreducible]` constants stay folded, body intact, with
113/// the opacity predicate built once from `Context::is_irreducible` rather than by each caller.
114/// `normalize` remains the kernel's face and unfolds everything, exactly as Lean's does.
115pub use reduction::{normalize_checked_elab, normalize_elab};
116
117pub mod equations;
118
119/// `Int` as a real inductive — Lean's `ofNat | negSucc` with its arithmetic defined rather than
120/// assumed (`Init/Data/Int/Basic.lean:40-45`, `:78-166`). The construction, packaged so the
121/// prelude adopts it in one call; the module header carries how Lean keeps it fast anyway.
122pub mod int_inductive;
123mod integer_laws;
124
125/// The universe-polymorphic eliminator — Lean's `Nat.rec.{u}`, whose motive lands in `Sort u`
126/// rather than in the inductive's own sort (`Init/Prelude.lean` states every core recursor this
127/// way). `derive_recursor` remains the monomorphic face; this one returns the level telescope
128/// beside the type and term, so a caller can register it either as `add_universe_poly` (referenced
129/// as `Term::Const { name, levels }`) or as a plain definition whose free level variable the
130/// application rule solves from the motive actually supplied.
131pub use recursor::derive_recursor_universe_poly;
132
133/// Certified universe-polymorphic quotient primitives.
134pub mod observational;
135pub mod quotient;