Markdown for LLMs
Advanced cheat sheet
The source Markdown for this article. Copy it into your assistant or download it as a text file.
# Advanced cheat sheet
The constructs beyond the [cheat sheet](/language/cheat-sheet/): decision
tables, presumptions and legal fictions, constraints, liberties and
immunities, questions only a person can decide, competing readings of a
text, procedures, stages, precedents, templates and units. As on the first
page, every `law` block belongs to one package that compiles, and every
section has a scenario that runs. At the end — an index of every construct
of the language.
<p class="play-open"><a href="/play/?preset=advanced-cheat-sheet">Open this package in the playground →</a> — edit the rules and the scenarios of this page and run them in your browser.</p>
## Package header
```law
language "law.core" version "0.2";
package demo.parking.advanced version "0.1.0";
namespace "urn:law:demo:parking-advanced";
entity Applicant;
entity Office;
```
## Decision tables
```law
decision LongTermDiscount(months: Integer) -> Decimal {
table hit unique {
when months >= 12 => 20 percent;
otherwise => 0 percent;
}
}
```
A `decision` maps inputs to an output by rows. `hit unique` means at most
one row may match; `otherwise` is the row for everything else. The answer
names the row that fired.
## Presumptions and fictions
```law
relation applied_for_permit(a: Applicant) kind empirical;
relation good_standing(a: Applicant) kind institutional;
relation unpaid_fine_recorded(a: Applicant) kind institutional;
presumption GoodStanding(a: Applicant) {
when applied_for_permit(a);
presume good_standing(a);
unless unpaid_fine_recorded(a);
}
relation notice_posted(a: Applicant) kind empirical;
relation notice_received(a: Applicant) kind institutional;
fiction DeemedReceipt strict {
for a: Applicant;
when notice_posted(a);
deem notice_received(a);
}
```
| Form | Use it when the norm says |
|---|---|
| `presumption … { presume …; unless …; }` | "is presumed … until …": holds by default, evidence rebuts it |
| `fiction … { deem …; }` | "is deemed …": treated as true whatever the facts are |
## Constraints
```law
relation permit_issued(a: Applicant) kind empirical;
relation fee_paid(a: Applicant) kind empirical;
constraint IssuedNeedsFee(a: Applicant) {
when permit_issued(a);
require fee_paid(a);
severity error;
message "a permit is issued only after the fee is paid";
}
```
A `constraint` derives nothing. It checks that decided facts fit together
and reports a finding when they do not; a legal consequence of the breach
needs its own rule.
## Liberties and immunities
```law
relation permit_refused(a: Applicant, o: Office) kind empirical;
relation objects(a: Applicant, o: Office) kind empirical;
relation permit_displayed(a: Applicant, o: Office) kind empirical;
relation vehicle_towed(o: Office, a: Applicant) kind institutional;
rule ObjectionRight strict {
for a: Applicant;
for o: Office;
when permit_refused(a, o);
then liberty MayObject {
holder a;
against o;
action objects(a, o);
window [@2026-03-01, @2026-03-31];
};
}
rule NoTowing strict {
for a: Applicant;
for o: Office;
when permit_displayed(a, o);
then immunity NoTowingWithPermit {
holder a;
against o;
protected_effect vehicle_towed(o, a);
window [@2026-01-01, @2026-12-31];
};
}
```
| Position | Says |
|---|---|
| `liberty` | the holder may do something; nobody can demand otherwise |
| `immunity` | the holder is shielded: the other side cannot bring this effect about |
Together with `duty`, `prohibition` and `power` from the first page these
are the five positions a norm can give.
## Questions only a person can decide
```law
external judgment relation hardship(a: Applicant) {
authority HearingOfficer;
}
relation hardship_waiver(a: Applicant) kind institutional;
rule HardshipWaiver strict {
for a: Applicant;
when applied_for_permit(a) and hardship(a);
then hardship_waiver(a);
}
```
Some criteria ("undue hardship", "reasonable", "proportionate") are decided
by a named authority, not computed. Until the decision is supplied the
answer is `REQUIRES_JUDGMENT`; once it is given as a fact with
`origin adjudicated`, the rule fires.
## Competing readings
```law
relation second_vehicle(a: Applicant) kind empirical;
relation second_permit(a: Applicant) kind institutional;
interpretation Narrow {
status reviewed;
rule NarrowReading strict {
for a: Applicant;
when second_vehicle(a);
then not second_permit(a);
}
}
interpretation Broad {
status reviewed;
rule BroadReading strict {
for a: Applicant;
when second_vehicle(a);
then second_permit(a);
}
}
interpretation_group SecondVehicle {
alternatives Narrow, Broad;
selection exactly_one;
}
```
When a text can be read two ways, each reading is an `interpretation`, and
the group says how many may be in force. The case chooses one in its
context (`interpretation Broad;`); the answer records which reading it
rests on. Until a reading is chosen, every answer of the package carries the
issue `INTERPRETATION_REQUIRED` — the open question is never hidden.
## Procedures
```law
event PermitApplied {
applicant: Applicant;
}
relation application_complete(a: Applicant) kind empirical;
procedure PermitProcess(a: Applicant) {
state Draft initial;
state Filed;
state Issued terminal;
transition File {
from Draft;
to Filed;
on PermitApplied;
when application_complete(a);
}
transition Issue {
from Filed;
to Issued;
}
}
```
A `procedure` is a state machine for one case: states, and transitions
triggered by events and guarded by conditions. The question
`current_state(case, State)` says where the case stands now and which
attempts moved it.
## Stages
```text
stage Reminders {
index round: Integer from 1 to 3;
bind reminder index 1;
}
```
```law
relation overdue() kind empirical;
relation reminder(i: Integer) kind institutional;
relation final_notice() kind institutional;
rule FirstReminder strict {
when overdue();
then reminder(1);
}
rule NextReminder(i: Integer) strict {
when supported(reminder(i)) and i < 3;
then reminder(i + 1);
}
rule FinalNotice strict {
when supported(reminder(3));
then final_notice();
}
```
A `stage` evaluates rounds in order: each round is closed before the next
one reads it. Use it for anything that counts steps — reminders, rounds of
a vote, an elimination tournament. A package with a stage cannot also hold
a procedure (`LDC-E4126`), so the `stage` declaration above is shown, not
compiled into this page's package; the rules it orders are.
## Precedents
```law
relation lives_in_city(a: Applicant) kind empirical;
relation second_home(a: Applicant) kind empirical;
relation resident_for_permit(a: Applicant) kind institutional;
factors ResidencyLine {
for a: Applicant;
domain lives_in_city(a);
plaintiff lives_in_city;
defendant second_home;
courts HIGH; LOW;
}
rule SecondHomeNotResident strict {
for a: Applicant;
when second_home(a);
then not resident_for_permit(a);
}
precedent P1 of ResidencyLine {
court HIGH;
decided @2020-06-01;
plaintiff lives_in_city;
outcome resident_for_permit(a);
}
```
`factors` names the considerations a line of cases weighs for each side;
a `precedent` records which factors a court found and what it held. A new
case with the same factors follows the holding; a case with a factor the
precedent did not have is distinguished, and the general rule answers.
## Templates
```law
relation employed_in_city(a: Applicant) kind institutional;
relation worker_permit(a: Applicant) kind institutional;
expansion pair {
params { subject: binder; ground: relation(subject); result: relation(subject); }
exports { ok = self/ok; }
emit rule self/ok strict {
for subject; when ground(subject); then result(subject);
scope from self; effective from self; labels from self; source from self;
}
}
expand pair WorkerPermit {
label en unofficial "Workers in the city get a worker permit";
bind subject = a: Applicant;
ground = employed_in_city;
result = worker_permit;
}
```
An `expansion` is a rule template with parameters; `expand` fills it in.
Use it when an act repeats one pattern for many subjects — the expanded
rule is an ordinary rule with its own name in the answer.
## Units and quantities
```law
relation distance_to_zone(a: Applicant, d: Quantity) kind empirical { key(a); }
relation far_from_zone(a: Applicant) kind institutional;
rule FarFromZone strict {
for a: Applicant;
for d: Quantity;
when distance_to_zone(a, d) and d >= 2 km;
then far_from_zone(a);
}
```
Quantities carry their unit tag (`3 km`). Values in different units are
never mixed silently: comparing `2500 m` with `2 km` reports
`DIMENSION_MISMATCH` and the answer's status is `TYPE_ERROR`; conversion is always explicit — `convert(value, num, den, unit)`
with an exact factor. New units are declared with `unit` and `derived unit`.
## Scenarios
Each section has a scenario; here is the first one. A scenario is written
the same way as on the [first page](/language/cheat-sheet/#scenarios).
```law
test "a decision table" {
given {
context { legal_time @2026-03-01; decision_time @2026-03-01T09:00:00Z; knowledge_time @2026-03-01T09:00:00Z; timezone "UTC"; }
}
evaluate LongTermDiscount(12);
expect value == 0.2;
}
```
## Run it
```bash
law engine check advanced.law
law engine test tests/advanced.lawtest --program advanced.law
```
Expected output:
```text
check OK: advanced.law
```
```text
test PASS: a decision table
test PASS: a presumption holds by default
test PASS: evidence rebuts the presumption
test PASS: a fiction
test PASS: a constraint reports a breach
test PASS: liberty and immunity
test PASS: a judgment not yet given
test PASS: a judgment given
test PASS: the broad reading
test PASS: the narrow reading
test PASS: no reading chosen
test PASS: a procedure step
test PASS: rules that count steps
test PASS: the precedent is followed
test PASS: the precedent is distinguished
test PASS: an expanded template
test PASS: quantities in one unit compare
test PASS: different units are not mixed
```
## All constructs
Every construct of the language with a one-line description, the same text
the editor shows on hover.
<!-- generated: cheat-sheet constructs -->
| Word | Construct | What it does |
|---|---|---|
| `action` | Action with actor | Declares an event with a designated actor: an action someone performs, with typed fields. |
| `align` | Fragment alignment | States that two fragments in different languages correspond, with review status. |
| `and` | Conjunction | Conjoins formulas: every conjunct must hold for the whole to hold. |
| `as` | Premise alias | Names the unwrapped value of an if some premise: the binder the when-line reads. |
| `assert` | Assertion | Asserts one proposition as fact, with id, origin, validity window and evidence links. |
| `calendar` | Calendar dataset | Declares a versioned calendar dataset binding: timezone, period and a content-addressed resource. |
| `case` | Case file | Pins one matter to decide: its evaluation context, named individuals and asserted facts with evidence. |
| `classification` | Classification | Supports a class by rule-like conditions: strict or defeasible strength. |
| `closure` | Closed-world scope | Bounds explicit negation: only inside predicate, domain and snapshot may absence become false. |
| `collect` | Comprehension | Builds a set or list by filtering: collect bindings of a type where a formula holds. |
| `const` | Named constant | Binds an immutable snapshot value to a name: numbers, money, or an individual via entity_ref. |
| `constraint` | Non-derivational check | States a mandatory relation between decided facts: when the antecedent holds, the requirement must hold too. |
| `context` | Named context profile | Pins reusable evaluation axes under one versioned name: jurisdiction, time, resolvers and policies. |
| `counterfactual` | What-if analysis | Asks what minimal case change would flip a target: mutable and immutable inputs plus cost. |
| `deadline` | Deadline policy | Pins how calendar deadlines count: start day, end inclusion, rolling and cutoff. |
| `decision` | Named pure decision | Names a pure query over evaluated legal state: one table or let* plus return, no norms or effects. |
| `defeasible` | Defeasible strength | A candidate consequence that a stronger opposite can defeat. |
| `defeat` | Defeater head | Heads a defeater rule: removes support for the named conclusion without asserting anything. |
| `defeater` | Defeater rule | Blocks a conclusion without supporting its complement. |
| `definition` | Exact definition | Defines a concept by exact condition: the head holds exactly when the body holds. |
| `derived` | Derived unit | Declares a derived unit as a product and quotient of simple ones: it has no scale of its own. |
| `edition` | Source edition | Pins one content-language-revision Expression of a source: language, officiality and lifecycle. |
| `effective` | Effective window | Bounds the rule to a legal-time interval: outside it the rule does not apply. |
| `entity` | Nominal entity type | Declares a nominal type: identity is the pair (type, stable id); equal ids in two types never mix. |
| `entrenchment` | Entrenchment | Shields one source passage over a time window: a locator plus its validity interval. |
| `enum` | Enumeration | Declares a closed set of named members: the total vocabulary of one choice. |
| `event` | Event declaration | Desugars to an immutable nominal entity with id and typed fields; executable use wants one canonical time interval. |
| `Event` | Domain event | Declares an immutable nominal event subtype with typed intrinsic fields; identity is the stable id. |
| `evidence` | Evidence document | Declares a case document: a stable id over a typed schema with provenance fields. |
| `expand` | Expansion instance | Instantiates a named expansion: binds its parameters to local relations and values. |
| `expansion` | Expansion definition | A closed generation profile: params plus emit rules that generate nodes with stable ids, labels and anchors. |
| `exports` | Export map | Names what an expansion publishes: local names for generated nodes. |
| `factors` | Factor dictionary | Declares the closed factor vocabulary of one precedent line: signature, domain, sides and courts. |
| `facts` | Exported fact group | Named unit for exporting facts across the package border; the body holds asserts only. |
| `fiction` | Legal fiction | Deems an institutional fact true when its conditions hold: the law treats it as decided. |
| `fragment` | Source fragment | Pins one addressable passage inside an edition: kind, locator and fixed text. |
| `function` | Pure function | Returns a data value, never a proposition; pure means no assertions, no norms, no ambient reads. |
| `governs` | Temporal scope | Scopes a rule to regulated-fact time on a named axis: support outside the window is not support. |
| `if` | Conditional term | Chooses between two data terms on a boolean: if the condition holds, the first, else the second. |
| `import` | Dependency import | Declares a dependency once per package; only its pub symbols become reachable as pkg::Symbol. |
| `integer` | Integer parameter | An expansion parameter holding a whole number: the threshold of an aggregate premise. |
| `interpretation` | Named reading | Groups rules, priorities and definitions as one reading of a named document, with status and authority. |
| `interpretation_group` | Reading alternatives | Groups rival readings of one document with a selection policy: exactly one, any, or composed. |
| `jurisdiction` | Source jurisdiction | The legal order a source belongs to, written as an institution identifier. |
| `key` | Expansion case key | Names the generated node after the case: `key(c)` is the case name. |
| `key` | Key declaration | Names the arguments that identify a tuple or a generated node. |
| `key` | Relation key | Declares the candidate key: one key projection identifies one tuple. |
| `language` | Language header | Opens every file: the language name and the exact version the file is written against. |
| `list` | List aggregate | Collects the outputs of all matching rows of a decision table into a list. |
| `list` | List parameter | An expansion parameter holding a finite list of relation references. |
| `map` | Total enum map | Declares a closed total mapping from one enum to another: sugar over a pure function. |
| `namespace` | Namespace declaration | URI from which declaration StableIds are built ({namespace}#{Name}); one package forms one tree. |
| `option` | Optional premise parameter | An expansion parameter for a premise that may be absent. |
| `package` | Package declaration | Names the package and pins the language version; every file belongs to exactly one package. |
| `params` | Expansion params | Declares what an expansion instance must bind: binders, relations and value slots. |
| `precedent` | Precedent case | Records one decided case as factor sets and an outcome under a named vocabulary. |
| `presumption` | Presumption | Holds a conclusion defeasibly until an exception fires: a rule, a defeater and a priority in one form. |
| `priority` | Rule priority | Orders conflicting rules: prefer the winning application over the losing one, with an explicit reason. |
| `procedure` | Procedure automaton | Declares a state automaton over one instance: named states plus the transitions between them. |
| `property` | Property check | States what must hold over generated inputs: a forall domain plus a pure expectation. |
| `publication` | Published file | Pins one published file of an edition: media type, retrieval address and content hash. |
| `quantity` | Duration parameter | An expansion parameter holding the duration of a term, used in the date term of a deontic window. |
| `query` | Query declaration | A named computation over legal state that adds no support: local lets, then one return. |
| `record` | Value record | Bundles typed fields under one name: the plain value object of the language. |
| `reference` | Dynamic reference | Declares a reference resolved at evaluation: source, locator, resolution axis and policy. |
| `region` | Parallel region | Declares one token-holding area of a parallel state: its own states and transitions. |
| `relation` | Relation | Declares a named predicate: rules derive which of its tuples hold. |
| `revision` | Revision link | Links editions into an immutable graph: what came before, what comes next, and why. |
| `role` | Legal role | Introduces one LegalRole constant for an actor type, read through the has_role relation. |
| `rule` | Inference rule | Derives a conclusion when its conditions hold. |
| `scope` | Rule scope | Restricts when a rule applies: a formula kept separate for indexing and explanations. |
| `set` | Set literal (reserved) | Reserved word of the set literal; a set is built by a `collect` comprehension. |
| `snapshot` | Snapshot function | Declares an external function deterministic only against an exact snapshot hash, under a named capability. |
| `some` | Present option | Passes a present optional argument at an instance: some names the value the option carries. |
| `source` | Source work | Declares the abstract Work behind an act: its kind, jurisdiction, authority and number. |
| `stage` | Reserved tour boundary | Reserves a named node for round-based stratification: an empty body stays a loud boundary. |
| `state` | Automaton state | Names one state of a procedure automaton: entry states are initial, sinks are terminal. |
| `strict` | Strict strength | An indefeasible consequence inside the chosen theory. |
| `support` | Support edge | Links one document to one proposition with a fixed relation: supports, refutes, authenticates, measures, reports or establishes. |
| `temporal_resolution_policy` | Day-resolution policy | Pins how a Date becomes an Instant interval: one fixed offset and a day boundary. |
| `term` | Legal term with cases | Writes one legal deadline with a general rule and named special cases. |
| `test` | Executable test | Pins one executable check: given holds the case, evaluate asks the question, expect states the verdict. |
| `text` | Amendment text | The new text an amendment operation puts at a locator. |
| `text` | Fragment text | The pinned official text of a fragment, in a named language and status. |
| `then` | Rule head | States what the rule concludes: a literal or a norm template. |
| `timezone` | Calendar time zone | The time zone of a calendar snapshot. |
| `transition` | Automaton transition | Moves one procedure automaton from one state to another on an event, under a guard. |
| `type` | Type alias | Names an existing type without nominal separation; transparency holds on both compiler stages. |
| `unit` | Unit declaration | Declares a measurement unit: a simple atom carries exact scale and dimension, a derived unit multiplies simple ones. |
| `Unit` | Unit tag surface | The declared name for measurement-unit tags: tags resolve in the unit registry, conversions stay explicit. |
| `unless` | Rule exception | Adds a defeasible exception to a rule: when it fires, the rule does not. |
| `uri` | Publication address | The canonical address of a publication of an edition. |
| `use` | Explicit selection | Selects records explicitly: in a case, use names a snapshot alias and the records taken from it. |
| `verification` | Verification record | Pins one external authenticity check of a case document: evidence, hash, verifier and outcome. |
| `when` | Body clause | Conjoins the conditions a rule needs: literals, comparisons, calls. |
| `where` | Filter clause | Filters a comprehension or aggregate: only bindings satisfying the formula are collected. |
| `within` | Aggregate window | Bounds an event day to the instance window inside a count premise: day within window. |
<!-- /generated -->