Documentation

ConvexAnalysis.IntervalDerivative

Interval differentiation of arithmetic expressions #

The mean value form, the interval Newton method and the Krawczyk test need enclosures of derivatives or slopes. This file computes them automatically for arithmetic expressions (ConvexAnalysis.ArithExpr): the symbolic partial derivative ArithExpr.pderiv i e is again an arithmetic expression, so its natural interval extension, or any evaluation of it with outward rounding, encloses the partial derivative of e on a box by the fundamental theorem of interval arithmetic. With these derivative enclosures the mean value form encloses the range, interval branch and bound with the mean value form converges, and the interval matrix of the computed partial derivatives of a system encloses its slopes. So the interval Krawczyk test needs no hypothesis besides the computed inclusion; the interval Newton test needs in addition that every matrix of the interval matrix is invertible, and its operator is the exact Newton set, not a computed hull. The Hansen–Sengupta test (ConvexAnalysis.HansenSengupta) computes an enclosure of the Newton set and needs no regularity hypothesis.

Main definitions #

Main statements #

Implementation notes #

References #

Tags #

automatic differentiation, symbolic differentiation, interval arithmetic, derivative enclosure, slope enclosure, mean value form, interval branch and bound, Krawczyk test, interval Newton method

def ConvexAnalysis.ArithExpr.pderiv {ι : Type u_1} [DecidableEq ι] (i : ι) :

