Entails
Browse documentation

Language specification

The parser constructs a source-located syntax tree. The machine and certificate declarations have a separate semantic checker and Lean backend. The stage-zero bootstrap type-checks and evaluates a subset of inductive types and functions. The parse command checks syntax for the full grammar.

1. Source text

2. Grammar

The executable grammar is grammar.lark. Lark compiles it as strict LALR(1), with a basic lexer and indentation tokens inserted after lexing. Conflicts fail during parser construction.

The following EBNF expresses the declaration and expression rules. Newline, indent, and dedent are tokens after indentation processing.

module       = [ newline ], declaration, { declaration } ;
declaration  = inductive | function | parallel-function | machine | certificate
             | paper-title | paper-abstract | paper-section | paper-paragraph ;
paper-title  = "paper", text-literal, newline ;
paper-abstract = "abstract", text-literal, newline ;
paper-section = "section", text-literal, newline ;
paper-paragraph = "paragraph", text-literal, newline ;
machine      = "machine", value-name, ":", newline, indent,
               "initial", value-name, newline, { transition }, dedent ;
transition   = "transition", value-name, "(", value-name, ")", "->",
               value-name, "(", write-symbol, ",", value-name, ")", newline ;
write-symbol = value-name | "keep" ;
certificate  = "certificate", value-name, "(", value-name, ")", ":",
               newline, indent, "invariant", value-name, newline,
               { region }, "return", expression, newline, dedent ;
region       = "region", value-name, [ "(", value-name, ")" ], newline ;

inductive    = "inductive", type-name, ":", newline, indent,
               constructor, { constructor }, dedent ;
constructor  = value-name, [ "(", [ parameters ], ")" ], newline ;

function     = "function", value-name, "(", [ function-parameters ], ")",
               "->", type-name, ":", block ;
parallel-function = "@", "runtime", "(", ("asynchronous" | "threaded"), ")", newline,
                    "parallel", function ;
parameters   = parameter, { ",", parameter } ;
parameter    = value-name, ":", type-name ;
function-parameters = function-parameter, { ",", function-parameter } ;
function-parameter = [ "borrow", [ "mutable" ] ], parameter ;

block        = newline, indent, statement, dedent ;
statement    = "return", expression, newline
             | "match", expression, ":", newline, indent,
               branch, { branch }, dedent ;
branch       = "case", pattern, ":", block ;
pattern      = value-name, [ "(", [ value-name, { ",", value-name } ], ")" ] ;

expression   = natural-literal | text-literal
             | value-name, [ "(", [ expression, { ",", expression } ], ")" ]
             | "wait", expression
             | "borrow", [ "mutable" ], value-name
             | "(", expression, ")" ;

Each function block and case body is one expression-producing statement. Function calls are positional. Patterns name a constructor and bind its arguments. The language currently has no infix expressions.

A file can declare one paper title and abstract and interleave section headings and paragraphs with code. These declarations carry prose and leave machine execution unchanged. The paper compiler describes each code declaration and includes mathematical forms where applicable. For a certificate, paper --check asks Lean to verify the generated obligations. Without --check the paper reports the claim as unchecked.

Parallel declarations, waits, and borrows parse. The runtime design specifies execution and static ownership rules. Stage zero evaluates the synchronous subset.

3. Natural numbers

NaturalNumbers is the inductive type generated by zero and successor(previous: NaturalNumbers). The constructors are disjoint and successor is injective. A literal with mathematical value n denotes n applications of successor to zero. This denotes the value independently of its storage representation.

The first semantic rules to implement are introduction by constructors, elimination by exhaustive constructor matching, and recursion on a structurally smaller constructor field. Induction on NaturalNumbers uses a proof at zero and a proof that the predicate at previous implies the predicate at successor(previous). The runtime may use a binary representation. Fixed-width lowering needs a range check or an established bound.

4. Deterministic machines

