TorchLean API

NN.MLTheory.CROWN.Proofs.GraphCrownCertSoundness

End-to-end CROWN certificate-checking framework (graph dialect) #

This file provides the reusable end-to-end CROWN certificate-checking framework for graph dialects:

The main theorem is phrased in the standard "if the checker accepts, the bound holds" style.

Relation to auto_LiRPA / alpha-beta-CROWN #

This file is written in a producer/checker style that matches common workflows:

We deliberately state the main theorem schematically in terms of an abstract step function: plain CROWN, α-CROWN, and α/β-CROWN can all share the same end-to-end checker theorem once their transfer rules are proved sound.

Trust boundary for transcendental ops #

IEEE-754 does not standardize libm transcendental functions. For ops like exp, log, tanh, and sigmoid, soundness is therefore expressed as an explicit assumption in the checker predicate. A concrete checker may discharge that assumption with a proved approximation or a validated external interval enclosure, but it may not infer it from a particular libm implementation.

References (code) #

Pointwise interpretation of affine bounds #

A FlatAffineBounds α represents (componentwise) affine lower/upper functions of a fixed flattened input vector. To compare it to a concrete semantic value, we evaluate the affine maps at the chosen input point.

def NN.MLTheory.CROWN.Graph.CrownCertSoundness.affineEvalAt {α : Type} [TorchLean.Storage α] [Context α] {inDim outDim : } (aff : AffineVec α inDim outDim) (x : TorchLean.Tensor α [inDim]) :

Evaluate an affine form A x + c at a concrete input point.

