Todd Waugh Ambridge, January 2024 # Global optimisation \begin{code} {-# OPTIONS --without-K --safe #-} open import MLTT.Spartan open import UF.FunExt open import Fin.Type open import Fin.Bishop module TWA.Thesis.Chapter4.GlobalOptimisation (fe : FunExt) where open import TWA.Thesis.Chapter3.ClosenessSpaces fe open import TWA.Thesis.Chapter4.ApproxOrder fe \end{code} ## Absolute global optimisation \begin{code} is-global-minimal : {X : π€ Μ } {Y : π₯ Μ } (_β€_ : Y β Y β π¦ Μ ) β (X β Y) β X β π€ β π¦ Μ is-global-minimal {π€} {π₯} {π¦'} {X} _β€_ f xβ = (x : X) β f xβ β€ f x has-global-minimal : {X : π€ Μ } {Y : π₯ Μ } (_β€_ : Y β Y β π¦ Μ ) β (X β Y) β π€ β π¦ Μ has-global-minimal f = Ξ£ β (is-global-minimal f) Fin-global-minimal : (n : β) β Fin n β {Y : π€ Μ } β (_β€_ : Y β Y β π¦ Μ ) β is-linear-preorder _β€_ β (f : Fin n β Y) β has-global-minimal _β€_ f Fin-global-minimal 1 π _β€_ (p , _) f = π , Ξ³ where Ξ³ : is-global-minimal _β€_ f π Ξ³ π = β€-reflβ¨ p β© (f π) Fin-global-minimal (succ (succ n)) x _β€_ l@(p , _) f with Fin-global-minimal (succ n) π _β€_ l (f β suc) ... | (x'β , m) = Cases (β€-linearβ¨ l β© (f (suc x'β)) (f π)) Ξ³β Ξ³β where Ξ³β : f (suc x'β) β€ f π β has-global-minimal _β€_ f Ξ³β x'ββ€π = suc x'β , Ξ³ where Ξ³ : (x : Fin (succ (succ n))) β f (suc x'β) β€ f x Ξ³ π = x'ββ€π Ξ³ (suc x) = m x Ξ³β : f π β€ f (suc x'β) β has-global-minimal _β€_ f Ξ³β πβ€x'β = π , Ξ³ where Ξ³ : (x : Fin (succ (succ n))) β f π β€ f x Ξ³ π = β€-reflβ¨ p β© (f π) Ξ³ (suc x) = β€-transβ¨ p β© (f π) (f (suc x'β)) (f (suc x)) πβ€x'β (m x) finite-global-minimal : {X : π€ Μ } {Y : π₯ Μ } β X β finite-linear-order X β (_β€_ : Y β Y β π¦ Μ ) β is-linear-preorder _β€_ β (f : X β Y) β has-global-minimal _β€_ f finite-global-minimal x (n , e@(g , _ , (h , ΞΌ))) _β€_ l f = h xβ , Ξ» x β transport (f (h xβ) β€_) (ap f (ΞΌ x)) (Ξ³β (g x)) where Ξ³ : has-global-minimal _β€_ (f β h) Ξ³ = Fin-global-minimal n (g x) _β€_ l (f β h) xβ : Fin n xβ = prβ Ξ³ Ξ³β : is-global-minimal _β€_ (f β h) xβ Ξ³β = prβ Ξ³ \end{code} ## Approximate global optimisation \begin{code} is_global-minimal : β β {π€ π₯ : Universe} β {X : π€ Μ } {Y : π₯ Μ } β (_β€βΏ_ : Y β Y β β β π¦ Μ ) β (f : X β Y) β X β π¦ β π€ Μ (is Ο΅ global-minimal) {π€} {π₯} {X} _β€βΏ_ f xβ = (x : X) β (f xβ β€βΏ f x) Ο΅ has_global-minimal : β β {π€ π₯ : Universe} {X : π€ Μ } β {Y : π₯ Μ } β (_β€βΏ_ : Y β Y β β β π¦ Μ ) β (f : X β Y) β (π¦ β π€) Μ (has Ο΅ global-minimal) {π€} {π₯} {π¦} {X} _β€βΏ_ f = Ξ£ ((is Ο΅ global-minimal) {π€} {π₯} {π¦} {X} _β€βΏ_ f) F-Ο΅-global-minimal : {X : π€ Μ } (Y : ClosenessSpace π₯) β X β finite-linear-order X β (_β€βΏ_ : β¨ Y β© β β¨ Y β© β β β π¦' Μ ) β is-approx-order Y _β€βΏ_ β (Ο΅ : β) β (f : X β β¨ Y β©) β (has Ο΅ global-minimal) _β€βΏ_ f F-Ο΅-global-minimal Y x l _β€βΏ_ a Ο΅ = finite-global-minimal x l (Ξ» x y β (x β€βΏ y) Ο΅) (β€βΏ-all-linear Y a Ο΅) \end{code} ## Global optimisation theorem \begin{code} cover-continuity-lemma : (X : ClosenessSpace π€) {X' : π€' Μ } (Y : ClosenessSpace π₯) β (_β€βΏ_ : β¨ Y β© β β¨ Y β© β β β π¦' Μ ) β is-approx-order Y _β€βΏ_ β (Ο΅ : β) β (f : β¨ X β© β β¨ Y β©) (Ο : f-ucontinuous X Y f) β let Ξ΄ = prβ (Ο Ο΅) in (((g , _) , _) : X' is Ξ΄ net-of X) β finite-linear-order X' β (x : β¨ X β©) β Ξ£ x' κ X' , (f (g x') β€βΏ f x) Ο΅ cover-continuity-lemma X Y _β€βΏ_ a Ο΅ f Ο ((g , h , Ξ·) , _) e x = h x , β€βΏ-close Y a Ο΅ (f (g (h x))) (f x) (C-sym Y Ο΅ (f x) (f (g (h x))) (prβ (Ο Ο΅) x (g (h x)) (Ξ· x))) global-opt : (X : ClosenessSpace π€) (Y : ClosenessSpace π₯) β β¨ X β© β (_β€βΏ_ : β¨ Y β© β β¨ Y β© β β β π¦' Μ ) β is-approx-order Y _β€βΏ_ β (Ο΅ : β) β (f : β¨ X β© β β¨ Y β©) (Ο : f-ucontinuous X Y f) β totally-bounded X π€' β (has Ο΅ global-minimal) _β€βΏ_ f global-opt {π€} {π₯} {π¦'} {π€'} X Y xβ _β€βΏ_ a Ο΅ f Ο t = (g x'β) , (Ξ» x β β€βΏ-trans Y a Ο΅ (f (g x'β)) (f (g (h x))) (f x) (m (h x)) (h-min x)) where Ξ΄ : β Ξ΄ = prβ (Ο Ο΅) X' : π€' Μ X' = prβ (t Ξ΄) X'-is-Ξ΄-net : X' is Ξ΄ net-of X X'-is-Ξ΄-net = prβ (t Ξ΄) X'-is-finite : finite-linear-order X' X'-is-finite = prβ X'-is-Ξ΄-net g : X' β β¨ X β© g = prβ (prβ X'-is-Ξ΄-net) h : β¨ X β© β X' h = prβ (prβ (prβ X'-is-Ξ΄-net)) Ξ· : (x : β¨ X β©) β Ξ£ x' κ X' , (f (g x') β€βΏ f x) Ο΅ Ξ· = cover-continuity-lemma X Y _β€βΏ_ a Ο΅ f Ο X'-is-Ξ΄-net X'-is-finite h-min : (x : β¨ X β©) β (f (g (h x)) β€βΏ f x) Ο΅ h-min x = prβ (Ξ· x) first : has Ο΅ global-minimal _β€βΏ_ (f β g) first = F-Ο΅-global-minimal Y (h xβ) X'-is-finite _β€βΏ_ a Ο΅ (f β g) x'β : X' x'β = prβ first m : is Ο΅ global-minimal _β€βΏ_ (f β g) x'β m = prβ first \end{code}