Title: | R6 Mathematical Sets Interface |
---|---|
Description: | An object-oriented package for mathematical sets, upgrading the current gold-standard {sets}. Many forms of mathematical sets are implemented, including (countably finite) sets, tuples, intervals (countably infinite or uncountable), and fuzzy variants. Wrappers extend functionality by allowing symbolic representations of complex operations on sets, including unions, (cartesian) products, exponentiation, and differences (asymmetric and symmetric). |
Authors: | Raphael Sonabend [aut, cre] , Franz Kiraly [aut] |
Maintainer: | Raphael Sonabend <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.6 |
Built: | 2024-11-07 02:41:17 UTC |
Source: | https://github.com/xoopR/set6 |
set6 upgrades the {sets}
package to R6. Many forms of mathematical sets are implemented,
including (countably finite) sets, tuples, intervals (countably infinite or uncountable),
and fuzzy variants. Wrappers extend functionality by allowing symbolic representations of
complex operations on sets, including unions, (cartesian) products, exponentiation, and
differences (asymmetric and symmetric).
The main features of set6 are:
Object-oriented programming, which allows a clear inheritance structure for Sets, Intervals, Tuples, and other variants.
Set operations and wrappers for both explicit and symbolic representations for algebra of sets.
Methods for assertions and comparison checks, including subsets, equality, and containedness.
To learn more about set6, start with the set6 vignette:
vignette("set6", "set6")
And for more advanced usage see the complete tutorials at
Maintainer: Raphael Sonabend [email protected] (ORCID)
Authors:
Franz Kiraly [email protected]
Useful links:
Report bugs at https://github.com/xoopR/set6/issues
FuzzySet
/FuzzyTuple
Coerces object to an R6 FuzzySet/FuzzyTuple
as.FuzzySet(object) ## S3 method for class 'numeric' as.FuzzySet(object) ## S3 method for class 'list' as.FuzzySet(object) ## S3 method for class 'matrix' as.FuzzySet(object) ## S3 method for class 'data.frame' as.FuzzySet(object) ## S3 method for class 'Set' as.FuzzySet(object) ## S3 method for class 'FuzzySet' as.FuzzySet(object) ## S3 method for class 'Interval' as.FuzzySet(object) ## S3 method for class 'ConditionalSet' as.FuzzySet(object) as.FuzzyTuple(object) ## S3 method for class 'numeric' as.FuzzyTuple(object) ## S3 method for class 'list' as.FuzzyTuple(object) ## S3 method for class 'matrix' as.FuzzyTuple(object) ## S3 method for class 'data.frame' as.FuzzyTuple(object) ## S3 method for class 'Set' as.FuzzyTuple(object) ## S3 method for class 'FuzzySet' as.FuzzyTuple(object) ## S3 method for class 'Interval' as.FuzzyTuple(object) ## S3 method for class 'ConditionalSet' as.FuzzyTuple(object) as.FuzzyMultiset(object) ## S3 method for class 'numeric' as.FuzzyMultiset(object) ## S3 method for class 'list' as.FuzzyMultiset(object) ## S3 method for class 'matrix' as.FuzzyMultiset(object) ## S3 method for class 'data.frame' as.FuzzyMultiset(object) ## S3 method for class 'Set' as.FuzzyMultiset(object) ## S3 method for class 'FuzzySet' as.FuzzyMultiset(object) ## S3 method for class 'Interval' as.FuzzyMultiset(object) ## S3 method for class 'ConditionalSet' as.FuzzyMultiset(object)
as.FuzzySet(object) ## S3 method for class 'numeric' as.FuzzySet(object) ## S3 method for class 'list' as.FuzzySet(object) ## S3 method for class 'matrix' as.FuzzySet(object) ## S3 method for class 'data.frame' as.FuzzySet(object) ## S3 method for class 'Set' as.FuzzySet(object) ## S3 method for class 'FuzzySet' as.FuzzySet(object) ## S3 method for class 'Interval' as.FuzzySet(object) ## S3 method for class 'ConditionalSet' as.FuzzySet(object) as.FuzzyTuple(object) ## S3 method for class 'numeric' as.FuzzyTuple(object) ## S3 method for class 'list' as.FuzzyTuple(object) ## S3 method for class 'matrix' as.FuzzyTuple(object) ## S3 method for class 'data.frame' as.FuzzyTuple(object) ## S3 method for class 'Set' as.FuzzyTuple(object) ## S3 method for class 'FuzzySet' as.FuzzyTuple(object) ## S3 method for class 'Interval' as.FuzzyTuple(object) ## S3 method for class 'ConditionalSet' as.FuzzyTuple(object) as.FuzzyMultiset(object) ## S3 method for class 'numeric' as.FuzzyMultiset(object) ## S3 method for class 'list' as.FuzzyMultiset(object) ## S3 method for class 'matrix' as.FuzzyMultiset(object) ## S3 method for class 'data.frame' as.FuzzyMultiset(object) ## S3 method for class 'Set' as.FuzzyMultiset(object) ## S3 method for class 'FuzzySet' as.FuzzyMultiset(object) ## S3 method for class 'Interval' as.FuzzyMultiset(object) ## S3 method for class 'ConditionalSet' as.FuzzyMultiset(object)
object |
object to coerce |
as.FuzzySet.list
- Assumes list
has two items, named elements
and membership
,
and that they are ordered to be corresponding.
as.FuzzySet.matrix
- Assumes first column corresponds to elements
and second column
corresponds to their respective membership
.
as.FuzzySet.data.frame
- First checks to see if one column is called elements
and the
other is called membership
. If not then uses as.FuzzySet.matrix
.
as.FuzzySet.Set
- Creates a FuzzySet by assuming Set elements all have membership
equal to .
as.FuzzySet.Interval
- First tries coercion via as.Set.Interval then uses
as.FuzzySet.Set.
Other coercions:
as.Interval()
,
as.Set()
Interval
Coerces object to an R6 Interval.
as.Interval(object) ## S3 method for class 'Set' as.Interval(object) ## S3 method for class 'Interval' as.Interval(object) ## S3 method for class 'list' as.Interval(object) ## S3 method for class 'data.frame' as.Interval(object) ## S3 method for class 'matrix' as.Interval(object) ## S3 method for class 'numeric' as.Interval(object) ## S3 method for class 'ConditionalSet' as.Interval(object)
as.Interval(object) ## S3 method for class 'Set' as.Interval(object) ## S3 method for class 'Interval' as.Interval(object) ## S3 method for class 'list' as.Interval(object) ## S3 method for class 'data.frame' as.Interval(object) ## S3 method for class 'matrix' as.Interval(object) ## S3 method for class 'numeric' as.Interval(object) ## S3 method for class 'ConditionalSet' as.Interval(object)
object |
object to coerce |
as.Interval.list/as.Interval.data.frame
- Assumes the list
/data.frame
has
named items/columns: lower, upper, type, class
.
as.Interval.numeric
- If the numeric
vector is a continuous interval with no breaks then
coerces to an Interval with: lower = min(object), upper = max(object), class = "integer"
.
Ordering is ignored.
as.Interval.matrix
- Tries coercion via as.Interval.numeric on the first column of the
matrix.
as.Interval.Set
- First tries coercion via as.Interval.numeric, if possible wraps result
in a Set.
as.Interval.FuzzySet
- Tries coercion via as.Interval.Set on the support of the FuzzySet.
Other coercions:
as.FuzzySet()
,
as.Set()
Set
/Tuple
Coerces object to an R6 Set/Tuple
as.Set(object) ## Default S3 method: as.Set(object) ## S3 method for class 'numeric' as.Set(object) ## S3 method for class 'list' as.Set(object) ## S3 method for class 'matrix' as.Set(object) ## S3 method for class 'data.frame' as.Set(object) ## S3 method for class 'Set' as.Set(object) ## S3 method for class 'FuzzySet' as.Set(object) ## S3 method for class 'Interval' as.Set(object) ## S3 method for class 'ConditionalSet' as.Set(object) as.Tuple(object) ## Default S3 method: as.Tuple(object) ## S3 method for class 'numeric' as.Tuple(object) ## S3 method for class 'list' as.Tuple(object) ## S3 method for class 'matrix' as.Tuple(object) ## S3 method for class 'data.frame' as.Tuple(object) ## S3 method for class 'FuzzySet' as.Tuple(object) ## S3 method for class 'Set' as.Tuple(object) ## S3 method for class 'Interval' as.Tuple(object) ## S3 method for class 'ConditionalSet' as.Tuple(object) as.Multiset(object) ## Default S3 method: as.Multiset(object) ## S3 method for class 'numeric' as.Multiset(object) ## S3 method for class 'list' as.Multiset(object) ## S3 method for class 'matrix' as.Multiset(object) ## S3 method for class 'data.frame' as.Multiset(object) ## S3 method for class 'FuzzySet' as.Multiset(object) ## S3 method for class 'Set' as.Multiset(object) ## S3 method for class 'Interval' as.Multiset(object) ## S3 method for class 'ConditionalSet' as.Multiset(object)
as.Set(object) ## Default S3 method: as.Set(object) ## S3 method for class 'numeric' as.Set(object) ## S3 method for class 'list' as.Set(object) ## S3 method for class 'matrix' as.Set(object) ## S3 method for class 'data.frame' as.Set(object) ## S3 method for class 'Set' as.Set(object) ## S3 method for class 'FuzzySet' as.Set(object) ## S3 method for class 'Interval' as.Set(object) ## S3 method for class 'ConditionalSet' as.Set(object) as.Tuple(object) ## Default S3 method: as.Tuple(object) ## S3 method for class 'numeric' as.Tuple(object) ## S3 method for class 'list' as.Tuple(object) ## S3 method for class 'matrix' as.Tuple(object) ## S3 method for class 'data.frame' as.Tuple(object) ## S3 method for class 'FuzzySet' as.Tuple(object) ## S3 method for class 'Set' as.Tuple(object) ## S3 method for class 'Interval' as.Tuple(object) ## S3 method for class 'ConditionalSet' as.Tuple(object) as.Multiset(object) ## Default S3 method: as.Multiset(object) ## S3 method for class 'numeric' as.Multiset(object) ## S3 method for class 'list' as.Multiset(object) ## S3 method for class 'matrix' as.Multiset(object) ## S3 method for class 'data.frame' as.Multiset(object) ## S3 method for class 'FuzzySet' as.Multiset(object) ## S3 method for class 'Set' as.Multiset(object) ## S3 method for class 'Interval' as.Multiset(object) ## S3 method for class 'ConditionalSet' as.Multiset(object)
object |
object to coerce |
as.Set.default
- Creates a Set using the object as the elements.
as.Set.list
- Creates a Set for each element in list
.
as.Set.matrix/as.Set.data.frame
- Creates a Set for each column in matrix/data.frame
.
as.Set.FuzzySet
- Creates a Set from the support of the FuzzySet.
as.Set.Interval
- If the interval has finite cardinality then creates a Set from the
Interval elements.
Other coercions:
as.FuzzySet()
,
as.Interval()
ComplementSet class for symbolic complement of mathematical sets.
The purpose of this class is to provide a symbolic representation for the complement of sets that cannot be represented in a simpler class. Whilst this is not an abstract class, it is not recommended to construct this class directly but via the set operation methods.
set6::Set
-> set6::SetWrapper
-> ComplementSet
elements
Returns the elements in the object.
length
Returns the number of elements in the object.
addedSet
For the ComplementSet
wrapper, X-Y
, returns the set X
.
subtractedSet
For the ComplementSet
wrapper, X-Y
, returns the set Y
.
new()
Create a new ComplementSet
object. It is not recommended to construct this class directly.
ComplementSet$new(addset, subtractset, lower = NULL, upper = NULL, type = NULL)
A new ComplementSet
object.
strprint()
Creates a printable representation of the object.
ComplementSet$strprint(n = 2)
n
numeric. Number of elements to display on either side of ellipsis when printing.
A character string representing the object.
contains()
Tests if elements x
are contained in self
.
ComplementSet$contains(x, all = FALSE, bound = FALSE)
If all == TRUE
then returns TRUE
if all x
are contained in self
, otherwise FALSE
.
If all == FALSE
returns a vector of logicals corresponding to the length of x
, representing
if each is contained in self
. If bound == TRUE
then an element is contained in self
if it
is on or within the (possibly-open) bounds of self
, otherwise TRUE
only if the element is within
self
or the bounds are closed.
clone()
The objects of this class are cloneable with this method.
ComplementSet$clone(deep = FALSE)
deep
Whether to make a deep clone.
Set operations: setunion, setproduct, setpower, setcomplement, setsymdiff, powerset, setintersect
Other wrappers:
ExponentSet
,
PowersetSet
,
ProductSet
,
UnionSet
The mathematical set of complex numbers, defined as the the set of reals with possibly imaginary components. i.e.
where is the set of reals.
There is no inherent ordering in the set of complex numbers, hence only the contains
method is implemented here.
set6::Set
-> Complex
new()
Create a new Complex
object.
Complex$new()
A new Complex
object.
contains()
Tests to see if x
is contained in the Set.
Complex$contains(x, all = FALSE, bound = NULL)
x
any. Object or vector of objects to test.
all
logical. If FALSE
tests each x
separately. Otherwise returns TRUE
only if all x
pass test.
bound
logical.
x
can be of any type, including a Set itself. x
should be a tuple if
checking to see if it lies within a set of dimension greater than one. To test for multiple x
at the same time, then provide these as a list.
If all = TRUE
then returns TRUE
if all x
are contained in the Set
, otherwise
returns a vector of logicals. For Intervals, bound
is used to specify if elements lying on the
(possibly open) boundary of the interval are considered contained (bound = TRUE
) or not (bound = FALSE
).
If all
is TRUE
then returns TRUE
if all elements of x
are contained in the Set
, otherwise
FALSE.
If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
The infix operator %inset%
is available to test if x
is an element in the Set
,
see examples.
equals()
Tests if two sets are equal.
Complex$equals(x, all = FALSE)
If all
is TRUE
then returns TRUE
if all x
are equal to the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
Infix operators can be used for:
Equal | == |
Not equal | != |
# Equals Set$new(1,2)$equals(Set$new(5,6)) Set$new(1,2)$equals(Interval$new(1,2)) Set$new(1,2) == Interval$new(1,2, class = "integer") # Not equal !Set$new(1,2)$equals(Set$new(1,2)) Set$new(1,2) != Set$new(1,5)
isSubset()
Test if one set is a (proper) subset of another
Complex$isSubset(x, proper = FALSE, all = FALSE)
x
any. Object or vector of objects to test.
proper
logical. If TRUE
tests for proper subsets.
all
logical. If FALSE
tests each x
separately. Otherwise returns TRUE
only if all x
pass test.
If using the method directly, and not via one of the operators then the additional boolean
argument proper
can be used to specify testing of subsets or proper subsets. A Set is a proper
subset of another if it is fully contained by the other Set (i.e. not equal to) whereas a Set is a
(non-proper) subset if it is fully contained by, or equal to, the other Set.
When calling $isSubset
on objects inheriting from Interval, the method treats the interval as if
it is a Set, i.e. ordering and class are ignored. Use $isSubinterval
to test if one interval
is a subinterval of another.
Infix operators can be used for:
Subset | < |
Proper Subset | <= |
Superset | > |
Proper Superset | >=
|
Every Set
is a subset of a Universal
. No Set
is a super set of a Universal
,
and only a Universal
is not a proper subset of a Universal
.
If all
is TRUE
then returns TRUE
if all x
are subsets of the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
Set$new(1,2,3)$isSubset(Set$new(1,2), proper = TRUE) Set$new(1,2) < Set$new(1,2,3) # proper subset c(Set$new(1,2,3), Set$new(1)) < Set$new(1,2,3) # not proper Set$new(1,2,3) <= Set$new(1,2,3) # proper
strprint()
Creates a printable representation of the object.
Complex$strprint(n = 2)
n
numeric. Number of elements to display on either side of ellipsis when printing.
A character string representing the object.
clone()
The objects of this class are cloneable with this method.
Complex$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other special sets:
ExtendedReals
,
Integers
,
Logicals
,
Naturals
,
NegIntegers
,
NegRationals
,
NegReals
,
PosIntegers
,
PosNaturals
,
PosRationals
,
PosReals
,
Rationals
,
Reals
,
Universal
## ------------------------------------------------ ## Method `Complex$equals` ## ------------------------------------------------ # Equals Set$new(1,2)$equals(Set$new(5,6)) Set$new(1,2)$equals(Interval$new(1,2)) Set$new(1,2) == Interval$new(1,2, class = "integer") # Not equal !Set$new(1,2)$equals(Set$new(1,2)) Set$new(1,2) != Set$new(1,5) ## ------------------------------------------------ ## Method `Complex$isSubset` ## ------------------------------------------------ Set$new(1,2,3)$isSubset(Set$new(1,2), proper = TRUE) Set$new(1,2) < Set$new(1,2,3) # proper subset c(Set$new(1,2,3), Set$new(1)) < Set$new(1,2,3) # not proper Set$new(1,2,3) <= Set$new(1,2,3) # proper
## ------------------------------------------------ ## Method `Complex$equals` ## ------------------------------------------------ # Equals Set$new(1,2)$equals(Set$new(5,6)) Set$new(1,2)$equals(Interval$new(1,2)) Set$new(1,2) == Interval$new(1,2, class = "integer") # Not equal !Set$new(1,2)$equals(Set$new(1,2)) Set$new(1,2) != Set$new(1,5) ## ------------------------------------------------ ## Method `Complex$isSubset` ## ------------------------------------------------ Set$new(1,2,3)$isSubset(Set$new(1,2), proper = TRUE) Set$new(1,2) < Set$new(1,2,3) # proper subset c(Set$new(1,2,3), Set$new(1)) < Set$new(1,2,3) # not proper Set$new(1,2,3) <= Set$new(1,2,3) # proper
A mathematical set defined by one or more logical conditions.
Conditional sets are a useful tool for symbolically defining possibly infinite sets. They can be combined
using standard 'and', &
, and 'or', |
, operators.
set6::Set
-> ConditionalSet
condition
Returns the condition defining the ConditionalSet.
class
Returns argclass
, see $new
.
elements
Returns NA
.
new()
Create a new ConditionalSet
object.
ConditionalSet$new(condition = function(x) TRUE, argclass = NULL)
condition
function. Defines the set, see details.
argclass
list. Optional list of sets that the function arguments live in, see details.
The condition
should be given as a function that when evaluated returns
either TRUE
or FALSE
. Further constraints can be given by providing the universe of the
function arguments as Sets, if these are not given then Universal is assumed.
See examples. Defaults construct the Universal set.
A new ConditionalSet
object.
contains()
Tests to see if x
is contained in the Set.
ConditionalSet$contains(x, all = FALSE, bound = NULL)
x
any. Object or vector of objects to test.
all
logical. If FALSE
tests each x
separately. Otherwise returns TRUE
only if all x
pass test.
bound
ignored, added for consistency.
x
can be of any type, including a Set itself. x
should be a tuple if
checking to see if it lies within a set of dimension greater than one. To test for multiple x
at the same time, then provide these as a list.
If all = TRUE
then returns TRUE
if all x
are contained in the Set
, otherwise
returns a vector of logicals.
An element is contained in a ConditionalSet
if it returns TRUE
as an argument in the defining function.
For sets that are defined with a function that takes multiple arguments, a Tuple should be
passed to x
.
If all
is TRUE
then returns TRUE
if all elements of x
are contained in the Set
, otherwise
FALSE.
If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
The infix operator %inset%
is available to test if x
is an element in the Set
,
see examples.
# Set of positives s = ConditionalSet$new(function(x) x > 0) s$contains(list(1,-1)) # Set via equality s = ConditionalSet$new(function(x, y) x + y == 2) s$contains(list(Set$new(2, 0), Set$new(0, 2))) # Tuples are recommended when using contains as they allow non-unique elements s = ConditionalSet$new(function(x, y) x + y == 4) \dontrun{ s$contains(Set$new(2, 2)) # Errors as Set$new(2,2) == Set$new(2) } # Set of Positive Naturals s = ConditionalSet$new(function(x) TRUE, argclass = list(x = PosNaturals$new())) s$contains(list(-2, 2))
equals()
Tests if two sets are equal.
ConditionalSet$equals(x, all = FALSE)
Two sets are equal if they contain the same elements. Infix operators can be used for:
Equal | == |
Not equal | != |
If all
is TRUE
then returns TRUE
if all x
are equal to the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
strprint()
Creates a printable representation of the object.
ConditionalSet$strprint(n = NULL)
n
ignored, added for consistency.
A character string representing the object.
summary()
See strprint
.
ConditionalSet$summary(n = NULL)
n
ignored, added for consistency.
isSubset()
Currently undefined for ConditionalSet
s.
ConditionalSet$isSubset(x, proper = FALSE, all = FALSE)
x
ignored, added for consistency.
proper
ignored, added for consistency.
all
ignored, added for consistency.
clone()
The objects of this class are cloneable with this method.
ConditionalSet$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other sets:
FuzzyMultiset
,
FuzzySet
,
FuzzyTuple
,
Interval
,
Multiset
,
Set
,
Tuple
# Set of Positive Naturals s <- ConditionalSet$new(function(x) TRUE, argclass = list(x = PosNaturals$new())) ## ------------------------------------------------ ## Method `ConditionalSet$contains` ## ------------------------------------------------ # Set of positives s = ConditionalSet$new(function(x) x > 0) s$contains(list(1,-1)) # Set via equality s = ConditionalSet$new(function(x, y) x + y == 2) s$contains(list(Set$new(2, 0), Set$new(0, 2))) # Tuples are recommended when using contains as they allow non-unique elements s = ConditionalSet$new(function(x, y) x + y == 4) ## Not run: s$contains(Set$new(2, 2)) # Errors as Set$new(2,2) == Set$new(2) ## End(Not run) # Set of Positive Naturals s = ConditionalSet$new(function(x) TRUE, argclass = list(x = PosNaturals$new())) s$contains(list(-2, 2))
# Set of Positive Naturals s <- ConditionalSet$new(function(x) TRUE, argclass = list(x = PosNaturals$new())) ## ------------------------------------------------ ## Method `ConditionalSet$contains` ## ------------------------------------------------ # Set of positives s = ConditionalSet$new(function(x) x > 0) s$contains(list(1,-1)) # Set via equality s = ConditionalSet$new(function(x, y) x + y == 2) s$contains(list(Set$new(2, 0), Set$new(0, 2))) # Tuples are recommended when using contains as they allow non-unique elements s = ConditionalSet$new(function(x, y) x + y == 4) ## Not run: s$contains(Set$new(2, 2)) # Errors as Set$new(2,2) == Set$new(2) ## End(Not run) # Set of Positive Naturals s = ConditionalSet$new(function(x) TRUE, argclass = list(x = PosNaturals$new())) s$contains(list(-2, 2))
Operator for $contains
methods. See Set$contains
for full details.
Operators can be used for:
Name | Description | Operator |
Contains | x contains y |
y $inset$ x |
x %inset% y
x %inset% y
x , y
|
Operator for $equals
methods. See Set$equals
for full details.
Operators can be used for:
Name | Description | Operator |
Equal | x equals y |
== |
Not Equal | x does not equal y |
!= |
## S3 method for class 'Set' x == y ## S3 method for class 'Set' x != y
## S3 method for class 'Set' x == y ## S3 method for class 'Set' x != y
x , y
|
ExponentSet class for symbolic exponentiation of mathematical sets.
The purpose of this class is to provide a symbolic representation for the exponentiation of sets that cannot be represented in a simpler class. Whilst this is not an abstract class, it is not recommended to construct this class directly but via the set operation methods.
set6::Set
-> set6::SetWrapper
-> set6::ProductSet
-> ExponentSet
power
Returns the power that the wrapped set is raised to.
new()
Create a new ExponentSet
object. It is not recommended to construct this
class directly.
ExponentSet$new(set, power)
set
Set to wrap.
power
numeric. Power to raise Set to.
A new ExponentSet
object.
strprint()
Creates a printable representation of the object.
ExponentSet$strprint(n = 2)
n
numeric. Number of elements to display on either side of ellipsis when printing.
A character string representing the object.
contains()
Tests if elements x
are contained in self
.
ExponentSet$contains(x, all = FALSE, bound = FALSE)
If all == TRUE
then returns TRUE
if all x
are contained in self
,
otherwise FALSE
. If all == FALSE
returns a vector of logicals corresponding to the
length of x
, representing if each is contained in self
. If bound == TRUE
then an
element is contained in self
if it is on or within the (possibly-open) bounds of self
,
otherwise TRUE
only if the element is within self
or the bounds are closed.
clone()
The objects of this class are cloneable with this method.
ExponentSet$clone(deep = FALSE)
deep
Whether to make a deep clone.
Set operations: setunion, setproduct, setpower, setcomplement, setsymdiff, powerset, setintersect
Other wrappers:
ComplementSet
,
PowersetSet
,
ProductSet
,
UnionSet
The mathematical set of extended real numbers,
defined as the union of the set of reals with . i.e.
where is the set of reals.
set6::Set
-> set6::Interval
-> set6::SpecialSet
-> set6::Reals
-> ExtendedReals
new()
Create a new ExtendedReals
object.
ExtendedReals$new()
A new ExtendedReals
object.
clone()
The objects of this class are cloneable with this method.
ExtendedReals$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other special sets:
Complex
,
Integers
,
Logicals
,
Naturals
,
NegIntegers
,
NegRationals
,
NegReals
,
PosIntegers
,
PosNaturals
,
PosRationals
,
PosReals
,
Rationals
,
Reals
,
Universal
A general FuzzyMultiset object for mathematical fuzzy multisets, inheriting from FuzzySet
.
Fuzzy multisets generalise standard mathematical multisets to allow for fuzzy relationships. Whereas a
standard, or crisp, multiset assumes that an element is either in a multiset or not, a fuzzy multiset allows
an element to be in a multiset to a particular degree, known as the membership function, which
quantifies the inclusion of an element by a number in [0, 1]. Thus a (crisp) multiset is a
fuzzy multiset where all elements have a membership equal to . Similarly to Multisets, elements
do not need to be unique.
set6::Set
-> set6::FuzzySet
-> FuzzyMultiset
equals()
Tests if two sets are equal.
FuzzyMultiset$equals(x, all = FALSE)
Two fuzzy sets are equal if they contain the same elements with the same memberships and in the same order. Infix operators can be used for:
Equal | == |
Not equal | != |
If all
is TRUE
then returns TRUE
if all x
are equal to the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
isSubset()
Test if one set is a (proper) subset of another
FuzzyMultiset$isSubset(x, proper = FALSE, all = FALSE)
x
any. Object or vector of objects to test.
proper
logical. If TRUE
tests for proper subsets.
all
logical. If FALSE
tests each x
separately. Otherwise returns TRUE
only if all x
pass test.
If using the method directly, and not via one of the operators then the additional boolean
argument proper
can be used to specify testing of subsets or proper subsets. A Set is a proper
subset of another if it is fully contained by the other Set (i.e. not equal to) whereas a Set is a
(non-proper) subset if it is fully contained by, or equal to, the other Set.
Infix operators can be used for:
Subset | < |
Proper Subset | <= |
Superset | > |
Proper Superset | >=
|
If all
is TRUE
then returns TRUE
if all x
are subsets of the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
alphaCut()
The alpha-cut of a fuzzy set is defined as the set
where is an element in the fuzzy set,
, and
is the corresponding membership.
FuzzyMultiset$alphaCut(alpha, strong = FALSE, create = FALSE)
alpha
numeric in [0, 1] to determine which elements to return
strong
logical, if FALSE
(default) then includes elements greater than or equal to alpha, otherwise only strictly greater than
create
logical, if FALSE
(default) returns the elements in the alpha cut, otherwise returns a crisp set of the elements
Elements in FuzzyMultiset or a Set of the elements.
clone()
The objects of this class are cloneable with this method.
FuzzyMultiset$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other sets:
ConditionalSet
,
FuzzySet
,
FuzzyTuple
,
Interval
,
Multiset
,
Set
,
Tuple
# Different constructors FuzzyMultiset$new(1, 0.5, 2, 1, 3, 0) FuzzyMultiset$new(elements = 1:3, membership = c(0.5, 1, 0)) # Crisp sets are a special case FuzzyMultiset # Note membership defaults to full membership FuzzyMultiset$new(elements = 1:5) == Multiset$new(1:5) f <- FuzzyMultiset$new(1, 0.2, 2, 1, 3, 0) f$membership() f$alphaCut(0.3) f$core() f$inclusion(0) f$membership(0) f$membership(1) # Elements can be duplicated, and with different memberships, # although this is not necessarily sensible. FuzzyMultiset$new(1, 0.1, 1, 1) # Like FuzzySets, ordering does not matter. FuzzyMultiset$new(1, 0.1, 2, 0.2) == FuzzyMultiset$new(2, 0.2, 1, 0.1)
# Different constructors FuzzyMultiset$new(1, 0.5, 2, 1, 3, 0) FuzzyMultiset$new(elements = 1:3, membership = c(0.5, 1, 0)) # Crisp sets are a special case FuzzyMultiset # Note membership defaults to full membership FuzzyMultiset$new(elements = 1:5) == Multiset$new(1:5) f <- FuzzyMultiset$new(1, 0.2, 2, 1, 3, 0) f$membership() f$alphaCut(0.3) f$core() f$inclusion(0) f$membership(0) f$membership(1) # Elements can be duplicated, and with different memberships, # although this is not necessarily sensible. FuzzyMultiset$new(1, 0.1, 1, 1) # Like FuzzySets, ordering does not matter. FuzzyMultiset$new(1, 0.1, 2, 0.2) == FuzzyMultiset$new(2, 0.2, 1, 0.1)
A general FuzzySet object for mathematical fuzzy sets, inheriting from Set
.
Fuzzy sets generalise standard mathematical sets to allow for fuzzy relationships. Whereas a
standard, or crisp, set assumes that an element is either in a set or not, a fuzzy set allows
an element to be in a set to a particular degree, known as the membership function, which
quantifies the inclusion of an element by a number in [0, 1]. Thus a (crisp) set is a
fuzzy set where all elements have a membership equal to . Similarly to Sets, elements
must be unique and the ordering does not matter, to establish order and non-unique elements,
FuzzyTuples can be used.
set6::Set
-> FuzzySet
new()
Create a new FuzzySet
object.
FuzzySet$new( ..., elements = NULL, membership = rep(1, length(elements)), class = NULL )
...
Alternating elements and membership, see details.
elements
Elements in the set, see details.
membership
Corresponding membership of the elements, see details.
class
Optional string naming a class that if supplied gives the set the typed
property.
FuzzySet
s can be constructed in one of two ways, either by supplying the elements and their
membership in alternate order, or by providing a list of elements to elements
and a list of
respective memberships to membership
, see examples. If the class
argument is non-NULL
,
then all elements will be coerced to the given class in construction, and if elements of a
different class are added these will either be rejected or coerced.
A new FuzzySet
object.
strprint()
Creates a printable representation of the object.
FuzzySet$strprint(n = 2)
n
numeric. Number of elements to display on either side of ellipsis when printing.
A character string representing the object.
membership()
Returns the membership, i.e. value in [0, 1], of either the given element(s) or all elements in the fuzzy set.
FuzzySet$membership(element = NULL)
element
element or list of element in the set
, if NULL
returns membership of all elements
For FuzzySet
s this is straightforward and returns the membership of the given element(s),
however in FuzzyTuple
s and FuzzyMultiset
s when an element may be duplicated, the function returns the membership of
all instances of the element.
Value, or list of values, in [0, 1].
f = FuzzySet$new(1, 0.1, 2, 0.5, 3, 1) f$membership() f$membership(2) f$membership(list(1, 2))
alphaCut()
The alpha-cut of a fuzzy set is defined as the set
where is an element in the fuzzy set,
, and
is the corresponding membership.
FuzzySet$alphaCut(alpha, strong = FALSE, create = FALSE)
alpha
numeric in [0, 1] to determine which elements to return
strong
logical, if FALSE
(default) then includes elements greater than or equal to alpha, otherwise only strictly greater than
create
logical, if FALSE
(default) returns the elements in the alpha cut, otherwise returns a crisp set of the elements
Elements in FuzzySet or a Set of the elements.
f = FuzzySet$new(1, 0.1, 2, 0.5, 3, 1) # Alpha-cut f$alphaCut(0.5) # Strong alpha-cut f$alphaCut(0.5, strong = TRUE) # Create a set from the alpha-cut f$alphaCut(0.5, create = TRUE)
support()
The support of a fuzzy set is defined as the set of elements whose membership
is greater than zero, or the strong alpha-cut with ,
where is an element in the fuzzy set,
, and
is the corresponding
membership.
FuzzySet$support(create = FALSE)
create
logical, if FALSE
(default) returns the support elements, otherwise returns a Set of the support elements
Support elements in fuzzy set or a Set of the support elements.
f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1) f$support() f$support(TRUE)
core()
The core of a fuzzy set is defined as the set of elements whose membership is equal to one,
or the alpha-cut with ,
where is an element in the fuzzy set,
, and
is the corresponding membership.
FuzzySet$core(create = FALSE)
create
logical, if FALSE
(default) returns the core elements, otherwise returns a Set of the core elements
Core elements in FuzzySet or a Set of the core elements.
f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1) f$core() f$core(TRUE)
inclusion()
An element in a fuzzy set, with corresponding membership , is:
Included - If
Partially Included - If
Not Included - If
FuzzySet$inclusion(element)
element
element or list of elements in fuzzy set for which to get the inclusion level
For FuzzySets this is straightforward and returns the inclusion level of the given element(s), however in FuzzyTuples and FuzzyMultisets when an element may be duplicated, the function returns the inclusion level of all instances of the element.
One of: "Included", "Partially Included", "Not Included"
f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1) f$inclusion(0.1) f$inclusion(1) f$inclusion(3)
equals()
Tests if two sets are equal.
FuzzySet$equals(x, all = FALSE)
Two fuzzy sets are equal if they contain the same elements with the same memberships. Infix operators can be used for:
Equal | == |
Not equal | != |
If all
is TRUE
then returns TRUE
if all x
are equal to the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
isSubset()
Test if one set is a (proper) subset of another
FuzzySet$isSubset(x, proper = FALSE, all = FALSE)
x
any. Object or vector of objects to test.
proper
logical. If TRUE
tests for proper subsets.
all
logical. If FALSE
tests each x
separately. Otherwise returns TRUE
only if all x
pass test.
If using the method directly, and not via one of the operators then the additional boolean
argument proper
can be used to specify testing of subsets or proper subsets. A Set is a proper
subset of another if it is fully contained by the other Set (i.e. not equal to) whereas a Set is a
(non-proper) subset if it is fully contained by, or equal to, the other Set.
Infix operators can be used for:
Subset | < |
Proper Subset | <= |
Superset | > |
Proper Superset | >=
|
If all
is TRUE
then returns TRUE
if all x
are subsets of the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
clone()
The objects of this class are cloneable with this method.
FuzzySet$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other sets:
ConditionalSet
,
FuzzyMultiset
,
FuzzyTuple
,
Interval
,
Multiset
,
Set
,
Tuple
# Different constructors FuzzySet$new(1, 0.5, 2, 1, 3, 0) FuzzySet$new(elements = 1:3, membership = c(0.5, 1, 0)) # Crisp sets are a special case FuzzySet # Note membership defaults to full membership FuzzySet$new(elements = 1:5) == Set$new(1:5) f <- FuzzySet$new(1, 0.2, 2, 1, 3, 0) f$membership() f$alphaCut(0.3) f$core() f$inclusion(0) f$membership(0) f$membership(1) ## ------------------------------------------------ ## Method `FuzzySet$membership` ## ------------------------------------------------ f = FuzzySet$new(1, 0.1, 2, 0.5, 3, 1) f$membership() f$membership(2) f$membership(list(1, 2)) ## ------------------------------------------------ ## Method `FuzzySet$alphaCut` ## ------------------------------------------------ f = FuzzySet$new(1, 0.1, 2, 0.5, 3, 1) # Alpha-cut f$alphaCut(0.5) # Strong alpha-cut f$alphaCut(0.5, strong = TRUE) # Create a set from the alpha-cut f$alphaCut(0.5, create = TRUE) ## ------------------------------------------------ ## Method `FuzzySet$support` ## ------------------------------------------------ f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1) f$support() f$support(TRUE) ## ------------------------------------------------ ## Method `FuzzySet$core` ## ------------------------------------------------ f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1) f$core() f$core(TRUE) ## ------------------------------------------------ ## Method `FuzzySet$inclusion` ## ------------------------------------------------ f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1) f$inclusion(0.1) f$inclusion(1) f$inclusion(3)
# Different constructors FuzzySet$new(1, 0.5, 2, 1, 3, 0) FuzzySet$new(elements = 1:3, membership = c(0.5, 1, 0)) # Crisp sets are a special case FuzzySet # Note membership defaults to full membership FuzzySet$new(elements = 1:5) == Set$new(1:5) f <- FuzzySet$new(1, 0.2, 2, 1, 3, 0) f$membership() f$alphaCut(0.3) f$core() f$inclusion(0) f$membership(0) f$membership(1) ## ------------------------------------------------ ## Method `FuzzySet$membership` ## ------------------------------------------------ f = FuzzySet$new(1, 0.1, 2, 0.5, 3, 1) f$membership() f$membership(2) f$membership(list(1, 2)) ## ------------------------------------------------ ## Method `FuzzySet$alphaCut` ## ------------------------------------------------ f = FuzzySet$new(1, 0.1, 2, 0.5, 3, 1) # Alpha-cut f$alphaCut(0.5) # Strong alpha-cut f$alphaCut(0.5, strong = TRUE) # Create a set from the alpha-cut f$alphaCut(0.5, create = TRUE) ## ------------------------------------------------ ## Method `FuzzySet$support` ## ------------------------------------------------ f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1) f$support() f$support(TRUE) ## ------------------------------------------------ ## Method `FuzzySet$core` ## ------------------------------------------------ f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1) f$core() f$core(TRUE) ## ------------------------------------------------ ## Method `FuzzySet$inclusion` ## ------------------------------------------------ f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1) f$inclusion(0.1) f$inclusion(1) f$inclusion(3)
A general FuzzyTuple object for mathematical fuzzy tuples, inheriting from FuzzySet
.
Fuzzy tuples generalise standard mathematical tuples to allow for fuzzy relationships. Whereas a
standard, or crisp, tuple assumes that an element is either in a tuple or not, a fuzzy tuple allows
an element to be in a tuple to a particular degree, known as the membership function, which
quantifies the inclusion of an element by a number in [0, 1]. Thus a (crisp) tuple is a
fuzzy tuple where all elements have a membership equal to . Similarly to Tuples, elements
do not need to be unique and the ordering does matter, FuzzySets are special cases where the ordering
does not matter and elements must be unique.
set6::Set
-> set6::FuzzySet
-> FuzzyTuple
equals()
Tests if two sets are equal.
FuzzyTuple$equals(x, all = FALSE)
Two fuzzy sets are equal if they contain the same elements with the same memberships and in the same order. Infix operators can be used for:
Equal | == |
Not equal | != |
If all
is TRUE
then returns TRUE
if all x
are equal to the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
isSubset()
Test if one set is a (proper) subset of another
FuzzyTuple$isSubset(x, proper = FALSE, all = FALSE)
x
any. Object or vector of objects to test.
proper
logical. If TRUE
tests for proper subsets.
all
logical. If FALSE
tests each x
separately. Otherwise returns TRUE
only if all x
pass test.
If using the method directly, and not via one of the operators then the additional boolean
argument proper
can be used to specify testing of subsets or proper subsets. A Set is a proper
subset of another if it is fully contained by the other Set (i.e. not equal to) whereas a Set is a
(non-proper) subset if it is fully contained by, or equal to, the other Set.
Infix operators can be used for:
Subset | < |
Proper Subset | <= |
Superset | > |
Proper Superset | >=
|
If all
is TRUE
then returns TRUE
if all x
are subsets of the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
alphaCut()
The alpha-cut of a fuzzy set is defined as the set
where is an element in the fuzzy set,
, and
is the corresponding membership.
FuzzyTuple$alphaCut(alpha, strong = FALSE, create = FALSE)
alpha
numeric in [0, 1] to determine which elements to return
strong
logical, if FALSE
(default) then includes elements greater than or equal to alpha, otherwise only strictly greater than
create
logical, if FALSE
(default) returns the elements in the alpha cut, otherwise returns a crisp set of the elements
Elements in FuzzyTuple or a Set of the elements.
clone()
The objects of this class are cloneable with this method.
FuzzyTuple$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other sets:
ConditionalSet
,
FuzzyMultiset
,
FuzzySet
,
Interval
,
Multiset
,
Set
,
Tuple
# Different constructors FuzzyTuple$new(1, 0.5, 2, 1, 3, 0) FuzzyTuple$new(elements = 1:3, membership = c(0.5, 1, 0)) # Crisp sets are a special case FuzzyTuple # Note membership defaults to full membership FuzzyTuple$new(elements = 1:5) == Tuple$new(1:5) f <- FuzzyTuple$new(1, 0.2, 2, 1, 3, 0) f$membership() f$alphaCut(0.3) f$core() f$inclusion(0) f$membership(0) f$membership(1) # Elements can be duplicated, and with different memberships, # although this is not necessarily sensible. FuzzyTuple$new(1, 0.1, 1, 1) # More important is ordering. FuzzyTuple$new(1, 0.1, 2, 0.2) != FuzzyTuple$new(2, 0.2, 1, 0.1) FuzzySet$new(1, 0.1, 2, 0.2) == FuzzySet$new(2, 0.2, 1, 0.1)
# Different constructors FuzzyTuple$new(1, 0.5, 2, 1, 3, 0) FuzzyTuple$new(elements = 1:3, membership = c(0.5, 1, 0)) # Crisp sets are a special case FuzzyTuple # Note membership defaults to full membership FuzzyTuple$new(elements = 1:5) == Tuple$new(1:5) f <- FuzzyTuple$new(1, 0.2, 2, 1, 3, 0) f$membership() f$alphaCut(0.3) f$core() f$inclusion(0) f$membership(0) f$membership(1) # Elements can be duplicated, and with different memberships, # although this is not necessarily sensible. FuzzyTuple$new(1, 0.1, 1, 1) # More important is ordering. FuzzyTuple$new(1, 0.1, 2, 0.2) != FuzzyTuple$new(2, 0.2, 1, 0.1) FuzzySet$new(1, 0.1, 2, 0.2) == FuzzySet$new(2, 0.2, 1, 0.1)
The mathematical set of integers, defined as the set of whole numbers. i.e.
set6::Set
-> set6::Interval
-> set6::SpecialSet
-> Integers
new()
Create a new Integers
object.
Integers$new(lower = -Inf, upper = Inf, type = "()")
lower
numeric. Where to start the set. Advised to ignore, used by child-classes.
upper
numeric. Where to end the set. Advised to ignore, used by child-classes.
type
character Set closure type. Advised to ignore, used by child-classes.
A new Integers
object.
clone()
The objects of this class are cloneable with this method.
Integers$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other special sets:
Complex
,
ExtendedReals
,
Logicals
,
Naturals
,
NegIntegers
,
NegRationals
,
NegReals
,
PosIntegers
,
PosNaturals
,
PosRationals
,
PosReals
,
Rationals
,
Reals
,
Universal
A general Interval object for mathematical intervals, inheriting from Set. Intervals may be open, closed, or half-open; as well as bounded above, below, or not at all.
The Interval class can be used for finite or infinite intervals, but often Sets will be preferred for integer intervals over a finite continuous range.
set6::Set
-> Interval
length
If the Interval
is countably finite then returns the number of elements in the Interval
,
otherwise Inf
. See the cardinality property for the type of infinity.
elements
If the Interval
is finite then returns all elements in the Interval
, otherwise NA
.
new()
Create a new Interval
object.
Interval$new( lower = -Inf, upper = Inf, type = c("[]", "(]", "[)", "()"), class = "numeric", universe = ExtendedReals$new() )
lower
numeric. Lower limit of the interval.
upper
numeric. Upper limit of the interval.
type
character. One of: '()', '(]', '[)', '[]', which specifies if interval is open, left-open, right-open, or closed.
class
character. One of: 'numeric', 'integer', which specifies if interval is over the Reals or Integers.
universe
Set. Universe that the interval lives in, default Reals.
Interval
s are constructed by specifying the Interval
limits, the boundary type,
the class, and the possible universe. The universe
differs from class
as it is primarily used
for the setcomplement method. Whereas class
specifies if the interval takes integers or
numerics, the universe
specifies what range the interval could take.
A new Interval
object.
strprint()
Creates a printable representation of the object.
Interval$strprint(...)
...
ignored, added for consistency.
A character string representing the object.
equals()
Tests if two sets are equal.
Interval$equals(x, all = FALSE)
Two Interval
s are equal if they have the same: class, type, and bounds.
Infix operators can be used for:
Equal | == |
Not equal | != |
If all
is TRUE
then returns TRUE
if all x
are equal to the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
Interval$new(1,5) == Interval$new(1,5) Interval$new(1,5, class = "integer") != Interval$new(1,5,class="numeric")
contains()
Tests to see if x
is contained in the Set.
Interval$contains(x, all = FALSE, bound = FALSE)
x
any. Object or vector of objects to test.
all
logical. If FALSE
tests each x
separately. Otherwise returns TRUE
only if all x
pass test.
bound
logical.
x
can be of any type, including a Set itself. x
should be a tuple if
checking to see if it lies within a set of dimension greater than one. To test for multiple x
at the same time, then provide these as a list.
If all = TRUE
then returns TRUE
if all x
are contained in the Set
, otherwise
returns a vector of logicals. For Intervals, bound
is used to specify if elements lying on the
(possibly open) boundary of the interval are considered contained (bound = TRUE
) or not (bound = FALSE
).
If all
is TRUE
then returns TRUE
if all elements of x
are contained in the Set
, otherwise
FALSE.
If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
The infix operator %inset%
is available to test if x
is an element in the Set
,
see examples.
s = Set$new(1:5) # Simplest case s$contains(4) 8 %inset% s # Test if multiple elements lie in the set s$contains(4:6, all = FALSE) s$contains(4:6, all = TRUE) # Check if a tuple lies in a Set of higher dimension s2 = s * s s2$contains(Tuple$new(2,1)) c(Tuple$new(2,1), Tuple$new(1,7), 2) %inset% s2
isSubset()
Test if one set is a (proper) subset of another
Interval$isSubset(x, proper = FALSE, all = FALSE)
x
any. Object or vector of objects to test.
proper
logical. If TRUE
tests for proper subsets.
all
logical. If FALSE
tests each x
separately. Otherwise returns TRUE
only if all x
pass test.
If using the method directly, and not via one of the operators then the additional boolean
argument proper
can be used to specify testing of subsets or proper subsets. A Set is a proper
subset of another if it is fully contained by the other Set (i.e. not equal to) whereas a Set is a
(non-proper) subset if it is fully contained by, or equal to, the other Set.
When calling isSubset
on objects inheriting from Interval
, the method treats the interval as if
it is a Set, i.e. ordering and class are ignored. Use isSubinterval
to test if one interval
is a subinterval of another.
Infix operators can be used for:
Subset | < |
Proper Subset | <= |
Superset | > |
Proper Superset | >=
|
If all
is TRUE
then returns TRUE
if all x
are subsets of the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
Interval$new(1,3) < Interval$new(1,5) Set$new(1,3) < Interval$new(0,5)
isSubinterval()
Test if one interval is a (proper) subinterval of another
Interval$isSubinterval(x, proper = FALSE, all = FALSE)
x
Set
or list
proper
If TRUE
then tests if x
is a proper subinterval (i.e. subinterval and not equal to)
of self
, otherwise FALSE
tests if x
is a (non-proper) subinterval.
all
If TRUE
then returns TRUE
if all x
are subintervals, otherwise returns a vector of logicals.
If x
is a Set then will be coerced to an Interval if possible. $isSubinterval
differs
from $isSubset
in that ordering and class are respected in $isSubinterval
. See examples for
a clearer illustration of the difference.
If all
is TRUE
then returns TRUE
if all x
are subsets of the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
Interval$new(1,3)$isSubset(Set$new(1,2)) # TRUE Interval$new(1,3)$isSubset(Set$new(2, 1)) # TRUE Interval$new(1,3, class = "integer")$isSubinterval(Set$new(1, 2)) # TRUE Interval$new(1,3)$isSubinterval(Set$new(1, 2)) # FALSE Interval$new(1,3)$isSubinterval(Set$new(2, 1)) # FALSE Reals$new()$isSubset(Integers$new()) # TRUE Reals$new()$isSubinterval(Integers$new()) # FALSE
clone()
The objects of this class are cloneable with this method.
Interval$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other sets:
ConditionalSet
,
FuzzyMultiset
,
FuzzySet
,
FuzzyTuple
,
Multiset
,
Set
,
Tuple
# Set of Reals Interval$new() # Set of Integers Interval$new(class = "integer") # Half-open interval i <- Interval$new(1, 10, "(]") i$contains(c(1, 10)) i$contains(c(1, 10), bound = TRUE) # Equivalent Set and Interval Set$new(1:5) == Interval$new(1, 5, class = "integer") # SpecialSets can provide more efficient implementation Interval$new() == ExtendedReals$new() Interval$new(class = "integer", type = "()") == Integers$new() ## ------------------------------------------------ ## Method `Interval$equals` ## ------------------------------------------------ Interval$new(1,5) == Interval$new(1,5) Interval$new(1,5, class = "integer") != Interval$new(1,5,class="numeric") ## ------------------------------------------------ ## Method `Interval$contains` ## ------------------------------------------------ s = Set$new(1:5) # Simplest case s$contains(4) 8 %inset% s # Test if multiple elements lie in the set s$contains(4:6, all = FALSE) s$contains(4:6, all = TRUE) # Check if a tuple lies in a Set of higher dimension s2 = s * s s2$contains(Tuple$new(2,1)) c(Tuple$new(2,1), Tuple$new(1,7), 2) %inset% s2 ## ------------------------------------------------ ## Method `Interval$isSubset` ## ------------------------------------------------ Interval$new(1,3) < Interval$new(1,5) Set$new(1,3) < Interval$new(0,5) ## ------------------------------------------------ ## Method `Interval$isSubinterval` ## ------------------------------------------------ Interval$new(1,3)$isSubset(Set$new(1,2)) # TRUE Interval$new(1,3)$isSubset(Set$new(2, 1)) # TRUE Interval$new(1,3, class = "integer")$isSubinterval(Set$new(1, 2)) # TRUE Interval$new(1,3)$isSubinterval(Set$new(1, 2)) # FALSE Interval$new(1,3)$isSubinterval(Set$new(2, 1)) # FALSE Reals$new()$isSubset(Integers$new()) # TRUE Reals$new()$isSubinterval(Integers$new()) # FALSE
# Set of Reals Interval$new() # Set of Integers Interval$new(class = "integer") # Half-open interval i <- Interval$new(1, 10, "(]") i$contains(c(1, 10)) i$contains(c(1, 10), bound = TRUE) # Equivalent Set and Interval Set$new(1:5) == Interval$new(1, 5, class = "integer") # SpecialSets can provide more efficient implementation Interval$new() == ExtendedReals$new() Interval$new(class = "integer", type = "()") == Integers$new() ## ------------------------------------------------ ## Method `Interval$equals` ## ------------------------------------------------ Interval$new(1,5) == Interval$new(1,5) Interval$new(1,5, class = "integer") != Interval$new(1,5,class="numeric") ## ------------------------------------------------ ## Method `Interval$contains` ## ------------------------------------------------ s = Set$new(1:5) # Simplest case s$contains(4) 8 %inset% s # Test if multiple elements lie in the set s$contains(4:6, all = FALSE) s$contains(4:6, all = TRUE) # Check if a tuple lies in a Set of higher dimension s2 = s * s s2$contains(Tuple$new(2,1)) c(Tuple$new(2,1), Tuple$new(1,7), 2) %inset% s2 ## ------------------------------------------------ ## Method `Interval$isSubset` ## ------------------------------------------------ Interval$new(1,3) < Interval$new(1,5) Set$new(1,3) < Interval$new(0,5) ## ------------------------------------------------ ## Method `Interval$isSubinterval` ## ------------------------------------------------ Interval$new(1,3)$isSubset(Set$new(1,2)) # TRUE Interval$new(1,3)$isSubset(Set$new(2, 1)) # TRUE Interval$new(1,3, class = "integer")$isSubinterval(Set$new(1, 2)) # TRUE Interval$new(1,3)$isSubinterval(Set$new(1, 2)) # FALSE Interval$new(1,3)$isSubinterval(Set$new(2, 1)) # FALSE Reals$new()$isSubset(Integers$new()) # TRUE Reals$new()$isSubinterval(Integers$new()) # FALSE
Operator for $isSubset
methods. See Set$isSubset
for full details.
Operators can be used for:
Name | Description | Operator |
Subset | x is a subset of y |
x <= y |
Proper Subset | x is a proper subset of y |
x < y |
Superset | x is a superset of y |
x >= y |
Proper Superset | x is a proper superset of y |
x > y |
## S3 method for class 'Set' x < y ## S3 method for class 'Set' x <= y ## S3 method for class 'Set' x > y ## S3 method for class 'Set' x >= y
## S3 method for class 'Set' x < y ## S3 method for class 'Set' x <= y ## S3 method for class 'Set' x > y ## S3 method for class 'Set' x >= y
x , y
|
Lists special sets that can be used in Set.
listSpecialSets(simplify = FALSE)
listSpecialSets(simplify = FALSE)
simplify |
logical. If |
Either a list of characters (if simplify
is TRUE
) or a data.frame
of SpecialSet
s
and their traits.
listSpecialSets() listSpecialSets(TRUE)
listSpecialSets() listSpecialSets(TRUE)
The Logicals
is defined as the Set containing the elements TRUE
and FALSE
.
set6::Set
-> Logicals
new()
Create a new Logicals
object.
Logicals$new()
The Logical set is the set containing TRUE
and FALSE
.
A new Logicals
object.
clone()
The objects of this class are cloneable with this method.
Logicals$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other special sets:
Complex
,
ExtendedReals
,
Integers
,
Naturals
,
NegIntegers
,
NegRationals
,
NegReals
,
PosIntegers
,
PosNaturals
,
PosRationals
,
PosReals
,
Rationals
,
Reals
,
Universal
l <- Logicals$new() print(l) l$contains(list(TRUE, 1, FALSE))
l <- Logicals$new() print(l) l$contains(list(TRUE, 1, FALSE))
The LogicalSet
is defined as the Set containing the elements TRUE
and FALSE
.
set6::Set
-> LogicalSet
new()
Create a new LogicalSet
object.
LogicalSet$new()
The Logical set is the set containing TRUE
and FALSE
.
A new LogicalSet
object.
clone()
The objects of this class are cloneable with this method.
LogicalSet$clone(deep = FALSE)
deep
Whether to make a deep clone.
l <- LogicalSet$new() print(l) l$contains(list(TRUE, 1, FALSE))
l <- LogicalSet$new() print(l) l$contains(list(TRUE, 1, FALSE))
A general Multiset object for mathematical Multisets, inheriting from Set
.
Multisets are generalisations of sets that allow an element to be repeated. They can be thought of as Tuples without ordering.
set6::Set
-> Multiset
equals()
Tests if two sets are equal.
Multiset$equals(x, all = FALSE)
An object is equal to a Multiset if it contains all the same elements, and in the same order. Infix operators can be used for:
Equal | == |
Not equal | != |
If all
is TRUE
then returns TRUE
if all x
are equal to the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
Multiset$new(1,2) == Multiset$new(1,2) Multiset$new(1,2) != Multiset$new(1,2) Multiset$new(1,1) != Set$new(1,1)
isSubset()
Test if one set is a (proper) subset of another
Multiset$isSubset(x, proper = FALSE, all = FALSE)
x
any. Object or vector of objects to test.
proper
logical. If TRUE
tests for proper subsets.
all
logical. If FALSE
tests each x
separately. Otherwise returns TRUE
only if all x
pass test.
If using the method directly, and not via one of the operators then the additional boolean
argument proper
can be used to specify testing of subsets or proper subsets. A Set is a proper
subset of another if it is fully contained by the other Set (i.e. not equal to) whereas a Set is a
(non-proper) subset if it is fully contained by, or equal to, the other Set.
When calling $isSubset
on objects inheriting from Interval, the method treats the interval as if
it is a Set, i.e. ordering and class are ignored. Use $isSubinterval
to test if one interval
is a subinterval of another.
Infix operators can be used for:
Subset | < |
Proper Subset | <= |
Superset | > |
Proper Superset | >=
|
An object is a (proper) subset of a Multiset if it contains all (some) of the same elements, and in the same order.
If all
is TRUE
then returns TRUE
if all x
are subsets of the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
Multiset$new(1,2,3) < Multiset$new(1,2,3,4) Multiset$new(1,3,2) < Multiset$new(1,2,3,4) Multiset$new(1,3,2,4) <= Multiset$new(1,2,3,4)
clone()
The objects of this class are cloneable with this method.
Multiset$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other sets:
ConditionalSet
,
FuzzyMultiset
,
FuzzySet
,
FuzzyTuple
,
Interval
,
Set
,
Tuple
# Multiset of integers Multiset$new(1:5) # Multiset of multiple types Multiset$new("a", 5, Set$new(1), Multiset$new(2)) # Each Multiset has properties and traits t <- Multiset$new(1, 2, 3) t$traits t$properties # Elements can be duplicated Multiset$new(2, 2) != Multiset$new(2) # Ordering does not matter Multiset$new(1, 2) == Multiset$new(2, 1) ## ------------------------------------------------ ## Method `Multiset$equals` ## ------------------------------------------------ Multiset$new(1,2) == Multiset$new(1,2) Multiset$new(1,2) != Multiset$new(1,2) Multiset$new(1,1) != Set$new(1,1) ## ------------------------------------------------ ## Method `Multiset$isSubset` ## ------------------------------------------------ Multiset$new(1,2,3) < Multiset$new(1,2,3,4) Multiset$new(1,3,2) < Multiset$new(1,2,3,4) Multiset$new(1,3,2,4) <= Multiset$new(1,2,3,4)
# Multiset of integers Multiset$new(1:5) # Multiset of multiple types Multiset$new("a", 5, Set$new(1), Multiset$new(2)) # Each Multiset has properties and traits t <- Multiset$new(1, 2, 3) t$traits t$properties # Elements can be duplicated Multiset$new(2, 2) != Multiset$new(2) # Ordering does not matter Multiset$new(1, 2) == Multiset$new(2, 1) ## ------------------------------------------------ ## Method `Multiset$equals` ## ------------------------------------------------ Multiset$new(1,2) == Multiset$new(1,2) Multiset$new(1,2) != Multiset$new(1,2) Multiset$new(1,1) != Set$new(1,1) ## ------------------------------------------------ ## Method `Multiset$isSubset` ## ------------------------------------------------ Multiset$new(1,2,3) < Multiset$new(1,2,3,4) Multiset$new(1,3,2) < Multiset$new(1,2,3,4) Multiset$new(1,3,2,4) <= Multiset$new(1,2,3,4)
The mathematical set of natural numbers, defined as the counting numbers. i.e.
set6::Set
-> set6::Interval
-> set6::SpecialSet
-> Naturals
new()
Create a new Naturals
object.
Naturals$new(lower = 0)
lower
numeric. Where to start the set. Advised to ignore, used by child-classes.
A new Naturals
object.
clone()
The objects of this class are cloneable with this method.
Naturals$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other special sets:
Complex
,
ExtendedReals
,
Integers
,
Logicals
,
NegIntegers
,
NegRationals
,
NegReals
,
PosIntegers
,
PosNaturals
,
PosRationals
,
PosReals
,
Rationals
,
Reals
,
Universal
The mathematical set of negative integers, defined as the set of negative whole numbers. i.e.
set6::Set
-> set6::Interval
-> set6::SpecialSet
-> set6::Integers
-> NegIntegers
new()
Create a new NegIntegers
object.
NegIntegers$new(zero = FALSE)
zero
logical. If TRUE, zero is included in the set.
A new NegIntegers
object.
clone()
The objects of this class are cloneable with this method.
NegIntegers$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other special sets:
Complex
,
ExtendedReals
,
Integers
,
Logicals
,
Naturals
,
NegRationals
,
NegReals
,
PosIntegers
,
PosNaturals
,
PosRationals
,
PosReals
,
Rationals
,
Reals
,
Universal
The mathematical set of negative rational numbers, defined as the set of numbers that can be written as a fraction of two integers and are non-positive. i.e.
where is the set of integers.
The $contains
method does not work for the set of Rationals as it is notoriously
difficult/impossible to find an algorithm for determining if any given number is rational or not.
Furthermore, computers must truncate all irrational numbers to rational numbers.
set6::Set
-> set6::Interval
-> set6::SpecialSet
-> set6::Rationals
-> NegRationals
new()
Create a new NegRationals
object.
NegRationals$new(zero = FALSE)
zero
logical. If TRUE, zero is included in the set.
A new NegRationals
object.
clone()
The objects of this class are cloneable with this method.
NegRationals$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other special sets:
Complex
,
ExtendedReals
,
Integers
,
Logicals
,
Naturals
,
NegIntegers
,
NegReals
,
PosIntegers
,
PosNaturals
,
PosRationals
,
PosReals
,
Rationals
,
Reals
,
Universal
The mathematical set of negative real numbers, defined as the union of the set of negative rationals and negative irrationals. i.e.
where is the set of negative irrationals and
is the set of negative rationals.
set6::Set
-> set6::Interval
-> set6::SpecialSet
-> set6::Reals
-> NegReals
new()
Create a new NegReals
object.
NegReals$new(zero = FALSE)
zero
logical. If TRUE, zero is included in the set.
A new NegReals
object.
clone()
The objects of this class are cloneable with this method.
NegReals$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other special sets:
Complex
,
ExtendedReals
,
Integers
,
Logicals
,
Naturals
,
NegIntegers
,
NegRationals
,
PosIntegers
,
PosNaturals
,
PosRationals
,
PosReals
,
Rationals
,
Reals
,
Universal
The mathematical set of positive integers, defined as the set of positive whole numbers. i.e.
set6::Set
-> set6::Interval
-> set6::SpecialSet
-> set6::Integers
-> PosIntegers
new()
Create a new PosIntegers
object.
PosIntegers$new(zero = FALSE)
zero
logical. If TRUE, zero is included in the set.
A new PosIntegers
object.
clone()
The objects of this class are cloneable with this method.
PosIntegers$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other special sets:
Complex
,
ExtendedReals
,
Integers
,
Logicals
,
Naturals
,
NegIntegers
,
NegRationals
,
NegReals
,
PosNaturals
,
PosRationals
,
PosReals
,
Rationals
,
Reals
,
Universal
The mathematical set of positive natural numbers, defined as the positive counting numbers. i.e.
set6::Set
-> set6::Interval
-> set6::SpecialSet
-> set6::Naturals
-> PosNaturals
new()
Create a new PosNaturals
object.
PosNaturals$new()
A new PosNaturals
object.
clone()
The objects of this class are cloneable with this method.
PosNaturals$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other special sets:
Complex
,
ExtendedReals
,
Integers
,
Logicals
,
Naturals
,
NegIntegers
,
NegRationals
,
NegReals
,
PosIntegers
,
PosRationals
,
PosReals
,
Rationals
,
Reals
,
Universal
The mathematical set of positive rational numbers, defined as the set of numbers that can be written as a fraction of two integers and are non-negative. i.e.
where is the set of integers.
The $contains
method does not work for the set of Rationals as it is notoriously
difficult/impossible to find an algorithm for determining if any given number is rational or not.
Furthermore, computers must truncate all irrational numbers to rational numbers.
set6::Set
-> set6::Interval
-> set6::SpecialSet
-> set6::Rationals
-> PosRationals
new()
Create a new PosRationals
object.
PosRationals$new(zero = FALSE)
zero
logical. If TRUE, zero is included in the set.
A new PosRationals
object.
clone()
The objects of this class are cloneable with this method.
PosRationals$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other special sets:
Complex
,
ExtendedReals
,
Integers
,
Logicals
,
Naturals
,
NegIntegers
,
NegRationals
,
NegReals
,
PosIntegers
,
PosNaturals
,
PosReals
,
Rationals
,
Reals
,
Universal
The mathematical set of positive real numbers, defined as the union of the set of positive rationals and positive irrationals. i.e.
where is the set of positive irrationals and
is the set of positive rationals.
set6::Set
-> set6::Interval
-> set6::SpecialSet
-> set6::Reals
-> PosReals
new()
Create a new PosReals
object.
PosReals$new(zero = FALSE)
zero
logical. If TRUE, zero is included in the set.
A new PosReals
object.
clone()
The objects of this class are cloneable with this method.
PosReals$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other special sets:
Complex
,
ExtendedReals
,
Integers
,
Logicals
,
Naturals
,
NegIntegers
,
NegRationals
,
NegReals
,
PosIntegers
,
PosNaturals
,
PosRationals
,
Rationals
,
Reals
,
Universal
Calculates and returns the powerset of a Set.
powerset(x, simplify = FALSE)
powerset(x, simplify = FALSE)
x |
|
simplify |
logical, if |
A powerset of a set, S, is defined as the set of all subsets of S, including S itself and the empty set.
Other operators:
setcomplement()
,
setintersect()
,
setpower()
,
setproduct()
,
setsymdiff()
,
setunion()
# simplify = FALSE is default powerset(Set$new(1, 2)) powerset(Set$new(1, 2), simplify = TRUE) # powerset of intervals powerset(Interval$new()) # powerset of powersets powerset(powerset(Reals$new())) powerset(powerset(Reals$new()))$properties$cardinality
# simplify = FALSE is default powerset(Set$new(1, 2)) powerset(Set$new(1, 2), simplify = TRUE) # powerset of intervals powerset(Interval$new()) # powerset of powersets powerset(powerset(Reals$new())) powerset(powerset(Reals$new()))$properties$cardinality
PowersetSet class for symbolic powerset of mathematical sets.
The purpose of this class is to provide a symbolic representation for the powerset of sets that cannot be represented in a simpler class. Whilst this is not an abstract class, it is not recommended to construct this class directly but via the set operation methods.
set6::Set
-> set6::SetWrapper
-> set6::ProductSet
-> PowersetSet
new()
Create a new PowersetSet
object. It is not recommended to construct this class directly.
PowersetSet$new(set)
set
Set to wrap.
A new PowersetSet
object.
strprint()
Creates a printable representation of the object.
PowersetSet$strprint(n = 2)
n
numeric. Number of elements to display on either side of ellipsis when printing.
A character string representing the object.
contains()
Tests if elements x
are contained in self
.
PowersetSet$contains(x, all = FALSE, bound = NULL)
If all == TRUE
then returns TRUE
if all x
are contained in self
, otherwise FALSE
.
If all == FALSE
returns a vector of logicals corresponding to the length of x
, representing
if each is contained in self
. If bound == TRUE
then an element is contained in self
if it
is on or within the (possibly-open) bounds of self
, otherwise TRUE
only if the element is within
self
or the bounds are closed.
isSubset()
Tests if x
is a (proper) subset of self
.
PowersetSet$isSubset(x, proper = FALSE, all = FALSE)
If all == TRUE
then returns TRUE
if all x
are (proper) subsets of self
, otherwise FALSE
.
If all == FALSE
returns a vector of logicals corresponding to the length of x
, representing
if each is a (proper) subset of self
.
clone()
The objects of this class are cloneable with this method.
PowersetSet$clone(deep = FALSE)
deep
Whether to make a deep clone.
Set operations: setunion, setproduct, setpower, setcomplement, setsymdiff, powerset, setintersect
Other wrappers:
ComplementSet
,
ExponentSet
,
ProductSet
,
UnionSet
ProductSet class for symbolic product of mathematical sets.
The purpose of this class is to provide a symbolic representation for the product of sets that cannot be represented in a simpler class. Whilst this is not an abstract class, it is not recommended to construct this class directly but via the set operation methods.
set6::Set
-> set6::SetWrapper
-> ProductSet
length
Returns the number of elements in the object.
new()
Create a new ProductSet
object. It is not recommended to construct this class directly.
ProductSet$new( setlist, lower = NULL, upper = NULL, type = NULL, cardinality = NULL )
setlist
list
of Sets to wrap.
lower
lower bound of new object.
upper
upper bound of new object.
type
closure type of new object.
cardinality
Either an integer, "Aleph0", or a beth number. If NULL
then calculated automatically (recommended).
A new ProductSet
object.
strprint()
Creates a printable representation of the object.
ProductSet$strprint(n = 2)
n
numeric. Number of elements to display on either side of ellipsis when printing.
A character string representing the object.
contains()
Tests if elements x
are contained in self
.
ProductSet$contains(x, all = FALSE, bound = FALSE)
If all == TRUE
then returns TRUE
if all x
are contained in self
, otherwise FALSE
.
If all == FALSE
returns a vector of logicals corresponding to the length of x
, representing
if each is contained in self
. If bound == TRUE
then an element is contained in self
if it
is on or within the (possibly-open) bounds of self
, otherwise TRUE
only if the element is within
self
or the bounds are closed.
clone()
The objects of this class are cloneable with this method.
ProductSet$clone(deep = FALSE)
deep
Whether to make a deep clone.
Set operations: setunion, setproduct, setpower, setcomplement, setsymdiff, powerset, setintersect
Other wrappers:
ComplementSet
,
ExponentSet
,
PowersetSet
,
UnionSet
Used to store the properties of a Set. Though this is not an abstract class, it should never be constructed outside of the Set constructor.
closure
Returns the closure of the Set
. One of "open", "half-open", or "closed."
countability
Returns the countability of the Set
. One of "countably finite", "countably infinite", or "uncountable".
cardinality
Returns the cardinality of the Set
. Either an integer if the Set
is countably finite, Aleph0 if countably infinite, or a Beth number.
empty
Returns if the Set
is empty or not. TRUE
if the Set cardinality is 0
, FALSE
otherwise.
singleton
Returns if the Set
is a singleton or not. TRUE
if the Set cardinality is 1
, FALSE
otherwise.
new()
Creates a new Properties
object.
Properties$new(closure = character(0), cardinality = NULL)
closure
One of "open", "half-open", or "closed."
cardinality
If non-NULL
then either an integer, "Aleph0", or a Beth number.
A new Properties
object.
print()
Prints the Properties
list.
Properties$print()
Prints Properties
list to console.
strprint()
Creates a printable representation of the Properties
.
Properties$strprint()
A list
of properties.
clone()
The objects of this class are cloneable with this method.
Properties$clone(deep = FALSE)
deep
Whether to make a deep clone.
The mathematical set of rational numbers, defined as the set of numbers that can be written as a fraction of two integers. i.e.
where is the set of integers.
The $contains
method does not work for the set of Rationals as it is notoriously
difficult/impossible to find an algorithm for determining if any given number is rational or not.
Furthermore, computers must truncate all irrational numbers to rational numbers.
set6::Set
-> set6::Interval
-> set6::SpecialSet
-> Rationals
new()
Create a new Rationals
object.
Rationals$new(lower = -Inf, upper = Inf, type = "()")
lower
numeric. Where to start the set. Advised to ignore, used by child-classes.
upper
numeric. Where to end the set. Advised to ignore, used by child-classes.
type
character Set closure type. Advised to ignore, used by child-classes.
A new Rationals
object.
contains()
Method not possible for Rationals.
Rationals$contains(...)
...
Ignored
isSubset()
Method not possible for Rationals.
Rationals$isSubset(...)
...
Ignored
equals()
Method not possible for Rationals.
Rationals$equals(...)
...
Ignored
clone()
The objects of this class are cloneable with this method.
Rationals$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other special sets:
Complex
,
ExtendedReals
,
Integers
,
Logicals
,
Naturals
,
NegIntegers
,
NegRationals
,
NegReals
,
PosIntegers
,
PosNaturals
,
PosRationals
,
PosReals
,
Reals
,
Universal
The mathematical set of real numbers, defined as the union of the set of rationals and irrationals. i.e.
where is the set of irrationals and
is the set of rationals.
set6::Set
-> set6::Interval
-> set6::SpecialSet
-> Reals
new()
Create a new Reals
object.
Reals$new(lower = -Inf, upper = Inf, type = "()")
lower
numeric. Where to start the set. Advised to ignore, used by child-classes.
upper
numeric. Where to end the set. Advised to ignore, used by child-classes.
type
character Set closure type. Advised to ignore, used by child-classes.
A new Reals
object.
clone()
The objects of this class are cloneable with this method.
Reals$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other special sets:
Complex
,
ExtendedReals
,
Integers
,
Logicals
,
Naturals
,
NegIntegers
,
NegRationals
,
NegReals
,
PosIntegers
,
PosNaturals
,
PosRationals
,
PosReals
,
Rationals
,
Universal
A general Set object for mathematical sets. This also serves as the parent class to intervals, tuples, and fuzzy variants.
Mathematical sets can loosely be thought of as a collection of objects of any kind. The Set class is used for sets of finite elements, for infinite sets use Interval. These can be expanded for fuzzy logic by using FuzzySets. Elements in a set cannot be duplicated and ordering of elements does not matter, Tuples can be used if duplicates or ordering are required.
properties
Returns an object of class Properties
, which lists the properties of the Set. Set
properties include:
empty
- is the Set empty or does it contain elements?
singleton
- is the Set a singleton? i.e. Does it contain only one element?
cardinality
- number of elements in the Set
countability
- One of: countably finite, countably infinite, uncountable
closure
- One of: closed, open, half-open
traits
List the traits of the Set. Set traits include:
crisp
- is the Set crisp or fuzzy?
type
Returns the type of the Set. One of: (), (], [), [], {}
max
If the Set consists of numerics only then returns the maximum element in the Set. For open or half-open sets, then the maximum is defined by
min
If the Set consists of numerics only then returns the minimum element in the Set. For open or half-open sets, then the minimum is defined by
upper
If the Set consists of numerics only then returns the upper bound of the Set.
lower
If the Set consists of numerics only then returns the lower bound of the Set.
class
If all elements in the Set are the same class then returns that class, otherwise "ANY".
elements
If the Set is finite then returns all elements in the Set as a list
, otherwise "NA".
universe
Returns the universe of the Set, i.e. the set of values that can be added to the Set.
range
If the Set consists of numerics only then returns the range of the Set defined by
length
If the Set is finite then returns the number of elements in the Set, otherwise Inf. See the cardinality property for the type of infinity.
new()
Create a new Set
object.
Set$new(..., universe = Universal$new(), elements = NULL, class = NULL)
...
ANY
Elements can be of any class except list
, as long as there is a unique
as.character
coercion method available.
universe
Set. Universe that the Set lives in, i.e. elements that could be added to the Set. Default is Universal.
elements
list. Alternative constructor that may be more efficient if passing objects of multiple classes.
class
character. Optional string naming a class that if supplied gives the set the
typed
property. All elements will be coerced to this class and therefore there must be
a coercion method to this class available.
A new Set
object.
print()
Prints a symbolic representation of the Set
.
Set$print(n = 2)
n
numeric. Number of elements to display on either side of ellipsis when printing.
The function useUnicode()
can be used to determine if unicode should be used when
printing the Set
. Internally print
first calls strprint
to create a printable representation
of the Set.
strprint()
Creates a printable representation of the object.
Set$strprint(n = 2)
n
numeric. Number of elements to display on either side of ellipsis when printing.
A character string representing the object.
summary()
Summarises the Set
.
Set$summary(n = 2)
n
numeric. Number of elements to display on either side of ellipsis when printing.
The function useUnicode()
can be used to determine if unicode should be used when
printing the Set
. Summarised details include the Set
class, properties, and traits.
contains()
Tests to see if x
is contained in the Set.
Set$contains(x, all = FALSE, bound = NULL)
x
any. Object or vector of objects to test.
all
logical. If FALSE
tests each x
separately. Otherwise returns TRUE
only if all x
pass test.
bound
ignored, added for consistency.
x
can be of any type, including a Set itself. x
should be a tuple if
checking to see if it lies within a set of dimension greater than one. To test for multiple x
at the same time, then provide these as a list.
If all = TRUE
then returns TRUE
if all x
are contained in the Set
, otherwise
returns a vector of logicals.
If all
is TRUE
then returns TRUE
if all elements of x
are contained in the Set
, otherwise
FALSE.
If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
The infix operator %inset%
is available to test if x
is an element in the Set
,
see examples.
s = Set$new(elements = 1:5) # Simplest case s$contains(4) 8 %inset% s # Test if multiple elements lie in the set s$contains(4:6, all = FALSE) s$contains(4:6, all = TRUE) # Check if a tuple lies in a Set of higher dimension s2 = s * s s2$contains(Tuple$new(2,1)) c(Tuple$new(2,1), Tuple$new(1,7), 2) %inset% s2
equals()
Tests if two sets are equal.
Set$equals(x, all = FALSE)
Two sets are equal if they contain the same elements. Infix operators can be used for:
Equal | == |
Not equal | != |
If all
is TRUE
then returns TRUE
if all x
are equal to the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
# Equals Set$new(1,2)$equals(Set$new(5,6)) Set$new(1,2)$equals(Interval$new(1,2)) Set$new(1,2) == Interval$new(1,2, class = "integer") # Not equal !Set$new(1,2)$equals(Set$new(1,2)) Set$new(1,2) != Set$new(1,5)
isSubset()
Test if one set is a (proper) subset of another
Set$isSubset(x, proper = FALSE, all = FALSE)
x
any. Object or vector of objects to test.
proper
logical. If TRUE
tests for proper subsets.
all
logical. If FALSE
tests each x
separately. Otherwise returns TRUE
only if all x
pass test.
If using the method directly, and not via one of the operators then the additional boolean
argument proper
can be used to specify testing of subsets or proper subsets. A Set is a proper
subset of another if it is fully contained by the other Set (i.e. not equal to) whereas a Set is a
(non-proper) subset if it is fully contained by, or equal to, the other Set.
Infix operators can be used for:
Subset | < |
Proper Subset | <= |
Superset | > |
Proper Superset | >=
|
If all
is TRUE
then returns TRUE
if all x
are subsets of the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
Set$new(1,2,3)$isSubset(Set$new(1,2), proper = TRUE) Set$new(1,2) < Set$new(1,2,3) # proper subset c(Set$new(1,2,3), Set$new(1)) < Set$new(1,2,3) # not proper Set$new(1,2,3) <= Set$new(1,2,3) # proper
add()
Add elements to a set.
Set$add(...)
...
elements to add
$add
is a wrapper around the setunion
method with setunion(self, Set$new(...))
.
Note a key difference is that any elements passed to ...
are first converted to a Set
, this
important difference is illustrated in the examples by adding an Interval to a Set
.
Additionally, $add
first coerces ...
to $class
if self
is a typed-set (i.e. $class != "ANY"
),
and $add
checks if elements in ...
live in the universe of self
.
An object inheriting from Set.
Set$new(1,2)$add(3)$print() Set$new(1,2,universe = Interval$new(1,3))$add(3)$print() \dontrun{ # errors as 4 is not in [1,3] Set$new(1,2,universe = Interval$new(1,3))$add(4)$print() } # coerced to complex Set$new(0+1i, 2i, class = "complex")$add(4)$print() # setunion vs. add Set$new(1,2)$add(Interval$new(5,6))$print() Set$new(1,2) + Interval$new(5,6)
remove()
Remove elements from a set.
Set$remove(...)
...
elements to remove
$remove
is a wrapper around the setcomplement
method with
setcomplement(self, Set$new(...))
. Note a key difference is that any elements passed to ...
are first converted to a Set
, this important difference is illustrated in the examples by
removing an Interval from a Set
.
If the complement cannot be simplified to a Set
then a ComplementSet is returned
otherwise an object inheriting from Set is returned.
Set$new(1,2,3)$remove(1,2)$print() Set$new(1,Set$new(1),2)$remove(Set$new(1))$print() Interval$new(1,5)$remove(5)$print() Interval$new(1,5)$remove(4)$print() # setcomplement vs. remove Set$new(1,2,3)$remove(Interval$new(5,7))$print() Set$new(1,2,3) - Interval$new(5,7)
multiplicity()
Returns the number of times an element appears in a set,
Set$multiplicity(element = NULL)
element
element or list of elements in the set
, if NULL
returns multiplicity of all elements
Value, or list of values, in R+.
Set$new(1, 1, 2)$multiplicity() Set$new(1, 1, 2)$multiplicity(1) Set$new(1, 1, 2)$multiplicity(list(1, 2)) Tuple$new(1, 1, 2)$multiplicity(1) Tuple$new(1, 1, 2)$multiplicity(2)
clone()
The objects of this class are cloneable with this method.
Set$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other sets:
ConditionalSet
,
FuzzyMultiset
,
FuzzySet
,
FuzzyTuple
,
Interval
,
Multiset
,
Tuple
# Set of integers Set$new(1:5) # Set of multiple types Set$new("a", 5, Set$new(1)) # Each Set has properties and traits s <- Set$new(1, 2, 3) s$traits s$properties # Elements cannot be duplicated Set$new(2, 2) == Set$new(2) # Ordering does not matter Set$new(1, 2) == Set$new(2, 1) ## ------------------------------------------------ ## Method `Set$contains` ## ------------------------------------------------ s = Set$new(elements = 1:5) # Simplest case s$contains(4) 8 %inset% s # Test if multiple elements lie in the set s$contains(4:6, all = FALSE) s$contains(4:6, all = TRUE) # Check if a tuple lies in a Set of higher dimension s2 = s * s s2$contains(Tuple$new(2,1)) c(Tuple$new(2,1), Tuple$new(1,7), 2) %inset% s2 ## ------------------------------------------------ ## Method `Set$equals` ## ------------------------------------------------ # Equals Set$new(1,2)$equals(Set$new(5,6)) Set$new(1,2)$equals(Interval$new(1,2)) Set$new(1,2) == Interval$new(1,2, class = "integer") # Not equal !Set$new(1,2)$equals(Set$new(1,2)) Set$new(1,2) != Set$new(1,5) ## ------------------------------------------------ ## Method `Set$isSubset` ## ------------------------------------------------ Set$new(1,2,3)$isSubset(Set$new(1,2), proper = TRUE) Set$new(1,2) < Set$new(1,2,3) # proper subset c(Set$new(1,2,3), Set$new(1)) < Set$new(1,2,3) # not proper Set$new(1,2,3) <= Set$new(1,2,3) # proper ## ------------------------------------------------ ## Method `Set$add` ## ------------------------------------------------ Set$new(1,2)$add(3)$print() Set$new(1,2,universe = Interval$new(1,3))$add(3)$print() ## Not run: # errors as 4 is not in [1,3] Set$new(1,2,universe = Interval$new(1,3))$add(4)$print() ## End(Not run) # coerced to complex Set$new(0+1i, 2i, class = "complex")$add(4)$print() # setunion vs. add Set$new(1,2)$add(Interval$new(5,6))$print() Set$new(1,2) + Interval$new(5,6) ## ------------------------------------------------ ## Method `Set$remove` ## ------------------------------------------------ Set$new(1,2,3)$remove(1,2)$print() Set$new(1,Set$new(1),2)$remove(Set$new(1))$print() Interval$new(1,5)$remove(5)$print() Interval$new(1,5)$remove(4)$print() # setcomplement vs. remove Set$new(1,2,3)$remove(Interval$new(5,7))$print() Set$new(1,2,3) - Interval$new(5,7) ## ------------------------------------------------ ## Method `Set$multiplicity` ## ------------------------------------------------ Set$new(1, 1, 2)$multiplicity() Set$new(1, 1, 2)$multiplicity(1) Set$new(1, 1, 2)$multiplicity(list(1, 2)) Tuple$new(1, 1, 2)$multiplicity(1) Tuple$new(1, 1, 2)$multiplicity(2)
# Set of integers Set$new(1:5) # Set of multiple types Set$new("a", 5, Set$new(1)) # Each Set has properties and traits s <- Set$new(1, 2, 3) s$traits s$properties # Elements cannot be duplicated Set$new(2, 2) == Set$new(2) # Ordering does not matter Set$new(1, 2) == Set$new(2, 1) ## ------------------------------------------------ ## Method `Set$contains` ## ------------------------------------------------ s = Set$new(elements = 1:5) # Simplest case s$contains(4) 8 %inset% s # Test if multiple elements lie in the set s$contains(4:6, all = FALSE) s$contains(4:6, all = TRUE) # Check if a tuple lies in a Set of higher dimension s2 = s * s s2$contains(Tuple$new(2,1)) c(Tuple$new(2,1), Tuple$new(1,7), 2) %inset% s2 ## ------------------------------------------------ ## Method `Set$equals` ## ------------------------------------------------ # Equals Set$new(1,2)$equals(Set$new(5,6)) Set$new(1,2)$equals(Interval$new(1,2)) Set$new(1,2) == Interval$new(1,2, class = "integer") # Not equal !Set$new(1,2)$equals(Set$new(1,2)) Set$new(1,2) != Set$new(1,5) ## ------------------------------------------------ ## Method `Set$isSubset` ## ------------------------------------------------ Set$new(1,2,3)$isSubset(Set$new(1,2), proper = TRUE) Set$new(1,2) < Set$new(1,2,3) # proper subset c(Set$new(1,2,3), Set$new(1)) < Set$new(1,2,3) # not proper Set$new(1,2,3) <= Set$new(1,2,3) # proper ## ------------------------------------------------ ## Method `Set$add` ## ------------------------------------------------ Set$new(1,2)$add(3)$print() Set$new(1,2,universe = Interval$new(1,3))$add(3)$print() ## Not run: # errors as 4 is not in [1,3] Set$new(1,2,universe = Interval$new(1,3))$add(4)$print() ## End(Not run) # coerced to complex Set$new(0+1i, 2i, class = "complex")$add(4)$print() # setunion vs. add Set$new(1,2)$add(Interval$new(5,6))$print() Set$new(1,2) + Interval$new(5,6) ## ------------------------------------------------ ## Method `Set$remove` ## ------------------------------------------------ Set$new(1,2,3)$remove(1,2)$print() Set$new(1,Set$new(1),2)$remove(Set$new(1))$print() Interval$new(1,5)$remove(5)$print() Interval$new(1,5)$remove(4)$print() # setcomplement vs. remove Set$new(1,2,3)$remove(Interval$new(5,7))$print() Set$new(1,2,3) - Interval$new(5,7) ## ------------------------------------------------ ## Method `Set$multiplicity` ## ------------------------------------------------ Set$new(1, 1, 2)$multiplicity() Set$new(1, 1, 2)$multiplicity(1) Set$new(1, 1, 2)$multiplicity(list(1, 2)) Tuple$new(1, 1, 2)$multiplicity(1) Tuple$new(1, 1, 2)$multiplicity(2)
Displays the contents of the NEWS.md file for viewing set6 release information.
set6News()
set6News()
NEWS.md in viewer.
set6News()
set6News()
Returns the set difference of two objects inheriting from class Set
. If y
is missing
then the complement of x
from its universe is returned.
setcomplement(x, y, simplify = TRUE) ## S3 method for class 'Set' setcomplement(x, y, simplify = TRUE) ## S3 method for class 'Interval' setcomplement(x, y, simplify = TRUE) ## S3 method for class 'FuzzySet' setcomplement(x, y, simplify = TRUE) ## S3 method for class 'ConditionalSet' setcomplement(x, y, simplify = TRUE) ## S3 method for class 'Reals' setcomplement(x, y, simplify = TRUE) ## S3 method for class 'Rationals' setcomplement(x, y, simplify = TRUE) ## S3 method for class 'Integers' setcomplement(x, y, simplify = TRUE) ## S3 method for class 'ComplementSet' setcomplement(x, y, simplify = TRUE) ## S3 method for class 'Set' x - y
setcomplement(x, y, simplify = TRUE) ## S3 method for class 'Set' setcomplement(x, y, simplify = TRUE) ## S3 method for class 'Interval' setcomplement(x, y, simplify = TRUE) ## S3 method for class 'FuzzySet' setcomplement(x, y, simplify = TRUE) ## S3 method for class 'ConditionalSet' setcomplement(x, y, simplify = TRUE) ## S3 method for class 'Reals' setcomplement(x, y, simplify = TRUE) ## S3 method for class 'Rationals' setcomplement(x, y, simplify = TRUE) ## S3 method for class 'Integers' setcomplement(x, y, simplify = TRUE) ## S3 method for class 'ComplementSet' setcomplement(x, y, simplify = TRUE) ## S3 method for class 'Set' x - y
x , y
|
Set |
simplify |
logical, if |
The difference of two sets, , is defined as the set of elements that exist
in set
and not
,
The set difference of two ConditionalSets is defined by combining their defining functions by a negated
'and', !&
, operator. See examples.
The complement of fuzzy and crisp sets first coerces fuzzy sets to crisp sets by finding their support.
An object inheriting from Set
containing the set difference of elements in x
and y
.
Other operators:
powerset()
,
setintersect()
,
setpower()
,
setproduct()
,
setsymdiff()
,
setunion()
# absolute complement setcomplement(Set$new(1, 2, 3, universe = Reals$new())) setcomplement(Set$new(1, 2, universe = Set$new(1, 2, 3, 4, 5))) # complement of two sets Set$new(-2:4) - Set$new(2:5) setcomplement(Set$new(1, 4, "a"), Set$new("a", 6)) # complement of two intervals Interval$new(1, 10) - Interval$new(5, 15) Interval$new(1, 10) - Interval$new(-15, 15) Interval$new(1, 10) - Interval$new(-1, 2) # complement of mixed set types Set$new(1:10) - Interval$new(5, 15) Set$new(5, 7) - Tuple$new(6, 8, 7) # FuzzySet-Set returns a FuzzySet FuzzySet$new(1, 0.1, 2, 0.5) - Set$new(2:5) # Set-FuzzySet returns a Set Set$new(2:5) - FuzzySet$new(1, 0.1, 2, 0.5) # complement of conditional sets ConditionalSet$new(function(x, y, simplify = TRUE) x >= y) - ConditionalSet$new(function(x, y, simplify = TRUE) x == y) # complement of special sets Reals$new() - NegReals$new() Rationals$new() - PosRationals$new() Integers$new() - PosIntegers$new()
# absolute complement setcomplement(Set$new(1, 2, 3, universe = Reals$new())) setcomplement(Set$new(1, 2, universe = Set$new(1, 2, 3, 4, 5))) # complement of two sets Set$new(-2:4) - Set$new(2:5) setcomplement(Set$new(1, 4, "a"), Set$new("a", 6)) # complement of two intervals Interval$new(1, 10) - Interval$new(5, 15) Interval$new(1, 10) - Interval$new(-15, 15) Interval$new(1, 10) - Interval$new(-1, 2) # complement of mixed set types Set$new(1:10) - Interval$new(5, 15) Set$new(5, 7) - Tuple$new(6, 8, 7) # FuzzySet-Set returns a FuzzySet FuzzySet$new(1, 0.1, 2, 0.5) - Set$new(2:5) # Set-FuzzySet returns a Set Set$new(2:5) - FuzzySet$new(1, 0.1, 2, 0.5) # complement of conditional sets ConditionalSet$new(function(x, y, simplify = TRUE) x >= y) - ConditionalSet$new(function(x, y, simplify = TRUE) x == y) # complement of special sets Reals$new() - NegReals$new() Rationals$new() - PosRationals$new() Integers$new() - PosIntegers$new()
Returns the intersection of two objects inheriting from class Set
.
setintersect(x, y) ## S3 method for class 'Interval' setintersect(x, y) ## S3 method for class 'ConditionalSet' setintersect(x, y) ## S3 method for class 'UnionSet' setintersect(x, y) ## S3 method for class 'ComplementSet' setintersect(x, y) ## S3 method for class 'ProductSet' setintersect(x, y) ## S3 method for class 'Set' x & y
setintersect(x, y) ## S3 method for class 'Interval' setintersect(x, y) ## S3 method for class 'ConditionalSet' setintersect(x, y) ## S3 method for class 'UnionSet' setintersect(x, y) ## S3 method for class 'ComplementSet' setintersect(x, y) ## S3 method for class 'ProductSet' setintersect(x, y) ## S3 method for class 'Set' x & y
x , y
|
Set |
The intersection of two sets, , is defined as the set of elements that exist
in both sets,
In the case where no elements are common to either set, then the empty set is returned.
The intersection of two ConditionalSets is defined by combining their defining functions by an
'and', &
, operator. See examples.
The intersection of fuzzy and crisp sets first coerces fuzzy sets to crisp sets by finding their support.
A Set
consisting of elements in both x
and y
.
Other operators:
powerset()
,
setcomplement()
,
setpower()
,
setproduct()
,
setsymdiff()
,
setunion()
# intersection of two sets Set$new(-2:4) & Set$new(2:5) setintersect(Set$new(1, 4, "a"), Set$new("a", 6)) Set$new(1:4) & Set$new(5:7) # intersection of two intervals Interval$new(1, 10) & Interval$new(5, 15) Interval$new(1, 2) & Interval$new(2, 3) Interval$new(1, 5, class = "integer") & Interval$new(2, 7, class = "integer") # intersection of mixed set types Set$new(1:10) & Interval$new(5, 15) Set$new(5, 7) & Tuple$new(6, 8, 7) # Ignores membership of FuzzySet FuzzySet$new(1, 0.1, 2, 0.5) & Set$new(2:5) # intersection of conditional sets ConditionalSet$new(function(x, y) x >= y) & ConditionalSet$new(function(x, y) x == y) ConditionalSet$new(function(x) x == 2) & ConditionalSet$new(function(y) y == 3) # But be careful not to make an empty set ConditionalSet$new(function(x) x == 2) & ConditionalSet$new(function(x) x == 3)
# intersection of two sets Set$new(-2:4) & Set$new(2:5) setintersect(Set$new(1, 4, "a"), Set$new("a", 6)) Set$new(1:4) & Set$new(5:7) # intersection of two intervals Interval$new(1, 10) & Interval$new(5, 15) Interval$new(1, 2) & Interval$new(2, 3) Interval$new(1, 5, class = "integer") & Interval$new(2, 7, class = "integer") # intersection of mixed set types Set$new(1:10) & Interval$new(5, 15) Set$new(5, 7) & Tuple$new(6, 8, 7) # Ignores membership of FuzzySet FuzzySet$new(1, 0.1, 2, 0.5) & Set$new(2:5) # intersection of conditional sets ConditionalSet$new(function(x, y) x >= y) & ConditionalSet$new(function(x, y) x == y) ConditionalSet$new(function(x) x == 2) & ConditionalSet$new(function(y) y == 3) # But be careful not to make an empty set ConditionalSet$new(function(x) x == 2) & ConditionalSet$new(function(x) x == 3)
A convenience wrapper for the n-ary cartesian product of a Set
by itself,
possibly multiple times.
setpower(x, power, simplify = FALSE, nest = FALSE) ## S3 method for class 'Set' x ^ power
setpower(x, power, simplify = FALSE, nest = FALSE) ## S3 method for class 'Set' x ^ power
x |
Set |
power |
power to raise set to, if |
simplify |
logical, if |
nest |
logical, if |
See the details of setproduct for a longer discussion on the use of the nest
argument, in particular with regards to n-ary cartesian products vs. 'standard' cartesian
products.
An R6 object of class Set
or ExponentSet
inheriting from ProductSet
.
Other operators:
powerset()
,
setcomplement()
,
setintersect()
,
setproduct()
,
setsymdiff()
,
setunion()
# Power of a Set setpower(Set$new(1, 2), 3, simplify = FALSE) setpower(Set$new(1, 2), 3, simplify = TRUE) Set$new(1, 2)^3 # Power of an interval Interval$new(2, 5)^5 Reals$new()^3 # Use tuples for contains (PosNaturals$new()^3)$contains(Tuple$new(1, 2, 3)) # Power of ConditionalSet is meaningless ConditionalSet$new(function(x) TRUE)^2 # Power of FuzzySet FuzzySet$new(1, 0.1, 2, 0.5)^2 # Variable length x <- Interval$new(0, 1)^"n" x$contains(Tuple$new(0)) x$contains(Tuple$new(0, 1)) x$contains(Tuple$new(0, 1, 0, 0, 1, 1, 0)) x$contains(list(Tuple$new(0, 2), Tuple$new(1, 1)))
# Power of a Set setpower(Set$new(1, 2), 3, simplify = FALSE) setpower(Set$new(1, 2), 3, simplify = TRUE) Set$new(1, 2)^3 # Power of an interval Interval$new(2, 5)^5 Reals$new()^3 # Use tuples for contains (PosNaturals$new()^3)$contains(Tuple$new(1, 2, 3)) # Power of ConditionalSet is meaningless ConditionalSet$new(function(x) TRUE)^2 # Power of FuzzySet FuzzySet$new(1, 0.1, 2, 0.5)^2 # Variable length x <- Interval$new(0, 1)^"n" x$contains(Tuple$new(0)) x$contains(Tuple$new(0, 1)) x$contains(Tuple$new(0, 1, 0, 0, 1, 1, 0)) x$contains(list(Tuple$new(0, 2), Tuple$new(1, 1)))
Returns the cartesian product of objects inheriting from class Set
.
setproduct(..., simplify = FALSE, nest = FALSE) ## S3 method for class 'Set' x * y
setproduct(..., simplify = FALSE, nest = FALSE) ## S3 method for class 'Set' x * y
... |
Sets |
simplify |
logical, if |
nest |
logical, if |
x , y
|
The cartesian product of multiple sets, the 'n-ary Cartesian product', is often
implemented in programming languages as being identical to the cartesian product of two sets applied recursively.
However, for sets ,
This is accommodated with the nest
argument. If nest == TRUE
then , i.e. the cartesian
product for two sets is applied recursively. If
nest == FALSE
then and
the n-ary cartesian product is computed. As it appears the latter (n-ary product) is more common,
nest = FALSE
is the default. The N-ary cartesian product of sets,
, is defined as
where is a tuple.
The product of fuzzy and crisp sets first coerces fuzzy sets to crisp sets by finding their support.
Either an object of class ProductSet
or an unwrapped object inheriting from Set
.
Other operators:
powerset()
,
setcomplement()
,
setintersect()
,
setpower()
,
setsymdiff()
,
setunion()
# difference between nesting Set$new(1, 2) * Set$new(2, 3) * Set$new(4, 5) setproduct(Set$new(1, 2) * Set$new(2, 3), Set$new(4, 5), nest = FALSE) # same as above setproduct(Set$new(1, 2) * Set$new(2, 3), Set$new(4, 5), nest = TRUE) unnest_set <- setproduct(Set$new(1, 2) * Set$new(2, 3), Set$new(4, 5), nest = FALSE) nest_set <- setproduct(Set$new(1, 2) * Set$new(2, 3), Set$new(4, 5), nest = TRUE) # note the difference when using contains unnest_set$contains(Tuple$new(1, 3, 5)) nest_set$contains(Tuple$new(Tuple$new(1, 3), 5)) # product of two sets Set$new(-2:4) * Set$new(2:5) setproduct(Set$new(1, 4, "a"), Set$new("a", 6)) setproduct(Set$new(1, 4, "a"), Set$new("a", 6), simplify = TRUE) # product of two intervals Interval$new(1, 10) * Interval$new(5, 15) Interval$new(1, 2, type = "()") * Interval$new(2, 3, type = "(]") Interval$new(1, 5, class = "integer") * Interval$new(2, 7, class = "integer") # product of mixed set types Set$new(1:10) * Interval$new(5, 15) Set$new(5, 7) * Tuple$new(6, 8, 7) FuzzySet$new(1, 0.1) * Set$new(2) # product of FuzzySet FuzzySet$new(1, 0.1, 2, 0.5) * Set$new(2:5) # product of conditional sets ConditionalSet$new(function(x, y) x >= y) * ConditionalSet$new(function(x, y) x == y) # product of special sets PosReals$new() * NegReals$new()
# difference between nesting Set$new(1, 2) * Set$new(2, 3) * Set$new(4, 5) setproduct(Set$new(1, 2) * Set$new(2, 3), Set$new(4, 5), nest = FALSE) # same as above setproduct(Set$new(1, 2) * Set$new(2, 3), Set$new(4, 5), nest = TRUE) unnest_set <- setproduct(Set$new(1, 2) * Set$new(2, 3), Set$new(4, 5), nest = FALSE) nest_set <- setproduct(Set$new(1, 2) * Set$new(2, 3), Set$new(4, 5), nest = TRUE) # note the difference when using contains unnest_set$contains(Tuple$new(1, 3, 5)) nest_set$contains(Tuple$new(Tuple$new(1, 3), 5)) # product of two sets Set$new(-2:4) * Set$new(2:5) setproduct(Set$new(1, 4, "a"), Set$new("a", 6)) setproduct(Set$new(1, 4, "a"), Set$new("a", 6), simplify = TRUE) # product of two intervals Interval$new(1, 10) * Interval$new(5, 15) Interval$new(1, 2, type = "()") * Interval$new(2, 3, type = "(]") Interval$new(1, 5, class = "integer") * Interval$new(2, 7, class = "integer") # product of mixed set types Set$new(1:10) * Interval$new(5, 15) Set$new(5, 7) * Tuple$new(6, 8, 7) FuzzySet$new(1, 0.1) * Set$new(2) # product of FuzzySet FuzzySet$new(1, 0.1, 2, 0.5) * Set$new(2:5) # product of conditional sets ConditionalSet$new(function(x, y) x >= y) * ConditionalSet$new(function(x, y) x == y) # product of special sets PosReals$new() * NegReals$new()
Returns the symmetric difference of two objects inheriting from class Set
.
setsymdiff(x, y, simplify = TRUE) x %-% y
setsymdiff(x, y, simplify = TRUE) x %-% y
x , y
|
Set |
simplify |
logical, if |
The symmetric difference, aka disjunctive union, of two sets, , is defined as the set
of elements that exist in set
or in
but not both,
The symmetric difference can also be expressed as the union of two sets minus the intersection.
Therefore setsymdiff
is written as a thin wrapper over these operations, so for two sets, A,B
: A %-% B = (A | B) - (A & B)
.
The symmetric difference of fuzzy and crisp sets first coerces fuzzy sets to crisp sets by finding their support.
An object inheriting from Set
containing the symmetric difference of elements in both x
and y
.
Other operators:
powerset()
,
setcomplement()
,
setintersect()
,
setpower()
,
setproduct()
,
setunion()
# symmetrical difference compared to union and intersection Set$new(1, 2, 3) %-% Set$new(3, 4) (Set$new(1, 2, 3) | Set$new(3, 4)) - (Set$new(1, 2, 3) & Set$new(3, 4)) # ConditionalSets demonstrate the internal logic ConditionalSet$new(function(x) x > 0) %-% ConditionalSet$new(function(y) y == 0)
# symmetrical difference compared to union and intersection Set$new(1, 2, 3) %-% Set$new(3, 4) (Set$new(1, 2, 3) | Set$new(3, 4)) - (Set$new(1, 2, 3) & Set$new(3, 4)) # ConditionalSets demonstrate the internal logic ConditionalSet$new(function(x) x > 0) %-% ConditionalSet$new(function(y) y == 0)
Returns the union of objects inheriting from class Set.
setunion(..., simplify = TRUE) ## S3 method for class 'Set' x + y ## S3 method for class 'Set' x | y
setunion(..., simplify = TRUE) ## S3 method for class 'Set' x + y ## S3 method for class 'Set' x | y
... |
Sets |
simplify |
logical, if |
x , y
|
The union of sets,
, is defined as the set of elements that exist
in one or more sets,
The union of multiple ConditionalSets is given by combining their defining functions by an
'or', |
, operator. See examples.
The union of fuzzy and crisp sets first coerces fuzzy sets to crisp sets by finding their support.
An object inheriting from Set containing the union of supplied sets.
Other operators:
powerset()
,
setcomplement()
,
setintersect()
,
setpower()
,
setproduct()
,
setsymdiff()
# union of Sets Set$new(-2:4) + Set$new(2:5) setunion(Set$new(1, 4, "a"), Set$new("a", 6)) Set$new(1, 2) + Set$new("a", 1i) + Set$new(9) # union of intervals Interval$new(1, 10) + Interval$new(5, 15) + Interval$new(20, 30) Interval$new(1, 2, type = "()") + Interval$new(2, 3, type = "(]") Interval$new(1, 5, class = "integer") + Interval$new(2, 7, class = "integer") # union of mixed types Set$new(1:10) + Interval$new(5, 15) Set$new(1:10) + Interval$new(5, 15, class = "integer") Set$new(5, 7) | Tuple$new(6, 8, 7) # union of FuzzySet FuzzySet$new(1, 0.1, 2, 0.5) + Set$new(2:5) # union of conditional sets ConditionalSet$new(function(x, y) x >= y) + ConditionalSet$new(function(x, y) x == y) + ConditionalSet$new(function(x) x == 2) # union of special sets PosReals$new() + NegReals$new() Set$new(-Inf, Inf) + Reals$new()
# union of Sets Set$new(-2:4) + Set$new(2:5) setunion(Set$new(1, 4, "a"), Set$new("a", 6)) Set$new(1, 2) + Set$new("a", 1i) + Set$new(9) # union of intervals Interval$new(1, 10) + Interval$new(5, 15) + Interval$new(20, 30) Interval$new(1, 2, type = "()") + Interval$new(2, 3, type = "(]") Interval$new(1, 5, class = "integer") + Interval$new(2, 7, class = "integer") # union of mixed types Set$new(1:10) + Interval$new(5, 15) Set$new(1:10) + Interval$new(5, 15, class = "integer") Set$new(5, 7) | Tuple$new(6, 8, 7) # union of FuzzySet FuzzySet$new(1, 0.1, 2, 0.5) + Set$new(2:5) # union of conditional sets ConditionalSet$new(function(x, y) x >= y) + ConditionalSet$new(function(x, y) x == y) + ConditionalSet$new(function(x) x == 2) # union of special sets PosReals$new() + NegReals$new() Set$new(-Inf, Inf) + Reals$new()
This class should not be constructed directly. Parent class to SetWrapper
s.
Wrappers in set6 are utilised to facilitate lazy evaluation and symbolic representation.
Each operation has an associated wrapper that will be returned if simplify = FALSE
or if the
result would be too complex to return as a simple Set. Wrappers have an identical interface
to Set. Their primary advantage lies in a neat representation of any set composition (the
result of an operation) and the ability to query the set contents without ever directly
evaluating the set elements.
set6::Set
-> SetWrapper
wrappedSets
Returns the list of Set
s that are wrapped in the given wrapper.
new()
Create a new SetWrapper
object. It is not recommended to construct this class directly.
SetWrapper$new( setlist, lower = NULL, upper = NULL, type = NULL, class = NULL, cardinality )
A new SetWrapper
object.
equals()
Tests if x
is equal to self
.
SetWrapper$equals(x, all = FALSE)
If all == TRUE
then returns TRUE
if all x
are equal to self
, otherwise FALSE
.
If all == FALSE
returns a vector of logicals corresponding to the length of x
, representing
if each is equal to self
.
isSubset()
Tests if x
is a (proper) subset of self
.
SetWrapper$isSubset(x, proper = FALSE, all = FALSE)
x
x
any. Object or vector of objects to test.
proper
logical. If TRUE
tests for proper subsets.
all
logical. If FALSE
tests each x
separately. Otherwise returns TRUE
only if all x
pass test.
all
logical. If FALSE
tests each x
separately. Otherwise returns TRUE
only if all x
pass test.
If all == TRUE
then returns TRUE
if all x
are (proper) subsets of self
, otherwise FALSE
.
If all == FALSE
returns a vector of logicals corresponding to the length of x
, representing
if each is a (proper) subset of self
.
clone()
The objects of this class are cloneable with this method.
SetWrapper$clone(deep = FALSE)
deep
Whether to make a deep clone.
The 'special sets' are the group of sets that are commonly used in mathematics and are thus given their own names.
This is an abstract class and should not be constructed directly. Use listSpecialSets to see the list of implemented special sets.
set6::Set
-> set6::Interval
-> SpecialSet
new()
SpecialSet
is an abstract class, the constructor cannot be used directly.
SpecialSet$new(lower = -Inf, upper = Inf, type = "()", class = "numeric")
lower
defines the lower bound of the interval.
upper
defines the upper bound of the interval.
type
defines the interval closure type.
class
defines the interval class.
strprint()
Creates a printable representation of the object.
SpecialSet$strprint(n = NULL)
n
ignored, added for consistency.
A character string representing the object.
clone()
The objects of this class are cloneable with this method.
SpecialSet$clone(deep = FALSE)
deep
Whether to make a deep clone.
Validation checks to test if a given object is closed.
testClosed(object, errormsg = "This is not a closed set") checkClosed(object, errormsg = "This is not a closed set") assertClosed(object, errormsg = "This is not a closed set")
testClosed(object, errormsg = "This is not a closed set") checkClosed(object, errormsg = "This is not a closed set") assertClosed(object, errormsg = "This is not a closed set")
object |
object to test |
errormsg |
error message to overwrite default if check fails |
If check passes then assert
returns object
invisibly and test
/check
return TRUE
. If check fails, assert
stops code with error, check
returns
an error message as string, and test
returns FALSE
.
testClosed(Interval$new(1, 10, type = "[]")) testClosed(Interval$new(1, 10, type = "(]"))
testClosed(Interval$new(1, 10, type = "[]")) testClosed(Interval$new(1, 10, type = "(]"))
Validation checks to test if a given object is closedabove.
testClosedAbove(object, errormsg = "This is not a set closed above") checkClosedAbove(object, errormsg = "This is not a set closed above") assertClosedAbove(object, errormsg = "This is not a set closed above")
testClosedAbove(object, errormsg = "This is not a set closed above") checkClosedAbove(object, errormsg = "This is not a set closed above") assertClosedAbove(object, errormsg = "This is not a set closed above")
object |
object to test |
errormsg |
error message to overwrite default if check fails |
If check passes then assert
returns object
invisibly and test
/check
return TRUE
. If check fails, assert
stops code with error, check
returns
an error message as string, and test
returns FALSE
.
testClosedAbove(Interval$new(1, 10, type = "[]")) testClosedAbove(Interval$new(1, 10, type = "[)"))
testClosedAbove(Interval$new(1, 10, type = "[]")) testClosedAbove(Interval$new(1, 10, type = "[)"))
Validation checks to test if a given object is closedbelow.
testClosedBelow(object, errormsg = "This is not a set closed below") checkClosedBelow(object, errormsg = "This is not a set closed below") assertClosedBelow(object, errormsg = "This is not a set closed below")
testClosedBelow(object, errormsg = "This is not a set closed below") checkClosedBelow(object, errormsg = "This is not a set closed below") assertClosedBelow(object, errormsg = "This is not a set closed below")
object |
object to test |
errormsg |
error message to overwrite default if check fails |
If check passes then assert
returns object
invisibly and test
/check
return TRUE
. If check fails, assert
stops code with error, check
returns
an error message as string, and test
returns FALSE
.
testClosedBelow(Interval$new(1, 10, type = "[]")) testClosedBelow(Interval$new(1, 10, type = "(]"))
testClosedBelow(Interval$new(1, 10, type = "[]")) testClosedBelow(Interval$new(1, 10, type = "(]"))
Validation checks to test if a given object is an R6 ConditionalSet
.
testConditionalSet( object, errormsg = "This is not an R6 ConditionalSet object" ) checkConditionalSet( object, errormsg = "This is not an R6 ConditionalSet object" ) assertConditionalSet( object, errormsg = "This is not an R6 ConditionalSet object" )
testConditionalSet( object, errormsg = "This is not an R6 ConditionalSet object" ) checkConditionalSet( object, errormsg = "This is not an R6 ConditionalSet object" ) assertConditionalSet( object, errormsg = "This is not an R6 ConditionalSet object" )
object |
object to test |
errormsg |
error message to overwrite default if check fails |
If check passes then assert
returns object
invisibly and test
/check
return TRUE
. If check fails, assert
stops code with error, check
returns
an error message as string, and test
returns FALSE
.
testConditionalSet(Set$new(2, 3)) testConditionalSet(list(Set$new(2), Set$new(3))) testConditionalSet(Tuple$new(2, 3)) testConditionalSet(Interval$new()) testConditionalSet(FuzzySet$new(2, 0.1)) testConditionalSet(FuzzyTuple$new(2, 0.1)) testConditionalSet(ConditionalSet$new(function(x) x == 0))
testConditionalSet(Set$new(2, 3)) testConditionalSet(list(Set$new(2), Set$new(3))) testConditionalSet(Tuple$new(2, 3)) testConditionalSet(Interval$new()) testConditionalSet(FuzzySet$new(2, 0.1)) testConditionalSet(FuzzyTuple$new(2, 0.1)) testConditionalSet(ConditionalSet$new(function(x) x == 0))
Validation checks to test if given elements are contained in a set.
testContains( object, elements, errormsg = "elements are not contained in the set" ) checkContains( object, elements, errormsg = "elements are not contained in the set" ) assertContains( object, elements, errormsg = "elements are not contained in the set" )
testContains( object, elements, errormsg = "elements are not contained in the set" ) checkContains( object, elements, errormsg = "elements are not contained in the set" ) assertContains( object, elements, errormsg = "elements are not contained in the set" )
object |
object to test |
elements |
elements to check |
errormsg |
error message to overwrite default if check fails |
If check passes then assert
returns object
invisibly and test
/check
return TRUE
. If check fails, assert
stops code with error, check
returns
an error message as string, and test
returns FALSE
.
testContains(Set$new(1,2,3), c(1,2)) testContains(Set$new(1,2,3), c(3,4))
testContains(Set$new(1,2,3), c(1,2)) testContains(Set$new(1,2,3), c(3,4))
Validation checks to test if a given object is countablyfinite.
testCountablyFinite(object, errormsg = "This is not a countably finite set") checkCountablyFinite(object, errormsg = "This is not a countably finite set") assertCountablyFinite(object, errormsg = "This is not a countably finite set")
testCountablyFinite(object, errormsg = "This is not a countably finite set") checkCountablyFinite(object, errormsg = "This is not a countably finite set") assertCountablyFinite(object, errormsg = "This is not a countably finite set")
object |
object to test |
errormsg |
error message to overwrite default if check fails |
If check passes then assert
returns object
invisibly and test
/check
return TRUE
. If check fails, assert
stops code with error, check
returns
an error message as string, and test
returns FALSE
.
testCountablyFinite(Set$new(1,2,3)) testCountablyFinite(Interval$new(1,10))
testCountablyFinite(Set$new(1,2,3)) testCountablyFinite(Interval$new(1,10))
Validation checks to test if a given object is crisp.
testCrisp(object, errormsg = "This is not crisp.") checkCrisp(object, errormsg = "This is not crisp.") assertCrisp(object, errormsg = "This is not crisp.")
testCrisp(object, errormsg = "This is not crisp.") checkCrisp(object, errormsg = "This is not crisp.") assertCrisp(object, errormsg = "This is not crisp.")
object |
object to test |
errormsg |
error message to overwrite default if check fails |
If check passes then assert
returns object
invisibly and test
/check
return TRUE
. If check fails, assert
stops code with error, check
returns
an error message as string, and test
returns FALSE
.
testCrisp(Set$new(1)) testCrisp(FuzzySet$new(1, 0.5))
testCrisp(Set$new(1)) testCrisp(FuzzySet$new(1, 0.5))
Validation checks to test if a given object is empty.
testEmpty(object, errormsg = "This is not an empty set") checkEmpty(object, errormsg = "This is not an empty set") assertEmpty(object, errormsg = "This is not an empty set")
testEmpty(object, errormsg = "This is not an empty set") checkEmpty(object, errormsg = "This is not an empty set") assertEmpty(object, errormsg = "This is not an empty set")
object |
object to test |
errormsg |
error message to overwrite default if check fails |
If check passes then assert
returns object
invisibly and test
/check
return TRUE
. If check fails, assert
stops code with error, check
returns
an error message as string, and test
returns FALSE
.
testEmpty(Set$new()) testEmpty(Set$new(1))
testEmpty(Set$new()) testEmpty(Set$new(1))
Validation checks to test if a given object is finite.
testFinite(object, errormsg = "This is not finite") checkFinite(object, errormsg = "This is not finite") assertFinite(object, errormsg = "This is not finite")
testFinite(object, errormsg = "This is not finite") checkFinite(object, errormsg = "This is not finite") assertFinite(object, errormsg = "This is not finite")
object |
object to test |
errormsg |
error message to overwrite default if check fails |
If check passes then assert
returns object
invisibly and test
/check
return TRUE
. If check fails, assert
stops code with error, check
returns
an error message as string, and test
returns FALSE
.
testFinite(Interval$new(1, 10, class = "integer")) testFinite(Interval$new(1, 10, class = "numeric"))
testFinite(Interval$new(1, 10, class = "integer")) testFinite(Interval$new(1, 10, class = "numeric"))
Validation checks to test if a given object is fuzzy.
testFuzzy(object, errormsg = "This is not fuzzy.") checkFuzzy(object, errormsg = "This is not fuzzy.") assertFuzzy(object, errormsg = "This is not fuzzy.")
testFuzzy(object, errormsg = "This is not fuzzy.") checkFuzzy(object, errormsg = "This is not fuzzy.") assertFuzzy(object, errormsg = "This is not fuzzy.")
object |
object to test |
errormsg |
error message to overwrite default if check fails |
If check passes then assert
returns object
invisibly and test
/check
return TRUE
. If check fails, assert
stops code with error, check
returns
an error message as string, and test
returns FALSE
.
testFuzzy(FuzzySet$new(1, 0.5)) testFuzzy(Set$new(1))
testFuzzy(FuzzySet$new(1, 0.5)) testFuzzy(Set$new(1))
Validation checks to test if a given object is an R6 FuzzyMultiset
.
testFuzzyMultiset(object, errormsg = "This is not an R6 FuzzyMultiset object") checkFuzzyMultiset(object, errormsg = "This is not an R6 FuzzyMultiset object") assertFuzzyMultiset( object, errormsg = "This is not an R6 FuzzyMultiset object" )
testFuzzyMultiset(object, errormsg = "This is not an R6 FuzzyMultiset object") checkFuzzyMultiset(object, errormsg = "This is not an R6 FuzzyMultiset object") assertFuzzyMultiset( object, errormsg = "This is not an R6 FuzzyMultiset object" )
object |
object to test |
errormsg |
error message to overwrite default if check fails |
If check passes then assert
returns object
invisibly and test
/check
return TRUE
. If check fails, assert
stops code with error, check
returns
an error message as string, and test
returns FALSE
.
testFuzzyMultiset(Set$new(2, 3)) testFuzzyMultiset(list(Set$new(2), Set$new(3))) testFuzzyMultiset(Tuple$new(2, 3)) testFuzzyMultiset(Interval$new()) testFuzzyMultiset(FuzzySet$new(2, 0.1)) testFuzzyMultiset(FuzzyTuple$new(2, 0.1)) testFuzzyMultiset(ConditionalSet$new(function(x) x == 0))
testFuzzyMultiset(Set$new(2, 3)) testFuzzyMultiset(list(Set$new(2), Set$new(3))) testFuzzyMultiset(Tuple$new(2, 3)) testFuzzyMultiset(Interval$new()) testFuzzyMultiset(FuzzySet$new(2, 0.1)) testFuzzyMultiset(FuzzyTuple$new(2, 0.1)) testFuzzyMultiset(ConditionalSet$new(function(x) x == 0))
Validation checks to test if a given object is an R6 FuzzySet
.
testFuzzySet(object, errormsg = "This is not an R6 FuzzySet object") checkFuzzySet(object, errormsg = "This is not an R6 FuzzySet object") assertFuzzySet(object, errormsg = "This is not an R6 FuzzySet object")
testFuzzySet(object, errormsg = "This is not an R6 FuzzySet object") checkFuzzySet(object, errormsg = "This is not an R6 FuzzySet object") assertFuzzySet(object, errormsg = "This is not an R6 FuzzySet object")
object |
object to test |
errormsg |
error message to overwrite default if check fails |
If check passes then assert
returns object
invisibly and test
/check
return TRUE
. If check fails, assert
stops code with error, check
returns
an error message as string, and test
returns FALSE
.
testFuzzySet(Set$new(2, 3)) testFuzzySet(list(Set$new(2), Set$new(3))) testFuzzySet(Tuple$new(2, 3)) testFuzzySet(Interval$new()) testFuzzySet(FuzzySet$new(2, 0.1)) testFuzzySet(FuzzyTuple$new(2, 0.1)) testFuzzySet(ConditionalSet$new(function(x) x == 0))
testFuzzySet(Set$new(2, 3)) testFuzzySet(list(Set$new(2), Set$new(3))) testFuzzySet(Tuple$new(2, 3)) testFuzzySet(Interval$new()) testFuzzySet(FuzzySet$new(2, 0.1)) testFuzzySet(FuzzyTuple$new(2, 0.1)) testFuzzySet(ConditionalSet$new(function(x) x == 0))
Validation checks to test if a given object is an R6 FuzzyTuple
.
testFuzzyTuple(object, errormsg = "This is not an R6 FuzzyTuple object") checkFuzzyTuple(object, errormsg = "This is not an R6 FuzzyTuple object") assertFuzzyTuple(object, errormsg = "This is not an R6 FuzzyTuple object")
testFuzzyTuple(object, errormsg = "This is not an R6 FuzzyTuple object") checkFuzzyTuple(object, errormsg = "This is not an R6 FuzzyTuple object") assertFuzzyTuple(object, errormsg = "This is not an R6 FuzzyTuple object")
object |
object to test |
errormsg |
error message to overwrite default if check fails |
If check passes then assert
returns object
invisibly and test
/check
return TRUE
. If check fails, assert
stops code with error, check
returns
an error message as string, and test
returns FALSE
.
testFuzzyTuple(Set$new(2, 3)) testFuzzyTuple(list(Set$new(2), Set$new(3))) testFuzzyTuple(Tuple$new(2, 3)) testFuzzyTuple(Interval$new()) testFuzzyTuple(FuzzySet$new(2, 0.1)) testFuzzyTuple(FuzzyTuple$new(2, 0.1)) testFuzzyTuple(ConditionalSet$new(function(x) x == 0))
testFuzzyTuple(Set$new(2, 3)) testFuzzyTuple(list(Set$new(2), Set$new(3))) testFuzzyTuple(Tuple$new(2, 3)) testFuzzyTuple(Interval$new()) testFuzzyTuple(FuzzySet$new(2, 0.1)) testFuzzyTuple(FuzzyTuple$new(2, 0.1)) testFuzzyTuple(ConditionalSet$new(function(x) x == 0))
Validation checks to test if a given object is an R6 Interval
.
testInterval(object, errormsg = "This is not an R6 Interval object") checkInterval(object, errormsg = "This is not an R6 Interval object") assertInterval(object, errormsg = "This is not an R6 Interval object")
testInterval(object, errormsg = "This is not an R6 Interval object") checkInterval(object, errormsg = "This is not an R6 Interval object") assertInterval(object, errormsg = "This is not an R6 Interval object")
object |
object to test |
errormsg |
error message to overwrite default if check fails |
If check passes then assert
returns object
invisibly and test
/check
return TRUE
. If check fails, assert
stops code with error, check
returns
an error message as string, and test
returns FALSE
.
testInterval(Set$new(2, 3)) testInterval(list(Set$new(2), Set$new(3))) testInterval(Tuple$new(2, 3)) testInterval(Interval$new()) testInterval(FuzzySet$new(2, 0.1)) testInterval(FuzzyTuple$new(2, 0.1)) testInterval(ConditionalSet$new(function(x) x == 0))
testInterval(Set$new(2, 3)) testInterval(list(Set$new(2), Set$new(3))) testInterval(Tuple$new(2, 3)) testInterval(Interval$new()) testInterval(FuzzySet$new(2, 0.1)) testInterval(FuzzyTuple$new(2, 0.1)) testInterval(ConditionalSet$new(function(x) x == 0))
Validation checks to test if a given object is an R6 Multiset
.
testMultiset(object, errormsg = "This is not an R6 Multiset object") checkMultiset(object, errormsg = "This is not an R6 Multiset object") assertMultiset(object, errormsg = "This is not an R6 Multiset object")
testMultiset(object, errormsg = "This is not an R6 Multiset object") checkMultiset(object, errormsg = "This is not an R6 Multiset object") assertMultiset(object, errormsg = "This is not an R6 Multiset object")
object |
object to test |
errormsg |
error message to overwrite default if check fails |
If check passes then assert
returns object
invisibly and test
/check
return TRUE
. If check fails, assert
stops code with error, check
returns
an error message as string, and test
returns FALSE
.
testMultiset(Set$new(2, 3)) testMultiset(list(Set$new(2), Set$new(3))) testMultiset(Tuple$new(2, 3)) testMultiset(Interval$new()) testMultiset(FuzzySet$new(2, 0.1)) testMultiset(FuzzyTuple$new(2, 0.1)) testMultiset(ConditionalSet$new(function(x) x == 0))
testMultiset(Set$new(2, 3)) testMultiset(list(Set$new(2), Set$new(3))) testMultiset(Tuple$new(2, 3)) testMultiset(Interval$new()) testMultiset(FuzzySet$new(2, 0.1)) testMultiset(FuzzyTuple$new(2, 0.1)) testMultiset(ConditionalSet$new(function(x) x == 0))
Validation checks to test if a given object is an R6 Set
.
testSet(object, errormsg = "This is not an R6 Set object") checkSet(object, errormsg = "This is not an R6 Set object") assertSet(object, errormsg = "This is not an R6 Set object")
testSet(object, errormsg = "This is not an R6 Set object") checkSet(object, errormsg = "This is not an R6 Set object") assertSet(object, errormsg = "This is not an R6 Set object")
object |
object to test |
errormsg |
error message to overwrite default if check fails |
If check passes then assert
returns object
invisibly and test
/check
return TRUE
. If check fails, assert
stops code with error, check
returns
an error message as string, and test
returns FALSE
.
testSet(Set$new(2, 3)) testSet(list(Set$new(2), Set$new(3))) testSet(Tuple$new(2, 3)) testSet(Interval$new()) testSet(FuzzySet$new(2, 0.1)) testSet(FuzzyTuple$new(2, 0.1)) testSet(ConditionalSet$new(function(x) x == 0))
testSet(Set$new(2, 3)) testSet(list(Set$new(2), Set$new(3))) testSet(Tuple$new(2, 3)) testSet(Interval$new()) testSet(FuzzySet$new(2, 0.1)) testSet(FuzzyTuple$new(2, 0.1)) testSet(ConditionalSet$new(function(x) x == 0))
Validation checks to test if a given object is an R6 SetList
.
testSetList(object, errormsg = "One or more items in the list are not Sets") checkSetList(object, errormsg = "One or more items in the list are not Sets") assertSetList(object, errormsg = "One or more items in the list are not Sets")
testSetList(object, errormsg = "One or more items in the list are not Sets") checkSetList(object, errormsg = "One or more items in the list are not Sets") assertSetList(object, errormsg = "One or more items in the list are not Sets")
object |
object to test |
errormsg |
error message to overwrite default if check fails |
If check passes then assert
returns object
invisibly and test
/check
return TRUE
. If check fails, assert
stops code with error, check
returns
an error message as string, and test
returns FALSE
.
testSetList(Set$new(2, 3)) testSetList(list(Set$new(2), Set$new(3))) testSetList(Tuple$new(2, 3)) testSetList(Interval$new()) testSetList(FuzzySet$new(2, 0.1)) testSetList(FuzzyTuple$new(2, 0.1)) testSetList(ConditionalSet$new(function(x) x == 0))
testSetList(Set$new(2, 3)) testSetList(list(Set$new(2), Set$new(3))) testSetList(Tuple$new(2, 3)) testSetList(Interval$new()) testSetList(FuzzySet$new(2, 0.1)) testSetList(FuzzyTuple$new(2, 0.1)) testSetList(ConditionalSet$new(function(x) x == 0))
Validation checks to test if given sets are subsets of a set.
testSubset( object, sets, proper = FALSE, errormsg = "sets are not subsets of the object" ) checkSubset( object, sets, proper = FALSE, errormsg = "sets are not subsets of the object" ) assertSubset( object, sets, proper = FALSE, errormsg = "sets are not subsets of the object" )
testSubset( object, sets, proper = FALSE, errormsg = "sets are not subsets of the object" ) checkSubset( object, sets, proper = FALSE, errormsg = "sets are not subsets of the object" ) assertSubset( object, sets, proper = FALSE, errormsg = "sets are not subsets of the object" )
object |
object to test |
sets |
sets to check |
proper |
logical. If TRUE tests for proper subsets. |
errormsg |
error message to overwrite default if check fails |
If check passes then assert
returns object
invisibly and test
/check
return TRUE
. If check fails, assert
stops code with error, check
returns
an error message as string, and test
returns FALSE
.
testSubset(Set$new(1,2,3), Set$new(1,2)) testSubset(Set$new(1,2,3), Set$new(3,4))
testSubset(Set$new(1,2,3), Set$new(1,2)) testSubset(Set$new(1,2,3), Set$new(3,4))
Validation checks to test if a given object is an R6 Tuple
.
testTuple(object, errormsg = "This is not an R6 Tuple object") checkTuple(object, errormsg = "This is not an R6 Tuple object") assertTuple(object, errormsg = "This is not an R6 Tuple object")
testTuple(object, errormsg = "This is not an R6 Tuple object") checkTuple(object, errormsg = "This is not an R6 Tuple object") assertTuple(object, errormsg = "This is not an R6 Tuple object")
object |
object to test |
errormsg |
error message to overwrite default if check fails |
If check passes then assert
returns object
invisibly and test
/check
return TRUE
. If check fails, assert
stops code with error, check
returns
an error message as string, and test
returns FALSE
.
testTuple(Set$new(2, 3)) testTuple(list(Set$new(2), Set$new(3))) testTuple(Tuple$new(2, 3)) testTuple(Interval$new()) testTuple(FuzzySet$new(2, 0.1)) testTuple(FuzzyTuple$new(2, 0.1)) testTuple(ConditionalSet$new(function(x) x == 0))
testTuple(Set$new(2, 3)) testTuple(list(Set$new(2), Set$new(3))) testTuple(Tuple$new(2, 3)) testTuple(Interval$new()) testTuple(FuzzySet$new(2, 0.1)) testTuple(FuzzyTuple$new(2, 0.1)) testTuple(ConditionalSet$new(function(x) x == 0))
A general Tuple object for mathematical tuples, inheriting from Set
.
Tuples are similar to sets, except that they drop the constraint for elements to be unique, and
ordering in a tuple does matter. Tuples are useful for methods including $contains
that may
require non-unique elements. They are also the return type of the product of sets. See examples.
set6::Set
-> Tuple
equals()
Tests if two sets are equal.
Tuple$equals(x, all = FALSE)
An object is equal to a Tuple if it contains all the same elements, and in the same order. Infix operators can be used for:
Equal | == |
Not equal | != |
If all
is TRUE
then returns TRUE
if all x
are equal to the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
Tuple$new(1,2) == Tuple$new(1,2) Tuple$new(1,2) != Tuple$new(1,2) Tuple$new(1,1) != Set$new(1,1)
isSubset()
Test if one set is a (proper) subset of another
Tuple$isSubset(x, proper = FALSE, all = FALSE)
x
any. Object or vector of objects to test.
proper
logical. If TRUE
tests for proper subsets.
all
logical. If FALSE
tests each x
separately. Otherwise returns TRUE
only if all x
pass test.
If using the method directly, and not via one of the operators then the additional boolean
argument proper
can be used to specify testing of subsets or proper subsets. A Set is a proper
subset of another if it is fully contained by the other Set (i.e. not equal to) whereas a Set is a
(non-proper) subset if it is fully contained by, or equal to, the other Set.
When calling $isSubset
on objects inheriting from Interval, the method treats the interval as if
it is a Set, i.e. ordering and class are ignored. Use $isSubinterval
to test if one interval
is a subinterval of another.
Infix operators can be used for:
Subset | < |
Proper Subset | <= |
Superset | > |
Proper Superset | >=
|
An object is a (proper) subset of a Tuple if it contains all (some) of the same elements, and in the same order.
If all
is TRUE
then returns TRUE
if all x
are subsets of the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
Tuple$new(1,2,3) < Tuple$new(1,2,3,4) Tuple$new(1,3,2) < Tuple$new(1,2,3,4)
clone()
The objects of this class are cloneable with this method.
Tuple$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other sets:
ConditionalSet
,
FuzzyMultiset
,
FuzzySet
,
FuzzyTuple
,
Interval
,
Multiset
,
Set
# Tuple of integers Tuple$new(1:5) # Tuple of multiple types Tuple$new("a", 5, Set$new(1), Tuple$new(2)) # Each Tuple has properties and traits t <- Tuple$new(1, 2, 3) t$traits t$properties # Elements can be duplicated Tuple$new(2, 2) != Tuple$new(2) # Ordering does matter Tuple$new(1, 2) != Tuple$new(2, 1) ## ------------------------------------------------ ## Method `Tuple$equals` ## ------------------------------------------------ Tuple$new(1,2) == Tuple$new(1,2) Tuple$new(1,2) != Tuple$new(1,2) Tuple$new(1,1) != Set$new(1,1) ## ------------------------------------------------ ## Method `Tuple$isSubset` ## ------------------------------------------------ Tuple$new(1,2,3) < Tuple$new(1,2,3,4) Tuple$new(1,3,2) < Tuple$new(1,2,3,4)
# Tuple of integers Tuple$new(1:5) # Tuple of multiple types Tuple$new("a", 5, Set$new(1), Tuple$new(2)) # Each Tuple has properties and traits t <- Tuple$new(1, 2, 3) t$traits t$properties # Elements can be duplicated Tuple$new(2, 2) != Tuple$new(2) # Ordering does matter Tuple$new(1, 2) != Tuple$new(2, 1) ## ------------------------------------------------ ## Method `Tuple$equals` ## ------------------------------------------------ Tuple$new(1,2) == Tuple$new(1,2) Tuple$new(1,2) != Tuple$new(1,2) Tuple$new(1,1) != Set$new(1,1) ## ------------------------------------------------ ## Method `Tuple$isSubset` ## ------------------------------------------------ Tuple$new(1,2,3) < Tuple$new(1,2,3,4) Tuple$new(1,3,2) < Tuple$new(1,2,3,4)
UnionSet class for symbolic union of mathematical sets.
The purpose of this class is to provide a symbolic representation for the union of sets that cannot be represented in a simpler class. Whilst this is not an abstract class, it is not recommended to construct this class directly but via the set operation methods.
set6::Set
-> set6::SetWrapper
-> UnionSet
elements
Returns the elements in the object.
length
Returns the number of elements in the object.
new()
Create a new UnionSet
object. It is not recommended to construct this class directly.
UnionSet$new(setlist, lower = NULL, upper = NULL, type = NULL)
setlist
list
of Sets to wrap.
lower
lower bound of new object.
upper
upper bound of new object.
type
closure type of new object.
A new UnionSet
object.
strprint()
Creates a printable representation of the object.
UnionSet$strprint(n = 2)
n
numeric. Number of elements to display on either side of ellipsis when printing.
A character string representing the object.
contains()
Tests if elements x
are contained in self
.
UnionSet$contains(x, all = FALSE, bound = FALSE)
x
any. Object or vector of objects to test.
all
logical. If FALSE
tests each x
separately. Otherwise returns TRUE
only if all x
pass test.
bound
logical.
If all == TRUE
then returns TRUE
if all x
are contained in self
, otherwise FALSE
.
If all == FALSE
returns a vector of logicals corresponding to the length of x
, representing
if each is contained in self
. If bound == TRUE
then an element is contained in self
if it
is on or within the (possibly-open) bounds of self
, otherwise TRUE
only if the element is within
self
or the bounds are closed.
clone()
The objects of this class are cloneable with this method.
UnionSet$clone(deep = FALSE)
deep
Whether to make a deep clone.
Set operations: setunion, setproduct, setpower, setcomplement, setsymdiff, powerset, setintersect
Other wrappers:
ComplementSet
,
ExponentSet
,
PowersetSet
,
ProductSet
The Universal
is defined as the Set containing all possible elements.
The Universal set is the default universe to all sets, and is the largest possible set.
The Universal set contains every single possible element. We denote the Universal set with V
instead of U
to avoid confusion with the union symbol. The Universal set cardinality is set to
Inf
where we assume Inf
is greater than any Aleph
or Beth
numbers. The Universal set is
also responsible for a few set paradoxes, to resolve these we use the following results:
Let be the universal set,
be any non-universal set, and
the empty set, then
set6::Set
-> Universal
new()
Create a new Universal
object.
Universal$new()
The Universal set is the set containing every possible element.
A new Universal
object.
equals()
Tests if two sets are equal.
Universal$equals(x, all = FALSE)
If all
is TRUE
then returns TRUE
if all x
are equal to the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
Infix operators can be used for:
Equal | == |
Not equal | != |
# Equals Set$new(1,2)$equals(Set$new(5,6)) Set$new(1,2)$equals(Interval$new(1,2)) Set$new(1,2) == Interval$new(1,2, class = "integer") # Not equal !Set$new(1,2)$equals(Set$new(1,2)) Set$new(1,2) != Set$new(1,5)
isSubset()
Test if one set is a (proper) subset of another
Universal$isSubset(x, proper = FALSE, all = FALSE)
x
any. Object or vector of objects to test.
proper
logical. If TRUE
tests for proper subsets.
all
logical. If FALSE
tests each x
separately. Otherwise returns TRUE
only if all x
pass test.
If using the method directly, and not via one of the operators then the additional boolean
argument proper
can be used to specify testing of subsets or proper subsets. A Set is a proper
subset of another if it is fully contained by the other Set (i.e. not equal to) whereas a Set is a
(non-proper) subset if it is fully contained by, or equal to, the other Set.
When calling $isSubset
on objects inheriting from Interval, the method treats the interval as if
it is a Set, i.e. ordering and class are ignored. Use $isSubinterval
to test if one interval
is a subinterval of another.
Infix operators can be used for:
Subset | < |
Proper Subset | <= |
Superset | > |
Proper Superset | >=
|
Every Set
is a subset of a Universal
. No Set
is a super set of a Universal
,
and only a Universal
is not a proper subset of a Universal
.
If all
is TRUE
then returns TRUE
if all x
are subsets of the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
Set$new(1,2,3)$isSubset(Set$new(1,2), proper = TRUE) Set$new(1,2) < Set$new(1,2,3) # proper subset c(Set$new(1,2,3), Set$new(1)) < Set$new(1,2,3) # not proper Set$new(1,2,3) <= Set$new(1,2,3) # proper
contains()
Tests to see if x
is contained in the Set.
Universal$contains(x, all = FALSE, bound = NULL)
x
any. Object or vector of objects to test.
all
logical. If FALSE
tests each x
separately. Otherwise returns TRUE
only if all x
pass test.
bound
ignored.
x
can be of any type, including a Set itself. x
should be a tuple if
checking to see if it lies within a set of dimension greater than one. To test for multiple x
at the same time, then provide these as a list.
If using the method directly, and not via one of the operators then the additional boolean
arguments all
and bound
. If all = TRUE
then returns TRUE
if all x
are contained in the Set
, otherwise
returns a vector of logicals. For Intervals, bound
is used to specify if elements lying on the
(possibly open) boundary of the interval are considered contained (bound = TRUE
) or not (bound = FALSE
).
If all
is TRUE
then returns TRUE
if all elements of x
are contained in the Set
, otherwise
FALSE.
If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
The infix operator %inset%
is available to test if x
is an element in the Set
,
see examples.
Every element is contained within the Universal set.
s = Set$new(1:5) # Simplest case s$contains(4) 8 %inset% s # Test if multiple elements lie in the set s$contains(4:6, all = FALSE) s$contains(4:6, all = TRUE) # Check if a tuple lies in a Set of higher dimension s2 = s * s s2$contains(Tuple$new(2,1)) c(Tuple$new(2,1), Tuple$new(1,7), 2) %inset% s2
strprint()
Creates a printable representation of the object.
Universal$strprint(n = NULL)
n
numeric. Number of elements to display on either side of ellipsis when printing.
A character string representing the object.
clone()
The objects of this class are cloneable with this method.
Universal$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other special sets:
Complex
,
ExtendedReals
,
Integers
,
Logicals
,
Naturals
,
NegIntegers
,
NegRationals
,
NegReals
,
PosIntegers
,
PosNaturals
,
PosRationals
,
PosReals
,
Rationals
,
Reals
u <- Universal$new() print(u) u$contains(c(1, letters, TRUE, Set$new()), all = TRUE) ## ------------------------------------------------ ## Method `Universal$equals` ## ------------------------------------------------ # Equals Set$new(1,2)$equals(Set$new(5,6)) Set$new(1,2)$equals(Interval$new(1,2)) Set$new(1,2) == Interval$new(1,2, class = "integer") # Not equal !Set$new(1,2)$equals(Set$new(1,2)) Set$new(1,2) != Set$new(1,5) ## ------------------------------------------------ ## Method `Universal$isSubset` ## ------------------------------------------------ Set$new(1,2,3)$isSubset(Set$new(1,2), proper = TRUE) Set$new(1,2) < Set$new(1,2,3) # proper subset c(Set$new(1,2,3), Set$new(1)) < Set$new(1,2,3) # not proper Set$new(1,2,3) <= Set$new(1,2,3) # proper ## ------------------------------------------------ ## Method `Universal$contains` ## ------------------------------------------------ s = Set$new(1:5) # Simplest case s$contains(4) 8 %inset% s # Test if multiple elements lie in the set s$contains(4:6, all = FALSE) s$contains(4:6, all = TRUE) # Check if a tuple lies in a Set of higher dimension s2 = s * s s2$contains(Tuple$new(2,1)) c(Tuple$new(2,1), Tuple$new(1,7), 2) %inset% s2
u <- Universal$new() print(u) u$contains(c(1, letters, TRUE, Set$new()), all = TRUE) ## ------------------------------------------------ ## Method `Universal$equals` ## ------------------------------------------------ # Equals Set$new(1,2)$equals(Set$new(5,6)) Set$new(1,2)$equals(Interval$new(1,2)) Set$new(1,2) == Interval$new(1,2, class = "integer") # Not equal !Set$new(1,2)$equals(Set$new(1,2)) Set$new(1,2) != Set$new(1,5) ## ------------------------------------------------ ## Method `Universal$isSubset` ## ------------------------------------------------ Set$new(1,2,3)$isSubset(Set$new(1,2), proper = TRUE) Set$new(1,2) < Set$new(1,2,3) # proper subset c(Set$new(1,2,3), Set$new(1)) < Set$new(1,2,3) # not proper Set$new(1,2,3) <= Set$new(1,2,3) # proper ## ------------------------------------------------ ## Method `Universal$contains` ## ------------------------------------------------ s = Set$new(1:5) # Simplest case s$contains(4) 8 %inset% s # Test if multiple elements lie in the set s$contains(4:6, all = FALSE) s$contains(4:6, all = TRUE) # Check if a tuple lies in a Set of higher dimension s2 = s * s s2$contains(Tuple$new(2,1)) c(Tuple$new(2,1), Tuple$new(1,7), 2) %inset% s2
The UniversalSet
is defined as the Set containing all possible elements.
The Universal set is the default universe to all sets, and is the largest possible set.
The Universal set contains every single possible element. We denote the Universal set with V
instead of U
to avoid confusion with the union symbol. The Universal set cardinality is set to
Inf
where we assume Inf
is greater than any Aleph
or Beth
numbers. The Universal set is
also responsible for a few set paradoxes, to resolve these we use the following results:
Let be the universal set,
be any non-universal set, and
the empty set, then
set6::Set
-> UniversalSet
new()
Create a new UniversalSet
object.
UniversalSet$new()
The Universal set is the set containing every possible element.
A new UniversalSet
object.
equals()
Tests if two sets are equal.
UniversalSet$equals(x, all = FALSE)
If all
is TRUE
then returns TRUE
if all x
are equal to the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
Infix operators can be used for:
Equal | == |
Not equal | != |
# Equals Set$new(1,2)$equals(Set$new(5,6)) Set$new(1,2)$equals(Interval$new(1,2)) Set$new(1,2) == Interval$new(1,2, class = "integer") # Not equal !Set$new(1,2)$equals(Set$new(1,2)) Set$new(1,2) != Set$new(1,5)
isSubset()
Test if one set is a (proper) subset of another
UniversalSet$isSubset(x, proper = FALSE, all = FALSE)
x
any. Object or vector of objects to test.
proper
logical. If TRUE
tests for proper subsets.
all
logical. If FALSE
tests each x
separately. Otherwise returns TRUE
only if all x
pass test.
If using the method directly, and not via one of the operators then the additional boolean
argument proper
can be used to specify testing of subsets or proper subsets. A Set is a proper
subset of another if it is fully contained by the other Set (i.e. not equal to) whereas a Set is a
(non-proper) subset if it is fully contained by, or equal to, the other Set.
When calling $isSubset
on objects inheriting from Interval, the method treats the interval as if
it is a Set, i.e. ordering and class are ignored. Use $isSubinterval
to test if one interval
is a subinterval of another.
Infix operators can be used for:
Subset | < |
Proper Subset | <= |
Superset | > |
Proper Superset | >=
|
Every Set
is a subset of a UniversalSet
. No Set
is a super set of a UniversalSet
,
and only a UniversalSet
is not a proper subset of a UniversalSet
.
If all
is TRUE
then returns TRUE
if all x
are subsets of the Set, otherwise
FALSE
. If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
Set$new(1,2,3)$isSubset(Set$new(1,2), proper = TRUE) Set$new(1,2) < Set$new(1,2,3) # proper subset c(Set$new(1,2,3), Set$new(1)) < Set$new(1,2,3) # not proper Set$new(1,2,3) <= Set$new(1,2,3) # proper
contains()
Tests to see if x
is contained in the Set.
UniversalSet$contains(x, all = FALSE, bound = NULL)
x
any. Object or vector of objects to test.
all
logical. If FALSE
tests each x
separately. Otherwise returns TRUE
only if all x
pass test.
bound
ignored.
x
can be of any type, including a Set itself. x
should be a tuple if
checking to see if it lies within a set of dimension greater than one. To test for multiple x
at the same time, then provide these as a list.
If using the method directly, and not via one of the operators then the additional boolean
arguments all
and bound
. If all = TRUE
then returns TRUE
if all x
are contained in the Set
, otherwise
returns a vector of logicals. For Intervals, bound
is used to specify if elements lying on the
(possibly open) boundary of the interval are considered contained (bound = TRUE
) or not (bound = FALSE
).
If all
is TRUE
then returns TRUE
if all elements of x
are contained in the Set
, otherwise
FALSE.
If all
is FALSE
then returns a vector of logicals corresponding to each individual
element of x
.
The infix operator %inset%
is available to test if x
is an element in the Set
,
see examples.
Every element is contained within the Universal set.
s = Set$new(1:5) # Simplest case s$contains(4) 8 %inset% s # Test if multiple elements lie in the set s$contains(4:6, all = FALSE) s$contains(4:6, all = TRUE) # Check if a tuple lies in a Set of higher dimension s2 = s * s s2$contains(Tuple$new(2,1)) c(Tuple$new(2,1), Tuple$new(1,7), 2) %inset% s2
strprint()
Creates a printable representation of the object.
UniversalSet$strprint(n = NULL)
n
numeric. Number of elements to display on either side of ellipsis when printing.
A character string representing the object.
clone()
The objects of this class are cloneable with this method.
UniversalSet$clone(deep = FALSE)
deep
Whether to make a deep clone.
u <- UniversalSet$new() print(u) u$contains(c(1, letters, TRUE, Set$new()), all = TRUE) ## ------------------------------------------------ ## Method `UniversalSet$equals` ## ------------------------------------------------ # Equals Set$new(1,2)$equals(Set$new(5,6)) Set$new(1,2)$equals(Interval$new(1,2)) Set$new(1,2) == Interval$new(1,2, class = "integer") # Not equal !Set$new(1,2)$equals(Set$new(1,2)) Set$new(1,2) != Set$new(1,5) ## ------------------------------------------------ ## Method `UniversalSet$isSubset` ## ------------------------------------------------ Set$new(1,2,3)$isSubset(Set$new(1,2), proper = TRUE) Set$new(1,2) < Set$new(1,2,3) # proper subset c(Set$new(1,2,3), Set$new(1)) < Set$new(1,2,3) # not proper Set$new(1,2,3) <= Set$new(1,2,3) # proper ## ------------------------------------------------ ## Method `UniversalSet$contains` ## ------------------------------------------------ s = Set$new(1:5) # Simplest case s$contains(4) 8 %inset% s # Test if multiple elements lie in the set s$contains(4:6, all = FALSE) s$contains(4:6, all = TRUE) # Check if a tuple lies in a Set of higher dimension s2 = s * s s2$contains(Tuple$new(2,1)) c(Tuple$new(2,1), Tuple$new(1,7), 2) %inset% s2
u <- UniversalSet$new() print(u) u$contains(c(1, letters, TRUE, Set$new()), all = TRUE) ## ------------------------------------------------ ## Method `UniversalSet$equals` ## ------------------------------------------------ # Equals Set$new(1,2)$equals(Set$new(5,6)) Set$new(1,2)$equals(Interval$new(1,2)) Set$new(1,2) == Interval$new(1,2, class = "integer") # Not equal !Set$new(1,2)$equals(Set$new(1,2)) Set$new(1,2) != Set$new(1,5) ## ------------------------------------------------ ## Method `UniversalSet$isSubset` ## ------------------------------------------------ Set$new(1,2,3)$isSubset(Set$new(1,2), proper = TRUE) Set$new(1,2) < Set$new(1,2,3) # proper subset c(Set$new(1,2,3), Set$new(1)) < Set$new(1,2,3) # not proper Set$new(1,2,3) <= Set$new(1,2,3) # proper ## ------------------------------------------------ ## Method `UniversalSet$contains` ## ------------------------------------------------ s = Set$new(1:5) # Simplest case s$contains(4) 8 %inset% s # Test if multiple elements lie in the set s$contains(4:6, all = FALSE) s$contains(4:6, all = TRUE) # Check if a tuple lies in a Set of higher dimension s2 = s * s s2$contains(Tuple$new(2,1)) c(Tuple$new(2,1), Tuple$new(1,7), 2) %inset% s2
Change whether unicode symbols should be used when printing sets.
useUnicode(use)
useUnicode(use)
use |
logical, if |
Using unicode symbols makes the printing of sets and properties 'prettier', however may not
work on all machines or versions of R
. Therefore this function is used to decide whether
unicode representations should be used, or standard alpha-numeric and special characters.
By default set6
starts with unicode printing turned on.
current <- useUnicode() useUnicode(TRUE) useUnicode() useUnicode(current)
current <- useUnicode() useUnicode(TRUE) useUnicode() useUnicode(current)