Skip to content

Commit da2eea2

Browse files
Time to proofread
1 parent 2b9f280 commit da2eea2

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

PYTHON-README.md

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,28 +1178,45 @@ Intervals are used in conjunction with set operations:
11781178
<!-- [3, 5) - [4, 6] = [3, 4) -->
11791179
<!-- [4, 6] - [3, 5) = [5, 6] -->
11801180
1181-
In code:
1181+
Integer versions in basic python look like this
1182+
1183+
```python
1184+
# intersection of two int intervals
1185+
[x for x in range(3,5) if x in range(4, 6+1)]
1186+
# Out: [4]
1187+
1188+
# Union of two int intervals
1189+
[x for x in range(20) if x in range(3, 5) or x in range(4, 6+1)]
1190+
# Out: [3, 4, 5, 6]
1191+
1192+
# Set difference
1193+
[x for x in range(3, 5) if x not in range(4, 6+1)]
1194+
# Out: [3]
11821195
1183-
```js
1184-
var Interval = require('interval-arithmetic')
1185-
var nextafter = require('nextafter')
1196+
[x for x in range(4, 6+1) if x not in range(3, 5)]
1197+
# Out: [5, 6]
1198+
```
1199+
1200+
Using `np.linspace`, we can approximate what the real versions would look like.
11861201
1187-
var a = Interval(3, nextafter(5, -Infinity))
1188-
var b = Interval(4, 6)
1202+
```python
1203+
R = np.linspace(-1, 9, 100)
11891204
1190-
Interval.intersection(a, b)
1191-
// {lo: 4, hi: 4.999999999999999}
1205+
# intersection of two float intervals
1206+
[x for x in R if 3 <= x < 5 and 4 <= x <= 6]
11921207
1193-
Interval.union(a, b)
1194-
// {lo: 3, hi: 6}
1208+
# Union of two float intervals
1209+
[x for x in R if 3 <= x < 5 or 4 <= x <= 6]
11951210
1196-
Interval.difference(a, b)
1197-
// {lo: 3, hi: 3.9999999999999996}
1211+
# set differences of two float intervals.
1212+
[x for x in R if 3 <= x < 5 and not (4 <= x <= 6)]
11981213
1199-
Interval.difference(b, a)
1200-
// {lo: 5, hi: 6}
1214+
[x for x in R if 4 <= x <= 6 and not (3 <= x < 5)]
12011215
```
12021216
1217+
You should definitely run these in repl and try to wrap your head around them.
1218+
1219+
12031220
12041221
## more...
12051222

0 commit comments

Comments
 (0)