pith. machine review for the scientific record. sign in
def

mkError

definition
show as:
view math explainer →
module
IndisputableMonolith.Certificates.JMonotone
domain
Certificates
line
22 · github
papers citing
none yet

open explainer

Read the cached plain-language explainer.

open lean source

IndisputableMonolith.Certificates.JMonotone on GitHub at line 22.

browse module

All declarations in this module, on Recognition.

explainer page

A cached Ask Recognition explainer exists for this declaration.

open explainer

depends on

used by

formal source

  19
  20@[simp] def JMonotoneCert.verified (c : JMonotoneCert) : Prop := c.ok = true
  21
  22private def mkError (idxs : List Nat) : List String :=
  23  match idxs with
  24  | []      => []
  25  | (i::_)  =>
  26      let windowStart := (i / 8) * 8
  27      [s!"J-monotone violated within window starting at {windowStart} (first increase at step {i}→{i+1})"]
  28
  29/-- Build a JMonotone certificate from compiled code. -/
  30def JMonotoneCert.fromProgram (code : Array LInstr) (initBudget : Nat := 4) : JMonotoneCert :=
  31  let budgets := simulateBudget code initBudget
  32  let delta := deltaJPerWindow code
  33  let violations := jMonotoneViolations code initBudget code.size
  34  let ok := violations = []
  35  let errors := if ok then [] else mkError violations
  36  { ok := ok, initBudget := initBudget, budgets := budgets, deltaJ := delta,
  37    violations := violations, errors := errors }
  38
  39/-- Build a JMonotone certificate directly from LNAL source text. -/
  40def JMonotoneCert.fromSource (src : String) (initBudget : Nat := 4) : JMonotoneCert :=
  41  let code := match parseProgram src with
  42    | .ok code => code
  43    | .error _ => #[]
  44  fromProgram code initBudget
  45
  46/-- Helper returning the first violation index, if any. -/
  47def JMonotoneCert.firstViolation? (c : JMonotoneCert) : Option Nat :=
  48  match c.violations with
  49  | [] => none
  50  | i :: _ => some i