zeroIsSubj/zeroIsGlobal work on all zeroes

This commit is contained in:
rhiannon morris 2023-02-19 17:42:11 +01:00
parent e375d008e5
commit 810de09f61
3 changed files with 17 additions and 15 deletions

View file

@ -48,7 +48,7 @@ interface Eq q => IsQty q where
||| subject of a typing judgement [@qtt, §2.3].
IsSubj : Pred q
isSubj : Dec1 IsSubj
zeroIsSubj : IsSubj zero
zeroIsSubj : forall pi. IsZero pi -> IsSubj pi
oneIsSubj : IsSubj one
timesSubj : forall pi, rh. IsSubj pi -> IsSubj rh -> IsSubj (pi * rh)
@ -56,7 +56,7 @@ interface Eq q => IsQty q where
||| quantity. so not exact usage counts, maybe.
IsGlobal : Pred q
isGlobal : Dec1 IsGlobal
zeroIsGlobal : IsGlobal zero
zeroIsGlobal : forall pi. IsZero pi -> IsGlobal zero
public export
0 SQty : (q : Type) -> IsQty q => Type
@ -64,16 +64,27 @@ SQty q = Subset q IsSubj
public export %inline
szero : IsQty q => SQty q
szero = Element zero zeroIsSubj
szero = Element zero $ zeroIsSubj zeroIsZero
public export %inline
sone : IsQty q => SQty q
sone = Element one oneIsSubj
||| "σ ⨴ π"
|||
||| ``sg `subjMult` pi`` is equal to `pi` if it is zero, otherwise it
||| is equal to `sg`.
public export %inline
subjMult : IsQty q => SQty q -> q -> SQty q
subjMult sg pi = case isZero pi of
Yes y => Element pi $ zeroIsSubj y
No _ => sg
public export
0 GQty : (q : Type) -> IsQty q => Type
GQty q = Subset q IsGlobal
public export %inline
gzero : IsQty q => GQty q
gzero = Element zero zeroIsGlobal
gzero = Element zero $ zeroIsGlobal zeroIsZero

View file

@ -99,13 +99,13 @@ IsQty Three where
IsSubj = IsSubj3
isSubj = isSubj3
zeroIsSubj = SZero
zeroIsSubj = \Refl => SZero
oneIsSubj = SOne
timesSubj = timesSubj3
IsGlobal = IsGlobal3
isGlobal = isGlobal3
zeroIsGlobal = GZero
zeroIsGlobal = \Refl => GZero
export Uninhabited (IsGlobal3 One) where uninhabited _ impossible

View file

@ -52,15 +52,6 @@ private %inline
lookupFree : CanTC' q g m => Name -> m (Definition' q g)
lookupFree x = lookupFree' !ask x
||| ``sg `subjMult` pi`` is zero if either argument is, otherwise it
||| is equal to `sg`. (written as "σ ⨴ π" to emphasise its left bias.)
|||
||| only certain quantities can occur for a typing judgement to avoid losing
||| subject reduction [@qtt, §2.3], which is why this is not just `sg*pi`.
private %inline
subjMult : IsQty q => SQty q -> q -> SQty q
subjMult sg pi = if isYes $ isZero pi then szero else sg
parameters {auto _ : IsQty q} {auto _ : CanTC q m}
mutual