Class: VectorNumber
- Inherits:
-
Object
- Object
- VectorNumber
- Includes:
- Comparable, Enumerable
- Defined in:
- lib/vector_number.rb,
lib/vector_number/mathing.rb,
lib/vector_number/version.rb,
lib/vector_number/querying.rb,
lib/vector_number/comparing.rb,
lib/vector_number/converting.rb,
lib/vector_number/enumerating.rb,
lib/vector_number/stringifying.rb,
lib/vector_number/math_converting.rb,
lib/vector_number/numeric_refinements.rb
Overview
VectorNumber provides a Numeric-like experience for doing arithmetics on heterogeneous objects, with more advanced operations based on real vector spaces available when needed.
VectorNumber inherits from Object and includes Enumerable and Comparable. It implements mostly the same interface as Numeric classes, but can #coerce any value. Its behavior follows Complex when possible.
All instances are frozen after creation.
Creation
-
VectorNumber.[]: the simplest way to create a VectorNumber
-
#initialize: an alternative way, with some advanced features
Comparing
-
#==: test for equal value
-
#eql?: test for equal value and type
-
#<=>: compare real values
-
#hash: calculate hash value for use in Hashes
Querying
-
#zero?: check if all coefficients are zero
-
#nonzero?: check if any coefficient is non-zero
-
#positive?: check if all coefficients are positive
-
#negative?: check if all coefficients are negative
-
#finite?: check if all coefficients are finite
-
#infinite?: check if any coefficient is non-finite
-
#numeric?: test if value is real or complex
-
#nonnumeric?: test if value is not real or complex
-
#integer?:
false -
#real?:
false
Unary math operations
-
#abs/#magnitude: return absolute value (magnitude, length)
-
#abs2: return square of absolute value
Arithmetic operations
-
#coerce: convert any object to a VectorNumber
-
#fdiv: divide (scale) by a real number, using
fdiv -
#div: perform integer division
-
#remainder: return remainder from integer division
Rounding
-
#round: round each coefficient
-
#ceil: round each coefficient up towards +∞
-
#floor: round each coefficient down towards -∞
-
#truncate: truncate each coefficient towards 0
Type conversion
-
#real: return real part
-
#imag/#imaginary: return imaginary part
-
#to_f: convert to
Floatif possible -
#to_r: convert to
Rationalif possible -
#to_d: convert to
BigDecimalif possible -
#to_c: convert to
Complexif possible
Hash-like operations
-
#each/#each_pair: iterate through every pair of unit and coefficient
-
#[]: get coefficient by unit
-
#coefficients/##values: return an array of coefficients
-
#to_h: convert to Hash
Miscellaneous methods
Defined Under Namespace
Modules: NumericRefinements
Constant Summary collapse
- KNOWN_OPTIONS =
Keys for possible options. Unknown options will be rejected when creating a vector.
i[mult].freeze
- DEFAULT_OPTIONS =
Default values for options.
{ mult: :dot }.freeze
- UNIT =
Get a unit for nth numeric dimension, where 1 is real, 2 is imaginary.
->(n) { n }.freeze
- R =
Constant for real unit.
UNIT[1]
- I =
Constant for imaginary unit.
UNIT[2]
- VERSION =
"0.5.0"- MULT_STRINGS =
Predefined symbols for multiplication to display between unit and coefficient.
{ asterisk: "*", # U+002A cross: "×", # U+00D7 dot: "⋅", # U+22C5 invisible: "", # U+2062, zero-width multiplication operator space: " ", none: "", }.freeze
Instance Attribute Summary collapse
-
#options ⇒ Hash{Symbol => Object}
readonly
Options used for this vector.
-
#size ⇒ Integer
readonly
Number of non-zero dimensions.
Creation collapse
-
.[](*values, **options) ⇒ VectorNumber
Create new VectorNumber from a list of values, possibly specifying options.
-
#initialize(values = nil, options = nil) {|coefficient| ... } ⇒ VectorNumber
constructor
Create new VectorNumber from
values, possibly specifyingoptions, possibly modifying coefficients with a block.
Miscellaneous methods collapse
-
#+@ ⇒ VectorNumber
(also: #dup)
Return self.
-
#clone(freeze: true) ⇒ VectorNumber
Return self.
-
#inspect ⇒ String
Return string representation of the vector.
-
#to_s(mult: options[:mult]) ⇒ String
Return string representation of the vector.
Mathematical operations collapse
-
#%(other) ⇒ VectorNumber
(also: #modulo)
Return the modulus of dividing self by a real
otheras a vector. -
#*(other) ⇒ VectorNumber
(also: #mult)
Multiply all coefficients by a real
other, returning new vector. -
#+(other) ⇒ VectorNumber
(also: #add)
Return new vector as a sum of this and
othervalue. -
#-(other) ⇒ VectorNumber
(also: #sub)
Return new vector as a sum of this and additive inverse of
othervalue. -
#-@ ⇒ VectorNumber
(also: #neg)
Return new vector with negated coefficients (additive inverse).
-
#/(other) ⇒ VectorNumber
(also: #quo)
Divide all coefficients by a real
other, returning new vector. -
#abs ⇒ Float
(also: #magnitude)
Calculate the absolute value of the vector (its length).
-
#abs2 ⇒ Float
Calculate the square of absolute value.
-
#ceil(digits = 0) ⇒ VectorNumber
Return a new vector with every coefficient rounded using their
#ceil. -
#coerce(other) ⇒ Array(VectorNumber, VectorNumber)
The coerce method provides support for Ruby type coercion.
-
#div(other) ⇒ VectorNumber
Divide all coefficients by a real
other, converting results to integers using#floor. -
#divmod(other) ⇒ Array(VectorNumber, VectorNumber)
Return the quotient and modulus of dividing self by a real
other. -
#fdiv(other) ⇒ VectorNumber
Divide all coefficients by a real
otherusingfdiv, returning new vector with decimal coefficients. -
#floor(digits = 0) ⇒ VectorNumber
Return a new vector with every coefficient rounded using their
#floor. -
#remainder(other) ⇒ VectorNumber
Return the remainder of dividing self by a real
otheras a vector. -
#round(digits = 0, half: :up) ⇒ VectorNumber
Return a new vector with every coefficient rounded using their
#round. -
#truncate(digits = 0) ⇒ VectorNumber
Return a new vector with every coefficient truncated using their
#truncate.
Querying collapse
-
#finite? ⇒ Boolean
Returns
trueif all coefficients are finite,falseotherwise. -
#infinite? ⇒ 1?
Returns
1if any coefficients are non-finite,nilotherwise. -
#integer? ⇒ false
Always returns
false, as vectors are not Integers. -
#negative? ⇒ Boolean
Returns
trueif number is non-zero and all non-zero coefficients are negative, andfalseotherwise. -
#nonnumeric?(dimensions = 2) ⇒ Boolean
Whether this VectorNumber contains any non-numeric parts.
-
#nonzero? ⇒ VectorNumber?
Returns
selfif there are any non-zero coefficients,nilotherwise. -
#numeric?(dimensions = 2) ⇒ Boolean
Whether this VectorNumber can be considered strictly numeric — real or complex.
-
#positive? ⇒ Boolean
Returns
trueif number is non-zero and all non-zero coefficients are positive, andfalseotherwise. -
#real? ⇒ false
Always returns
false, as vectors are not real numbers. -
#zero? ⇒ Boolean
Returns
trueif there are no non-zero coefficients, andfalseotherwise.
Comparing collapse
-
#<=>(other) ⇒ Integer?
Compare to
otherand return -1, 0, or 1 ifselfis less than, equal, or larger thanotheron real number line, ornilif any or both values are non-real. -
#==(other) ⇒ Boolean
Test whether
otherhas the same value with == semantics. -
#eql?(other) ⇒ Boolean
Test whether
otheris VectorNumber and has the same value witheql?semantics. -
#hash ⇒ Integer
Generate an Integer hash value for self.
Converting to different numeric classes collapse
-
#imaginary ⇒ Integer, ...
(also: #imag)
Return imaginary part of the number.
-
#real ⇒ Integer, ...
Return real part of the number.
-
#to_c ⇒ Complex
Return value as a Complex if only real and/or imaginary parts are non-zero.
-
#to_d(ndigits = nil) ⇒ BigDecimal
Return value as a BigDecimal if only real part is non-zero.
-
#to_f ⇒ Float
Return value as a Float if only real part is non-zero.
-
#to_i ⇒ Integer
(also: #to_int)
Return value as an Integer, truncating it, if only real part is non-zero.
-
#to_r ⇒ Rational
Return value as a Rational if only real part is non-zero.
Hash-like operations collapse
-
#[](unit) ⇒ Numeric
Get the coefficient for the unit.
-
#coefficients ⇒ Array<Numeric>
(also: #values)
Get a list of non-zero coefficients.
-
#each(&block) ⇒ Object
(also: #each_pair)
Iterate through every pair of unit and coefficient.
-
#to_h(&block) ⇒ Hash{Object => Numeric}
Get mutable hash with vector’s data.
-
#unit?(unit) ⇒ Boolean
(also: #key?)
Check if a unit has a non-zero coefficient.
-
#units ⇒ Array<Object>
(also: #keys)
Get a list of units with non-zero coefficients.
Constructor Details
#initialize(values = nil, options = nil) {|coefficient| ... } ⇒ VectorNumber
Create new VectorNumber from values, possibly specifying options, possibly modifying coefficients with a block.
values can be:
-
an array of values (see []);
-
a VectorNumber to copy;
-
a hash in the format returned by #to_h;
-
nilto specify a 0-dimensional vector (same as an empty array or hash).
Using a hash as values is an advanced technique which allows to quickly construct a VectorNumber with desired units and coefficients, but it can also lead to unexpected results if care is not taken to provide only valid keys and values.
196 197 198 199 200 201 202 203 204 205 |
# File 'lib/vector_number.rb', line 196 def initialize(values = nil, = nil, &transform) # @type var options: Hash[Symbol, Object] initialize_from(values) apply_transform(&transform) finalize_contents (, values) .freeze @data.freeze freeze end |
Instance Attribute Details
#options ⇒ Hash{Symbol => Object} (readonly)
Options used for this vector.
157 158 159 |
# File 'lib/vector_number.rb', line 157 def end |
#size ⇒ Integer (readonly)
Number of non-zero dimensions.
148 149 150 |
# File 'lib/vector_number.rb', line 148 def size @size end |
Class Method Details
.[](*values, **options) ⇒ VectorNumber
Create new VectorNumber from a list of values, possibly specifying options.
138 139 140 |
# File 'lib/vector_number.rb', line 138 def self.[](*values, **) new(values, ) end |
Instance Method Details
#%(other) ⇒ VectorNumber Also known as: modulo
Return the modulus of dividing self by a real other as a vector.
This is equal to self - other * (self/other).floor, or, alternatively, self - other * self.div(other).
259 260 261 262 263 264 |
# File 'lib/vector_number/mathing.rb', line 259 def %(other) check_divisibility(other) other = other.real new { _1 % other } end |
#*(other) ⇒ VectorNumber Also known as: mult
Multiply all coefficients by a real other, returning new vector.
This effectively multiplies #magnitude by other.
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/vector_number/mathing.rb', line 115 def *(other) if real_number?(other) other = other.real # @type var other: Float new { _1 * other } elsif real_number?(self) && other.is_a?(self.class) # @type var other: untyped other * self else raise RangeError, "can't multiply #{self} and #{other}" end end |
#+(other) ⇒ VectorNumber Also known as: add
Return new vector as a sum of this and other value. This is analogous to [].
66 67 68 |
# File 'lib/vector_number/mathing.rb', line 66 def +(other) new([self, other]) end |
#+@ ⇒ VectorNumber Also known as: dup
Return self.
214 215 |
# File 'lib/vector_number.rb', line 214 def +@ = self # @since 0.2.4 |
#-(other) ⇒ VectorNumber Also known as: sub
89 90 91 |
# File 'lib/vector_number/mathing.rb', line 89 def -(other) self + new([other], &:-@) end |
#-@ ⇒ VectorNumber Also known as: neg
Return new vector with negated coefficients (additive inverse).
44 45 46 |
# File 'lib/vector_number/mathing.rb', line 44 def -@ new(&:-@) end |
#/(other) ⇒ VectorNumber Also known as: quo
This method never does integer division.
Divide all coefficients by a real other, returning new vector.
This effectively multiplies #magnitude by reciprocal of other.
153 154 155 156 157 158 159 160 161 |
# File 'lib/vector_number/mathing.rb', line 153 def /(other) check_divisibility(other) other = other.real # Prevent integer division, but without loss of accuracy. other = Rational(other) if other.integer? # @type var other: Float new { _1 / other } end |
#<=>(other) ⇒ Integer?
Compare to other and return -1, 0, or 1 if self is less than, equal, or larger than other on real number line, or nil if any or both values are non-real.
Most VectorNumbers are non-real and therefore not comparable with this method.
116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/vector_number/comparing.rb', line 116 def <=>(other) return nil unless numeric?(1) case other when VectorNumber other.numeric?(1) ? real <=> other.real : nil when Numeric other.imaginary.zero? ? real <=> other.real : nil else nil end end |
#==(other) ⇒ Boolean
Test whether other has the same value with == semantics.
Values are considered equal if
-
otheris a VectorNumber and it has the same units and equal coefficients, or -
otheris a Numeric equal in value to this (real or complex) number.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vector_number/comparing.rb', line 32 def ==(other) return true if equal?(other) case other when VectorNumber size == other.size && @data == other.to_h when Numeric numeric?(2) && other.real == real && other.imaginary == imaginary else # Can't compare a number-like value to a non-number. false end end |
#[](unit) ⇒ Numeric
Get the coefficient for the unit.
If the unit?(unit) is false, 0 is returned. Note that units for real and imaginary parts are VectorNumber::R and VectorNumber::I respectively.
111 |
# File 'lib/vector_number/enumerating.rb', line 111 def [](unit) = @data[unit] |
#abs ⇒ Float Also known as: magnitude
Calculate the absolute value of the vector (its length).
16 17 18 |
# File 'lib/vector_number/math_converting.rb', line 16 def abs Math.sqrt(abs2) end |
#abs2 ⇒ Float
Calculate the square of absolute value.
32 33 34 |
# File 'lib/vector_number/math_converting.rb', line 32 def abs2 coefficients.sum(&:abs2) end |
#ceil(digits = 0) ⇒ VectorNumber
Return a new vector with every coefficient rounded using their #ceil.
66 67 68 |
# File 'lib/vector_number/math_converting.rb', line 66 def ceil(digits = 0) new { _1.ceil(digits) } end |
#clone(freeze: true) ⇒ VectorNumber
Return self.
224 225 226 227 228 229 230 231 232 233 |
# File 'lib/vector_number.rb', line 224 def clone(freeze: true) case freeze when true, nil self when false raise ArgumentError, "can't unfreeze #{self.class}" else raise ArgumentError, "unexpected value for freeze: #{freeze.class}" end end |
#coefficients ⇒ Array<Numeric> Also known as: values
Get a list of non-zero coefficients.
72 |
# File 'lib/vector_number/enumerating.rb', line 72 def coefficients = @data.values |
#coerce(other) ⇒ Array(VectorNumber, VectorNumber)
The coerce method provides support for Ruby type coercion.
Unlike other numeric types, VectorNumber can coerce anything.
25 26 27 28 29 30 31 32 |
# File 'lib/vector_number/mathing.rb', line 25 def coerce(other) case other when VectorNumber [other, self] else [new([other]), self] end end |
#div(other) ⇒ VectorNumber
Divide all coefficients by a real other, converting results to integers using #floor.
This is requal to (self / other).floor.
222 223 224 225 226 227 |
# File 'lib/vector_number/mathing.rb', line 222 def div(other) check_divisibility(other) other = other.real new { _1.div(other) } end |
#divmod(other) ⇒ Array(VectorNumber, VectorNumber)
292 293 294 |
# File 'lib/vector_number/mathing.rb', line 292 def divmod(other) [div(other), modulo(other)] end |
#each {|unit, coefficient| ... } ⇒ VectorNumber #each ⇒ Enumerator Also known as: each_pair
Iterate through every pair of unit and coefficient. Returns Enumerator (with set size) if no block is given.
39 40 41 42 43 44 |
# File 'lib/vector_number/enumerating.rb', line 39 def each(&block) return to_enum { size } unless block_given? @data.each(&block) self end |
#eql?(other) ⇒ Boolean
Test whether other is VectorNumber and has the same value with eql? semantics.
Values are considered equal only if other is a VectorNumber and it has exactly the same units and coefficients, though possibly in a different order. Additionally, ‘a.eql?(b)` implies `a.hash == b.hash`.
Note that #options are not considered for equality.
65 66 67 68 69 70 |
# File 'lib/vector_number/comparing.rb', line 65 def eql?(other) return true if equal?(other) return false unless other.is_a?(VectorNumber) size.eql?(other.size) && @data.eql?(other.to_h) end |
#fdiv(other) ⇒ VectorNumber
Divide all coefficients by a real other using fdiv, returning new vector with decimal coefficients.
There isn’t much benefit to this method, as #/ doesn’t do integer division, but it is provided for consistency.
189 190 191 192 193 194 |
# File 'lib/vector_number/mathing.rb', line 189 def fdiv(other) check_divisibility(other) other = other.real new { _1.fdiv(other) } end |
#finite? ⇒ Boolean
Returns true if all coefficients are finite, false otherwise.
55 56 57 |
# File 'lib/vector_number/querying.rb', line 55 def finite? all? { |_u, v| v.finite? } end |
#floor(digits = 0) ⇒ VectorNumber
Return a new vector with every coefficient rounded using their #floor.
83 84 85 |
# File 'lib/vector_number/math_converting.rb', line 83 def floor(digits = 0) new { _1.floor(digits) } end |
#hash ⇒ Integer
Generate an Integer hash value for self.
Hash values are stable during runtime, but not between processes. Options are disregarded for hash calculation.
85 86 87 |
# File 'lib/vector_number/comparing.rb', line 85 def hash [self.class, @data].hash end |
#imaginary ⇒ Integer, ... Also known as: imag
Return imaginary part of the number.
26 |
# File 'lib/vector_number/converting.rb', line 26 def imaginary = @data[I] |
#infinite? ⇒ 1?
Returns 1 if any coefficients are non-finite, nil otherwise.
This behavior is the same as Complex‘s.
71 72 73 |
# File 'lib/vector_number/querying.rb', line 71 def infinite? finite? ? nil : 1 # rubocop:disable Style/ReturnNilInPredicateMethodDefinition end |
#inspect ⇒ String
Return string representation of the vector.
This is similar to Complex#inspect: it returns result of #to_s in round brackets.
65 66 67 68 |
# File 'lib/vector_number/stringifying.rb', line 65 def inspect # TODO: Probably make this independent of options. "(#{self})" end |
#integer? ⇒ false
Always returns false, as vectors are not Integers.
156 |
# File 'lib/vector_number/querying.rb', line 156 def integer? = false |
#negative? ⇒ Boolean
Returns true if number is non-zero and all non-zero coefficients are negative, and false otherwise.
136 137 138 |
# File 'lib/vector_number/querying.rb', line 136 def negative? !zero? && all? { |_u, c| c.negative? } end |
#nonnumeric?(dimensions = 2) ⇒ Boolean
Whether this VectorNumber contains any non-numeric parts.
43 |
# File 'lib/vector_number/querying.rb', line 43 def nonnumeric?(dimensions = 2) = !numeric?(dimensions) |
#nonzero? ⇒ VectorNumber?
Returns self if there are any non-zero coefficients, nil otherwise.
This is synonymous with size not being equal to 0. Behavior of returning self or nil is the same as Numeric‘s.
104 105 106 |
# File 'lib/vector_number/querying.rb', line 104 def nonzero? zero? ? nil : self # rubocop:disable Style/ReturnNilInPredicateMethodDefinition end |
#numeric?(dimensions = 2) ⇒ Boolean
Whether this VectorNumber can be considered strictly numeric — real or complex.
24 25 26 27 28 |
# File 'lib/vector_number/querying.rb', line 24 def numeric?(dimensions = 2) raise ArgumentError, "`dimensions` must be non-negative" unless dimensions >= 0 size <= dimensions && (1..dimensions).count { @data[UNIT[_1]].nonzero? } == size end |
#positive? ⇒ Boolean
Returns true if number is non-zero and all non-zero coefficients are positive, and false otherwise.
120 121 122 |
# File 'lib/vector_number/querying.rb', line 120 def positive? !zero? && all? { |_u, c| c.positive? } end |
#real ⇒ Integer, ...
Return real part of the number.
15 |
# File 'lib/vector_number/converting.rb', line 15 def real = @data[R] |
#real? ⇒ false
Always returns false, as vectors are not real numbers.
This behavior is the same as Complex‘s.
149 |
# File 'lib/vector_number/querying.rb', line 149 def real? = false |
#remainder(other) ⇒ VectorNumber
Return the remainder of dividing self by a real other as a vector.
This is equal to self - other * (self/other).truncate.
323 324 325 326 327 328 |
# File 'lib/vector_number/mathing.rb', line 323 def remainder(other) check_divisibility(other) other = other.real new { _1.remainder(other) } end |
#round(digits = 0, half: :up) ⇒ VectorNumber
Return a new vector with every coefficient rounded using their #round.
In the case of BigDecimal coefficients, the half parameter is converted to the corresponding BigDecimal rounding mode (one of :half_up, :half_down, or :half_even). Other modes can not be specified.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/vector_number/math_converting.rb', line 110 def round(digits = 0, half: :up) if defined?(BigDecimal) bd_mode = case half when :down then :half_down when :even then :half_even else :half_up end new { _1.is_a?(BigDecimal) ? _1.round(digits, bd_mode) : _1.round(digits, half: half) } # :nocov: else new { _1.round(digits, half: half) } end # :nocov: end |
#to_c ⇒ Complex
Return value as a Complex if only real and/or imaginary parts are non-zero.
146 147 148 149 150 |
# File 'lib/vector_number/converting.rb', line 146 def to_c raise_convert_error(Complex) unless numeric?(2) Complex(real, imaginary) end |
#to_d(ndigits = nil) ⇒ BigDecimal
Return value as a BigDecimal if only real part is non-zero.
122 123 124 125 126 127 128 129 |
# File 'lib/vector_number/converting.rb', line 122 def to_d(ndigits = nil) raise_convert_error(BigDecimal) unless numeric?(1) return BigDecimal(real, ndigits) if ndigits return BigDecimal(real, Float::DIG) if real.is_a?(Float) BigDecimal(real) end |
#to_f ⇒ Float
Return value as a Float if only real part is non-zero.
71 72 73 74 75 |
# File 'lib/vector_number/converting.rb', line 71 def to_f raise_convert_error(Float) unless numeric?(1) real.to_f end |
#to_h(&block) ⇒ Hash{Object => Numeric}
Get mutable hash with vector’s data.
Returned hash has a default value of 0.
88 89 90 91 92 93 94 95 |
# File 'lib/vector_number/enumerating.rb', line 88 def to_h(&block) # TODO: Remove block argument. if block_given? @data.to_h(&block) else @data.dup end end |
#to_i ⇒ Integer Also known as: to_int
Return value as an Integer, truncating it, if only real part is non-zero.
47 48 49 50 51 |
# File 'lib/vector_number/converting.rb', line 47 def to_i raise_convert_error(Integer) unless numeric?(1) real.to_i end |
#to_r ⇒ Rational
Return value as a Rational if only real part is non-zero.
92 93 94 95 96 |
# File 'lib/vector_number/converting.rb', line 92 def to_r raise_convert_error(Rational) unless numeric?(1) real.to_r end |
#to_s(mult: options[:mult]) ⇒ String
Return string representation of the vector.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/vector_number/stringifying.rb', line 38 def to_s(mult: [:mult]) return "0" if zero? result = +"" each_with_index do |(unit, coefficient), index| if index.zero? result << "-" if coefficient.negative? else result << (coefficient.positive? ? " + " : " - ") end result << value_to_s(unit, coefficient.abs, mult: mult) end result end |
#truncate(digits = 0) ⇒ VectorNumber
Return a new vector with every coefficient truncated using their #truncate.
49 50 51 |
# File 'lib/vector_number/math_converting.rb', line 49 def truncate(digits = 0) new { _1.truncate(digits) } end |
#unit?(unit) ⇒ Boolean Also known as: key?
Check if a unit has a non-zero coefficient.
123 |
# File 'lib/vector_number/enumerating.rb', line 123 def unit?(unit) = @data.key?(unit) |
#units ⇒ Array<Object> Also known as: keys
Get a list of units with non-zero coefficients.
58 |
# File 'lib/vector_number/enumerating.rb', line 58 def units = @data.keys |
#zero? ⇒ Boolean
Returns true if there are no non-zero coefficients, and false otherwise.
This is synonymous with size being 0.
88 |
# File 'lib/vector_number/querying.rb', line 88 def zero? = size.zero? |