------------------------------------------------------------------------
-- Term equality tests used by Definition.Typed.Decidable.Internal
------------------------------------------------------------------------

open import Definition.Typed.Restrictions
open import Graded.Modality
open import Graded.Mode

module Definition.Typed.Decidable.Internal.Equality
  {a b} {M : Set a} {Mode : Set b}
  {𝕄 : Modality M}
  (𝐌 : IsMode Mode 𝕄)
  (R : Type-restrictions 𝕄)
  where

open import Definition.Typed.Decidable.Internal.Term 𝐌 R

import Definition.Untyped M as U

open import Tools.Fin as Fin
open import Tools.Maybe
open import Tools.Nat as N using (Nat)
open import Tools.PropositionalEquality
import Tools.Vec as Vec

private variable
  m n : Nat
  c   : Constants

-- Are the two grade terms syntactically equal?

infix 4 _β‰Ÿα΅_

_β‰Ÿα΅_ : (t₁ tβ‚‚ : Termᡍ n) β†’ Maybe (t₁ ≑ tβ‚‚)
var x β‰Ÿα΅ var y =
  cong var <$> decβ‡’maybe (x β‰Ÿβ±½ y)
𝟘 β‰Ÿα΅ 𝟘 =
  just refl
πŸ™ β‰Ÿα΅ πŸ™ =
  just refl
Ο‰ β‰Ÿα΅ Ο‰ =
  just refl
t₁₁ + t₁₂ β‰Ÿα΅ t₂₁ + tβ‚‚β‚‚ =
  congβ‚‚ _+_ <$> t₁₁ β‰Ÿα΅ t₂₁ βŠ› t₁₂ β‰Ÿα΅ tβ‚‚β‚‚
t₁₁ Β· t₁₂ β‰Ÿα΅ t₂₁ Β· tβ‚‚β‚‚ =
  congβ‚‚ _Β·_ <$> t₁₁ β‰Ÿα΅ t₂₁ βŠ› t₁₂ β‰Ÿα΅ tβ‚‚β‚‚
t₁₁ ∧ t₁₂ β‰Ÿα΅ t₂₁ ∧ tβ‚‚β‚‚ =
  congβ‚‚ _∧_ <$> t₁₁ β‰Ÿα΅ t₂₁ βŠ› t₁₂ β‰Ÿα΅ tβ‚‚β‚‚
⌜⌞ t₁ ⌟⌝ β‰Ÿα΅ ⌜⌞ tβ‚‚ ⌟⌝ =
  cong ⌜⌞_⌟⌝ <$> t₁ β‰Ÿα΅ tβ‚‚
_ β‰Ÿα΅ _ =
  nothing

-- Are the two strength terms syntactically equal?

infix 4 _β‰ŸΛ’_

_β‰ŸΛ’_ : (t₁ tβ‚‚ : TermΛ’ n) β†’ Maybe (t₁ ≑ tβ‚‚)
var x β‰ŸΛ’ var y =
  cong var <$> decβ‡’maybe (x β‰Ÿβ±½ y)
𝕀 β‰ŸΛ’ 𝕀 =
  just refl
𝕨 β‰ŸΛ’ 𝕨 =
  just refl
_ β‰ŸΛ’ _ =
  nothing

-- Are the two binder mode terms syntactically equal?

infix 4 _β‰Ÿα΅‡α΅_

_β‰Ÿα΅‡α΅_ : (t₁ tβ‚‚ : Termᡇᡐ m n) β†’ Maybe (t₁ ≑ tβ‚‚)
var x β‰Ÿα΅‡α΅ var y =
  cong var <$> decβ‡’maybe (x β‰Ÿβ±½ y)
BMΞ  β‰Ÿα΅‡α΅ BMΞ  =
  just refl
BMΞ£ s₁ β‰Ÿα΅‡α΅ BMΞ£ sβ‚‚ =
  cong BMΞ£ <$> s₁ β‰ŸΛ’ sβ‚‚
_ β‰Ÿα΅‡α΅ _ =
  nothing