Class: P1788::Interval

Inherits:
Object
  • Object
show all
Defined in:
ext/p1788/p1788.cc,
ext/p1788/p1788.cc

Overview

The set of mathematical intervals implemented by the Interval class is denoted 𝕀ℝ. It comprises those subsets [𝒙] of the real line ℝ that are closed and connected in the topological sense: that is, the empty set (βˆ…) together with all the nonempty intervals, denoted [𝒙, 𝒙], defined by

[𝒙, 𝒙] = { π‘₯ ∈ ℝ | 𝒙 ≀ π‘₯ ≀ 𝒙 },

where 𝒙 = inf([𝒙]) ∈ ℝ βˆͺ {-∞} and 𝒙 = sup([𝒙]) ∈ ℝ βˆͺ {+∞} are extended-real numbers satisfying 𝒙 ≀ 𝒙, 𝒙 < +∞ and 𝒙 > -∞.

Set operation methods

#& #| #bisect #overlapping_state #inflate

Boolean methods

#empty? #entire? #all_reals? #pos_reals? #neg_reals? #positive? #strictly_positive? #negative? #strictly_negative? #common? #bounded? #symmetric? #singleton? #eql? #== #less? #greater? #strictly_less? #strictly_greater? #precedes? #succeeds? #strictly_precedes? #strictly_succeeds? #disjoint_from? #intersect? #overlap? #subset_of? #strict_subset_of? #superset_of? #strict_superset_of? #interior_subset_of? #contain_interior_of? #include? #bisectable? #inclusion_test

Numeric methods

#inf #sup #midpoint #splitpoint #radius #mid_rad #width #magnitude #mignitude

Forward elementary function methods

#+@ #-@ #+ #- <em> #/ </em>* #pow #pown #recip #abs #sqr #sqrt #exp #exp2 #exp10 #log #log2 #log10 #sin #cos #tan #asin #acos #atan #sinh #cosh #tanh #asinh #acosh #atanh #sign #ceil #floor #floorceil #truncate #round_ties_to_even #round_ties_to_away #min #max #div_to_pair #cancel_plus #cancel_minus #fma

Reverse elementary functions methods

#mul_rev_to_pair #mul_rev #sqr_rev #abs_rev #pown_rev #pow_rev1 #pow_rev2 #sin_rev #cos_rev #tan_rev #cosh_rev

Ruby object methods

#inspect #coerce #=== #to_s #to_a #to_latex #dup #clone #hash

Constant Summary collapse

EMPTY_SET =

βˆ…

empty_set
ALL_REALS =

[-∞, ∞]

all_reals
POS_REALS =

[0, ∞]

pos_reals
NEG_REALS =

[-∞, 0]

neg_reals
PI =

[↓𝛑↓, ↑𝛑↑]

pi
HALF_PI =

[↓𝛑/2↓, ↑𝛑/2↑]

hpi
TWO_PI =

[↓2𝛑↓, ↑2𝛑↑]

pi2
MINUS_PI_PI =

[↓-𝛑↓, ↑𝛑↑]

minus_pi_pi
MINUS_HPI_HPI =

[↓-𝛑/2↓, ↑𝛑/2↑]

minus_hpi_hpi
MINUS_ONE_ONE =

[-1, 1]

minus_one_one
E =

[↓𝑒↓, ↑𝑒↑]

e

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#newInterval #new(numeric) ⇒ Interval #new(lower, upper) ⇒ Interval #new(range) ⇒ Interval #new(array) ⇒ Interval #new(str) ⇒ Interval #new(other_interval) ⇒ Interval

Create a new P1788::Interval

Overloads:

  • #newInterval

    Return a new interval [-∞, +∞]

  • #new(numeric) ⇒ Interval

    Return a singleton interval in case of Float or Integer, or a classic interval if the Rational cannot exactly be expressed as a Float.

    Parameters:

    • numeric (Float, Integer, Rational)
  • #new(lower, upper) ⇒ Interval

    Parameters:

    • lower (Float, Integer, Rational)

      lower bound

    • upper (Float, Integer, Rational)

      upper bound

  • #new(range) ⇒ Interval

    Parameters:

    • range (Range<Float, Integer, Rational>)
  • #new(array) ⇒ Interval

    Parameters:

    • array (Array<Float, Integer, Rational>)

      an array containing at most 2 elements

  • #new(str) ⇒ Interval

    Parameters:

    • str (String)

      something like '[0.1, 1/10]' or "[0.1]" or "[1/10]"

  • #new(other_interval) ⇒ Interval

    Parameters:

See Also:



408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
# File 'ext/p1788/p1788.cc', line 408

static VALUE p1788_interval_initialize(int argc, VALUE *argv, VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	double lower, upper;
	VALUE beg, end, a1, a2;
	int i, arlen;

	switch (rb_scan_args(argc, argv, "02", &a1, &a2)) {
		case 0:
			break;
		case 1:
			if (rb_obj_is_kind_of(a1, rb_cNumeric))
				inter = p1788_rbnumeric2interval(a1);
			else if (rb_obj_is_kind_of(a1, rb_cString))
				inter = Interval(std::string(StringValueCStr(a1)));
			else if (rb_obj_is_kind_of(a1, rb_cRange)) {
				rb_range_values(a1, &beg, &end, &i);
				lower = Interval::inf(p1788_rbnumeric2interval(beg));
				upper = Interval::sup(p1788_rbnumeric2interval(end));
				inter = Interval(lower, upper);
			}
			else if (rb_obj_is_kind_of(a1, rb_cArray)) {
				arlen = rb_array_len(a1);
				if (arlen == 0)
					inter = Interval();
				else if (arlen == 1)
					inter = p1788_rbnumeric2interval(rb_ary_entry(a1, 0));
				else if (arlen == 2) {
					lower = Interval::inf(p1788_rbnumeric2interval(rb_ary_entry(a1, 0)));
					upper = Interval::sup(p1788_rbnumeric2interval(rb_ary_entry(a1, 1)));
					inter = Interval(lower, upper);
				}
				else
					rb_raise(rb_eArgError, "the array must have 0, 1 or 2 elements, not %d", arlen);
			}
			else if (rb_obj_is_kind_of(a1, c_Interval)) {
				inter = Interval(p1788_interval_rb2ref(a1));
			}
			else
				rb_raise(rb_eArgError, "expecting Float, Integer, Rational, String, Range, Array or Interval, not %" PRIsVALUE, rb_class_name(rb_class_of(a1)));
			break;
		case 2:
			if (rb_obj_is_kind_of(a1, rb_cNumeric) && rb_obj_is_kind_of(a2, rb_cNumeric)) {
				lower = Interval::inf(p1788_rbnumeric2interval(a1));
				upper = Interval::sup(p1788_rbnumeric2interval(a2));
				inter = Interval(lower, upper);
			}
			else
				rb_raise(rb_eArgError, "expecting two Numerics, or a [Numeric, Range or Array]");
			break;
		default:
			rb_raise(rb_eArgError, "expecting 0 to 2 arguments, not %d", argc);
	}

	return self;
}

Class Method Details

.[](*args) ⇒ Interval

Create a new P1788::Interval

Examples:

P1788::Interval[]              #=> #<P1788::Interval ℝ>
P1788::Interval[0.7]           #=> #<P1788::Interval {0.7}>
P1788::Interval[1, 2.3]        #=> #<P1788::Interval [1, 2.3]>
P1788::Interval[-3.4 .. 5.6]   #=> #<P1788::Interval [-3.4, 5.6]>
a = [7, 8]
P1788::Interval[a]             #=> #<P1788::Interval [7, 8]>
P1788::Interval['[-4.9]']      #=> #<P1788::Interval [-4.9, -4.8999999999999995]>
P1788::Interval['[1/10, Inf]'] #=> #<P1788::Interval [0.09999999999999999, +∞]>
P1788::Interval[0, Float::INFINITY] #=> #<P1788::Interval β„β‚Š>
P1788::Interval[Float::NAN]    #=> #<P1788::Interval βˆ…>

See Also:



481
482
483
484
# File 'ext/p1788/p1788.cc', line 481

static VALUE p1788_interval_rb_new(int argc, VALUE *argv, VALUE self)
{
	return rb_class_new_instance(argc, argv, c_Interval);
}

Instance Method Details

#*(y) ⇒ Interval

Arithmetic multiplication

[𝒔𝒆𝒍𝒇]*[π’š]Β Β =Β Β hull{ π‘₯⋅𝑦 | π‘₯ ∈ [𝒔𝒆𝒍𝒇], 𝑦 ∈ [π’š] }Β Β βŠ†Β Β β„

Reverse function: #mul_rev



2112
2113
2114
2115
# File 'ext/p1788/p1788.cc', line 2112

static VALUE p1788_interval_mul(VALUE self, VALUE y)
{
	P1788_INTERVAL_BINARY_OP(self, y, mul);
}

#**(exponent) ⇒ Interval

Power operator

If exponent is an integer, calls #pown, else call #pow.

Parameters:



2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
# File 'ext/p1788/p1788.cc', line 2195

static VALUE p1788_interval_powop(VALUE self, VALUE exponent)
{
	VALUE r;
	int p;
	double d;
	if (rb_obj_is_kind_of(exponent, rb_cInteger)) {
		p = NUM2INT(exponent);
		if (p == 2)
			P1788_NEW_RB_INTERVAL(r, Interval::sqr(p1788_interval_rb2ref(self)));
		else
			P1788_NEW_RB_INTERVAL(r, Interval::pown(p1788_interval_rb2ref(self), p));
	}
	else if (rb_obj_is_kind_of(exponent, rb_cNumeric)) {
		d = NUM2DBL(exponent);
		p = NUM2INT(exponent);
		if (d >= 0.0 && d == (double)p) {
			if (p == 2)
				P1788_NEW_RB_INTERVAL(r, Interval::sqr(p1788_interval_rb2ref(self)));
			else
				P1788_NEW_RB_INTERVAL(r, Interval::pown(p1788_interval_rb2ref(self), p));
		}
		else
			P1788_NEW_RB_INTERVAL(r, Interval::pow(p1788_interval_rb2ref(self), Interval(d, d)));
	}
	else if (is_an_interval_vector(exponent)) {
		const Interval &inter = p1788_interval_rb2ref(self);
		const IntervalVector &v = p1788_vector_rb2ref(exponent);
		const int l = v.size();
		IntervalVector *t = new IntervalVector(l);
		for (int i = 0; i < l; i++)
			(*t)[i] = Interval::pow(inter, v[i]);
		return p1788_vector_alloc_from_pointer(t);
	}
	else {
		P1788_NEW_RB_INTERVAL(r, Interval::pow(p1788_interval_rb2ref(self), p1788_rbobj2interval(exponent)));
	}
	return r;
}

#+(interval) ⇒ Interval #+(vector) ⇒ IntervalVector

Arithmetic addition

[𝒔𝒆𝒍𝒇] + [π’š]Β Β =Β Β hull{ π‘₯ + 𝑦 | π‘₯ ∈ [𝒔𝒆𝒍𝒇], 𝑦 ∈ [π’š] }Β Β βŠ†Β Β β„

Reverse function: #-

Overloads:



2088
2089
2090
2091
# File 'ext/p1788/p1788.cc', line 2088

