Learn R Programming

set6 (version 0.1.1)

ConditionalSet: Mathematical Set of Conditions

Description

A mathematical set defined by one or more logical conditions.

Value

R6 object of class ConditionalSet inheriting from Set.

Constructor

ConditionalSet$new(condition, argclass = NULL)

Constructor Arguments

Argument Type Details
condition function Function for defining the set. See constructor details.

Constructor 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 the UniversalSet is assumed. See examples.

Public Fields

Field Link
condition condition

class class elements elements length length lower lower upper upper max max min min range range properties properties traits traits type type

Public Methods

Comparison Methods Link contains(x, all = FALSE, bound = NULL) contains equals(x, all = FALSE) equals isSubset(x, proper = FALSE, all = FALSE) isSubset Representation Methods Link strprint(n = 2) strprint print(n = 2) print summary(n = 2) summary

Details

Conditional sets are a useful tool for symbolically defining possibly infinite sets. They can be combined using standard 'and', &, and 'or', |, operators.

See Also

Other sets: FuzzySet, FuzzyTuple, Interval, Set, Tuple, UniversalSet

Examples

Run this code
# NOT RUN {
# 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)
# }
# NOT RUN {
s$contains(Tuple$new(2, 2))

# Set of Positive Naturals
s = ConditionalSet$new(function(x) TRUE, argclass = list(x = PosNaturals$new()))
s$contains(list(-2, 2))

# }

Run the code above in your browser using DataLab