1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
|
# Comparison RPN Operators
`gt` provides six comparison operators, each with both a named and a symbolic
alias. All operators are metric-aware — they convert values to base units
before comparing. Results are boolean (`true` / `false`) and coerce
seamlessly into arithmetic (true → 1, false → 0).
## Operators
| Operator | Alias | RPN | Infix | Description |
|----------|-------|-------------|---------|-----------------|
| `gt` | `>` | `a b gt` | `a > b` | Greater than |
| `lt` | `<` | `a b lt` | `a < b` | Less than |
| `gte` | `>=` | `a b gte` | `a >= b`| Greater/equal |
| `lte` | `<=` | `a b lte` | `a <= b`| Less/equal |
| `eq` | `==` | `a b eq` | `a == b`| Equal |
| `neq` | `!=` | `a b neq` | `a != b`| Not equal |
All operators pop two values (`a` first, then `b`) from the stack, compare
them, and push the boolean result.
## Truth Table
### `gt` / `>`
| a | b | Result |
|-----|-----|--------|
| 5 | 3 | true |
| 3 | 5 | false |
| 5 | 5 | false |
```
$ gt '5 3 gt'
true
$ gt '5 3 >'
true
```
### `lt` / `<`
| a | b | Result |
|-----|-----|--------|
| 3 | 5 | true |
| 5 | 3 | false |
| 5 | 5 | false |
```
$ gt '3 5 lt'
true
$ gt '3 5 <'
true
```
### `gte` / `>=`
| a | b | Result |
|-----|-----|--------|
| 5 | 3 | true |
| 5 | 5 | true |
| 3 | 5 | false |
```
$ gt '5 5 gte'
true
$ gt '5 3 >='
true
```
### `lte` / `<=`
| a | b | Result |
|-----|-----|--------|
| 3 | 5 | true |
| 5 | 5 | true |
| 5 | 3 | false |
```
$ gt '5 5 lte'
true
$ gt '3 5 <='
true
```
### `eq` / `==`
| a | b | Result |
|-----|-----|--------|
| 5 | 5 | true |
| 5 | 3 | false |
```
$ gt '5 5 eq'
true
$ gt '5 5 =='
true
```
### `neq` / `!=`
| a | b | Result |
|-----|-----|--------|
| 5 | 3 | true |
| 5 | 5 | false |
```
$ gt '5 3 neq'
true
$ gt '5 3 !='
true
```
## Metric-Aware Comparison
Comparison operators convert operands to base units before comparing, so
different units within the same category can be compared directly.
### Same category, different units
```
$ gt '1km 1000m eq'
true
$ gt '1km 500m gt'
true
$ gt '500m 1km lt'
true
```
### Data storage (decimal SI prefixes)
```
$ gt '1GB 1000MB gte'
true
$ gt '1GB 1000MB gt'
false
$ gt '1GB 1024MB eq'
false
```
`1GB` equals exactly `1000MB` (decimal SI), so `gt` is false and `gte` is
true. `1024MB` is not equal to `1GB`.
### Network throughput
```
$ gt '100Mbps 50Mbps gt'
true
$ gt '1Gbps 1000Mbps eq'
true
```
### Incompatible categories
Comparing values from different metric categories produces an error:
```
$ gt '5m 3kg gt'
Error: incompatible metric categories
```
Examples of incompatible pairs:
- Distance vs. weight: `1km 5kg >`
- Time vs. bandwidth: `1hr 100Mbps <`
- Mass vs. distance: `10lb 5mi >=`
Unitless numbers are always compatible with any metric value.
## Boolean Coercion in Arithmetic
Boolean results are represented as floating-point numbers: `true` → 1,
`false` → 0. This allows comparison results to flow directly into arithmetic
without explicit conversion.
### Conditional addition
```
$ gt '5 3 gt 1 +'
2
```
`5 > 3` is true (1), so `1 + 1 = 2`.
```
$ gt '3 5 gt 1 +'
1
```
`3 > 5` is false (0), so `0 + 1 = 1`.
### Conditional multiplication
```
$ gt '5 3 gt 10 *'
10
```
`5 > 3` is true (1), so `1 * 10 = 10`.
```
$ gt '3 5 gt 10 *'
0
```
`3 > 5` is false (0), so `0 * 10 = 0`.
### Chained comparisons
```
$ gt '9 3 gt 4 5 lt +'
2
```
`9 > 3` (true/1) + `4 < 5` (true/1) = `1 + 1 = 2`.
### Boolean arithmetic with subtraction
```
$ gt '5 3 gt 0 -'
1
```
`5 > 3` (true/1) - 0 = 1.
```
$ gt '5 5 eq 1 -'
0
```
`5 == 5` (true/1) - 1 = 0.
## Practical Use Cases
### Threshold checks
Test whether a value exceeds a threshold:
```
$ gt '85 80 gt'
true
```
CPU at 85%, threshold at 80% — alert.
```
$ gt '50 10 gte'
true
```
Disk free at 50%, minimum at 10% — OK.
### Range validation
Check that a value falls within acceptable bounds:
```
$ gt '72 68 gte 100 lte +'
2
```
Temperature 72°F: `72 >= 68` (true/1) + `72 <= 100` (true/1) = 2 (both
checks pass).
```
$ gt '105 68 gte 100 lte +'
1
```
Temperature 105°F: `105 >= 68` (true/1) + `105 <= 100` (false/0) = 1
(outside range).
When the sum is 2, the value is within range. Any other result means at
least one check failed.
### Metric validation
Validate that a metric measurement meets requirements:
```
$ gt '100Mbps 50Mbps gt'
true
```
Download speed 100Mbps exceeds minimum 50Mbps — pass.
```
$ gt '2hr 1hr gte'
true
```
Battery life 2hr meets minimum 1hr requirement — pass.
### Counting conditions
Sum boolean results to count how many conditions are met:
```
$ gt '10 5 gt 20 15 gt 30 25 gt +'
3
```
All three conditions are true: `1 + 1 + 1 = 3`.
### Guard expressions
Multiply a value by a condition to guard it:
```
$ gt '99 80 gt *'
99
```
Value 99 is used because `99 > 80` is true (1): `99 * 1 = 99`.
```
$ gt '50 80 gt *'
0
```
Value 50 is discarded because `50 > 80` is false (0): `50 * 0 = 0`.
## Edge Cases
### Zero comparisons
```
$ gt '0 0 eq'
true
$ gt '0 0 neq'
false
$ gt '0 1 lt'
true
```
### Negative numbers
```
$ gt '-1 0 lt'
true
$ gt '-5 -3 lt'
true
```
### Insufficient operands
Any comparison on an empty or single-element stack returns an error:
```
$ gt 'gt'
Error: stack is empty
$ gt '5 gt'
Error: stack has insufficient operands
```
## Summary
Comparison operators provide boolean results that integrate naturally into
RPN arithmetic. The metric-aware design lets you compare values across units
automatically, while the symbolic aliases (`>`, `<`, `>=`, `<=`, `==`,
`!=`) offer familiar notation alongside the named operators (`gt`, `lt`,
`gte`, `lte`, `eq`, `neq`).
|