Phpml\Math\Set::power PHP Method

power() public static method

Creates the power set of A.
public static power ( Set $a ) : array
$a Set
return array
    public static function power(Set $a) : array
    {
        $power = [new self()];
        foreach ($a as $multiplicand) {
            foreach ($power as $multiplier) {
                $power[] = new self(array_merge([$multiplicand], $multiplier->toArray()));
            }
        }
        return $power;
    }

Usage Example

Example #1
0
 public function testPower()
 {
     $power = Set::power(new Set(['A', 'B']));
     $this->assertInternalType('array', $power);
     $this->assertEquals([new Set(), new Set(['A']), new Set(['B']), new Set(['A', 'B'])], $power);
     $this->assertEquals(4, count($power));
 }