Mode of #cas

minimize

The minimum of a polynomial on the real line or on an interval, exact or enclosed, with a theorem.

#cas [minimize x] p
gives the global minimum of the polynomial p, as an exact value when a rational point attains it and otherwise as a certified enclosure, and proves that no value of p is smaller.
#cas [minimize x in [a, b]] p
gives the minimum of p on the closed interval [a,b] with rational endpoints a<b, with a point of the interval that attains it or comes within the enclosure.
#cas (digits := d) [minimize x] p
the same with an enclosure of width at most 2·10−d, for d from 1 to 6. The interval form takes d too.

minimize looks for the smallest value of a polynomial and proves that nothing goes below it. When a rational point attains the minimum, the answer is exact, and the theorem says m≤p(x) for every real x, and p(x0)=m.

Often the minimizer is irrational, as for x4−x, whose minimizer is 4−1/3. Then the answer is an enclosure [lo,hi] of the minimum, and the theorem says lo≤p(x) for every x, and p(x1)≤hi at a rational point x1 near the minimizer. What it bounds is the value of the minimum, not the position of the minimizer.

Details and Options

  • p is a polynomial in x with rational coefficients and no other variable.
  • The exact theorem is (∀x,m≤p)∧p(x0)=m, and the enclosure theorem is (∀x,lo≤p)∧p(x1)≤hi. Lean writes the value at the point as (fun x ↦ p) x₀.
  • The candidates are the real roots of the derivative p′. The bound comes from the sign certificate that cas uses for p−m≥0, and the value at the point from norm_num.
  • A polynomial of odd degree, or of positive even degree with a negative leading coefficient, is unbounded below and is refused. On a closed interval every polynomial has a minimum.
  • On [a,b] the theorem is (∀x∈[a,b],m≤p)∧x0∈[a,b]∧p(x0)=m, stated with Set.Icc a b, or its enclosure form with a witness x1 in the interval.
  • (digits := d) makes the enclosure at most 2·10−d wide, for d from 1 to 6, by default 3. More digits make the sign certificate slower.
  • maximize is minimize of −p. In a proof, cas proves the bound ∀x,m≤p, and cega proves bounds on an interval for functions other than polynomials.

Examples (18)#

Basic Examples (3)

A quadratic, with an exact minimum at a rational point:

In[1]:=
#cas [minimize x] (x^2 - 2*x + 4)
Out[1]=

exact global minimum

min = 3 at x = 1
Input (polynomial)
(x^2 - 2*x + 4)

Checked by Lean’s kernel: Global bound attained at the point

(∀ (x : ℝ), 3 ≤ x ^ 2 - 2 * x + 4) ∧ (fun x ↦ x ^ 2 - 2 * x + 4) 1 = 3
The certificate: 1 checked step
  1. Global bound attained at the point

    (∀ (x : ℝ), 3 ≤ x ^ 2 - 2 * x + 4) ∧ (fun x ↦ x ^ 2 - 2 * x + 4) 1 = 3

    Checked by Lean’s kernel

The computation
  • Critical points

    Real roots of the derivative from the root list (not proof): 1

The minimizer of x4−x is 4−1/3, so the minimum is enclosed:

In[2]:=
#cas [minimize x] (x^4 - x)
Out[2]=

certified enclosure of the global minimum

min ∈ [-0.473, -0.472] near x = 0.62996
Input (polynomial)
(x^4 - x)

Checked by Lean’s kernel: Global bound and a nearby value

(∀ (x : ℝ), -473 / 10 ^ 3 ≤ x ^ 4 - x) ∧ (fun x ↦ x ^ 4 - x) (62996 / 10 ^ 5) ≤ -472 / 10 ^ 3
The certificate: 1 checked step
  1. Global bound and a nearby value

    (∀ (x : ℝ), -473 / 10 ^ 3 ≤ x ^ 4 - x) ∧ (fun x ↦ x ^ 4 - x) (62996 / 10 ^ 5) ≤ -472 / 10 ^ 3

    Checked by Lean’s kernel

The computation
  • Critical points

    Real roots of the derivative from the root list (not proof): 1

The minimum on an interval:

In[3]:=
#cas [minimize x in [0, 2]] (x^2 - 2*x)
Out[3]=

exact minimum on the interval

min = -1 at x = 1
Domain
x ∈ [0, 2]
Input (polynomial)
(x^2 - 2*x)

Checked by Lean’s kernel: Bound on the interval attained at the point

