Expand description
§OxiLean Standard Library — Core Data Types & Theorems
The standard library provides essential types, type classes, and theorems for OxiLean programs. It is written in OxiLean itself and loaded into the kernel environment at startup.
§Quick Start
§Using Standard Types
theorem two_plus_three : 2 + 3 = 5 := by
norm_num
def my_list : List Nat := [1, 2, 3]
instance : Eq Nat := { ... }§Architecture Overview
The standard library is organized into logical categories:
Standard Library Organization
├─ Primitive Types
│ ├─ nat, bool, char, int
│ ├─ string, list, array
│ ├─ option, result, sum
│ └─ prod, sigma
│
├─ Type Classes & Traits
│ ├─ Eq, Ord, Show, Repr
│ ├─ Functor, Monad, Applicative
│ ├─ Monoid, Semigroup
│ └─ Decidable
│
├─ Core Theorems & Lemmas
│ ├─ Equality (eq.rs)
│ ├─ Logic (logic.rs, prop.rs)
│ ├─ Arithmetic (nat.rs, int.rs)
│ └─ Order (ord.rs, order.rs)
│
└─ Utilities & Automation
├─ Tactic lemmas
├─ Decision procedures
└─ Parsing combinators§Key Concepts & Terminology
§Inductive Types
Core types are defined inductively:
Nat : Type 0
| zero : Nat
| succ : Nat → Nat
Bool : Prop
| true : Bool
| false : Bool
List α : Type 0
| nil : List α
| cons : α → List α → List αEach inductive type comes with:
- Constructors: Ways to create values
- Recursor: Principle for inductive recursion
- Induction principle: Structural induction proof technique
§Type Classes
Type classes enable ad-hoc polymorphism:
class Eq (α : Type u) : Prop where
eq : α → α → Prop
refl : ∀ x, eq x x
symm : ∀ x y, eq x y → eq y x
trans : ∀ x y z, eq x y → eq y z → eq x zInstances provide implementations for specific types:
instance Eq Nat : Eq Nat where
eq := Nat.eq
refl := Nat.eq_refl
...§Recursion Schemes
Each inductive type gets a recursor for primitive recursion:
Nat.rec :
{motive : Nat → Sort u}
→ motive 0
→ (∀ n, motive n → motive (n + 1))
→ ∀ n, motive nHigher-order recursion patterns (fold, map, etc.) are defined in terms of recs.
§Decidability
For computable propositions, we can decide them algorithmically:
class Decidable (p : Prop) : Type 0 where
decide : Bool
correct : decide = true ↔ pExamples: 2 + 3 = 5 is decidable (computable), but ∀ n, P n usually isn’t.
§Module Organization
§Primitive Types & Constructors
| Module | Types | Purpose |
|---|---|---|
nat | Nat | Natural numbers (zero, successor) |
bool | Bool | Booleans (true, false) |
int | Int | Signed integers |
char | Char | Unicode characters |
string | String | Text strings |
§Collection Types
| Module | Types | Purpose |
|---|---|---|
list | List α | Linked lists |
array | Array α | Fixed-size arrays |
vec | Vec α | Dynamic vectors (like Lean 4) |
set | Set α | Mathematical sets |
fin | Fin n | Finite sets (0..n-1) |
§Option & Alternative Types
| Module | Types | Purpose |
|---|---|---|
option | Option α | Nullable value |
result | Result α ε | Value or error |
sum | α ⊕ β | Tagged union |
either | Either α β | Alternative representation |
prod | α × β | Pairs/products |
sigma | Σ x, P x | Dependent pairs |
§Type Classes
| Module | Classes | Purpose |
|---|---|---|
eq | Eq | Equality relation |
ord | Ord | Total ordering |
show | Show | String representation |
repr | Repr | Debug representation |
decidable | Decidable | Computable propositions |
§Higher-Order Abstractions
| Module | Classes | Purpose |
|---|---|---|
functor | Functor | Map over container |
applicative | Applicative | Apply pure functions |
monad | Monad | Sequencing computations |
algebra | Monoid, Semigroup | Algebraic structures |
§Logic & Propositions
| Module | Purpose |
|---|---|
logic | Classical logic (excluded middle, etc.) |
prop | Propositional theorems |
eq | Equality and substitution |
§Arithmetic & Order
| Module | Purpose |
|---|---|
nat | Natural number theorems |
int | Integer theorems |
order | Partial orders |
ordering | Compare result type |
range | Integer ranges |
§Advanced Structures
| Module | Purpose |
|---|---|
rbtree | Red-black trees (sorted maps) |
hashmap | Hash maps |
hashset | Hash sets |
stream | Lazy sequences |
thunk | Delayed computation |
lazy | Lazy values |
§Utilities
| Module | Purpose |
|---|---|
wellfounded | Well-founded relations |
quotient_types | Quotient type operations |
tactic_lemmas | Lemmas useful for automation |
parsec | Parsing combinators |
io | I/O operations |
§Type Hierarchy
The standard library respects the universe hierarchy:
Data types (Nat, Bool, List) : Type 0
Type classes (Eq, Show) : Type 0 → Prop or Type 1
Propositions (Nat.add_comm) : Prop
Proofs (rfl, trans) : Prop§Usage Examples
§Example 1: Working with Natural Numbers
theorem add_comm : ∀ n m : Nat, n + m = m + n := by
intro n m
induction n with
| zero => simp
| succ n ih => simp [ih]§Example 2: List Operations
def append {α : Type u} : List α → List α → List α
| [], ys => ys
| x :: xs, ys => x :: append xs ys
theorem append_nil : ∀ xs : List α, append xs [] = xs := by
intro xs
induction xs with
| nil => rfl
| cons x xs ih => simp [ih]§Example 3: Type Class Instance
instance : Eq (List Nat) where
eq xs ys := (append xs [] = append ys [])
refl xs := rfl
...§Example 4: Pattern Matching
def is_zero : Nat → Bool
| 0 => true
| _ + 1 => false
def head {α : Type u} : List α → Option α
| [] => none
| x :: _ => some x§Environment Building
The standard library is built in phases:
- Phase 1: Primitives — Nat, Bool, basic operations
- Phase 2: Collections — List, Array, Set
- Phase 3: Type Classes — Eq, Show, etc.
- Phase 4: Theorems — Induction principles, lemmas
- Phase 5: Automation — Tactic lemmas, decision procedures
Loading happens in oxilean-std via build_*_env functions:
let env = Environment::new();
let env = build_nat_env(env)?;
let env = build_list_env(env)?;
let env = build_eq_env(env)?;
// etc...§Integration with Elaborator & Tactics
§Decidability
The norm_num and decide tactics use decidable instances:
2 + 3 = 5viaDecidableinstance on Nat equalitydecideextracts this decision to reduce proofs automatically
§Simplification
The simp tactic uses lemmas from the standard library:
- Reflexivity:
x = x - Commutativity:
x + y = y + x - Associativity:
(x + y) + z = x + (y + z)
§Induction
The induction tactic uses recursors and induction principles:
- For
Nat: Decompose into zero/successor cases - For
List: Decompose into nil/cons cases
§Performance & Memory
- Lazy evaluation: Some computations deferred via
Thunk - Persistent data structures: Lists/sets use structural sharing
- Universe polymorphism: Generic types work across universe levels
§Further Reading
- ARCHITECTURE.md — System architecture
- BLUEPRINT.md — Formal specifications
- Module documentation for specific type definitions
Re-exports§
pub use algebra::build_algebra_env;pub use array::build_array_env;pub use bitvec::build_bitvec_env;pub use bool::build_bool_env;pub use category_theory::build_category_theory_env;pub use char::build_char_env;pub use decidable::build_decidable_env;pub use either::build_either_env;pub use eq::build_eq_env;pub use fin::build_fin_env;pub use functor::build_functor_env;pub use group_theory::build_group_theory_env;pub use hashmap::build_hashmap_env;pub use hashset::build_hashset_env;pub use int::build_int_env;pub use io::build_io_env;pub use lazy::build_lazy_env;pub use list::build_list_env;pub use logic::build_logic_env;pub use monad::build_monad_env;pub use nat::build_nat_env;pub use option::build_option_env;pub use ord::build_ord_env;pub use order::build_order_env;pub use ordering::build_ordering_env;pub use parsec::build_parsec_env;pub use prod::build_prod_env;pub use prop::build_prop_env;pub use quotient_types::build_quotient_types_env;pub use range::build_range_env;pub use rbtree::build_rbtree_env;pub use real::build_real_env;pub use repr::build_repr_env;pub use result::build_result_env;pub use set::build_set_env;pub use show::build_show_env;pub use sigma::build_sigma_env;pub use stream::build_stream_env;pub use string::build_string_env;pub use sum::build_sum_env;pub use tactic_lemmas::build_tactic_lemmas_env;pub use thunk::build_thunk_env;pub use topology::build_topology_env;pub use vec::build_vec_env;pub use wellfounded::build_wellfounded_env;
Modules§
- abstract_
algebra_ adv - Auto-generated module structure
- abstract_
algebra_ advanced - Auto-generated module structure
- abstract_
interpretation - Auto-generated module structure
- algebra
- Auto-generated module structure
- algebraic_
combinatorics - Auto-generated module structure
- algebraic_
effects - Auto-generated module structure
- algebraic_
geometry - Auto-generated module structure
- algebraic_
number_ theory - Auto-generated module structure
- algebraic_
topology - Auto-generated module structure
- analytic_
number_ theory - Auto-generated module structure
- approximation_
algorithms - Auto-generated module structure
- arithmetic_
geometry - Auto-generated module structure
- array
- Auto-generated module structure
- automata_
theory - Auto-generated module structure
- bayesian_
networks - Auto-generated module structure
- bioinformatics
- Auto-generated module structure
- birational_
geometry - Auto-generated module structure
- bitvec
- Auto-generated module structure
- bool
- Auto-generated module structure
- categorical_
logic - Auto-generated module structure
- category_
theory - Auto-generated module structure
- category_
theory_ ext - Auto-generated module structure
- certified_
algorithms - Auto-generated module structure
- chaos_
theory - Auto-generated module structure
- char
- Auto-generated module structure
- chromatic_
homotopy - Auto-generated module structure
- coalgebra_
theory - Auto-generated module structure
- coding_
theory - Auto-generated module structure
- combinatorial_
game_ theory - Auto-generated module structure
- combinatorial_
optimization - Auto-generated module structure
- combinatorics
- Auto-generated module structure
- compiler_
theory - Auto-generated module structure
- complex
- Auto-generated module structure
- complexity
- Auto-generated module structure
- computational_
geometry - Auto-generated module structure
- concurrency_
theory - Auto-generated module structure
- constructive_
mathematics - Auto-generated module structure
- control_
theory - Auto-generated module structure
- convex_
analysis - Auto-generated module structure
- convex_
geometry - Auto-generated module structure
- convex_
optimization - Auto-generated module structure
- cryptographic_
protocols - Auto-generated module structure
- cryptography
- Auto-generated module structure
- cubical_
type_ theory - Auto-generated module structure
- data_
structures - Auto-generated module structure
- decidable
- Auto-generated module structure
- denotational_
semantics - Auto-generated module structure
- derived_
algebraic_ geometry - Auto-generated module structure
- descriptive_
set_ theory - Auto-generated module structure
- differential_
equations - Auto-generated module structure
- differential_
geometry - Auto-generated module structure
- differential_
privacy - Auto-generated module structure
- diophantine_
geometry - Auto-generated module structure
- distributed_
systems_ theory - Auto-generated module structure
- domain_
theory - Auto-generated module structure
- either
- Auto-generated module structure
- elliptic_
curves - Auto-generated module structure
- env_
builder - Auto-generated module structure
- eq
- Auto-generated module structure
- ergodic_
theory - Auto-generated module structure
- fin
- Auto-generated module structure
- finite_
element_ method - Auto-generated module structure
- forcing_
theory - Auto-generated module structure
- formal_
languages - Auto-generated module structure
- formal_
verification - Auto-generated module structure
- functional_
analysis - Auto-generated module structure
- functional_
calculus - Auto-generated module structure
- functional_
programming - Auto-generated module structure
- functor
- Auto-generated module structure
- fuzzy_
logic - Auto-generated module structure
- game_
theory - Auto-generated module structure
- game_
theory_ ext - Auto-generated module structure
- geometric_
group_ theory - Auto-generated module structure
- geometric_
measure_ theory - Auto-generated module structure
- graph
- Auto-generated module structure
- groebner_
bases - Auto-generated module structure
- group_
theory - Auto-generated module structure
- harmonic_
analysis - Auto-generated module structure
- hashmap
- Auto-generated module structure
- hashset
- Auto-generated module structure
- higher_
category_ theory - Auto-generated module structure
- homological_
algebra - Auto-generated module structure
- homological_
computations - Auto-generated module structure
- homotopy_
theory - Auto-generated module structure
- homotopy_
type_ theory - Auto-generated module structure
- information_
geometry - Auto-generated module structure
- information_
theoretic_ security - Auto-generated module structure
- information_
theory - Auto-generated module structure
- information_
theory_ ext - Auto-generated module structure
- int
- Auto-generated module structure
- intersection_
theory - Auto-generated module structure
- io
- Auto-generated module structure
- iwasawa_
theory - Auto-generated module structure
- k_
theory - Auto-generated module structure
- knot_
theory - Auto-generated module structure
- lambda_
calculus - Auto-generated module structure
- lattice_
theory - Auto-generated module structure
- lazy
- Auto-generated module structure
- lie_
theory - Auto-generated module structure
- linear_
algebra - Auto-generated module structure
- linear_
logic - Auto-generated module structure
- linear_
programming - Auto-generated module structure
- list
- Auto-generated module structure
- logic
- Auto-generated module structure
- low_
dimensional_ topology - Auto-generated module structure
- machine_
learning - Auto-generated module structure
- mathematical_
ecology - Auto-generated module structure
- mathematical_
physics - Auto-generated module structure
- measure_
theory - Auto-generated module structure
- mechanism_
design - Auto-generated module structure
- modal_
logic - Auto-generated module structure
- model_
checking - Auto-generated module structure
- model_
theory - Auto-generated module structure
- modular_
forms - Auto-generated module structure
- monad
- Auto-generated module structure
- motivic_
cohomology - Auto-generated module structure
- nat
- Auto-generated module structure
- network_
theory - Auto-generated module structure
- noncommutative_
geometry - Auto-generated module structure
- nonstandard_
analysis - Auto-generated module structure
- number_
theory - Auto-generated module structure
- numerical_
analysis - Auto-generated module structure
- numerical_
linear_ algebra - Auto-generated module structure
- observational_
type_ theory - Auto-generated module structure
- operations_
research - Auto-generated module structure
- operator_
algebras - Auto-generated module structure
- optimization_
theory - Auto-generated module structure
- option
- Auto-generated module structure
- ord
- Auto-generated module structure
- order
- Auto-generated module structure
- order_
topology - Auto-generated module structure
- ordering
- Auto-generated module structure
- padic_
analysis - Auto-generated module structure
- padic_
hodge_ theory - Auto-generated module structure
- parameterized_
complexity - Auto-generated module structure
- parametricity
- Auto-generated module structure
- parsec
- Auto-generated module structure
- pde_
theory - Auto-generated module structure
- point_
free_ topology - Auto-generated module structure
- point_
set_ topology - Auto-generated module structure
- post_
quantum_ crypto - Auto-generated module structure
- probabilistic_
programming - Auto-generated module structure
- probability
- Auto-generated module structure
- prod
- Auto-generated module structure
- program_
logics - Auto-generated module structure
- program_
synthesis - Auto-generated module structure
- proof_
mining - Auto-generated module structure
- proof_
theory - Auto-generated module structure
- prop
- Auto-generated module structure
- quantum_
computing - Auto-generated module structure
- quantum_
error_ correction - Auto-generated module structure
- quantum_
field_ theory - Auto-generated module structure
- quantum_
information - Auto-generated module structure
- quotient_
types - Auto-generated module structure
- random_
matrix_ theory - Auto-generated module structure
- range
- Auto-generated module structure
- rbtree
- Auto-generated module structure
- real
- Auto-generated module structure
- repr
- Auto-generated module structure
- representation_
theory - Auto-generated module structure
- result
- Auto-generated module structure
- reverse_
mathematics - Auto-generated module structure
- rough_
set_ theory - Auto-generated module structure
- session_
types - Auto-generated module structure
- set
- Auto-generated module structure
- set_
theory_ zfc - Auto-generated module structure
- sheaf_
theory - Auto-generated module structure
- show
- Auto-generated module structure
- sigma
- Auto-generated module structure
- social_
choice_ theory - Auto-generated module structure
- spectral_
methods - Auto-generated module structure
- spectral_
theory - Auto-generated module structure
- static_
analysis - Auto-generated module structure
- statistical_
learning - Auto-generated module structure
- statistical_
mechanics - Auto-generated module structure
- stochastic_
control - Auto-generated module structure
- stochastic_
processes - Auto-generated module structure
- stream
- Auto-generated module structure
- string
- Auto-generated module structure
- string_
theory_ basics - Auto-generated module structure
- sum
- Auto-generated module structure
- surreal_
numbers - Auto-generated module structure
- symplectic_
geometry - Auto-generated module structure
- systems_
biology - Auto-generated module structure
- tactic_
lemmas - Auto-generated module structure
- tauberian_
theory - Auto-generated module structure
- temporal_
logic - Auto-generated module structure
- term_
rewriting - Auto-generated module structure
- thunk
- Auto-generated module structure
- topological_
data_ analysis - Auto-generated module structure
- topological_
quantum_ computation - Auto-generated module structure
- topology
- Auto-generated module structure
- topology_
ext - Auto-generated module structure
- topos_
theory - Auto-generated module structure
- tropical_
geometry - Auto-generated module structure
- type_
inference_ algorithms - Auto-generated module structure
- type_
theory - Auto-generated module structure
- type_
theory_ advanced - Auto-generated module structure
- universal_
algebra - Auto-generated module structure
- variational_
analysis - Auto-generated module structure
- variational_
calculus - Auto-generated module structure
- vec
- Auto-generated module structure
- wellfounded
- Auto-generated module structure
Structs§
- BitSet64
- A fixed-size bit set backed by a single
u64. Supports positions 0..63. - Counter
- A monotonically increasing counter, useful for generating fresh variable IDs.
- Diagnostic
- A single compiler diagnostic.
- Diagnostic
Bag - Accumulator for multiple diagnostics.
- Directed
Graph - A directed graph with
nnodes, represented as an adjacency list. - Fresh
Name Gen - Generates fresh name strings of the form
prefix_N. - Located
- A value annotated with a
Span. - MinHeap
- A min-heap priority queue.
- Module
Dep - A dependency pair: (dependent, dependency).
- Multi
Map - A simple multi-map: each key may map to multiple values.
- Name
Table - A simple string-interning table backed by a
Vec. - Scope
Table - A scoped symbol table supporting nested scopes.
- Span
- Utility type for carrying source-location metadata.
- StdEntry
- A record of a single OxiLean standard library theorem or definition that the elaborator knows about.
- StdFeatures
- Feature flags for optional standard library components.
- StdLib
Stats - Standard library module statistics.
- StdModule
Entry - A registry entry describing one standard library module.
- StdVersion
- Version information for the OxiLean standard library.
- String
Set - A set of
Stringvalues backed by a sortedVecfor deterministic output. - Trie
- A simple trie mapping byte strings to values.
Enums§
- Build
Phase - Represents a phase in the standard library build process.
- Diagnostic
Level - Severity levels for compiler diagnostics.
- StdCategory
- A category tag for standard library modules.
Constants§
- STD_
KNOWN_ ENTRIES - A representative sample of well-known standard library entries.
- STD_
VERSION - OxiLean standard library version string.
Statics§
- CORE_
DEPS - Minimal dependency graph for core standard library modules.
- STD_
MODULE_ REGISTRY - Inventory of all standard library modules.
Functions§
- all_
modules - Get all modules.
- all_
theorems - Return all theorems (non-definitions) in the standard library sample.
- count_
default_ modules - Count how many modules are loaded by default.
- count_
total_ modules - Count total number of registered standard library modules.
- default_
modules - Get all default-loaded modules.
- dependents_
of - Get all modules that depend on the given module.
- direct_
deps - Get all dependencies of a named module (direct only).
- entries_
in_ module - Return all entries from a given module.
- find_
module - Look up a module entry by its qualified name.
- lookup_
std_ entry - Look up a standard library entry by its qualified name.
- module_
category - Map a module name to its
StdCategory. - modules_
for_ phase - Get all module entries for a specific build phase.
- topological_
sort_ modules - Compute a topological ordering of modules based on
CORE_DEPS.