Documentation

Docs / Proofs

Strict.lean

Lean 4 source (Lean 4 core, no Mathlib). 24 theorems. Download Strict.lean.

Theorems in this file
  • G.eval_readFree
  • G.mono
  • protects_rf
  • capAllows_rf
  • permitsAt_rf
  • blocked_rf
  • capsOK_rf
  • permitted_rf
  • release_reading_free_of_check
  • noninterference_of_check
  • check_is_needed
  • allow_iff_release
  • allow_reading_free
  • readings_only_ask
  • confirm_is_sound
  • blocked_of_forbids
  • blocked_of_bounds
  • asks_of_factAsks
  • allowM_iff
  • allowM_reading_free
  • forbid_beats_ask
  • boundary_asks_owner
  • confirmM_is_useful
  • decideM_eq_decide'
/-
  Strict mode as a CHECK, not as a type (25 November 2026).

  `Core.lean` makes Restriction N the type of the effects: `permit`, `forbid`, `cap` and
  `boundary` carry facts-only guards, so `release_reading_free` holds by `rfl`. That is the
  design, but it is not what the interpreter does: `experiments/kernel/core.py` accepts one
  guard language for every effect and rejects rule sets with `check_restrictions`.

  This file models the interpreter's arrangement and proves that the check is what carries
  the guarantee:

  * one guard type `G` for all six effects, in which `read` may appear anywhere positively;
  * `Effect.strictOK`, the syntactic check (no `read` in a permit, forbid, cap or boundary);
  * `release_reading_free_of_check`: every rule set that passes the check releases the same
    thing under every assignment of readings, proved by induction over guards and rule lists;
  * `check_is_needed`: a one-rule set that fails the check releases under one reading and
    not under another, so the check cannot be dropped (the Lean twin of `cedar/broken.cedar`);
  * `decide`, a three-valued verdict with strict mode's "please confirm" (SEMANTICS §2.6),
    and theorems that a reading can never produce `allow`, and that a confirmation question is
    asked only when the requester's own declaration (a fact) would release.

  Lean 4 core only, no Mathlib. Check with: lean Strict.lean
-/

namespace AccessStrict

structure FormOrder (Fm : Type) where
  le : Fm → Fm → Bool
  refl : ∀ a, le a a = true
  trans : ∀ a b c, le a b = true → le b c = true → le a c = true

/-- One guard language for every effect. Readings appear only positively: there is no
    negated reading, which is the positivity half of Restriction N. -/
inductive G (F Rd : Type) where
  | tt : G F Rd
  | ff : G F Rd
  | fact : F → G F Rd
  | nfact : F → G F Rd
  | read : Rd → G F Rd
  | and : G F Rd → G F Rd → G F Rd
  | or : G F Rd → G F Rd → G F Rd

variable {F Rd A Fm : Type}

def G.eval (φ : F → Bool) (ρ : Rd → Bool) : G F Rd → Bool
  | .tt => true
  | .ff => false
  | .fact a => φ a
  | .nfact a => !φ a
  | .read b => ρ b
  | .and g h => g.eval φ ρ && h.eval φ ρ
  | .or g h => g.eval φ ρ || h.eval φ ρ

/-- The guard mentions no reading. -/
def G.readFree : G F Rd → Bool
  | .read _ => false
  | .and g h => g.readFree && h.readFree
  | .or g h => g.readFree && h.readFree
  | _ => true