static VALUE p1788_interval_add(VALUE self, VALUE y)
{
	P1788_INTERVAL_BINARY_OP(self, y, add);
}

#+@Interval

Returns self.

Returns:



1623
1624
1625
1626
1627
1628
# File 'ext/p1788/p1788.cc', line 1623

static VALUE p1788_interval_pos(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::pos(p1788_interval_rb2ref(self)));
	return r;
}

#-(y) ⇒ Interval

Arithmetic subtraction

[𝒔𝒆𝒍𝒇] - [π’š]Β Β =Β Β hull{ π‘₯ - 𝑦 | π‘₯ ∈ [𝒔𝒆𝒍𝒇], 𝑦 ∈ [π’š] }Β Β βŠ†Β Β β„

Reverse function: #+



2100
2101
2102
2103
# File 'ext/p1788/p1788.cc', line 2100

static VALUE p1788_interval_sub(VALUE self, VALUE y)
{
	P1788_INTERVAL_BINARY_OP(self, y, sub);
}

#-@Interval

Opposite

[𝒔𝒆𝒍𝒇].negΒ Β =Β Β [-𝒔𝒆𝒍𝒇, -𝒔𝒆𝒍𝒇]



1635
1636
1637
1638
1639
1640
# File 'ext/p1788/p1788.cc', line 1635

static VALUE p1788_interval_neg(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::neg(p1788_interval_rb2ref(self)));
	return r;
}

#/(y) ⇒ Interval

Arithmetic division

[𝒔𝒆𝒍𝒇] / [π’š]Β Β =Β Β hull{ π‘₯/𝑦 | π‘₯ ∈ [𝒔𝒆𝒍𝒇], 𝑦 ∈ [π’š] }Β Β βŠ†Β Β β„

Reverse function: #*



2124
2125
2126
2127
# File 'ext/p1788/p1788.cc', line 2124

static VALUE p1788_interval_div(VALUE self, VALUE y)
{
	P1788_INTERVAL_BINARY_OP(self, y, div);
}

#==(y) ⇒ Boolean

self = y

(βˆ€ π‘₯ ∈ [𝒔𝒆𝒍𝒇], βˆƒ 𝑦 ∈ [π’š], π‘₯ = 𝑦) ∧ (βˆ€ 𝑦 ∈ [π’š], βˆƒ π‘₯ ∈ [𝒔𝒆𝒍𝒇], 𝑦 = π‘₯)

true if ([𝒔𝒆𝒍𝒇] = βˆ… ∧ [π’š] = βˆ…) ∨ ([𝒔𝒆𝒍𝒇] β‰  βˆ… ∧ [π’š] β‰  βˆ… ∧ 𝒔𝒆𝒍𝒇 = π’š ∧ 𝒔𝒆𝒍𝒇 = π’š)
false otherwise

Returns:

  • (Boolean)


936
937
938
939
940
941
# File 'ext/p1788/p1788.cc', line 936

static VALUE p1788_interval_equal(VALUE self, VALUE y)
{
	Interval iother = p1788_rbobj2interval(y);
	Interval &inter = p1788_interval_rb2ref(self);
	return Interval::equal(inter, iother) ? Qtrue : Qfalse;
}

#===(obj) ⇒ Boolean

Case subsumption operator.

Used to write case expressions with intervals.

Returns true if obj can be converted to a P1788::Interval and obj is contained in self, false otherwise.

Returns:

  • (Boolean)


964
965
966
967
968
969
970
971
972
# File 'ext/p1788/p1788.cc', line 964

static VALUE p1788_interval_tripleequal(VALUE self, VALUE obj)
{
	VALUE other = rb_rescue(p1788_casesubsumption_func, obj, p1788_casesubsumption_rescue, Qnil);
	if (other == Qnil)
		return Qfalse;
	Interval &a = p1788_interval_rb2ref(self);
	Interval &b = p1788_interval_rb2ref(other);
	return Interval::subset(b, a) ? Qtrue : Qfalse;
}

#absInterval

Absolute value

[𝒔𝒆𝒍𝒇].absΒ Β =Β Β hull{ |π‘₯| οΏ¨ π‘₯ ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„β‚Š

Reverse function: #abs_rev



2032
2033
2034
2035
2036
2037
# File 'ext/p1788/p1788.cc', line 2032

static VALUE p1788_interval_abs(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::abs(p1788_interval_rb2ref(self)));
	return r;
}

#abs_rev(x = ALL_REALS) ⇒ Interval

Reverse absolute value.

abs_rev([𝒙])Β Β =Β Β hull{ π‘₯ ∈ [𝒙] οΏ¨ |π‘₯| ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„

Reverse function: #abs



2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
# File 'ext/p1788/p1788.cc', line 2373

static VALUE p1788_interval_abs_rev(int argc, VALUE *argv, VALUE self)
{
	VALUE x, r;
	rb_scan_args(argc, argv, "01", &x);
	if (x == Qnil) {
		P1788_NEW_RB_INTERVAL(r, Interval::abs_rev(p1788_interval_rb2ref(self)));
	}
	else {
		P1788_NEW_RB_INTERVAL(r, Interval::abs_rev(p1788_interval_rb2ref(self), p1788_rbobj2interval(x)));
	}
	return r;
}

#acosInterval

Arc cosine

[𝒔𝒆𝒍𝒇].acosΒ Β =Β Β hull{ acos(π‘₯) | π‘₯ ∈ [𝒔𝒆𝒍𝒇]∩[-1, 1] }Β Β βŠ†Β Β [0, 𝛑]

Reverse function: #cos



1831
1832
1833
1834
1835
1836
# File 'ext/p1788/p1788.cc', line 1831

static VALUE p1788_interval_acos(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::acos(p1788_interval_rb2ref(self)));
	return r;
}

#acoshInterval

Inverse hyperbolic cosine

[𝒔𝒆𝒍𝒇].acoshΒ Β =Β Β hull{ acosh(π‘₯) | π‘₯ ∈ [𝒔𝒆𝒍𝒇]∩[1,+∞] }Β Β βŠ†Β Β β„β‚Š

Reverse function: #cosh



1915
1916
1917
1918
1919
1920
# File 'ext/p1788/p1788.cc', line 1915

static VALUE p1788_interval_acosh(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::acosh(p1788_interval_rb2ref(self)));
	return r;
}

#asinInterval

Arc sine

[𝒔𝒆𝒍𝒇].asinΒ Β =Β Β hull{ asin(π‘₯) | π‘₯ ∈ [𝒔𝒆𝒍𝒇]∩[-1, 1] }Β Β βŠ†Β Β [-𝛑/2, 𝛑/2]

Reverse function: #sin



1817
1818
1819
1820
1821
1822
# File 'ext/p1788/p1788.cc', line 1817

static VALUE p1788_interval_asin(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::asin(p1788_interval_rb2ref(self)));
	return r;
}

#asinhInterval

Inverse hyperbolic sine

[𝒔𝒆𝒍𝒇].asinhΒ Β =Β Β hull{ asinh(π‘₯) | π‘₯ ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„

Reverse function: #sinh



1901
1902
1903
1904
1905
1906
# File 'ext/p1788/p1788.cc', line 1901

static VALUE p1788_interval_asinh(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::asinh(p1788_interval_rb2ref(self)));
	return r;
}

#atanInterval

Arc tangent

[𝒔𝒆𝒍𝒇].atanΒ Β =Β Β hull{ atan(π‘₯) | π‘₯ ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β [-𝛑/2, 𝛑/2]Β 

Reverse function: #tan



1845
1846
1847
1848
1849
1850
# File 'ext/p1788/p1788.cc', line 1845

static VALUE p1788_interval_atan(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::atan(p1788_interval_rb2ref(self)));
	return r;
}

#atanhInterval

Inverse hyperbolic tangent

[𝒔𝒆𝒍𝒇].atanhΒ Β =Β Β hull{ atanh(π‘₯) | π‘₯ ∈ [𝒔𝒆𝒍𝒇]∩[-1,1] }Β Β βŠ†Β Β β„

Reverse function: #tanh



1929
1930
1931
1932
1933
1934
# File 'ext/p1788/p1788.cc', line 1929

static VALUE p1788_interval_atanh(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::atanh(p1788_interval_rb2ref(self)));
	return r;
}

#bisect(ratio = 0.5) ⇒ Array[Interval] Also known as: split

Split self into two intervals, according to ratio. Raise an exception if self cannot be bisected into two nonempty non-singleton intervals (see #bisectable?).

Parameters:

  • ratio (Float) (defaults to: 0.5)

    tell where to split the interval, 0 < ratio < 1

Returns:

  • (Array[Interval])

    An Array of two intervals

See Also:



1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
# File 'ext/p1788/p1788.cc', line 1498

static VALUE p1788_interval_bisect(int argc, VALUE *argv, VALUE self)
{
	if (argc > 1)
		rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 0..1)", argc);
	VALUE r1, r2;
	const Interval &inter = p1788_interval_rb2ref(self);
	const double l = Interval::inf(inter);
	const double m = Interval::mid(inter);
	const double u = Interval::sup(inter);
	if (Interval::is_empty(inter) || Interval::inf(inter) >= m || m >= Interval::sup(inter)) {
		rb_raise(rb_eRuntimeError, "%" PRIsVALUE " cannot be bisected in two nonempty non-singleton intervals",
				p1788_interval_inspect(self));
	}
	if (argc < 1 || l == -INF || u == INF) {
		P1788_NEW_RB_INTERVAL(r1, Interval(l, m));
		P1788_NEW_RB_INTERVAL(r2, Interval(m, u));
	}
	else {
		double r = NUM2DBL(argv[0]);
		if (r <= 0.0 || r >= 1.0)
			rb_raise(rb_eRuntimeError, "the given bisection ratio must be > 0 and < 1");
		double p;
		if (r == 0.5)
			p = m;
		else {
			p = l+r*Interval::wid(inter);
			if (p >= u)
				p = std::nextafter(l, INF);
			if (p >= u)
				rb_raise(rb_eRuntimeError, "%" PRIsVALUE " cannot be bisected in two nonempty non-singleton intervals",
						p1788_interval_inspect(self));
		}
		P1788_NEW_RB_INTERVAL(r1, Interval(l, p));
		P1788_NEW_RB_INTERVAL(r2, Interval(p, u));
	}
	return rb_ary_new_from_args(2, r1, r2);
}

#bisectable?Boolean

Tells if self can be bisected. An interval is bisectable if it can be bisected into two nonempty non-singleton intervals. Example of non bisectable intervals are [3.0, 3.0.next_float] and [Float::MAX, +∞].

Returns:

  • (Boolean)


1306
1307
1308
1309
# File 'ext/p1788/p1788.cc', line 1306

static VALUE p1788_interval_bisectable(VALUE self)
{
	return p1788_interval_is_bisectable(p1788_interval_rb2ref(self)) ? Qtrue : Qfalse;
}

#bounded?Boolean

Note:

An empty interval is always bounded

self is empty or a bounded interval

Returns:

  • (Boolean)

See Also:

  • common


878
879
880
881
882
# File 'ext/p1788/p1788.cc', line 878

static VALUE p1788_interval_bounded(VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	return (Interval::is_empty(inter) || Interval::is_common_interval(inter)) ? Qtrue : Qfalse;
}

#cancel_minus(y) ⇒ Interval

Cancellative subtraction