Instances For

    Evaluate affine lower/upper bounds at a concrete input point, yielding a FlatBox.

    Instances For

      Enclosure predicate #

      We reuse Semantics.encloses from NN.MLTheory.CROWN.Graph for componentwise enclosure.

      A flat box encloses a flat vector, once their lengths are known to agree.

      Instances For

        Enclosure of a node value v under an affine bound b, evaluated at the designated input x.

        This is a well-typed variant of EnclosesVec (boundsEvalAt b x) v that guards the dependent dimension b.inDim.

        In a well-formed CROWN certificate, every bound satisfies b.inDim = ctx.inputDim, so the guard branch is the one that matters.

        Instances For

          Local semantic consistency #

          We reuse the real-valued graph dialect evaluator from graph_cert_soundness.lean, but we keep the definition abstract: the CROWN enclosure theorem below holds for any locally-consistent semantic interpretation vals (provided the graph is topologically sorted).

          For IEEE32Exec, a separate evaluator can be plugged in later; the theorem below is stated for any vals satisfying SemLocalOK.

          A CROWN certificate "step function" (checker interface) #

          The runtime runCROWN produces nodewise FlatAffineBounds. For a certificate/checker architecture, we treat the producer as untrusted and phrase correctness as a local step condition:

          This file separates the generic checker theorem from per-operator transfer proofs. In particular, transcendental operators are represented by explicit transfer-soundness assumptions supplied by the backend or checker workflow.

          Safe lookup of a certificate entry, returning none out of bounds.

          Instances For

            crownStepNode? is a parameter to the checker theorem: different certificate formats (plain CROWN, α/β-CROWN, split certificates) can share the same end-to-end theorem as long as they provide a step function and discharge transfer soundness.

            The certificate is exactly what the step rule recomputes at every node: a local fixed point.

            Checking this is cheap and purely syntactic, which is the whole point of shipping a certificate rather than rerunning the bounding algorithm.

            Instances For

              Every graph node has both a certificate entry and a semantic value.

              Instances For

                Transfer-rule soundness assumptions #

                CrownTransferSound is the kernel of the checker theorem: it states that the certificate's local step rule is sound for each supported node kind.

                For transcendental ops, this assumption is where you connect to an oracle model (e.g. Arb).

                Each node's step rule is sound: parents enclosing their values force the node to enclose its own. This is the assumption a certificate format has to discharge to reuse the checker theorem.

                Instances For

                  Checker implies enclosure #

                  If a certificate is locally consistent and the transfer rules are sound, then every certified node encloses the graph value computed at that node.

                  This theorem does not pick a certificate producer or a nonlinear backend. Those details come in through step and CrownTransferSound.

                  theorem NN.MLTheory.CROWN.Graph.CrownCertSoundness.crown_checker_encloses_semantics_match (g : Graph) (ps : ParamStore ) (step : Array (Option (FlatAffineBounds ))Option (FlatAffineBounds )) (cert : Array (Option (FlatAffineBounds ))) (inputs : Std.HashMap CertSoundness.Val) (vals : Array (Option CertSoundness.Val)) (ctx : AffineCtx) (x : TorchLean.Tensor [ctx.inputDim]) (htopo : CertSoundness.TopoSorted g) (_hsem : CertSoundness.SemLocalOK g ps inputs vals) (hcert : CrownCertLocalOK g step cert) (hsound : CrownTransferSound g ps inputs vals ctx x step cert) (id : ) :
                  id < g.nodes.sizematch cert[id]!, vals[id]! with | some b, some v => EnclosesAtInput ctx x b v | x, x_1 => True
                  theorem NN.MLTheory.CROWN.Graph.CrownCertSoundness.crown_checker_encloses_semantics (g : Graph) (ps : ParamStore ) (step : Array (Option (FlatAffineBounds ))Option (FlatAffineBounds )) (cert : Array (Option (FlatAffineBounds ))) (inputs : Std.HashMap CertSoundness.Val) (vals : Array (Option CertSoundness.Val)) (ctx : AffineCtx) (x : TorchLean.Tensor [ctx.inputDim]) (htopo : CertSoundness.TopoSorted g) (hsem : CertSoundness.SemLocalOK g ps inputs vals) (hcert : CrownCertLocalOK g step cert) (hsound : CrownTransferSound g ps inputs vals ctx x step cert) (id : ) :
                  id < g.nodes.size∀ (b : FlatAffineBounds ) (v : CertSoundness.Val), cert[id]! = some bvals[id]! = some vEnclosesAtInput ctx x b v

                  Wherever both a certificate entry and a semantic value are present, the entry encloses the value.

                  This is the partial form of the main theorem: it says nothing about nodes the checker skipped, which is exactly why crown_checker_encloses_all_nodes below also takes a coverage hypothesis.

                  theorem NN.MLTheory.CROWN.Graph.CrownCertSoundness.crown_checker_encloses_all_nodes (g : Graph) (ps : ParamStore ) (step : Array (Option (FlatAffineBounds ))Option (FlatAffineBounds )) (cert : Array (Option (FlatAffineBounds ))) (inputs : Std.HashMap CertSoundness.Val) (vals : Array (Option CertSoundness.Val)) (ctx : AffineCtx) (x : TorchLean.Tensor [ctx.inputDim]) (htopo : CertSoundness.TopoSorted g) (hsem : CertSoundness.SemLocalOK g ps inputs vals) (hcert : CrownCertLocalOK g step cert) (hcoverage : CrownCertCovers g cert vals) (hsound : CrownTransferSound g ps inputs vals ctx x step cert) (id : ) :
                  id < g.nodes.size∃ (b : FlatAffineBounds ) (v : CertSoundness.Val), cert[id]! = some b vals[id]! = some v EnclosesAtInput ctx x b v

                  Complete certificate coverage turns local replay and transfer soundness into an enclosure theorem for every graph node. Unlike the partial match theorem above, this result cannot succeed through a missing certificate entry or missing semantic value.

                  IEEE32Exec specialization #

                  For IEEE32 we still leave the node evaluator to the caller. The caller supplies the evaluator, proves that vals is its trace, and proves that evaluating node id does not read vals[id]!. The floating-point refinement theorem itself lives outside this checker lemma.

                  @[reducible, inline]

                  A flat node value in the binary32 executable semantics.

                  Instances For
                    @[reducible, inline]

                    Type of a caller-supplied binary32 node evaluator: nodes, parameters, inputs, partial trace, node id, and an optional result.

                    Instances For

                      The IEEE32 node evaluator may inspect already-computed values, but not the slot it is supposed to compute.

                      Instances For
                        theorem NN.MLTheory.CROWN.Graph.CrownCertSoundness.crown_checker_encloses_semantics_ieee32exec_match (g : Graph) (_ps : ParamStore (FloatLib.Floats.ExecFloat.Binary 8 23 FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee (FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee.defaultBias 8) IEEE32Val._proof_1 IEEE32Val._proof_2 IEEE32Val._proof_3 IEEE32Val._proof_4)) (step : Array (Option (FlatAffineBounds (FloatLib.Floats.ExecFloat.Binary 8 23 FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee (FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee.defaultBias 8) IEEE32Val._proof_1 IEEE32Val._proof_2 IEEE32Val._proof_3 IEEE32Val._proof_4)))Option (FlatAffineBounds (FloatLib.Floats.ExecFloat.Binary 8 23 FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee (FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee.defaultBias 8) IEEE32Val._proof_1 IEEE32Val._proof_2 IEEE32Val._proof_3 IEEE32Val._proof_4))) (cert : Array (Option (FlatAffineBounds (FloatLib.Floats.ExecFloat.Binary 8 23 FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee (FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee.defaultBias 8) IEEE32Val._proof_1 IEEE32Val._proof_2 IEEE32Val._proof_3 IEEE32Val._proof_4)))) (evalNode? : IEEE32EvalNode?) (inputs : Std.HashMap IEEE32Val) (vals : Array (Option IEEE32Val)) (ctx : AffineCtx) (x : TorchLean.Tensor (FloatLib.Floats.ExecFloat.Binary 8 23 FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee (FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee.defaultBias 8) IEEE32Val._proof_1 IEEE32Val._proof_2 IEEE32Val._proof_3 IEEE32Val._proof_4) [ctx.inputDim]) (htopo : CertSoundness.TopoSorted g) (_hsem : IEEE32SemLocalOK evalNode? g _ps inputs vals) (hcert : CrownCertLocalOK g step cert) (hsound : id < g.nodes.size, (∀ pg.nodes[id]!.parents, match cert[p]!, vals[p]! with | some bp, some vp => EnclosesAtInput ctx x bp vp | x, x_1 => True)match step cert id, vals[id]! with | some b, some v => EnclosesAtInput ctx x b v | x, x_1 => True) (id : ) :
                        id < g.nodes.sizematch cert[id]!, vals[id]! with | some b, some v => EnclosesAtInput ctx x b v | x, x_1 => True

                        Checker-implies-enclosure for ExecFloat.Binary 8 23 certificates, in the partial match form.

                        The proof is a pure topological induction: it only rewrites certificate entries with the step function and passes parent enclosures to hsound. In particular it never compares two ExecFloat.Binary 8 23 values, so no order structure on ExecFloat.Binary 8 23 is assumed; the enclosure predicate itself uses the LE supplied by the Context IEEE32Exec instance, which is not a lawful order because of NaN. Any order reasoning belongs in the transfer proofs discharging hsound.

                        theorem NN.MLTheory.CROWN.Graph.CrownCertSoundness.crown_checker_encloses_semantics_ieee32exec (g : Graph) (ps : ParamStore (FloatLib.Floats.ExecFloat.Binary 8 23 FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee (FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee.defaultBias 8) IEEE32Val._proof_1 IEEE32Val._proof_2 IEEE32Val._proof_3 IEEE32Val._proof_4)) (step : Array (Option (FlatAffineBounds (FloatLib.Floats.ExecFloat.Binary 8 23 FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee (FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee.defaultBias 8) IEEE32Val._proof_1 IEEE32Val._proof_2 IEEE32Val._proof_3 IEEE32Val._proof_4)))Option (FlatAffineBounds (FloatLib.Floats.ExecFloat.Binary 8 23 FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee (FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee.defaultBias 8) IEEE32Val._proof_1 IEEE32Val._proof_2 IEEE32Val._proof_3 IEEE32Val._proof_4))) (cert : Array (Option (FlatAffineBounds (FloatLib.Floats.ExecFloat.Binary 8 23 FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee (FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee.defaultBias 8) IEEE32Val._proof_1 IEEE32Val._proof_2 IEEE32Val._proof_3 IEEE32Val._proof_4)))) (evalNode? : IEEE32EvalNode?) (inputs : Std.HashMap IEEE32Val) (vals : Array (Option IEEE32Val)) (ctx : AffineCtx) (x : TorchLean.Tensor (FloatLib.Floats.ExecFloat.Binary 8 23 FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee (FloatLib.Floats.Formats.BinaryInterchange.FloatFormat.Encoding.ieee.defaultBias 8) IEEE32Val._proof_1 IEEE32Val._proof_2 IEEE32Val._proof_3 IEEE32Val._proof_4) [ctx.inputDim]) (htopo : CertSoundness.TopoSorted g) (hsem : IEEE32SemLocalOK evalNode? g ps inputs vals) (hcert : CrownCertLocalOK g step cert) (hsound : id < g.nodes.size, (∀ pg.nodes[id]!.parents, match cert[p]!, vals[p]! with | some bp, some vp => EnclosesAtInput ctx x bp vp | x, x_1 => True)match step cert id, vals[id]! with | some b, some v => EnclosesAtInput ctx x b v | x, x_1 => True) (id : ) :

                        Checker-implies-enclosure for ExecFloat.Binary 8 23 certificates, quantified over the node ids at which both a certificate entry and a semantic value are present. See crown_checker_encloses_semantics_ieee32exec_match for why no order on ExecFloat.Binary 8 23 is assumed.