# lawref.evaluator.defeasible

*module*

L1: defeasible/defeater, приоритеты и defeat — SPEC [§104](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#104-defeasible-candidate)–[§115](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#115-конфликтный-результат).

Кандидаты по стратам [§110](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#110-stratification)/[§111](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#111-порядок-evaluation-strata), defeat [§107](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#107-defeat), surviving support [§108](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#108-surviving-support)
(candidate-level team [§109](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#109-team-support)), ambiguity-preserving BOTH [§112](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#112-ambiguity-policy), отчёты [§115](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#115-конфликтный-результат).
В конце каждой страты дозапускается strict closure ([§111](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#111-порядок-evaluation-strata) шаг 1) — отсюда
единственная дуга к `strict`, обратной нет.

## lawref.evaluator.defeasible.META_STD

*attribute* · *module attribute*

```python
META_STD = 'urn:law:std#'
```

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

## lawref.evaluator.defeasible.NORM_STD

*attribute* · *module attribute*

```python
NORM_STD = 'urn:law:std#'
```

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

## lawref.evaluator.defeasible.defeasible_closure

*function*

```python
def defeasible_closure(store: SupportStore, nodes: list[dict], legal_time: str, registry: ProofRegistry, issues: list[dict], limits: dict | None = None, env: Any = None, program_hash: str = '', input_hash: str = '', prepared: dict[str, Any] | None = None, prepared_strict: Any = None, state: dict | None = None, emit_prepared_issues: bool = True) -> list[dict]
```

L1 ([§104](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#104-defeasible-candidate)–[§112](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#112-ambiguity-policy)): кандидаты defeasible/defeater по стратам [§110](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#110-stratification)/[§111](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#111-порядок-evaluation-strata),
defeat [§107](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#107-defeat), surviving support [§108](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#108-surviving-support) (candidate-level team [§109](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#109-team-support)),
ambiguity-preserving BOTH [§112](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#112-ambiguity-policy); отчёты о конфликтах [§115](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#115-конфликтный-результат).

V1-объём: приоритеты — rule-level ([§106](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#106-priority-relation)) с транзитивным замыканием и
детекцией цикла (PRIORITY_CONFLICT, без tie-break); тела — established-
конъюнкты (default negation [§113](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#113-default-negation) — следующий срез); стратификация — по
глубине цепочек defeasible-голов (цикл — NON_EXECUTABLE_UNSTRATIFIED).

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

## lawref.evaluator.defeasible.prepare_defeasible

*function*

```python
def prepare_defeasible(nodes: list[dict]) -> dict[str, Any]
```

Установка поражаемого слоя — чистая функция от узлов программы:
кандидаты [§104](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#104-defeasible-candidate) с конъюнктами и их предупреждения, замыкание приоритетов
[§106](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#106-priority-relation), условные приоритеты, ранги [§110](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#110-stratification) и их issues. Вид программы
(`evaluator.prepared`) считает её один раз на дату права; issues
воспроизводятся `defeasible_closure` в прежнем порядке и числе.

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

## lawref.evaluator.defeasible.rule_ranks

*function*

```python
def rule_ranks(nodes: list[dict]) -> dict[str, int]
```

Ранги [§110](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#110-stratification) по одному CLIR-документу — вход для ворот.

Повторяет отбор правил, который делает `defeasible_closure`
(`_rule_filter_l1` отсеивает то, что v1 не исполняет), и потому видит
ровно то множество, которое участвует в конфликтных группах [§111](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#111-порядок-evaluation-strata).
Диагностики отбора глушатся: ворота спрашивают о рангах, а о мёртвых
правилах докладывает `verify/ci/gates/silence/check_dead_rules.py`.

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

## lawref.evaluator.defeasible.stratify

*function*

```python
def stratify(drules: list[tuple[dict, list]], issues: list[dict], derived: set[str] | frozenset[str] = frozenset(), chain: list[tuple[str, list[str]]] = ()) -> dict[str, int] | None
```

Ранг правила [§110](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#110-stratification) (v1): глубина цепочки через defeasible-головы.

Извлечено из тела `defeasible_closure` БЕЗ изменения поведения, чтобы у
рангов был один носитель. Вторая копия этого цикла разошлась бы с первой
молча — тот же довод, по которому `verify/ci/gates/silence/check_dead_rules.py` переиспользует
`rules.rule_execution_status`, а не повторяет её.

Читатель снаружи один и важный: `verify/ci/gates/silence/check_stratum_barrier.py`. Приоритет
[§116](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/17-part-xvi-priority-declarations.ru.md#116-direct-priority) разрешает конфликт ТОЛЬКО внутри страты ([§111](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#111-порядок-evaluation-strata) собирает конфликтные
группы для каждой страты отдельно), поэтому объявленное ребро между
правилами РАЗНЫХ рангов не применяется никогда — и молчит при чистых
`check`, `lower` и воротах мёртвых правил. Считать ранги воротам
приходится теми же, что считает вывод, иначе они докладывали бы о
несуществующих дефектах либо молчали о настоящих.

`None` — программа нестратифицируема ([§110](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#110-stratification)): цикл через defeasible-
зависимости, вывод не выполняется.

`chain` — строго-позитивные рёбра программы (`rules.strict_positive_chain`),
errata E-0172: предикат, который строгая цепочка выводит из головы
поражаемого правила страты k, полон лишь к шагу 1 страты k + 1 [§111](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#111-порядок-evaluation-strata), и
правило, читающее его в теле или выводящее его голову, стоит там же.
Пустой `chain` — прежние ранги.

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