rei-lang 0.3.0 → 0.4.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.
- package/LICENSE +230 -191
- package/PEACE_USE_CLAUSE.md +95 -0
- package/README.md +257 -186
- package/bin/rei.js +259 -144
- package/dist/index.d.mts +257 -0
- package/dist/index.d.ts +181 -93
- package/dist/index.js +5710 -239
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8741 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +73 -62
- package/spec/REI_BNF_v0.2.md +398 -0
- package/spec/REI_BNF_v0.3.md +358 -0
- package/spec/REI_SPEC_v0.1.md +587 -0
- package/theory/LICENSE-THEORY.md +57 -0
- package/theory/README.md +85 -0
- package/theory/category-c-design.md +502 -0
- package/theory/core-theories-11-14.md +799 -0
- package/theory/core-theories-15-21.md +675 -0
- package/theory/core-theories-8-10.md +582 -0
- package/theory/d-fumt-overview.md +99 -0
- package/theory/genesis-axiom-system.md +124 -0
- package/theory/gft-theory.md +160 -0
- package/theory/index.ts +9 -0
- package/theory/notation-equivalence.md +134 -0
- package/theory/semantic-compressor.ts +903 -0
- package/theory/stdlib-tier1-design.md +477 -0
- package/theory/theories-11-14.ts +466 -0
- package/theory/theories-15-21.ts +762 -0
- package/theory/theories-22-28.ts +794 -0
- package/theory/theories-29-35.ts +607 -0
- package/theory/theories-36-42.ts +937 -0
- package/theory/theories-43-49.ts +1298 -0
- package/theory/theories-50-56.ts +1449 -0
- package/theory/theories-57-66.ts +1724 -0
- package/theory/theories-67.ts +1696 -0
- package/theory/theories-8-10.ts +284 -0
- package/dist/index.cjs +0 -3282
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -169
package/README.md
CHANGED
|
@@ -1,186 +1,257 @@
|
|
|
1
|
-
# Rei (0
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/rei-lang)
|
|
4
|
-
[ — D-FUMT Computational Language
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/rei-lang)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
[]()
|
|
6
|
+
|
|
7
|
+
**Rei** (0₀式 / れいしき) is a mathematical computation language based on **D-FUMT** (Dimensional Fujimoto Universal Mathematical Theory). Its center-periphery patterns as language primitives achieve an **average 74% code reduction** over equivalent implementations in general-purpose languages.
|
|
8
|
+
|
|
9
|
+
**Author:** Nobuki Fujimoto
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install rei-lang
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
### As a Library
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { rei } from 'rei-lang';
|
|
25
|
+
|
|
26
|
+
// Multi-dimensional number computation
|
|
27
|
+
rei('let field = 𝕄{5; 1, 2, 3, 4}');
|
|
28
|
+
const result = rei('field |> compute :weighted');
|
|
29
|
+
console.log(result); // 7.5
|
|
30
|
+
|
|
31
|
+
// Define functions with compress
|
|
32
|
+
rei('compress energy(m) = m |> compute :weighted');
|
|
33
|
+
rei('let e = energy(𝕄{0; 10, 20, 30})');
|
|
34
|
+
console.log(rei('e')); // 20
|
|
35
|
+
|
|
36
|
+
// Genesis axiom system
|
|
37
|
+
rei('let g = genesis()');
|
|
38
|
+
rei('g |> forward');
|
|
39
|
+
rei('g |> forward');
|
|
40
|
+
console.log(rei('g.state')); // "line"
|
|
41
|
+
|
|
42
|
+
// Reset state between sessions
|
|
43
|
+
rei.reset();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Interactive REPL
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npx rei
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
╔══════════════════════════════════════════╗
|
|
54
|
+
║ Rei (0₀式) REPL v0.2.0 ║
|
|
55
|
+
║ D-FUMT Computational Language ║
|
|
56
|
+
╚══════════════════════════════════════════╝
|
|
57
|
+
|
|
58
|
+
零 > 𝕄{5; 1, 2, 3, 4} |> compute :weighted
|
|
59
|
+
7.5
|
|
60
|
+
|
|
61
|
+
零 > compress karma(i, e, r) = i * e * r
|
|
62
|
+
compress karma(i, e, r)
|
|
63
|
+
|
|
64
|
+
零 > karma(0.8, 0.9, 0.7)
|
|
65
|
+
0.504
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Execute a File
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
npx rei program.rei
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Inline Evaluation
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npx rei -e "2 + 3 * 4"
|
|
78
|
+
# → 14
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Language Features
|
|
84
|
+
|
|
85
|
+
### Multi-Dimensional Numbers (𝕄)
|
|
86
|
+
|
|
87
|
+
The core data structure. A center value with peripheral neighbors, computed in 4 modes:
|
|
88
|
+
|
|
89
|
+
```rei
|
|
90
|
+
let m = 𝕄{5; 1, 2, 3, 4}
|
|
91
|
+
|
|
92
|
+
m |> compute :weighted // center + weighted avg of neighbors
|
|
93
|
+
m |> compute :multiplicative // center × Π(1 + nᵢ)
|
|
94
|
+
m |> compute :harmonic // center + n / Σ(1/|nᵢ|)
|
|
95
|
+
m |> compute :exponential // center × avg(e^nᵢ)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Extended Numbers (拡張数)
|
|
99
|
+
|
|
100
|
+
Numbers with subscript-based dimensional extension:
|
|
101
|
+
|
|
102
|
+
```rei
|
|
103
|
+
let a = 0ooo // 3rd-order extension of zero
|
|
104
|
+
a >> :x >> :x // extend: order 3 → 5
|
|
105
|
+
a << // reduce: order 3 → 2
|
|
106
|
+
a |> valStar // numeric projection: 0.001
|
|
107
|
+
|
|
108
|
+
πooo // π extended to 3rd order
|
|
109
|
+
0₀ // D-FUMT zero symbol
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Compress (関数定義)
|
|
113
|
+
|
|
114
|
+
Functions are defined with `compress` — reflecting D-FUMT's compression philosophy:
|
|
115
|
+
|
|
116
|
+
```rei
|
|
117
|
+
compress distance(x, y) = sqrt(x * x + y * y)
|
|
118
|
+
compress field(c, r) = 𝕄{c; r, r, r, r}
|
|
119
|
+
|
|
120
|
+
distance(3, 4) // 5
|
|
121
|
+
field(10, 2) |> compute :weighted // 12
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Pipe Operator (|>)
|
|
125
|
+
|
|
126
|
+
Center-to-periphery data flow:
|
|
127
|
+
|
|
128
|
+
```rei
|
|
129
|
+
-25 |> abs |> sqrt // 5
|
|
130
|
+
[3, 1, 2] |> sort |> reverse // [3, 2, 1]
|
|
131
|
+
"hello" |> upper // "HELLO"
|
|
132
|
+
𝕄{0; 1, 2, 3} |> normalize // normalized neighbors
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Genesis Axiom System (生成公理系)
|
|
136
|
+
|
|
137
|
+
Models computational emergence from void:
|
|
138
|
+
|
|
139
|
+
```rei
|
|
140
|
+
let g = genesis() // void
|
|
141
|
+
g |> forward // void → dot
|
|
142
|
+
g |> forward // dot → line
|
|
143
|
+
g |> forward // line → surface
|
|
144
|
+
g |> forward // surface → solid
|
|
145
|
+
g |> forward // solid → omega (Ω)
|
|
146
|
+
g.omega // 1
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Or from the primordial dot (・):
|
|
150
|
+
|
|
151
|
+
```rei
|
|
152
|
+
let g = ・
|
|
153
|
+
g |> forward // dot
|
|
154
|
+
g |> forward // line
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Four-Valued Logic (四価0π)
|
|
158
|
+
|
|
159
|
+
Beyond true/false — Theory #21:
|
|
160
|
+
|
|
161
|
+
```rei
|
|
162
|
+
⊤ // true
|
|
163
|
+
⊥ // false
|
|
164
|
+
⊤π // true-pi (π-rotated truth)
|
|
165
|
+
⊥π // false-pi
|
|
166
|
+
|
|
167
|
+
¬⊤ // ⊥
|
|
168
|
+
⊤ ∧ ⊥ // ⊥
|
|
169
|
+
⊥ ∨ ⊤ // ⊤
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Variable Binding
|
|
173
|
+
|
|
174
|
+
```rei
|
|
175
|
+
let x = 42 // immutable
|
|
176
|
+
let mut y = 10 // mutable
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## Benchmarks
|
|
182
|
+
|
|
183
|
+
| Task | Conventional | Rei | Reduction |
|
|
184
|
+
|------|-------------|-----|-----------|
|
|
185
|
+
| Image kernel calculations | 32 lines | 8 lines | **4×** |
|
|
186
|
+
| Multi-dimensional data aggregation | 45 lines | 12 lines | **3.7×** |
|
|
187
|
+
| Graph structure transformation | 52 lines | 14 lines | **3.7×** |
|
|
188
|
+
| **Average** | | | **74%** |
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## API Reference
|
|
193
|
+
|
|
194
|
+
### `rei(code: string): ReiValue`
|
|
195
|
+
|
|
196
|
+
Evaluate a string of Rei code. State persists across calls.
|
|
197
|
+
|
|
198
|
+
### `rei.reset(): void`
|
|
199
|
+
|
|
200
|
+
Clear all variable and function bindings.
|
|
201
|
+
|
|
202
|
+
### `rei.parse(code: string): ASTNode`
|
|
203
|
+
|
|
204
|
+
Parse code and return the AST without evaluating.
|
|
205
|
+
|
|
206
|
+
### `rei.tokenize(code: string): Token[]`
|
|
207
|
+
|
|
208
|
+
Tokenize code and return the token stream.
|
|
209
|
+
|
|
210
|
+
### Classes
|
|
211
|
+
|
|
212
|
+
- `Lexer` — Tokenizer
|
|
213
|
+
- `Parser` — Recursive descent parser
|
|
214
|
+
- `Evaluator` — AST evaluator with environment/scope chain
|
|
215
|
+
- `Environment` — Scope management
|
|
216
|
+
|
|
217
|
+
### Types
|
|
218
|
+
|
|
219
|
+
- `MultiDimNumber` — `{ center, neighbors, mode, weights? }`
|
|
220
|
+
- `ReiExtended` — `{ base, order, subscripts, valStar() }`
|
|
221
|
+
- `GenesisState` — `{ state, omega, history }`
|
|
222
|
+
- `ReiFunction` — `{ name, params, body, closure }`
|
|
223
|
+
- `Quad` — `{ value: 'top' | 'bottom' | 'topPi' | 'bottomPi' }`
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## BNF Specification
|
|
228
|
+
|
|
229
|
+
The complete BNF v0.2 specification is available in the repository.
|
|
230
|
+
|
|
231
|
+
Key features integrated from 21 D-FUMT theories:
|
|
232
|
+
- 45 keywords, 10 operators, 9 types
|
|
233
|
+
- Full backward compatibility with v0.1
|
|
234
|
+
- Complete operator precedence table
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Theoretical Foundation
|
|
239
|
+
|
|
240
|
+
Rei is grounded in **D-FUMT** (Dimensional Fujimoto Universal Mathematical Theory), a framework of 66 interconnected theories spanning pure mathematics to philosophy and AI consciousness. The language's core innovation — **center-periphery patterns as language primitives** — derives from D-FUMT's multi-dimensional number system theory.
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
☮️ Peace Use Clause / 平和利用条項
|
|
244
|
+
Rei is licensed under Apache 2.0 with an additional Peace Use Clause.
|
|
245
|
+
Rei は Apache 2.0 ライセンスに加え、平和利用条項が適用されます。
|
|
246
|
+
Rooted in the Buddhist concept of "Kū" (空, Emptiness) and D-FUMT's consciousness mathematics, Rei is designed exclusively for the peaceful advancement of humanity. This software may not be used for:
|
|
247
|
+
仏教の「空」の概念と D-FUMT の意識数学に基づき、Rei は人類の平和的発展のためにのみ設計されています。以下の目的での使用は禁止されています:
|
|
248
|
+
|
|
249
|
+
🚫 Weapons, military systems, or LAWS / 兵器・軍事システム・自律型致死兵器
|
|
250
|
+
🚫 Human rights violations / 人権侵害
|
|
251
|
+
🚫 Intentional environmental destruction / 意図的な環境破壊
|
|
252
|
+
|
|
253
|
+
✅ Education, research, humanitarian aid, and creative endeavors are encouraged.
|
|
254
|
+
✅ 教育・研究・人道支援・創造的活動での使用を推奨します。
|
|
255
|
+
See PEACE_USE_CLAUSE.md for full details.
|
|
256
|
+
|
|
257
|
+
MIT © Nobuki Fujimoto
|