eyemind 0.3.5 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/SPEC.md +275 -190
  2. package/package.json +1 -1
  3. package/src/version.js +1 -1
package/SPEC.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ```text
4
4
  Title: The eyemind Rule Language and Proof Format
5
- Version: eyemind 0.3.5
5
+ Version: eyemind 0.3.7
6
6
  ```
7
7
 
8
8
  This document specifies the syntax and meaning of eyemind programs and data
@@ -103,7 +103,8 @@ Programs are JavaScript scripts. Conclusions, proofs and check reports are
103
103
  data documents whose expressions MUST be read without execution.
104
104
 
105
105
  The JavaScript library API, browser interface, installation and release
106
- procedures are outside this specification.
106
+ procedures are outside this specification. [Section 1.3](#13-terminology) defines the terms
107
+ used throughout.
107
108
 
108
109
  ### 1.2 Requirements and notation
109
110
 
@@ -121,27 +122,117 @@ its name and number of arguments.
121
122
 
122
123
  ### 1.3 Terminology
123
124
 
124
- - **Clause**: a fact, a forward rule or a backward rule.
125
+ These terms are used throughout. Each entry names the section that defines
126
+ it fully; where an entry and that section differ, the section governs.
127
+
128
+ Terms and matching:
129
+
130
+ - **Term**: an atom, a number, a variable or a compound ([Section 2.1](#21-kinds-of-terms)).
125
131
  - **Substitution**: an assignment of terms to variables.
126
132
  - **Instance**: the result of applying a substitution to a term or clause.
127
133
  - **Ground**: containing no variable.
128
- - **Identical**: equal by canonical text (Section 9), with each variable
129
- identical only to itself.
134
+ - **Identical**: equal by canonical text, with each variable identical only
135
+ to itself.
130
136
  - **Renamed apart**: with fresh variables, preserving all sharing within
131
137
  the renamed terms and avoiding capture of other variables.
132
- - **Conclusion**: a term reported by a run (Section 8.6).
133
- - **Document**: a sequence of expressions in the data syntax of Section 9.
138
+ - **Anonymous variable**: an occurrence of `_`, or a variable named `_`
139
+ followed by digits; inside a negation it stands for any value (Sections
140
+ [3.3](#33-term-construction) and [4.2](#42-controls)).
141
+ - **Canonical text**: the one spelling a writer gives a term (Sections [9.2](#92-canonical-atoms-numbers-variables-and-lists)
142
+ and [9.3](#93-canonical-compounds)).
143
+ - **Document**: a sequence of expressions in the data syntax of [Section 9](#9-document-syntax-and-canonical-text),
144
+ read without executing it.
145
+
146
+ Programs:
147
+
148
+ - **Clause**: a fact, a forward rule or a backward rule, numbered from 1 in
149
+ statement order ([Section 3.5](#35-clause-constraints-and-numbering)). `fact`, `implies` and `implied_by` state
150
+ them ([Section 3.4](#34-statements)); a query is a forward rule with the head `'true'`, and a
151
+ contradiction one with the head `'false'`.
152
+ - **Head** and **body**: the conclusions of a clause, and its premises.
153
+ - **Goal**: an atom, a compound, a variable bound to one of them, or a
154
+ conjunction of goals, to be solved ([Section 4.1](#41-goal-syntax)).
155
+ - **Control**: `and`, `or`, `not`, `call`, `once` or `findall` ([Section 4.2](#42-controls)).
156
+ A **negation** is a `not(G)` goal and a **collection** a
157
+ `findall(T, G, L)` goal.
158
+ - **Primitive**: a built-in goal such as `is` or `atom_concat` ([Section 4.3](#43-primitives)).
159
+ - **Rank** and **stratum**: a clause's rank is at least that of every
160
+ clause it depends on, and above that of every clause a negation or
161
+ collection in its body depends on; a stratum is the forward rules of one
162
+ rank ([Section 6.1](#61-dependencies-and-stratification)).
163
+ - **Rule template**: a rule written in a forward rule's conclusion; that
164
+ forward rule is its **generator** ([Section 6.2](#62-inline-rule-templates)).
165
+ - **Captured variable**: a template variable that also occurs in its
166
+ generator's body or ordinary heads ([Section 6.2](#62-inline-rule-templates)).
167
+ - **Appended clause**: the clause compiled from a template, numbered after
168
+ the stated clauses ([Section 6.2](#62-inline-rule-templates)).
169
+ - **Rule instance**: an appended clause with its captured variables bound by
170
+ one solution of its generator ([Section 6.2](#62-inline-rule-templates)).
171
+ - **Source inspection**: an `implies` or `implied_by` goal, which matches the
172
+ program's own rules as data ([Section 6.3](#63-source-rule-inspection)).
173
+
174
+ Runs:
175
+
176
+ - **Run**: one evaluation of a program: forward reasoning, then any goals
177
+ ([Section 8](#8-evaluation-and-conclusions)).
178
+ - **Derived fact**: a fact a forward rule adds during a run ([Section 8.2](#82-forward-evaluation-and-witnesses)).
179
+ - **Firing**: one solution of a forward rule's body, with the instance of
180
+ its heads it gives ([Section 8.2](#82-forward-evaluation-and-witnesses)).
181
+ - **Witness** or **Skolem term**: the term `skolem(Rule, Variable,
182
+ Arguments)` a firing gives a head variable its body leaves unbound
183
+ (Sections [7.2](#72-variables-and-witnesses) and [8.2](#82-forward-evaluation-and-witnesses)).
184
+ - **External goal**: a goal given to a run from outside the program
185
+ ([Section 8.4](#84-external-goals)).
186
+ - **Halt**: the end of a run that concludes `'false'`, with halt code 65
187
+ ([Section 8.5](#85-contradictions)).
188
+ - **Conclusion**: a term reported by a run ([Section 8.6](#86-reported-conclusions)).
134
189
  - **Reasoner**: a processor that evaluates programs and checks its generated
135
- proofs before returning them.
190
+ proofs before returning them ([Section 8.7](#87-proof-generation)).
136
191
  - **Checker**: a processor that verifies proof documents against a supplied
137
- program, without using reasoning to fill missing derivations.
192
+ program, without using reasoning to fill missing derivations ([Section 11](#11-proof-checking)).
193
+
194
+ Proofs:
195
+
196
+ - **Proof document**: a document recording how a run's conclusions follow
197
+ from the program ([Section 10](#10-proof-documents)). Its **claims** are its statements other
198
+ than `clause/2`, `step/4`, `searched/2`, `derived/2` and `called/2`
199
+ ([Section 10.1](#101-structure)).
200
+ - **Clause display**: `clause(N, Display)`, clause `N` in normalized form
201
+ ([Section 10.2](#102-clause-displays)).
202
+ - **Step**: `step(Goal, By, Bindings, Uses)`, the justification of one goal
203
+ by a clause, a primitive, a control, an absence or a collection; its
204
+ **uses** are the goals that justify it ([Section 10.3](#103-steps)).
205
+ - **Boundary**: a negation or collection that a proof justifies by an
206
+ `'absent'` or `'collected'` step ([Section 11.7](#117-c6-boundary-consistency)).
207
+ - **Search certificate**: the tables and listings that record the searches
208
+ behind a proof's boundaries ([Section 10.4](#104-search-certificates)).
209
+ - **Table**: `searched(Call, Answers)`, every answer of one call, in order
210
+ ([Section 10.4](#104-search-certificates)).
211
+ - **Listing**: `derived(Pattern, Facts)`, every fact a run derived for one
212
+ relation, in order ([Section 10.4](#104-search-certificates)).
213
+ - **Call table**: `called(Call, Answers)`, a table of a call made while
214
+ answering an original question, kept apart from the tables of the search
215
+ certificate and checked by C10 ([Section 10.5](#105-call-fidelity-certificates)).
216
+ - **Original question**: each external goal; without external goals, the
217
+ body of each query; without queries, each ordinary forward head. C10
218
+ checks the claims answering them ([Section 11.14](#1114-c10-call-fidelity)).
219
+ - **Settled**: established by its search certificate, as a boundary is when
220
+ C9 accepts that certificate ([Section 11.10](#1110-c9-search-closure)).
221
+ - **Trusted boundary**: a boundary that is not settled. A valid proof
222
+ assumes it, and its check report lists it as an **obligation**, as it
223
+ lists each claim whose call fidelity remains unproved (Sections [11.7](#117-c6-boundary-consistency),
224
+ [11.14](#1114-c10-call-fidelity) and [12](#12-check-reports)).
225
+ - **Check report**: what a checker writes: the claims, the outcome of each
226
+ of C1–C10, failures, obligations, counts and a verdict ([Section 12](#12-check-reports)).
227
+ - **Valid**: of a proof, failing no condition; a valid proof with
228
+ obligations is valid conditional on them ([Section 11.11](#1111-counts-and-validity)).
138
229
 
139
230
  ## 2. Terms
140
231
 
141
232
  ### 2.1 Kinds of terms
142
233
 
143
234
  A term is one of the following. The examples use document syntax; program
144
- construction is defined separately in Section 3.3.
235
+ construction is defined separately in [Section 3.3](#33-term-construction).
145
236
 
146
237
  | Kind | Meaning | Examples |
147
238
  | --- | --- | --- |
@@ -172,7 +263,7 @@ list** ends in `[]`. A tail left as a variable gives an **open list**;
172
263
  a non-list tail gives an **improper list**. Only the final item may be a
173
264
  spread tail; a program that spreads a logical variable or compound before
174
265
  the last item, as in `[...T, 1]`, MUST raise an error. In document syntax, `[...Tail]` denotes `Tail` itself.
175
- Program spread expressions also follow Section 3.3.
266
+ Program spread expressions also follow [Section 3.3](#33-term-construction).
176
267
 
177
268
  The empty list is the atom whose text is `[]`, so `'[]'` denotes the same
178
269
  term. A non-empty list has the compound structure exposed by `functor` and
@@ -181,7 +272,7 @@ term structure, not an alternative written list syntax. A character list
181
272
  contains one-character atoms.
182
273
 
183
274
  A non-empty proper list in a goal position denotes conjunction instead
184
- (Section 4.1). A list inside an ordinary argument remains list data.
275
+ ([Section 4.1](#41-goal-syntax)). A list inside an ordinary argument remains list data.
185
276
 
186
277
  ### 2.3 Identity and unification
187
278
 
@@ -202,7 +293,7 @@ Terms are totally ordered: variables, numbers, atoms, then compounds.
202
293
  Numbers are ordered by value, compared exactly across integers and floats;
203
294
  a float precedes an integer of equal value. Atoms are ordered by Unicode
204
295
  code point. Compounds are ordered by arity, then name, then arguments from
205
- left to right. Lists follow their compound structure (Section 2.2).
296
+ left to right. Lists follow their compound structure ([Section 2.2](#22-lists)).
206
297
 
207
298
  Variables are ordered by the code points of their names. Fresh variables
208
299
  introduced by renaming apart have unspecified names, so programs SHOULD NOT
@@ -219,19 +310,19 @@ construct its clauses. No import is required for the statements and term
219
310
  constructors defined here. Clauses are stated in the order their statement
220
311
  calls occur; multiple input scripts are processed in input order. Each
221
312
  script runs in a scope of its own: a name one script declares is, in
222
- another script, resolved as Section 3.2 specifies, so scripts share no
313
+ another script, resolved as [Section 3.2](#32-names) specifies, so scripts share no
223
314
  declarations.
224
315
 
225
- The supplied names are the statements of Section 3.4, `forward`, `backward`,
226
- `preds`, `vars`, `struct`, the controls and primitives of Section 4, the
316
+ The supplied names are the statements of [Section 3.4](#34-statements), `forward`, `backward`,
317
+ `preds`, `vars`, `struct`, the controls and primitives of [Section 4](#4-goals-and-primitives), the
227
318
  atom `fail`, and the library name `eyemind`. Library operations are outside
228
- this specification. Other names are resolved as Section 3.2 specifies.
319
+ this specification. Other names are resolved as [Section 3.2](#32-names) specifies.
229
320
 
230
321
  ### 3.2 Names
231
322
 
232
323
  A name a script does not declare or assign is resolved as follows:
233
324
 
234
- 1. a supplied name (Section 3.1) has that meaning;
325
+ 1. a supplied name ([Section 3.1](#31-scripts)) has that meaning;
235
326
  2. the JavaScript globals `Math`, `JSON`, `BigInt`, `Infinity`, `NaN`,
236
327
  `undefined`, `console`, `globalThis`, `parseInt`, `parseFloat`, `isNaN`
237
328
  and `isFinite` keep their meaning;
@@ -263,7 +354,7 @@ script discards, and a loader MAY accept it.
263
354
  ### 3.3 Term construction
264
355
 
265
356
  Program expressions construct terms as follows. This is distinct from
266
- reading a data document (Section 9.1).
357
+ reading a data document ([Section 9.1](#91-accepted-document-syntax)).
267
358
 
268
359
  | Program expression | Term constructed |
269
360
  | --- | --- |
@@ -272,16 +363,16 @@ reading a data document (Section 9.1).
272
363
  | An integral finite number, such as `2` or `2.0` | Integer. |
273
364
  | A non-integral finite number, such as `0.5` | Float. |
274
365
  | `float(N)`, where `N` is a finite JavaScript number | Float, including an integral value or signed zero. |
275
- | An implicit variable name, such as `X` | Variable (Section 3.2). |
366
+ | An implicit variable name, such as `X` | Variable ([Section 3.2](#32-names)). |
276
367
  | `p(T1, ..., Tn)`, with `n >= 1` | Compound named `p`, when `p` is a predicate constructor. |
277
368
  | `p` or `p()` | Atom `p`, when `p` is a predicate constructor. |
278
369
  | `struct(Name, T1, ..., Tn)` | Compound with the atom name `Name`; `struct(Name)` gives the atom. |
279
- | `[]`, `[T1, ..., Tn]`, `[Head, ...Tail]` | Lists (Section 2.2). |
370
+ | `[]`, `[T1, ..., Tn]`, `[Head, ...Tail]` | Lists ([Section 2.2](#22-lists)). |
280
371
 
281
372
  Thus `2.0` in a program is an integer; use `float(2)` for the float `2.0`.
282
373
  Applied to anything other than a JavaScript number, such as a `BigInt`, a
283
374
  string or a variable, `float(...)` is the ordinary compound `float/1`, the
284
- arithmetic function of Section 5.2: `is(Y, float(2n))` binds `Y` to `2.0`.
375
+ arithmetic function of [Section 5.2](#52-functions-and-arities): `is(Y, float(2n))` binds `Y` to `2.0`.
285
376
  Use a `BigInt` literal for an integer outside JavaScript's exact number
286
377
  range, for example `9007199254740993n`. Numeric expressions are evaluated by
287
378
  JavaScript before conversion to terms.
@@ -311,7 +402,7 @@ term. Such a result is converted by the rules above like any other
311
402
  number, so JavaScript arithmetic can lose integer precision, as in
312
403
  `2 ** 60 + 1`, or the distinction between integers and floats, as in
313
404
  `0.5 + 0.5`, which gives the integer 1. Programs SHOULD compute with `is`
314
- and the arithmetic functions of Section 5, such as `is(Y, add(3, 4))`.
405
+ and the arithmetic functions of [Section 5](#5-arithmetic), such as `is(Y, add(3, 4))`.
315
406
 
316
407
  ### 3.4 Statements
317
408
 
@@ -351,16 +442,16 @@ query(grandparent(X, Z))
351
442
 
352
443
  Queries are forward rules with head `'true'`; contradictions are forward
353
444
  rules with head `'false'`. Their reporting and halting behavior is defined
354
- in Section 8. `implies` and `implied_by` also return rule values. A value
445
+ in [Section 8](#8-evaluation-and-conclusions). `implies` and `implied_by` also return rule values. A value
355
446
  embedded in another statement contributes a template or inspection pattern
356
- as Section 6 specifies, instead of a separate clause.
447
+ as [Section 6](#6-rule-structure) specifies, instead of a separate clause.
357
448
 
358
- `facts_from` input MUST be read using Section 9.1 and MUST NOT be executed.
449
+ `facts_from` input MUST be read using [Section 9.1](#91-accepted-document-syntax) and MUST NOT be executed.
359
450
  It only states facts. A path requires file access; a text string does not.
360
451
 
361
452
  ### 3.5 Clause constraints and numbering
362
453
 
363
- After embedded rule calls have been excluded (Section 6.2), clauses are
454
+ After embedded rule calls have been excluded ([Section 6.2](#62-inline-rule-templates)), clauses are
364
455
  numbered from 1 in statement order. A multi-argument `fact` contributes one
365
456
  numbered clause per argument. Each clause records the source line where its
366
457
  statement call begins; facts read by `facts_from` use that call's line.
@@ -368,7 +459,7 @@ statement call begins; facts read by `facts_from` use that call's line.
368
459
  A clause MUST be rejected when:
369
460
 
370
461
  - a head is not an atom or compound, or is a list, the atom `'[]'` or a
371
- `'.'/2` compound, which as a goal would be a conjunction (Section 4.1) and
462
+ `'.'/2` compound, which as a goal would be a conjunction ([Section 4.1](#41-goal-syntax)) and
372
463
  could never call the clause;
373
464
  - a head uses `step/4`, `clause/2`, `searched/2`, `derived/2`, `called/2`, reserved
374
465
  for proof documents, or explicitly states the reserved predicate
@@ -380,9 +471,9 @@ A clause MUST be rejected when:
380
471
 
381
472
  Conjunctive bodies are flattened to their ordered goals. Conjunctive forward
382
473
  heads retain their order. Only a forward rule may have several heads;
383
- backward templates with several heads are expanded as Section 6.2 defines.
474
+ backward templates with several heads are expanded as [Section 6.2](#62-inline-rule-templates) defines.
384
475
  Reserved template and inspection forms are permitted only in the positions
385
- specified in Section 6.
476
+ specified in [Section 6](#6-rule-structure).
386
477
 
387
478
  ## 4. Goals and Primitives
388
479
 
@@ -417,10 +508,10 @@ implies(p(X), [q(X), r(X)]) // Two heads.
417
508
  ```
418
509
 
419
510
  The control meanings apply in goal contexts. Arithmetic terms with the
420
- names `and`, `or` and `not` instead have the meanings of Section 5.
511
+ names `and`, `or` and `not` instead have the meanings of [Section 5](#5-arithmetic).
421
512
 
422
513
  Unbound callable variables and forward dependencies are restricted by
423
- Section 6.1. A goal whose name and arity identify neither a control,
514
+ [Section 6.1](#61-dependencies-and-stratification). A goal whose name and arity identify neither a control,
424
515
  primitive, inspection form nor any clause head has no solution.
425
516
 
426
517
  ### 4.2 Controls
@@ -435,7 +526,7 @@ primitive, inspection form nor any clause head has no solution.
435
526
  | `findall(T, G, L)` | `findall(T, G, L)` | Unifies `L` with the list of instances of `T`, one per solution of `G`, in order, each renamed apart. |
436
527
 
437
528
  Anonymous variables are `_` occurrences and source variables named `_`
438
- followed by digits (Section 3.3), including their renamed-apart copies.
529
+ followed by digits ([Section 3.3](#33-term-construction)), including their renamed-apart copies.
439
530
 
440
531
  The term forms in the table have exactly the displayed arities. In program
441
532
  scripts, the following constructors additionally accept goal sequences:
@@ -468,7 +559,7 @@ primitive called outside its patterns raises an error.
468
559
  | `identical(@X, @Y)` | | `X` and `Y` are identical. |
469
560
  | `not_identical(@X, @Y)` | | `X` and `Y` are not identical. |
470
561
  | `compare(?O, @X, @Y)` | | Unifies `O` with `'<'`, `'='` or `'>'`, by the standard order. |
471
- | `is(?V, +E)` | | Evaluates `E` (Section 5) and unifies `V` with the result. |
562
+ | `is(?V, +E)` | | Evaluates `E` ([Section 5](#5-arithmetic)) and unifies `V` with the result. |
472
563
  | `eq(+E1, +E2)`, `ne(+E1, +E2)` | | The values of `E1` and `E2` are equal, or not. |
473
564
  | `lt(+E1, +E2)`, `le(+E1, +E2)`, `gt(+E1, +E2)`, `ge(+E1, +E2)` | | Compares the values of `E1` and `E2`. |
474
565
  | `is_var(@X)`, `is_nonvar(@X)` | | `X` is an unbound variable, or is not. |
@@ -482,7 +573,7 @@ primitive called outside its patterns raises an error.
482
573
  | `atom_chars` | `atom_chars(+A, ?L)`, `atom_chars(-A, +L)` | `L` is the list of `A`'s characters as atoms. |
483
574
  | `atom_codes` | `atom_codes(+A, ?L)`, `atom_codes(-A, +L)` | `L` is the list of `A`'s character code points. Each code MUST be an integer from 0 to 1114111 (0x10FFFF); a code of a lone surrogate gives that lone surrogate. |
484
575
  | `atom_length` | `atom_length(+A, ?N)` | `N` is the number of characters of `A`. |
485
- | `number_chars` | `number_chars(?N, +L)`, `number_chars(+N, -L)` | A bound `L` is read as a number: an optional sign and decimal digits give an integer, and with a fraction or an exponent a float, as in `'007'`, `'-21.5'`, `'.5'`, `'1.'` and `'2E-2'`; other text fails, as does text whose value is too large for a finite float, such as `'1e400'`. Otherwise `L` spells `N` in its canonical text (Section 9.2). |
576
+ | `number_chars` | `number_chars(?N, +L)`, `number_chars(+N, -L)` | A bound `L` is read as a number: an optional sign and decimal digits give an integer, and with a fraction or an exponent a float, as in `'007'`, `'-21.5'`, `'.5'`, `'1.'` and `'2E-2'`; other text fails, as does text whose value is too large for a finite float, such as `'1e400'`. Otherwise `L` spells `N` in its canonical text ([Section 9.2](#92-canonical-atoms-numbers-variables-and-lists)). |
486
577
  | `atom_concat` | `atom_concat(+A, +B, ?AB)`, `atom_concat(?A, ?B, +AB)` | `AB` is `A` followed by `B`; with `AB` given, every split, shortest `A` first. |
487
578
 
488
579
  A character is a Unicode code point. Every primitive except `atom_concat` has
@@ -492,7 +583,7 @@ patterns raises an error, as `atom_length(123, N)` does; one given arguments
492
583
  of the right kinds that has no solution fails, as `arg(5, f(1), A)` does.
493
584
 
494
585
  All primitives take exactly the displayed number of arguments. `functor`
495
- and `univ` expose list structure as specified in Section 2.2; use bracket
586
+ and `univ` expose list structure as specified in [Section 2.2](#22-lists); use bracket
496
587
  syntax when writing lists.
497
588
 
498
589
  ## 5. Arithmetic
@@ -500,14 +591,14 @@ syntax when writing lists.
500
591
  ### 5.1 Expressions
501
592
 
502
593
  An arithmetic expression is a number, a variable bound to an expression,
503
- one of the atoms `'pi'`, `'e'`, `'tau'`, or a function term from Section 5.2.
594
+ one of the atoms `'pi'`, `'e'`, `'tau'`, or a function term from [Section 5.2](#52-functions-and-arities).
504
595
  The constants denote binary64 approximations of pi, e and twice pi.
505
596
  Arguments of a function term are evaluated recursively. An unbound variable,
506
597
  an unknown function, an unsupported arity or any other atom is an error.
507
598
 
508
599
  Arithmetic is evaluated only where required by a primitive such as `is`,
509
600
  `eq` or `lt`. Elsewhere `add(1, 2)` is a compound term, not the number 3.
510
- Comparisons are goals (Section 4.3), not arithmetic expressions.
601
+ Comparisons are goals ([Section 4.3](#43-primitives)), not arithmetic expressions.
511
602
 
512
603
  ### 5.2 Functions and arities
513
604
 
@@ -540,9 +631,9 @@ inclusive range. Function names are written as calls, for example
540
631
  | `gcd`, `lcm` | 1 or more | Nonnegative integer greatest common divisor or least common multiple. |
541
632
 
542
633
  A zero-argument call denotes an atom, not a function term; only the three
543
- constant atoms of Section 5.1 are arithmetic values. A `float(N)` applied
634
+ constant atoms of [Section 5.1](#51-expressions) are arithmetic values. A `float(N)` applied
544
635
  directly to a JavaScript number in a script constructs a float immediately
545
- (Section 3.3).
636
+ ([Section 3.3](#33-term-construction)).
546
637
 
547
638
  ### 5.3 Numeric results
548
639
 
@@ -560,7 +651,7 @@ their exact quotient once to the nearest binary64 value, with halfway cases
560
651
  rounded to even, including in the subnormal range. Underflow to zero keeps
561
652
  the sign, and a zero quotient has the sign binary64 division gives it:
562
653
  `div(0, -5)` is `-0.0`. `sqrt(-0.0)` is `-0.0`. `round(X)` gives an integer; `round(X, Digits)` rounds to the
563
- specified number of decimal places. Float spelling is defined in Section 9.2.
654
+ specified number of decimal places. Float spelling is defined in [Section 9.2](#92-canonical-atoms-numbers-variables-and-lists).
564
655
 
565
656
  Numeric comparison is exact across integers and floats. Bitwise operations
566
657
  use unbounded two's-complement integers.
@@ -584,10 +675,10 @@ exceeds 2^26.
584
675
 
585
676
  A body goal depends on a clause when the goal, renamed apart, unifies with
586
677
  one of the clause's heads. The dependency is **closed** when the goal occurs
587
- inside a negation or as the goal of a collection (Section 4.2), and **open**
678
+ inside a negation or as the goal of a collection ([Section 4.2](#42-controls)), and **open**
588
679
  otherwise. Each clause has a rank: the least assignment such that a clause's
589
680
  rank is at least the rank of every clause it depends on, plus one for a closed
590
- dependency. Forward rules run in order of rank (Section 8.2).
681
+ dependency. Forward rules run in order of rank ([Section 8.2](#82-forward-evaluation-and-witnesses)).
591
682
 
592
683
  A program MUST be rejected when:
593
684
 
@@ -603,7 +694,7 @@ name MAY have different ranks.
603
694
  Nested `implies(Body, Head)` and `implied_by(Head, Body)` calls construct rule
604
695
  templates. A rule value in a conclusion MUST occur as a top-level conjunct of
605
696
  an `implies` conclusion; in a body, `implies` and `implied_by` are inspection
606
- goals (Section 6.3). A rule value anywhere else in a clause, such as an
697
+ goals ([Section 6.3](#63-source-rule-inspection)). A rule value anywhere else in a clause, such as an
607
698
  argument of an ordinary head or goal, or the template or result of `findall`,
608
699
  MUST be rejected. The conclusion MAY combine ordinary heads and several
609
700
  templates. Each template's
@@ -628,7 +719,7 @@ A template variable is **captured** when it also occurs in the generating
628
719
  clause's body or in an ordinary sibling head. The other variables are local
629
720
  to that template: they are universally quantified within the generated rule,
630
721
  except for head-only variables of a forward template, which receive witnesses
631
- as Section 8.2 describes. Variables shared only between sibling templates are
722
+ as [Section 8.2](#82-forward-evaluation-and-witnesses) describes. Variables shared only between sibling templates are
632
723
  local to each. Every call in a template body, including calls inside controls,
633
724
  MUST be statically named; a variable in a term's argument is permitted, but a
634
725
  variable used as a goal is not. A forward template MAY conclude further inline
@@ -670,12 +761,12 @@ each template conjunct by the list of its captured variables, in order of
670
761
  their first occurrence in the template as written, leaving ordinary
671
762
  heads in place. These lists are compiler data and are never concluded as
672
763
  facts. Only variables of this projection participate in that firing's witness
673
- construction (Section 8.2). A witness introduced by the generator remains
764
+ construction ([Section 8.2](#82-forward-evaluation-and-witnesses)). A witness introduced by the generator remains
674
765
  shared across every use of the derived rule; a witness introduced by a derived
675
766
  forward rule additionally depends on its captured context. An existential
676
767
  variable is a feature of a forward rule, not a third rule direction.
677
768
 
678
- All potential clauses participate in Section 6.1, including clauses whose
769
+ All potential clauses participate in [Section 6.1](#61-dependencies-and-stratification), including clauses whose
679
770
  generators never succeed. Each appended clause has an open dependency on its
680
771
  generator as well as the dependencies of its own body. Consequently, negation
681
772
  and collection wait for both the generator and all potential rules they may
@@ -693,7 +784,7 @@ templates and whose bodies contain no inspection goals, including inside
693
784
  controls. Facts, queries, contradictions, template generators and appended
694
785
  clauses are excluded. Inspecting rules therefore cannot inspect themselves.
695
786
  A rule value used as an inspection pattern is embedded in the inspecting
696
- statement (Section 6.2), so a stored rule value used as a pattern loses its
787
+ statement ([Section 6.2](#62-inline-rule-templates)), so a stored rule value used as a pattern loses its
697
788
  standalone clause and is not in the catalogue.
698
789
 
699
790
  The catalogue keeps source order. A rule's body and forward head conjunctions
@@ -707,15 +798,15 @@ Free variables supplied by a successful inspection are scoped universal
707
798
  pattern variables. Forward conclusions preserve them, including through
708
799
  backward derivations and copied collection results. Derived patterns are
709
800
  identified up to variable renaming and freshened, together with their evidence,
710
- at every use. Unrelated unbound variables keep Section 8.2's witness behavior.
801
+ at every use. Unrelated unbound variables keep [Section 8.2](#82-forward-evaluation-and-witnesses)'s witness behavior.
711
802
  When inspection variables remain free in a conclusion or its captured
712
803
  template context, that firing MUST NOT introduce head-only existential
713
804
  witnesses: it MUST fail with an error requiring the inspection variables to
714
- be bound first. Section 11.9 rejects certificates that bypass this boundary.
805
+ be bound first. [Section 11.9](#119-c8-witness-integrity) rejects certificates that bypass this boundary.
715
806
 
716
807
  Inspection uses a fixed source catalogue, so its own results do not depend on
717
808
  forward rounds. Other goals using derived patterns still participate in
718
- stratification. Negation and collection keep their own justifications (Section 10.3).
809
+ stratification. Negation and collection keep their own justifications ([Section 10.3](#103-steps)).
719
810
 
720
811
  ## 7. Semantics
721
812
 
@@ -723,27 +814,27 @@ stratification. Negation and collection keep their own justifications (Section 1
723
814
 
724
815
  Ordinary predicates have a **Herbrand interpretation**: ground terms denote
725
816
  themselves, and predicates relate those terms. The **Herbrand universe**
726
- contains the finite ground terms of Section 2, including values constructed
817
+ contains the finite ground terms of [Section 2](#2-terms), including values constructed
727
818
  by arithmetic or text operations and Skolem terms. The **Herbrand base** is
728
819
  the set of ordinary ground predicate applications over that universe,
729
820
  including predicates of arity 0. An interpretation is a subset of the base.
730
821
 
731
- Matching uses Section 2.3's unification, including its signed-zero rule.
822
+ Matching uses [Section 2.3](#23-identity-and-unification)'s unification, including its signed-zero rule.
732
823
  Asserting a relation does not change term identity. Controls, primitives
733
- and source inspection have the fixed meanings of Sections 4-6.
824
+ and source inspection have the fixed meanings of Sections [4](#4-goals-and-primitives)–[6](#6-rule-structure).
734
825
 
735
826
  ### 7.2 Variables and witnesses
736
827
 
737
828
  Variables of facts and backward clauses are universally quantified within
738
- their clause, except for collection-local variables (Section 4.2).
829
+ their clause, except for collection-local variables ([Section 4.2](#42-controls)).
739
830
  `fact(p(X))` states every ground instance of `p(X)`. Resolution may return
740
831
  a universal answer containing variables without enumerating its ground
741
- instances. Template variables have the scope of Section 6.2.
832
+ instances. Template variables have the scope of [Section 6.2](#62-inline-rule-templates).
742
833
 
743
834
  An unbound variable in a forward conclusion instead receives a witness,
744
- unless it is a scoped inspection variable (Section 6.3). For example,
835
+ unless it is a scoped inspection variable ([Section 6.3](#63-source-rule-inspection)). For example,
745
836
  `implies(person(X), has_token(X, T))` introduces an existential witness for
746
- `T`. Section 8.2 determines its Skolem term from the rule and head context,
837
+ `T`. [Section 8.2](#82-forward-evaluation-and-witnesses) determines its Skolem term from the rule and head context,
747
838
  including captured template values. Body variables absent from that context
748
839
  do not distinguish witnesses; shared head variables share a witness.
749
840
 
@@ -763,7 +854,7 @@ under further substitution. This fragment excludes negation, collection,
763
854
 
764
855
  Its meaning is the **least Herbrand model**: the smallest interpretation
765
856
  containing the facts and closed under ground rule instances, with matching
766
- as in Section 7.1. If a body holds, every head of that rule instance holds.
857
+ as in [Section 7.1](#71-herbrand-interpretation). If a body holds, every head of that rule instance holds.
767
858
  Existential forward rules extend this reading with the specified witnesses.
768
859
  The closure can be infinite.
769
860
 
@@ -776,9 +867,9 @@ the newly derived facts or selected answers printed by a run.
776
867
  ### 7.4 Negation and collection
777
868
 
778
869
  For stratified negation, interpret ranks in increasing order, fixing lower
779
- strata before testing absence at a higher rank (Section 6.1). `not(G)`
780
- holds when `G` has no solution, with the binding restrictions of Section
781
- 4.2. This is absence relative to the program, not falsity in the world.
870
+ strata before testing absence at a higher rank ([Section 6.1](#61-dependencies-and-stratification)). `not(G)`
871
+ holds when `G` has no solution, with the binding restrictions of [Section
872
+ 4.2](#42-controls). This is absence relative to the program, not falsity in the world.
782
873
  For relational goals this gives the stratified least-model reading.
783
874
 
784
875
  Collection also waits for its dependencies. `findall` collects ordered
@@ -790,7 +881,7 @@ list. Clause order and duplicate source clauses can affect that list.
790
881
  ### 7.5 Sets and operational behavior
791
882
 
792
883
  Derived facts and reported answers follow the duplicate-suppression rules
793
- of Section 8. These rules do not remove alternative search derivations.
884
+ of [Section 8](#8-evaluation-and-conclusions). These rules do not remove alternative search derivations.
794
885
  The unrestricted least-model reading alone therefore does not define every
795
886
  program's answers. `once` selects the first solution, and tests such as
796
887
  `is_var`, `identical` and `not_unify` can observe current bindings:
@@ -803,18 +894,18 @@ implied_by(p(X), [not_unify(X, 'a'), q(X)])
803
894
  The goal `p(X)` has no answer because the initial unbound `X` unifies with
804
895
  `'a'`, causing `not_unify` to fail. The goal `p('b')` succeeds. Forward
805
896
  rules calling such clauses can inherit their dependence on call bindings.
806
- Section 8 defines the observable goal, clause and result order.
897
+ [Section 8](#8-evaluation-and-conclusions) defines the observable goal, clause and result order.
807
898
 
808
899
  ### 7.6 Termination and proof claims
809
900
 
810
901
  Arithmetic, term construction and witness introduction can generate an
811
902
  infinite closure. A finite model does not ensure search termination:
812
903
  `implied_by(p(X), p(X))` has an empty least model, but searching `p('a')`
813
- recurs indefinitely. Exceeding a resource bound raises an error (Section
814
- 8.3). Contradictions halt without completing the closure (Section 8.5).
904
+ recurs indefinitely. Exceeding a resource bound raises an error ([Section
905
+ 8.3](#83-resource-bounds)). Contradictions halt without completing the closure ([Section 8.5](#85-contradictions)).
815
906
  A valid proof establishes only its claims subject to its trusted boundaries
816
- (Section 11.12), not completeness of the model or the answers. Its search
817
- certificate settles the negations and collections it can (Section 10.4).
907
+ ([Section 11.12](#1112-scope-of-a-valid-proof)), not completeness of the model or the answers. Its search
908
+ certificate settles the negations and collections it can ([Section 10.4](#104-search-certificates)).
818
909
 
819
910
  ## 8. Evaluation and Conclusions
820
911
 
@@ -822,7 +913,7 @@ certificate settles the negations and collections it can (Section 10.4).
822
913
 
823
914
  Goals are solved depth-first, left to right. A goal is solved, in order:
824
915
 
825
- 1. by a control, primitive or source inspection (Sections 4 and 6.3), when
916
+ 1. by a control, primitive or source inspection (Sections [4](#4-goals-and-primitives) and [6.3](#63-source-rule-inspection)), when
826
917
  it is one;
827
918
  2. otherwise against the facts derived so far by forward rules with the same
828
919
  name and arity, in the order they were derived;
@@ -837,7 +928,7 @@ head meets the goal, and searches only its own body.
837
928
 
838
929
  ### 8.2 Forward evaluation and witnesses
839
930
 
840
- Forward rules run stratum by stratum, in increasing rank (Section 6.1). Within
931
+ Forward rules run stratum by stratum, in increasing rank ([Section 6.1](#61-dependencies-and-stratification)). Within
841
932
  a stratum, rounds are repeated until a round adds no new fact or rule instance.
842
933
  In a round, clauses run in clause order. An appended clause runs its derived
843
934
  instances in the order they were created; a potential clause with no instance
@@ -851,7 +942,7 @@ and `p(2)` publishes `a(1)`, `b(1)`, `a(2)`, `b(2)`. For each head:
851
942
  - a head variable the solution leaves unbound is bound to a **Skolem term**
852
943
  `skolem(Rule, Variable, Arguments)`: `Rule` is the clause number of the
853
944
  rule, `Variable` the name of the head variable the term stands for, as the
854
- program writes it (an anonymous one as `_0`, `_1`, ..., Section 3.3), and
945
+ program writes it (an anonymous one as `_0`, `_1`, ..., [Section 3.3](#33-term-construction)), and
855
946
  `Arguments` the list of
856
947
  the ground values the solution gives the heads' other variables, in order
857
948
  of their first occurrence in the heads. A Skolem term is thus a function of
@@ -864,33 +955,31 @@ and `p(2)` publishes `a(1)`, `b(1)`, `a(2)`, `b(2)`. For each head:
864
955
  for, keeps its own name when no other term of the firing has it; the
865
956
  others take that name followed by the first of `1`, `2`, ... that is
866
957
  free, in order of first occurrence in the heads. A rule that keeps meeting new firings does
867
- not terminate (Section 8.3). Derived facts other than scoped inspection
868
- patterns (Section 6.3) are therefore ground. A
869
- checker verifies the Skolem terms of a proof (C8, Section 11.9);
958
+ not terminate ([Section 8.3](#83-resource-bounds)). Derived facts other than scoped inspection
959
+ patterns ([Section 6.3](#63-source-rule-inspection)) are therefore ground. A
960
+ checker verifies the Skolem terms of a proof (C8, [Section 11.9](#119-c8-witness-integrity));
870
961
  - a head `'true'` reports the instance of the rule's body, as a conjunction,
871
962
  once per distinct instance (by identity of canonical text);
872
963
  - a head `'false'` records the conclusion `'false'` and stops all reasoning
873
964
  with halt code 65;
874
- - a template head derives a rule instance as specified in Section 6.2;
965
+ - a template head derives a rule instance as specified in [Section 6.2](#62-inline-rule-templates);
875
966
  - any other head is added as a derived fact unless an identical fact is
876
967
  already derived or is a ground fact of the program.
877
968
 
878
- When the run asks its own goals (Section 8.4), rules whose heads are all
969
+ When the run asks its own goals ([Section 8.4](#84-external-goals)), rules whose heads are all
879
970
  `'true'` are not run.
880
971
 
881
- For a generator, use its scope projection (Section 6.2) as its head when
882
- constructing witnesses. For an appended forward clause of Section 6.2,
972
+ For a generator, use its scope projection ([Section 6.2](#62-inline-rule-templates)) as its head when
973
+ constructing witnesses. For an appended forward clause of [Section 6.2](#62-inline-rule-templates),
883
974
  prepend one element to
884
975
  `Arguments`: the grounded capture list of its rule instance. This distinguishes
885
976
  witnesses of different captured contexts even when a head does not mention
886
977
  those values. An empty capture list still contributes one element, `[]`.
887
978
  Original clauses, including generators, use the ordinary witness convention.
888
979
 
889
- Scoped inspection variables of Section 6.3 are preserved instead of receiving
890
- witnesses; derived conclusions may therefore be universal patterns. Each use
891
- renames a pattern and its evidence apart. Such patterns are suppressed when
892
- an alpha-equivalent pattern was already derived. Other derived facts keep
893
- their ordinary ground identity convention.
980
+ Scoped inspection variables ([Section 6.3](#63-source-rule-inspection)) are preserved instead of receiving
981
+ witnesses, so such a conclusion is a universal pattern. It is not added when
982
+ a pattern identical up to renaming of its variables was already derived.
894
983
 
895
984
  ### 8.3 Resource bounds
896
985
 
@@ -913,7 +1002,7 @@ as complete. The bounds count as follows:
913
1002
 
914
1003
  A run that exceeds a bound concludes nothing: the command line writes no
915
1004
  conclusions to standard output, even answers found before the bound was
916
- reached, and exits with code 1 (Section 13.1).
1005
+ reached, and exits with code 1 ([Section 13.1](#131-invocation-and-options)).
917
1006
 
918
1007
  Each supplied bound MUST be a positive integer no greater than 9007199254740991.
919
1008
 
@@ -945,11 +1034,11 @@ Rule instances are not facts and cannot be queried as enabling predicates.
945
1034
  The `derived` statistic counts only facts added during reasoning.
946
1035
 
947
1036
  The output of a run is a comment line saying which of these the conclusions
948
- are, followed by the canonical text (Section 9) of each conclusion, one per
1037
+ are, followed by the canonical text ([Section 9](#9-document-syntax-and-canonical-text)) of each conclusion, one per
949
1038
  line. The comment MUST say when the run halted, when the conclusions answer
950
1039
  goals, when they answer `query()` rules, or when they are derived facts, and
951
1040
  MUST say so when there are none. Comments are informative and MAY be worded
952
- differently; they are ignored when the output is read (Section 9.1).
1041
+ differently; they are ignored when the output is read ([Section 9.1](#91-accepted-document-syntax)).
953
1042
 
954
1043
  ### 8.7 Proof generation
955
1044
 
@@ -957,13 +1046,13 @@ When a proof is requested, each solution records how each of its goals was
957
1046
  justified: by a fact or rule of the program, by a derived fact (whose own
958
1047
  record is kept), by a primitive, by a control, by an absence (a negation) or
959
1048
  by a collection (`findall`). For each conclusion the first derivation found is
960
- recorded. Each original question gets call-fidelity evidence (Sections 10.5 and 11.14),
1049
+ recorded. Each original question gets call-fidelity evidence (Sections [10.5](#105-call-fidelity-certificates) and [11.14](#1114-c10-call-fidelity)),
961
1050
  when supported. Each negation and collection of a proof gets the search certificate
962
- that settles it (Sections 10.4 and 11.10) whenever Section 11.10 allows one. A
1051
+ that settles it (Sections [10.4](#104-search-certificates) and [11.10](#1110-c9-search-closure)) whenever [Section 11.10](#1110-c9-search-closure) allows one. A
963
1052
  table holds every answer of its call, so it can search beyond where the run
964
1053
  stopped, as under `once`; a boundary whose tables would meet an error, or
965
- exceed `max_inferences` calls and answers (Section 8.3), stays trusted. A
966
- reasoner MUST check every proof it generates (Section 11) before returning it,
1054
+ exceed `max_inferences` calls and answers ([Section 8.3](#83-resource-bounds)), stays trusted. A
1055
+ reasoner MUST check every proof it generates ([Section 11](#11-proof-checking)) before returning it,
967
1056
  and MUST fail with an error rather than return a proof that does not pass. A
968
1057
  run without conclusions has a proof without claims, which is valid and
969
1058
  certifies nothing.
@@ -976,7 +1065,7 @@ cannot produce a proof.
976
1065
 
977
1066
  A document is data, not a program. Readers MUST use the syntax below and
978
1067
  MUST NOT execute any expression. Writers MUST use the canonical forms of
979
- Sections 9.2-9.4. The grammar is given in Appendix A.
1068
+ Sections [9.2](#92-canonical-atoms-numbers-variables-and-lists)–[9.4](#94-variable-scope-in-output). The grammar is given in [Appendix A](#appendix-a-document-grammar).
980
1069
 
981
1070
  ### 9.1 Accepted document syntax
982
1071
 
@@ -991,12 +1080,12 @@ expression per line. Readers accept exactly:
991
1080
  - a decimal integer literal with optional suffix `n`, or a finite decimal
992
1081
  float literal containing a point or exponent: a number;
993
1082
  - a name: the variable of that name, where each `_` is a new anonymous
994
- variable (Section 4.2) and a name starting with `VAR_` is decoded
995
- (Section 9.2), with malformed encodings rejected; a decoded name is a
1083
+ variable ([Section 4.2](#42-controls)) and a name starting with `VAR_` is decoded
1084
+ ([Section 9.2](#92-canonical-atoms-numbers-variables-and-lists)), with malformed encodings rejected; a decoded name is a
996
1085
  named variable even when it is `_`, so `VAR___` twice is one variable;
997
1086
  - a call of a plain name: the compound, or the atom when there are no
998
- arguments; `struct('name', ...)` as in Section 9.3; `and` and `or` with
999
- more than two arguments as in Section 4.2;
1087
+ arguments; `struct('name', ...)` as in [Section 9.3](#93-canonical-compounds); `and` and `or` with
1088
+ more than two arguments as in [Section 4.2](#42-controls);
1000
1089
  - an array literal: the list, where only the last item MAY be spread
1001
1090
  (`...Tail`) and then is the tail; `[...T]` is `T`;
1002
1091
  - an object literal `{K: V, ...}` whose keys are names or strings: the list
@@ -1025,7 +1114,7 @@ variable; use `'alice'` for an atom. A no-argument call such as `alice()`
1025
1114
  also denotes the atom. `2` and `2n` denote integers, while `2.0` and `2e0`
1026
1115
  denote floats. `float(2)` is a compound expression, not a float literal.
1027
1116
  Array syntax denotes list data; only reading it as a goal applies the
1028
- conjunction rules of Section 4.1.
1117
+ conjunction rules of [Section 4.1](#41-goal-syntax).
1029
1118
 
1030
1119
  String escapes are `\\`, `\'`, `\"`, `\n`, `\r`, `\t`, `\b`, `\f`,
1031
1120
  `\v`, `\0` (not followed by a decimal digit), `\xHH`, `\uHHHH` and
@@ -1066,18 +1155,18 @@ Object keys may also use these reserved names, since keys denote atom text.
1066
1155
  digits, such as `1e+22` or `1e-05`.
1067
1156
  - A variable is written as its name when the name is an ASCII identifier
1068
1157
  (letters, digits and `_`, not starting with a digit), not a reserved name
1069
- of Section 9.1, not `_` and does not begin with `VAR_`. Any other name is
1158
+ of [Section 9.1](#91-accepted-document-syntax), not `_` and does not begin with `VAR_`. Any other name is
1070
1159
  written `VAR_` followed by the name with every ASCII letter and digit kept,
1071
1160
  every `_` doubled and every other character `c` replaced by `_hex_` where
1072
1161
  `hex` is the lowercase hexadecimal code point of `c`. The variable name `A-B`
1073
1162
  is thus written `VAR_A_2d_B`. A reader decodes such a name back
1074
- (Section 9.1).
1163
+ ([Section 9.1](#91-accepted-document-syntax)).
1075
1164
  - A list is written `[I1, I2, ...]`; an open list ends with `, ...Tail`.
1076
1165
 
1077
1166
  ### 9.3 Canonical compounds
1078
1167
 
1079
1168
  A compound is written `name(A1, A2, ...)` when its name is an ASCII
1080
- identifier, not a reserved name of Section 9.1 and not `struct`, and
1169
+ identifier, not a reserved name of [Section 9.1](#91-accepted-document-syntax) and not `struct`, and
1081
1170
  `struct('name', A1, ...)` otherwise. Arguments are separated by `, `.
1082
1171
 
1083
1172
  A chain of conjunctions or disjunctions built from the left,
@@ -1087,23 +1176,24 @@ A chain of conjunctions or disjunctions built from the left,
1087
1176
 
1088
1177
  ### 9.4 Variable scope in output
1089
1178
 
1090
- The conclusions a run writes, its proof documents (Section 10) and check
1091
- reports (Section 12) use the following variable names. In
1179
+ The conclusions a run writes, its proof documents ([Section 10](#10-proof-documents)) and check
1180
+ reports ([Section 12](#12-check-reports)) use the following variable names. In
1092
1181
  the conclusions of a run and in a proof document, the variables are named
1093
1182
  `A`, `B`, ..., `Z`, `A1`, ..., `Z1`, `A2`, ... in the order the document
1094
1183
  first shows them, across the whole document, the conclusions written first;
1095
1184
  the clause displays of a proof keep the program's names. A check report
1096
- names the variables of each fact anew (Section 12).
1097
- Call tables have a separate naming scope and preserve anonymous-variable
1098
- status as specified in Section 10.5.
1185
+ names the variables of each fact anew ([Section 12](#12-check-reports)).
1186
+ The call tables of a proof (`called/2`, [Section 10.5](#105-call-fidelity-certificates)) name their variables
1187
+ in a scope of their own, keeping anonymous variables distinct from named
1188
+ ones.
1099
1189
 
1100
1190
  ## 10. Proof Documents
1101
1191
 
1102
1192
  ### 10.1 Structure
1103
1193
 
1104
- A proof document is a document (Section 9.1) holding, in this order:
1194
+ A proof document is a document ([Section 9.1](#91-accepted-document-syntax)) holding, in this order:
1105
1195
 
1106
- 1. the output of the run (Section 8.6): its comment line, then its
1196
+ 1. the output of the run ([Section 8.6](#86-reported-conclusions)): its comment line, then its
1107
1197
  conclusions, one per line;
1108
1198
  2. an empty line;
1109
1199
  3. when the proof cites any clause, a comment line introducing the clauses,
@@ -1112,10 +1202,10 @@ A proof document is a document (Section 9.1) holding, in this order:
1112
1202
  4. an empty line;
1113
1203
  5. when there are steps, comment lines saying what a step records, then one
1114
1204
  `step(Goal, By, Bindings, Uses)` per justified goal;
1115
- 6. when it has a search certificate (Section 10.4), an empty line, comment
1205
+ 6. when it has a search certificate ([Section 10.4](#104-search-certificates)), an empty line, comment
1116
1206
  lines introducing it, then one `derived(Pattern, Facts)` per listed
1117
1207
  relation, then one `searched(Call, Answers)` per table;
1118
- 7. then any `called(Call, Answers)` tables (Section 10.5), in first-consulted
1208
+ 7. then any `called(Call, Answers)` tables ([Section 10.5](#105-call-fidelity-certificates)), in first-consulted
1119
1209
  order and with their own variable naming scope.
1120
1210
 
1121
1211
  Comments are informative and MAY be worded differently; they are ignored when
@@ -1123,7 +1213,6 @@ the document is read.
1123
1213
 
1124
1214
  A checker MUST treat every statement that is neither `clause/2`, `step/4`,
1125
1215
  `searched/2`, `derived/2` nor `called/2` as a claim, whatever its position.
1126
- Call tables follow the other search certificate statements (Section 10.5).
1127
1216
 
1128
1217
  ### 10.2 Clause displays
1129
1218
 
@@ -1135,14 +1224,14 @@ array of heads, and `G1, ...` are the body goals themselves. Displays are not
1135
1224
  authority: a checker MUST compare each with the program it checks against.
1136
1225
 
1137
1226
  Each argument of a multi-argument `fact` has its own `fact(Head)` display.
1138
- A body is displayed with its conjunctions flattened (Section 3.5), whether
1227
+ A body is displayed with its conjunctions flattened ([Section 3.5](#35-clause-constraints-and-numbering)), whether
1139
1228
  the program wrote them as arrays or with `and`: `implied_by(r, and(a, b))`
1140
1229
  has display `implied_by('r', ['a', 'b'])`.
1141
1230
  Conjunctive query and contradiction bodies are displayed as separate goal
1142
1231
  arguments: `query([p(X), q(X)])` has display `query(p(X), q(X))`.
1143
1232
 
1144
1233
  For a program with templates, displays show the original generators and the
1145
- potential appended clauses of Section 6.2. A derived rule's body includes all
1234
+ potential appended clauses of [Section 6.2](#62-inline-rule-templates). A derived rule's body includes all
1146
1235
  enclosing generator premises. The source program is the authority for its
1147
1236
  origin, captures and scope projections; a display cannot introduce a new
1148
1237
  rule. A reasoner displays the enclosing generators as well as the clauses its
@@ -1172,7 +1261,7 @@ order. `By` is one of:
1172
1261
 
1173
1262
  `Bindings` is an object from each variable name of the cited clause, as
1174
1263
  the program wrote it, to its value in this step: `{X: 'socrates'}`. A key
1175
- that is a plain name of Section 9.2 is written bare, and any other name as a
1264
+ that is a plain name of [Section 9.2](#92-canonical-atoms-numbers-variables-and-lists) is written bare, and any other name as a
1176
1265
  string, such as `{'A-B': 1}`. A
1177
1266
  reasoner writes every variable of the clause, in the order the clause display
1178
1267
  first shows them (for `implies`, the premise first);
@@ -1192,18 +1281,18 @@ proof's negations and collections:
1192
1281
 
1193
1282
  - `searched(Call, Answers)` is a **table**: `Call` is a goal as one of those
1194
1283
  searches called it, and `Answers` the array of its answers, each the
1195
- instance of `Call` that one solution gave, in the order of Section 8.1,
1284
+ instance of `Call` that one solution gave, in the order of [Section 8.1](#81-goal-search),
1196
1285
  repetitions included. Each answer's variables are its own: they are shared
1197
1286
  neither with `Call` nor with another answer.
1198
1287
  - `derived(Pattern, Facts)` is a **listing**: `Pattern` is the name of a
1199
1288
  relation that forward rules conclude, applied to distinct variables, or the
1200
1289
  name alone for arity 0, and `Facts` the array of every fact the run derived
1201
- for that relation, in the order derived (Section 8.2). Each listed fact has
1290
+ for that relation, in the order derived ([Section 8.2](#82-forward-evaluation-and-witnesses)). Each listed fact has
1202
1291
  steps of its own.
1203
1292
 
1204
1293
  A table exists for each call to a relation that a backward rule defines or
1205
1294
  forward rules conclude, made by those searches or by the closure checks of
1206
- Section 11.10; a call to a relation defined by facts alone needs none. A
1295
+ [Section 11.10](#1110-c9-search-closure); a call to a relation defined by facts alone needs none. A
1207
1296
  listing exists for each relation forward rules conclude that a table or a
1208
1297
  closure check consults. A reasoner writes only the tables and listings of
1209
1298
  the boundaries it settles: listings first, in the order first consulted,
@@ -1217,15 +1306,13 @@ searched(nonpacifist('ada'), [])
1217
1306
  ### 10.5 Call-fidelity certificates
1218
1307
 
1219
1308
  `called(Call, Answers)` is a **call table**. Its shape and answer ordering
1220
- are those of `searched/2` (Section 10.4), but it certifies calls made from
1221
- the original questions. C10 is always checked, including when the document
1222
- has no call tables. External questions remain inputs to the checker: a
1223
- table cannot supply or specialize the question to which a claim must answer.
1224
- Missing call evidence remains an explicit obligation, never an unconditional
1225
- `checked` verdict (Section 11.14).
1309
+ are those of `searched/2` ([Section 10.4](#104-search-certificates)), but it records a call made while
1310
+ answering an original question, for C10 ([Section 11.14](#1114-c10-call-fidelity)). External goals
1311
+ remain inputs to the checker: a call table cannot supply or specialize the
1312
+ question a claim must answer.
1226
1313
 
1227
1314
  Two calls identify the same call table only when they are identical up to
1228
- renaming **that preserves anonymous-variable status** (Section 4.2), including
1315
+ renaming **that preserves anonymous-variable status** ([Section 4.2](#42-controls)), including
1229
1316
  inside nested compounds. There MUST NOT be two such tables. An anonymous
1230
1317
  variable cannot be renamed to a named one, or vice versa, when comparing
1231
1318
  call-table answers either. These restrictions matter because a named unbound
@@ -1241,7 +1328,7 @@ For example, a named call returning an anonymous parameter may be:
1241
1328
  called(p(A), [p(_1)])
1242
1329
  ```
1243
1330
 
1244
- Each answer is freshened separately when used, as in Section 10.4. C10 call
1331
+ Each answer is freshened separately when used, as in [Section 10.4](#104-search-certificates). C10 call
1245
1332
  tables and C9 search tables are distinct, even for textually identical calls.
1246
1333
  They share any applicable `derived/2` listings, whose facts require steps.
1247
1334
 
@@ -1251,15 +1338,15 @@ A checker is given a program, a proof document and, when the proof answers
1251
1338
  goals asked from outside the program, those goals. It MUST NOT call a
1252
1339
  reasoner to supply a missing step; it MAY recompute primitives, and it MAY
1253
1340
  expand a call one level against the program with every inner call answered
1254
- by the search certificate (Section 11.10). It
1341
+ by the search certificate ([Section 11.10](#1110-c9-search-closure)). It
1255
1342
  checks C1–C10 and records each failure with its condition, a
1256
1343
  detail and, where there is one, the term concerned.
1257
1344
 
1258
1345
  ### 11.1 Reading the document
1259
1346
 
1260
- The document MUST read (Section 9.1); otherwise C3 fails and the document has
1347
+ The document MUST read ([Section 9.1](#91-accepted-document-syntax)); otherwise C3 fails and the document has
1261
1348
  no claims and no steps. Each `clause(N, Display)` MUST name a clause of the
1262
- program whose display (Section 10.2) is identical to `Display`, variable
1349
+ program whose display ([Section 10.2](#102-clause-displays)) is identical to `Display`, variable
1263
1350
  names included, so a display that merely renames the clause's variables
1264
1351
  differs; otherwise C1 fails. Each `step` MUST have bindings that read as a list of `'='/2` pairs,
1265
1352
  as an object literal does, and a list of uses, and no two steps may have
@@ -1268,7 +1355,7 @@ statement MUST have a callable `Call` and an array of answers, and a
1268
1355
  `derived` statement a callable `Pattern` and an array of facts; no two tables
1269
1356
  may have calls identical up to renaming of their variables, and no two
1270
1357
  listings may name the same relation; otherwise C3 fails and the statement is
1271
- set aside. Every other statement is a claim (Section 10.1).
1358
+ set aside. Every other statement is a claim ([Section 10.1](#101-structure)).
1272
1359
 
1273
1360
  ### 11.2 C1 Resolution
1274
1361
 
@@ -1288,8 +1375,8 @@ program. Its bindings may name variables of those generators' scope
1288
1375
  projections as well as of the clause itself. The checker renames these
1289
1376
  projections together with the clause before applying the bindings.
1290
1377
 
1291
- For a `source(N)` step, `N` MUST identify an eligible source rule of Section
1292
- 6.3. Bindings and uses MUST both be empty. The rule's inspection term,
1378
+ For a `source(N)` step, `N` MUST identify an eligible source rule of [Section
1379
+ 6.3](#63-source-rule-inspection). Bindings and uses MUST both be empty. The rule's inspection term,
1293
1380
  renamed apart, MUST unify with `Goal` and resolve exactly
1294
1381
  to it without instantiating the step's own terms. This checks variable
1295
1382
  sharing as well as the rule's direction and structure. The source rule is
@@ -1307,7 +1394,7 @@ failure, whose conclusion is the goal of that step.
1307
1394
 
1308
1395
  ### 11.4 C3 Justification
1309
1396
 
1310
- `By` MUST be one of the forms of Section 10.3. A `'builtin'` step MUST have
1397
+ `By` MUST be one of the forms of [Section 10.3](#103-steps). A `'builtin'` step MUST have
1311
1398
  no bindings and no uses and a goal that is a primitive; an `'absent'` or
1312
1399
  `'collected'` step MUST have no bindings and no uses and a goal that is a
1313
1400
  negation or a `findall`, respectively. A step that fails C3 is not a trusted
@@ -1334,7 +1421,7 @@ Host math is the one exception to identical re-decision. A `'builtin'` step
1334
1421
  `log10`, a trigonometric or hyperbolic function, or `pow`, also passes C5
1335
1422
  when `E` evaluates to a float at most 4 units in the last place from `V`,
1336
1423
  that is, with at most 3 floats between them. Such results may differ between
1337
- conforming implementations (Section 14). C5 therefore accepts this bounded
1424
+ conforming implementations ([Section 14](#14-conformance)). C5 therefore accepts this bounded
1338
1425
  variation. C10 still compares actual answers of the original question;
1339
1426
  when those answers depend on host math, a proof MAY fail C10 on another
1340
1427
  implementation even when its primitive steps pass C5. Every other recomputed result MUST be identical; a difference
@@ -1344,7 +1431,7 @@ proof fail on an implementation other than the one that made it.
1344
1431
  ### 11.7 C6 Boundary consistency
1345
1432
 
1346
1433
  A negation or collection is a **boundary**. A boundary that its search
1347
- certificate settles or refutes is checked by C9 (Section 11.10); C6
1434
+ certificate settles or refutes is checked by C9 ([Section 11.10](#1110-c9-search-closure)); C6
1348
1435
  confronts every other well-formed boundary step with the evidence at hand.
1349
1436
 
1350
1437
  A boundary that is not settled cannot be proved, but the evidence at
@@ -1364,7 +1451,7 @@ could refute the boundary, and it is left undecided.
1364
1451
  decided when `G` is a single goal with evidence. It fails C6 when an
1365
1452
  instance of `T` for some evidence of `G` unifies with no element of `L`.
1366
1453
 
1367
- A trusted boundary that is not refuted remains an obligation (Section 12).
1454
+ A trusted boundary that is not refuted remains an obligation ([Section 12](#12-check-reports)).
1368
1455
 
1369
1456
  ### 11.8 C7 Relevance
1370
1457
 
@@ -1381,12 +1468,12 @@ or closure check of some boundary.
1381
1468
 
1382
1469
  A forward rule's head MAY contain variables its body does not contain; each
1383
1470
  says that something exists, and a reasoner concludes it with a Skolem term
1384
- (Section 8.2). C1 alone would accept any value for such a variable, since any
1471
+ ([Section 8.2](#82-forward-evaluation-and-witnesses)). C1 alone would accept any value for such a variable, since any
1385
1472
  value gives an instance of the rule, so for a `clause(N)` step citing a
1386
1473
  forward rule, under the substitution of C1, each such variable `V` MUST be
1387
1474
  bound to `skolem(N, Name, Args)`, where:
1388
1475
 
1389
- - `Name` is the name of `V` as the program writes it (Section 8.2);
1476
+ - `Name` is the name of `V` as the program writes it ([Section 8.2](#82-forward-evaluation-and-witnesses));
1390
1477
  - `Args` is the same for every such variable of the step, and is the list of
1391
1478
  the values of the heads' variables, in order of their first occurrence in
1392
1479
  the heads, omitting a value only when it holds a fresh parameter of this
@@ -1421,7 +1508,7 @@ establish its **parametric provenance**:
1421
1508
  change. A backward caller cannot make an earlier firing's data fresh.
1422
1509
  4. An unchanged boundary may use its original evidence or obligation. A
1423
1510
  changed boundary MUST already be settled in its original form, and its
1424
- abstracted form MUST also be settled by Section 11.10, consulting only
1511
+ abstracted form MUST also be settled by [Section 11.10](#1110-c9-search-closure), consulting only
1425
1512
  tables and listings the original boundary rests on. A missing or
1426
1513
  incomplete certificate fails provenance; an obligation for a specific
1427
1514
  boundary MUST NOT silently become an obligation for a stronger one.
@@ -1430,23 +1517,23 @@ Failure of this provenance check is C8, not C1: the original step may be a
1430
1517
  valid clause instance while proposing the wrong witness context. Provenance
1431
1518
  rechecks do not add steps or change the C1, C5 or C9 counts. They establish
1432
1519
  that the displayed firing's evidence permits fresh parameters, not that the
1433
- firing is the one an original open call would select (Section 11.13).
1520
+ firing is the one an original open call would select ([Section 11.13](#1113-operational-query-fidelity)).
1434
1521
 
1435
1522
  When a forward clause has any such variables, its full head under the step's
1436
1523
  substitution MUST be ground; a step that leaves such a variable unbound, or
1437
1524
  bound to anything but its Skolem term, fails C8 rather than C1. A generic inspection pattern cannot share one
1438
- existential witness across all its instances (Section 6.3).
1525
+ existential witness across all its instances ([Section 6.3](#63-source-rule-inspection)).
1439
1526
 
1440
- For a generator, use its scope projection (Section 6.2) as the head for this
1527
+ For a generator, use its scope projection ([Section 6.2](#62-inline-rule-templates)) as the head for this
1441
1528
  check. For every derived clause step, including a backward clause step, the
1442
1529
  checker MUST also perform C8 for each enclosing generator under the same
1443
1530
  substitution. A forged outer witness cannot be authorized by using it in a
1444
1531
  backward conclusion. Variables supplied by the instance's captures are not
1445
1532
  new witnesses of the derived clause.
1446
1533
 
1447
- For an appended forward clause of Section 6.2, prepend the capture list,
1534
+ For an appended forward clause of [Section 6.2](#62-inline-rule-templates), prepend the capture list,
1448
1535
  instantiated under the step's substitution, as one element of `Args`, as
1449
- required by Section 8.2. The checker MUST compute this from the source
1536
+ required by [Section 8.2](#82-forward-evaluation-and-witnesses). The checker MUST compute this from the source
1450
1537
  template's capture list and the substitution, not from the witness term.
1451
1538
 
1452
1539
  A variable of the head that also occurs in the body is not checked by C8,
@@ -1458,9 +1545,9 @@ by C8.
1458
1545
 
1459
1546
  ### 11.10 C9 Search closure
1460
1547
 
1461
- A checker tries to **settle** each well-formed boundary step (Sections 11.4
1462
- and 11.7) with the search certificate, by searching its goal `G` as Section
1463
- 8.1 does, except that:
1548
+ A checker tries to **settle** each well-formed boundary step (Sections [11.4](#114-c3-justification)
1549
+ and [11.7](#117-c6-boundary-consistency)) with the search certificate, by searching its goal `G` as [Section
1550
+ 8.1](#81-goal-search) does, except that:
1464
1551
 
1465
1552
  - a call to a relation that a backward rule defines or forward rules
1466
1553
  conclude is answered by the table whose call is identical to it up to
@@ -1468,7 +1555,7 @@ and 11.7) with the search certificate, by searching its goal `G` as Section
1468
1555
  defined by facts alone by those facts, in clause order;
1469
1556
  - a negation inside the search treats its unbound variables as anonymous.
1470
1557
 
1471
- The **expansion** of a call is the search of Section 8.1 taken one level:
1558
+ The **expansion** of a call is the search of [Section 8.1](#81-goal-search) taken one level:
1472
1559
  the facts in the listing of its relation, in order, then the program's facts
1473
1560
  and backward rules of that name and arity, in clause order, each rule's body
1474
1561
  searched in its place, inner calls answered as above. The boundary's search
@@ -1483,7 +1570,7 @@ settled when:
1483
1570
  listed name and arity and ground, and is **closed**: for each forward
1484
1571
  rule with a head of that relation, each solution of the rule's body under
1485
1572
  the certificate, with the rule's witnesses bound to their Skolem terms
1486
- (Section 8.2), gives head instances of that relation that are listed or
1573
+ ([Section 8.2](#82-forward-evaluation-and-witnesses)), gives head instances of that relation that are listed or
1487
1574
  are ground facts of the program;
1488
1575
  3. no table it rests on depends on itself through the tables its expansion
1489
1576
  consults;
@@ -1495,7 +1582,7 @@ settled when:
1495
1582
  order of derived facts cannot be checked this way; and its search reaches
1496
1583
  no source inspection and no clause appended by a template, and it
1497
1584
  consults no listing whose relation a forward rule with a template head
1498
- or captures concludes (Section 6.2).
1585
+ or captures concludes ([Section 6.2](#62-inline-rule-templates)).
1499
1586
 
1500
1587
  For example, the absence `not(nonpacifist('ada'))` rests on the table
1501
1588
  `searched(nonpacifist('ada'), [])` and the listing `derived(nonpacifist(A),
@@ -1514,7 +1601,7 @@ list does not agree, is not settled. A listing's facts are examined in
1514
1601
  order, and the first that is not ground, such as a pattern a source
1515
1602
  inspection derived, leaves the boundary not settled rather than failing it. A boundary that is not settled is
1516
1603
  trusted, including one that fails C9; C6 confronts each boundary C9 neither
1517
- settled nor refuted with the evidence (Section 11.7).
1604
+ settled nor refuted with the evidence ([Section 11.7](#117-c6-boundary-consistency)).
1518
1605
 
1519
1606
  ### 11.11 Counts and validity
1520
1607
 
@@ -1545,7 +1632,7 @@ A proof is **valid** when no condition failed. A valid proof with obligations is
1545
1632
  A valid proof establishes that each of its claims follows from the program
1546
1633
  by the recorded steps, given its obligations; a settled boundary is
1547
1634
  established by its search certificate, and an unconditional verdict also
1548
- establishes operational query fidelity (Section 11.13). It does not establish
1635
+ establishes operational query fidelity ([Section 11.13](#1113-operational-query-fidelity)). It does not establish
1549
1636
  that the claims are all the conclusions of the program, that the program
1550
1637
  derives no `'false'`, or that the program is the one intended: a proof MAY
1551
1638
  leave conclusions out, and a run's own proof holds exactly its conclusions.
@@ -1553,7 +1640,7 @@ leave conclusions out, and a run's own proof holds exactly its conclusions.
1553
1640
  ### 11.13 Operational query fidelity
1554
1641
 
1555
1642
  **Operational query fidelity** means that a claimed answer can be reported
1556
- for an original question under Section 8, retaining its original call-time
1643
+ for an original question under [Section 8](#8-evaluation-and-conclusions), retaining its original call-time
1557
1644
  bindings, control choices and applicable forward state. Each claimed answer
1558
1645
  must be reachable in that question's ordered search. This is distinct from
1559
1646
  completeness: a proof may omit other reachable answers without falsifying
@@ -1576,7 +1663,7 @@ The question `q(X)` answers only `q('a')`. Nevertheless, a C1–C9 proof may
1576
1663
  justify `q('b')` with `once(p('b'))` and `p('b')`, since the specialized
1577
1664
  call `q('b')` succeeds. A final substitution does not show that the original
1578
1665
  call was `once(p(X))` with `X` unbound, or that its first answer was `'a'`.
1579
- Tests of current variable state have the same distinction (Section 7.5).
1666
+ Tests of current variable state have the same distinction ([Section 7.5](#75-sets-and-operational-behavior)).
1580
1667
 
1581
1668
  A checker claiming the additional property MUST validate evidence of the
1582
1669
  original call state, propagation of bindings between ordered premises,
@@ -1585,7 +1672,7 @@ closure. A claimed call state or substitution is not authority: it must
1585
1672
  follow from the original question, source clauses and checked evidence.
1586
1673
  It MUST preserve generator captures independently of later caller bindings
1587
1674
  and MUST NOT invoke the reasoner to fill gaps. C10 provides the certificate
1588
- check of Section 11.14. A C1–C9 verdict alone MUST NOT be presented as
1675
+ check of [Section 11.14](#1114-c10-call-fidelity). A C1–C9 verdict alone MUST NOT be presented as
1589
1676
  establishing it.
1590
1677
 
1591
1678
  ### 11.14 C10 Call fidelity
@@ -1606,19 +1693,19 @@ proofs certify no answers and do not establish that a question has none.
1606
1693
  When the claims contain `'false'`, C10 is inapplicable: it covers no answers
1607
1694
  and adds no call-fidelity obligations for that halted proof.
1608
1695
 
1609
- For each such question a checker searches its answers by Section 11.10's
1696
+ For each such question a checker searches its answers by [Section 11.10](#1110-c9-search-closure)'s
1610
1697
  one-level expansion and closure checks, with the following differences:
1611
1698
 
1612
1699
  1. Inner relation calls use `called/2` rather than `searched/2`. Call and
1613
- answer comparison preserves anonymous-variable status (Section 10.5).
1700
+ answer comparison preserves anonymous-variable status ([Section 10.5](#105-call-fidelity-certificates)).
1614
1701
  Facts alone and primitives need no table, as in C9. Source clauses,
1615
1702
  freshened apart, determine the bindings passed between ordered premises;
1616
1703
  the final values displayed by a logical step are not inputs to that search.
1617
- 2. Negation MUST enforce Section 4.2's binding restriction at the actual
1704
+ 2. Negation MUST enforce [Section 4.2](#42-controls)'s binding restriction at the actual
1618
1705
  call. C9's treatment of an unbound named variable as anonymous MUST NOT
1619
1706
  be used. A source search that raises an error fails its certificate.
1620
- 3. `once` and `findall` keep their Section 4.2 meanings, so the first answer
1621
- or collected answers come from the actual inner call. Section 11.10's
1707
+ 3. `once` and `findall` keep their [Section 4.2](#42-controls) meanings, so the first answer
1708
+ or collected answers come from the actual inner call. [Section 11.10](#1110-c9-search-closure)'s
1622
1709
  restriction on order-sensitive uses of derived listings still applies.
1623
1710
  The order of unrelated answers of an ordinary question need not be
1624
1711
  established to check membership of a claim.
@@ -1647,7 +1734,7 @@ unproved.
1647
1734
  Every relevant call certificate MUST be valid. Each claim MUST be identical,
1648
1735
  up to renaming, to an answer of at least one corresponding original question;
1649
1736
  merely being an instance of a more general answer does not suffice. For
1650
- example, `q('b')` fails C10 for the question in Section 11.13 even though
1737
+ example, `q('b')` fails C10 for the question in [Section 11.13](#1113-operational-query-fidelity) even though
1651
1738
  its ground logical derivation passes C1–C9. A proof of `p('a')` likewise
1652
1739
  cannot replace an original call's actual universal answer `p(A)`.
1653
1740
 
@@ -1661,9 +1748,8 @@ The current format requires complete tables, including for a relation
1661
1748
  called under `once`. A later error or recursion may prevent that table
1662
1749
  from closing even when `once` itself terminates. C10 then cannot be
1663
1750
  established; a search-prefix certificate is not defined here. A reasoner
1664
- MUST attempt call-fidelity certification for every generated proof and check
1665
- the resulting proof before returning it. Unresolved evidence remains an
1666
- obligation. A reasoner MAY bound this auxiliary production; exceeding its
1751
+ MUST attempt call-fidelity certification for every proof it generates
1752
+ ([Section 8.7](#87-proof-generation)); unresolved evidence remains an obligation. A reasoner MAY bound this auxiliary production; exceeding its
1667
1753
  bound leaves call fidelity unproved, and it MUST NOT change the run's
1668
1754
  answers. The bounds are not part of conformance, so two conforming reasoners
1669
1755
  may differ in which claims of a generated proof carry call-fidelity
@@ -1676,13 +1762,13 @@ for C7, and their listed facts are reachable through that evidence. C10's
1676
1762
  auxiliary search does not change C1–C9 covered counts. Its own covered count
1677
1763
  counts claims whose call fidelity is established or refuted, excluding
1678
1764
  unresolved claims. Failures are reported in
1679
- claim order after checking boundaries and before C7 and C2 (Section 12).
1765
+ claim order after checking boundaries and before C7 and C2 ([Section 12](#12-check-reports)).
1680
1766
  The answer checks are per original question; they do not establish that all
1681
1767
  answers were claimed or that preceding distinct questions terminated.
1682
1768
 
1683
1769
  ## 12. Check Reports
1684
1770
 
1685
- A check report is a document (Section 9.1) beginning with the proof's claims,
1771
+ A check report is a document ([Section 9.1](#91-accepted-document-syntax)) beginning with the proof's claims,
1686
1772
  in proof order, in canonical text, one per line, followed by a blank line and
1687
1773
  the following report facts, one per line:
1688
1774
 
@@ -1695,7 +1781,7 @@ the following report facts, one per line:
1695
1781
  `obligation('call_fidelity', 'original_call', Claim)` per unresolved claim,
1696
1782
  in claim order;
1697
1783
  4. `steps(N)`, `verified(N)`, `recomputed(N)`, `composed(N)`, `trusted(N)`,
1698
- `claims(N)`, the counts of Section 11.11;
1784
+ `claims(N)`, the counts of [Section 11.11](#1111-counts-and-validity);
1699
1785
  5. `verdict(V)`, where `V` is `failed(N)` when `N` failures were recorded,
1700
1786
  otherwise `'checked_with_obligations'` when there are obligations,
1701
1787
  otherwise `'checked'`.
@@ -1710,7 +1796,7 @@ and that the verdict does not establish completeness. Comments are informative
1710
1796
  and MAY be worded differently. They are ignored when the document is read.
1711
1797
 
1712
1798
  Failures are listed in the order they are found: those of reading the
1713
- document (Section 11.1), in document order; C4 for each claim, in claim
1799
+ document ([Section 11.1](#111-reading-the-document)), in document order; C4 for each claim, in claim
1714
1800
  order; then for each step, in document order, C4 for its uses and the C1, C3,
1715
1801
  C5 or C8 failure of its justification; for each boundary, in step order, the
1716
1802
  C9 failures of its search certificate in the order found, or else its C6
@@ -1722,7 +1808,7 @@ specified. It MUST NOT affect validity, counts or the condition reported.
1722
1808
 
1723
1809
  The initial answers keep the variable names of the proof. The variables of
1724
1810
  each subsequent report fact are renamed `A`, `B`, ..., `Z`, `A1`, ... in order
1725
- of first occurrence. A report is ordinary data: `facts_from` (Section 3.4)
1811
+ of first occurrence. A report is ordinary data: `facts_from` ([Section 3.4](#34-statements))
1726
1812
  states it as facts.
1727
1813
 
1728
1814
  ### 12.1 JSON form
@@ -1753,11 +1839,11 @@ eyemind [OPTION ...] [FILE ...]
1753
1839
  | `-c`, `--prove-and-check` | Generate a proof, check the rendered proof against the input program, and print its answers and check report. |
1754
1840
  | `--check-proof FILE` | Check the proof in `FILE` (`-` for standard input) against the program and print its answers and report. |
1755
1841
  | `--json` | With either checking mode, print the report, including `answers`, as JSON. |
1756
- | `--goal GOAL` | Ask `GOAL`, read as in Section 9.1, where an array is a conjunction; MAY be repeated. With `--check-proof`, the goals the proof answers. |
1842
+ | `--goal GOAL` | Ask `GOAL`, read as in [Section 9.1](#91-accepted-document-syntax), where an array is a conjunction; MAY be repeated. With `--check-proof`, the goals the proof answers. |
1757
1843
  | `--strict-proof` | With either checking mode, forbid trusted obligations. |
1758
- | `--unused` | Print the unused clauses (Section 13.2). |
1844
+ | `--unused` | Print the unused clauses ([Section 13.2](#132-unused-clauses)). |
1759
1845
  | `--stats` | Print reasoning statistics as JSON to standard error: `inferences`, the goals started, which `--max-inferences` bounds; `rounds`, the forward rounds run over all strata; and `derived`, the facts forward rules added, not counting a conclusion the program states as a fact, a query's answers or `'false'`. |
1760
- | `--max-depth N`, `--max-iterations N`, `--max-inferences N` | The bounds of Section 8.3; `N` MUST be a positive safe integer, at most 9007199254740991. |
1846
+ | `--max-depth N`, `--max-iterations N`, `--max-inferences N` | The bounds of [Section 8.3](#83-resource-bounds), with the values it allows. |
1761
1847
  | `-v`, `--version` | Print the version. |
1762
1848
  | `-h`, `--help` | Print the usage, including every option and its short alias where one exists. |
1763
1849
 
@@ -1774,7 +1860,7 @@ a program, the command line MUST say how to check it instead.
1774
1860
  | 0 | Success, including a check that found the proof valid. |
1775
1861
  | 1 | An error, printed to standard error as `eyemind: message`. |
1776
1862
  | 2 | A check that found the proof not valid; the report is printed as usual. |
1777
- | 65 | The run halted (Section 8.5). |
1863
+ | 65 | The run halted ([Section 8.5](#85-contradictions)). |
1778
1864
 
1779
1865
  ### 13.2 Unused clauses
1780
1866
 
@@ -1783,18 +1869,18 @@ unless a negation or collection in the proof could consult it and its
1783
1869
  omission changes the conclusions or halt code, or causes an error. The clauses a
1784
1870
  negation or collection could consult are those whose heads have the name and
1785
1871
  arity of a goal it reaches through the program's bodies. Running the program
1786
- without a clause leaves every other clause its number (Section 3.4), so the
1787
- Skolem terms of the other rules (Section 8.2) do not change.
1872
+ without a clause leaves every other clause its number ([Section 3.5](#35-clause-constraints-and-numbering)), so the
1873
+ Skolem terms of the other rules ([Section 8.2](#82-forward-evaluation-and-witnesses)) do not change.
1788
1874
 
1789
1875
  Unused clauses are reported one per line, in clause order, as
1790
- `unused(line(L), Display)`, where `L` is the clause's line (Section 3.4) in
1791
- the script that states it, and `Display` as in Section 10.2; with several
1876
+ `unused(line(L), Display)`, where `L` is the clause's line ([Section 3.5](#35-clause-constraints-and-numbering)) in
1877
+ the script that states it, and `Display` as in [Section 10.2](#102-clause-displays); with several
1792
1878
  scripts, clause order tells which script a line belongs to. The listing is
1793
1879
  the result whether or not the program halts with `'false'`, and the command
1794
1880
  exits with code 0 after it.
1795
1881
 
1796
1882
  "Unused" is relative to the recorded derivations, which are the first ones
1797
- found (Section 8.7). A clause that only offers a second derivation of a
1883
+ found ([Section 8.7](#87-proof-generation)). A clause that only offers a second derivation of a
1798
1884
  conclusion, such as a duplicate rule, is unused, though leaving out the
1799
1885
  clause that offers the first one would make it used; leaving out several
1800
1886
  unused clauses together can therefore change the conclusions. A
@@ -1806,19 +1892,18 @@ not in the proof.
1806
1892
  ## 14. Conformance
1807
1893
 
1808
1894
  A conforming reasoner MUST implement the program syntax, semantics and
1809
- evaluation of Sections 2-8 and the document and proof formats of Sections
1810
- 9-12. It MUST check every proof it generates before returning it. A
1811
- conforming checker MUST implement Sections 9-12 against the supplied
1812
- program, including the clause and template rules of Sections 3 and 6,
1895
+ evaluation of Sections [2](#2-terms)–[8](#8-evaluation-and-conclusions) and the document and proof formats of Sections
1896
+ [9](#9-document-syntax-and-canonical-text)–[12](#12-check-reports). A conforming checker MUST implement Sections [9](#9-document-syntax-and-canonical-text)–[12](#12-check-reports) against the supplied
1897
+ program, including the clause and template rules of Sections [3](#3-program-syntax) and [6](#6-rule-structure),
1813
1898
  without invoking a reasoner to complete the certificate. The command-line
1814
- interface of Section 13 is a separate conformance requirement.
1899
+ interface of [Section 13](#13-command-line-interface) is a separate conformance requirement.
1815
1900
 
1816
1901
  Canonical term spelling, conclusion order, proof contents and report counts
1817
1902
  are required as specified. Comment wording and failure `Detail` text are
1818
- informative. Fresh variable names are unspecified where Section 2.4 says
1903
+ informative. Fresh variable names are unspecified where [Section 2.4](#24-standard-order) says
1819
1904
  so. Float results of `exp`, logarithms, trigonometric and hyperbolic
1820
1905
  functions, and `pow` with floats MAY differ by one unit in the last place,
1821
- and C5 accepts a result of such a function within 4 units (Section 11.6).
1906
+ and C5 accepts a result of such a function within 4 units ([Section 11.6](#116-c5-re-decision)).
1822
1907
 
1823
1908
  The conformance cases and saved example documents exercise these
1824
1909
  requirements. They do not replace the definitions in this specification.
@@ -1826,7 +1911,7 @@ requirements. They do not replace the definitions in this specification.
1826
1911
  ### 14.1 Conformance test suite
1827
1912
 
1828
1913
  The conformance test suite tests an implementation of the command line of
1829
- Section 13.1 as a black box: each case creates files, runs the command and
1914
+ [Section 13.1](#131-invocation-and-options) as a black box: each case creates files, runs the command and
1830
1915
  compares its exit code and output with what this specification requires.
1831
1916
  The suite is the `conformance` directory of the eyemind repository. Its
1832
1917
  expected outputs are derived from this specification; where a case and this
@@ -1838,7 +1923,7 @@ the order they run. Each element is an object with three string members:
1838
1923
  of this specification it tests, separated by commas; and `topic`, a
1839
1924
  description. The cases of a file run in the order they appear in it.
1840
1925
 
1841
- **Case files.** A case file is a document (Section 9.1), read as data and
1926
+ **Case files.** A case file is a document ([Section 9.1](#91-accepted-document-syntax)), read as data and
1842
1927
  never executed, whatever its file name extension. Each of its terms is one
1843
1928
  case, `conformance(Name, Settings)`, where `Name` is an atom unique in the
1844
1929
  suite and `Settings` is a proper list of the settings below. A **block** is a
@@ -1877,7 +1962,7 @@ the expected and actual standard output MUST have the same number of lines,
1877
1962
  and each expected line MUST equal the actual one, except that each `…`
1878
1963
  (U+2026) in an expected line matches any sequence of characters within that
1879
1964
  line; this specification leaves such text, for example a failure detail, to
1880
- the implementation (Section 14). As JSON, both outputs MUST parse, and they
1965
+ the implementation ([Section 14](#14-conformance)). As JSON, both outputs MUST parse, and they
1881
1966
  MUST be equal as JSON values: arrays element by element, objects with the
1882
1967
  same member names whatever their order, numbers by their values, and
1883
1968
  strings as lines are, so that an expected string containing `…` matches any
@@ -1889,8 +1974,8 @@ Programs execute JavaScript and require the caller's trust. Documents,
1889
1974
  including proofs, reports, goals and `facts_from` input, MUST be read as data
1890
1975
  without executing code. A deployment accepting untrusted documents SHOULD
1891
1976
  bound their size, nesting depth, processing time and memory, in addition to
1892
- the reasoning bounds of Section 8.3. A valid proof establishes only the
1893
- claims and assumptions described in Section 11.12.
1977
+ the reasoning bounds of [Section 8.3](#83-resource-bounds). A valid proof establishes only the
1978
+ claims and assumptions described in [Section 11.12](#1112-scope-of-a-valid-proof).
1894
1979
 
1895
1980
  ## Appendix A. Document Grammar
1896
1981
 
@@ -1898,7 +1983,7 @@ This grammar defines document expressions. Quoted strings are literal
1898
1983
  tokens; `|` gives alternatives, `[ ... ]` an optional part, `{ ... }`
1899
1984
  repetition, parentheses grouping, and `? ... ?` a lexical class defined in
1900
1985
  prose. String literals, reserved names and
1901
- layout follow Section 9.1. Line feeds inside brackets are layout; outside
1986
+ layout follow [Section 9.1](#91-accepted-document-syntax). Line feeds inside brackets are layout; outside
1902
1987
  brackets they separate statements.
1903
1988
 
1904
1989
  ```ebnf
@@ -1947,7 +2032,7 @@ type('socrates', 'mortal')
1947
2032
  type('socrates', 'human')
1948
2033
  ```
1949
2034
 
1950
- Its proof document (Section 10):
2035
+ Its proof document ([Section 10](#10-proof-documents)):
1951
2036
 
1952
2037
  ```js
1953
2038
  // Answers: each instance of a query() that holds.
@@ -1971,7 +2056,7 @@ derived(type(A, B), [type('socrates', 'mortal')])
1971
2056
  called(type(A, B), [type('socrates', 'mortal'), type('socrates', 'human')])
1972
2057
  ```
1973
2058
 
1974
- Its check report (Section 12):
2059
+ Its check report ([Section 12](#12-check-reports)):
1975
2060
 
1976
2061
  ```js
1977
2062
  // Checked answers: these follow from the input program.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyemind",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "A dependency-free JavaScript rule language with forward and backward reasoning and checkable proofs.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // The release this checkout is; ./release keeps it in step with package.json.
2
- export const VERSION = '0.3.5';
2
+ export const VERSION = '0.3.7';