@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
package/README.md
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
**ST** es un lenguaje ejecutable para lógica, argumentación y formalización documental.
|
|
8
8
|
Combina verificación formal, scripting declarativo, control de flujo, funciones, perfiles lógicos múltiples y una **Text Layer** para conectar fórmulas con texto humano real.
|
|
9
9
|
|
|
10
|
-
[](package.json)
|
|
11
|
+
[]()
|
|
11
12
|
[](LICENSE)
|
|
12
13
|
[]()
|
|
13
14
|
|
|
@@ -37,7 +38,7 @@ Combina verificación formal, scripting declarativo, control de flujo, funciones
|
|
|
37
38
|
### Con npm
|
|
38
39
|
|
|
39
40
|
```bash
|
|
40
|
-
npm install
|
|
41
|
+
npm install @stevenvo780/st-lang@4.5.0
|
|
41
42
|
```
|
|
42
43
|
|
|
43
44
|
### Desde el código fuente
|
|
@@ -52,41 +53,72 @@ npm link
|
|
|
52
53
|
|
|
53
54
|
---
|
|
54
55
|
|
|
55
|
-
##
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
###
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
56
|
+
## What's new in V4 (4.0 → 4.5.0)
|
|
57
|
+
|
|
58
|
+
52+ módulos nuevos. 4041 tests (eran 1583 en v3.3).
|
|
59
|
+
|
|
60
|
+
### Performance & SAT
|
|
61
|
+
- CDCL v2 con VSIDS, clause learning y reinicios Luby.
|
|
62
|
+
- SAT incremental — reutiliza estado entre consultas.
|
|
63
|
+
- MUS (Minimal Unsatisfiable Subsets) para diagnóstico de inconsistencias.
|
|
64
|
+
- Cache de derivaciones con memoización y theorem-cache persistente.
|
|
65
|
+
|
|
66
|
+
### Type theory
|
|
67
|
+
- Curry-Howard: pruebas como programas, términos como tipos.
|
|
68
|
+
- System F con polimorfismo paramétrico.
|
|
69
|
+
- MLTT (Martin-Löf Type Theory) con tipos dependientes.
|
|
70
|
+
- NbE (Normalización por Evaluación) para reducción eficiente.
|
|
71
|
+
- Refinement types sobre términos base.
|
|
72
|
+
|
|
73
|
+
### Modal & temporal
|
|
74
|
+
- Frame axioms K / T / B / 4 / 5 / D; sistemas S4, S5, KD45 completos.
|
|
75
|
+
- CTL (Computation Tree Logic) con operadores EX/AX/EF/AF/EG/AG.
|
|
76
|
+
- LTL (Linear Temporal Logic) con next/until/release.
|
|
77
|
+
- μ-calculus modal con punto fijo mínimo y máximo.
|
|
78
|
+
- Hybrid logic con operadores de nombrado y satisfacción (@).
|
|
79
|
+
|
|
80
|
+
### Substructural & resource logic
|
|
81
|
+
- Lógica lineal y afín (no-contraction, no-weakening).
|
|
82
|
+
- π-calculus: razonamiento sobre procesos concurrentes.
|
|
83
|
+
- Proof nets: representación canónica de pruebas lineales.
|
|
84
|
+
|
|
85
|
+
### Non-classical
|
|
86
|
+
- Intuicionista NJ (natural deduction intuicionista completa).
|
|
87
|
+
- Lógica many-valued (Łukasiewicz, Gödel) y Belnap four-valued.
|
|
88
|
+
- Paraconsistente — soporte para contradicciones sin explosión.
|
|
89
|
+
|
|
90
|
+
### Decision procedures
|
|
91
|
+
- FOL con igualdad — resolución para fragmentos decidibles.
|
|
92
|
+
- ALC Description Logic (subsumption, instance checking).
|
|
93
|
+
- AC-3 CSP — constraint propagation para problemas de satisfacción.
|
|
94
|
+
- STRIPS — planificación clásica sobre estados y acciones.
|
|
95
|
+
|
|
96
|
+
### Probabilistic & uncertainty
|
|
97
|
+
- Bayesian reasoning con redes y propagación de evidencia.
|
|
98
|
+
- Hyperreal extensions: probabilidad con infinitesimales.
|
|
99
|
+
- Fuzzy logic — valores de verdad continuos en [0,1].
|
|
100
|
+
|
|
101
|
+
### Term mechanics
|
|
102
|
+
- TRS + KB (Term Rewriting Systems + Knuth-Bendix completion).
|
|
103
|
+
- Anti-unification — lgg (least general generalization) de términos.
|
|
104
|
+
- HO-unify (Higher-Order Unification).
|
|
105
|
+
- SKI combinators y reducción.
|
|
106
|
+
- λ-calculus con α/β/η reducción.
|
|
107
|
+
|
|
108
|
+
### Integration
|
|
109
|
+
- Text Layer v2 con invalidación propagada de claims.
|
|
110
|
+
- MDX bridge bidireccional: prosa ↔ ST sincronizados.
|
|
111
|
+
- Proof exchange Ed25519: pruebas firmadas y compartibles entre workspaces.
|
|
112
|
+
- Time-travel: snapshots ST por commit de workspace.
|
|
113
|
+
- Plugin system: perfiles lógicos custom registrables en runtime.
|
|
114
|
+
|
|
115
|
+
### Knowledge & argumentation
|
|
116
|
+
- FCA (Formal Concept Analysis) — retículos de conceptos formales.
|
|
117
|
+
- Dung argumentation — grafos de ataque, extensiones admisibles/estables.
|
|
118
|
+
- Default logic — inferencia por defecto con excepciones.
|
|
119
|
+
- AGM belief revision — cambio de creencias con postulados AGM.
|
|
120
|
+
- Abduction — inferencia a la mejor explicación.
|
|
121
|
+
- Profile bridge — mapeo semántico entre perfiles lógicos.
|
|
90
122
|
|
|
91
123
|
---
|
|
92
124
|
|
|
@@ -403,6 +435,15 @@ st.exec('logic arithmetic');
|
|
|
403
435
|
st.exec('explain 2 + 3 * 4');
|
|
404
436
|
```
|
|
405
437
|
|
|
438
|
+
### Subpaths disponibles
|
|
439
|
+
|
|
440
|
+
| Subpath | Uso |
|
|
441
|
+
|---------|-----|
|
|
442
|
+
| `@stevenvo780/st-lang` | Entrypoint principal: `evaluate`, `typeCheck`, `createInterpreter` |
|
|
443
|
+
| `@stevenvo780/st-lang/api` | API pura sin CLI: `evaluate`, `createInterpreter` |
|
|
444
|
+
| `@stevenvo780/st-lang/types` | Tipos TypeScript exportados (AST, perfiles, resultados) |
|
|
445
|
+
| `@stevenvo780/st-lang/protocol` | `ProtocolHandler` para integraciones de editor |
|
|
446
|
+
|
|
406
447
|
---
|
|
407
448
|
|
|
408
449
|
## Carpeta `examples/`
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
export interface Stream<T> {
|
|
2
|
+
head: T;
|
|
3
|
+
tail: () => Stream<T>;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Cons explícito: crea un stream con cabeza `h` y cola perezosa
|
|
7
|
+
* `t` (una función que produce el resto cuando se evalúa).
|
|
8
|
+
*/
|
|
9
|
+
export declare function cons<T>(h: T, t: () => Stream<T>): Stream<T>;
|
|
10
|
+
/**
|
|
11
|
+
* `repeat(x)` = x, x, x, ... (stream constante)
|
|
12
|
+
*
|
|
13
|
+
* Definición corecursiva clásica: repeat(x) = cons(x, () => repeat(x)).
|
|
14
|
+
* El thunk evita la recursión infinita en tiempo de construcción.
|
|
15
|
+
*/
|
|
16
|
+
export declare function repeat<T>(x: T): Stream<T>;
|
|
17
|
+
/**
|
|
18
|
+
* `iterate(f, x)` = x, f(x), f(f(x)), ...
|
|
19
|
+
*
|
|
20
|
+
* Definición corecursiva: iterate(f, x) = cons(x, () => iterate(f, f(x))).
|
|
21
|
+
*/
|
|
22
|
+
export declare function iterate<T>(f: (x: T) => T, x: T): Stream<T>;
|
|
23
|
+
/**
|
|
24
|
+
* `unfold(seed, step)`: anamorfismo genérico. `step(s)` devuelve
|
|
25
|
+
* el siguiente par `[valor, próximaSemilla]` o `null` para terminar.
|
|
26
|
+
* Para streams infinitos, `step` nunca debe devolver `null`. Si
|
|
27
|
+
* devuelve `null` durante una iteración, devolvemos un stream que
|
|
28
|
+
* cicla la última cabeza producida (decisión: streams totales).
|
|
29
|
+
*/
|
|
30
|
+
export declare function unfold<S, T>(seed: S, step: (s: S) => readonly [T, S] | null): Stream<T>;
|
|
31
|
+
/**
|
|
32
|
+
* `take(s, n)`: extrae los primeros n elementos de un stream.
|
|
33
|
+
* Observación finita; es la única forma de "ver" un stream.
|
|
34
|
+
*/
|
|
35
|
+
export declare function take<T>(s: Stream<T>, n: number): T[];
|
|
36
|
+
/**
|
|
37
|
+
* `drop(s, n)`: descarta los primeros n elementos.
|
|
38
|
+
*/
|
|
39
|
+
export declare function drop<T>(s: Stream<T>, n: number): Stream<T>;
|
|
40
|
+
/**
|
|
41
|
+
* `nth(s, i)`: i-ésimo elemento (0-indexed).
|
|
42
|
+
*/
|
|
43
|
+
export declare function nth<T>(s: Stream<T>, i: number): T;
|
|
44
|
+
/**
|
|
45
|
+
* `map(f, s)`: aplica `f` a cada elemento.
|
|
46
|
+
*
|
|
47
|
+
* Definición corecursiva: map(f, s) = cons(f(head s), () => map(f, tail s)).
|
|
48
|
+
*/
|
|
49
|
+
export declare function map<T, U>(f: (x: T) => U, s: Stream<T>): Stream<U>;
|
|
50
|
+
/**
|
|
51
|
+
* `zipWith(f, a, b)`: combina dos streams elemento a elemento.
|
|
52
|
+
*
|
|
53
|
+
* zipWith(f, a, b) = cons(f(head a, head b), () => zipWith(f, tail a, tail b))
|
|
54
|
+
*/
|
|
55
|
+
export declare function zipWith<A, B, C>(f: (a: A, b: B) => C, a: Stream<A>, b: Stream<B>): Stream<C>;
|
|
56
|
+
/**
|
|
57
|
+
* `zip(a, b)`: par-zip estándar.
|
|
58
|
+
*/
|
|
59
|
+
export declare function zip<A, B>(a: Stream<A>, b: Stream<B>): Stream<[A, B]>;
|
|
60
|
+
/**
|
|
61
|
+
* `filter(pred, s)`: PRECONDICIÓN — el predicado debe ser satisfecho
|
|
62
|
+
* infinitas veces, de lo contrario el stream resultante se "atasca".
|
|
63
|
+
* No protegemos contra eso porque coinductivamente no es decidible.
|
|
64
|
+
*/
|
|
65
|
+
export declare function filter<T>(pred: (x: T) => boolean, s: Stream<T>): Stream<T>;
|
|
66
|
+
/**
|
|
67
|
+
* naturals = 0, 1, 2, 3, ...
|
|
68
|
+
*/
|
|
69
|
+
export declare const naturals: Stream<number>;
|
|
70
|
+
export declare const fibonacci: Stream<number>;
|
|
71
|
+
export interface BisimulationProof<T> {
|
|
72
|
+
/** Par inicial cuyo membership en la bisimulación queremos probar. */
|
|
73
|
+
initial: [Stream<T>, Stream<T>];
|
|
74
|
+
/**
|
|
75
|
+
* Relación candidata R. Por bisimulación, basta que R sea una
|
|
76
|
+
* "bisimulación up-to": cerrada bajo los destructores en el sentido
|
|
77
|
+
* de que R(s,t) ⇒ R(tail s, tail t).
|
|
78
|
+
*/
|
|
79
|
+
relation: (a: Stream<T>, b: Stream<T>) => boolean;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* `isBisimilar(a, b, depth)`: chequeo de bisimilaridad acotado.
|
|
83
|
+
* Compara cabezas hasta profundidad `depth`. Retorna `false` apenas
|
|
84
|
+
* encuentra una divergencia (refutación constructiva); retorna `true`
|
|
85
|
+
* si los primeros `depth` elementos coinciden (evidencia positiva
|
|
86
|
+
* acotada — para una prueba real de bisimilaridad, usar `prove`).
|
|
87
|
+
*
|
|
88
|
+
* Usa `Object.is` para comparar primitivos. Para tipos compuestos
|
|
89
|
+
* el caller debería envolver con un equality explícito (no hacemos
|
|
90
|
+
* deep-equals porque tendría costo no obvio y semántica ambigua).
|
|
91
|
+
*/
|
|
92
|
+
export declare function isBisimilar<T>(a: Stream<T>, b: Stream<T>, depth?: number): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Igualdad observacional para elementos de un stream. Soportamos:
|
|
95
|
+
* • primitivos (===, con Object.is para NaN/+0/-0)
|
|
96
|
+
* • arrays y tuplas (recursión elemento a elemento)
|
|
97
|
+
* • objetos planos por keys propias
|
|
98
|
+
* No hace circular-detection: si pasás un grafo cíclico, va a colgar.
|
|
99
|
+
*/
|
|
100
|
+
declare function equal(x: unknown, y: unknown): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* `prove(claim, depth)`: aplica la técnica de bisimulación up-to.
|
|
103
|
+
*
|
|
104
|
+
* Algoritmo: empieza con el par inicial, y para cada paso i ∈ [0, depth):
|
|
105
|
+
* 1. Verifica que la relación R sostenga el par actual (a_i, b_i).
|
|
106
|
+
* 2. Verifica que las cabezas sean iguales: head(a_i) = head(b_i).
|
|
107
|
+
* 3. Avanza: a_{i+1} = tail(a_i), b_{i+1} = tail(b_i).
|
|
108
|
+
*
|
|
109
|
+
* Si la relación R es genuinamente una bisimulación (clausurada bajo
|
|
110
|
+
* tail), todos los pasos pasarán para cualquier `depth`. El método
|
|
111
|
+
* es completo "en el límite": probar para `depth = ∞` ≡ probar bisim.
|
|
112
|
+
* En la práctica devolvemos true si depth pasos pasaron sin error.
|
|
113
|
+
*
|
|
114
|
+
* Si la relación falla en algún paso, retornamos false (evidencia de
|
|
115
|
+
* que R no es una bisimulación, o de que (a, b) no es bisimilar).
|
|
116
|
+
*/
|
|
117
|
+
export declare function prove<T>(claim: BisimulationProof<T>, depth?: number): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* `interleave(a, b)`: intercala a, b, a, b, ... toma 1 de a luego 1 de b.
|
|
120
|
+
*
|
|
121
|
+
* interleave(a, b) = cons(head a, () => interleave(b, tail a))
|
|
122
|
+
*
|
|
123
|
+
* Nota: el "switch" entre a y b se hace por el truco clásico:
|
|
124
|
+
* llamar recursivamente con los argumentos invertidos.
|
|
125
|
+
*/
|
|
126
|
+
export declare function interleave<T>(a: Stream<T>, b: Stream<T>): Stream<T>;
|
|
127
|
+
/**
|
|
128
|
+
* `scan(f, init, s)`: prefijos acumulados; análogo a Array.prototype.reduce
|
|
129
|
+
* pero coinductivo. scan(+, 0, naturals) = 0, 0, 1, 3, 6, 10, ...
|
|
130
|
+
*/
|
|
131
|
+
export declare function scan<T, U>(f: (acc: U, x: T) => U, init: U, s: Stream<T>): Stream<U>;
|
|
132
|
+
export declare const __internals: {
|
|
133
|
+
equal: typeof equal;
|
|
134
|
+
};
|
|
135
|
+
export {};
|
|
136
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/coinduction/index.ts"],"names":[],"mappings":"AA8BA,MAAM,WAAW,MAAM,CAAC,CAAC;IACvB,IAAI,EAAE,CAAC,CAAC;IACR,IAAI,EAAE,MAAM,MAAM,CAAC,CAAC,CAAC,CAAC;CACvB;AAID;;;GAGG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAE3D;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAMzC;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAE1D;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAWvF;AAID;;;GAGG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAWpD;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EA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AC;IAClC,sEAAsE;IACtE,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAChC;;;;OAIG;IACH,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC;CACnD;AAID;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,GAAE,MAAsB,GAAG,OAAO,CAYjG;AAED;;;;;;GAMG;AACH,iBAAS,KAAK,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAuB9C;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,KAAK,GAAE,MAAsB,GAAG,OAAO,CAY5F;AAID;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAKnE;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAKnF;AAID,eAAO,MAAM,WAAW;;CAAY,CAAC"}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// ST Coinduction — Streams + corecursion + bisimulación up-to
|
|
4
|
+
// ============================================================
|
|
5
|
+
// Streams coinductivos definidos por destructores (head, tail).
|
|
6
|
+
// Construcción corecursiva via thunks perezosos (la cola es una
|
|
7
|
+
// función `() => Stream<T>` para evitar evaluación infinita).
|
|
8
|
+
//
|
|
9
|
+
// Bisimulación: la noción natural de igualdad para streams. Dos
|
|
10
|
+
// streams `s, t` son bisimilares si existe una relación R tal que
|
|
11
|
+
// • R(s, t) ⇒ head(s) = head(t)
|
|
12
|
+
// • R(s, t) ⇒ R(tail(s), tail(t))
|
|
13
|
+
// La igualdad sintáctica falla (dos streams pueden generar la
|
|
14
|
+
// misma secuencia con thunks distintos); la bisimulación es la
|
|
15
|
+
// clausura coinductiva apropiada.
|
|
16
|
+
//
|
|
17
|
+
// Como las secuencias son infinitas no podemos verificar
|
|
18
|
+
// bisimilaridad en general (semi-decidible). Por eso ofrecemos:
|
|
19
|
+
// • isBisimilar(a, b, depth): chequeo "hasta profundidad", suficiente
|
|
20
|
+
// para refutación (encontrar el primer prefijo divergente) y para
|
|
21
|
+
// evidencia computacional positiva acotada.
|
|
22
|
+
// • prove(claim, depth): técnica "bisimulación up-to". El usuario
|
|
23
|
+
// provee una relación R; chequeamos por `depth` pasos que
|
|
24
|
+
// R(a,b) ⇒ head(a)=head(b) ∧ R(tail a, tail b).
|
|
25
|
+
// Si la relación es realmente una bisimulación, ningún paso falla;
|
|
26
|
+
// si depth pasos pasaron sin fallar, tenemos alta confianza
|
|
27
|
+
// (en el caso límite, todos los pasos válidos = bisimulación).
|
|
28
|
+
// ============================================================
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.__internals = exports.fibonacci = exports.naturals = void 0;
|
|
31
|
+
exports.cons = cons;
|
|
32
|
+
exports.repeat = repeat;
|
|
33
|
+
exports.iterate = iterate;
|
|
34
|
+
exports.unfold = unfold;
|
|
35
|
+
exports.take = take;
|
|
36
|
+
exports.drop = drop;
|
|
37
|
+
exports.nth = nth;
|
|
38
|
+
exports.map = map;
|
|
39
|
+
exports.zipWith = zipWith;
|
|
40
|
+
exports.zip = zip;
|
|
41
|
+
exports.filter = filter;
|
|
42
|
+
exports.isBisimilar = isBisimilar;
|
|
43
|
+
exports.prove = prove;
|
|
44
|
+
exports.interleave = interleave;
|
|
45
|
+
exports.scan = scan;
|
|
46
|
+
// ── Constructores ───────────────────────────────────────────
|
|
47
|
+
/**
|
|
48
|
+
* Cons explícito: crea un stream con cabeza `h` y cola perezosa
|
|
49
|
+
* `t` (una función que produce el resto cuando se evalúa).
|
|
50
|
+
*/
|
|
51
|
+
function cons(h, t) {
|
|
52
|
+
return { head: h, tail: t };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* `repeat(x)` = x, x, x, ... (stream constante)
|
|
56
|
+
*
|
|
57
|
+
* Definición corecursiva clásica: repeat(x) = cons(x, () => repeat(x)).
|
|
58
|
+
* El thunk evita la recursión infinita en tiempo de construcción.
|
|
59
|
+
*/
|
|
60
|
+
function repeat(x) {
|
|
61
|
+
// Truco para evitar reconstruir el objeto en cada `tail`: usamos
|
|
62
|
+
// un nodo que se referencia a sí mismo. Esto preserva la semántica
|
|
63
|
+
// (tail(repeat x) = repeat x) y además garantiza punto-fijo.
|
|
64
|
+
const node = { head: x, tail: () => node };
|
|
65
|
+
return node;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* `iterate(f, x)` = x, f(x), f(f(x)), ...
|
|
69
|
+
*
|
|
70
|
+
* Definición corecursiva: iterate(f, x) = cons(x, () => iterate(f, f(x))).
|
|
71
|
+
*/
|
|
72
|
+
function iterate(f, x) {
|
|
73
|
+
return { head: x, tail: () => iterate(f, f(x)) };
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* `unfold(seed, step)`: anamorfismo genérico. `step(s)` devuelve
|
|
77
|
+
* el siguiente par `[valor, próximaSemilla]` o `null` para terminar.
|
|
78
|
+
* Para streams infinitos, `step` nunca debe devolver `null`. Si
|
|
79
|
+
* devuelve `null` durante una iteración, devolvemos un stream que
|
|
80
|
+
* cicla la última cabeza producida (decisión: streams totales).
|
|
81
|
+
*/
|
|
82
|
+
function unfold(seed, step) {
|
|
83
|
+
const next = step(seed);
|
|
84
|
+
if (next === null) {
|
|
85
|
+
// Streams en este módulo son totales; si el cliente decide terminar,
|
|
86
|
+
// estabilizamos en un punto fijo trivial usando undefined.
|
|
87
|
+
// En la práctica, los callers no deberían llamar unfold con un step
|
|
88
|
+
// que puede devolver null si esperan un stream infinito.
|
|
89
|
+
throw new Error('unfold: step returned null on infinite stream');
|
|
90
|
+
}
|
|
91
|
+
const [value, nextSeed] = next;
|
|
92
|
+
return { head: value, tail: () => unfold(nextSeed, step) };
|
|
93
|
+
}
|
|
94
|
+
// ── Destructores y observaciones ────────────────────────────
|
|
95
|
+
/**
|
|
96
|
+
* `take(s, n)`: extrae los primeros n elementos de un stream.
|
|
97
|
+
* Observación finita; es la única forma de "ver" un stream.
|
|
98
|
+
*/
|
|
99
|
+
function take(s, n) {
|
|
100
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
101
|
+
throw new Error(`take: n debe ser entero no-negativo, recibido ${n}`);
|
|
102
|
+
}
|
|
103
|
+
const out = [];
|
|
104
|
+
let cur = s;
|
|
105
|
+
for (let i = 0; i < n; i++) {
|
|
106
|
+
out.push(cur.head);
|
|
107
|
+
cur = cur.tail();
|
|
108
|
+
}
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* `drop(s, n)`: descarta los primeros n elementos.
|
|
113
|
+
*/
|
|
114
|
+
function drop(s, n) {
|
|
115
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
116
|
+
throw new Error(`drop: n debe ser entero no-negativo, recibido ${n}`);
|
|
117
|
+
}
|
|
118
|
+
let cur = s;
|
|
119
|
+
for (let i = 0; i < n; i++)
|
|
120
|
+
cur = cur.tail();
|
|
121
|
+
return cur;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* `nth(s, i)`: i-ésimo elemento (0-indexed).
|
|
125
|
+
*/
|
|
126
|
+
function nth(s, i) {
|
|
127
|
+
return drop(s, i).head;
|
|
128
|
+
}
|
|
129
|
+
// ── Functor / aplicativos ───────────────────────────────────
|
|
130
|
+
/**
|
|
131
|
+
* `map(f, s)`: aplica `f` a cada elemento.
|
|
132
|
+
*
|
|
133
|
+
* Definición corecursiva: map(f, s) = cons(f(head s), () => map(f, tail s)).
|
|
134
|
+
*/
|
|
135
|
+
function map(f, s) {
|
|
136
|
+
return { head: f(s.head), tail: () => map(f, s.tail()) };
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* `zipWith(f, a, b)`: combina dos streams elemento a elemento.
|
|
140
|
+
*
|
|
141
|
+
* zipWith(f, a, b) = cons(f(head a, head b), () => zipWith(f, tail a, tail b))
|
|
142
|
+
*/
|
|
143
|
+
function zipWith(f, a, b) {
|
|
144
|
+
return {
|
|
145
|
+
head: f(a.head, b.head),
|
|
146
|
+
tail: () => zipWith(f, a.tail(), b.tail()),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* `zip(a, b)`: par-zip estándar.
|
|
151
|
+
*/
|
|
152
|
+
function zip(a, b) {
|
|
153
|
+
return zipWith((x, y) => [x, y], a, b);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* `filter(pred, s)`: PRECONDICIÓN — el predicado debe ser satisfecho
|
|
157
|
+
* infinitas veces, de lo contrario el stream resultante se "atasca".
|
|
158
|
+
* No protegemos contra eso porque coinductivamente no es decidible.
|
|
159
|
+
*/
|
|
160
|
+
function filter(pred, s) {
|
|
161
|
+
let cur = s;
|
|
162
|
+
while (!pred(cur.head)) {
|
|
163
|
+
cur = cur.tail();
|
|
164
|
+
}
|
|
165
|
+
const advanced = cur;
|
|
166
|
+
return {
|
|
167
|
+
head: advanced.head,
|
|
168
|
+
tail: () => filter(pred, advanced.tail()),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
// ── Streams notables ────────────────────────────────────────
|
|
172
|
+
/**
|
|
173
|
+
* naturals = 0, 1, 2, 3, ...
|
|
174
|
+
*/
|
|
175
|
+
exports.naturals = iterate((n) => n + 1, 0);
|
|
176
|
+
/**
|
|
177
|
+
* fibonacci = 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
|
|
178
|
+
*
|
|
179
|
+
* Definición clásica corecursiva (Hinze):
|
|
180
|
+
* fib = 0 :: 1 :: zipWith(+, fib, tail fib)
|
|
181
|
+
*
|
|
182
|
+
* En TypeScript necesitamos un thunk que se autorreferencie. Lo
|
|
183
|
+
* implementamos con una closure que devuelve siempre el mismo nodo.
|
|
184
|
+
*/
|
|
185
|
+
function makeFibonacci() {
|
|
186
|
+
// fib(n) clásico vía iterate sobre el par (a, b) = (fib n, fib (n+1)).
|
|
187
|
+
// Equivalente computacionalmente a la definición zipWith pero sin
|
|
188
|
+
// requerir auto-referencia en TS (que generaría thunks anidados
|
|
189
|
+
// exponencialmente sin memoización).
|
|
190
|
+
return map(([a, _b]) => a, iterate(([a, b]) => [b, a + b], [0, 1]));
|
|
191
|
+
}
|
|
192
|
+
exports.fibonacci = makeFibonacci();
|
|
193
|
+
const DEFAULT_DEPTH = 64;
|
|
194
|
+
/**
|
|
195
|
+
* `isBisimilar(a, b, depth)`: chequeo de bisimilaridad acotado.
|
|
196
|
+
* Compara cabezas hasta profundidad `depth`. Retorna `false` apenas
|
|
197
|
+
* encuentra una divergencia (refutación constructiva); retorna `true`
|
|
198
|
+
* si los primeros `depth` elementos coinciden (evidencia positiva
|
|
199
|
+
* acotada — para una prueba real de bisimilaridad, usar `prove`).
|
|
200
|
+
*
|
|
201
|
+
* Usa `Object.is` para comparar primitivos. Para tipos compuestos
|
|
202
|
+
* el caller debería envolver con un equality explícito (no hacemos
|
|
203
|
+
* deep-equals porque tendría costo no obvio y semántica ambigua).
|
|
204
|
+
*/
|
|
205
|
+
function isBisimilar(a, b, depth = DEFAULT_DEPTH) {
|
|
206
|
+
if (!Number.isInteger(depth) || depth < 0) {
|
|
207
|
+
throw new Error(`isBisimilar: depth debe ser entero no-negativo, recibido ${depth}`);
|
|
208
|
+
}
|
|
209
|
+
let curA = a;
|
|
210
|
+
let curB = b;
|
|
211
|
+
for (let i = 0; i < depth; i++) {
|
|
212
|
+
if (!equal(curA.head, curB.head))
|
|
213
|
+
return false;
|
|
214
|
+
curA = curA.tail();
|
|
215
|
+
curB = curB.tail();
|
|
216
|
+
}
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Igualdad observacional para elementos de un stream. Soportamos:
|
|
221
|
+
* • primitivos (===, con Object.is para NaN/+0/-0)
|
|
222
|
+
* • arrays y tuplas (recursión elemento a elemento)
|
|
223
|
+
* • objetos planos por keys propias
|
|
224
|
+
* No hace circular-detection: si pasás un grafo cíclico, va a colgar.
|
|
225
|
+
*/
|
|
226
|
+
function equal(x, y) {
|
|
227
|
+
if (Object.is(x, y))
|
|
228
|
+
return true;
|
|
229
|
+
if (typeof x !== typeof y)
|
|
230
|
+
return false;
|
|
231
|
+
if (x === null || y === null)
|
|
232
|
+
return false;
|
|
233
|
+
if (typeof x !== 'object')
|
|
234
|
+
return false;
|
|
235
|
+
if (Array.isArray(x) !== Array.isArray(y))
|
|
236
|
+
return false;
|
|
237
|
+
if (Array.isArray(x) && Array.isArray(y)) {
|
|
238
|
+
if (x.length !== y.length)
|
|
239
|
+
return false;
|
|
240
|
+
for (let i = 0; i < x.length; i++) {
|
|
241
|
+
if (!equal(x[i], y[i]))
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
const ox = x;
|
|
247
|
+
const oy = y;
|
|
248
|
+
const kx = Object.keys(ox);
|
|
249
|
+
const ky = Object.keys(oy);
|
|
250
|
+
if (kx.length !== ky.length)
|
|
251
|
+
return false;
|
|
252
|
+
for (const k of kx) {
|
|
253
|
+
if (!Object.prototype.hasOwnProperty.call(oy, k))
|
|
254
|
+
return false;
|
|
255
|
+
if (!equal(ox[k], oy[k]))
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* `prove(claim, depth)`: aplica la técnica de bisimulación up-to.
|
|
262
|
+
*
|
|
263
|
+
* Algoritmo: empieza con el par inicial, y para cada paso i ∈ [0, depth):
|
|
264
|
+
* 1. Verifica que la relación R sostenga el par actual (a_i, b_i).
|
|
265
|
+
* 2. Verifica que las cabezas sean iguales: head(a_i) = head(b_i).
|
|
266
|
+
* 3. Avanza: a_{i+1} = tail(a_i), b_{i+1} = tail(b_i).
|
|
267
|
+
*
|
|
268
|
+
* Si la relación R es genuinamente una bisimulación (clausurada bajo
|
|
269
|
+
* tail), todos los pasos pasarán para cualquier `depth`. El método
|
|
270
|
+
* es completo "en el límite": probar para `depth = ∞` ≡ probar bisim.
|
|
271
|
+
* En la práctica devolvemos true si depth pasos pasaron sin error.
|
|
272
|
+
*
|
|
273
|
+
* Si la relación falla en algún paso, retornamos false (evidencia de
|
|
274
|
+
* que R no es una bisimulación, o de que (a, b) no es bisimilar).
|
|
275
|
+
*/
|
|
276
|
+
function prove(claim, depth = DEFAULT_DEPTH) {
|
|
277
|
+
if (!Number.isInteger(depth) || depth < 0) {
|
|
278
|
+
throw new Error(`prove: depth debe ser entero no-negativo, recibido ${depth}`);
|
|
279
|
+
}
|
|
280
|
+
let [curA, curB] = claim.initial;
|
|
281
|
+
for (let i = 0; i < depth; i++) {
|
|
282
|
+
if (!claim.relation(curA, curB))
|
|
283
|
+
return false;
|
|
284
|
+
if (!equal(curA.head, curB.head))
|
|
285
|
+
return false;
|
|
286
|
+
curA = curA.tail();
|
|
287
|
+
curB = curB.tail();
|
|
288
|
+
}
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
291
|
+
// ── Utilidades para combinar streams (Hinze classics) ──────
|
|
292
|
+
/**
|
|
293
|
+
* `interleave(a, b)`: intercala a, b, a, b, ... toma 1 de a luego 1 de b.
|
|
294
|
+
*
|
|
295
|
+
* interleave(a, b) = cons(head a, () => interleave(b, tail a))
|
|
296
|
+
*
|
|
297
|
+
* Nota: el "switch" entre a y b se hace por el truco clásico:
|
|
298
|
+
* llamar recursivamente con los argumentos invertidos.
|
|
299
|
+
*/
|
|
300
|
+
function interleave(a, b) {
|
|
301
|
+
return {
|
|
302
|
+
head: a.head,
|
|
303
|
+
tail: () => interleave(b, a.tail()),
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* `scan(f, init, s)`: prefijos acumulados; análogo a Array.prototype.reduce
|
|
308
|
+
* pero coinductivo. scan(+, 0, naturals) = 0, 0, 1, 3, 6, 10, ...
|
|
309
|
+
*/
|
|
310
|
+
function scan(f, init, s) {
|
|
311
|
+
return {
|
|
312
|
+
head: init,
|
|
313
|
+
tail: () => scan(f, f(init, s.head), s.tail()),
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
// ── Exports auxiliares para tests ───────────────────────────
|
|
317
|
+
exports.__internals = { equal };
|
|
318
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/coinduction/index.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,8DAA8D;AAC9D,+DAA+D;AAC/D,gEAAgE;AAChE,gEAAgE;AAChE,8DAA8D;AAC9D,EAAE;AACF,gEAAgE;AAChE,kEAAkE;AAClE,kCAAkC;AAClC,oCAAoC;AACpC,8DAA8D;AAC9D,+DAA+D;AAC/D,kCAAkC;AAClC,EAAE;AACF,yDAAyD;AACzD,gEAAgE;AAChE,wEAAwE;AACxE,sEAAsE;AACtE,gDAAgD;AAChD,oEAAoE;AACpE,8DAA8D;AAC9D,sDAAsD;AACtD,uEAAuE;AACvE,gEAAgE;AAChE,mEAAmE;AACnE,+DAA+D;;;AAe/D,o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