-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generalize graphs, rename old def to finite graph
- Loading branch information
Showing
10 changed files
with
247 additions
and
49 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 |
---|---|---|
|
@@ -22,3 +22,5 @@ target | |
elba.lock | ||
build | ||
compare | ||
*.ttc | ||
*.ttm |
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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
\iffalse | ||
SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
This file is part of `idris-ct` Category Theory in Idris library. | ||
|
||
Copyright (C) 2019 Stichting Statebox <https://statebox.nl> | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
|
||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
\fi | ||
|
||
> module Free.Finite.FinGraph | ||
> | ||
> import Data.Vect | ||
> | ||
> %access public export | ||
> %default total | ||
> | ||
> record FinGraph where | ||
> constructor MkFinGraph | ||
> vertices : Type | ||
> edges : Vect n (vertices, vertices) | ||
> | ||
> Edge : (g : FinGraph) -> (i, j : vertices g) -> Type | ||
> Edge g i j = Elem (i, j) (edges g) | ||
> | ||
> edgeOrigin : {g : FinGraph} -> Edge g i j -> vertices g | ||
> edgeOrigin {i} _ = i | ||
> | ||
> edgeTarget : {g : FinGraph} -> Edge g i j -> vertices g | ||
> edgeTarget {j} _ = j | ||
|
||
data TriangleVertices = One | Two | Three | ||
|
||
triangle : FinGraph | ||
triangle = MkFinGraph TriangleVertices [(One, Two), (Two, Three), (Three, One)] |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
\iffalse | ||
SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
This file is part of `idris-ct` Category Theory in Idris library. | ||
|
||
Copyright (C) 2019 Stichting Statebox <https://statebox.nl> | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
|
||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
\fi | ||
|
||
> module Free.Finite.FinPath | ||
> | ||
> import Data.List | ||
> import Free.Finite.FinGraph | ||
> | ||
> %access public export | ||
> %default total | ||
> | ||
> data FinPath : (g : FinGraph) -> vertices g -> vertices g -> Type where | ||
> Nil : FinPath g i i | ||
> (::) : (a : Edge g i j) -> FinPath g j k -> FinPath g i k | ||
|
||
nullFinPath : FinPath FinGraph.triangle One One | ||
nullFinPath = Nil | ||
|
||
oneToThree : FinPath FinGraph.triangle One Three | ||
oneToThree = [Here, There Here] | ||
|
||
oneToThree' : FinPath FinGraph.triangle One Three | ||
oneToThree' = Here :: There Here :: Nil | ||
|
||
> edgeToFinPath : {g : FinGraph} -> (a : Edge g i j) -> FinPath g (edgeOrigin a) (edgeTarget a) | ||
> edgeToFinPath a = [a] | ||
> | ||
> joinFinPath : FinPath g i j -> FinPath g j k -> FinPath g i k | ||
> joinFinPath [] y = y | ||
> joinFinPath (x :: xs) y = x :: joinFinPath xs y | ||
> | ||
> joinFinPathNil : (p : FinPath g i j) -> joinFinPath p [] = p | ||
> joinFinPathNil Nil = Refl | ||
> joinFinPathNil (x :: xs) = cong $ joinFinPathNil xs | ||
> | ||
> joinFinPathAssoc : | ||
> (p : FinPath g i j) | ||
> -> (q : FinPath g j k) | ||
> -> (r : FinPath g k l) | ||
> -> joinFinPath p (joinFinPath q r) = joinFinPath (joinFinPath p q) r | ||
> joinFinPathAssoc Nil q r = Refl | ||
> joinFinPathAssoc (x :: xs) q r = cong $ joinFinPathAssoc xs q r |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
\iffalse | ||
SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
This file is part of `idris-ct` Category Theory in Idris library. | ||
|
||
Copyright (C) 2019 Stichting Statebox <https://statebox.nl> | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
|
||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
\fi | ||
|
||
> module Free.Finite.FinPathCategory | ||
> | ||
> import Basic.Category | ||
> import Data.Vect | ||
> import Free.FinGraph | ||
> import Free.FinPath | ||
> | ||
> %access public export | ||
> %default total | ||
> | ||
> pathCategory : FinGraph -> Category | ||
> pathCategory g = MkCategory | ||
> (vertices g) | ||
> (FinPath g) | ||
> (\a => Nil) | ||
> (\a, b, c, f, g => joinFinPath f g) | ||
> (\a, b, f => Refl) | ||
> (\a, b, f => joinFinPathNil f) | ||
> (\a, b, c, d, f, g, h => joinFinPathAssoc f g h) |
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
\iffalse | ||
SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
This file is part of `idris-ct` Category Theory in Idris library. | ||
|
||
Copyright (C) 2019 Stichting Statebox <https://statebox.nl> | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
|
||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
\fi | ||
|
||
> module Free.Finite.FreeFinFunctor | ||
> | ||
> import Basic.Category | ||
> import Basic.Functor | ||
> import Data.Vect | ||
> import Free.Finite.FinGraph | ||
> import Free.Finite.FinPath | ||
> import Free.Finite.FinPathCategory | ||
> | ||
> %access public export | ||
> %default total | ||
> | ||
> record FinGraphEmbedding (g : FinGraph) (cat : Category) where | ||
> constructor MkFinGraphEmbedding | ||
> mapVertices : vertices g -> obj cat | ||
> mapEdges : (i, j : vertices g) -> Edge g i j -> mor cat (mapVertices i) (mapVertices j) | ||
> | ||
> foldFinPath : | ||
> (g : FinGraph) | ||
> -> (ge : FinGraphEmbedding g cat) | ||
> -> FinPath g i j | ||
> -> mor cat (mapVertices ge i) (mapVertices ge j) | ||
> foldFinPath _ {cat} ge {i} [] = identity cat (mapVertices ge i) | ||
> foldFinPath g {cat} ge {i} ((::) {j} x xs) = compose cat _ _ _ (mapEdges ge i j x) (foldFinPath g ge xs) | ||
> | ||
> freeFinFunctorCompose : | ||
> (g : FinGraph) | ||
> -> (ge : FinGraphEmbedding g cat) | ||
> -> (i, j, k : vertices g) | ||
> -> (f : FinPath g i j) | ||
> -> (h : FinPath g j k) | ||
> -> foldFinPath g ge {i} {j = k} (joinFinPath f h) | ||
> = compose cat | ||
> (mapVertices ge i) | ||
> (mapVertices ge j) | ||
> (mapVertices ge k) | ||
> (foldFinPath g ge {i} {j} f) | ||
> (foldFinPath g ge {i = j} {j = k} h) | ||
> freeFinFunctorCompose g {cat} ge j j k [] h = sym $ leftIdentity cat | ||
> (mapVertices ge j) | ||
> (mapVertices ge k) | ||
> (foldFinPath g ge h) | ||
> freeFinFunctorCompose g {cat} ge i j k ((::) {j=l} x xs) h = | ||
> trans (cong {f = compose cat _ _ _ (mapEdges ge i l x)} $ freeFinFunctorCompose g ge _ _ _ xs h) | ||
> (associativity cat _ _ _ _ (mapEdges ge i l x) (foldFinPath g ge xs) (foldFinPath g ge h)) | ||
> | ||
> freeFinFunctor : (g : FinGraph) -> FinGraphEmbedding g cat -> CFunctor (pathCategory g) cat | ||
> freeFinFunctor g ge = MkCFunctor | ||
> (mapVertices ge) | ||
> (\i, j, p => foldFinPath g ge {i} {j} p) | ||
> (\_ => Refl) | ||
> (freeFinFunctorCompose g ge) |
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
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
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
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