Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 48f2dea

Browse files
author
Raphael Sonabend
committed
Closes #56
1 parent 64cee9c commit 48f2dea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1001
-173
lines changed

CRAN-RELEASE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This package was submitted to CRAN on 2020-07-26.
2+
Once it is accepted, delete this file and tag the release (commit 5a74439f94).

DESCRIPTION

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: set6
22
Title: R6 Mathematical Sets Interface
3-
Version: 0.1.8
3+
Version: 0.1.8.9000
44
Authors@R:
55
c(person(given = "Raphael",
66
family = "Sonabend",
@@ -22,7 +22,7 @@ BugReports: https://github.com/xoopR/set6/issues
2222
VignetteBuilder:
2323
knitr
2424
Encoding: UTF-8
25-
RoxygenNote: 7.1.0
25+
RoxygenNote: 7.1.1
2626
Roxygen: list(markdown = TRUE, r6 = TRUE)
2727
Collate:
2828
'Properties.R'
@@ -34,14 +34,17 @@ Collate:
3434
'SetWrapper_PowersetSet.R'
3535
'SetWrapper_ProductSet.R'
3636
'SetWrapper_UnionSet.R'
37+
'Set_Complex.R'
3738
'Set_ConditionalSet.R'
3839
'Set_FuzzySet.R'
3940
'Set_FuzzySet_FuzzyTuple.R'
4041
'Set_Interval.R'
4142
'setSymbol.R'
4243
'Set_Interval_SpecialSet.R'
4344
'Set_LogicalSet.R'
45+
'Set_Logicals.R'
4446
'Set_Tuple.R'
47+
'Set_Universal.R'
4548
'Set_UniversalSet.R'
4649
'asFuzzySet.R'
4750
'asInterval.R'

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export(FuzzyTuple)
8282
export(Integers)
8383
export(Interval)
8484
export(LogicalSet)
85+
export(Logicals)
8586
export(Naturals)
8687
export(NegIntegers)
8788
export(NegRationals)
@@ -97,6 +98,7 @@ export(Reals)
9798
export(Set)
9899
export(Tuple)
99100
export(UnionSet)
101+
export(Universal)
100102
export(UniversalSet)
101103
export(as.FuzzySet)
102104
export(as.FuzzyTuple)

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# set6 0.1.8.9000
2+
3+
* UniversalSet renamed Universal, old class will be removed in v0.4.0.
4+
* LogicalSet renamed Logicals, old class will be removed in v0.4.0.
5+
* `Complex` now inherits from `Set`, incorrect methods for `isSubset, equals` have been removed.
6+
17
# set6 0.1.8
28

39
* Patch for R-devel

R/Set.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ Set <- R6Class("Set",
3333
#' @description Create a new `Set` object.
3434
#' @details Sets are constructed by elements of any types (including R6 classes), excluding lists.
3535
#' `Set`s should be used within `Set`s instead of lists. The `universe` argument is useful for taking the absolute complement
36-
#' of the `Set`. If a universe isn't given then [UniversalSet] is assumed. If the `class` argument is non-NULL, then all elements
36+
#' of the `Set`. If a universe isn't given then [Universal] is assumed. If the `class` argument is non-NULL, then all elements
3737
#' will be coerced to the given class in construction, and if elements of a different class are added these will either be rejected
3838
#' or coerced.
3939
#' @param ... any. Elements in the set.
40-
#' @param universe Set. Universe that the Set lives in, i.e. elements that could be added to the Set. Default is the [UniversalSet].
40+
#' @param universe Set. Universe that the Set lives in, i.e. elements that could be added to the Set. Default is the [Universal].
4141
#' @param elements list. Alternative constructor that may be more efficient if passing objects of multiple classes.
4242
#' @param class character. Optional string naming a class that if supplied gives the set the `typed` property.
4343
#' @return A new `Set` object.
44-
initialize = function(..., universe = UniversalSet$new(), elements = NULL, class = NULL) {
44+
initialize = function(..., universe = Universal$new(), elements = NULL, class = NULL) {
4545

4646
private$.universe <- assertSet(universe)
4747

@@ -75,7 +75,7 @@ Set <- R6Class("Set",
7575
}
7676
}
7777

78-
if (getR6Class(universe) != "UniversalSet") {
78+
if (getR6Class(universe) != "Universal") {
7979
assertContains(universe, elements, errormsg = "elements are not contained in the given universe")
8080
}
8181

@@ -289,7 +289,7 @@ Set <- R6Class("Set",
289289
}
290290
}
291291

292-
if (getR6Class(y) %in% c("ConditionalSet", "UniversalSet")) {
292+
if (getR6Class(y) %in% c("ConditionalSet", "Universal")) {
293293
return(FALSE)
294294
} else if (testInterval(y)) {
295295
if (testFinite(y)) {

R/Set_Complex.R

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#' @name Complex
2+
#' @title Set of Complex Numbers
3+
#' @description The mathematical set of complex numbers,
4+
#' defined as the the set of reals with possibly imaginary components. i.e.
5+
#' \deqn{\\{a + bi \\ : \\ a,b \in R\\}}{{a + bi : a,b \epsilon R}}
6+
#' where \eqn{R} is the set of reals.
7+
#'
8+
#' @details There is no inherent ordering in the set of complex numbers, hence only the `contains`
9+
#' method is implemented here.
10+
#'
11+
#' @family special sets
12+
#' @export
13+
Complex <- R6Class("Complex",
14+
inherit = Set,
15+
public = list(
16+
#' @description Create a new `Complex` object.
17+
#' @return A new `Complex` object.
18+
initialize = function() {
19+
private$.properties <- Properties$new(closure = "open", cardinality = Inf)
20+
invisible(self)
21+
},
22+
23+
#' @description Tests to see if \code{x} is contained in the Set.
24+
#'
25+
#' @param x any. Object or vector of objects to test.
26+
#' @param all logical. If `FALSE` tests each `x` separately. Otherwise returns `TRUE` only if all `x` pass test.
27+
#' @param bound logical.
28+
#'
29+
#' @details \code{x} can be of any type, including a Set itself. \code{x} should be a tuple if
30+
#' checking to see if it lies within a set of dimension greater than one. To test for multiple \code{x}
31+
#' at the same time, then provide these as a list.
32+
#'
33+
#' If `all = TRUE` then returns `TRUE` if all `x` are contained in the `Set`, otherwise
34+
#' returns a vector of logicals. For [Interval]s, `bound` is used to specify if elements lying on the
35+
#' (possibly open) boundary of the interval are considered contained (`bound = TRUE`) or not (`bound = FALSE`).
36+
#'
37+
#' @return If \code{all} is `TRUE` then returns `TRUE` if all elements of \code{x} are contained in the `Set`, otherwise
38+
#' `FALSE.` If \code{all} is `FALSE` then returns a vector of logicals corresponding to each individual
39+
#' element of \code{x}.
40+
#'
41+
#' The infix operator `%inset%` is available to test if `x` is an element in the `Set`,
42+
#' see examples.
43+
contains = function(x, all = FALSE, bound = NULL) {
44+
returner(
45+
x = sapply(x, is.complex),
46+
all = all
47+
)
48+
},
49+
50+
#' @description Tests if two sets are equal.
51+
#' @param x [Set] or vector of [Set]s.
52+
#' @param all logical. If `FALSE` tests each `x` separately. Otherwise returns `TRUE` only if all `x` pass test.
53+
#' @return If `all` is `TRUE` then returns `TRUE` if all `x` are equal to the Set, otherwise
54+
#' `FALSE`. If `all` is `FALSE` then returns a vector of logicals corresponding to each individual
55+
#' element of `x`.
56+
#'
57+
#' Infix operators can be used for:
58+
#' \tabular{ll}{
59+
#' Equal \tab `==` \cr
60+
#' Not equal \tab `!=` \cr
61+
#' }
62+
#'
63+
#' @examples
64+
#' # Equals
65+
#' Set$new(1,2)$equals(Set$new(5,6))
66+
#' Set$new(1,2)$equals(Interval$new(1,2))
67+
#' Set$new(1,2) == Interval$new(1,2, class = "integer")
68+
#'
69+
#' # Not equal
70+
#' !Set$new(1,2)$equals(Set$new(1,2))
71+
#' Set$new(1,2) != Set$new(1,5)
72+
equals = function(x, all = FALSE) {
73+
ret <- sapply(listify(x), getR6Class) %in% "Complex"
74+
returner(ret, all)
75+
},
76+
77+
#' @description Test if one set is a (proper) subset of another
78+
#' @param x any. Object or vector of objects to test.
79+
#' @param proper logical. If `TRUE` tests for proper subsets.
80+
#' @param all logical. If `FALSE` tests each `x` separately. Otherwise returns `TRUE` only if all `x` pass test.
81+
#' @details If using the method directly, and not via one of the operators then the additional boolean
82+
#' argument `proper` can be used to specify testing of subsets or proper subsets. A Set is a proper
83+
#' subset of another if it is fully contained by the other Set (i.e. not equal to) whereas a Set is a
84+
#' (non-proper) subset if it is fully contained by, or equal to, the other Set.
85+
#'
86+
#' When calling `$isSubset` on objects inheriting from [Interval], the method treats the interval as if
87+
#' it is a [Set], i.e. ordering and class are ignored. Use `$isSubinterval` to test if one interval
88+
#' is a subinterval of another.
89+
#'
90+
#' Infix operators can be used for:
91+
#' \tabular{ll}{
92+
#' Subset \tab `<` \cr
93+
#' Proper Subset \tab `<=` \cr
94+
#' Superset \tab `>` \cr
95+
#' Proper Superset \tab `>=`
96+
#' }
97+
#'
98+
#' Every `Set` is a subset of a `Universal`. No `Set` is a super set of a `Universal`,
99+
#' and only a `Universal` is not a proper subset of a `Universal`.
100+
#'
101+
#' @return If `all` is `TRUE` then returns `TRUE` if all `x` are subsets of the Set, otherwise
102+
#' `FALSE`. If `all` is `FALSE` then returns a vector of logicals corresponding to each individual
103+
#' element of `x`.
104+
#' @examples
105+
#' Set$new(1,2,3)$isSubset(Set$new(1,2), proper = TRUE)
106+
#' Set$new(1,2) < Set$new(1,2,3) # proper subset
107+
#'
108+
#' c(Set$new(1,2,3), Set$new(1)) < Set$new(1,2,3) # not proper
109+
#' Set$new(1,2,3) <= Set$new(1,2,3) # proper
110+
isSubset = function(x, proper = FALSE, all = FALSE) {
111+
stop("Not implemented for complex sets.")
112+
},
113+
114+
#' @description Creates a printable representation of the object.
115+
#' @param n numeric. Number of elements to display on either side of ellipsis when printing.
116+
#' @return A character string representing the object.
117+
strprint = function(n = 2) {
118+
setSymbol(getR6Class(self))
119+
}
120+
)
121+
)

R/Set_ConditionalSet.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ConditionalSet <- R6Class("ConditionalSet",
2020
#' @param argclass list. Optional list of sets that the function arguments live in, see details.
2121
#' @details The `condition` should be given as a function that when evaluated returns
2222
#' either `TRUE` or `FALSE`. Further constraints can be given by providing the universe of the
23-
#' function arguments as [Set]s, if these are not given then the [UniversalSet] is assumed.
23+
#' function arguments as [Set]s, if these are not given then [Universal] is assumed.
2424
#' See examples.
2525
initialize = function(condition, argclass = NULL) {
2626
if (!is.function(condition)) {
@@ -39,7 +39,7 @@ ConditionalSet <- R6Class("ConditionalSet",
3939
if (!is.null(argclass)) {
4040
assertSetList(argclass)
4141
} else {
42-
argclass <- rep(list(UniversalSet$new()), private$.dimension)
42+
argclass <- rep(list(Universal$new()), private$.dimension)
4343
names(argclass) <- names(formals(condition))
4444
}
4545

R/Set_Interval_SpecialSet.R

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ SpecialSet <- R6Class("SpecialSet",
2020
stop(paste(getR6Class(self, pos = environment()), "is an abstract class that can't be initialized."))
2121
}
2222

23-
super$initialize(lower = lower, upper = upper, type = type, class = class, universe = UniversalSet$new())
23+
super$initialize(lower = lower, upper = upper, type = type, class = class, universe = Universal$new())
2424

2525
invisible(self)
2626
},
@@ -288,53 +288,3 @@ ExtendedReals <- R6Class("ExtendedReals",
288288
}
289289
)
290290
)
291-
292-
#' @name Complex
293-
#' @title Set of Complex Numbers
294-
#' @description The mathematical set of complex numbers,
295-
#' defined as the the set of reals with possibly imaginary components. i.e.
296-
#' \deqn{\\{a + bi \\ : \\ a,b \in R\\}}{{a + bi : a,b \epsilon R}}
297-
#' where \eqn{R} is the set of reals.
298-
#' @details Unlike the other `SpecialSet`s, `Complex` can be used to define an `Interval`. In this
299-
#' case where values can be complex, as opposed to reals or integers in [Interval].
300-
#' @family special sets
301-
#' @export
302-
Complex <- R6Class("Complex",
303-
inherit = SpecialSet,
304-
public = list(
305-
#' @description Create a new `Complex` object.
306-
#' @return A new `Complex` object.
307-
#' @param lower complex. Where to start the set.
308-
#' @param upper complex. Where to end the set.
309-
initialize = function(lower = -Inf + 0i, upper = Inf + 0i) {
310-
super$initialize(lower = as.complex(lower), upper = as.complex(upper), type = "()", class = "numeric")
311-
},
312-
313-
#' @description Tests to see if \code{x} is contained in the Set.
314-
#'
315-
#' @param x any. Object or vector of objects to test.
316-
#' @param all logical. If `FALSE` tests each `x` separately. Otherwise returns `TRUE` only if all `x` pass test.
317-
#' @param bound logical.
318-
#'
319-
#' @details \code{x} can be of any type, including a Set itself. \code{x} should be a tuple if
320-
#' checking to see if it lies within a set of dimension greater than one. To test for multiple \code{x}
321-
#' at the same time, then provide these as a list.
322-
#'
323-
#' If `all = TRUE` then returns `TRUE` if all `x` are contained in the `Set`, otherwise
324-
#' returns a vector of logicals. For [Interval]s, `bound` is used to specify if elements lying on the
325-
#' (possibly open) boundary of the interval are considered contained (`bound = TRUE`) or not (`bound = FALSE`).
326-
#'
327-
#' @return If \code{all} is `TRUE` then returns `TRUE` if all elements of \code{x} are contained in the `Set`, otherwise
328-
#' `FALSE.` If \code{all} is `FALSE` then returns a vector of logicals corresponding to each individual
329-
#' element of \code{x}.
330-
#'
331-
#' The infix operator `%inset%` is available to test if `x` is an element in the `Set`,
332-
#' see examples.
333-
contains = function(x, all = FALSE, bound = NULL) {
334-
returner(
335-
x = sapply(x, is.complex),
336-
all = all
337-
)
338-
}
339-
)
340-
)

R/Set_LogicalSet.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#' @name LogicalSet
22
#' @title Set of Logicals
33
#' @description The `LogicalSet` is defined as the [Set] containing the elements `TRUE` and `FALSE`.
4-
#' @family sets
54
#'
65
#' @examples
76
#' l <- LogicalSet$new()
@@ -15,6 +14,7 @@ LogicalSet <- R6::R6Class("LogicalSet",
1514
#' @details The Logical set is the set containing `TRUE` and `FALSE`.
1615
#' @return A new `LogicalSet` object.
1716
initialize = function() {
17+
warning("Deprecated. In the future please use Logicals$new(). This will be removed in v0.4.0.")
1818
private$.elements <- list(TRUE, FALSE)
1919
private$.str_elements <- c("TRUE", "FALSE")
2020
private$.class <- "logical"

R/Set_Logicals.R

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#' @name Logicals
2+
#' @title Set of Logicals
3+
#' @description The `Logicals` is defined as the [Set] containing the elements `TRUE` and `FALSE`.
4+
#' @family special sets
5+
#'
6+
#' @examples
7+
#' l <- Logicals$new()
8+
#' print(l)
9+
#' l$contains(list(TRUE, 1, FALSE))
10+
#' @export
11+
Logicals <- R6::R6Class("Logicals",
12+
inherit = Set,
13+
public = list(
14+
#' @description Create a new `Logicals` object.
15+
#' @details The Logical set is the set containing `TRUE` and `FALSE`.
16+
#' @return A new `Logicals` object.
17+
initialize = function() {
18+
private$.elements <- list(TRUE, FALSE)
19+
private$.str_elements <- c("TRUE", "FALSE")
20+
private$.class <- "logical"
21+
private$.properties <- Properties$new(closure = "closed", cardinality = 2)
22+
private$.lower <- TRUE
23+
private$.upper <- FALSE
24+
private$.universe <- self
25+
invisible(self)
26+
}
27+
)
28+
)

0 commit comments

Comments
 (0)