Open Smoren opened 1 year ago
Hi @Smoren,
Thank you for your interest in MathPHP and for your pull request.
I understand the functionality from our conversations in the IterTools PRs.
I have a question about implementation. Based on your description here:
For any N sets:
1-partial intersection is equivalent to the union of these sets. 2-partial intersection is equivalent to the difference of the union and the symmetric difference of these sets. N-partial intersection is equivalent to the common (complete) intersection of these sets. For any M > N M-partial intersection always equals to the empty set.
Since this new set operation seems to be able to be defined in terms of other set operations (union, difference, symmetric difference, and intersection), and those set operations are already defined on Set
, would it be possible to implement the proposed partialIntersection
in terms of the other already-existing set operations?
Also, whether or not the above is possible or not, allow me to introduce how we do unit testing for MathPHP. In addition to the individual unit tests on each method (Which you added, thank you!), whenever possible, we also add axiom unit tests based on mathematical axioms that show principles that should hold regardless of how things are implemented. See the SetAxiomsTest for examples for the class you are working on. For other examples, see MatrixAxiomsTest and VectorAxiomsTest for instance. The definitions you stated above seem like good axiom tests to add for this new operation. For these kinds of tests, using a wide variety of inputs is recommended, as the axioms should hold regardless, and no pre-computed results generally need to be done as the axioms compute the rules that must hold.
Thanks, Mark
Hi @markrogoyski,
Thanks for the feedback!
Indeed, there are cases (N=1, N=2, N=M, N>M) in which the operation is easily defined in terms of classical set operations. However, I don't see an easy way to express the partial intersection in terms of other operations for the cases 2<M<N. The algorithm that I have implemented works universally for any M>0, without considering special cases. Moreover, two classical operations can be considered as a special case of partial intersection:
As for axiomatic tests: I'll try to figure it out.
P.S. Can you unlock github workflow for me to run without manual approval please?
Thank you!
UPD: All the axiomatic unit tests are added.
P.S. Can you unlock github workflow for me to run without manual approval please?
It seems like first time contributors to a repository require manual approval from what I can tell. I think this is a relatively new GitHub feature probably to prevent abuse of resources. After you have merged something it should run automatically on each PR and additional commit. I'll just have to kick it off manually for now it seems.
@markrogoyski, OK, got it.
So I think this PR is ready to merge if you do not have new questions.
Thank you!
Hi @markrogoyski, I've rebase this branch from develop
and resolved the conflicts.
Hi @markrogoyski,
This is a PR about the M-partial intersection which have been previously added to your IterTools repository.
Definition
Properties
For any N sets:
Example
Given: sets A, B, C, D (N = 4).
M = 1
It is equivalent to
A ∪ B ∪ C ∪ D
.M = 2
It is equivalent to
(A ∪ B ∪ C ∪ D) \ ∆(A, B, C, D)
.M = 3
M = 4 (M = N)
It is equivalent to
A ∩ B ∩ C ∩ D
.M = 5 (M > N)
Equals to an empty set.
More examples you can see in this repo.