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.
Other sets:
FuzzyMultiset
,
FuzzySet
,
FuzzyTuple
,
Interval
,
Multiset
,
Set
,
Tuple
set6::Set
-> ConditionalSet
condition
Returns the condition defining the ConditionalSet.
class
Returns argclass
, see $new
.
elements
Returns NA
.
Inherited methods
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.
# 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)) #> [1] TRUE FALSE # Set via equality s = ConditionalSet$new(function(x, y) x + y == 2) s$contains(list(Set$new(2, 0), Set$new(0, 2))) #> [1] TRUE TRUE # Tuples are recommended when using contains as they allow non-unique elements s = ConditionalSet$new(function(x, y) x + y == 4) if (FALSE) { 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)) #> [1] FALSE TRUE