Json #
Shared JSON helpers for TorchLean verification tools.
Many verification workflows consume small JSON “certificates” produced by Python tooling (often PyTorch-based). This module centralizes:
- “shape” checks (object + field existence),
- simple scalar parsing (Nat/Float/Bool),
- small array helpers used across checkers.
These helpers take a strict stance: malformed certificates fail fast with contextual error messages instead of silently defaulting.
Read and parse a JSON verification artifact from disk.
Use this at checker boundaries instead of repeating IO.FS.readFile and Json.parse in every
tool. The file path is included in parse errors.
Instances For
Parse a rational in the format emitted by TorchLean’s Arb helpers:
- integer:
"5","-3" - fraction:
"5/2","-7/10"
Fraction strings represent arbitrary rationals without a floating-point conversion, including
values such as 1/3 that cannot be written as a finite JSON decimal.
Instances For
Parse either {lo, hi} or {center, eps} notation for a finite axis-aligned region.
When dim is absent, it is inferred from the endpoint or center array. When present, it must be a
natural number equal to the resulting endpoint lengths. Numbers are first decoded to host binary64.
The {center, eps} arithmetic rounds outward from those decoded values, not from the original
exact JSON decimals. Endpoint notation uses the decoded values directly. The parser rejects
negative radii, non-finite values, incomplete schemas, and intervals whose lower endpoint exceeds
the upper one.
Keeping these checks here gives certificate consumers one well-formed region type instead of
several subtly different parsers.
Instances For
Decode a JSON boolean if the value is exactly true or false.
Instances For
Require a top-level format field to match an expected artifact schema string.
This makes schema checks uniform across verification tools and keeps examples from hand-rolling their own unsupported-format errors.