Skip to content

Commit 2738401

Browse files
Strict order equational reasoning (#1203)
* Add QuosetReasoning.agda Co-authored-by: Ettore Forigo <ettore.forigo@gmail.com> * add missing `no-eta-equality` in SubRelation, make SubRelation instance private --------- Co-authored-by: Ettore Forigo <ettore.forigo@gmail.com>
1 parent 69b70a2 commit 2738401

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
-- Example of usage:
2+
--
3+
-- open <-syntax
4+
-- open ≤-syntax
5+
-- open ≡-syntax
6+
--
7+
-- example : ∀ (x y z u v w α γ δ : P)
8+
-- → x < y
9+
-- → y ≤ z
10+
-- → z ≡ u
11+
-- → u < v
12+
-- → v ≤ w
13+
-- → w ≡ α
14+
-- → α ≡ γ
15+
-- → γ ≡ δ
16+
-- → x < δ
17+
-- example x y z u v w α γ δ x<y y≤z z≡u u<v v≤w w≡α α≡γ γ≡δ = begin
18+
-- x <⟨ x<y ⟩
19+
-- y ≤⟨ y≤z ⟩
20+
-- z ≡→≤⟨ z ≡⟨ z≡u ⟩
21+
-- u ≡⟨ sym z≡u ⟩
22+
-- z ≡[ i ]⟨ z≡u i ⟩
23+
-- u ∎ ⟩
24+
-- u <⟨ u<v ⟩
25+
-- v ≤⟨ v≤w ⟩
26+
-- w ≡→≤⟨
27+
-- w ≡⟨ w≡α ⟩
28+
-- α ≡⟨ α≡γ ⟩
29+
-- γ ≡[ i ]⟨ γ≡δ i ⟩
30+
-- δ ∎
31+
-- ⟩
32+
-- δ ◾
33+
34+
{-# OPTIONS --safe #-}
35+
{-
36+
Equational reasoning in a Quoset that is also a Poset, i.e.
37+
for writing a chain of <,≤,≡ with at least a <
38+
-}
39+
module Cubical.Relation.Binary.Order.QuosetReasoning where
40+
41+
open import Cubical.Foundations.Prelude
42+
open import Cubical.Data.Bool.Base
43+
open import Cubical.Data.Empty.Base as ⊥
44+
45+
open import Cubical.Relation.Nullary.Base
46+
47+
open import Cubical.Relation.Binary.Base
48+
open BinaryRelation
49+
open import Cubical.Relation.Binary.Order.Poset.Base
50+
open import Cubical.Relation.Binary.Order.Quoset.Base
51+
52+
private
53+
variable
54+
ℓ ℓ≤ ℓ< : Level
55+
56+
-- Record with all the parts needed to extract a subrelation from a relation
57+
-- (e.g. from a chain of <,≤,=, with at least a <, to a <)
58+
-- Note:
59+
-- It could be better to move this record in Relation.Binary.Base,
60+
-- but there isn't yet a proper module for subrelations.
61+
record SubRelation
62+
{ℓR}
63+
{P : Type ℓ}
64+
(_R_ : Rel P P ℓR ) ℓS ℓIsS : Type (ℓ-max ℓ (ℓ-max ℓR (ℓ-max (ℓ-suc ℓS) (ℓ-suc ℓIsS)))) where
65+
no-eta-equality
66+
field
67+
_S_ : Rel P P ℓS
68+
IsS : {x y} x R y Type ℓIsS
69+
IsS? : {x y} (xRy : x R y) Dec (IsS xRy)
70+
extract : {x y} {xRy : x R y} IsS xRy x S y
71+
72+
module <-≤-Reasoning
73+
(P : Type ℓ)
74+
((posetstr (_≤_) isPoset) : PosetStr ℓ≤ P)
75+
((quosetstr (_<_) isQuoset) : QuosetStr ℓ< P)
76+
(<-≤-trans : x {y z} x < y y ≤ z x < z)
77+
(≤-<-trans : x {y z} x ≤ y y < z x < z) where
78+
79+
open IsPoset
80+
open IsQuoset
81+
open SubRelation
82+
83+
private
84+
variable
85+
x y z : P
86+
data _<≤≡_ : P P Type (ℓ-max ℓ (ℓ-max ℓ< ℓ≤)) where
87+
strict : x < y x <≤≡ y
88+
nonstrict : x ≤ y x <≤≡ y
89+
equal : x ≡ y x <≤≡ y
90+
91+
sub : SubRelation _<≤≡_ ℓ< ℓ<
92+
sub ._S_ = _<_
93+
sub .IsS {x} {y} r with r
94+
... | strict x<y = x < y
95+
... | equal _ = ⊥*
96+
... | nonstrict _ = ⊥*
97+
sub .IsS? r with r
98+
... | strict x<y = yes x<y
99+
... | nonstrict _ = no λ ()
100+
... | equal _ = no λ ()
101+
sub .extract {xRy = strict _ } x<y = x<y
102+
103+
open SubRelation sub renaming (IsS? to Is<? ; extract to extract<)
104+
infix 1 begin_
105+
begin_ : (r : x <≤≡ y) {True (Is<? r)} x < y
106+
begin_ r {s} = extract< {xRy = r} (toWitness s)
107+
108+
-- Partial order syntax
109+
module ≤-syntax where
110+
infixr 2 step-≤
111+
step-≤ : (x : P) y <≤≡ z x ≤ y x <≤≡ z
112+
step-≤ x r x≤y with r
113+
... | strict y<z = strict (≤-<-trans x x≤y y<z)
114+
... | nonstrict y≤z = nonstrict (isPoset .is-trans x _ _ x≤y y≤z)
115+
... | equal y≡z = nonstrict (subst (x ≤_) y≡z x≤y)
116+
117+
syntax step-≤ x yRz x≤y = x ≤⟨ x≤y ⟩ yRz
118+
119+
module <-syntax where
120+
infixr 2 step-<
121+
step-< : (x : P) y <≤≡ z x < y x <≤≡ z
122+
step-< x r x<y with r
123+
... | strict y<z = strict (isQuoset .is-trans x _ _ x<y y<z)
124+
... | nonstrict y≤z = strict (<-≤-trans x x<y y≤z)
125+
... | equal y≡z = strict (subst (x <_) y≡z x<y)
126+
127+
syntax step-< x yRz x<y = x <⟨ x<y ⟩ yRz
128+
129+
module ≡-syntax where
130+
infixr 2 step-≡→≤
131+
step-≡→≤ : (x : P) y <≤≡ z x ≡ y x <≤≡ z
132+
step-≡→≤ x y<≤≡z x≡y = subst (_<≤≡ _) (λ i x≡y (~ i)) y<≤≡z
133+
134+
syntax step-≡→≤ x yRz x≡y = x ≡→≤⟨ x≡y ⟩ yRz
135+
136+
infix 3 _◾
137+
_◾ : x x <≤≡ x
138+
x ◾ = equal refl

0 commit comments

Comments
 (0)