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.
Files changed (40) hide show
  1. package/LICENSE +230 -191
  2. package/PEACE_USE_CLAUSE.md +95 -0
  3. package/README.md +257 -186
  4. package/bin/rei.js +259 -144
  5. package/dist/index.d.mts +257 -0
  6. package/dist/index.d.ts +181 -93
  7. package/dist/index.js +5710 -239
  8. package/dist/index.js.map +1 -1
  9. package/dist/index.mjs +8741 -0
  10. package/dist/index.mjs.map +1 -0
  11. package/package.json +73 -62
  12. package/spec/REI_BNF_v0.2.md +398 -0
  13. package/spec/REI_BNF_v0.3.md +358 -0
  14. package/spec/REI_SPEC_v0.1.md +587 -0
  15. package/theory/LICENSE-THEORY.md +57 -0
  16. package/theory/README.md +85 -0
  17. package/theory/category-c-design.md +502 -0
  18. package/theory/core-theories-11-14.md +799 -0
  19. package/theory/core-theories-15-21.md +675 -0
  20. package/theory/core-theories-8-10.md +582 -0
  21. package/theory/d-fumt-overview.md +99 -0
  22. package/theory/genesis-axiom-system.md +124 -0
  23. package/theory/gft-theory.md +160 -0
  24. package/theory/index.ts +9 -0
  25. package/theory/notation-equivalence.md +134 -0
  26. package/theory/semantic-compressor.ts +903 -0
  27. package/theory/stdlib-tier1-design.md +477 -0
  28. package/theory/theories-11-14.ts +466 -0
  29. package/theory/theories-15-21.ts +762 -0
  30. package/theory/theories-22-28.ts +794 -0
  31. package/theory/theories-29-35.ts +607 -0
  32. package/theory/theories-36-42.ts +937 -0
  33. package/theory/theories-43-49.ts +1298 -0
  34. package/theory/theories-50-56.ts +1449 -0
  35. package/theory/theories-57-66.ts +1724 -0
  36. package/theory/theories-67.ts +1696 -0
  37. package/theory/theories-8-10.ts +284 -0
  38. package/dist/index.cjs +0 -3282
  39. package/dist/index.cjs.map +0 -1
  40. package/dist/index.d.cts +0 -169
