# Determinism: a foundational DS guarantee

A foundational language-level guarantee. DS is **deterministic
under a fixed three-tuple**: same compiled rule set, same
event trace, same platform → same observable output, every
time, byte-for-byte.

Platform is the third bound, not a footnote. Within one
platform the guarantee is absolute; **across platforms it is also
absolute** — every operation the language admits is exact or
correctly rounded (64-bit integer arithmetic, the IEEE `+ − × ÷ √`,
and the transcendentals, [LEXP.3.9.2]), so rule firing order and
every computed value are byte-identical on every conforming target.

This is not a performance property or an implementation hint.
It is a spec-level commitment the language makes to every rule
author and every tool that interacts with DS. Testing
([LTES]) and debugging ([LDEB]) both depend on
it. A runtime that cannot honour it on its own platform is not
a conforming DS runtime.

## What this is not

- Not a claim about wall-clock reproducibility. The clock is
  input, not output (see [LTES]); two runs that use the same clock schedule produce
  the same output, but wall-clock latency between two
  observable events isn't bounded by this guarantee.
- Not a claim about performance parity. Runtime-internal
  choices (scheduling, caching, Rete-memory layout) may differ
  across implementations as long as observable output matches.

---

(LDET-1)=
## The guarantee, scoped precisely [LDET.1]

(LDET-1-1)=
[LDET.1.1] The guarantee, stated:

> **Given the same compiled rule set and the same event trace,
> every conforming DS runtime produces the same observable output,
> every time, on every platform.**

The platform signature is provenance, not a boundary on the guarantee
([LDET.2.3.6]).

