summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-24 23:10:22 +0300
committerPaul Buetow <paul@buetow.org>2026-05-24 23:10:22 +0300
commit50bff2ffa7a09f3ae35b10219b49d5cf38457066 (patch)
tree997173667c42b78d902ce8f715d52af72b238e6a
parentdc89fa2bbcdea7c8847828f64be5e46ddded33fb (diff)
docs: de-LLM all .md files - remove corporate language, over-explanation, and LLM patterns
-rw-r--r--README.md4
-rw-r--r--docs/basic-arithmetic.md92
-rw-r--r--docs/cli-usage.md76
-rw-r--r--docs/comparisons.md110
-rw-r--r--docs/constants.md8
-rw-r--r--docs/custom-metrics.md55
-rw-r--r--docs/fast-power.md2
-rw-r--r--docs/hyper-operators.md114
-rw-r--r--docs/log-operators.md67
-rw-r--r--docs/metric-commands.md16
-rw-r--r--docs/metrics.md2
-rw-r--r--docs/percentage-calculations.md54
-rw-r--r--docs/repl-mode.md2
-rw-r--r--docs/stack-operations.md60
-rw-r--r--docs/symbols.md9
-rw-r--r--docs/unit-conversion.md34
-rw-r--r--docs/variables.md9
-rw-r--r--logo.svg10
18 files changed, 122 insertions, 602 deletions
diff --git a/README.md b/README.md
index 2d30ea2..565f396 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ A command-line calculator with percentage calculations and RPN (Reverse Polish N
![gt Logo](logo.svg)
-This is a toy project created to experiment with local LLMs (Qwen, Gemma, Nemotron, GPT OSS) and how well they hold up as pair programmers.
+This is a toy project to experiment with local LLMs (Qwen, Gemma, Nemotron, GPT OSS) as pair programmers.
## Installation
@@ -30,7 +30,7 @@ gt # interactive REPL
## Feature Guide
-All features are documented in the [`docs/`](docs/) directory:
+All features are documented in [`docs/`](docs/):
| Topic | Doc |
|-------|-----|
diff --git a/docs/basic-arithmetic.md b/docs/basic-arithmetic.md
index 162d10f..4e22386 100644
--- a/docs/basic-arithmetic.md
+++ b/docs/basic-arithmetic.md
@@ -1,9 +1,6 @@
# Basic Arithmetic RPN Operators
-`gt` evaluates expressions using Reverse Polish Notation (RPN), a stack-based
-calculation method where operators follow their operands. No parentheses are
-needed, and the order of operations is determined entirely by the sequence of
-tokens.
+gt evaluates expressions using Reverse Polish Notation (RPN), a stack-based calculation method where operators follow their operands. No parentheses needed — the token sequence determines the order of operations.
## How RPN Works
@@ -12,8 +9,7 @@ Each token is processed left to right:
1. **Numbers** are pushed onto the stack.
2. **Operators** pop the required operands, compute the result, and push it back.
-For example, `3 4 +` pushes 3, then 4, then `+` pops both (3 and 4), adds
-them, and pushes the result (7).
+For example, `3 4 +` pushes 3, then 4, then `+` pops both, adds them, and pushes 7.
### Stack visualization
@@ -31,9 +27,7 @@ Result: 7
## Operators
-All binary arithmetic operators pop two values and push one result. The
-**first** value pushed is the left operand (`a`), and the **second** value
-pushed is the right operand (`b`). The operation is always `a <op> b`.
+All binary arithmetic operators pop two values and push one result. The **first** value pushed is the left operand (`a`), the **second** is the right operand (`b`). The operation is always `a <op> b`.
### `+` Addition
@@ -44,16 +38,13 @@ $ gt '3 4 +'
### `-` Subtraction
-Computes `a - b` (first value minus second value).
+Computes `a - b` (first value minus second). Order matters:
```
$ gt '3 4 -'
-1
```
-Note: order matters in RPN subtraction. `3 4 -` yields `-1` because it
-computes `3 - 4`.
-
### `*` Multiplication
```
@@ -63,7 +54,7 @@ $ gt '5 6 *'
### `/` Division
-Computes `a / b` (first value divided by second value).
+Computes `a / b` (first value divided by second).
```
$ gt '20 4 /'
@@ -72,26 +63,15 @@ $ gt '20 4 /'
### `^` Power
-Computes `a ^ b` (first value raised to the power of the second). Result is
-always unitless.
+Computes `a ^ b` (first value raised to the power of the second). Result is always unitless.
```
$ gt '2 3 ^'
8
-```
-
-Additional examples:
-
-```
$ gt '2 10 ^'
1024
$ gt '5 0 ^'
1
-```
-
-Supports negative exponents:
-
-```
$ gt '2 -3 ^'
0.125
```
@@ -103,11 +83,6 @@ Computes `a % b` (remainder of `a / b`).
```
$ gt '10 3 %'
1
-```
-
-Additional examples:
-
-```
$ gt '7 3 %'
1
$ gt '13 5 %'
@@ -118,7 +93,7 @@ $ gt '100 7 %'
## Multi-operand Expressions
-RPN naturally handles complex expressions without parentheses.
+RPN handles complex expressions without parentheses.
### Chained operations
@@ -127,16 +102,14 @@ $ gt '1 2 3 + +'
6
```
-Step by step: `1` pushed, `2` pushed, `3` pushed, `+` pops 2 and 3
-producing 5 (stack: `[1, 5]`), `+` pops 1 and 5 producing 6.
+Step by step: `1` pushed, `2` pushed, `3` pushed, `+` pops 2 and 3 producing 5 (stack: `[1, 5]`), `+` pops 1 and 5 producing 6.
```
$ gt '10 2 3 - *'
-10
```
-Step by step: `10` pushed, `2` pushed, `3` pushed, `-` pops 2 and 3
-producing -1 (stack: `[10, -1]`), `*` pops 10 and -1 producing -10.
+Step by step: `10` pushed, `2` pushed, `3` pushed, `-` pops 2 and 3 producing -1 (stack: `[10, -1]`), `*` pops 10 and -1 producing -10.
### Nested operations
@@ -156,15 +129,14 @@ This is `2^3 + 4^5` = `8 + 1024` = `1032`.
### Order of operations
-In RPN, the order of operations is explicit in the token sequence:
+In RPN, the order is explicit in the token sequence:
```
$ gt '10 3 2 * /'
1.666666667
```
-This computes `10 / (3 * 2)` = `10 / 6`. The inner operation `3 2 *` is
-evaluated first because the `*` comes before `/`.
+This computes `10 / (3 * 2)` = `10 / 6`. The inner operation `3 2 *` is evaluated first because `*` comes before `/`.
```
$ gt '100 10 / 5 +'
@@ -182,7 +154,7 @@ $ gt '1 2 + 3 4 + * 5 6 + +'
Breakdown: `(1+2) * (3+4) + (5+6)` = `3 * 7 + 11` = `21 + 11` = `32`.
-## Practical Use Cases
+## Examples
### Compound calculations
@@ -193,21 +165,6 @@ $ gt '10 5 + 3 * 20 4 / -'
35
```
-Stack trace:
-```
- Token Stack
- ----- -----
- 10 [10]
- 5 [10, 5]
- + [15]
- 3 [15, 3]
- * [45]
- 20 [45, 20]
- 4 [45, 20, 4]
- / [45, 5]
- - [40]
-```
-
### Geometry
Circle area (pi * r^2):
@@ -242,7 +199,7 @@ $ gt '10 20 30 + + 3 /'
### Division by zero
-Returns an error rather than infinity or NaN:
+Returns an error:
```
$ gt '5 0 /'
@@ -260,16 +217,9 @@ Error: modulo by zero
### Negative results
-Subtraction produces negative numbers naturally:
-
```
$ gt '3 7 -'
-4
-```
-
-Multiplication with negative numbers works as expected:
-
-```
$ gt '-5 3 *'
-15
```
@@ -286,22 +236,6 @@ $ gt '5 +'
Error: stack has insufficient operands
```
-### Power special cases
-
-Any number to the power of 0 yields 1:
-
-```
-$ gt '5 0 ^'
-1
-```
-
-Negative exponents produce fractional results:
-
-```
-$ gt '2 -3 ^'
-0.125
-```
-
## Summary Table
| Operator | RPN | Infix | Description | Example result |
diff --git a/docs/cli-usage.md b/docs/cli-usage.md
index b551083..0bbb938 100644
--- a/docs/cli-usage.md
+++ b/docs/cli-usage.md
@@ -1,6 +1,6 @@
# CLI Usage
-gt supports several invocation modes for different use cases: single-expression evaluation, interactive REPL, piping, and stdin redirection.
+gt supports several invocation modes: single-expression evaluation, interactive REPL, piping, and stdin redirection.
## Invocation Modes
@@ -14,7 +14,7 @@ gt '20% of 150' # → 30
gt '100Mbps @Gbps convert' # → 1
```
-This is the primary mode for scripts, one-off calculations, and CI pipelines. Each invocation starts with a fresh state — no variables, no history, no persistent settings.
+This is the primary mode for scripts, one-off calculations, and CI pipelines. Each invocation starts fresh — no variables, no history.
### REPL Mode
@@ -26,7 +26,7 @@ gt
This starts the interactive Read-Eval-Print Loop with command history, tab completion, and persistent variable storage. See [repl-mode.md](repl-mode.md) for full details.
-When stdin is not a terminal (e.g., piped input), gt falls back to single-command mode instead of starting the REPL.
+When stdin is not a terminal (e.g., piped input), gt falls back to single-command mode.
### Pipe Mode
@@ -38,18 +38,15 @@ echo '20% of 150' | gt # → 30
echo '100kmh @mph convert' | gt # → 62.13711922
```
-gt reads from stdin, trims whitespace, tries RPN parsing first, then falls back to percentage calculation. This makes it easy to integrate gt into shell pipelines.
+gt reads from stdin, trims whitespace, tries RPN parsing first, then falls back to percentage calculation.
### Stdin Redirection
-Redirect a file or use `/dev/stdin`:
-
```bash
gt < input.txt
-gt /dev/stdin < input.txt
```
-The `readStdin()` function in `cmd/gt/main.go` uses `os.ReadFile("/dev/stdin")` for full reads, with a 4096-byte buffer fallback if `/dev/stdin` is unavailable on the platform.
+gt uses `os.ReadFile("/dev/stdin")` for full reads, with a 4096-byte buffer fallback if `/dev/stdin` is unavailable.
### Empty Input
@@ -71,8 +68,6 @@ Error: no input provided
### Version
-Print the current version:
-
```bash
$ gt version
v0.4.2
@@ -89,14 +84,7 @@ $ gt -h
Error: rpn fallback failed for input "-h": perc: unable to parse input "-h": unknown error
```
-To see usage information, provide empty input or just run `gt` with no stdin:
-
-```bash
-$ echo '' | gt
-Usage: gt <calculation>
- gt version
-...
-```
+To see usage information, provide empty input or just run `gt` with no stdin.
### `--log` Flag
@@ -110,7 +98,7 @@ See [repl-mode.md](repl-mode.md) for details on session logging.
## Boolean Coercion
-gt treats `true` and `false` as first-class literals on the RPN stack. Comparison operators (`==`, `!=`, `>`, `<`, `>=`, `<=`) produce boolean values. Booleans coerce to numbers when used in arithmetic: `true` is `1`, `false` is `0`.
+gt treats `true` and `false` as first-class literals on the RPN stack. Comparison operators produce boolean values. Booleans coerce to numbers in arithmetic: `true` is `1`, `false` is `0`.
### Boolean Literals
@@ -125,27 +113,19 @@ gt 'false' # → false
gt '5 5 ==' # → true
gt '5 6 ==' # → false
gt '5 3 >' # → true
-gt '3 5 <' # → true
-gt '5 5 >' # → false
```
### Boolean-Arithmetic Coercion
-When a boolean is used with an arithmetic operator, it is coerced to `1` (true) or `0` (false):
-
```bash
gt 'true true +' # → 2 (1 + 1)
gt 'true false +' # → 1 (1 + 0)
gt 'false false +' # → 0 (0 + 0)
gt 'true 2 *' # → 2 (1 * 2)
-gt 'false 1 +' # → 1 (0 + 1)
-gt 'false 0 +' # → 0 (0 + 0)
```
### Mixed Boolean-Arithmetic Expressions
-Use comparison results directly in arithmetic without explicit conversion:
-
```bash
gt '5 3 == 1 +' # → 1 (false + 1 = 0 + 1)
gt '5 5 == 10 *' # → 10 (true * 10 = 1 * 10)
@@ -153,20 +133,12 @@ gt '5 5 == 10 *' # → 10 (true * 10 = 1 * 10)
### Comparing Booleans to Numbers
-Equality comparisons work between booleans and their numeric equivalents:
-
```bash
gt 'true 1 ==' # → true (1 == 1)
gt 'false 0 ==' # → true (0 == 0)
gt 'true 0 ==' # → false (1 != 0)
```
-### Implementation Details
-
-Boolean values are stored as a special `Float` variant (or `Rat` in rational mode) with an `isBool` flag. The `Float64()` method coerces `true` to `1` and `false` to `0` automatically. The `String()` method returns `"true"` or `"false"` instead of a numeric representation, preserving readability on the stack.
-
-See `internal/rpn/number.go` for the `Float` and `Rat` boolean implementations, and `internal/rpn/rpn_parse.go` for the `pushLiteral()` function that recognizes `true` and `false` tokens.
-
## Exit Codes
| Condition | Exit Code |
@@ -175,14 +147,12 @@ See `internal/rpn/number.go` for the `Float` and `Rat` boolean implementations,
| Error (parse failure, invalid expression, etc.) | 1 |
| Empty input (no TTY) | 1 |
-Error messages are printed to stdout with the prefix `Error:` followed by a newline and the result.
+Error messages are printed to stdout with the prefix `Error:`.
-## Practical Use Cases
+## Examples
### In Shell Scripts
-Embed calculations directly in scripts:
-
```bash
THRESHOLD=$(gt '100Mbps 50 /')
if [ "$THRESHOLD" -gt 1000 ]; then
@@ -192,8 +162,6 @@ fi
### In CI Pipelines
-Validate calculations in build steps:
-
```yaml
- name: Check bandwidth math
run: |
@@ -203,40 +171,16 @@ Validate calculations in build steps:
### In Pipes
-Combine with other tools:
-
```bash
cat sizes.txt | xargs -I{} gt '{} @GB convert'
-find . -type f -exec wc -c {} + | awk '{print $1}' | xargs -I{} gt '{} @MiB convert'
```
### Quick Conversions at the Prompt
```bash
-# Travel planning
gt '500mi @km convert' # → 804.672
-
-# Data transfer
-gt '10GB 2hr /' # → transfer rate
-
-# Weight
-gt '150lb @kg convert' # → 68.04
-
-# Percentage
gt '15% of 899' # → discount amount
-```
-
-### Conditional Logic
-
-Use boolean coercion for inline conditionals:
-
-```bash
-# Check if a value meets a threshold
gt '75 80 >' # → false (75 < 80)
-gt '85 80 >' # → true (85 > 80)
-
-# Combine with arithmetic
-gt '75 80 > 1 -' # → 1 (not greater, so 1 - false = 1 - 0 = 1)
```
## Summary of Modes
@@ -245,6 +189,6 @@ gt '75 80 > 1 -' # → 1 (not greater, so 1 - false = 1 - 0 = 1)
|------|---------|-------|----------|
| Single-expression | `gt '3 4 +'` | Fresh per invocation | Scripts, CI, one-off math |
| REPL | `gt` (with TTY) | Persistent (saved to disk) | Interactive exploration |
-| Pipe | `echo '3 4 +' \| gt` | Fresh per invocation | Pipelines, xargs |
+| Pipe | `echo '3 4 +' | gt` | Fresh per invocation | Pipelines, xargs |
| Stdin redirect | `gt < file.txt` | Fresh per invocation | Batch processing |
| Version | `gt version` | N/A | Checking installed version |
diff --git a/docs/comparisons.md b/docs/comparisons.md
index 3c990a7..0f82ec2 100644
--- a/docs/comparisons.md
+++ b/docs/comparisons.md
@@ -1,9 +1,6 @@
# 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).
+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 into arithmetic (true → 1, false → 0).
## Operators
@@ -16,8 +13,7 @@ seamlessly into arithmetic (true → 1, false → 0).
| `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.
+All operators pop two values (`a` first, then `b`) from the stack, compare them, and push the boolean result.
## Truth Table
@@ -44,13 +40,6 @@ true
| 5 | 3 | false |
| 5 | 5 | false |
-```
-$ gt '3 5 lt'
-true
-$ gt '3 5 <'
-true
-```
-
### `gte` / `>=`
| a | b | Result |
@@ -59,13 +48,6 @@ true
| 5 | 5 | true |
| 3 | 5 | false |
-```
-$ gt '5 5 gte'
-true
-$ gt '5 3 >='
-true
-```
-
### `lte` / `<=`
| a | b | Result |
@@ -74,13 +56,6 @@ true
| 5 | 5 | true |
| 5 | 3 | false |
-```
-$ gt '5 5 lte'
-true
-$ gt '3 5 <='
-true
-```
-
### `eq` / `==`
| a | b | Result |
@@ -88,13 +63,6 @@ true
| 5 | 5 | true |
| 5 | 3 | false |
-```
-$ gt '5 5 eq'
-true
-$ gt '5 5 =='
-true
-```
-
### `neq` / `!=`
| a | b | Result |
@@ -102,17 +70,9 @@ true
| 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.
+Comparison operators convert operands to base units before comparing, so different units within the same category can be compared directly.
### Same category, different units
@@ -136,8 +96,7 @@ $ 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`.
+`1GB` equals exactly `1000MB` (decimal SI), so `gt` is false and `gte` is true. `1024MB` is not equal to `1GB`.
### Network throughput
@@ -157,19 +116,11 @@ $ 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.
+Boolean results coerce to numbers: `true` → 1, `false` → 0. This lets comparison results flow directly into arithmetic.
### Conditional addition
@@ -192,17 +143,10 @@ $ gt '3 5 gt 1 +'
```
$ 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
```
@@ -217,23 +161,14 @@ $ gt '9 3 gt 4 5 lt +'
```
$ 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
+## Examples
### Threshold checks
-Test whether a value exceeds a threshold:
-
```
$ gt '85 80 gt'
true
@@ -241,13 +176,6 @@ 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:
@@ -257,24 +185,19 @@ $ gt '72 68 gte 100 lte +'
2
```
-Temperature 72°F: `72 >= 68` (true/1) + `72 <= 100` (true/1) = 2 (both
-checks pass).
+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).
+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.
+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
@@ -282,13 +205,6 @@ 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:
@@ -350,11 +266,3 @@ 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`).
diff --git a/docs/constants.md b/docs/constants.md
index effb71b..264e2cd 100644
--- a/docs/constants.md
+++ b/docs/constants.md
@@ -1,6 +1,6 @@
# Constants
-The gt calculator includes a comprehensive set of built-in mathematical constants that can be used directly in RPN expressions. Constants are resolved automatically — just use the name as a token.
+gt includes these built-in mathematical constants. They're resolved automatically — just use the name as a token.
## Built-in Constants
@@ -81,9 +81,9 @@ Lists all 36 built-in constants with their values, sorted alphabetically.
gt 'clearconstants'
```
-Removes all user-defined constants and resets built-in constants to their default values. Built-in constants cannot be permanently deleted.
+Removes all user-defined constants and resets built-in constants to their default values. Built-in constants can't be permanently deleted.
-## Practical Use Cases
+## Examples
### Geometry
@@ -140,4 +140,4 @@ gt 'pi' # → 3.141592654 (constant restored)
- Constants are resolved before variables in the lookup order
- All constants use float64 precision (10 significant digits in output)
- Greek letter aliases are fully supported for the most common constants
-- Built-in constants cannot be individually deleted, only overwritten with variables
+- Built-in constants can't be individually deleted, only overwritten with variables
diff --git a/docs/custom-metrics.md b/docs/custom-metrics.md
index abef141..a830d37 100644
--- a/docs/custom-metrics.md
+++ b/docs/custom-metrics.md
@@ -1,8 +1,8 @@
# Custom Metrics
-The `custom` command lets you define your own units of measurement. Custom metrics behave like built-in metrics — they support suffix notation (`10foobar`), metric-aware arithmetic, and conversion to their base unit. They are particularly useful for domain-specific units that gt doesn't ship with out of the box.
+The `custom` command lets you define your own units of measurement. Custom metrics behave like built-in metrics — they support suffix notation (`10foobar`), metric-aware arithmetic, and conversion to their base unit. They're useful for domain-specific units that gt doesn't ship with.
-Custom metrics are RPN operators — they work on the stack, consume tokens, and produce string output. They can be used in single-command mode (`./gt '<expression>'`) or interactively in REPL mode (`./gt`).
+Custom metrics are RPN operators — they work on the stack, consume tokens, and produce string output. They work in single-command mode (`gt '<expression>'`) or interactively in REPL mode (`gt`).
## `custom define`
@@ -25,12 +25,6 @@ gt 'custom define myhour 3600 Time'
gt 'custom define widget 0.5 Universal'
# → defined custom metric "widget" (factor: 0.5, category: Universal)
-
-gt 'custom define negtest -5 Custom'
-# → defined custom metric "negtest" (factor: -5, category: Custom)
-
-gt 'custom define zerounit 0 Custom'
-# → defined custom metric "zerounit" (factor: 0, category: Custom)
```
The factor determines how many base units one unit of the custom metric equals. For example, `foobar` with factor 42 means `1foobar = 42 Custom_base`.
@@ -59,7 +53,7 @@ gt 'custom define foobar 42 Custom'
## `custom undefine`
-Remove a previously defined custom metric. Built-in metrics cannot be removed.
+Remove a previously defined custom metric. Built-in metrics can't be removed.
```bash
gt 'custom undefine <name>'
@@ -112,13 +106,6 @@ gt 'custom show [name]'
### Show all custom metrics
-```bash
-gt 'custom show'
-# → no custom metrics defined
-```
-
-In REPL mode after defining metrics:
-
```
> custom define foobar 42 Custom
defined custom metric "foobar" (factor: 42, category: Custom)
@@ -163,20 +150,16 @@ defined custom metric "foobar" (factor: 42, category: Custom)
Custom metrics in the same category are compatible for addition and subtraction. The result uses the unit of the bottom-of-stack operand:
```
-> custom define foobar 42 Custom
-defined custom metric "foobar" (factor: 42, category: Custom)
> 10foobar 5foobar +
15
> 5foobar 3foobar -
2
```
-The result is unitless because the metric system resolves to base units for the calculation. For factor 42: `10foobar = 420`, `5foobar = 210`, so `420 + 210 = 630` which is `15 foobar` in base units. The displayed value is the quotient in terms of the result's unit.
+The result is unitless because the metric system resolves to base units for the calculation. For factor 42: `10foobar = 420`, `5foobar = 210`, so `420 + 210 = 630` which is `15 foobar` in base units.
### Multiplication and division
-Custom metrics work with multiplication and division:
-
```
> custom define mul_unit 5 Custom
defined custom metric "mul_unit" (factor: 5, category: Custom)
@@ -193,15 +176,13 @@ defined custom metric "div_unit" (factor: 10, category: Custom)
Unitless values (`Cool`/Universal) can be added to custom metrics:
```
-> custom define foobar 42 Custom
-defined custom metric "foobar" (factor: 42, category: Custom)
> 10foobar 5 +
10
```
### Incompatible categories
-Custom metrics in different categories cannot be mixed:
+Custom metrics in different categories can't be mixed:
```
> custom define timetest 3600 Time
@@ -217,8 +198,6 @@ Error: metric arithmetic requires compatible categories (Time vs Distance)
Custom metrics support `@<unit> convert` within their category. Conversion to a different category fails:
```
-> custom define foobar 42 Custom
-defined custom metric "foobar" (factor: 42, category: Custom)
> 10foobar @Custom_base convert
420
> 10foobar @Mbps convert
@@ -236,14 +215,12 @@ defined custom metric "hyper_test" (factor: 100, category: Custom)
18
```
-## Practical Use Cases
+## Examples
### Company-specific units
-Define internal measurement units that aren't standard:
-
```
-> custom define reel 304.8 meters
+> custom define reel 304.8 Distance
defined custom metric "reel" (factor: 304.8, category: Distance)
> 5reel @m convert
1524
@@ -251,8 +228,6 @@ defined custom metric "reel" (factor: 304.8, category: Distance)
### Recipe and cooking units
-Create convenient cooking measurements:
-
```
> custom define cup 240 Weight
defined custom metric "cup" (factor: 240, category: Weight)
@@ -264,8 +239,6 @@ defined custom metric "cup" (factor: 240, category: Weight)
### Game currencies and points
-Define game-specific units for calculating rewards:
-
```
> custom define gold 1000 Universal
defined custom metric "gold" (factor: 1000, category: Universal)
@@ -275,8 +248,6 @@ defined custom metric "gold" (factor: 1000, category: Universal)
### Time conversions with custom units
-Create convenient time units:
-
```
> custom define fortnight 1209600 Time
defined custom metric "fortnight" (factor: 1209600, category: Time)
@@ -293,10 +264,6 @@ Defining a metric with a name that already exists (including built-in metrics) f
```bash
gt 'custom define Mbps 1000 DataRate'
# → Error: rpn: custom define: metric "Mbps" already exists
-
-gt 'custom define foobar 42 Custom'
-gt 'custom define foobar 99 Custom'
-# → Error: rpn: custom define: metric "foobar" already exists
```
In REPL mode, the second define on the same RPN instance fails:
@@ -372,9 +339,7 @@ gt 'custom rename foobar'
## REPL vs Single-Command Mode
-Custom metric commands behave differently depending on how gt is invoked:
-
-### Single-command mode (`./gt '<expression>'`)
+### Single-command mode (`gt '<expression>'`)
Each invocation creates a fresh process with a clean metric registry. `custom define` confirms the metric was registered but stops evaluation, so subsequent tokens are not processed:
@@ -387,7 +352,7 @@ gt 'custom define foobar 42 Custom 10foobar 5foobar +'
# → defined custom metric "foobar" (factor: 42, category: Custom)
```
-### REPL mode (`./gt` interactively)
+### REPL mode (`gt` interactively)
The RPN engine and metric registry persist across lines. Define metrics first, then use them in subsequent calculations:
@@ -408,7 +373,7 @@ removed custom metric "foobar"
no custom metrics defined
```
-REPL mode is the recommended way to work with custom metrics, as it allows defining, using, and managing metrics in a single session.
+REPL mode is the recommended way to work with custom metrics.
## Summary
diff --git a/docs/fast-power.md b/docs/fast-power.md
index 5d6a981..a00f7a5 100644
--- a/docs/fast-power.md
+++ b/docs/fast-power.md
@@ -112,4 +112,4 @@ The `**` operator **requires** an integer exponent. Use `^` for fractional expon
- **Time complexity**: O(log |n|) where n is the exponent. An exponent of 100 requires only ~7 loop iterations (vs 99 naive multiplications).
- **Space complexity**: O(1) for positive exponents; O(log |n|) stack depth for negative exponents (recursive call).
- The implementation uses `float64` throughout, so results may lose precision for very large exponents (same limitations as any floating-point computation).
-- For the specific case of exponent 0, the function returns 1 immediately without entering the loop.
+- For exponent 0, the function returns 1 immediately without entering the loop.
diff --git a/docs/hyper-operators.md b/docs/hyper-operators.md
index 0953e10..bb05e20 100644
--- a/docs/hyper-operators.md
+++ b/docs/hyper-operators.md
@@ -1,11 +1,8 @@
# Hyper RPN Operators
-Hyper operators operate on **all** values currently on the stack, rather than
-just the top one or two. They pop every value, reduce them left-associatively,
-and push a single result back.
+Hyper operators operate on **all** values currently on the stack, rather than just the top one or two. They pop every value, reduce them left-associatively, and push a single result back.
-The syntax uses square brackets: `[+]`, `[*]`, `[-]`, `[/]`, `[^]`, `[%]`,
-`[lg]`, `[log]`, `[ln]`.
+The syntax uses square brackets: `[+]`, `[*]`, `[-]`, `[/]`, `[^]`, `[%]`, `[lg]`, `[log]`, `[ln]`.
## How Hyper Operators Work
@@ -24,13 +21,11 @@ Input: 1 2 3 4 5 [+]
Result: 15
```
-All five values are consumed, summed left-to-right (`((((1 + 2) + 3) + 4) +
-5)`), and the single result is pushed back.
+All five values are consumed, summed left-to-right (`((((1 + 2) + 3) + 4) + 5)`), and the single result is pushed back.
### Requirements
-- At least **two** values must be on the stack, or the operator returns an
- error.
+- At least **two** values must be on the stack, or the operator returns an error.
- After execution, exactly one value remains on the stack.
## Arithmetic Hyper Operators
@@ -44,8 +39,6 @@ $ gt '1 2 3 4 5 [+]'
15
```
-Equivalently: `1 + 2 + 3 + 4 + 5` = 15.
-
With two operands, behaves identically to binary `+`:
```
@@ -60,11 +53,6 @@ Multiplies all stack values left-associatively. Result is always unitless.
```
$ gt '2 3 4 [*]'
24
-```
-
-Equivalently: `2 * 3 * 4` = 24.
-
-```
$ gt '1 2 3 [*]'
6
```
@@ -76,38 +64,24 @@ Subtracts all stack values left-associatively from the first.
```
$ gt '10 3 2 [-]'
5
-```