A machine module declares finite nullary inductive types MachineState and TapeSymbol. The former contains running states; the latter includes blank. A transition is keyed by a running state and a read symbol and specifies a destination, a written symbol, and one move (left, stay, right). Destinations can be running states or the reserved halt outcomes accept and reject. The initial state must be a running state. Duplicate keys are invalid. Names in rows are resolved against their respective types. keep in the write position expands to the read symbol of that row.

A tape maps natural cell indices to symbols. A finite input is placed from cell zero onward, with all other cells blank. A MachineConfiguration contains a control state (running, accepted, or rejected), a natural head index, and the tape. The input configuration has its head at zero. The runtime stores only nonblank cells, with binary natural indices. The Lean model uses total tape functions, so its proofs also apply to arbitrary tails satisfying the initial guard premise.

entails run --stdin reads one line of text as whitespace-separated tape symbols. A blank input line creates a blank tape. End of stream before any line is an input error. The host input operation occurs before the clock starts.

One native step reads the current cell and dispatches through the table. A present row writes the symbol, moves the head, and enters its destination; left moves at zero clamp to zero. A missing row takes one native step to reject while leaving the head and tape intact. Halted configurations are absorbing. With the constructors of NaturalNumbers:

run(machine, initial, zero) = initial
run(machine, initial, successor(steps)) = step(machine, run(machine, initial, steps))

A run accepts by deadline d exactly when its configuration at d is accepted, including a halt on the last allowed step. A running state at the deadline counts as clocked nonacceptance. Replay checks the observed halt first, then the deadline, then the local replay budget. A shorter local budget that reaches neither a halt nor the deadline yields an inconclusive result, with no clocked acceptance bit. The replay limit is independent of the machine deadline and the resources Lean uses to check a proof.

5. Guard invariants

A certificate names a machine, a guard symbol, and allowed pairs of running state and head region (at_guard for index zero, positive otherwise). A bare region state expands to both regions for that state. It represents configurations whose cell zero equals the guard symbol and whose control is rejected or at a listed running pair. The proof term induction(initialization, preservation, acceptance_exclusion) invokes the clock induction rule with these three obligations:

  1. The input configuration satisfies the invariant whenever its cell zero equals the guard.
  2. Every concrete native step from the invariant preserves it. At cell zero, the only compatible read is the guard symbol, and a row must preserve it. At a positive cell, every symbol must be considered. A positive left move can produce either head region.
  3. Every configuration satisfying the invariant excludes acceptance.

The backend emits the actual table and a Lean proof for each obligation. Initialization and finite transition cases are discharged by kernel-checked decision proofs. The generic Lean induction theorem derives exclusion of acceptance at every natural deadline. A failed closure case is reported at the corresponding row where present. These declarations define a restricted proof language. Parsing a declaration alone does not discharge an obligation.

Entails also has a separate checker for this certificate form. It evaluates one native step on representatives for head zero, head one, and heads at least two. All heads in the last class remain positive after any native move. Only the guard can be read at zero. At a positive head every tape symbol is possible. The guard can change only on a write at zero. These facts make the representatives exhaustive for the invariant, independent of initial tape length or deadline. The checker also verifies the initial state and excludes the accept outcome. The Lean backend and this checker share the parsed machine and certificate, and use separate checks of the obligations.

Discovery enumerates all binary payloads through a finite training width with the declared guard prefixed. It collects running state and head-region pairs observed in the native traces. It then widens the head regions by following compatible rows among the observed states until no pairs are added. The proposed invariant is independently checked against every symbol and the full transition table, including rows absent during training.

entails check discharges the named certificate against its declared machine by default. The --machine option submits the same guard, regions, and proof term against another table in the module. For a fixed stated machine and certificate, these obligations are independent of the input width and deadline. The checker enumerates three head classes per state and read symbol. With the original machine fixed, the proof data have constant size and the guard premise is checked directly on the initial tape. In the general machine slice, the finite obligations admit polynomial-time checking in the explicit machine and certificate lengths by table and region lookup. This count describes the finite obligations. Entails currently has no general proof language or complexity bound for Lean proof checking.

