docs← Back to article

Markdown for LLMs

Find a minimal change of inputs

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

Download this articlePlain text ↗
# Find a minimal change of inputs

## Intent

I want to find a minimal change of inputs.

## Wrong form and why it stays silent

Without cost, minimality is undefined. The solver requires a finite presented set and does not guess arbitrary facts.

```text title="Incorrect form"
counterfactual MakeReady { target ready(); mutable ready; }
```

## Correct form

```law
language "law.core" version "0.2";
package recipe.m04 version "1.0.0";
namespace "urn:recipe:m-queries:04";
relation ready();
counterfactual MakeReady { target ready(); mutable ready; cost "urn:recipe:m-queries:04:unit-cost"; }
```

## Frozen execution scene

| Input / variant | Question | Expectation |
|---|---|---|
| 2. both ready supports | `truth(ready())` | `truth_status == BOTH; evaluation_status == COMPUTED;` |
| 1. original goal unknown | `truth(ready())` | `truth_status == NEITHER;  evaluation_status == COMPUTED;` |

```law
test "unknown initial goal" {
    given {
        context { legal_time @2026-09-13; decision_time @2026-09-13T09:00:00Z; knowledge_time @2026-09-13T09:00:00Z; timezone "UTC";  }

    }
    evaluate truth(ready());
    expect truth_status == NEITHER; expect evaluation_status == COMPUTED;
}
```

A contested proposition is checked separately with an ordinary truth query:

```law
test "disputed goal stays both" {
    given {
        context { legal_time @2026-09-13; decision_time @2026-09-13T09:00:00Z; knowledge_time @2026-09-13T09:00:00Z; timezone "UTC";  }
        assert ready(); assert not ready();
    }
    evaluate truth(ready());
    expect truth_status == BOTH; expect evaluation_status == COMPUTED;
}
```

A separate finite set is presented to the solver. The program and case are taken from this test, programHash/caseHash and the input contentHash are pinned, and the ordinary `counterfactual` of both implementations is called to reproduce the certificate. This is a separate counterfactual interface, not a variety of `truth` in `evaluates`.

| Set / input change | Checked solver result |
|---|---|
| empty: cost 0, no operations; b and a: cost 1, addAssertion ready() | both equal minima, a and b in canonical order |
| empty only | NO_SOLUTION |
| ready() already in the original case | ALREADY_SATISFIED |
| not ready() in the case, candidate adds ready() | NO_SOLUTION; targetStatus FALSE_ONLY of established(ready) |
| wrong programHash with recalculated contentHash | COUNTERFACTUAL_PROGRAM_HASH_MISMATCH |
| setContext legalTime, only mutable ready allowed | refusal of a forbidden mutation |

The surface target ready() lowers into a status condition established(ready),
so with two supports the raw truthStatus is BOTH (scene 2), while the certificate
targetStatus is FALSE_ONLY. These are different questions, not a loss of positive support.

Cost is given as an exact Decimal string and belongs to the named model
`urn:recipe:m-queries:04:unit-cost`; the adapter does not compute it. The set itself
does not change the program and contains only operations over the input.

Check of result fields and extra inputs:

```python
>>> import runpy
>>> checks = runpy.run_path("docs/recipes/m-queries/resources/check.py")
>>> checks["counterfactual"](https://github.com/arxohq/law/blob/master/docs/recipes/m-queries/4)
True
```

## Counterfactual

The sidecar mutation reproduces `LDC-E1205`. Counterfactual table variants are executed separately; input errors are not passed off as NEITHER.

## Boundary

Counterfactual is a separate command and result type. Candidate worlds are presented as input; search does not promise a global minimum outside the set. The law, evidence, and the chosen reading are immutable.

## Pitfall

Equal minima, cutoff, and Contradiction are checked separately; absence of cost must not be patched by an arbitrary default.