TorchLean API

NN.Verification.Builtin.Proved.Syntax

Verified Forward Fragment: Syntax And Evaluation #

The first-order forward language used by the TorchLean verifier bridge, together with its direct value evaluator over the scalar semantics selected by the caller.

@[simp]
theorem NN.Verification.Builtin.Proved.dval_tensor_mk {α : Type} [TorchLean.Storage α] [Context α] {s : Spec.Shape} (t : TorchLean.Tensor α s) :
{ shape := s, tensor := t }.tensor = t

Projecting the tensor from a freshly constructed dynamic value is definitionally exact.

@[simp]

Shape checking succeeds for a dynamic value constructed with the expected shape tag.

Typed indices #

An index into a shape context Γ, carrying a proof that it has shape s.

  • i : Fin Γ.length

    Position in the context.

  • h : Γ.get self.i = s

    Proof that the context entry at i has shape s.

Instances For
    @[simp]
    theorem NN.Verification.Builtin.Proved.Idx.mk_eta {Γ : List Spec.Shape} {s : Spec.Shape} (x : Idx Γ s) :
    { i := x.i, h := } = x

    Eta rule for Idx: rebuilding from projections gives the same index.

    The underlying numeric index of an Idx.

    This is convenient when we store context values in arrays (indexed by Nat) rather than in dependent lists.

    Instances For

      Parameter access #

      def NN.Verification.Builtin.Proved.getParam {α : Type} [TorchLean.Storage α] {paramShapes : List Spec.Shape} {s : Spec.Shape} (params : TorchLean.TensorPack α paramShapes) (idx : Idx paramShapes s) :

      Fetch a parameter tensor from a TensorPack, using a typed index Idx.

      This is the bridge between the parameter context paramShapes and the strongly-typed tensor value returned at shape s.

      Instances For

        First-order SSA nodes #

        @[reducible, inline]

        Evaluation context shape list.

        We always treat the distinguished input as index 0, then append the shapes of previously-produced SSA node outputs (ss).

        Instances For

          Typed evidence for matrix multiplication over an arbitrary shared leading shape.

          Instances For
            def NN.Verification.Builtin.Proved.MatmulOperation.denote {α : Type} [TorchLean.Storage α] [Context α] {leftShape rightShape outShape : Spec.Shape} (op : MatmulOperation leftShape rightShape outShape) (left : TorchLean.Tensor α leftShape) (right : TorchLean.Tensor α rightShape) :
            TorchLean.Tensor α outShape

            Typed denotation of a supported matrix multiplication operation.

            Instances For

              Typed evidence for LayerNorm over a suffix of an arbitrary tensor shape.

              rows × width is an evaluation view obtained by flattening the dimensions before and after axis; it is not a restriction on the rank or layout of the input tensor.

              Instances For

                A well-typed SSA node in the verified forward fragment.

                Each Node can only reference earlier values (via Idx (Ctx inShape ss) _), ensuring the DAG/SSA discipline by construction.

                The constructors match the operator subset for which this file proves lowering correctness into the verifier IR (NN.IR.Graph). Adding a new operator means extending both this syntax and the correctness proof, which keeps the trusted fragment explicit.

                Instances For

                  Forward programs (closed let-chains) #

                  Well-typed first-order programs, represented as a forward “let chain”.

                  The type parameter ss tracks the list of already-produced node output shapes, so every node can only reference earlier values (including the distinguished input at index 0).

                  Instances For
                    @[reducible, inline]
                    abbrev NN.Verification.Builtin.Proved.ForwardProgram (α : Type) [TorchLean.Storage α] (paramShapes : List Spec.Shape) (inShape outShape : Spec.Shape) :

                    A closed program in the proved forward fragment, from inShape to outShape.

                    Instances For

                      Evaluation #

                      Read a dynamic value from the executable context with a user-facing bounds error.

                      Instances For
                        def NN.Verification.Builtin.Proved.getVal {α : Type} [TorchLean.Storage α] [Context α] {inShape : Spec.Shape} {ss : List Spec.Shape} {s : Spec.Shape} (vals : Array (Spec.SomeTensor α)) (idx : Idx (Ctx inShape ss) s) :

                        Read a previously computed dynamic value and cast it back to the statically expected shape.

                        The verified fragment constructs only well-scoped indices, but the executable evaluator stores values in an array, so this check gives a clear error if an implementation bug ever violates the shape discipline.

                        Instances For
                          def NN.Verification.Builtin.Proved.evalNode {α : Type} [TorchLean.Storage α] [Context α] {paramShapes : List Spec.Shape} {inShape : Spec.Shape} {ss : List Spec.Shape} {out : Spec.Shape} (node : Node α paramShapes inShape ss out) (params : TorchLean.TensorPack α paramShapes) (vals : Array (Spec.SomeTensor α)) :

                          Evaluate a single SSA node, given the parameter environment and current value context.

                          This mirrors the IR denotation for the supported operator subset.

                          Instances For
                            def NN.Verification.Builtin.Proved.evalForwardLetChain {α : Type} [TorchLean.Storage α] [Context α] {paramShapes : List Spec.Shape} {inShape : Spec.Shape} {ss : List Spec.Shape} {out : Spec.Shape} (g : ForwardLetChain α paramShapes inShape ss out) (params : TorchLean.TensorPack α paramShapes) (vals : Array (Spec.SomeTensor α)) :

                            Evaluate a forward let-chain program, threading an array of dynamic values.

                            The vals array stores the input and all previously-computed node outputs, so that node evaluation can do simple array lookups by Idx.id.

                            Instances For
                              def NN.Verification.Builtin.Proved.evalForward {α : Type} [TorchLean.Storage α] [Context α] {paramShapes : List Spec.Shape} {inShape outShape : Spec.Shape} (p : ForwardProgram α paramShapes inShape outShape) (params : TorchLean.TensorPack α paramShapes) (x : TorchLean.Tensor α inShape) :

                              Evaluate a verified forward fragment program.

                              This is the top-level evaluator for ForwardProgram: it initializes the context with the input value and then interprets the SSA let-chain.

                              Instances For