Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/source/rst/get_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Get started

This library allows you to make boolean operations between subsets on the real line:

* `EmptyR1`: An empty subset, without any elements
* `WholeR1`: The entire real line
* `SingleValueR1`: An subset with only one element
* `IntervalR1`: An subset of continuous elements between
* `DisjointR1`: The union of `SingleValueR1` and `IntervalR1`
* `Empty`: An empty subset, without any elements
* `Whole`: The entire real line
* `SingleValue`: An subset with only one element
* `Interval`: An subset of continuous elements between
* `Disjoint`: The union of `SingleValue` and `Interval`
10 changes: 5 additions & 5 deletions docs/source/rst/references.rst
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
.. autoclass:: rbool.base.EmptyR1
.. autoclass:: rbool.base.Empty
:members:
:inherited-members:
:undoc-members:
:show-inheritance:

----------------------------------------------------

.. autoclass:: rbool.base.WholeR1
.. autoclass:: rbool.base.Whole
:members:
:inherited-members:
:undoc-members:
:show-inheritance:

----------------------------------------------------

.. autoclass:: rbool.singles.SingleValueR1
.. autoclass:: rbool.singles.SingleValue
:members:
:inherited-members:
:undoc-members:
:show-inheritance:

----------------------------------------------------

.. autoclass:: rbool.singles.IntervalR1
.. autoclass:: rbool.singles.Interval
:members:
:inherited-members:
:undoc-members:
:show-inheritance:

----------------------------------------------------

.. autoclass:: rbool.singles.DisjointR1
.. autoclass:: rbool.singles.Disjoint
:members:
:inherited-members:
:undoc-members:
Expand Down
4 changes: 2 additions & 2 deletions src/rbool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
Init file that includes the most used classes and functions of the module
"""

from .base import EmptyR1, Future, SubSetR1, WholeR1
from .base import Empty, Future, SubSetR1, Whole
from .bool1d import contains, extract_knots, intersect, invert, unite
from .converter import from_any
from .limits import infimum, maximum, minimum, supremum
from .singles import DisjointR1, IntervalR1, SingleValueR1, bigger, lower
from .singles import Disjoint, Interval, SingleValue, bigger, lower
from .transform import move, scale

Future.convert = from_any
Expand Down
30 changes: 15 additions & 15 deletions src/rbool/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
or when concatenating piecewise curves

Here we define 5 classes:
* EmptyR1 : Represents an empty set {} of the real line R1
* WholeR1 : Represents the entire real line R1
* SingleValueR1 : Represents a subset of R1 with only one finite element
* IntervalR1 : Represents a subset of R1 with continuous points
* DisjointR1 : Represents the union of some SingleValueR1 and IntervalR1
* Empty : Represents an empty set {} of the real line R1
* Whole : Represents the entire real line R1
* SingleValue : Represents a subset of R1 with only one finite element
* Interval : Represents a subset of R1 with continuous points
* Disjoint : Represents the union of some SingleValue and Interval

With them, we can verify if one subset contains another subset
It's possible to make the standard boolean operations, like union,
Expand Down Expand Up @@ -201,11 +201,11 @@ def __ne__(self, other):
return not self == other


class EmptyR1(SubSetR1):
class Empty(SubSetR1):
"""
EmptyR1 class is a singleton that represents an empty set
Empty class is a singleton that represents an empty set

It's equivalent to: EmptyR1 = {}
It's equivalent to: Empty = {}
"""

instance = None
Expand All @@ -229,7 +229,7 @@ def scale(self, amount: Real) -> SubSetR1:
return self

def __invert__(self):
return WholeR1()
return Whole()

def __and__(self, other):
Future.convert(other)
Expand All @@ -249,7 +249,7 @@ def __str__(self):
return r"{}"

def __repr__(self):
return "EmptyR1"
return "Empty"

def __eq__(self, other):
return self is Future.convert(other)
Expand All @@ -258,11 +258,11 @@ def __hash__(self):
return 0


class WholeR1(SubSetR1):
class Whole(SubSetR1):
"""
WholeR1 class is a singleton that represents the entire real line
Whole class is a singleton that represents the entire real line