The symbolic partial derivative of an expression with respect to the variable x i, by the rules of differentiation: (e₁ e₂)' = e₁' e₂ + e₁ e₂', (e⁻¹)' = -(e' (e⁻¹)²), (exp e)' = e' exp e, (log e)' = e' e⁻¹, (√e)' = e' (2 √e)⁻¹ and (e ^ k)' = e' (k e ^ (k - 1)). No simplification is done, so every subexpression of e and its derivative occur in the result (ArithExpr.isSmoothAt_of_intervalEval_pderiv_eq_some).

Equations
Instances For
    def ConvexAnalysis.ArithExpr.IsSmoothAt {ι : Type u_1} (x : ι → ℝ) :

    e.IsSmoothAt x: every inverse, logarithm and square root in e is applied to a nonzero number at x. This syntactic condition is sufficient for smoothness, not necessary: then the real value of e is smooth near x (ArithExpr.contDiffAt_eval), with the partial derivatives given by ArithExpr.pderiv (ArithExpr.hasFDerivAt_eval), but for example (x - x)⁻¹ is constant and not IsSmoothAt anywhere. The real value uses Mathlib's total functions, which are smooth away from 0 (Real.log x = log |x|, and Real.sqrt x = 0 for x < 0); where e is defined (ArithExpr.IsDefinedAt), the condition says that every square root has a positive argument.

    Equations
    Instances For
      theorem ConvexAnalysis.ArithExpr.contDiffAt_eval {ι : Type u_1} {e : ArithExpr ι} {x : ι → ℝ} [Fintype ι] {n : WithTop ℕ∞} (h : IsSmoothAt x e) :
      ContDiffAt ℝ n (fun (y : ι → ℝ) => eval y e) x

      The real value is smooth where no inverse, logarithm or square root has the argument 0.

      theorem ConvexAnalysis.ArithExpr.hasFDerivAt_eval {ι : Type u_1} {e : ArithExpr ι} {x : ι → ℝ} [DecidableEq ι] [Fintype ι] (h : IsSmoothAt x e) :
      HasFDerivAt (fun (y : ι → ℝ) => eval y e) (∑ i : ι, eval x (pderiv i e) • ContinuousLinearMap.proj i) x

      Correctness of the symbolic derivative: if no inverse, logarithm or square root in e has the argument 0 at x, then the real value of e is differentiable at x, and its derivative is v ↦ ∑ i, ∂ᵢe(x) v i with the partial derivatives ∂ᵢe(x) the values of ArithExpr.pderiv i e.

      theorem ConvexAnalysis.ArithExpr.fderiv_eval_apply_single {ι : Type u_1} {e : ArithExpr ι} {x : ι → ℝ} [DecidableEq ι] [Fintype ι] (h : IsSmoothAt x e) (i : ι) :
      (fderiv ℝ (fun (y : ι → ℝ) => eval y e) x) (Pi.single i 1) = eval x (pderiv i e)

      The partial derivatives of the real value at x are the values of the symbolic partial derivatives, where e is smooth.

      theorem ConvexAnalysis.ArithExpr.hasDerivAt_eval_update {ι : Type u_1} {e : ArithExpr ι} {x : ι → ℝ} [DecidableEq ι] [Fintype ι] (h : IsSmoothAt x e) (i : ι) :
      HasDerivAt (fun (t : ℝ) => eval (Function.update x i t) e) (eval x (pderiv i e)) (x i)

      The partial derivative of e in direction i at x, as the derivative of t ↦ e(x₁, …, t, …, xₙ) at t = x i, is the value of ArithExpr.pderiv i e.

      Derivative enclosures #

      If the natural interval extension of a partial derivative of e is defined on X, then e is smooth at every point of X: ArithExpr.pderiv keeps every subexpression of e, and the interval extensions of the inverses in ArithExpr.pderiv i e exclude the argument 0 of every inverse, logarithm and square root of e.

      If the natural interval extension of a partial derivative of e is defined on X, then every square root in e and in the derivative has an argument bounded away from 0 on X (ArithExpr.SqrtArgPos): the derivative (√u)' = u' (2 √u)⁻¹ is defined only if the interval of u has a positive lower endpoint.

      theorem ConvexAnalysis.ArithExpr.exists_length_intervalEval_pderiv_le {ι : Type u_1} {X₀ : ι → NonemptyInterval ℝ} {G₀ : NonemptyInterval ℝ} {e : ArithExpr ι} {i : ι} [DecidableEq ι] [Fintype ι] (h₀ : intervalEval X₀ (pderiv i e) = some G₀) :
      ∃ (C : ℝ), 0 ≤ C ∧ ∀ X ≤ X₀, ∀ (G : NonemptyInterval ℝ), intervalEval X (pderiv i e) = some G → G.length ≤ C * IntervalArith.width X

      Linear convergence of derivative enclosures: if the natural interval extension of ArithExpr.pderiv i e is defined on X₀, its length on the subboxes X of X₀ is at most C · width X. This is ArithExpr.exists_length_intervalEval_le; its condition on square roots holds by ArithExpr.sqrtArgPos_of_intervalEval_pderiv_eq_some.

      theorem ConvexAnalysis.ArithExpr.fderiv_eval_apply_single_mem {ι : Type u_1} {X : ι → NonemptyInterval ℝ} {G : NonemptyInterval ℝ} {e : ArithExpr ι} {x : ι → ℝ} {i : ι} [DecidableEq ι] [Fintype ι] (h : intervalEval X (pderiv i e) = some G) (hx : x ∈ IntervalArith.box X) :
      (fderiv ℝ (fun (y : ι → ℝ) => eval y e) x) (Pi.single i 1) ∈ G

      Derivative enclosure by interval differentiation: if the natural interval extension G of ArithExpr.pderiv i e is defined on X, then e is differentiable at every point x of the box X, and its partial derivative ∂ᵢe(x) lies in G. This is the fundamental theorem of interval arithmetic (ArithExpr.eval_mem_of_intervalEval_eq_some) for the symbolic derivative, with ArithExpr.fderiv_eval_apply_single. The same intervals are computed by forward-mode automatic differentiation in interval arithmetic, the recursive differentiation of Neumaier, Section 2.2 and [Ral81].

      theorem ConvexAnalysis.ArithExpr.IsRoundedEval.fderiv_eval_apply_single_mem {ι : Type u_1} {X : ι → NonemptyInterval ℝ} {G : NonemptyInterval ℝ} {e : ArithExpr ι} {x : ι → ℝ} {i : ι} [DecidableEq ι] [Fintype ι] (h : IsRoundedEval X (pderiv i e) G) (hx : x ∈ IntervalArith.box X) :
      (fderiv ℝ (fun (y : ι → ℝ) => eval y e) x) (Pi.single i 1) ∈ G

      Derivative enclosure with outward rounding: if G is a rounded evaluation of ArithExpr.pderiv i e on X (ArithExpr.IsRoundedEval, for example an interval computed with dyadic or floating-point endpoints and directed rounding), then the partial derivative ∂ᵢe(x) lies in G for every x in the box X.

      theorem ConvexAnalysis.ArithExpr.IsRoundedEval.isSmoothAt_of_pderiv {ι : Type u_1} {X : ι → NonemptyInterval ℝ} {G : NonemptyInterval ℝ} {e : ArithExpr ι} {x : ι → ℝ} {i : ι} [DecidableEq ι] (h : IsRoundedEval X (pderiv i e) G) (hx : x ∈ IntervalArith.box X) :

      If a rounded evaluation of a partial derivative of e on X exists, then e is smooth at every point of the box X.

      The mean value form with automatic derivative enclosures #

      theorem ConvexAnalysis.ArithExpr.mem_meanValueForm_pderiv {ι : Type u_1} {X : ι → NonemptyInterval ℝ} {e : ArithExpr ι} {x : ι → ℝ} [DecidableEq ι] [Fintype ι] {G : ι → NonemptyInterval ℝ} {c : ι → ℝ} (hG : ∀ (i : ι), IsRoundedEval X (pderiv i e) (G i)) (hc : c ∈ IntervalArith.box X) (hx : x ∈ IntervalArith.box X) :

      The mean value form with interval derivatives encloses the range (Neumaier, Theorem 2.3.3 with derivative enclosures by recursive differentiation, Neumaier, Section 2.2): if the intervals G i are rounded evaluations of the partial derivatives ArithExpr.pderiv i e on X (for example their natural interval extensions, ArithExpr.isRoundedEval_of_intervalEval_eq_some) and c ∈ X, then e(x) ∈ e(c) + ∑ i, G i · (X i - c i) for all x ∈ X. No condition on e itself is needed: the derivative enclosures make e differentiable on X.

      theorem ConvexAnalysis.ArithExpr.exists_meanValueForm_pderiv_approx {ι : Type u_1} {X₀ : ι → NonemptyInterval ℝ} {e : ArithExpr ι} [DecidableEq ι] [Fintype ι] {G₀ : ι → NonemptyInterval ℝ} (h₀ : ∀ (i : ι), intervalEval X₀ (pderiv i e) = some (G₀ i)) :
      ∃ (L : ℝ), ∀ X ≤ X₀, ∀ (G : ι → NonemptyInterval ℝ), (∀ (i : ι), intervalEval X (pderiv i e) = some (G i)) → ∀ c ∈ IntervalArith.box X, (∃ y ∈ IntervalArith.box X, eval y e ≤ (IntervalArith.meanValueForm (eval c e) G X c).toProd.1 + ↑(Fintype.card ι) * L * IntervalArith.width X ^ 2) ∧ ∃ y ∈ IntervalArith.box X, (IntervalArith.meanValueForm (eval c e) G X c).toProd.2 - ↑(Fintype.card ι) * L * IntervalArith.width X ^ 2 ≤ eval y e

      Quadratic convergence of the mean value form with interval derivatives (Neumaier, Corollary 2.3.4 for this choice of derivative enclosures): if the natural interval extensions of the partial derivatives of e are defined on X₀, there is L such that on every subbox X of X₀ both endpoints of the mean value form with the natural interval extensions G i of the partial derivatives on X are within n L (width X)² of values of e on X. The derivative enclosures converge linearly (ArithExpr.exists_length_intervalEval_pderiv_le), with no condition on square roots.

      noncomputable def ConvexAnalysis.ArithExpr.intervalGradient {ι : Type u_1} [DecidableEq ι] (e : ArithExpr ι) (X : ι → NonemptyInterval ℝ) (i : ι) :

      The natural interval extension of the gradient of e on X: the natural interval extension of ArithExpr.pderiv i e, and the junk value [0, 0] where it is undefined. It encloses the partial derivatives of e on X where it is defined (ArithExpr.fderiv_eval_apply_single_mem).

      Equations
      Instances For
        theorem ConvexAnalysis.ArithExpr.intervalEval_pderiv_eq_intervalGradient {ι : Type u_1} {X X₀ : ι → NonemptyInterval ℝ} {G₀ : NonemptyInterval ℝ} {e : ArithExpr ι} {i : ι} [DecidableEq ι] (hX : X ≤ X₀) (h₀ : intervalEval X₀ (pderiv i e) = some G₀) :

        On the subboxes of a box on which they are defined, the natural interval extensions of the partial derivatives are ArithExpr.intervalGradient.

        theorem ConvexAnalysis.BranchAndBound.exists_isMinOn_and_tendsto_meanValue_pderiv {ι : Type u_1} [Fintype ι] [Nonempty ι] [DecidableEq ι] {a b : ι → ℝ} {e : ArithExpr ι} (hab : a ≤ b) {G₀ : ι → NonemptyInterval ℝ} (h₀ : ∀ (i : ι), ArithExpr.intervalEval (IntervalArith.ofCorners a b) (ArithExpr.pderiv i e) = some (G₀ i)) :
        ∃ z ∈ Set.Icc a b, IsMinOn (fun (x : ι → ℝ) => ArithExpr.eval x e) (Set.Icc a b) z ∧ Filter.Tendsto (fun (k : ℕ) => meanValueBound (fun (x : ι → ℝ) => ArithExpr.eval x e) e.intervalGradient a b (meanValueNode (fun (x : ι → ℝ) => ArithExpr.eval x e) e.intervalGradient a b k)) Filter.atTop (nhds (ArithExpr.eval z e)) ∧ Filter.Tendsto (incumbent (fun (x : ι → ℝ) => ArithExpr.eval x e) fun (k : ℕ) => bisectionCenter a b (meanValueNode (fun (x : ι → ℝ) => ArithExpr.eval x e) e.intervalGradient a b k)) Filter.atTop (nhds (ArithExpr.eval z e))

        Convergence of interval branch and bound with the mean value form and automatic derivative enclosures: if the natural interval extensions of the partial derivatives of e are defined on the box Icc a b, then e has a minimizer z on the box, and with the mean value forms built from the natural interval extensions of the partial derivatives on each box (ArithExpr.intervalGradient), the lower bounds of the selected boxes and the incumbent values at their centers tend to e(z). This is ConvexAnalysis.BranchAndBound.exists_isMinOn_and_tendsto_meanValue; its hypotheses hold by ArithExpr.fderiv_eval_apply_single_mem and the linear convergence of the derivative enclosures (ArithExpr.exists_length_intervalEval_pderiv_le).

        Slope enclosures and the Krawczyk test with automatic derivatives #

        theorem ConvexAnalysis.isSlopeEnclosure_of_isRoundedEval_pderiv {ι : Type u_1} [Fintype ι] [DecidableEq ι] {F : ι → ArithExpr ι} {M : ι → ι → NonemptyInterval ℝ} {X : ι → NonemptyInterval ℝ} (hM : ∀ (k j : ι), ArithExpr.IsRoundedEval X (ArithExpr.pderiv j (F k)) (M k j)) :
        IsSlopeEnclosure {A : Matrix ι ι ℝ | ∀ (k j : ι), A k j ∈ M k j} (fun (x : ι → ℝ) (k : ι) => ArithExpr.eval x (F k)) (IntervalArith.box X)

        Slope enclosure by interval differentiation: for a system F : ι → ArithExpr ι (the map x ↦ (F k (x))ₖ), if every M k j is a rounded evaluation on X of the partial derivative ArithExpr.pderiv j (F k) (for example its natural interval extension, ArithExpr.isRoundedEval_of_intervalEval_eq_some), then the interval matrix M encloses the slopes of the map on the box X. This is ConvexAnalysis.isSlopeEnclosure_matrixIcc_of_hasFDerivWithinAt with the Jacobian enclosure of ConvexAnalysis.ArithExpr.IsRoundedEval.fderiv_eval_apply_single_mem (Neumaier, Corollary 5.1.5, with an interval Jacobian computed by recursive differentiation, Neumaier, Section 2.2).

        theorem ConvexAnalysis.continuousOn_of_isRoundedEval_pderiv {ι : Type u_1} [Fintype ι] [DecidableEq ι] {F : ι → ArithExpr ι} {M : ι → ι → NonemptyInterval ℝ} {X : ι → NonemptyInterval ℝ} (hM : ∀ (k j : ι), ArithExpr.IsRoundedEval X (ArithExpr.pderiv j (F k)) (M k j)) :
        ContinuousOn (fun (x : ι → ℝ) (k : ι) => ArithExpr.eval x (F k)) (IntervalArith.box X)

        The map of a system F : ι → ArithExpr ι is continuous on a box on which its partial derivatives have rounded evaluations.

        theorem ConvexAnalysis.existsUnique_eq_zero_of_intervalKrawczyk_pderiv {ι : Type u_1} [Fintype ι] [DecidableEq ι] {F : ι → ArithExpr ι} {M : ι → ι → NonemptyInterval ℝ} {X : ι → NonemptyInterval ℝ} {x₀ : ι → ℝ} {Fx₀ : ι → NonemptyInterval ℝ} {Y : Matrix ι ι ℝ} (hM : ∀ (k j : ι), ArithExpr.IsRoundedEval X (ArithExpr.pderiv j (F k)) (M k j)) (hx₀ : x₀ ∈ IntervalArith.box X) (hFx₀ : ∀ (k : ι), ArithExpr.eval x₀ (F k) ∈ Fx₀ k) (hK : ∀ (i : ι), (X i).toProd.1 < (intervalKrawczyk Fx₀ M Y x₀ X i).toProd.1 ∧ (intervalKrawczyk Fx₀ M Y x₀ X i).toProd.2 < (X i).toProd.2) :
        ∃! x : ι → ℝ, x ∈ IntervalArith.box X ∧ (fun (k : ι) => ArithExpr.eval x (F k)) = 0

        The interval Krawczyk test with automatic derivatives: let F : ι → ArithExpr ι be a system of expressions, M k j a rounded evaluation on the box X of the partial derivative ArithExpr.pderiv j (F k) (for example its natural interval extension), x₀ ∈ X, Fx₀ an interval vector enclosing F(x₀) (for example rounded evaluations of F k on the point box of x₀, by ConvexAnalysis.ArithExpr.IsRoundedEval.eval_mem) and Y any matrix. If the interval Krawczyk operator ConvexAnalysis.intervalKrawczyk with Fx₀ and the interval matrix M lies in the interior of X, side by side, then the system F x = 0 has exactly one solution in X. Besides x₀ ∈ X and the computed inclusions, nothing is assumed: differentiability and the slope enclosure follow (ConvexAnalysis.isSlopeEnclosure_of_isRoundedEval_pderiv). This is the strict Krawczyk test (Neumaier, Theorem 5.1.8 (iii), see ConvexAnalysis.existsUnique_eq_zero_of_krawczyk_subset_interior) with the operator in real interval arithmetic, which is not computable itself; with dyadic endpoints it is computed by ConvexAnalysis.RatArithExpr.krawczykTest, and ConvexAnalysis.RatArithExpr.existsUnique_eq_zero_of_krawczykTest is the form for a computed result.

        theorem ConvexAnalysis.existsUnique_eq_zero_of_intervalNewton_subset_pderiv {ι : Type u_1} [Fintype ι] [DecidableEq ι] {F : ι → ArithExpr ι} {M : ι → ι → NonemptyInterval ℝ} {X : ι → NonemptyInterval ℝ} {x₀ : ι → ℝ} (hM : ∀ (k j : ι), ArithExpr.IsRoundedEval X (ArithExpr.pderiv j (F k)) (M k j)) (hunit : ∀ (A : Matrix ι ι ℝ), (∀ (k j : ι), A k j ∈ M k j) → IsUnit A) (hx₀ : x₀ ∈ IntervalArith.box X) (hN : intervalNewton (fun (x : ι → ℝ) (k : ι) => ArithExpr.eval x (F k)) {A : Matrix ι ι ℝ | ∀ (k j : ι), A k j ∈ M k j} x₀ ⊆ IntervalArith.box X) :
        ∃! x : ι → ℝ, x ∈ IntervalArith.box X ∧ (fun (k : ι) => ArithExpr.eval x (F k)) = 0

        The interval Newton test with automatic derivatives: with M as in ConvexAnalysis.existsUnique_eq_zero_of_intervalKrawczyk_pderiv, if every matrix in the interval matrix M is invertible, x₀ ∈ X and the interval Newton operator ConvexAnalysis.intervalNewton of M lies in X, then the system F x = 0 has exactly one solution in X. This is ConvexAnalysis.existsUnique_eq_zero_of_intervalNewton_subset with the slope enclosure ConvexAnalysis.isSlopeEnclosure_of_isRoundedEval_pderiv. Unlike the Krawczyk test, the invertibility hunit is a hypothesis, and hN is the inclusion of the exact Newton set, not of a computed hull. The Hansen–Sengupta test ConvexAnalysis.existsUnique_eq_zero_of_hansenSengupta_pderiv computes an enclosure of the Newton set and certifies the invertibility.