Set of real numbers: Difference between revisions

→‎{{header|Perl 6}}: Update syntax to work with present compiler.
(→‎{{header|Perl 6}}: Mark as broken)
(→‎{{header|Perl 6}}: Update syntax to work with present compiler.)
Line 1,198:
 
=={{header|Perl 6}}==
{{works with|Rakudo|2018.04}}
{{broken|Perl 6}}
<lang perl6>class Iv {
has $.range handles <min max excludes_minexcludes-min excludes_maxexcludes-max minmax ACCEPTS>;
method empty {
$.min after $.max or $.min === $.max && ($.excludes_minexcludes-min || $.excludes_maxexcludes-max)
}
multi method Bool() { not self.empty };
method length() { $.max - $.min }
method gist() {
($.excludes_minexcludes-min ?? '(' !! '[') ~
$.min ~ ',' ~ $.max ~
($.excludes_maxexcludes-max ?? ')' !! ']');
}
}
Line 1,223:
method new(@ranges) {
my @iv = canon @ranges.map: { Iv.new(:range($_)) }
self.bless(*, :intervals(@iv));
}
 
Line 1,242:
while @old {
my $old = @old.shift;
my $excludes_minexcludes-min = !$pre.excludes_maxexcludes-max;
my $excludes_maxexcludes-max = !$old.excludes_minexcludes-min;
push @new, $(Range.new($pre.max,$old.min,:$excludes_minexcludes-min,:$excludes_maxexcludes-max));
$pre = $old;
}
Line 1,266:
my $min = $a.range.min max $b.range.min;
my $max = $a.range.max min $b.range.max;
my $excludes_minexcludes-min = not $min ~~ $a & $b;
my $excludes_maxexcludes-max = not $max ~~ $a & $b;
Iv.new(:range(Range.new($min,$max,:$excludes_minexcludes-min, :$excludes_maxexcludes-max)));
}
}
Line 1,274:
my $min = $a.range.min min $b.range.min;
my $max = $a.range.max max $b.range.max;
my $excludes_minexcludes-min = not $min ~~ $a | $b;
my $excludes_maxexcludes-max = not $max ~~ $a | $b;
Iv.new(:range(Range.new($min,$max,:$excludes_minexcludes-min, :$excludes_maxexcludes-max)));
}
 
Line 1,286:
my $min = $a.range.min max $b.range.min;
my $max = $a.range.max min $b.range.max;
my $excludes_minexcludes-min = not $min ~~ $a & $b;
my $excludes_maxexcludes-max = not $max ~~ $a & $b;
push @overlap, $(Range.new($min,$max,:$excludes_minexcludes-min, :$excludes_maxexcludes-max));
}
}
Line 1,322:
 
say "\t\t\t\t0\t1\t2";
say "(0, 1] ∪ [0, 2) -> $s1.gist()\t", 0 ~~ $s1,"\t", 1 ~~ $s1,"\t", 2 ~~ $s1;
say "[0, 2) ∩ (1, 2] -> $s2.gist()\t", 0 ~~ $s2,"\t", 1 ~~ $s2,"\t", 2 ~~ $s2;
say "[0, 3) − (0, 1) -> $s3.gist()\t", 0 ~~ $s3,"\t", 1 ~~ $s3,"\t", 2 ~~ $s3;
say "[0, 3) − [0, 1] -> $s4.gist()\t", 0 ~~ $s4,"\t", 1 ~~ $s4,"\t", 2 ~~ $s4;
 
say '';
Line 1,332:
say "[0,3] − ℝ is empty: ", not iv(0..3) − ℝ;
 
my $A = iv(0..10)
[∪] iv |(0..10).map: ({ iv $_ - 1/6 .. $_ + 1/6 }).cache;
[∪] (0..10).map: { iv $_ - 1/6 .. $_ + 1/6 }
 
my $B = iv 0..sqrt(1/6),
10,333

edits