1Set::Infinite(3)      User Contributed Perl Documentation     Set::Infinite(3)
2
3
4

NAME

6       Set::Infinite - Sets of intervals
7

SYNOPSIS

9         use Set::Infinite;
10
11         $set = Set::Infinite->new(1,2);    # [1..2]
12         print $set->union(5,6);            # [1..2],[5..6]
13

DESCRIPTION

15       Set::Infinite is a Set Theory module for infinite sets.
16
17       A set is a collection of objects.  The objects that belong to a set are
18       called its members, or "elements".
19
20       As objects we allow (almost) anything:  reals, integers, and objects
21       (such as dates).
22
23       We allow sets to be infinite.
24
25       There is no account for the order of elements. For example, {1,2} =
26       {2,1}.
27
28       There is no account for repetition of elements. For example, {1,2,2} =
29       {1,1,1,2} = {1,2}.
30

CONSTRUCTOR

32       new
33
34       Creates a new set object:
35
36           $set = Set::Infinite->new;             # empty set
37           $set = Set::Infinite->new( 10 );       # single element
38           $set = Set::Infinite->new( 10, 20 );   # single range
39           $set = Set::Infinite->new(
40                     [ 10, 20 ], [ 50, 70 ] );    # two ranges
41
42       empty set
43               $set = Set::Infinite->new;
44
45       set with a single element
46               $set = Set::Infinite->new( 10 );
47
48               $set = Set::Infinite->new( [ 10 ] );
49
50       set with a single span
51               $set = Set::Infinite->new( 10, 20 );
52
53               $set = Set::Infinite->new( [ 10, 20 ] );
54               # 10 <= x <= 20
55
56       set with a single, open span
57               $set = Set::Infinite->new(
58                   {
59                       a => 10, open_begin => 0,
60                       b => 20, open_end => 1,
61                   }
62               );
63               # 10 <= x < 20
64
65       set with multiple spans
66               $set = Set::Infinite->new( 10, 20,  100, 200 );
67
68               $set = Set::Infinite->new( [ 10, 20 ], [ 100, 200 ] );
69
70               $set = Set::Infinite->new(
71                   {
72                       a => 10, open_begin => 0,
73                       b => 20, open_end => 0,
74                   },
75                   {
76                       a => 100, open_begin => 0,
77                       b => 200, open_end => 0,
78                   }
79               );
80
81       The "new()" method expects ordered parameters.
82
83       If you have unordered ranges, you can build the set using "union":
84
85           @ranges = ( [ 10, 20 ], [ -10, 1 ] );
86           $set = Set::Infinite->new;
87           $set = $set->union( @$_ ) for @ranges;
88
89       The data structures passed to "new" must be immutable.  So this is not
90       good practice:
91
92           $set = Set::Infinite->new( $object_a, $object_b );
93           $object_a->set_value( 10 );
94
95       This is the recommended way to do it:
96
97           $set = Set::Infinite->new( $object_a->clone, $object_b->clone );
98           $object_a->set_value( 10 );
99
100       clone / copy
101
102       Creates a new object, and copy the object data.
103
104       empty_set
105
106       Creates an empty set.
107
108       If called from an existing set, the empty set inherits the "type" and
109       "density" characteristics.
110
111       universal_set
112
113       Creates a set containing "all" possible elements.
114
115       If called from an existing set, the universal set inherits the "type"
116       and "density" characteristics.
117

SET FUNCTIONS

119       union
120
121           $set = $set->union($b);
122
123       Returns the set of all elements from both sets.
124
125       This function behaves like an "OR" operation.
126
127           $set1 = new Set::Infinite( [ 1, 4 ], [ 8, 12 ] );
128           $set2 = new Set::Infinite( [ 7, 20 ] );
129           print $set1->union( $set2 );
130           # output: [1..4],[7..20]
131
132       intersection
133
134           $set = $set->intersection($b);
135
136       Returns the set of elements common to both sets.
137
138       This function behaves like an "AND" operation.
139
140           $set1 = new Set::Infinite( [ 1, 4 ], [ 8, 12 ] );
141           $set2 = new Set::Infinite( [ 7, 20 ] );
142           print $set1->intersection( $set2 );
143           # output: [8..12]
144
145       complement
146
147       minus
148
149       difference
150
151           $set = $set->complement;
152
153       Returns the set of all elements that don't belong to the set.
154
155           $set1 = new Set::Infinite( [ 1, 4 ], [ 8, 12 ] );
156           print $set1->complement;
157           # output: (-inf..1),(4..8),(12..inf)
158
159       The complement function might take a parameter:
160
161           $set = $set->minus($b);
162
163       Returns the set-difference, that is, the elements that don't belong to
164       the given set.
165
166           $set1 = new Set::Infinite( [ 1, 4 ], [ 8, 12 ] );
167           $set2 = new Set::Infinite( [ 7, 20 ] );
168           print $set1->minus( $set2 );
169           # output: [1..4]
170
171       simmetric_difference
172
173       Returns a set containing elements that are in either set, but not in
174       both. This is the "set" version of "XOR".
175

