@nahisaho/musubix-synthesis 2.0.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/README.md +100 -0
- package/dist/dsl/DSL.d.ts +73 -0
- package/dist/dsl/DSL.d.ts.map +1 -0
- package/dist/dsl/DSL.js +250 -0
- package/dist/dsl/DSL.js.map +1 -0
- package/dist/dsl/DSLBuilder.d.ts +33 -0
- package/dist/dsl/DSLBuilder.d.ts.map +1 -0
- package/dist/dsl/DSLBuilder.js +51 -0
- package/dist/dsl/DSLBuilder.js.map +1 -0
- package/dist/dsl/TypeSystem.d.ts +51 -0
- package/dist/dsl/TypeSystem.d.ts.map +1 -0
- package/dist/dsl/TypeSystem.js +253 -0
- package/dist/dsl/TypeSystem.js.map +1 -0
- package/dist/dsl/index.d.ts +8 -0
- package/dist/dsl/index.d.ts.map +1 -0
- package/dist/dsl/index.js +8 -0
- package/dist/dsl/index.js.map +1 -0
- package/dist/errors.d.ts +93 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +142 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/rules/MetaLearner.d.ts +50 -0
- package/dist/rules/MetaLearner.d.ts.map +1 -0
- package/dist/rules/MetaLearner.js +144 -0
- package/dist/rules/MetaLearner.js.map +1 -0
- package/dist/rules/RuleExtractor.d.ts +69 -0
- package/dist/rules/RuleExtractor.d.ts.map +1 -0
- package/dist/rules/RuleExtractor.js +290 -0
- package/dist/rules/RuleExtractor.js.map +1 -0
- package/dist/rules/RuleLibrary.d.ts +55 -0
- package/dist/rules/RuleLibrary.d.ts.map +1 -0
- package/dist/rules/RuleLibrary.js +190 -0
- package/dist/rules/RuleLibrary.js.map +1 -0
- package/dist/rules/index.d.ts +9 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +9 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/synthesis/Enumerator.d.ts +78 -0
- package/dist/synthesis/Enumerator.d.ts.map +1 -0
- package/dist/synthesis/Enumerator.js +292 -0
- package/dist/synthesis/Enumerator.js.map +1 -0
- package/dist/synthesis/PBESynthesizer.d.ts +37 -0
- package/dist/synthesis/PBESynthesizer.d.ts.map +1 -0
- package/dist/synthesis/PBESynthesizer.js +187 -0
- package/dist/synthesis/PBESynthesizer.js.map +1 -0
- package/dist/synthesis/VersionSpace.d.ts +50 -0
- package/dist/synthesis/VersionSpace.d.ts.map +1 -0
- package/dist/synthesis/VersionSpace.js +102 -0
- package/dist/synthesis/VersionSpace.js.map +1 -0
- package/dist/synthesis/WitnessEngine.d.ts +64 -0
- package/dist/synthesis/WitnessEngine.d.ts.map +1 -0
- package/dist/synthesis/WitnessEngine.js +217 -0
- package/dist/synthesis/WitnessEngine.js.map +1 -0
- package/dist/synthesis/index.d.ts +9 -0
- package/dist/synthesis/index.d.ts.map +1 -0
- package/dist/synthesis/index.js +9 -0
- package/dist/synthesis/index.js.map +1 -0
- package/dist/types.d.ts +372 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type System
|
|
3
|
+
* @module @nahisaho/musubix-synthesis
|
|
4
|
+
* @description Type checking and inference for DSL
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Type system implementation
|
|
8
|
+
*/
|
|
9
|
+
export class TypeSystem {
|
|
10
|
+
operators;
|
|
11
|
+
constants;
|
|
12
|
+
constructor(configOrDsl) {
|
|
13
|
+
if ('getOperator' in configOrDsl) {
|
|
14
|
+
// It's an IDSL
|
|
15
|
+
this.operators = configOrDsl.operators;
|
|
16
|
+
this.constants = configOrDsl.constants;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
// It's a DSLConfig
|
|
20
|
+
this.operators = new Map(configOrDsl.operators.map((op) => [op.name, op]));
|
|
21
|
+
this.constants = new Map(configOrDsl.constants.map((c) => [c.name, c]));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Type check a program (returns boolean for simple check)
|
|
26
|
+
*/
|
|
27
|
+
check(program, env) {
|
|
28
|
+
const result = this.checkWithDetails(program, env);
|
|
29
|
+
return result.valid;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Type check a program with full results
|
|
33
|
+
*/
|
|
34
|
+
checkWithDetails(program, env) {
|
|
35
|
+
const errors = [];
|
|
36
|
+
const context = this.normalizeContext(env);
|
|
37
|
+
const inferredType = this.inferExpression(program.expression, context, errors);
|
|
38
|
+
return {
|
|
39
|
+
valid: errors.length === 0,
|
|
40
|
+
inferredType: inferredType ?? undefined,
|
|
41
|
+
errors,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Infer the type of an expression
|
|
46
|
+
*/
|
|
47
|
+
infer(expression, env) {
|
|
48
|
+
const errors = [];
|
|
49
|
+
const context = this.normalizeContext(env);
|
|
50
|
+
return this.inferExpression(expression, context, errors);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Normalize context from Record or TypeContext
|
|
54
|
+
*/
|
|
55
|
+
normalizeContext(env) {
|
|
56
|
+
if (!env) {
|
|
57
|
+
return { variables: new Map() };
|
|
58
|
+
}
|
|
59
|
+
if ('variables' in env && env.variables instanceof Map) {
|
|
60
|
+
return env;
|
|
61
|
+
}
|
|
62
|
+
// It's a Record<string, TypeSignature>
|
|
63
|
+
const variables = new Map();
|
|
64
|
+
for (const [key, value] of Object.entries(env)) {
|
|
65
|
+
variables.set(key, value);
|
|
66
|
+
}
|
|
67
|
+
return { variables };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Unify two types
|
|
71
|
+
*/
|
|
72
|
+
unify(a, b) {
|
|
73
|
+
// Same type
|
|
74
|
+
if (this.typeEquals(a, b))
|
|
75
|
+
return a;
|
|
76
|
+
// Any unifies with anything
|
|
77
|
+
if (a === 'any')
|
|
78
|
+
return b;
|
|
79
|
+
if (b === 'any')
|
|
80
|
+
return a;
|
|
81
|
+
// Numeric subtyping
|
|
82
|
+
if ((a === 'int' && b === 'float') || (a === 'float' && b === 'int')) {
|
|
83
|
+
return 'float';
|
|
84
|
+
}
|
|
85
|
+
// Function types
|
|
86
|
+
if (typeof a === 'object' && typeof b === 'object') {
|
|
87
|
+
if (a.kind === 'function' && b.kind === 'function') {
|
|
88
|
+
if (a.inputs.length !== b.inputs.length)
|
|
89
|
+
return null;
|
|
90
|
+
const unifiedInputs = [];
|
|
91
|
+
for (let i = 0; i < a.inputs.length; i++) {
|
|
92
|
+
const unified = this.unify(a.inputs[i], b.inputs[i]);
|
|
93
|
+
if (!unified)
|
|
94
|
+
return null;
|
|
95
|
+
unifiedInputs.push(unified);
|
|
96
|
+
}
|
|
97
|
+
const unifiedOutput = this.unify(a.output, b.output);
|
|
98
|
+
if (!unifiedOutput)
|
|
99
|
+
return null;
|
|
100
|
+
return { kind: 'function', inputs: unifiedInputs, output: unifiedOutput };
|
|
101
|
+
}
|
|
102
|
+
// Generic types
|
|
103
|
+
if (a.kind === 'generic' || b.kind === 'generic') {
|
|
104
|
+
return a.kind === 'generic' ? b : a;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Check if sub is a subtype of sup
|
|
111
|
+
*/
|
|
112
|
+
isSubtype(sub, sup) {
|
|
113
|
+
// Any is a supertype of everything
|
|
114
|
+
if (sup === 'any')
|
|
115
|
+
return true;
|
|
116
|
+
// Exact match
|
|
117
|
+
if (this.typeEquals(sub, sup))
|
|
118
|
+
return true;
|
|
119
|
+
// Handle function types
|
|
120
|
+
if (typeof sub === 'object' && typeof sup === 'object') {
|
|
121
|
+
if (sub.kind === 'function' && sup.kind === 'function') {
|
|
122
|
+
// Contravariant in inputs, covariant in output
|
|
123
|
+
if (sub.inputs.length !== sup.inputs.length)
|
|
124
|
+
return false;
|
|
125
|
+
// Check inputs (contravariant)
|
|
126
|
+
for (let i = 0; i < sub.inputs.length; i++) {
|
|
127
|
+
if (!this.isSubtype(sup.inputs[i], sub.inputs[i]))
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
// Check output (covariant)
|
|
131
|
+
return this.isSubtype(sub.output, sup.output);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// Numeric subtyping: int <: float
|
|
135
|
+
if (sub === 'int' && sup === 'float')
|
|
136
|
+
return true;
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Check if two types are equal
|
|
141
|
+
*/
|
|
142
|
+
typeEquals(a, b) {
|
|
143
|
+
if (typeof a === 'string' && typeof b === 'string') {
|
|
144
|
+
return a === b;
|
|
145
|
+
}
|
|
146
|
+
if (typeof a === 'object' && typeof b === 'object') {
|
|
147
|
+
if (a.kind !== b.kind)
|
|
148
|
+
return false;
|
|
149
|
+
if (a.kind === 'function' && b.kind === 'function') {
|
|
150
|
+
if (a.inputs.length !== b.inputs.length)
|
|
151
|
+
return false;
|
|
152
|
+
for (let i = 0; i < a.inputs.length; i++) {
|
|
153
|
+
if (!this.typeEquals(a.inputs[i], b.inputs[i]))
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
return this.typeEquals(a.output, b.output);
|
|
157
|
+
}
|
|
158
|
+
if (a.kind === 'generic' && b.kind === 'generic') {
|
|
159
|
+
return a.name === b.name;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Infer expression type with error collection
|
|
166
|
+
*/
|
|
167
|
+
inferExpression(expr, context, errors) {
|
|
168
|
+
switch (expr.kind) {
|
|
169
|
+
case 'constant': {
|
|
170
|
+
const constant = this.constants.get(expr.name);
|
|
171
|
+
if (!constant) {
|
|
172
|
+
errors.push({ message: `Unknown constant: ${expr.name}` });
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
return constant.type;
|
|
176
|
+
}
|
|
177
|
+
case 'variable': {
|
|
178
|
+
if (expr.name === 'input') {
|
|
179
|
+
return 'any'; // Input type is typically any or inferred from context
|
|
180
|
+
}
|
|
181
|
+
const type = context.variables.get(expr.name);
|
|
182
|
+
if (!type) {
|
|
183
|
+
errors.push({ message: `Unknown variable: ${expr.name}` });
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
return type;
|
|
187
|
+
}
|
|
188
|
+
case 'application': {
|
|
189
|
+
const operator = this.operators.get(expr.operator);
|
|
190
|
+
if (!operator) {
|
|
191
|
+
errors.push({ message: `Unknown operator: ${expr.operator}` });
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
// Check argument count
|
|
195
|
+
if (expr.args.length !== operator.inputTypes.length) {
|
|
196
|
+
errors.push({
|
|
197
|
+
message: `Operator ${expr.operator} expects ${operator.inputTypes.length} arguments, got ${expr.args.length}`,
|
|
198
|
+
});
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
// Check argument types
|
|
202
|
+
for (let i = 0; i < expr.args.length; i++) {
|
|
203
|
+
const argType = this.inferExpression(expr.args[i], context, errors);
|
|
204
|
+
if (argType) {
|
|
205
|
+
const expectedType = operator.inputTypes[i];
|
|
206
|
+
if (!this.isSubtype(argType, expectedType)) {
|
|
207
|
+
errors.push({
|
|
208
|
+
message: `Argument ${i} type mismatch`,
|
|
209
|
+
expected: this.typeToString(expectedType),
|
|
210
|
+
actual: this.typeToString(argType),
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return operator.outputType;
|
|
216
|
+
}
|
|
217
|
+
case 'lambda': {
|
|
218
|
+
// Add parameter to context
|
|
219
|
+
const newContext = {
|
|
220
|
+
variables: new Map(context.variables),
|
|
221
|
+
};
|
|
222
|
+
newContext.variables.set(expr.parameter, expr.parameterType);
|
|
223
|
+
// Infer body type
|
|
224
|
+
const bodyType = this.inferExpression(expr.body, newContext, errors);
|
|
225
|
+
if (!bodyType)
|
|
226
|
+
return null;
|
|
227
|
+
return {
|
|
228
|
+
kind: 'function',
|
|
229
|
+
inputs: [expr.parameterType],
|
|
230
|
+
output: bodyType,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
default:
|
|
234
|
+
errors.push({ message: `Unknown expression kind` });
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Convert type to string
|
|
240
|
+
*/
|
|
241
|
+
typeToString(type) {
|
|
242
|
+
if (typeof type === 'string')
|
|
243
|
+
return type;
|
|
244
|
+
if (type.kind === 'function') {
|
|
245
|
+
const inputs = type.inputs.map((t) => this.typeToString(t)).join(', ');
|
|
246
|
+
return `(${inputs}) -> ${this.typeToString(type.output)}`;
|
|
247
|
+
}
|
|
248
|
+
if (type.kind === 'generic')
|
|
249
|
+
return type.name;
|
|
250
|
+
return JSON.stringify(type);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=TypeSystem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeSystem.js","sourceRoot":"","sources":["../../src/dsl/TypeSystem.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAgBH;;GAEG;AACH,MAAM,OAAO,UAAU;IACJ,SAAS,CAAwB;IACjC,SAAS,CAAwB;IAElD,YAAY,WAA6B;QACvC,IAAI,aAAa,IAAI,WAAW,EAAE,CAAC;YACjC,eAAe;YACf,IAAI,CAAC,SAAS,GAAG,WAAW,CAAC,SAAS,CAAC;YACvC,IAAI,CAAC,SAAS,GAAG,WAAW,CAAC,SAAS,CAAC;QACzC,CAAC;aAAM,CAAC;YACN,mBAAmB;YACnB,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,CAAC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;QAC1C,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAC7B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACvE,OAAO,IAAI,MAAM,QAAQ,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5D,CAAC;QACD,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC,IAAI,CAAC;QAC9C,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dsl/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dsl/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Errors for MUSUBIX Synthesis
|
|
3
|
+
* @module @nahisaho/musubix-synthesis
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Base synthesis error
|
|
7
|
+
*/
|
|
8
|
+
export declare class SynthesisError extends Error {
|
|
9
|
+
readonly code: string;
|
|
10
|
+
constructor(message: string, code?: string);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* DSL error
|
|
14
|
+
*/
|
|
15
|
+
export declare class DSLError extends SynthesisError {
|
|
16
|
+
constructor(message: string);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* DSL operator not found
|
|
20
|
+
*/
|
|
21
|
+
export declare class OperatorNotFoundError extends DSLError {
|
|
22
|
+
readonly operatorName: string;
|
|
23
|
+
constructor(operatorName: string);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Type error
|
|
27
|
+
*/
|
|
28
|
+
export declare class TypeError extends SynthesisError {
|
|
29
|
+
readonly expected?: string;
|
|
30
|
+
readonly actual?: string;
|
|
31
|
+
constructor(message: string, expected?: string, actual?: string);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Type mismatch error
|
|
35
|
+
*/
|
|
36
|
+
export declare class TypeMismatchError extends TypeError {
|
|
37
|
+
constructor(expected: string, actual: string);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Synthesis failure error
|
|
41
|
+
*/
|
|
42
|
+
export declare class SynthesisFailureError extends SynthesisError {
|
|
43
|
+
readonly reason: string;
|
|
44
|
+
constructor(reason: string);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Synthesis timeout error
|
|
48
|
+
*/
|
|
49
|
+
export declare class SynthesisTimeoutError extends SynthesisError {
|
|
50
|
+
readonly timeout: number;
|
|
51
|
+
constructor(timeout: number);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Depth exceeded error
|
|
55
|
+
*/
|
|
56
|
+
export declare class DepthExceededError extends SynthesisError {
|
|
57
|
+
readonly maxDepth: number;
|
|
58
|
+
constructor(maxDepth: number);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* No solution error
|
|
62
|
+
*/
|
|
63
|
+
export declare class NoSolutionError extends SynthesisError {
|
|
64
|
+
constructor(message?: string);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Invalid example error
|
|
68
|
+
*/
|
|
69
|
+
export declare class InvalidExampleError extends SynthesisError {
|
|
70
|
+
readonly exampleIndex: number;
|
|
71
|
+
constructor(exampleIndex: number, reason: string);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Rule error
|
|
75
|
+
*/
|
|
76
|
+
export declare class RuleError extends SynthesisError {
|
|
77
|
+
constructor(message: string);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Rule not found error
|
|
81
|
+
*/
|
|
82
|
+
export declare class RuleNotFoundError extends RuleError {
|
|
83
|
+
readonly ruleId: string;
|
|
84
|
+
constructor(ruleId: string);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Execution error
|
|
88
|
+
*/
|
|
89
|
+
export declare class ExecutionError extends SynthesisError {
|
|
90
|
+
readonly program?: string;
|
|
91
|
+
constructor(message: string, program?: string);
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAA0B;CAK9D;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,cAAc;gBAC9B,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,QAAQ;IACjD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;gBAElB,YAAY,EAAE,MAAM;CAKjC;AAED;;GAEG;AACH,qBAAa,SAAU,SAAQ,cAAc;IAC3C,QAAQ,CAAC,QAAQ,CAAC,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ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Errors for MUSUBIX Synthesis
|
|
3
|
+
* @module @nahisaho/musubix-synthesis
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Base synthesis error
|
|
7
|
+
*/
|
|
8
|
+
export class SynthesisError extends Error {
|
|
9
|
+
code;
|
|
10
|
+
constructor(message, code = 'SYNTHESIS_ERROR') {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'SynthesisError';
|
|
13
|
+
this.code = code;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* DSL error
|
|
18
|
+
*/
|
|
19
|
+
export class DSLError extends SynthesisError {
|
|
20
|
+
constructor(message) {
|
|
21
|
+
super(message, 'DSL_ERROR');
|
|
22
|
+
this.name = 'DSLError';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* DSL operator not found
|
|
27
|
+
*/
|
|
28
|
+
export class OperatorNotFoundError extends DSLError {
|
|
29
|
+
operatorName;
|
|
30
|
+
constructor(operatorName) {
|
|
31
|
+
super(`Unknown operator: ${operatorName}`);
|
|
32
|
+
this.name = 'OperatorNotFoundError';
|
|
33
|
+
this.operatorName = operatorName;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Type error
|
|
38
|
+
*/
|
|
39
|
+
export class TypeError extends SynthesisError {
|
|
40
|
+
expected;
|
|
41
|
+
actual;
|
|
42
|
+
constructor(message, expected, actual) {
|
|
43
|
+
super(message, 'TYPE_ERROR');
|
|
44
|
+
this.name = 'TypeError';
|
|
45
|
+
this.expected = expected;
|
|
46
|
+
this.actual = actual;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Type mismatch error
|
|
51
|
+
*/
|
|
52
|
+
export class TypeMismatchError extends TypeError {
|
|
53
|
+
constructor(expected, actual) {
|
|
54
|
+
super(`Type mismatch: expected ${expected}, got ${actual}`, expected, actual);
|
|
55
|
+
this.name = 'TypeMismatchError';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Synthesis failure error
|
|
60
|
+
*/
|
|
61
|
+
export class SynthesisFailureError extends SynthesisError {
|
|
62
|
+
reason;
|
|
63
|
+
constructor(reason) {
|
|
64
|
+
super(`Synthesis failed: ${reason}`, 'SYNTHESIS_FAILURE');
|
|
65
|
+
this.name = 'SynthesisFailureError';
|
|
66
|
+
this.reason = reason;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Synthesis timeout error
|
|
71
|
+
*/
|
|
72
|
+
export class SynthesisTimeoutError extends SynthesisError {
|
|
73
|
+
timeout;
|
|
74
|
+
constructor(timeout) {
|
|
75
|
+
super(`Synthesis timed out after ${timeout}ms`, 'SYNTHESIS_TIMEOUT');
|
|
76
|
+
this.name = 'SynthesisTimeoutError';
|
|
77
|
+
this.timeout = timeout;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Depth exceeded error
|
|
82
|
+
*/
|
|
83
|
+
export class DepthExceededError extends SynthesisError {
|
|
84
|
+
maxDepth;
|
|
85
|
+
constructor(maxDepth) {
|
|
86
|
+
super(`Maximum depth ${maxDepth} exceeded`, 'DEPTH_EXCEEDED');
|
|
87
|
+
this.name = 'DepthExceededError';
|
|
88
|
+
this.maxDepth = maxDepth;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* No solution error
|
|
93
|
+
*/
|
|
94
|
+
export class NoSolutionError extends SynthesisError {
|
|
95
|
+
constructor(message = 'No solution found') {
|
|
96
|
+
super(message, 'NO_SOLUTION');
|
|
97
|
+
this.name = 'NoSolutionError';
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Invalid example error
|
|
102
|
+
*/
|
|
103
|
+
export class InvalidExampleError extends SynthesisError {
|
|
104
|
+
exampleIndex;
|
|
105
|
+
constructor(exampleIndex, reason) {
|
|
106
|
+
super(`Invalid example at index ${exampleIndex}: ${reason}`, 'INVALID_EXAMPLE');
|
|
107
|
+
this.name = 'InvalidExampleError';
|
|
108
|
+
this.exampleIndex = exampleIndex;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Rule error
|
|
113
|
+
*/
|
|
114
|
+
export class RuleError extends SynthesisError {
|
|
115
|
+
constructor(message) {
|
|
116
|
+
super(message, 'RULE_ERROR');
|
|
117
|
+
this.name = 'RuleError';
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Rule not found error
|
|
122
|
+
*/
|
|
123
|
+
export class RuleNotFoundError extends RuleError {
|
|
124
|
+
ruleId;
|
|
125
|
+
constructor(ruleId) {
|
|
126
|
+
super(`Rule not found: ${ruleId}`);
|
|
127
|
+
this.name = 'RuleNotFoundError';
|
|
128
|
+
this.ruleId = ruleId;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Execution error
|
|
133
|
+
*/
|
|
134
|
+
export class ExecutionError extends SynthesisError {
|
|
135
|
+
program;
|
|
136
|
+
constructor(message, program) {
|
|
137
|
+
super(message, 'EXECUTION_ERROR');
|
|
138
|
+
this.name = 'ExecutionError';
|
|
139
|
+
this.program = program;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,IAAI,CAAS;IAEtB,YAAY,OAAe,EAAE,OAAe,iBAAiB;QAC3D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B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;CACF;AAED;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,SAAS;IACrC,MAAM,CAAS;IAExB,YAAY,MAAc;QACxB,KAAK,CAAC,mBAAmB,MAAM,EAAE,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,cAAc;IACvC,OAAO,CAAU;IAE1B,YAAY,OAAe,EAAE,OAAgB;QAC3C,KAAK,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MUSUBIX Synthesis
|
|
3
|
+
* @module @nahisaho/musubix-synthesis
|
|
4
|
+
* @description Program synthesis with DSL and PBE
|
|
5
|
+
*/
|
|
6
|
+
export * from './types.js';
|
|
7
|
+
export * from './errors.js';
|
|
8
|
+
export { DSLBuilder, DSL, TypeSystem, } from './dsl/index.js';
|
|
9
|
+
export { Enumerator, PBESynthesizer, WitnessEngine, VersionSpace, } from './synthesis/index.js';
|
|
10
|
+
export { RuleExtractor, RuleLibrary, MetaLearner, resetRuleIdCounter, } from './rules/index.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,YAAY,CAAC;AAG3B,cAAc,aAAa,CAAC;AAG5B,OAAO,EACL,UAAU,EACV,GAAG,EACH,UAAU,GACX,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,UAAU,EACV,cAAc,EACd,aAAa,EACb,YAAY,GACb,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,aAAa,EACb,WAAW,EACX,WAAW,EACX,kBAAkB,GACnB,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MUSUBIX Synthesis
|
|
3
|
+
* @module @nahisaho/musubix-synthesis
|
|
4
|
+
* @description Program synthesis with DSL and PBE
|
|
5
|
+
*/
|
|
6
|
+
// Types
|
|
7
|
+
export * from './types.js';
|
|
8
|
+
// Errors
|
|
9
|
+
export * from './errors.js';
|
|
10
|
+
// DSL
|
|
11
|
+
export { DSLBuilder, DSL, TypeSystem, } from './dsl/index.js';
|
|
12
|
+
// Synthesis
|
|
13
|
+
export { Enumerator, PBESynthesizer, WitnessEngine, VersionSpace, } from './synthesis/index.js';
|
|
14
|
+
// Rules
|
|
15
|
+
export { RuleExtractor, RuleLibrary, MetaLearner, resetRuleIdCounter, } from './rules/index.js';
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,QAAQ;AACR,cAAc,YAAY,CAAC;AAE3B,SAAS;AACT,cAAc,aAAa,CAAC;AAE5B,MAAM;AACN,OAAO,EACL,UAAU,EACV,GAAG,EACH,UAAU,GACX,MAAM,gBAAgB,CAAC;AAExB,YAAY;AACZ,OAAO,EACL,UAAU,EACV,cAAc,EACd,aAAa,EACb,YAAY,GACb,MAAM,sBAAsB,CAAC;AAE9B,QAAQ;AACR,OAAO,EACL,aAAa,EACb,WAAW,EACX,WAAW,EACX,kBAAkB,GACnB,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Meta Learner
|
|
3
|
+
* @module @nahisaho/musubix-synthesis
|
|
4
|
+
* @description Continuous rule improvement and suggestions
|
|
5
|
+
* Traces to: REQ-SYN-004 (Rule Learning)
|
|
6
|
+
*/
|
|
7
|
+
import type { IMetaLearner, IRuleLibrary, SynthesisResult, SynthesisRule } from '../types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Meta learner implementation
|
|
10
|
+
*/
|
|
11
|
+
export declare class MetaLearner implements IMetaLearner {
|
|
12
|
+
private readonly library;
|
|
13
|
+
private readonly extractor;
|
|
14
|
+
private readonly pendingSuggestions;
|
|
15
|
+
private totalLearned;
|
|
16
|
+
constructor(library: IRuleLibrary);
|
|
17
|
+
/**
|
|
18
|
+
* Learn from synthesis result
|
|
19
|
+
*/
|
|
20
|
+
learn(result: SynthesisResult, usedRules: SynthesisRule[]): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Update confidence for a rule
|
|
23
|
+
*/
|
|
24
|
+
updateConfidence(ruleId: string, success: boolean): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Suggest new rules
|
|
27
|
+
*/
|
|
28
|
+
suggestRules(): Promise<SynthesisRule[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Get total learned count
|
|
31
|
+
*/
|
|
32
|
+
getTotalLearned(): number;
|
|
33
|
+
/**
|
|
34
|
+
* Reset state (for testing)
|
|
35
|
+
*/
|
|
36
|
+
reset(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Check if similar rule exists
|
|
39
|
+
*/
|
|
40
|
+
private hasSimularRule;
|
|
41
|
+
/**
|
|
42
|
+
* Check rule similarity
|
|
43
|
+
*/
|
|
44
|
+
private rulesAreSimilar;
|
|
45
|
+
/**
|
|
46
|
+
* Find generalization opportunities
|
|
47
|
+
*/
|
|
48
|
+
private findGeneralizationOpportunities;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=MetaLearner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MetaLearner.d.ts","sourceRoot":"","sources":["../../src/rules/MetaLearner.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,aAAa,EACd,MAAM,aAAa,CAAC;AAGrB;;GAEG;AACH,qBAAa,WAAY,YAAW,YAAY;IAC9C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IACvC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;IAC1C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAkB;IACrD,OAAO,CAAC,YAAY,CAAS;gBAEjB,OAAO,EAAE,YAAY;IAOjC;;OAEG;IACG,KAAK,CACT,MAAM,EAAE,eAAe,EACvB,SAAS,EAAE,aAAa,EAAE,GACzB,OAAO,CAAC,IAAI,CAAC;IAyBhB;;OAEG;IACG,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvE;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;IAqB9C;;OAEG;IACH,eAAe,IAAI,MAAM;IAIzB;;OAEG;IACH,KAAK,IAAI,IAAI;IAMb;;OAEG;IACH,OAAO,CAAC,cAAc;IAStB;;OAEG;IACH,OAAO,CAAC,eAAe;IAoBvB;;OAEG;IACH,OAAO,CAAC,+BAA+B;CAiCxC"}
|