package/dist/index.d.ts CHANGED
@@ -1,72 +1,106 @@
1
- declare const TokenType: Record<string, string>;
2
- interface Token {
3
- type: string;
4
- value: string;
5
- line: number;
6
- col: number;
1
+ /** 結合モード */
2
+ type BindingMode = 'mirror' | 'inverse' | 'resonance' | 'entangle' | 'causal';
3
+ /** 伝播規則 */
4
+ interface PropagationRule {
5
+ type: 'immediate' | 'delayed' | 'attenuated';
6
+ delay: number;
7
+ attenuation: number;
7
8
  }
8
- declare class Lexer {
9
- private source;
10
- private chars;
11
- private pos;
12
- private line;
13
- private col;
14
- private tokens;
15
- constructor(source: string);
16
- tokenize(): Token[];
17
- private skipWhitespaceAndComments;
18
- private readString;
19
- private isExtStart;
20
- private readExtLit;
21
- private readNumber;
22
- private readUnicodeToken;
23
- private readMultiCharOp;
24
- private readSingleCharOp;
25
- private readIdentOrKeyword;
26
- private advance;
27
- private peek;
28
- private emit;
29
- private isDigit;
30
- private isIdentStart;
31
- private isIdentPart;
32
- private shouldNegateBePrefix;
9
+ /** 結合イベント 記憶属性との統合 */
10
+ interface BindingEvent {
11
+ step: number;
12
+ type: 'created' | 'propagated' | 'broken' | 'strengthened' | 'weakened';
13
+ sourceValue: any;
14
+ targetValue: any;
15
+ delta: number;
33
16
  }
34
-
35
- declare class Parser {
36
- private pos;
37
- private tokens;
38
- constructor(tokens: Token[]);
39
- parseProgram(): any;
40
- private parseStatement;
41
- private parseLetStmt;
42
- private parseCompressDef;
43
- private parseCompressLevel;
44
- private parseParamDecl;
45
- private parseExpression;
46
- private parsePipe;
47
- private parsePipeCommand;
48
- private parseLogicOr;
49
- private parseLogicAnd;
50
- private parseComparison;
51
- private parseAddition;
52
- private parseMultiplication;
53
- private parseExtendReduce;
54
- private parseUnary;
55
- private parsePostfix;
56
- private parsePrimary;
57
- private parseMDimLit;
58
- private parseSpaceLit;
59
- private parseIfExpr;
60
- private parseMatchExpr;
61
- private peek;
62
- private isAtEnd;
63
- private check;
64
- private checkAhead;
65
- private advance;
66
- private match;
67
- private expect;
68
- private error;
69
- private shouldNegateBePrefix;
17
+ /** 結合(Binding)— 2つの値の非局所的な関係 */
18
+ interface ReiBinding {
19
+ id: string;
20
+ sourceRef: string;
21
+ targetRef: string;
22
+ mode: BindingMode;
23
+ strength: number;
24
+ propagation: PropagationRule;
25
+ bidirectional: boolean;
26
+ active: boolean;
27
+ history: BindingEvent[];
28
+ createdAt: number;
29
+ }
30
+ /** 結合の要約(σ.relation に含める用) */
31
+ interface BindingSummary {
32
+ id: string;
33
+ target: string;
34
+ mode: BindingMode;
35
+ strength: number;
36
+ active: boolean;
37
+ propagationCount: number;
38
+ }
39
+ /**
40
+ * 結合レジストリ — 全結合を管理し、伝播を実行する
41
+ *
42
+ * Evaluator内に1つのインスタンスを保持する。
43
+ * 変数への代入(Environment.set)時に propagate() が呼ばれ、
44
+ * 結合先に変更が自動的に伝播する。
45
+ */
46
+ declare class BindingRegistry {
47
+ private bindings;
48
+ private refIndex;
49
+ private globalStep;
50
+ private _propagating;
51
+ /**
52
+ * 2つの変数参照を結合する
53
+ *
54
+ * @param sourceRef 結合元の変数名
55
+ * @param targetRef 結合先の変数名
56
+ * @param mode 結合モード
57
+ * @param strength 結合の強さ (0.0~1.0)
58
+ * @param bidirectional 双方向結合にするか
59
+ * @param propagation 伝播規則
60
+ * @returns 作成された結合
61
+ */
62
+ bind(sourceRef: string, targetRef: string, mode?: BindingMode, strength?: number, bidirectional?: boolean, propagation?: PropagationRule): ReiBinding;
63
+ /**
64
+ * 変数の値が変化したとき、結合先に変更を伝播する
65
+ *
66
+ * @param changedRef 変更された変数名
67
+ * @param newValue 新しい値
68
+ * @param getValue 変数の値を取得する関数
69
+ * @param setValue 変数の値を設定する関数
70
+ * @returns 伝播された結合の数
71
+ */
72
+ propagate(changedRef: string, newValue: any, getValue: (ref: string) => any, setValue: (ref: string, value: any) => void): number;
73
+ private computePropagatedValue;
74
+ /**
75
+ * 2つの変数間の結合を解除する
76
+ */
77
+ unbind(sourceRef: string, targetRef: string): boolean;
78
+ /**
79
+ * 変数に関連する全結合を解除する
80
+ */
81
+ unbindAll(ref: string): number;
82
+ /**
83
+ * 変数に関連する全結合の要約を返す
84
+ */
85
+ getBindingsFor(ref: string): BindingSummary[];
86
+ /**
87
+ * 全結合を返す
88
+ */
89
+ getAllBindings(): ReiBinding[];
90
+ /**
91
+ * アクティブな結合の数を返す
92
+ */
93
+ get activeCount(): number;
94
+ /**
95
+ * レジストリをリセットする
96
+ */
97
+ reset(): void;
98
+ /**
99
+ * 変数のσ.relation情報を構築する
100
+ */
101
+ buildRelationSigma(ref: string): any[];
102
+ private findBinding;
103
+ private addToIndex;
70
104
  }
71
105
 
72
106
  interface SigmaMetadata {
@@ -93,6 +127,7 @@ declare class Environment {
93
127
  }
94
128
  declare class Evaluator {
95
129
  env: Environment;
130
+ bindingRegistry: BindingRegistry;
96
131
  constructor(parent?: Environment);
97
132
  private registerBuiltins;
98
133
  eval(ast: any): any;
@@ -131,39 +166,92 @@ declare class Evaluator {
131
166
  isSpace(v: any): boolean;
132
167
  isDNode(v: any): boolean;
133
168
  isReiVal(v: any): boolean;
169
+ isStringMDim(v: any): boolean;
134
170
  /** 値からσメタデータを取得(Tier 1) */
135
171
  getSigmaMetadata(v: any): SigmaMetadata;
136
172
  /** ReiValを透過的にアンラップ */
137
173
  unwrap(v: any): any;
174
+ /** 値からその変数名を逆引きする(参照一致) */
175
+ findRefByValue(value: any): string | null;
176
+ /** 結合の伝播をトリガーする(変数名 + 新値) */
177
+ triggerPropagation(ref: string, newValue: any): number;
138
178
  }
139
179
 
140
- /**
141
- * Evaluate Rei code and return the result.
142
- *
143
- * @example
144
- * ```typescript
145
- * import { rei } from 'rei-lang';
146
- *
147
- * // Basic computation
148
- * rei('𝕄{5; 1, 2, 3} |> compute'); // 7
149
- *
150
- * // Sigma self-reference (C1)
151
- * rei('42 |> sigma'); // { reiType: "SigmaResult", ... }
152
- *
153
- * // Consciousness axioms
154
- * rei('𝕄{5; 1, 2, 3} |> awareness'); // awakening score
155
- * rei('𝕄{5; 1, 2, 3} |> consensus'); // multi-mode consensus
156
- *
157
- * // Encode/Decode (U5 completeness)
158
- * rei('[1, 2, 3] |> encode |> compute'); // encode anything to 𝕄
159
- * ```
160
- */
161
- declare function rei(code: string): any;
162
- declare namespace rei {
180
+ interface Token {
181
+ type: string;
182
+ value: string;
183
+ line: number;
184
+ col: number;
185
+ }
186
+ declare class Lexer {
187
+ private source;
188
+ private chars;
189
+ private pos;
190
+ private line;
191
+ private col;
192
+ private tokens;
193
+ constructor(source: string);
194
+ tokenize(): Token[];
195
+ private skipWhitespaceAndComments;
196
+ private readString;
197
+ private isExtStart;
198
+ private readExtLit;
199
+ private readNumber;
200
+ private readUnicodeToken;
201
+ private readMultiCharOp;
202
+ private readSingleCharOp;
203
+ private readIdentOrKeyword;
204
+ private advance;
205
+ private peek;
206
+ private emit;
207
+ private isDigit;
208
+ private isIdentStart;
209
+ private isIdentPart;
210
+ private shouldNegateBePrefix;
211
+ }
212
+
213
+ declare class Parser {
214
+ private pos;
215
+ private tokens;
216
+ constructor(tokens: Token[]);
217
+ parseProgram(): any;
218
+ private parseStatement;
219
+ private parseLetStmt;
220
+ private parseCompressDef;
221
+ private parseCompressLevel;
222
+ private parseParamDecl;
223
+ private parseExpression;
224
+ private parsePipe;
225
+ private parsePipeCommand;
226
+ private parseLogicOr;
227
+ private parseLogicAnd;
228
+ private parseComparison;
229
+ private parseAddition;
230
+ private parseMultiplication;
231
+ private parseExtendReduce;
232
+ private parseUnary;
233
+ private parsePostfix;
234
+ private parsePrimary;
235
+ private parseMDimLit;
236
+ private parseSpaceLit;
237
+ private parseIfExpr;
238
+ private parseMatchExpr;
239
+ private peek;
240
+ private isAtEnd;
241
+ private check;
242
+ private checkAhead;
243
+ private advance;
244
+ private match;
245
+ private expect;
246
+ private error;
247
+ private shouldNegateBePrefix;
248
+ }
249
+
250
+ declare function reiFn(source: string): any;
251
+ declare namespace reiFn {
163
252
  var reset: () => void;
164
253
  var evaluator: () => Evaluator;
165
- var parse: (code: string) => any;
166
- var tokenize: (code: string) => Token[];
167
254
  }
255
+ declare const rei: typeof reiFn;
168
256
 
169
- export { Environment, Evaluator, Lexer, Parser, type Token, TokenType, rei };
257
+ export { Evaluator, Lexer, Parser, rei };