Division under an explicit policy
Intention
Section titled “Intention”I want to round an exact quotient once, at a stated precision.
The scenes check a short rule and two separate long cases; rounding happens once, at the stated precision.
Incorrect form and why it stays silent
Section titled “Incorrect form and why it stays silent”pure function Third(x: Money) -> Money = div_round(x, 3.0, 2);A rounding mode is mandatory; div_round does not choose it for the author. round(money / 3.0) also does not help: inexact division fails before rounding. A 28-digit context limit of one implementation is not a language rule.
Correct form
Section titled “Correct form”language "law.core" version "0.2";package recipes.l.r10 version "0.1.0";namespace "urn:recipe:l-calc:10";
pure function Third(x: Money) -> Money = div_round(x, 3.0, 2, "HALF_UP");Frozen execution scene
Section titled “Frozen execution scene”| Facts and choice | Question | Answer |
|---|---|---|
| 1. one money unit among three | Third(1 KZT) | 0.33 KZT / COMPUTED |
| 2. an integer quotient is still rounded by the policy | div_round(1.0, 8.0, 2, "HALF_UP") | 0.13 / COMPUTED |
| 3. long explicitly stated precision 28 | div_round(1.0, 3.0, 28, "DOWN") | 0.3333333333333333333333333333 / COMPUTED |
| 4. rounding after inexact division is too late | round(1 KZT / 3.0, 2, "HALF_UP") | no value / RUNTIME_ERROR |
| 5. long explicitly stated precision 34 | div_round(1.0, 3.0, 34, "DOWN") | 0.3333333333333333333333333333333333 / COMPUTED |
one money unit split three ways
test "one money unit split three ways" { given { context { legal_time @2026-09-13; decision_time @2026-09-13T09:00:00+05:00; knowledge_time @2026-09-13T09:00:00+05:00; timezone "Asia/Almaty"; }
} evaluate Third(1 KZT); expect value == 0.33 KZT; expect evaluation_status == COMPUTED;
}integer quotient rounded by policy
test "integer quotient rounded by policy" { given { context { legal_time @2026-09-13; decision_time @2026-09-13T09:00:00+05:00; knowledge_time @2026-09-13T09:00:00+05:00; timezone "Asia/Almaty"; }
} evaluate div_round(1.0, 8.0, 2, "HALF_UP"); expect value == 0.13; expect evaluation_status == COMPUTED;
}long stated precision 28
test "long stated precision 28" { given { context { legal_time @2026-09-13; decision_time @2026-09-13T09:00:00+05:00; knowledge_time @2026-09-13T09:00:00+05:00; timezone "Asia/Almaty"; }
} evaluate div_round(1.0, 3.0, 28, "DOWN"); expect value == 0.3333333333333333333333333333; expect evaluation_status == COMPUTED;
}rounding after inexact division fails
test "rounding after inexact division fails" { given { context { legal_time @2026-09-13; decision_time @2026-09-13T09:00:00+05:00; knowledge_time @2026-09-13T09:00:00+05:00; timezone "Asia/Almaty"; }
} evaluate round(1 KZT / 3.0, 2, "HALF_UP");
expect evaluation_status == RUNTIME_ERROR; expect issue(INEXACT_DIVISION);}Counterfactual
Section titled “Counterfactual”Mutation: div_round(x, 3.0, 2, "HALF_UP") → div_round(x, 3.0, 2); expected LDC-E2116. Additional counterfactuals are shown as separate table rows.
An extra scene precision=34 checks the normative expectation: 34 threes. A previous defect that returned 28 threes is closed; now both implementations return 34 threes and their documents match. The scene is an ordinary jointly passing run. The check below executes the same expectation with both runners and pins the parity.
test "long stated precision 34" { given { context { legal_time @2026-09-13; decision_time @2026-09-13T09:00:00+05:00; knowledge_time @2026-09-13T09:00:00+05:00; timezone "Asia/Almaty"; }
} evaluate div_round(1.0, 3.0, 34, "DOWN"); expect value == 0.3333333333333333333333333333333333; expect evaluation_status == COMPUTED;
}>>> import runpy>>> checks = runpy.run_path("docs/recipes/l-calc/resources/check.py")>>> checks["check_precision"]()'precision=34; lawc = lawref (34 threes)'Boundary
Section titled “Boundary”Precision 0…34 is allowed. The defect at precision 34 is closed: both implementations return 34 threes, and the extra long example is the rule, not a qualified failure.
Pitfall
Section titled “Pitfall”An inexact division fails before any rounding can repair it: rounding after / is too late.
Documentation for Arxo. Writings — blog.arxo.io.
Anonymous visit counts on stats.arxo.io, no cookies.