Class: Stupidedi::Sets::RelativeComplement
- Inherits:
-
AbstractSet
- Object
- AbstractSet
- Stupidedi::Sets::RelativeComplement
- Defined in:
- lib/stupidedi/sets/relative_complement.rb
Overview
This data type is an infinite and non-enumerable set of values that encodes the complement of a RelativeSet
Set Operations (collapse)
Set Ordering (collapse)
- - ==(other)
-
- (Boolean) proper_subset?(other)
True if this set is a subset of the
otherset and there exists at least one element in theotherset that doesn't belong to this set. -
- (Boolean) proper_superset?(other)
True if this set is a superset of the
otherset and there exists at least one element in this set that doesn't belong to theotherset.
Pretty Printing (collapse)
Instance Method Summary (collapse)
-
- (Boolean) empty?
False.
-
- (Boolean) finite?
False.
- - (Boolean) include?(object)
-
- (RelativeComplement) initialize(complement)
constructor
A new instance of RelativeComplement.
-
- (AbstractSet) replace(other)
Returns the
otherset, converting it to an AbstractSet if it isn't already. -
- (Numeric) size
Returns the number of elements in the set.
Methods inherited from AbstractSet
#&, #+, #-, #<, #<=, #>, #>=, #^, #disjoint?, #exclude?, #infinite?, #subset?, #superset?, #|, #~
Constructor Details
- (RelativeComplement) initialize(complement)
A new instance of RelativeComplement
12 13 14 |
# File 'lib/stupidedi/sets/relative_complement.rb', line 12 def initialize(complement) @complement = complement end |
Instance Method Details
- ==(other)
119 120 121 122 |
# File 'lib/stupidedi/sets/relative_complement.rb', line 119 def ==(other) eql?(other) or (other.is_a?(RelativeComplement) and complement == other.complement) end |
- complement
48 49 50 51 |
# File 'lib/stupidedi/sets/relative_complement.rb', line 48 def complement # ¬(¬A) = A @complement end |
- difference(other)
95 96 97 98 99 100 101 102 103 |
# File 'lib/stupidedi/sets/relative_complement.rb', line 95 def difference(other) if other.is_a?(RelativeComplement) # ¬A ∖ ¬B = ¬A ∩ B = B ∖ A other.complement.difference(complement) else # ¬A ∖ B = ¬A ∩ ¬B = ¬(A ∪ B) complement.union(Sets.build(other)).complement end end |
- (Boolean) empty?
False
35 36 37 |
# File 'lib/stupidedi/sets/relative_complement.rb', line 35 def empty? false end |
- (Boolean) finite?
False
29 30 31 |
# File 'lib/stupidedi/sets/relative_complement.rb', line 29 def finite? false end |
- (Boolean) include?(object)
17 18 19 |
# File 'lib/stupidedi/sets/relative_complement.rb', line 17 def include?(object) not @complement.include?(object) end |
- (String) inspect
128 129 130 |
# File 'lib/stupidedi/sets/relative_complement.rb', line 128 def inspect "RelativeComplement(#{@complement.inspect})" end |
- intersection(other)
54 55 56 57 58 59 60 61 62 |
# File 'lib/stupidedi/sets/relative_complement.rb', line 54 def intersection(other) if other.is_a?(RelativeComplement) # ¬A ∩ ¬B = ¬(A ∪ B) complement.union(other.complement).complement else # ¬A ∩ B = B ∖ A Sets.build(other).difference(complement) end end |
- (Boolean) proper_subset?(other)
True if this set is a subset of the other set and there exists at
least one element in the other set that doesn't belong to this set
109 110 111 |
# File 'lib/stupidedi/sets/relative_complement.rb', line 109 def proper_subset?(other) other.is_a?(RelativeComplement) and intersection(other) == self end |
- (Boolean) proper_superset?(other)
True if this set is a superset of the other set and there exists at
least one element in this set that doesn't belong to the other set
114 115 116 |
# File 'lib/stupidedi/sets/relative_complement.rb', line 114 def proper_superset?(other) other.is_a?(RelativeComplement) and intersection(other) == other end |
- (AbstractSet) replace(other)
Returns the other set, converting it to an AbstractSet if it isn't
already.
40 41 42 |
# File 'lib/stupidedi/sets/relative_complement.rb', line 40 def replace(other) Sets.build(other) end |
- (Numeric) size
Returns the number of elements in the set
23 24 25 |
# File 'lib/stupidedi/sets/relative_complement.rb', line 23 def size 1.0 / 0.0 end |
- symmetric_difference(other)
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/stupidedi/sets/relative_complement.rb', line 76 def symmetric_difference(other) if other.is_a?(RelativeComplement) # ¬A ⊖ ¬B = (¬A ∖ ¬B) ∪ (¬B ∖ ¬A) # = (B ∖ A) ∪ (A ∖ B) # = A ⊖ B complement.symmetric_difference(other.complement) else # ¬A ⊖ B = (¬A ∖ B) ∪ (B ∖ ¬A) # = (¬A ∩ ¬B) ∪ (B ∩ A) # = (¬B ∖ A) ∪ (A ∖ ¬B) # = A ⊖ ¬B other = Sets.build(other) intersection(other.complement). union(other.intersection(complement)) end end |
- union(other)
65 66 67 68 69 70 71 72 73 |
# File 'lib/stupidedi/sets/relative_complement.rb', line 65 def union(other) if other.is_a?(RelativeComplement) # ¬A ∪ ¬B = ¬(A ∩ B) complement.intersection(other.complement).complement else # ¬A ∪ B = ¬(A ∖ B) complement.difference(Sets.build(other)).complement end end |