(∀ x ∈ Set.Icc 0 2, -1 ≤ x ^ 2 - 2 * x) ∧ 1 ∈ Set.Icc 0 2 ∧ (fun x ↦ x ^ 2 - 2 * x) 1 = -1
The certificate: 1 checked step
  1. Bound on the interval attained at the point

    (∀ x ∈ Set.Icc 0 2, -1 ≤ x ^ 2 - 2 * x) ∧ 1 ∈ Set.Icc 0 2 ∧ (fun x ↦ x ^ 2 - 2 * x) 1 = -1

    Checked by Lean’s kernel

The computation
  • Candidates

    Endpoints and real roots of the derivative in the interval (not proof): 3

Scope (5)

A quartic with a rational minimizer and a rational minimum:

In[4]:=
#cas [minimize x] (x^4 - x^3)
Out[4]=

exact global minimum

min = -27/256 at x = 3/4
Input (polynomial)
(x^4 - x^3)

Checked by Lean’s kernel: Global bound attained at the point

(∀ (x : ℝ), -(27 / 256) ≤ x ^ 4 - x ^ 3) ∧ (fun x ↦ x ^ 4 - x ^ 3) (3 / 4) = -(27 / 256)
The certificate: 1 checked step
  1. Global bound attained at the point

    (∀ (x : ℝ), -(27 / 256) ≤ x ^ 4 - x ^ 3) ∧ (fun x ↦ x ^ 4 - x ^ 3) (3 / 4) = -(27 / 256)

    Checked by Lean’s kernel

The computation
  • Critical points

    Real roots of the derivative from the root list (not proof): 2

A quartic with two local minima. The global one is at an irrational point:

In[5]:=
#cas [minimize x] (x^4 - 3*x^2 + x)
Out[5]=

certified enclosure of the global minimum

min ∈ [-3.514, -3.513] near x = -1.30084
Input (polynomial)
(x^4 - 3*x^2 + x)

Checked by Lean’s kernel: Global bound and a nearby value

(∀ (x : ℝ), -3514 / 10 ^ 3 ≤ x ^ 4 - 3 * x ^ 2 + x) ∧
  (fun x ↦ x ^ 4 - 3 * x ^ 2 + x) (-130084 / 10 ^ 5) ≤ -3513 / 10 ^ 3
The certificate: 1 checked step
  1. Global bound and a nearby value

    (∀ (x : ℝ), -3514 / 10 ^ 3 ≤ x ^ 4 - 3 * x ^ 2 + x) ∧
      (fun x ↦ x ^ 4 - 3 * x ^ 2 + x) (-130084 / 10 ^ 5) ≤ -3513 / 10 ^ 3

    Checked by Lean’s kernel

The computation
  • Critical points

    Real roots of the derivative from the root list (not proof): 3

On an interval, the candidates are the critical points inside and the two endpoints:

In[6]:=
#cas [minimize x in [-1, 2]] (x^3 - 3*x)
Out[6]=

exact minimum on the interval

min = -2 at x = 1
Domain
x ∈ [-1, 2]
Input (polynomial)
(x^3 - 3*x)

Checked by Lean’s kernel: Bound on the interval attained at the point

(∀ x ∈ Set.Icc (-1) 2, -2 ≤ x ^ 3 - 3 * x) ∧ 1 ∈ Set.Icc (-1) 2 ∧ (fun x ↦ x ^ 3 - 3 * x) 1 = -2
The certificate: 1 checked step
  1. Bound on the interval attained at the point

    (∀ x ∈ Set.Icc (-1) 2, -2 ≤ x ^ 3 - 3 * x) ∧ 1 ∈ Set.Icc (-1) 2 ∧ (fun x ↦ x ^ 3 - 3 * x) 1 = -2

    Checked by Lean’s kernel

The computation
  • Candidates

    Endpoints and real roots of the derivative in the interval (not proof): 4
In[7]:=
#cas [minimize x in [1, 2]] (x)
Out[7]=

exact minimum on the interval

min = 1 at x = 1
Domain
x ∈ [1, 2]
Input (polynomial)
(x)

Checked by Lean’s kernel: Bound on the interval attained at the point

(∀ x ∈ Set.Icc 1 2, 1 ≤ x) ∧ 1 ∈ Set.Icc 1 2 ∧ (fun x ↦ x) 1 = 1
The certificate: 1 checked step
  1. Bound on the interval attained at the point

    (∀ x ∈ Set.Icc 1 2, 1 ≤ x) ∧ 1 ∈ Set.Icc 1 2 ∧ (fun x ↦ x) 1 = 1

    Checked by Lean’s kernel

