From 60df74256ed2006c34ac7960d54f979999d5a284 Mon Sep 17 00:00:00 2001 From: Carlos Adir Date: Mon, 4 Aug 2025 20:02:21 +0200 Subject: [PATCH 1/3] docs: add examples of use --- README.md | 38 +++++++++++++++++ docs/source/rst/get_started.rst | 72 +++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) diff --git a/README.md b/README.md index 9053312..76a282b 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,44 @@ A python package for unidimensional boolean operations +Simple example + +```python3 +>>> 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} +``` + +Other features: + +```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 lower(5) # interval [-3, 6] is inside (-inf, 5] ? +False +``` + ### Installation: diff --git a/docs/source/rst/get_started.rst b/docs/source/rst/get_started.rst index 164a549..8aae52d 100644 --- a/docs/source/rst/get_started.rst +++ b/docs/source/rst/get_started.rst @@ -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} +``` + From d9e84ee875eea3841b98dea3493988c03b50eeba Mon Sep 17 00:00:00 2001 From: Carlos Adir Date: Mon, 4 Aug 2025 20:02:42 +0200 Subject: [PATCH 2/3] dev: use package __version__ inside __init__.py --- src/rbool/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rbool/__init__.py b/src/rbool/__init__.py index ead9cea..0feeace 100644 --- a/src/rbool/__init__.py +++ b/src/rbool/__init__.py @@ -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 @@ -17,4 +19,4 @@ Future.scale = scale Future.move = move -__version__ = "0.0.2" +__version__ = importlib.metadata.version("rbool") From 0f9168518635a6c767ae0e736c5ff0639c9a434e Mon Sep 17 00:00:00 2001 From: Carlos Adir Date: Mon, 4 Aug 2025 20:14:19 +0200 Subject: [PATCH 3/3] docs: add more examples --- README.md | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 76a282b..d678a74 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,9 @@ A python package for unidimensional boolean operations -Simple example +#### Simple example -```python3 +```python >>> from rbool import * >>> interval = Interval(-10, 5) # Create a closed interval >>> interval @@ -27,9 +27,19 @@ Simple example [-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 ``` -Other features: +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 @@ -45,8 +55,12 @@ Other features: (-inf, 5] >>> {-15, 0} in lower(5) # -15 and 0 are inside (-inf, 5] ? True ->>> [-3, 6] in lower(5) # interval [-3, 6] is inside (-inf, 5] ? +>>> [-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} ```