rei-lang 0.5.0 → 0.5.1
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/README.md +474 -451
- package/bin/rei.js +259 -259
- package/dist/index.d.mts +218 -2
- package/dist/index.d.ts +218 -2
- package/dist/index.js +786 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +778 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +80 -78
package/README.md
CHANGED
|
@@ -1,451 +1,474 @@
|
|
|
1
|
-
# Rei (0₀式) — D-FUMT Computational Language
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/rei-lang)
|
|
4
|
-
[](./LICENSE)
|
|
5
|
-
[ 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
|
-
## What's New in v0.5
|
|
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
|
-
```rei
|
|
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
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
|
370
|
-
|
|
371
|
-
|
|
|
372
|
-
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
|
399
|
-
|
|
400
|
-
| `
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
|
405
|
-
|
|
406
|
-
| `
|
|
407
|
-
| `
|
|
408
|
-
| `
|
|
409
|
-
| `
|
|
410
|
-
| `
|
|
411
|
-
| `
|
|
412
|
-
| `
|
|
413
|
-
| `
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
1
|
+
# Rei (0₀式) — 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
|
+
## What's New in v0.5.1 — AgentSpace (Phase 4a)
|
|
14
|
+
|
|
15
|
+
**Puzzles and games are the same abstraction.** AgentSpace unifies puzzle-solving and game-playing on the v0.5 agent runtime:
|
|
16
|
+
|
|
17
|
+
- **Puzzles** = cooperative multi-agent systems (all cells work toward a common goal)
|
|
18
|
+
- **Games** = competitive multi-agent systems (players have opposing objectives)
|
|
19
|
+
|
|
20
|
+
The only difference is agent `behavior` and mediator `strategy`.
|
|
21
|
+
|
|
22
|
+
```rei
|
|
23
|
+
// Puzzle: Agent-based solving
|
|
24
|
+
30 |> generate_sudoku(42) |> agent_solve // 81 cooperative agents solve sudoku
|
|
25
|
+
30 |> 数独生成(42) |> 自律解法 // Japanese syntax
|
|
26
|
+
|
|
27
|
+
// Game: Agent-based play
|
|
28
|
+
game("tictactoe") |> agent_play("competitive", "cooperative")
|
|
29
|
+
game("tictactoe") |> agent_match // Full match to completion
|
|
30
|
+
|
|
31
|
+
// Unified observation
|
|
32
|
+
sudoku(grid) |> as_agent_space |> 調停σ // Same σ for both
|
|
33
|
+
game("tictactoe") |> as_agent_space |> 調停σ
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### v0.5 Agent Runtime
|
|
37
|
+
|
|
38
|
+
v0.5 introduced a **self-organizing agent runtime** — entities perceive, decide, and act autonomously, coordinated by a conflict-resolving mediator.
|
|
39
|
+
|
|
40
|
+
- **EventBus** — Type-safe event-driven architecture with flow momentum tracking
|
|
41
|
+
- **Entity Agent** — Six-attribute autonomous agents (perceive → decide → act cycle)
|
|
42
|
+
- **Mediator** — Concurrent execution engine with conflict detection and resolution strategies
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Install
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm install rei-lang
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Quick Start
|
|
53
|
+
|
|
54
|
+
### As a Library
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { rei } from 'rei-lang';
|
|
58
|
+
|
|
59
|
+
// Multi-dimensional number computation
|
|
60
|
+
rei('let field = 𝕄{5; 1, 2, 3, 4}');
|
|
61
|
+
const result = rei('field |> compute :weighted');
|
|
62
|
+
console.log(result); // 7.5
|
|
63
|
+
|
|
64
|
+
// Define functions with compress
|
|
65
|
+
rei('compress energy(m) = m |> compute :weighted');
|
|
66
|
+
rei('let e = energy(𝕄{0; 10, 20, 30})');
|
|
67
|
+
console.log(rei('e')); // 20
|
|
68
|
+
|
|
69
|
+
// Genesis axiom system
|
|
70
|
+
rei('let g = genesis()');
|
|
71
|
+
rei('g |> forward');
|
|
72
|
+
rei('g |> forward');
|
|
73
|
+
console.log(rei('g.state')); // "line"
|
|
74
|
+
|
|
75
|
+
// Reset state between sessions
|
|
76
|
+
rei.reset();
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Interactive REPL
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npx rei
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
╔══════════════════════════════════════════╗
|
|
87
|
+
║ Rei (0₀式) REPL v0.5.0 ║
|
|
88
|
+
║ D-FUMT Computational Language ║
|
|
89
|
+
╚══════════════════════════════════════════╝
|
|
90
|
+
|
|
91
|
+
零 > 𝕄{5; 1, 2, 3, 4} |> compute :weighted
|
|
92
|
+
7.5
|
|
93
|
+
|
|
94
|
+
零 > compress karma(i, e, r) = i * e * r
|
|
95
|
+
compress karma(i, e, r)
|
|
96
|
+
|
|
97
|
+
零 > karma(0.8, 0.9, 0.7)
|
|
98
|
+
0.504
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Execute a File
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
npx rei program.rei
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Language Features
|
|
110
|
+
|
|
111
|
+
### Multi-Dimensional Numbers (𝕄)
|
|
112
|
+
|
|
113
|
+
The core data structure. A center value with peripheral neighbors, computed in 4 modes:
|
|
114
|
+
|
|
115
|
+
```rei
|
|
116
|
+
let m = 𝕄{5; 1, 2, 3, 4}
|
|
117
|
+
|
|
118
|
+
m |> compute :weighted // center + weighted avg of neighbors
|
|
119
|
+
m |> compute :multiplicative // center × Π(1 + nᵢ)
|
|
120
|
+
m |> compute :harmonic // center + n / Σ(1/|nᵢ|)
|
|
121
|
+
m |> compute :exponential // center × avg(e^nᵢ)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Extended Numbers (拡張数)
|
|
125
|
+
|
|
126
|
+
Numbers with subscript-based dimensional extension:
|
|
127
|
+
|
|
128
|
+
```rei
|
|
129
|
+
let a = 0ooo // 3rd-order extension of zero
|
|
130
|
+
a >> :x >> :x // extend: order 3 → 5
|
|
131
|
+
a << // reduce: order 3 → 2
|
|
132
|
+
a |> valStar // numeric projection: 0.001
|
|
133
|
+
|
|
134
|
+
πooo // π extended to 3rd order
|
|
135
|
+
0₀ // D-FUMT zero symbol
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Compress (関数定義)
|
|
139
|
+
|
|
140
|
+
Functions are defined with `compress` — reflecting D-FUMT's compression philosophy:
|
|
141
|
+
|
|
142
|
+
```rei
|
|
143
|
+
compress distance(x, y) = sqrt(x * x + y * y)
|
|
144
|
+
compress field(c, r) = 𝕄{c; r, r, r, r}
|
|
145
|
+
|
|
146
|
+
distance(3, 4) // 5
|
|
147
|
+
field(10, 2) |> compute :weighted // 12
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Pipe Operator (|>)
|
|
151
|
+
|
|
152
|
+
Center-to-periphery data flow:
|
|
153
|
+
|
|
154
|
+
```rei
|
|
155
|
+
-25 |> abs |> sqrt // 5
|
|
156
|
+
[3, 1, 2] |> sort |> reverse // [3, 2, 1]
|
|
157
|
+
"hello" |> upper // "HELLO"
|
|
158
|
+
𝕄{0; 1, 2, 3} |> normalize // normalized neighbors
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Genesis Axiom System (生成公理系)
|
|
162
|
+
|
|
163
|
+
Models computational emergence from void:
|
|
164
|
+
|
|
165
|
+
```rei
|
|
166
|
+
let g = genesis() // void
|
|
167
|
+
g |> forward // void → dot
|
|
168
|
+
g |> forward // dot → line
|
|
169
|
+
g |> forward // line → surface
|
|
170
|
+
g |> forward // surface → solid
|
|
171
|
+
g |> forward // solid → omega (Ω)
|
|
172
|
+
g.omega // 1
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Four-Valued Logic (四価0π)
|
|
176
|
+
|
|
177
|
+
Beyond true/false — based on D-FUMT Theory #21:
|
|
178
|
+
|
|
179
|
+
```rei
|
|
180
|
+
⊤ // true
|
|
181
|
+
⊥ // false
|
|
182
|
+
⊤π // true-pi (π-rotated truth)
|
|
183
|
+
⊥π // false-pi
|
|
184
|
+
|
|
185
|
+
¬⊤ // ⊥
|
|
186
|
+
⊤ ∧ ⊥ // ⊥
|
|
187
|
+
⊥ ∨ ⊤ // ⊤
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## v0.5 Agent Runtime
|
|
193
|
+
|
|
194
|
+
### EventBus (イベントバス)
|
|
195
|
+
|
|
196
|
+
Type-safe event system with flow momentum tracking. Events follow a `category:action` pattern (e.g., `entity:fuse`, `agent:act`, `space:diffuse`).
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
import { rei, ReiEventBus } from 'rei-lang';
|
|
200
|
+
|
|
201
|
+
// Access via Evaluator
|
|
202
|
+
const ev = rei.evaluator();
|
|
203
|
+
const bus = ev.eventBus;
|
|
204
|
+
|
|
205
|
+
// Subscribe to events
|
|
206
|
+
bus.on('entity:fuse', (event) => {
|
|
207
|
+
console.log('Fusion occurred:', event.data);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// Subscribe with filter
|
|
211
|
+
bus.subscribe(
|
|
212
|
+
(e) => e.category === 'agent',
|
|
213
|
+
(e) => console.log(`Agent ${e.data.agentId}: ${e.action}`)
|
|
214
|
+
);
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
In Rei syntax with pipe commands:
|
|
218
|
+
|
|
219
|
+
```rei
|
|
220
|
+
// Emit a custom event
|
|
221
|
+
"mySource" |> emit("entity:transform", "data")
|
|
222
|
+
|
|
223
|
+
// Subscribe to events
|
|
224
|
+
"entity:*" |> subscribe
|
|
225
|
+
|
|
226
|
+
// Check flow momentum state
|
|
227
|
+
0 |> flow_momentum // → { state: "expanding", rate: 12.5, ... }
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Entity Agent (自律エンティティ)
|
|
231
|
+
|
|
232
|
+
Entities in Rei are autonomous agents with the six D-FUMT attributes (場・流れ・記憶・層・関係・意志), executing a perceive → decide → act lifecycle.
|
|
233
|
+
|
|
234
|
+
```rei
|
|
235
|
+
// Spawn an agent from a value
|
|
236
|
+
let a = 𝕄{10; 1, 2, 3} |> spawn
|
|
237
|
+
|
|
238
|
+
// Agent lifecycle
|
|
239
|
+
a |> perceive // observe environment → Perception
|
|
240
|
+
a |> decide // choose action → Decision
|
|
241
|
+
a |> act // execute decision → ActionResult
|
|
242
|
+
|
|
243
|
+
// Agent introspection
|
|
244
|
+
a |> agent_sigma // σ metadata: state, step, memory, bindings
|
|
245
|
+
a |> 自律σ // 日本語版
|
|
246
|
+
|
|
247
|
+
// Agent behaviors: reactive / proactive / cooperative / competitive / contemplative
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
// Programmatic API
|
|
252
|
+
import { ReiAgent, AgentRegistry } from 'rei-lang';
|
|
253
|
+
|
|
254
|
+
const registry = new AgentRegistry();
|
|
255
|
+
const agent = registry.spawn(42, {
|
|
256
|
+
behavior: 'cooperative',
|
|
257
|
+
autonomyLevel: 0.8,
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
const perception = agent.perceive(registry);
|
|
261
|
+
const decision = agent.decide(perception);
|
|
262
|
+
const result = agent.act(registry, decision);
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Mediator (調停エンジン)
|
|
266
|
+
|
|
267
|
+
The Mediator coordinates multiple agents running concurrently, detecting and resolving conflicts with configurable strategies.
|
|
268
|
+
|
|
269
|
+
```rei
|
|
270
|
+
// Concurrent execution — all agents perceive → decide → resolve conflicts → act
|
|
271
|
+
0 |> mediate // 1 round of concurrent execution
|
|
272
|
+
0 |> mediate(5) // 5 rounds with convergence detection
|
|
273
|
+
0 |> mediate(10, 0.8) // max 10 rounds, convergence threshold 0.8
|
|
274
|
+
|
|
275
|
+
// Strategies: priority / cooperative / sequential / cancel_both / mediator
|
|
276
|
+
0 |> mediate_strategy("cooperative") // 協調 — merge conflicting intentions
|
|
277
|
+
0 |> 調停戦略("協調") // 日本語版
|
|
278
|
+
|
|
279
|
+
// Inter-agent messaging
|
|
280
|
+
"agent_a" |> mediate_message("agent_b", "hello") // point-to-point
|
|
281
|
+
"agent_a" |> mediate_broadcast("共有データ") // broadcast to all
|
|
282
|
+
|
|
283
|
+
// Mediator σ — statistics and convergence history
|
|
284
|
+
0 |> mediator_sigma // → { totalRounds, conflicts, convergenceHistory, ... }
|
|
285
|
+
0 |> 調停σ // 日本語版
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
Conflict types detected automatically: **target contention** (same target), **resource conflict** (shared resource), **mutual fuse** (A↔B fusion), **contradictory** (fuse vs separate).
|
|
289
|
+
|
|
290
|
+
Resolution strategies:
|
|
291
|
+
|
|
292
|
+
| Strategy | Japanese | Behavior |
|
|
293
|
+
|----------|----------|----------|
|
|
294
|
+
| `priority` | 優先 | Highest confidence × priority wins |
|
|
295
|
+
| `cooperative` | 協調 | Merge intentions into compromise |
|
|
296
|
+
| `sequential` | 順次 | Execute in priority order |
|
|
297
|
+
| `cancel_both` | 両方取消 | Cancel conflicting actions |
|
|
298
|
+
| `mediator` | 調停者 | Mediator's own judgment (中道) |
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
// Programmatic API
|
|
302
|
+
import { ReiMediator, AgentRegistry } from 'rei-lang';
|
|
303
|
+
|
|
304
|
+
const registry = new AgentRegistry();
|
|
305
|
+
const mediator = new ReiMediator(registry);
|
|
306
|
+
|
|
307
|
+
// Spawn agents
|
|
308
|
+
registry.spawn(10, { behavior: 'cooperative' });
|
|
309
|
+
registry.spawn(20, { behavior: 'competitive' });
|
|
310
|
+
|
|
311
|
+
// Run concurrent rounds with convergence detection
|
|
312
|
+
const result = mediator.run({
|
|
313
|
+
maxRounds: 10,
|
|
314
|
+
convergenceThreshold: 0.8,
|
|
315
|
+
});
|
|
316
|
+
console.log(result.converged, result.totalRounds);
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## Six Attributes (六属性)
|
|
322
|
+
|
|
323
|
+
Every entity in Rei carries six attributes from D-FUMT theory:
|
|
324
|
+
|
|
325
|
+
| Attribute | Japanese | Role |
|
|
326
|
+
|-----------|----------|------|
|
|
327
|
+
| Field (場) | ば | Spatial context and neighbors |
|
|
328
|
+
| Flow (流れ) | ながれ | Temporal momentum and EventBus connection |
|
|
329
|
+
| Memory (記憶) | きおく | History of observations and actions |
|
|
330
|
+
| Layer (層) | そう | Hierarchical depth and nesting |
|
|
331
|
+
| Relation (関係) | かんけい | Bindings between entities |
|
|
332
|
+
| Will (意志) | いし | Intention-driven computation strategy |
|
|
333
|
+
|
|
334
|
+
```rei
|
|
335
|
+
// Relation binding
|
|
336
|
+
let x = 42
|
|
337
|
+
let y = 100
|
|
338
|
+
x |> bind(y, "collaborator") // create a relation
|
|
339
|
+
|
|
340
|
+
// Will-driven computation
|
|
341
|
+
let m = 𝕄{5; 1, 2, 3}
|
|
342
|
+
m |> intend("maximize") // set intention
|
|
343
|
+
m |> will_compute // compute guided by will
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
348
|
+
## RCT Compression (Rei Compression Theory)
|
|
349
|
+
|
|
350
|
+
D-FUMT Theory #67 — generative compression outperforming gzip on structured data:
|
|
351
|
+
|
|
352
|
+
```rei
|
|
353
|
+
// Core compression (Direction 1-2)
|
|
354
|
+
let data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
|
355
|
+
data |> compress // → compact θ representation
|
|
356
|
+
data |> compress |> decompress // → lossless round-trip
|
|
357
|
+
|
|
358
|
+
// Semantic compression (Direction 3)
|
|
359
|
+
"let x = 𝕄{5; 1, 2, 3}" |> semantic_compress // → θ parameters
|
|
360
|
+
"let x = 𝕄{5; 1, 2, 3}" |> 意味圧縮 // 日本語版
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
---
|
|
364
|
+
|
|
365
|
+
## Benchmarks
|
|
366
|
+
|
|
367
|
+
| Task | Conventional | Rei | Reduction |
|
|
368
|
+
|------|-------------|-----|-----------|
|
|
369
|
+
| Image kernel calculations | 32 lines | 8 lines | **4×** |
|
|
370
|
+
| Multi-dimensional data aggregation | 45 lines | 12 lines | **3.7×** |
|
|
371
|
+
| Graph structure transformation | 52 lines | 14 lines | **3.7×** |
|
|
372
|
+
| **Average** | | | **74%** |
|
|
373
|
+
|
|
374
|
+
---
|
|
375
|
+
|
|
376
|
+
## API Reference
|
|
377
|
+
|
|
378
|
+
### `rei(code: string): ReiValue`
|
|
379
|
+
|
|
380
|
+
Evaluate a string of Rei code. State persists across calls.
|
|
381
|
+
|
|
382
|
+
### `rei.reset(): void`
|
|
383
|
+
|
|
384
|
+
Clear all variable and function bindings.
|
|
385
|
+
|
|
386
|
+
### `rei.evaluator(): Evaluator`
|
|
387
|
+
|
|
388
|
+
Access the underlying Evaluator instance (for EventBus, AgentRegistry, etc.).
|
|
389
|
+
|
|
390
|
+
### Classes
|
|
391
|
+
|
|
392
|
+
| Class | Description |
|
|
393
|
+
|-------|-------------|
|
|
394
|
+
| `Lexer` | Tokenizer |
|
|
395
|
+
| `Parser` | Recursive descent parser |
|
|
396
|
+
| `Evaluator` | AST evaluator with environment/scope chain |
|
|
397
|
+
| `ReiEventBus` | Type-safe event system with flow momentum |
|
|
398
|
+
| `ReiAgent` | Autonomous entity with six attributes |
|
|
399
|
+
| `AgentRegistry` | Agent lifecycle management |
|
|
400
|
+
| `ReiMediator` | Concurrent execution engine with conflict resolution |
|
|
401
|
+
|
|
402
|
+
### Types
|
|
403
|
+
|
|
404
|
+
| Type | Shape |
|
|
405
|
+
|------|-------|
|
|
406
|
+
| `MultiDimNumber` | `{ center, neighbors, mode, weights? }` |
|
|
407
|
+
| `ReiExtended` | `{ base, order, subscripts, valStar() }` |
|
|
408
|
+
| `GenesisState` | `{ state, omega, history }` |
|
|
409
|
+
| `ReiFunction` | `{ name, params, body, closure }` |
|
|
410
|
+
| `Quad` | `{ value: 'top' \| 'bottom' \| 'topPi' \| 'bottomPi' }` |
|
|
411
|
+
| `ReiEvent` | `{ type, category, action, timestamp, data, source?, depth }` |
|
|
412
|
+
| `AgentSigma` | `{ state, kind, behavior, step, perception, decisions, memory }` |
|
|
413
|
+
| `MediatorSigma` | `{ totalRounds, conflicts, convergenceHistory, agentCount }` |
|
|
414
|
+
|
|
415
|
+
---
|
|
416
|
+
|
|
417
|
+
## Bilingual Pipe Commands (日本語対応)
|
|
418
|
+
|
|
419
|
+
All pipe commands have Japanese aliases:
|
|
420
|
+
|
|
421
|
+
| English | 日本語 | Description |
|
|
422
|
+
|---------|--------|-------------|
|
|
423
|
+
| `spawn` | `生成` | Create agent from value |
|
|
424
|
+
| `perceive` | `知覚` | Agent observes environment |
|
|
425
|
+
| `decide` | `判断` | Agent chooses action |
|
|
426
|
+
| `act` | `行動` | Agent executes decision |
|
|
427
|
+
| `agent_sigma` | `自律σ` | Agent metadata |
|
|
428
|
+
| `mediate` | `調停` | Concurrent round execution |
|
|
429
|
+
| `mediate_run` | `調停実行` | Multi-round execution |
|
|
430
|
+
| `mediator_sigma` | `調停σ` | Mediator statistics |
|
|
431
|
+
| `mediate_strategy` | `調停戦略` | Set conflict strategy |
|
|
432
|
+
| `mediate_message` | `調停通信` | Point-to-point message |
|
|
433
|
+
| `mediate_broadcast` | `調停放送` | Broadcast to all agents |
|
|
434
|
+
| `emit` | `発火` | Emit event |
|
|
435
|
+
| `subscribe` | `購読` | Subscribe to events |
|
|
436
|
+
| `bind` | `結合` | Create relation binding |
|
|
437
|
+
| `intend` | `意図` | Set entity intention |
|
|
438
|
+
| `compress` | `圧縮` | RCT compression |
|
|
439
|
+
| `decompress` | `復元` | RCT decompression |
|
|
440
|
+
|
|
441
|
+
---
|
|
442
|
+
|
|
443
|
+
## BNF Specification
|
|
444
|
+
|
|
445
|
+
The complete BNF v0.3 specification is available in [`spec/`](./spec/).
|
|
446
|
+
|
|
447
|
+
---
|
|
448
|
+
|
|
449
|
+
## Theoretical Foundation
|
|
450
|
+
|
|
451
|
+
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.
|
|
452
|
+
|
|
453
|
+
See [`theory/`](./theory/) for the complete theoretical documentation.
|
|
454
|
+
|
|
455
|
+
---
|
|
456
|
+
|
|
457
|
+
## ☮️ Peace Use Clause / 平和利用条項
|
|
458
|
+
|
|
459
|
+
Rei is licensed under Apache 2.0 with an additional Peace Use Clause.
|
|
460
|
+
Rei は Apache 2.0 ライセンスに加え、平和利用条項が適用されます。
|
|
461
|
+
|
|
462
|
+
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:
|
|
463
|
+
仏教の「空」の概念と D-FUMT の意識数学に基づき、Rei は人類の平和的発展のためにのみ設計されています。以下の目的での使用は禁止されています:
|
|
464
|
+
|
|
465
|
+
🚫 Weapons, military systems, or LAWS / 兵器・軍事システム・自律型致死兵器
|
|
466
|
+
🚫 Human rights violations / 人権侵害
|
|
467
|
+
🚫 Intentional environmental destruction / 意図的な環境破壊
|
|
468
|
+
|
|
469
|
+
✅ Education, research, humanitarian aid, and creative endeavors are encouraged.
|
|
470
|
+
✅ 教育・研究・人道支援・創造的活動での使用を推奨します。
|
|
471
|
+
|
|
472
|
+
See [PEACE_USE_CLAUSE.md](./PEACE_USE_CLAUSE.md) for full details.
|
|
473
|
+
|
|
474
|
+
Apache 2.0 © Nobuki Fujimoto
|