Grace/Cumulus/Real/Analysis/RealInduction.g17

Open in Workbench Download source

Imports

SequentialCompactness

Declarations

Source

1-- Induction along a closed interval: a property that holds at the left2-- endpoint and spreads past every point reaches the right endpoint. From it,3-- a function continuous on [A, B] is bounded, stays a positive distance from4-- every value it does not take, and is uniformly continuous; no point is5-- selected, only the supremum of the points reached is taken.6-- Part of Cumulus, the Grace17 mathematics library.7-- Copyright (c) 2026 Grant Passmore.8-- Released under the Apache License 2.0. See LICENSE in the repository root.9-- Authors: Grant Passmore1011module Grace.Cumulus.Real.Analysis.RealInduction12import SequentialCompactness1314theorem realPositive.common_lower (D E : Real)15  requires positiveD : 0 < D16  requires positiveE : 0 < E17  shows ∃ F ∈ ℝ, 0 < F ∧ F ≤ D ∧ F ≤ E18proof19  have split : D ≤ E ∨ ¬(D ≤ E) by tauto20  cases split with below | above21  . have realD : D ∈ ℝ by simp [Real]22    witness D23    refine ⟨realD, positiveD, realLe.reflexive at D, below⟩24  . have less := realLess.of_not_le with above25    have weak := realLess.implies_le with less26    have realE : E ∈ ℝ by simp [Real]27    witness E28    refine ⟨realE, positiveE, weak, realLe.reflexive at E⟩2930theorem realBound.common_upper (M N : Real)31  shows ∃ K ∈ ℝ, M ≤ K ∧ N ≤ K32proof33  have split : M ≤ N ∨ ¬(M ≤ N) by tauto34  cases split with below | above35  . have realN : N ∈ ℝ by simp [Real]36    witness N37    refine ⟨realN, below, realLe.reflexive at N⟩38  . have less := realLess.of_not_le with above39    have weak := realLess.implies_le with less40    have realM : M ∈ ℝ by simp [Real]41    witness M42    refine ⟨realM, realLe.reflexive at M, weak⟩4344-- The points of [A, B] that lie in P.45def reachedPoints (P : Set) (A B : Real) : Set :=46  { Point ∈ closedInterval(A, B) | Point ∈ P }4748-- Real induction. Let C be the supremum of the points of [A, B] in P. A point49-- of P just below C carries P past C, so C + D/2 would be a larger point of50-- P unless it lies beyond B; then B itself is carried.51theorem closedInterval.real_induction (P : Set) (A B : Real)52  requires ordered : A ≤ B53  requires start : A ∈ P54  requires extend : ∀ C ∈ closedInterval(A, B), ∃ D ∈ ℝ, 0 < D ∧55    ∀ Z ∈ closedInterval(A, B), (Z ∈ P → (C:R) - (D:R) < (Z:R) →56      ∀ W ∈ closedInterval(A, B), ((W:R) < (C:R) + (D:R) → W ∈ P))57  shows B ∈ P58proof59  have leftMember := closedInterval.left_mem with ordered60  have rightMember := closedInterval.right_mem with ordered61  have aData : A ∈ closedInterval(A, B) ∧ A ∈ P := ⟨leftMember, start⟩62  have aIn := reachedPoints.membership.backward at P, A, B, A with aData63  have inhabited : Nonempty(reachedPoints(P, A, B)) := ⟨A, aIn⟩64  have pointsReal : reachedPoints(P, A, B) ⊆ ℝ65    intros X member66    obtain ⟨inInterval, inP⟩ := reachedPoints.membership.forward with member67    obtain ⟨realX, lowerX, upperX⟩ := closedInterval.membership.forward with inInterval68    exact realX69  have upper : RealUpperBound(reachedPoints(P, A, B), B)70    unfold RealUpperBound71    have typedB : Real(B) by assumption72    refine ⟨typedB, pointsReal, _⟩73    intros X member74    obtain ⟨inInterval, inP⟩ := reachedPoints.membership.forward with member75    obtain ⟨realX, lowerX, upperX⟩ := closedInterval.membership.forward with inInterval76    exact realLe.subset with *77  have bounded : ∃ D, RealUpperBound(reachedPoints(P, A, B), D) := ⟨B, upper⟩78  obtain ⟨C, lubC⟩ := Real.least_upper_bound_property at reachedPoints(P, A, B) with *79  have least := lubC80  rcases lubC with ⟨⟨typedC, pointsSubset, boundsC⟩, leastC⟩81  have realC : C ∈ ℝ by exact typedC82  have aSubset := boundsC with A, aIn83  have aLe := realLe.of_subset at A, C with *84  have cSubset := leastC with B, upper85  have cLe := realLe.of_subset at C, B with *86  have cData : C ∈ ℝ ∧ A ≤ C ∧ C ≤ B by refine ⟨realC, aLe, cLe⟩87  have cIn : C ∈ closedInterval(A, B)88    exact closedInterval.membership.backward with cData89  obtain ⟨D, realD, positiveD, carries⟩ := extend with C, cIn90  obtain ⟨Z, zReached, near⟩ := RealLeastUpperBound.approached with least, positiveD91  obtain ⟨zIn, zP⟩ := reachedPoints.membership.forward with zReached92  have spread := carries with Z, zIn, zP, near93  have halfPositive := half.positive at D with *94  have halfLess := half.lt_self at D with *95  have reach : C + half(D) ≤ B ∨ ¬(C + half(D) ≤ B) by tauto96  cases reach with inside | outside97  . exfalso98    have xReal := realAddValue.real at C, half(D) with *99    have xMember : C + half(D) ∈ ℝ by exact xReal100    have xData : C + half(D) ∈ ℝ ∧ A ≤ C + half(D) ∧ C + half(D) ≤ B101      refine ⟨xMember, _, inside⟩102      linarith103    have xIn : C + half(D) ∈ closedInterval(A, B)104      exact closedInterval.membership.backward with xData105    have xBelow : C + half(D) < C + D by linarith106    have xP := spread with C + half(D), xIn, xBelow107    have xPoints : C + half(D) ∈ closedInterval(A, B) ∧ C + half(D) ∈ P := ⟨xIn, xP⟩108    have xReached := reachedPoints.membership.backward at P, A, B, C + half(D) with xPoints109    have xSubset := boundsC with C + half(D), xReached110    have xLe := realLe.of_subset at C + half(D), C with *111    linarith112  . have bLess := realLess.of_not_le with outside113    have bBelow : B < C + D by linarith114    exact spread with B, rightMember, bBelow115116-- The points Z for which f is bounded above on the part of [A, B] up to Z.117def boundedPrefixes (f : Set) (A B : Real) : Set :=118  { Reach ∈ ℝ | ∃ Ceiling ∈ ℝ, ∀ Point ∈ closedInterval(A, B),119    (Point:R) ≤ (Reach:R) → (f(Point):R) ≤ (Ceiling:R) }120121theorem ContinuousOn.closed_interval_bounded_above (f : Set) (A B : Real)122  requires ordered : A ≤ B123  requires continuous : ContinuousOn(f, closedInterval(A, B))124  shows ∃ Ceiling ∈ ℝ, ∀ X ∈ closedInterval(A, B), (f(X):R) ≤ (Ceiling:R)125proof126  rcases continuous with ⟨function, subset, pointwise⟩127  have leftMember := closedInterval.left_mem with ordered128  have realA : A ∈ ℝ by simp [Real]129  have imageA := FunctionBetween.apply_closed with function, realA130  have start : A ∈ boundedPrefixes(f, A, B)131    apply boundedPrefixes.membership.backward132    refine ⟨realA, f(A), imageA, _⟩133    intros X xIn xBelow134    obtain ⟨realX, lowerX, upperX⟩ := closedInterval.membership.forward with xIn135    have same := realLe.antisymmetric with xBelow, lowerX136    rw same137    exact realLe.reflexive138  have extend : ∀ C ∈ closedInterval(A, B), ∃ D ∈ ℝ, 0 < D ∧139      ∀ Z ∈ closedInterval(A, B), (Z ∈ boundedPrefixes(f, A, B) →140        (C:R) - (D:R) < (Z:R) →141        ∀ W ∈ closedInterval(A, B), ((W:R) < (C:R) + (D:R) →142          W ∈ boundedPrefixes(f, A, B)))143    intros C cIn144    obtain ⟨realC, lowerC, upperC⟩ := closedInterval.membership.forward with cIn145    have within := pointwise with C, cIn146    have imageC := FunctionBetween.apply_closed with function, realC147    obtain ⟨D, realD, positiveD, maps⟩ :=148      ContinuousWithinAt.maps_ball at f, closedInterval(A, B), C, realOne with149        within, realZero.lt_one150    witness D151    refine ⟨realD, positiveD, _⟩152    intros Z zIn zPrefix near W wIn wBelow153    obtain ⟨realZ, M, realM, boundM⟩ := boundedPrefixes.membership.forward with zPrefix154    obtain ⟨realW, lowerW, upperW⟩ := closedInterval.membership.forward with wIn155    have localReal := realAddValue.real at f(C), realOne with imageC, realOne.real156    obtain ⟨K, realK, mK, localK⟩ := realBound.common_upper at M, f(C) + 1157    apply boundedPrefixes.membership.backward158    refine ⟨realW, K, realK, _⟩159    intros X xIn xBelow160    obtain ⟨realX, lowerX, upperX⟩ := closedInterval.membership.forward with xIn161    have imageX := FunctionBetween.apply_closed with function, realX162    have split : (X:R) ≤ (Z:R) ∨ ¬((X:R) ≤ (Z:R)) by tauto163    cases split with early | late164    . have bound := boundM with X, xIn, early165      exact realLe.transitive with bound, mK166    . have after := realLess.of_not_le with late167      have nearData : C - D < X ∧ X < C + D168        constructor169        . linarith170        . linarith171      have nearX := openBall.order_characterization.backward with nearData172      have mapped := maps with X, realX, xIn, nearX173      obtain ⟨lowerImage, upperImage⟩ := openBall.order_characterization.forward with mapped174      linarith175  have reached := closedInterval.real_induction with ordered, start, extend176  obtain ⟨realB, M, realM, boundM⟩ := boundedPrefixes.membership.forward with reached177  witness M178  refine ⟨realM, _⟩179  intros X xIn180  obtain ⟨realX, lowerX, upperX⟩ := closedInterval.membership.forward with xIn181  exact boundM with X, xIn, upperX182183-- The points Z up to which f stays a fixed positive distance away from V.184def separatedPrefixes (f : Set) (A B V : Real) : Set :=185  { Reach ∈ ℝ | ∃ Margin ∈ ℝ, 0 < Margin ∧ ∀ Point ∈ closedInterval(A, B),186    (Point:R) ≤ (Reach:R) → (Margin:R) ≤ dist(f(Point), V) }187188-- A continuous function on [A, B] that never takes the value V keeps a189-- positive distance from it.190theorem ContinuousOn.closed_interval_gap (f : Set) (A B V : Real)191  requires ordered : A ≤ B192  requires continuous : ContinuousOn(f, closedInterval(A, B))193  requires avoids : ∀ X ∈ closedInterval(A, B), f(X) ≠ V194  shows ∃ Margin ∈ ℝ, 0 < Margin ∧195    ∀ X ∈ closedInterval(A, B), (Margin:R) ≤ dist(f(X), V)196proof197  rcases continuous with ⟨function, subset, pointwise⟩198  have leftMember := closedInterval.left_mem with ordered199  have realA : A ∈ ℝ by simp [Real]200  have imageA := FunctionBetween.apply_closed with function, realA201  have start : A ∈ separatedPrefixes(f, A, B, V)202    apply separatedPrefixes.membership.backward203    have unequal := avoids with A, leftMember204    have positive := dist.positive_of_ne with unequal205    have distReal := dist.real at f(A), V206    have distMember : dist(f(A), V) ∈ ℝ by simp [Real]207    refine ⟨realA, dist(f(A), V), distMember, positive, _⟩208    intros X xIn xBelow209    obtain ⟨realX, lowerX, upperX⟩ := closedInterval.membership.forward with xIn210    have same := realLe.antisymmetric with xBelow, lowerX211    rw same212    exact realLe.reflexive213  have extend : ∀ C ∈ closedInterval(A, B), ∃ D ∈ ℝ, 0 < D ∧214      ∀ Z ∈ closedInterval(A, B), (Z ∈ separatedPrefixes(f, A, B, V) →215        (C:R) - (D:R) < (Z:R) →216        ∀ W ∈ closedInterval(A, B), ((W:R) < (C:R) + (D:R) →217          W ∈ separatedPrefixes(f, A, B, V)))218    intros C cIn219    obtain ⟨realC, lowerC, upperC⟩ := closedInterval.membership.forward with cIn220    have within := pointwise with C, cIn221    have imageC := FunctionBetween.apply_closed with function, realC222    have unequal := avoids with C, cIn223    have positive := dist.positive_of_ne with unequal224    have halfPositive := half.positive with positive225    obtain ⟨D, realD, positiveD, maps⟩ :=226      ContinuousWithinAt.maps_ball at f, closedInterval(A, B), C, half(dist(f(C), V)) with227        within, halfPositive228    witness D229    refine ⟨realD, positiveD, _⟩230    intros Z zIn zPrefix near W wIn wBelow231    obtain ⟨realZ, E, realE, positiveE, boundE⟩ :=232      separatedPrefixes.membership.forward with zPrefix233    obtain ⟨realW, lowerW, upperW⟩ := closedInterval.membership.forward with wIn234    obtain ⟨F, realF, positiveF, fE, fHalf⟩ :=235      realPositive.common_lower with positiveE, halfPositive236    apply separatedPrefixes.membership.backward237    refine ⟨realW, F, realF, positiveF, _⟩238    intros X xIn xBelow239    obtain ⟨realX, lowerX, upperX⟩ := closedInterval.membership.forward with xIn240    have imageX := FunctionBetween.apply_closed with function, realX241    have split : (X:R) ≤ (Z:R) ∨ ¬((X:R) ≤ (Z:R)) by tauto242    cases split with early | late243    . have bound := boundE with X, xIn, early244      exact realLe.transitive with fE, bound245    . have after := realLess.of_not_le with late246      have nearData : C - D < X ∧ X < C + D247        constructor248        . linarith249        . linarith250      have nearX := openBall.order_characterization.backward with nearData251      have mapped := maps with X, realX, xIn, nearX252      obtain ⟨imageMember, close⟩ := openBall.membership.forward with mapped253      have triangle := dist.triangle at f(C), f(X), V254      have symmetric := dist.symmetric at f(C), f(X)255      rw symmetric at triangle256      have halves := half.add_self at dist(f(C), V)257      have realXV := dist.real at f(X), V258      have realXC := dist.real at f(X), f(C)259      have realCV := dist.real at f(C), V260      have realHalf := half.real at dist(f(C), V)261      linarith262  have reached := closedInterval.real_induction with ordered, start, extend263  obtain ⟨realB, E, realE, positiveE, boundE⟩ :=264    separatedPrefixes.membership.forward with reached265  witness E266  refine ⟨realE, positiveE, _⟩267  intros X xIn268  obtain ⟨realX, lowerX, upperX⟩ := closedInterval.membership.forward with xIn269  exact boundE with X, xIn, upperX270271-- The points Z up to which one input radius keeps f within E on [A, B].272def uniformPrefixes (f : Set) (A B E : Real) : Set :=273  { Reach ∈ ℝ | ∃ Radius ∈ ℝ, 0 < Radius ∧ ∀ First ∈ closedInterval(A, B),274    ∀ Second ∈ closedInterval(A, B), (First:R) ≤ (Reach:R) →275      (Second:R) ≤ (Reach:R) → First ∈ openBall(Second, Radius) →276        f(First) ∈ openBall(f(Second), E) }277278-- Heine–Cantor on [A, B] from continuity at each point of it: near a point C279-- both inputs of a close pair beyond the reached part lie within the radius280-- for E/2 at C, so their values lie within E of each other.281theorem closedInterval.uniform_of_local_control (f : Set) (A B E : Real)282  requires ordered : A ≤ B283  requires values : ∀ X ∈ closedInterval(A, B), f(X) ∈ ℝ284  requires local : ∀ C ∈ ℝ, C ∈ closedInterval(A, B) → ∀ R ∈ ℝ, 0 < R →285    ∃ D ∈ ℝ, 0 < D ∧ ∀ X ∈ ℝ, (X ∈ closedInterval(A, B) →286      (X ∈ openBall(C, D) → f(X) ∈ openBall(f(C), R)))287  requires positive : 0 < E288  shows ∃ Radius ∈ ℝ, 0 < Radius ∧ ∀ X ∈ ℝ, (X ∈ closedInterval(A, B) →289    ∀ Y ∈ ℝ, (Y ∈ closedInterval(A, B) →290      (X ∈ openBall(Y, Radius) → f(X) ∈ openBall(f(Y), E))))291proof292  have leftMember := closedInterval.left_mem with ordered293  have realA : A ∈ ℝ by simp [Real]294  have halfE := half.positive with positive295  have halfEReal := half.real at E296  have halfEMember : half(E) ∈ ℝ by simp [Real]297  have start : A ∈ uniformPrefixes(f, A, B, E)298    apply uniformPrefixes.membership.backward299    have oneMember := realOne.real300    unfold Real at oneMember301    refine ⟨realA, realOne, oneMember, realZero.lt_one, _⟩302    intros X xIn Y yIn xBelow yBelow near303    obtain ⟨realX, lowerX, upperX⟩ := closedInterval.membership.forward with xIn304    obtain ⟨realY, lowerY, upperY⟩ := closedInterval.membership.forward with yIn305    have sameX := realLe.antisymmetric with xBelow, lowerX306    have sameY := realLe.antisymmetric with yBelow, lowerY307    have imageA := values with A, leftMember308    have typedImage : Real(f(A)) by simp [Real]309    rw [sameX, sameY]310    exact openBall.center with typedImage, positive311  have extend : ∀ C ∈ closedInterval(A, B), ∃ D ∈ ℝ, 0 < D ∧312      ∀ Z ∈ closedInterval(A, B), (Z ∈ uniformPrefixes(f, A, B, E) →313        (C:R) - (D:R) < (Z:R) →314        ∀ W ∈ closedInterval(A, B), ((W:R) < (C:R) + (D:R) →315          W ∈ uniformPrefixes(f, A, B, E)))316    intros C cIn317    obtain ⟨realC, lowerC, upperC⟩ := closedInterval.membership.forward with cIn318    obtain ⟨R, realR, positiveR, maps⟩ :=319      local with C, realC, cIn, half(E), halfEMember, halfE320    have halfR := half.positive with positiveR321    have halfRReal := half.real at R322    have halfRMember : half(R) ∈ ℝ by simp [Real]323    have halvesR := half.add_self at R324    witness half(R)325    refine ⟨halfRMember, halfR, _⟩326    intros Z zIn zPrefix near W wIn wBelow327    obtain ⟨realZ, DZ, realDZ, positiveDZ, uniformZ⟩ :=328      uniformPrefixes.membership.forward with zPrefix329    obtain ⟨realW, lowerW, upperW⟩ := closedInterval.membership.forward with wIn330    obtain ⟨F, realF, positiveF, fDZ, fHalf⟩ :=331      realPositive.common_lower with positiveDZ, halfR332    apply uniformPrefixes.membership.backward333    refine ⟨realW, F, realF, positiveF, _⟩334    intros X xIn Y yIn xBelow yBelow nearXY335    obtain ⟨realX, lowerX, upperX⟩ := closedInterval.membership.forward with xIn336    obtain ⟨realY, lowerY, upperY⟩ := closedInterval.membership.forward with yIn337    have split : ((X:R) ≤ (Z:R) ∧ (Y:R) ≤ (Z:R)) ∨338        ¬((X:R) ≤ (Z:R) ∧ (Y:R) ≤ (Z:R)) by tauto339    cases split with both | notBoth340    . obtain ⟨xEarly, yEarly⟩ := both341      have wider := openBall.mono with nearXY, fDZ342      exact uniformZ with X, xIn, Y, yIn, xEarly, yEarly, wider343    . obtain ⟨lowerXY, upperXY⟩ := openBall.order_characterization.forward with nearXY344      have lows : C - R < X ∧ C - R < Y345        have early : (X:R) ≤ (Z:R) ∨ ¬((X:R) ≤ (Z:R)) by tauto346        cases early with xEarly | xLate347        . have yAfter : Z < Y348            by_contra notAfter349            have yEarly := realLe.of_not_less with notAfter350            apply notBoth351            exact ⟨xEarly, yEarly⟩352          constructor353          . linarith354          . linarith355        . have xAfter := realLess.of_not_le with xLate356          constructor357          . linarith358          . linarith359      obtain ⟨lowX, lowY⟩ := lows360      have nearXData : C - R < X ∧ X < C + R361        constructor362        . exact lowX363        . linarith364      have nearYData : C - R < Y ∧ Y < C + R365        constructor366        . exact lowY367        . linarith368      have nearX := openBall.order_characterization.backward with nearXData369      have nearY := openBall.order_characterization.backward with nearYData370      have mappedX := maps with X, realX, xIn, nearX371      have mappedY := maps with Y, realY, yIn, nearY372      have imageX := values with X, xIn373      have imageY := values with Y, yIn374      have imageC := values with C, cIn375      have typedX : Real(f(X)) by simp [Real]376      have typedY : Real(f(Y)) by simp [Real]377      have typedC : Real(f(C)) by simp [Real]378      have backY := openBall.symmetric.forward at f(Y), f(C), half(E) with379        typedY, typedC, halfEReal, mappedY380      have joined := openBall.triangle at f(X), f(C), f(Y), half(E), half(E) with381        typedX, typedC, typedY, halfEReal, halfEReal, mappedX, backY382      have halvesE := half.add_self at E383      rwa halvesE at joined384  have reached := closedInterval.real_induction with ordered, start, extend385  obtain ⟨realB, D, realD, positiveD, uniformB⟩ :=386    uniformPrefixes.membership.forward with reached387  witness D388  refine ⟨realD, positiveD, _⟩389  intros X realX xIn Y realY yIn near390  obtain ⟨memberX, lowerX, upperX⟩ := closedInterval.membership.forward with xIn391  obtain ⟨memberY, lowerY, upperY⟩ := closedInterval.membership.forward with yIn392  exact uniformB with X, xIn, Y, yIn, upperX, upperY, near393