Cancellative subtraction solves the following problem: Recover interval [𝒛] from intervals [𝒔𝒆𝒍𝒇] and [π’š], given that [𝒔𝒆𝒍𝒇] = [π’š] + [𝒛].

For any two bounded intervals [𝒔𝒆𝒍𝒇] and [π’š], [𝒔𝒆𝒍𝒇].cancel_minus([π’š]) is the tightest interval [𝒛] such that [π’š] + [𝒛] βŠ‡ [𝒔𝒆𝒍𝒇].



2156
2157
2158
2159
# File 'ext/p1788/p1788.cc', line 2156

static VALUE p1788_interval_cancel_minus(VALUE self, VALUE y)
{
	P1788_INTERVAL_BINARY_OP(self, y, cancel_minus);
}

#cancel_plus(y) ⇒ Interval

Cancellative addition

self.cancel_plux([π’š]) = self.cancel_minus(-[π’š])

See Also:



2167
2168
2169
2170
# File 'ext/p1788/p1788.cc', line 2167

static VALUE p1788_interval_cancel_plus(VALUE self, VALUE y)
{
	P1788_INTERVAL_BINARY_OP(self, y, cancel_plus);
}

#ceilInterval

Round towards +∞

[𝒔𝒆𝒍𝒇].ceilΒ Β =Β Β [ceil(𝒔𝒆𝒍𝒇), ceil(𝒔𝒆𝒍𝒇)]



1953
1954
1955
1956
1957
1958
# File 'ext/p1788/p1788.cc', line 1953

static VALUE p1788_interval_ceil(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::ceil(p1788_interval_rb2ref(self)));
	return r;
}

#cloneInterval

Return a new P1788::Interval equal to self, also copying its singleton class.

Returns:



511
512
513
514
515
516
# File 'ext/p1788/p1788.cc', line 511

static VALUE p1788_interval_clone(VALUE self)
{
	VALUE c = rb_call_super(0, NULL);
	p1788_interval_rb2ref(c) = p1788_interval_rb2ref(self);
	return c;
}

#coerce(other) ⇒ Array<Interval>

The coerce method provides support for Ruby type coercion. This coercion mechanism is used by Ruby to handle mixed-type numeric operations: it is intended to find a compatible common type between the two operands of the operator.

Parameters:

  • other (Numeric)

Returns:

  • (Array<Interval>)

    [other.to_interval, self]



750
751
752
753
754
755
# File 'ext/p1788/p1788.cc', line 750

static VALUE p1788_interval_coerce(VALUE self, VALUE other)
{
	VALUE rbo;
	P1788_NEW_RB_INTERVAL(rbo, p1788_rbobj2interval(other));
	return rb_ary_new_from_args(2, rbo, self);
}

#common?Boolean

self is a bounded nonempty interval

Returns:

  • (Boolean)

See Also:



867
868
869
870
# File 'ext/p1788/p1788.cc', line 867

static VALUE p1788_interval_common(VALUE self)
{
	return Interval::is_common_interval(p1788_interval_rb2ref(self)) ? Qtrue : Qfalse;
}

#contain_interior_of?(y) ⇒ Boolean

y is in the interior of self

[𝒔𝒆𝒍𝒇] βͺΎ [π’š]

(βˆ€ 𝑦 ∈ [π’š], βˆƒ π‘₯ ∈ [𝒔𝒆𝒍𝒇] : 𝑦 < π‘₯) ∧ (βˆ€ 𝑦 ∈ [π’š], βˆƒ π‘₯ ∈ [𝒔𝒆𝒍𝒇] : 𝑦 > π‘₯)

true if [π’š] = βˆ… ∨ ([𝒔𝒆𝒍𝒇] β‰  βˆ… ∧ 𝒔𝒆𝒍𝒇 < π’š ∧ π’š < 𝒔𝒆𝒍𝒇)
false otherwise

Returns:

  • (Boolean)


1267
1268
1269
1270
1271
1272
# File 'ext/p1788/p1788.cc', line 1267

static VALUE p1788_interval_contains_interior(VALUE self, VALUE y)
{
	Interval &inter = p1788_interval_rb2ref(self);
	Interval iother = p1788_rbobj2interval(y);
	return Interval::contains_interior(inter, iother) ? Qtrue : Qfalse;
}

#convex_hull(y) ⇒ Interval Also known as: |

Interval hull of the union of self and y

[𝒔𝒆𝒍𝒇].convex_hull([π’š])Β Β =Β Β hull( [𝒔𝒆𝒍𝒇] βˆͺ [π’š] )



2070
2071
2072
2073
# File 'ext/p1788/p1788.cc', line 2070

static VALUE p1788_interval_convex_hull(VALUE self, VALUE y)
{
	P1788_INTERVAL_BINARY_OP(self, y, convex_hull);
}

#cosInterval

Cosine

[𝒔𝒆𝒍𝒇].cosΒ Β =Β Β hull{ cos(π‘₯) | π‘₯ ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β [-1, 1]

Reverse function: #cos_rev



1789
1790
1791
1792
1793
1794
# File 'ext/p1788/p1788.cc', line 1789

static VALUE p1788_interval_cos(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::cos(p1788_interval_rb2ref(self)));
	return r;
}

#cos_rev(x = ALL_REALS) ⇒ Interval

Reverse cosine

cos_rev([𝒙])Β Β =Β Β hull{ π‘₯ ∈ [𝒙] | cos(π‘₯) ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„

Reverse function: #cos



2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
# File 'ext/p1788/p1788.cc', line 2489

static VALUE p1788_interval_cos_rev(int argc, VALUE *argv, VALUE self)
{
	VALUE x, r;
	rb_scan_args(argc, argv, "01", &x);
	if (x == Qnil) {
		P1788_NEW_RB_INTERVAL(r, Interval::cos_rev(p1788_interval_rb2ref(self)));
	}
	else {
		P1788_NEW_RB_INTERVAL(r, Interval::cos_rev(p1788_interval_rb2ref(self), p1788_rbobj2interval(x)));
	}
	return r;
}

#coshInterval

Hyperbolic cosine

[𝒔𝒆𝒍𝒇].coshΒ Β =Β Β hull{ (𝑒π‘₯ + 𝑒-π‘₯) / 2 | π‘₯ ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β [1, +∞]

Reverse function: #cosh_rev



1873
1874
1875
1876
1877
1878
# File 'ext/p1788/p1788.cc', line 1873

static VALUE p1788_interval_cosh(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::cosh(p1788_interval_rb2ref(self)));
	return r;
}

#cosh_rev(x = ALL_REALS) ⇒ Interval

Reverse hyperbolic cosine

cosh_rev([𝒙])Β Β =Β Β hull{ π‘₯ ∈ [𝒙] | cosh(π‘₯) ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„

Reverse function: #cosh



2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
# File 'ext/p1788/p1788.cc', line 2531

static VALUE p1788_interval_cosh_rev(int argc, VALUE *argv, VALUE self)
{
	VALUE x, r;
	rb_scan_args(argc, argv, "01", &x);
	if (x == Qnil) {
		P1788_NEW_RB_INTERVAL(r, Interval::cosh_rev(p1788_interval_rb2ref(self)));
	}
	else {
		P1788_NEW_RB_INTERVAL(r, Interval::cosh_rev(p1788_interval_rb2ref(self), p1788_rbobj2interval(x)));
	}
	return r;
}

#disjoint_from?(y) ⇒ Boolean

[𝒔𝒆𝒍𝒇] ∩ [π’š] = βˆ…

βˆ€ π‘₯ ∈ [𝒔𝒆𝒍𝒇], βˆ€ 𝑦 ∈ [π’š], π‘₯ β‰  𝑦

true if [𝒔𝒆𝒍𝒇] = βˆ… ∨ [π’š] = βˆ… ∨ 𝒔𝒆𝒍𝒇 < π’š ∨ π’š < 𝒔𝒆𝒍𝒇
false otherwise

Returns:

  • (Boolean)

See Also:

  • intersect


1128
1129
1130
1131
1132
1133
# File 'ext/p1788/p1788.cc', line 1128

static VALUE p1788_interval_disjoint(VALUE self, VALUE y)
{
	Interval iother = p1788_rbobj2interval(y);
	Interval &inter = p1788_interval_rb2ref(self);
	return Interval::disjoint(inter, iother) ? Qtrue : Qfalse;
}

#div_to_pair(y) ⇒ Array<Interval>

Two-output division

Returns a pair of intervals, 𝒔𝒆𝒍𝒇 / (π’š ∩ ℝ₋) and 𝒔𝒆𝒍𝒇 / (π’š ∩ β„β‚Š)

Returns:

  • (Array<Interval>)

    [βˆ…, βˆ…] if 𝒔𝒆𝒍𝒇/π’š is empty, [[𝒔𝒆𝒍𝒇/π’š], βˆ…] if 𝒔𝒆𝒍𝒇/π’š has one component, [[𝒔𝒆𝒍𝒇/π’š]₁, [𝒔𝒆𝒍𝒇/π’š]β‚‚] if 𝒔𝒆𝒍𝒇/π’š has two components



2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
# File 'ext/p1788/p1788.cc', line 2178

static VALUE p1788_interval_div_to_pair(VALUE self, VALUE y)
{
	VALUE r1, r2;
	Interval iother = p1788_rbobj2interval(y);
	Interval &inter = p1788_interval_rb2ref(self);
	std::pair< Interval, Interval > p = Interval::mul_rev_to_pair(iother, inter);
	P1788_NEW_RB_INTERVAL(r1, p.first);
	P1788_NEW_RB_INTERVAL(r2, p.second);
	return rb_ary_new_from_args(2, r1, r2);
}

#dupInterval

Return a new P1788::Interval equal to self.

Returns:



502
503
504
505
# File 'ext/p1788/p1788.cc', line 502

static VALUE p1788_interval_dup(VALUE self)
{
	return rb_class_new_instance(1, &self, c_Interval);
}

#empty?Boolean

[𝒔𝒆𝒍𝒇] = βˆ… ?

Returns:

  • (Boolean)


764
765
766
767
# File 'ext/p1788/p1788.cc', line 764

static VALUE p1788_interval_empty(VALUE self)
{
	return Interval::is_empty(p1788_interval_rb2ref(self)) ? Qtrue : Qfalse;
}

#entire?Boolean Also known as: all_reals?

[𝒔𝒆𝒍𝒇] = ℝ ?

Returns:

  • (Boolean)


782
783
784
785
# File 'ext/p1788/p1788.cc', line 782

static VALUE p1788_interval_entire(VALUE self)
{
	return Interval::is_entire(p1788_interval_rb2ref(self)) ? Qtrue : Qfalse;
}

#eql?(y) ⇒ Boolean

self #== y and y is an P1788::Interval

Returns:

  • (Boolean)


920
921
922
923
924
925
# File 'ext/p1788/p1788.cc', line 920

static VALUE p1788_interval_eql(VALUE self, VALUE y)
{
	if (!rb_obj_is_kind_of(y, c_Interval))
		return Qfalse;
	return Interval::equal(p1788_interval_rb2ref(self), p1788_interval_rb2ref(y)) ? Qtrue : Qfalse;
}

#expInterval

e raised to the power of self

[𝒔𝒆𝒍𝒇].expΒ Β =Β Β hull{ 𝑒π‘₯ | π‘₯ ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„β‚Š

Reverse function: #log



1691
1692
1693
1694
1695
1696
# File 'ext/p1788/p1788.cc', line 1691

static VALUE p1788_interval_exp(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::exp(p1788_interval_rb2ref(self)));
	return r;
}

#exp10Interval

10 raised to the power of self

[𝒔𝒆𝒍𝒇].exp10Β Β =Β Β hull{ 10π‘₯ | π‘₯ ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„β‚Š

Reverse function: #log10



1719
1720
1721
1722
1723
1724
# File 'ext/p1788/p1788.cc', line 1719

static VALUE p1788_interval_exp10(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::exp10(p1788_interval_rb2ref(self)));
	return r;
}

#exp2Interval

2 raised to the power of self

[𝒔𝒆𝒍𝒇].exp2Β Β =Β Β hull{ 2π‘₯ | π‘₯ ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„β‚Š

Reverse function: #log2



1705
1706
1707
1708
1709
1710
# File 'ext/p1788/p1788.cc', line 1705

static VALUE p1788_interval_exp2(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::exp2(p1788_interval_rb2ref(self)));
	return r;
}

#floorInterval

Round towards -∞

[𝒔𝒆𝒍𝒇].floorΒ Β =Β Β [floor(𝒔𝒆𝒍𝒇), floor(𝒔𝒆𝒍𝒇)]



1965
1966
1967
1968
1969
1970
# File 'ext/p1788/p1788.cc', line 1965

static VALUE p1788_interval_floor(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::floor(p1788_interval_rb2ref(self)));
	return r;
}

#floorceilInterval

Inflate self towards nearest integer bounds

[𝒔𝒆𝒍𝒇].floorceilΒ Β =Β Β [floor(𝒔𝒆𝒍𝒇), ceil(𝒔𝒆𝒍𝒇)]



1977
1978
1979
1980
1981
1982
1983
# File 'ext/p1788/p1788.cc', line 1977

static VALUE p1788_interval_floorceil(VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval(std::floor(Interval::inf(inter)), std::ceil(Interval::sup(inter))));
	return r;
}

