------------------------------------------------------------------------
-- Assumptions used to state some theorems in
-- Graded.Erasure.LogicalRelation.Fundamental elsewhere for consequences
-- of the fundamental lemma.
------------------------------------------------------------------------

open import Graded.Modality
open import Graded.Usage.Restrictions
open import Definition.Typed.EqualityRelation
open import Definition.Typed.Restrictions

module Graded.Erasure.LogicalRelation.Fundamental.Assumptions
  {a} {M : Set a}
  {š•„ : Modality M}
  (TR : Type-restrictions š•„)
  (UR : Usage-restrictions š•„)
  where

open Modality š•„
open Type-restrictions TR
open Usage-restrictions UR

open import Definition.Untyped M
open import Definition.Typed TR
open import Definition.Typed.Consequences.Consistency TR
open import Definition.Typed.Properties TR
open import Definition.Typed.Substitution TR

open import Graded.Mode š•„
open import Graded.Usage š•„ UR
open import Graded.Restrictions š•„

open import Tools.Nat
open import Tools.Sum

private variable
  k kᵈ : Nat
  āˆ‡    : DCon (Term 0) _

-- A cut-down variant of Fundamental-assumptions (which is defined
-- below).

record Fundamental-assumptions⁻ (Ī” : Cons kᵈ k) : Set a where
  no-eta-equality
  field
    -- Every transparent definition in Ī” is well-resourced.
    well-resourced : ā–ø[ šŸ™įµ ] (Ī” .defs)
    -- If erased matches are allowed for emptyrec when the mode isĀ šŸ™įµ,
    -- then the contexts in Ī” are consistent.
    consistent : Emptyrec-allowed šŸ™įµ šŸ˜ → Consistent Ī”
    -- Erased matches are not allowed unless the variable context is
    -- empty.
    closed-or-no-erased-matches :
      No-erased-matches TR UR āŠŽ Empty-con (Ī” .vars)
    instance
      -- No-equality-reflection holds or the variable context is
      -- empty.
      ⦃ no-equality-reflection-or-empty ⦄ :
        No-equality-reflection or-empty Ī” .vars

-- The fundamental lemma is proved under the assumption that a given
-- context pair Ī” satisfies the following assumptions.

record Fundamental-assumptions (Ī” : Cons kᵈ k) : Set a where
  no-eta-equality
  field
    -- The context is well-formed.
    well-formed : ⊢ Ī”
    -- Other assumptions.
    other-assumptions : Fundamental-assumptions⁻ Ī”

  open Fundamental-assumptions⁻ other-assumptions public

-- Fundamental-assumptions⁻ holds for an empty variable context if the
-- definition context is well-formed and well-resourced.

fundamental-assumptions⁻₀ :
  Ā» āˆ‡ → ā–ø[ šŸ™įµ ] āˆ‡ → Fundamental-assumptions⁻ (āˆ‡ Ā» ε)
fundamental-assumptions⁻₀ ā‰«āˆ‡ ā–øāˆ‡     = record
  { well-resourced                  = ā–øāˆ‡
  ; consistent                      = Ī» _ →
                                        inhabited-consistent
                                          (⊢ˢʷ∷-idSubst (ε ā‰«āˆ‡))
  ; closed-or-no-erased-matches     = injā‚‚ ε
  ; no-equality-reflection-or-empty = ε
  }

-- Fundamental-assumptions holds for an empty variable context if the
-- definition context is well-formed and well-resourced.

fundamental-assumptionsā‚€ :
  Ā» āˆ‡ → ā–ø[ šŸ™įµ ] āˆ‡ → Fundamental-assumptions (āˆ‡ Ā» ε)
fundamental-assumptionsā‚€ ā‰«āˆ‡ ā–øāˆ‡ = record
  { well-formed       = ε ā‰«āˆ‡
  ; other-assumptions = fundamental-assumptions⁻₀ ā‰«āˆ‡ ā–øāˆ‡
  }