Learn R Programming

⚠️There's a newer version (0.2.4) of this package.Take me there.

set6

What is set6?

set6 is an R6 upgrade to the sets package in R that includes:

  • Multi-dimensional sets
  • Tuples
  • Finite and infinite intervals
  • Fuzzy sets and tuples
  • Set operations including union, intersect, (asymmetric and symmetric) difference, and product
  • Symbolic representation of infinite sets including common special sets such as the Reals and Integers
  • ConditionalSets for defining sets according to logical conditions

Main Features

A Clear Inheritance Structure

# Sets require elements to be unique and order doesn't matter
Set$new(1, 2, 1) == Set$new(1, 2)
Set$new(1, 2) == Set$new(2, 1)

# But tuples can enforce these restrictions
Tuple$new(1, 2, 1) != Tuple$new(1, 2)
Tuple$new(1, 2) != Tuple$new(2, 1)

# Fuzzy sets and tuples extend sets further
f = FuzzySet$new(1, 0, 2, 0.6, 3, 1)
f$inclusion(1)
f$inclusion(2)
f$inclusion(3)

# Symbolic intervals provide a clean way to represent infinite sets
Interval$new()
# Different closure types and classes are possible
Interval$new(1, 7, type = "(]") # half-open
Interval$new(1, 7, class = "integer") == Set$new(1:7)

# And SpecialSets inheriting from these intervals
Reals$new()
PosRationals$new()

Set operations

# Union
Set$new(1, 4, "a", "b") + Set$new(5)
Interval$new(1, 5) + FuzzyTuple$new(1, 0.6)

# Power
Set$new(1:5)^2
# A symbolic representation is also possible
setpower(Set$new(1:5), power = 2, simplify = FALSE)
Reals$new()^5

# Product
Set$new(1,2) * Set$new(5, 6)
Interval$new(1,5) * Tuple$new(3)

# Intersection
Set$new(1:5) & Set$new(4:10)
ConditionalSet$new(function(x) x == 0) & Set$new(-2:2)
Interval$new(1, 10) & Set$new(5:6)

# Difference
Interval$new(1, 10) - Set$new(5)
Set$new(1:5) - Set$new(2:3)

Containedness and Comparators

Interval$new(1, 10)$contains(5)
# check multiple elements
Interval$new(1, 10)$contains(8:12)
# only return TRUE if all are TRUE
Interval$new(1, 10)$contains(8:12, all = TRUE)
# decide whether open bounds should be included
Interval$new(1, 10, type = "()")$contains(10, bound = TRUE)
Interval$new(1, 10, type = "()")$contains(10, bound = TRUE)

Interval$new(1, 5, class = "numeric")$equals(Set$new(1:5))
Interval$new(1, 5, class = "integer")$equals(Set$new(1:5))

Set$new(1) == FuzzySet$new(1, 1)

# proper subsets
Set$new(1:3)$isSubset(Set$new(1), proper = TRUE)
Set$new(1) < Set$new(1:3)

# (non-proper) subsets
Set$new(1:3)$isSubset(Set$new(1:3), proper = FALSE)
Set$new(1:3) <= Set$new(1:3)

