Skip to content

hyperpolymath/betlang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

BetLang

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.


Core Concept

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.


What BetLang Is

  • 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)

What BetLang Is Not

  • 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.)


v1.0 Architecture

BetLang is a multi-layer system with clearly separated responsibilities:

Racket — Authoritative Frontend / Specification

  • #lang betlang defines 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.


Julia — Compute Kernel

  • 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.


Lean 4 — Proof / Export Layer

  • 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.


Rust — Optional Tooling Layer

  • Status: Paused / Non-core

  • Intended for:

  • Packaging

  • WASM targets

  • Native runtime wrappers

Rust is explicitly not part of core semantics.


Core Features

Ternary Computation

  • (bet A B C) — primitive choice

  • (bet/weighted …​) — non-uniform probabilities

  • (bet_conditional …​) — predicate-driven selection

Lazy Semantics

  • Only the chosen branch is evaluated

  • Enables symbolic and infinite structures

  • Prevents unnecessary computation

Compositionality

  • Bets compose like algebraic objects

  • Supports chaining, mapping, folding, and higher-order composition


The Real Moat: Uncertainty-Aware Number Systems

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


Semantics

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


Tooling Roadmap

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 / identity

See: docs/toolchain-roadmap.md


Example

(bet 'win 'draw 'lose)
(bet/weighted '(common 7) '(uncommon 2) '(rare 1))
(bet (expensive-computation)
     (cheap-approximation)
     (fallback))

Only one branch is evaluated.


Use Cases

  • Probabilistic programming

  • Bayesian inference

  • Uncertainty quantification

  • Symbolic statistics

  • Decision theory

  • Risk modeling

  • Scientific computing

  • Research in probabilistic semantics


Philosophy

BetLang is built on three principles:

  1. Ternary over binary — real-world decisions are rarely yes/no

  2. Uncertainty as structure — not noise, but a first-class object

  3. Symbolic first — computation should remain inspectable and composable


Status

  • Racket frontend: Authoritative

  • Julia backend: Active development

  • Lean integration: Planned / partial

  • Rust tooling: Optional / paused


License

BetLang uses PMPL-1.0 (Palimpsest Public License).

See LICENSE for the precise definition and terms.


Closing

BetLang is not about betting.

It is about making uncertainty programmable.

About

Nextgen language: betlang

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors