open import Tools.Bool using (T; false)
open import Tools.Level
open import Tools.Sum
open import Graded.Modality.Instances.Zero-one-many false as ππΟ
open import Graded.Modality.Variant lzero
module Graded.Modality.Instances.Linearity
(variant : Modality-variant)
where
open Modality-variant variant
open ππΟ renaming (Zero-one-many to Linearity) public
open import Graded.Modality Linearity
open import Graded.FullReduction.Assumptions
import Graded.Modality.Properties
open import Definition.Untyped using (BMΞ£; π€; π¨)
import Definition.Typed.Restrictions
import Graded.Usage.Restrictions
open import Tools.Empty
open import Tools.Function
open import Tools.Nat using (Sequence)
open import Tools.Product
open import Tools.PropositionalEquality
open import Tools.Relation
linearityModality : Modality
linearityModality = zero-one-many-modality variant
open Definition.Typed.Restrictions linearityModality
open Graded.Usage.Restrictions linearityModality
private variable
rs : Type-restrictions
us : Usage-restrictions
pα΅’ : Sequence Linearity
incomparable :
let nrβ = zero-one-many-has-nr .Has-nr.nr
nrβ = zero-one-many-greatest-star-nr .Has-nr.nr
in
(ββ
Ξ» p r z s n β Β¬ nrβ p r z s n β€ nrβ p r z s n) Γ
(ββ
Ξ» p r z s n β Β¬ nrβ p r z s n β€ nrβ p r z s n)
incomparable =
(π , π , π , π , π , (Ξ» ()))
, (π , π , π , π , π , (Ξ» ()))
instance
linearity-has-well-behaved-zero :
Has-well-behaved-zero
(Modality.semiring-with-meet linearityModality)
linearity-has-well-behaved-zero = zero-one-many-has-well-behaved-zero
open Graded.Modality.Properties linearityModality
Suitable-for-full-reduction :
Type-restrictions β Usage-restrictions β Set
Suitable-for-full-reduction rs us =
(UnitΛ’-allowed β StarΛ’-sink) Γ
(UnitΚ·-allowed β Β¬ UnitΚ·-Ξ·) Γ
(β p β Β¬ Ξ£Λ’-allowed π p) Γ
(β p β Β¬ Ξ£Λ’-allowed Ο p)
where
open Type-restrictions rs
open Usage-restrictions us
suitable-for-full-reduction :
Type-restrictions β β Ξ» rs β Suitable-for-full-reduction rs us
suitable-for-full-reduction {us} rs =
record rs
{ Unit-allowed = Ξ» where
π¨ β UnitΚ·-allowed Γ Β¬ UnitΚ·-Ξ·
π€ β UnitΛ’-allowed Γ StarΛ’-sink
; Ξ Ξ£-allowed = Ξ» b p q β
Ξ Ξ£-allowed b p q Γ (b β‘ BMΞ£ π€ β p β‘ π)
; []-cong-allowed = Ξ» where
π¨ β []-congΚ·-allowed Γ Β¬ UnitΚ·-Ξ·
π€ β β₯
; []-congβErased = Ξ» where
{s = π¨} (ok , no-Ξ·) β
([]-congβErased ok .projβ , no-Ξ·)
, []-congβErased ok .projβ
, Ξ» ()
{s = π€} ()
; []-congβΒ¬Trivial = Ξ» { {s = π¨} _ (); {s = π€} () }
}
, projβ
, projβ
, (Ξ» _ β ((Ξ» ()) ββ (_$ refl)) ββ projβ)
, (Ξ» _ β ((Ξ» ()) ββ (_$ refl)) ββ projβ)
where
open Type-restrictions rs
open Usage-restrictions us
full-reduction-assumptions :
Suitable-for-full-reduction rs us β
Full-reduction-assumptions rs us
full-reduction-assumptions (sink , no-Ξ· , Β¬π , Β¬Ο) = record
{ sinkβπβ€π = Ξ» where
{s = π€} ok _ β injβ (refl , sink ok)
{s = π¨} _ (injβ ())
{s = π¨} ok (injβ Ξ·) β β₯-elim (no-Ξ· ok Ξ·)
; β‘πβπβ€π = Ξ» where
{p = π} ok β β₯-elim (Β¬π _ ok)
{p = Ο} ok β β₯-elim (Β¬Ο _ ok)
{p = π} _ β injβ refl
}
full-reduction-assumptions-suitable :
Full-reduction-assumptions rs us β Suitable-for-full-reduction rs us
full-reduction-assumptions-suitable {us = us} as =
(Ξ» ok β case sinkβπβ€π ok (injβ refl) of Ξ» where
(injβ (_ , sink)) β sink
(injβ ()))
, (Ξ» ok Ξ· β case sinkβπβ€π ok (injβ Ξ·) of Ξ» where
(injβ (() , _))
(injβ ()))
, (Ξ» p Ξ£-ok β case β‘πβπβ€π Ξ£-ok of Ξ» where
(injβ ())
(injβ (_ , _ , ())))
, (Ξ» p Ξ£-ok β case β‘πβπβ€π Ξ£-ok of Ξ» where
(injβ ())
(injβ (() , _)))
where
open Full-reduction-assumptions as
open Usage-restrictions us
opaque
π-GLB-inv :
Semiring-with-meet.Greatest-lower-bound zero-one-many-semiring-with-meet π pα΅’ β
β i β pα΅’ i β‘ π
π-GLB-inv π-glb i = lemma _ (π-glb .projβ i)
where
lemma : β p β π β€ p β p β‘ π
lemma π ()
lemma π _ = refl
lemma Ο ()
opaque
nrα΅’-GLB-π-inv :
let π = zero-one-many-semiring-with-meet in
β r z s β
Semiring-with-meet.Greatest-lower-bound π π (Semiring-with-meet.nrα΅’ π r z s) β
z β‘ π Γ s β‘ π
nrα΅’-GLB-π-inv r π π (πβ€ , _) = refl , refl
nrα΅’-GLB-π-inv π π π (πβ€ , _) = case πβ€ 1 of Ξ» ()
nrα΅’-GLB-π-inv π π π (πβ€ , _) = case πβ€ 1 of Ξ» ()
nrα΅’-GLB-π-inv Ο π π (πβ€ , _) = case πβ€ 1 of Ξ» ()
nrα΅’-GLB-π-inv r π Ο (πβ€ , _) = case πβ€ 1 of Ξ» ()
nrα΅’-GLB-π-inv r π s (πβ€ , _) = case πβ€ 0 of Ξ» ()
nrα΅’-GLB-π-inv r Ο s (πβ€ , _) = case πβ€ 0 of Ξ» ()
opaque
nrα΅’-GLB-π-inv :
let π = zero-one-many-semiring-with-meet in
β r z s β
Semiring-with-meet.Greatest-lower-bound π π (Semiring-with-meet.nrα΅’ π r z s) β
r β‘ π Γ z β‘ π Γ s β‘ π β r β‘ π Γ z β‘ π Γ s β‘ π
nrα΅’-GLB-π-inv π π π (πβ€ , glb) = case glb π (Ξ» i β β€-reflexive (sym (nrα΅’-π i))) of Ξ» ()
nrα΅’-GLB-π-inv π π π (πβ€ , glb) = case glb π (Ξ» i β β€-reflexive (sym (nrα΅’-π i))) of Ξ» ()
nrα΅’-GLB-π-inv Ο π π (πβ€ , glb) = case glb π (Ξ» i β β€-reflexive (sym (nrα΅’-π i))) of Ξ» ()
nrα΅’-GLB-π-inv π π π (πβ€ , _) = case πβ€ 0 of Ξ» ()
nrα΅’-GLB-π-inv π π π (πβ€ , _) = case πβ€ 2 of Ξ» ()
nrα΅’-GLB-π-inv Ο π π (πβ€ , _) = case πβ€ 2 of Ξ» ()
nrα΅’-GLB-π-inv r π Ο (πβ€ , _) = case πβ€ 1 of Ξ» ()
nrα΅’-GLB-π-inv π π π (πβ€ , _) = case πβ€ 1 of Ξ» ()
nrα΅’-GLB-π-inv π π π (πβ€ , _) = injβ (refl , refl , refl)
nrα΅’-GLB-π-inv Ο π π (πβ€ , _) = case πβ€ 1 of Ξ» ()
nrα΅’-GLB-π-inv π π π (πβ€ , _) = injβ (refl , refl , refl)
nrα΅’-GLB-π-inv π π π (πβ€ , _) = case πβ€ 1 of Ξ» ()
nrα΅’-GLB-π-inv Ο π π (πβ€ , _) = case πβ€ 1 of Ξ» ()
nrα΅’-GLB-π-inv r π Ο (πβ€ , _) = case πβ€ 1 of Ξ» ()
nrα΅’-GLB-π-inv r Ο s (πβ€ , _) = case πβ€ 0 of Ξ» ()
opaque
nrα΅’-rπp-GLB-π-inv :
let π = zero-one-many-semiring-with-meet in
β p r β
Semiring-with-meet.Greatest-lower-bound π π (Semiring-with-meet.nrα΅’ π r π p) β
p β‘ π Γ r β‘ π β p β‘ π Γ r β‘ π
nrα΅’-rπp-GLB-π-inv p r glb =
case nrα΅’-GLB-π-inv r π p glb of Ξ» where
(injβ (rβ‘π , _ , pβ‘π)) β injβ (pβ‘π , rβ‘π)
(injβ (rβ‘π , _ , pβ‘π)) β injβ (pβ‘π , rβ‘π)