Skip to content

Commit 3b6e4cb

Browse files
committed
Add an inductive equality
1 parent 707fdb1 commit 3b6e4cb

File tree

1 file changed

+61
-14
lines changed

1 file changed

+61
-14
lines changed

formal-spec/CategoricalCrypto/SRel.agda

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ R₁ ≡ᵗ R₂ = R₁ ≤ᵗ R₂ × R₂ ≤ᵗ R₁
5353
module _ ((record { State = S₁ ; rel = rel₁ }) : SRel A B)
5454
((record { State = S₂ ; rel = rel₂ }) : SRel A B) where
5555

56+
infix 4 _≡ᵉ_
5657
record _≡ᵉ_ : Type where
5758
field S₁↔S₂ : S₁ ↔ S₂
5859

@@ -70,8 +71,10 @@ module _ ((record { State = S₁ ; rel = rel₁ }) : SRel A B)
7071
rel₂ s a b (to s') ∎
7172
where open R.EquationalReasoning
7273

74+
private variable R R₁ R₂ R₃ R₄ : SRel A B
75+
7376
-- ≡ᵉ is much easier to prove, but less general
74-
≡ᵉ⇒≡ᵗ : {R₁ R₂ : SRel A B} R₁ ≡ᵉ R₂ R₁ ≡ᵗ R₂
77+
≡ᵉ⇒≡ᵗ : R₁ ≡ᵉ R₂ R₁ ≡ᵗ R₂
7578
≡ᵉ⇒≡ᵗ {R₁ = R₁} {R₂} R₁≡ᵉR₂ = < to , trace⇔₁ > , < from , trace⇔₂ >
7679
where
7780
open _≡ᵉ_ R₁≡ᵉR₂; open Inverse S₁↔S₂
@@ -87,6 +90,8 @@ module _ ((record { State = S₁ ; rel = rel₁ }) : SRel A B)
8790
trace⇔₂ s (_ ∷ _) [] = R.K-refl
8891
trace⇔₂ s (a ∷ as) (b ∷ bs) = R.SK-sym $ ∃-cong S₁↔S₂ (rel₁f⇔rel₂t ×-cong R.SK-sym (trace⇔₂ s as bs))
8992

93+
infix 4 _≡ᵗ_ _≡ⁱ_
94+
9095
module _ ((record { State = S₁ ; rel = rel₁ }) : SRel B C)
9196
((record { State = S₂ ; rel = rel₂ }) : SRel A B) where
9297

@@ -95,9 +100,64 @@ module _ ((record { State = S₁ ; rel = rel₁ }) : SRel B C)
95100
∘-rel₁ : rel₁ (proj₁ s) b c (proj₁ s')
96101
∘-rel₂ : rel₂ (proj₂ s) a b (proj₂ s')
97102

103+
infixr 9 _∘_
98104
_∘_ : SRel A C
99105
_∘_ = record { State = _ ; rel = ∘-rel }
100106

107+
⊗₀ : Type × Type Type
108+
⊗₀ = uncurry _⊎_
109+
110+
module ((record { State = State₁ ; rel = rel₁ }
111+
, record { State = State₂ ; rel = rel₂ }) : SRel A B × SRel C D) where
112+
113+
data ⊗-rel : SRelType (A ⊎ C) (B ⊎ D) (State₁ × State₂) where
114+
⊗₁₁ : {s₁ s₁' s₂ a c} rel₁ s₁ a c s₁' ⊗-rel (s₁ , s₂) (inj₁ a) (inj₁ c) (s₁' , s₂)
115+
⊗₁₂ : {s₁ s₂ s₂' b d} rel₂ s₂ b d s₂' ⊗-rel (s₁ , s₂) (inj₂ b) (inj₂ d) (s₁ , s₂')
116+
117+
: SRel (A ⊎ C) (B ⊎ D)
118+
= record { State = _ ; rel = ⊗-rel}
119+
120+
infixr 10 _⊗₁_
121+
_⊗₁_ : SRel A B SRel C D SRel (A ⊎ C) (B ⊎ D)
122+
_⊗₁_ = curry ⊗.₁
123+
124+
-- This definition is awkward, because we would prefer to allow 'arbitrary' extensions of the state.
125+
-- This could be done by instead having an injection `State ↪ State'` or a partial function
126+
-- `State' → Maybe State`.
127+
-- However, none of these are stronger, since you can always replace the state with an isomorphic
128+
-- type via `≡ᵉ⇒≡ⁱ`. I don't know what the best option would be.
129+
130+
weakenState : SRel A B Type SRel A B
131+
weakenState R S = let open SRel R in record
132+
{ State = State ⊎ S
133+
; rel = λ where
134+
(inj₁ s) a b (inj₁ s') rel s a b s'
135+
_ _ _ _
136+
}
137+
138+
data _≡ⁱ_ : SRel A B SRel A B Type₁ where
139+
≡ᵉ⇒≡ⁱ : R₁ ≡ᵉ R₂ R₁ ≡ⁱ R₂
140+
weaken : {X} R ≡ⁱ weakenState R X
141+
≡ⁱ-∘ : R₁ ≡ⁱ R₂ R₃ ≡ⁱ R₄ R₁ ∘ R₂ ≡ⁱ R₃ ∘ R₄
142+
≡ⁱ-⊗ : R₁ ≡ⁱ R₂ R₃ ≡ⁱ R₄ R₁ ⊗₁ R₂ ≡ⁱ R₃ ⊗₁ R₄
143+
144+
≡ⁱ-refl : R ≡ⁱ R
145+
≡ⁱ-sym : R₁ ≡ⁱ R₂ R₂ ≡ⁱ R₁
146+
≡ⁱ-trans : R₁ ≡ⁱ R₂ R₂ ≡ⁱ R₃ R₁ ≡ⁱ R₃
147+
148+
-- this should be straightforward
149+
≡ⁱ⇒≡ᵗ : R₁ ≡ⁱ R₂ R₁ ≡ᵗ R₂
150+
≡ⁱ⇒≡ᵗ = {!!}
151+
152+
-- here's a proof sketch, assuming the axiom of choice:
153+
-- - we can assume that R₁ and R₂ have 'minimal' state because of `weaken` (choose a minimal one)
154+
-- - WLOG assume S₁ ↪ S₂, then again by weaken & ≡ᵉ⇒≡ⁱ it follows that we can weaken R₂ to
155+
-- have state type S₂, so we can assume R₁ and R₂ have the same state type
156+
-- - now proving R₁ ≡ᵉ R₂ should be straightforward since we just need to prove `rel₁⇔rel₂'`,
157+
-- and that follows from the traces
158+
-- ≡ᵗ⇒≡ⁱ : R₁ ≡ᵗ R₂ → R₁ ≡ⁱ R₂
159+
-- ≡ᵗ⇒≡ⁱ = {!!}
160+
101161
SRelC : Category (sucˡ ℓ0) (sucˡ ℓ0) ℓ0
102162
SRelC = categoryHelper record
103163
{ Obj = Type
@@ -147,19 +207,6 @@ module RelsMonoidal where
147207
open import Categories.Category.Monoidal.Utilities (CocartesianMonoidal.+-monoidal (Rels 0ℓ 0ℓ) Rels-Cocartesian) public
148208
open Shorthands public
149209

150-
⊗₀ : Type × Type Type
151-
⊗₀ = uncurry _⊎_
152-
153-
module _ ((record { State = State₁ ; rel = rel₁ }
154-
, record { State = State₂ ; rel = rel₂ }) : SRel A B × SRel C D) where
155-
156-
data ⊗-rel : SRelType (A ⊎ C) (B ⊎ D) (State₁ × State₂) where
157-
⊗₁₁ : {s₁ s₁' s₂ a c} rel₁ s₁ a c s₁' ⊗-rel (s₁ , s₂) (inj₁ a) (inj₁ c) (s₁' , s₂)
158-
⊗₁₂ : {s₁ s₂ s₂' b d} rel₂ s₂ b d s₂' ⊗-rel (s₁ , s₂) (inj₂ b) (inj₂ d) (s₁ , s₂')
159-
160-
⊗₁ : SRel (A ⊎ C) (B ⊎ D)
161-
⊗₁ = record { State = _ ; rel = ⊗-rel}
162-
163210
Monoidal-SRelC : Monoidal SRelC
164211
Monoidal-SRelC = monoidalHelper SRelC record
165212
{ ⊗ = record

0 commit comments

Comments
 (0)