# lawref.counterfactual

*module*

Finite, offline counterfactual solver for the Core 0.1 [§186](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/26-part-xxv-proof-graph-and-explanations.ru.md#186-counterfactual) errata.

This module intentionally mirrors ``law-eval/src/counterfactual.rs``.  It
enumerates only supplied candidate patches, returns every success in the first
exact-cost tier, and treats any fatal/incomplete candidate before the cutoff as
an incomplete search rather than publishing a partial minimum.

## lawref.counterfactual.INPUT_VERSION

*attribute* · *module attribute*

```python
INPUT_VERSION = 'law.core.counterfactual-input/0.1'
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/counterfactual.py#L20-L20)

## lawref.counterfactual.RESULT_VERSION

*attribute* · *module attribute*

```python
RESULT_VERSION = 'law.core.counterfactual-result/0.1'
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/counterfactual.py#L21-L21)

## lawref.counterfactual.SOLVER_PROFILE

*attribute* · *module attribute*

```python
SOLVER_PROFILE = 'law.solver.finite-enumeration/0.1'
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/counterfactual.py#L22-L22)

## lawref.counterfactual.CounterfactualError

*class*

```python
class CounterfactualError(ValueError)
```

Bases: `ValueError`

Stable machine-readable counterfactual input/search failure.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/counterfactual.py#L26-L32)

### lawref.counterfactual.CounterfactualError.code

*attribute* · *instance attribute*

```python
code = code
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/counterfactual.py#L31-L31)

### lawref.counterfactual.CounterfactualError.message

*attribute* · *instance attribute*

```python
message = message
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/counterfactual.py#L32-L32)

## lawref.counterfactual.evaluate_counterfactual

*function*

```python
def evaluate_counterfactual(ir: dict, case: dict, input_: dict, options: dict | None = None, external_snapshots: list[dict] | None = None) -> dict
```

Evaluate all candidates through the first complete successful tier.

Options внутренних прогонов [§186](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/26-part-xxv-proof-graph-and-explanations.ru.md#186-counterfactual) берутся из ``case["options"]``, если
вызывающий не назвал свои: DECISION-0111 [§2.2](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/01-part-i-audit.ru.md#22-четырёхзначной-логики-самой-по-себе-недостаточно) объявляет ``case.options``
ЕДИНСТВЕННЫМ местом семантических опций, а `EvaluationRequest.build`
затирает их переданным словарём. До errata E-0135 (06.09.2026) умолчание
``{}`` молча выбрасывало выбор прочтения [§152](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/21-part-xx-interpretations-and-theories.ru.md#152-interpretation) и календарь дела: кандидаты
считались в мире без опций, а `caseHash` входа — по делу с ними.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/counterfactual.py#L221-L386)

## lawref.counterfactual.verify_counterfactual_result

*function*

```python
def verify_counterfactual_result(ir: dict, case: dict, input_: dict, claimed: dict, options: dict | None = None, external_snapshots: list[dict] | None = None) -> None
```

Replay and verify the complete canonical certificate and solution set.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/counterfactual.py#L389-L398)
