------------------------------------------------------------------------
-- Properties of equality.
------------------------------------------------------------------------

open import Graded.Modality

module Graded.Modality.Properties.Equivalence
  {a} {M : Set a} (𝕄 : Semiring-with-meet M) where

open Semiring-with-meet 𝕄

open import Graded.Modality.Properties.PartialOrder 𝕄

open import Tools.Function
open import Tools.PropositionalEquality
import Tools.Reasoning.PropositionalEquality
open import Tools.Relation

private variable
  p q : M

------------------------------------------------------------------------
-- Decision procedures

-- If _≀_ is decidable, then _≑_ is decidable (for M).

≀-decidable→≑-decidable : Decidable _≀_ β†’ Decidable (_≑_ {A = M})
≀-decidable→≑-decidable _≀?_ p q = case p ≀? q of Ξ» where
  (no pβ‰°q)  β†’ no Ξ» p≑q β†’ pβ‰°q (≀-reflexive p≑q)
  (yes p≀q) β†’ case q ≀? p of Ξ» where
    (no qβ‰°p)  β†’ no Ξ» p≑q β†’ qβ‰°p (≀-reflexive (sym p≑q))
    (yes q≀p) β†’ yes (≀-antisym p≀q q≀p)

------------------------------------------------------------------------
-- Properties related to "πŸ™Β β‰‘Β πŸ˜"

-- If πŸ™Β β‰‘Β πŸ˜, then every value is equal to 𝟘.

β‰‘πŸ˜ : πŸ™ ≑ 𝟘 β†’ p ≑ 𝟘
β‰‘πŸ˜ {p = p} πŸ™β‰‘πŸ˜ = begin
  p      β‰‘Λ˜βŸ¨ Β·-identityΛ‘ _ ⟩
  πŸ™ Β· p  β‰‘βŸ¨ Β·-congΚ³ πŸ™β‰‘πŸ˜ ⟩
  𝟘 Β· p  β‰‘βŸ¨ Β·-zeroΛ‘ _ ⟩
  𝟘      ∎
  where
  open Tools.Reasoning.PropositionalEquality

-- If πŸ™Β β‰‘Β πŸ˜, then _≑_ is trivial.

≑-trivial : πŸ™ ≑ 𝟘 β†’ p ≑ q
≑-trivial {p = p} {q = q} πŸ™β‰‘πŸ˜ = begin
  p  β‰‘βŸ¨ β‰‘πŸ˜ πŸ™β‰‘πŸ˜ ⟩
  𝟘  β‰‘Λ˜βŸ¨ β‰‘πŸ˜ πŸ™β‰‘πŸ˜ ⟩
  q  ∎
  where
  open Tools.Reasoning.PropositionalEquality

-- If there are two distinct values, then πŸ™Β β‰’Β πŸ˜.

β‰’β†’πŸ™β‰’πŸ˜ : p β‰’ q β†’ πŸ™ β‰’ 𝟘
β‰’β†’πŸ™β‰’πŸ˜ pβ‰’q = pβ‰’q βˆ˜β†’ ≑-trivial