@@ 54-65 (lines=12) @@ | ||
51 | * |
|
52 | * @return Set[] |
|
53 | */ |
|
54 | public static function cartesian(self $a, self $b): array |
|
55 | { |
|
56 | $cartesian = []; |
|
57 | ||
58 | foreach ($a as $multiplier) { |
|
59 | foreach ($b as $multiplicand) { |
|
60 | $cartesian[] = new self(array_merge([$multiplicand], [$multiplier])); |
|
61 | } |
|
62 | } |
|
63 | ||
64 | return $cartesian; |
|
65 | } |
|
66 | ||
67 | /** |
|
68 | * Creates the power set of A. |
|
@@ 72-83 (lines=12) @@ | ||
69 | * |
|
70 | * @return Set[] |
|
71 | */ |
|
72 | public static function power(self $a): array |
|
73 | { |
|
74 | $power = [new self()]; |
|
75 | ||
76 | foreach ($a as $multiplicand) { |
|
77 | foreach ($power as $multiplier) { |
|
78 | $power[] = new self(array_merge([$multiplicand], $multiplier->toArray())); |
|
79 | } |
|
80 | } |
|
81 | ||
82 | return $power; |
|
83 | } |
|
84 | ||
85 | /** |
|
86 | * @param string|int|float|bool $element |