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
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// Rei (0₀式) — Theory #8–#10 Implementation
|
|
3
|
+
// #8 Contraction Zero Theory (縮小ゼロ理論)
|
|
4
|
+
// #9 Linear Number System Theory (直線数体系理論)
|
|
5
|
+
// #10 Dot Number System Theory (点数体系理論)
|
|
6
|
+
// Author: Nobuki Fujimoto
|
|
7
|
+
// ============================================================
|
|
8
|
+
|
|
9
|
+
import { MultiDimNumber } from '../core/types';
|
|
10
|
+
|
|
11
|
+
// ============================================================
|
|
12
|
+
// #8 Contraction Zero Theory (縮小ゼロ理論)
|
|
13
|
+
// ============================================================
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Dynamic Equilibrium Zero (0̃)
|
|
17
|
+
* The limit point of iterative contraction.
|
|
18
|
+
* Unlike static 0, 0̃ retains structural memory of
|
|
19
|
+
* the contraction path.
|
|
20
|
+
*/
|
|
21
|
+
export interface DynamicEquilibriumZero {
|
|
22
|
+
readonly kind: 'dynamic_zero';
|
|
23
|
+
readonly value: 0;
|
|
24
|
+
readonly contractionDepth: number;
|
|
25
|
+
readonly residualEntropy: number; // Information lost during contraction
|
|
26
|
+
readonly contractionPath: readonly number[]; // History of intermediate values
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Contract a multidimensional number toward zero.
|
|
31
|
+
* Each step: center ← weighted mean of neighbors, neighbors ← contracted.
|
|
32
|
+
* Terminates when |center| + Σ|neighbors| < ε.
|
|
33
|
+
*/
|
|
34
|
+
export function contractToZero(
|
|
35
|
+
md: MultiDimNumber,
|
|
36
|
+
options: { maxSteps?: number; epsilon?: number } = {}
|
|
37
|
+
): { result: DynamicEquilibriumZero; steps: MultiDimNumber[] } {
|
|
38
|
+
const { maxSteps = 1000, epsilon = 1e-12 } = options;
|
|
39
|
+
const steps: MultiDimNumber[] = [md];
|
|
40
|
+
let current = md;
|
|
41
|
+
|
|
42
|
+
for (let i = 0; i < maxSteps; i++) {
|
|
43
|
+
const mean = current.neighbors.reduce((s, n) => s + n, 0) / current.neighbors.length;
|
|
44
|
+
const factor = 1 / (i + 2);
|
|
45
|
+
const newCenter = current.center * factor + mean * (1 - factor) * factor;
|
|
46
|
+
const newNeighbors = current.neighbors.map(n => n * factor);
|
|
47
|
+
|
|
48
|
+
current = {
|
|
49
|
+
center: newCenter,
|
|
50
|
+
neighbors: newNeighbors,
|
|
51
|
+
mode: current.mode,
|
|
52
|
+
};
|
|
53
|
+
steps.push(current);
|
|
54
|
+
|
|
55
|
+
const totalMagnitude = Math.abs(newCenter) + newNeighbors.reduce((s, n) => s + Math.abs(n), 0);
|
|
56
|
+
if (totalMagnitude < epsilon) break;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const residualEntropy = steps.length > 1
|
|
60
|
+
? -steps.slice(1).reduce((s, step) => {
|
|
61
|
+
const total = Math.abs(step.center) + step.neighbors.reduce((a, b) => a + Math.abs(b), 0);
|
|
62
|
+
return s + (total > 0 ? total * Math.log(total + 1e-30) : 0);
|
|
63
|
+
}, 0) / steps.length
|
|
64
|
+
: 0;
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
result: {
|
|
68
|
+
kind: 'dynamic_zero',
|
|
69
|
+
value: 0,
|
|
70
|
+
contractionDepth: steps.length - 1,
|
|
71
|
+
residualEntropy,
|
|
72
|
+
contractionPath: steps.map(s => s.center),
|
|
73
|
+
},
|
|
74
|
+
steps,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Check if a value has reached dynamic equilibrium.
|
|
80
|
+
*/
|
|
81
|
+
export function isDynamicEquilibrium(md: MultiDimNumber, epsilon = 1e-10): boolean {
|
|
82
|
+
const total = Math.abs(md.center) + md.neighbors.reduce((s, n) => s + Math.abs(n), 0);
|
|
83
|
+
return total < epsilon;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Compute the contraction limit of iterative application of a function.
|
|
88
|
+
*/
|
|
89
|
+
export function contractionLimit(
|
|
90
|
+
initial: number,
|
|
91
|
+
fn: (x: number) => number,
|
|
92
|
+
options: { maxSteps?: number; epsilon?: number } = {}
|
|
93
|
+
): { limit: number; steps: number; converged: boolean } {
|
|
94
|
+
const { maxSteps = 10000, epsilon = 1e-12 } = options;
|
|
95
|
+
let current = initial;
|
|
96
|
+
|
|
97
|
+
for (let i = 0; i < maxSteps; i++) {
|
|
98
|
+
const next = fn(current);
|
|
99
|
+
if (Math.abs(next - current) < epsilon) {
|
|
100
|
+
return { limit: next, steps: i + 1, converged: true };
|
|
101
|
+
}
|
|
102
|
+
current = next;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return { limit: current, steps: maxSteps, converged: false };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
// ============================================================
|
|
110
|
+
// #9 Linear Number System Theory (直線数体系理論)
|
|
111
|
+
// ============================================================
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* A linear number: a value on a directed axis with
|
|
115
|
+
* projection and interpolation operations.
|
|
116
|
+
*/
|
|
117
|
+
export interface LinearNumber {
|
|
118
|
+
readonly kind: 'linear';
|
|
119
|
+
readonly value: number;
|
|
120
|
+
readonly axis: 'axial' | 'radial' | 'tangent';
|
|
121
|
+
readonly origin: number; // Reference point on the axis
|
|
122
|
+
readonly direction: 1 | -1;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export type AxisSpec = 'axial' | 'radial' | 'tangent';
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Project a multidimensional number onto a linear axis.
|
|
129
|
+
* - axial: Project onto center → N/S axis
|
|
130
|
+
* - radial: Project onto center → distance axis
|
|
131
|
+
* - tangent: Project onto perpendicular to radial
|
|
132
|
+
*/
|
|
133
|
+
export function project(md: MultiDimNumber, axis: AxisSpec): LinearNumber {
|
|
134
|
+
switch (axis) {
|
|
135
|
+
case 'axial': {
|
|
136
|
+
// N(index 0) - S(index 4) axis
|
|
137
|
+
const n = md.neighbors[0] ?? 0;
|
|
138
|
+
const s = md.neighbors[4] ?? 0;
|
|
139
|
+
return {
|
|
140
|
+
kind: 'linear',
|
|
141
|
+
value: n - s,
|
|
142
|
+
axis: 'axial',
|
|
143
|
+
origin: md.center,
|
|
144
|
+
direction: n >= s ? 1 : -1,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
case 'radial': {
|
|
148
|
+
const avgNeighbor = md.neighbors.reduce((a, b) => a + b, 0) / md.neighbors.length;
|
|
149
|
+
return {
|
|
150
|
+
kind: 'linear',
|
|
151
|
+
value: avgNeighbor - md.center,
|
|
152
|
+
axis: 'radial',
|
|
153
|
+
origin: md.center,
|
|
154
|
+
direction: avgNeighbor >= md.center ? 1 : -1,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
case 'tangent': {
|
|
158
|
+
// E(index 2) - W(index 6) axis (perpendicular to axial)
|
|
159
|
+
const e = md.neighbors[2] ?? 0;
|
|
160
|
+
const w = md.neighbors[6] ?? 0;
|
|
161
|
+
return {
|
|
162
|
+
kind: 'linear',
|
|
163
|
+
value: e - w,
|
|
164
|
+
axis: 'tangent',
|
|
165
|
+
origin: md.center,
|
|
166
|
+
direction: e >= w ? 1 : -1,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Linear interpolation between two linear numbers on the same axis.
|
|
174
|
+
*/
|
|
175
|
+
export function linearInterpolate(a: LinearNumber, b: LinearNumber, t: number): LinearNumber {
|
|
176
|
+
if (a.axis !== b.axis) {
|
|
177
|
+
throw new Error(`Cannot interpolate between different axes: ${a.axis} vs ${b.axis}`);
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
kind: 'linear',
|
|
181
|
+
value: a.value * (1 - t) + b.value * t,
|
|
182
|
+
axis: a.axis,
|
|
183
|
+
origin: a.origin * (1 - t) + b.origin * t,
|
|
184
|
+
direction: t < 0.5 ? a.direction : b.direction,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Check duality between linear and spiral projections.
|
|
190
|
+
* Linear is the "unrolled" spiral (curvature → 0 limit).
|
|
191
|
+
*/
|
|
192
|
+
export function linearSpiralDual(linear: LinearNumber): {
|
|
193
|
+
spiralRadius: number;
|
|
194
|
+
spiralAngle: number;
|
|
195
|
+
} {
|
|
196
|
+
return {
|
|
197
|
+
spiralRadius: Math.abs(linear.value),
|
|
198
|
+
spiralAngle: linear.direction === 1 ? 0 : Math.PI,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
// ============================================================
|
|
204
|
+
// #10 Dot Number System Theory (点数体系理論)
|
|
205
|
+
// ============================================================
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* A Dot (・): the most primitive mathematical entity.
|
|
209
|
+
* Pre-numeric: before 0₀, before 0, before any number.
|
|
210
|
+
* Dots combine to form simplices, which generate numbers.
|
|
211
|
+
*/
|
|
212
|
+
export interface Dot {
|
|
213
|
+
readonly kind: 'dot';
|
|
214
|
+
readonly id: number;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export interface DotCombination {
|
|
218
|
+
readonly kind: 'dot_combination';
|
|
219
|
+
readonly dots: readonly Dot[];
|
|
220
|
+
readonly shape: 'point' | 'line' | 'triangle' | 'tetrahedron' | 'simplex';
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
let _dotCounter = 0;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Create a new unique dot.
|
|
227
|
+
*/
|
|
228
|
+
export function dot(): Dot {
|
|
229
|
+
return { kind: 'dot', id: _dotCounter++ };
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Combine dots: ・⊕・⊕・ = △
|
|
234
|
+
*/
|
|
235
|
+
export function dotMerge(...dots: Dot[]): DotCombination {
|
|
236
|
+
const shapeMap: Record<number, DotCombination['shape']> = {
|
|
237
|
+
1: 'point',
|
|
238
|
+
2: 'line',
|
|
239
|
+
3: 'triangle',
|
|
240
|
+
4: 'tetrahedron',
|
|
241
|
+
};
|
|
242
|
+
return {
|
|
243
|
+
kind: 'dot_combination',
|
|
244
|
+
dots,
|
|
245
|
+
shape: shapeMap[dots.length] ?? 'simplex',
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Convert a number into dots (decomposition to primitive level).
|
|
251
|
+
* n → n dots combined.
|
|
252
|
+
*/
|
|
253
|
+
export function toDots(n: number): DotCombination {
|
|
254
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
255
|
+
throw new Error('toDots requires a non-negative integer');
|
|
256
|
+
}
|
|
257
|
+
const dots = Array.from({ length: n }, () => dot());
|
|
258
|
+
return dotMerge(...dots);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Convert dots back to a number.
|
|
263
|
+
*/
|
|
264
|
+
export function fromDots(combination: DotCombination): number {
|
|
265
|
+
return combination.dots.length;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Generate Genesis sequence from dots:
|
|
270
|
+
* ・ → 0₀ → 0 → ℕ
|
|
271
|
+
*/
|
|
272
|
+
export function dotGenesis(): {
|
|
273
|
+
void_state: null;
|
|
274
|
+
dot_state: Dot;
|
|
275
|
+
zero_zero: { base: 0; subscript: 'o' };
|
|
276
|
+
zero: 0;
|
|
277
|
+
} {
|
|
278
|
+
return {
|
|
279
|
+
void_state: null,
|
|
280
|
+
dot_state: dot(),
|
|
281
|
+
zero_zero: { base: 0, subscript: 'o' },
|
|
282
|
+
zero: 0,
|
|
283
|
+
};
|
|
284
|
+
}
|