Module: Combinatorics::CartesianProduct

Defined in:
lib/combinatorics/cartesian_product/cardinality.rb,
lib/combinatorics/cartesian_product/mixin.rb

Overview

Author:

Since:

  • 0.4.0

Defined Under Namespace

Modules: Mixin

Class Method Summary collapse

Class Method Details

.cardinality(a, b) ⇒ Fixnum

Wrapper for Cartesian product cardinality method defined above

Examples:

Calculate elements in Cartesian product of two equal-size sets

cardinality(3, 4) 
# => 12

Parameters:

  • a (Fixnum)

    Cardinality of first set.

  • b (Fixnum)

    Cardinality of second set.

Returns:

  • (Fixnum)

    Length of enumeration resulting from a Cartesian product.

Raises:

  • (RangeError)

    Inputs must be greater than zero.

Since:

  • 0.4.0



29
30
31
32
33
34
35
# File 'lib/combinatorics/cartesian_product/cardinality.rb', line 29

def self.cardinality(a,b)
  if (a <= 0 || b <= 0)
    raise(RangeError,"inputs must be greater than zero")
  end

  a * b
end

.X(a, b) ⇒ Object

Note:

The letter `X' is scholastic notation for the Cartesian product set operation

See Also:

Since:

  • 0.4.0



43
44
45
# File 'lib/combinatorics/cartesian_product/cardinality.rb', line 43

def self.X(a,b)
  cardinality(a,b)
end