math-php icon indicating copy to clipboard operation
math-php copied to clipboard

Set::intersectPartial() method added to the SetTheory namespace

Open Smoren opened this issue 1 year ago • 6 comments

Hi @markrogoyski,

This is a PR about the M-partial intersection which have been previously added to your IterTools repository.

Definition

An M-partial intersection (for M > 0) of N sets is a set elements in which are contained in at least M initial sets.

Properties

For any N sets:

  1. 1-partial intersection is equivalent to the union of these sets.
  2. 2-partial intersection is equivalent to the difference of the union and the symmetric difference of these sets.
  3. N-partial intersection is equivalent to the common (complete) intersection of these sets.
  4. For any M > N M-partial intersection always equals to the empty set.

Example

Given: sets A, B, C, D (N = 4).

use MathPHP\SetTheory\Set;

$a = new Set([1, 2, 3, 4, 5]);
$b = new Set([1, 2, 10, 11]);
$c = new Set([1, 2, 3, 12]);
$d = new Set([1, 4, 13, 14]);

M = 1

It is equivalent to A ∪ B ∪ C ∪ D.

image

$r = $a->intersectPartial(1, $b, $c, $d);
// [1, 2, 3, 4, 5, 10, 11, 12, 13, 14]

M = 2

It is equivalent to (A ∪ B ∪ C ∪ D) \ ∆(A, B, C, D).

image

$r = $a->intersectPartial(2, $b, $c, $d);
// [1, 2, 3, 4]

M = 3

image

$r = $a->intersectPartial(3, $b, $c, $d);
// [1, 2]

M = 4 (M = N)

It is equivalent to A ∩ B ∩ C ∩ D.

image

$r = $a->intersectPartial(4, $b, $c, $d);
// [1]

M = 5 (M > N)

Equals to an empty set.

image

$r = $a->intersectPartial(5, $b, $c, $d);
// []

More examples you can see in this repo.

Smoren avatar Jan 26 '23 16:01 Smoren