@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.
Files changed (66) hide show
  1. package/README.md +100 -0
  2. package/dist/dsl/DSL.d.ts +73 -0
  3. package/dist/dsl/DSL.d.ts.map +1 -0
  4. package/dist/dsl/DSL.js +250 -0
  5. package/dist/dsl/DSL.js.map +1 -0
  6. package/dist/dsl/DSLBuilder.d.ts +33 -0
  7. package/dist/dsl/DSLBuilder.d.ts.map +1 -0
  8. package/dist/dsl/DSLBuilder.js +51 -0
  9. package/dist/dsl/DSLBuilder.js.map +1 -0
  10. package/dist/dsl/TypeSystem.d.ts +51 -0
  11. package/dist/dsl/TypeSystem.d.ts.map +1 -0
  12. package/dist/dsl/TypeSystem.js +253 -0
  13. package/dist/dsl/TypeSystem.js.map +1 -0
  14. package/dist/dsl/index.d.ts +8 -0
  15. package/dist/dsl/index.d.ts.map +1 -0
  16. package/dist/dsl/index.js +8 -0
  17. package/dist/dsl/index.js.map +1 -0
  18. package/dist/errors.d.ts +93 -0
  19. package/dist/errors.d.ts.map +1 -0
  20. package/dist/errors.js +142 -0
  21. package/dist/errors.js.map +1 -0
  22. package/dist/index.d.ts +11 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +16 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/rules/MetaLearner.d.ts +50 -0
  27. package/dist/rules/MetaLearner.d.ts.map +1 -0
  28. package/dist/rules/MetaLearner.js +144 -0
  29. package/dist/rules/MetaLearner.js.map +1 -0
  30. package/dist/rules/RuleExtractor.d.ts +69 -0
  31. package/dist/rules/RuleExtractor.d.ts.map +1 -0
  32. package/dist/rules/RuleExtractor.js +290 -0
  33. package/dist/rules/RuleExtractor.js.map +1 -0
  34. package/dist/rules/RuleLibrary.d.ts +55 -0
  35. package/dist/rules/RuleLibrary.d.ts.map +1 -0
  36. package/dist/rules/RuleLibrary.js +190 -0
  37. package/dist/rules/RuleLibrary.js.map +1 -0
  38. package/dist/rules/index.d.ts +9 -0
  39. package/dist/rules/index.d.ts.map +1 -0
  40. package/dist/rules/index.js +9 -0
  41. package/dist/rules/index.js.map +1 -0
  42. package/dist/synthesis/Enumerator.d.ts +78 -0
  43. package/dist/synthesis/Enumerator.d.ts.map +1 -0
  44. package/dist/synthesis/Enumerator.js +292 -0
  45. package/dist/synthesis/Enumerator.js.map +1 -0
  46. package/dist/synthesis/PBESynthesizer.d.ts +37 -0
  47. package/dist/synthesis/PBESynthesizer.d.ts.map +1 -0
  48. package/dist/synthesis/PBESynthesizer.js +187 -0
  49. package/dist/synthesis/PBESynthesizer.js.map +1 -0
  50. package/dist/synthesis/VersionSpace.d.ts +50 -0
  51. package/dist/synthesis/VersionSpace.d.ts.map +1 -0
  52. package/dist/synthesis/VersionSpace.js +102 -0
  53. package/dist/synthesis/VersionSpace.js.map +1 -0
  54. package/dist/synthesis/WitnessEngine.d.ts +64 -0
  55. package/dist/synthesis/WitnessEngine.d.ts.map +1 -0
  56. package/dist/synthesis/WitnessEngine.js +217 -0
  57. package/dist/synthesis/WitnessEngine.js.map +1 -0
  58. package/dist/synthesis/index.d.ts +9 -0
  59. package/dist/synthesis/index.d.ts.map +1 -0
  60. package/dist/synthesis/index.js +9 -0
  61. package/dist/synthesis/index.js.map +1 -0
  62. package/dist/types.d.ts +372 -0
  63. package/dist/types.d.ts.map +1 -0
  64. package/dist/types.js +7 -0
  65. package/dist/types.js.map +1 -0
  66. package/package.json +52 -0