The computation
  • Candidates

    Endpoints and real roots of the derivative in the interval (not proof): 2

A polynomial of odd degree has a minimum on a closed interval, here at 2/3:

In[8]:=
#cas [minimize x in [0, 2]] (x^3 - 2*x)
Out[8]=

certified enclosure of the minimum on the interval

min ∈ [-1.089, -1.088], witness x = 0.8165 with value ≤ -1.088
Domain
x ∈ [0, 2]
Input (polynomial)
(x^3 - 2*x)

Checked by Lean’s kernel: Bound on the interval and a witness value

(∀ x ∈ Set.Icc 0 2, -1089 / 10 ^ 3 ≤ x ^ 3 - 2 * x) ∧
  8165 / 10 ^ 4 ∈ Set.Icc 0 2 ∧ (fun x ↦ x ^ 3 - 2 * x) (8165 / 10 ^ 4) ≤ -1088 / 10 ^ 3
The certificate: 1 checked step
  1. Bound on the interval and a witness value

    (∀ x ∈ Set.Icc 0 2, -1089 / 10 ^ 3 ≤ x ^ 3 - 2 * x) ∧
      8165 / 10 ^ 4 ∈ Set.Icc 0 2 ∧ (fun x ↦ x ^ 3 - 2 * x) (8165 / 10 ^ 4) ≤ -1088 / 10 ^ 3

    Checked by Lean’s kernel

The computation
  • Candidates

    Endpoints and real roots of the derivative in the interval (not proof): 3

Rational endpoints:

In[9]:=
#cas [minimize x in [1/2, 3/2]] (x^5 - 5*x)
Out[9]=

exact minimum on the interval

min = -4 at x = 1
Domain
x ∈ [1/2, 3/2]
Input (polynomial)
(x^5 - 5*x)

Checked by Lean’s kernel: Bound on the interval attained at the point

(∀ x ∈ Set.Icc (1 / 2) (3 / 2), -4 ≤ x ^ 5 - 5 * x) ∧
  1 ∈ Set.Icc (1 / 2) (3 / 2) ∧ (fun x ↦ x ^ 5 - 5 * x) 1 = -4
The certificate: 1 checked step
  1. Bound on the interval attained at the point

    (∀ x ∈ Set.Icc (1 / 2) (3 / 2), -4 ≤ x ^ 5 - 5 * x) ∧
      1 ∈ Set.Icc (1 / 2) (3 / 2) ∧ (fun x ↦ x ^ 5 - 5 * x) 1 = -4

    Checked by Lean’s kernel

The computation
  • Candidates

    Endpoints and real roots of the derivative in the interval (not proof): 3

Options (1)

(digits := 4) makes the enclosure at most 2·10−4 wide:

In[10]:=
#cas (digits := 4) [minimize x] (x^4 - x)
Out[10]=

certified enclosure of the global minimum

min ∈ [-0.4725, -0.4724] near x = 0.629961
Input (polynomial)
(x^4 - x)

Checked by Lean’s kernel: Global bound and a nearby value

(∀ (x : ℝ), -4725 / 10 ^ 4 ≤ x ^ 4 - x) ∧ (fun x ↦ x ^ 4 - x) (629961 / 10 ^ 6) ≤ -4724 / 10 ^ 4
The certificate: 1 checked step
  1. Global bound and a nearby value

    (∀ (x : ℝ), -4725 / 10 ^ 4 ≤ x ^ 4 - x) ∧ (fun x ↦ x ^ 4 - x) (629961 / 10 ^ 6) ≤ -4724 / 10 ^ 4

    Checked by Lean’s kernel

The computation
  • Critical points

    Real roots of the derivative from the root list (not proof): 1

Applications (2)

The bound in a proof. cas proves it, and only the three standard axioms are used:

In[11]:=
theorem minimize_quadratic : ∀ x : ℝ, 3 ≤ x ^ 2 - 2 * x + 4 := by
  cas

#print axioms minimize_quadratic
Out[11]=

minimize_quadratic depends on the axioms propext, Classical.choice, Quot.sound.


The exact minimum of x4−x3 is a sharp bound:

In[12]:=
example : ∀ x : ℝ, (-27 : ℝ) / 256 ≤ x ^ 4 - x ^ 3 := by cas
Out[12]=

Lean accepts the proof.

Properties and Relations (2)

