@stevenvo780/st-lang 4.4.0 → 4.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 +78 -37
- package/dist/coinduction/index.d.ts +136 -0
- package/dist/coinduction/index.d.ts.map +1 -0
- package/dist/coinduction/index.js +318 -0
- package/dist/coinduction/index.js.map +1 -0
- package/dist/combinators-ski/abstract.d.ts +5 -0
- package/dist/combinators-ski/abstract.d.ts.map +1 -0
- package/dist/combinators-ski/abstract.js +88 -0
- package/dist/combinators-ski/abstract.js.map +1 -0
- package/dist/combinators-ski/index.d.ts +6 -0
- package/dist/combinators-ski/index.d.ts.map +1 -0
- package/dist/combinators-ski/index.js +30 -0
- package/dist/combinators-ski/index.js.map +1 -0
- package/dist/combinators-ski/reduce.d.ts +10 -0
- package/dist/combinators-ski/reduce.d.ts.map +1 -0
- package/dist/combinators-ski/reduce.js +118 -0
- package/dist/combinators-ski/reduce.js.map +1 -0
- package/dist/combinators-ski/types.d.ts +23 -0
- package/dist/combinators-ski/types.d.ts.map +1 -0
- package/dist/combinators-ski/types.js +102 -0
- package/dist/combinators-ski/types.js.map +1 -0
- package/dist/constructive-reals/index.d.ts +132 -0
- package/dist/constructive-reals/index.d.ts.map +1 -0
- package/dist/constructive-reals/index.js +723 -0
- package/dist/constructive-reals/index.js.map +1 -0
- package/dist/game-semantics/convert.d.ts +4 -0
- package/dist/game-semantics/convert.d.ts.map +1 -0
- package/dist/game-semantics/convert.js +28 -0
- package/dist/game-semantics/convert.js.map +1 -0
- package/dist/game-semantics/index.d.ts +6 -0
- package/dist/game-semantics/index.d.ts.map +1 -0
- package/dist/game-semantics/index.js +28 -0
- package/dist/game-semantics/index.js.map +1 -0
- package/dist/game-semantics/strategy.d.ts +34 -0
- package/dist/game-semantics/strategy.d.ts.map +1 -0
- package/dist/game-semantics/strategy.js +336 -0
- package/dist/game-semantics/strategy.js.map +1 -0
- package/dist/game-semantics/types.d.ts +64 -0
- package/dist/game-semantics/types.d.ts.map +1 -0
- package/dist/game-semantics/types.js +78 -0
- package/dist/game-semantics/types.js.map +1 -0
- package/dist/higher-order-unify/index.d.ts +5 -0
- package/dist/higher-order-unify/index.d.ts.map +1 -0
- package/dist/higher-order-unify/index.js +27 -0
- package/dist/higher-order-unify/index.js.map +1 -0
- package/dist/higher-order-unify/normalize.d.ts +14 -0
- package/dist/higher-order-unify/normalize.d.ts.map +1 -0
- package/dist/higher-order-unify/normalize.js +191 -0
- package/dist/higher-order-unify/normalize.js.map +1 -0
- package/dist/higher-order-unify/pattern.d.ts +4 -0
- package/dist/higher-order-unify/pattern.d.ts.map +1 -0
- package/dist/higher-order-unify/pattern.js +70 -0
- package/dist/higher-order-unify/pattern.js.map +1 -0
- package/dist/higher-order-unify/types.d.ts +19 -0
- package/dist/higher-order-unify/types.d.ts.map +1 -0
- package/dist/higher-order-unify/types.js +14 -0
- package/dist/higher-order-unify/types.js.map +1 -0
- package/dist/higher-order-unify/unify.d.ts +5 -0
- package/dist/higher-order-unify/unify.d.ts.map +1 -0
- package/dist/higher-order-unify/unify.js +306 -0
- package/dist/higher-order-unify/unify.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -1
- package/dist/index.js.map +1 -1
- package/dist/nbe/index.d.ts +3 -0
- package/dist/nbe/index.d.ts.map +1 -0
- package/dist/nbe/index.js +25 -0
- package/dist/nbe/index.js.map +1 -0
- package/dist/nbe/nbe.d.ts +7 -0
- package/dist/nbe/nbe.d.ts.map +1 -0
- package/dist/nbe/nbe.js +118 -0
- package/dist/nbe/nbe.js.map +1 -0
- package/dist/nbe/types.d.ts +54 -0
- package/dist/nbe/types.d.ts.map +1 -0
- package/dist/nbe/types.js +117 -0
- package/dist/nbe/types.js.map +1 -0
- package/dist/profile-bridge/index.d.ts +64 -0
- package/dist/profile-bridge/index.d.ts.map +1 -0
- package/dist/profile-bridge/index.js +328 -0
- package/dist/profile-bridge/index.js.map +1 -0
- package/dist/proof-nets/construct.d.ts +3 -0
- package/dist/proof-nets/construct.d.ts.map +1 -0
- package/dist/proof-nets/construct.js +85 -0
- package/dist/proof-nets/construct.js.map +1 -0
- package/dist/proof-nets/correctness.d.ts +3 -0
- package/dist/proof-nets/correctness.d.ts.map +1 -0
- package/dist/proof-nets/correctness.js +213 -0
- package/dist/proof-nets/correctness.js.map +1 -0
- package/dist/proof-nets/cut-elim.d.ts +9 -0
- package/dist/proof-nets/cut-elim.d.ts.map +1 -0
- package/dist/proof-nets/cut-elim.js +149 -0
- package/dist/proof-nets/cut-elim.js.map +1 -0
- package/dist/proof-nets/index.d.ts +6 -0
- package/dist/proof-nets/index.d.ts.map +1 -0
- package/dist/proof-nets/index.js +33 -0
- package/dist/proof-nets/index.js.map +1 -0
- package/dist/proof-nets/types.d.ts +36 -0
- package/dist/proof-nets/types.d.ts.map +1 -0
- package/dist/proof-nets/types.js +89 -0
- package/dist/proof-nets/types.js.map +1 -0
- package/dist/tableau-framework/TableauProver.d.ts +10 -0
- package/dist/tableau-framework/TableauProver.d.ts.map +1 -0
- package/dist/tableau-framework/TableauProver.js +118 -0
- package/dist/tableau-framework/TableauProver.js.map +1 -0
- package/dist/tableau-framework/index.d.ts +5 -0
- package/dist/tableau-framework/index.d.ts.map +1 -0
- package/dist/tableau-framework/index.js +11 -0
- package/dist/tableau-framework/index.js.map +1 -0
- package/dist/tableau-framework/propositional.d.ts +11 -0
- package/dist/tableau-framework/propositional.d.ts.map +1 -0
- package/dist/tableau-framework/propositional.js +143 -0
- package/dist/tableau-framework/propositional.js.map +1 -0
- package/dist/tableau-framework/types.d.ts +32 -0
- package/dist/tableau-framework/types.d.ts.map +1 -0
- package/dist/tableau-framework/types.js +6 -0
- package/dist/tableau-framework/types.js.map +1 -0
- package/dist/tests/coinduction/coinduction.test.d.ts +2 -0
- package/dist/tests/coinduction/coinduction.test.d.ts.map +1 -0
- package/dist/tests/coinduction/coinduction.test.js +217 -0
- package/dist/tests/coinduction/coinduction.test.js.map +1 -0
- package/dist/tests/combinators-ski/combinators-ski.test.d.ts +2 -0
- package/dist/tests/combinators-ski/combinators-ski.test.d.ts.map +1 -0
- package/dist/tests/combinators-ski/combinators-ski.test.js +211 -0
- package/dist/tests/combinators-ski/combinators-ski.test.js.map +1 -0
- package/dist/tests/constructive-reals/constructive-reals.test.d.ts +2 -0
- package/dist/tests/constructive-reals/constructive-reals.test.d.ts.map +1 -0
- package/dist/tests/constructive-reals/constructive-reals.test.js +357 -0
- package/dist/tests/constructive-reals/constructive-reals.test.js.map +1 -0
- package/dist/tests/game-semantics/game-semantics.test.d.ts +2 -0
- package/dist/tests/game-semantics/game-semantics.test.d.ts.map +1 -0
- package/dist/tests/game-semantics/game-semantics.test.js +143 -0
- package/dist/tests/game-semantics/game-semantics.test.js.map +1 -0
- package/dist/tests/higher-order-unify/ho-unify.test.d.ts +2 -0
- package/dist/tests/higher-order-unify/ho-unify.test.d.ts.map +1 -0
- package/dist/tests/higher-order-unify/ho-unify.test.js +264 -0
- package/dist/tests/higher-order-unify/ho-unify.test.js.map +1 -0
- package/dist/tests/integration/cross-modules.test.d.ts +8 -0
- package/dist/tests/integration/cross-modules.test.d.ts.map +1 -0
- package/dist/tests/integration/cross-modules.test.js +668 -0
- package/dist/tests/integration/cross-modules.test.js.map +1 -0
- package/dist/tests/nbe/nbe.test.d.ts +2 -0
- package/dist/tests/nbe/nbe.test.d.ts.map +1 -0
- package/dist/tests/nbe/nbe.test.js +121 -0
- package/dist/tests/nbe/nbe.test.js.map +1 -0
- package/dist/tests/profile-bridge/translations.test.d.ts +2 -0
- package/dist/tests/profile-bridge/translations.test.d.ts.map +1 -0
- package/dist/tests/profile-bridge/translations.test.js +266 -0
- package/dist/tests/profile-bridge/translations.test.js.map +1 -0
- package/dist/tests/proof-nets/proof-nets.test.d.ts +2 -0
- package/dist/tests/proof-nets/proof-nets.test.d.ts.map +1 -0
- package/dist/tests/proof-nets/proof-nets.test.js +263 -0
- package/dist/tests/proof-nets/proof-nets.test.js.map +1 -0
- package/dist/tests/tableau-framework/tableau.test.d.ts +2 -0
- package/dist/tests/tableau-framework/tableau.test.d.ts.map +1 -0
- package/dist/tests/tableau-framework/tableau.test.js +196 -0
- package/dist/tests/tableau-framework/tableau.test.js.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// Bracket abstraction: λ-cálculo → SKI
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// Algoritmo clásico de Curry para eliminar λ-abstracciones, traducido
|
|
7
|
+
// como `lambda x . T ≡ [x] T` con las reglas:
|
|
8
|
+
//
|
|
9
|
+
// [x] x = I
|
|
10
|
+
// [x] M = K M si x ∉ FV(M)
|
|
11
|
+
// [x] (M N) = S ([x] M) ([x] N)
|
|
12
|
+
//
|
|
13
|
+
// Es el llamado "algoritmo (abc)" — simple, no optimizado: produce
|
|
14
|
+
// términos grandes pero correctos. Hay variantes que aprovechan
|
|
15
|
+
// patrones como `[x] (M x) = M` (η) o introducen B, C, W, T, K' para
|
|
16
|
+
// reducir tamaño; aquí elegimos la canónica por claridad pedagógica.
|
|
17
|
+
//
|
|
18
|
+
// `toLambda` hace el camino inverso: codifica S, K, I como las
|
|
19
|
+
// λ-abstracciones que los definen. No pretende invertir
|
|
20
|
+
// `abstractFromLambda` exactamente — el round-trip es semántico
|
|
21
|
+
// (alpha/beta-eta equivalente), no sintáctico.
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.abstractFromLambda = abstractFromLambda;
|
|
24
|
+
exports.toLambda = toLambda;
|
|
25
|
+
const types_1 = require("../lambda-calc/types");
|
|
26
|
+
const types_2 = require("./types");
|
|
27
|
+
// Convierte un λ-término a SKI puro (sólo S, K, I y variables libres).
|
|
28
|
+
function abstractFromLambda(t) {
|
|
29
|
+
switch (t.kind) {
|
|
30
|
+
case 'var':
|
|
31
|
+
return (0, types_2.cvar)(t.name);
|
|
32
|
+
case 'app':
|
|
33
|
+
return { kind: 'app', fn: abstractFromLambda(t.fn), arg: abstractFromLambda(t.arg) };
|
|
34
|
+
case 'abs': {
|
|
35
|
+
// [param] body
|
|
36
|
+
const inner = abstractFromLambda(t.body);
|
|
37
|
+
return bracket(t.param, inner);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// [x] T con T ya en SKI.
|
|
42
|
+
function bracket(x, t) {
|
|
43
|
+
// [x] x = I
|
|
44
|
+
if (t.kind === 'var' && t.name === x)
|
|
45
|
+
return (0, types_2.I)();
|
|
46
|
+
// [x] M = K M si x ∉ FV(M)
|
|
47
|
+
if (!(0, types_2.freeVars)(t).has(x))
|
|
48
|
+
return (0, types_2.app)((0, types_2.K)(), t);
|
|
49
|
+
// En este punto t es necesariamente una aplicación: si fuese una
|
|
50
|
+
// constante S/K/I no tendría FV, y si fuese `var` su nombre ≠ x ya
|
|
51
|
+
// habría caído en la rama K. Mantengo el switch para que TS
|
|
52
|
+
// narrowee y queden cubiertas las ramas restantes.
|
|
53
|
+
switch (t.kind) {
|
|
54
|
+
case 'app':
|
|
55
|
+
// [x] (M N) = S ([x] M) ([x] N)
|
|
56
|
+
return (0, types_2.app)((0, types_2.S)(), bracket(x, t.fn), bracket(x, t.arg));
|
|
57
|
+
case 'var':
|
|
58
|
+
case 'S':
|
|
59
|
+
case 'K':
|
|
60
|
+
case 'I':
|
|
61
|
+
// Inalcanzable por las guardas previas; reproducimos K-rule
|
|
62
|
+
// por defensa para no caer en undefined.
|
|
63
|
+
return (0, types_2.app)((0, types_2.K)(), t);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// SKI → λ-cálculo. Codifica S, K, I como sus definiciones lambda
|
|
67
|
+
// canónicas y deja las variables libres como variables. Útil para
|
|
68
|
+
// round-trip: el resultado, normalizado en λ, debe ser
|
|
69
|
+
// alpha-equivalente al término original aplicado a los mismos
|
|
70
|
+
// argumentos (la equivalencia es semántica, no sintáctica).
|
|
71
|
+
function toLambda(c) {
|
|
72
|
+
switch (c.kind) {
|
|
73
|
+
case 'I':
|
|
74
|
+
// I = λx.x
|
|
75
|
+
return (0, types_1.lam)('x', (0, types_1.v)('x'));
|
|
76
|
+
case 'K':
|
|
77
|
+
// K = λx.λy.x
|
|
78
|
+
return (0, types_1.lam)('x', (0, types_1.lam)('y', (0, types_1.v)('x')));
|
|
79
|
+
case 'S':
|
|
80
|
+
// S = λx.λy.λz. x z (y z)
|
|
81
|
+
return (0, types_1.lam)('x', (0, types_1.lam)('y', (0, types_1.lam)('z', (0, types_1.apN)((0, types_1.v)('x'), (0, types_1.v)('z'), (0, types_1.ap)((0, types_1.v)('y'), (0, types_1.v)('z'))))));
|
|
82
|
+
case 'var':
|
|
83
|
+
return (0, types_1.v)(c.name);
|
|
84
|
+
case 'app':
|
|
85
|
+
return (0, types_1.ap)(toLambda(c.fn), toLambda(c.arg));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=abstract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract.js","sourceRoot":"","sources":["../../src/combinators-ski/abstract.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,uCAAuC;AACvC,+DAA+D;AAC/D,EAAE;AACF,sEAAsE;AACtE,gDAAgD;AAChD,EAAE;AACF,sBAAsB;AACtB,iDAAiD;AACjD,sCAAsC;AACtC,EAAE;AACF,mEAAmE;AACnE,gEAAgE;AAChE,qEAAqE;AACrE,qEAAqE;AACrE,EAAE;AACF,+DAA+D;AAC/D,wDAAwD;AACxD,gEAAgE;AAChE,+CAA+C;;AAQ/C,gDAYC;AA+BD,4BAmBC;AAnED,gDAAoF;AAEpF,mCAAuD;AAEvD,uEAAuE;AACvE,SAAgB,kBAAkB,CAAC,CAAa;IAC9C,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;QACf,KAAK,KAAK;YACR,OAAO,IA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AAC,IAAA,SAAC,GAAE,EAAE,CAAC,CAAC,CAAC;IACvB,CAAC;AACH,CAAC;AAED,iEAAiE;AACjE,kEAAkE;AAClE,uDAAuD;AACvD,8DAA8D;AAC9D,4DAA4D;AAC5D,SAAgB,QAAQ,CAAC,CAAQ;IAC/B,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;QACf,KAAK,GAAG;YACN,WAAW;YACX,OAAO,IAAA,WAAG,EAAC,GAAG,EAAE,IAAA,SAAM,EAAC,GAAG,CAAC,CAAC,CAAC;QAC/B,KAAK,GAAG;YACN,cAAc;YACd,OAAO,IAAA,WAAG,EAAC,GAAG,EAAE,IAAA,WAAG,EAAC,GAAG,EAAE,IAAA,SAAM,EAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACzC,KAAK,GAAG;YACN,0BAA0B;YAC1B,OAAO,IAAA,WAAG,EACR,GAAG,EACH,IAAA,WAAG,EAAC,GAAG,EAAE,IAAA,WAAG,EAAC,GAAG,EAAE,IAAA,WAAM,EAAC,IAAA,SAAM,EAAC,GAAG,CAAC,EAAE,IAAA,SAAM,EAAC,GAAG,CAAC,EAAE,IAAA,UAAK,EAAC,IAAA,SAAM,EAAC,GAAG,CAAC,EAAE,IAAA,SAAM,EAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CACtF,CAAC;QACJ,KAAK,KAAK;YACR,OAAO,IAAA,SAAM,EAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACxB,KAAK,KAAK;YACR,OAAO,IAAA,UAAK,EAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAClD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { CTerm } from './types';
|
|
2
|
+
export { S, K, I, cvar, app, ctermEq, freeVars, termToString } from './types';
|
|
3
|
+
export { reduceStep, normalize, isNormalForm } from './reduce';
|
|
4
|
+
export type { NormalizeResult } from './reduce';
|
|
5
|
+
export { abstractFromLambda, toLambda } from './abstract';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/combinators-ski/index.ts"],"names":[],"mappings":"AAWA,YAAY,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE9E,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC/D,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// SKI combinatory logic — Punto de entrada público
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// API:
|
|
7
|
+
// - Tipos: CTerm
|
|
8
|
+
// - Constructores: S(), K(), I(), cvar, app
|
|
9
|
+
// - Estructura: ctermEq, freeVars, termToString
|
|
10
|
+
// - Reducción: reduceStep, normalize, isNormalForm, NormalizeResult
|
|
11
|
+
// - Bracket abstraction: abstractFromLambda, toLambda
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.toLambda = exports.abstractFromLambda = exports.isNormalForm = exports.normalize = exports.reduceStep = exports.termToString = exports.freeVars = exports.ctermEq = exports.app = exports.cvar = exports.I = exports.K = exports.S = void 0;
|
|
14
|
+
var types_1 = require("./types");
|
|
15
|
+
Object.defineProperty(exports, "S", { enumerable: true, get: function () { return types_1.S; } });
|
|
16
|
+
Object.defineProperty(exports, "K", { enumerable: true, get: function () { return types_1.K; } });
|
|
17
|
+
Object.defineProperty(exports, "I", { enumerable: true, get: function () { return types_1.I; } });
|
|
18
|
+
Object.defineProperty(exports, "cvar", { enumerable: true, get: function () { return types_1.cvar; } });
|
|
19
|
+
Object.defineProperty(exports, "app", { enumerable: true, get: function () { return types_1.app; } });
|
|
20
|
+
Object.defineProperty(exports, "ctermEq", { enumerable: true, get: function () { return types_1.ctermEq; } });
|
|
21
|
+
Object.defineProperty(exports, "freeVars", { enumerable: true, get: function () { return types_1.freeVars; } });
|
|
22
|
+
Object.defineProperty(exports, "termToString", { enumerable: true, get: function () { return types_1.termToString; } });
|
|
23
|
+
var reduce_1 = require("./reduce");
|
|
24
|
+
Object.defineProperty(exports, "reduceStep", { enumerable: true, get: function () { return reduce_1.reduceStep; } });
|
|
25
|
+
Object.defineProperty(exports, "normalize", { enumerable: true, get: function () { return reduce_1.normalize; } });
|
|
26
|
+
Object.defineProperty(exports, "isNormalForm", { enumerable: true, get: function () { return reduce_1.isNormalForm; } });
|
|
27
|
+
var abstract_1 = require("./abstract");
|
|
28
|
+
Object.defineProperty(exports, "abstractFromLambda", { enumerable: true, get: function () { return abstract_1.abstractFromLambda; } });
|
|
29
|
+
Object.defineProperty(exports, "toLambda", { enumerable: true, get: function () { return abstract_1.toLambda; } });
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/combinators-ski/index.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,mDAAmD;AACnD,+DAA+D;AAC/D,EAAE;AACF,OAAO;AACP,mBAAmB;AACnB,8CAA8C;AAC9C,kDAAkD;AAClD,sEAAsE;AACtE,wDAAwD;;;AAGxD,iCAA8E;AAArE,0FAAA,CAAC,OAAA;AAAE,0FAAA,CAAC,OAAA;AAAE,0FAAA,CAAC,OAAA;AAAE,6FAAA,IAAI,OAAA;AAAE,4FAAA,GAAG,OAAA;AAAE,gGAAA,OAAO,OAAA;AAAE,iGAAA,QAAQ,OAAA;AAAE,qGAAA,YAAY,OAAA;AAE5D,mCAA+D;AAAtD,oGAAA,UAAU,OAAA;AAAE,mGAAA,SAAS,OAAA;AAAE,sGAAA,YAAY,OAAA;AAG5C,uCAA0D;AAAjD,8GAAA,kBAAkB,OAAA;AAAE,oGAAA,QAAQ,OAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CTerm } from './types';
|
|
2
|
+
export declare function reduceStep(t: CTerm): CTerm | null;
|
|
3
|
+
export interface NormalizeResult {
|
|
4
|
+
result: CTerm;
|
|
5
|
+
steps: number;
|
|
6
|
+
terminated: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function normalize(t: CTerm, maxSteps?: number): NormalizeResult;
|
|
9
|
+
export declare function isNormalForm(t: CTerm): boolean;
|
|
10
|
+
//# sourceMappingURL=reduce.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reduce.d.ts","sourceRoot":"","sources":["../../src/combinators-ski/reduce.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGrC,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,IAAI,CAgBjD;AA2DD,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,KAAK,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;CACrB;AAKD,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,SAAO,GAAG,eAAe,CASpE;AAGD,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,GAAG,OAAO,CAE9C"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// SKI combinatory logic — Reducción
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// Reglas (weak reduction, leftmost-outermost):
|
|
7
|
+
// I x → x
|
|
8
|
+
// K x y → x (descarta `y` aunque éste tenga redex propios)
|
|
9
|
+
// S x y z → x z (y z)
|
|
10
|
+
//
|
|
11
|
+
// `reduceStep` aplica un único paso si encuentra un redex en la
|
|
12
|
+
// cabeza o, si no, baja por las ramas siguiendo orden
|
|
13
|
+
// leftmost-outermost. Como no hay binders ni captura, no se requiere
|
|
14
|
+
// renombrar; la sustitución es pegado físico de subárboles.
|
|
15
|
+
//
|
|
16
|
+
// La forma normal SKI puede no existir (e.g. términos divergentes
|
|
17
|
+
// equivalentes a Ω), por lo que `normalize` recibe `maxSteps`.
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.reduceStep = reduceStep;
|
|
20
|
+
exports.normalize = normalize;
|
|
21
|
+
exports.isNormalForm = isNormalForm;
|
|
22
|
+
// Devuelve el término reducido en UN paso, o `null` si no hay redex.
|
|
23
|
+
function reduceStep(t) {
|
|
24
|
+
// Intenta primero un paso en la posición de cabeza.
|
|
25
|
+
const head = reduceHead(t);
|
|
26
|
+
if (head !== null)
|
|
27
|
+
return head;
|
|
28
|
+
// Si no hay redex en cabeza, baja recursivamente.
|
|
29
|
+
switch (t.kind) {
|
|
30
|
+
case 'app': {
|
|
31
|
+
const fn2 = reduceStep(t.fn);
|
|
32
|
+
if (fn2 !== null)
|
|
33
|
+
return { kind: 'app', fn: fn2, arg: t.arg };
|
|
34
|
+
const arg2 = reduceStep(t.arg);
|
|
35
|
+
if (arg2 !== null)
|
|
36
|
+
return { kind: 'app', fn: t.fn, arg: arg2 };
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
default:
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Intenta una reducción en la posición de cabeza del término.
|
|
44
|
+
// Devuelve `null` si no hay redex de cabeza.
|
|
45
|
+
function reduceHead(t) {
|
|
46
|
+
if (t.kind !== 'app')
|
|
47
|
+
return null;
|
|
48
|
+
// Junta la cabeza (combinador o variable) con sus argumentos
|
|
49
|
+
// recorridos por la espina izquierda.
|
|
50
|
+
const spine = [];
|
|
51
|
+
let cursor = t;
|
|
52
|
+
while (cursor.kind === 'app') {
|
|
53
|
+
spine.unshift(cursor.arg);
|
|
54
|
+
cursor = cursor.fn;
|
|
55
|
+
}
|
|
56
|
+
// `cursor` es la cabeza definitiva (S/K/I/var); `spine` son los args
|
|
57
|
+
// aplicados de izquierda a derecha.
|
|
58
|
+
switch (cursor.kind) {
|
|
59
|
+
case 'I': {
|
|
60
|
+
const x = spine[0];
|
|
61
|
+
if (x === undefined)
|
|
62
|
+
return null;
|
|
63
|
+
// I x rest... → x rest...
|
|
64
|
+
return rebuild(x, spine.slice(1));
|
|
65
|
+
}
|
|
66
|
+
case 'K': {
|
|
67
|
+
const x = spine[0];
|
|
68
|
+
const y = spine[1];
|
|
69
|
+
if (x === undefined || y === undefined)
|
|
70
|
+
return null;
|
|
71
|
+
// K x y rest... → x rest... (y se descarta)
|
|
72
|
+
return rebuild(x, spine.slice(2));
|
|
73
|
+
}
|
|
74
|
+
case 'S': {
|
|
75
|
+
const x = spine[0];
|
|
76
|
+
const y = spine[1];
|
|
77
|
+
const z = spine[2];
|
|
78
|
+
if (x === undefined || y === undefined || z === undefined)
|
|
79
|
+
return null;
|
|
80
|
+
// S x y z rest... → (x z (y z)) rest...
|
|
81
|
+
const reduced = {
|
|
82
|
+
kind: 'app',
|
|
83
|
+
fn: { kind: 'app', fn: x, arg: z },
|
|
84
|
+
arg: { kind: 'app', fn: y, arg: z },
|
|
85
|
+
};
|
|
86
|
+
return rebuild(reduced, spine.slice(3));
|
|
87
|
+
}
|
|
88
|
+
default:
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Reconstruye `head arg0 arg1 ...` como aplicación asociativa a la izquierda.
|
|
93
|
+
function rebuild(head, args) {
|
|
94
|
+
let acc = head;
|
|
95
|
+
for (const a of args) {
|
|
96
|
+
acc = { kind: 'app', fn: acc, arg: a };
|
|
97
|
+
}
|
|
98
|
+
return acc;
|
|
99
|
+
}
|
|
100
|
+
// Itera reducciones hasta forma normal o agotar `maxSteps`.
|
|
101
|
+
// `terminated=true` significa que no quedan redex (forma normal SKI);
|
|
102
|
+
// `false` indica que se alcanzó el cap (típico para términos divergentes).
|
|
103
|
+
function normalize(t, maxSteps = 1000) {
|
|
104
|
+
let current = t;
|
|
105
|
+
let steps = 0;
|
|
106
|
+
for (; steps < maxSteps; steps += 1) {
|
|
107
|
+
const next = reduceStep(current);
|
|
108
|
+
if (next === null)
|
|
109
|
+
return { result: current, steps, terminated: true };
|
|
110
|
+
current = next;
|
|
111
|
+
}
|
|
112
|
+
return { result: current, steps, terminated: false };
|
|
113
|
+
}
|
|
114
|
+
// ¿No hay más redex aplicable?
|
|
115
|
+
function isNormalForm(t) {
|
|
116
|
+
return reduceStep(t) === null;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=reduce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reduce.js","sourceRoot":"","sources":["../../src/combinators-ski/reduce.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,oCAAoC;AACpC,+DAA+D;AAC/D,EAAE;AACF,+CAA+C;AAC/C,iBAAiB;AACjB,yEAAyE;AACzE,yBAAyB;AACzB,EAAE;AACF,gEAAgE;AAChE,sDAAsD;AACtD,qEAAqE;AACrE,4DAA4D;AAC5D,EAAE;AACF,kEAAkE;AAClE,+DAA+D;;AAK/D,gCAgBC;AAoED,8BASC;AAGD,oCAEC;AAnGD,qEAAqE;AACrE,SAAgB,UAAU,CAAC,CAAQ;IACjC,oDAAoD;IACpD,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IAC3B,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC/B,kDAAkD;IAClD,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;QACf,KAAK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EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;IACzC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAQD,4DAA4D;AAC5D,sEAAsE;AACtE,2EAA2E;AAC3E,SAAgB,SAAS,CAAC,CAAQ,EAAE,QAAQ,GAAG,IAAI;IACjD,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,OAAO,KAAK,GAAG,QAAQ,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;QACjC,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QACvE,OAAO,GAAG,IAAI,CAAC;IACjB,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;AACvD,CAAC;AAED,+BAA+B;AAC/B,SAAgB,YAAY,CAAC,CAAQ;IACnC,OAAO,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type CTerm = {
|
|
2
|
+
kind: 'S';
|
|
3
|
+
} | {
|
|
4
|
+
kind: 'K';
|
|
5
|
+
} | {
|
|
6
|
+
kind: 'I';
|
|
7
|
+
} | {
|
|
8
|
+
kind: 'var';
|
|
9
|
+
name: string;
|
|
10
|
+
} | {
|
|
11
|
+
kind: 'app';
|
|
12
|
+
fn: CTerm;
|
|
13
|
+
arg: CTerm;
|
|
14
|
+
};
|
|
15
|
+
export declare const S: () => CTerm;
|
|
16
|
+
export declare const K: () => CTerm;
|
|
17
|
+
export declare const I: () => CTerm;
|
|
18
|
+
export declare const cvar: (name: string) => CTerm;
|
|
19
|
+
export declare function app(...ts: CTerm[]): CTerm;
|
|
20
|
+
export declare function ctermEq(a: CTerm, b: CTerm): boolean;
|
|
21
|
+
export declare function termToString(t: CTerm): string;
|
|
22
|
+
export declare function freeVars(t: CTerm): Set<string>;
|
|
23
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/combinators-ski/types.ts"],"names":[],"mappings":"AAeA,MAAM,MAAM,KAAK,GACb;IAAE,IAAI,EAAE,GAAG,CAAA;CAAE,GACb;IAAE,IAAI,EAAE,GAAG,CAAA;CAAE,GACb;IAAE,IAAI,EAAE,GAAG,CAAA;CAAE,GACb;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC7B;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,EAAE,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,KAAK,CAAA;CAAE,CAAC;AAG3C,eAAO,MAAM,CAAC,QAAO,KAAwB,CAAC;AAC9C,eAAO,MAAM,CAAC,QAAO,KAAwB,CAAC;AAC9C,eAAO,MAAM,CAAC,QAAO,KAAwB,CAAC;AAC9C,eAAO,MAAM,IAAI,GAAI,MAAM,MAAM,KAAG,KAAgC,CAAC;AAIrE,wBAAgB,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,GAAG,KAAK,CAYzC;AAGD,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,OAAO,CAcnD;AAID,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,CAgB7C;AAGD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,CAI9C"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// SKI combinatory logic — Términos y constructores
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// Sistema base de combinadores S, K, I (Schönfinkel / Curry). Es
|
|
7
|
+
// Turing-completo y equivalente al λ-cálculo, pero sin variables
|
|
8
|
+
// ligadas: toda función se construye combinando S, K, I y variables
|
|
9
|
+
// libres mediante aplicación. Las λ-abstracciones se "eliminan"
|
|
10
|
+
// vía bracket abstraction (ver `abstract.ts`).
|
|
11
|
+
//
|
|
12
|
+
// Reglas de reducción:
|
|
13
|
+
// I x → x
|
|
14
|
+
// K x y → x
|
|
15
|
+
// S x y z → x z (y z)
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.cvar = exports.I = exports.K = exports.S = void 0;
|
|
18
|
+
exports.app = app;
|
|
19
|
+
exports.ctermEq = ctermEq;
|
|
20
|
+
exports.termToString = termToString;
|
|
21
|
+
exports.freeVars = freeVars;
|
|
22
|
+
// ---------- Constructores convenientes ----------
|
|
23
|
+
const S = () => ({ kind: 'S' });
|
|
24
|
+
exports.S = S;
|
|
25
|
+
const K = () => ({ kind: 'K' });
|
|
26
|
+
exports.K = K;
|
|
27
|
+
const I = () => ({ kind: 'I' });
|
|
28
|
+
exports.I = I;
|
|
29
|
+
const cvar = (name) => ({ kind: 'var', name });
|
|
30
|
+
exports.cvar = cvar;
|
|
31
|
+
// Aplicación n-aria asociativa a la izquierda: app(f, a, b, c) = ((f a) b) c.
|
|
32
|
+
// Con un solo argumento devuelve el término tal cual; sin argumentos lanza.
|
|
33
|
+
function app(...ts) {
|
|
34
|
+
const head = ts[0];
|
|
35
|
+
if (head === undefined) {
|
|
36
|
+
throw new Error('app() requiere al menos un término');
|
|
37
|
+
}
|
|
38
|
+
let acc = head;
|
|
39
|
+
for (let i = 1; i < ts.length; i += 1) {
|
|
40
|
+
const next = ts[i];
|
|
41
|
+
if (next === undefined)
|
|
42
|
+
break;
|
|
43
|
+
acc = { kind: 'app', fn: acc, arg: next };
|
|
44
|
+
}
|
|
45
|
+
return acc;
|
|
46
|
+
}
|
|
47
|
+
// Igualdad estructural (no hay alpha — no hay binders).
|
|
48
|
+
function ctermEq(a, b) {
|
|
49
|
+
if (a.kind !== b.kind)
|
|
50
|
+
return false;
|
|
51
|
+
switch (a.kind) {
|
|
52
|
+
case 'S':
|
|
53
|
+
case 'K':
|
|
54
|
+
case 'I':
|
|
55
|
+
return true;
|
|
56
|
+
case 'var':
|
|
57
|
+
return a.name === b.name;
|
|
58
|
+
case 'app': {
|
|
59
|
+
const bb = b;
|
|
60
|
+
return ctermEq(a.fn, bb.fn) && ctermEq(a.arg, bb.arg);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Pretty-printer. Aplicación asociativa a la izquierda: agrupa con
|
|
65
|
+
// paréntesis sólo cuando el argumento es a su vez una aplicación.
|
|
66
|
+
function termToString(t) {
|
|
67
|
+
switch (t.kind) {
|
|
68
|
+
case 'S':
|
|
69
|
+
return 'S';
|
|
70
|
+
case 'K':
|
|
71
|
+
return 'K';
|
|
72
|
+
case 'I':
|
|
73
|
+
return 'I';
|
|
74
|
+
case 'var':
|
|
75
|
+
return t.name;
|
|
76
|
+
case 'app': {
|
|
77
|
+
const fn = termToString(t.fn);
|
|
78
|
+
const arg = t.arg.kind === 'app' ? `(${termToString(t.arg)})` : termToString(t.arg);
|
|
79
|
+
return `${fn} ${arg}`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Variables libres del término (no hay ligadas en SKI puro).
|
|
84
|
+
function freeVars(t) {
|
|
85
|
+
const acc = new Set();
|
|
86
|
+
collect(t, acc);
|
|
87
|
+
return acc;
|
|
88
|
+
}
|
|
89
|
+
function collect(t, acc) {
|
|
90
|
+
switch (t.kind) {
|
|
91
|
+
case 'var':
|
|
92
|
+
acc.add(t.name);
|
|
93
|
+
return;
|
|
94
|
+
case 'app':
|
|
95
|
+
collect(t.fn, acc);
|
|
96
|
+
collect(t.arg, acc);
|
|
97
|
+
return;
|
|
98
|
+
default:
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/combinators-ski/types.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,mDAAmD;AACnD,+DAA+D;AAC/D,EAAE;AACF,iEAAiE;AACjE,iEAAiE;AACjE,oEAAoE;AACpE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,uBAAuB;AACvB,iBAAiB;AACjB,iBAAiB;AACjB,yBAAyB;;;AAiBzB,kBAYC;AAGD,0BAcC;AAID,oCAgBC;AAGD,4BAIC;AAhED,mDAAmD;AAC5C,MAAM,CAAC,GAAG,GAAU,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;AAAjC,QAAA,CAAC,KAAgC;AACvC,MAAM,CAAC,GAAG,GAAU,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;AAAjC,QAAA,CAAC,KAAgC;AACvC,MAAM,CAAC,GAAG,GAAU,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;AAAjC,QAAA,CAAC,KAAgC;AACvC,MAAM,IAAI,GAAG,CAAC,IAAY,EAAS,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAAxD,QAAA,IAAI,QAAoD;AAErE,8EAA8E;AAC9E,4EAA4E;AAC5E,SAAgB,GAAG,CAAC,GAAG,EAAW;IAChC,MAAM,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IACnB,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;IACD,IAAI,GAAG,GAAU,IAAI,CAAC;IACtB,K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AAC,CAAC,CAAC;YACX,MAAM,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YAC9B,MAAM,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YACpF,OAAO,GAAG,EAAE,IAAI,GAAG,EAAE,CAAC;QACxB,CAAC;IACH,CAAC;AACH,CAAC;AAED,6DAA6D;AAC7D,SAAgB,QAAQ,CAAC,CAAQ;IAC/B,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9B,OAAO,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAChB,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,OAAO,CAAC,CAAQ,EAAE,GAAgB;IACzC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;QACf,KAAK,KAAK;YACR,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YAChB,OAAO;QACT,KAAK,KAAK;YACR,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;YACnB,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;YACpB,OAAO;QACT;YACE,OAAO;IACX,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
export interface CReal {
|
|
2
|
+
/**
|
|
3
|
+
* Devuelve una aproximación dyádica de x con error < 2^{-precision}.
|
|
4
|
+
* numerator / denominator ≈ x, denominator = 2^precision.
|
|
5
|
+
*/
|
|
6
|
+
approx(precision: number): {
|
|
7
|
+
numerator: bigint;
|
|
8
|
+
denominator: bigint;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** Eleva 2 a un entero no negativo. */
|
|
12
|
+
declare function pow2(n: number): bigint;
|
|
13
|
+
/**
|
|
14
|
+
* Divide entero con "round half away from zero".
|
|
15
|
+
* shiftRight(x, k) ≈ x / 2^k redondeado.
|
|
16
|
+
* Garantiza |shiftRight(x,k) - x/2^k| ≤ 1/2.
|
|
17
|
+
*/
|
|
18
|
+
declare function shiftRight(x: bigint, k: number): bigint;
|
|
19
|
+
/**
|
|
20
|
+
* Calcula el número de bits del entero (|x| en binario).
|
|
21
|
+
* bitLength(0) = 0, bitLength(1) = 1, bitLength(7) = 3, bitLength(8) = 4.
|
|
22
|
+
*/
|
|
23
|
+
declare function bitLength(x: bigint): number;
|
|
24
|
+
export declare function fromInt(n: number | bigint): CReal;
|
|
25
|
+
export declare function fromRational(p: number | bigint, q: number | bigint): CReal;
|
|
26
|
+
export declare function neg(a: CReal): CReal;
|
|
27
|
+
export declare function abs(a: CReal): CReal;
|
|
28
|
+
/**
|
|
29
|
+
* add(a,b) a precisión p:
|
|
30
|
+
* pedimos a y b a precisión p+2.
|
|
31
|
+
* error de cada uno < 2^{-(p+2)} → error en a+b < 2·2^{-(p+2)} = 2^{-(p+1)}.
|
|
32
|
+
* Al pasar de escala p+2 a p (shift de 2), introducimos error
|
|
33
|
+
* de redondeo ≤ 1/2 en la unidad p, = 2^{-(p+1)}.
|
|
34
|
+
* Total: < 2^{-(p+1)} + 2^{-(p+1)} = 2^{-p}. ✓
|
|
35
|
+
*/
|
|
36
|
+
export declare function add(a: CReal, b: CReal): CReal;
|
|
37
|
+
export declare function sub(a: CReal, b: CReal): CReal;
|
|
38
|
+
/**
|
|
39
|
+
* mul(a,b) a precisión p:
|
|
40
|
+
* Necesitamos cotas sobre |a| y |b|. Tomamos una aproximación gruesa
|
|
41
|
+
* a precisión 0 para estimar el tamaño en bits.
|
|
42
|
+
* Sean |a| ≤ 2^A, |b| ≤ 2^B (con A,B no-negativos).
|
|
43
|
+
* Trabajamos a precisión p + A + B + 3.
|
|
44
|
+
* En esa escala el producto cabe y la cota de error queda < 2^{-p}.
|
|
45
|
+
*
|
|
46
|
+
* Detalle del error: si â = a + ε_a con |ε_a| < 2^{-w} y análogamente
|
|
47
|
+
* para b̂ (w = work precision en los operandos), entonces
|
|
48
|
+
* â·b̂ - a·b = a·ε_b + b·ε_a + ε_a·ε_b.
|
|
49
|
+
* |a·ε_b| ≤ 2^A · 2^{-w}, idem para b.
|
|
50
|
+
* Eligiendo w = p + A + B + 3 ese error queda < 2·2^{-(p+B+3)}
|
|
51
|
+
* acotado holgadamente por 2^{-(p+1)}, y el shift final añade otro
|
|
52
|
+
* 2^{-(p+1)}, dando < 2^{-p}.
|
|
53
|
+
*/
|
|
54
|
+
export declare function mul(a: CReal, b: CReal): CReal;
|
|
55
|
+
/**
|
|
56
|
+
* div(a,b) a precisión p (b ≠ 0).
|
|
57
|
+
* Encontramos k tal que |b| ≥ 2^{-k}.
|
|
58
|
+
* Necesitamos también cota superior A_bits sobre |a|.
|
|
59
|
+
* Trabajamos a precisión w = p + 2k + A_bits + 4.
|
|
60
|
+
*
|
|
61
|
+
* Si â = a + ε_a, b̂ = b + ε_b, entonces
|
|
62
|
+
* â/b̂ - a/b = (ε_a · b - a · ε_b) / (b · b̂).
|
|
63
|
+
* |b · b̂| ≥ (2^{-k}) · (2^{-k} - 2^{-w}) ≥ 2^{-2k-1}.
|
|
64
|
+
* |ε_a · b| ≤ 2^{-w} · (|b̂|+2^{-w}).
|
|
65
|
+
* |a · ε_b| ≤ |â+2^{-w}| · 2^{-w}.
|
|
66
|
+
* Tomando w = p + 2k + A_bits + 4 acotamos por < 2^{-p}.
|
|
67
|
+
*/
|
|
68
|
+
export declare function div(a: CReal, b: CReal): CReal;
|
|
69
|
+
/**
|
|
70
|
+
* sqrt(a) para a ≥ 0. Si a < 0 (detectado con cota), lanza.
|
|
71
|
+
* Implementación: Newton-Raphson en bigint sobre x² = N donde
|
|
72
|
+
* N = aprox(a) a precisión 2·prec + buffer. La raíz cuadrada entera
|
|
73
|
+
* de N da nuestra aproximación a √a a precisión prec.
|
|
74
|
+
*/
|
|
75
|
+
export declare function sqrt(a: CReal): CReal;
|
|
76
|
+
/** Raíz cuadrada entera (floor) de n ≥ 0 vía Newton. */
|
|
77
|
+
declare function isqrt(n: bigint): bigint;
|
|
78
|
+
/**
|
|
79
|
+
* compareWithEpsilon(a, b, epsPrec):
|
|
80
|
+
* Si |a - b| < 2^{-epsPrec}, devuelve 0 (indistinguibles).
|
|
81
|
+
* Si a > b + 2^{-epsPrec}, devuelve 1.
|
|
82
|
+
* Si a < b - 2^{-epsPrec}, devuelve -1.
|
|
83
|
+
*
|
|
84
|
+
* Implementación: comparamos aproximaciones a precisión epsPrec + 3.
|
|
85
|
+
* |aw/2^w - a| < 2^{-w}, idem b. Entonces
|
|
86
|
+
* (aw - bw)/2^w está dentro de (a - b) ± 2·2^{-w}.
|
|
87
|
+
* Eligiendo w = epsPrec + 3:
|
|
88
|
+
* • Si (aw - bw) > 2^{w - epsPrec} + 2 = 8 + 2 = 10 (en escala w),
|
|
89
|
+
* entonces a - b > 2^{-epsPrec}, devolvemos 1.
|
|
90
|
+
* • Análogo para -10.
|
|
91
|
+
* • En otro caso, devolvemos 0.
|
|
92
|
+
*/
|
|
93
|
+
export declare function compareWithEpsilon(a: CReal, b: CReal, epsilonPrecision: number): -1 | 0 | 1;
|
|
94
|
+
/**
|
|
95
|
+
* toString(r, digits): representación decimal con `digits` dígitos
|
|
96
|
+
* después del punto. Usa precisión binaria suficiente:
|
|
97
|
+
* 2^p > 10^digits ⇔ p > digits · log2(10) ≈ digits · 3.322.
|
|
98
|
+
* Tomamos p = ceil(digits · 4) + 8 para holgura.
|
|
99
|
+
*/
|
|
100
|
+
export declare function toString(r: CReal, digits: number): string;
|
|
101
|
+
/**
|
|
102
|
+
* exp(x) = Σ x^k / k!. Para que la serie converja rápido reducimos
|
|
103
|
+
* primero el argumento: escribimos x = q · ln(2) + r con |r| ≤ ln(2)/2
|
|
104
|
+
* usando q = round(x / ln(2)). Luego exp(x) = 2^q · exp(r).
|
|
105
|
+
*
|
|
106
|
+
* Para esta versión inicial hacemos una reducción más simple: si
|
|
107
|
+
* |x| > 1, dividimos por 2^k hasta que |x/2^k| < 1, calculamos
|
|
108
|
+
* exp(x/2^k) por serie, y elevamos al cuadrado k veces (exp(y)² = exp(2y)).
|
|
109
|
+
* Esto mantiene la convergencia de la serie acotada a ~prec términos.
|
|
110
|
+
*/
|
|
111
|
+
export declare function exp(x: CReal): CReal;
|
|
112
|
+
export declare function log(x: CReal): CReal;
|
|
113
|
+
export declare function sin(x: CReal): CReal;
|
|
114
|
+
export declare function cos(x: CReal): CReal;
|
|
115
|
+
/**
|
|
116
|
+
* pow(a, b) = exp(b · log(a)) para a > 0.
|
|
117
|
+
* Caso especial: si b es un entero, hacemos exponenciación rápida
|
|
118
|
+
* sobre CReal para evitar log de a (lo que permite a ≤ 0 si b es entero).
|
|
119
|
+
*/
|
|
120
|
+
export declare function pow(a: CReal, b: CReal | number): CReal;
|
|
121
|
+
export declare const PI: CReal;
|
|
122
|
+
export declare const E: CReal;
|
|
123
|
+
export declare const SQRT2: CReal;
|
|
124
|
+
/** @internal Exposed for whitebox tests. */
|
|
125
|
+
export declare const __internals: {
|
|
126
|
+
shiftRight: typeof shiftRight;
|
|
127
|
+
bitLength: typeof bitLength;
|
|
128
|
+
isqrt: typeof isqrt;
|
|
129
|
+
pow2: typeof pow2;
|
|
130
|
+
};
|
|
131
|
+
export {};
|
|
132
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constructive-reals/index.ts"],"names":[],"mappings":"AA6CA,MAAM,WAAW,KAAK;IACpB;;;OAGG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;CACvE;AAID,uCAAuC;AACvC,iBAAS,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,M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