docs← Back to article

Markdown for LLMs

Calculations and external inputs

The source Markdown for this article. Copy it into your assistant or download it as a text file.

Download this articlePlain text ↗
# Calculations and external inputs

## Task and place

Acts speak in amounts: premiums, penalties, tariffs, thresholds. This stage turns each figure into typed arithmetic with an explicit rounding policy, proves each table complete row by row, and draws the line where the package stops computing and starts trusting outside figures. It sits inside rule drafting, right after vocabulary declares the kinds: vocabulary names the money and rate relations, this stage fills their values, and scenarios trip every figure.

## Inputs

- The act's figures with their units: rates, day counts, percentage bounds, currency.
- The tariff tables exactly as printed, including any non-monotonic row the author is tempted to smooth.
- The input conventions of the forum: which currency, which precision, who supplies payroll and delay figures.
- The [EAI tariff decision](/handbook/files/filled/eai-decision-tariff.md) and the [EAI threshold decision](/handbook/files/filled/eai-decision-threshold.md), which settle this stage's close calls for the running example.

## Actions

- Declare one kind per figure: counters are integers, rates are decimals, amounts are money with an explicit currency suffix.
- Multiply freely but divide strictly: money divides only by a decimal divisor, written with a point (3.0, never 3); an inexact quotient is refused unless the rule names an explicit rounding policy.
- Round only by written policy: every rounding step names precision and mode; the machine never rounds on its own.
- Model each tariff row as its own rule carrying its own source label, so a wrong row fails and reads alone.
- Sum over collections with the enumerated entity inside the collection form, and pair every total with a positive-count condition plus a separate zero rule fed by an explicit completeness confirmation — a missing statement is a gap in evidence, not a zero bill.
- Put a key on every computed head, so a fed value that disagrees with the derived one surfaces as a conflict instead of a second silent answer.

## Decisions

- Table shape (EAI-D1): twenty-two strict rules, one per risk class, rather than a single routing table — each pair keeps its own label and its own failure.
- Boundary reading (EAI-D2): the thirty-to-one-hundred range is inclusive at both ends, so thirty qualifies and twenty-nine stays undecided.
- Rounding policy (EAI-D3): the penalty rule computes the exact product with no rounding step, because the act states a plain product and any rounding would be authorial invention. The downstream consequence — unrounded amounts in answers — is documented in the record, not hidden.

## Artifact

The artifact has three parts: input conventions (currency, kinds, who supplies each figure), the calculation policy (the exact expression per amount plus its rounding rule or its explicit absence), and the automation limits (what the machine refuses and what must arrive precomputed from outside). For the running example the policy reads: premium base equals insured sum times rate, and the due premium is the base at or above the case-supplied minimum wage, else the wage; penalty equals unpaid times 0.015 times days; all exact, with no rounding step anywhere.

## EAI example

All amounts are tenge. A class twenty-two employer with an insured sum of one million owes a premium of exactly twenty-nine thousand six hundred: one million times 0.0296. The same employer with a doubled insured sum owes fifty-nine thousand two hundred — the base reads the sum, not payroll; payroll still travels with the case but no premium rule touches it. A base below the case-supplied minimum wage answers the wage instead. Two days of delay on one hundred thousand unpaid yield a penalty of exactly three thousand: one hundred thousand times 0.015 times two. One hundred unpaid over one day yields a penalty of exactly 1.5 KZT — the fractional figure that tells the exact product apart from a smuggled rounding step. The tariff table is complete by enumeration: classes one through twenty-two each map to exactly one strict rule, a class outside that range derives no tariff so the premium stays silent, and the printed rates are copied per row without smoothing — the table is not monotonic (class nine sits below class eight), which is why a formula would be wrong and twenty-two rows are right. No rule sums over a collection; the only collection form in the package quantifies a goal property, not a money total.

Observed on the accepted candidate with the pinned tool (`law` 0.1.0, semantics law.core/0.2, published build):

```text
$ law test docs/handbook/files/fixtures/eai-candidate
  ok   [kz.corpus.employee_accident_insurance#authored] tests/tariff.lawtest / EAI-TARIFF-CLASS-07-PREMIUM
  ok   [kz.corpus.employee_accident_insurance#authored] tests/bounds.lawtest / EAI-LOSS-100-QUALIFIES
  ok   [kz.corpus.employee_accident_insurance#authored] tests/bounds.lawtest / EAI-LOSS-101-SILENT
  ok   [kz.corpus.employee_accident_insurance#authored] tests/penalty-fractional.lawtest / EAI-PENALTY-FRACTIONAL-EXACT
total: 37 checked, 37 passed, 0 failed, 0 not run; code 0
```

Each tariff row is pinned by its own check: the class-22 check proves class 22 only, and removing the class-7 rule on a scratch copy fails exactly the class-7 check while the other thirty-six pass. The base itself is pinned the same way: removing the floor rule fails exactly the floor probe. The source snapshot's seven checks never proved the table — the guard-dropping and rounding-smuggling mutants both survived them seven of seven.

## Pitfall

Three traps share one root: kinds never convert on their own — but they surface at three different layers, and the page states which is which. The static package check (`law engine check`) refuses malformed rules before any question is asked: mixed-kind comparisons (LDC-E2108), unbound rule variables (LDC-E4101), and rounding without a three-part policy (LDC-E2116). Case input validation rejects a wrongly kinded fact fed to a question. What remains for runtime scenarios is behavior the first two layers accept: the literal 1 is an integer while 1.0 is a decimal, so a full rate written as 1 fails against a decimal parameter when the question runs; a money divisor written as 3 instead of 3.0 fails for the same reason — the scalar shortcut applies only to multiplication. And a total over distinct values silently undercounts two equal charges, while an empty sum is refused rather than zeroed: both are caught only by scenarios that feed those inputs, never by the static check. Read each layer's refusal as the policy doing its job, and never credit one layer with another's catch.

## Verify

The stage is done when the check passes, all thirty-seven candidate scenarios pass, and every figure in the policy has tripwire failures that name the fault they catch. Criterion per figure: change one digit in a scratch copy of one tariff row and watch exactly that row's check fail; smuggle a rounding step into the penalty and watch exactly the fractional probe fail while the round-figure check still passes; feed insured sum two million against payroll one million and watch the answer follow the sum; restore, and all thirty-seven pass again. Single-failure cases are the isolated-probe special case — where one requirement owns several checks, the expected set fails instead. The tariff lines above are the tripwire evidence row by row, the fractional probe is the tripwire for EAI-D3, the premium-base probes are the tripwire for EAI-D4, and the two boundary pairs trip EAI-D2 at each end. The source seven-of-seven is not evidence for any figure it never fed.

## Limits

The running example computes everything inside its own rules: payroll, insured sum, minimum wage, risk class, loss percent, and delay figures arrive as case facts, and no outside computation feeds the package. Where an act points outward — a schedule maintained elsewhere, a payroll feed, a regulator rounding instruction — the automation-limits part names the external figure, its supplier, and the trust placed in it; the package then reads the figure as a fact and never recomputes it. EAI-D3 stays open by design: if a rounding instruction appears, the record reopens and the exact-product rule gains a policy.

## Next step

Continue with [Reuse and dependencies](/handbook/reuse-dependencies/), which draws the boundary around borrowed content the figures may rest on.

## Sources

- [Numbers and money](/tutorials/numbers/)
- [Tutorials](/tutorials/) — including the collections drill behind set totals.
- [Language reference](/constructs/) — kinds, money, and collection forms.
- [Command line](/cli/) — the check and test commands used above.
- [Recording decisions](/handbook/decisions/) — the records EAI-D1 through EAI-D3.