A Symbolic Probabilistic Metalanguage / Probabilistic CAS
BetLang is a domain-specific language for symbolic probabilistic computation. It is not a betting language—it is a compositional system for reasoning under uncertainty, built around a minimal ternary core and an extensible tower of uncertainty-aware number systems.
At its heart is a single idea:
Computation is structured choice under uncertainty.
The fundamental primitive is the ternary form:
(bet A B C)This represents a probabilistic, lazy choice between three branches.
Unlike conventional probabilistic languages:
-
Evaluation is lazy (only the selected branch is computed)
-
Choice is first-class and compositional
-
The system is symbolic-first, not purely numeric
This makes BetLang closer to a probabilistic computer algebra system (CAS) than a simulation DSL.
-
A Symbolic Probabilistic Metalanguage (SPML)
-
A Probabilistic CAS for uncertainty-aware computation
-
A ternary computation model with lazy semantics
-
A hosted language in Racket with formalizable semantics
-
A system with a rich uncertainty-aware number tower (14 systems)
-
Not a DeFi or gambling language
-
Not just a Monte Carlo scripting tool
-
Not limited to numeric probability (supports epistemic uncertainty, intervals, belief functions, etc.)
BetLang is a multi-layer system with clearly separated responsibilities:
-
#lang betlangdefines the language -
syntax-parse+ nanopass for IR and transformations -
Lazy ternary semantics are canonical and non-negotiable
-
Optional type/refinement layer via Typed Racket / Turnstile+
This is the source of truth for semantics.
-
High-performance execution backend
-
Primary path for numerical and statistical workloads
-
Integration with:
-
Distributions.jl -
StatsBase.jl -
Random.jl -
Planned:
-
AbstractAlgebra.jl -
IntervalArithmetic.jl -
Differentiable inference via
Zygote/Enzyme
Over time, the full uncertainty number tower migrates here.
-
Used for:
-
Convergence guarantees
-
Safety properties
-
Semantic correctness proofs
-
Not part of the day-to-day compilation path
This layer ensures BetLang can become formally trustworthy.
-
(bet A B C)— primitive choice -
(bet/weighted …)— non-uniform probabilities -
(bet_conditional …)— predicate-driven selection
-
Only the chosen branch is evaluated
-
Enables symbolic and infinite structures
-
Prevents unnecessary computation
BetLang includes 14 distinct number systems for representing uncertainty:
-
Gaussian distributions n- Interval / affine arithmetic
-
Fuzzy numbers
-
Bayesian numbers
-
Risk-based numbers (VaR / CVaR)
-
Surreal and hyperreal systems
-
p-adic probability systems
-
Imprecise probabilities
-
Dempster–Shafer belief functions
These are not addons—they are the type system of the language.
See: docs/number-tower.md
BetLang distinguishes between:
-
Ternary logic (Kleene-style truth values)
-
Ternary probabilistic belief (distributional uncertainty)
This distinction is critical and formalized in:
-
docs/ternary-semantics.md
Planned unified CLI:
bet check # static + semantic validation
bet fmt # canonical formatting
bet lsp # editor integration
bet run --julia # execute via Julia backend
bet trace # execution tracing
bet hash # reproducibility / identitySee: docs/toolchain-roadmap.md
(bet 'win 'draw 'lose)(bet/weighted '(common 7) '(uncommon 2) '(rare 1))(bet (expensive-computation)
(cheap-approximation)
(fallback))Only one branch is evaluated.
-
Probabilistic programming
-
Bayesian inference
-
Uncertainty quantification
-
Symbolic statistics
-
Decision theory
-
Risk modeling
-
Scientific computing
-
Research in probabilistic semantics
BetLang is built on three principles:
-
Ternary over binary — real-world decisions are rarely yes/no
-
Uncertainty as structure — not noise, but a first-class object
-
Symbolic first — computation should remain inspectable and composable
-
Racket frontend: Authoritative
-
Julia backend: Active development
-
Lean integration: Planned / partial
-
Rust tooling: Optional / paused
BetLang uses PMPL-1.0 (Palimpsest Public License).
See LICENSE for the precise definition and terms.