Mode of #cas

maximize

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

#cas [maximize x] p
gives the global maximum 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 larger.
#cas [maximize x in [a, b]] p
gives the maximum 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) [maximize 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.

maximize looks for the largest value of a polynomial and proves that nothing goes above it. It is minimize applied to −p, with the inequalities turned around, so everything on that page holds here too.

You get one of two answers. When a rational point attains the maximum, the answer is exact, and the theorem says p(x)≤M for every real x, and p(x0)=M. Otherwise the answer is an enclosure, and the theorem says p(x)≤hi for every x, and lo≤p(x1) at a rational point x1 near the maximizer. What it bounds is the value of the maximum, not the position of the maximizer.

Details and Options

  • p is a polynomial in x with rational coefficients and no other variable.
  • The exact theorem is (∀x,p≤M)∧p(x0)=M, and the enclosure theorem is (∀x,p≤hi)∧lo≤p(x1). Lean writes the value at the point as (fun x ↦ p) x₀.
  • A polynomial of odd degree, or of positive even degree with a positive leading coefficient, is unbounded above and is refused. On a closed interval every polynomial has a maximum.
  • On [a,b] the bound is ∀x∈[a,b],p≤M, stated with Set.Icc a b, and the point is proved to lie in the interval.
  • (digits := d) makes the enclosure at most 2·10−d wide, for d from 1 to 6, by default 3.
  • In a proof, cas proves the bound ∀x,p≤M, and cega proves bounds on an interval, also for functions other than polynomials.

Examples (13)#

Basic Examples (3)

A downward parabola, with its maximum at a rational point:

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

exact global maximum

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

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

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

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

    Checked by Lean’s kernel

The computation
  • Critical points

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

The maximum on an interval, at an endpoint:

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

exact maximum on the interval

max = 18 at x = 3
Domain
x ∈ [-3, 3]
Input (polynomial)
(x^3 - 3*x)

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

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

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

    Checked by Lean’s kernel

The computation
  • Candidates

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

An enclosed maximum, with a witness in the interval:

In[3]:=
#cas [maximize x in [0, 1]] (x * (1 - x) * (x + 1))
Out[3]=

certified enclosure of the maximum on the interval

max ∈ [0.384, 0.385], witness x = 0.57735 with value ≥ 0.384
Domain
x ∈ [0, 1]
Input (polynomial)
(x * (1 - x) * (x + 1))

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

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

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

    Checked by Lean’s kernel

The computation
  • Candidates

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

Scope (3)

A maximum inside the interval:

In[4]:=
#cas [maximize x in [-1, 1]] (1 - x^2)
Out[4]=

exact maximum on the interval

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

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

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

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

    Checked by Lean’s kernel

The computation
  • Candidates

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

A convex function takes its maximum at an endpoint:

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

exact maximum on the interval

max = 0 at x = 0
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, x ^ 2 - 2 * x ≤ 0) ∧ 0 ∈ Set.Icc 0 2 ∧ (fun x ↦ x ^ 2 - 2 * x) 0 = 0
The certificate: 1 checked step
  1. Bound on the interval attained at the point

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

    Checked by Lean’s kernel

The computation
  • Candidates

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

A quartic with a negative leading coefficient:

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

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

Options (1)

(digits := 4) makes the enclosure at most 2·10−4 wide, on the real line and on an interval:

In[7]:=
#cas (digits := 4) [maximize x] (1 - x^4 + x)
Out[7]=

certified enclosure of the global maximum

max ∈ [1.4724, 1.4725] near x = 0.629961
Input (polynomial)
(1 - x^4 + x)

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

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

    (∀ (x : ℝ), 1 - x ^ 4 + x ≤ 14725 / 10 ^ 4) ∧
      14724 / 10 ^ 4 ≤ (fun x ↦ 1 - x ^ 4 + x) (629961 / 10 ^ 6)

    Checked by Lean’s kernel

The computation
  • Critical points

    Real roots of the derivative from the root list (not proof): 1
In[8]:=
#cas (digits := 4) [maximize x in [0, 1]] (x - x^3)
Out[8]=

certified enclosure of the maximum on the interval

max ∈ [0.3849, 0.3850], witness x = 0.57735 with value ≥ 0.3849
Domain
x ∈ [0, 1]
Input (polynomial)
(x - x^3)

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

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

    (∀ x ∈ Set.Icc 0 1, x - x ^ 3 ≤ 3850 / 10 ^ 4) ∧
      57735 / 10 ^ 5 ∈ Set.Icc 0 1 ∧ 3849 / 10 ^ 4 ≤ (fun x ↦ x - x ^ 3) (57735 / 10 ^ 5)

    Checked by Lean’s kernel

The computation
  • Candidates

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

Applications (2)

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

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

#print axioms maximize_quadratic
Out[9]=

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


A bound on an interval, from the maximum 1/4 of x(1−x) on [0,1]. The tactic cega proves it:

In[10]:=
#cas [maximize x in [0, 1]] (x * (1 - x))
Out[10]=

exact maximum on the interval

max = 1/4 at x = 1/2
Domain
x ∈ [0, 1]
Input (polynomial)
(x * (1 - x))

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

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

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

    Checked by Lean’s kernel

The computation
  • Candidates

    Endpoints and real roots of the derivative in the interval (not proof): 3
In[11]:=
example (x : ℝ) (h0 : 0 ≤ x) (h1 : x ≤ 1) : x * (1 - x) ≤ 1 / 4 := by
  cega
Out[11]=

Lean accepts the proof.

Properties and Relations (1)

minimize of −p=x2−2x−3 gives the same point as the first example, and the opposite value:

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

exact global minimum

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

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

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

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

    Checked by Lean’s kernel

The computation
  • Critical points

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

Possible Issues (2)

A polynomial of even degree with a positive leading coefficient has no maximum:

In[13]:=
#cas [maximize x] (x^2)
Out[13]=

Error

maximize: the polynomial is unbounded above (degree 2, leading coefficient 1), so it has no maximum

On a closed interval it has one:

In[14]:=
#cas [maximize x in [-1, 1]] (x^2 + 1)
Out[14]=

exact maximum on the interval

max = 2 at x = -1
Domain
x ∈ [-1, 1]
Input (polynomial)
(x^2 + 1)

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

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

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

    Checked by Lean’s kernel

The computation
  • Candidates

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

The smaller endpoint comes first:

In[15]:=
#cas [maximize x in [1, 0]] (x)
Out[15]=

Error

maximize needs rational endpoints a < b

Neat Examples (1)

The open box of largest volume from a unit square of card: cut squares of side x from the corners and fold, for the volume x(1−2x)2:

In[16]:=
#cas [maximize x in [0, 1/2]] (x * (1 - 2*x)^2)
Out[16]=

exact maximum on the interval

max = 2/27 at x = 1/6
Domain
x ∈ [0, 1/2]
Input (polynomial)
(x * (1 - 2*x)^2)

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

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

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

    Checked by Lean’s kernel

The computation
  • Candidates

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

See Also

minimize · derive · roots · reduce · enclose · cega