#fma(x, y) ⇒ Interval

Fused multiply add

fma([𝒙], [π’š])Β Β =Β Β hull{ π‘₯⋅𝑦 + 𝑧 | π‘₯ ∈ [𝒙], 𝑦 ∈ [π’š], 𝑧 ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„



2279
2280
2281
2282
2283
2284
2285
2286
2287
# File 'ext/p1788/p1788.cc', line 2279

static VALUE p1788_interval_fma(VALUE self, VALUE x, VALUE y)
{
	Interval ix = p1788_rbobj2interval(x);
	Interval iy = p1788_rbobj2interval(y);
	Interval &inter = p1788_interval_rb2ref(self);
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::fma(ix, iy, inter));
	return r;
}

#greater?(y) ⇒ Boolean

self is weakly greater than y

(βˆ€ π‘₯ ∈ [𝒔𝒆𝒍𝒇], βˆƒ 𝑦 ∈ [π’š], π‘₯ β‰₯ 𝑦) ∧ (βˆ€ 𝑦 ∈ [π’š], βˆƒ π‘₯ ∈ [𝒔𝒆𝒍𝒇], π‘₯ β‰₯ 𝑦)

true if ([𝒔𝒆𝒍𝒇] = βˆ… ∧ [π’š] = βˆ…) ∨ ([𝒔𝒆𝒍𝒇] β‰  βˆ… ∧ [π’š] β‰  βˆ… ∧ 𝒔𝒆𝒍𝒇 β‰₯ π’š ∧ 𝒔𝒆𝒍𝒇 β‰₯ π’š)
false otherwise

Returns:

  • (Boolean)


1015
1016
1017
1018
1019
1020
# File 'ext/p1788/p1788.cc', line 1015

static VALUE p1788_interval_greater(VALUE self, VALUE y)
{
	Interval iother = p1788_rbobj2interval(y);
	Interval &inter = p1788_interval_rb2ref(self);
	return Interval::greater(inter, iother) ? Qtrue : Qfalse;
}

#hashInteger

Returns:

  • (Integer)


977
978
979
980
981
982
983
984
985
986
987
988
# File 'ext/p1788/p1788.cc', line 977

static VALUE p1788_interval_hash(VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	st_index_t v, h[2];
	VALUE n;
	n = rb_hash(DBL2NUM(Interval::inf(inter)));
	h[0] = NUM2LONG(n);
	n = rb_hash(DBL2NUM(Interval::sup(inter)));
	h[1] = NUM2LONG(n);
	v = rb_memhash(h, sizeof(h));
	return ST2FIX(v);
}

#include?(y) ⇒ Boolean

y is a member of self

𝑦 ∈ [𝒔𝒆𝒍𝒇]

true if [𝒔𝒆𝒍𝒇] β‰  βˆ… ∧ 𝒔𝒆𝒍𝒇 ≀ 𝑦 ∧ 𝑦 ≀ 𝒔𝒆𝒍𝒇 ∧ 𝑦 β‰  ±∞
false otherwise

Parameters:

  • y (Numeric)

Returns:

  • (Boolean)


1284
1285
1286
1287
1288
1289
# File 'ext/p1788/p1788.cc', line 1284

static VALUE p1788_interval_include(VALUE self, VALUE y)
{
	Interval &inter = p1788_interval_rb2ref(self);
	double od = NUM2DBL(y);
	return Interval::is_member(od, inter) ? Qtrue : Qfalse;
}

#inclusion_test(y) ⇒ Boolean?

Test if self is included in y, disjoint from y, or if self and y intersect.

Returns:
flase if self and y are disjoint; else
true if self is included in y; else
nil : self and y intersect.

Parameters:

Returns:

  • (Boolean, nil)


1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
# File 'ext/p1788/p1788.cc', line 1321

static VALUE p1788_interval_inclusion_test(VALUE self, VALUE y)
{
	VALUE r = Qnil;
	Interval &inter = p1788_interval_rb2ref(self);
	Interval iother = p1788_rbobj2interval(y);
	if (Interval::disjoint(inter, iother))
		r = Qfalse;
	else if (Interval::subset(inter, iother))
		r = Qtrue;
	return r;
}

#infFloat? Also known as: lower_bound

Lower bound of the interval. Returns nil if the interval is empty.

Returns:

  • (Float, nil)


1341
1342
1343
1344
1345
1346
1347
# File 'ext/p1788/p1788.cc', line 1341

static VALUE p1788_interval_inf(VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	if (Interval::is_empty(inter))
		return Qnil;
	return DBL2NUM(Interval::inf(inter));
}

#inflate(rad) ⇒ Interval #inflate(delta, chi) ⇒ Interval

Inflate (or deflate) the interval.