@@ -0,0 +1,190 @@
1
+ /**
2
+ * Rule Library
3
+ * @module @nahisaho/musubix-synthesis
4
+ * @description Storage and retrieval of synthesis rules
5
+ * Traces to: REQ-SYN-004 (Rule Learning)
6
+ */
7
+ /**
8
+ * Rule library implementation
9
+ */
10
+ export class RuleLibrary {
11
+ rules;
12
+ constructor() {
13
+ this.rules = new Map();
14
+ }
15
+ /**
16
+ * Add a rule to the library
17
+ */
18
+ async add(rule) {
19
+ this.rules.set(rule.id, rule);
20
+ }
21
+ /**
22
+ * Get a rule by ID
23
+ */
24
+ async get(id) {
25
+ return this.rules.get(id) ?? null;
26
+ }
27
+ /**
28
+ * Match rules against specification
29
+ */
30
+ async match(spec) {
31
+ const matches = [];
32
+ for (const rule of this.rules.values()) {
33
+ if (this.ruleMatchesSpec(rule, spec)) {
34
+ matches.push(rule);
35
+ }
36
+ }
37
+ // Sort by confidence (descending)
38
+ matches.sort((a, b) => b.confidence - a.confidence);
39
+ return matches;
40
+ }
41
+ /**
42
+ * Record rule usage
43
+ */
44
+ async recordUsage(ruleId, success) {
45
+ const rule = this.rules.get(ruleId);
46
+ if (!rule)
47
+ return;
48
+ const currentUsage = rule.usageCount ?? 0;
49
+ const currentSuccess = rule.successCount ?? 0;
50
+ // Update mutable copy
51
+ const updated = {
52
+ ...rule,
53
+ usageCount: currentUsage + 1,
54
+ successCount: currentSuccess + (success ? 1 : 0),
55
+ confidence: this.calculateConfidence(currentUsage + 1, currentSuccess + (success ? 1 : 0)),
56
+ };
57
+ this.rules.set(ruleId, updated);
58
+ }
59
+ /**
60
+ * Calculate confidence from usage statistics
61
+ */
62
+ calculateConfidence(usageCount, successCount) {
63
+ // Bayesian update with prior of 0.5
64
+ // Add smoothing to avoid extreme values
65
+ const alpha = successCount + 1;
66
+ const beta = (usageCount - successCount) + 1;
67
+ return alpha / (alpha + beta);
68
+ }
69
+ /**
70
+ * Prune low-confidence rules
71
+ */
72
+ async prune(threshold) {
73
+ let pruned = 0;
74
+ const toDelete = [];
75
+ for (const [id, rule] of this.rules) {
76
+ // Prune if confidence is below threshold
77
+ // Only require high usage count if usageCount is defined and > 0
78
+ const usageCount = rule.usageCount ?? 0;
79
+ const shouldPrune = rule.confidence < threshold && (usageCount === 0 || usageCount > 10);
80
+ if (shouldPrune) {
81
+ toDelete.push(id);
82
+ pruned++;
83
+ }
84
+ }
85
+ for (const id of toDelete) {
86
+ this.rules.delete(id);
87
+ }
88
+ return pruned;
89
+ }
90
+ /**
91
+ * Get all rules
92
+ */
93
+ async getAll() {
94
+ return Array.from(this.rules.values());
95
+ }
96
+ /**
97
+ * Check if rule matches spec
98
+ */
99
+ ruleMatchesSpec(rule, spec) {
100
+ const pattern = rule.pattern;
101
+ // Check inputCount if specified
102
+ if (pattern.inputCount !== undefined) {
103
+ const firstInput = spec.examples[0]?.input;
104
+ const specInputCount = typeof firstInput === 'object' && firstInput !== null
105
+ ? Object.keys(firstInput).length
106
+ : 0;
107
+ if (pattern.inputCount !== specInputCount) {
108
+ return false;
109
+ }
110
+ }
111
+ // Check exampleCount if specified
112
+ if (pattern.exampleCount !== undefined) {
113
+ if (pattern.exampleCount !== spec.examples.length) {
114
+ return false;
115
+ }
116
+ }
117
+ // Check type constraints
118
+ if (pattern.typeConstraints && spec.inputType) {
119
+ const [inputType, outputType] = pattern.typeConstraints;
120
+ if (inputType !== 'any' && inputType !== spec.inputType) {
121
+ return false;
122
+ }
123
+ if (outputType !== 'any' && spec.outputType && outputType !== spec.outputType) {
124
+ return false;
125
+ }
126
+ }
127
+ // Check input/output patterns
128
+ if (pattern.inputPattern) {
129
+ if (!this.valueMatchesPattern(spec.examples[0]?.input, pattern.inputPattern)) {
130
+ return false;
131
+ }
132
+ }
133
+ if (pattern.outputPattern) {
134
+ if (!this.valueMatchesPattern(spec.examples[0]?.output, pattern.outputPattern)) {
135
+ return false;
136
+ }
137
+ }
138
+ return true;
139
+ }
140
+ /**
141
+ * Check if value matches pattern
142
+ */
143
+ valueMatchesPattern(value, pattern) {
144
+ if (pattern === undefined || pattern === null)
145
+ return true;
146
+ if (typeof pattern === 'object' && pattern !== null) {
147
+ const p = pattern;
148
+ // Type pattern
149
+ if ('type' in p) {
150
+ return typeof value === p.type;
151
+ }
152
+ // Prefix/suffix pattern for strings
153
+ if ('prefix' in p || 'suffix' in p) {
154
+ if (typeof value !== 'string')
155
+ return false;
156
+ if (p.prefix && !value.startsWith(p.prefix))
157
+ return false;
158
+ if (p.suffix && !value.endsWith(p.suffix))
159
+ return false;
160
+ return true;
161
+ }
162
+ // Array length pattern
163
+ if ('arrayLength' in p) {
164
+ if (!Array.isArray(value))
165
+ return false;
166
+ return value.length === p.arrayLength;
167
+ }
168
+ // Any of pattern
169
+ if ('anyOf' in p) {
170
+ const anyOf = p.anyOf;
171
+ return anyOf.some((v) => this.valuesEqual(value, v));
172
+ }
173
+ }
174
+ return this.valuesEqual(value, pattern);
175
+ }
176
+ /**
177
+ * Value equality
178
+ */
179
+ valuesEqual(a, b) {
180
+ if (a === b)
181
+ return true;
182
+ if (typeof a !== typeof b)
183
+ return false;
184
+ if (typeof a === 'object' && a !== null && b !== null) {
185
+ return JSON.stringify(a) === JSON.stringify(b);
186
+ }
187
+ return false;
188
+ }
189
+ }
190
+ //# sourceMappingURL=RuleLibrary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RuleLibrary.js","sourceRoot":"","sources":["../../src/rules/RuleLibrary.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;GAEG;AACH,MAAM,OAAO,WAAW;IACd,KAAK,CAA6B;IAE1C;QACE,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG,CAAC,IAAmB;QAC3B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG,CAAC,EAAU;QAClB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK,CAAC,IAAmB;QAC7B,MAAM,OAAO,GAAoB,EAAE,CAAC;QAEpC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;YACvC,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,C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W,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;YACvD,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED;;OAEG;IACK,WAAW,CAAC,CAAU,EAAE,CAAU;QACxC,IAAI,CAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACzB,IAAI,OAAO,CAAC,KAAK,OAAO,CAAC;YAAE,OAAO,KAAK,CAAC;QACxC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;YACtD,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACjD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Rules module
3
+ * @module @nahisaho/musubix-synthesis/rules
4
+ * @description Rule extraction, storage, and meta-learning
5
+ */
6
+ export { RuleExtractor, resetRuleIdCounter } from './RuleExtractor.js';
7
+ export { RuleLibrary } from './RuleLibrary.js';
8
+ export { MetaLearner } from './MetaLearner.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Rules module
3
+ * @module @nahisaho/musubix-synthesis/rules
4
+ * @description Rule extraction, storage, and meta-learning
5
+ */
6
+ export { RuleExtractor, resetRuleIdCounter } from './RuleExtractor.js';
7
+ export { RuleLibrary } from './RuleLibrary.js';
8
+ export { MetaLearner } from './MetaLearner.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Enumerator
3
+ * @module @nahisaho/musubix-synthesis
4
+ * @description Exhaustive program enumeration
5
+ */
6
+ import type { EnumerationOptions, Expression, IDSL, IEnumerator, Program, Specification, TypeSignature } from '../types.js';
7
+ /**
8
+ * Reset ID counter (for testing)
9
+ */
10
+ export declare function resetProgramIdCounter(): void;
11
+ /**
12
+ * Enumeration options for sync enumerate
13
+ */
14
+ export interface EnumerateOptions {
15
+ maxDepth: number;
16
+ maxPrograms?: number;
17
+ targetType?: TypeSignature;
18
+ }
19
+ /**
20
+ * Enumerator implementation
21
+ */
22
+ export declare class Enumerator implements IEnumerator {
23
+ private readonly dsl;
24
+ constructor(dsl: IDSL);
25
+ /**
26
+ * Enumerate programs synchronously
27
+ */
28
+ enumerate(options: EnumerateOptions): Program[];
29
+ /**
30
+ * Enumerate expressions at a given depth
31
+ */
32
+ enumerateExpressions(depth: number): Expression[];
33
+ /**
34
+ * Get the depth of an expression
35
+ */
36
+ getExpressionDepth(expr: Expression): number;
37
+ /**
38
+ * Count programs at a given depth
39
+ */
40
+ countPrograms(depth: number): number;
41
+ /**
42
+ * Enumerate all programs up to given depth/cost (async generator)
43
+ */
44
+ enumerateAsync(options: EnumerationOptions): AsyncGenerator<Program, void, unknown>;
45
+ /**
46
+ * Enumerate programs that might satisfy the spec
47
+ */
48
+ enumerateForSpec(spec: Specification, options: EnumerationOptions): AsyncGenerator<Program, void, unknown>;
49
+ /**
50
+ * Enumerate expressions at a specific depth (sync)
51
+ */
52
+ private enumerateAtDepthSync;
53
+ /**
54
+ * Enumerate arguments at exactly a specific depth (for avoiding duplicates)
55
+ */
56
+ private enumerateArgumentsAtDepth;
57
+ /**
58
+ * Enumerate all combinations of arguments for an operator
59
+ */
60
+ private enumerateArguments;
61
+ /**
62
+ * Check if types match
63
+ */
64
+ private typeMatches;
65
+ /**
66
+ * Compute expression cost
67
+ */
68
+ private computeExpressionCost;
69
+ /**
70
+ * Quick check if program might satisfy examples
71
+ */
72
+ private mightSatisfyExamples;
73
+ /**
74
+ * Check value equality
75
+ */
76
+ private valuesEqual;
77
+ }
78
+ //# sourceMappingURL=Enumerator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Enumerator.d.ts","sourceRoot":"","sources":["../../src/synthesis/Enumerator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAElB,UAAU,EACV,IAAI,EACJ,WAAW,EACX,OAAO,EACP,aAAa,EACb,aAAa,EACd,MAAM,aAAa,CAAC;AAUrB;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,aAAa,CAAC;CAC5B;AAED;;GAEG;AACH,qBAAa,UAAW,YAAW,WAAW;IAC5C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAO;gBAEf,GAAG,EAAE,IAAI;IAIrB;;OAEG;IACH,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,EAAE;IA6B/C;;OAEG;IACH,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,EAAE;IAIjD;;OAEG;IACH,kBAAkB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM;IAiB5C;;OAEG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAUpC;;OAEG;IACI,cAAc,CACnB,OAAO,EAAE,kBAAkB,GAC1B,cAAc,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC;IAiBzC;;OAEG;IACI,gBAAgB,CACrB,IAAI,EAAE,aAAa,EACnB,OAAO,EAAE,kBAAkB,GAC1B,cAAc,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC;IA6BzC;;OAEG;IACH,OAAO,CAAE,oBAAoB;IAgD7B;;OAEG;IACH,OAAO,CAAE,yBAAyB;IA2BlC;;OAEG;IACH,OAAO,CAAE,kBAAkB;IA+B3B;;OAEG;IACH,OAAO,CAAC,WAAW;IAQnB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAsB7B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAW5B;;OAEG;IACH,OAAO,CAAC,WAAW;CAYpB"}
@@ -0,0 +1,292 @@
1
+ /**
2
+ * Enumerator
3
+ * @module @nahisaho/musubix-synthesis
4
+ * @description Exhaustive program enumeration
5
+ */
6
+ /**
7
+ * Generate unique IDs
8
+ */
9
+ let programIdCounter = 0;
10
+ function generateProgramId() {
11
+ return `prog-${++programIdCounter}`;
12
+ }
13
+ /**
14
+ * Reset ID counter (for testing)
15
+ */
16
+ export function resetProgramIdCounter() {
17
+ programIdCounter = 0;
18
+ }
19
+ /**
20
+ * Enumerator implementation
21
+ */
22
+ export class Enumerator {
23
+ dsl;
24
+ constructor(dsl) {
25
+ this.dsl = dsl;
26
+ }
27
+ /**
28
+ * Enumerate programs synchronously
29
+ */
30
+ enumerate(options) {
31
+ const { maxDepth, maxPrograms, targetType } = options;
32
+ const programs = [];
33
+ const seen = new Set();
34
+ for (let depth = 0; depth <= maxDepth; depth++) {
35
+ for (const expr of this.enumerateAtDepthSync(depth, targetType)) {
36
+ if (maxPrograms && programs.length >= maxPrograms) {
37
+ return programs;
38
+ }
39
+ // Avoid duplicates
40
+ const serialized = JSON.stringify(expr);
41
+ if (seen.has(serialized)) {
42
+ continue;
43
+ }
44
+ seen.add(serialized);
45
+ programs.push({
46
+ id: generateProgramId(),
47
+ expression: expr,
48
+ cost: this.computeExpressionCost(expr),
49
+ });
50
+ }
51
+ }
52
+ return programs;
53
+ }
54
+ /**
55
+ * Enumerate expressions at a given depth
56
+ */
57
+ enumerateExpressions(depth) {
58
+ return Array.from(this.enumerateAtDepthSync(depth));
59
+ }
60
+ /**
61
+ * Get the depth of an expression
62
+ */
63
+ getExpressionDepth(expr) {
64
+ switch (expr.kind) {
65
+ case 'constant':
66
+ case 'variable':
67
+ return 0;
68
+ case 'application':
69
+ if (expr.args.length === 0) {
70
+ return 1;
71
+ }
72
+ return 1 + Math.max(...expr.args.map((a) => this.getExpressionDepth(a)));
73
+ case 'lambda':
74
+ return 1 + this.getExpressionDepth(expr.body);
75
+ default:
76
+ return 0;
77
+ }
78
+ }
79
+ /**
80
+ * Count programs at a given depth
81
+ */
82
+ countPrograms(depth) {
83
+ let count = 0;
84
+ for (let d = 0; d <= depth; d++) {
85
+ for (const _ of this.enumerateAtDepthSync(d)) {
86
+ count++;
87
+ }
88
+ }
89
+ return count;
90
+ }
91
+ /**
92
+ * Enumerate all programs up to given depth/cost (async generator)
93
+ */
94
+ async *enumerateAsync(options) {
95
+ const { maxDepth, maxCost = Infinity, targetType } = options;
96
+ for (let depth = 0; depth <= maxDepth; depth++) {
97
+ for (const expr of this.enumerateAtDepthSync(depth, targetType)) {
98
+ const cost = this.computeExpressionCost(expr);
99
+ if (cost <= maxCost) {
100
+ yield {
101
+ id: generateProgramId(),
102
+ expression: expr,
103
+ cost,
104
+ };
105
+ }
106
+ }
107
+ }
108
+ }
109
+ /**
110
+ * Enumerate programs that might satisfy the spec
111
+ */
112
+ async *enumerateForSpec(spec, options) {
113
+ const { maxDepth, maxCost = Infinity, yieldInterval = 100 } = options;
114
+ const targetType = spec.outputType;
115
+ let count = 0;
116
+ for (let depth = 0; depth <= maxDepth; depth++) {
117
+ for (const expr of this.enumerateAtDepthSync(depth, targetType)) {
118
+ const cost = this.computeExpressionCost(expr);
119
+ if (cost <= maxCost) {
120
+ const program = {
121
+ id: generateProgramId(),
122
+ expression: expr,
123
+ cost,
124
+ };
125
+ // Check if program satisfies any examples (early filter)
126
+ if (this.mightSatisfyExamples(program, spec.examples)) {
127
+ yield program;
128
+ }
129
+ count++;
130
+ if (count % yieldInterval === 0) {
131
+ await new Promise((r) => setTimeout(r, 0));
132
+ }
133
+ }
134
+ }
135
+ }
136
+ }
137
+ /**
138
+ * Enumerate expressions at a specific depth (sync)
139
+ */
140
+ *enumerateAtDepthSync(depth, targetType) {
141
+ if (depth === 0) {
142
+ // Constants only at depth 0
143
+ for (const [, constant] of this.dsl.constants) {
144
+ if (!targetType || this.typeMatches(constant.type, targetType)) {
145
+ yield { kind: 'constant', name: constant.name };
146
+ }
147
+ }
148
+ }
149
+ else if (depth === 1) {
150
+ // At depth 1: input variables + operator applications with depth-0 args
151
+ // Input variable is included at depth 1 since it requires one level of complexity
152
+ yield { kind: 'variable', name: 'input' };
153
+ // Applications of operators with depth-0 arguments
154
+ for (const [, operator] of this.dsl.operators) {
155
+ if (targetType && !this.typeMatches(operator.outputType, targetType)) {
156
+ continue;
157
+ }
158
+ // Generate all combinations of arguments with depth 0 (constants only)
159
+ for (const args of this.enumerateArgumentsAtDepth(operator.inputTypes, 0)) {
160
+ yield { kind: 'application', operator: operator.name, args };
161
+ }
162
+ }
163
+ }
164
+ else {
165
+ // Applications of operators at depth > 1
166
+ for (const [, operator] of this.dsl.operators) {
167
+ if (targetType && !this.typeMatches(operator.outputType, targetType)) {
168
+ continue;
169
+ }
170
+ // Generate all combinations of arguments
171
+ for (const args of this.enumerateArguments(operator.inputTypes, depth - 1)) {
172
+ yield { kind: 'application', operator: operator.name, args };
173
+ }
174
+ }
175
+ }
176
+ }
177
+ /**
178
+ * Enumerate arguments at exactly a specific depth (for avoiding duplicates)
179
+ */
180
+ *enumerateArgumentsAtDepth(inputTypes, exactDepth) {
181
+ if (inputTypes.length === 0) {
182
+ yield [];
183
+ return;
184
+ }
185
+ if (inputTypes.length === 1) {
186
+ for (const expr of this.enumerateAtDepthSync(exactDepth, inputTypes[0])) {
187
+ yield [expr];
188
+ }
189
+ return;
190
+ }
191
+ // For multiple arguments, enumerate combinations at same depth
192
+ const firstType = inputTypes[0];
193
+ const restTypes = inputTypes.slice(1);
194
+ for (const firstExpr of this.enumerateAtDepthSync(exactDepth, firstType)) {
195
+ for (const restExprs of this.enumerateArgumentsAtDepth(restTypes, exactDepth)) {
196
+ yield [firstExpr, ...restExprs];
197
+ }
198
+ }
199
+ }
200
+ /**
201
+ * Enumerate all combinations of arguments for an operator
202
+ */
203
+ *enumerateArguments(inputTypes, maxArgDepth) {
204
+ if (inputTypes.length === 0) {
205
+ yield [];
206
+ return;
207
+ }
208
+ if (inputTypes.length === 1) {
209
+ for (let d = 0; d <= maxArgDepth; d++) {
210
+ for (const expr of this.enumerateAtDepthSync(d, inputTypes[0])) {
211
+ yield [expr];
212
+ }
213
+ }
214
+ return;
215
+ }
216
+ // For multiple arguments, enumerate combinations
217
+ const firstType = inputTypes[0];
218
+ const restTypes = inputTypes.slice(1);
219
+ for (let d = 0; d <= maxArgDepth; d++) {
220
+ for (const firstExpr of this.enumerateAtDepthSync(d, firstType)) {
221
+ for (const restExprs of this.enumerateArguments(restTypes, maxArgDepth)) {
222
+ yield [firstExpr, ...restExprs];
223
+ }
224
+ }
225
+ }
226
+ }
227
+ /**
228
+ * Check if types match
229
+ */
230
+ typeMatches(actual, expected) {
231
+ if (expected === 'any')
232
+ return true;
233
+ if (typeof actual === 'string' && typeof expected === 'string') {
234
+ return actual === expected;
235
+ }
236
+ return false;
237
+ }
238
+ /**
239
+ * Compute expression cost
240
+ */
241
+ computeExpressionCost(expr) {
242
+ switch (expr.kind) {
243
+ case 'constant':
244
+ return 1;
245
+ case 'variable':
246
+ return 1;
247
+ case 'application': {
248
+ const operator = this.dsl.getOperator(expr.operator);
249
+ const opCost = operator?.cost ?? 1;
250
+ const argsCost = expr.args.reduce((sum, arg) => sum + this.computeExpressionCost(arg), 0);
251
+ return opCost + argsCost;
252
+ }
253
+ case 'lambda':
254
+ return 1 + this.computeExpressionCost(expr.body);
255
+ default:
256
+ return 1;
257
+ }
258
+ }
259
+ /**
260
+ * Quick check if program might satisfy examples
261
+ */
262
+ mightSatisfyExamples(program, examples) {
263
+ if (examples.length === 0)
264
+ return true;
265
+ try {
266
+ const result = this.dsl.execute(program, examples[0].input);
267
+ return this.valuesEqual(result, examples[0].output);
268
+ }
269
+ catch {
270
+ return false;
271
+ }
272
+ }
273
+ /**
274
+ * Check value equality
275
+ */
276
+ valuesEqual(a, b) {
277
+ if (a === b)
278
+ return true;
279
+ if (typeof a !== typeof b)
280
+ return false;
281
+ if (Array.isArray(a) && Array.isArray(b)) {
282
+ if (a.length !== b.length)
283
+ return false;
284
+ return a.every((v, i) => this.valuesEqual(v, b[i]));
285
+ }
286
+ if (typeof a === 'object' && a !== null && b !== null) {
287
+ return JSON.stringify(a) === JSON.stringify(b);
288
+ }
289
+ return false;
290
+ }
291
+ }
292
+ //# sourceMappingURL=Enumerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Enumerator.js","sourceRoot":"","sources":["../../src/synthesis/Enumerator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAaH;;GAEG;AACH,IAAI,gBAAgB,GAAG,CAAC,CAAC;AACzB,SAAS,iBAAiB;IACxB,OAAO,QAAQ,EAAE,gBAAgB,EAAE,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACnC,gBAAgB,GAAG,CAAC,CAAC;AACvB,CAAC;AAWD;;GAEG;AACH,MAAM,OAAO,UAAU;IACJ,GAAG,CAAO;IAE3B,YAAY,GAAS;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,OAAyB;QACjC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AAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;YACzC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;gBAAE,OAAO,KAAK,CAAC;YACxC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACtD,CAAC;QACD,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;YACtD,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACjD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * PBE Synthesizer
3
+ * @module @nahisaho/musubix-synthesis
4
+ * @description Programming by Example synthesizer
5
+ * Traces to: REQ-SYN-003 (PBE Synthesis)
6
+ */
7
+ import type { Example, IDSL, IPBESynthesizer, Program, Specification, SynthesisOptions, SynthesisResult } from '../types.js';
8
+ /**
9
+ * PBE Synthesizer implementation
10
+ */
11
+ export declare class PBESynthesizer implements IPBESynthesizer {
12
+ private searchNodes;
13
+ private pruned;
14
+ private lastDsl;
15
+ constructor();
16
+ /**
17
+ * Synthesize a program from specification
18
+ */
19
+ synthesize(spec: Specification, dsl: IDSL, options?: SynthesisOptions): Promise<SynthesisResult>;
20
+ /**
21
+ * Get candidates from last synthesis
22
+ */
23
+ getCandidates(spec: Specification, dsl: IDSL, limit?: number): Program[];
24
+ /**
25
+ * Disambiguate candidates with additional example
26
+ */
27
+ disambiguate(candidates: Program[], example: Example): Program[];
28
+ /**
29
+ * Check if program satisfies all examples
30
+ */
31
+ private satisfiesAllExamples;
32
+ /**
33
+ * Check value equality
34
+ */
35
+ private valuesEqual;
36
+ }
37
+ //# sourceMappingURL=PBESynthesizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PBESynthesizer.d.ts","sourceRoot":"","sources":["../../src/synthesis/PBESynthesizer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,OAAO,EACP,IAAI,EACJ,eAAe,EACf,OAAO,EACP,aAAa,EACb,gBAAgB,EAChB,eAAe,EAChB,MAAM,aAAa,CAAC;AAgBrB;;GAEG;AACH,qBAAa,cAAe,YAAW,eAAe;IACpD,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAc;;IAQ7B;;OAEG;IACG,UAAU,CACd,IAAI,EAAE,aAAa,EACnB,GAAG,EAAE,IAAI,EACT,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,eAAe,CAAC;IAyF3B;;OAEG;IACH,aAAa,CAAC,IAAI,EAAE,aAAa,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,EAAE;IAkBxE;;OAEG;IACH,YAAY,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,EAAE;IAahE;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAkB5B;;OAEG;IACH,OAAO,CAAC,WAAW;CAYpB"}