# multi-dimensional checks
x = PosReals$new()^2
x$contains(list(Tuple$new(1, 1), Tuple$new(-2, 3))

Usage

The primary use-cases of set6 are:

  1. Upgrading sets Extend the R sets package to R6, which allows for generalised Set objects with a clear inheritance structure. As well as adding features including symbolic representation of infinite sets, and cartesian products.
  2. Defining parameter interfaces All objects inheriting from the Set parent class include methods equals and contains, which are used to check if two sets are equal or if elements lie in the given set. This makes set6 ideal for parameter interfaces in which a range of values (possibly multi-dimensional or of mixed types) need to be defined.

Short-term development plans

Whilst the set6 API is stable, it is considered 'maturing', and therefore whilst there are no plans for major updates, these may still occur. There are a few features and refactoring we plan on implementing before we consider the package to be in its first complete version. These mainly include

  • Finalising all methods and fields - some are missing or possibly inaccurate for some wrappers. For example the cardinality of ComplementSets is imprecise at the moment.
  • We are considering adding a simplify method to wrappers to reduce classes inheriting from SetWrapper to simpler sets. This allows users to perform operations with simplify = FALSE and then to change their mind.
  • There are some inefficient loops implemented that will need refactoring for more efficient code.
  • Adding more tutorials to make the interface easier for beginners, especially people new to R6

At a later stage we may consider adding Venn diagrams for visualisation of sets and intervals, but this is very low priority.

Contributing

As set6 is in its early stages, contributions are very welcome. If you have any ideas for good features please open an issue or create a pull request. Otherwise bug reports are very appreciated if you stumble across any broken code, these can be posted to the issue tracker. For updates on set6 follow/star this repo.

Installation

A CRAN release is expected by the end of November. Until then the latest stable build can be installed via

remotes::install_github("RaphaelS1/set6")

Copy Link

Version

Install

install.packages('set6')

Monthly Downloads

24

Version

0.1.0

License

MIT + file LICENSE

Maintainer

Raphael Sonabend

Last Published

December 23rd, 2019

Functions in set6 (0.1.0)

PosReals

Set of Positive Real Numbers
PosRationals

Set of Positive Rational Numbers
PosNaturals

Set of Positive Natural Numbers
Tuple

Mathematical Tuple
PowersetSet

Set of Powersets
as.FuzzySet

Coercion to R6 FuzzySet/FuzzyTuple
alphaCut

Get Elements in FuzzySet with Membership Greater than Alpha
UnionSet

Set of Unions
Integers

Set of Integers
ProductSet

Set of Products
NegRationals

Set of Negative Rational Numbers
NegIntegers

Set of Negative Integers
class

Class of Set
Rationals

Set of Rational Numbers
setintersect

Intersection of Two Sets
condition

ConditionalSet Condition
powerset

Calculate a Set's Powerset
properties

Set Properties
setpower

Power of a Set
testClosedBelow

assert/check/test/ClosedBelow
as.Interval

Coercion to R6 Interval
NegReals

Set of Negative Real Numbers
PosIntegers

Set of Positive Integers
Reals

Set of Real Numbers
isSubset

Test If Two Sets Are Subsets
contains

Are Elements Contained in the Set?
core

Get Core of FuzzySet
as.Set

Coercion to R6 Set/Tuple
length

Number of Elements in the Set
inclusion

Get Inclusion Level of Element In FuzzySet
addedSet

Get Added Set in Wrapper
isSubinterval

Test If Two Intervals Are Subintervals
absComplement

Absolute Complement of a Set
Set

Mathematical Set
membership

Get Membership of Element in FuzzySet
setcomplement

(Relative) Complement of Two Sets
max

Set Maximum
set6News

Show set6 NEWS.md File
testFinite

assert/check/test/Finite
elements

Set Elements
testSetList

assert/check/test/SetList
testTuple

assert/check/test/Tuple
testConditionalSet

assert/check/test/ConditionalSet
min

Set Minimum
power

Get The Power of ExponentSet
range

Numeric Range of Set
set6-package

set6: R6 Mathematical Sets Interface
equals

Are Two Sets Equal?
setproduct

Cartesian Product of Sets
testFuzzy

assert/check/test/Fuzzy
setunion

Union of Sets
testClosedAbove

assert/check/test/ClosedAbove
strprint

String Representation For Print
testClosed

assert/check/test/Closed
testInterval

assert/check/test/Interval
testSet

assert/check/test/Set
lower

Lower Limit of Set
support

Get Support of FuzzySet
listSpecialSets

Lists Implemented R6 Special Sets
subtractedSet

Get Subtracted Set in Wrapper
testFuzzySet

assert/check/test/FuzzySet
setsymdiff

Symmetric Difference of Two Sets
type

Set Type
traits

Set Traits
testFuzzyTuple

assert/check/test/FuzzyTuple
universe

Universe of a Set
upper

Upper Limit of Set
testCrisp

assert/check/test/Crisp
wrappedSets

Get Sets in Wrapper
useUnicode

Get/Set Unicode Printing Method
testEmpty

assert/check/test/Empty
ComplementSet

Set of Complements
FuzzyTuple

Mathematical Fuzzy Tuple
ExtendedReals

Set of Extended Real Numbers
Interval

Mathematical Finite or Infinite Interval
Naturals

Set of Natural Numbers
ExponentSet

Set of Exponentiations
ConditionalSet

Mathematical Set of Conditions
Complex

Set of Complex Numbers
FuzzySet

Mathematical Fuzzy Set