From 18bfac4ab75034b3a70e59d69e8045f514080fe8 Mon Sep 17 00:00:00 2001 From: Raphael Sonabend Date: Fri, 17 Jul 2020 21:38:53 +0100 Subject: [PATCH] docs, fixes in variable exponent --- CRAN-RELEASE | 2 + R/SetWrapper_ExponentSet.R | 51 +++++++++++------------ R/operation_cleaner.R | 5 +++ R/operation_setpower.R | 15 ++++--- R/operation_setproduct.R | 6 +++ man/ConditionalSet.Rd | 3 +- man/ExponentSet.Rd | 13 +++--- man/FuzzySet.Rd | 3 +- man/FuzzyTuple.Rd | 3 +- man/Interval.Rd | 5 +-- man/LogicalSet.Rd | 3 +- man/Set.Rd | 3 +- man/Tuple.Rd | 3 +- man/UniversalSet.Rd | 3 +- man/as.FuzzySet.Rd | 14 ++++--- man/as.Interval.Rd | 15 ++++--- man/as.Set.Rd | 3 +- man/listSpecialSets.Rd | 6 ++- man/powerSet.Rd | 8 ++-- man/setcomplement.Rd | 15 ++++--- man/setintersect.Rd | 13 +++--- man/setpower.Rd | 26 ++++++++---- man/setproduct.Rd | 19 ++++----- man/setsymdiff.Rd | 5 +-- man/setunion.Rd | 13 +++--- man/useUnicode.Rd | 2 +- tests/testthat/test_operations_setpower.R | 7 ++++ 27 files changed, 147 insertions(+), 117 deletions(-) create mode 100644 CRAN-RELEASE diff --git a/CRAN-RELEASE b/CRAN-RELEASE new file mode 100644 index 00000000..0f083b94 --- /dev/null +++ b/CRAN-RELEASE @@ -0,0 +1,2 @@ +This package was submitted to CRAN on 2020-07-17. +Once it is accepted, delete this file and tag the release (commit 502c918e89). diff --git a/R/SetWrapper_ExponentSet.R b/R/SetWrapper_ExponentSet.R index 9241ef59..4627a5b1 100644 --- a/R/SetWrapper_ExponentSet.R +++ b/R/SetWrapper_ExponentSet.R @@ -6,7 +6,8 @@ ExponentSet <- R6Class("ExponentSet", inherit = ProductSet, public = list( - #' @description Create a new `ExponentSet` object. It is not recommended to construct this class directly. + #' @description Create a new `ExponentSet` object. It is not recommended to construct this + #' class directly. #' @param set [Set] to wrap. #' @param power numeric. Power to raise Set to. #' @return A new `ExponentSet` object. @@ -53,38 +54,36 @@ ExponentSet <- R6Class("ExponentSet", #' @description Tests if elements `x` are contained in `self`. #' @template param_xall #' @param bound logical - #' @return 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. + #' @return 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. contains = function(x, all = FALSE, bound = FALSE) { - if (self$power == "n") { - if (!testTuple(x)) { - stop("Variable exponent set can only perform containedness checks on a single tuple.") - } else { - if (x$length == 1) { - return(self$wrappedSets[[1]]$contains(x$elements[[1]], all, bound)) - } else { - return(setpower(self$wrappedSets[[1]], x$length)$contains(x, all, bound)) - } - } - } - x <- listify(x) - ret <- sapply(x, function(el) { - if (!testSet(el)) { - el <- as.Set(el) + if (self$power == "n") { + len <- x[[1]]$length + if (len == 1) { + return(self$wrappedSets[[1]]$contains(unlist(rsapply(x, "elements", active = TRUE)), + all, bound)) + } else { + return(setpower(self$wrappedSets[[1]], len)$contains(x, all, bound)) } + } else { + ret <- sapply(x, function(el) { + if (!testSet(el)) { + el <- as.Set(el) + } - if (el$length != self$power) { - return(FALSE) - } + if (el$length != self$power) { + return(FALSE) + } - all(self$wrappedSets[[1]]$contains(el$elements, bound = bound)) - }) + all(self$wrappedSets[[1]]$contains(el$elements, bound = bound)) + }) + } returner(ret, all) } diff --git a/R/operation_cleaner.R b/R/operation_cleaner.R index cd55c04b..6dc461cd 100644 --- a/R/operation_cleaner.R +++ b/R/operation_cleaner.R @@ -11,6 +11,11 @@ operation_cleaner <- function(sets, operation_class, nest, simplify = TRUE) { } else if (is.null(wraps)) { return(x) } else { + if (inherits(x, "ExponentSet")) { + if (x$power == "n") { + return(x) + } + } return(wraps) } })) diff --git a/R/operation_setpower.R b/R/operation_setpower.R index 30dacaed..1a2fd49a 100644 --- a/R/operation_setpower.R +++ b/R/operation_setpower.R @@ -41,11 +41,12 @@ #' x$contains(Tuple$new(0)) #' x$contains(Tuple$new(0, 1)) #' x$contains(Tuple$new(0, 1, 0, 0, 1, 1, 0)) -#' x$contains(Tuple$new(0, 2)) +#' x$contains(list(Tuple$new(0, 2), Tuple$new(1, 1))) #' #' @export setpower <- function(x, power, simplify = FALSE, nest = FALSE) { - if (getR6Class(x) == "UniversalSet") { + classx <- getR6Class(x) + if (classx == "UniversalSet") { return(x) } @@ -55,11 +56,15 @@ setpower <- function(x, power, simplify = FALSE, nest = FALSE) { return(x) } else if (power == "n") { return(ExponentSet$new(x, power)) - } else if (getR6Class(x) %in% c("Set", "FuzzySet", "Tuple", "FuzzyTuple") & simplify) { + } else if (classx %in% c("Set", "FuzzySet", "Tuple", "FuzzyTuple") & simplify) { x <- rep(list(x), power) return(do.call(setproduct, c(x, list(nest = nest, simplify = TRUE)))) - } else if (inherits(x, "ExponentSet")) { - return(ExponentSet$new(x$wrappedSets[[1]], x$power * power)) + } else if (classx == "ExponentSet") { + if (x$power == "n") { + return(x) + } else { + return(ExponentSet$new(x$wrappedSets[[1]], x$power * power)) + } } else { return(ExponentSet$new(x, power)) } diff --git a/R/operation_setproduct.R b/R/operation_setproduct.R index 0e87da19..edd5c9c9 100644 --- a/R/operation_setproduct.R +++ b/R/operation_setproduct.R @@ -75,6 +75,12 @@ setproduct <- function(..., simplify = FALSE, nest = FALSE) { } classes <- sapply(sets, getR6Class) + if ("ExponentSet" %in% classes) { + varexp <- sapply(sets[classes == "ExponentSet"], function(x) x$power == "n") + if (any(varexp)) { + return(sets[classes == "ExponentSet"][which(varexp)[1]][[1]]) + } + } if (length(unique(rsapply(sets, "strprint"))) == 1 & !simplify) { return(ExponentSet$new(sets[[1]], length(sets))) diff --git a/man/ConditionalSet.Rd b/man/ConditionalSet.Rd index 9cb86d2d..19b6b691 100644 --- a/man/ConditionalSet.Rd +++ b/man/ConditionalSet.Rd @@ -12,8 +12,7 @@ using standard 'and', \code{&}, and 'or', \code{|}, operators. } \examples{ # Set of Positive Naturals -s = ConditionalSet$new(function(x) TRUE, argclass = list(x = PosNaturals$new())) - +s <- ConditionalSet$new(function(x) TRUE, argclass = list(x = PosNaturals$new())) ## ------------------------------------------------ ## Method `ConditionalSet$contains` diff --git a/man/ExponentSet.Rd b/man/ExponentSet.Rd index dd9640b5..de1071ad 100644 --- a/man/ExponentSet.Rd +++ b/man/ExponentSet.Rd @@ -56,7 +56,8 @@ Other wrappers: \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-new}{}}} \subsection{Method \code{new()}}{ -Create a new \code{ExponentSet} object. It is not recommended to construct this class directly. +Create a new \code{ExponentSet} object. It is not recommended to construct this +class directly. \subsection{Usage}{ \if{html}{\out{
}}\preformatted{ExponentSet$new(set, power)}\if{html}{\out{
}} } @@ -115,11 +116,11 @@ Tests if elements \code{x} are contained in \code{self}. \if{html}{\out{}} } \subsection{Returns}{ -If \code{all == TRUE} then returns \code{TRUE} if all \code{x} are contained in \code{self}, otherwise \code{FALSE}. -If \code{all == FALSE} returns a vector of logicals corresponding to the length of \code{x}, representing -if each is contained in \code{self}. If \code{bound == TRUE} then an element is contained in \code{self} if it -is on or within the (possibly-open) bounds of \code{self}, otherwise \code{TRUE} only if the element is within -\code{self} or the bounds are closed. +If \code{all == TRUE} then returns \code{TRUE} if all \code{x} are contained in \code{self}, +otherwise \code{FALSE}. If \code{all == FALSE} returns a vector of logicals corresponding to the +length of \code{x}, representing if each is contained in \code{self}. If \code{bound == TRUE} then an +element is contained in \code{self} if it is on or within the (possibly-open) bounds of \code{self}, +otherwise \code{TRUE} only if the element is within \code{self} or the bounds are closed. } } \if{html}{\out{
}} diff --git a/man/FuzzySet.Rd b/man/FuzzySet.Rd index de8e75dd..b0fb4994 100644 --- a/man/FuzzySet.Rd +++ b/man/FuzzySet.Rd @@ -24,7 +24,7 @@ FuzzySet$new(elements = 1:3, membership = c(0.5, 1, 0)) # 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 <- FuzzySet$new(1, 0.2, 2, 1, 3, 0) f$membership() f$alphaCut(0.3) f$core() @@ -32,7 +32,6 @@ f$inclusion(0) f$membership(0) f$membership(1) - ## ------------------------------------------------ ## Method `FuzzySet$membership` ## ------------------------------------------------ diff --git a/man/FuzzyTuple.Rd b/man/FuzzyTuple.Rd index 526351c5..e10d62ef 100644 --- a/man/FuzzyTuple.Rd +++ b/man/FuzzyTuple.Rd @@ -24,7 +24,7 @@ FuzzyTuple$new(elements = 1:3, membership = c(0.5, 1, 0)) # 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 <- FuzzyTuple$new(1, 0.2, 2, 1, 3, 0) f$membership() f$alphaCut(0.3) f$core() @@ -39,7 +39,6 @@ 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) - } \seealso{ Other sets: diff --git a/man/Interval.Rd b/man/Interval.Rd index 411eefe4..25bf92d7 100644 --- a/man/Interval.Rd +++ b/man/Interval.Rd @@ -19,18 +19,17 @@ Interval$new() Interval$new(class = "integer") # Half-open interval -i = Interval$new(1, 10, "(]") +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") +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` ## ------------------------------------------------ diff --git a/man/LogicalSet.Rd b/man/LogicalSet.Rd index 88d3d378..3e71d63e 100644 --- a/man/LogicalSet.Rd +++ b/man/LogicalSet.Rd @@ -7,10 +7,9 @@ The \code{LogicalSet} is defined as the \link{Set} containing the elements \code{TRUE} and \code{FALSE}. } \examples{ -l = LogicalSet$new() +l <- LogicalSet$new() print(l) l$contains(list(TRUE, 1, FALSE)) - } \seealso{ Other sets: diff --git a/man/Set.Rd b/man/Set.Rd index 4fafecbc..33f807d8 100644 --- a/man/Set.Rd +++ b/man/Set.Rd @@ -21,7 +21,7 @@ Set$new(1:5) Set$new("a", 5, Set$new(1)) # Each Set has properties and traits -s = Set$new(1,2,3) +s <- Set$new(1, 2, 3) s$traits s$properties @@ -31,7 +31,6 @@ Set$new(2, 2) == Set$new(2) # Ordering does not matter Set$new(1, 2) == Set$new(2, 1) - ## ------------------------------------------------ ## Method `Set$contains` ## ------------------------------------------------ diff --git a/man/Tuple.Rd b/man/Tuple.Rd index 63794089..46493d22 100644 --- a/man/Tuple.Rd +++ b/man/Tuple.Rd @@ -19,7 +19,7 @@ Tuple$new(1:5) Tuple$new("a", 5, Set$new(1), Tuple$new(2)) # Each Tuple has properties and traits -t = Tuple$new(1,2,3) +t <- Tuple$new(1, 2, 3) t$traits t$properties @@ -29,7 +29,6 @@ Tuple$new(2, 2) != Tuple$new(2) # Ordering does matter Tuple$new(1, 2) != Tuple$new(2, 1) - ## ------------------------------------------------ ## Method `Tuple$equals` ## ------------------------------------------------ diff --git a/man/UniversalSet.Rd b/man/UniversalSet.Rd index 5c42c9c1..440a3089 100644 --- a/man/UniversalSet.Rd +++ b/man/UniversalSet.Rd @@ -22,11 +22,10 @@ Let \eqn{V} be the universal set, \eqn{S} be any non-universal set, and \eqn{0} \deqn{P(V) = V} } \examples{ -u = UniversalSet$new() +u <- UniversalSet$new() print(u) u$contains(c(1, letters, TRUE, Set$new()), all = TRUE) - ## ------------------------------------------------ ## Method `UniversalSet$equals` ## ------------------------------------------------ diff --git a/man/as.FuzzySet.Rd b/man/as.FuzzySet.Rd index e3e316e0..b03aa9c6 100644 --- a/man/as.FuzzySet.Rd +++ b/man/as.FuzzySet.Rd @@ -67,12 +67,14 @@ Coerces object to an R6 \link{FuzzySet}/\link{FuzzyTuple} \itemize{ \item \code{as.FuzzySet.list} - Assumes \code{list} has two items, named \code{elements} and \code{membership}, and that they are ordered to be corresponding. -\item \code{as.FuzzySet.matrix} - Assumes first column corresponds to \code{elements} and second column corresponds -to their respective \code{membership}. -\item \code{as.FuzzySet.data.frame} - First checks to see if one column is called \code{elements} and the other is called \code{membership}. -If not then uses \code{as.FuzzySet.matrix}. -\item \code{as.FuzzySet.Set} - Creates a \link{FuzzySet} by assuming \link{Set} elements all have \code{membership} equal to \eqn{1}. -\item \code{as.FuzzySet.Interval} - First tries coercion via \link{as.Set.Interval} then uses \link{as.FuzzySet.Set}. +\item \code{as.FuzzySet.matrix} - Assumes first column corresponds to \code{elements} and second column +corresponds to their respective \code{membership}. +\item \code{as.FuzzySet.data.frame} - First checks to see if one column is called \code{elements} and the +other is called \code{membership}. If not then uses \code{as.FuzzySet.matrix}. +\item \code{as.FuzzySet.Set} - Creates a \link{FuzzySet} by assuming \link{Set} elements all have \code{membership} +equal to \eqn{1}. +\item \code{as.FuzzySet.Interval} - First tries coercion via \link{as.Set.Interval} then uses +\link{as.FuzzySet.Set}. } } \seealso{ diff --git a/man/as.Interval.Rd b/man/as.Interval.Rd index 370ff5f9..a0465591 100644 --- a/man/as.Interval.Rd +++ b/man/as.Interval.Rd @@ -35,12 +35,15 @@ Coerces object to an R6 \link{Interval}. } \details{ \itemize{ -\item \code{as.Interval.list/as.Interval.data.frame} - Assumes the \code{list}/\code{data.frame} has named items/columns: -\verb{lower, upper, type, class}. -\item \code{as.Interval.numeric} - If the \code{numeric} vector is a continuous interval with no breaks then coerces to an \link{Interval} -with: \verb{lower = min(object), upper = max(object), class = "integer"}. Ordering is ignored. -\item \code{as.Interval.matrix} - Tries coercion via \link{as.Interval.numeric} on the first column of the matrix. -\item \code{as.Interval.Set} - First tries coercion via \link{as.Interval.numeric}, if possible wraps result in a \link{Set}. +\item \code{as.Interval.list/as.Interval.data.frame} - Assumes the \code{list}/\code{data.frame} has +named items/columns: \verb{lower, upper, type, class}. +\item \code{as.Interval.numeric} - If the \code{numeric} vector is a continuous interval with no breaks then +coerces to an \link{Interval} with: \verb{lower = min(object), upper = max(object), class = "integer"}. +Ordering is ignored. +\item \code{as.Interval.matrix} - Tries coercion via \link{as.Interval.numeric} on the first column of the +matrix. +\item \code{as.Interval.Set} - First tries coercion via \link{as.Interval.numeric}, if possible wraps result +in a \link{Set}. \item \code{as.Interval.FuzzySet} - Tries coercion via \link{as.Interval.Set} on the support of the \link{FuzzySet}. } } diff --git a/man/as.Set.Rd b/man/as.Set.Rd index 3967be3c..88c1c8c7 100644 --- a/man/as.Set.Rd +++ b/man/as.Set.Rd @@ -75,7 +75,8 @@ Coerces object to an R6 \link{Set}/\link{Tuple} \item \code{as.Set.list} - Creates a \link{Set} for each element in \code{list}. \item \code{as.Set.matrix/as.Set.data.frame} - Creates a \link{Set} for each column in \code{matrix/data.frame}. \item \code{as.Set.FuzzySet} - Creates a \link{Set} from the support of the \link{FuzzySet}. -\item \code{as.Set.Interval} - If the interval has finite cardinality then creates a \link{Set} from the \link{Interval} elements. +\item \code{as.Set.Interval} - If the interval has finite cardinality then creates a \link{Set} from the +\link{Interval} elements. } } \seealso{ diff --git a/man/listSpecialSets.Rd b/man/listSpecialSets.Rd index 588c1df3..97188a18 100644 --- a/man/listSpecialSets.Rd +++ b/man/listSpecialSets.Rd @@ -7,10 +7,12 @@ listSpecialSets(simplify = FALSE) } \arguments{ -\item{simplify}{logical. If \code{FALSE} (default) returns data.frame of set name and symbol, otherwise set names as characters.} +\item{simplify}{logical. If \code{FALSE} (default) returns data.frame of set name and symbol, +otherwise set names as characters.} } \value{ -Either a list of characters (if \code{simplify} is \code{TRUE}) or a \code{data.frame} of \code{SpecialSet}s and their traits. +Either a list of characters (if \code{simplify} is \code{TRUE}) or a \code{data.frame} of \code{SpecialSet}s +and their traits. } \description{ Lists special sets that can be used in Set. diff --git a/man/powerSet.Rd b/man/powerSet.Rd index c54d172c..66dea2b2 100644 --- a/man/powerSet.Rd +++ b/man/powerSet.Rd @@ -19,13 +19,13 @@ creates an object of class \link{PowersetSet}.} Calculates and returns the powerset of a Set. } \details{ -A powerset of a set, S, is defined as the set of all subsets of S, including S itself and -the empty set. +A powerset of a set, S, is defined as the set of all subsets of S, including S itself +and the empty set. } \examples{ # simplify = FALSE is default -powerset(Set$new(1,2)) -powerset(Set$new(1,2), simplify = TRUE) +powerset(Set$new(1, 2)) +powerset(Set$new(1, 2), simplify = TRUE) # powerset of intervals powerset(Interval$new()) diff --git a/man/setcomplement.Rd b/man/setcomplement.Rd index 38b94542..fdc1cd36 100644 --- a/man/setcomplement.Rd +++ b/man/setcomplement.Rd @@ -39,8 +39,8 @@ setcomplement(x, y, simplify = TRUE) \arguments{ \item{x, y}{Set} -\item{simplify}{logical, if \code{TRUE} (default) returns the result in its simplest form, usually a \code{Set} or -\link{UnionSet}, otherwise a \code{ComplementSet}.} +\item{simplify}{logical, if \code{TRUE} (default) returns the result in its simplest form, usually a +\code{Set} or \link{UnionSet}, otherwise a \code{ComplementSet}.} } \value{ An object inheriting from \code{Set} containing the set difference of elements in \code{x} and \code{y}. @@ -61,13 +61,13 @@ The complement of fuzzy and crisp sets first coerces fuzzy sets to crisp sets by } \examples{ # absolute complement -setcomplement(Set$new(1,2,3, universe = Reals$new())) -setcomplement(Set$new(1,2, universe = Set$new(1,2,3,4,5))) +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)) +setcomplement(Set$new(1, 4, "a"), Set$new("a", 6)) # complement of two intervals @@ -78,7 +78,7 @@ 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) +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) @@ -88,13 +88,12 @@ 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) + 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() - } \seealso{ Other operators: diff --git a/man/setintersect.Rd b/man/setintersect.Rd index 34b53970..fd36ab99 100644 --- a/man/setintersect.Rd +++ b/man/setintersect.Rd @@ -48,7 +48,7 @@ The intersection of fuzzy and crisp sets first coerces fuzzy sets to crisp sets # intersection of two sets Set$new(-2:4) & Set$new(2:5) -setintersect(Set$new(1,4,"a"), Set$new("a", 6)) +setintersect(Set$new(1, 4, "a"), Set$new("a", 6)) Set$new(1:4) & Set$new(5:7) # intersection of two intervals @@ -56,12 +56,12 @@ Set$new(1:4) & Set$new(5:7) 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") + 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) +Set$new(5, 7) & Tuple$new(6, 8, 7) # Ignores membership of FuzzySet @@ -70,15 +70,14 @@ 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, y) x == y) ConditionalSet$new(function(x) x == 2) & - ConditionalSet$new(function(y) y == 3) + 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) - + ConditionalSet$new(function(x) x == 3) } \seealso{ Other operators: diff --git a/man/setpower.Rd b/man/setpower.Rd index 30962de7..3359d923 100644 --- a/man/setpower.Rd +++ b/man/setpower.Rd @@ -12,10 +12,11 @@ setpower(x, power, simplify = FALSE, nest = FALSE) \arguments{ \item{x}{Set} -\item{power}{power to raise set to} +\item{power}{power to raise set to, if \code{"n"} then a variable dimension set is created, +see examples.`} -\item{simplify}{logical, if \code{TRUE} returns the result in its simplest (unwrapped) form, usually a \code{Set}, -otherwise an \code{ExponentSet}.} +\item{simplify}{logical, if \code{TRUE} returns the result in its simplest (unwrapped) form, usually +a \code{Set}, otherwise an \code{ExponentSet}.} \item{nest}{logical, if \code{FALSE} (default) returns the n-ary cartesian product, otherwise returns the cartesian product applied n times. @@ -25,17 +26,19 @@ the cartesian product applied n times. An R6 object of class \code{Set} or \code{ExponentSet} inheriting from \code{ProductSet}. } \description{ -A convenience wrapper for the n-ary cartesian product of a \code{Set} by itself, possibly multiple times. +A convenience wrapper for the n-ary cartesian product of a \code{Set} by itself, +possibly multiple times. } \details{ -See the details of \link{setproduct} for a longer discussion on the use of the \code{nest} argument, in particular -with regards to n-ary cartesian products vs. 'standard' cartesian products. +See the details of \link{setproduct} for a longer discussion on the use of the \code{nest} +argument, in particular with regards to n-ary cartesian products vs. 'standard' cartesian +products. } \examples{ # 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 +Set$new(1, 2)^3 # Power of an interval Interval$new(2, 5)^5 @@ -48,7 +51,14 @@ Reals$new()^3 ConditionalSet$new(function(x) TRUE)^2 # Power of FuzzySet -FuzzySet$new(1,0.1,2,0.5)^2 +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))) } \seealso{ diff --git a/man/setproduct.Rd b/man/setproduct.Rd index 157196ce..9f1dddea 100644 --- a/man/setproduct.Rd +++ b/man/setproduct.Rd @@ -45,38 +45,37 @@ The product of fuzzy and crisp sets first coerces fuzzy sets to crisp sets by fi 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) +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)) +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) +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") + 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) +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) + ConditionalSet$new(function(x, y) x == y) # product of special sets PosReals$new() * NegReals$new() - } \seealso{ Other operators: diff --git a/man/setsymdiff.Rd b/man/setsymdiff.Rd index d203bcaf..f6873796 100644 --- a/man/setsymdiff.Rd +++ b/man/setsymdiff.Rd @@ -34,13 +34,12 @@ The symmetric difference of fuzzy and crisp sets first coerces fuzzy sets to cri } \examples{ # 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)) +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) - } \seealso{ Other operators: diff --git a/man/setunion.Rd b/man/setunion.Rd index ea4a306d..cf29abee 100644 --- a/man/setunion.Rd +++ b/man/setunion.Rd @@ -40,21 +40,21 @@ The union of fuzzy and crisp sets first coerces fuzzy sets to crisp sets by find # 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) +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") + 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) +Set$new(5, 7) | Tuple$new(6, 8, 7) # union of FuzzySet FuzzySet$new(1, 0.1, 2, 0.5) + Set$new(2:5) @@ -62,13 +62,12 @@ 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) + 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() - } \seealso{ Other operators: diff --git a/man/useUnicode.Rd b/man/useUnicode.Rd index 92872bad..b1c87a0b 100644 --- a/man/useUnicode.Rd +++ b/man/useUnicode.Rd @@ -20,7 +20,7 @@ unicode representations should be used, or standard alpha-numeric and special ch By default \code{set6} starts with unicode printing turned on. } \examples{ -current = useUnicode() +current <- useUnicode() useUnicode(TRUE) useUnicode() useUnicode(current) diff --git a/tests/testthat/test_operations_setpower.R b/tests/testthat/test_operations_setpower.R index fc64d7b9..8c5d541b 100644 --- a/tests/testthat/test_operations_setpower.R +++ b/tests/testthat/test_operations_setpower.R @@ -37,4 +37,11 @@ test_that("variable", { expect_true(x$contains(Tuple$new(0, 1, 0, 0, 1, 1, 0))) expect_false(x$contains(Tuple$new(0, 2))) expect_error(x$contains(1)) + + expect_equal(x$contains(list(Tuple$new(1), Tuple$new(2))), c(TRUE, FALSE)) + expect_equal(x$contains(list(Tuple$new(1, 0), Tuple$new(1, 1))), c(TRUE, TRUE)) + + expect_equal(x * Reals$new(), x) + expect_equal((Reals$new()^"n") * (Reals$new()^2), Reals$new()^"n") + expect_equal(x^2, x) })