-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add code for generating and working with quotients #43
Open
WhatisRT
wants to merge
4
commits into
master
Choose a base branch
from
quotients
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7ff772f
Add code for generating and working with quotients
WhatisRT 94d4600
Remove some unnecessary stuff
WhatisRT b142fa4
Implemented some of Frederik's suggestions
WhatisRT 5a9201e
Add quotients by arbitrary relations, by forming an equivalence closure
WhatisRT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
module Quotient | ||
|
||
import Control.Isomorphism | ||
|
||
%access public export | ||
%default total | ||
|
||
extEq : (a -> b) -> (a -> b) -> Type | ||
extEq {a} f g = (x : a) -> f x = g x | ||
|
||
Rel : Type -> Type | ||
Rel x = x -> x -> Type | ||
|
||
record EqRel (x : Type) where | ||
constructor MkEqRel | ||
rel : Rel x | ||
refl : (a : x) -> rel a a | ||
sym : (a, b : x) -> rel a b -> rel b a | ||
trans : (a, b, c : x) -> rel a b -> rel b c -> rel a c | ||
|
||
parameters (rel : Rel x) | ||
data EqClosure' : Rel x where | ||
ClosureIncl : rel a b -> EqClosure' a b | ||
ClosureRefl : EqClosure' a a | ||
ClosureSym : EqClosure' a b -> EqClosure' b a | ||
ClosureTrans : EqClosure' a b -> EqClosure' b c -> EqClosure' a c | ||
|
||
EqClosure : Rel x -> EqRel x | ||
EqClosure r = MkEqRel (EqClosure' r) | ||
(\a => ClosureRefl r) | ||
(\a, b, h => ClosureSym r h) | ||
(\a, b, c, h, h' => ClosureTrans r h h') | ||
|
||
RespectingMap : (x, y : Type) -> EqRel x -> Type | ||
RespectingMap x y eq = (f : (x -> y) ** ((a, b : x) -> (rel eq) a b -> f a = f b)) | ||
|
||
record Quotient (x : Type) (eq : EqRel x) where | ||
constructor MkQuotient | ||
carrier : Type | ||
proj : RespectingMap x carrier eq | ||
exists : (y : Type) -> (f : RespectingMap x y eq) | ||
-> (g : (carrier -> y) ** (extEq (fst f) (g . (fst proj)))) | ||
unique : (y : Type) -> (f : RespectingMap x y eq) | ||
-> (g : (carrier -> y)) -> extEq (fst f) (g . (fst proj)) | ||
-> extEq g (fst (exists y f)) | ||
|
||
Quotient' : (x : Type) -> Rel x -> Type | ||
Quotient' x eq = Quotient x (EqClosure eq) | ||
|
||
existsUnique : (q : Quotient x eq) -> (f : RespectingMap x y eq) | ||
-> (g : carrier q -> y) -> (extEq (fst f) (g . (fst $ proj q))) | ||
-> (h : carrier q -> y) -> (extEq (fst f) (h . (fst $ proj q))) | ||
-> extEq g h | ||
existsUnique {y=y} (MkQuotient carrier proj exists unique) f g gh h hh x = | ||
trans (unique y f g gh x) $ sym $ unique y f h hh x | ||
|
||
projectionInducesIdentity : (q : Quotient x eq) -> (f : carrier q -> carrier q) -> extEq (fst $ proj q) (f . (fst $ proj q)) -> extEq f Basics.id | ||
projectionInducesIdentity q f h x = sym $ existsUnique q (proj q) id (\a => Refl) f h x | ||
|
||
QuotientUnique : (q, q' : Quotient x eq) | ||
-> (iso : Iso (carrier q) (carrier q') ** (extEq ((to iso) . (fst $ proj q)) (fst $ proj q'))) | ||
QuotientUnique q q' = let | ||
(isoTo ** commTo) = exists q (carrier q') (proj q') | ||
(isoFrom ** commFrom) = exists q' (carrier q) (proj q) | ||
iso = MkIso isoTo isoFrom | ||
(projectionInducesIdentity q' (isoTo . isoFrom) (\a => trans (commTo a) (cong $ commFrom a))) | ||
(projectionInducesIdentity q (isoFrom . isoTo) (\a => trans (commFrom a) (cong $ commTo a))) | ||
in (iso ** (\a => sym $ commTo a)) | ||
|
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,24 @@ | ||
module Quotients | ||
|
||
import Quotient.Quotient | ||
|
||
%access public export | ||
%default total | ||
|
||
trivialEqRel : (x : Type) -> EqRel x | ||
trivialEqRel x = MkEqRel (\x, y => x = y) (\x => Refl) (\x, y, r => sym r) (\x, y, z, l, r => trans l r) | ||
|
||
trivialQuotient : (x : Type) -> Quotient x $ trivialEqRel x | ||
trivialQuotient x = MkQuotient x | ||
((id {a=x}) ** (\a, b, h => h)) | ||
(\y, f => ((fst f) ** (\a => Refl))) | ||
(\y, f, g, h, a => sym $ h a) | ||
|
||
fullEqRel : (x : Type) -> EqRel x | ||
fullEqRel x = MkEqRel (\x, y => ()) (\x => ()) (\x, y, r => ()) (\x, y, z, l, r => ()) | ||
|
||
fullQuotient : (x : Type) -> (a : x) -> Quotient x $ fullEqRel x | ||
fullQuotient x a = MkQuotient () | ||
((\b => ()) ** (\a, b, h => Refl)) | ||
(\y, f => ((\b => (fst f) a) ** (\b => snd f b a ()))) | ||
(\y, f, g, h, () => sym $ h a) |
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,33 @@ | ||
module UnsafeQuotient | ||
|
||
import Quotient.Quotient | ||
|
||
%default total | ||
%access export | ||
|
||
private | ||
data InternalQuotientType : (x : Type) -> (eq : EqRel x) -> Type where | ||
InternalWrap : x -> InternalQuotientType x eq | ||
|
||
QuotientType : (x : Type) -> (eq : EqRel x) -> Type | ||
QuotientType = InternalQuotientType | ||
|
||
Wrap : x -> QuotientType x eq | ||
Wrap = InternalWrap | ||
|
||
private | ||
unwrap : QuotientType x eq -> x | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably best not to export There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, completely missed that. |
||
unwrap (InternalWrap a) = a | ||
|
||
postulate | ||
QuotientEquality : (x : Type) -> (eq : EqRel x) -> (rel eq a b) -> Wrap a = Wrap b | ||
|
||
UnsafeQuotient : (x : Type) -> (eq : EqRel x) -> Quotient x eq | ||
UnsafeQuotient x eq = MkQuotient | ||
(QuotientType x eq) | ||
(Wrap ** (\a, b, h => QuotientEquality x eq h)) | ||
(\y, f => ((\a => fst f $ unwrap a) ** (\a => Refl))) | ||
(\y, f, g, h, (InternalWrap a) => sym $ h a) | ||
|
||
UnsafeQuotient' : (x : Type) -> (eq : Rel x) -> Quotient' x eq | ||
UnsafeQuotient' x eq = UnsafeQuotient x (EqClosure eq) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this module use
%access public export
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, forgot that.