diff --git a/PYTHON-README.md b/PYTHON-README.md index f53f5be..9ec428c 100644 --- a/PYTHON-README.md +++ b/PYTHON-README.md @@ -1178,28 +1178,45 @@ Intervals are used in conjunction with set operations: -In code: +Integer versions in basic python look like this + +```python +# intersection of two int intervals +[x for x in range(3,5) if x in range(4, 6+1)] +# Out: [4] + +# Union of two int intervals +[x for x in range(20) if x in range(3, 5) or x in range(4, 6+1)] +# Out: [3, 4, 5, 6] + +# Set difference +[x for x in range(3, 5) if x not in range(4, 6+1)] +# Out: [3] -```js -var Interval = require('interval-arithmetic') -var nextafter = require('nextafter') +[x for x in range(4, 6+1) if x not in range(3, 5)] +# Out: [5, 6] +``` + +Using `np.linspace`, we can approximate what the real versions would look like. -var a = Interval(3, nextafter(5, -Infinity)) -var b = Interval(4, 6) +```python +R = np.linspace(-1, 9, 100) -Interval.intersection(a, b) -// {lo: 4, hi: 4.999999999999999} +# intersection of two float intervals +[x for x in R if 3 <= x < 5 and 4 <= x <= 6] -Interval.union(a, b) -// {lo: 3, hi: 6} +# Union of two float intervals +[x for x in R if 3 <= x < 5 or 4 <= x <= 6] -Interval.difference(a, b) -// {lo: 3, hi: 3.9999999999999996} +# set differences of two float intervals. +[x for x in R if 3 <= x < 5 and not (4 <= x <= 6)] -Interval.difference(b, a) -// {lo: 5, hi: 6} +[x for x in R if 4 <= x <= 6 and not (3 <= x < 5)] ``` +You should definitely run these in repl and try to wrap your head around them. + + ## more...