Todd Waugh Ambridge, January 2024 # Ternary signed-digit encodings' suitability for search, optimisation and regression \begin{code} {-# OPTIONS --without-K --safe #-} open import MLTT.Spartan open import UF.DiscreteAndSeparated open import UF.Subsingletons open import UF.FunExt open import MLTT.Two-Properties open import UF.SubtypeClassifier module TWA.Thesis.Chapter6.SignedDigitSearch (fe : FunExt) (pe : PropExt) where open import TWA.Thesis.Chapter2.Finite open import TWA.Thesis.Chapter2.Sequences open import TWA.Thesis.Chapter3.ClosenessSpaces fe hiding (decidable-predicate;decidable-uc-predicate) open import TWA.Thesis.Chapter3.ClosenessSpaces-Examples fe open import TWA.Thesis.Chapter3.SearchableTypes fe open import TWA.Thesis.Chapter3.SearchableTypes-Examples fe pe open import TWA.Thesis.Chapter4.ApproxOrder fe open import TWA.Thesis.Chapter4.ApproxOrder-Examples fe open import TWA.Thesis.Chapter4.GlobalOptimisation fe open import TWA.Thesis.Chapter5.SignedDigit open import TWA.Thesis.Chapter6.SequenceContinuity fe open import TWA.Thesis.Chapter6.SignedDigitOrder fe \end{code} ## Totally bounded \begin{code} πα΄Ί-totally-bounded : totally-bounded πα΄Ί-ClosenessSpace π€β πα΄Ί-totally-bounded = ββF-totally-bounded π-is-discrete π-is-finite O πα΄ΊΓπα΄Ί-totally-bounded : totally-bounded πα΄ΊΓπα΄Ί-ClosenessSpace π€β πα΄ΊΓπα΄Ί-totally-bounded = Γ-totally-bounded πα΄Ί-ClosenessSpace πα΄Ί-ClosenessSpace πα΄Ί-totally-bounded πα΄Ί-totally-bounded \end{code} ## Global optimisation \begin{code} πα΄Ίβπα΄Ί-global-opt : (f : πα΄Ί β πα΄Ί) β f-ucontinuous πα΄Ί-ClosenessSpace πα΄Ί-ClosenessSpace f β (Ο΅ : β) β (has Ο΅ global-minimal) _β€βΏπα΄Ί_ f πα΄Ίβπα΄Ί-global-opt f Ο Ο΅ = global-opt πα΄Ί-ClosenessSpace πα΄Ί-ClosenessSpace (repeat O) _β€βΏπα΄Ί_ β€βΏπα΄Ί-is-approx-order Ο΅ f Ο πα΄Ί-totally-bounded \end{code} ## Uniformly continuously searchable \begin{code} πα΄Ί-csearchable-tb πα΄Ί-csearchable : {π¦ : Universe} β csearchable π¦ πα΄Ί-ClosenessSpace πα΄Ί-csearchable-tb = totally-bounded-csearchable πα΄Ί-ClosenessSpace (repeat O) πα΄Ί-totally-bounded πα΄Ί-csearchable = discrete-finite-seq-csearchable O π-is-finite π-is-discrete πα΄ΊΓπα΄Ί-csearchable-tb πα΄ΊΓπα΄Ί-csearchable : {π¦ : Universe} β csearchable π¦ πα΄ΊΓπα΄Ί-ClosenessSpace πα΄ΊΓπα΄Ί-csearchable-tb = totally-bounded-csearchable πα΄ΊΓπα΄Ί-ClosenessSpace (repeat O , repeat O) πα΄ΊΓπα΄Ί-totally-bounded πα΄ΊΓπα΄Ί-csearchable = Γ-csearchable πα΄Ί-ClosenessSpace πα΄Ί-ClosenessSpace πα΄Ί-csearchable πα΄Ί-csearchable \end{code} ## Cantor space search and optimisation \begin{code} β€β-is-preorder : is-preorder _β€β_ β€β-is-preorder = (Ξ» _ β β€β-refl) , β€β-trans , Ξ» _ _ β β€β-is-prop-valued β€β-is-antisym-preorder : is-partial-order _β€β_ β€β-is-antisym-preorder = β€β-is-preorder , Ξ» _ _ β β€β-anti β€β-is-antisym-linear-preorder : is-linear-order _β€β_ β€β-is-antisym-linear-preorder = β€β-is-antisym-preorder , β€β-linear where β€β-linear : linear _β€β_ β€β-linear β _ = inl β β€β-linear β β = inr β β€β-linear β β = inl β πα΄Ί : π€β Μ πα΄Ί = β β π πα΄Ί-lexicorder : πα΄Ί β πα΄Ί β π€β Μ πα΄Ί-lexicorder = discrete-lexicorder π-is-discrete _β€β_ πα΄Ί-lexicorder-is-preorder : is-preorder πα΄Ί-lexicorder πα΄Ί-lexicorder-is-preorder = discrete-lexicorder-is-preorder π-is-discrete _β€β_ β€β-is-antisym-preorder πα΄Ί-approx-lexicorder : πα΄Ί β πα΄Ί β β β π€β Μ πα΄Ί-approx-lexicorder = discrete-approx-lexicorder π-is-discrete _β€β_ πα΄Ί-approx-lexicorder-is-approx-order : is-approx-order πα΄Ί-ClosenessSpace πα΄Ί-approx-lexicorder πα΄Ί-approx-lexicorder-is-approx-order = discrete-approx-lexicorder-is-approx-order π-is-discrete _β€β_ β€β-is-antisym-linear-preorder πα΄Ί-approx-lexicorder' : πα΄Ί β πα΄Ί β β β Ξ© π€β πα΄Ί-approx-lexicorder' Ξ± Ξ² n = πα΄Ί-approx-lexicorder Ξ± Ξ² n , β€βΏ-prop πα΄Ί-ClosenessSpace πα΄Ί-approx-lexicorder-is-approx-order n Ξ± Ξ² πα΄Ί-totally-bounded : totally-bounded πα΄Ί-ClosenessSpace π€β πα΄Ί-totally-bounded = ββF-totally-bounded π-is-discrete π-is-finite β πα΄ΊΓπα΄Ί-totally-bounded : totally-bounded πα΄ΊΓπα΄Ί-ClosenessSpace π€β πα΄ΊΓπα΄Ί-totally-bounded = Γ-totally-bounded πα΄Ί-ClosenessSpace πα΄Ί-ClosenessSpace πα΄Ί-totally-bounded πα΄Ί-totally-bounded πα΄Ίβπα΄Ί-global-opt : (f : πα΄Ί β πα΄Ί) β f-ucontinuous πα΄Ί-ClosenessSpace πα΄Ί-ClosenessSpace f β (Ο΅ : β) β (has Ο΅ global-minimal) _β€βΏπα΄Ί_ f πα΄Ίβπα΄Ί-global-opt f Ο Ο΅ = global-opt πα΄Ί-ClosenessSpace πα΄Ί-ClosenessSpace (repeat β) _β€βΏπα΄Ί_ β€βΏπα΄Ί-is-approx-order Ο΅ f Ο πα΄Ί-totally-bounded πα΄Ί-csearchable-tb πα΄Ί-csearchable : {π¦ : Universe} β csearchable π¦ πα΄Ί-ClosenessSpace πα΄Ί-csearchable-tb = totally-bounded-csearchable πα΄Ί-ClosenessSpace (repeat β) πα΄Ί-totally-bounded πα΄Ί-csearchable = discrete-finite-seq-csearchable β π-is-finite π-is-discrete πα΄ΊΓπα΄Ί-csearchable-tb πα΄ΊΓπα΄Ί-csearchable : {π¦ : Universe} β csearchable π¦ πα΄ΊΓπα΄Ί-ClosenessSpace πα΄ΊΓπα΄Ί-csearchable-tb = totally-bounded-csearchable πα΄ΊΓπα΄Ί-ClosenessSpace (repeat β , repeat β) πα΄ΊΓπα΄Ί-totally-bounded πα΄ΊΓπα΄Ί-csearchable = Γ-csearchable πα΄Ί-ClosenessSpace πα΄Ί-ClosenessSpace πα΄Ί-csearchable πα΄Ί-csearchable \end{code} ## Conversion from Cantor sequence to ternary signed-digit encoding \begin{code} πβπ : π β π πβπ β = β1 πβπ β = +1 _β : πα΄Ί β πα΄Ί _β = map πβπ _β€ : πα΄Ί Γ πα΄Ί β πα΄Ί Γ πα΄Ί _β€ (Ξ± , Ξ²) = Ξ± β , Ξ² β β-ucontinuous : f-ucontinuous πα΄Ί-ClosenessSpace πα΄Ί-ClosenessSpace _β β-ucontinuous = seq-f-ucontinuousΒΉ-to-closeness π-is-discrete π-is-discrete _β (map-ucontinuous' πβπ) β€-ucontinuous : f-ucontinuous πα΄ΊΓπα΄Ί-ClosenessSpace πα΄ΊΓπα΄Ί-ClosenessSpace _β€ β€-ucontinuous Ο΅ = Ο΅ , (Ξ» xβ xβ Cxβxβ β Γ-C-combine πα΄Ί-ClosenessSpace πα΄Ί-ClosenessSpace (prβ (xβ β€)) (prβ (xβ β€)) (prβ (xβ β€)) (prβ (xβ β€)) Ο΅ (prβ (β-ucontinuous Ο΅) (prβ xβ) (prβ xβ) (Γ-C-left πα΄Ί-ClosenessSpace πα΄Ί-ClosenessSpace (prβ xβ) (prβ xβ) (prβ xβ) (prβ xβ) Ο΅ Cxβxβ)) (prβ (β-ucontinuous Ο΅) (prβ xβ) (prβ xβ) (Γ-C-right πα΄Ί-ClosenessSpace πα΄Ί-ClosenessSpace (prβ xβ) (prβ xβ) (prβ xβ) (prβ xβ) Ο΅ Cxβxβ))) β-pred : decidable-uc-predicate π¦ πα΄Ί-ClosenessSpace β decidable-uc-predicate π¦ πα΄Ί-ClosenessSpace β-pred ((p , d) , Ο) = (p β _β , d β _β) , p-ucontinuous-comp πα΄Ί-ClosenessSpace πα΄Ί-ClosenessSpace _β β-ucontinuous p Ο β€-pred : decidable-uc-predicate π¦ πα΄ΊΓπα΄Ί-ClosenessSpace β decidable-uc-predicate π¦ πα΄ΊΓπα΄Ί-ClosenessSpace β€-pred ((p , d) , Ο) = (p β _β€ , d β _β€) , p-ucontinuous-comp πα΄ΊΓπα΄Ί-ClosenessSpace πα΄ΊΓπα΄Ί-ClosenessSpace _β€ β€-ucontinuous p Ο \end{code}