DENSITY METHODS

177       real
178
179           $set1 = $set->real;
180
181       Returns a set with density "0".
182
183       integer
184
185           $set1 = $set->integer;
186
187       Returns a set with density "1".
188

LOGIC FUNCTIONS

190       intersects
191
192           $logic = $set->intersects($b);
193
194       contains
195
196           $logic = $set->contains($b);
197
198       is_empty
199
200       is_null
201
202           $logic = $set->is_null;
203
204       is_nonempty
205
206       This set that has at least 1 element.
207
208       is_span
209
210       This set that has a single span or interval.
211
212       is_singleton
213
214       This set that has a single element.
215
216       is_subset( $set )
217
218       Every element of this set is a member of the given set.
219
220       is_proper_subset( $set )
221
222       Every element of this set is a member of the given set.  Some members
223       of the given set are not elements of this set.
224
225       is_disjoint( $set )
226
227       The given set has no elements in common with this set.
228
229       is_too_complex
230
231       Sometimes a set might be too complex to enumerate or print.
232
233       This happens with sets that represent infinite recurrences, such as
234       when you ask for a quantization on a set bounded by -inf or inf.
235
236       See also: "count" method.
237

SCALAR FUNCTIONS

239       min
240
241           $i = $set->min;
242
243       max
244
245           $i = $set->max;
246
247       size
248
249           $i = $set->size;
250
251       count
252
253           $i = $set->count;
254

OVERLOADED OPERATORS

256       stringification
257
258           print $set;
259
260           $str = "$set";
261
262       See also: "as_string".
263
264       comparison
265
266           sort
267
268           > < == >= <= <=>
269
270       See also: "spaceship" method.
271

CLASS METHODS

273           Set::Infinite->separators(@i)
274
275               chooses the interval separators for stringification.
276
277               default are [ ] ( ) '..' ','.
278
279           inf
280
281               returns an 'Infinity' number.
282
283           minus_inf
284
285               returns '-Infinity' number.
286
287       type
288
289           type( "My::Class::Name" )
290
291       Chooses a default object data type.
292
293       Default is none (a normal Perl SCALAR).
294

SPECIAL SET FUNCTIONS

296       span
297
298           $set1 = $set->span;
299
300       Returns the set span.
301
302       until
303
304       Extends a set until another:
305
306           0,5,7 -> until 2,6,10
307
308       gives
309
310           [0..2), [5..6), [7..10)
311
312       start_set
313
314       end_set
315
316       These methods do the inverse of the "until" method.
317
318       Given:
319
320           [0..2), [5..6), [7..10)
321
322       start_set is:
323
324           0,5,7
325
326       end_set is:
327
328           2,6,10
329
330       intersected_spans
331
332           $set = $set1->intersected_spans( $set2 );
333
334       The method returns a new set, containing all spans that are intersected
335       by the given set.
336
337       Unlike the "intersection" method, the spans are not modified.  See dia‐
338       gram below:
339
340                      set1   [....]   [....]   [....]   [....]
341                      set2      [................]
342
343              intersection      [.]   [....]   [.]
344
345         intersected_spans   [....]   [....]   [....]
346
347       quantize
348
349           quantize( parameters )
350
351               Makes equal-sized subsets.
352
353               Returns an ordered set of equal-sized subsets.
354
355               Example:
356
357                   $set = Set::Infinite->new([1,3]);
358                   print join (" ", $set->quantize( quant => 1 ) );
359
360               Gives:
361
362                   [1..2) [2..3) [3..4)
363
364       select
365
366           select( parameters )
367
368       Selects set spans based on their ordered positions
369
370       "select" has a behaviour similar to an array "slice".
371
372                   by       - default=All
373                   count    - default=Infinity
374
375        0  1  2  3  4  5  6  7  8      # original set
376        0  1  2                        # count => 3
377           1              6            # by => [ -2, 1 ]
378
379       offset
380
381           offset ( parameters )
382
383       Offsets the subsets. Parameters:
384
385           value   - default=[0,0]
386           mode    - default='offset'. Possible values are: 'offset', 'begin', 'end'.
387           unit    - type of value. Can be 'days', 'weeks', 'hours', 'minutes', 'seconds'.
388
389       iterate
390
391           iterate ( sub { } , @args )
392
393       Iterates on the set spans, over a callback subroutine.  Returns the
394       union of all partial results.
395
396       The callback argument $_[0] is a span. If there are additional argu‐
397       ments they are passed to the callback.
398
399       The callback can return a span, a hashref (see "Set::Infinite::Basic"),
400       a scalar, an object, or "undef".
401
402       [EXPERIMENTAL] "iterate" accepts an optional "backtrack_callback" argu‐
403       ment.  The purpose of the "backtrack_callback" is to reverse the iter‐
404       ate() function, overcoming the limitations of the internal backtracking
405       algorithm.  The syntax is:
406
407           iterate ( sub { } , backtrack_callback => sub { }, @args )
408
409       The "backtrack_callback" can return a span, a hashref, a scalar, an
410       object, or "undef".
411
412       For example, the following snippet adds a constant to each element of
413       an unbounded set:
414
415           $set1 = $set->iterate(
416                        sub { $_[0]->min + 54, $_[0]->max + 54 },
417                     backtrack_callback =>
418                        sub { $_[0]->min - 54, $_[0]->max - 54 },
419                     );
420
421       first / last
422
423           first / last
424
425       In scalar context returns the first or last interval of a set.
426
427       In list context returns the first or last interval of a set, and the
428       remaining set (the 'tail').
429
430       See also: "min", "max", "min_a", "max_a" methods.
431
432       type
433
434           type( "My::Class::Name" )
435
436       Chooses a default object data type.
437
438       default is none (a normal perl SCALAR).
439

