TorchLean API

NN.Verification.Cert.NodeReplay

Node-Certificate Replay #

Parsing, exact comparison, and local replay for node-wise verification certificates.

The IBP and CROWN checkers consume the same basic artifact shapes: flat interval boxes, affine lower/upper bounds, and optional per-node vectors. We keep those format-level operations here so each checker can focus on its propagation rule:

The JSON artifact is always untrusted. These helpers only parse and compare data; acceptance still requires each checker to recompute the corresponding bound inside Lean. Interval claims are checked by containment after rounding each decimal endpoint outward into binary32, while affine replay transcripts must match the executable binary32 result exactly after rounding each decimal coefficient to nearest.

Whether every entry of a fixed-size vector is finite.

Instances For
    def NN.Verification.Cert.NodeReplay.finiteMatrix (rows cols : ℕ) (A : Fin rows → Fin cols → Float) :

    Whether every entry of a fixed-size matrix is finite.

    Instances For

      Whether outer contains inner componentwise.

      This deliberately has no tolerance after decimal decoding. The decoded lower endpoint may be farther down and the upper endpoint farther up, but neither may lie inward of the recomputed box.

      Instances For

        Proved local replay #

        The diagnostic node checkers below replay bounds incrementally so that they can report the first bad node. The final acceptance decision also runs this pure check against the complete imported certificate. Its soundness theorem supplies exactly the CrownCertLocalOK hypothesis expected by the graph-level CROWN theorem.

        Check that every affine entry is exactly the result of applying step to the imported certificate.

        This is intentionally narrower than the complete certificate checker: parsing, IBP containment, shape checks, and domain checks remain separate executable obligations. This predicate is the local-replay component whose proposition-level meaning is CrownCertLocalOK.

        Instances For

          Read a length-dim JSON vector into binary32, rounding each exact decimal once with mode. Callers validate the JSON entries through host binary64 first. This conversion itself does not check finiteness after rounding into binary32, whose smaller range can overflow.

          Instances For

            Parse a flat interval box (two arrays of floats) from JSON.

            Each decimal endpoint is rounded once into binary32: lower endpoints toward -∞ and upper endpoints toward +∞. The parsed box is therefore the smallest binary32 box containing the decimal box the artifact states. Containment is then checked exactly on binary32 values, so a decimal endpoint that lies inward of Lean's endpoint by less than one binary32 ulp is read as Lean's value. Serializations that print the shortest round-trip decimal of each endpoint still check.

            Instances For

              Parse an optional α vector for α-CROWN ReLU relaxations.

              The soundness theorem for the lower ReLU relaxation assumes every α component is in [0, 1]. We enforce that contract at the JSON boundary, so a malformed external certificate cannot be accepted by executable checking while relying on proof hypotheses that are false. Each entry is rounded once to the nearest binary32 value; rounding is monotone and 0 and 1 are exact, so the range survives the conversion.

              Instances For

                Parse flattened affine bounds (lower/upper) from JSON.

                The affine transcript must equal Lean's binary32 replay bit for bit, so each decimal coefficient is read as the binary32 value nearest to it, with a single rounding from the exact decimal.

                Instances For

                  Parse one JSON entry per graph node. The array must have exactly g.nodes.size entries; each entry is parsed together with its node so entry parsers can use the node's output dimension.

                  Instances For

                    A node-wise CROWN certificate: the affine context, the interval and affine bounds per node, the optional α vectors of the ReLU lower relaxations, and optional ReLU phases.

                    Instances For

                      An integer from JSON, as a number or a string.

                      Instances For

                        One node's ReLU phases from JSON: null, or dim entries each -1, 0 or 1.

                        Instances For

                          Parse a CROWN node certificate.

                          The producer may omit "alpha" and "phases"; then no node has a custom α vector or a phase. The field "beta", the former name of "phases", is rejected rather than ignored, so an older certificate cannot silently lose its phases. Whenever α is present, parseAlphaVec? enforces the [0,1] side condition required by the ReLU relaxation proof.

                          Instances For

                            Check that an optional per-node certificate array contains all parents of node id.

                            Instances For

                              Check that binary elementwise parent boxes have the same flattened size as each other and as the node output. This closes the hole where a malformed certificate could make the runtime helper use the left box on a dimension mismatch.

                              Instances For

                                Domain and shape preconditions that must hold before a node-wise certificate checker replays a bound step. These executable checks mirror the side conditions that the mathematical rules need.

                                Instances For