@@ -1178,28 +1178,45 @@ Intervals are used in conjunction with set operations:
1178
1178
< !-- [3 , 5 ) - [4 , 6 ] = [3 , 4 ) -- >
1179
1179
< !-- [4 , 6 ] - [3 , 5 ) = [5 , 6 ] -- >
1180
1180
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]
1182
1195
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.
1186
1201
1187
- var a = Interval( 3 , nextafter( 5 , - Infinity))
1188
- var b = Interval( 4 , 6 )
1202
+ ```python
1203
+ R = np.linspace( - 1 , 9 , 100 )
1189
1204
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 ]
1192
1207
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 ]
1195
1210
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 )]
1198
1213
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 )]
1201
1215
```
1202
1216
1217
+ You should definitely run these in repl and try to wrap your head around them.
1218
+
1219
+
1203
1220
1204
1221
# # more...
1205
1222
0 commit comments