open import Tools.Level
open import Tools.Relation
module Graded.Modality {a} (M : Set a) where
open import Tools.Algebra M
open import Tools.Bool using (Bool; T)
open import Tools.Nat using (Nat; 1+; Sequence)
open import Tools.Product
open import Tools.PropositionalEquality
open import Tools.Sum
open import Graded.Modality.Variant a
private variable
n n₁ n₂ p p′ q r z z₁ s s₁ s₂ z₂ : M
pᵢ : Sequence M
record Semiring-with-meet : Set a where
no-eta-equality
pattern
infixr 40 _+_
infixr 43 _∧_
infixr 45 _·_
infix 10 _≤_ _<_
field
_+_ _·_ _∧_ : Op₂ M
𝟘 𝟙 ω : M
+-·-Semiring : IsSemiring _+_ _·_ 𝟘 𝟙
∧-Semilattice : IsMeetSemilattice _∧_
·-distrib-∧ : _·_ DistributesOver _∧_
+-distrib-∧ : _+_ DistributesOver _∧_
_≤_ : Rel M a
p ≤ q = p ≡ p ∧ q
_<_ : Rel M a
p < q = p ≤ q × p ≢ q
field
ω≤𝟙 : ω ≤ 𝟙
ω·+≤ω·ʳ : ω · (p + q) ≤ ω · q
is-𝟘? : (p : M) → Dec (p ≡ 𝟘)
Trivial : Set a
Trivial = 𝟙 ≡ 𝟘
Least-such-that : (M → Set a) → M → Set a
Least-such-that P p = P p × (∀ q → P q → p ≤ q)
Greatest-such-that : ∀ {ℓ} → (M → Set ℓ) → M → Set (a ⊔ ℓ)
Greatest-such-that P p = P p × (∀ q → P q → q ≤ p)
Greatest-lower-bound : M → Sequence M → Set a
Greatest-lower-bound p pᵢ = Greatest-such-that (λ r → ∀ i → r ≤ pᵢ i) p
nrᵢ : (r z s : M) → Sequence M
nrᵢ r z s 0 = z
nrᵢ r z s (1+ i) = s + r · nrᵢ r z s i
·-distribˡ-∧ : _·_ DistributesOverˡ _∧_
·-distribˡ-∧ = proj₁ ·-distrib-∧
·-distribʳ-∧ : _·_ DistributesOverʳ _∧_
·-distribʳ-∧ = proj₂ ·-distrib-∧
+-distribˡ-∧ : _+_ DistributesOverˡ _∧_
+-distribˡ-∧ = proj₁ +-distrib-∧
+-distribʳ-∧ : _+_ DistributesOverʳ _∧_
+-distribʳ-∧ = proj₂ +-distrib-∧
+-·-Semiring′ : Semiring a a
+-·-Semiring′ = record
{ Carrier = M
; _≈_ = _≡_
; _+_ = _+_
; _*_ = _·_
; 0# = 𝟘
; 1# = 𝟙
; isSemiring = +-·-Semiring
}
open IsSemiring +-·-Semiring public
using (
+-assoc;
+-cong;
+-congˡ;
+-congʳ;
+-identity;
+-identityˡ;
+-identityʳ;
+-comm
)
renaming (
*-assoc to ·-assoc;
*-cong to ·-cong;
*-congˡ to ·-congˡ;
*-congʳ to ·-congʳ;
*-identity to ·-identity;
*-identityˡ to ·-identityˡ;
*-identityʳ to ·-identityʳ;
distrib to ·-distrib-+;
distribˡ to ·-distribˡ-+;
distribʳ to ·-distribʳ-+;
zero to ·-zero;
zeroˡ to ·-zeroˡ;
zeroʳ to ·-zeroʳ
)
open IsMeetSemilattice ∧-Semilattice public
using (∧-cong; ∧-congˡ; ∧-congʳ)
renaming (comm to ∧-comm;
idem to ∧-idem;
assoc to ∧-assoc
)
record Has-well-behaved-zero (𝕄 : Semiring-with-meet) : Set a where
no-eta-equality
pattern
open Semiring-with-meet 𝕄
field
non-trivial : ¬ Trivial
zero-product : {p q : M} → p · q ≡ 𝟘 → p ≡ 𝟘 ⊎ q ≡ 𝟘
+-positiveˡ : {p q : M} → p + q ≡ 𝟘 → p ≡ 𝟘
∧-positiveˡ : {p q : M} → p ∧ q ≡ 𝟘 → p ≡ 𝟘
record Has-nr (𝕄 : Semiring-with-meet) : Set a where
no-eta-equality
pattern
open Semiring-with-meet 𝕄
field
nr : M → M → M → M → M → M
nr-monotone :
z₁ ≤ z₂ → s₁ ≤ s₂ → n₁ ≤ n₂ →
nr p r z₁ s₁ n₁ ≤ nr p r z₂ s₂ n₂
nr-· : nr p r z s n · q ≤ nr p r (z · q) (s · q) (n · q)
nr-+ :
nr p r z₁ s₁ n₁ + nr p r z₂ s₂ n₂ ≤
nr p r (z₁ + z₂) (s₁ + s₂) (n₁ + n₂)
nr-positive :
⦃ 𝟘-well-behaved : Has-well-behaved-zero 𝕄 ⦄ →
nr p r z s n ≡ 𝟘 → z ≡ 𝟘 × s ≡ 𝟘 × n ≡ 𝟘
nr-zero : n ≤ 𝟘 → nr p r z s n ≤ z
nr-suc : nr p r z s n ≤ s + p · n + r · nr p r z s n
Linearity-like-nr-for-𝟘 : Set a
Linearity-like-nr-for-𝟘 =
∀ {p z s n} →
nr p 𝟘 z s n ≡ ((𝟙 ∧ p) · n + s) ∧ (n + z)
Linearity-like-nr-for-𝟙 : Set a
Linearity-like-nr-for-𝟙 =
∀ {p z s n} →
nr p 𝟙 z s n ≡ (𝟙 + p) · n + ω · s + z
record Is-factoring-nr {𝕄 : Semiring-with-meet} (has-nr : Has-nr 𝕄) : Set a where
no-eta-equality
pattern
open Semiring-with-meet 𝕄
open Has-nr has-nr
field
nr₂ : (p r : M) → M
nr₂≢𝟘 : {p r : M} → nr₂ p r ≢ 𝟘
nr-factoring : {p r z s n : M} → nr p r z s n ≡ nr₂ p r · n + nr p r z s 𝟘
record Has-well-behaved-GLBs (𝕄 : Semiring-with-meet) : Set a where
no-eta-equality
open Semiring-with-meet 𝕄
field
+-GLBˡ :
Greatest-lower-bound p pᵢ →
Greatest-lower-bound (q + p) (λ i → q + pᵢ i)
·-GLBˡ :
Greatest-lower-bound p pᵢ →
Greatest-lower-bound (q · p) (λ i → q · pᵢ i)
·-GLBʳ :
Greatest-lower-bound p pᵢ →
Greatest-lower-bound (p · q) (λ i → pᵢ i · q)
+nrᵢ-GLB :
Greatest-lower-bound p (nrᵢ r z₁ s₁) →
Greatest-lower-bound p′ (nrᵢ r z₂ s₂) →
∃ λ q → Greatest-lower-bound q (nrᵢ r (z₁ + z₂) (s₁ + s₂)) × p + p′ ≤ q
record Has-star (r : Semiring-with-meet) : Set a where
no-eta-equality
pattern
open Semiring-with-meet r
infix 50 _⊛_▷_
field
_⊛_▷_ : Op₃ M
⊛-ineq : ((p q r : M) → p ⊛ q ▷ r ≤ q + r · p ⊛ q ▷ r)
× ((p q r : M) → p ⊛ q ▷ r ≤ p)
+-sub-interchangeable-⊛ : (r : M) → _+_ SubInterchangeable (_⊛_▷ r) by _≤_
·-sub-distribʳ-⊛ : (r : M) → _·_ SubDistributesOverʳ (_⊛_▷ r) by _≤_
⊛-sub-distrib-∧ : (r : M) → (_⊛_▷ r) SubDistributesOver _∧_ by _≤_
⊛-ineq₁ : (p q r : M) → p ⊛ q ▷ r ≤ q + r · (p ⊛ q ▷ r)
⊛-ineq₁ = proj₁ ⊛-ineq
⊛-ineq₂ : (p q r : M) → p ⊛ q ▷ r ≤ p
⊛-ineq₂ = proj₂ ⊛-ineq
⊛-sub-distribˡ-∧ : (r : M) → (_⊛_▷ r) SubDistributesOverˡ _∧_ by _≤_
⊛-sub-distribˡ-∧ r = proj₁ (⊛-sub-distrib-∧ r)
⊛-sub-distribʳ-∧ : (r : M) → (_⊛_▷ r) SubDistributesOverʳ _∧_ by _≤_
⊛-sub-distribʳ-∧ r = proj₂ (⊛-sub-distrib-∧ r)
record Modality : Set (lsuc a) where
no-eta-equality
pattern
field
variant : Modality-variant
semiring-with-meet : Semiring-with-meet
open Semiring-with-meet semiring-with-meet public
open Modality-variant variant public
field
𝟘-well-behaved : T 𝟘ᵐ-allowed → Has-well-behaved-zero semiring-with-meet