The minimizer 3/4 is a root of the derivative:

In[13]:=
#cas [derive x] (x^4 - x^3)
Out[13]=
4x3−3x2
4*x^3 - 3*x^2

Checked by Lean’s kernel: Derivative of the input

∀ (x : ℝ), HasDerivAt (fun x ↦ x ^ 4 - x ^ 3) (4 * x ^ 3 - 3 * x ^ 2) x

from CAS.Command.hasDerivAt_of_displayRoute

The certificate: 5 checked steps
  1. Derivative of the input

    ∀ (x : ℝ), HasDerivAt (fun x ↦ x ^ 4 - x ^ 3) (4 * x ^ 3 - 3 * x ^ 2) x

    Checked by Lean’s kernel · CAS.Command.hasDerivAt_of_displayRoute

  2. Partial derivative in x: indexed rules compute Expr.diff

    (CAS.Verified.Expr.DiffDerivation.build 0 ((𝕏[0].pow 4).sub (𝕏[0].pow 3))).rawDerivative =
      CAS.Verified.Expr.diff 0 ((𝕏[0].pow 4).sub (𝕏[0].pow 3))

    Checked by Lean’s kernel · CAS.Verified.Expr.DiffDerivation.rawDerivative_eq_diff

  3. Partial derivative in x: normalization preserves evaluation

    ∀ (ρ : Fin 1 → ℝ),
      CAS.Verified.Expr.eval ρ
          (CAS.Verified.Expr.DiffDerivation.build 0 ((𝕏[0].pow 4).sub (𝕏[0].pow 3))).simplifiedDerivative =
        CAS.Verified.Expr.eval ρ
          (CAS.Verified.Expr.DiffDerivation.build 0 ((𝕏[0].pow 4).sub (𝕏[0].pow 3))).rawDerivative

    Checked by Lean’s kernel · CAS.Verified.Expr.DiffDerivation.eval_simplifiedDerivative_eq_rawDerivative

  4. Partial derivative in x: side-conditioned display normalization

    ∀ (ρ : Fin 1 → ℝ),
      CAS.Verified.Expr.Alg.SideHolds ρ
          (CAS.Command.displayDerivativeRoute
              (CAS.Verified.Expr.DiffDerivation.build 0 ((𝕏[0].pow 4).sub (𝕏[0].pow 3)))).nonzero →
        CAS.Verified.Expr.eval ρ
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0 ((𝕏[0].pow 4).sub (𝕏[0].pow 3)))).rhs =
          CAS.Verified.Expr.eval ρ
            (CAS.Verified.Expr.DiffDerivation.build 0 ((𝕏[0].pow 4).sub (𝕏[0].pow 3))).simplifiedDerivative

    Checked by Lean’s kernel · CAS.Command.displayDerivativeRoute_sound

  5. Partial derivative in x: analytic semantics of the displayed result

    ∀ (x : ℝ^1),
      CAS.Verified.Expr.ValidAt x.ofLp ((𝕏[0].pow 4).sub (𝕏[0].pow 3)) →
        CAS.Verified.Expr.Alg.SideHolds x.ofLp
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0 ((𝕏[0].pow 4).sub (𝕏[0].pow 3)))).nonzero →
          (fderiv ℝ (fun y ↦ CAS.Verified.Expr.eval y.ofLp ((𝕏[0].pow 4).sub (𝕏[0].pow 3))) x)
              (EuclideanSpace.single 0 1) =
            CAS.Verified.Expr.eval x.ofLp
              (CAS.Command.displayDerivativeRoute
                  (CAS.Verified.Expr.DiffDerivation.build 0 ((𝕏[0].pow 4).sub (𝕏[0].pow 3)))).rhs

    Checked by Lean’s kernel · CAS.Command.fderiv_apply_single_eq_eval_displayDerivative

The computation
  • Variables: x
  • Analytic domain conditions

    Raw checked nonzero requirements: (none)
    Raw checked positivity requirements: (none)
  • Partial derivative in x

    • 1. Apply symbolic differentiation rules

      raw result: 4*x^3*1 - 3*x^2*1
    • 2. Normalize the symbolic derivative unconditionally

      normalized result: 4*x^3 - 3*x^2
    • 3. Apply checked side-conditioned cleanup

      displayed result: 4*x^3 - 3*x^2
      additional nonzero requirements: (none)

maximize of −p gives the same point:

In[14]:=
#cas [maximize x] (x^3 - x^4)
Out[14]=

exact global maximum

