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