1Set::Infinite::Basic(3)User Contributed Perl DocumentatioSnet::Infinite::Basic(3)
2
3
4
6 Set::Infinite::Basic - Sets of intervals 6 =head1 SYNOPSIS
7
8 use Set::Infinite::Basic;
9
10 $set = Set::Infinite::Basic->new(1,2); # [1..2]
11 print $set->union(5,6); # [1..2],[5..6]
12
14 Set::Infinite::Basic is a Set Theory module for infinite sets.
15
16 It works on reals, integers, and objects.
17
18 This module does not support recurrences. Recurrences are implemented
19 in Set::Infinite.
20
22 empty_set
23
24 Creates an empty_set.
25
26 If called from an existing set, the empty set inherits the "type" and
27 "density" characteristics.
28
29 universal_set
30
31 Creates a set containing "all" possible elements.
32
33 If called from an existing set, the universal set inherits the "type"
34 and "density" characteristics.
35
36 until
37
38 Extends a set until another:
39
40 0,5,7 -> until 2,6,10
41
42 gives
43
44 [0..2), [5..6), [7..10)
45
46 Note: this function is still experimental.
47
48 copy
49
50 clone
51
52 Makes a new object from the object's data.
53
54 Mode functions:
55
56 $set = $set->real;
57
58 $set = $set->integer;
59
60 Logic functions:
61
62 $logic = $set->intersects($b);
63
64 $logic = $set->contains($b);
65
66 $logic = $set->is_null; # also called "is_empty"
67
68 Set functions:
69
70 $set = $set->union($b);
71
72 $set = $set->intersection($b);
73
74 $set = $set->complement;
75 $set = $set->complement($b); # can also be called "minus" or "difference"
76
77 $set = $set->simmetric_difference( $b );
78
79 $set = $set->span;
80
81 result is (min .. max)
82
83 Scalar functions:
84
85 $i = $set->min;
86
87 $i = $set->max;
88
89 $i = $set->size;
90
91 $i = $set->count; # number of spans
92
93 Overloaded Perl functions:
94
95 print
96
97 sort, <=>
98
99 Global functions:
100
101 separators(@i)
102
103 chooses the interval separators.
104
105 default are [ ] ( ) '..' ','.
106
107 INFINITY
108
109 returns an 'Infinity' number.
110
111 NEG_INFINITY
112
113 returns a '-Infinity' number.
114
115 iterate ( sub { } )
116
117 Iterates over a subroutine.
118 Returns the union of partial results.
119
120 first
121
122 In scalar context returns the first interval of a set.
123
124 In list context returns the first interval of a set, and the
125 'tail'.
126
127 Works in unbounded sets
128
129 type($i)
130
131 chooses an object data type.
132
133 default is none (a normal perl SCALAR).
134
135 examples:
136
137 type('Math::BigFloat');
138 type('Math::BigInt');
139 type('Set::Infinite::Date');
140 See notes on Set::Infinite::Date below.
141
142 tolerance(0) defaults to real sets (default)
143 tolerance(1) defaults to integer sets
144
145 real defaults to real sets (default)
146
147 integer defaults to integer sets
148
149 Internal functions:
150
151 $set->fixtype;
152
153 $set->numeric;
154
156 $set = Set::Infinite->new(10,1);
157 Will be interpreted as [1..10]
158
159 $set = Set::Infinite->new(1,2,3,4);
160 Will be interpreted as [1..2],[3..4] instead of [1,2,3,4].
161 You probably want ->new([1],[2],[3],[4]) instead,
162 or maybe ->new(1,4)
163
164 $set = Set::Infinite->new(1..3);
165 Will be interpreted as [1..2],3 instead of [1,2,3].
166 You probably want ->new(1,3) instead.
167
169 The internal representation of a span is a hash:
170
171 { a => start of span,
172 b => end of span,
173 open_begin => '0' the span starts in 'a'
174 '1' the span starts after 'a'
175 open_end => '0' the span ends in 'b'
176 '1' the span ends before 'b'
177 }
178
179 For example, this set:
180
181 [100..200),300,(400..infinity)
182
183 is represented by the array of hashes:
184
185 list => [
186 { a => 100, b => 200, open_begin => 0, open_end => 1 },
187 { a => 300, b => 300, open_begin => 0, open_end => 0 },
188 { a => 400, b => infinity, open_begin => 0, open_end => 1 },
189 ]
190
191 The density of a set is stored in the "tolerance" variable:
192
193 tolerance => 0; # the set is made of real numbers.
194
195 tolerance => 1; # the set is made of integers.
196
197 The "type" variable stores the class of objects that will be stored in
198 the set.
199
200 type => 'DateTime'; # this is a set of DateTime objects
201
202 The infinity value is generated by Perl, when it finds a numerical
203 overflow:
204
205 $inf = 100**100**100;
206
208 Set::Infinite
209
211 Flavio Soibelmann Glock <fglock@pucrs.br>
212
213
214
215perl v5.8.8 2004-11-03 Set::Infinite::Basic(3)