Debian Codegraph @

src/Relation/Binary/Reasoning/MultiSetoid.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Convenient syntax for "equational reasoning" in multiple Setoids.
5 ------------------------------------------------------------------------
6
7 -- Example use:
8 --
9 -- open import Data.Maybe.Properties
10 -- open import Data.Maybe.Relation.Binary.Equality
11 -- open import Relation.Binary.Reasoning.MultiSetoid
12 --
13 -- begin⟨ S ⟩
14 -- x ≈⟨ drop-just (begin⟨ setoid S ⟩
15 -- just x ≈⟨ justx≈mz ⟩
16 -- mz ≈⟨ mz≈justy ⟩
17 -- just y ∎)⟩
18 -- y ≈⟨ y≈z ⟩
19 -- z ∎
20
21 -- Note this module is not reimplemented in terms of `Reasoning.Setoid`
22 -- as this introduces unsolved metas as the underlying base module
23 -- `Base.Single` does not require `_≈_` be symmetric.
24
25 {-# OPTIONS --cubical-compatible --safe #-}
26
27 module Relation.Binary.Reasoning.MultiSetoid where
28
29 open import Level using (Level; _⊔_)
30 open import Function.Base using (case_of_)
31 open import Relation.Binary.Core using (_⇒_)
32 open import Relation.Binary.Definitions using (Trans; Reflexive)
33 open import Relation.Binary.Bundles using (Setoid)
34 open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_)
35 open import Relation.Binary.Reasoning.Syntax
36
37 private
38 variable
39 a ℓ : Level
40
41 ------------------------------------------------------------------------
42 -- Combinators that take the current setoid as an explicit argument.
43
44 module _ (S : Setoid a ℓ) where
45 open Setoid S
46
47 data IsRelatedTo (x y : _) : Set (a ⊔ ℓ) where
48 relTo : (x≈y : x ≈ y) → IsRelatedTo x y
49
50 start : IsRelatedTo ⇒ _≈_
51 start (relTo x≈y) = x≈y
52
53 ≡-go : Trans _≡_ IsRelatedTo IsRelatedTo
54 ≡-go x≡y (relTo y∼z) = relTo (case x≡y of λ where ≡.refl → y∼z)
55
56 ≈-go : Trans _≈_ IsRelatedTo IsRelatedTo
57 ≈-go x≈y (relTo y≈z) = relTo (trans x≈y y≈z)
58
59 end : Reflexive IsRelatedTo
60 end = relTo refl
61
62 ------------------------------------------------------------------------
63 -- Reasoning combinators
64
65 -- Those that take the current setoid as an explicit argument.
66 open begin-syntax IsRelatedTo start public
67 renaming (begin_ to begin⟨_⟩_)
68
69
70 -- Those that take the current setoid as an implicit argument.
71 module _ {S : Setoid a ℓ} where
72 open Setoid S
73
74 open ≡-syntax (IsRelatedTo S) (≡-go S)
75 open ≈-syntax (IsRelatedTo S) (IsRelatedTo S) (≈-go S) sym public
76 open end-syntax (IsRelatedTo S) (end S) public