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
conditionReturns the condition defining the ConditionalSet.
classReturns argclass, see $new.
elementsReturns NA.
Inherited methods
new()Create a new ConditionalSet object.
ConditionalSet$new(condition = function(x) TRUE, argclass = NULL)
conditionfunction. Defines the set, see details.
argclasslist. 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)
xany. Object or vector of objects to test.
alllogical. If FALSE tests each x separately. Otherwise returns TRUE only if all x pass test.
boundignored, 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)
nignored, added for consistency.
A character string representing the object.
summary()See strprint.
ConditionalSet$summary(n = NULL)
nignored, added for consistency.
isSubset()Currently undefined for ConditionalSets.
ConditionalSet$isSubset(x, proper = FALSE, all = FALSE)
xignored, added for consistency.
properignored, added for consistency.
allignored, added for consistency.
clone()The objects of this class are cloneable with this method.
ConditionalSet$clone(deep = FALSE)
deepWhether 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