import Graded.Modality
import Graded.Mode.Instances.Zero-one.Variant
module Graded.Restrictions.Zero-one
{a} {M : Set a}
(open Graded.Modality M)
(π : Modality)
(open Graded.Mode.Instances.Zero-one.Variant π)
(variant : Mode-variant)
where
open Modality π
open import Tools.Bool
open import Tools.Empty
open import Tools.Function
open import Tools.Level
open import Tools.Product as Ξ£
open import Tools.PropositionalEquality
open import Tools.Relation as Dec
open import Tools.Sum
open import Tools.Unit
open import Graded.Modality.Properties π
open import Graded.Mode.Instances.Zero-one variant hiding (_β_)
import Graded.Usage.Decidable.Assumptions as UD
open import Graded.Usage.Erased-matches
open import Graded.Usage.Restrictions π Zero-one-isMode
open import Graded.Usage.Restrictions.Natrec π
import Definition.Typechecking.Decidable.Assumptions as TD
open import Definition.Typed.Restrictions π
open import Definition.Typed.Variant
open import Definition.Untyped.NotParametrised
open import Definition.Untyped.Properties.NotParametrised
open import Graded.Restrictions π Zero-one-isMode public
hiding (nr-available-UR; no-usage-restrictions;
No-erased-matches; No-erased-matchesβ²)
import Graded.Restrictions π Zero-one-isMode as GR
private variable
TR : Type-restrictions
UR : Usage-restrictions
b : Bool
ok : T _
s : Strength
nm : Natrec-mode
opaque
πα΅πα΅ββ€α΅ :
(P : (m mβ² : Mode) β Set) β
(β {ok} β P πα΅ πα΅[ ok ]) β
(β {m} β P m m) β
β {m mβ²} β m β€α΅ mβ² β P m mβ²
πα΅πα΅ββ€α΅ P okββ okα΅£ {(πα΅)} {(πα΅)} mβ€α΅mβ² = subst (P _) πα΅-cong okα΅£
πα΅πα΅ββ€α΅ P okββ okα΅£ {(πα΅)} {(πα΅)} ()
πα΅πα΅ββ€α΅ P okββ okα΅£ {(πα΅)} {(πα΅[ ok ])} mβ€α΅mβ² = subst (P _) πα΅-cong (okββ {ok})
πα΅πα΅ββ€α΅ P okββ okα΅£ {(πα΅)} {(πα΅)} mβ€α΅mβ² = okα΅£
no-usage-restrictions :
(nm : Natrec-mode) β
Bool β Bool β Usage-restrictions
no-usage-restrictions nm =
GR.no-usage-restrictions nm
(Ξ» { β¦ (Nr) β¦ β Zero-one-supports-nr β¦ Natrec-mode-Has-nr Nr β¦ })
not-all-for-πα΅ : (Mode β Erased-matches) β Mode β Erased-matches
not-all-for-πα΅ f πα΅ = f πα΅
not-all-for-πα΅ f πα΅ with f πα΅
β¦ | all = some
β¦ | em = em
not-all-erased-matches-JK : Usage-restrictions β Usage-restrictions
not-all-erased-matches-JK UR = record UR
{ erased-matches-for-J =
not-all-for-πα΅ erased-matches-for-J
; erased-matches-for-J-β€α΅α΅ =
πα΅πα΅ββ€α΅ (Ξ» m mβ² β not-all-for-πα΅ erased-matches-for-J m β€α΅α΅ not-all-for-πα΅ erased-matches-for-J mβ²)
(not-all-for-πα΅-β€α΅α΅ erased-matches-for-J (erased-matches-for-J-β€α΅α΅ πα΅β€))
β€α΅α΅-reflexive
; erased-matches-for-K =
not-all-for-πα΅ erased-matches-for-K
; erased-matches-for-K-β€α΅α΅ =
πα΅πα΅ββ€α΅ (Ξ» m mβ² β not-all-for-πα΅ erased-matches-for-K m β€α΅α΅ not-all-for-πα΅ erased-matches-for-K mβ²)
(not-all-for-πα΅-β€α΅α΅ erased-matches-for-K (erased-matches-for-K-β€α΅α΅ πα΅β€))
β€α΅α΅-reflexive
}
where
open Usage-restrictions UR
opaque
not-all-for-πα΅-β€α΅α΅ :
(f : Mode β Erased-matches) β
f πα΅ β€α΅α΅ f πα΅[ ok ] β
not-all-for-πα΅ f πα΅ β€α΅α΅ not-all-for-πα΅ f πα΅[ ok ]
not-all-for-πα΅-β€α΅α΅ f f-β€α΅α΅ with f πα΅
β¦ | all = β€α΅α΅-transitive _ f-β€α΅α΅
β¦ | some = f-β€α΅α΅
β¦ | none = f-β€α΅α΅
only-some-erased-matches : Usage-restrictions β Usage-restrictions
only-some-erased-matches UR = record UR
{ Prodrec-allowed = Ξ» m r p q β
Prodrec-allowed m r p q Γ
(m β‘ πα΅ β Β¬ Trivial β r β’ π)
; Prodrec-allowed-upwards-closed = Ξ» (ok , rβ’π) mβ€mβ² β
Prodrec-allowed-upwards-closed ok mβ€mβ² , Ξ» { refl β rβ’π (β€α΅-πα΅β mβ€mβ²) }
; erased-matches-for-J =
f (erased-matches-for-J πα΅?)
; erased-matches-for-J-β€α΅α΅ =
πα΅πα΅ββ€α΅ (Ξ» m mβ² β f _ m β€α΅α΅ f _ mβ²) _ β€α΅α΅-reflexive
; erased-matches-for-K =
f (erased-matches-for-K πα΅?)
; erased-matches-for-K-β€α΅α΅ =
πα΅πα΅ββ€α΅ (Ξ» m mβ² β f _ m β€α΅α΅ f _ mβ²) _ β€α΅α΅-reflexive
}
where
open Usage-restrictions UR
f : Erased-matches β Mode β Erased-matches
f _ πα΅ = none
f em πα΅ = em
no-erased-matches-UR :
Type-restrictions β Usage-restrictions β Usage-restrictions
no-erased-matches-UR TR UR = record (only-some-erased-matches UR)
{ Unitrec-allowed = Ξ» m p q β
Unitrec-allowed m p q Γ
(m β‘ πα΅ β Β¬ Trivial β p β‘ π β UnitΚ·-Ξ·)
; Unitrec-allowed-upwards-closed = Ξ» (ok , Ξ·) mβ€mβ² β
Unitrec-allowed-upwards-closed ok mβ€mβ² , Ξ» { refl β Ξ· (β€α΅-πα΅β mβ€mβ²) }
}
where
open Type-restrictions TR
open Usage-restrictions UR
nr-available-UR :
(has-nr : Has-nr π) β
Usage-restrictions β Usage-restrictions
nr-available-UR has-nr UR = record UR
{ natrec-mode = Nr β¦ has-nr β¦
; mode-supports-nr = Ξ» { β¦ (Nr) β¦ β Zero-one-supports-nr}
}
at-least-some : (Mode β Erased-matches) β Mode β Erased-matches
at-least-some f m = case f m of Ξ» where
none β some
em β em
no-[]-cong-UR : Usage-restrictions β Usage-restrictions
no-[]-cong-UR UR = record UR
{ []-cong-allowed-mode = Ξ» _ _ β Lift _ β₯
; []-cong-allowed-mode-upwards-closed = Ξ» ()
; erased-matches-for-J = at-least-some erased-matches-for-J
; erased-matches-for-J-β€α΅α΅ =
πα΅πα΅ββ€α΅ (Ξ» m mβ² β at-least-some erased-matches-for-J m β€α΅α΅ at-least-some erased-matches-for-J mβ²)
at-least-some-β€α΅α΅ β€α΅α΅-reflexive
}
where
open Usage-restrictions UR
at-least-some-β€α΅α΅ :
at-least-some erased-matches-for-J πα΅ β€α΅α΅
at-least-some erased-matches-for-J πα΅[ ok ]
at-least-some-β€α΅α΅ {ok}
with erased-matches-for-J πα΅
| erased-matches-for-J πα΅[ ok ]
| erased-matches-for-J-β€α΅α΅ {m = πα΅} {mβ² = πα΅[ ok ]} πα΅β€
β¦ | none | none | _ = _
β¦ | none | some | _ = _
β¦ | none | all | _ = _
β¦ | all | none | ()
β¦ | some | none | ()
β¦ | not-none _ | not-none _ | r = r
Only-some-erased-matches :
Type-restrictions β Usage-restrictions β Set a
Only-some-erased-matches TR UR =
Β¬ Trivial β
(β {r p q} β Prodrec-allowed πα΅ r p q β r β’ π) Γ
(β {s} β Β¬ ([]-cong-allowed s)) Γ
erased-matches-for-J πα΅ β‘ none Γ
erased-matches-for-K πα΅ β‘ none
where
open Type-restrictions TR
open Usage-restrictions UR
opaque
Only-some-erased-matches-only-some-erased-matches :
β TR UR β
Only-some-erased-matches
(no-erased-matches-TR π€ (no-erased-matches-TR π¨ TR))
(only-some-erased-matches UR)
Only-some-erased-matches-only-some-erased-matches _ _ πβ’π =
(Ξ» x β x refl πβ’π) ββ projβ
, (Ξ» where
{s = π€} β (_$ refl) ββ projβ
{s = π¨} β (_$ refl) ββ projβ ββ projβ)
, refl
, refl
No-erased-matches : Type-restrictions β Usage-restrictions β Set a
No-erased-matches TR UR =
Β¬ Trivial β
(β {r p q} β Prodrec-allowed πα΅ r p q β r β’ π) Γ
(β {p q} β Unitrec-allowed πα΅ p q β p β‘ π β UnitΚ·-Ξ·) Γ
(β {s} β Β¬ ([]-cong-allowed s)) Γ
erased-matches-for-J πα΅ β‘ none Γ
erased-matches-for-K πα΅ β‘ none
where
open Type-restrictions TR
open Usage-restrictions UR
No-erased-matches-no-erased-matches :
β TR UR β
let TRβ² = no-erased-matches-TR π€ (no-erased-matches-TR π¨ TR) in
No-erased-matches TRβ² (no-erased-matches-UR TRβ² UR)
No-erased-matches-no-erased-matches TR UR πβ’π =
case Only-some-erased-matches-only-some-erased-matches TR UR πβ’π of Ξ»
(pr , rest) β
(Ξ» {_ _ _} β pr)
, (Ξ» {_ _} β (Ξ» x β x refl πβ’π) ββ projβ)
, rest
opaque
Only-some-erased-matchesβNo-erased-matches :
β TR UR β
Type-restrictions.UnitΚ·-Ξ· TR β
Only-some-erased-matches TR UR β No-erased-matches TR UR
Only-some-erased-matchesβNo-erased-matches _ _ Ξ· =
Ξ£.map idαΆ ((Ξ» {_ _} _ _ β Ξ·) ,_) ββ_
No-erased-matchesβ² : Type-variant β Usage-restrictions β Set a
No-erased-matchesβ² TV UR =
Β¬ Trivial β
(β {r p q} β Prodrec-allowed πα΅ r p q β r β’ π) Γ
(β {p q} β Unitrec-allowed πα΅ p q β p β‘ π β UnitΚ·-Ξ·) Γ
(β {s} β Β¬ ([]-cong-allowed-mode s πα΅)) Γ
erased-matches-for-J πα΅ β‘ none Γ
erased-matches-for-K πα΅ β‘ none
where
open Type-variant TV
open Usage-restrictions UR
opaque
Assumptions-no-usage-restrictions :
β¦ ok : Natrec-mode-supports-usage-inference nm β¦ β
Decidable (_β‘_ {A = M}) β
UD.Assumptions (no-usage-restrictions nm b false)
Assumptions-no-usage-restrictions dec = Ξ» where
._β_ β dec
.Prodrec-allowed? _ _ _ _ β yes _
.Unitrec-allowed? _ _ _ β yes _
.Emptyrec-allowed? _ _ β yes _
.[]-cong-allowed-mode? _ _ β yes _
.no-sink-or-β€π β injβ idαΆ
where
open UD.Assumptions
opaque
Assumptions-not-all-erased-matches-JK :
UD.Assumptions UR β UD.Assumptions (not-all-erased-matches-JK UR)
Assumptions-not-all-erased-matches-JK as = Ξ» where
._β_ β A._β_
.Prodrec-allowed? β A.Prodrec-allowed?
.Unitrec-allowed? β A.Unitrec-allowed?
.Emptyrec-allowed? β A.Emptyrec-allowed?
.[]-cong-allowed-mode? β A.[]-cong-allowed-mode?
.no-sink-or-β€π β A.no-sink-or-β€π
where
module A = UD.Assumptions as
open UD.Assumptions
opaque
Assumptions-only-some-erased-matches :
UD.Assumptions UR β UD.Assumptions (only-some-erased-matches UR)
Assumptions-only-some-erased-matches as = Ξ» where
._β_ β A._β_
.Prodrec-allowed? m r p q β A.Prodrec-allowed? m r p q
Γ-dec
Dec.map (Ξ» β‘π β trans (sym (ββββ _)) (trans (ββ-cong β‘π) βπβ))
(Ξ» { refl β βπα΅β}) (β m β A.β π)
β-dec
Β¬? trivial?
β-dec
Β¬? (r A.β π)
.Unitrec-allowed? β A.Unitrec-allowed?
.Emptyrec-allowed? β A.Emptyrec-allowed?
.[]-cong-allowed-mode? β A.[]-cong-allowed-mode?
.no-sink-or-β€π β A.no-sink-or-β€π
where
module A = UD.Assumptions as
open UD.Assumptions
opaque
Assumptions-no-erased-matches-UR :
β TR β UD.Assumptions UR β
UD.Assumptions (no-erased-matches-UR TR UR)
Assumptions-no-erased-matches-UR TR as = Ξ» where
._β_ β A._β_
.Prodrec-allowed? β A.Prodrec-allowed?
.Unitrec-allowed? m p q β A.Unitrec-allowed? m p q
Γ-dec
(Dec.map (Ξ» β‘π β trans (sym (ββββ _)) (trans (ββ-cong β‘π) βπβ))
(Ξ» { refl β βπα΅β}) (β m β A.β π)
β-dec
Β¬? trivial?
β-dec
p A.β π
β-dec
UnitΚ·-Ξ·?)
.Emptyrec-allowed? β A.Emptyrec-allowed?
.[]-cong-allowed-mode? β A.[]-cong-allowed-mode?
.no-sink-or-β€π β A.no-sink-or-β€π
where
module A = UD.Assumptions (Assumptions-only-some-erased-matches as)
open UD.Assumptions
open Type-restrictions TR