Grace/Cumulus/Real/Analysis/Locality.g17

Open in Workbench Download source

Imports

Differentiation · OpenIntervals

Declarations

Source

1-- Limits, continuity, and derivatives at a point depend only on the values2-- near the point: one-sided agreement with two functions that have the same3-- limit (gluing), and agreement on an open interval around the point.4-- Part of Cumulus, the Grace17 mathematics library.5-- Copyright (c) 2026 Grant Passmore.6-- Released under the Apache License 2.0. See LICENSE in the repository root.7-- Authors: Grant Passmore89module Grace.Cumulus.Real.Analysis.Locality10import Differentiation11import OpenIntervals1213-- A function equal to g on (B, A) and to h on (A, C), where g and h both14-- tend to L at A, tends to L at A.15theorem TendsToAt.glue (f g h : Set) (L A B C : Real)16  requires limitG : TendsToAt(g, L, A)17  requires limitH : TendsToAt(h, L, A)18  requires function : f : ℝ → ℝ19  requires below : B < A20  requires above : A < C21  requires left : ∀ x ∈ ℝ, B < x → x < A → f(x) = g(x)22  requires right : ∀ x ∈ ℝ, A < x → x < C → f(x) = h(x)23  shows TendsToAt(f, L, A)24proof25  refine ⟨function, ?_⟩26  intros e eMember positive27  obtain ⟨R, rMember, rPositive, mapsG⟩ := TendsToAt.eventually28    with limitG, positive29  obtain ⟨S, sMember, sPositive, mapsH⟩ := TendsToAt.eventually30    with limitH, positive31  have rReal : Real(R) by exact rMember32  have sReal : Real(S) by exact sMember33  have leftPositive : 0 < A - B by linarith34  have rightPositive : 0 < C - A by linarith35  obtain ⟨P, pMember, pPositive, pR, pS⟩ := positiveRadius.common36    with rPositive, sPositive37  obtain ⟨Q, qMember, qPositive, qLeft, qRight⟩ := positiveRadius.common38    with leftPositive, rightPositive39  have pReal : Real(P) by exact pMember40  have qReal : Real(Q) by exact qMember41  obtain ⟨d, dMember, dPositive, dP, dQ⟩ := positiveRadius.common42    with pPositive, qPositive43  refine ⟨d, dMember, dPositive, ?_⟩44  intros x xMember distinct near45  have xReal : Real(x) by exact xMember46  obtain ⟨_, distance⟩ := openBall.membership.forward with near47  have upper := abs.upper at x - A48  have lower := abs.upper_neg at x - A49  unfold dist at distance50  have order := realLess.trichotomy at x, A51  rcases order with smaller | equal | larger52  . have radius : d ≤ R by linarith53    have nearG := openBall.mono at x, A, d, R with near, radius54    have lowerX : B < x by linarith55    have value := left with x, xMember, lowerX, smaller56    rw value57    exact mapsG with x, xMember, distinct, nearG58  . exfalso59    exact distinct with equal60  . have radius : d ≤ S by linarith61    have nearH := openBall.mono at x, A, d, S with near, radius62    have upperX : x < C by linarith63    have value := right with x, xMember, larger, upperX64    rw value65    exact mapsH with x, xMember, distinct, nearH6667-- Limits are local: functions equal on an open interval around A, except68-- perhaps at A, have the same limits at A.69theorem TendsToAt.congr_local (f g : Set) (L A B C : Real)70  requires limit : TendsToAt(g, L, A)71  requires function : f : ℝ → ℝ72  requires below : B < A73  requires above : A < C74  requires agree : ∀ x ∈ openInterval(B, C), x ≠ A → f(x) = g(x)75  shows TendsToAt(f, L, A)76proof77  have side : ∀ x ∈ ℝ, B < x → x < C → x ≠ A → f(x) = g(x)78    intros x xMember lower upper distinct79    have inside := openInterval.membership.backward80      with ⟨xMember, lower, upper⟩81    exact agree with x, inside, distinct82  have left : ∀ x ∈ ℝ, B < x → x < A → f(x) = g(x)83    intros x xMember lower upper84    have xReal : Real(x) by exact xMember85    have within : x < C by linarith86    have distinct : x ≠ A by linarith87    exact side with x, xMember, lower, within, distinct88  have right : ∀ x ∈ ℝ, A < x → x < C → f(x) = g(x)89    intros x xMember lower upper90    have xReal : Real(x) by exact xMember91    have within : B < x by linarith92    have distinct : x ≠ A by linarith93    exact side with x, xMember, within, upper, distinct94  exact TendsToAt.glue with limit, limit, function, below, above, left, right9596theorem TendsToAt.local_iff (f g : Set) (L A B C : Real)97  requires functionF : f : ℝ → ℝ98  requires functionG : g : ℝ → ℝ99  requires below : B < A100  requires above : A < C101  requires agree : ∀ x ∈ openInterval(B, C), x ≠ A → f(x) = g(x)102  shows TendsToAt(f, L, A) ↔ TendsToAt(g, L, A)103proof104  have symmetric : ∀ x ∈ openInterval(B, C), x ≠ A → g(x) = f(x)105    intros x inside distinct106    have value := agree with x, inside, distinct107    rw value108  constructor109  . intro limit110    exact TendsToAt.congr_local with limit, functionG, below, above,111      symmetric112  . intro limit113    exact TendsToAt.congr_local with limit, functionF, below, above, agree114115-- A function equal to g on (B, A] and to h on [A, C), both continuous at116-- A, is continuous at A.117theorem ContinuousAt.glue (f g h : Set) (A B C : Real)118  requires continuousG : ContinuousAt(g, A)119  requires continuousH : ContinuousAt(h, A)120  requires function : f : ℝ → ℝ121  requires below : B < A122  requires above : A < C123  requires left : ∀ x ∈ ℝ, B < x → x ≤ A → f(x) = g(x)124  requires right : ∀ x ∈ ℝ, A ≤ x → x < C → f(x) = h(x)125  shows ContinuousAt(f, A)126proof127  have aMember : A ∈ ℝ by typecheck128  have leftOpen : ∀ x ∈ ℝ, B < x → x < A → f(x) = g(x)129    intros x xMember lower upper130    have xReal : Real(x) by exact xMember131    have weak : x ≤ A by linarith132    exact left with x, xMember, lower, weak133  have rightOpen : ∀ x ∈ ℝ, A < x → x < C → f(x) = h(x)134    intros x xMember lower upper135    have xReal : Real(x) by exact xMember136    have weak : A ≤ x by linarith137    exact right with x, xMember, weak, upper138  have reflexive := realLe.reflexive at A139  have atG := left with A, aMember, below, reflexive140  have atH := right with A, aMember, reflexive, above141  have limitG := ContinuousAt.tends_to with continuousG142  have limitH := ContinuousAt.tends_to with continuousH143  rw [← atG] at limitG144  rw [← atH] at limitH145  have limit := TendsToAt.glue with limitG, limitH, function, below, above,146    leftOpen, rightOpen147  exact TendsToAt.continuous_at with limit, rfl148149-- Continuity is local: functions equal on an open interval around A are150-- continuous at A together.151theorem ContinuousAt.local_iff (f g : Set) (A B C : Real)152  requires functionF : f : ℝ → ℝ153  requires functionG : g : ℝ → ℝ154  requires below : B < A155  requires above : A < C156  requires agree : ∀ x ∈ openInterval(B, C), f(x) = g(x)157  shows ContinuousAt(f, A) ↔ ContinuousAt(g, A)158proof159  have forward : ∀ x ∈ ℝ, B < x → x < C → f(x) = g(x)160    intros x xMember lower upper161    have inside := openInterval.membership.backward162      with ⟨xMember, lower, upper⟩163    exact agree with x, inside164  have backward : ∀ x ∈ ℝ, B < x → x < C → g(x) = f(x)165    intros x xMember lower upper166    have value := forward with x, xMember, lower, upper167    rw value168  constructor169  . intro continuous170    have left : ∀ x ∈ ℝ, B < x → x ≤ A → g(x) = f(x)171      intros x xMember lower upper172      have xReal : Real(x) by exact xMember173      have within : x < C by linarith174      exact backward with x, xMember, lower, within175    have right : ∀ x ∈ ℝ, A ≤ x → x < C → g(x) = f(x)176      intros x xMember lower upper177      have xReal : Real(x) by exact xMember178      have within : B < x by linarith179      exact backward with x, xMember, within, upper180    exact ContinuousAt.glue with continuous, continuous, functionG, below,181      above, left, right182  . intro continuous183    have left : ∀ x ∈ ℝ, B < x → x ≤ A → f(x) = g(x)184      intros x xMember lower upper185      have xReal : Real(x) by exact xMember186      have within : x < C by linarith187      exact forward with x, xMember, lower, within188    have right : ∀ x ∈ ℝ, A ≤ x → x < C → f(x) = g(x)189      intros x xMember lower upper190      have xReal : Real(x) by exact xMember191      have within : B < x by linarith192      exact forward with x, xMember, within, upper193    exact ContinuousAt.glue with continuous, continuous, functionF, below,194      above, left, right195196-- A function equal to g on (B, A] and to h on [A, C), where g and h both197-- have derivative D at A, has derivative D at A.198theorem HasDerivativeAt.glue (f g h : Set) (D A B C : Real)199  requires derivativeG : HasDerivativeAt(g, D, A)200  requires derivativeH : HasDerivativeAt(h, D, A)201  requires function : f : ℝ → ℝ202  requires below : B < A203  requires above : A < C204  requires left : ∀ x ∈ ℝ, B < x → x ≤ A → f(x) = g(x)205  requires right : ∀ x ∈ ℝ, A ≤ x → x < C → f(x) = h(x)206  shows HasDerivativeAt(f, D, A)207proof208  have gFunction := HasDerivativeAt.function with derivativeG209  have hFunction := HasDerivativeAt.function with derivativeH210  have limitG := HasDerivativeAt.limit with derivativeG211  have limitH := HasDerivativeAt.limit with derivativeH212  have quotient := differenceQuotient.function at f, A with function213  have aMember : A ∈ ℝ by typecheck214  have reflexive := realLe.reflexive at A215  have atG := left with A, aMember, below, reflexive216  have atH := right with A, aMember, reflexive, above217  have leftShift : ∀ t ∈ ℝ, B - A < t → t < realZero →218      differenceQuotient(f, A)(t) = differenceQuotient(g, A)(t)219    intros t tMember lower upper220    have tReal : Real(t) by exact tMember221    have moved : A + t ∈ ℝ by typecheck222    have lowerMoved : B < A + t by linarith223    have upperMoved : A + t ≤ A by linarith224    have value := left with A + t, moved, lowerMoved, upperMoved225    have quotientF := differenceQuotient.value at f, A, t with function226    have quotientG := differenceQuotient.value at g, A, t with gFunction227    rw [quotientF, quotientG, value, atG]228  have rightShift : ∀ t ∈ ℝ, realZero < t → t < C - A →229      differenceQuotient(f, A)(t) = differenceQuotient(h, A)(t)230    intros t tMember lower upper231    have tReal : Real(t) by exact tMember232    have moved : A + t ∈ ℝ by typecheck233    have lowerMoved : A ≤ A + t by linarith234    have upperMoved : A + t < C by linarith235    have value := right with A + t, moved, lowerMoved, upperMoved236    have quotientF := differenceQuotient.value at f, A, t with function237    have quotientH := differenceQuotient.value at h, A, t with hFunction238    rw [quotientF, quotientH, value, atH]239  have shiftedBelow : B - A < realZero by linarith240  have shiftedAbove : realZero < C - A by linarith241  have limit := TendsToAt.glue with limitG, limitH, quotient, shiftedBelow,242    shiftedAbove, leftShift, rightShift243  refine ⟨function, limit⟩244245-- Derivatives are local: functions equal on an open interval around A have246-- the same derivatives at A.247theorem HasDerivativeAt.local_iff (f g : Set) (D A B C : Real)248  requires functionF : f : ℝ → ℝ249  requires functionG : g : ℝ → ℝ250  requires below : B < A251  requires above : A < C252  requires agree : ∀ x ∈ openInterval(B, C), f(x) = g(x)253  shows HasDerivativeAt(f, D, A) ↔ HasDerivativeAt(g, D, A)254proof255  have forward : ∀ x ∈ ℝ, B < x → x < C → f(x) = g(x)256    intros x xMember lower upper257    have inside := openInterval.membership.backward258      with ⟨xMember, lower, upper⟩259    exact agree with x, inside260  have backward : ∀ x ∈ ℝ, B < x → x < C → g(x) = f(x)261    intros x xMember lower upper262    have value := forward with x, xMember, lower, upper263    rw value264  constructor265  . intro derivative266    have left : ∀ x ∈ ℝ, B < x → x ≤ A → g(x) = f(x)267      intros x xMember lower upper268      have xReal : Real(x) by exact xMember269      have within : x < C by linarith270      exact backward with x, xMember, lower, within271    have right : ∀ x ∈ ℝ, A ≤ x → x < C → g(x) = f(x)272      intros x xMember lower upper273      have xReal : Real(x) by exact xMember274      have within : B < x by linarith275      exact backward with x, xMember, within, upper276    exact HasDerivativeAt.glue with derivative, derivative, functionG, below,277      above, left, right278  . intro derivative279    have left : ∀ x ∈ ℝ, B < x → x ≤ A → f(x) = g(x)280      intros x xMember lower upper281      have xReal : Real(x) by exact xMember282      have within : x < C by linarith283      exact forward with x, xMember, lower, within284    have right : ∀ x ∈ ℝ, A ≤ x → x < C → f(x) = g(x)285      intros x xMember lower upper286      have xReal : Real(x) by exact xMember287      have within : B < x by linarith288      exact forward with x, xMember, within, upper289    exact HasDerivativeAt.glue with derivative, derivative, functionF, below,290      above, left, right291