@stevenvo780/st-lang 4.12.0 → 4.14.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/dist/reasoning/datalog/index.d.ts +131 -0
- package/dist/reasoning/datalog/index.d.ts.map +1 -0
- package/dist/reasoning/datalog/index.js +706 -0
- package/dist/reasoning/datalog/index.js.map +1 -0
- package/dist/reasoning/galois-fields/index.d.ts +29 -0
- package/dist/reasoning/galois-fields/index.d.ts.map +1 -0
- package/dist/reasoning/galois-fields/index.js +522 -0
- package/dist/reasoning/galois-fields/index.js.map +1 -0
- package/dist/reasoning/hoare-logic/index.d.ts +130 -0
- package/dist/reasoning/hoare-logic/index.d.ts.map +1 -0
- package/dist/reasoning/hoare-logic/index.js +535 -0
- package/dist/reasoning/hoare-logic/index.js.map +1 -0
- package/dist/reasoning/lattice/index.d.ts +165 -0
- package/dist/reasoning/lattice/index.d.ts.map +1 -0
- package/dist/reasoning/lattice/index.js +587 -0
- package/dist/reasoning/lattice/index.js.map +1 -0
- package/dist/reasoning/model-checking/index.d.ts +113 -0
- package/dist/reasoning/model-checking/index.d.ts.map +1 -0
- package/dist/reasoning/model-checking/index.js +786 -0
- package/dist/reasoning/model-checking/index.js.map +1 -0
- package/dist/reasoning/polynomial-ring/index.d.ts +30 -0
- package/dist/reasoning/polynomial-ring/index.d.ts.map +1 -0
- package/dist/reasoning/polynomial-ring/index.js +797 -0
- package/dist/reasoning/polynomial-ring/index.js.map +1 -0
- package/dist/reasoning/separation-logic/index.d.ts +190 -0
- package/dist/reasoning/separation-logic/index.d.ts.map +1 -0
- package/dist/reasoning/separation-logic/index.js +758 -0
- package/dist/reasoning/separation-logic/index.js.map +1 -0
- package/dist/reasoning/universal-algebra/index.d.ts +196 -0
- package/dist/reasoning/universal-algebra/index.d.ts.map +1 -0
- package/dist/reasoning/universal-algebra/index.js +865 -0
- package/dist/reasoning/universal-algebra/index.js.map +1 -0
- package/dist/tests/reasoning/datalog/datalog.test.d.ts +2 -0
- package/dist/tests/reasoning/datalog/datalog.test.d.ts.map +1 -0
- package/dist/tests/reasoning/datalog/datalog.test.js +333 -0
- package/dist/tests/reasoning/datalog/datalog.test.js.map +1 -0
- package/dist/tests/reasoning/galois-fields/galois-fields.test.d.ts +2 -0
- package/dist/tests/reasoning/galois-fields/galois-fields.test.d.ts.map +1 -0
- package/dist/tests/reasoning/galois-fields/galois-fields.test.js +226 -0
- package/dist/tests/reasoning/galois-fields/galois-fields.test.js.map +1 -0
- package/dist/tests/reasoning/hoare-logic/hoare-logic.test.d.ts +2 -0
- package/dist/tests/reasoning/hoare-logic/hoare-logic.test.d.ts.map +1 -0
- package/dist/tests/reasoning/hoare-logic/hoare-logic.test.js +340 -0
- package/dist/tests/reasoning/hoare-logic/hoare-logic.test.js.map +1 -0
- package/dist/tests/reasoning/lattice/lattice.test.d.ts +2 -0
- package/dist/tests/reasoning/lattice/lattice.test.d.ts.map +1 -0
- package/dist/tests/reasoning/lattice/lattice.test.js +238 -0
- package/dist/tests/reasoning/lattice/lattice.test.js.map +1 -0
- package/dist/tests/reasoning/model-checking/model-checking.test.d.ts +2 -0
- package/dist/tests/reasoning/model-checking/model-checking.test.d.ts.map +1 -0
- package/dist/tests/reasoning/model-checking/model-checking.test.js +222 -0
- package/dist/tests/reasoning/model-checking/model-checking.test.js.map +1 -0
- package/dist/tests/reasoning/polynomial-ring/polynomial-ring.test.d.ts +2 -0
- package/dist/tests/reasoning/polynomial-ring/polynomial-ring.test.d.ts.map +1 -0
- package/dist/tests/reasoning/polynomial-ring/polynomial-ring.test.js +230 -0
- package/dist/tests/reasoning/polynomial-ring/polynomial-ring.test.js.map +1 -0
- package/dist/tests/reasoning/separation-logic/separation-logic.test.d.ts +2 -0
- package/dist/tests/reasoning/separation-logic/separation-logic.test.d.ts.map +1 -0
- package/dist/tests/reasoning/separation-logic/separation-logic.test.js +311 -0
- package/dist/tests/reasoning/separation-logic/separation-logic.test.js.map +1 -0
- package/dist/tests/reasoning/universal-algebra/universal-algebra.test.d.ts +2 -0
- package/dist/tests/reasoning/universal-algebra/universal-algebra.test.d.ts.map +1 -0
- package/dist/tests/reasoning/universal-algebra/universal-algebra.test.js +289 -0
- package/dist/tests/reasoning/universal-algebra/universal-algebra.test.js.map +1 -0
- package/dist/tests/type-theory/lambda-cube/lambda-cube.test.d.ts +2 -0
- package/dist/tests/type-theory/lambda-cube/lambda-cube.test.d.ts.map +1 -0
- package/dist/tests/type-theory/lambda-cube/lambda-cube.test.js +266 -0
- package/dist/tests/type-theory/lambda-cube/lambda-cube.test.js.map +1 -0
- package/dist/type-theory/lambda-cube/erase.d.ts +26 -0
- package/dist/type-theory/lambda-cube/erase.d.ts.map +1 -0
- package/dist/type-theory/lambda-cube/erase.js +68 -0
- package/dist/type-theory/lambda-cube/erase.js.map +1 -0
- package/dist/type-theory/lambda-cube/examples.d.ts +59 -0
- package/dist/type-theory/lambda-cube/examples.d.ts.map +1 -0
- package/dist/type-theory/lambda-cube/examples.js +110 -0
- package/dist/type-theory/lambda-cube/examples.js.map +1 -0
- package/dist/type-theory/lambda-cube/index.d.ts +11 -0
- package/dist/type-theory/lambda-cube/index.d.ts.map +1 -0
- package/dist/type-theory/lambda-cube/index.js +64 -0
- package/dist/type-theory/lambda-cube/index.js.map +1 -0
- package/dist/type-theory/lambda-cube/normalize.d.ts +17 -0
- package/dist/type-theory/lambda-cube/normalize.d.ts.map +1 -0
- package/dist/type-theory/lambda-cube/normalize.js +134 -0
- package/dist/type-theory/lambda-cube/normalize.js.map +1 -0
- package/dist/type-theory/lambda-cube/rules.d.ts +26 -0
- package/dist/type-theory/lambda-cube/rules.d.ts.map +1 -0
- package/dist/type-theory/lambda-cube/rules.js +67 -0
- package/dist/type-theory/lambda-cube/rules.js.map +1 -0
- package/dist/type-theory/lambda-cube/typecheck.d.ts +20 -0
- package/dist/type-theory/lambda-cube/typecheck.d.ts.map +1 -0
- package/dist/type-theory/lambda-cube/typecheck.js +168 -0
- package/dist/type-theory/lambda-cube/typecheck.js.map +1 -0
- package/dist/type-theory/lambda-cube/types.d.ts +40 -0
- package/dist/type-theory/lambda-cube/types.d.ts.map +1 -0
- package/dist/type-theory/lambda-cube/types.js +192 -0
- package/dist/type-theory/lambda-cube/types.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CubeTerm } from './types';
|
|
2
|
+
export type UntypedTerm = {
|
|
3
|
+
kind: 'var';
|
|
4
|
+
name: string;
|
|
5
|
+
} | {
|
|
6
|
+
kind: 'abs';
|
|
7
|
+
param: string;
|
|
8
|
+
body: UntypedTerm;
|
|
9
|
+
} | {
|
|
10
|
+
kind: 'app';
|
|
11
|
+
fn: UntypedTerm;
|
|
12
|
+
arg: UntypedTerm;
|
|
13
|
+
};
|
|
14
|
+
export interface EraseError {
|
|
15
|
+
error: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function isEraseError(r: UntypedTerm | EraseError): r is EraseError;
|
|
18
|
+
/**
|
|
19
|
+
* Borrado total a λ-cálculo no tipado. Sorts y Π no tienen
|
|
20
|
+
* representante runtime — si aparecen como sub-término principal,
|
|
21
|
+
* el resultado es un error de borrado.
|
|
22
|
+
*/
|
|
23
|
+
export declare function erase(term: CubeTerm): UntypedTerm | EraseError;
|
|
24
|
+
/** Serialización legible del λ-untyped. */
|
|
25
|
+
export declare function untypedToString(t: UntypedTerm): string;
|
|
26
|
+
//# sourceMappingURL=erase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"erase.d.ts","sourceRoot":"","sources":["../../../src/type-theory/lambda-cube/erase.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC7B;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GACjD;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,EAAE,EAAE,WAAW,CAAC;IAAC,GAAG,EAAE,WAAW,CAAA;CAAE,CAAC;AAEvD,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,WAAW,GAAG,UAAU,GAAG,CAAC,IAAI,UAAU,CAEzE;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,QAAQ,GAAG,WAAW,GAAG,UAAU,CAqB9D;AAED,2CAA2C;AAC3C,wBAAgB,eAAe,CAAC,CAAC,EAAE,WAAW,GAAG,MAAM,CAWtD"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// Lambda Cube — Erasure a λ-cálculo no tipado
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// La función de borrado (erasure / type-erasure) traduce un término
|
|
7
|
+
// del cubo a un λ-término puro:
|
|
8
|
+
//
|
|
9
|
+
// |x| = x
|
|
10
|
+
// |s| = ⊥ (sorts no tienen representante runtime)
|
|
11
|
+
// |λ x:A. b| = λ x. |b|
|
|
12
|
+
// |Π x:A. B| = ⊥ (los Π son tipos, no se ejecutan)
|
|
13
|
+
// |f a| = |f| |a|
|
|
14
|
+
//
|
|
15
|
+
// El erasure preserva β: si `t →β t'` en el cubo entonces
|
|
16
|
+
// `|t| →β |t'|` en λ-untyped. Esa es la base de la "phase distinction"
|
|
17
|
+
// estándar de los sistemas de tipos polimórficos.
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.isEraseError = isEraseError;
|
|
20
|
+
exports.erase = erase;
|
|
21
|
+
exports.untypedToString = untypedToString;
|
|
22
|
+
function isEraseError(r) {
|
|
23
|
+
return typeof r === 'object' && r !== null && 'error' in r && typeof r.error === 'string';
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Borrado total a λ-cálculo no tipado. Sorts y Π no tienen
|
|
27
|
+
* representante runtime — si aparecen como sub-término principal,
|
|
28
|
+
* el resultado es un error de borrado.
|
|
29
|
+
*/
|
|
30
|
+
function erase(term) {
|
|
31
|
+
switch (term.kind) {
|
|
32
|
+
case 'var':
|
|
33
|
+
return { kind: 'var', name: term.name };
|
|
34
|
+
case 'sort':
|
|
35
|
+
return { error: `no se puede borrar el sort '${term.sort}' a λ-untyped` };
|
|
36
|
+
case 'pi':
|
|
37
|
+
return { error: `no se puede borrar un Π-type a λ-untyped` };
|
|
38
|
+
case 'lam': {
|
|
39
|
+
const body = erase(term.body);
|
|
40
|
+
if (isEraseError(body))
|
|
41
|
+
return body;
|
|
42
|
+
return { kind: 'abs', param: term.bind, body };
|
|
43
|
+
}
|
|
44
|
+
case 'app': {
|
|
45
|
+
const fn = erase(term.fn);
|
|
46
|
+
if (isEraseError(fn))
|
|
47
|
+
return fn;
|
|
48
|
+
const arg = erase(term.arg);
|
|
49
|
+
if (isEraseError(arg))
|
|
50
|
+
return arg;
|
|
51
|
+
return { kind: 'app', fn, arg };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** Serialización legible del λ-untyped. */
|
|
56
|
+
function untypedToString(t) {
|
|
57
|
+
switch (t.kind) {
|
|
58
|
+
case 'var':
|
|
59
|
+
return t.name;
|
|
60
|
+
case 'abs':
|
|
61
|
+
return `(λ${t.param}. ${untypedToString(t.body)})`;
|
|
62
|
+
case 'app': {
|
|
63
|
+
const arg = t.arg.kind === 'app' ? `(${untypedToString(t.arg)})` : untypedToString(t.arg);
|
|
64
|
+
return `(${untypedToString(t.fn)} ${arg})`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=erase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"erase.js","sourceR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1B,IAAI,YAAY,CAAC,EAAE,CAAC;gBAAE,OAAO,EAAE,CAAC;YAChC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAI,YAAY,CAAC,GAAG,CAAC;gBAAE,OAAO,GAAG,CAAC;YAClC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC;QAClC,CAAC;IACH,CAAC;AACH,CAAC;AAED,2CAA2C;AAC3C,SAAgB,eAAe,CAAC,CAAc;IAC5C,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;QACf,KAAK,KAAK;YACR,OAAO,CAAC,CAAC,IAAI,CAAC;QAChB,KAAK,KAAK;YACR,OAAO,KAAK,CAAC,CAAC,KAAK,KAAK,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QACrD,KAAK,KAAK,CAAC,CAAC,CAAC;YACX,MAAM,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YAC1F,OAAO,IAAI,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,GAAG,GAAG,CAAC;QAC7C,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type CubeTerm } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Identidad polimórfica: λ X:*. λ x:X. x ∈ λ2.
|
|
4
|
+
* Tipo: Π X:*. X → X.
|
|
5
|
+
*/
|
|
6
|
+
export declare function polymorphicIdentity(): CubeTerm;
|
|
7
|
+
/** Tipo de la identidad polimórfica: Π X:*. X → X. */
|
|
8
|
+
export declare function polymorphicIdentityType(): CubeTerm;
|
|
9
|
+
/**
|
|
10
|
+
* Encoding Church de un natural `n` en System F:
|
|
11
|
+
* n = λ X:*. λ s:X→X. λ z:X. s (s (... (s z) ...)) con n aplicaciones
|
|
12
|
+
*
|
|
13
|
+
* Tipo: Π X:*. (X → X) → X → X.
|
|
14
|
+
*/
|
|
15
|
+
export declare function churchNumeral(n: number): CubeTerm;
|
|
16
|
+
/** Tipo de un natural Church: Π X:*. (X → X) → X → X. */
|
|
17
|
+
export declare function churchNumeralType(): CubeTerm;
|
|
18
|
+
/**
|
|
19
|
+
* Tipo polimórfico de pares: Π A:*. Π B:*. (Π C:*. (A → B → C) → C) → ...
|
|
20
|
+
* En la versión sencilla devolvemos solo el tipo de "Pair A B":
|
|
21
|
+
*
|
|
22
|
+
* Π A:*. Π B:*. Π C:*. (A → B → C) → C
|
|
23
|
+
*/
|
|
24
|
+
export declare function churchPairType(): CubeTerm;
|
|
25
|
+
/**
|
|
26
|
+
* Esquema de "lista dependiente": dado un tipo de vectores indexado
|
|
27
|
+
* por `Nat`, devolvemos el Π típico
|
|
28
|
+
*
|
|
29
|
+
* Π n : Nat. Vector n
|
|
30
|
+
*
|
|
31
|
+
* Requiere que el contexto declare `Nat : *` y `Vector : Nat → *`.
|
|
32
|
+
* Atención: ambos extremos son `*`, así que esta Π usa la regla
|
|
33
|
+
* (*,*) y queda legal incluso en λ→ una vez que `Vector` está en el
|
|
34
|
+
* contexto. El sabor "dependiente" viene del hecho de que el
|
|
35
|
+
* codominio menciona el binder `n`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function dependentList(): CubeTerm;
|
|
38
|
+
/**
|
|
39
|
+
* Predicado sobre `Nat`: `Π n:Nat. *`. Domino `Nat : *` y codominio
|
|
40
|
+
* `*` (cuyo sort es `◻`). Esa es justo la formación (*,◻) — exclusiva
|
|
41
|
+
* de los vértices con tipos dependientes (λP, λP2, λPω, λC).
|
|
42
|
+
*
|
|
43
|
+
* Requiere `Nat : *` en el contexto.
|
|
44
|
+
*/
|
|
45
|
+
export declare function predicateOverNat(): CubeTerm;
|
|
46
|
+
/**
|
|
47
|
+
* Operador de tipo `id-type`: λ A:*. A → A en λω.
|
|
48
|
+
* Tipo: * → *.
|
|
49
|
+
*/
|
|
50
|
+
export declare function typeLevelIdentity(): CubeTerm;
|
|
51
|
+
/** Tipo del operador `typeLevelIdentity`: * → *. */
|
|
52
|
+
export declare function typeLevelIdentityKind(): CubeTerm;
|
|
53
|
+
/**
|
|
54
|
+
* En el Calculus of Constructions, el tipo polimórfico
|
|
55
|
+
* Π A:*. A → A
|
|
56
|
+
* vive en el universo `*`.
|
|
57
|
+
*/
|
|
58
|
+
export declare function cocPolyIdentityType(): CubeTerm;
|
|
59
|
+
//# sourceMappingURL=examples.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"examples.d.ts","sourceRoot":"","sources":["../../../src/type-theory/lambda-cube/examples.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,QAAQ,EAAwC,MAAM,SAAS,CAAC;AAE9E;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,QAAQ,CAE9C;AAED,sDAAsD;AACtD,wBAAgB,uBAAuB,IAAI,QAAQ,CAElD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,QAAQ,CAUjD;AAED,yDAAyD;AACzD,wBAAgB,iBAAiB,IAAI,QAAQ,CAG5C;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,IAAI,QAAQ,CAKzC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,IAAI,QAAQ,CAExC;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,IAAI,QAAQ,CAE3C;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,QAAQ,CAE5C;AAED,oDAAoD;AACpD,wBAAgB,qBAAqB,IAAI,QAAQ,CAEhD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,QAAQ,CAE9C"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// Lambda Cube — Términos canónicos
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// Construcciones clásicas de cada vértice del cubo. Cada función
|
|
7
|
+
// devuelve un `CubeTerm` directamente; el tipo correspondiente es
|
|
8
|
+
// inferible con `inferType` en el sistema apropiado.
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.polymorphicIdentity = polymorphicIdentity;
|
|
11
|
+
exports.polymorphicIdentityType = polymorphicIdentityType;
|
|
12
|
+
exports.churchNumeral = churchNumeral;
|
|
13
|
+
exports.churchNumeralType = churchNumeralType;
|
|
14
|
+
exports.churchPairType = churchPairType;
|
|
15
|
+
exports.dependentList = dependentList;
|
|
16
|
+
exports.predicateOverNat = predicateOverNat;
|
|
17
|
+
exports.typeLevelIdentity = typeLevelIdentity;
|
|
18
|
+
exports.typeLevelIdentityKind = typeLevelIdentityKind;
|
|
19
|
+
exports.cocPolyIdentityType = cocPolyIdentityType;
|
|
20
|
+
const types_1 = require("./types");
|
|
21
|
+
/**
|
|
22
|
+
* Identidad polimórfica: λ X:*. λ x:X. x ∈ λ2.
|
|
23
|
+
* Tipo: Π X:*. X → X.
|
|
24
|
+
*/
|
|
25
|
+
function polymorphicIdentity() {
|
|
26
|
+
return (0, types_1.cLam)('X', types_1.cStar, (0, types_1.cLam)('x', (0, types_1.cVar)('X'), (0, types_1.cVar)('x')));
|
|
27
|
+
}
|
|
28
|
+
/** Tipo de la identidad polimórfica: Π X:*. X → X. */
|
|
29
|
+
function polymorphicIdentityType() {
|
|
30
|
+
return (0, types_1.cPi)('X', types_1.cStar, (0, types_1.cArrow)((0, types_1.cVar)('X'), (0, types_1.cVar)('X')));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Encoding Church de un natural `n` en System F:
|
|
34
|
+
* n = λ X:*. λ s:X→X. λ z:X. s (s (... (s z) ...)) con n aplicaciones
|
|
35
|
+
*
|
|
36
|
+
* Tipo: Π X:*. (X → X) → X → X.
|
|
37
|
+
*/
|
|
38
|
+
function churchNumeral(n) {
|
|
39
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
40
|
+
throw new Error(`churchNumeral requiere natural ≥ 0, recibió ${n}`);
|
|
41
|
+
}
|
|
42
|
+
const X = (0, types_1.cVar)('X');
|
|
43
|
+
let body = (0, types_1.cVar)('z');
|
|
44
|
+
for (let i = 0; i < n; i++) {
|
|
45
|
+
body = (0, types_1.cApp)((0, types_1.cVar)('s'), body);
|
|
46
|
+
}
|
|
47
|
+
return (0, types_1.cLam)('X', types_1.cStar, (0, types_1.cLam)('s', (0, types_1.cArrow)(X, X), (0, types_1.cLam)('z', X, body)));
|
|
48
|
+
}
|
|
49
|
+
/** Tipo de un natural Church: Π X:*. (X → X) → X → X. */
|
|
50
|
+
function churchNumeralType() {
|
|
51
|
+
const X = (0, types_1.cVar)('X');
|
|
52
|
+
return (0, types_1.cPi)('X', types_1.cStar, (0, types_1.cArrow)((0, types_1.cArrow)(X, X), (0, types_1.cArrow)(X, X)));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Tipo polimórfico de pares: Π A:*. Π B:*. (Π C:*. (A → B → C) → C) → ...
|
|
56
|
+
* En la versión sencilla devolvemos solo el tipo de "Pair A B":
|
|
57
|
+
*
|
|
58
|
+
* Π A:*. Π B:*. Π C:*. (A → B → C) → C
|
|
59
|
+
*/
|
|
60
|
+
function churchPairType() {
|
|
61
|
+
const A = (0, types_1.cVar)('A');
|
|
62
|
+
const B = (0, types_1.cVar)('B');
|
|
63
|
+
const C = (0, types_1.cVar)('C');
|
|
64
|
+
return (0, types_1.cPi)('A', types_1.cStar, (0, types_1.cPi)('B', types_1.cStar, (0, types_1.cPi)('C', types_1.cStar, (0, types_1.cArrow)((0, types_1.cArrow)(A, (0, types_1.cArrow)(B, C)), C))));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Esquema de "lista dependiente": dado un tipo de vectores indexado
|
|
68
|
+
* por `Nat`, devolvemos el Π típico
|
|
69
|
+
*
|
|
70
|
+
* Π n : Nat. Vector n
|
|
71
|
+
*
|
|
72
|
+
* Requiere que el contexto declare `Nat : *` y `Vector : Nat → *`.
|
|
73
|
+
* Atención: ambos extremos son `*`, así que esta Π usa la regla
|
|
74
|
+
* (*,*) y queda legal incluso en λ→ una vez que `Vector` está en el
|
|
75
|
+
* contexto. El sabor "dependiente" viene del hecho de que el
|
|
76
|
+
* codominio menciona el binder `n`.
|
|
77
|
+
*/
|
|
78
|
+
function dependentList() {
|
|
79
|
+
return (0, types_1.cPi)('n', (0, types_1.cVar)('Nat'), (0, types_1.cApp)((0, types_1.cVar)('Vector'), (0, types_1.cVar)('n')));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Predicado sobre `Nat`: `Π n:Nat. *`. Domino `Nat : *` y codominio
|
|
83
|
+
* `*` (cuyo sort es `◻`). Esa es justo la formación (*,◻) — exclusiva
|
|
84
|
+
* de los vértices con tipos dependientes (λP, λP2, λPω, λC).
|
|
85
|
+
*
|
|
86
|
+
* Requiere `Nat : *` en el contexto.
|
|
87
|
+
*/
|
|
88
|
+
function predicateOverNat() {
|
|
89
|
+
return (0, types_1.cPi)('n', (0, types_1.cVar)('Nat'), types_1.cStar);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Operador de tipo `id-type`: λ A:*. A → A en λω.
|
|
93
|
+
* Tipo: * → *.
|
|
94
|
+
*/
|
|
95
|
+
function typeLevelIdentity() {
|
|
96
|
+
return (0, types_1.cLam)('A', types_1.cStar, (0, types_1.cArrow)((0, types_1.cVar)('A'), (0, types_1.cVar)('A')));
|
|
97
|
+
}
|
|
98
|
+
/** Tipo del operador `typeLevelIdentity`: * → *. */
|
|
99
|
+
function typeLevelIdentityKind() {
|
|
100
|
+
return (0, types_1.cArrow)(types_1.cStar, types_1.cStar);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* En el Calculus of Constructions, el tipo polimórfico
|
|
104
|
+
* Π A:*. A → A
|
|
105
|
+
* vive en el universo `*`.
|
|
106
|
+
*/
|
|
107
|
+
function cocPolyIdentityType() {
|
|
108
|
+
return (0, types_1.cPi)('A', types_1.cStar, (0, types_1.cArrow)((0, types_1.cVar)('A'), (0, types_1.cVar)('A')));
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=examples.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"examples.js","sourceRoot":"","sources":["../../../src/type-theory/lambda-cube/examples.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,mCAAmC;AACnC,+DAA+D;AAC/D,EAAE;AACF,iEAAiE;AACjE,kEAAkE;AAClE,qDAAqD;;AAQrD,kDAEC;AAGD,0DAEC;AAQD,sCAUC;AAGD,8CAGC;AAQD,wCAKC;AAcD,sCAEC;AASD,4CAEC;AAMD,8CAEC;AAGD,sDAEC;AAOD,kDAEC;AAnGD,mCAA8E;AAE9E;;;GAGG;AACH,SAAgB,mBAAmB;IACjC,OAAO,IAAA,YAAI,EAAC,GAAG,EAAE,aAAK,EAAE,IAAA,YAAI,EAAC,GAAG,EAAE,IAAA,YAAI,EAAC,GAAG,CAAC,EAAE,IAAA,YAAI,EAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED,sDAAsD;AACtD,SAAgB,uBAAuB;IACrC,OAAO,IAAA,WAAG,EAAC,GAAG,EAAE,aAAK,EAAE,IAAA,cAAM,EAAC,IAAA,YAAI,EAAC,GAAG,CAAC,EAAE,IAAA,YAAI,EAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC;AAED;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,CAAS;IACrC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,EAAE,CAA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AAC,EAAE,IAAA,cAAM,EAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/F,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,aAAa;IAC3B,OAAO,IAAA,WAAG,EAAC,GAAG,EAAE,IAAA,YAAI,EAAC,KAAK,CAAC,EAAE,IAAA,YAAI,EAAC,IAAA,YAAI,EAAC,QAAQ,CAAC,EAAE,IAAA,YAAI,EAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAChE,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,gBAAgB;IAC9B,OAAO,IAAA,WAAG,EAAC,GAAG,EAAE,IAAA,YAAI,EAAC,KAAK,CAAC,EAAE,aAAK,CAAC,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,SAAgB,iBAAiB;IAC/B,OAAO,IAAA,YAAI,EAAC,GAAG,EAAE,aAAK,EAAE,IAAA,cAAM,EAAC,IAAA,YAAI,EAAC,GAAG,CAAC,EAAE,IAAA,YAAI,EAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,oDAAoD;AACpD,SAAgB,qBAAqB;IACnC,OAAO,IAAA,cAAM,EAAC,aAAK,EAAE,aAAK,CAAC,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB;IACjC,OAAO,IAAA,WAAG,EAAC,GAAG,EAAE,aAAK,EAAE,IAAA,cAAM,EAAC,IAAA,YAAI,EAAC,GAAG,CAAC,EAAE,IAAA,YAAI,EAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type { Sort, CubeSystem, CubeTerm, CubeContext } from './types';
|
|
2
|
+
export { cVar, cSort, cStar, cBox, cPi, cLam, cApp, cArrow, occursFree, freeVars, termToString, alphaEq, emptyContext, extendContext, } from './types';
|
|
3
|
+
export type { FormationRule, CubeRules } from './rules';
|
|
4
|
+
export { SYSTEMS, hasRule, rulesOf, AXIOMS, axiomFor } from './rules';
|
|
5
|
+
export { substitute, reduceStep, normalize, alphaBetaEq, isNormal } from './normalize';
|
|
6
|
+
export type { InferError, InferResult } from './typecheck';
|
|
7
|
+
export { inferType, checkType, isInferError, isClosedUnder } from './typecheck';
|
|
8
|
+
export type { UntypedTerm, EraseError } from './erase';
|
|
9
|
+
export { erase, isEraseError, untypedToString } from './erase';
|
|
10
|
+
export { polymorphicIdentity, polymorphicIdentityType, churchNumeral, churchNumeralType, churchPairType, dependentList, predicateOverNat, typeLevelIdentity, typeLevelIdentityKind, cocPolyIdentityType, } from './examples';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/type-theory/lambda-cube/index.ts"],"names":[],"mappings":"AAcA,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACvE,OAAO,EACL,IAAI,EACJ,KAAK,EACL,KAAK,EACL,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,aAAa,GACd,MAAM,SAAS,CAAC;AAEjB,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEtE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvF,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEhF,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/D,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// Lambda Cube (Barendregt) — API pública
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// Implementación uniforme de los 8 vértices del cubo λ como un Pure
|
|
7
|
+
// Type System (PTS) parametrizado por el conjunto de reglas de
|
|
8
|
+
// formación. Permite:
|
|
9
|
+
//
|
|
10
|
+
// - inferType / checkType en cualquier vértice (λ→, λ2, λω, λC, ...).
|
|
11
|
+
// - normalize por β-reducción (call-by-name).
|
|
12
|
+
// - erase a λ-cálculo no tipado.
|
|
13
|
+
// - Construcciones canónicas: identity polimórfico, Church numerals,
|
|
14
|
+
// id-type operator, dependent list schema, etc.
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.cocPolyIdentityType = exports.typeLevelIdentityKind = exports.typeLevelIdentity = exports.predicateOverNat = exports.dependentList = exports.churchPairType = exports.churchNumeralType = exports.churchNumeral = exports.polymorphicIdentityType = exports.polymorphicIdentity = exports.untypedToString = exports.isEraseError = exports.erase = exports.isClosedUnder = exports.isInferError = exports.checkType = exports.inferType = exports.isNormal = exports.alphaBetaEq = exports.normalize = exports.reduceStep = exports.substitute = exports.axiomFor = exports.AXIOMS = exports.rulesOf = exports.hasRule = exports.SYSTEMS = exports.extendContext = exports.emptyContext = exports.alphaEq = exports.termToString = exports.freeVars = exports.occursFree = exports.cArrow = exports.cApp = exports.cLam = exports.cPi = exports.cBox = exports.cStar = exports.cSort = exports.cVar = void 0;
|
|
17
|
+
var types_1 = require("./types");
|
|
18
|
+
Object.defineProperty(exports, "cVar", { enumerable: true, get: function () { return types_1.cVar; } });
|
|
19
|
+
Object.defineProperty(exports, "cSort", { enumerable: true, get: function () { return types_1.cSort; } });
|
|
20
|
+
Object.defineProperty(exports, "cStar", { enumerable: true, get: function () { return types_1.cStar; } });
|
|
21
|
+
Object.defineProperty(exports, "cBox", { enumerable: true, get: function () { return types_1.cBox; } });
|
|
22
|
+
Object.defineProperty(exports, "cPi", { enumerable: true, get: function () { return types_1.cPi; } });
|
|
23
|
+
Object.defineProperty(exports, "cLam", { enumerable: true, get: function () { return types_1.cLam; } });
|
|
24
|
+
Object.defineProperty(exports, "cApp", { enumerable: true, get: function () { return types_1.cApp; } });
|
|
25
|
+
Object.defineProperty(exports, "cArrow", { enumerable: true, get: function () { return types_1.cArrow; } });
|
|
26
|
+
Object.defineProperty(exports, "occursFree", { enumerable: true, get: function () { return types_1.occursFree; } });
|
|
27
|
+
Object.defineProperty(exports, "freeVars", { enumerable: true, get: function () { return types_1.freeVars; } });
|
|
28
|
+
Object.defineProperty(exports, "termToString", { enumerable: true, get: function () { return types_1.termToString; } });
|
|
29
|
+
Object.defineProperty(exports, "alphaEq", { enumerable: true, get: function () { return types_1.alphaEq; } });
|
|
30
|
+
Object.defineProperty(exports, "emptyContext", { enumerable: true, get: function () { return types_1.emptyContext; } });
|
|
31
|
+
Object.defineProperty(exports, "extendContext", { enumerable: true, get: function () { return types_1.extendContext; } });
|
|
32
|
+
var rules_1 = require("./rules");
|
|
33
|
+
Object.defineProperty(exports, "SYSTEMS", { enumerable: true, get: function () { return rules_1.SYSTEMS; } });
|
|
34
|
+
Object.defineProperty(exports, "hasRule", { enumerable: true, get: function () { return rules_1.hasRule; } });
|
|
35
|
+
Object.defineProperty(exports, "rulesOf", { enumerable: true, get: function () { return rules_1.rulesOf; } });
|
|
36
|
+
Object.defineProperty(exports, "AXIOMS", { enumerable: true, get: function () { return rules_1.AXIOMS; } });
|
|
37
|
+
Object.defineProperty(exports, "axiomFor", { enumerable: true, get: function () { return rules_1.axiomFor; } });
|
|
38
|
+
var normalize_1 = require("./normalize");
|
|
39
|
+
Object.defineProperty(exports, "substitute", { enumerable: true, get: function () { return normalize_1.substitute; } });
|
|
40
|
+
Object.defineProperty(exports, "reduceStep", { enumerable: true, get: function () { return normalize_1.reduceStep; } });
|
|
41
|
+
Object.defineProperty(exports, "normalize", { enumerable: true, get: function () { return normalize_1.normalize; } });
|
|
42
|
+
Object.defineProperty(exports, "alphaBetaEq", { enumerable: true, get: function () { return normalize_1.alphaBetaEq; } });
|
|
43
|
+
Object.defineProperty(exports, "isNormal", { enumerable: true, get: function () { return normalize_1.isNormal; } });
|
|
44
|
+
var typecheck_1 = require("./typecheck");
|
|
45
|
+
Object.defineProperty(exports, "inferType", { enumerable: true, get: function () { return typecheck_1.inferType; } });
|
|
46
|
+
Object.defineProperty(exports, "checkType", { enumerable: true, get: function () { return typecheck_1.checkType; } });
|
|
47
|
+
Object.defineProperty(exports, "isInferError", { enumerable: true, get: function () { return typecheck_1.isInferError; } });
|
|
48
|
+
Object.defineProperty(exports, "isClosedUnder", { enumerable: true, get: function () { return typecheck_1.isClosedUnder; } });
|
|
49
|
+
var erase_1 = require("./erase");
|
|
50
|
+
Object.defineProperty(exports, "erase", { enumerable: true, get: function () { return erase_1.erase; } });
|
|
51
|
+
Object.defineProperty(exports, "isEraseError", { enumerable: true, get: function () { return erase_1.isEraseError; } });
|
|
52
|
+
Object.defineProperty(exports, "untypedToString", { enumerable: true, get: function () { return erase_1.untypedToString; } });
|
|
53
|
+
var examples_1 = require("./examples");
|
|
54
|
+
Object.defineProperty(exports, "polymorphicIdentity", { enumerable: true, get: function () { return examples_1.polymorphicIdentity; } });
|
|
55
|
+
Object.defineProperty(exports, "polymorphicIdentityType", { enumerable: true, get: function () { return examples_1.polymorphicIdentityType; } });
|
|
56
|
+
Object.defineProperty(exports, "churchNumeral", { enumerable: true, get: function () { return examples_1.churchNumeral; } });
|
|
57
|
+
Object.defineProperty(exports, "churchNumeralType", { enumerable: true, get: function () { return examples_1.churchNumeralType; } });
|
|
58
|
+
Object.defineProperty(exports, "churchPairType", { enumerable: true, get: function () { return examples_1.churchPairType; } });
|
|
59
|
+
Object.defineProperty(exports, "dependentList", { enumerable: true, get: function () { return examples_1.dependentList; } });
|
|
60
|
+
Object.defineProperty(exports, "predicateOverNat", { enumerable: true, get: function () { return examples_1.predicateOverNat; } });
|
|
61
|
+
Object.defineProperty(exports, "typeLevelIdentity", { enumerable: true, get: function () { return examples_1.typeLevelIdentity; } });
|
|
62
|
+
Object.defineProperty(exports, "typeLevelIdentityKind", { enumerable: true, get: function () { return examples_1.typeLevelIdentityKind; } });
|
|
63
|
+
Object.defineProperty(exports, "cocPolyIdentityType", { enumerable: true, get: function () { return examples_1.cocPolyIdentityType; } });
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/type-theory/lambda-cube/index.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,yCAAyC;AACzC,+DAA+D;AAC/D,EAAE;AACF,oEAAoE;AACpE,+DAA+D;AAC/D,sBAAsB;AACtB,EAAE;AACF,wEAAwE;AACxE,gDAAgD;AAChD,mCAAmC;AACnC,uEAAuE;AACvE,oDAAoD;;;AAGpD,iCAeiB;AAdf,6FAAA,IAAI,OAAA;AACJ,8FAAA,KAAK,OAAA;AACL,8FAAA,KAAK,OAAA;AACL,6FAAA,IAAI,OAAA;AACJ,4FAAA,GAAG,OAAA;AACH,6FAAA,IAAI,OAAA;AACJ,6FAAA,IAAI,OAAA;AACJ,+FAAA,MAAM,OAAA;AACN,mGAAA,UAAU,OAAA;AACV,iGAAA,QAAQ,OAAA;AACR,qGAAA,YAAY,OAAA;AACZ,gGAAA,OAAO,OAAA;AACP,qGAAA,YAAY,OAAA;AACZ,sGAAA,aAAa,OAAA;AAIf,iCAAsE;AAA7D,gGAAA,OAAO,OAAA;AAAE,gGAAA,OAAO,OAAA;AAAE,gGAAA,OAAO,OAAA;AAAE,+FAAA,MAAM,OAAA;AAAE,iGAAA,QAAQ,OAAA;AAEpD,yCAAuF;AAA9E,uGAAA,UAAU,OAAA;AAAE,uGAAA,UAAU,OAAA;AAAE,sGAAA,SAAS,OAAA;AAAE,wGAAA,WAAW,OAAA;AAAE,qGAAA,QAAQ,OAAA;AAGjE,yCAAgF;AAAvE,sGAAA,SAAS,OAAA;AAAE,sGAAA,SAAS,OAAA;AAAE,yGAAA,YAAY,OAAA;AAAE,0GAAA,aAAa,OAAA;AAG1D,iCAA+D;AAAtD,8FAAA,KAAK,OAAA;AAAE,qGAAA,YAAY,OAAA;AAAE,wGAAA,eAAe,OAAA;AAE7C,uCAWoB;AAVlB,+GAAA,mBAAmB,OAAA;AACnB,mHAAA,uBAAuB,OAAA;AACvB,yGAAA,aAAa,OAAA;AACb,6GAAA,iBAAiB,OAAA;AACjB,0GAAA,cAAc,OAAA;AACd,yGAAA,aAAa,OAAA;AACb,4GAAA,gBAAgB,OAAA;AAChB,6GAAA,iBAAiB,OAAA;AACjB,iHAAA,qBAAqB,OAAA;AACrB,+GAAA,mBAAmB,OAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CubeSystem } from './types';
|
|
2
|
+
import { type CubeTerm } from './types';
|
|
3
|
+
/** Sustitución capture-avoiding: term[value/name]. */
|
|
4
|
+
export declare function substitute(term: CubeTerm, name: string, value: CubeTerm): CubeTerm;
|
|
5
|
+
/**
|
|
6
|
+
* Un paso de β-reducción top-down (call-by-name): si el término es
|
|
7
|
+
* `(λ x:A. b) arg`, devuelve `b[arg/x]`. Si no hay redex top-level,
|
|
8
|
+
* intenta reducir en sub-términos.
|
|
9
|
+
*/
|
|
10
|
+
export declare function reduceStep(term: CubeTerm): CubeTerm | undefined;
|
|
11
|
+
/** Normaliza por reducción a normal-form. `maxSteps` evita loops divergentes. */
|
|
12
|
+
export declare function normalize(term: CubeTerm, _system: CubeSystem, maxSteps?: number): CubeTerm;
|
|
13
|
+
/** ¿Dos términos son iguales módulo α y β? */
|
|
14
|
+
export declare function alphaBetaEq(a: CubeTerm, b: CubeTerm, system: CubeSystem): boolean;
|
|
15
|
+
/** ¿El término está en forma normal (no quedan β-redex)? */
|
|
16
|
+
export declare function isNormal(term: CubeTerm): boolean;
|
|
17
|
+
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../src/type-theory/lambda-cube/normalize.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,KAAK,QAAQ,EAAqB,MAAM,SAAS,CAAC;AAU3D,sDAAsD;AACtD,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,QAAQ,CA2BlF;AA0BD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAgC/D;AAED,iFAAiF;AACjF,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,SAAO,GAAG,QAAQ,CAQxF;AAED,8CAA8C;AAC9C,wBAAgB,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAKjF;AAED,4DAA4D;AAC5D,wBAAgB,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAEhD"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// Lambda Cube — Sustitución capture-avoiding + β-normalización
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// Al ser un Pure Type System, tipos y términos comparten sintaxis.
|
|
7
|
+
// La β-reducción ocurre en cualquier sub-término, así que normalize
|
|
8
|
+
// también reduce dentro de Π y dentro del dominio de λ.
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.substitute = substitute;
|
|
11
|
+
exports.reduceStep = reduceStep;
|
|
12
|
+
exports.normalize = normalize;
|
|
13
|
+
exports.alphaBetaEq = alphaBetaEq;
|
|
14
|
+
exports.isNormal = isNormal;
|
|
15
|
+
const types_1 = require("./types");
|
|
16
|
+
let freshCounter = 0;
|
|
17
|
+
function fresh(base, avoid) {
|
|
18
|
+
let candidate = `${base}#${freshCounter++}`;
|
|
19
|
+
while (avoid.has(candidate))
|
|
20
|
+
candidate = `${base}#${freshCounter++}`;
|
|
21
|
+
return candidate;
|
|
22
|
+
}
|
|
23
|
+
/** Sustitución capture-avoiding: term[value/name]. */
|
|
24
|
+
function substitute(term, name, value) {
|
|
25
|
+
switch (term.kind) {
|
|
26
|
+
case 'var':
|
|
27
|
+
return term.name === name ? value : term;
|
|
28
|
+
case 'sort':
|
|
29
|
+
return term;
|
|
30
|
+
case 'pi':
|
|
31
|
+
return substBinder(term.bind, term.domain, term.codomain, name, value, (b, d, c) => ({
|
|
32
|
+
kind: 'pi',
|
|
33
|
+
bind: b,
|
|
34
|
+
domain: d,
|
|
35
|
+
codomain: c,
|
|
36
|
+
}));
|
|
37
|
+
case 'lam':
|
|
38
|
+
return substBinder(term.bind, term.domain, term.body, name, value, (b, d, c) => ({
|
|
39
|
+
kind: 'lam',
|
|
40
|
+
bind: b,
|
|
41
|
+
domain: d,
|
|
42
|
+
body: c,
|
|
43
|
+
}));
|
|
44
|
+
case 'app':
|
|
45
|
+
return {
|
|
46
|
+
kind: 'app',
|
|
47
|
+
fn: substitute(term.fn, name, value),
|
|
48
|
+
arg: substitute(term.arg, name, value),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function substBinder(bind, dom, body, name, value, build) {
|
|
53
|
+
const newDom = substitute(dom, name, value);
|
|
54
|
+
// Si el binder coincide con `name`, `body` no contiene `name` libre.
|
|
55
|
+
if (bind === name) {
|
|
56
|
+
return build(bind, newDom, body);
|
|
57
|
+
}
|
|
58
|
+
const fv = (0, types_1.freeVars)(value);
|
|
59
|
+
if (fv.has(bind)) {
|
|
60
|
+
const newBind = fresh(bind, new Set([...fv, ...(0, types_1.freeVars)(body), name]));
|
|
61
|
+
const renamed = substitute(body, bind, { kind: 'var', name: newBind });
|
|
62
|
+
return build(newBind, newDom, substitute(renamed, name, value));
|
|
63
|
+
}
|
|
64
|
+
return build(bind, newDom, substitute(body, name, value));
|
|
65
|
+
}
|
|
66
|
+
// ---------- β-reducción ----------
|
|
67
|
+
/**
|
|
68
|
+
* Un paso de β-reducción top-down (call-by-name): si el término es
|
|
69
|
+
* `(λ x:A. b) arg`, devuelve `b[arg/x]`. Si no hay redex top-level,
|
|
70
|
+
* intenta reducir en sub-términos.
|
|
71
|
+
*/
|
|
72
|
+
function reduceStep(term) {
|
|
73
|
+
switch (term.kind) {
|
|
74
|
+
case 'var':
|
|
75
|
+
case 'sort':
|
|
76
|
+
return undefined;
|
|
77
|
+
case 'app': {
|
|
78
|
+
// β-redex top-level
|
|
79
|
+
if (term.fn.kind === 'lam') {
|
|
80
|
+
return substitute(term.fn.body, term.fn.bind, term.arg);
|
|
81
|
+
}
|
|
82
|
+
// Reducir fn primero (call-by-name)
|
|
83
|
+
const fnRed = reduceStep(term.fn);
|
|
84
|
+
if (fnRed)
|
|
85
|
+
return { kind: 'app', fn: fnRed, arg: term.arg };
|
|
86
|
+
const argRed = reduceStep(term.arg);
|
|
87
|
+
if (argRed)
|
|
88
|
+
return { kind: 'app', fn: term.fn, arg: argRed };
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
case 'pi': {
|
|
92
|
+
const dom = reduceStep(term.domain);
|
|
93
|
+
if (dom)
|
|
94
|
+
return { kind: 'pi', bind: term.bind, domain: dom, codomain: term.codomain };
|
|
95
|
+
const cod = reduceStep(term.codomain);
|
|
96
|
+
if (cod)
|
|
97
|
+
return { kind: 'pi', bind: term.bind, domain: term.domain, codomain: cod };
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
case 'lam': {
|
|
101
|
+
const dom = reduceStep(term.domain);
|
|
102
|
+
if (dom)
|
|
103
|
+
return { kind: 'lam', bind: term.bind, domain: dom, body: term.body };
|
|
104
|
+
const body = reduceStep(term.body);
|
|
105
|
+
if (body)
|
|
106
|
+
return { kind: 'lam', bind: term.bind, domain: term.domain, body };
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** Normaliza por reducción a normal-form. `maxSteps` evita loops divergentes. */
|
|
112
|
+
function normalize(term, _system, maxSteps = 1000) {
|
|
113
|
+
let current = term;
|
|
114
|
+
for (let i = 0; i < maxSteps; i++) {
|
|
115
|
+
const next = reduceStep(current);
|
|
116
|
+
if (next === undefined)
|
|
117
|
+
return current;
|
|
118
|
+
current = next;
|
|
119
|
+
}
|
|
120
|
+
return current;
|
|
121
|
+
}
|
|
122
|
+
/** ¿Dos términos son iguales módulo α y β? */
|
|
123
|
+
function alphaBetaEq(a, b, system) {
|
|
124
|
+
if ((0, types_1.alphaEq)(a, b))
|
|
125
|
+
return true;
|
|
126
|
+
const na = normalize(a, system);
|
|
127
|
+
const nb = normalize(b, system);
|
|
128
|
+
return (0, types_1.alphaEq)(na, nb);
|
|
129
|
+
}
|
|
130
|
+
/** ¿El término está en forma normal (no quedan β-redex)? */
|
|
131
|
+
function isNormal(term) {
|
|
132
|
+
return reduceStep(term) === undefined;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=normalize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","s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CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,8CAA8C;AAC9C,SAAgB,WAAW,CAAC,CAAW,EAAE,CAAW,EAAE,MAAkB;IACtE,IAAI,IAAA,eAAO,EAAC,CAAC,EAAE,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAC/B,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAChC,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,IAAA,eAAO,EAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AACzB,CAAC;AAED,4DAA4D;AAC5D,SAAgB,QAAQ,CAAC,IAAc;IACrC,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CubeSystem, Sort } from './types';
|
|
2
|
+
export interface FormationRule {
|
|
3
|
+
from: Sort;
|
|
4
|
+
to: Sort;
|
|
5
|
+
}
|
|
6
|
+
export interface CubeRules {
|
|
7
|
+
formationRules: FormationRule[];
|
|
8
|
+
}
|
|
9
|
+
export declare const SYSTEMS: Record<CubeSystem, CubeRules>;
|
|
10
|
+
/** ¿El par (s1, s2) está en las reglas de formación de `system`? */
|
|
11
|
+
export declare function hasRule(system: CubeSystem, from: Sort, to: Sort): boolean;
|
|
12
|
+
/** Conjunto de pares de formación de un sistema, en orden canónico. */
|
|
13
|
+
export declare function rulesOf(system: CubeSystem): FormationRule[];
|
|
14
|
+
/**
|
|
15
|
+
* Reglas de axioma. En el cubo Barendregt clásico el único axioma es
|
|
16
|
+
* * : ◻
|
|
17
|
+
* (no hay jerarquía de universos: ◻ no tiene tipo propio, por eso los
|
|
18
|
+
* términos del cubo no pueden anidar ◻ : ?). Si se intentara tipar ◻
|
|
19
|
+
* directamente, el typechecker reportará error.
|
|
20
|
+
*/
|
|
21
|
+
export declare const AXIOMS: Array<{
|
|
22
|
+
sort: Sort;
|
|
23
|
+
type: Sort;
|
|
24
|
+
}>;
|
|
25
|
+
export declare function axiomFor(sort: Sort): Sort | undefined;
|
|
26
|
+
//# sourceMappingURL=rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../../src/type-theory/lambda-cube/rules.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAEhD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,IAAI,CAAC;IACX,EAAE,EAAE,IAAI,CAAC;CACV;AAED,MAAM,WAAW,SAAS;IACxB,cAAc,EAAE,aAAa,EAAE,CAAC;CACjC;AAOD,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,UAAU,EAAE,SAAS,CASjD,CAAC;AAEF,oEAAoE;AACpE,wBAAgB,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,GAAG,OAAO,CAMzE;AAED,uEAAuE;AACvE,wBAAgB,OAAO,CAAC,MAAM,EAAE,UAAU,GAAG,aAAa,EAAE,CAE3D;AAED;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAA8B,CAAC;AAEpF,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,CAKrD"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// Lambda Cube — Pure Type System rules per vértice
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// Cada sistema del cubo se identifica por su conjunto de reglas de
|
|
7
|
+
// formación (s1, s2): bajo qué sorts es legal formar `Π x:A. B` donde
|
|
8
|
+
// `A : s1` y `B : s2`.
|
|
9
|
+
//
|
|
10
|
+
// La regla común a todos los sistemas es (*, *) — la flecha sobre
|
|
11
|
+
// términos del λ-cálculo simplemente tipado. Las otras tres se
|
|
12
|
+
// "encienden" según la posición en el cubo:
|
|
13
|
+
//
|
|
14
|
+
// eje X (◻, *) — polimorfismo: cuantificar sobre tipos
|
|
15
|
+
// eje Y (◻, ◻) — operadores de tipo: funciones type→type
|
|
16
|
+
// eje Z (*, ◻) — tipos dependientes: tipo que depende de un valor
|
|
17
|
+
//
|
|
18
|
+
// Cualquier subconjunto que contenga (*, *) da un PTS coherente.
|
|
19
|
+
// El número total de vértices es 2^3 = 8.
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.AXIOMS = exports.SYSTEMS = void 0;
|
|
22
|
+
exports.hasRule = hasRule;
|
|
23
|
+
exports.rulesOf = rulesOf;
|
|
24
|
+
exports.axiomFor = axiomFor;
|
|
25
|
+
const BASE = { from: '*', to: '*' };
|
|
26
|
+
const POLY = { from: '◻', to: '*' };
|
|
27
|
+
const OPS = { from: '◻', to: '◻' };
|
|
28
|
+
const DEP = { from: '*', to: '◻' };
|
|
29
|
+
exports.SYSTEMS = {
|
|
30
|
+
lambda: { formationRules: [BASE] },
|
|
31
|
+
lambda2: { formationRules: [BASE, POLY] },
|
|
32
|
+
'lambda-omega-bar': { formationRules: [BASE, OPS] },
|
|
33
|
+
'lambda-omega': { formationRules: [BASE, POLY, OPS] },
|
|
34
|
+
'lambda-P': { formationRules: [BASE, DEP] },
|
|
35
|
+
'lambda-P2': { formationRules: [BASE, POLY, DEP] },
|
|
36
|
+
'lambda-P-omega': { formationRules: [BASE, OPS, DEP] },
|
|
37
|
+
'lambda-C': { formationRules: [BASE, POLY, OPS, DEP] },
|
|
38
|
+
};
|
|
39
|
+
/** ¿El par (s1, s2) está en las reglas de formación de `system`? */
|
|
40
|
+
function hasRule(system, from, to) {
|
|
41
|
+
const rules = exports.SYSTEMS[system].formationRules;
|
|
42
|
+
for (const r of rules) {
|
|
43
|
+
if (r.from === from && r.to === to)
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
/** Conjunto de pares de formación de un sistema, en orden canónico. */
|
|
49
|
+
function rulesOf(system) {
|
|
50
|
+
return exports.SYSTEMS[system].formationRules;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Reglas de axioma. En el cubo Barendregt clásico el único axioma es
|
|
54
|
+
* * : ◻
|
|
55
|
+
* (no hay jerarquía de universos: ◻ no tiene tipo propio, por eso los
|
|
56
|
+
* términos del cubo no pueden anidar ◻ : ?). Si se intentara tipar ◻
|
|
57
|
+
* directamente, el typechecker reportará error.
|
|
58
|
+
*/
|
|
59
|
+
exports.AXIOMS = [{ sort: '*', type: '◻' }];
|
|
60
|
+
function axiomFor(sort) {
|
|
61
|
+
for (const a of exports.AXIOMS) {
|
|
62
|
+
if (a.sort === sort)
|
|
63
|
+
return a.type;
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=rules.js.map
|