TorchLean API

NN.Examples.Functional.Transcendentals

Differentiate three scalar functions #

Run lake exe torchlean transcendentals to compare autograd with hand-computed derivatives:

All three are evaluated at x = 0.5 using Float and absolute tolerance 1e-6. Each check also rejects a named wrong answer. In particular, the last one distinguishes a missing minus sign from rounding error. Every check should print PASS or PASS-NEG; a mismatch exits with an error. No dataset or GPU is needed.

expProofSurface and expBackward_eq_adjoint_fderiv give the separate real-arithmetic theorem. The executable comparisons test the Float tape on these inputs; they do not prove its native implementation or establish a derivative at every input. Read expNegativeTwoFn, then gradAt, then checkAll for the application flow.

Proof objects and runtime checks #

The theorem-backed real-valued exp op used by the proof layer.

This is the actual proof layer object: it packages the forward op, its JVP, a Fréchet-derivative candidate, and the theorem that the JVP is the true derivative. The runtime checks below exercise the executable Float tape; this declaration points to the corresponding real-valued theorem.

Instances For

    For scalar exp over , the proved backward rule is the adjoint of the Fréchet derivative.

    This is the theorem-level statement that the executable regression check is meant to complement.

    Functions under test (written once; gradients come from autograd) #

    $f(x)=e^{-2x}$; its derivative needs both the factor two and the minus sign.

    Instances For

      $f(x)=3x+1$ via the scalar-affine op.

      Instances For

        Float checks #

        Absolute-tolerance float compare.

        Instances For
          def NN.Examples.Functional.Transcendentals.expectGrad (name : String) (got expected : Float) (tol : Float := 1e-6) :

          Positive control: name's autograd gradient is approximately equal to the expected value; throws on mismatch.

          Instances For
            def NN.Examples.Functional.Transcendentals.expectNot (name : String) (got wrong : Float) (tol : Float := 1e-6) :

            Negative control: the gradient must not equal wrong; throws if it does.

            Instances For

              Differentiate a scalar→scalar Fn at a Float point, returning the gradient.

              Instances For

                Compare each derivative with its analytic value and reject a plausible wrong value.

                The positive checks establish agreement at the sampled point; the negative controls show that those points and tolerances distinguish the particular mistakes named below.

                Instances For

                  Command-line help for the transcendental autograd checks.

                  Instances For