-
Notifications
You must be signed in to change notification settings - Fork 58
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
WIP - Permutation Groupoid #707
base: main
Are you sure you want to change the base?
Conversation
After some more work on this, trying to speed up composition for One alternative would be to store the mapping in a more usual way, either as a |
More and more I am thinking that implementing |
850004e
to
f917260
Compare
f917260
to
15dffb0
Compare
I have reimplemented As I explain in a |
src/categorical_algebra/FinSets.jl
Outdated
BijectionThinWrap(FinFunction(f, args...)) | ||
|
||
function FinBijection(f::Union{AbstractDict{K,Int},AbstractVector{Int}}) where K | ||
function minandmax(p::Tuple{<:Number, <:Number}, n::Int)::Tuple{Int,Int} |
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.
This is a little overzealous for a type assert, the julia compiler will infer this method correctly.
src/categorical_algebra/FinSets.jl
Outdated
function minandmax(p::Tuple{<:Number, <:Number}, n::Int)::Tuple{Int,Int} | ||
(Int(min(p[1], n)), Int(max(p[2], n))) | ||
end | ||
minval, maxval = reduce(minandmax, values(f), init=(Inf, -Inf)) |
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.
Maybe use typemax(Int), typemin(Int)
for this sentinel value, since Inf and -Inf are Float64
. You probably also want to return the min, then the max so that you can interpret it as a range. min:max
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.
Thanks, will change the sentinel value. About the ordering thing, if I'm not misunderstanding you, minandmax
is already returning the values in that order, as is.
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.
nevermind that. reading min and max too many times in a row, I forgot which is which.
src/categorical_algebra/Sets.jl
Outdated
(f::AbsBijectionWrap)(x) = (unwrap(f))(x) | ||
|
||
# Developer's note: should I add in a `known_correct` parameter, asking | ||
# the caller to decide whether the SetFunction should be checked for bijectivity? |
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.
yes, that is usually how we enable optional correctness checking.
src/categorical_algebra/Sets.jl
Outdated
|
||
# Developer's note: should I add in a `known_correct` parameter, asking | ||
# the caller to decide whether the SetFunction should be checked for bijectivity? | ||
@struct_hash_equal struct BijectionThinWrap{Dom<:SetOb, Codom<:SetOb, |
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.
Thin
has a technical meaning in CT, that there is at most one morphism between two objects. Here I think you are just meaning "thin wrapper" like a lightweight wrapper type. It would be good to avoid the word thin for this non-jargon usage.
|
||
function Base.show(io::IO, f::BijectionThinWrap) | ||
replacerules = (r"^SetFunction" => "Bijection", r"^FinFunction" => "FinBijection") | ||
print(io, replace(repr(f.func), replacerules...)) |
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.
Make sure to include a test for this so that we can detect breakage. I can imagine changing the "SetFunction" and this pattern not matching any more.
# for `compose_inv`, the obvious idea would be to try refactoring | ||
# `CompositeFunction` to store a list of `SetFunction`s instead of a pair. | ||
|
||
function compose_inv(f::SetFunction, g::SetFunction) |
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.
I think this might be easier with MLStyle pattern matching and structural recursion.
…nWrap` to `BijectionWrapper`
- Rewrite `comp_inv_helper` with MLStyle pattern matching - Reconceive `BijectionBimap`, allowing it to contain instances of `AbsBijectionWrapper` - Reconceive `do_inv`, making it return a `Bijection` - Tighten up `minandmax` definition - Implement specific `do_compose` for `BijectionBimap`s
Thanks for the comments @jpfairbanks ! For now, I decided not to worry about implementing the Other needed steps:
|
This is a chunk of the work I've been doing toward implementation of #231. The main result here is the implementation of
FinBijectionCycles
: a concrete type for finite automorphisms that are backed by a set of cycles.Cycle
s are implemented asCircularVector
s, fromCircularArrays.jl
, which are wrapped so that we can provide appropriate implementations of==
andhash
.The commit also introduces an abstract type
SetBijection <: SetFunction
and redeclaresIdentityFunction <: SetBijection
.Potential Issues:
FinBijectionCycles
, as implemented here, is meaningfully slower than for vector-backed and dict-backedFinFunction
s. If the underlying data of the function is truly going to be a set of cycles, then I'm not sure how the speed can be improved. It seems that some transformation would need to be computed.f :: FinBijectionCycles
,show(f)
doesn't look great.FinFunction
types. Maybe this has been somewhat preempted, or superceded, by other ongoing work. Namely, the refactor ofFinFunction
s to use Columns.Feedback would be greatly appreciated!