-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f73b5d
commit f14f68b
Showing
3 changed files
with
71 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,44 @@ | ||
module Graph (A : Set) where | ||
module Graph where | ||
|
||
-- Core graph construction primitives | ||
data Graph : Set where | ||
ε : Graph -- Empty graph | ||
[_] : A -> Graph -- Graph comprising a single vertex | ||
_+_ : Graph -> Graph -> Graph -- Overlay two graphs | ||
_*_ : Graph -> Graph -> Graph -- Connect two graphs | ||
data Graph (A : Set) : Set where | ||
ε : Graph A -- Empty graph | ||
v : A -> Graph A -- Graph comprising a single vertex | ||
_+_ : Graph A -> Graph A -> Graph A -- Overlay two graphs | ||
_*_ : Graph A -> Graph A -> Graph A -- Connect two graphs | ||
|
||
infixl 4 _≡_ | ||
infixl 8 _+_ | ||
infixl 9 _*_ | ||
infix 10 _⊆_ | ||
|
||
-- Equational theory of graphs | ||
data _≡_ : (x : Graph) -> (y : Graph) -> Set where | ||
data _≡_ {A} : (x y : Graph A) -> Set where | ||
-- Equivalence relation | ||
reflexivity : ∀ {x} -> x ≡ x | ||
symmetry : ∀ {x y} -> x ≡ y -> y ≡ x | ||
transitivity : ∀ {x y z} -> x ≡ y -> y ≡ z -> x ≡ z | ||
reflexivity : ∀ {x : Graph A} -> x ≡ x | ||
symmetry : ∀ {x y : Graph A} -> x ≡ y -> y ≡ x | ||
transitivity : ∀ {x y z : Graph A} -> x ≡ y -> y ≡ z -> x ≡ z | ||
|
||
-- Congruence | ||
+left-congruence : ∀ {x y z} -> x ≡ y -> x + z ≡ y + z | ||
+right-congruence : ∀ {x y z} -> x ≡ y -> z + x ≡ z + y | ||
*left-congruence : ∀ {x y z} -> x ≡ y -> x * z ≡ y * z | ||
*right-congruence : ∀ {x y z} -> x ≡ y -> z * x ≡ z * y | ||
+left-congruence : ∀ {x y z : Graph A} -> x ≡ y -> x + z ≡ y + z | ||
+right-congruence : ∀ {x y z : Graph A} -> x ≡ y -> z + x ≡ z + y | ||
*left-congruence : ∀ {x y z : Graph A} -> x ≡ y -> x * z ≡ y * z | ||
*right-congruence : ∀ {x y z : Graph A} -> x ≡ y -> z * x ≡ z * y | ||
|
||
-- Axioms of + | ||
+commutativity : ∀ {x y} -> x + y ≡ y + x | ||
+associativity : ∀ {x y z} -> x + (y + z) ≡ (x + y) + z | ||
+commutativity : ∀ {x y : Graph A} -> x + y ≡ y + x | ||
+associativity : ∀ {x y z : Graph A} -> x + (y + z) ≡ (x + y) + z | ||
|
||
-- Axioms of * | ||
*left-identity : ∀ {x} -> ε * x ≡ x | ||
*right-identity : ∀ {x} -> x * ε ≡ x | ||
*associativity : ∀ {x y z} -> x * (y * z) ≡ (x * y) * z | ||
*left-identity : ∀ {x : Graph A} -> ε * x ≡ x | ||
*right-identity : ∀ {x : Graph A} -> x * ε ≡ x | ||
*associativity : ∀ {x y z : Graph A} -> x * (y * z) ≡ (x * y) * z | ||
|
||
-- Other axioms | ||
left-distributivity : ∀ {x y z} -> x * (y + z) ≡ x * y + x * z | ||
right-distributivity : ∀ {x y z} -> (x + y) * z ≡ x * z + y * z | ||
decomposition : ∀ {x y z} -> x * y * z ≡ x * y + x * z + y * z | ||
left-distributivity : ∀ {x y z : Graph A} -> x * (y + z) ≡ x * y + x * z | ||
right-distributivity : ∀ {x y z : Graph A} -> (x + y) * z ≡ x * z + y * z | ||
decomposition : ∀ {x y z : Graph A} -> x * y * z ≡ x * y + x * z + y * z | ||
|
||
_⊆_ : Graph -> Graph -> Set | ||
-- Subgraph relation | ||
_⊆_ : ∀ {A} -> Graph A -> Graph A -> Set | ||
x ⊆ y = x + y ≡ y | ||
|
||
data BinaryOperator : Set where | ||
overlay : BinaryOperator | ||
connect : BinaryOperator | ||
|
||
apply : BinaryOperator -> Graph -> Graph -> Graph | ||
apply overlay a b = a + b | ||
apply connect a b = a * b | ||
|
||
L : ∀ {op : BinaryOperator} -> ∀ {x y z} -> x ≡ y -> apply op x z ≡ apply op y z | ||
L {overlay} {x} {y} {z} eq = +left-congruence {x} {y} {z} eq | ||
L {connect} {x} {y} {z} eq = *left-congruence {x} {y} {z} eq | ||
|
||
R : ∀ {op : BinaryOperator} -> ∀ {x y z} -> x ≡ y -> apply op z x ≡ apply op z y | ||
R {overlay} {x} {y} {z} eq = +right-congruence {x} {y} {z} eq | ||
R {connect} {x} {y} {z} eq = *right-congruence {x} {y} {z} eq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,40 @@ | ||
module Reasoning (A : Set) where | ||
module Reasoning where | ||
|
||
open import Graph A | ||
open import Graph | ||
|
||
-- Standard syntax sugar for writing equational proofs | ||
infix 4 _≈_ | ||
data _≈_ (x y : Graph) : Set where | ||
data _≈_ {A} (x y : Graph A) : Set where | ||
prove : x ≡ y -> x ≈ y | ||
|
||
infix 1 begin_ | ||
begin_ : {x y : Graph} -> x ≈ y -> x ≡ y | ||
begin_ : ∀ {A} {x y : Graph A} -> x ≈ y -> x ≡ y | ||
begin prove p = p | ||
|
||
infixr 2 _≡⟨_⟩_ | ||
_≡⟨_⟩_ : (x : Graph) {y z : Graph} -> x ≡ y -> y ≈ z -> x ≈ z | ||
_≡⟨_⟩_ : ∀ {A} (x : Graph A) {y z : Graph A} -> x ≡ y -> y ≈ z -> x ≈ z | ||
_ ≡⟨ p ⟩ prove q = prove (transitivity p q) | ||
|
||
infix 3 _∎ | ||
_∎ : (x : Graph) -> x ≈ x | ||
_∎ : ∀ {A} (x : Graph A) -> x ≈ x | ||
_∎ _ = prove reflexivity | ||
|
||
infixl 8 _>>_ | ||
_>>_ : ∀ {x y z} -> x ≡ y -> y ≡ z -> x ≡ z | ||
_>>_ : ∀ {A} {x y z : Graph A} -> x ≡ y -> y ≡ z -> x ≡ z | ||
_>>_ = transitivity | ||
|
||
data BinaryOperator : Set where | ||
overlay : BinaryOperator | ||
connect : BinaryOperator | ||
|
||
apply : ∀ {A} -> BinaryOperator -> Graph A -> Graph A -> Graph A | ||
apply overlay a b = a + b | ||
apply connect a b = a * b | ||
|
||
L : ∀ {op : BinaryOperator} -> ∀ {A} {x y z : Graph A} -> x ≡ y -> apply op x z ≡ apply op y z | ||
L {overlay} {x} {y} {z} eq = +left-congruence {x} {y} {z} eq | ||
L {connect} {x} {y} {z} eq = *left-congruence {x} {y} {z} eq | ||
|
||
R : ∀ {op : BinaryOperator} -> ∀ {A} {x y z : Graph A} -> x ≡ y -> apply op z x ≡ apply op z y | ||
R {overlay} {x} {y} {z} eq = +right-congruence {x} {y} {z} eq | ||
R {connect} {x} {y} {z} eq = *right-congruence {x} {y} {z} eq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters