--------------------------------------------------------------------------------
title:         Properties of ideals
author:        Ayberk Tosun
date-started:  2024-03-02
dates-updated: [2024-03-13, 2024-03-28, 2024-05-03]
--------------------------------------------------------------------------------

\begin{code}

{-# OPTIONS --safe --without-K #-}

open import UF.FunExt
open import UF.PropTrunc
open import UF.Subsingletons

module Locales.DistributiveLattice.Ideal-Properties
        (pt : propositional-truncations-exist)
        (fe : Fun-Ext)
        (pe : Prop-Ext)
       where

open import Locales.DistributiveLattice.Definition fe pt
open import Locales.DistributiveLattice.Ideal pt fe pe
open import Locales.DistributiveLattice.Spectrum fe pe pt
open import Locales.Frame pt fe hiding (is-directed)
open import MLTT.Spartan
open import Slice.Family
open import UF.Classifiers
open import UF.Logic
open import UF.SubtypeClassifier

open AllCombinators pt fe hiding (_∨_)
open PropositionalTruncation pt hiding (_∨_)

\end{code}

We work in a module parameterized by a 𝓀-distributive-lattice `L`.

\begin{code}

module IdealProperties (L : DistributiveLattice 𝓀) where

 open DefnOfFrameOfIdeal  L
 open DistributiveLattice L
 open IdealNotation L

 contains-𝟏-implies-above-𝟏 : (I : Ideal L) β†’ 𝟏 ∈ⁱ I β†’ (𝟏ᡒ βŠ†α΅’ I) holds
 contains-𝟏-implies-above-𝟏 I μ₁ x ΞΌβ‚‚ =
  I-is-downward-closed x 𝟏 (𝟏ᡈ-is-top L x) μ₁
   where
    open Ideal I using (I-is-downward-closed)

 above-𝟏-implies-contains-𝟏 : (I : Ideal L) β†’ (𝟏ᡒ βŠ†α΅’ I) holds β†’ 𝟏 ∈ⁱ I
 above-𝟏-implies-contains-𝟏 I Ο† = Ο† 𝟏 (≀-is-reflexive (poset-ofᡈ L) 𝟏)

\end{code}

Added on 2024-03-13.

\begin{code}

 open PrincipalIdeals L
 open Joins _βŠ†α΅’_

\end{code}

Every ideal is the join of the principal ideals of the elements it contains. To
prove this fact, we start by writing down the family of principal ideals
generated by the elements of a given ideal.

\begin{code}

 principal-ideals-of : (I : Ideal L) β†’ Fam 𝓀 (Ideal L)
 principal-ideals-of I = ⁅ ↓ u ∣ (u , _) ∢ Ξ£ u κž‰ ∣ L ∣ᡈ , u ∈ⁱ I ⁆

\end{code}

Given an ideal `I`, it is clear that it is an upper bound of its family of
principal ideals.

\begin{code}

 ideal-is-an-upper-bound-of-its-principal-ideals
  : (I : Ideal L)
  β†’ (I is-an-upper-bound-of (principal-ideals-of I)) holds
 ideal-is-an-upper-bound-of-its-principal-ideals I (u , ΞΌα΅’) x ΞΌ =
  I-is-downward-closed x u ΞΌ ΞΌα΅’
   where
    open Ideal I using (I-is-downward-closed)

\end{code}

It is in fact the _least_ upper bound of this family.

\begin{code}

 ideal-is-lowerbound-of-upperbounds-of-its-principal-ideals
  : (I Iα΅€ : Ideal L)
  β†’ (Iα΅€ is-an-upper-bound-of (principal-ideals-of I)
  β‡’ (I βŠ†α΅’ Iα΅€)) holds
 ideal-is-lowerbound-of-upperbounds-of-its-principal-ideals I Iα΅€ Ο† x ΞΌ =
  Ο† (x , ΞΌ) x (≀-is-reflexive (poset-ofᡈ L) x)

\end{code}

Added on 2024-03-28.

\begin{code}

 open import Locales.DirectedFamily pt fe _βŠ†α΅’_

 principal-ideals-of-ideal-form-a-directed-family
  : (I : Ideal L)
  β†’ is-directed (principal-ideals-of I) holds
 principal-ideals-of-ideal-form-a-directed-family I =
  ∣ 𝟎 , I-contains-𝟎 ∣ , ‑
   where
    open Ideal I hiding (I)
    open PosetReasoning (poset-ofᡈ L)

    ‑ : is-closed-under-binary-upper-bounds (principal-ideals-of I) holds
    ‑ (x , μ₁) (y , ΞΌβ‚‚) = ∣ (x ∨ y , I-is-closed-under-∨ x y μ₁ ΞΌβ‚‚) , Ξ² , Ξ³ ∣
     where
      Ξ² : (↓ x βŠ†α΅’ ↓ (x ∨ y)) holds
      Ξ² z p = z β‰€βŸ¨ p ⟩ x β‰€βŸ¨ ∨-is-an-upper-bound₁ L x y ⟩ (x ∨ y) β– 

      Ξ³ : (↓ y βŠ†α΅’ ↓ (x ∨ y)) holds
      Ξ³ z p = z β‰€βŸ¨ p ⟩ y β‰€βŸ¨ ∨-is-an-upper-boundβ‚‚ L x y ⟩ (x ∨ y) β– 

\end{code}

Added on 2024-05-03.

Every ideal is directed.

\begin{code}

 open classifier-single-universe 𝓀

 open import Locales.DirectedFamily pt fe (Ξ» x y β†’ x β‰€α΅ˆ[ L ] y)
  using ()
  renaming (is-directed to is-directed-L;
            is-closed-under-binary-upper-bounds
             to is-closed-under-binary-upper-bounds-L)

 ideals-are-directed : (I : Ideal L) β†’ is-directed-L (𝕋 ∣ L ∣ᡈ (_∈ⁱ I)) holds
 ideals-are-directed ℐ = ∣ 𝟎 , I-contains-𝟎 ∣ , †
  where
   open Ideal ℐ using (I-contains-𝟎; I-is-closed-under-∨)

   † : is-closed-under-binary-upper-bounds-L (𝕋 ∣ L ∣ᡈ (_∈ⁱ ℐ)) holds
   † (x , μ₁) (y , ΞΌβ‚‚) = ∣ ((x ∨ y) , I-is-closed-under-∨ x y μ₁ ΞΌβ‚‚) , Ξ² , Ξ³ ∣
    where
     Ξ² : (x β‰€α΅ˆ[ L ] (x ∨ y)) holds
     Ξ² = ∨-is-an-upper-bound₁ L x y

     Ξ³ : (y β‰€α΅ˆ[ L ] (x ∨ y)) holds
     Ξ³ = ∨-is-an-upper-boundβ‚‚ L x y

\end{code}