Class: Math::SetTheory::NaturalNumbers

Inherits:
NumberSet show all
Includes:
Singleton
Defined in:
lib/ruuuby/math/set_theory/discrete/natural_numbers.rb

Overview

also called: counting-numbers

Instance Attribute Summary

Attributes inherited from NumberSet

#name, #symbol, #𝔠

Attributes inherited from Closure

#axioms

Instance Method Summary collapse

Methods inherited from NumberSet

#countable?, #countably_infinite?, #finite?, #uncountable?, #βˆ‹?, #∌?, #βŠ‚?, #βŠƒ?, #βŠ„?, #βŠ…?, #βŠ†?, #βŠ‡?

Constructor Details

#initializeNaturalNumbers

Returns a new instance of NaturalNumbers.



11
12
13
14
15
16
17
# File 'lib/ruuuby/math/set_theory/discrete/natural_numbers.rb', line 11

def initialize
  super(:β„•, ::Math::SetTheory::NumberSet::AlephNumbers::ZERO, {
      closed_under_addition: true,
      closed_under_multiplication: true
  })
  @subset_of = [:π•Œ, :𝔸ᡣ, :𝔸, :ℝ, :β„‚, :β„š, :β„€, :π•Ž]
end

Instance Method Details

#_βˆ‹?(n) ⇒ Boolean

Returns true.

Returns:

  • (Boolean)

    true



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ruuuby/math/set_theory/discrete/natural_numbers.rb', line 20

def _βˆ‹?(n)
  if n.zero?
    false
  else
    case(n)
    when ::Integer
      n > 0
    when ::Float
      ((!(n.∞? || n.negative?)) && (n.positive? && n.smells_like_int?))
    when ::BigDecimal
      case(n.sign)
      when ::BigDecimal::SIGN_NaN, ::BigDecimal::SIGN_POSITIVE_INFINITE, ::BigDecimal::SIGN_NEGATIVE_INFINITE, ::BigDecimal::SIGN_NEGATIVE_FINITE, ::BigDecimal::SIGN_POSITIVE_ZERO, ::BigDecimal::SIGN_NEGATIVE_ZERO
        false
      else
        n.smells_like_int?
      end
    when ::Complex
      n.imaginary == 0 && β„•.βˆ‹?(n.real)
    when ::Rational
      β„•.βˆ‹?(n.numerator) && β„•.βˆ‹?(n.denominator)
    else
      false
    end
  end
end