@euclid-tools/euclid 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,103 @@
1
+ # Expression Reference — `calculate` tool
2
+
3
+ ## Operators
4
+
5
+ | Operator | Meaning | Example |
6
+ | -------- | -------------- | ----------------- |
7
+ | `+` | Addition | `2 + 3` → `5` |
8
+ | `-` | Subtraction | `10 - 4` → `6` |
9
+ | `*` | Multiplication | `7 * 8` → `56` |
10
+ | `/` | Division | `15 / 4` → `3.75` |
11
+ | `^` | Exponentiation | `2^10` → `1024` |
12
+ | `!` | Factorial | `5!` → `120` |
13
+
14
+ Standard order of operations applies. Use parentheses to control grouping.
15
+
16
+ ## Functions
17
+
18
+ | Function | Description | Example |
19
+ | -------------- | -------------------- | ----------------------- |
20
+ | `sqrt(x)` | Square root | `sqrt(144)` → `12` |
21
+ | `abs(x)` | Absolute value | `abs(-5)` → `5` |
22
+ | `ceil(x)` | Round up | `ceil(4.2)` → `5` |
23
+ | `floor(x)` | Round down | `floor(4.8)` → `4` |
24
+ | `round(x)` | Round to nearest | `round(4.5)` → `5` |
25
+ | `exp(x)` | e^x | `exp(1)` → `2.71828...` |
26
+ | `log(x, base)` | Logarithm | `log(100, 10)` → `2` |
27
+ | `ln(x)` | Natural log (base e) | `ln(e)` → `1` |
28
+ | `sin(x)` | Sine (radians) | `sin(pi / 2)` → `1` |
29
+ | `cos(x)` | Cosine (radians) | `cos(0)` → `1` |
30
+ | `tan(x)` | Tangent (radians) | `tan(pi / 4)` → `1` |
31
+ | `asin(x)` | Inverse sine | `asin(1)` → `1.5707...` |
32
+ | `acos(x)` | Inverse cosine | `acos(1)` → `0` |
33
+ | `atan(x)` | Inverse tangent | `atan(1)` → `0.7853...` |
34
+
35
+ ### Trigonometry with degrees
36
+
37
+ Trig functions use **radians** by default. Append `deg` for degree input:
38
+
39
+ ```
40
+ sin(30 deg) → 0.5
41
+ cos(45 deg) → 0.7071...
42
+ sin(pi / 6) → 0.5 (radians, same result)
43
+ ```
44
+
45
+ ## Constants
46
+
47
+ | Constant | Value | Usage |
48
+ | -------- | ------------------- | ------------ |
49
+ | `pi` | 3.14159265358979... | `2 * pi * r` |
50
+ | `e` | 2.71828182845904... | `e^2` |
51
+ | `phi` | 1.61803398874989... | Golden ratio |
52
+
53
+ ## Unicode Support
54
+
55
+ These symbols are normalized automatically — you can use them directly:
56
+
57
+ | Input | Converted to | Example |
58
+ | ------------------- | ------------ | ------------------------------------------ |
59
+ | `×` | `*` | `2 × 3` → `2 * 3` |
60
+ | `÷` | `/` | `10 ÷ 2` → `10 / 2` |
61
+ | `²` | `^2` | `5²` → `5^2` |
62
+ | `³` | `^3` | `2³` → `2^3` |
63
+ | `√` | `sqrt(...)` | `√16` → `sqrt(16)`, `√(2+3)` → `sqrt(2+3)` |
64
+ | `π` | `pi` | `2π` → `2pi` |
65
+ | `−` (Unicode minus) | `-` | `5 − 3` → `5 - 3` |
66
+
67
+ ## Thousands Separators
68
+
69
+ Commas in numbers are stripped automatically:
70
+
71
+ ```
72
+ 3,456 * 7,891 → 3456 * 7891
73
+ 1,000,000 + 500 → 1000000 + 500
74
+ ```
75
+
76
+ Function argument commas are preserved: `log(100, 10)` stays as-is.
77
+
78
+ ## Precision
79
+
80
+ The `precision` parameter controls significant digits in the result (default: 14):
81
+
82
+ ```
83
+ calculate({ expression: "pi", precision: 6 }) → "3.14159"
84
+ calculate({ expression: "1/3" }) → "0.33333333333333"
85
+ ```
86
+
87
+ ## Edge Cases
88
+
89
+ | Expression | Result | Note |
90
+ | ------------------ | ------------------- | ---------------- |
91
+ | `1 / 0` | `Infinity` | Not an error |
92
+ | `-1 / 0` | `-Infinity` | Not an error |
93
+ | `0 / 0` | `NaN` | Not an error |
94
+ | `sqrt(-1)` | `i` | Complex number |
95
+ | `e^(i * pi) + 1` | `≈ 0` | Euler's identity |
96
+ | Very large numbers | Scientific notation | e.g., `1e+30` |
97
+
98
+ ## Limits
99
+
100
+ - **Max expression length:** 1000 characters
101
+ - **Execution timeout:** 5 seconds
102
+ - **Disabled functions:** `import`, `createUnit`, `evaluate`, `parse`, `simplify`,
103
+ `derivative`, `resolve`, `reviver` (blocked for security)
@@ -0,0 +1,93 @@
1
+ ---
2
+ name: math
3
+ description: >
4
+ Guidance for using Euclid's deterministic MCP math tools (calculate, convert,
5
+ statistics). Use when the user's request requires numerical computation, unit
6
+ conversion, or statistical analysis instead of mental math.
7
+ ---
8
+
9
+ # Euclid Math Tools
10
+
11
+ ## The Rule
12
+
13
+ If a user's request requires a numerical result, unit conversion, or statistical
14
+ computation, use the Euclid MCP tools. **Never predict, estimate, or mentally
15
+ compute when a deterministic tool is available.**
16
+
17
+ This applies to all math: arithmetic, percentages, exponents, roots, trigonometry,
18
+ logarithms, factorials, combinatorics, unit conversions, and dataset statistics.
19
+
20
+ Even for "simple" math like `247 * 38`, use the `calculate` tool. Mental math
21
+ is a prediction — the tool is deterministic.
22
+
23
+ ## Which Tool to Use
24
+
25
+ | The user needs... | Use | Example |
26
+ | ----------------------------------------- | ------------ | ------------------------------------------------------- |
27
+ | A numerical result from a math expression | `calculate` | "What is 15% of 847?" → `0.15 * 847` |
28
+ | To convert between units of measurement | `convert` | "Convert 5 km to miles" → `convert(5, "km", "mile")` |
29
+ | A statistic computed on a dataset | `statistics` | "Average of these scores" → `statistics("mean", [...])` |
30
+ | A conceptual explanation | None | "Explain what a derivative is" |
31
+ | A rough estimate or guess | None | "About how many people fit in a stadium" |
32
+ | Symbolic algebra (no numeric answer) | None | "Simplify x^2 + 2x" |
33
+
34
+ ## Key Behaviors
35
+
36
+ **Always use the tool, never fall back to mental math.** If a calculation errors,
37
+ read the `hint` and `examples` fields in the error response. Fix the input and
38
+ retry. Do not fall back to predicting the answer.
39
+
40
+ **Chain tools when needed.** Calculate a value, then convert its units. Compute
41
+ individual values, then run statistics on them. Each tool does one thing well.
42
+
43
+ **Present full precision.** Do not round or truncate Euclid results unless the
44
+ user explicitly asks for rounding. The tool returns precise results — preserve them.
45
+
46
+ **Unicode and natural language work.** Expressions with `×`, `÷`, `√`, `π`, `²`,
47
+ `³` are normalized automatically. Unit names like `"celsius"`, `"fahrenheit"`,
48
+ `"miles per hour"` are also normalized. No need to manually convert these.
49
+
50
+ **Use `calculate` broadly.** Percentages, compound interest, combinatorics,
51
+ trigonometry, logarithms, factorials — anything with a single correct numerical
52
+ answer belongs in `calculate`.
53
+
54
+ ## Tool Quick Reference
55
+
56
+ ### calculate
57
+
58
+ Takes `expression` (string) and optional `precision` (number, default 14).
59
+
60
+ ```
61
+ calculate({ expression: "0.15 * 847" })
62
+ calculate({ expression: "sin(30 deg)", precision: 6 })
63
+ calculate({ expression: "12! / (4! * 8!)" })
64
+ ```
65
+
66
+ For expression syntax, available functions, and edge cases, see
67
+ [EXPRESSIONS.md](EXPRESSIONS.md).
68
+
69
+ ### convert
70
+
71
+ Takes `value` (number), `from` (string), `to` (string).
72
+
73
+ ```
74
+ convert({ value: 100, from: "fahrenheit", to: "celsius" })
75
+ convert({ value: 60, from: "mph", to: "kph" })
76
+ convert({ value: 1024, from: "bytes", to: "kB" })
77
+ ```
78
+
79
+ For supported units, aliases, and categories, see [UNITS.md](UNITS.md).
80
+
81
+ ### statistics
82
+
83
+ Takes `operation` (enum), `data` (number[]), optional `percentile` (0-100).
84
+
85
+ ```
86
+ statistics({ operation: "mean", data: [85, 92, 78, 95, 88] })
87
+ statistics({ operation: "percentile", data: [120, 340, 200, 150, 180], percentile: 90 })
88
+ ```
89
+
90
+ Operations: `mean`, `median`, `mode`, `std`, `variance`, `min`, `max`, `sum`,
91
+ `percentile`.
92
+
93
+ For details on each operation and data format, see [STATISTICS.md](STATISTICS.md).
@@ -0,0 +1,51 @@
1
+ # Statistics Reference — `statistics` tool
2
+
3
+ ## Operations
4
+
5
+ | Operation | Description | Example |
6
+ | ------------ | ------------------------- | -------------------------------------------------------- |
7
+ | `mean` | Arithmetic average | `statistics("mean", [1, 2, 3])` → `2` |
8
+ | `median` | Middle value (sorted) | `statistics("median", [1, 3, 5, 7])` → `4` |
9
+ | `mode` | Most frequent value | `statistics("mode", [1, 2, 2, 3])` → `2` |
10
+ | `std` | Sample standard deviation | `statistics("std", [2, 4, 6])` → `2` |
11
+ | `variance` | Sample variance | `statistics("variance", [2, 4, 6])` → `4` |
12
+ | `min` | Minimum value | `statistics("min", [5, 1, 9])` → `1` |
13
+ | `max` | Maximum value | `statistics("max", [5, 1, 9])` → `9` |
14
+ | `sum` | Sum of all values | `statistics("sum", [10, 20, 30])` → `60` |
15
+ | `percentile` | Value at nth percentile | `statistics("percentile", [10, 20, 30], 90)` → see below |
16
+
17
+ ### Notes on specific operations
18
+
19
+ **`mode`**: If multiple values share the highest frequency, returns the first one
20
+ encountered. It does not return all modes.
21
+
22
+ **`percentile`**: Requires the `percentile` parameter (0–100). This is the most
23
+ common error — omitting it produces:
24
+
25
+ ```
26
+ "Percentile value is required when operation is 'percentile'"
27
+ ```
28
+
29
+ Example:
30
+
31
+ ```
32
+ statistics({ operation: "percentile", data: [120, 340, 200, 150, 180], percentile: 90 })
33
+ ```
34
+
35
+ **`std` and `variance`**: These compute **sample** standard deviation and variance
36
+ (dividing by n-1), not population (dividing by n).
37
+
38
+ ## Data Format
39
+
40
+ - Data is a plain JSON array of numbers: `[85, 92, 78, 95, 88]`
41
+ - Array must contain at least one number (empty arrays are rejected)
42
+ - Maximum 10,000 elements per array
43
+
44
+ ## Common Errors
45
+
46
+ | Error | Cause | Fix |
47
+ | -------------------------------------- | -------------------------- | --------------------------------- |
48
+ | "Data array is empty" | Empty `[]` passed | Provide at least one number |
49
+ | "Percentile value is required..." | `percentile` param missing | Add `percentile: N` (0–100) |
50
+ | "Percentile must be between 0 and 100" | Value out of range | Use a value from 0 to 100 |
51
+ | "Unknown operation" | Typo in operation name | Use one of the 9 valid operations |
@@ -0,0 +1,130 @@
1
+ # Unit Reference — `convert` tool
2
+
3
+ ## Supported Unit Categories
4
+
5
+ ### Length
6
+
7
+ | Unit | Aliases |
8
+ | ------------- | --------------------- |
9
+ | Meter | `m`, `cm`, `mm`, `km` |
10
+ | Mile | `mi`, `mile`, `miles` |
11
+ | Yard | `yd` |
12
+ | Foot | `ft` |
13
+ | Inch | `inch`, `in` |
14
+ | Nautical mile | `nmi` |
15
+
16
+ ### Mass
17
+
18
+ | Unit | Aliases |
19
+ | -------- | --------------- |
20
+ | Kilogram | `kg`, `g`, `mg` |
21
+ | Pound | `lb` |
22
+ | Ounce | `oz` |
23
+ | Ton | `ton` |
24
+ | Stone | `stone` |
25
+
26
+ ### Volume
27
+
28
+ | Unit | Aliases |
29
+ | ----------- | ------------------------------- |
30
+ | Liter | `liter`, `litre`, `litres`, `L` |
31
+ | Milliliter | `ml`, `mL` |
32
+ | Gallon | `gal` |
33
+ | Pint | `pint` |
34
+ | Cup | `cup` |
35
+ | Fluid ounce | `floz` |
36
+
37
+ ### Temperature
38
+
39
+ | Unit | Code | Natural language alias |
40
+ | ---------- | ------ | ---------------------- |
41
+ | Celsius | `degC` | `celsius` |
42
+ | Fahrenheit | `degF` | `fahrenheit` |
43
+ | Kelvin | `K` | — |
44
+ | Rankine | `degR` | — |
45
+
46
+ Temperature units in mathjs are `degC` and `degF`, but you can use `celsius` and
47
+ `fahrenheit` — they are normalized automatically.
48
+
49
+ ### Speed
50
+
51
+ | Unit | Code |
52
+ | ------------------------- | --------------------------- |
53
+ | Meters per second | `m/s` |
54
+ | Kilometers per hour | `km/h` |
55
+ | Miles per hour | `mph` |
56
+ | Kilometers per hour (alt) | `kph`, `kmh` |
57
+ | Knots | `knot`, `knots`, `kn`, `kt` |
58
+
59
+ ### Time
60
+
61
+ | Unit | Code |
62
+ | ------ | ------ |
63
+ | Second | `s` |
64
+ | Minute | `min` |
65
+ | Hour | `h` |
66
+ | Day | `day` |
67
+ | Week | `week` |
68
+
69
+ ### Area
70
+
71
+ | Unit | Code | Natural language alias |
72
+ | ---------------- | -------- | ---------------------- |
73
+ | Square meter | `m^2` | `square meters` |
74
+ | Square foot | `ft^2` | `square feet` |
75
+ | Square kilometer | `km^2` | `square kilometers` |
76
+ | Square mile | `mile^2` | `square miles` |
77
+
78
+ ### Volume (Cubic)
79
+
80
+ | Unit | Code | Natural language alias |
81
+ | ----------- | ------ | ---------------------- |
82
+ | Cubic meter | `m^3` | `cubic meters` |
83
+ | Cubic foot | `ft^3` | `cubic feet` |
84
+ | Cubic inch | `in^3` | `cubic inches` |
85
+
86
+ ### Data
87
+
88
+ | Unit | Code |
89
+ | -------- | --------------- |
90
+ | Byte | `byte`, `bytes` |
91
+ | Kilobyte | `kB` |
92
+ | Megabyte | `MB` |
93
+ | Gigabyte | `GB` |
94
+ | Terabyte | `TB` |
95
+ | Bit | `b` |
96
+ | Kilobit | `kb` |
97
+ | Megabit | `Mb` |
98
+ | Gigabit | `Gb` |
99
+ | Terabit | `Tb` |
100
+
101
+ ## Natural Language Aliases
102
+
103
+ These are normalized automatically (case-insensitive):
104
+
105
+ | You can say... | Converted to |
106
+ | --------------------- | ------------ |
107
+ | `celsius` | `degC` |
108
+ | `fahrenheit` | `degF` |
109
+ | `kilometers per hour` | `km/hour` |
110
+ | `miles per hour` | `mile/hour` |
111
+ | `meters per second` | `m/s` |
112
+ | `feet per second` | `ft/s` |
113
+ | `square meters` | `m^2` |
114
+ | `square feet` | `ft^2` |
115
+ | `square kilometers` | `km^2` |
116
+ | `square miles` | `mile^2` |
117
+ | `cubic meters` | `m^3` |
118
+ | `cubic feet` | `ft^3` |
119
+ | `cubic inches` | `in^3` |
120
+ | `litres` | `liter` |
121
+
122
+ ## Incompatible Units
123
+
124
+ Both units must measure the same quantity. Converting between different quantities
125
+ (e.g., `kg` to `km`, or `degC` to `mph`) returns an error:
126
+
127
+ ```
128
+ "Units are incompatible. Ensure both measure the same quantity
129
+ (e.g., length to length, weight to weight)."
130
+ ```