INTERNAL FUNCTIONS

441       _backtrack
442
443           $set->_backtrack( 'intersection', $b );
444
445       Internal function to evaluate recurrences.
446
447       numeric
448
449           $set->numeric;
450
451       Internal function to ignore the set "type".  It is used in some inter‐
452       nal optimizations, when it is possible to use scalar values instead of
453       objects.
454
455       fixtype
456
457           $set->fixtype;
458
459       Internal function to fix the result of operations that use the
460       numeric() function.
461
462       tolerance
463
464           $set = $set->tolerance(0)    # defaults to real sets (default)
465           $set = $set->tolerance(1)    # defaults to integer sets
466
467       Internal function for changing the set "density".
468
469       min_a
470
471           ($min, $min_is_open) = $set->min_a;
472
473       max_a
474
475           ($max, $max_is_open) = $set->max_a;
476
477       as_string
478
479       Implements the "stringification" operator.
480
481       Stringification of unbounded recurrences is not implemented.
482
483       Unbounded recurrences are stringified as "function descriptions", if
484       the class variable $PRETTY_PRINT is set.
485
486       spaceship
487
488       Implements the "comparison" operator.
489
490       Comparison of unbounded recurrences is not implemented.
491

CAVEATS

493       * constructor "span" notation
494               $set = Set::Infinite->new(10,1);
495
496           Will be interpreted as [1..10]
497
498       * constructor "multiple-span" notation
499               $set = Set::Infinite->new(1,2,3,4);
500
501           Will be interpreted as [1..2],[3..4] instead of [1,2,3,4].  You
502           probably want ->new([1],[2],[3],[4]) instead, or maybe ->new(1,4)
503
504       * "range operator"
505               $set = Set::Infinite->new(1..3);
506
507           Will be interpreted as [1..2],3 instead of [1,2,3].  You probably
508           want ->new(1,3) instead.
509

INTERNALS

511       The base set object, without recurrences, is a "Set::Infinite::Basic".
512
513       A recurrence-set is represented by a method name, one or two parent
514       objects, and extra arguments.  The "list" key is set to an empty array,
515       and the "too_complex" key is set to 1.
516
517       This is a structure that holds the union of two "complex sets":
518
519         {
520           too_complex => 1,             # "this is a recurrence"
521           list   => [ ],                # not used
522           method => 'union',            # function name
523           parent => [ $set1, $set2 ],   # "leaves" in the syntax-tree
524           param  => [ ]                 # optional arguments for the function
525         }
526
527       This is a structure that holds the complement of a "complex set":
528
529         {
530           too_complex => 1,             # "this is a recurrence"
531           list   => [ ],                # not used
532           method => 'complement',       # function name
533           parent => $set,               # "leaf" in the syntax-tree
534           param  => [ ]                 # optional arguments for the function
535         }
536

SEE ALSO

538       See modules DateTime::Set, DateTime::Event::Recurrence, Date‐
539       Time::Event::ICal, DateTime::Event::Cron for up-to-date information on
540       date-sets.
541
542       The perl-date-time project <http://datetime.perl.org>
543

AUTHOR

545       Flavio Soibelmann Glock <fglock@pucrs.br>
546
548       Copyright (c) 2003 Flavio Soibelmann Glock.  All rights reserved.  This
549       program is free software; you can redistribute it and/or modify it
550       under the same terms as Perl itself.
551
552       The full text of the license can be found in the LICENSE file included
553       with this module.
554
555
556
557perl v5.8.8                       2004-11-03                  Set::Infinite(3)
Impressum