set6: R6 Mathematical Sets Interface

set6 makes use of the R6 object-oriented paradigm to introduce classes for important mathematical objects, including sets, tuples, and intervals (finite and infinite). Until now, the R (R Core Team, 2017) programming language has traditionally supported mathematical sets in one of two ways: 1. via the five set operation functions: union, intersect, setdiff, setequal, is.element; and 2. via the sets (Meyer & Hornik, 2009) package. set6 uses R6 (Chang, 2018) and has a clear class interface with minimal dependencies, which makes it the perfect dependency for any package that requires mathematical data types as R6 objects. Making use of design patterns (Gamma et al., 1996), such as wrappers and compositors, set6 allows for symbolic representation of sets to ensure maximum efficiency, and to provide neat and clear print methods.

set6 is currently being used in distr6 (Sonabend & Kiraly, 2019), which is an object-oriented probability distributions interface, that makes use of set6 for distribution and parameter support. Additional uses of set6 include representing infinite sets, and constructing assertions.
The speed and efficiency of R6 and Rcpp (Eddelbuettel & Francois, 2011) allows set6 to be a scalable and efficient interface. A focus on symbolic representation and neat printing methods means that set6 can accurately and clearly represent complicated sets. set6 has the ambitious long-term goal of being the only dependency package needed for object-oriented interfaces in R that require clear symbolic representations of mathematical sets.
Related software in R includes sets (Meyer & Hornik, 2009), which uses the S3 and S4 objectoriented paradigms to implement mathematical sets. Whilst sets and set6 have similar implemented features, as both offer multiple forms of sets (intervals, fuzzy, etc.) and with symbolic representation, the sets package does not offer lazy evaluation in set operations, which leads to significant overheads for large or possibly-infinite sets. Similar packages in other computing languages include: i) portion (Decan, 2020) in Python, which only supports intervals without generalisation to other mathematical sets; ii) IntervalSets.jl (Navelkar, 2016) in Julia, which is again limited to intervals though with good features for infix operators and inspection; iii) a variety of packages in the JuliaIntervals suite (https://juliapackages. com/u/juliaintervals), which primarily focus on rigorous arithmetic implementation; and iv) LazySets.jl (Forets & Schilling, 2018) and DomainSets.jl (Huybrechs, 2018) which both faciliate symbolic representation of sets and infinite intervals in Julia.
The example below demonstrates construction of a set and interval, comparisons of these, the set complement operator, and printing of the final result. Note the example does not use unicode printing but that this is possible within the package.
Key Design Principles 1. Maximum user-control over set operations -Users can select how operations act on sets, including a choice of associativity, lazy evaluation, and unicode printing. 2. Minimal dependencies -set6 has the goal of being a key dependency to any objectoriented package requiring representation of mathematical sets, for example for representing function inputs and supports. Therefore set6 is itself dependent on only three packages. 3. Inspectability and reactive user interface -set6 prioritises symbolic representation and lazy evaluation to allow for the package to be scalable and to fit into any other package. However it is ensured that this does not detract from a clear user interface, i.e. at all times it should be clear what an object contains both externally (how it prints) and internally (inspection methods). set6 allows sets to be queried in many different ways, including calling the elements in the set (if finite), finding the bounds of the set (if numeric), and listing properties and traits.  (Eddelbuettel & Francois, 2011) means that the computations are incredibly quick for sets and intervals of any size. 3. Representation of infinite sets -Symbolic representation and lazy evaluation allows infinite (or very large) sets and intervals to be constructed. This also allows operations such as powerset to be used without crashing the system. 4. Comparison of, possibly infinite, sets -Two Set objects can be compared to check if they are equal or (proper) sub/supersets. Infix operators allow quick and neat comparison. 5. Creation of composite sets from simpler classes -Common set operations, such as unions and complements are implemented, as well as products and exponents. These make use of S3 dispatch to allow quick calculation of composite sets. In line with design principle 4), lazy and greedy evaluation with symbolic representation allow for composite sets to be created, inspected, and printed, without ever needing to be evaluated themselves.

Software Availability
set6 is available on GitHub and CRAN. It can either be installed from GitHub using the devtools (Wickham et al., 2019) library or directly from CRAN with install.packages. The package uses the MIT open-source licence. Contributions, issues, feature requests, and general feedback can all be found and provided on the project GitHub. Full tutorials and further details are available on the project website.