Class: Cantor::RelativeComplement
Overview
This data type is an infinite and non-enumerable set of values that encodes the complement of a RelativeSet
Instance Method Summary
collapse
Methods inherited from AbstractSet
#&, #+, #-, #<, #<=, #>, #>=, #^, #contain?, #disjoint?, #exclude?, #infinite?, #member?, #present?, #subset?, #superset?, #|, #~
Constructor Details
Returns a new instance of RelativeComplement.
11
12
13
|
# File 'lib/cantor/relative_complement.rb', line 11
def initialize(complement)
@complement = complement
end
|
Instance Method Details
#==(other) ⇒ Object
118
119
120
121
|
# File 'lib/cantor/relative_complement.rb', line 118
def ==(other)
eql?(other) or
(other.is_a?(RelativeComplement) and complement == other.complement)
end
|
#complement ⇒ Object
47
48
49
50
|
# File 'lib/cantor/relative_complement.rb', line 47
def complement
@complement
end
|
#difference(other) ⇒ Object
94
95
96
97
98
99
100
101
102
|
# File 'lib/cantor/relative_complement.rb', line 94
def difference(other)
if other.is_a?(RelativeComplement)
other.complement.difference(complement)
else
complement.union(Cantor.build(other)).complement
end
end
|
#empty? ⇒ Boolean
34
35
36
|
# File 'lib/cantor/relative_complement.rb', line 34
def empty?
false
end
|
#finite? ⇒ Boolean
28
29
30
|
# File 'lib/cantor/relative_complement.rb', line 28
def finite?
false
end
|
#include?(object) ⇒ Boolean
16
17
18
|
# File 'lib/cantor/relative_complement.rb', line 16
def include?(object)
not @complement.include?(object)
end
|
#inspect ⇒ String
127
128
129
|
# File 'lib/cantor/relative_complement.rb', line 127
def inspect
"RelativeComplement(#{@complement.inspect})"
end
|
#intersection(other) ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/cantor/relative_complement.rb', line 53
def intersection(other)
if other.is_a?(RelativeComplement)
complement.union(other.complement).complement
else
Cantor.build(other).difference(complement)
end
end
|
#proper_subset?(other) ⇒ Boolean
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
108
109
110
|
# File 'lib/cantor/relative_complement.rb', line 108
def proper_subset?(other)
other.is_a?(RelativeComplement) and intersection(other) == self
end
|
#proper_superset?(other) ⇒ Boolean
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
113
114
115
|
# File 'lib/cantor/relative_complement.rb', line 113
def proper_superset?(other)
other.is_a?(RelativeComplement) and intersection(other) == other
end
|
#replace(other) ⇒ Object
39
40
41
|
# File 'lib/cantor/relative_complement.rb', line 39
def replace(other)
Cantor.build(other)
end
|
#size ⇒ Object
22
23
24
|
# File 'lib/cantor/relative_complement.rb', line 22
def size
1.0 / 0.0
end
|
#symmetric_difference(other) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/cantor/relative_complement.rb', line 75
def symmetric_difference(other)
if other.is_a?(RelativeComplement)
complement.symmetric_difference(other.complement)
else
other = Cantor.build(other)
intersection(other.complement).
union(other.intersection(complement))
end
end
|
#union(other) ⇒ Object
64
65
66
67
68
69
70
71
72
|
# File 'lib/cantor/relative_complement.rb', line 64
def union(other)
if other.is_a?(RelativeComplement)
complement.intersection(other.complement).complement
else
complement.difference(Cantor.build(other)).complement
end
end
|