# The definition

The Lean 4 definition of what a router answers, the proofs that the answers are unique, and how it keeps the two ports in step.

patrun has two ports, and both must give the same answer to the same query. Tests can show that they agree on the cases someone wrote down. A definition says what the answer is for every case.

## What it defines

The repository's `spec/` directory holds a definition of what a router answers, written in Lean 4, for patterns whose values are exact strings or the star. That is all that Seneca, the main user of patrun, asks of it. Globs and intervals are outside it for now.

It says what each answer is, as relations over the table of patterns that hold data, and not how to compute it: which patterns match a query, the order of [How a match is chosen](https://rjrodger.github.io/patrun/reference/matching.html), and what `find`, `findExact`, `collect`, `collectExact`, `list`, and `get` give.

## What it proves

The definition comes with proofs, checked by Lean:

- the order of the matches is strict and total, so `find` and `findExact` each have one answer;
- the order puts the narrower of two patterns first;
- a model that computes the answers, from a list of patterns, gives the answer the definition gives for every operation.

## How it keeps the ports in step

The model is run as an oracle. It checks the rows of test cases that the JavaScript and Go ports share, and writes more rows for them to run. A port that answers otherwise fails its own tests, so the definition, not either port, decides what is right.

The `spec/README.md` file in the repository describes the definition in full, and lists where the ports still differ from it.