/-- A guard without readings means the same under every assignment of readings. -/
theorem G.eval_readFree (φ : F → Bool) (ρ ρ' : Rd → Bool) :
    ∀ g : G F Rd, g.readFree = true → g.eval φ ρ = g.eval φ ρ'
  | .tt, _ => rfl
  | .ff, _ => rfl
  | .fact _, _ => rfl
  | .nfact _, _ => rfl
  | .read _, h => by simp [G.readFree] at h
  | .and g k, h => by
      simp only [G.readFree, Bool.and_eq_true] at h
      simp only [G.eval, G.eval_readFree φ ρ ρ' g h.1, G.eval_readFree φ ρ ρ' k h.2]
  | .or g k, h => by
      simp only [G.readFree, Bool.and_eq_true] at h
      simp only [G.eval, G.eval_readFree φ ρ ρ' g h.1, G.eval_readFree φ ρ ρ' k h.2]

/-- More readings can only make a guard true, never false. -/
theorem G.mono (φ : F → Bool) {ρ ρ' : Rd → Bool} (hle : ∀ b, ρ b = true → ρ' b = true) :
    ∀ g : G F Rd, g.eval φ ρ = true → g.eval φ ρ' = true
  | .tt, h => h
  | .ff, h => h
  | .fact _, h => h
  | .nfact _, h => h
  | .read b, h => hle b h
  | .and g k, h => by
      simp only [G.eval, Bool.and_eq_true] at h ⊢
      exact ⟨G.mono φ hle g h.1, G.mono φ hle k h.2⟩
  | .or g k, h => by
      simp only [G.eval, Bool.or_eq_true] at h ⊢
      cases h with
      | inl h => exact Or.inl (G.mono φ hle g h)
      | inr h => exact Or.inr (G.mono φ hle k h)

inductive Effect (F Rd Fm : Type) where
  | permit : Fm → G F Rd → Effect F Rd Fm
  | ask : G F Rd → Effect F Rd Fm
  | forbid : G F Rd → Effect F Rd Fm
  | cap : Fm → G F Rd → Effect F Rd Fm
  | boundary : G F Rd → G F Rd → Effect F Rd Fm   -- applies when, lifted when
  | duty : Nat → G F Rd → Effect F Rd Fm

/-- Restriction N, strict form, as the interpreter's check: no reading in any guard of an
    effect that can release or protect. `ask` and `duty` may read. -/
def Effect.strictOK : Effect F Rd Fm → Bool
  | .permit _ g => g.readFree
  | .forbid g => g.readFree
  | .cap _ g => g.readFree
  | .boundary g l => g.readFree && l.readFree
  | .ask _ => true
  | .duty _ _ => true

structure Rule (F Rd A Fm : Type) where
  anchors : List A
  eff : Effect F Rd Fm

def strictOK (R : List (Rule F Rd A Fm)) : Bool := R.all fun r => r.eff.strictOK

def touches (m : A → Bool) (r : Rule F Rd A Fm) : Bool := r.anchors.all m

def protects (φ : F → Bool) (ρ : Rd → Bool) : Effect F Rd Fm → Bool
  | .forbid g => g.eval φ ρ
  | .boundary g l => g.eval φ ρ && !l.eval φ ρ
  | _ => false

def capAllows (O : FormOrder Fm) (φ : F → Bool) (ρ : Rd → Bool) (f : Fm) : Effect F Rd Fm → Bool
  | .cap c g => !g.eval φ ρ || O.le f c
  | _ => true

def permitsAt (O : FormOrder Fm) (φ : F → Bool) (ρ : Rd → Bool) (f : Fm) : Effect F Rd Fm → Bool
  | .permit p g => g.eval φ ρ && O.le f p
  | _ => false

def blocked (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool) (R : List (Rule F Rd A Fm)) : Bool :=
  R.any fun r => touches m r && protects φ ρ r.eff

def capsOK (O : FormOrder Fm) (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool)
    (R : List (Rule F Rd A Fm)) (f : Fm) : Bool :=
  R.all fun r => !touches m r || capAllows O φ ρ f r.eff

def permitted (O : FormOrder Fm) (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool)
    (R : List (Rule F Rd A Fm)) (f : Fm) : Bool :=
  R.any fun r => touches m r && permitsAt O φ ρ f r.eff

/-- The release decision now evaluates every guard with the readings. -/
def release (O : FormOrder Fm) (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool)
    (R : List (Rule F Rd A Fm)) (q f : Fm) : Bool :=
  !blocked m φ ρ R && capsOK O m φ ρ R f && permitted O m φ ρ R f && O.le f q

variable (O : FormOrder Fm)

/-! ## Effect-level: a checked effect ignores the readings -/

theorem protects_rf (φ : F → Bool) (ρ ρ' : Rd → Bool) :
    ∀ e : Effect F Rd Fm, e.strictOK = true → protects φ ρ e = protects φ ρ' e
  | .forbid g, h => by simp only [Effect.strictOK] at h; simp only [protects, G.eval_readFree φ ρ ρ' g h]
  | .boundary g l, h => by
      simp only [Effect.strictOK, Bool.and_eq_true] at h
      simp only [protects, G.eval_readFree φ ρ ρ' g h.1, G.eval_readFree φ ρ ρ' l h.2]
  | .permit _ _, _ => rfl
  | .cap _ _, _ => rfl
  | .ask _, _ => rfl
  | .duty _ _, _ => rfl

theorem capAllows_rf (φ : F → Bool) (ρ ρ' : Rd → Bool) (f : Fm) :
    ∀ e : Effect F Rd Fm, e.strictOK = true → capAllows O φ ρ f e = capAllows O φ ρ' f e
  | .cap _ g, h => by simp only [Effect.strictOK] at h; simp only [capAllows, G.eval_readFree φ ρ ρ' g h]
  | .permit _ _, _ => rfl
  | .forbid _, _ => rfl
  | .boundary _ _, _ => rfl
  | .ask _, _ => rfl
  | .duty _ _, _ => rfl

theorem permitsAt_rf (φ : F → Bool) (ρ ρ' : Rd → Bool) (f : Fm) :
    ∀ e : Effect F Rd Fm, e.strictOK = true → permitsAt O φ ρ f e = permitsAt O φ ρ' f e
  | .permit _ g, h => by simp only [Effect.strictOK] at h; simp only [permitsAt, G.eval_readFree φ ρ ρ' g h]
  | .cap _ _, _ => rfl
  | .forbid _, _ => rfl
  | .boundary _ _, _ => rfl
  | .ask _, _ => rfl
  | .duty _ _, _ => rfl

/-! ## Rule-set level, by induction over the rule list -/

theorem blocked_rf (m : A → Bool) (φ : F → Bool) (ρ ρ' : Rd → Bool) :
    ∀ R : List (Rule F Rd A Fm), strictOK R = true → blocked m φ ρ R = blocked m φ ρ' R
  | [], _ => rfl
  | r :: R, h => by
      simp only [strictOK, List.all_cons, Bool.and_eq_true] at h
      have ih := blocked_rf m φ ρ ρ' R h.2
      simp only [blocked, List.any_cons] at ih ⊢
      rw [protects_rf φ ρ ρ' r.eff h.1, ih]

theorem capsOK_rf (m : A → Bool) (φ : F → Bool) (ρ ρ' : Rd → Bool) (f : Fm) :
    ∀ R : List (Rule F Rd A Fm), strictOK R = true → capsOK O m φ ρ R f = capsOK O m φ ρ' R f
  | [], _ => rfl
  | r :: R, h => by
      simp only [strictOK, List.all_cons, Bool.and_eq_true] at h
      have ih := capsOK_rf m φ ρ ρ' f R h.2
      simp only [capsOK, List.all_cons] at ih ⊢
      rw [capAllows_rf O φ ρ ρ' f r.eff h.1, ih]

theorem permitted_rf (m : A → Bool) (φ : F → Bool) (ρ ρ' : Rd → Bool) (f : Fm) :
    ∀ R : List (Rule F Rd A Fm), strictOK R = true → permitted O m φ ρ R f = permitted O m φ ρ' R f
  | [], _ => rfl
  | r :: R, h => by
      simp only [strictOK, List.all_cons, Bool.and_eq_true] at h
      have ih := permitted_rf m φ ρ ρ' f R h.2
      simp only [permitted, List.any_cons] at ih ⊢
      rw [permitsAt_rf O φ ρ ρ' f r.eff h.1, ih]

/-- **The headline theorem, for the checked arrangement.** Every rule set that passes the
    strict check releases exactly the same thing under every assignment of readings. -/
theorem release_reading_free_of_check (m : A → Bool) (φ : F → Bool) (ρ ρ' : Rd → Bool)
    (R : List (Rule F Rd A Fm)) (hR : strictOK R = true) (q f : Fm) :
    release O m φ ρ R q f = release O m φ ρ' R q f := by
  simp only [release, blocked_rf m φ ρ ρ' R hR, capsOK_rf O m φ ρ ρ' f R hR,
    permitted_rf O m φ ρ ρ' f R hR]

/-- Non-interference for the checked arrangement: once protection applies under the facts,
    nothing is released under any reading. -/
theorem noninterference_of_check (m : A → Bool) (φ : F → Bool) (ρ₀ : Rd → Bool)
    (R : List (Rule F Rd A Fm)) (hR : strictOK R = true) (q : Fm)
    (h : blocked m φ ρ₀ R = true) : ∀ (ρ : Rd → Bool) (f : Fm), release O m φ ρ R q f = false := by
  intro ρ f
  have hb : blocked m φ ρ R = true := by rw [blocked_rf m φ ρ ρ₀ R hR]; exact h
  simp [release, hb]

/-! ## The check is needed -/

/-- The two-element chain `false ≤ true`, enough for a counterexample. -/
def boolOrder : FormOrder Bool :=
  ⟨fun a b => !a || b, by intro a; cases a <;> rfl,
   by intro a b c; cases a <;> cases b <;> cases c <;> simp⟩

/-- One permit whose guard is a reading (`cedar/broken.cedar` in one line). It fails the
    check, and the release then depends on the reading. -/
def brokenRules : List (Rule Unit Unit Unit Bool) := [⟨[], .permit true (.read ())⟩]

theorem check_is_needed :
    strictOK brokenRules = false ∧
    release boolOrder (fun _ => true) (fun _ => false) (fun _ => true) brokenRules true true = true ∧
    release boolOrder (fun _ => true) (fun _ => false) (fun _ => false) brokenRules true true = false := by
  decide

/-! ## Verdicts: deny, ask, allow, with strict mode's "please confirm" (SEMANTICS §2.6) -/

inductive Verdict where
  | deny | ask | allow
  deriving DecidableEq, Repr

/-- Some touching `ask` rule applies (its guard may read). -/
def asks (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool) (R : List (Rule F Rd A Fm)) : Bool :=
  R.any fun r => touches m r && match r.eff with
    | .ask g => g.eval φ ρ
    | _ => false

/-- Add the fact `a` to the facts: the requester's own declaration. -/
def withFact [DecidableEq F] (φ : F → Bool) (a : F) : F → Bool := fun x => φ x || decide (x = a)

/-- The decision. `props` are the use cases the model proposes, each paired with the fact the
    requester would make by confirming it (`declared(r, u)`). The model's readings `ρ` say
    which proposals it holds. Allow comes only from the facts; a reading can cause a question. -/
def decide' [DecidableEq F] (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool)
    (R : List (Rule F Rd A Fm)) (props : List (Rd × F)) (q f : Fm) : Verdict :=
  if release O m φ ρ R q f then .allow
  else if props.any (fun p => ρ p.1 && release O m (withFact φ p.2) ρ R q f) then .ask
  else if asks m φ ρ R then .ask
  else .deny

/-- Allow is exactly release under the facts. -/
theorem allow_iff_release [DecidableEq F] (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool)
    (R : List (Rule F Rd A Fm)) (props : List (Rd × F)) (q f : Fm) :
    decide' O m φ ρ R props q f = .allow ↔ release O m φ ρ R q f = true := by
  unfold decide'
  by_cases h : release O m φ ρ R q f = true
  · simp [h]
  · simp only [h]
    constructor
    · intro hd
      by_cases h2 : props.any (fun p => ρ p.1 && release O m (withFact φ p.2) ρ R q f) = true
      · simp [h2] at hd
      · by_cases h3 : asks m φ ρ R = true
        · simp [h2, h3] at hd
        · simp [h2, h3] at hd
    · intro hc; simp at hc

/-- **A reading can never produce allow.** For a checked rule set, the verdict is allow under
    one assignment of readings exactly when it is allow under any other. -/
theorem allow_reading_free [DecidableEq F] (m : A → Bool) (φ : F → Bool) (ρ ρ' : Rd → Bool)
    (R : List (Rule F Rd A Fm)) (hR : strictOK R = true) (props : List (Rd × F)) (q f : Fm) :
    decide' O m φ ρ R props q f = .allow ↔ decide' O m φ ρ' R props q f = .allow := by
  rw [allow_iff_release, allow_iff_release, release_reading_free_of_check O m φ ρ ρ' R hR]

/-- A reading can only move the verdict between deny and ask. -/
theorem readings_only_ask [DecidableEq F] (m : A → Bool) (φ : F → Bool) (ρ ρ' : Rd → Bool)
    (R : List (Rule F Rd A Fm)) (hR : strictOK R = true) (props : List (Rd × F)) (q f : Fm)
    (hne : decide' O m φ ρ R props q f ≠ decide' O m φ ρ' R props q f) :
    decide' O m φ ρ R props q f ≠ .allow ∧ decide' O m φ ρ' R props q f ≠ .allow := by
  constructor
  · intro ha
    have hb := (allow_reading_free O m φ ρ ρ' R hR props q f).1 ha
    exact hne (ha.trans hb.symm)
  · intro hb
    have ha := (allow_reading_free O m φ ρ ρ' R hR props q f).2 hb
    exact hne (ha.trans hb.symm)

/-- **A confirmation is asked only when the answer is a fact that would release.** If the
    verdict is not allow and no ask rule applies, an ask can only come from a proposal the model
    read whose declaration (a fact the requester makes and answers for) would release. -/
theorem confirm_is_sound [DecidableEq F] (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool)
    (R : List (Rule F Rd A Fm)) (props : List (Rd × F)) (q f : Fm)
    (hask : decide' O m φ ρ R props q f = .ask) (hno : asks m φ ρ R = false) :
    ∃ p ∈ props, ρ p.1 = true ∧ release O m (withFact φ p.2) ρ R q f = true := by
  unfold decide' at hask
  by_cases h : release O m φ ρ R q f = true
  · simp [h] at hask
  · by_cases h2 : props.any (fun p => ρ p.1 && release O m (withFact φ p.2) ρ R q f) = true
    · simp only [List.any_eq_true, Bool.and_eq_true] at h2
      obtain ⟨p, hp, h3, h4⟩ := h2
      exact ⟨p, hp, h3, h4⟩
    · simp [h, h2, hno] at hask

/-! ## The Interpreter's Verdict: Forbid Before Ask, and the Minimum Useful Form

  Differential testing against `core.py` (experiments/difftest/RESULTS.md) found two places where
  `decide'` asks and the interpreter denies: (1) a forbid and an ask rule both apply (the
  interpreter: a forbid decides, deny); (2) a confirmation whose release is below the form the
  requester said is the least useful (`min_useful`). `decideM` is the interpreter's reading:
  `useful f` says that the candidate form `f` meets the requester's minimum. The theorems of
  `decide'` carry over, and two new ones state the two fixes. -/

/-- A forbid applies on the facts. -/
def forbids (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool) (R : List (Rule F Rd A Fm)) : Bool :=
  R.any fun r => touches m r && match r.eff with
    | .forbid g => g.eval φ ρ
    | _ => false

/-- A boundary applies and is not lifted. -/
def bounds (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool) (R : List (Rule F Rd A Fm)) : Bool :=
  R.any fun r => touches m r && match r.eff with
    | .boundary g l => g.eval φ ρ && !l.eval φ ρ
    | _ => false

/-- An ask rule whose guard reads nothing applies: its answer is a fact (a grant by the owner). -/
def factAsks (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool) (R : List (Rule F Rd A Fm)) : Bool :=
  R.any fun r => touches m r && match r.eff with
    | .ask g => g.readFree && g.eval φ ρ
    | _ => false

theorem blocked_of_forbids (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool) (R : List (Rule F Rd A Fm))
    (h : forbids m φ ρ R = true) : blocked m φ ρ R = true := by
  unfold forbids at h; unfold blocked
  rw [List.any_eq_true] at h ⊢
  obtain ⟨r, hr, h2⟩ := h
  refine ⟨r, hr, ?_⟩
  simp only [Bool.and_eq_true] at h2 ⊢
  refine ⟨h2.1, ?_⟩
  have he := h2.2
  split at he <;> simp_all [protects]

theorem blocked_of_bounds (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool) (R : List (Rule F Rd A Fm))
    (h : bounds m φ ρ R = true) : blocked m φ ρ R = true := by
  unfold bounds at h; unfold blocked
  rw [List.any_eq_true] at h ⊢
  obtain ⟨r, hr, h2⟩ := h
  refine ⟨r, hr, ?_⟩
  simp only [Bool.and_eq_true] at h2 ⊢
  refine ⟨h2.1, ?_⟩
  have he := h2.2
  split at he <;> simp_all [protects]

theorem asks_of_factAsks (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool) (R : List (Rule F Rd A Fm))
    (h : factAsks m φ ρ R = true) : asks m φ ρ R = true := by
  unfold factAsks at h; unfold asks
  rw [List.any_eq_true] at h ⊢
  obtain ⟨r, hr, h2⟩ := h
  refine ⟨r, hr, ?_⟩
  simp only [Bool.and_eq_true] at h2 ⊢
  refine ⟨h2.1, ?_⟩
  have he := h2.2
  split at he <;> simp_all

/-- The verdict as the interpreter computes it (matched against core.py by differential testing):
    allow on a useful release; deny on a forbid; ask to confirm a proposal that would release a
    useful form; at an unlifted boundary, ask only through a fact-only ask (its answer is the
    owner's grant), else deny; ask if an ask rule applies; else deny. -/
def decideM [DecidableEq F] (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool)
    (R : List (Rule F Rd A Fm)) (props : List (Rd × F)) (useful : Fm → Bool) (q f : Fm) : Verdict :=
  if release O m φ ρ R q f && useful f then .allow
  else if forbids m φ ρ R then .deny
  else if props.any (fun p => ρ p.1 && release O m (withFact φ p.2) ρ R q f && useful f) then .ask
  else if bounds m φ ρ R then (if factAsks m φ ρ R then .ask else .deny)
  else if asks m φ ρ R then .ask
  else .deny

/-- Allow is exactly a release of a useful form under the facts. -/
theorem allowM_iff [DecidableEq F] (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool)
    (R : List (Rule F Rd A Fm)) (props : List (Rd × F)) (useful : Fm → Bool) (q f : Fm) :
    decideM O m φ ρ R props useful q f = .allow ↔ (release O m φ ρ R q f && useful f) = true := by
  unfold decideM
  by_cases h : (release O m φ ρ R q f && useful f) = true
  · simp [h]
  · simp only [h]
    constructor
    · intro hd
      repeat' split at hd
      all_goals simp_all
    · intro hc; simp at hc

/-- **A reading never produces allow**, in the interpreter's verdict too. -/
theorem allowM_reading_free [DecidableEq F] (m : A → Bool) (φ : F → Bool) (ρ ρ' : Rd → Bool)
    (R : List (Rule F Rd A Fm)) (hR : strictOK R = true) (props : List (Rd × F))
    (useful : Fm → Bool) (q f : Fm) :
    decideM O m φ ρ R props useful q f = .allow ↔ decideM O m φ ρ' R props useful q f = .allow := by
  rw [allowM_iff, allowM_iff, release_reading_free_of_check O m φ ρ ρ' R hR]

/-- **Forbid before ask.** When a forbid applies on the facts, the verdict is deny, whatever the
    readings, the proposals and the ask rules. -/
theorem forbid_beats_ask [DecidableEq F] (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool)
    (R : List (Rule F Rd A Fm)) (props : List (Rd × F)) (useful : Fm → Bool) (q f : Fm)
    (hb : forbids m φ ρ R = true) :
    decideM O m φ ρ R props useful q f = .deny := by
  have hr : release O m φ ρ R q f = false := by
    simp [release, blocked_of_forbids m φ ρ R hb]
  simp [decideM, hr, hb]

/-- **An unlifted boundary asks only its owner.** With no confirmation that would lift it, an
    unlifted boundary gives ask only when a fact-only ask applies, else deny. -/
theorem boundary_asks_owner [DecidableEq F] (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool)
    (R : List (Rule F Rd A Fm)) (props : List (Rd × F)) (useful : Fm → Bool) (q f : Fm)
    (hb : bounds m φ ρ R = true) (hf : forbids m φ ρ R = false)
    (hp : props.any (fun p => ρ p.1 && release O m (withFact φ p.2) ρ R q f && useful f) = false) :
    decideM O m φ ρ R props useful q f = (if factAsks m φ ρ R then .ask else .deny) := by
  have hr : release O m φ ρ R q f = false := by
    simp [release, blocked_of_bounds m φ ρ R hb]
  simp [decideM, hr, hf, hp, hb]

/-- **A confirmation is asked only when its answer would release a useful form.** -/
theorem confirmM_is_useful [DecidableEq F] (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool)
    (R : List (Rule F Rd A Fm)) (props : List (Rd × F)) (useful : Fm → Bool) (q f : Fm)
    (hask : decideM O m φ ρ R props useful q f = .ask) (hno : asks m φ ρ R = false) :
    ∃ p ∈ props, ρ p.1 = true ∧ release O m (withFact φ p.2) ρ R q f = true ∧ useful f = true := by
  unfold decideM at hask
  by_cases h2 : props.any (fun p => ρ p.1 && release O m (withFact φ p.2) ρ R q f && useful f) = true
  · simp only [List.any_eq_true, Bool.and_eq_true] at h2
    obtain ⟨p, hp, ⟨h3, h4⟩, h5⟩ := h2
    exact ⟨p, hp, h3, h4, h5⟩
  · repeat' split at hask
    all_goals (try simp [asks_of_factAsks m φ ρ R (by assumption)] at hno)
    all_goals simp_all

/-- With no minimum and nothing blocked, `decideM` is `decide'`: the fix changes nothing else. -/
theorem decideM_eq_decide' [DecidableEq F] (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool)
    (R : List (Rule F Rd A Fm)) (props : List (Rd × F)) (q f : Fm)
    (hb : blocked m φ ρ R = false) :
    decideM O m φ ρ R props (fun _ => true) q f = decide' O m φ ρ R props q f := by
  have h1 : forbids m φ ρ R = false := by
    cases h : forbids m φ ρ R
    · rfl
    · simp [blocked_of_forbids m φ ρ R h] at hb
  have h2 : bounds m φ ρ R = false := by
    cases h : bounds m φ ρ R
    · rfl
    · simp [blocked_of_bounds m φ ρ R h] at hb
  unfold decideM decide'
  by_cases hr : release O m φ ρ R q f = true
  · simp [hr]
  · simp only [hr, h1, h2, Bool.and_true, Bool.false_eq_true, ite_false]

end AccessStrict

Last built 2026-11-25