Skip to content

Commit

Permalink
Extend API
Browse files Browse the repository at this point in the history
  • Loading branch information
snowleopard committed Apr 16, 2017
1 parent c27bf8f commit 1b0651a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
31 changes: 28 additions & 3 deletions src/API.agda
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,36 @@ connects = foldr connect empty
vertices : {A} -> List A -> Graph A
vertices = overlays ∘ map vertex

clique : {A} -> List A -> Graph A
clique = connects ∘ map vertex

edges : {A} -> List (A × A) -> Graph A
edges = overlays ∘ map (uncurry edge)

graph : {A} -> List A -> List (A × A) -> Graph A
graph vs es = overlay (vertices vs) (edges es)

foldg : {A} {B : Set} -> B -> (A -> B) -> (B -> B -> B) -> (B -> B -> B) -> Graph A -> B
foldg {A} {B} e w o c = go
where
go : Graph A -> B
go ε = e
go (v x) = w x
go (x + y) = o (go x) (go y)
go (x * y) = c (go x) (go y)

path : {A} -> List A -> Graph A
path [] = empty
path (x :: []) = vertex x
path (x :: xs) = edges (zip (x :: xs) xs)

circuit : {A} -> List A -> Graph A
circuit [] = empty
circuit (x :: xs) = path ([ x ] ++ xs ++ [ x ])

clique : {A} -> List A -> Graph A
clique = connects ∘ map vertex

biclique : {A} -> List A -> List A -> Graph A
biclique xs ys = connect (vertices xs) (vertices ys)

star : {A} -> A -> List A -> Graph A
star x ys = connect (vertex x) (vertices ys)

2 changes: 1 addition & 1 deletion src/API/Theorems.agda
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ open import Prelude
open import Reasoning

-- vertices [x] == vertex x
vertices-vertex : {A} {x : A} -> vertices (x :: []) ≡ vertex x
vertices-vertex : {A} {x : A} -> vertices [ x ] ≡ vertex x
vertices-vertex = +identity >> reflexivity

-- vertices xs ⊆ clique xs
Expand Down
9 changes: 9 additions & 0 deletions src/Prelude.agda
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ data List (A : Set) : Set where
_::_ : A -> List A -> List A

infixr 20 _::_
infixr 15 _++_

[_] : {A} -> A -> List A
[ x ] = x :: []

_++_ : {A} -> List A -> List A -> List A
[] ++ l = l
Expand All @@ -29,3 +33,8 @@ foldr f b (x :: xs) = f x (foldr f b xs)
map : {A B} -> (A -> B) -> List A -> List B
map f [] = []
map f (x :: xs) = f x :: map f xs

zip : {A B} -> List A -> List B -> List (A × B)
zip [] _ = []
zip _ [] = []
zip (x :: xs) (y :: ys) = (x , y) :: zip xs ys

0 comments on commit 1b0651a

Please sign in to comment.