Release context: Current released language surface Language coverage: Core language, the language-completeness contract, the epistemic solver surface, epistemic executor completion (EIR-derived candidate enumeration, value-level modal membership, per-tuple-key FAEEL foundedness, ground epistemic constraints, safe split, and joint multi-epistemic solving), and semantic completion (mixed global+per-row modal gates compose conjunctively; finite nested modal chains normalize by parity/duality; same-name multi-arity disambiguates by arity-qualified tuple sources; recursive execution covers determined stratification, positive Gelfond 1991 compatibility recursion, stratified negated modals, and cyclic negated modals through theThis document provides a comprehensive reference for the XLOG language, covering all syntax, semantics, and features of XLOG as a GPU-native logic programming language. The language-completeness additions define the contract for finite terms, lists, safe meta-predicates, deterministic negation, magic sets, probabilistic aggregates, approximate inference, and CLI inspectability. The epistemic source surface addsxlog-gpuGPU-backed WFS plan without the oldxlog_probhost-WFS solver; only genuinely unbounded, unsafe, or unfounded modal cycles remain fail-closed)
know, possible,
not know, not possible, and #pragma epistemic_mode = faeel|g91.
Accepted epistemic programs route through the high-level EIR and GPU epistemic
runtime; unsupported forms must fail with typed diagnostics rather than
silently falling back to CPU evaluation.
Table of Contents
- Overview
- Basic Syntax
- Data Types
- Language Completeness Contract
- Predicates and Declarations
- Facts
- Rules
- Queries
- Constraints
- Variables and Wildcards
- Comparisons
- Arithmetic Expressions
- Negation
- Aggregations
- Lists
- Safe Meta-Predicates
- Magic Sets
- User-Defined Functions
- Modules
- Symbols
- Probabilistic Logic
- Epistemic Logic
- Approximate Inference
- Neural Predicates
- Learnable Rules
- Term Embeddings
- GPU ILP Configuration
- Pragmas and Directives
- CLI Developer Experience
- Float Predicates and IEEE 754 Semantics
- Comments
- Complete Grammar Reference
Overview
XLOG is a GPU-native logic programming language that compiles typed, modular logic programs into backend-specific GPU execution paths. It supports:- Datalog fundamentals: Facts, rules, recursive queries, and stratified negation
- Arithmetic operations: Comparisons, computed values via
is, and built-in functions - Aggregations:
count,sum,min,max, andlogsumexp - Probabilistic reasoning: Probabilistic facts, annotated disjunctions, evidence, and queries
- Epistemic reasoning:
know/possiblemodal body literals, FAEEL default semantics, and Gelfond 1991 compatibility mode through explicit EIR/GPU execution paths - Language-completeness contract: Finite lists, safe meta-predicates, explicit negation contracts, magic-set planning, probabilistic aggregate semantics, approximate inference configuration, incremental parsing, and CLI inspectability
- GPU execution: All core operations (joins, sorts, aggregations) run on the GPU
Hello World Example
Basic Syntax
Program Structure
An XLOG program consists of a sequence of statements. Each statement ends with a period (.).
Statement Types
| Statement | Syntax | Description |
|---|---|---|
| Predicate declaration | pred name(types). | Declares a predicate with typed columns |
| Fact | name(values). | Asserts a ground tuple |
| Rule | head :- body. | Derives new facts from existing ones |
| Query | ?- atom. | Specifies output relations |
| Constraint | :- body. | Asserts that body must have no solutions |
| Function | func name(params) = expr. | Defines a user function |
| Use | use module. | Imports predicates from a module |
| Domain | domain name: type. | Declares a domain type |
| Pragma | #pragma key = value | Sets compiler/runtime options |
Identifiers
- Predicates and atoms: Start with a lowercase letter, followed by alphanumerics or underscores (
edge,reach_from,node2) - Variables: Start with an uppercase letter, followed by alphanumerics or underscores (
X,Node,Value1) - Anonymous variable: A single underscore (
_) matches any value without binding
Data Types
XLOG supports the following scalar types:| Type | Description | Range |
|---|---|---|
u32 | Unsigned 32-bit integer | 0 to 4,294,967,295 |
u64 | Unsigned 64-bit integer | 0 to 18,446,744,073,709,551,615 |
i32 | Signed 32-bit integer | -2,147,483,648 to 2,147,483,647 |
i64 | Signed 64-bit integer | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
f32 | 32-bit floating point | IEEE 754 single precision |
f64 | 64-bit floating point | IEEE 754 double precision |
bool | Boolean | true or false |
symbol | Interned string | Reversible u32 ID with string table |
Literals
Type Inference
Types are inferred from predicate declarations. All uses of a predicate must be consistent with its declared types.Language-Completeness Type Forms
The language-completeness contract extends the type model with finite language-level terms that must lower to typed relation layouts before execution:| Type form | Meaning | Execution status |
|---|---|---|
domain name: type | Named alias for an existing scalar type | Existing source form; the contract requires alias preservation in diagnostics and schema metadata |
column: type | Named predicate column | Named predicate columns are accepted and preserved in schema metadata |
list<T> | Finite homogeneous list of T | Accepted lists lower to helper relations, not CPU term heaps |
term | Finite ground term value | Only finite, typed terms are accepted |
compound | Finite compound term with functor and arity | Unsupported recursive or open compounds are rejected |
predref | Static predicate reference for maplist and related meta use | Runtime-variable predicate names are rejected |
Language Completeness Contract
The language-completeness contract is a language-surface expansion over the core runtime. New syntax is accepted only when it can be normalized into the existing typed AST, RIR, probabilistic IR, optimizer, runtime, WCOJ, and CLI paths.Execution Responsibilities
| Layer | Allowed work |
|---|---|
| Parser and AST | Recognize source syntax, preserve spans, and represent finite high-level terms |
| Semantic analysis | Type check, safety check, reject unbounded or dynamic forms, and desugar high-level constructs |
| Optimizer and planner | Rewrite programs, including magic sets, while preserving output semantics |
| Runtime, epistemic, and probability engines | Execute accepted relational, epistemic, aggregate, exact, and MC work through production GPU-capable paths |
| CLI | Orchestrate commands, format diagnostics, and transfer only requested final results |
Feature Coverage Matrix
| Feature | Syntax | Semantics | Example | Unsupported forms | Execution path |
|---|---|---|---|---|---|
| Incremental parsing | Statement-level .xlog source units with stable spans | Reuse unchanged statement parses and invalidate changed statements plus dependent module state | Editing one rule in a REPL/watch session preserves parse cache for unchanged facts | Cache reuse across changed module dependencies without invalidation | Parser/session cache only; no runtime execution |
| List syntax and built-ins | [], [A, B], [H|T], list<T> | Finite, typed lists normalize to helper relations | has_member(X) :- member(X, [1,2,3]). | Open-ended generators, cyclic lists, heterogeneous lists without a declared finite term type | AST/desugar to typed helper relations and normal runtime joins/aggregates |
| Safe meta-predicates | ground, var, nonvar, functor, =.., findall, maplist | Static inspection and finite collection only | xs(L) :- findall(X, edge(1, X), L). | Unrestricted call/N, dynamic database mutation, runtime-variable predicate names | Compile-time/static expansion plus typed relational lowering |
| Deterministic NAF | not atom(...) | Closed-world stratified negation over deterministic relations; named variables in the negated atom must be bound by a prior source-order binder | leaf(X) :- node(X), not edge(X, _). | Unbound variables in negated atoms, unstratified deterministic cycles | Existing stratification and runtime anti-join paths |
| Magic sets | #pragma magic_sets = on|off|auto and compiler configuration override | Bound deterministic recursive queries may be rewritten with adornments and magic predicates | ?- reach(1, Y). specializes recursive reachability | Unsafe interaction with negation, aggregates, meta/list helpers, mutual recursion, or SIPS cases if equivalence cannot be proven | Source/RIR rewrite before optimizer and WCOJ planning |
| Probabilistic aggregates | Aggregate heads and aggregate outputs in query/evidence | Finite aggregate outcomes in exact and MC inference | query(out_degree(1, 2)). over probabilistic edge facts | Exact aggregate domains over cap, unsupported numeric operator/domain pairs | Exact provenance/PIR or MC sampling plus deterministic aggregate execution |
| Aggregate lifting | Finite-domain aggregate metadata and caps | Use lifted compact-domain computation when identical to finite exact enumeration | Small count/sum domains avoid naive enumeration | Domain cap exceeded, non-finite domains, unsupported floating tolerance | Probabilistic aggregate planner and exact/MC engines |
| Approximate inference | #pragma prob_engine = mc, samples, seed, confidence, method | MC estimates are reproducible under fixed seed and report uncertainty | #pragma prob_samples = 10000 with query(rain). | Invalid confidence ranges, unsupported methods, hidden default override ambiguity | Existing MC engine with documented source/CLI precedence |
| Epistemic literals | know atom(...), possible atom(...), not know atom(...), not possible atom(...), finite nested modal chains, #pragma epistemic_mode = faeel|g91 | Modal literals are preserved in EIR; the epistemic executor derives candidate worlds from EIR, checks value-level tuple-key membership, normalizes finite nested chains by parity/duality, solves same-name multi-arity by arity-qualified tuple sources, supports determined-head stratification, positive Gelfond 1991 compatibility recursion, stratified negated-modal recursion, and cyclic negated-modal recursion through the xlog-gpu GPU-backed WFS plan without the old xlog_prob host-WFS solver. This is not a device-resident/no-host-interaction WFS residency claim; host orchestration and metadata convergence reads may still occur. | accepted() :- know fact(). | Direct raw RIR lowering, genuinely unbounded/untyped modal tuple keys, unsafe unbound negated epistemic variables, CPU-only world-view scans, and genuine modal cycles without a founded order | Parser/AST -> EIR -> epistemic GPU executable plans, reduced ordinary plans, or GPU-backed WFS alternating-fixpoint plans through high-level xlog run dispatch |
| CLI explain | xlog explain --format text|json|dot file.xlog | Show parse, strata, RIR, optimized RIR, magic-set, WCOJ, and probability sections when applicable | xlog explain --format json reach.xlog | Unknown output formats or unavailable sections without a typed reason | CLI orchestration plus compiler/explain APIs |
| CLI REPL | xlog repl | Interactive multiline fact/rule/query session using parser cache | Add facts, then query relation state | GPU execution before a command requests it, unsupported mutation semantics | CLI session cache plus normal compile/run on submitted programs |
| CLI watch | xlog watch file.xlog | Rerun or re-explain changed files with debounce and typed diagnostics | Edit a rule and see updated diagnostics/output | Silent stale cache reuse after file/module change | CLI file watcher plus parser/session cache and normal commands |
Diagnostic Contract
Unsupported language-completeness and epistemic forms must report:- the feature area, such as
list,meta,naf,magic_sets,prob_aggregate, orepistemic; - the source span when available;
- the reason the form is unsafe, unbounded, or not GPU-lowerable;
- a remediation, such as adding a positive binder, a finite cap, or a static predicate reference.
Source-Audit Status
The historic documentation-reference checkpoint is retained by the language-completeness rows above. Current source accepts the epistemic literals andepistemic_mode pragma listed
here and routes accepted epistemic examples through xlog run. The epistemic
executor adds EIR-derived candidate enumeration, value-level modal
membership, per-tuple-key FAEEL foundedness, ground and variable-keyed epistemic
integrity constraints, safe split equivalence, same-name multi-arity
disambiguation, finite nested-chain normalization, determined-head
stratification, positive Gelfond 1991 compatibility recursion, stratified negated-modal
recursion, and cyclic negated-modal recursion through the xlog-gpu
GPU-backed WFS plan without the old xlog_prob host-WFS solver.
The remaining unsupported epistemic boundaries are
direct raw RIR lowering, genuinely unbounded/untyped modal tuple keys, unsafe
unbound negated epistemic variables, CPU-only world-view scans, unimplemented
cyclic WFS shapes outside the xlog-gpu GPU-backed negated-modal WFS plan, and modal
cycles without a founded order.
Predicates and Declarations
Predicate Declarations
Predicate declarations specify the name and column types:Visibility
By default, predicates are public and can be imported by other modules. Useprivate to hide internal predicates:
Domain Declarations
Domain declarations provide semantic naming for types:Facts
Facts are ground atoms (no variables) that assert tuples exist in a relation:Numeric Facts
Rules
Rules derive new facts from existing ones. A rule has a head (the derived fact) and a body (the conditions).Simple Rules
Recursive Rules
Recursive rules derive facts that depend on themselves:Multi-Atom Bodies
Rules can have multiple atoms in the body, which are implicitly joined:Variable Binding
Variables are bound by appearing in positive atoms. The same variable name in different atoms creates a join condition:Queries
Queries specify which relations to output. Use?- followed by an atom pattern:
Constraints
Constraints assert that a condition must have no solutions. If any tuples satisfy the constraint body, execution fails:Variables and Wildcards
Named Variables
Variables start with an uppercase letter and are bound to values when matched:Anonymous Wildcard
The underscore (_) matches any value without binding. Multiple underscores in a rule are independent:
Comparisons
XLOG supports comparison operators in rule bodies:| Operator | Meaning |
|---|---|
= | Equal |
== | Equal (alternative syntax) |
!= | Not equal |
< | Less than |
<= | Less than or equal |
> | Greater than |
>= | Greater than or equal |
Examples
Explicit Equality
Use= to explicitly compare variables (in addition to implicit join):
Arithmetic Expressions
XLOG uses theis keyword for arithmetic computations. The left-hand side must be a fresh (unbound) variable.
Basic Syntax
Operators
| Category | Operators |
|---|---|
| Binary | +, -, *, /, % (modulo) |
| Precedence | *, /, % bind tighter than +, - |
| Parentheses | Override precedence with (...) |
Built-in Functions
| Function | Description | Return Type |
|---|---|---|
abs(X) | Absolute value | Same as input |
min(X, Y) | Minimum of two values | Same as inputs |
max(X, Y) | Maximum of two values | Same as inputs |
pow(X, Y) | X raised to power Y | f64 |
cast(X, type) | Type conversion | Specified type |
Examples
Type Casting
Type casting is explicit in XLOG. Usecast(expr, type):
Division and Error Handling
| Condition | Integer Behavior | Float Behavior |
|---|---|---|
| Division by zero | Returns INT64_MAX | Returns NaN or Inf |
| Overflow | Wraps (standard semantics) | IEEE 754 behavior |
Negation
XLOG supports deterministic negation as failure using thenot keyword.
In deterministic programs, not atom(...) is closed-world, stratified
negation. This is distinct from probabilistic nonmonotone negation, where exact
inference may use Well-Founded Semantics (WFS) for accepted probabilistic
programs.
Syntax
Examples
Stratification Requirements
Negation must be stratifiable: there cannot be a cycle where a predicate depends on its own negation. Valid (stratifiable):negation safety error. Low-level stratification analysis still reports the
underlying dependency cycle for callers that use it directly.
Domain Safety
Named variables in negated atoms must be bound by a prior source-order binder in the same rule body. Positive atoms bind their named variables, and a deterministicis expression binds its target after the expression appears.
Source order matters: a later positive atom does not make an earlier negated
atom safe. Use _ for existential positions inside negated atoms.
Aggregations
Aggregations compute summary values over groups of tuples.Supported Aggregates
| Aggregate | Description | Input Types | Output Type |
|---|---|---|---|
count(X) | Count of values | Any | u64 |
sum(X) | Sum of values | u32 | u64 |
min(X) | Minimum value | u32 | u32 |
max(X) | Maximum value | u32 | u32 |
logsumexp(X) | Log-sum-exp (numerically stable) | f64 | f64 |
Syntax
Aggregates appear in the rule head. Variables not in the aggregate form the grouping key:Examples
Multi-Key Aggregation
Multiple Aggregates
Computing Averages
XLOG does not have a built-inavg aggregate. Compute it using sum and count:
Log-Sum-Exp Aggregation
For probabilistic and numerical applications,logsumexp computes log(sum(exp(values))) in a numerically stable way:
Lists
The language-completeness contract defines finite list syntax and list built-ins. Lists are accepted only when they are finite and typed; accepted programs lower to relation layouts and normal GPU-capable execution paths. Current finite-list implementation status: scalar, symbol, nested finite list, and finite meta term IDs are normalized tou64 list identifiers plus
__xlog_list_* helper relations. list<T> predicate columns lower to scalar
list-id columns while helper relations carry length, item, cons, append, sort,
msort, and set facts. The current implementation accepts finite literals,
declared list<T> columns, safe [Head | Tail] patterns in declared list
columns, and the built-ins below when their list argument has a finite literal
or a known list<T> type.
Syntax
Built-Ins
| Built-in | Contract |
|---|---|
is_list(X) | Succeeds when X is a finite list value |
member(X, L) | Enumerates or checks finite membership |
memberchk(X, L) | Deterministic membership check |
length(L, N) | Computes the finite list length |
nth(N, L, X) | Binds/checks zero-based element N |
append(A, B, C) | Concatenates finite lists when at least two sides are bound enough to avoid generation |
sort(L, S) | Sorts finite list values with duplicate removal |
msort(L, S) | Sorts finite list values preserving duplicates |
list_to_set(L, S) | Removes duplicates while producing a finite normalized list |
append(A, B, C)accepts finite first and second list literals in this node; split generation such asappend(A, B, [1,2,3])is rejected as unbounded;sort,msort, andlist_to_setrequire a finite input literal in this node;term,compound, andpredreflist elements lower to finiteu64meta term IDs when they appear in declaredlist<term>,list<compound>, orlist<predref>contexts.
Examples
Unsupported Forms
The following forms are outside the finite-list contract:- unbounded list generation, such as asking
append(A, B, [1,2,3])to enumerate every split unless a finite split mode is explicitly implemented; - cyclic lists;
- heterogeneous lists unless represented through a declared finite
termdomain; - list evaluation that requires an arbitrary CPU Prolog term heap.
Safe Meta-Predicates
Safe meta-predicates provide finite term inspection and static predicate mapping. They do not introduce an unrestricted Prolog dynamic database or unrestrictedcall/N.
Current safe-meta implementation status: accepted safe meta forms normalize
before stratification and lowering into ordinary helper relations such as
__xlog_meta_functor, __xlog_meta_univ, __xlog_meta_findall_*, and
__xlog_meta_maplist_*. Finite term, compound, and predref predicate
columns lower to u64 term IDs; compound metadata and univ parts are stored in
typed helper relations. findall and maplist currently accept finite source
facts and finite list literals only; derived-goal collection and non-literal
maplist inputs are explicitly rejected until an aggregate-backed collection
path lands.
Supported Meta-Predicates
| Predicate | Contract |
|---|---|
ground(Term) | True when the term is fully ground after static analysis or finite binding |
var(Term) | True only at the supported static/runtime boundary for unbound variables |
nonvar(Term) | True when Term is known not to be a variable |
functor(Term, Name, Arity) | Inspects or checks a finite compound term’s functor and arity |
Term =.. Parts | Converts between finite compound terms and a finite [Functor, Args...] list |
findall(Template, Goal, List) | Collects finite goal results into a normalized list relation; empty result succeeds with [] |
maplist(PredRef, List) | Statically expands a unary predicate reference over a finite list |
maplist(PredRef, ListA, ListB) | Statically expands a binary predicate reference over aligned finite lists |
Examples
Unsupported Forms
- runtime-variable predicate names in
maplistor any future call-like form; assert,retract, dynamic database mutation, or IO predicates;findallover derived goals or goals with variables that are neither bound beforefindallnor collected by the template;- non-literal
maplistinputs in the current safe-meta subset; - constructing recursive or open compound terms with
=..; - higher-arity
maplistunless explicitly implemented and tested.
Magic Sets
Magic-set rewriting specializes bound deterministic recursive queries by adding derived magic predicates and adorned rules before optimization. The accepted accepted magic-set subset is a source-level rewrite over positive recursive rules that can be proven query-equivalent under the supported left-to-right SIPS.Configuration
auto lets the compiler apply the rewrite only when it can prove that the
transformed program preserves query output. on requests the rewrite and fails
with a typed magic_sets error if the compiler cannot safely apply it.
off disables the rewrite.
Example
1 may seed a magic predicate so recursive evaluation
does not materialize unreachable source components. xlog explain must show
the adornment, generated magic predicates, and any declined-rewrite reason.
The compiler currently emits helper predicates such as
__xlog_magic_reach_bf, where b marks a bound argument and f marks a free
argument. Accepted rules continue through the normal AST, stratification,
lowering, optimizer, WCOJ, and runtime paths.
Supported Subset
- deterministic programs with
?-queries over recursive predicates; - at least one scalar constant in the queried recursive atom;
- positive recursive rules over the same head predicate;
- source-order binding propagation through prior positive body atoms;
auto,on, andoffsource pragmas.
Declined Forms
auto leaves the program unchanged and records a decline reason. on fails
with a typed diagnostic for:
- unbound recursive calls under the supported SIPS;
- rules with negation, aggregation, comparison,
is, or unnormalized univ in the recursive target; - recursive rules that cross language-completeness list/meta helper predicates;
- mutual-recursive SCCs in the current subset;
- probabilistic profiles, which remain governed by the probabilistic engine.
Unsupported Forms
Magic-set rewriting must decline or fail before execution when negation, aggregates, list/meta constructs, or probabilistic rules would make equivalence uncertain. It must not create a runtime side engine.User-Defined Functions
XLOG supports user-defined functions for reusable calculations.Basic Functions
Conditional Functions
Useif-then-else for conditional logic:
Recursive Functions
Functions can be recursive but must have a base case:Using Functions in Rules
Functions can be called in rule bodies using theis expression or direct call syntax:
Type Annotations
Optional type annotations for documentation and checking:Private Functions
Functions can be marked private:Modules
XLOG supports organizing code into modules for reusability and encapsulation.Creating Modules
A module is a.xlog file. The filename (without extension) becomes the module name:
Importing Modules
Use theuse statement to import predicates from modules:
Module Paths
Module paths use/ as the separator:
Visibility and Encapsulation
Predicates and functions are public by default. Useprivate to hide implementation details:
Symbols
Symbols are interned strings, represented internally as integers for efficient comparison and storage.Declaring Symbol Types
Symbol Literals
Symbol literals are written as identifiers (lowercase) or as string literals:Querying Symbols
Symbols are displayed as their original string values in query output:Symbol Comparison
Symbols can be compared for equality:Reversible Symbols
Symbols are reversible: the original string value is preserved and displayed in query output. Symbols are stored internally asu32 IDs with a
bidirectional mapping to strings.
Probabilistic Logic
XLOG supports probabilistic Datalog for reasoning under uncertainty.Probabilistic Facts
Probabilistic facts are Bernoulli random variables with a specified probability:Annotated Disjunctions
Annotated disjunctions represent categorical distributions (mutually exclusive outcomes):Deterministic Rules with Probabilistic Facts
Rules can derive facts from probabilistic facts:Evidence
Evidence constrains the probabilistic model to worlds consistent with observations:Probabilistic Queries
Usequery to compute the probability of an atom:
Complete Probabilistic Example
Inference Engines
XLOG supports two inference engines:| Engine | Flag | Description |
|---|---|---|
| Exact | --prob-engine exact_ddnnf | Knowledge compilation via Decision-DNNF; exact probabilities |
| Monte Carlo | --prob-engine mc | Sampling-based; approximate with confidence intervals |
- Stratified deterministic negation: Automatic layer detection and
two-valued evaluation for deterministic
not atomprograms - Probabilistic non-monotone negation: Well-Founded Semantics (WFS) for accepted cyclic probabilistic programs
- Finite probabilistic aggregates:
count,sum,min,max, andlogsumexpaggregate outputs compiled through provenance/PIR when the exact finite domain cap is respected - Gradients: Correct gradient flow through negated literals
count, sum, min, max,
and logsumexp aggregate programs are supported for exact and MC inference in
the finite probabilistic-aggregate subset. Exact mode enumerates finite aggregate
outcomes into provenance/PIR formulas, so query and evidence may reference
aggregate output tuples. Exact enumeration is capped at 16 uncertain
contributing rows per group; cap excess fails with a typed
prob_aggregate error that recommends MC or reducing the finite domain.
Monte Carlo supports probabilistic rules and non-monotone recursion.
The production MC path is the GPU-resident megakernel engine, which rejects
negation, aggregates, and other unbounded constructs with a typed
ResidentRejection. Programs in that fragment (including non-monotone
recursion and language-completeness probabilistic aggregates under MC) require an explicit
opt-in to the labeled CPU oracle — --allow-cpu-oracle on the CLI,
allow_cpu_oracle=True in Python, McEvalConfig::allow_cpu_oracle_fallback
in Rust — and their results carry mc_engine = "cpu-oracle". Without the
opt-in, such programs fail closed with the typed rejection (corrected
2026-06-10; previously this fallback was silent and unlabeled):
Probabilistic Aggregates
Finite probabilistic aggregate programs may query or condition on aggregate outputs:count(..., 0) tuples. MC mode samples worlds on the GPU and
executes the shared deterministic aggregate path for each accepted sample batch.
Aggregate Lifting
Small-domain aggregate lifting is permitted only when the lifted computation is semantically identical to finite exact enumeration. Explain output must report the detected finite domain, cap, operator, and whether lifting fired, declined, or fell back to supported exact enumeration. In the aggregate-lifting subset, finite probabilisticcount aggregate heads use
exact cardinality dynamic programming when every aggregate expression in the
head is count(...). The lift constructs formulas for exactly k contributing
rows over the same row-presence formulas used by finite enumeration, so it does
not change exact semantics. The count lift accepts up to 64 uncertain rows per
group; larger count domains fail closed with a typed agg_lift error.
sum, min, max, and logsumexp remain on exact finite outcome enumeration
in this subset. Their explain entries report fallback_exact_enumeration with a
per-operator rationale and continue to use the 16-uncertain-row exact aggregate
cap. xlog explain --format json emits an aggregate_lifting array containing
the predicate, group key, operator, finite-domain source, domain size, cap,
status, reason, naive outcome count, and dynamic-programming state count.
Monte Carlo Sampling Methods
The Monte Carlo engine supports two sampling methods:| Method | Description |
|---|---|
Rejection | Sample from the prior and discard worlds where evidence is not satisfied. |
EvidenceClamping | Force evidence variables directly in the CUDA sampler when the evidence is forceable at the probabilistic-fact / positive-AD level. |
Negation in Probabilistic Programs
Probabilistic exact inference supports both stratified probabilistic negation and accepted non-monotone WFS profiles:Probabilistic Recursion
Probabilistic facts can be used with recursive rules:Pragma for Engine Selection
The inference engine can be specified in the source file:Epistemic Logic
Epistemic logic is part of the accepted source surface. Epistemic logic adds modal body literals for bounded knowledge and possibility reasoning. Modal literals are valid in rule bodies and use the same atom syntax as ordinary predicates.Modal Literals
| Form | Meaning |
|---|---|
know atom(...) | The atom must hold in every accepted world/model. |
possible atom(...) | The atom must hold in at least one accepted world/model. |
not know atom(...) | The atom is not known in every accepted world/model. |
not possible atom(...) | The atom is absent from every accepted world/model. |
know possible fact(),
not know possible fact(), and know not possible fact() are accepted program
forms. The parser normalizes them to a single epistemic literal by the semantic
parity/duality rules: the operator adjacent to the atom determines the modal
operator, while leading/interior/atom-adjacent not tokens dualize or negate
the resulting literal according to their position.
Epistemic Mode Pragma
faeel is the default epistemic mode when no pragma is present. g91 is an
explicit compatibility mode for programs that need Gelfond 1991 possibility behavior.
Runtime Boundary
Accepted epistemic programs enter EIR throughxlog_logic::build_eir and run
through the high-level xlog run / xlog_gpu::LogicProgram dispatch path. That
path lowers accepted programs into epistemic GPU executable plans. Direct
ordinary RIR lowering of raw epistemic body literals remains a rejection
boundary and must report UnsupportedEpistemicConstruct.
Examples
FAEEL default knowledge:Approximate Inference
Approximate inference is the source and CLI contract for Monte Carlo probabilistic reasoning. It must be reproducible under a fixed seed and must report uncertainty, sample counts, evidence handling, and sampling method.Source Pragmas
| Pragma | Meaning |
|---|---|
prob_samples | Number of MC samples |
prob_seed | Fixed random seed; identical input plus seed must replay identical counts |
prob_confidence | Confidence level for reported intervals |
prob_method | Sampling method, such as rejection or evidence_clamping |
prob_max_nonmonotone_iterations | Bound for nonmonotone WFS/MC iteration where applicable |
xlog prob uses source #pragma prob_engine = mc
when --prob-engine is not supplied. CLI flags override source pragmas
field-by-field: --samples, --seed, --confidence, --prob-method, and
--prob-max-nonmonotone-iterations replace only their matching source values.
--output json emits a machine-readable MC report with the same probability,
standard-error, confidence-interval, sample-count, evidence-count, seed,
confidence, and sampling-method fields as the pretty/csv batch output.
Output Contract
Approximate output formats must include:- probability estimate;
- standard error;
- confidence interval low/high;
- sample count;
- evidence count or acceptance/clamping count;
- seed and method.
Neural Predicates
Neural predicate declarations embed a neural network directly into an XLOG program as a first-class predicate.Declaration Forms
Classification (nn/4):
nn/3):
Arguments
| Position | Meaning |
|---|---|
network_name | Python-side registration name |
[InputVar, ...] | Input variables passed to the forward pass |
OutputVar | Predicted label or dense embedding output |
[label1, ...] | Label set for nn/4 declarations |
atom | Predicate template instantiated by the declaration |
Lowering
Fornn/4, the network output is treated as a label distribution and lowered
to probabilistic facts that enter the inference pipeline. For nn/3, the
network output is a dense tensor bound into the program and used through the
embedding APIs.
Example: MNIST Classification
Example: Embedding Mode
Cross-Registration Validation
Classification declarations (nn/4) require register_network(). Embedding
declarations (nn/3) require register_embedding(). Reusing the same name
across both forms is rejected.
Learnable Rules
Learnable rules are the source-level surface for differentiable ILP. A rule is gated by a named mask tensor:Training API
Multiple Learnable Rules
Cross-References
architecture/dilp-training.mdarchitecture/rfc-tensorized-ilp.mdarchitecture/python-bindings.md
Term Embeddings
Term embeddings associate dense vectors with discrete logic terms.register_embedding()
forward_embedding()
nn.Embedding, gradients remain attached; for frozen tensors they do
not.
Current scope: explicit training-side embedding registration and batched
lookup are supported. Rule-level embedding inference remains deferred.
GPU ILP Configuration
The GPU-resident ILP path exposes runtime configuration and telemetry through Python.coo_chunk_budget
Controls the per-chunk temporary allocation ceiling used during sparse COO
construction on GPU:
coo_memory_cap naming is deprecated.
host_transfer_stats()
Training APIs expose transfer telemetry so strict zero device-to-host workflows can verify
that the hot path stayed device-resident:
Pragmas and Directives
Pragmas configure compiler and runtime behavior. The current source grammar acceptsprob_engine, prob_cache,
epistemic_mode, max_recursion_depth, magic_sets, and the MC configuration
pragmas below. The language-completeness rows remain contract-backed where they depend on
finite-list, safe-meta, magic-set, probability, and CLI nodes; the epistemic mode pragma is accepted for the epistemic
solver surface.
Syntax
Available Pragmas
| Pragma | Values | Description |
|---|---|---|
prob_engine | exact_ddnnf, mc | Select probabilistic inference engine |
prob_cache | on, off | Enable/disable probability caching |
epistemic_mode | faeel, g91 | Select FAEEL default or Gelfond 1991 compatibility epistemic semantics |
max_recursion_depth | integer | Maximum recursion iterations |
magic_sets | auto, on, off | Control bound-recursive magic-set rewriting |
prob_samples | integer | Monte Carlo sample count |
prob_seed | integer | Monte Carlo random seed |
prob_confidence | float in (0, 1) | Monte Carlo confidence level |
prob_method | rejection, evidence_clamping | Monte Carlo sampling method |
prob_max_nonmonotone_iterations | integer | Bound nonmonotone probabilistic iteration where applicable |
Examples
CLI Developer Experience
Developer-experience commands make the language inspectable and interactive without changing the runtime execution contract.xlog explain
- parse and AST summary;
- predicate declarations and schema metadata;
- stratification and negation safety;
- RIR and optimized RIR summaries;
- magic-set adornments, generated predicates, and declined reasons;
- WCOJ eligibility and selected execution path;
- probabilistic engine, aggregate, and approximate-inference sections for probabilistic programs.
Incremental Parsing
xlog_logic::ParserSession is the shared parser cache for explain, REPL, and
watch workflows. It splits .xlog source into statement units, records stable
text hashes and byte/line spans, and reparses only changed statements through
the production parser. Cache statistics report hits, misses, invalidations,
module invalidations, statement count, and an estimated statement-unit speedup.
Module invalidation removes the changed module and cached sources that import
that module name. Incremental parse diagnostics include the original
line/column and byte span before forwarding the underlying parser error.
xlog repl
xlog watch
--once, --explain, and
--debounce-ms, using the shared parser session before any execution path.
Unsupported REPL/watch mutation semantics, such as dynamic assert or
retract, remain outside the language.
Float Predicates and IEEE 754 Semantics
XLOG uses hybrid semantics for floating-point comparisons to handle special values (NaN, Infinity, signed zero) correctly.Comparison Semantics
| Operator | Semantics | NaN Behavior |
|---|---|---|
=, != | IEEE 754 equality | NaN = NaN is FALSE |
<, <=, >, >= | Total ordering | NaN is comparable |
Total Ordering
For ordering comparisons, XLOG uses a total ordering consistent with Rust’sf64::total_cmp:
- NaN values are at the extremes (negative NaN is smallest, positive NaN is largest)
-0.0and+0.0are distinguishable in ordering (unlike IEEE equality)- All values are comparable (no undefined ordering)
Filtering NaN Values
SinceNaN != NaN under IEEE 754, use equality to filter out NaN:
Detecting Special Values
Use ordering to detect special values:Example: Data Cleaning Pipeline
Comments
XLOG supports single-line comments:/* ... */) are not supported.
Complete Grammar Reference
The following is a summary of the current XLOG grammar plus the language-completeness extensions and epistemic source surface in PEG-style notation.Lexical Elements
Types
Terms and Atoms
Expressions
Aggregates
Rules and Facts
Probabilistic Constructs
Declarations
Modules
Pragmas
CLI Examples
Program Structure
See Also
- Architecture Guide - System design and implementation details
- Language Completeness Architecture Contract - Parser, term, probability, CLI, and epistemic/solver handoff contract
- Epistemic Semantics And EIR - Epistemic source surface, EIR boundary, and GPU runtime path
- Arithmetic Expressions - Detailed
issyntax documentation - Probabilistic Tier - Exact and Monte Carlo inference
- GPU Execution - GPU-resident evaluation details
- CLI Reference - Command-line interface documentation
- Examples - Annotated example programs