A mathematical set defined by one or more logical conditions.

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

Super class

set6::Set -> ConditionalSet

Active bindings

condition

Returns the condition defining the ConditionalSet.

class

Returns argclass, see $new.

elements

Returns NA.

Methods

Public methods

Inherited methods

Method new()

Create a new ConditionalSet object.

Usage

ConditionalSet$new(condition = function(x) TRUE, argclass = NULL)

Arguments

condition

function. Defines the set, see details.

argclass

list. Optional list of sets that the function arguments live in, see details.

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.

Returns

A new ConditionalSet object.


Method contains()

Tests to see if x is contained in the Set.

Usage

ConditionalSet$contains(x, all = FALSE, bound = NULL)

Arguments

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.

Details

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.

Returns

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.

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))


Method equals()

Tests if two sets are equal.

Usage

ConditionalSet$equals(x, all = FALSE)

Arguments

x

Set or vector of Sets.

all

logical. If FALSE tests each x separately. Otherwise returns TRUE only if all x pass test.

Details

Two sets are equal if they contain the same elements. Infix operators can be used for:

Equal==
Not equal!=

Returns

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.


Method strprint()

Creates a printable representation of the object.

Usage

ConditionalSet$strprint(n = NULL)

Arguments

n

ignored, added for consistency.

Returns

A character string representing the object.


Method summary()

See strprint.

Usage

ConditionalSet$summary(n = NULL)

Arguments

n

ignored, added for consistency.


Method isSubset()

Currently undefined for ConditionalSets.

Usage

ConditionalSet$isSubset(x, proper = FALSE, all = FALSE)

Arguments

x

ignored, added for consistency.

proper

ignored, added for consistency.

all

ignored, added for consistency.


Method clone()

The objects of this class are cloneable with this method.

Usage

ConditionalSet$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

# 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