It's equivalent to: WholeR1 = (-inf, +inf)
It's equivalent to: Whole = (-inf, +inf)
"""

instance = None
Expand All @@ -287,7 +287,7 @@ def scale(self, amount: Real) -> SubSetR1:
return self

def __invert__(self):
return EmptyR1()
return Empty()

def __and__(self, other):
return Future.convert(other)
Expand All @@ -307,7 +307,7 @@ def __str__(self):
return "(" + str(NEGINF) + ", " + str(POSINF) + ")"

def __repr__(self):
return "WholeR1"
return "Whole"

def __eq__(self, other):
return self is Future.convert(other)
Expand Down
38 changes: 19 additions & 19 deletions src/rbool/bool1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@
from numbers import Real
from typing import Callable, Iterable, List, Set, Union

from .base import EmptyR1, Future, SubSetR1, WholeR1
from .base import Empty, Future, SubSetR1, Whole
from .numbs import Is
from .singles import DisjointR1, IntervalR1, SingleValueR1, bigger, lower
from .singles import Disjoint, Interval, SingleValue, bigger, lower


def extract_knots(obj: SubSetR1) -> Iterable[Real]:
"""
Extract all the knots from the SubSetR1.

If it's a SingleValueR1, gives the internal value
If it's a IntervalR1, gives the extremities
If it's a DisjointR1, use recursion
If it's a SingleValue, gives the internal value
If it's a Interval, gives the extremities
If it's a Disjoint, use recursion
"""
if isinstance(obj, SingleValueR1):
if isinstance(obj, SingleValue):
yield obj.internal
if isinstance(obj, IntervalR1):
if isinstance(obj, Interval):
if Is.finite(obj[0]):
yield obj[0]
if Is.finite(obj[1]):
yield obj[1]
if isinstance(obj, DisjointR1):
if isinstance(obj, Disjoint):
for sub in obj:
yield from extract_knots(sub)

Expand Down Expand Up @@ -61,13 +61,13 @@ def general_subset(knots: Iterable[Real], insides: Iterable[bool]) -> SubSetR1:
Transforms the knots real values and the vector of insides into a SubSetR1

Basically it gets all the knots from a group of subsets:
* internal value of SingleValueR1
* start and end of an IntervalR1
* knots of the internals for case DisjointR1
* internal value of SingleValue
* start and end of an Interval
* knots of the internals for case Disjoint
and then mark the middle points from the

Then, this function walks from left to right, deciding which SingleValueR1
or IntervalR1 should be gotten to make the return SubSetR1.
Then, this function walks from left to right, deciding which SingleValue
or Interval should be gotten to make the return SubSetR1.

This is an internal function and should not be used careless
"""
Expand All @@ -76,11 +76,11 @@ def general_subset(knots: Iterable[Real], insides: Iterable[bool]) -> SubSetR1:
if len(insides) != 2 * len(knots) + 1:
raise ValueError(f"Invalid: knots = {knots}, insides = {insides}")
if all(insides):
return WholeR1()
return Whole()
if not any(insides):
return EmptyR1()
return Empty()

items: List[Union[SingleValueR1, IntervalR1]] = []
items: List[Union[SingleValue, Interval]] = []
start: Union[None, Real] = None
close: bool = False
for i, knot in enumerate(knots):
Expand All @@ -90,13 +90,13 @@ def general_subset(knots: Iterable[Real], insides: Iterable[bool]) -> SubSetR1:
if left == midd == righ:
continue
if not left and not righ:
items.append(SingleValueR1(knot))
items.append(SingleValue(knot))
continue
if left: # Finish interval
if start is None:
newinterv = lower(knot, midd)
else:
newinterv = IntervalR1(start, knot, close, midd)
newinterv = Interval(start, knot, close, midd)
items.append(newinterv)
start = None
if righ:
Expand All @@ -109,7 +109,7 @@ def general_subset(knots: Iterable[Real], insides: Iterable[bool]) -> SubSetR1:
if len(items) == 1:
return items[0]

return DisjointR1(items)
return Disjoint(items)


def unite(*subsets: SubSetR1) -> SubSetR1:
Expand Down
Loading
Loading