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#cas [maximize x in [a, b]] p#cas (digits := d) [maximize x] pmaximize looks for the largest value of a polynomial and proves that nothing goes above it. It is minimize applied to , 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 for every real , and . Otherwise the answer is an enclosure, and the theorem says for every , and at a rational point near the maximizer. What it bounds is the value of the maximum, not the position of the maximizer.
Examples (13)#
Basic Examples (3)
A downward parabola, with its maximum at a rational point:
#cas [maximize x] (3 + 2*x - x^2)
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
Global bound attained at the point
(∀ (x : ℝ), 3 + 2 * x - x ^ 2 ≤ 4) ∧ (fun x ↦ 3 + 2 * x - x ^ 2) 1 = 4
The computation
Critical points
Real roots of the derivative from the root list (not proof): 1
The maximum on an interval, at an endpoint:
#cas [maximize x in [-3, 3]] (x^3 - 3*x)
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
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 computation
Candidates
Endpoints and real roots of the derivative in the interval (not proof): 4
An enclosed maximum, with a witness in the interval:
#cas [maximize x in [0, 1]] (x * (1 - x) * (x + 1))
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
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 computation
Candidates
Endpoints and real roots of the derivative in the interval (not proof): 3
Scope (3)
A maximum inside the interval:
#cas [maximize x in [-1, 1]] (1 - x^2)
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
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 computation
Candidates
Endpoints and real roots of the derivative in the interval (not proof): 3
A convex function takes its maximum at an endpoint:
#cas [maximize x in [0, 2]] (x^2 - 2*x)
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
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 computation
Candidates
Endpoints and real roots of the derivative in the interval (not proof): 3
A quartic with a negative leading coefficient:
#cas [maximize x] (x^3 - x^4)
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
Global bound attained at the point
(∀ (x : ℝ), x ^ 3 - x ^ 4 ≤ 27 / 256) ∧ (fun x ↦ x ^ 3 - x ^ 4) (3 / 4) = 27 / 256
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 wide, on the real line and on an interval:
#cas (digits := 4) [maximize x] (1 - x^4 + x)
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
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 computation
Critical points
Real roots of the derivative from the root list (not proof): 1
#cas (digits := 4) [maximize x in [0, 1]] (x - x^3)
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
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 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:
theorem maximize_quadratic : ∀ x : ℝ, 3 + 2 * x - x ^ 2 ≤ 4 := by cas #print axioms maximize_quadratic
maximize_quadratic depends on the axioms propext, Classical.choice, Quot.sound.
A bound on an interval, from the maximum of on . The tactic cega proves it:
#cas [maximize x in [0, 1]] (x * (1 - x))
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
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 computation
Candidates
Endpoints and real roots of the derivative in the interval (not proof): 3
example (x : ℝ) (h0 : 0 ≤ x) (h1 : x ≤ 1) : x * (1 - x) ≤ 1 / 4 := by cega
Lean accepts the proof.
Properties and Relations (1)
minimize of gives the same point as the first example, and the opposite value:
#cas [minimize x] (x^2 - 2*x - 3)
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
Global bound attained at the point
(∀ (x : ℝ), -4 ≤ x ^ 2 - 2 * x - 3) ∧ (fun x ↦ x ^ 2 - 2 * x - 3) 1 = -4
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:
#cas [maximize x] (x^2)
Error
maximize: the polynomial is unbounded above (degree 2, leading coefficient 1), so it has no maximum
On a closed interval it has one:
#cas [maximize x in [-1, 1]] (x^2 + 1)
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
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 computation
Candidates
Endpoints and real roots of the derivative in the interval (not proof): 3
The smaller endpoint comes first:
#cas [maximize x in [1, 0]] (x)
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 from the corners and fold, for the volume :
#cas [maximize x in [0, 1/2]] (x * (1 - 2*x)^2)
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
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 computation
Candidates
Endpoints and real roots of the derivative in the interval (not proof): 4
