Documentation

LeanCert.Engine.Optimization.Gradient

Gradient Interval Computation for Optimization #

This file provides functions to compute interval bounds on the gradient ∇f(B) of an expression over a box B. This is used for monotonicity-based pruning in branch-and-bound global optimization.

Main definitions #

Design #

The gradient is computed by running forward-mode AD (from AD.lean) for each coordinate direction. The result is a list of intervals, one per variable.

Monotonicity pruning: If ∂f/∂xᵢ > 0 on the entire box B, then f is minimized when xᵢ = B[i].lo. We can shrink the box in that dimension to a point.

Gradient computation #

Compute the gradient interval: bounds on each partial derivative over a box. Returns a list of intervals, where the i-th interval contains ∂f/∂xᵢ for all x ∈ B.

Equations
Instances For

    Compute gradient for n variables (explicit dimension)

    Equations
    Instances For

      Computable versions #

      Create dual environment for differentiating with respect to variable idx (computable). Active variable gets der = 1, passive variables get der = 0.

      Equations
      Instances For

        Evaluate with derivative with respect to variable idx (computable version)

        Equations
        Instances For

          Computable derivative interval for multi-variable expressions. Computes the interval containing ∂f/∂xᵢ over the box.

          Equations
          Instances For

            Computable version of gradient interval for Core expressions. This can be used with native_decide for verified optimization.

            Equations
            Instances For

              Sign classification #

              Classification of an interval's sign

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

                  Classify the sign of an interval

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

                    Monotonicity predicates #

                    Pruning queries #

                    Can we prune coordinate i to its low endpoint for minimization? True if ∂f/∂xᵢ > 0 on B (f is increasing in xᵢ, so min is at lo).

                    Equations
                    Instances For

                      Can we prune coordinate i to its high endpoint for minimization? True if ∂f/∂xᵢ < 0 on B (f is decreasing in xᵢ, so min is at hi).

                      Equations
                      Instances For

                        Prune a box for minimization by fixing monotonic coordinates. Returns a (potentially smaller) box and a list of fixed coordinates.

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

                          Correctness theorems #

                          theorem LeanCert.Engine.Optimization.gradientInterval_correct (e : Core.Expr) (hsupp : ExprSupported e) (B : Box) (ρ : ) ( : Box.envMem ρ B) (hzero : iList.length B, ρ i = 0) (i : Fin (List.length B)) :
                          deriv (e.evalAlong ρ i) (ρ i) (gradientIntervalN e B (List.length B))[i]?.getD default

                          The computed gradient interval contains the true partial derivatives. This follows from evalDual_der_correct_idx in AD.lean.

                          theorem LeanCert.Engine.Optimization.pruneToLo_preserves_min (e : Core.Expr) (hsupp : ExprSupported e) (B : Box) (i : Fin (List.length B)) (hgrad : isStrictlyPositive (derivInterval e B.toEnv i) = true) (ρ : ) :
                          Box.envMem ρ B(∀ jList.length B, ρ j = 0)∃ (ρ' : ), Box.envMem ρ' B (∀ jList.length B, ρ' j = 0) ρ' i = B[i].lo Core.Expr.eval ρ' e Core.Expr.eval ρ e

                          If we prune a coordinate to lo because ∂f/∂xᵢ > 0, the minimum is preserved. Informal: if f is increasing in xᵢ on B, then min{f(x) : x ∈ B} = min{f(x) : xᵢ = B[i].lo}. NOTE: Requires ρ j = 0 for j ≥ B.length (standard assumption for box membership).

                          theorem LeanCert.Engine.Optimization.pruneToHi_preserves_min (e : Core.Expr) (hsupp : ExprSupported e) (B : Box) (i : Fin (List.length B)) (hgrad : isStrictlyNegative (derivInterval e B.toEnv i) = true) (ρ : ) :
                          Box.envMem ρ B(∀ jList.length B, ρ j = 0)∃ (ρ' : ), Box.envMem ρ' B (∀ jList.length B, ρ' j = 0) ρ' i = B[i].hi Core.Expr.eval ρ' e Core.Expr.eval ρ e

                          If we prune a coordinate to hi because ∂f/∂xᵢ < 0, the minimum is preserved. NOTE: Requires ρ j = 0 for j ≥ B.length (standard assumption for box membership).

                          Pruned box membership and correctness #

                          Helper: membership in the pruned box implies membership in the original box. The pruned box only shrinks coordinates, never expands them.

                          The pruned box has the same length as the original box

                          theorem LeanCert.Engine.Optimization.pruneBoxForMin_correct (e : Core.Expr) (hsupp : ExprSupported e) (B : Box) :
                          have grad := gradientIntervalN e B (List.length B); have B' := (pruneBoxForMin B grad).1; ∀ (ρ : ), Box.envMem ρ B(∀ iList.length B, ρ i = 0)∃ (ρ' : ), Box.envMem ρ' B' (∀ iList.length B', ρ' i = 0) Core.Expr.eval ρ' e Core.Expr.eval ρ e

                          Main correctness theorem for pruneBoxForMin:

                          After pruning, for any point ρ in the original box B, there exists a point ρ' in the pruned box B' such that f(ρ') ≤ f(ρ).

                          This means the minimum over B can be found by searching only in B'.

                          The proof constructs ρ' by moving each coordinate to its endpoint when the gradient has a definite sign. For each coordinate:

                          • If ∂f/∂xᵢ > 0 on B, move xᵢ to B[i].lo (f is increasing, min at left)
                          • If ∂f/∂xᵢ < 0 on B, move xᵢ to B[i].hi (f is decreasing, min at right)
                          • Otherwise, keep xᵢ = ρ[i]

                          The proof then shows f(ρ') ≤ f(ρ) by induction on coordinates, using the monotonicity lemmas increasing_min_at_left_idx and decreasing_min_at_right_idx.