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
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,58 @@

A python package for unidimensional boolean operations

#### Simple example

```python
>>> from rbool import *
>>> interval = Interval(-10, 5) # Create a closed interval
>>> interval
[-10, 5]
>>> interval | (3, 8) # Unite with open interval
[-10, 8)
>>> ~interval # Complementar of the interval
(-inf, 10) U (5, inf)
>>> interval |= {-2, 6, 10} # Unite with single values
>>> interval
[-10, 5] U {6, 10}
>>> interval - {2, 3} # Remove single values from interval
[-10, 2) U (2, 3) U (3, 5] U {6, 10}
>>> [-8, 3] in interval # Checks if [-8, 3] is inside the interval
True
```

The usual operations happens between two subsets:
* `A | B`: union
* `A & B`: intersection
* `~A`: complementar
* `A ^ B`: XOR
* `A - B`: subtract
* `A in B`: is subset ?

#### Useful functions

```python
>>> minimum("[-3, 10]") # Gets the minimum value from subset
-3
>>> minimum("(-3, 10]") # Returns None, there's no minimum
>>> infimum("(-3, 10]") # Gets the infimum value from subset
-3
>>> maximum("(-3, 10]") # Gets the maximum value
10
>>> supremum("(-3, 10]")
10
>>> lower(5) # All values on real line less than 5
(-inf, 5]
>>> {-15, 0} in lower(5) # -15 and 0 are inside (-inf, 5] ?
True
>>> [-3, 6] in bigger(5) # interval [-3, 6] is inside [5, inf) ?
False
>>> scale("[-3, 10) U {15}", 2) # Maps each value 'x' to '2*x'
[-6, 20) U {30}
>>> move("[-3, 10) U {15}", -8) # Maps each value 'x' to 'x - 8'
[-8, 2) U {7}
```


### Installation:

Expand Down
72 changes: 72 additions & 0 deletions docs/source/rst/get_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,75 @@ This library allows you to make boolean operations between subsets on the real l
* `SingleValue`: An subset with only one element
* `Interval`: An subset of continuous elements between
* `Disjoint`: The union of `SingleValue` and `Interval`


Create an interval
------------------

The standard is a closed interval

```python
>>> from rbool import *
>>> interval = Interval(-10, 5)
>>> interval
[-10, 5]
```

You can convert from a list (closed interval) or a tuple:

```python
>>> from rbool import from_any
>>> interval1 = from_any([-5, 2]) # closed interval
>>> interval1
[-5, 2]
>>> interval2 = from_any((-3, 8)) # open interval
(-3, 8)
```


Operate with intervals
----------------------

You can operate with the symbols:
* `|`: union
* `&`: intersection
* `^`: XOR
* `~`: complementar
* `-`: subtract

Examples:

```python
>>> from rbool import from_any
>>> interval1 = from_any([-5, 2]) # closed interval
>>> interval2 = from_any((-3, 8)) # open interval
>>> interval1 & interval2 # intersect
(-3, 2]
>>> interval1 | interval2 # unite
[-5, 8)
>>> interval1 ^ interval2 # XOR
[-5, -3] U (2, 8)
>>> interval1 - interval2 # subtract
[-5, -3]
>>> ~interval1 # complementar
(-inf, -5) U (2, inf)
>>> interval1 | (~interval1) # unite with its complementar
(-inf, inf)
```

Use single values
-----------------

You can also create single scalar values:
```python
>>> from rbool import SingleValue
>>> single = SingleValue(5) # Only one value
>>> single
{5}
>>> single |= {-3, 9, 12} # Unite with other 3 values
>>> single
{-3, 5, 9, 12}
>>> single | [6, 10] # Unite with an interval
{-3, 5} U [6, 10] U {12}
```

4 changes: 3 additions & 1 deletion src/rbool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Init file that includes the most used classes and functions of the module
"""

import importlib

from .base import Empty, Future, SubSetR1, Whole
from .bool1d import contains, extract_knots, intersect, invert, unite
from .converter import from_any
Expand All @@ -17,4 +19,4 @@
Future.scale = scale
Future.move = move

__version__ = "0.0.2"
__version__ = importlib.metadata.version("rbool")
Loading