*checks:* `idris×2`  —  *see also:* [LDET.2.3.6](#LDET-2-3-6)

(LDET-1-11)=
[LDET.1.11] **The guarantee is for an artefact that does not lie.** A run in
which evaluating an expression raises an `EngineError` — a value contradicting
the type the artefact declared for it ([IRET.9.6]) — is outside [LDET.1.1]. Two
conforming runtimes may then differ in whether they meet the error at all: one
may reject a fact on a comparison that never inspects the lie, where another
evaluates the lying operand and halts the tier. That error ends the trace, as
every halting fault does ([LFST.9.2.1]); what precedes it stays comparable.

*checks:* `alloy×3` `k`  —  *see also:* [IRET.9.6](#IRET-9-6), [LDET.1.1](#LDET-1-1), [LFST.9.2.1](#LFST-9-2-1)

(LDET-1-12)=
[LDET.1.12] **Settings never change a result.** A program's capability
settings ([LCAP.1]) may restrict which constructs it may use and choose how
the engine executes it. They must not change what it computes. For one
source, one event trace and one platform, any two settings under which the
source compiles produce the same observable output, provided neither run
meets a capacity fault or a deadline halt.

The capacity fault and the deadline halt are the residue ([STYL.2.15.4]):
they are how a strategy restricts *how* computation happens, and each is an
observable, specified outcome ([LCSP.2.3], [RTCT.12]). The binding fields
that record the settings themselves ([RBND.1.3]) differ by definition, and are
not output. An engine behaviour that differs between settings in any other
observable is a determinism defect, whatever the setting that selected it.

*see also:* [LCAP.1](#LCAP-1), [LCSP.2.3](#LCSP-2-3), [RBND.1.3](#RBND-1-3), [RTCT.12](#RTCT-12)

(LDET-1-2)=
[LDET.1.2] The event trace is a concrete artefact with a committed
format — see [LFST] for the
protobuf schema, event kinds and single-writer-per-stream
sequencing.

(LDET-1-3)=
[LDET.1.3] The scope is worth being explicit about before unpacking it.
DS's determinism guarantee is over an **event trace** — the
total sequence of inputs the engine consumes — not over
"the same rules under the same real-world conditions." The
three modes of running DS make this distinction concrete:

(LDET-1-4)=
- [LDET.1.4] **Live mode.** The event trace is generated on the fly
  from real-world events: sensors fire, adapters respond,
  clocks tick, external processes write shared state. The
  event trace itself varies between runs — wall-clock
  timing is different, adapter responses depend on external
  systems, concurrent writers race. **Live output is
  non-deterministic**, and correctly so. The language's
  guarantee isn't violated; it simply doesn't apply to
  "run the same scenario live twice and get identical
  output" — that would require the world to stand still.

(LDET-1-5)=
- [LDET.1.5] **Replay mode.** The event trace is a recorded artefact
  — a captured live session, with every event the engine
  saw stamped into the record. Replaying that stream on
  the same platform reproduces the original output
  byte-for-byte. All the things that varied live are
  frozen in the recording.

(LDET-1-6)=
- [LDET.1.6] **Simulated / test mode.** The event trace is supplied
  by a test harness per TESTING §Event-trace primitive.
  The harness controls the clock, provides adapter-mock
  responses, schedules events explicitly. Output is
  deterministic because the harness fixes every input the
  engine would otherwise read from the environment.

(LDET-1-7)=
[LDET.1.7] The common thread: **whatever is in the event trace is
repeatable; whatever isn't, isn't.** The engine is
deterministic; the world isn't. DS's guarantee is that you
can capture the world's behaviour into an event trace once,
and from then on the engine's behaviour on that stream is
reproducible.

(LDET-1-8)=
### What that means for common constructs [LDET.1.8]

(LDET-1-8-1)=
[LDET.1.8.1] Several language-level constructs feel "non-deterministic"
because they read state that varies in live mode. They are
all deterministic in replay and simulation:

(LDET-1-8-2)=
- [LDET.1.8.2] **`now()` / tick timing.** Wall-clock reads in live mode
  vary between runs — obviously. In replay, `now()` is
  whatever the recording said it was at that instant; in
  simulation, it's what the test harness sets. Rules that
  compare `now()` produce the same answer every time the
  recording is replayed. Both engine clocks — the wall clock
  `now()` reads and the monotonic clock every relative-time
  mechanism reads — are recorded inputs, not real-time
  quantities ([LTIM.2.8.5]).

*see also:* [LTIM.2.8.5](#LTIM-2-8-5)

(LDET-1-8-3)=
- [LDET.1.8.3] **Cache reads with concurrent writers.** Cache is shared
  mutable state. If two tiers (or two activations, or two
  processes) write the same key in quick succession, the
  order in which those writes land affects what a
  subsequent `cache-get` returns. In live mode that order
  can depend on scheduling, process placement, and wire
  latency — not deterministic. In replay, every cache
  write is recorded as part of the event trace in a
  canonical total order ([RFCS.15.7]), so the sequence is
  fixed. A read is not recorded: it is a pure internal read
  of the engine's cache, re-derived from the writes before
  it ([LFST.5.1]). In simulation, the harness controls the
  ordering directly.

*see also:* [LFST.5.1](#LFST-5-1), [RFCS.15.7](#RFCS-15-7)

(LDET-1-8-4)=
- [LDET.1.8.4] **Adapter-service responses.** A real adapter hitting a real
  external system (HA state, weather API, MQTT broker)
  returns whatever external reality produces. Two live
  runs can see different responses for identical calls.
  Recording captures each response; replay uses the
  recorded value; simulation supplies the mock.

(LDET-1-8-5)=
- [LDET.1.8.5] **Call-target I/O.** The integrator's `call` handler
  ([LCRS])
  may do I/O, network reads, and anything else their
  platform requires. Live, their returns vary. Recording
  captures every invocation, so replay is deterministic.
  Same story as adapter responses.

(LDET-1-8-6)=
- [LDET.1.8.6] **Cross-tier fact arrival.** When one tier publishes a
  fact to another, wire latency determines when the
  receiving tier sees it. Under heavy load two live runs
  can see the same facts in slightly different arrival
  orders. The event trace at the receiving tier records
  arrival order; replay is deterministic with respect to
  that recorded stream.

(LDET-1-8-7)=
- [LDET.1.8.7] **Adapter discovery burst ordering.** A discovery-driven
  adapter enumerates its entities at connect. The
  enumeration order must be spec-committed (alphabetical
  by entity_id, per ADAPTER_CONTRACT) for determinism to
  hold across adapter implementations; given that
  ordering, the burst is deterministic within one
  adapter. Across adapter processes, the recording of
  each fact with its wall-clock timestamp captures what
  the receiving tier observed.

(LDET-1-8-8)=
- [LDET.1.8.8] **Hydration queries.** `call hydrate_*` returns
  historical records from the facts or samples plane. Live, the
  records returned depend on what was stored at query time. Recording captures the
  query response; replay returns the same records.

*Deferred: not binding in this edition.*

(LDET-1-8-9)=
[LDET.1.8.9] The consistent pattern across all of these: **record the
event into the event trace, and the engine's response to it
becomes deterministic on replay.** The engine is
deterministic over the stream; the live stream is
non-deterministic because reality is. No contradiction.

(LDET-1-9)=
### What determinism is therefore about [LDET.1.9]

(LDET-1-9-1)=
[LDET.1.9.1] DS's determinism guarantee enables three specific things
that would otherwise be impossible:

(LDET-1-9-2)=
- [LDET.1.9.2] **Trustworthy regression tests.** Capture a failing
  production scenario, replay it in a test, get the exact
  same failure every time. The test isn't racy, isn't
  timing-dependent, isn't platform-dependent within the
  platform signature.

(LDET-1-9-3)=
- [LDET.1.9.3] **Time-travel debugging.** The debugger can pause a
  replay at any instant, step backwards, and show exactly
  the state the live system was in — because that state is
  reconstructable from the recording.

(LDET-1-9-4)=
- [LDET.1.9.4] **Provable rule changes.** Given a recorded session, you
  can change a rule, replay, and diff the outputs with
  confidence that any difference is caused by the rule
  change — not by scheduling, timing, or external state.

(LDET-1-9-5)=
[LDET.1.9.5] These are the real payoff. "Live runs produce identical
output" is neither claimed nor useful — the point of a rule
engine is to *react to* varying real-world conditions, not
to produce constant output.

---

(LDET-1-10)=
[LDET.1.10] **One version, and it is the DS version.** No DS artefact carries a
format version of its own. A `.dsc` records the version that compiled it, in
`proto/header.proto#DscHeader`'s `compiler_version`; a `.dstrace` records the
version that wrote it, in `proto/stream_header.proto#StreamHeader`'s
`ds_version`. There is no second version axis, and a runtime **must not**
introduce one.

**The acceptance rule is a string prefix on the minor series.** A runtime
**must** accept an artefact whose recorded version begins with its own
`<major>.<minor>.` and **must** reject every other — a `.dsc` with
`DS_ERR_DSC_VERSION`, a `.dstrace` with `DS_ERR_FS_VERSION` ([NERR.13]). A `0.12.4` runtime therefore reads what `0.12.0` and
`0.12.9` wrote and refuses everything from `0.11` and `0.13`. The comparison is
on the string, so it needs no parse and admits no ordering question: a version
either shares the prefix or it does not.

**[LDET.1.1]'s guarantee is scoped to that series.** One event trace replayed
against one compiled rule set produces the same observable output for every
release sharing a `<major>.<minor>.` prefix. Across a minor bump the guarantee
does not hold, and nothing claims it does — replaying a historical recording
requires the release that wrote it ([RARC.4.2]).

**Why one number is enough.** Protobuf is normative specification here, not an
implementation detail ([STYL.2.14]): the wire shapes **are** part of the
language definition, so they move when the language moves and at no other time.
A version derived from the release therefore changes exactly when the wire can
change.

**The cost, stated because it binds work rather than prose.** A change to what
bytes mean **must not** land inside a minor series: recordings made earlier in
that series would stop replaying identically, which is the guarantee above. Wire
changes wait for the minor bump.

⚠ **`proto/header.proto#DscHeader` and `proto/stream_header.proto#StreamHeader`
carry no format version.** The field numbers and names they reserve are out of
use: nothing may read them, and they are never reused ([STYL.2.8.7]).

*ratified*  —  *see also:* [LDET.1.1](#LDET-1-1), [NERR.13](#NERR-13), [RARC.4.2](#RARC-4-2)

(LDET-2)=
## Output identity given matching inputs [LDET.2]

(LDET-2-1)=
[LDET.2.1] Expanded:

| Input (must be identical) | Output (will be identical) |
|---|---|
| Compiled rule set (schemas + rules + manifests) | The full sequence of rule activations and their firing order |
| Event-trace event sequence (asserts / retracts / clock advances / adapter responses / adapter emits in exactly the same order at exactly the same clock instants) | The full sequence of facts asserted, retracted, and their slot values at every instant |
| Adapter-mock contract (same services, same responses to same correlation ids) | The full sequence of outgoing `call` actions with args and correlation ids |
| Starting engine state: its working memory and services at the first event, and its configuration ([LDET.2.7]). Its cache's starting entries are carried, not given: the host's seeds by the event trace's head ([RFCS.26.1]), the `initial` block's by the rule set ([LGRA.24.3]) | Every `cache-set` / `cache-get` / `log` / `emit` / `publish` and its payload |
| Platform signature — OS, CPU architecture, libc / libm, compiler toolchain | The full operator-log stream (`logical_assert`, `logical_retract`, activation lifecycle events) |
| | Engine state at every instant, observable via the introspection surface in TESTING and DEBUGGING |

*ratified*  —  *see also:* [LDET.2.7](#LDET-2-7), [LGRA.24.3](#LGRA-24-3), [RFCS.26.1](#RFCS-26-1)

(LDET-2-2)=
[LDET.2.2] "Same" in the output column means **byte-for-byte identical**
when the output is captured in a canonical form — same event
kinds, same slot values, same ordering, same clock instants,
same bindings.

(LDET-2-2a)=
[LDET.2.2a] **Series backing state is part of "starting engine state."**
A series' running stats, deques, and signal backings are
engine state that lives outside working memory and is not serialised
across restarts ([LSER.9.2]). Byte-for-byte
replay of any rule that reads an aggregation therefore requires the
*same* series state at the start of replay — in practice either
(a) the recording began at engine-cold (empty backings), so every
sample re-absorbs from the stream in the same fact order and the
backings rebuild identically (the only v1-faithful path), or
(b) series state is captured into the starting snapshot. A recording
that starts against an already-warm engine cannot reproduce
series-derived facts, because the pre-recording history is absent
from the stream.

*ratified*  —  *see also:* [LSER.9.2](#LSER-9-2)

(LDET-2-2b)=
[LDET.2.2b] **Engine cloning preserves the full "starting engine state," so
the clone is byte-identical.** Because clone deep-copies the mutable state and
continues every counter ([IARC.11]) — including the series backings and the
reservoir PRNG that [LDET.2.2a] names as engine state — a clone taken mid-run and
driven with the same input sequence produces a **byte-identical** observable
stream to the source (the equivalence half of the [NLFC.8.1] contract; 0-ULP,
even cross-platform in v1). Determinism *is* the test: **one conformance fixture
MUST pin the clone-diverge-compare check** — clone mid-run, drive `src` and the
clone with an identical input sequence, assert their observable streams are
byte-identical and that freeing one leaves the other fully functional — so clone
cannot silently rot.

*ratified*  —  *see also:* [IARC.11](#IARC-11), [LDET.2.2a](#LDET-2-2a), [NLFC.8.1](#NLFC-8-1)

(LDET-2-3)=
### Platform signature [LDET.2.3]

(LDET-2-3-1)=
[LDET.2.3.1] A **platform signature** is the tuple of environment
properties that bound floating-point / libm behaviour:

(LDET-2-3-2)=
- [LDET.2.3.2] OS family (Linux / BSD).

(LDET-2-3-3)=
- [LDET.2.3.3] CPU architecture (x86_64 / aarch64 / others).

(LDET-2-3-4)=
- [LDET.2.3.4] libc implementation (glibc / musl / BSD libc).
  Recorded as provenance, not as a determinism input: every
  correctly rounded function the engine evaluates, the
  transcendentals ([LDET.3.4.4]) and the fused multiply-add
  ([LEXP.3.2.2]) alike, is compiled into the engine rather than
  taken from the C library, so 0-ULP holds across every libc DS
  ships an artefact against ([LDET.3.4.1]). The signature still carries the
  actual libc string so an integrator running on a libc
  outside that set can scope their own replay envelope.

*see also:* [LDET.3.4.1](#LDET-3-4-1), [LDET.3.4.4](#LDET-3-4-4), [LEXP.3.2.2](#LEXP-3-2-2)

(LDET-2-3-5)=
- [LDET.2.3.5] Compiler toolchain version (major/minor).

(LDET-2-3-6)=
[LDET.2.3.6] Two environments are on the **same platform signature** when
all components match. The byte-for-byte guarantee above does not
depend on that: it holds across signatures as well as within one
([LDET.3.4.1]). The signature is provenance and a refusal key,
not a boundary on the guarantee ([NDET.2.3]).

*see also:* [LDET.3.4.1](#LDET-3-4-1), [NDET.2.3](#NDET-2-3)

(LDET-2-3-7)=
[LDET.2.3.7] Across platform signatures the guarantee is unchanged, and
[LDET.3] below says why: the whole admitted v1 surface is EXACT, so a recorded session replays
bit-for-bit on any conforming platform ([LDET.3.4.1]).

*see also:* [LDET.3](#LDET-3), [LDET.3.4.1](#LDET-3-4-1)

(LDET-2-4)=
### What's in "event trace" [LDET.2.4]

(LDET-2-4-1)=
[LDET.2.4.1] Per TESTING §Event-trace primitive, the event trace is the
total input to the engine — every event the engine would
observe or act on, captured in a canonical total order:

(LDET-2-4-2)=
- [LDET.2.4.2] Working-memory mutations (assert, retract).

(LDET-2-4-3)=
- [LDET.2.4.3] Clock progression (advance, ticks).

(LDET-2-4-4)=
- [LDET.2.4.4] Adapter responses (mock or real, recorded canonically).

(LDET-2-4-5)=
- [LDET.2.4.5] Adapter-emitted facts.

(LDET-2-4-6)=
- [LDET.2.4.6] `call` invocations and their responses
  ([LCRS] — every invocation
  records args-in, response-out).

(LDET-2-4-7)=
- [LDET.2.4.7] Cache operations (every `cache-set`, `cache-get`,
  `cache-delete` in canonical order; for multi-writer
  scenarios the total order is what replay preserves).

(LDET-2-4-8)=
- [LDET.2.4.8] Cross-tier boundary events (emit / publish from another
  tier, with arrival ordering at the receiving tier).

(LDET-2-4-9)=
- [LDET.2.4.9] Adapter lifecycle events (discovery bursts, schema
  extends, entity unavailability).

(LDET-2-4-10)=
[LDET.2.4.10] If the event trace is identical, the output is identical. If
the event trace differs by even one re-ordered event, the
guarantee does not apply — the output may legitimately change.
Recording captures all of the above; replay reproduces all of
the above; simulated tests supply all of the above from the
harness.

*checks:* `tla×7`

(LDET-2-5)=
### What's NOT in "event trace" [LDET.2.5]

(LDET-2-5-1)=
[LDET.2.5.1] Deliberately excluded; runtimes vary these freely without
violating determinism:

(LDET-2-5-2)=
- [LDET.2.5.2] Wall-clock timing between events (the clock is a recorded
  input, not wall time in replay).

(LDET-2-5-3)=
- [LDET.2.5.3] CPU / memory / thread-scheduling behaviour.

(LDET-2-5-4)=
- [LDET.2.5.4] Internal Rete-memory layout.

(LDET-2-5-5)=
- [LDET.2.5.5] Log line *timing* in wall time (content is determined;
  delivery timing is not).

(LDET-2-5-6)=
- [LDET.2.5.6] Hardware-level performance characteristics.

(LDET-2-6)=
[LDET.2.6] The compiled rule set is a **precondition** of replay, not a
stream input ([LDET.2.1]). A conforming runtime must not replay a fact
stream against an unverified program: whenever the DSC is obtainable —
embedded in the stream or supplied — it must verify the stream's
`dsc_hash` binding before replay ([RFCS.4.5]). The optional `.dstrace`
packaging is **determinism-neutral**: embedding the DSC by concatenation
([RFCS.13]) replays bit-identically to the lean stream plus its DSC, and does
not change the observable replay output.

*see also:* [LDET.2.1](#LDET-2-1), [RFCS.13](#RFCS-13), [RFCS.4.5](#RFCS-4-5)

(LDET-2-7)=
[LDET.2.7] **Engine configuration is a precondition of replay, as the
compiled rule set is ([LDET.2.6]).** An integrator configures an engine through
the host interface as well as through the event stream. A setting given through
the host interface is not an event, so the stream does not record it and a
replaying engine does not learn it from the trace ([LFST.9.2.1]).

The integrator must therefore give the replaying engine every setting the
recording engine had that can change an observable in [LDET.2.1]'s output
column. A setting the integrator changed during the run is given again at the
same point, between the same two inputs. A replay against an engine configured otherwise is not a replay of the
recorded run: a divergence it finds is the difference in configuration, not a
determinism failure.

A conforming runtime must state which of its settings can change an observable.
A setting that cannot — one that sizes storage without refusing anything, or
that decides only whether an artefact loads — is not a precondition.

---

*see also:* [LDET.2.1](#LDET-2-1), [LDET.2.6](#LDET-2-6), [LFST.9.2.1](#LFST-9-2-1)

(LDET-3)=
## Cross-platform determinism [LDET.3]

(LDET-3-1)=
[LDET.3.1] The guarantee is byte-for-byte within a platform signature
and byte-for-byte across them. Replaying a session on a different
OS / arch / libm than it was recorded on changes nothing about the
output ([LDET.3.4.1]); the sections below say what that rests on.

*ratified*  —  *see also:* [LDET.3.4.1](#LDET-3-4-1)

(LDET-3-2)=
### What stays identical across platforms [LDET.3.2]

(LDET-3-2-1)=
- [LDET.3.2.1] **Rule firing order.** Rete conflict resolution is
  combinatorial, not numeric. The terminal ordinal (source
  order) then activation-creation order is platform-independent.

(LDET-3-2-2)=
- [LDET.3.2.2] **Integer arithmetic.** Two's-complement 64-bit signed is
  portable. Add / subtract / multiply / shift / bitwise all
  produce identical results on any conforming platform.
  Division and modulo on well-defined inputs (divisor ≠ 0)
  are identical.

*ratified*

(LDET-3-2-3)=
- [LDET.3.2.3] **String operations.** Equality, length and interpolation
  ([LGRA.2.9.6]) — all platform-independent.

*see also:* [LGRA.2.9.6](#LGRA-2-9-6)

(LDET-3-2-4)=
- [LDET.3.2.4] **Fact-identity decisions.** Whether two facts are
  considered equal (for no-op reassertion suppression, for
  logical-fact coalescence) is determined by slot values
  compared structurally; platform-independent for all
  non-float slots.

(LDET-3-2-5)=
- [LDET.3.2.5] **Observable event ordering.** Which fact is asserted
  first, which rule activation fires first, which `call`
  issues first — all platform-independent because they
  follow from rule firing order.

(LDET-3-2-6)=
- [LDET.3.2.6] **Synthetic identifiers.** Synthetic names ([LLEX.10.6.1]) are
  derived from source text; identical across platforms.

*see also:* [LLEX.10.6.1](#LLEX-10-6-1)

(LDET-3-2-7)=
- [LDET.3.2.7] **Float canonical text form + Float→JSON serialization.** A finite
  `Float` renders as the **shortest decimal string that parses back to the
  identical IEEE-754 `double`** — the round-trip *shape*: fixed notation for
  `1e-4 ≤ |x| < 1e16`, scientific outside. In fixed notation the `.0` is
  **kept** on a whole float (`42.0` → `"42.0"`, never `"42"`, so the value
  round-trips as a `Float`, not collapsing to an `Int`). In scientific notation
  a mantissa of one digit carries no point (`1e16` → `"1e+16"`, never
  `"1.0e+16"`): the
  exponent already makes the text a `FLOAT_LIT` ([LLEX.11.2]). Lowercase signed
  exponent with ≥2 digits; `-0.0` preserved in
  the rendered text. A `Json` value holds no `-0.0` ([LGRA.5.8.8]), so none
  reaches its text. This shaping is DS-owned — it is *repr-shaped*, **not** Python-`repr`-identical: the runtime
  owns its own shaping and depends on no host `repr`. The compiler lowers a source
  `FloatLit` through the **same** shaping ([LUNI.2.7], [LUNI.17.7]), so a
  serialized cache value and the same value written as a source literal render
  alike, and a serialized cache value round-trips (`cached("k")` reads back what
  was written).

  **Determinism scope.** Both the shaping and the digits are the runtime's own,
  on every platform: the digits are correctly rounded and the form round-trips
  bit for bit ([LDET.3.2.8]). No host conversion routine takes part.

  **Non-finite on the JSON data plane — hard error.** The JSON data plane (the
  cache value, and every JSON value the engine builds) uses the finite form above; a **non-finite** `Float` (`±Inf`, or a
  NaN an expression produced, [LDET.3.6.2]) forced into a JSON
  body is a **`NOT_REPRESENTABLE` trap at the verb** ([LERR.1.4.9]): the engine
  abandons the activation and the verb does not run, so no `inf` token reaches
  the wire. A rule's path does not return `DS_ERR_JSON_NONFINITE`, which answers
  a host call that would build such a value ([LGRA.5.8.10]). A `Json`
  value holds none ([LGRA.5.8.10]), and no non-finite value is ever serialized
  to JSON.

  **±`Inf` text form (the text / display plane, not JSON).** Where a non-finite
  `Float` is rendered as **text** rather than JSON — `Float::String` ([LCST.4.5.6])
  and the display default below — `±Inf` renders `"inf"` / `"-inf"`. This clause is
  the home of both the finite canonical form and the `±Inf` text form; `[LCST.4.5.6]`
  references it.

  **Display default.** A string-interpolation segment with no
  explicit format spec (`"{x}"`), and `log` message text, render a `Float`
  in this **same** canonical form (faithful-by-default, the auto formatter); an
  explicit author format spec renders by [LGRA.2.9.6.5]'s rules. Display default, data plane
  and source-literal form are therefore one and the same shaping. *Carve-out:* the internal identity-value **row key** used for
  fact dedup is not observable rendering and is not governed here — `-0.0` is
  normalized to `0.0` in the identity / join float hashes ([LFAC.2]), and a
  `Float` used as an identity key already sits outside the cross-platform guarantee
  ([LDET.3.2.4] covers non-float slots).

*ratified*  —  *checks:* `k` `idris×26`  —  *see also:* [LCST.4.5.6](#LCST-4-5-6), [LDET.3.2.4](#LDET-3-2-4), [LDET.3.2.8](#LDET-3-2-8), [LDET.3.6.2](#LDET-3-6-2), [LERR.1.4.9](#LERR-1-4-9), [LFAC.2](#LFAC-2), [LGRA.2.9.6.5](#LGRA-2-9-6-5), [LGRA.5.8.10](#LGRA-5-8-10), [LGRA.5.8.8](#LGRA-5-8-8), [LLEX.11.2](#LLEX-11-2), [LUNI.17.7](#LUNI-17-7), [LUNI.2.7](#LUNI-2-7)

(LDET-3-2-8)=
- [LDET.3.2.8] **Decimal text and `Float` convert with correct rounding, in both
  directions, and the runtime owns both.**

  - **Parse.** Decimal text becomes the binary64 value nearest the exact decimal
    value it denotes, ties to even (roundTiesToEven), whatever the number of
    significant digits. This covers every place a `Float` is read from text: a
    source literal, a cast from `String` ([LCST.4.5]), and a number in JSON
    handed to the engine. A source literal whose value lies past the largest
    finite `Float` is a lexer error ([LLEX.11.2.4]). Inside a `Json` value a zero then loses its sign
    ([LGRA.5.8.8]), and JSON text whose number lies past the largest finite
    `Float` is malformed ([LGRA.5.8.10]).
  - **Render.** The digits of the canonical form ([LDET.3.2.7]) are the
    fewest that parse back to the same value, correctly rounded under the same
    rule. A fixed precision ([LGRA.2.9.6.10]) is the binary value correctly
    rounded to that many decimal places, ties to even.
  - **Round trip.** For every finite `Float` `x`, parsing the canonical text of
    `x` yields `x`, bit for bit, `-0.0` included. The runtime must establish
    this for all finite values by proof, not by sampling.
  - **Owned, not delegated.** The runtime must perform both conversions itself.
    Neither may depend on a host platform's conversion routines, because the
    runtime does not control their rounding, and a difference between two
    platforms is a difference in replayed output ([LDET.1.1]).

*checks:* `k` `idris×79`  —  *see also:* [LCST.4.5](#LCST-4-5), [LDET.1.1](#LDET-1-1), [LDET.3.2.7](#LDET-3-2-7), [LGRA.2.9.6.10](#LGRA-2-9-6-10), [LGRA.5.8.10](#LGRA-5-8-10), [LGRA.5.8.8](#LGRA-5-8-8), [LLEX.11.2.4](#LLEX-11-2-4)

(LDET-3-3a)=
### Determinism-class registry [LDET.3.3a]

(LDET-3-3a-1)=
[LDET.3.3a.1] **Purpose.** [LDET.3.2] is the **single normative source of
truth** for which constructs are cross-platform-exact — the table the series
backends and the unit / complex layers all read, so the classification lives in
one place and cannot drift across docs. **In v1 every admitted construct is
EXACT.**

*see also:* [LDET.3.2](#LDET-3-2)

(LDET-3-3a-2)=
[LDET.3.3a.2] **Classes.**
- **EXACT** — cross-platform 0-ULP ([LDET.3.2]): identical bits on every
  conforming platform given fixed fact order. **This is the only v1 class.**

*see also:* [LDET.3.2](#LDET-3-2)

(LDET-3-3a-9)=
[LDET.3.3a.9] **Registry** (the v1 EXACT core; other layers classify *per this
class*, [LDET.3.3a.6]):

*see also:* [LDET.3.3a.6](#LDET-3-3a-6)

(LDET-3-3a-4)=
[LDET.3.3a.4]

| Construct                                                                                                                                                                     | Builtin                                                                                                                                           | Class | Note                                                                                                                                                                            |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|-------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| integer `+ − × ÷ % // << >> & &#124; ^ ~`, comparisons, boolean, string ops, fact-identity                                                                                    | —                                                                                                                                                 | EXACT | [LDET.3.2]                                                                                                                                                                      |
| float `+ − × ÷` and `√` / `math.sqrt`                                                                                                                                         | `FN_SQRT`                                                                                                                                         | EXACT | IEEE correctly-rounded, IEEE results at the exceptional operands ([LDET.3.6.2])                                                                                                 |
| `abs` `round` `math.floor` `math.ceil` `math.trunc` `math.sign`                                                                                                               | `FN_ABS` `FN_ROUND` `FN_FLOOR` `FN_CEIL` `FN_TRUNC` `FN_SIGN`                                                                                     | EXACT | [LEXP.3.2]                                                                                                                                                                      |
| `math.fma`                                                                                                                                                                    | `FN_FMA`                                                                                                                                          | EXACT | IEEE 754 fused multiply-add, rounded once ([LEXP.3.2.2])                                                                                                                        |
| `math.degrees` `math.radians`                                                                                                                                                 | `FN_DEGREES` `FN_RADIANS`                                                                                                                         | EXACT | one rounded multiplication by a pinned π-derived `float64` constant ([LEXP.3.6.1])                                                                                              |
| `math.pow(x, y)` / `**`                                                                                                                                                       | `FN_POW`                                                                                                                                          | EXACT | non-negative compile-time integer exponent → `Int` by **binary exponentiation**; any other → `Float` by the **correctly-rounded `pow`** ([LEXP.3.2], [LEXP.7.3a], [LEXP.3.9.3]) |
| `math.exp` `math.ln` `math.log2` `math.log10`                                                                                                                                 | `FN_EXP` `FN_LN` `FN_LOG2` `FN_LOG10`                                                                                                             | EXACT | correctly rounded ([LEXP.3.9.2], [LEXP.3.9.3])                                                                                                                                  |
| `math.sin` `math.cos` `math.tan` `math.asin` `math.acos` `math.atan` `math.atan2`                                                                                             | `FN_SIN` `FN_COS` `FN_TAN` `FN_ASIN` `FN_ACOS` `FN_ATAN` `FN_ATAN2`                                                                               | EXACT | correctly rounded ([LEXP.3.9.2], [LEXP.3.9.3])                                                                                                                                  |
| `math.sinh` `math.cosh` `math.tanh`                                                                                                                                           | `FN_SINH` `FN_COSH` `FN_TANH`                                                                                                                     | EXACT | correctly rounded ([LEXP.3.9.2], [LEXP.3.9.3])                                                                                                                                  |
| `distance.euclidean` / `distance.manhattan` / `distance.chebyshev` / `distance.hypotenuse`                                                                                    | `FN_EUCLIDEAN_2D` `FN_EUCLIDEAN_3D` `FN_MANHATTAN_2D` `FN_MANHATTAN_3D` `FN_CHEBYSHEV_2D` `FN_CHEBYSHEV_3D` `FN_HYPOTENUSE_2D` `FN_HYPOTENUSE_3D` | EXACT | basic ops + `sqrt`                                                                                                                                                              |
| `distance.cosine`                                                                                                                                                             | `FN_COSINE_2D` `FN_COSINE_3D`                                                                                                                     | EXACT | dot product, `sqrt`, division — no trigonometric call ([LEXP.5.7.3])                                                                                                            |
| `distance.great_circle`                                                                                                                                                       | `FN_GREAT_CIRCLE`                                                                                                                                 | EXACT | correctly rounded primitives composed as [LEXP.5.11.2] writes them                                                                                                              |
| complex `arg(z)` and `exp(z)`; tier-2 unit conversions and `unit formula`s that reach a transcendental                                                                        | —                                                                                                                                                 | EXACT | correctly-rounded primitives composed as the formula is written ([LUNI.14.5], [LUNI.4.3], [LUNI.4.5])                                                                           |
| series exact backends — `SeriesBackendWelfordEwma` (cumulative), `SeriesBackendRingBuffer`, `SeriesBackendMonotonicDeque`, `SeriesBackendFifoDeque`, `SeriesBackendReservoir` | —                                                                                                                                                 | EXACT | integer / comparison / correctly-rounded                                                                                                                                        |

*see also:* [LDET.3.2](#LDET-3-2), [LEXP.3.2](#LEXP-3-2), [LEXP.3.2.2](#LEXP-3-2-2), [LEXP.3.6.1](#LEXP-3-6-1), [LEXP.5.11.2](#LEXP-5-11-2), [LEXP.5.7.3](#LEXP-5-7-3), [LEXP.7.3a](#LEXP-7-3a), [LDET.3.6.2](#LDET-3-6-2), [LEXP.3.9.2](#LEXP-3-9-2), [LEXP.3.9.3](#LEXP-3-9-3), [LUNI.14.5](#LUNI-14-5), [LUNI.4.3](#LUNI-4-3), [LUNI.4.5](#LUNI-4-5)

(LDET-3-3a-6)=
[LDET.3.3a.6] **Consumers** (classify per this registry; must not restate it
independently, to avoid drift): the expression builtins ([LEXP.3]); the series exact backends; unit conversions (tier-1 affine = EXACT);
and `complex` ops (`+ − ×`, `conjugate`, `real`, `imag`, `abs`, `arg`, `exp` =
EXACT). **In v1 every consumer is EXACT**, tier-2 unit formulas and `complex`
`arg`/`exp` included: their transcendental steps are correctly rounded
([LDET.3.4.4]).

*see also:* [LEXP.3](#LEXP-3), [LDET.3.4.4](#LDET-3-4-4)

(LDET-3-3a-7)=
[LDET.3.3a.7] **Compile-time evaluation into a bundle-bound value.** A value
computed at **compile time** whose result is serialized into the bundle — a
constant folded into the program image, a lowered DSC atom, a representative
value, a numeric literal apportioned to a fixed-point scale — **MUST** be
produced by the **EXACT-class** machinery of this registry: exact
integer/rational arithmetic, or the correctly-rounded IEEE operations of
[LDET.3.3a.4]. It **MUST NOT** be produced by the compiler host's native
floating point — host `libm` transcendentals, extended-precision or
FMA-contracted evaluation, or locale-dependent decimal parsing — because **the
compiler host is not a conforming target** ([LDET.2.3]), and a value it rounds
differently from a conforming engine is a silent cross-target divergence baked
permanently into the bundle. *Instance:* a duration literal apportioned to
nanoseconds, or a unit-conversion factor folded into a threshold, is computed in
exact integer/rational arithmetic and quantised once by round-half-to-even —
never host `double`. A transcendental the compiler folds is the correctly-rounded
value [LEXP.3.9.2] requires, at [LEXP.3.9.3]'s special values, computed in
round-to-nearest-even ([LDET.3.6.1]) — the same bits a conforming engine
returns. (Since v1 admits only EXACT constructs, every compile-time
bundle-bound value is covered by this clause directly.)

*see also:* [LDET.2.3](#LDET-2-3), [LDET.3.3a.4](#LDET-3-3a-4), [LEXP.3.9.2](#LEXP-3-9-2), [LEXP.3.9.3](#LEXP-3-9-3), [LDET.3.6.1](#LDET-3-6-1)

(LDET-3-3a-10)=
[LDET.3.3a.10] **A NaN is not folded.** The compiler must not serialise into
the bundle a compile-time value that is NaN. An expression whose value at compile
time is NaN is lowered as written, and the engine evaluates it ([LDET.3.6.2]).
IEEE 754 leaves a NaN's sign and payload to the hardware ([LEXP.4.3]), so a
folded NaN would make the bundle's bytes depend on the compiler host, which
[LDET.3.3a.7] forbids. `+Inf` and `-Inf` each have one encoding and fold like any
other value.

*see also:* [LDET.3.6.2](#LDET-3-6-2), [LEXP.4.3](#LEXP-4-3), [LDET.3.3a.7](#LDET-3-3a-7)

(LDET-3-3a-8)=
[LDET.3.3a.8] **One definition for a value computed both at compile time and at
runtime.** When the *same* logical value is computed in **two places** — once at
compile time (folded into the bundle) and once at runtime (recomputed by the
engine) — both computations **MUST** derive from a **single exact definition**,
so the two agree **bit-for-bit**. A value MUST NOT be carried in one
representation for the compile-time computation and a different,
independently-rounded representation for the runtime one; where a convenience
representation is stored (e.g. a `double` for display or interpolation), it MUST
NOT be an arithmetic input to either computation of the shared value. Two
derivations of "the same" value that can disagree by a ULP are a determinism
defect even when each is internally EXACT. *Instance:* a series window boundary
or a unit-conversion factor used **both** at compile time (folded into a lowered
atom) and at runtime (recomputed by the engine) must derive from a single exact
definition, so the two agree to the bit; a convenience `double` stored for
display must not be an arithmetic input to either computation.

*ratified*

(LDET-3-4)=
### What rule authors should do about it [LDET.3.4]

(LDET-3-4-1)=
- [LDET.3.4.1] **Nothing — every v1 rule is cross-platform bit-identical.** The
  basic operations are EXACT ([LDET.3.2]) and every transcendental is correctly
  rounded ([LDET.3.4.4]), so a recorded session replays bit-for-bit on any
  conforming platform.

*see also:* [LDET.3.2](#LDET-3-2), [LDET.3.4.4](#LDET-3-4-4)

(LDET-3-4-2)=
- [LDET.3.4.2] **Integer-heavy and float-arithmetic rules alike port cleanly.**
  Counts, flags, states, enums, exact string matches, and the IEEE
  correctly-rounded `+ − × ÷ √` are all cross-platform bit-identical.

(LDET-3-4-4)=
- [LDET.3.4.4] **Every transcendental is correctly rounded.** Bit-identity
  ([LDET.3.4.1]) extends to the transcendental functions ([LEXP.3.9]), to `**`
  at every exponent ([LEXP.7.3a]), and to the unit conversions, `unit formula`s
  and complex operations built on them ([LUNI.4.3], [LUNI.4.5], [LUNI.14.5]),
  because each is correctly rounded ([LEXP.3.9.2]) and fixed at its special
  values ([LEXP.3.9.3]). Nothing in a compiled bundle reaches a
  platform-variable operation, so there is no envelope to calibrate and no
  result to compare within a tolerance.

  A composite is evaluated as its formula is written, one rounded operation at a
  time ([LDET.3.6.1]). It is not correctly rounded itself, and it is identical on
  every conforming engine. The angle conversions ([LEXP.3.6.1]) and
  `distance.great_circle` ([LEXP.5.11.2]) are composites of this kind.

*see also:* [LDET.3.4.1](#LDET-3-4-1), [LEXP.3.9](#LEXP-3-9), [LEXP.7.3a](#LEXP-7-3a), [LUNI.4.3](#LUNI-4-3), [LUNI.4.5](#LUNI-4-5), [LUNI.14.5](#LUNI-14-5), [LEXP.3.9.2](#LEXP-3-9-2), [LEXP.3.9.3](#LEXP-3-9-3), [LDET.3.6.1](#LDET-3-6-1), [LEXP.3.6.1](#LEXP-3-6-1), [LEXP.5.11.2](#LEXP-5-11-2)

(LDET-3-5)=
### Cross-platform bit-identity is mandatory in v1 [LDET.3.5]

(LDET-3-5-1)=
[LDET.3.5.1] v1's surface is **uniformly exact** — only correctly rounded
operations plus integer / comparison / string work, so **cross-platform bit-identity is
mandatory and automatic**: a compiled bundle produces byte-identical output on
every conforming target.

---

(LDET-3-6)=
### The floating-point environment [LDET.3.6]

(LDET-3-6-1)=
[LDET.3.6.1] **One rounding mode, the engine's.** Every `Float` operation the
engine performs is IEEE 754 binary64 arithmetic rounding to nearest, ties to
even, with subnormals kept and no two operations fused into one. `math.fma` is one
operation, IEEE 754's fused multiply-add, and not a fusion of two
([LEXP.3.2.2]). The rounding
mode is state the host process shares, so the engine must establish
round-to-nearest-even for its own evaluation whatever mode the integrator's
thread holds, and must restore the integrator's mode before control passes back
to the integrator, by a callback or by the return of an engine call. The
integrator's own floating-point code never sees the engine's mode.

The mode the engine restores when an engine call returns is the one the
integrator held when it made that call. A mode integrator code sets inside a
callback belongs to that callback, and the engine does not keep it.

*ratified*  —  *checks:* `tla×23`  —  *see also:* [LEXP.3.2.2](#LEXP-3-2-2)

(LDET-3-6-2)=
[LDET.3.6.2] **IEEE results, including the exceptional ones.** A `Float`
operation whose IEEE 754 result is an infinity or a NaN returns it, and none
traps: `x / 0.0` is `±Inf` for a nonzero `x` and NaN for `0.0 / 0.0`, `sqrt`
of a negative is NaN, and `**` and the transcendental functions follow
[LEXP.3.9.3]. No floating-point exception flag is observable. A NaN result flows
on through its expression, and [LEXP.4.2] keeps it out of working memory and
every payload. Division and modulo of `Int` operands by zero are not IEEE
operations and stay runtime errors ([LEXP.7.15.1]).

*ratified*  —  *checks:* `alloy×3` `k` `idris×5`  —  *see also:* [LEXP.3.9.3](#LEXP-3-9-3), [LEXP.4.2](#LEXP-4-2), [LEXP.7.15.1](#LEXP-7-15-1)

(LDET-3-6-3)=
[LDET.3.6.3] **No NaN is written to a floating-point field.** A NaN's sign and
payload are the hardware's ([LEXP.4.3]), so a NaN in a field of a bundle, a
recording or a payload would make its bytes differ by target. Nothing that
writes a message under `proto/` may write a NaN to a `double` or `float` field.
Every such field must have a row in [LDET.3.6.4] naming its writer and the clause
that keeps a NaN out of it, and a field must not be added without one.

*see also:* [LEXP.4.3](#LEXP-4-3), [LDET.3.6.4](#LDET-3-6-4)

(LDET-3-6-4)=
[LDET.3.6.4]

| Message                                     | Field         | Writer                                                        | What keeps a NaN out                                                                                                                                   |
|---------------------------------------------|---------------|---------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|
| `proto/alfa.proto#AlphaLiteral`             | `float_val`   | the compiler                                                  | a compile-time value that is NaN is not folded ([LDET.3.3a.10]); `nan` is not a usable value ([LEXP.4.1])                                              |
| `proto/rete_expr.proto#Expr`                | `lit_float`   | the compiler                                                  | a compile-time value that is NaN is not folded ([LDET.3.3a.10]); `nan` is not a usable value ([LEXP.4.1])                                              |
| `proto/slot.proto#Slot`                     | `tolerance`   | the compiler                                                  | a non-negative literal of the slot's type ([RLOW.3.7.7]); `nan` is not a usable value ([LEXP.4.1])                                                     |
| `proto/test_scenario.proto#TestSlotLiteral` | `f_val`       | the compiler                                                  | a slot value, where `nan` is refused ([LEXP.4.2]), and not folded to NaN ([LDET.3.3a.10])                                                              |
| `proto/fact_external.proto#Arg`             | `float_value` | the engine: a call's arguments, and a fact leaving the engine | a NaN `Float` call argument refuses the call before it is issued ([LEXP.4.2]); no slot holds NaN, because NaN never enters working memory ([LEXP.4.2]) |

*see also:* [LDET.3.3a.10](#LDET-3-3a-10), [LEXP.4.1](#LEXP-4-1), [LEXP.4.2](#LEXP-4-2), [RLOW.3.7.7](#RLOW-3-7-7)

(LDET-4)=
## Firing order is reproducible [LDET.4]

(LDET-4-2)=
[LDET.4.2] **The firing order is fully determined by the inputs.** The
same event trace driven into two conforming engines produces
the same activation order, under the total order of
[LDET.5.1]. The order is not readable off the source text
alone — it depends on the inputs — but it is reproducible.

---

*ratified*  —  *see also:* [LDET.5.1](#LDET-5-1)

(LDET-5)=
## Rule-firing order is spec-defined [LDET.5]

(LDET-5-1)=
[LDET.5.1] When more than one rule activation matches at the same clock
instant, the order in which they fire is determined by the
following total order:

1. **[LDET.5.4]** — the terminal ordinal, which is source order.
2. **[LDET.5.5]** — activation-creation order, within one rule.

**Source order is the outer key**, and that is the whole of the author's
control: the rule written first fires first. `[LDET.5.5]` orders the
activations *of a single rule* against each other and never decides
between two different rules.

The keys are total by construction and nothing has to assume it. The
ordinal is unique per rule, so two activations of **different** rules are
separated by the first key alone; and two activations of the **same**
rule share an ordinal but cannot share a creation timetag, because a
timetag is assigned per token and a token reaches exactly one terminal.

*ratified*  —  *checks:* `alloy×5` `tla×19` `idris×11`  —  *see also:* [LDET.5.4](#LDET-5-4), [LDET.5.5](#LDET-5-5)

(LDET-5-3)=
2. [LDET.5.3] **Refraction is suppression, not an ordering key.** An
   activation whose (rule, token) identity has already fired in this
   cycle is **not eligible to fire again** until its LHS changes. It is
   removed from consideration; it is not sorted later.

   In the CLIPS model, refraction is an axis in the conflict-resolution
   strategy. Here selection happens first and suppression is applied to
   the winner, so a refracted activation never competes at all.

*ratified*  —  *checks:* `tla×17` `idris×9`

(LDET-5-8)=
[LDET.5.8] **An engine-synthesised fact is not a working-memory fact.** An
engine **may** synthesise a fact to carry its own state — the clock tick that
re-drives a time-dependent LHS is the standing case ([RARC.12.4]). Such a fact
**must not** be a working-memory fact: it is not counted by the fact count, it
is not delivered to the fact callbacks, and — the part that decides an
observable — **cycling it is not a change to the LHS** for [LDET.5.3]'s
refraction rule.

**The observable.** A rule whose LHS became true only because a
time-dependent test changed fires **once**. Take a rule `late` whose one
pattern matches a `Ping` fact `p` under the guard
`now() > calendar.time(1970, 1, 1, 0, 0, 5)` ([LTIM.14.1]), which opens once
the clock passes 5 s after the epoch, and whose RHS only logs. Assert one `Ping`, pump twice with the gate shut, advance the clock past it,
and pump twice more. `late` fires exactly once, in the third pump. It **must
not** fire again in the fourth, or in every pump thereafter.

**Why the alternative is refused, and it is not a near miss.** The tick has to
be somewhere a join can bind against, and putting it in working memory is the
obvious place. Do that and the rule above fires forever, for two independent
reasons either of which is sufficient: the tick's fact id enters the token
tuple refraction is keyed on, so a fresh id each pump means the suppression
never matches; and cycling a working-memory fact is a working-memory change, so
the "discard refraction on a change" rule clears the memory every pump as well.
A runtime that puts synthetic facts in working memory therefore needs a
separate filter at the fact count, at the fact callbacks, **and at refraction**
— and the third is the one that gets missed.

**The `after` follow-up meets the same trap.** It escapes it by retracting its
own timer as the last action
of its RHS — no timer, no match, no re-fire — and the reason recorded there is
exactly this one: without the self-retraction, refraction is per-(timer, tick)
and each new tick re-fires it forever. A `now()` `where` has nothing to
retract, so it has no such escape and needs the rule stated instead.

**What this does not say** ([STYL.2.15.4]). It does not say where a synthetic
fact lives, how it is represented, or whether its schema appears in any
registry. Those are an implementation's to choose. It says only that whatever
an engine does there is invisible to the fact count, to the fact callbacks and
to refraction — which is what makes the firing count above a property of the
language rather than of a runtime.

*ratified*  —  *checks:* `idris×29`  —  *see also:* [LDET.5.3](#LDET-5-3), [LTIM.14.1](#LTIM-14-1), [LTIM.2.6.2](#LTIM-2-6-2), [RARC.12.1](#RARC-12-1), [RARC.12.4](#RARC-12-4)

(LDET-5-4)=
1. [LDET.5.4] **The terminal ordinal — the first key, and it is source
   order.** Each rule is assigned a zero-based ordinal from the order its
   terminal appears in the compiled artefact, which `[RLOW.14.3]` requires
   to be canonical source order: within a file, the rule written first;
   across files, **import-DAG topological order, leaf libraries first**.

   Import-DAG rather than lexicographic-by-path because a path-based rule
   moves when a file is renamed, and because a library's rules are already
   loaded before its importer's — the DAG order is the one the compiler
   has, not one it would have to reconstruct.

   **This is spatial author intent** ([LDET.5.7.3]) and it is the reason
   the order is spec-defined rather than implementation-defined
   ([LTES.12.9]): a firing order that fell out of when matches happened to
   complete would depend on propagation internals, which is precisely what
   that clause forbids.

*ratified*  —  *checks:* `alloy×3` `idris×2`  —  *see also:* [RLOW.14.3](#RLOW-14-3), [LDET.5.7.3](#LDET-5-7-3), [LTES.12.9](#LTES-12-9)

(LDET-5-5)=
2. [LDET.5.5] **Activation-creation order — the second key, within one
   rule.** Among activations *of the same rule*, partial matches that
   completed earlier fire before those completed later, by a monotonic
   creation timetag assigned when the match completes. A match completes
   when the last of its facts enters working memory; a fact that is
   replaced ([LFAC.1.2.2]) enters anew.

   **Matches that complete together are ordered by their facts.** One
   assertion can complete several matches of one rule at once — the new
   fact joining several partners. Among those, the engine **must** assign
   timetags in the lexicographic order of the matches' facts, compared
   pattern by pattern from the first pattern, each fact ranked by when it
   entered working memory. The timetag is therefore a function of the
   match and of working memory alone. The order in which the engine's
   memories happen to be traversed **must not** affect it ([LDET.5.9]).

   **It never decides between two different rules.** Those are separated
   by `[LDET.5.4]` before this key is reached — which is what keeps the
   order out of the hands of propagation internals.

*ratified*  —  *checks:* `alloy×10` `tla×4` `idris×107`  —  *see also:* [LDET.5.4](#LDET-5-4), [LDET.5.9](#LDET-5-9), [LFAC.1.2.2](#LFAC-1-2-2)

(LDET-5-9)=
[LDET.5.9] **The order is a function of the activation set, never of how the
set was reached.** [LDET.5.4] and [LDET.5.5] order the activations that are
eligible in this cycle. Whether an activation became eligible because a fact
was asserted, or because a negated condition stopped being satisfied and
released it, **must not** affect where it fires.

Concretely: **blocking does not unassign a creation timetag, and unblocking
does not mint one.** [LDET.5.5]'s timetag is assigned when the partial match
completes; a match that completed and was then held back by a negated
condition has already completed. When it is released it fires in the position
its original timetag gives it. Two engines that agree on working memory and on
the match set therefore agree on the order, whatever bookkeeping either uses to
track blocked tokens.

**This is forced by [LDET.1.1], not chosen.** The guarantee is over the fact
stream: the same rules and the same stream replay bit-for-bit. A replay
reconstructs working memory **by assertion** — it has no blocker to retract,
because the recording carries facts and not the network's internal history — so
an order that depended on the traversal that released blocked tokens would
differ between a run and its own replay, in the same runtime, on the same
machine. A determinism guarantee that fails on replay is not one. So
restoration order cannot be observable, and this clause says so rather than
leaving it to be re-derived.

**What it costs, stated plainly.** [IRET.7] calls a NOT node's bookkeeping an
implementation detail, and it is one only while its traversal order is
unobservable. An engine that fires released activations in the order its
blocked-token structure happens to yield does not conform.

**What this does not settle** ([STYL.2.15.4]). It does not say how an engine
represents a held-back match, nor that it must retain one at all: an engine
free to recompute the match on release conforms, provided the timetag it fires
under is the one the match first completed with. What is fixed is the
observable, and the observable is that the order carries no information about
the blocking.

*ratified*  —  *checks:* `tla×2` `idris×42`  —  *see also:* [IRET.7](#IRET-7), [LDET.1.1](#LDET-1-1), [LDET.5.4](#LDET-5-4), [LDET.5.5](#LDET-5-5)

(LDET-5-10)=
[LDET.5.10] **Join structure is not shared across rules, or across distinct
call sites of any construct that expands to more than one rule's worth of
pattern, when doing so would change activation-creation order.** [IRET.6.6]
permits sharing a single-schema, pre-join test between rules; nothing
analogous is permitted for join-level structure. A creation timetag is
assigned when a partial match completes ([LDET.5.5]); merging the join work
of two structurally identical productions into one shared structure would
complete their matches together, changing which one is assigned the earlier
timetag. The compiler must not perform such a merge, whatever produced the
duplication — literal repetition in source, or a construct that expands one
written form into several rules' worth of pattern.

*see also:* [IRET.6.6](#IRET-6-6), [LDET.5.5](#LDET-5-5)

(LDET-5-11)=
[LDET.5.11] **One step that removes several things removes them in an order
state fixes.** When a single engine step removes more than one fact from working
memory, or more than one entry from the cache ([LSTO.4.7]), the engine **must**
remove them in this order:

- **facts:** by when each entered working memory, the rank [LDET.5.5] already
  orders facts by;
- **facts a TTL sweep expires:** by deadline, earliest first, and facts that
  share a deadline by when each entered working memory, in either TTL mode
  ([LDTL.6.1], [LDTL.6.2]);
- **cache entries:** by when each entry's key was last set.

Everything the removals produce follows that order: the withdrawal records, the
retractions each one cascades into, and the cache-removal notifications the
integrator receives.

The steps this binds include a correlation sweep that supersedes several facts
at once, a cache TTL sweep, and a TTL sweep, `dynamic_ttl`'s included
([LDTL.1.2]).

Each order is a function of state a replay rebuilds exactly, so a run and its
replay remove in the same order ([LDET.5.9]). The order in which the engine's
own structures happen to be traversed **must not** affect it.

*ratified*  —  *see also:* [LDET.5.5](#LDET-5-5), [LDET.5.9](#LDET-5-9), [LDTL.1.2](#LDTL-1-2), [LDTL.6.1](#LDTL-6-1), [LDTL.6.2](#LDTL-6-2), [LSTO.4.7](#LSTO-4-7)

(LDET-5-6)=
[LDET.5.6] Implementations must honour this order. Implementations MAY
use internal data structures (hash tables, heaps, etc.) as
long as the observable firing order matches the spec.

*ratified*

(LDET-5-7)=
### Why this ordering and not another [LDET.5.7]

(LDET-5-7-1)=
[LDET.5.7.1] The spec picks a total order because *some* order must be
picked and a random-seeming one makes rules harder to reason
about. The ordinal-then-creation rule:

(LDET-5-7-3)=
- [LDET.5.7.3] Is **spatial author intent** — the rule written first wins,
  which is the same convention the language already uses for actions
  ([LLET.9.4]), `let` bindings ([LLET.9.3]) and `after` clauses
  ([LTAC.2.3]). Written order means something in DS, and rules are not the
  exception.

*see also:* [LLET.9.4](#LLET-9-4), [LLET.9.3](#LLET-9-3), [LTAC.2.3](#LTAC-2-3)

(LDET-5-7-4)=
- [LDET.5.7.4] Is stable across reorderings that don't touch the rule in
  question.

(LDET-5-7-5)=
- [LDET.5.7.5] Is spec-committed, so a DS author can learn it once and
  trust it.

(LDET-5-7-6)=
[LDET.5.7.6] Runtimes are forbidden from using any other ordering under
any circumstances.

---

(LDET-6)=
## Implementation commitments [LDET.6]

(LDET-6-1)=
### Conflict resolution [LDET.6.1]

(LDET-6-1-1)=
[LDET.6.1.1] The conflict resolver must honour [LDET.5] exactly.
It must not depend on:

*see also:* [LDET.5](#LDET-5)

(LDET-6-1-2)=
- [LDET.6.1.2] Hash table iteration order.

(LDET-6-1-3)=
- [LDET.6.1.3] Memory allocation order.

(LDET-6-1-4)=
- [LDET.6.1.4] OS thread scheduling.

(LDET-6-1-5)=
- [LDET.6.1.5] Input timing (within the same clock instant).

(LDET-6-1-6)=
- [LDET.6.1.6] Any source of randomness other than seeds explicitly
  provided by the event trace.

(LDET-6-2)=
### Floating-point arithmetic [LDET.6.2]

(LDET-6-2-1)=
[LDET.6.2.1] All floating-point operations use IEEE 754 double precision
with **default rounding mode (round-to-nearest, ties-to-even)**.

(LDET-6-2-2)=
- [LDET.6.2.2] Basic operations (+, −, ×, ÷, √) are correctly rounded by
  IEEE 754; identical across any conforming platform.

(LDET-6-2-3)=
- [LDET.6.2.3] Aggressive math optimisations (`-ffast-math`,
  `-funsafe-math-optimizations`) are **not permitted** for
  any arithmetic whose result affects observable output.
  These are the primary within-platform source of
  floating-point non-determinism (reassociation, denormal
  flushing, sin-cos fused approximations), and the spec
  forbids them outright.

(LDET-6-2-4)=
- [LDET.6.2.4] Denormal flush-to-zero is **not permitted**.

*ratified*

(LDET-6-2-6)=
[LDET.6.2.6] This is tighter than many language defaults, and
it costs nothing to hold: every admitted operation is
correctly-rounded IEEE 754 or integer, so there is no
platform-variable case left to bound. Within-platform and
cross-platform alike, full bit-determinism.

(LDET-6-3)=
### Integer arithmetic [LDET.6.3]

(LDET-6-3-1)=
[LDET.6.3.1] Integers are 64-bit signed. Overflow wraps in two's
complement (per [LEXP]). Division by zero and modulo by zero are
runtime errors with deterministic outcomes (exception with a
specific code).

*ratified*

(LDET-6-4)=
### Synthetic identifiers [LDET.6.4]

(LDET-6-4-1)=
[LDET.6.4.1] Synthetic names ([LLEX.10.6.1]:
`$CaptureBindings_outer_c0`, `$Timer_rule_N`, etc.) are generated from the
source text, not from wall-clock or random sources. Two runs of the same
compiler over the same source produce the same synthetic
names.

*see also:* [LLEX.10.6.1](#LLEX-10-6-1)

(LDET-6-4-2)=
[LDET.6.4.2] If an author's rules call a runtime UUID primitive (not in v1
but may come), the primitive must be seedable from the fact
stream. A "give me a random UUID" call that reads `/dev/urandom`
silently breaks determinism and is therefore not permitted.

(LDET-6-5)=
### Parallelism [LDET.6.5]

(LDET-6-5-1)=
[LDET.6.5.1] A runtime may execute rule activations in parallel as an
optimisation, provided the observable output matches the
sequential semantic defined by [LDET.5].

*see also:* [LDET.5](#LDET-5)

(LDET-6-5-2)=
[LDET.6.5.2] Practically, this means:

(LDET-6-5-3)=
- [LDET.6.5.3] Parallel activations may execute concurrently only if their
  RHS actions do not observably interact (no shared cache
  key, no shared emitted-fact schema, no overlapping `call`
  dispatch).

(LDET-6-5-4)=
- [LDET.6.5.4] A runtime using parallelism must prove to itself (via the
  compiler or a conservative analysis) that parallel
  execution is semantically equivalent to sequential
  execution in firing order.

(LDET-6-5-5)=
- [LDET.6.5.5] When in doubt, serialise. Performance is the reason to
  parallelise; determinism is non-negotiable.

(LDET-6-6)=
### Adapters [LDET.6.6]

(LDET-6-6-1)=
[LDET.6.6.1] Adapter behaviour is deterministic under the adapter-mock
contract: the same mock responses produce the same engine
behaviour. A real adapter contacting a real external system
is by definition not deterministic (external state is not a
DS input); to debug real-adapter behaviour, record a session
(per TESTING §Event-trace primitive) and replay with mocks.

---

(LDET-7)=
## Author-facing implications [LDET.7]

(LDET-7-1)=
[LDET.7.1] What this guarantee lets rule authors do:

(LDET-7-2)=
1. [LDET.7.2] **Trust that tests mean something.** If a test passes, the
   scenario it describes is passing for a reason — it will
   pass again on every run on every conforming runtime. If it
   fails intermittently, that is a test bug (non-deterministic
   input) or a runtime bug (violation of this guarantee), not
   a rule bug to work around.

(LDET-7-3)=
2. [LDET.7.3] **Replay production incidents exactly.** A recording of a
   production session, replayed against the same rule set and
   same adapter-mock responses, reproduces the incident bit-for-
   bit. The author can step, inspect, and understand without
   having to reproduce the real-world conditions.

(LDET-7-4)=
3. [LDET.7.4] **Trust the debugger's view.** When a debugger pauses at
   an instant and shows working memory / Rete network / agenda
   state, that state is exactly what it would be at that
   instant every time. Stepping backwards shows the state that
   was. No race conditions, no "it depends on timing."

(LDET-7-5)=
4. [LDET.7.5] **Diff two runs to find the change.** If a rule change
   produces different output, the difference is caused by
   the rule change — not by scheduling luck.

(LDET-7-6)=
5. [LDET.7.6] **Reason about rule behaviour from source.** Rule firing
   order is legible (with the debugger if not by eye) because
   it's determined by source and inputs ([LDET.4.2]) — not by hash-order or
   thread-timing.

*see also:* [LDET.4.2](#LDET-4-2)

(LDET-7-7)=
[LDET.7.7] What this guarantee does **not** grant:

(LDET-7-8)=
- [LDET.7.8] **Intuitive firing order.** Determinism says the order is
  reproducible; it doesn't say it's the order you'd expect
  from reading one rule in isolation. Use the debugger.

(LDET-7-9)=
- [LDET.7.9] **Real-time reproducibility.** Two runs with the same
  wall-clock schedule (i.e. outside replay mode) may differ
  observably because adapter responses genuinely varied. The
  guarantee is about the event trace, not the wall clock.

(LDET-7-10)=
- [LDET.7.10] **Performance parity across runtimes.** Runtime A may
  process a scenario in 10 ms; runtime B may take 100 ms;
  both may conform.

---

(LDET-8)=
## Interaction with other spec docs [LDET.8]

(LDET-8-1)=
### With testing [LDET.8.1]

(LDET-8-1-1)=
[LDET.8.1.1] [LTES.5] states determinism as a guaranteed property of the
event-trace mechanism. It is the same guarantee this document states; the
implementation commitments for it are here.

*see also:* [LTES.5](#LTES-5)

(LDET-8-2)=
### With debugging [LDET.8.2]

(LDET-8-2-1)=
[LDET.8.2.1] [LDEB.6.4] rests replay and branching on the determinism
guarantee this document states. Time-travel replay, bidirectional
navigation and fork-from-instant branching all depend on it being
unconditional.

*see also:* [LDEB.6.4](#LDEB-6-4)

(LDET-8-3)=
### With LOGICAL_FACTS [LDET.8.3]

(LDET-8-3-1)=
[LDET.8.3.1] Logical-fact multi-justifier coalescence must produce the
same fact set regardless of which justifier activated first
(within the spec-defined firing order). The coalescence
operation is commutative on the justifier set — add/remove
order does not affect the coalesced lifetime, provided each
add/remove event is at a spec-defined instant.

*ratified*

(LDET-8-4)=
### With cross-tier emit [LDET.8.4]

(LDET-8-4-1)=
[LDET.8.4.1] The publishing tier's engine emits cross-tier facts in a
deterministic sequence (same clock instant → same ordering
rule as intra-tier activations). Receiving tier sees the
same sequence.

(LDET-8-5)=
### With adapter discovery bursts [LDET.8.5]

(LDET-8-5-1)=
[LDET.8.5.1] Adapter connect-time seeds (discovery-driven adapters) emit
facts in a deterministic order: alphabetical by entity_id
or by the adapter's own declared enumeration order,
spec-committed rather than adapter-choice. Prevents replay
from differing when an adapter internally enumerates in an
order that happens to vary.

---

(LDET-9)=
## Consequences for the conformance suite [LDET.9]

(LDET-9-1)=
[LDET.9.1] The conformance contract lives in
[LCON], which specifies the test
categories every runtime must pass. The enumerated test
catalogue with named tests, scenarios, and pass criteria
lives runtime-side at
[RCTS].

(LDET-9-2)=
[LDET.9.2] Category summary:

(LDET-9-3)=
[LDET.9.3] **Within-platform (bit-identical required):**

(LDET-9-4)=
- [LDET.9.4] Byte-for-byte replay

(LDET-9-5)=
- [LDET.9.5] Rule-firing order

(LDET-9-6)=
- [LDET.9.6] Hash-order independence

(LDET-9-7)=
- [LDET.9.7] Parallelism regression

(LDET-9-8)=
- [LDET.9.8] Integer arithmetic stability

*ratified*

(LDET-9-9)=
- [LDET.9.9] Basic-float stability

*ratified*

(LDET-9-10)=
[LDET.9.10] **Cross-platform (bit-identity):**

(LDET-9-11)=
- [LDET.9.11] Rule-order identity

(LDET-9-12)=
- [LDET.9.12] Integer identity

(LDET-9-14)=
- [LDET.9.14] Boolean threshold stability

(LDET-9-15)=
[LDET.9.15] **Extended-capability:** deterministic clock, adapter mock,
event-trace record/replay, introspection surface.

(LDET-9-16)=
[LDET.9.16] A runtime that fails a within-platform test is
non-conforming. A runtime whose output on a cross-platform
test is not bit-identical is non-conforming: every
transcendental is correctly rounded ([LDET.3.4.4]), so no tolerance
applies ([LDET.3.4.1]). Per [LCON],
conformance is binary — pass every required test or be
non-conforming, with no partial-conformance levels.

*see also:* [LDET.3.4.1](#LDET-3-4-1), [LDET.3.4.4](#LDET-3-4-4)

(LDET-11)=
## Determinism refinements [LDET.11]

(LDET-11-4)=
4. [LDET.11.4] **Internal randomness is fixed-seed.** The one place randomness appears internally
   — the `sample <n>` reservoir
   time model ([LSMP]) — uses a
   **fixed-seed integer PRNG** (`xorshift64`, seed
   `0x9e3779b97f4a7c15`, advanced once per absorbed sample in
   event-trace order). That is a deterministic function of the input
   sequence — the seed-from-event-trace discipline this clause
   requires — and pure 64-bit integer arithmetic, so it is
   cross-platform bit-exact. Wall-clock or entropy-pool seeding would violate this
   guarantee.

(LDET-11-5)=
5. [LDET.11.5] **Real-world state enters through the adapter
   contract.** A primitive that read it any other way (filesystem,
   HTTP) would lose determinism for every scenario that used it.

