Documentation

LeanMlir.Proofs.Nets.ResNet.ResNet34

Toward real ResNet-34 — the deep-block chain (Chapter 5 Milestone B4) #

A real ResNet-34 stacks 16 basic blocks in four stages (3+4+6+3). Within a stage every block is a self-map Vec n → Vec n (same channel count) but with its own weights — so it is a composition of a list of distinct same-type maps, not an iterate of one map.

This file proves the generic enabler: if every map in a list is differentiable and has a VJP, their composition (chainComp) does too — by induction chaining vjp_comp. That turns "16 blocks deep" into a List.length, no per-block boilerplate. The full ResNet-34 forward (strided proj blocks via flatConvStride2

Closes under [propext, Classical.choice, Quot.sound].

noncomputable def Proofs.chainComp {n : } (fs : List (Vec nVec n)) :
Vec nVec n

Compose a list of self-maps left-to-right as data flows: chainComp [f₁,…,fₖ] = f₁ ∘ … ∘ fₖ (the last list element runs first, i.e. is the deepest). A ResNet stage is chainComp of its blocks.

Equations
Instances For
    @[simp]
    theorem Proofs.chainComp_cons {n : } (f : Vec nVec n) (fs : List (Vec nVec n)) :
    chainComp (f :: fs) = f chainComp fs
    theorem Proofs.chainComp_differentiable {n : } (fs : List (Vec nVec n)) (hdiff : ffs, Differentiable f) :

    A chain of differentiable maps is differentiable.

    noncomputable def Proofs.vjp_chain {n : } (fs : List (Vec nVec n)) (hdiff : ffs, Differentiable f) (hvjp : (f : Vec nVec n) → f fsHasVJP f) :

    Deep-chain VJP. A composition of a list of differentiable maps that each have a VJP has a VJP — the backward runs each block's backward in reverse order. By induction chaining vjp_comp; the structural heart of a deep ResNet stage (k distinct-weight basic blocks).

    Equations
    Instances For
      theorem Proofs.vjp_chain_correct {n : } (fs : List (Vec nVec n)) (hdiff : ffs, Differentiable f) (hvjp : (f : Vec nVec n) → f fsHasVJP f) (x dy : Vec n) (i : Fin n) :
      (vjp_chain fs hdiff hvjp).backward x dy i = j : Fin n, pdiv (chainComp fs) x i j * dy j

      Deep-chain VJP correctness (ℝ-headline): the chained backward equals the pdiv-contracted Jacobian of the whole composition.

      def Proofs.ChainData {n : } (x : Vec n) :
      List (Vec nVec n)Type

      Recursive hypothesis bundle for a chain of HasVJPAt blocks: each block is DifferentiableAt and HasVJPAt at its running activation — the point chainComp rest x feeding it (the deeper blocks run first). Residual identity blocks are only HasVJPAt at smooth points, so the chain must thread the point, not assume global differentiability.

      Equations
      Instances For
        noncomputable def Proofs.chain_vjp_diff_at {n : } (x : Vec n) (fs : List (Vec nVec n)) :

        The chain at a point both has a VJP and is differentiable there, from the per-block ChainData. The companion DifferentiableAt is carried alongside so the recursion can feed the inner-composition differentiability into each vjp_comp_at / DifferentiableAt.comp.

        Equations
        Instances For
          noncomputable def Proofs.vjp_chain_at {n : } (x : Vec n) (fs : List (Vec nVec n)) (hdata : ChainData x fs) :

          Deep-block chain VJP at a smooth point. A composition of conditional (HasVJPAt) blocks — e.g. the k identity residual blocks of a ResNet stage — has a VJP at x, given each block is differentiable + has a VJP at its running activation (ChainData). The _at peer of vjp_chain.

          Equations
          Instances For
            theorem Proofs.vjp_chain_at_correct {n : } (x : Vec n) (fs : List (Vec nVec n)) (hdata : ChainData x fs) (dy : Vec n) (i : Fin n) :
            (vjp_chain_at x fs hdata).backward dy i = j : Fin n, pdiv (chainComp fs) x i j * dy j

            Deep-chain-at VJP correctness (ℝ-headline): the chained backward at x equals the pdiv-Jacobian of the composition at x.

            noncomputable def Proofs.resStage_has_vjp_at {m n : } (down : Vec mVec n) (ids : List (Vec nVec n)) (x : Vec m) (hdown_diff : DifferentiableAt down x) (hdown : HasVJPAt down x) (hids : ChainData (down x) ids) :
            HasVJPAt (chainComp ids down) x

            A full ResNet stage has a VJP at a point. A stage is a downsample block down : Vec m → Vec n (channel/spatial change — rblkPStrided, or for the first stage the identity / stem-fed input) followed by a chain of k identity residual blocks chainComp ids : Vec n → Vec n. VJPAt by one vjp_comp_at gluing the downsample to the (deep-chained) identity blocks. The reusable composition pattern for assembling ResNet-34's four stages.

            Equations
            Instances For
              theorem Proofs.resStage_has_vjp_at_correct {m n : } (down : Vec mVec n) (ids : List (Vec nVec n)) (x : Vec m) (hdown_diff : DifferentiableAt down x) (hdown : HasVJPAt down x) (hids : ChainData (down x) ids) (dy : Vec n) (i : Fin m) :
              (resStage_has_vjp_at down ids x hdown_diff hdown hids).backward dy i = j : Fin n, pdiv (chainComp ids down) x i j * dy j

              ResNet-stage VJP correctness (ℝ-headline): the stage's backward equals the pdiv-Jacobian of (identity-block chain) ∘ downsample at x.

              noncomputable def Proofs.vjp_comp_diff_at {m n p : } (f : Vec mVec n) (g : Vec nVec p) (x : Vec m) (hf : HasVJPAt f x ×' DifferentiableAt f x) (hg : HasVJPAt g (f x) ×' DifferentiableAt g (f x)) :

              Compose two HasVJPAt-with-DifferentiableAt pairs (carried as PProd so the DifferentiableAt Prop is allowed). The fold step for the whole net.

              Equations
              Instances For
                noncomputable def Proofs.resnet34_has_vjp_at {s0 s1 s2 s3 s4 s5 s6 s7 : } (stem : Vec s0Vec s1) (mp : Vec s1Vec s2) (ids1 : List (Vec s2Vec s2)) (down2 : Vec s2Vec s3) (ids2 : List (Vec s3Vec s3)) (down3 : Vec s3Vec s4) (ids3 : List (Vec s4Vec s4)) (down4 : Vec s4Vec s5) (ids4 : List (Vec s5Vec s5)) (gap : Vec s5Vec s6) (dense : Vec s6Vec s7) (x : Vec s0) (hstem : HasVJPAt stem x ×' DifferentiableAt stem x) (hmp : HasVJPAt mp (stem x) ×' DifferentiableAt mp (stem x)) (hids1 : ChainData (mp (stem x)) ids1) (hdown2 : HasVJPAt down2 (chainComp ids1 (mp (stem x))) ×' DifferentiableAt down2 (chainComp ids1 (mp (stem x)))) (hids2 : ChainData (down2 (chainComp ids1 (mp (stem x)))) ids2) (hdown3 : HasVJPAt down3 (chainComp ids2 (down2 (chainComp ids1 (mp (stem x))))) ×' DifferentiableAt down3 (chainComp ids2 (down2 (chainComp ids1 (mp (stem x)))))) (hids3 : ChainData (down3 (chainComp ids2 (down2 (chainComp ids1 (mp (stem x)))))) ids3) (hdown4 : HasVJPAt down4 (chainComp ids3 (down3 (chainComp ids2 (down2 (chainComp ids1 (mp (stem x))))))) ×' DifferentiableAt down4 (chainComp ids3 (down3 (chainComp ids2 (down2 (chainComp ids1 (mp (stem x)))))))) (hids4 : ChainData (down4 (chainComp ids3 (down3 (chainComp ids2 (down2 (chainComp ids1 (mp (stem x)))))))) ids4) (hgap : HasVJPAt gap (chainComp ids4 (down4 (chainComp ids3 (down3 (chainComp ids2 (down2 (chainComp ids1 (mp (stem x))))))))) ×' DifferentiableAt gap (chainComp ids4 (down4 (chainComp ids3 (down3 (chainComp ids2 (down2 (chainComp ids1 (mp (stem x)))))))))) (hdense : HasVJPAt dense (gap (chainComp ids4 (down4 (chainComp ids3 (down3 (chainComp ids2 (down2 (chainComp ids1 (mp (stem x)))))))))) ×' DifferentiableAt dense (gap (chainComp ids4 (down4 (chainComp ids3 (down3 (chainComp ids2 (down2 (chainComp ids1 (mp (stem x))))))))))) :
                HasVJPAt (dense gap chainComp ids4 down4 chainComp ids3 down3 chainComp ids2 down2 chainComp ids1 mp stem) x

                Whole-network ResNet-34 VJP. The conditional VJP of a real ResNet-34-shaped network at an input x:

                dense ∘ GAP ∘ stage₄ ∘ stage₃ ∘ stage₂ ∘ stage₁ ∘ maxpool ∘ stem

                with stageᵢ = (identity-block chain) ∘ downsampleᵢ for the three downsampling stages (the 3+4+6+3 = 16 basic blocks live in the idsᵢ lists + the three downᵢ blocks; instantiate down/ids/stem/gap/dense with the verified convBnReluStrided/rblkPStrided/rblk/globalAvgPoolFlat/dense and maxPoolFlat). Parametric over the component functions and their per-component VJP+differentiability witnesses at the running activations — so depth is a List.length, not 100 explicit weight arguments. Folded from the verified vjp_comp_at / vjp_chain_at (ChainData threads each block's smooth point).

                This is the structural analogue of cnn_has_vjp_at scaled to 34 layers; the discharge of the smoothness/no-tie hypotheses for a concrete instance (à la CnnConcrete) plus per-channel BN and the GPU render remain.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  noncomputable def Proofs.convBnStrided_has_vjp {ic oc h w kH kW : } (W : Kernel4 oc ic kH kW) (b : Vec oc) (ε γ β : ) ( : 0 < ε) :
                  HasVJP (bnForward (oc * h * w) ε γ β flatConvStride2 W b)

                  conv(stride-2) → bn block VJP (no ReLU), everywhere. The strided peer of convBn_has_vjp: flatConvStride2 then bnForward, both differentiable everywhere, so a global HasVJP. The downsampling body of a stage-start block and its strided 1×1 projection skip.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    theorem Proofs.convBnStrided_differentiable {ic oc h w kH kW : } (W : Kernel4 oc ic kH kW) (b : Vec oc) (ε γ β : ) ( : 0 < ε) :

                    conv(stride-2) → bn is differentiable everywhere.

                    noncomputable def Proofs.convBnReluStrided_has_vjp_at {ic oc h w kH kW : } (W : Kernel4 oc ic kH kW) (b : Vec oc) (ε γ β : ) ( : 0 < ε) (v : Vec (ic * (2 * h) * (2 * w))) (h_smooth : ∀ (k : Fin (oc * h * w)), bnForward (oc * h * w) ε γ β (flatConvStride2 W b v) k 0) :
                    HasVJPAt (relu (oc * h * w) bnForward (oc * h * w) ε γ β flatConvStride2 W b) v

                    conv(stride-2) → bn → relu block VJP at a smooth point. The strided peer of convBnRelu_has_vjp_at (the workhorse opening each downsampling stage): two vjp_comp_at, with flatConvStride2_has_vjp for the conv and the ReLU smoothness hypothesis h_smooth (no post-BN activation hits the kink).

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      theorem Proofs.convBnReluStrided_has_vjp_at_correct {ic oc h w kH kW : } (W : Kernel4 oc ic kH kW) (b : Vec oc) (ε γ β : ) ( : 0 < ε) (v : Vec (ic * (2 * h) * (2 * w))) (h_smooth : ∀ (k : Fin (oc * h * w)), bnForward (oc * h * w) ε γ β (flatConvStride2 W b v) k 0) (dy : Vec (oc * h * w)) (i : Fin (ic * (2 * h) * (2 * w))) :
                      (convBnReluStrided_has_vjp_at W b ε γ β v h_smooth).backward dy i = j : Fin (oc * h * w), pdiv (relu (oc * h * w) bnForward (oc * h * w) ε γ β flatConvStride2 W b) v i j * dy j

                      Strided block VJP correctness (ℝ-headline): the strided downsampling block's backward equals the pdiv-Jacobian of relu ∘ bn ∘ conv_stride2.

                      noncomputable def Proofs.resblock_bodyStrided_has_vjp_at {ic oc h w kH₁ kW₁ kH₂ kW₂ : } (W₁ : Kernel4 oc ic kH₁ kW₁) (b₁ : Vec oc) (W₂ : Kernel4 oc oc kH₂ kW₂) (b₂ : Vec oc) (ε₁ γ₁ β₁ ε₂ γ₂ β₂ : ) (hε₁ : 0 < ε₁) (hε₂ : 0 < ε₂) (v : Vec (ic * (2 * h) * (2 * w))) (h_smooth₁ : ∀ (k : Fin (oc * h * w)), bnForward (oc * h * w) ε₁ γ₁ β₁ (flatConvStride2 W₁ b₁ v) k 0) :
                      HasVJPAt ((bnForward (oc * h * w) ε₂ γ₂ β₂ flatConv W₂ b₂) relu (oc * h * w) bnForward (oc * h * w) ε₁ γ₁ β₁ flatConvStride2 W₁ b₁) v

                      Strided basic-block body VJP F = convBn₂(stride 1) ∘ convBnRelu₁(stride 2) (channels ic → oc, spatial 2h×2w → h×w). The strided peer of resblock_body_has_vjp_at: inner downsampling conv→bn→relu (needs h_smooth₁), outer stride-1 conv→bn (everywhere); two vjp_comp_at.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        theorem Proofs.resblock_bodyStrided_differentiableAt {ic oc h w kH₁ kW₁ kH₂ kW₂ : } (W₁ : Kernel4 oc ic kH₁ kW₁) (b₁ : Vec oc) (W₂ : Kernel4 oc oc kH₂ kW₂) (b₂ : Vec oc) (ε₁ γ₁ β₁ ε₂ γ₂ β₂ : ) (hε₁ : 0 < ε₁) (hε₂ : 0 < ε₂) (v : Vec (ic * (2 * h) * (2 * w))) (h_smooth₁ : ∀ (k : Fin (oc * h * w)), bnForward (oc * h * w) ε₁ γ₁ β₁ (flatConvStride2 W₁ b₁ v) k 0) :
                        DifferentiableAt ((bnForward (oc * h * w) ε₂ γ₂ β₂ flatConv W₂ b₂) relu (oc * h * w) bnForward (oc * h * w) ε₁ γ₁ β₁ flatConvStride2 W₁ b₁) v

                        Strided basic-block body is DifferentiableAt at a smooth point.

                        noncomputable def Proofs.rblkPStrided_has_vjp_at {ic oc h w kH₁ kW₁ kH₂ kW₂ kHp kWp : } (W₁ : Kernel4 oc ic kH₁ kW₁) (b₁ : Vec oc) (W₂ : Kernel4 oc oc kH₂ kW₂) (b₂ : Vec oc) (Wp : Kernel4 oc ic kHp kWp) (bp : Vec oc) (ε₁ γ₁ β₁ ε₂ γ₂ β₂ εp γp βp : ) (hε₁ : 0 < ε₁) (hε₂ : 0 < ε₂) (hεp : 0 < εp) (v : Vec (ic * (2 * h) * (2 * w))) (h_smooth₁ : ∀ (k : Fin (oc * h * w)), bnForward (oc * h * w) ε₁ γ₁ β₁ (flatConvStride2 W₁ b₁ v) k 0) (h_smooth_out : ∀ (k : Fin (oc * h * w)), (bnForward (oc * h * w) εp γp βp flatConvStride2 Wp bp) v k + ((bnForward (oc * h * w) ε₂ γ₂ β₂ flatConv W₂ b₂) relu (oc * h * w) bnForward (oc * h * w) ε₁ γ₁ β₁ flatConvStride2 W₁ b₁) v k 0) :
                        HasVJPAt (relu (oc * h * w) residualProj (bnForward (oc * h * w) εp γp βp flatConvStride2 Wp bp) ((bnForward (oc * h * w) ε₂ γ₂ β₂ flatConv W₂ b₂) relu (oc * h * w) bnForward (oc * h * w) ε₁ γ₁ β₁ flatConvStride2 W₁ b₁)) v

                        Full strided residual-projection block VJP — the block that opens each ResNet-34 downsampling stage: relu( proj(x) + F(x) ) where both the body's first conv W₁ and the 1×1 projection skip Wp are stride-2 (so ic→oc, 2h×2w → h×w), and the body's second conv W₂ is stride-1. Built via residualProj_has_vjp_at (fan-in of the strided proj convBnStrided and the strided body) then a final vjp_comp_at with the post-add ReLU. The strided peer of resblockProj_has_vjp_at.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          theorem Proofs.rblkPStrided_has_vjp_at_correct {ic oc h w kH₁ kW₁ kH₂ kW₂ kHp kWp : } (W₁ : Kernel4 oc ic kH₁ kW₁) (b₁ : Vec oc) (W₂ : Kernel4 oc oc kH₂ kW₂) (b₂ : Vec oc) (Wp : Kernel4 oc ic kHp kWp) (bp : Vec oc) (ε₁ γ₁ β₁ ε₂ γ₂ β₂ εp γp βp : ) (hε₁ : 0 < ε₁) (hε₂ : 0 < ε₂) (hεp : 0 < εp) (v : Vec (ic * (2 * h) * (2 * w))) (h_smooth₁ : ∀ (k : Fin (oc * h * w)), bnForward (oc * h * w) ε₁ γ₁ β₁ (flatConvStride2 W₁ b₁ v) k 0) (h_smooth_out : ∀ (k : Fin (oc * h * w)), (bnForward (oc * h * w) εp γp βp flatConvStride2 Wp bp) v k + ((bnForward (oc * h * w) ε₂ γ₂ β₂ flatConv W₂ b₂) relu (oc * h * w) bnForward (oc * h * w) ε₁ γ₁ β₁ flatConvStride2 W₁ b₁) v k 0) (dy : Vec (oc * h * w)) (i : Fin (ic * (2 * h) * (2 * w))) :
                          (rblkPStrided_has_vjp_at W₁ b₁ W₂ b₂ Wp bp ε₁ γ₁ β₁ ε₂ γ₂ β₂ εp γp βp hε₁ hε₂ hεp v h_smooth₁ h_smooth_out).backward dy i = j : Fin (oc * h * w), pdiv (relu (oc * h * w) residualProj (bnForward (oc * h * w) εp γp βp flatConvStride2 Wp bp) ((bnForward (oc * h * w) ε₂ γ₂ β₂ flatConv W₂ b₂) relu (oc * h * w) bnForward (oc * h * w) ε₁ γ₁ β₁ flatConvStride2 W₁ b₁)) v i j * dy j

                          Strided residual-projection block VJP correctness (ℝ-headline): the downsampling block's backward equals the pdiv-Jacobian of relu ∘ residualProj (strided proj) (strided body).

                          theorem Proofs.bnIstd_pos {n : } (v : Vec n) (ε : ) ( : 0 < ε) :
                          0 < bnIstd n v ε

                          istd = 1/√(σ²+ε) > 0 (variance ≥ 0, ε > 0).

                          theorem Proofs.bnForward_injective {n : } (ε γ β : ) ( : 0 < ε) ( : γ 0) {v : Vec n} (hv : Function.Injective v) :

                          BN of an injective vector is injective when γ ≠ 0: bn is the strictly monotone affine map γ·istd·(· − μ) + β (istd > 0), so it preserves the distinctness needed for the stem's maxpool to have no ties.

                          theorem Proofs.bnXhat_sq_le {n : } (ε : ) ( : 0 < ε) (v : Vec n) (k : Fin n) :
                          bnXhat n ε v k ^ 2 n

                          Each normalized coordinate is bounded: x̂ₖ² ≤ n. Proof: istd² = 1/(σ²+ε) and (vₖ−μ)² ≤ Σⱼ(vⱼ−μ)² = n·σ² ≤ n·(σ²+ε).

                          theorem Proofs.bnForward_lb {n : } (ε γ β : ) ( : 0 < ε) (v : Vec n) (k : Fin n) :
                          β - |γ| * n bnForward n ε γ β v k

                          Dimension-robust BN lower bound β − |γ|·√n ≤ bn, with no mean/variance computation. Lets a large stem β force bn > 0 over a 256-element BN.

                          The strided decimation index is injective (distinct output cells map to distinct even input cells) — so decimateFlat of an injective vector is injective, the keystone of the strided stem's maxpool no-tie discharge.

                          theorem Proofs.decimateFlat_injective (oc h w : ) {x : Vec (oc * (2 * h) * (2 * w))} (hx : Function.Injective x) :

                          decimateFlat of an injective vector is injective.

                          noncomputable def Proofs.Zk :
                          Kernel4 1 1 1 1

                          The single-channel zero 1×1 kernel and zero bias.

                          Equations
                          Instances For
                            noncomputable def Proofs.Zb :
                            Vec 1
                            Equations
                            Instances For
                              theorem Proofs.bnForward_const_eq {n : } (hn : 0 < n) (ε γ β c : ) :
                              (bnForward n ε γ β fun (x : Fin n) => c) = fun (x : Fin n) => β

                              BN of a constant vector is its shift β (local copy of MobileNetV2's bnForward_const, re-proved here to avoid an inter-architecture import).

                              theorem Proofs.flatConv_zero {ic oc h w kH kW : } (W : Kernel4 oc ic kH kW) (b : Vec oc) (hW : ∀ (o : Fin oc) (c : Fin ic) (kh : Fin kH) (kw : Fin kW), W o c kh kw = 0) (hb : ∀ (o : Fin oc), b o = 0) (v : Vec (ic * h * w)) :
                              flatConv W b v = fun (x : Fin (oc * h * w)) => 0

                              A conv with everywhere-zero kernel/bias maps anything to 0 (local copy of MobileNetV2's flatConv_eq_zero).

                              theorem Proofs.relu_nonneg (n : ) (v : Vec n) (k : Fin n) :
                              0 relu n v k

                              ReLU output is always nonnegative.

                              theorem Proofs.relu_const_pos (n : ) (c : ) (hc : 0 < c) :
                              (relu n fun (x : Fin n) => c) = fun (x : Fin n) => c

                              ReLU is the identity on a positive constant vector.

                              theorem Proofs.flatConvStride2_eq_zero {ic oc h w kH kW : } (W : Kernel4 oc ic kH kW) (b : Vec oc) (hW : ∀ (o : Fin oc) (c : Fin ic) (kh : Fin kH) (kw : Fin kW), W o c kh kw = 0) (hb : ∀ (o : Fin oc), b o = 0) (a : Vec (ic * (2 * h) * (2 * w))) :
                              flatConvStride2 W b a = fun (x : Fin (oc * h * w)) => 0

                              A stride-2 conv with zero kernel/bias maps anything to 0 (decimate of 0).

                              noncomputable def Proofs.idBlk (h w : ) :
                              Vec (1 * h * w)Vec (1 * h * w)

                              A single-channel identity residual block with zero weights and BN (ε,γ,β)=(1,0,1): relu( x + bn₂(conv₂(relu(bn₁(conv₁ x)))) ). The body collapses to the constant β₂ = 1, so the block is relu(1 + x).

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For
                                theorem Proofs.idBlk_body_const (h w : ) (hhw : 0 < 1 * h * w) (a : Vec (1 * h * w)) :
                                ((bnForward (1 * h * w) 1 0 1 flatConv Zk Zb) relu (1 * h * w) bnForward (1 * h * w) 1 0 1 flatConv Zk Zb) a = fun (x : Fin (1 * h * w)) => 1

                                The identity block's body is the constant 1 (every conv is zero ⇒ every BN is its shift; the outer zero conv ignores its input).

                                theorem Proofs.idBlk_nonneg (h w : ) (a : Vec (1 * h * w)) (k : Fin (1 * h * w)) :
                                0 idBlk h w a k

                                The identity block output is nonnegative (it is a ReLU).

                                noncomputable def Proofs.idBlk_hasVJPAt (h w : ) (hhw : 0 < 1 * h * w) (a : Vec (1 * h * w)) (ha : ∀ (k : Fin (1 * h * w)), 0 a k) :
                                HasVJPAt (idBlk h w) a

                                The identity block has a VJP at any nonnegative activation: bn₁-input is constant (β₁=1≠0) and the post-add ReLU input is 1 + aₖ > 0 since aₖ ≥ 0.

                                Equations
                                Instances For
                                  theorem Proofs.idBlk_diffAt (h w : ) (hhw : 0 < 1 * h * w) (a : Vec (1 * h * w)) (ha : ∀ (k : Fin (1 * h * w)), 0 a k) :

                                  The identity block is differentiable at any nonnegative activation.

                                  theorem Proofs.chainComp_replicate_idBlk_nonneg (h w : ) (base : Vec (1 * h * w)) (hbase : ∀ (k : Fin (1 * h * w)), 0 base k) (j : ) (k : Fin (1 * h * w)) :
                                  0 chainComp (List.replicate j (idBlk h w)) base k

                                  A chain of identity blocks fed a nonnegative base stays nonnegative (each block is a ReLU; the base only matters for the empty chain).

                                  noncomputable def Proofs.idChainData (h w : ) (hhw : 0 < 1 * h * w) (base : Vec (1 * h * w)) (hbase : ∀ (k : Fin (1 * h * w)), 0 base k) (j : ) :

                                  ChainData for j stacked identity blocks at a nonnegative base — every running activation is a ReLU output (or the base), so each block's smooth-point hypotheses hold.

                                  Equations
                                  Instances For
                                    noncomputable def Proofs.downBlk (h w : ) :
                                    Vec (1 * (2 * h) * (2 * w))Vec (1 * h * w)

                                    A single-channel strided projection block with zero weights and BN (1,0,1): relu( proj(x) + bn₂(conv₂(relu(bn₁(conv₁ x)))) ), both conv₁ and proj stride-2. Body and projection both collapse to the constant 1, so the post-add ReLU input is 1 + 1 = 2 everywhere — unconditional (no activation-sign assumption).

                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For
                                      theorem Proofs.downBlk_proj_const (h w : ) (hhw : 0 < 1 * h * w) (a : Vec (1 * (2 * h) * (2 * w))) :
                                      (bnForward (1 * h * w) 1 0 1 flatConvStride2 Zk Zb) a = fun (x : Fin (1 * h * w)) => 1

                                      The strided block's projection path collapses to the constant 1.

                                      theorem Proofs.downBlk_body_const (h w : ) (hhw : 0 < 1 * h * w) (a : Vec (1 * (2 * h) * (2 * w))) :
                                      ((bnForward (1 * h * w) 1 0 1 flatConv Zk Zb) relu (1 * h * w) bnForward (1 * h * w) 1 0 1 flatConvStride2 Zk Zb) a = fun (x : Fin (1 * h * w)) => 1

                                      The strided block's residual body collapses to the constant 1.

                                      theorem Proofs.downBlk_nonneg (h w : ) (a : Vec (1 * (2 * h) * (2 * w))) (k : Fin (1 * h * w)) :
                                      0 downBlk h w a k

                                      The strided block output is nonnegative (a ReLU).

                                      noncomputable def Proofs.downBlk_hasVJPAt (h w : ) (hhw : 0 < 1 * h * w) (a : Vec (1 * (2 * h) * (2 * w))) :

                                      The strided block has a VJP at every point (smoothness is unconditional: both paths are constant 1, so the post-add ReLU input is 2 ≠ 0).

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For
                                        theorem Proofs.downBlk_diffAt (h w : ) (hhw : 0 < 1 * h * w) (a : Vec (1 * (2 * h) * (2 * w))) :

                                        The strided block is differentiable at every point.

                                        noncomputable def Proofs.ResNet34Concrete.Ws :
                                        Kernel4 1 1 1 1

                                        Stem: a 1×1 identity conv (so flatConvStride2 collapses to decimation), BN (ε,γ,β) = (1,1,20), ReLU. β = 20 > √256 forces bn > 0 (bnForward_lb), so ReLU is the identity and the stem output stays injective — the maxpool no-tie.

                                        Equations
                                        Instances For
                                          noncomputable def Proofs.ResNet34Concrete.bs :
                                          Vec 1
                                          Equations
                                          Instances For
                                            noncomputable def Proofs.ResNet34Concrete.X :
                                            Vec (1 * (2 * 16) * (2 * 16))

                                            Positional (hence injective) input: X i = i.

                                            Equations
                                            Instances For
                                              noncomputable def Proofs.ResNet34Concrete.Wd :
                                              Mat 1 2
                                              Equations
                                              Instances For
                                                noncomputable def Proofs.ResNet34Concrete.bd :
                                                Vec 2
                                                Equations
                                                Instances For
                                                  noncomputable def Proofs.ResNet34Concrete.stem :
                                                  Vec (1 * (2 * 16) * (2 * 16))Vec (1 * 16 * 16)

                                                  The stem relu ∘ bn ∘ conv_stride2 at 1ch, 16×16 output.

                                                  Equations
                                                  Instances For

                                                    The 1×1 identity stem conv is the identity on the flattened input.

                                                    Stride-2 identity conv = decimation.

                                                    theorem Proofs.ResNet34Concrete.stem_bn_pos (k : Fin (1 * 16 * 16)) :
                                                    0 < bnForward (1 * 16 * 16) 1 1 20 (flatConvStride2 Ws bs X) k

                                                    The stem's BN output is strictly positive: bn ≥ 20 − √256 = 4 > 0.

                                                    theorem Proofs.ResNet34Concrete.stem_pos (k : Fin (1 * 16 * 16)) :
                                                    0 < stem X k

                                                    Hence the whole stem output is strictly positive (ReLU = identity).

                                                    The stem output is injective: bn of the injective decimated input is injective (bnForward_injective, γ = 1 ≠ 0) and the ReLU is the identity (stem_pos).

                                                    The maxpool input (= stem X) is positionally injective ⇒ MaxPool2Smooth.

                                                    theorem Proofs.ResNet34Concrete.mp_stem_pos (k : Fin (1 * 8 * 8)) :
                                                    0 < maxPoolFlat 1 8 8 (stem X) k

                                                    The maxpool output is strictly positive (max of positive stem outputs).

                                                    The maxpool point bridge: flatten ∘ unflatten = id at the stem output.

                                                    Maxpool VJP at the stem output (no ties via stem_maxpool_smooth).

                                                    Equations
                                                    • One or more equations did not get rendered due to their size.
                                                    Instances For

                                                      Maxpool differentiability at the stem output.

                                                      noncomputable def Proofs.ResNet34Concrete.ids1 :
                                                      List (Vec (1 * 8 * 8)Vec (1 * 8 * 8))

                                                      ResNet-34's four stages: 3 + 4 + 6 + 3 = 16 identity blocks.

                                                      Equations
                                                      Instances For
                                                        noncomputable def Proofs.ResNet34Concrete.ids2 :
                                                        List (Vec (1 * 4 * 4)Vec (1 * 4 * 4))
                                                        Equations
                                                        Instances For
                                                          noncomputable def Proofs.ResNet34Concrete.ids3 :
                                                          List (Vec (1 * 2 * 2)Vec (1 * 2 * 2))
                                                          Equations
                                                          Instances For
                                                            noncomputable def Proofs.ResNet34Concrete.ids4 :
                                                            List (Vec (1 * 1 * 1)Vec (1 * 1 * 1))
                                                            Equations
                                                            Instances For
                                                              noncomputable def Proofs.ResNet34Concrete.fwd :
                                                              Vec (1 * (2 * 16) * (2 * 16))Vec 2

                                                              The concrete whole-network forward map: dense ∘ gap ∘ (stage₄…₁) ∘ maxpool ∘ stem, a real 34-layer ResNet (strided stem + 3 strided downsamplers + 16 identity blocks + GAP + dense) at 1 channel / 32×32.

                                                              Equations
                                                              • One or more equations did not get rendered due to their size.
                                                              Instances For

                                                                Whole-network VJP for a concrete ResNet-34 — every smoothness/no-tie hypothesis of resnet34_has_vjp_at discharged. The strided identity stem yields distinct positive BN outputs (so the maxpool has no ties via stem_maxpool_smooth); every residual block uses zero weights, so its body is the constant 1 (bnForward_const_eq) and the post-add ReLU input is 1 + activation > 0 (identity blocks, activation ≥ 0) or 2 (downsamplers).

                                                                Equations
                                                                • One or more equations did not get rendered due to their size.
                                                                Instances For
                                                                  theorem Proofs.ResNet34Concrete.resnet34Concrete_has_vjp_correct (dy : Vec 2) (i : Fin (1 * (2 * 16) * (2 * 16))) :
                                                                  resnet34Concrete_has_vjp_at.backward dy i = j : Fin 2, pdiv fwd X i j * dy j

                                                                  Public unconditional correctness theorem — the concrete ResNet-34's backward equals the pdiv-Jacobian VJP, no hypotheses. The ResNet-34 peer of CnnConcrete.cnnConcrete_has_vjp_correct.