| 
									
										
										
										
											2023-04-04 21:08:31 -07:00
										 |  |  |  | module Lattice where
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-02 20:36:12 -07:00
										 |  |  |  | open import Equivalence
 | 
					
						
							| 
									
										
										
										
											2023-09-03 21:05:57 -07:00
										 |  |  |  | import Chain
 | 
					
						
							| 
									
										
										
										
											2023-09-02 20:36:12 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-06 23:08:49 -07:00
										 |  |  |  | import Data.Nat.Properties as NatProps
 | 
					
						
							| 
									
										
										
										
											2023-09-03 23:56:39 -07:00
										 |  |  |  | open import Relation.Binary.PropositionalEquality as Eq using (_≡_; sym; subst)
 | 
					
						
							|  |  |  |  | open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; step-≡; _∎)
 | 
					
						
							| 
									
										
										
										
											2023-04-04 21:08:31 -07:00
										 |  |  |  | open import Relation.Binary.Definitions
 | 
					
						
							| 
									
										
										
										
											2023-09-03 21:05:57 -07:00
										 |  |  |  | open import Relation.Binary.Core using (_Preserves_⟶_ )
 | 
					
						
							| 
									
										
										
										
											2023-09-03 23:56:39 -07:00
										 |  |  |  | open import Relation.Nullary using (Dec; ¬_; yes; no)
 | 
					
						
							|  |  |  |  | open import Data.Nat as Nat using (ℕ; _≤_; _+_; suc)
 | 
					
						
							| 
									
										
										
										
											2023-08-20 21:53:27 -07:00
										 |  |  |  | open import Data.Product using (_×_; Σ; _,_; proj₁; proj₂)
 | 
					
						
							| 
									
										
										
										
											2023-07-13 21:50:27 -07:00
										 |  |  |  | open import Data.Sum using (_⊎_; inj₁; inj₂)
 | 
					
						
							| 
									
										
										
										
											2023-08-20 20:49:08 -07:00
										 |  |  |  | open import Agda.Primitive using (lsuc; Level) renaming (_⊔_ to _⊔ℓ_)
 | 
					
						
							|  |  |  |  | open import Function.Definitions using (Injective)
 | 
					
						
							| 
									
										
										
										
											2023-09-03 23:56:39 -07:00
										 |  |  |  | open import Data.Empty using (⊥)
 | 
					
						
							| 
									
										
										
										
											2023-04-04 21:08:31 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-03 23:56:39 -07:00
										 |  |  |  | absurd : ∀ {a} {A : Set a} →  ⊥ → A
 | 
					
						
							|  |  |  |  | absurd ()
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | record IsDecidable {a} {A : Set a} (R : A → A → Set a) : Set a where
 | 
					
						
							| 
									
										
										
										
											2023-08-20 18:35:57 -07:00
										 |  |  |  |     field
 | 
					
						
							|  |  |  |  |         R-dec : ∀ (a₁ a₂ : A) → Dec (R a₁ a₂)
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  | record IsSemilattice {a} (A : Set a)
 | 
					
						
							|  |  |  |  |     (_≈_ : A → A → Set a)
 | 
					
						
							|  |  |  |  |     (_⊔_ : A → A → A) : Set a where
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 19:57:26 -07:00
										 |  |  |  |     _≼_ : A → A → Set a
 | 
					
						
							|  |  |  |  |     a ≼ b = Σ A (λ c → (a ⊔ c) ≈ b)
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     _≺_ : A → A → Set a
 | 
					
						
							|  |  |  |  |     a ≺ b = (a ≼ b) × (¬ a ≈ b)
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-06 23:08:49 -07:00
										 |  |  |  |     field
 | 
					
						
							| 
									
										
										
										
											2023-07-15 15:16:51 -07:00
										 |  |  |  |         ≈-equiv : IsEquivalence A _≈_
 | 
					
						
							| 
									
										
										
										
											2023-09-03 17:08:37 -07:00
										 |  |  |  |         ≈-⊔-cong : ∀ {a₁ a₂ a₃ a₄} → a₁ ≈ a₂ → a₃ ≈ a₄ → (a₁ ⊔ a₃) ≈ (a₂ ⊔ a₄)
 | 
					
						
							| 
									
										
										
										
											2023-07-15 15:16:51 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |         ⊔-assoc : (x y z : A) → ((x ⊔ y) ⊔ z) ≈ (x ⊔ (y ⊔ z))
 | 
					
						
							|  |  |  |  |         ⊔-comm : (x y : A) → (x ⊔ y) ≈ (y ⊔ x)
 | 
					
						
							|  |  |  |  |         ⊔-idemp : (x : A) → (x ⊔ x) ≈ x
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-03 19:33:04 -07:00
										 |  |  |  |     open IsEquivalence ≈-equiv public
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 21:53:27 -07:00
										 |  |  |  |     ≼-refl : ∀ (a : A) → a ≼ a
 | 
					
						
							|  |  |  |  |     ≼-refl a = (a , ⊔-idemp a)
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-03 19:33:04 -07:00
										 |  |  |  |     ≼-cong : ∀ {a₁ a₂ a₃ a₄ : A} → a₁ ≈ a₂ → a₃ ≈ a₄ → a₁ ≼ a₃ → a₂ ≼ a₄
 | 
					
						
							|  |  |  |  |     ≼-cong a₁≈a₂ a₃≈a₄ (c₁ , a₁⊔c₁≈a₃) = (c₁ , ≈-trans (≈-⊔-cong (≈-sym a₁≈a₂) ≈-refl) (≈-trans a₁⊔c₁≈a₃ a₃≈a₄))
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     ≺-cong : ∀ {a₁ a₂ a₃ a₄ : A} → a₁ ≈ a₂ → a₃ ≈ a₄ → a₁ ≺ a₃ → a₂ ≺ a₄
 | 
					
						
							|  |  |  |  |     ≺-cong a₁≈a₂ a₃≈a₄ (a₁≼a₃ , a₁̷≈a₃) =
 | 
					
						
							|  |  |  |  |         ( ≼-cong a₁≈a₂ a₃≈a₄ a₁≼a₃
 | 
					
						
							|  |  |  |  |         , λ a₂≈a₄ → a₁̷≈a₃ (≈-trans a₁≈a₂ (≈-trans a₂≈a₄ (≈-sym a₃≈a₄)))
 | 
					
						
							|  |  |  |  |         )
 | 
					
						
							| 
									
										
										
										
											2023-07-15 15:16:51 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  | record IsLattice {a} (A : Set a)
 | 
					
						
							|  |  |  |  |     (_≈_ : A → A → Set a)
 | 
					
						
							|  |  |  |  |     (_⊔_ : A → A → A)
 | 
					
						
							|  |  |  |  |     (_⊓_ : A → A → A) : Set a where
 | 
					
						
							| 
									
										
										
										
											2023-04-04 21:08:31 -07:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     field
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |         joinSemilattice : IsSemilattice A _≈_ _⊔_
 | 
					
						
							|  |  |  |  |         meetSemilattice : IsSemilattice A _≈_ _⊓_
 | 
					
						
							| 
									
										
										
										
											2023-04-06 23:08:49 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |         absorb-⊔-⊓ : (x y : A) → (x ⊔ (x ⊓ y)) ≈ x
 | 
					
						
							|  |  |  |  |         absorb-⊓-⊔ : (x y : A) → (x ⊓ (x ⊔ y)) ≈ x
 | 
					
						
							| 
									
										
										
										
											2023-04-04 21:08:31 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-06 23:08:49 -07:00
										 |  |  |  |     open IsSemilattice joinSemilattice public
 | 
					
						
							| 
									
										
										
										
											2023-08-20 19:57:26 -07:00
										 |  |  |  |     open IsSemilattice meetSemilattice public using () renaming
 | 
					
						
							| 
									
										
										
										
											2023-04-06 23:08:49 -07:00
										 |  |  |  |         ( ⊔-assoc to ⊓-assoc
 | 
					
						
							|  |  |  |  |         ; ⊔-comm to ⊓-comm
 | 
					
						
							|  |  |  |  |         ; ⊔-idemp to ⊓-idemp
 | 
					
						
							| 
									
										
										
										
											2023-09-03 17:08:37 -07:00
										 |  |  |  |         ; ≈-⊔-cong to ≈-⊓-cong
 | 
					
						
							| 
									
										
										
										
											2023-08-20 21:53:27 -07:00
										 |  |  |  |         ; _≼_ to _≽_
 | 
					
						
							|  |  |  |  |         ; _≺_ to _≻_
 | 
					
						
							|  |  |  |  |         ; ≼-refl to ≽-refl
 | 
					
						
							| 
									
										
										
										
											2023-04-06 23:08:49 -07:00
										 |  |  |  |         )
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 18:35:57 -07:00
										 |  |  |  | record IsFiniteHeightLattice {a} (A : Set a)
 | 
					
						
							|  |  |  |  |     (h : ℕ)
 | 
					
						
							|  |  |  |  |     (_≈_ : A → A → Set a)
 | 
					
						
							|  |  |  |  |     (_⊔_ : A → A → A)
 | 
					
						
							|  |  |  |  |     (_⊓_ : A → A → A) : Set (lsuc a) where
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     field
 | 
					
						
							|  |  |  |  |         isLattice : IsLattice A _≈_ _⊔_ _⊓_
 | 
					
						
							| 
									
										
										
										
											2023-09-03 21:05:57 -07:00
										 |  |  |  |         fixedHeight : Chain.Height (_≈_) (IsLattice.≈-equiv isLattice) (IsLattice._≺_ isLattice) (IsLattice.≺-cong isLattice) h
 | 
					
						
							| 
									
										
										
										
											2023-08-20 18:35:57 -07:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     open IsLattice isLattice public
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-03 19:33:04 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 20:49:08 -07:00
										 |  |  |  | module _ {a b} {A : Set a} {B : Set b}
 | 
					
						
							| 
									
										
										
										
											2023-08-20 21:53:27 -07:00
										 |  |  |  |     (_≼₁_ : A → A → Set a) (_≼₂_ : B → B → Set b) where
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     Monotonic : (A → B) → Set (a ⊔ℓ b)
 | 
					
						
							|  |  |  |  |     Monotonic f = ∀ {a₁ a₂ : A} → a₁ ≼₁ a₂ → f a₁ ≼₂ f a₂
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | module ChainMapping {a b} {A : Set a} {B : Set b}
 | 
					
						
							|  |  |  |  |     {_≈₁_ : A → A → Set a} {_≈₂_ : B → B → Set b}
 | 
					
						
							|  |  |  |  |     {_⊔₁_ : A → A → A} {_⊔₂_ : B → B → B}
 | 
					
						
							| 
									
										
										
										
											2023-08-20 20:49:08 -07:00
										 |  |  |  |     (slA : IsSemilattice A _≈₁_ _⊔₁_) (slB : IsSemilattice B _≈₂_ _⊔₂_) where
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-03 21:05:57 -07:00
										 |  |  |  |     open IsSemilattice slA renaming (_≼_ to _≼₁_; _≺_ to _≺₁_; ≈-equiv to ≈₁-equiv; ≺-cong to ≺₁-cong)
 | 
					
						
							|  |  |  |  |     open IsSemilattice slB renaming (_≼_ to _≼₂_; _≺_ to _≺₂_; ≈-equiv to ≈₂-equiv; ≺-cong to ≺₂-cong)
 | 
					
						
							| 
									
										
										
										
											2023-08-20 20:49:08 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-03 21:05:57 -07:00
										 |  |  |  |     open Chain _≈₁_ ≈₁-equiv _≺₁_ ≺₁-cong using () renaming (Chain to Chain₁; step to step₁; done to done₁)
 | 
					
						
							|  |  |  |  |     open Chain _≈₂_ ≈₂-equiv _≺₂_ ≺₂-cong using () renaming (Chain to Chain₂; step to step₂; done to done₂)
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     Chain-map : ∀ (f : A → B) →
 | 
					
						
							|  |  |  |  |                 Monotonic _≼₁_ _≼₂_ f →
 | 
					
						
							|  |  |  |  |                 Injective _≈₁_ _≈₂_ f →
 | 
					
						
							|  |  |  |  |                 f Preserves _≈₁_ ⟶  _≈₂_ →
 | 
					
						
							|  |  |  |  |                 ∀ {a₁ a₂ : A} {n : ℕ} → Chain₁ a₁ a₂ n → Chain₂ (f a₁) (f a₂) n
 | 
					
						
							|  |  |  |  |     Chain-map f Monotonicᶠ Injectiveᶠ Preservesᶠ (done₁ a₁≈a₂) =
 | 
					
						
							|  |  |  |  |         done₂ (Preservesᶠ a₁≈a₂)
 | 
					
						
							|  |  |  |  |     Chain-map f Monotonicᶠ Injectiveᶠ Preservesᶠ (step₁ (a₁≼₁a , a₁̷≈₁a) a≈₁a' a'a₂) =
 | 
					
						
							| 
									
										
										
										
											2023-08-20 20:49:08 -07:00
										 |  |  |  |         let fa₁≺₂fa = (Monotonicᶠ a₁≼₁a , λ fa₁≈₂fa → a₁̷≈₁a (Injectiveᶠ fa₁≈₂fa))
 | 
					
						
							| 
									
										
										
										
											2023-09-03 21:05:57 -07:00
										 |  |  |  |             fa≈fa' = Preservesᶠ a≈₁a'
 | 
					
						
							|  |  |  |  |         in step₂ fa₁≺₂fa fa≈fa' (Chain-map f Monotonicᶠ Injectiveᶠ Preservesᶠ a'a₂)
 | 
					
						
							| 
									
										
										
										
											2023-08-20 20:49:08 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-15 13:12:21 -07:00
										 |  |  |  | record Semilattice {a} (A : Set a) : Set (lsuc a) where
 | 
					
						
							|  |  |  |  |     field
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |         _≈_ : A → A → Set a
 | 
					
						
							| 
									
										
										
										
											2023-07-15 13:12:21 -07:00
										 |  |  |  |         _⊔_ : A → A → A
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |         isSemilattice : IsSemilattice A _≈_ _⊔_
 | 
					
						
							| 
									
										
										
										
											2023-07-15 13:12:21 -07:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     open IsSemilattice isSemilattice public
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-06 23:08:49 -07:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | record Lattice {a} (A : Set a) : Set (lsuc a) where
 | 
					
						
							|  |  |  |  |     field
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |         _≈_ : A → A → Set a
 | 
					
						
							| 
									
										
										
										
											2023-04-06 23:08:49 -07:00
										 |  |  |  |         _⊔_ : A → A → A
 | 
					
						
							|  |  |  |  |         _⊓_ : A → A → A
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |         isLattice : IsLattice A _≈_ _⊔_ _⊓_
 | 
					
						
							| 
									
										
										
										
											2023-04-06 23:08:49 -07:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     open IsLattice isLattice public
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-15 13:12:21 -07:00
										 |  |  |  | module IsSemilatticeInstances where
 | 
					
						
							| 
									
										
										
										
											2023-07-14 19:59:07 -07:00
										 |  |  |  |     module ForNat where
 | 
					
						
							|  |  |  |  |         open Nat
 | 
					
						
							|  |  |  |  |         open NatProps
 | 
					
						
							|  |  |  |  |         open Eq
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-03 17:08:37 -07:00
										 |  |  |  |         private
 | 
					
						
							|  |  |  |  |             ≡-⊔-cong : ∀ {a₁ a₂ a₃ a₄} → a₁ ≡ a₂ → a₃ ≡ a₄ → (a₁ ⊔ a₃) ≡ (a₂ ⊔ a₄)
 | 
					
						
							|  |  |  |  |             ≡-⊔-cong a₁≡a₂ a₃≡a₄ rewrite a₁≡a₂ rewrite a₃≡a₄ = refl
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             ≡-⊓-cong : ∀ {a₁ a₂ a₃ a₄} → a₁ ≡ a₂ → a₃ ≡ a₄ → (a₁ ⊓ a₃) ≡ (a₂ ⊓ a₄)
 | 
					
						
							|  |  |  |  |             ≡-⊓-cong a₁≡a₂ a₃≡a₄ rewrite a₁≡a₂ rewrite a₃≡a₄ = refl
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |         NatIsMaxSemilattice : IsSemilattice ℕ _≡_ _⊔_
 | 
					
						
							| 
									
										
										
										
											2023-07-15 13:12:21 -07:00
										 |  |  |  |         NatIsMaxSemilattice = record
 | 
					
						
							| 
									
										
										
										
											2023-07-15 15:16:51 -07:00
										 |  |  |  |             { ≈-equiv = record
 | 
					
						
							|  |  |  |  |                 { ≈-refl = refl
 | 
					
						
							|  |  |  |  |                 ; ≈-sym = sym
 | 
					
						
							|  |  |  |  |                 ; ≈-trans = trans
 | 
					
						
							|  |  |  |  |                 }
 | 
					
						
							| 
									
										
										
										
											2023-09-03 17:08:37 -07:00
										 |  |  |  |             ; ≈-⊔-cong = ≡-⊔-cong
 | 
					
						
							| 
									
										
										
										
											2023-07-15 15:16:51 -07:00
										 |  |  |  |             ; ⊔-assoc = ⊔-assoc
 | 
					
						
							| 
									
										
										
										
											2023-07-15 13:12:21 -07:00
										 |  |  |  |             ; ⊔-comm = ⊔-comm
 | 
					
						
							|  |  |  |  |             ; ⊔-idemp = ⊔-idem
 | 
					
						
							| 
									
										
										
										
											2023-07-14 19:59:07 -07:00
										 |  |  |  |             }
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |         NatIsMinSemilattice : IsSemilattice ℕ _≡_ _⊓_
 | 
					
						
							| 
									
										
										
										
											2023-07-15 13:12:21 -07:00
										 |  |  |  |         NatIsMinSemilattice = record
 | 
					
						
							| 
									
										
										
										
											2023-07-15 15:16:51 -07:00
										 |  |  |  |             { ≈-equiv = record
 | 
					
						
							|  |  |  |  |                 { ≈-refl = refl
 | 
					
						
							|  |  |  |  |                 ; ≈-sym = sym
 | 
					
						
							|  |  |  |  |                 ; ≈-trans = trans
 | 
					
						
							|  |  |  |  |                 }
 | 
					
						
							| 
									
										
										
										
											2023-09-03 17:08:37 -07:00
										 |  |  |  |             ; ≈-⊔-cong = ≡-⊓-cong
 | 
					
						
							| 
									
										
										
										
											2023-07-15 15:16:51 -07:00
										 |  |  |  |             ; ⊔-assoc = ⊓-assoc
 | 
					
						
							| 
									
										
										
										
											2023-07-15 13:12:21 -07:00
										 |  |  |  |             ; ⊔-comm = ⊓-comm
 | 
					
						
							|  |  |  |  |             ; ⊔-idemp = ⊓-idem
 | 
					
						
							| 
									
										
										
										
											2023-07-14 19:59:07 -07:00
										 |  |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2023-07-14 19:42:29 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-15 13:12:21 -07:00
										 |  |  |  |     module ForProd {a} {A B : Set a}
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |         (_≈₁_ : A → A → Set a) (_≈₂_ : B → B → Set a)
 | 
					
						
							| 
									
										
										
										
											2023-07-15 13:12:21 -07:00
										 |  |  |  |         (_⊔₁_ : A → A → A) (_⊔₂_ : B → B → B)
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |         (sA : IsSemilattice A _≈₁_ _⊔₁_) (sB : IsSemilattice B _≈₂_ _⊔₂_) where
 | 
					
						
							| 
									
										
										
										
											2023-07-15 13:12:21 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-14 21:20:16 -07:00
										 |  |  |  |         open Eq
 | 
					
						
							|  |  |  |  |         open Data.Product
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 19:02:47 -07:00
										 |  |  |  |         module ProdEquiv = IsEquivalenceInstances.ForProd _≈₁_ _≈₂_ (IsSemilattice.≈-equiv sA) (IsSemilattice.≈-equiv sB)
 | 
					
						
							|  |  |  |  |         open ProdEquiv using (_≈_) public
 | 
					
						
							| 
									
										
										
										
											2023-07-14 21:20:16 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 19:02:47 -07:00
										 |  |  |  |         infixl 20 _⊔_
 | 
					
						
							| 
									
										
										
										
											2023-07-14 21:20:16 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 19:02:47 -07:00
										 |  |  |  |         _⊔_ : A × B → A × B → A × B
 | 
					
						
							|  |  |  |  |         (a₁ , b₁) ⊔ (a₂ , b₂) = (a₁ ⊔₁ a₂ , b₁ ⊔₂ b₂)
 | 
					
						
							| 
									
										
										
										
											2023-07-15 13:12:21 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 19:02:47 -07:00
										 |  |  |  |         ProdIsSemilattice : IsSemilattice (A × B) _≈_ _⊔_
 | 
					
						
							|  |  |  |  |         ProdIsSemilattice = record
 | 
					
						
							|  |  |  |  |             { ≈-equiv = ProdEquiv.ProdEquivalence
 | 
					
						
							| 
									
										
										
										
											2023-09-03 17:08:37 -07:00
										 |  |  |  |             ; ≈-⊔-cong = λ (a₁≈a₂ , b₁≈b₂) (a₃≈a₄ , b₃≈b₄) →
 | 
					
						
							|  |  |  |  |                 ( IsSemilattice.≈-⊔-cong sA a₁≈a₂ a₃≈a₄
 | 
					
						
							|  |  |  |  |                 , IsSemilattice.≈-⊔-cong sB b₁≈b₂ b₃≈b₄
 | 
					
						
							|  |  |  |  |                 )
 | 
					
						
							| 
									
										
										
										
											2023-08-20 19:02:47 -07:00
										 |  |  |  |             ; ⊔-assoc = λ (a₁ , b₁) (a₂ , b₂) (a₃ , b₃) →
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |                 ( IsSemilattice.⊔-assoc sA a₁ a₂ a₃
 | 
					
						
							|  |  |  |  |                 , IsSemilattice.⊔-assoc sB b₁ b₂ b₃
 | 
					
						
							|  |  |  |  |                 )
 | 
					
						
							| 
									
										
										
										
											2023-08-20 19:02:47 -07:00
										 |  |  |  |             ; ⊔-comm = λ (a₁ , b₁) (a₂ , b₂) →
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |                 ( IsSemilattice.⊔-comm sA a₁ a₂
 | 
					
						
							|  |  |  |  |                 , IsSemilattice.⊔-comm sB b₁ b₂
 | 
					
						
							|  |  |  |  |                 )
 | 
					
						
							| 
									
										
										
										
											2023-08-20 19:02:47 -07:00
										 |  |  |  |             ; ⊔-idemp = λ (a , b) →
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |                 ( IsSemilattice.⊔-idemp sA a
 | 
					
						
							|  |  |  |  |                 , IsSemilattice.⊔-idemp sB b
 | 
					
						
							|  |  |  |  |                 )
 | 
					
						
							| 
									
										
										
										
											2023-07-14 21:20:16 -07:00
										 |  |  |  |             }
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-30 20:36:19 -07:00
										 |  |  |  |     module ForMap {a} {A B : Set a}
 | 
					
						
							|  |  |  |  |         (≡-dec-A : Decidable (_≡_ {a} {A}))
 | 
					
						
							|  |  |  |  |         (_≈₂_ : B → B → Set a)
 | 
					
						
							|  |  |  |  |         (_⊔₂_ : B → B → B)
 | 
					
						
							|  |  |  |  |         (sB : IsSemilattice B _≈₂_ _⊔₂_) where
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         open import Map A B ≡-dec-A
 | 
					
						
							| 
									
										
										
										
											2023-07-30 21:50:28 -07:00
										 |  |  |  |         open IsSemilattice sB renaming
 | 
					
						
							| 
									
										
										
										
											2023-09-03 17:08:37 -07:00
										 |  |  |  |             ( ≈-refl to ≈₂-refl; ≈-sym to ≈₂-sym; ≈-⊔-cong to ≈₂-⊔₂-cong
 | 
					
						
							| 
									
										
										
										
											2023-07-30 21:50:28 -07:00
										 |  |  |  |             ; ⊔-assoc to ⊔₂-assoc; ⊔-comm to ⊔₂-comm; ⊔-idemp to ⊔₂-idemp
 | 
					
						
							|  |  |  |  |             )
 | 
					
						
							| 
									
										
										
										
											2023-07-30 20:36:19 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 19:02:47 -07:00
										 |  |  |  |         module MapEquiv = IsEquivalenceInstances.ForMap A B ≡-dec-A _≈₂_ (IsSemilattice.≈-equiv sB)
 | 
					
						
							|  |  |  |  |         open MapEquiv using (_≈_) public
 | 
					
						
							| 
									
										
										
										
											2023-07-30 20:36:19 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 19:02:47 -07:00
										 |  |  |  |         infixl 20 _⊔_
 | 
					
						
							|  |  |  |  |         infixl 20 _⊓_
 | 
					
						
							| 
									
										
										
										
											2023-07-30 20:36:19 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 19:02:47 -07:00
										 |  |  |  |         _⊔_ : Map → Map → Map
 | 
					
						
							|  |  |  |  |         m₁ ⊔ m₂ = union _⊔₂_ m₁ m₂
 | 
					
						
							| 
									
										
										
										
											2023-08-05 12:48:44 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 19:02:47 -07:00
										 |  |  |  |         _⊓_ : Map → Map → Map
 | 
					
						
							|  |  |  |  |         m₁ ⊓ m₂ = intersect _⊔₂_ m₁ m₂
 | 
					
						
							| 
									
										
										
										
											2023-07-30 20:36:19 -07:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         MapIsUnionSemilattice : IsSemilattice Map _≈_ _⊔_
 | 
					
						
							|  |  |  |  |         MapIsUnionSemilattice = record
 | 
					
						
							|  |  |  |  |             { ≈-equiv = MapEquiv.LiftEquivalence
 | 
					
						
							| 
									
										
										
										
											2023-09-03 17:08:37 -07:00
										 |  |  |  |             ; ≈-⊔-cong = λ {m₁} {m₂} {m₃} {m₄} → union-cong _≈₂_ _⊔₂_ ≈₂-⊔₂-cong {m₁} {m₂} {m₃} {m₄}
 | 
					
						
							| 
									
										
										
										
											2023-07-30 21:50:28 -07:00
										 |  |  |  |             ; ⊔-assoc = union-assoc _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ ⊔₂-assoc
 | 
					
						
							|  |  |  |  |             ; ⊔-comm = union-comm _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ ⊔₂-comm
 | 
					
						
							|  |  |  |  |             ; ⊔-idemp = union-idemp _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ ⊔₂-idemp
 | 
					
						
							| 
									
										
										
										
											2023-07-30 20:36:19 -07:00
										 |  |  |  |             }
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-05 12:48:44 -07:00
										 |  |  |  |         MapIsIntersectSemilattice : IsSemilattice Map _≈_ _⊓_
 | 
					
						
							|  |  |  |  |         MapIsIntersectSemilattice = record
 | 
					
						
							|  |  |  |  |             { ≈-equiv = MapEquiv.LiftEquivalence
 | 
					
						
							| 
									
										
										
										
											2023-09-03 17:08:37 -07:00
										 |  |  |  |             ; ≈-⊔-cong = λ {m₁} {m₂} {m₃} {m₄} → intersect-cong _≈₂_ _⊔₂_ ≈₂-⊔₂-cong {m₁} {m₂} {m₃} {m₄}
 | 
					
						
							| 
									
										
										
										
											2023-08-05 12:48:44 -07:00
										 |  |  |  |             ; ⊔-assoc = intersect-assoc _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ ⊔₂-assoc
 | 
					
						
							|  |  |  |  |             ; ⊔-comm = intersect-comm _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ ⊔₂-comm
 | 
					
						
							|  |  |  |  |             ; ⊔-idemp = intersect-idemp _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ ⊔₂-idemp
 | 
					
						
							|  |  |  |  |             }
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-15 13:12:21 -07:00
										 |  |  |  | module IsLatticeInstances where
 | 
					
						
							| 
									
										
										
										
											2023-07-14 21:49:47 -07:00
										 |  |  |  |     module ForNat where
 | 
					
						
							|  |  |  |  |         open Nat
 | 
					
						
							|  |  |  |  |         open NatProps
 | 
					
						
							|  |  |  |  |         open Eq
 | 
					
						
							| 
									
										
										
										
											2023-07-15 13:12:21 -07:00
										 |  |  |  |         open IsSemilatticeInstances.ForNat
 | 
					
						
							| 
									
										
										
										
											2023-07-14 21:49:47 -07:00
										 |  |  |  |         open Data.Product
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         private
 | 
					
						
							| 
									
										
										
										
											2023-07-15 12:18:50 -07:00
										 |  |  |  |             max-bound₁ : {x y z : ℕ} → x ⊔ y ≡ z → x ≤ z
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |             max-bound₁ {x} {y} {z} x⊔y≡z
 | 
					
						
							|  |  |  |  |                 rewrite sym x⊔y≡z
 | 
					
						
							|  |  |  |  |                 rewrite ⊔-comm x y = m≤n⇒m≤o⊔n y (≤-refl)
 | 
					
						
							| 
									
										
										
										
											2023-07-15 12:18:50 -07:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |             min-bound₁ : {x y z : ℕ} → x ⊓ y ≡ z → z ≤ x
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |             min-bound₁ {x} {y} {z} x⊓y≡z
 | 
					
						
							|  |  |  |  |                 rewrite sym x⊓y≡z = m≤n⇒m⊓o≤n y (≤-refl)
 | 
					
						
							| 
									
										
										
										
											2023-07-15 12:18:50 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-14 21:49:47 -07:00
										 |  |  |  |             minmax-absorb : {x y : ℕ} → x ⊓ (x ⊔ y) ≡ x
 | 
					
						
							|  |  |  |  |             minmax-absorb {x} {y} = ≤-antisym x⊓x⊔y≤x (helper x⊓x≤x⊓x⊔y (⊓-idem x))
 | 
					
						
							|  |  |  |  |                 where
 | 
					
						
							| 
									
										
										
										
											2023-07-15 12:18:50 -07:00
										 |  |  |  |                     x⊓x⊔y≤x = min-bound₁ {x} {x ⊔ y} {x ⊓ (x ⊔ y)} refl
 | 
					
						
							|  |  |  |  |                     x⊓x≤x⊓x⊔y = ⊓-mono-≤ {x} {x} ≤-refl (max-bound₁ {x} {y} {x ⊔ y} refl)
 | 
					
						
							| 
									
										
										
										
											2023-07-14 21:49:47 -07:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |                     -- >:(
 | 
					
						
							|  |  |  |  |                     helper : x ⊓ x ≤ x ⊓ (x ⊔ y) → x ⊓ x ≡ x → x ≤ x ⊓ (x ⊔ y)
 | 
					
						
							|  |  |  |  |                     helper x⊓x≤x⊓x⊔y x⊓x≡x rewrite x⊓x≡x = x⊓x≤x⊓x⊔y
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             maxmin-absorb : {x y : ℕ} → x ⊔ (x ⊓ y) ≡ x
 | 
					
						
							|  |  |  |  |             maxmin-absorb {x} {y} = ≤-antisym (helper x⊔x⊓y≤x⊔x (⊔-idem x)) x≤x⊔x⊓y
 | 
					
						
							|  |  |  |  |                 where
 | 
					
						
							| 
									
										
										
										
											2023-07-15 12:18:50 -07:00
										 |  |  |  |                     x≤x⊔x⊓y = max-bound₁ {x} {x ⊓ y} {x ⊔ (x ⊓ y)} refl
 | 
					
						
							|  |  |  |  |                     x⊔x⊓y≤x⊔x = ⊔-mono-≤ {x} {x} ≤-refl (min-bound₁ {x} {y} {x ⊓ y} refl)
 | 
					
						
							| 
									
										
										
										
											2023-07-14 21:49:47 -07:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |                     -- >:(
 | 
					
						
							|  |  |  |  |                     helper : x ⊔ (x ⊓ y) ≤ x ⊔ x  → x ⊔ x ≡ x → x ⊔ (x ⊓ y) ≤ x
 | 
					
						
							|  |  |  |  |                     helper x⊔x⊓y≤x⊔x x⊔x≡x rewrite x⊔x≡x = x⊔x⊓y≤x⊔x
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |         NatIsLattice : IsLattice ℕ _≡_ _⊔_ _⊓_
 | 
					
						
							| 
									
										
										
										
											2023-07-15 13:12:21 -07:00
										 |  |  |  |         NatIsLattice = record
 | 
					
						
							|  |  |  |  |             { joinSemilattice = NatIsMaxSemilattice
 | 
					
						
							|  |  |  |  |             ; meetSemilattice = NatIsMinSemilattice
 | 
					
						
							|  |  |  |  |             ; absorb-⊔-⊓ = λ x y → maxmin-absorb {x} {y}
 | 
					
						
							|  |  |  |  |             ; absorb-⊓-⊔ = λ x y → minmax-absorb {x} {y}
 | 
					
						
							| 
									
										
										
										
											2023-07-14 21:49:47 -07:00
										 |  |  |  |             }
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-15 13:12:21 -07:00
										 |  |  |  |     module ForProd {a} {A B : Set a}
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |         (_≈₁_ : A → A → Set a) (_≈₂_ : B → B → Set a)
 | 
					
						
							| 
									
										
										
										
											2023-07-15 13:12:21 -07:00
										 |  |  |  |         (_⊔₁_ : A → A → A) (_⊓₁_ : A → A → A)
 | 
					
						
							|  |  |  |  |         (_⊔₂_ : B → B → B) (_⊓₂_ : B → B → B)
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |         (lA : IsLattice A _≈₁_ _⊔₁_ _⊓₁_) (lB : IsLattice B _≈₂_ _⊔₂_ _⊓₂_) where
 | 
					
						
							| 
									
										
										
										
											2023-07-15 13:12:21 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 19:02:47 -07:00
										 |  |  |  |         module ProdJoin = IsSemilatticeInstances.ForProd _≈₁_ _≈₂_ _⊔₁_ _⊔₂_ (IsLattice.joinSemilattice lA) (IsLattice.joinSemilattice lB)
 | 
					
						
							|  |  |  |  |         open ProdJoin using (_⊔_; _≈_) public
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 19:02:47 -07:00
										 |  |  |  |         module ProdMeet = IsSemilatticeInstances.ForProd _≈₁_ _≈₂_ _⊓₁_ _⊓₂_ (IsLattice.meetSemilattice lA) (IsLattice.meetSemilattice lB)
 | 
					
						
							|  |  |  |  |         open ProdMeet using () renaming (_⊔_ to _⊓_) public
 | 
					
						
							| 
									
										
										
										
											2023-07-14 21:49:47 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 19:02:47 -07:00
										 |  |  |  |         ProdIsLattice : IsLattice (A × B) _≈_ _⊔_ _⊓_
 | 
					
						
							|  |  |  |  |         ProdIsLattice = record
 | 
					
						
							|  |  |  |  |             { joinSemilattice = ProdJoin.ProdIsSemilattice
 | 
					
						
							|  |  |  |  |             ; meetSemilattice = ProdMeet.ProdIsSemilattice
 | 
					
						
							|  |  |  |  |             ; absorb-⊔-⊓ = λ (a₁ , b₁) (a₂ , b₂) →
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |                 ( IsLattice.absorb-⊔-⊓ lA a₁ a₂
 | 
					
						
							|  |  |  |  |                 , IsLattice.absorb-⊔-⊓ lB b₁ b₂
 | 
					
						
							|  |  |  |  |                 )
 | 
					
						
							| 
									
										
										
										
											2023-08-20 19:02:47 -07:00
										 |  |  |  |             ; absorb-⊓-⊔ = λ (a₁ , b₁) (a₂ , b₂) →
 | 
					
						
							| 
									
										
										
										
											2023-07-15 14:40:11 -07:00
										 |  |  |  |                 ( IsLattice.absorb-⊓-⊔ lA a₁ a₂
 | 
					
						
							|  |  |  |  |                 , IsLattice.absorb-⊓-⊔ lB b₁ b₂
 | 
					
						
							|  |  |  |  |                 )
 | 
					
						
							| 
									
										
										
										
											2023-07-13 23:22:29 -07:00
										 |  |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2023-08-05 18:33:49 -07:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     module ForMap {a} {A B : Set a}
 | 
					
						
							|  |  |  |  |         (≡-dec-A : Decidable (_≡_ {a} {A}))
 | 
					
						
							|  |  |  |  |         (_≈₂_ : B → B → Set a)
 | 
					
						
							|  |  |  |  |         (_⊔₂_ : B → B → B)
 | 
					
						
							|  |  |  |  |         (_⊓₂_ : B → B → B)
 | 
					
						
							|  |  |  |  |         (lB : IsLattice B _≈₂_ _⊔₂_ _⊓₂_) where
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         open import Map A B ≡-dec-A
 | 
					
						
							|  |  |  |  |         open IsLattice lB renaming
 | 
					
						
							|  |  |  |  |             ( ≈-refl to ≈₂-refl; ≈-sym to ≈₂-sym
 | 
					
						
							|  |  |  |  |             ; ⊔-idemp to ⊔₂-idemp; ⊓-idemp to ⊓₂-idemp
 | 
					
						
							|  |  |  |  |             ; absorb-⊔-⊓ to absorb-⊔₂-⊓₂; absorb-⊓-⊔ to absorb-⊓₂-⊔₂
 | 
					
						
							|  |  |  |  |             )
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 19:02:47 -07:00
										 |  |  |  |         module MapJoin = IsSemilatticeInstances.ForMap ≡-dec-A _≈₂_ _⊔₂_ (IsLattice.joinSemilattice lB)
 | 
					
						
							|  |  |  |  |         open MapJoin using (_⊔_; _≈_) public
 | 
					
						
							| 
									
										
										
										
											2023-08-05 18:33:49 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 19:02:47 -07:00
										 |  |  |  |         module MapMeet = IsSemilatticeInstances.ForMap ≡-dec-A _≈₂_ _⊓₂_ (IsLattice.meetSemilattice lB)
 | 
					
						
							|  |  |  |  |         open MapMeet using (_⊓_) public
 | 
					
						
							| 
									
										
										
										
											2023-08-05 18:33:49 -07:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         MapIsLattice : IsLattice Map _≈_ _⊔_ _⊓_
 | 
					
						
							|  |  |  |  |         MapIsLattice = record
 | 
					
						
							|  |  |  |  |             { joinSemilattice = MapJoin.MapIsUnionSemilattice
 | 
					
						
							|  |  |  |  |             ; meetSemilattice = MapMeet.MapIsIntersectSemilattice
 | 
					
						
							|  |  |  |  |             ; absorb-⊔-⊓ = union-intersect-absorb _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ _⊓₂_ ⊔₂-idemp ⊓₂-idemp absorb-⊔₂-⊓₂ absorb-⊓₂-⊔₂
 | 
					
						
							|  |  |  |  |             ; absorb-⊓-⊔ = intersect-union-absorb _≈₂_ ≈₂-refl ≈₂-sym _⊔₂_ _⊓₂_ ⊔₂-idemp ⊓₂-idemp absorb-⊔₂-⊓₂ absorb-⊓₂-⊔₂
 | 
					
						
							|  |  |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2023-08-20 21:53:27 -07:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | module IsFiniteHeightLatticeInstances where
 | 
					
						
							|  |  |  |  |     module ForProd {a} {A B : Set a}
 | 
					
						
							|  |  |  |  |         (_≈₁_ : A → A → Set a) (_≈₂_ : B → B → Set a)
 | 
					
						
							| 
									
										
										
										
											2023-09-03 23:56:39 -07:00
										 |  |  |  |         (decA : IsDecidable _≈₁_) (decB : IsDecidable _≈₂_)
 | 
					
						
							| 
									
										
										
										
											2023-08-20 21:53:27 -07:00
										 |  |  |  |         (_⊔₁_ : A → A → A) (_⊓₁_ : A → A → A)
 | 
					
						
							|  |  |  |  |         (_⊔₂_ : B → B → B) (_⊓₂_ : B → B → B)
 | 
					
						
							|  |  |  |  |         (h₁ h₂ : ℕ)
 | 
					
						
							|  |  |  |  |         (lA : IsFiniteHeightLattice A h₁ _≈₁_ _⊔₁_ _⊓₁_) (lB : IsFiniteHeightLattice B h₂ _≈₂_ _⊔₂_ _⊓₂_) where
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-03 23:56:39 -07:00
										 |  |  |  |         open NatProps
 | 
					
						
							| 
									
										
										
										
											2023-08-20 21:53:27 -07:00
										 |  |  |  |         module ProdLattice = IsLatticeInstances.ForProd _≈₁_ _≈₂_ _⊔₁_ _⊓₁_ _⊔₂_ _⊓₂_ (IsFiniteHeightLattice.isLattice lA) (IsFiniteHeightLattice.isLattice lB)
 | 
					
						
							|  |  |  |  |         open ProdLattice using (_⊔_; _⊓_; _≈_) public
 | 
					
						
							| 
									
										
										
										
											2023-09-03 21:05:57 -07:00
										 |  |  |  |         open IsLattice ProdLattice.ProdIsLattice using (_≼_; _≺_; ≺-cong; ≈-equiv)
 | 
					
						
							| 
									
										
										
										
											2023-09-03 23:56:39 -07:00
										 |  |  |  |         open IsFiniteHeightLattice lA using () renaming (⊔-idemp to ⊔₁-idemp; _≼_ to _≼₁_; ≈-equiv to ≈₁-equiv; ≈-refl to ≈₁-refl; ≈-trans to ≈₁-trans; ≈-sym to ≈₁-sym; _≺_ to _≺₁_; ≺-cong to ≺₁-cong)
 | 
					
						
							|  |  |  |  |         open IsFiniteHeightLattice lB using () renaming (⊔-idemp to ⊔₂-idemp; _≼_ to _≼₂_; ≈-equiv to ≈₂-equiv; ≈-refl to ≈₂-refl; ≈-trans to ≈₂-trans; ≈-sym to ≈₂-sym; _≺_ to _≺₂_; ≺-cong to ≺₂-cong)
 | 
					
						
							|  |  |  |  |         open IsDecidable decA using () renaming (R-dec to ≈₁-dec)
 | 
					
						
							|  |  |  |  |         open IsDecidable decB using () renaming (R-dec to ≈₂-dec)
 | 
					
						
							| 
									
										
										
										
											2023-08-20 21:53:27 -07:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         module ChainMapping₁ = ChainMapping (IsFiniteHeightLattice.joinSemilattice lA) (IsLattice.joinSemilattice ProdLattice.ProdIsLattice)
 | 
					
						
							|  |  |  |  |         module ChainMapping₂ = ChainMapping (IsFiniteHeightLattice.joinSemilattice lB) (IsLattice.joinSemilattice ProdLattice.ProdIsLattice)
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-03 23:56:39 -07:00
										 |  |  |  |         module ChainA = Chain _≈₁_ ≈₁-equiv _≺₁_ ≺₁-cong
 | 
					
						
							|  |  |  |  |         module ChainB = Chain _≈₂_ ≈₂-equiv _≺₂_ ≺₂-cong
 | 
					
						
							|  |  |  |  |         module ProdChain = Chain _≈_ ≈-equiv _≺_ ≺-cong
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         open ChainA using () renaming (Chain to Chain₁; done to done₁; step to step₁; Chain-≈-cong₁ to Chain₁-≈-cong₁)
 | 
					
						
							|  |  |  |  |         open ChainB using () renaming (Chain to Chain₂; done to done₂; step to step₂; Chain-≈-cong₁ to Chain₂-≈-cong₁)
 | 
					
						
							|  |  |  |  |         open ProdChain using (Chain; concat; done; step)
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 21:53:27 -07:00
										 |  |  |  |         private
 | 
					
						
							|  |  |  |  |             a,∙-Monotonic : ∀ (a : A) → Monotonic _≼₂_ _≼_ (λ b → (a , b))
 | 
					
						
							|  |  |  |  |             a,∙-Monotonic a {b₁} {b₂} (b , b₁⊔b≈b₂) = ((a , b) , (⊔₁-idemp a , b₁⊔b≈b₂))
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-03 21:05:57 -07:00
										 |  |  |  |             a,∙-Preserves-≈₂ : ∀ (a : A) → (λ b → (a , b)) Preserves _≈₂_ ⟶  _≈_
 | 
					
						
							|  |  |  |  |             a,∙-Preserves-≈₂ a {b₁} {b₂} b₁≈b₂ = (≈₁-refl , b₁≈b₂)
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 21:53:27 -07:00
										 |  |  |  |             ∙,b-Monotonic : ∀ (b : B) → Monotonic _≼₁_ _≼_ (λ a → (a , b))
 | 
					
						
							|  |  |  |  |             ∙,b-Monotonic b {a₁} {a₂} (a , a₁⊔a≈a₂) = ((a , b) , (a₁⊔a≈a₂ , ⊔₂-idemp b))
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-03 21:05:57 -07:00
										 |  |  |  |             ∙,b-Preserves-≈₁ : ∀ (b : B) → (λ a → (a , b)) Preserves _≈₁_ ⟶  _≈_
 | 
					
						
							|  |  |  |  |             ∙,b-Preserves-≈₁ b {a₁} {a₂} a₁≈a₂ = (a₁≈a₂ , ≈₂-refl)
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 21:53:27 -07:00
										 |  |  |  |             amin : A
 | 
					
						
							|  |  |  |  |             amin = proj₁ (proj₁ (proj₁ (IsFiniteHeightLattice.fixedHeight lA)))
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             amax : A
 | 
					
						
							|  |  |  |  |             amax = proj₂ (proj₁ (proj₁ (IsFiniteHeightLattice.fixedHeight lA)))
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             bmin : B
 | 
					
						
							|  |  |  |  |             bmin = proj₁ (proj₁ (proj₁ (IsFiniteHeightLattice.fixedHeight lB)))
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             bmax : B
 | 
					
						
							|  |  |  |  |             bmax = proj₂ (proj₁ (proj₁ (IsFiniteHeightLattice.fixedHeight lB)))
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-03 23:56:39 -07:00
										 |  |  |  |             unzip : ∀ {a₁ a₂ : A} {b₁ b₂ : B} {n : ℕ} → Chain (a₁ , b₁) (a₂ , b₂) n → Σ (ℕ × ℕ) (λ (n₁ , n₂) → ((Chain₁ a₁ a₂ n₁ × Chain₂ b₁ b₂ n₂) × (n ≤ n₁ + n₂)))
 | 
					
						
							|  |  |  |  |             unzip (done (a₁≈a₂ , b₁≈b₂)) = ((0 , 0) , ((done₁ a₁≈a₂ , done₂ b₁≈b₂) , ≤-refl))
 | 
					
						
							|  |  |  |  |             unzip {a₁} {a₂} {b₁} {b₂} {n} (step {(a₁ , b₁)} {(a , b)} (((d₁ , d₂) , (a₁⊔d₁≈a , b₁⊔d₂≈b)) , a₁b₁̷≈ab) (a≈a' , b≈b') a'b'a₂b₂)
 | 
					
						
							|  |  |  |  |                 with ≈₁-dec a₁ a | ≈₂-dec b₁ b | unzip a'b'a₂b₂
 | 
					
						
							|  |  |  |  |             ...   | yes a₁≈a | yes b₁≈b | ((n₁ , n₂) , ((c₁ , c₂) , n≤n₁+n₂)) = absurd (a₁b₁̷≈ab (a₁≈a , b₁≈b))
 | 
					
						
							|  |  |  |  |             ...   | no a₁̷≈a  | yes b₁≈b | ((n₁ , n₂) , ((c₁ , c₂) , n≤n₁+n₂)) =
 | 
					
						
							|  |  |  |  |                     ((suc n₁ , n₂) , ((step₁ ((d₁ , a₁⊔d₁≈a) , a₁̷≈a) a≈a' c₁ , Chain₂-≈-cong₁ (≈₂-sym (≈₂-trans b₁≈b b≈b')) c₂), +-monoʳ-≤ 1 (n≤n₁+n₂)))
 | 
					
						
							|  |  |  |  |             ...   | yes a₁≈a | no b₁̷≈b | ((n₁ , n₂) , ((c₁ , c₂) , n≤n₁+n₂)) =
 | 
					
						
							|  |  |  |  |                     ((n₁ , suc n₂) , ( (Chain₁-≈-cong₁ (≈₁-sym (≈₁-trans a₁≈a a≈a')) c₁ , step₂ ((d₂ , b₁⊔d₂≈b) , b₁̷≈b) b≈b' c₂)
 | 
					
						
							|  |  |  |  |                                      , subst (n ≤_) (sym (+-suc n₁ n₂)) (+-monoʳ-≤ 1 n≤n₁+n₂)
 | 
					
						
							|  |  |  |  |                                      ))
 | 
					
						
							|  |  |  |  |             ...   | no a₁̷≈a  | no b₁̷≈b | ((n₁ , n₂) , ((c₁ , c₂) , n≤n₁+n₂)) =
 | 
					
						
							|  |  |  |  |                     ((suc n₁ , suc n₂) , ( (step₁ ((d₁ , a₁⊔d₁≈a) , a₁̷≈a) a≈a' c₁ , step₂ ((d₂ , b₁⊔d₂≈b) , b₁̷≈b) b≈b' c₂)
 | 
					
						
							|  |  |  |  |                                          , ≤-stepsˡ 1 (subst (n ≤_) (sym (+-suc n₁ n₂)) (+-monoʳ-≤ 1 n≤n₁+n₂))
 | 
					
						
							|  |  |  |  |                                          ))
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 21:53:27 -07:00
										 |  |  |  |         ProdIsFiniteHeightLattice : IsFiniteHeightLattice (A × B) (h₁ + h₂) _≈_ _⊔_ _⊓_
 | 
					
						
							|  |  |  |  |         ProdIsFiniteHeightLattice = record
 | 
					
						
							|  |  |  |  |             { isLattice = ProdLattice.ProdIsLattice
 | 
					
						
							|  |  |  |  |             ; fixedHeight =
 | 
					
						
							|  |  |  |  |                 ( ( ((amin , bmin) , (amax , bmax))
 | 
					
						
							| 
									
										
										
										
											2023-09-03 23:56:39 -07:00
										 |  |  |  |                   , concat
 | 
					
						
							| 
									
										
										
										
											2023-09-03 21:05:57 -07:00
										 |  |  |  |                       (ChainMapping₁.Chain-map (λ a → (a , bmin)) (∙,b-Monotonic _) proj₁ (∙,b-Preserves-≈₁ _) (proj₂ (proj₁ (IsFiniteHeightLattice.fixedHeight lA))))
 | 
					
						
							|  |  |  |  |                       (ChainMapping₂.Chain-map (λ b → (amax , b)) (a,∙-Monotonic _) proj₂ (a,∙-Preserves-≈₂ _) (proj₂ (proj₁ (IsFiniteHeightLattice.fixedHeight lB))))
 | 
					
						
							| 
									
										
										
										
											2023-08-20 21:53:27 -07:00
										 |  |  |  |                   )
 | 
					
						
							| 
									
										
										
										
											2023-09-03 23:56:39 -07:00
										 |  |  |  |                 , λ a₁b₁a₂b₂ → let ((n₁ , n₂) , ((a₁a₂ , b₁b₂) , n≤n₁+n₂)) = unzip a₁b₁a₂b₂
 | 
					
						
							|  |  |  |  |                                in ≤-trans n≤n₁+n₂ (+-mono-≤ (proj₂ (IsFiniteHeightLattice.fixedHeight lA) a₁a₂)
 | 
					
						
							|  |  |  |  |                                                             (proj₂ (IsFiniteHeightLattice.fixedHeight lB) b₁b₂))
 | 
					
						
							| 
									
										
										
										
											2023-08-20 21:53:27 -07:00
										 |  |  |  |                 )
 | 
					
						
							|  |  |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2023-09-15 21:07:14 -07:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | module FixedHeightLatticeIsBounded {a} {A : Set a} {h : ℕ}
 | 
					
						
							|  |  |  |  |     {_≈_ : A → A → Set a}
 | 
					
						
							|  |  |  |  |     {_⊔_ : A → A → A} {_⊓_ : A → A → A}
 | 
					
						
							|  |  |  |  |     (decA : IsDecidable _≈_)
 | 
					
						
							|  |  |  |  |     (lA : IsFiniteHeightLattice A h _≈_ _⊔_ _⊓_) where
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     open IsFiniteHeightLattice lA using (_≼_; _≺_; fixedHeight; ≈-equiv; ≈-refl; ≈-sym; ≈-trans; ≼-refl; ≼-cong; ≺-cong; ≈-⊔-cong; absorb-⊔-⊓; ⊔-comm; ⊓-comm)
 | 
					
						
							|  |  |  |  |     open IsDecidable decA using () renaming (R-dec to ≈-dec)
 | 
					
						
							|  |  |  |  |     open NatProps using (+-comm; m+1+n≰m)
 | 
					
						
							| 
									
										
										
										
											2023-09-16 00:23:44 -07:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     private
 | 
					
						
							|  |  |  |  |         module ChainA = Chain _≈_ ≈-equiv _≺_ ≺-cong
 | 
					
						
							| 
									
										
										
										
											2023-09-15 21:07:14 -07:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     A-BoundedBelow : Σ A (λ ⊥ᴬ → ∀ (a : A) → ⊥ᴬ ≼ a)
 | 
					
						
							|  |  |  |  |     A-BoundedBelow = (⊥ᴬ , ⊥ᴬ≼)
 | 
					
						
							|  |  |  |  |         where
 | 
					
						
							|  |  |  |  |             ⊥ᴬ : A
 | 
					
						
							|  |  |  |  |             ⊥ᴬ = proj₁ (proj₁ (proj₁ fixedHeight))
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             ⊥ᴬ≼ : ∀ (a : A) → ⊥ᴬ ≼ a
 | 
					
						
							|  |  |  |  |             ⊥ᴬ≼ a
 | 
					
						
							|  |  |  |  |                 with ≈-dec a ⊥ᴬ
 | 
					
						
							|  |  |  |  |             ...   | yes a≈⊥ᴬ = ≼-cong a≈⊥ᴬ ≈-refl (≼-refl a)
 | 
					
						
							|  |  |  |  |             ...   | no a̷≈⊥ᴬ with ≈-dec ⊥ᴬ (a ⊓ ⊥ᴬ)
 | 
					
						
							|  |  |  |  |             ...         | yes ⊥ᴬ≈a⊓⊥ᴬ = (a , ≈-trans (⊔-comm ⊥ᴬ a) (≈-trans (≈-⊔-cong (≈-refl {a}) ⊥ᴬ≈a⊓⊥ᴬ) (absorb-⊔-⊓ a ⊥ᴬ)))
 | 
					
						
							| 
									
										
										
										
											2023-09-16 00:23:44 -07:00
										 |  |  |  |             ...         | no ⊥ᴬ̷≈a⊓⊥ᴬ = absurd (ChainA.Bounded-suc-n (proj₂ fixedHeight) (ChainA.step x≺⊥ᴬ ≈-refl (proj₂ (proj₁ fixedHeight))))
 | 
					
						
							| 
									
										
										
										
											2023-09-15 21:07:14 -07:00
										 |  |  |  |                             where
 | 
					
						
							|  |  |  |  |                                 ⊥ᴬ⊓a̷≈⊥ᴬ : ¬ (⊥ᴬ ⊓ a) ≈ ⊥ᴬ
 | 
					
						
							|  |  |  |  |                                 ⊥ᴬ⊓a̷≈⊥ᴬ = λ ⊥ᴬ⊓a≈⊥ᴬ → ⊥ᴬ̷≈a⊓⊥ᴬ (≈-trans (≈-sym ⊥ᴬ⊓a≈⊥ᴬ) (⊓-comm _ _))
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                                 x≺⊥ᴬ : (⊥ᴬ ⊓ a) ≺ ⊥ᴬ
 | 
					
						
							|  |  |  |  |                                 x≺⊥ᴬ = ((⊥ᴬ , ≈-trans (⊔-comm _ _) (≈-trans (≈-refl {⊥ᴬ ⊔ (⊥ᴬ ⊓ a)}) (absorb-⊔-⊓ ⊥ᴬ a))) , ⊥ᴬ⊓a̷≈⊥ᴬ)
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | module FixedPoint {a} {A : Set a}
 | 
					
						
							|  |  |  |  |                   (h : ℕ)
 | 
					
						
							| 
									
										
										
										
											2023-09-16 00:23:44 -07:00
										 |  |  |  |                   (_≈_ : A → A → Set a) (decA : IsDecidable _≈_)
 | 
					
						
							| 
									
										
										
										
											2023-09-15 21:07:14 -07:00
										 |  |  |  |                   (_⊔_ : A → A → A) (_⊓_ : A → A → A)
 | 
					
						
							|  |  |  |  |                   (isFiniteHeightLattice : IsFiniteHeightLattice A h _≈_ _⊔_ _⊓_)
 | 
					
						
							|  |  |  |  |                   (f : A → A) (Monotonicᶠ : Monotonic (IsFiniteHeightLattice._≼_ isFiniteHeightLattice)
 | 
					
						
							|  |  |  |  |                                                       (IsFiniteHeightLattice._≼_ isFiniteHeightLattice) f) where
 | 
					
						
							| 
									
										
										
										
											2023-09-16 00:23:44 -07:00
										 |  |  |  |     open IsDecidable decA using () renaming (R-dec to ≈-dec)
 | 
					
						
							| 
									
										
										
										
											2023-09-15 21:07:14 -07:00
										 |  |  |  |     open IsFiniteHeightLattice isFiniteHeightLattice
 | 
					
						
							| 
									
										
										
										
											2023-09-16 00:23:44 -07:00
										 |  |  |  |     open FixedHeightLatticeIsBounded decA isFiniteHeightLattice
 | 
					
						
							|  |  |  |  |     open NatProps using (+-suc; +-comm)
 | 
					
						
							|  |  |  |  |     module ChainA = Chain _≈_ ≈-equiv _≺_ ≺-cong
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private
 | 
					
						
							|  |  |  |  |         ⊥ᴬ : A
 | 
					
						
							|  |  |  |  |         ⊥ᴬ = proj₁ A-BoundedBelow
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         ⊥ᴬ≼ : ∀ (a : A) → ⊥ᴬ ≼ a
 | 
					
						
							|  |  |  |  |         ⊥ᴬ≼ = proj₂ A-BoundedBelow
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         -- using 'g', for gas, here helps make sure the function terminates.
 | 
					
						
							|  |  |  |  |         -- since A forms a fixed-height lattice, we must find a solution after
 | 
					
						
							| 
									
										
										
										
											2023-09-16 13:07:31 -07:00
										 |  |  |  |         -- 'h' steps at most. Gas is set up such that as soon as it runs
 | 
					
						
							| 
									
										
										
										
											2023-09-16 00:23:44 -07:00
										 |  |  |  |         -- out, we have exceeded h steps, which shouldn't be possible.
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         doStep : ∀ (g hᶜ : ℕ) (a₁ a₂ : A) (c : ChainA.Chain a₁ a₂ hᶜ) (g+hᶜ≡h : g + hᶜ ≡ suc h) (a₂≼fa₂ : a₂ ≼ f a₂) → Σ A (λ a → a ≈ f a)
 | 
					
						
							|  |  |  |  |         doStep 0 hᶜ a₁ a₂ c g+hᶜ≡sh a₂≼fa₂ rewrite g+hᶜ≡sh = absurd (ChainA.Bounded-suc-n (proj₂ fixedHeight) c)
 | 
					
						
							|  |  |  |  |         doStep (suc g') hᶜ a₁ a₂ c g+hᶜ≡sh a₂≼fa₂ rewrite sym (+-suc g' hᶜ)
 | 
					
						
							|  |  |  |  |             with ≈-dec a₂ (f a₂)
 | 
					
						
							|  |  |  |  |         ...   | yes a₂≈fa₂ = (a₂ , a₂≈fa₂)
 | 
					
						
							|  |  |  |  |         ...   | no  a₂̷≈fa₂ = doStep g' (suc hᶜ) a₁ (f a₂) c' g+hᶜ≡sh (Monotonicᶠ a₂≼fa₂)
 | 
					
						
							|  |  |  |  |                     where
 | 
					
						
							|  |  |  |  |                         a₂≺fa₂ : a₂ ≺ f a₂
 | 
					
						
							|  |  |  |  |                         a₂≺fa₂ = (a₂≼fa₂ , a₂̷≈fa₂)
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                         c' : ChainA.Chain a₁ (f a₂) (suc hᶜ)
 | 
					
						
							|  |  |  |  |                         c' rewrite +-comm 1 hᶜ = ChainA.concat c (ChainA.step a₂≺fa₂ ≈-refl (ChainA.done (≈-refl {f a₂})))
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-16 13:07:31 -07:00
										 |  |  |  |         fix : Σ A (λ a → a ≈ f a)
 | 
					
						
							|  |  |  |  |         fix = doStep (suc h) 0 ⊥ᴬ ⊥ᴬ (ChainA.done ≈-refl) (+-comm (suc h) 0) (⊥ᴬ≼ (f ⊥ᴬ))
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     aᶠ : A
 | 
					
						
							|  |  |  |  |     aᶠ = proj₁ fix
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     aᶠ≈faᶠ : aᶠ ≈ f aᶠ
 | 
					
						
							|  |  |  |  |     aᶠ≈faᶠ = proj₂ fix
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private
 | 
					
						
							|  |  |  |  |         stepPreservesLess : ∀ (g hᶜ : ℕ) (a₁ a₂ a : A) (a≈fa : a ≈ f a) (a₂≼a : a₂ ≼ a)
 | 
					
						
							|  |  |  |  |                          (c : ChainA.Chain a₁ a₂ hᶜ) (g+hᶜ≡h : g + hᶜ ≡ suc h)
 | 
					
						
							|  |  |  |  |                          (a₂≼fa₂ : a₂ ≼ f a₂) →
 | 
					
						
							|  |  |  |  |                          proj₁ (doStep g hᶜ a₁ a₂ c g+hᶜ≡h a₂≼fa₂) ≼ a
 | 
					
						
							|  |  |  |  |         stepPreservesLess 0 _ _ _ _ _ _ c g+hᶜ≡sh _ rewrite g+hᶜ≡sh = absurd (ChainA.Bounded-suc-n (proj₂ fixedHeight) c)
 | 
					
						
							|  |  |  |  |         stepPreservesLess (suc g') hᶜ a₁ a₂ a a≈fa a₂≼a c g+hᶜ≡sh a₂≼fa₂ rewrite sym (+-suc g' hᶜ)
 | 
					
						
							|  |  |  |  |             with ≈-dec a₂ (f a₂)
 | 
					
						
							|  |  |  |  |         ...   | yes _ = a₂≼a
 | 
					
						
							|  |  |  |  |         ...   | no  _ = stepPreservesLess g' _ _ _ a a≈fa (≼-cong ≈-refl (≈-sym a≈fa) (Monotonicᶠ a₂≼a)) _ _ _
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     aᶠ≼ : ∀ (a : A) → a ≈ f a → aᶠ ≼ a
 | 
					
						
							|  |  |  |  |     aᶠ≼ a a≈fa = stepPreservesLess (suc h) 0 ⊥ᴬ ⊥ᴬ a a≈fa (⊥ᴬ≼ a) (ChainA.done ≈-refl) (+-comm (suc h) 0) (⊥ᴬ≼ (f ⊥ᴬ))
 | 
					
						
							|  |  |  |  | 
 |