entails check --paranoid requires the Lean proof export and the Entails guard check to pass. Independent replay and an axiom audit apply to the exported theorem. See proof checking for the axiom policy, the replay interface, and Lean project imports.

The experiment uses a shared finite alphabet and an explicit blank default. Acceptance is a halt outcome. The machine slice has no separate emitted output stream.

6. Bootstrap and the Proof Forest

entails build FILE -o PROGRAM compiles the checked first-order bootstrap subset through MLIR and LLVM. An executable provides main() -> Text or main(input: Text) -> Text. The one-argument form reads UTF-8 standard input through EOF and reports invalid UTF-8 as a runtime error. Both forms write the returned UTF-8 bytes to standard output. --emit mlir emits the module before LLVM conversion and permits a module without main. The native subset supports pure first-order calls, inductive constructors, constructor matches, natural and text literals, and the text primitives below. Constructor matching follows the same exhaustive type check as the stage-zero evaluator. The native path requires Unicode scalar values in text literals. Text and constructor values live for the duration of the executable’s evaluation. Naturals used as terminal widths retain their mathematical value until the text operation, where a width larger than any representable output covers the entire text.

The stage-zero host evaluates the packaged Entails Proof Forest module. Its executable subset consists of named constructor values, positional function calls, constructor matches, natural literals, and text literals. Text and compact NaturalNumbers are built into this subset. Its checker resolves type and value names, checks constructor and function arguments and return types, and requires exactly one branch for each constructor of the matched type. It checks arithmetic literals as natural values. Termination checking is outside this bootstrap subset. text_append(left: Text, right: Text) joins two text values. text_truncation computes a display-width budget for a prefix and suffix. The renderer supplies ... and truncates each overlong line, counting its indentation and outcome label against the terminal width. Terminals narrower than three columns display as much of the suffix as fits.

text_uncons(input: Text) -> TextHead returns empty_text for empty input. Otherwise it returns text_head(first, rest) with the first Unicode scalar as a one-scalar Text and the remaining Text in order. A combining mark or newline is one scalar of its own. The native operation decodes at most four bytes and returns views into the existing immutable input. Callers declare the result type with the following constructors.

inductive TextHead:
    empty_text
    text_head(first: Text, rest: Text)

function main(input: Text) -> Text:
    match text_uncons(input):
        case empty_text:
            return ""
        case text_head(first, rest):
            return rest

A forest is an ordered list of proof trees. Each tree contains a label, a proof outcome, and an ordered forest of children. The Entails module defines the data, assembles the tree from the evidence, and formats it recursively. For a guard certificate, the root is the certificate and the immediate children are initialization, preservation, and acceptance exclusion. A Lean refutation can carry source-located details under the affected obligation. Lean’s successful check marks all obligations proved. An unsuccessful check marks any explicitly refuted obligations failed and leaves the others unverified. An exhausted check has an inconclusive root.

The host supplies the Lean exit outcome and the source-located refutations and writes the rendered text to the output stream. The bootstrap evaluation of this module is separate from Lean’s proof checking.

7. Formalization scope

Entails can describe finite-state deterministic machines with a one-way tape and explicit accept and reject states. The Lean backend defines the configuration, one native step, and clock-indexed execution. Entails can state and check guard invariants for this model. The counter theorem applies at every natural deadline.

The current source language has one machine proof rule. A general theorem layer needs propositions, quantified and parameterized lemmas, reusable induction, and a termination discipline before arbitrary proofs can live in Entails.

Complexity claims also need explicit machine and input encodings, a model for native cost and simulation overhead, and definitions of languages, reductions, and resource-bounded verifiers. The clock-indexed semantics count transitions and provide a starting point for that work. The bootstrap checker currently checks the finite guard-certificate fragment.