The previous tutorial we looked at how wrappers are used to extend functionality in distr6 to composite and transformed distributions. Now we will take a slight detour from the distribution interface to look at symbolic sets and intervals. We will keep this tutorial brief as whilst these objects form an integral part of making distr6 have pretty print methods, they are purely symbolic and have little mathematical functionality.

## Sets, Intervals and SetIntervals

The class structure for these objects looks like: SetInterval -> Set, SetInterval -> Interval i.e. everything inherits from SetInterval, this means all methods from SetInterval are also in Set and Interval objects. Sets and intervals primarily differ in that sets expect discrete elements whereas intervals expect a range of numerics:

Set$new("A","B","C") #> [1] "{A, B, C}" Interval$new(lower = 1, upper = 10)
#> [1] "[1,10]"

The type of interval can be changed to ensure the correct bounds are set

Interval$new(-Inf, Inf, type = "()") #> [1] "(-∞,+∞)" Interval$new(-Inf, 10, type = "(]")
#> [1] "(-∞,10]"
Interval$new(1, Inf, type = "[)") #> [1] "[1,+∞)" Interval$new(1, 10, type = "[]")
#> [1] "[1,10]"

These also include basic accessors for the bounds of the interval

Interval$new(0,10,type = "()")$min()
#> [1] 1.1e-15
Interval$new(0,10,type = "()")$inf()
#> [1] 0
Interval$new(0,10,type = "()")$max()
#> [1] 10

#10 - 1.1e-15
Interval$new(0,10,type = "()")$sup()
#> [1] 10

And a way of testing if an element lies in the set or interval

Interval$new(0,10,type = "()")$liesInSetInterval(10)
#> [1] FALSE
Interval$new(0,10,type = "(]")$liesInSetInterval(10)
#> [1] TRUE

## Special Sets

distr6 includes some sets which are especially special, these can be listed with

listSpecialSets()
#>         ClassName       Symbol Infimum Supremum
#>  1:         Empty            ∅    NULL     NULL
#>  2:      Naturals           ℕ0       0      Inf
#>  3:   PosNaturals           ℕ+     0/1      Inf
#>  4:      Integers            ℤ    -Inf      Inf
#>  5:   PosIntegers           ℤ+     0/1      Inf
#>  6:   NegIntegers           ℤ-    -Inf     -1/0
#>  7:     Rationals            ℚ    -Inf      Inf
#>  8:  PosRationals           ℚ+     0/1      Inf
#>  9:  NegRationals           ℚ-    -Inf     -1/0
#> 10:         Reals            ℝ    -Inf      Inf
#> 11:      PosReals           ℝ+     0/1      Inf
#> 12:      NegReals           ℝ-    -Inf     -1/0
#> 13: ExtendedReals ℝ ∪ {-∞, +∞}    -Inf      Inf
#> 14:       Complex            ℂ    -Inf      Inf

And are constructed like any class

Reals$new() #> [1] "ℝ" Naturals$new()
#> [1] "ℕ0"

Note: We don’t have one set for non-negative and another for positive, this is determined by the zero argument

PosReals$new(zero = T)$liesInSetInterval(0)
#> [1] TRUE
PosReals$new(zero = F)$liesInSetInterval(0)
#> [1] FALSE

## SetInterval Operations

We also have available a few symbolic operations for sets

Reals$new() + Naturals$new()
#> [1] "{ℝ} ∪ {ℕ0}"
Reals$new() * Naturals$new()
#> [1] "{ℝ} × {ℕ0}"
PosReals$new() - Interval$new(-2, 5)
#> [1] "(5,+∞)"
Reals\$new()^2
#> [1] "ℝ^2"

## Summary

We have kept this very short as these are primarily meant to be used internally. We encourage you to look at the help pages in the documentation if you are interested in learning about sets further. In the next and final tutorial we conclude with running through how to construct your own custom distribution.