max = 27/256 at x = 3/4
Input (polynomial)
(x^3 - x^4)

Checked by Lean’s kernel: Global bound attained at the point

(∀ (x : ℝ), x ^ 3 - x ^ 4 ≤ 27 / 256) ∧ (fun x ↦ x ^ 3 - x ^ 4) (3 / 4) = 27 / 256
The certificate: 1 checked step
  1. Global bound attained at the point

    (∀ (x : ℝ), x ^ 3 - x ^ 4 ≤ 27 / 256) ∧ (fun x ↦ x ^ 3 - x ^ 4) (3 / 4) = 27 / 256

    Checked by Lean’s kernel

The computation
  • Critical points

    Real roots of the derivative from the root list (not proof): 2

Possible Issues (4)

A polynomial of odd degree has no global minimum:

In[15]:=
#cas [minimize x] (x^3 - x)
Out[15]=

Error

minimize: the polynomial is unbounded below (degree 3, leading coefficient 1), so it has no minimum

On a closed interval it has one:

In[16]:=
#cas [minimize x in [-1, 1]] (x^3 - x)
Out[16]=

certified enclosure of the minimum on the interval

min ∈ [-0.385, -0.384], witness x = 0.57735 with value ≤ -0.384
Domain
x ∈ [-1, 1]
Input (polynomial)
(x^3 - x)

Checked by Lean’s kernel: Bound on the interval and a witness value

(∀ x ∈ Set.Icc (-1) 1, -385 / 10 ^ 3 ≤ x ^ 3 - x) ∧
  57735 / 10 ^ 5 ∈ Set.Icc (-1) 1 ∧ (fun x ↦ x ^ 3 - x) (57735 / 10 ^ 5) ≤ -384 / 10 ^ 3
The certificate: 1 checked step
  1. Bound on the interval and a witness value

    (∀ x ∈ Set.Icc (-1) 1, -385 / 10 ^ 3 ≤ x ^ 3 - x) ∧
      57735 / 10 ^ 5 ∈ Set.Icc (-1) 1 ∧ (fun x ↦ x ^ 3 - x) (57735 / 10 ^ 5) ≤ -384 / 10 ^ 3

    Checked by Lean’s kernel

The computation
  • Candidates

    Endpoints and real roots of the derivative in the interval (not proof): 4

Only polynomials. For other functions on an interval, cega proves bounds:

In[17]:=
#cas [minimize x] (sin x)
Out[17]=

Error

minimize needs a polynomial in x with rational coefficients

The smaller endpoint comes first:

In[18]:=
#cas [minimize x in [1, 0]] (x)
Out[18]=

Error

minimize needs rational endpoints a < b

At most 6 digits:

In[19]:=
#cas (digits := 7) [minimize x] (x^4 - x)
Out[19]=

Error

minimize accepts between 1 and 6 digits

Neat Examples (1)

On [−2,2] the minimum of x4−3x2+x is the global one, with a witness in the interval:

In[20]:=
#cas [minimize x in [-2, 2]] (x^4 - 3*x^2 + x)
Out[20]=

certified enclosure of the minimum on the interval

min ∈ [-3.514, -3.513], witness x = -1.30084 with value ≤ -3.513
Domain
x ∈ [-2, 2]
Input (polynomial)
(x^4 - 3*x^2 + x)

Checked by Lean’s kernel: Bound on the interval and a witness value

(∀ x ∈ Set.Icc (-2) 2, -3514 / 10 ^ 3 ≤ x ^ 4 - 3 * x ^ 2 + x) ∧
  -130084 / 10 ^ 5 ∈ Set.Icc (-2) 2 ∧ (fun x ↦ x ^ 4 - 3 * x ^ 2 + x) (-130084 / 10 ^ 5) ≤ -3513 / 10 ^ 3
The certificate: 1 checked step
  1. Bound on the interval and a witness value

    (∀ x ∈ Set.Icc (-2) 2, -3514 / 10 ^ 3 ≤ x ^ 4 - 3 * x ^ 2 + x) ∧
      -130084 / 10 ^ 5 ∈ Set.Icc (-2) 2 ∧ (fun x ↦ x ^ 4 - 3 * x ^ 2 + x) (-130084 / 10 ^ 5) ≤ -3513 / 10 ^ 3

    Checked by Lean’s kernel

The computation
  • Candidates

    Endpoints and real roots of the derivative in the interval (not proof): 5

See Also

maximize · derive · roots · reduce · enclose · cega