Overloads:

  • #inflate(rad) ⇒ Interval

    Add [-rad, rad] to self

    Parameters:

    • rad (Float)

      rad < 0 : deflate; rad = 0 : no change; rad > 0 : inflate

  • #inflate(delta, chi) ⇒ Interval

    Relative and absolute inflation. Return `self.midpoint + delta*(self - self.midpoint) + chi*[-1, +1]1

    Parameters:

    • delta (Float)

      Relative coefficient. delta < 1 : deflate; delta = 1 : no change; delta > 1 : inflate

    • chi (Float)

      Absolute coefficient. chi < 0 : deflate; chi = 0 : no change; chi > 0 : inflate



1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
# File 'ext/p1788/p1788.cc', line 1596

static VALUE p1788_interval_inflate(int argc, VALUE *argv, VALUE self)
{
	VALUE r;
	if (argc == 1) {
		double rad = NUM2DBL(argv[0]);
		P1788_NEW_RB_INTERVAL(r, Interval::add(p1788_interval_rb2ref(self), Interval(-rad, rad)));
	}
	else if (argc == 2) {
		double delta = NUM2DBL(argv[0]);
		double chi   = NUM2DBL(argv[1]);
		const Interval &inter = p1788_interval_rb2ref(self);
		double mid = Interval::mid(inter);
		Interval m(mid, mid);
		Interval d(delta, delta);
		P1788_NEW_RB_INTERVAL(r, m + d*(inter-m) + Interval(-chi, chi));
	}
	else
		rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 1..2)", argc);
	return r;
}

#inspectString

Returns:

  • (String)


633
634
635
636
637
638
# File 'ext/p1788/p1788.cc', line 633

static VALUE p1788_interval_inspect(VALUE self)
{
	return rb_sprintf("#<%" PRIsVALUE " %" PRIsVALUE ">",
			rb_class_name(c_Interval),
			p1788_interval_to_s(self));
}

#interior_subset_of?(y) ⇒ Boolean

Note:

βˆ… βͺ½ βˆ… and ℝ βͺ½ ℝ

self is in the interior of y

[𝒔𝒆𝒍𝒇] βͺ½ [π’š]

(βˆ€ π‘₯ ∈ [𝒔𝒆𝒍𝒇], βˆƒ 𝑦 ∈ [π’š] : π‘₯ > 𝑦) ∧ (βˆ€ π‘₯ ∈ [𝒔𝒆𝒍𝒇], βˆƒ 𝑦 ∈ [π’š] : π‘₯ < 𝑦 )

true if [𝒔𝒆𝒍𝒇] = βˆ… ∨ ([π’š] β‰  βˆ… ∧ π’š < 𝒔𝒆𝒍𝒇 ∧ 𝒔𝒆𝒍𝒇 < π’š)
false otherwise

Returns:

  • (Boolean)


1249
1250
1251
1252
1253
1254
# File 'ext/p1788/p1788.cc', line 1249

static VALUE p1788_interval_interior(VALUE self, VALUE y)
{
	Interval &inter = p1788_interval_rb2ref(self);
	Interval iother = p1788_rbobj2interval(y);
	return Interval::interior(inter, iother) ? Qtrue : Qfalse;
}

#intersect?(y) ⇒ Boolean

[𝒔𝒆𝒍𝒇] ∩ [π’š] β‰  βˆ…

βˆƒ π‘₯ ∈ [𝒔𝒆𝒍𝒇], βˆƒ 𝑦 ∈ [π’š], π‘₯ = 𝑦

true if [𝒔𝒆𝒍𝒇] β‰  βˆ… ∧ [π’š] β‰  βˆ… ∧ 𝒔𝒆𝒍𝒇 β‰₯ π’š ∧ 𝒔𝒆𝒍𝒇 ≀ π’š
false otherwise

Returns:

  • (Boolean)

See Also:

  • disjoint_from


1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
# File 'ext/p1788/p1788.cc', line 1145

static VALUE p1788_interval_intersect(VALUE self, VALUE y)
{
	Interval iother = p1788_rbobj2interval(y);
	Interval &inter = p1788_interval_rb2ref(self);
#if 1
	return Interval::disjoint(inter, iother) ? Qfalse : Qtrue ;
#else
	if (Interval::is_empty(inter) || Interval::is_empty(iother))
		return Qfalse;
	double al = Interval::inf(inter);
	double au = Interval::sup(inter);
	double bl = Interval::inf(iother);
	double bu = Interval::sup(iother);
	return (au >= bl && al <= bu) ? Qtrue : Qfalse;
#endif
}

#intersection(y) ⇒ Interval Also known as: &

Intersection

[𝒔𝒆𝒍𝒇].intersection([π’š])Β Β =Β Β [𝒔𝒆𝒍𝒇] ∩ [π’š]



2060
2061
2062
2063
# File 'ext/p1788/p1788.cc', line 2060

static VALUE p1788_interval_intersection(VALUE self, VALUE y)
{
	P1788_INTERVAL_BINARY_OP(self, y, intersection);
}

#less?(y) ⇒ Boolean

self is weakly less than y

(βˆ€ π‘₯ ∈ [𝒔𝒆𝒍𝒇], βˆƒ 𝑦 ∈ [π’š], π‘₯ ≀ 𝑦) ∧ (βˆ€ 𝑦 ∈ [π’š], βˆƒ π‘₯ ∈ [𝒔𝒆𝒍𝒇], π‘₯ ≀ 𝑦)

true if ([𝒔𝒆𝒍𝒇] = βˆ… ∧ [π’š] = βˆ…) ∨ ([𝒔𝒆𝒍𝒇] β‰  βˆ… ∧ [π’š] β‰  βˆ… ∧ 𝒔𝒆𝒍𝒇 ≀ π’š ∧ 𝒔𝒆𝒍𝒇 ≀ π’š)
false otherwise

Returns:

  • (Boolean)


999
1000
1001
1002
1003
1004
# File 'ext/p1788/p1788.cc', line 999

static VALUE p1788_interval_less(VALUE self, VALUE y)
{
	Interval iother = p1788_rbobj2interval(y);
	Interval &inter = p1788_interval_rb2ref(self);
	return Interval::less(inter, iother) ? Qtrue : Qfalse;
}

#logInterval

Natural logarithm

[𝒔𝒆𝒍𝒇].logΒ Β =Β Β hull{ ln(π‘₯) | π‘₯ ∈ [𝒔𝒆𝒍𝒇]βˆ©β„β‚Š }Β Β βŠ†Β Β β„

Reverse function: #exp



1733
1734
1735
1736
1737
1738
# File 'ext/p1788/p1788.cc', line 1733

static VALUE p1788_interval_log(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::log(p1788_interval_rb2ref(self)));
	return r;
}

#log10Interval

Base 10 logarithm

[𝒔𝒆𝒍𝒇].log10Β Β =Β Β hull{ ln(π‘₯)/ln(10) | π‘₯ ∈ [𝒔𝒆𝒍𝒇]βˆ©β„β‚Š }Β Β βŠ†Β Β β„

Reverse function: #exp10



1761
1762
1763
1764
1765
1766
# File 'ext/p1788/p1788.cc', line 1761

static VALUE p1788_interval_log10(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::log10(p1788_interval_rb2ref(self)));
	return r;
}

#log2Interval

Base 2 logarithm

[𝒔𝒆𝒍𝒇].log2Β Β =Β Β hull{ ln(π‘₯)/ln(2) | π‘₯ ∈ [𝒔𝒆𝒍𝒇]βˆ©β„β‚Š }Β Β βŠ†Β Β β„

Reverse function: #exp2



1747
1748
1749
1750
1751
1752
# File 'ext/p1788/p1788.cc', line 1747

static VALUE p1788_interval_log2(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::log2(p1788_interval_rb2ref(self)));
	return r;
}

#magnitudeFloat?

Magnitude of self

[𝒔𝒆𝒍𝒇].mignitudeΒ Β =Β Β sup{ |π‘₯| οΏ¨ π‘₯ ∈ [𝒔𝒆𝒍𝒇] } if [𝒔𝒆𝒍𝒇] β‰  βˆ…, nil if [𝒔𝒆𝒍𝒇] = βˆ…

Returns:

  • (Float, nil)


1468
1469
1470
1471
1472
1473
1474
# File 'ext/p1788/p1788.cc', line 1468

static VALUE p1788_interval_mag(VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	if (Interval::is_empty(inter))
		return Qnil;
	return DBL2NUM(Interval::mag(inter));
}

#max(b) ⇒ Interval

Maximum of two intervals

[𝒔𝒆𝒍𝒇].max([𝒃])Β Β =Β Β [max(𝒔𝒆𝒍𝒇, 𝒃), max(𝒔𝒆𝒍𝒇, 𝒃)]



2144
2145
2146
2147
# File 'ext/p1788/p1788.cc', line 2144

static VALUE p1788_interval_max(VALUE self, VALUE b)
{
	P1788_INTERVAL_BINARY_OP(self, b, max);
}

#mid_radArray<Float,nil>

Midpoint and radius

Returns:



1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
# File 'ext/p1788/p1788.cc', line 1435

static VALUE p1788_interval_mid_rad(VALUE self)
{
	std::pair< double, double > p = Interval::mid_rad(p1788_interval_rb2ref(self));
	VALUE r1 = DBL2NUM(p.first);
	VALUE r2 = DBL2NUM(p.second);
	if (std::isnan(p.first))
		r1 = Qnil;
	if (std::isnan(p.second))
		r2 = Qnil;
	return rb_ary_new_from_args(2, r1, r2);
}

#midpointFloat?

Midpoint of self

Midpoint is (𝒔𝒆𝒍𝒇 + 𝒔𝒆𝒍𝒇)/2 if [𝒔𝒆𝒍𝒇] β‰  βˆ… and [𝒔𝒆𝒍𝒇] is bounded, nil otherwise

Returns:

  • (Float, nil)


1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
# File 'ext/p1788/p1788.cc', line 1406

static VALUE p1788_interval_mid(VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	if (Interval::is_empty(inter) || Interval::wid(inter) == INF)
		return Qnil;
	double mid = Interval::mid(inter);
	if (std::isnan(mid))
		return Qnil;
	return DBL2NUM(mid);
}

#mignitudeFloat?

Mignitude of self

[𝒔𝒆𝒍𝒇].mignitudeΒ Β =Β Β inf{ |π‘₯| οΏ¨ π‘₯ ∈ [𝒔𝒆𝒍𝒇] } if [𝒔𝒆𝒍𝒇] β‰  βˆ…, nil if [𝒔𝒆𝒍𝒇] = βˆ…

Returns:

  • (Float, nil)


1482
1483
1484
1485
1486
1487
1488
# File 'ext/p1788/p1788.cc', line 1482

static VALUE p1788_interval_mig(VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	if (Interval::is_empty(inter))
		return Qnil;
	return DBL2NUM(Interval::mig(inter));
}

#min(b) ⇒ Interval

Minimum of two intervals

[𝒔𝒆𝒍𝒇].min([𝒃])Β Β =Β Β [min(𝒔𝒆𝒍𝒇, 𝒃), min(𝒔𝒆𝒍𝒇, 𝒃)]



2134
2135
2136
2137
# File 'ext/p1788/p1788.cc', line 2134

static VALUE p1788_interval_min(VALUE self, VALUE b)
{
	P1788_INTERVAL_BINARY_OP(self, b, min);
}

#mul_rev(b, x = ALL_REALS) ⇒ Interval

Reverse multiplication

mul_rev([𝒃], [𝒙])Β Β =Β Β hull{ π‘₯ ∈ [𝒙] | βˆƒ 𝑏 ∈ [𝒃] : π‘₯⋅𝑏 ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„

Reverse function P1788.mul



2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
# File 'ext/p1788/p1788.cc', line 2331

static VALUE p1788_interval_mul_rev(int argc, VALUE *argv, VALUE self)
{
	VALUE b, x, r;
	rb_scan_args(argc, argv, "11", &b, &x);
	if (x == Qnil) {
		P1788_NEW_RB_INTERVAL(r, Interval::mul_rev(p1788_rbobj2interval(b), p1788_interval_rb2ref(self)));
	}
	else {
		P1788_NEW_RB_INTERVAL(r, Interval::mul_rev(p1788_rbobj2interval(b), p1788_interval_rb2ref(self), p1788_rbobj2interval(x)));
	}
	return r;
}

#mul_rev_to_pair(y) ⇒ Array<Interval>

Two-output division

[𝒔𝒆𝒍𝒇]/[𝒃] = { π‘₯ ∈ ℝ | βˆƒ 𝑏 ∈ [𝒃] : π‘₯⋅𝑏 ∈ [𝒔𝒆𝒍𝒇] }

Returns:

  • (Array<Interval>)

    a two elements array of intervals: [βˆ…, βˆ…] if 𝒔𝒆𝒍𝒇/𝒃 is empty, [[𝒔𝒆𝒍𝒇/𝒃], βˆ…] if 𝒔𝒆𝒍𝒇/𝒃 has one component, [[𝒔𝒆𝒍𝒇/𝒃]₁, [𝒔𝒆𝒍𝒇/𝒃]β‚‚] if 𝒔𝒆𝒍𝒇/𝒃 has two components



2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
# File 'ext/p1788/p1788.cc', line 2312

static VALUE p1788_interval_mul_rev_to_pair(VALUE self, VALUE y)
{
	VALUE r1, r2;
	Interval iother = p1788_rbobj2interval(y);
	Interval &inter = p1788_interval_rb2ref(self);
	std::pair< Interval, Interval > p = Interval::mul_rev_to_pair(inter, iother);
	P1788_NEW_RB_INTERVAL(r1, p.first);
	P1788_NEW_RB_INTERVAL(r2, p.second);
	return rb_ary_new_from_args(2, r1, r2);
}

#neg_reals?Boolean

[𝒔𝒆𝒍𝒇] = ℝ₋ ?

Returns:

  • (Boolean)


801
802
803
804
805
# File 'ext/p1788/p1788.cc', line 801

static VALUE p1788_interval_neg_reals(VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	return ((Interval::inf(inter) == -INF) && (Interval::sup(inter) == 0.0)) ? Qtrue : Qfalse;
}

#negative?Boolean

[𝒔𝒆𝒍𝒇] βŠ† [-∞, 0]

true if [𝒔𝒆𝒍𝒇] = βˆ… ∨ 𝒔𝒆𝒍𝒇 ≀ 0
false otherwise

Returns:

  • (Boolean)


841
842
843
844
845
# File 'ext/p1788/p1788.cc', line 841

static VALUE p1788_interval_negative(VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	return (Interval::is_empty(inter) || Interval::sup(inter) <= 0.0) ? Qtrue : Qfalse;
}

#nonempty?Boolean

[𝒔𝒆𝒍𝒇] β‰  βˆ… ?

Returns:

  • (Boolean)


773
774
775
776
# File 'ext/p1788/p1788.cc', line 773

static VALUE p1788_interval_nonempty(VALUE self)
{
	return Interval::is_empty(p1788_interval_rb2ref(self)) ? Qfalse : Qtrue;
}

#overlap?(y) ⇒ Boolean

Intersection of self and y is neither empty nor a singleton.

Returns:

  • (Boolean)


1166
1167
1168
1169
1170
# File 'ext/p1788/p1788.cc', line 1166

static VALUE p1788_interval_overlap(VALUE self, VALUE y)
{
	Interval inter = Interval::intersection(p1788_rbobj2interval(y), p1788_interval_rb2ref(self));
	return (Interval::is_empty(inter) || Interval::is_singleton(inter)) ? Qfalse : Qtrue;
}

#overlapping_state(y) ⇒ Symbol

Overlapping state between self and y

Returns:

  • (Symbol)

    :undefined, :both_empty, :first_empty, :second_empty, :before, :meets, :overlaps, :starts, :contained_by, :finishes, :equal, :finished_by, :contains, :started_by, :overlapped_by, :met_by or :after



1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
# File 'ext/p1788/p1788.cc', line 1540

static VALUE p1788_interval_overlapping_state(VALUE self, VALUE y)
{
	Interval iother = p1788_rbobj2interval(y);
	Interval &inter = p1788_interval_rb2ref(self);
	p1788::overlapping::overlapping_state ovlps = Interval::overlap(inter, iother);
	VALUE r;
	switch (ovlps) {
		case p1788::overlapping::overlapping_state::both_empty:
			r = ID2SYM(id_both_empty); break;
		case p1788::overlapping::overlapping_state::first_empty:
			r = ID2SYM(id_first_empty); break;
		case p1788::overlapping::overlapping_state::second_empty:
			r = ID2SYM(id_second_empty); break;
		case p1788::overlapping::overlapping_state::before:
			r = ID2SYM(id_before); break;
		case p1788::overlapping::overlapping_state::meets:
			r = ID2SYM(id_meets); break;
		case p1788::overlapping::overlapping_state::overlaps:
			r = ID2SYM(id_overlaps); break;
		case p1788::overlapping::overlapping_state::starts:
			r = ID2SYM(id_starts); break;
		case p1788::overlapping::overlapping_state::contained_by:
			r = ID2SYM(id_contained_by); break;
		case p1788::overlapping::overlapping_state::finishes:
			r = ID2SYM(id_finishes); break;
		case p1788::overlapping::overlapping_state::equal:
			r = ID2SYM(id_equal); break;
		case p1788::overlapping::overlapping_state::finished_by:
			r = ID2SYM(id_finished_by); break;
		case p1788::overlapping::overlapping_state::contains:
			r = ID2SYM(id_contains); break;
		case p1788::overlapping::overlapping_state::started_by:
			r = ID2SYM(id_started_by); break;
		case p1788::overlapping::overlapping_state::overlapped_by:
			r = ID2SYM(id_overlapped_by); break;
		case p1788::overlapping::overlapping_state::met_by:
			r = ID2SYM(id_met_by); break;
		case p1788::overlapping::overlapping_state::after:
			r = ID2SYM(id_after); break;
		default:
			r = ID2SYM(id_undefined);
	}
	return r;
}

#pos_reals?Boolean

[𝒔𝒆𝒍𝒇] = β„β‚Š ?

Returns:

  • (Boolean)


791
792
793
794
795
# File 'ext/p1788/p1788.cc', line 791

static VALUE p1788_interval_pos_reals(VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	return ((Interval::inf(inter) == 0.0) && (Interval::sup(inter) == INF)) ? Qtrue : Qfalse;
}

#positive?Boolean

[𝒔𝒆𝒍𝒇] βŠ† [0, +∞]

true if [𝒔𝒆𝒍𝒇] = βˆ… ∨ 𝒔𝒆𝒍𝒇 β‰₯ 0
false otherwise

Returns:

  • (Boolean)


814
815
816
817
818
# File 'ext/p1788/p1788.cc', line 814

static VALUE p1788_interval_positive(VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	return (Interval::is_empty(inter) || Interval::inf(inter) >= 0.0) ? Qtrue : Qfalse;
}

#pow(y) ⇒ Interval

Power function

[𝒔𝒆𝒍𝒇].pow([π’š])Β Β =Β Β hull{ π‘₯𝑦 | (π‘₯, 𝑦) ∈ {π‘₯ ∈ [𝒔𝒆𝒍𝒇], 𝑦 ∈ [π’š] | π‘₯>0} βˆͺ {π‘₯ ∈ [𝒔𝒆𝒍𝒇]∩{0}, 𝑦 ∈ [π’š] | 𝑦>0} }Β Β βŠ†Β Β β„β‚Š

Reverse functions: #pow_rev1 and #pow_rev2



2241
2242
2243
2244
2245
2246
2247
2248
2249
# File 'ext/p1788/p1788.cc', line 2241

static VALUE p1788_interval_pow(VALUE self, VALUE y)
{
	if (rb_obj_is_kind_of(y, rb_cNumeric) && NUM2DBL(y) == 2.0) {
		VALUE r;
		P1788_NEW_RB_INTERVAL(r, Interval::sqr(p1788_interval_rb2ref(self)));
		return r;
	}
	P1788_INTERVAL_BINARY_OP(self, y, cancel_plus);
}

#pow_rev1(b, x = ALL_REALS) ⇒ Interval

Reverse power function (base)

pow_rev1([𝒃], [𝒙])Β Β =Β Β hull{ π‘₯ ∈ [𝒙] | βˆƒ 𝑏 ∈ [𝒃] : π‘₯𝑏 ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„β‚Š

Reverse function: #pow



2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
# File 'ext/p1788/p1788.cc', line 2419

static VALUE p1788_interval_pow_rev1(int argc, VALUE *argv, VALUE self)
{
	VALUE rbb, rbx, rbr;
	rb_scan_args(argc, argv, "11", &rbb, &rbx);
	Interval  b = p1788_rbobj2interval(rbb);
	Interval  x = (rbx == Qnil) ? Interval(-INF, INF) : p1788_rbobj2interval(rbx);
	Interval &c = p1788_interval_rb2ref(self);

	Interval lnx = Interval::log(x);
	Interval m   = Interval::intersection(Interval::log(c), Interval::mul(b, lnx));
	Interval l   = Interval::mul_rev(b, m, lnx);
	Interval r   = Interval::intersection(Interval::exp(l), x);

	P1788_NEW_RB_INTERVAL(rbr, r);
	return rbr;
}

#pow_rev2(a, x = ALL_REALS) ⇒ Interval

Reverse power function (exponent)

pow_rev2([𝒂], [𝒙])Β Β =Β Β hull{ π‘₯ ∈ [𝒙] | βˆƒ π‘Ž ∈ [𝒂] : π‘Žπ‘₯ ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„

Reverse function: #pow



2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
# File 'ext/p1788/p1788.cc', line 2444

static VALUE p1788_interval_pow_rev2(int argc, VALUE *argv, VALUE self)
{
	VALUE rba, rbx, rbr;
	rb_scan_args(argc, argv, "11", &rba, &rbx);
	Interval a = p1788_rbobj2interval(rba);
	Interval x = (rbx == Qnil) ? Interval(-INF, INF) : p1788_rbobj2interval(rbx);
	Interval &c = p1788_interval_rb2ref(self);

	Interval lna = Interval::log(a);
	Interval m   = Interval::intersection(Interval::log(c), Interval::mul(x, lna));
	Interval r   = Interval::mul_rev(lna, m, x);

	P1788_NEW_RB_INTERVAL(rbr, r);
	return rbr;
}

#pown(n) ⇒ Interval

Power with integer exponent

[𝒔𝒆𝒍𝒇].pow(n)Β Β =Β Β hull{ π‘₯ⁿ | π‘₯ ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„ if n odd, β„β‚Š if n even, {1} if n = 0

Reverse function #pown_rev

Parameters:

  • n (Integer)

    integer exponent



2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
# File 'ext/p1788/p1788.cc', line 2259

static VALUE p1788_interval_pown(VALUE self, VALUE n)
{
	VALUE r;
	int p;
	if (!RB_INTEGER_TYPE_P(n))
		rb_raise(rb_eTypeError, "expecting an integer as exponent, not a %" PRIsVALUE, rb_class_name(rb_class_of(n)));
	p = NUM2INT(n);
	if (p == 2) {
		P1788_NEW_RB_INTERVAL(r, Interval::sqr(p1788_interval_rb2ref(self)));
	} else {
		P1788_NEW_RB_INTERVAL(r, Interval::pown(p1788_interval_rb2ref(self), p));
	}
	return r;
}

#pown_rev(n, x = ALL_REALS) ⇒ Interval

Reverse power with integer exponent

pown_rev(𝑛, [𝒙])Β Β =Β Β hull{ π‘₯ ∈ [𝒙] | π‘₯ⁿ ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„

Reverse function: #pown

Parameters:

  • n (Integer)

    integer exponent

  • x (Interval) (defaults to: ALL_REALS)


2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
# File 'ext/p1788/p1788.cc', line 2396

static VALUE p1788_interval_pown_rev(int argc, VALUE *argv, VALUE self)
{
	VALUE x, r, n;
	int p;
	rb_scan_args(argc, argv, "11", &n, &x);
	p = NUM2INT(n);
	if (x == Qnil) {
		P1788_NEW_RB_INTERVAL(r, Interval::pown_rev(p1788_interval_rb2ref(self), p));
	}
	else {
		P1788_NEW_RB_INTERVAL(r, Interval::pown_rev(p1788_interval_rb2ref(self), p1788_rbobj2interval(x), p));
	}
	return r;
}

#precedes?(y) ⇒ Boolean

self is to the left of but may touch y

βˆ€ π‘₯ ∈ [𝒔𝒆𝒍𝒇], βˆ€ 𝑦 ∈ [π’š], π‘₯ ≀ 𝑦

true if [𝒔𝒆𝒍𝒇] = βˆ… ∨ [π’š] = βˆ… ∨ 𝒔𝒆𝒍𝒇 ≀ π’š
false otherwise

Returns:

  • (Boolean)


1063
1064
1065
1066
1067
1068
# File 'ext/p1788/p1788.cc', line 1063

static VALUE p1788_interval_precedes(VALUE self, VALUE y)
{
	Interval iother = p1788_rbobj2interval(y);
	Interval &inter = p1788_interval_rb2ref(self);
	return Interval::precedes(inter, iother) ? Qtrue : Qfalse;
}

#radiusFloat?

Radius of self

Radius is (𝒔𝒆𝒍𝒇 - 𝒔𝒆𝒍𝒇)/2 if [𝒔𝒆𝒍𝒇] β‰  βˆ…, nil if [𝒔𝒆𝒍𝒇] = βˆ…

Returns:

  • (Float, nil)


1423
1424
1425
1426
1427
1428
1429
# File 'ext/p1788/p1788.cc', line 1423

static VALUE p1788_interval_rad(VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	if (Interval::is_empty(inter))
		return Qnil;
	return DBL2NUM(Interval::rad(inter));
}

#recipInterval

Reciprocal

[𝒔𝒆𝒍𝒇].recipΒ Β =Β Β hull{ 1/π‘₯ | π‘₯ ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„

Reverse function: #recip



1649
1650
1651
1652
1653
1654
# File 'ext/p1788/p1788.cc', line 1649

static VALUE p1788_interval_recip(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::recip(p1788_interval_rb2ref(self)));
	return r;
}

#round_ties_to_awayInterval

Round, ties to away from zero

Round bounds of self to their nearest integer values, rounding halfway cases away from zero.

[𝒔𝒆𝒍𝒇].round_ties_to_awayΒ Β =Β Β [round_ties_to_away(𝒔𝒆𝒍𝒇), round_ties_to_away(𝒔𝒆𝒍𝒇)]



2018
2019
2020
2021
2022
2023
# File 'ext/p1788/p1788.cc', line 2018

static VALUE p1788_interval_round_ties_to_away(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::round_ties_to_away(p1788_interval_rb2ref(self)));
	return r;
}

#round_ties_to_evenInterval Also known as: round

Round, ties to even

Round bounds of self to their nearest integer values, rounding halfway cases to nearest even.

[𝒔𝒆𝒍𝒇].round_ties_to_evenΒ Β =Β Β [round_ties_to_even(𝒔𝒆𝒍𝒇), round_ties_to_even(𝒔𝒆𝒍𝒇)]



2004
2005
2006
2007
2008
2009
# File 'ext/p1788/p1788.cc', line 2004

static VALUE p1788_interval_round_ties_to_even(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::round_ties_to_even(p1788_interval_rb2ref(self)));
	return r;
}

#signInterval

Sign of self

[𝒔𝒆𝒍𝒇].signΒ Β βŠ†Β Β [-1, 1]Β Β ({-1} if 𝒔𝒆𝒍𝒇 < 0, {1} if 𝒔𝒆𝒍𝒇 > 0, {0} if [𝒔𝒆𝒍𝒇] = {0})



1941
1942
1943
1944
1945
1946
# File 'ext/p1788/p1788.cc', line 1941

static VALUE p1788_interval_sign(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::sign(p1788_interval_rb2ref(self)));
	return r;
}

#sinInterval

Sine

[𝒔𝒆𝒍𝒇].sinΒ Β =Β Β hull{ sin(π‘₯) | π‘₯ ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β [-1, 1]

Reverse function: #sin_rev



1775
1776
1777
1778
1779
1780
# File 'ext/p1788/p1788.cc', line 1775

static VALUE p1788_interval_sin(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::sin(p1788_interval_rb2ref(self)));
	return r;
}

#sin_rev(x = ALL_REALS) ⇒ Interval

Reverse sine

sin_rev([𝒙])Β Β =Β Β hull{ π‘₯ ∈ [𝒙] | sin(π‘₯) ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„

Reverse function: #sin



2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
# File 'ext/p1788/p1788.cc', line 2468

static VALUE p1788_interval_sin_rev(int argc, VALUE *argv, VALUE self)
{
	VALUE x, r;
	rb_scan_args(argc, argv, "01", &x);
	if (x == Qnil) {
		P1788_NEW_RB_INTERVAL(r, Interval::sin_rev(p1788_interval_rb2ref(self)));
	}
	else {
		P1788_NEW_RB_INTERVAL(r, Interval::sin_rev(p1788_interval_rb2ref(self), p1788_rbobj2interval(x)));
	}
	return r;
}

#singleton?Boolean

Tels if self contains only one value.

Returns:

  • (Boolean)


911
912
913
914
# File 'ext/p1788/p1788.cc', line 911

static VALUE p1788_interval_singleton(VALUE self)
{
	return Interval::is_singleton(p1788_interval_rb2ref(self)) ? Qtrue : Qfalse;
}

#sinhInterval

Hyperbolic sine

[𝒔𝒆𝒍𝒇].sinhΒ Β =Β Β hull{ (𝑒π‘₯ - 𝑒-π‘₯) / 2 | π‘₯ ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„

Reverse function: #asinh



1859
1860
1861
1862
1863
1864
# File 'ext/p1788/p1788.cc', line 1859

static VALUE p1788_interval_sinh(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::sinh(p1788_interval_rb2ref(self)));
	return r;
}

#splitpointFloat?

Split point used to bisect

Split point is:
(𝒔𝒆𝒍𝒇 + 𝒔𝒆𝒍𝒇)/2 if [𝒔𝒆𝒍𝒇] is nonempty and bounded,
0 if [𝒔𝒆𝒍𝒇] = ℝ,
-Float::MAX if 𝒔𝒆𝒍𝒇 = -∞
Float::MAX if 𝒔𝒆𝒍𝒇 = +∞
nil if [𝒔𝒆𝒍𝒇] = βˆ…

Returns:

  • (Float, nil)


1391
1392
1393
1394
1395
1396
1397
1398
# File 'ext/p1788/p1788.cc', line 1391

static VALUE p1788_interval_splitpoint(VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	double sp = p1788_interval_splitpoint_double(inter);
	if (std::isnan(sp))
		return Qnil;
	return DBL2NUM(sp);
}

#sqrInterval

Square

[𝒔𝒆𝒍𝒇].sqrΒ Β =Β Β hull{ π‘₯Β² | π‘₯ ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„β‚Š

Reverse function: #sqr_rev



1663
1664
1665
1666
1667
1668
# File 'ext/p1788/p1788.cc', line 1663

static VALUE p1788_interval_sqr(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::sqr(p1788_interval_rb2ref(self)));
	return r;
}

#sqr_rev(x = ALL_REALS) ⇒ Interval

Reverse square

sqr_rev([𝒙])Β Β =Β Β hull{ π‘₯ ∈ [𝒙] | π‘₯Β² ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„

Reverse function: #sqr



2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
# File 'ext/p1788/p1788.cc', line 2352

static VALUE p1788_interval_sqr_rev(int argc, VALUE *argv, VALUE self)
{
	VALUE x, r;
	rb_scan_args(argc, argv, "01", &x);
	if (x == Qnil) {
		P1788_NEW_RB_INTERVAL(r, Interval::sqr_rev(p1788_interval_rb2ref(self)));
	}
	else {
		P1788_NEW_RB_INTERVAL(r, Interval::sqr_rev(p1788_interval_rb2ref(self), p1788_rbobj2interval(x)));
	}
	return r;
}

#sqrtInterval

Square root

[𝒔𝒆𝒍𝒇].sqrtΒ Β =Β Β hull{ π‘₯Β½ | π‘₯ ∈ [𝒔𝒆𝒍𝒇]βˆ©β„β‚Š }Β Β βŠ†Β Β β„β‚Š

Reverse function: #sqr



1677
1678
1679
1680
1681
1682
# File 'ext/p1788/p1788.cc', line 1677

static VALUE p1788_interval_sqrt(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::sqrt(p1788_interval_rb2ref(self)));
	return r;
}

#strict_subset_of?(y) ⇒ Boolean

self is a subset of but not equal to y

[𝒔𝒆𝒍𝒇] βŠ‚ [π’š] ∧ [𝒔𝒆𝒍𝒇] β‰  [π’š]

Returns:

  • (Boolean)

See Also:



1197
1198
1199
1200
1201
1202
# File 'ext/p1788/p1788.cc', line 1197

static VALUE p1788_interval_strict_subset(VALUE self, VALUE y)
{
	Interval &inter = p1788_interval_rb2ref(self);
	Interval iother = p1788_rbobj2interval(y);
	return (Interval::subset(inter, iother) && !Interval::equal(inter, iother)) ? Qtrue : Qfalse;
}

#strict_superset_of?(y) ⇒ Boolean

self is a superset of but not equal to y

[𝒔𝒆𝒍𝒇] βŠƒ [π’š] ∧ [π’š] β‰  [𝒔𝒆𝒍𝒇]

Returns:

  • (Boolean)

See Also:



1229
1230
1231
1232
1233
1234
# File 'ext/p1788/p1788.cc', line 1229

static VALUE p1788_interval_strict_superset(VALUE self, VALUE y)
{
	Interval &inter = p1788_interval_rb2ref(self);
	Interval iother = p1788_rbobj2interval(y);
	return (Interval::superset(inter, iother) && !Interval::equal(inter, iother)) ? Qtrue : Qfalse;
}

#strictly_greater?(y) ⇒ Boolean

self is strictly greater than y

(βˆ€ π‘₯ ∈ [𝒔𝒆𝒍𝒇], βˆƒ 𝑦 ∈ [π’š], π‘₯ > 𝑦) ∧ (βˆ€ 𝑦 ∈ [π’š], βˆƒ π‘₯ ∈ [𝒔𝒆𝒍𝒇], π‘₯ > 𝑦)

true if ([𝒔𝒆𝒍𝒇] = βˆ… ∧ [π’š] = βˆ…) ∨ ([𝒔𝒆𝒍𝒇] β‰  βˆ… ∧ [π’š] β‰  βˆ… ∧ 𝒔𝒆𝒍𝒇 > π’š ∧ 𝒔𝒆𝒍𝒇 > π’š)
false otherwise

Returns:

  • (Boolean)


1047
1048
1049
1050
1051
1052
# File 'ext/p1788/p1788.cc', line 1047

static VALUE p1788_interval_strictly_greater(VALUE self, VALUE y)
{
	Interval iother = p1788_rbobj2interval(y);
	Interval &inter = p1788_interval_rb2ref(self);
	return Interval::strictly_greater(inter, iother) ? Qtrue : Qfalse;
}

#strictly_less?(y) ⇒ Boolean

self is strictly less than y

(βˆ€ π‘₯ ∈ [𝒔𝒆𝒍𝒇], βˆƒ 𝑦 ∈ [π’š], π‘₯ < 𝑦) ∧ (βˆ€ 𝑦 ∈ [π’š], βˆƒ π‘₯ ∈ [𝒔𝒆𝒍𝒇], π‘₯ < 𝑦)

true if ([𝒔𝒆𝒍𝒇] = βˆ… ∧ [π’š] = βˆ…) ∨ ([𝒔𝒆𝒍𝒇] β‰  βˆ… ∧ [π’š] β‰  βˆ… ∧ 𝒔𝒆𝒍𝒇 < π’š ∧ 𝒔𝒆𝒍𝒇 < π’š)
false otherwise

Returns:

  • (Boolean)


1031
1032
1033
1034
1035
1036
# File 'ext/p1788/p1788.cc', line 1031

static VALUE p1788_interval_strictly_less(VALUE self, VALUE y)
{
	Interval iother = p1788_rbobj2interval(y);
	Interval &inter = p1788_interval_rb2ref(self);
	return Interval::strictly_less(inter, iother) ? Qtrue : Qfalse;
}

#strictly_negative?Boolean

[𝒔𝒆𝒍𝒇] βŠ‚ [-∞, 0]

true if [𝒔𝒆𝒍𝒇] = βˆ… ∨ 𝒔𝒆𝒍𝒇 < 0
false otherwise

Returns:

  • (Boolean)


855
856
857
858
859
# File 'ext/p1788/p1788.cc', line 855

static VALUE p1788_interval_strictly_negative(VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	return (Interval::is_empty(inter) || Interval::sup(inter) < 0.0) ? Qtrue : Qfalse;
}

#strictly_positive?Boolean

[𝒔𝒆𝒍𝒇] βŠ‚ [0, +∞]

true if [𝒔𝒆𝒍𝒇] = βˆ… ∨ 𝒔𝒆𝒍𝒇 > 0
false otherwise

Returns:

  • (Boolean)


828
829
830
831
832
# File 'ext/p1788/p1788.cc', line 828

static VALUE p1788_interval_strictly_positive(VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	return (Interval::is_empty(inter) || Interval::inf(inter) > 0.0) ? Qtrue : Qfalse;
}

#strictly_precedes?(y) ⇒ Boolean

self is strictly to the left of y

βˆ€ π‘₯ ∈ [𝒔𝒆𝒍𝒇], βˆ€ 𝑦 ∈ [π’š], π‘₯ < 𝑦

true if [𝒔𝒆𝒍𝒇] = βˆ… ∨ [π’š] = βˆ… ∨ 𝒔𝒆𝒍𝒇 < π’š
false otherwise

Returns:

  • (Boolean)


1095
1096
1097
1098
1099
1100
# File 'ext/p1788/p1788.cc', line 1095

static VALUE p1788_interval_strictly_precedes(VALUE self, VALUE y)
{
	Interval iother = p1788_rbobj2interval(y);
	Interval &inter = p1788_interval_rb2ref(self);
	return Interval::strictly_precedes(inter, iother) ? Qtrue : Qfalse;
}

#strictly_succeeds?(y) ⇒ Boolean

self is strictly to the right of y

βˆ€ π‘₯ ∈ [𝒔𝒆𝒍𝒇], βˆ€ 𝑦 ∈ [π’š], π‘₯ > 𝑦

true if [𝒔𝒆𝒍𝒇] = βˆ… ∨ [π’š] = βˆ… ∨ 𝒔𝒆𝒍𝒇 > π’š
false otherwise

Returns:

  • (Boolean)


1111
1112
1113
1114
1115
1116
# File 'ext/p1788/p1788.cc', line 1111

static VALUE p1788_interval_strictly_succeeds(VALUE self, VALUE y)
{
	Interval iother = p1788_rbobj2interval(y);
	Interval &inter = p1788_interval_rb2ref(self);
	return Interval::strictly_succeeds(inter, iother) ? Qtrue : Qfalse;
}

#subset_of?(y) ⇒ Boolean

self is a subset of or equal to y

[𝒔𝒆𝒍𝒇] βŠ† [π’š]

βˆ€ π‘₯ ∈ [𝒔𝒆𝒍𝒇], βˆƒ 𝑦 ∈ [π’š] : π‘₯ = 𝑦

true if [𝒔𝒆𝒍𝒇] = βˆ… ∨ ([π’š] β‰  βˆ… ∧ π’š ≀ 𝒔𝒆𝒍𝒇 ∧ 𝒔𝒆𝒍𝒇 ≀ π’š)
false otherwise

Returns:

  • (Boolean)


1183
1184
1185
1186
1187
1188
# File 'ext/p1788/p1788.cc', line 1183

static VALUE p1788_interval_subset(VALUE self, VALUE y)
{
	Interval &inter = p1788_interval_rb2ref(self);
	Interval iother = p1788_rbobj2interval(y);
	return Interval::subset(inter, iother) ? Qtrue : Qfalse;
}

#succeeds?(y) ⇒ Boolean

self is to the right of but may touch y

βˆ€ π‘₯ ∈ [𝒔𝒆𝒍𝒇], βˆ€ 𝑦 ∈ [π’š], π‘₯ β‰₯ 𝑦

true if [𝒔𝒆𝒍𝒇] = βˆ… ∨ [π’š] = βˆ… ∨ 𝒔𝒆𝒍𝒇 β‰₯ π’š
false otherwise

Returns:

  • (Boolean)


1079
1080
1081
1082
1083
1084
# File 'ext/p1788/p1788.cc', line 1079

static VALUE p1788_interval_succeeds(VALUE self, VALUE y)
{
	Interval iother = p1788_rbobj2interval(y);
	Interval &inter = p1788_interval_rb2ref(self);
	return Interval::succeeds(inter, iother) ? Qtrue : Qfalse;
}

#supFloat? Also known as: upper_bound

Upper bound of the interval. Returns nil if the interval is empty.

Returns:

  • (Float, nil)


1354
1355
1356
1357
1358
1359
1360
# File 'ext/p1788/p1788.cc', line 1354

static VALUE p1788_interval_sup(VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	if (Interval::is_empty(inter))
		return Qnil;
	return DBL2NUM(Interval::sup(inter));
}

#superset_of?(y) ⇒ Boolean Also known as: contain?

self is a superset of or equal to y

[𝒔𝒆𝒍𝒇] βŠ‡ [π’š]

βˆ€ 𝑦 ∈ [π’š], βˆƒ π‘₯ ∈ [𝒔𝒆𝒍𝒇] : 𝑦 = π‘₯

true if [π’š] = βˆ… ∨ ([𝒔𝒆𝒍𝒇] β‰  βˆ… ∧ 𝒔𝒆𝒍𝒇 ≀ π’š ∧ π’š ≀ 𝒔𝒆𝒍𝒇)
false otherwise

Returns:

  • (Boolean)


1215
1216
1217
1218
1219
1220
# File 'ext/p1788/p1788.cc', line 1215

static VALUE p1788_interval_superset(VALUE self, VALUE y)
{
	Interval &inter = p1788_interval_rb2ref(self);
	Interval iother = p1788_rbobj2interval(y);
	return Interval::superset(inter, iother) ? Qtrue : Qfalse;
}

#symmetric?Boolean

The lower bound of self is the opposite of the upper bound. An empty interval is not symmetric.

Returns:

  • (Boolean)


901
902
903
904
905
# File 'ext/p1788/p1788.cc', line 901

static VALUE p1788_interval_symmetric(VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	return (Interval::is_empty(inter) || Interval::inf(inter) != -Interval::sup(inter)) ? Qfalse : Qtrue;
}

#tanInterval

Tangent

[𝒔𝒆𝒍𝒇].tanΒ Β =Β Β hull{ tan(π‘₯) | π‘₯ ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„

Reverse function: #tan_rev



1803
1804
1805
1806
1807
1808
# File 'ext/p1788/p1788.cc', line 1803

static VALUE p1788_interval_tan(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::tan(p1788_interval_rb2ref(self)));
	return r;
}

#tan_rev(x = ALL_REALS) ⇒ Interval

Reverse tangent

tan_rev([𝒙])Β Β =Β Β hull{ π‘₯ ∈ [𝒙] | tan(π‘₯) ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β β„

Reverse function: #tan



2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
# File 'ext/p1788/p1788.cc', line 2510

static VALUE p1788_interval_tan_rev(int argc, VALUE *argv, VALUE self)
{
	VALUE x, r;
	rb_scan_args(argc, argv, "01", &x);
	if (x == Qnil) {
		P1788_NEW_RB_INTERVAL(r, Interval::tan_rev(p1788_interval_rb2ref(self)));
	}
	else {
		P1788_NEW_RB_INTERVAL(r, Interval::tan_rev(p1788_interval_rb2ref(self), p1788_rbobj2interval(x)));
	}
	return r;
}

#tanhInterval

Hyperbolic tangent

[𝒔𝒆𝒍𝒇].tanhΒ Β =Β Β hull{ sinh(π‘₯) / cosh(π‘₯) | π‘₯ ∈ [𝒔𝒆𝒍𝒇] }Β Β βŠ†Β Β [-1, 1]

Reverse function: #atanh



1887
1888
1889
1890
1891
1892
# File 'ext/p1788/p1788.cc', line 1887

static VALUE p1788_interval_tanh(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::tanh(p1788_interval_rb2ref(self)));
	return r;
}

#to_aArray<Float>

Returns a two element arrays containing the bounds of self.

Returns:

  • (Array<Float>)


522
523
524
525
526
527
528
529
530
531
# File 'ext/p1788/p1788.cc', line 522

static VALUE p1788_interval_to_a(VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	if (Interval::is_empty(inter))
		return rb_ary_new_capa(0);
	VALUE r = rb_ary_new_capa(2);
	rb_ary_store(r, 0, DBL2NUM(Interval::inf(inter)));
	rb_ary_store(r, 1, DBL2NUM(Interval::sup(inter)));
	return r;
}

#to_latex(print_dollars = true) ⇒ String

Returns a LaTex representation as a string.

Parameters:

  • print_dollars (Boolean) (defaults to: true)

    if true, will surround the string with $$ signs.

Returns:

  • (String)


733
734
735
736
737
738
739
740
741
# File 'ext/p1788/p1788.cc', line 733

static VALUE p1788_interval_to_latex(int argc, VALUE *argv, VALUE self)
{
	VALUE arg;
	if (rb_scan_args(argc, argv, "01", &arg) > 0) {
		if (arg == Qnil || arg == Qfalse)
			return p1788_interval_to_tex(self);
	}
	return rb_sprintf("$$ %" PRIsVALUE " $$", p1788_interval_to_tex(self));
}

#to_sString

Returns a unicode string representation of self.

Returns:

  • (String)


587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
# File 'ext/p1788/p1788.cc', line 587

static VALUE p1788_interval_to_s(VALUE self)
{
	double lb, ub;
	VALUE lbc, ubc;
	Interval &inter = p1788_interval_rb2ref(self);

	if (Interval::is_empty(inter))
		return rb_utf8_str_new_cstr("βˆ…");
	if (Interval::is_entire(inter))
		return rb_utf8_str_new_cstr("ℝ");

	lb = Interval::inf(inter);
	ub = Interval::sup(inter);

	if ((lb == 0.0) && (ub == INF))
		return rb_utf8_str_new_cstr("β„β‚Š");
	if ((lb == -INF) && (ub == 0.0))
		return rb_utf8_str_new_cstr("ℝ₋");

	if (lb == -INF)
		lbc = rb_utf8_str_new_cstr("-∞");
	else if (lb == INF)
		lbc = rb_utf8_str_new_cstr("+∞");
	else if ((double)((int)(lb)) == lb)
		lbc = rb_funcallv(INT2NUM((int)lb), id_to_s, 0, NULL);
	else
		lbc = rb_funcallv(DBL2NUM(lb), id_to_s, 0, NULL);

	if (Interval::is_singleton(inter))
		return rb_sprintf("{%" PRIsVALUE "}", lbc);

	if (ub == -INF)
		ubc = rb_utf8_str_new_cstr("-∞");
	else if (ub == INF)
		ubc = rb_utf8_str_new_cstr("+∞");
	else if ((double)((int)(ub)) == ub)
		ubc = rb_funcallv(INT2NUM((int)ub), id_to_s, 0, NULL);
	else
		ubc = rb_funcallv(DBL2NUM(ub), id_to_s, 0, NULL);

	return rb_sprintf("[%" PRIsVALUE ", %" PRIsVALUE "]", lbc, ubc);
}

#truncateInterval

Round towards 0

[𝒔𝒆𝒍𝒇].truncΒ Β =Β Β [trunc(𝒔𝒆𝒍𝒇), trunc(𝒔𝒆𝒍𝒇)]



1990
1991
1992
1993
1994
1995
# File 'ext/p1788/p1788.cc', line 1990

static VALUE p1788_interval_trunc(VALUE self)
{
	VALUE r;
	P1788_NEW_RB_INTERVAL(r, Interval::trunc(p1788_interval_rb2ref(self)));
	return r;
}

#unbounded?Boolean

Note:

An empty interval is always bounded

One of the bounds of self is infinite

Returns:

  • (Boolean)

See Also:



890
891
892
893
894
# File 'ext/p1788/p1788.cc', line 890

static VALUE p1788_interval_unbounded(VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	return (Interval::is_empty(inter) || Interval::is_common_interval(inter)) ? Qfalse : Qtrue;
}

#widthFloat?

Width of self

Width is 𝒔𝒆𝒍𝒇 - 𝒔𝒆𝒍𝒇 if [𝒔𝒆𝒍𝒇] β‰  βˆ…, nil if [𝒔𝒆𝒍𝒇] = βˆ…

Returns:

  • (Float, nil)


1454
1455
1456
1457
1458
1459
1460
# File 'ext/p1788/p1788.cc', line 1454

static VALUE p1788_interval_wid(VALUE self)
{
	Interval &inter = p1788_interval_rb2ref(self);
	if (Interval::is_empty(inter))
		return Qnil;
	return DBL2NUM(Interval::wid(inter));
}