-
Notifications
You must be signed in to change notification settings - Fork 70
@acset_colim variants: exposing name mapping, and morphisms
#986
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
Draft
kris-brown
wants to merge
3
commits into
main
Choose a base branch
from
namedacsetcolim
base: main
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.
+132
−36
Draft
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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,5 +1,6 @@ | ||
| module Yoneda | ||
| export representable, yoneda, subobject_classifier, internal_hom, @acset_colim | ||
| export representable, yoneda, subobject_classifier, internal_hom, @acset_colim, | ||
| @named_acset_colim, @acset_transformation_colim | ||
|
|
||
| using DataStructures, MLStyle | ||
|
|
||
|
|
@@ -219,6 +220,19 @@ function parse_diagram_data(x::Expr, mod::Module)::DiagramData | |
| Expr(:$, x) => Base.eval(mod, x) | ||
| end | ||
|
|
||
| function parse_eq(t1t2::Tuple) | ||
| p1,p2 = parse_call.(t1t2) | ||
| if p1 isa RPath | ||
| if p2 isa RPath | ||
| push!(data.eqs, p1 => p2) | ||
| else | ||
| data.vals[p1] = p2 | ||
| end | ||
| else | ||
| data.vals[p2] = p1 | ||
| end | ||
| end | ||
|
|
||
| for arg in Base.remove_linenums!(x).args | ||
| @match arg begin | ||
| Expr(:(::), partname::Symbol, parttype::Symbol) => begin | ||
|
|
@@ -227,18 +241,13 @@ function parse_diagram_data(x::Expr, mod::Module)::DiagramData | |
| Expr(:(::), Expr(:tuple, partnames...), parttype::Symbol) => begin | ||
| add_part.(partnames, Ref(parttype)) | ||
| end | ||
| Expr(:call, :(==), t1, t2) => begin | ||
| p1,p2 = parse_call.([t1,t2]) | ||
| if p1 isa RPath | ||
| if p2 isa RPath | ||
| push!(data.eqs, p1 => p2) | ||
| else | ||
| data.vals[p1] = p2 | ||
| end | ||
| else | ||
| data.vals[p2] = p1 | ||
| end | ||
| Expr(:call, :(==), t1, t2) => parse_eq((t1,t2)) | ||
| Expr(:comparison, raw...) => begin | ||
| all(==(:(==)), raw[2:2:end]) || error("Improper equality $arg") | ||
| ts = raw[1:2:end] | ||
| parse_eq.(zip(ts, ts[2:end])) | ||
| end | ||
| _ => error("Unexpected expr $arg") | ||
| end | ||
| end | ||
| data | ||
|
|
@@ -256,10 +265,59 @@ end | |
| """ | ||
| macro acset_colim(yon, body) | ||
| quote | ||
| colimit_representables($(parse_diagram_data(body, __module__)), $(esc(yon))) | ||
| colimit_representables($(parse_diagram_data(body, __module__)), $(esc(yon)))[2] | ||
| end | ||
| end | ||
|
|
||
| """ | ||
| ``` | ||
| Dom = @named_acset_colim yGraph MyDomain begin | ||
| v::V; e::E; src(e)==v | ||
| end | ||
| ``` | ||
|
|
||
| This would be have like `@acset_colim` and assign to `Dom` the walking edge | ||
| ACSet with src=1 and tgt=2. However, unlike `@acset_colim`, this also assigns | ||
| to a variable MyDomain the NamedTuple `(v=(:V, 1),e=(:E, 1))`. | ||
| """ | ||
| macro named_acset_colim(yon, names_var, body) | ||
| quote | ||
| names, acset = colimit_representables($(parse_diagram_data(body, __module__)), $(esc(yon))) | ||
| $(esc(names_var)) = names | ||
| acset | ||
| end | ||
| end | ||
|
|
||
| """ | ||
| Although providing an assignment for every generator is sufficient to guarantee | ||
| a uniquely determined homomorphism, it is not always necessary. If a generator | ||
| `a` in the domain is equal to some `b.f`, then only specifying `b` is necessary. | ||
| Furthermore, keyword arguments like `monic`, `epic`, and `iso` can be used to | ||
| specify a morphism uniquely (or `any` + `random` if it doesn't matter). | ||
| """ | ||
| macro acset_transformation_colim(yon, body1, body2, body3, kwargs=:((;))) | ||
| initial = Dict(map(filter(e->e isa Expr,body3.args)) do e | ||
| @match e begin | ||
| Expr(:call, :(=>), a, b) => a => b | ||
| end | ||
| end) | ||
| quote | ||
| names1, acset1 = colimit_representables( | ||
| $(parse_diagram_data(body1, __module__)), $(esc(yon))) | ||
| names2, acset2 = colimit_representables( | ||
| $(parse_diagram_data(body2, __module__)), $(esc(yon))) | ||
|
|
||
| initial=DefaultDict{Symbol,Dict}(()->Dict()) | ||
| for (k,v) in $initial | ||
| ty, domval = names1[k] | ||
| _, codval = names2[v] | ||
| initial[ty][domval] = codval | ||
| end | ||
| homomorphism(acset1, acset2; initial=initial, $(kwargs)...) | ||
| end | ||
| end | ||
|
|
||
|
|
||
| """ | ||
| Construct an ACSet given a colimit of representables, given by generating | ||
| representables and relations. Assumes a background context of VarACSetCategory | ||
|
|
@@ -327,11 +385,21 @@ function colimit_representables(data::DiagramData, y::FinDomFunctor) | |
| end | ||
|
|
||
| # If we are just asking for a coproduct of representables | ||
| isempty(spans) && return apex(Σ) | ||
| isempty(spans) && return (names, apex(Σ)) | ||
|
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.
|
||
|
|
||
| # Perform all pushouts at once by putting the spans together in parallel | ||
| lefts, rights = left.(spans), right.(spans) | ||
| apex(pushout[𝒞](foldl(oplus[𝒞′], lefts), foldl(copair[𝒞′], rights))) | ||
| _,bigι = big_colim = pushout[𝒞](foldl(oplus[𝒞′], lefts), foldl(copair[𝒞′], rights)) | ||
|
|
||
| # TODO get representing element for real. Requires passing in extra data. | ||
| names = NamedTuple(map(reprs) do (repr_type, repr_name) | ||
| ι = FinFunction(lookup[repr_name][repr_type], bigι[repr_type]) | ||
| length(dom(ι)) == 1 || error("Assumption that representing element is "* | ||
| "unique has been violated, more data required by `colimit_representables`") | ||
| repr_name => (repr_type, ι(only(dom(ι)))) | ||
| end) | ||
|
|
||
| (names, apex(big_colim)) | ||
| end | ||
|
|
||
| end # module | ||
This file contains hidden or 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
Oops, something went wrong.
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.
Comment on the PR moved here: #986 (comment)
Having some experience with these new macros now, I think that it might be unwise to have @named_acset_colimit implemented the way it is because it is not referentially transparent -- the names appear effectively by side-effect. This more functional (and simpler!) implementation might be better: