-
Notifications
You must be signed in to change notification settings - Fork 279
implements some helper functions for creating and manipulating partit… #892
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
implements some helper functions for creating and manipulating partit… #892
Conversation
I went for simplicity rather than performance. At any rate, any significant performance improvement would probably involve making the representation of the classes themselves more concrete than a However, this interface should be enough for some of the common uses of partitions, e.g. bisimilarity. |
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.
Great work, thanks!
There is a couple of minor issues, some things to discuss, and one important thing - the tests. We need to add tests to all newly added functions. Please, proceed to lib_test/bap_types/test_graph.ml
and try to add tests that check all the invariants of partition. And don't forget to enable tests with the --enable-tests
option to the configure script.
lib/graphlib/graphlib.mli
Outdated
Takes an additional [comp] argument to compare for equality | ||
within the equivalence classes. *) | ||
val refine : 'a t -> rel:('a -> 'a -> int) -> comp:('a -> 'a -> int) -> 'a t |
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.
why is rel
having type 'a -> 'a -> int
(i.e., the order type) instead of 'a -> 'a -> bool
which the type for equivalence? Also, I think that equiv
would be a better name, what do you think?
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.
also, let's rename comp
to cmp
to be consistent with Core's notation.
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.
Sounds good!
lib/graphlib/graphlib.mli
Outdated
(** [merge p x y] returns the partition p with the classes of [x] | ||
and [y] merged. Returns [p] unchanged if either [x] or [y] are | ||
not part of any equivalence class. *) | ||
val merge : 'a t -> 'a -> 'a -> 'a t |
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.
Why is merge
not called union
?
Also, both refine
and merge
should say something about equivalence class ordinals (equiv
s), i.e., whether they are preserved or not, e.g., whether eqclass p x = eqclass (merge p y z)
when not (equiv x y) and not (equiv x z)
. So far we do not try to preserve them, and people might store class ordinals and apply ordinals obtained from the past partitions to the new partitions. We should either clearly indicate that ordinals make sense only with the partition from which they were obtained and are shuffled on every new repartitioning, or we can try to preserve them. So this is also a point of discussion.
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.
Merge and union are pretty much used interchangeably in this context, either is fine by me.
I'm not sure what you mean by "equivalence class ordinals". Do you mean the representatives of the classes (roots), or their position in the array of roots?
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.
The latter, values of type equiv
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.
let's pick union
as it more in the line with union/find and unification
I've addressed most of the comments, and wrote some tests. I'm not sure how to implement "random" equivalences that are refinements of other equivalences, and there are a few invariants of Partition that are hard to test without internal access, but in the meantime, is this acceptable? |
yep, looks good, thanks for the contribution! |
…ions
Example usage: