@stevenvo780/st-lang 4.9.0 → 4.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/dist/logic/profiles/natural-deduction-nk/formula.d.ts +18 -0
  2. package/dist/logic/profiles/natural-deduction-nk/formula.d.ts.map +1 -0
  3. package/dist/logic/profiles/natural-deduction-nk/formula.js +102 -0
  4. package/dist/logic/profiles/natural-deduction-nk/formula.js.map +1 -0
  5. package/dist/logic/profiles/natural-deduction-nk/index.d.ts +5 -0
  6. package/dist/logic/profiles/natural-deduction-nk/index.d.ts.map +1 -0
  7. package/dist/logic/profiles/natural-deduction-nk/index.js +28 -0
  8. package/dist/logic/profiles/natural-deduction-nk/index.js.map +1 -0
  9. package/dist/logic/profiles/natural-deduction-nk/prover.d.ts +49 -0
  10. package/dist/logic/profiles/natural-deduction-nk/prover.d.ts.map +1 -0
  11. package/dist/logic/profiles/natural-deduction-nk/prover.js +557 -0
  12. package/dist/logic/profiles/natural-deduction-nk/prover.js.map +1 -0
  13. package/dist/logic/profiles/natural-deduction-nk/types.d.ts +48 -0
  14. package/dist/logic/profiles/natural-deduction-nk/types.d.ts.map +1 -0
  15. package/dist/logic/profiles/natural-deduction-nk/types.js +35 -0
  16. package/dist/logic/profiles/natural-deduction-nk/types.js.map +1 -0
  17. package/dist/proof-systems/distributed-exchange/index.d.ts +101 -0
  18. package/dist/proof-systems/distributed-exchange/index.d.ts.map +1 -0
  19. package/dist/proof-systems/distributed-exchange/index.js +408 -0
  20. package/dist/proof-systems/distributed-exchange/index.js.map +1 -0
  21. package/dist/reasoning/automata/dfa.d.ts +17 -0
  22. package/dist/reasoning/automata/dfa.d.ts.map +1 -0
  23. package/dist/reasoning/automata/dfa.js +276 -0
  24. package/dist/reasoning/automata/dfa.js.map +1 -0
  25. package/dist/reasoning/automata/index.d.ts +8 -0
  26. package/dist/reasoning/automata/index.d.ts.map +1 -0
  27. package/dist/reasoning/automata/index.js +64 -0
  28. package/dist/reasoning/automata/index.js.map +1 -0
  29. package/dist/reasoning/automata/languages.d.ts +10 -0
  30. package/dist/reasoning/automata/languages.d.ts.map +1 -0
  31. package/dist/reasoning/automata/languages.js +78 -0
  32. package/dist/reasoning/automata/languages.js.map +1 -0
  33. package/dist/reasoning/automata/nfa.d.ts +8 -0
  34. package/dist/reasoning/automata/nfa.d.ts.map +1 -0
  35. package/dist/reasoning/automata/nfa.js +122 -0
  36. package/dist/reasoning/automata/nfa.js.map +1 -0
  37. package/dist/reasoning/automata/pda.d.ts +10 -0
  38. package/dist/reasoning/automata/pda.d.ts.map +1 -0
  39. package/dist/reasoning/automata/pda.js +169 -0
  40. package/dist/reasoning/automata/pda.js.map +1 -0
  41. package/dist/reasoning/automata/regex.d.ts +6 -0
  42. package/dist/reasoning/automata/regex.d.ts.map +1 -0
  43. package/dist/reasoning/automata/regex.js +259 -0
  44. package/dist/reasoning/automata/regex.js.map +1 -0
  45. package/dist/reasoning/automata/types.d.ts +69 -0
  46. package/dist/reasoning/automata/types.d.ts.map +1 -0
  47. package/dist/reasoning/automata/types.js +29 -0
  48. package/dist/reasoning/automata/types.js.map +1 -0
  49. package/dist/reasoning/computability/index.d.ts +239 -0
  50. package/dist/reasoning/computability/index.d.ts.map +1 -0
  51. package/dist/reasoning/computability/index.js +851 -0
  52. package/dist/reasoning/computability/index.js.map +1 -0
  53. package/dist/reasoning/graph-theory/index.d.ts +63 -0
  54. package/dist/reasoning/graph-theory/index.d.ts.map +1 -0
  55. package/dist/reasoning/graph-theory/index.js +1043 -0
  56. package/dist/reasoning/graph-theory/index.js.map +1 -0
  57. package/dist/reasoning/group-presentation/cayley.d.ts +8 -0
  58. package/dist/reasoning/group-presentation/cayley.d.ts.map +1 -0
  59. package/dist/reasoning/group-presentation/cayley.js +38 -0
  60. package/dist/reasoning/group-presentation/cayley.js.map +1 -0
  61. package/dist/reasoning/group-presentation/index.d.ts +8 -0
  62. package/dist/reasoning/group-presentation/index.d.ts.map +1 -0
  63. package/dist/reasoning/group-presentation/index.js +36 -0
  64. package/dist/reasoning/group-presentation/index.js.map +1 -0
  65. package/dist/reasoning/group-presentation/standard-groups.d.ts +6 -0
  66. package/dist/reasoning/group-presentation/standard-groups.d.ts.map +1 -0
  67. package/dist/reasoning/group-presentation/standard-groups.js +93 -0
  68. package/dist/reasoning/group-presentation/standard-groups.js.map +1 -0
  69. package/dist/reasoning/group-presentation/todd-coxeter.d.ts +10 -0
  70. package/dist/reasoning/group-presentation/todd-coxeter.d.ts.map +1 -0
  71. package/dist/reasoning/group-presentation/todd-coxeter.js +362 -0
  72. package/dist/reasoning/group-presentation/todd-coxeter.js.map +1 -0
  73. package/dist/reasoning/group-presentation/types.d.ts +7 -0
  74. package/dist/reasoning/group-presentation/types.d.ts.map +1 -0
  75. package/dist/reasoning/group-presentation/types.js +22 -0
  76. package/dist/reasoning/group-presentation/types.js.map +1 -0
  77. package/dist/reasoning/group-presentation/words.d.ts +10 -0
  78. package/dist/reasoning/group-presentation/words.d.ts.map +1 -0
  79. package/dist/reasoning/group-presentation/words.js +109 -0
  80. package/dist/reasoning/group-presentation/words.js.map +1 -0
  81. package/dist/reasoning/number-theory/crt.d.ts +9 -0
  82. package/dist/reasoning/number-theory/crt.d.ts.map +1 -0
  83. package/dist/reasoning/number-theory/crt.js +39 -0
  84. package/dist/reasoning/number-theory/crt.js.map +1 -0
  85. package/dist/reasoning/number-theory/diophantine.d.ts +10 -0
  86. package/dist/reasoning/number-theory/diophantine.d.ts.map +1 -0
  87. package/dist/reasoning/number-theory/diophantine.js +87 -0
  88. package/dist/reasoning/number-theory/diophantine.js.map +1 -0
  89. package/dist/reasoning/number-theory/factorization.d.ts +12 -0
  90. package/dist/reasoning/number-theory/factorization.d.ts.map +1 -0
  91. package/dist/reasoning/number-theory/factorization.js +136 -0
  92. package/dist/reasoning/number-theory/factorization.js.map +1 -0
  93. package/dist/reasoning/number-theory/gcd.d.ts +8 -0
  94. package/dist/reasoning/number-theory/gcd.d.ts.map +1 -0
  95. package/dist/reasoning/number-theory/gcd.js +51 -0
  96. package/dist/reasoning/number-theory/gcd.js.map +1 -0
  97. package/dist/reasoning/number-theory/index.d.ts +9 -0
  98. package/dist/reasoning/number-theory/index.d.ts.map +1 -0
  99. package/dist/reasoning/number-theory/index.js +46 -0
  100. package/dist/reasoning/number-theory/index.js.map +1 -0
  101. package/dist/reasoning/number-theory/modular.d.ts +6 -0
  102. package/dist/reasoning/number-theory/modular.d.ts.map +1 -0
  103. package/dist/reasoning/number-theory/modular.js +75 -0
  104. package/dist/reasoning/number-theory/modular.js.map +1 -0
  105. package/dist/reasoning/number-theory/primality.d.ts +6 -0
  106. package/dist/reasoning/number-theory/primality.d.ts.map +1 -0
  107. package/dist/reasoning/number-theory/primality.js +144 -0
  108. package/dist/reasoning/number-theory/primality.js.map +1 -0
  109. package/dist/reasoning/number-theory/symbols.d.ts +3 -0
  110. package/dist/reasoning/number-theory/symbols.d.ts.map +1 -0
  111. package/dist/reasoning/number-theory/symbols.js +57 -0
  112. package/dist/reasoning/number-theory/symbols.js.map +1 -0
  113. package/dist/reasoning/real-analysis/index.d.ts +127 -0
  114. package/dist/reasoning/real-analysis/index.d.ts.map +1 -0
  115. package/dist/reasoning/real-analysis/index.js +638 -0
  116. package/dist/reasoning/real-analysis/index.js.map +1 -0
  117. package/dist/reasoning/topology/index.d.ts +41 -0
  118. package/dist/reasoning/topology/index.d.ts.map +1 -0
  119. package/dist/reasoning/topology/index.js +739 -0
  120. package/dist/reasoning/topology/index.js.map +1 -0
  121. package/dist/tests/logic/profiles/natural-deduction-nk/nk.test.d.ts +2 -0
  122. package/dist/tests/logic/profiles/natural-deduction-nk/nk.test.d.ts.map +1 -0
  123. package/dist/tests/logic/profiles/natural-deduction-nk/nk.test.js +288 -0
  124. package/dist/tests/logic/profiles/natural-deduction-nk/nk.test.js.map +1 -0
  125. package/dist/tests/proof-systems/distributed-exchange/distributed-exchange.test.d.ts +2 -0
  126. package/dist/tests/proof-systems/distributed-exchange/distributed-exchange.test.d.ts.map +1 -0
  127. package/dist/tests/proof-systems/distributed-exchange/distributed-exchange.test.js +328 -0
  128. package/dist/tests/proof-systems/distributed-exchange/distributed-exchange.test.js.map +1 -0
  129. package/dist/tests/reasoning/automata/automata.test.d.ts +2 -0
  130. package/dist/tests/reasoning/automata/automata.test.d.ts.map +1 -0
  131. package/dist/tests/reasoning/automata/automata.test.js +310 -0
  132. package/dist/tests/reasoning/automata/automata.test.js.map +1 -0
  133. package/dist/tests/reasoning/computability/computability.test.d.ts +2 -0
  134. package/dist/tests/reasoning/computability/computability.test.d.ts.map +1 -0
  135. package/dist/tests/reasoning/computability/computability.test.js +246 -0
  136. package/dist/tests/reasoning/computability/computability.test.js.map +1 -0
  137. package/dist/tests/reasoning/graph-theory/graph-theory.test.d.ts +2 -0
  138. package/dist/tests/reasoning/graph-theory/graph-theory.test.d.ts.map +1 -0
  139. package/dist/tests/reasoning/graph-theory/graph-theory.test.js +363 -0
  140. package/dist/tests/reasoning/graph-theory/graph-theory.test.js.map +1 -0
  141. package/dist/tests/reasoning/group-presentation/group-presentation.test.d.ts +2 -0
  142. package/dist/tests/reasoning/group-presentation/group-presentation.test.d.ts.map +1 -0
  143. package/dist/tests/reasoning/group-presentation/group-presentation.test.js +229 -0
  144. package/dist/tests/reasoning/group-presentation/group-presentation.test.js.map +1 -0
  145. package/dist/tests/reasoning/number-theory/number-theory.test.d.ts +2 -0
  146. package/dist/tests/reasoning/number-theory/number-theory.test.d.ts.map +1 -0
  147. package/dist/tests/reasoning/number-theory/number-theory.test.js +170 -0
  148. package/dist/tests/reasoning/number-theory/number-theory.test.js.map +1 -0
  149. package/dist/tests/reasoning/real-analysis/real-analysis.test.d.ts +2 -0
  150. package/dist/tests/reasoning/real-analysis/real-analysis.test.d.ts.map +1 -0
  151. package/dist/tests/reasoning/real-analysis/real-analysis.test.js +197 -0
  152. package/dist/tests/reasoning/real-analysis/real-analysis.test.js.map +1 -0
  153. package/dist/tests/reasoning/topology/topology.test.d.ts +2 -0
  154. package/dist/tests/reasoning/topology/topology.test.d.ts.map +1 -0
  155. package/dist/tests/reasoning/topology/topology.test.js +327 -0
  156. package/dist/tests/reasoning/topology/topology.test.js.map +1 -0
  157. package/dist/tests/tooling/exporters/coq-v2/coq-v2-exporter.test.d.ts +2 -0
  158. package/dist/tests/tooling/exporters/coq-v2/coq-v2-exporter.test.d.ts.map +1 -0
  159. package/dist/tests/tooling/exporters/coq-v2/coq-v2-exporter.test.js +411 -0
  160. package/dist/tests/tooling/exporters/coq-v2/coq-v2-exporter.test.js.map +1 -0
  161. package/dist/tests/tooling/exporters/lean4/lean4-exporter.test.d.ts +2 -0
  162. package/dist/tests/tooling/exporters/lean4/lean4-exporter.test.d.ts.map +1 -0
  163. package/dist/tests/tooling/exporters/lean4/lean4-exporter.test.js +473 -0
  164. package/dist/tests/tooling/exporters/lean4/lean4-exporter.test.js.map +1 -0
  165. package/dist/tests/tooling/lemma-library/lemma-library.test.d.ts +2 -0
  166. package/dist/tests/tooling/lemma-library/lemma-library.test.d.ts.map +1 -0
  167. package/dist/tests/tooling/lemma-library/lemma-library.test.js +197 -0
  168. package/dist/tests/tooling/lemma-library/lemma-library.test.js.map +1 -0
  169. package/dist/tests/tooling/provenance/ledger.test.d.ts +2 -0
  170. package/dist/tests/tooling/provenance/ledger.test.d.ts.map +1 -0
  171. package/dist/tests/tooling/provenance/ledger.test.js +545 -0
  172. package/dist/tests/tooling/provenance/ledger.test.js.map +1 -0
  173. package/dist/tooling/exporters/coq-v2/index.d.ts +68 -0
  174. package/dist/tooling/exporters/coq-v2/index.d.ts.map +1 -0
  175. package/dist/tooling/exporters/coq-v2/index.js +692 -0
  176. package/dist/tooling/exporters/coq-v2/index.js.map +1 -0
  177. package/dist/tooling/exporters/lean4/index.d.ts +47 -0
  178. package/dist/tooling/exporters/lean4/index.d.ts.map +1 -0
  179. package/dist/tooling/exporters/lean4/index.js +423 -0
  180. package/dist/tooling/exporters/lean4/index.js.map +1 -0
  181. package/dist/tooling/lemma-library/apply.d.ts +9 -0
  182. package/dist/tooling/lemma-library/apply.d.ts.map +1 -0
  183. package/dist/tooling/lemma-library/apply.js +94 -0
  184. package/dist/tooling/lemma-library/apply.js.map +1 -0
  185. package/dist/tooling/lemma-library/arithmetic.d.ts +3 -0
  186. package/dist/tooling/lemma-library/arithmetic.d.ts.map +1 -0
  187. package/dist/tooling/lemma-library/arithmetic.js +176 -0
  188. package/dist/tooling/lemma-library/arithmetic.js.map +1 -0
  189. package/dist/tooling/lemma-library/firstorder.d.ts +3 -0
  190. package/dist/tooling/lemma-library/firstorder.d.ts.map +1 -0
  191. package/dist/tooling/lemma-library/firstorder.js +136 -0
  192. package/dist/tooling/lemma-library/firstorder.js.map +1 -0
  193. package/dist/tooling/lemma-library/index.d.ts +13 -0
  194. package/dist/tooling/lemma-library/index.d.ts.map +1 -0
  195. package/dist/tooling/lemma-library/index.js +32 -0
  196. package/dist/tooling/lemma-library/index.js.map +1 -0
  197. package/dist/tooling/lemma-library/library.d.ts +34 -0
  198. package/dist/tooling/lemma-library/library.d.ts.map +1 -0
  199. package/dist/tooling/lemma-library/library.js +126 -0
  200. package/dist/tooling/lemma-library/library.js.map +1 -0
  201. package/dist/tooling/lemma-library/modal.d.ts +3 -0
  202. package/dist/tooling/lemma-library/modal.d.ts.map +1 -0
  203. package/dist/tooling/lemma-library/modal.js +138 -0
  204. package/dist/tooling/lemma-library/modal.js.map +1 -0
  205. package/dist/tooling/lemma-library/propositional.d.ts +3 -0
  206. package/dist/tooling/lemma-library/propositional.d.ts.map +1 -0
  207. package/dist/tooling/lemma-library/propositional.js +265 -0
  208. package/dist/tooling/lemma-library/propositional.js.map +1 -0
  209. package/dist/tooling/lemma-library/set-theory.d.ts +3 -0
  210. package/dist/tooling/lemma-library/set-theory.d.ts.map +1 -0
  211. package/dist/tooling/lemma-library/set-theory.js +134 -0
  212. package/dist/tooling/lemma-library/set-theory.js.map +1 -0
  213. package/dist/tooling/lemma-library/standard.d.ts +3 -0
  214. package/dist/tooling/lemma-library/standard.d.ts.map +1 -0
  215. package/dist/tooling/lemma-library/standard.js +27 -0
  216. package/dist/tooling/lemma-library/standard.js.map +1 -0
  217. package/dist/tooling/lemma-library/tfidf.d.ts +5 -0
  218. package/dist/tooling/lemma-library/tfidf.d.ts.map +1 -0
  219. package/dist/tooling/lemma-library/tfidf.js +100 -0
  220. package/dist/tooling/lemma-library/tfidf.js.map +1 -0
  221. package/dist/tooling/lemma-library/tokenize.d.ts +2 -0
  222. package/dist/tooling/lemma-library/tokenize.d.ts.map +1 -0
  223. package/dist/tooling/lemma-library/tokenize.js +74 -0
  224. package/dist/tooling/lemma-library/tokenize.js.map +1 -0
  225. package/dist/tooling/lemma-library/types.d.ts +53 -0
  226. package/dist/tooling/lemma-library/types.d.ts.map +1 -0
  227. package/dist/tooling/lemma-library/types.js +10 -0
  228. package/dist/tooling/lemma-library/types.js.map +1 -0
  229. package/dist/tooling/provenance/index.d.ts +3 -0
  230. package/dist/tooling/provenance/index.d.ts.map +1 -0
  231. package/dist/tooling/provenance/index.js +16 -0
  232. package/dist/tooling/provenance/index.js.map +1 -0
  233. package/dist/tooling/provenance/ledger.d.ts +89 -0
  234. package/dist/tooling/provenance/ledger.d.ts.map +1 -0
  235. package/dist/tooling/provenance/ledger.js +439 -0
  236. package/dist/tooling/provenance/ledger.js.map +1 -0
  237. package/dist/tooling/provenance/types.d.ts +70 -0
  238. package/dist/tooling/provenance/types.d.ts.map +1 -0
  239. package/dist/tooling/provenance/types.js +14 -0
  240. package/dist/tooling/provenance/types.js.map +1 -0
  241. package/package.json +1 -1
@@ -0,0 +1,692 @@
1
+ "use strict";
2
+ // ============================================================
3
+ // ST Exporters — Coq code generator V2
4
+ // ============================================================
5
+ // Mejoras sobre v1:
6
+ // - Tactics derivadas: auto / tauto / firstorder / intuition / lia / omega.
7
+ // - Dependent types: forall x : nat / forall x : Type, ...
8
+ // - Generación de hints: Hint Resolve, Hint Rewrite.
9
+ // - Proof terms (lambda) además de tactics, o "both".
10
+ // Mantiene coq/index.ts (v1) intacto: ambos coexisten.
11
+ // ============================================================
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.inferDependentSorts = inferDependentSorts;
14
+ exports.formulaToCoqType = formulaToCoqType;
15
+ exports.chooseStrategy = chooseStrategy;
16
+ exports.ndProofToProofTerm = ndProofToProofTerm;
17
+ exports.generateHints = generateHints;
18
+ exports.exportToCoqV2 = exportToCoqV2;
19
+ exports.exportProofToCoqV2 = exportProofToCoqV2;
20
+ exports.exportTheoryToCoqV2 = exportTheoryToCoqV2;
21
+ // ----------------------------------------------------------------
22
+ // Dependent sort inference
23
+ // ----------------------------------------------------------------
24
+ /**
25
+ * Heurística simple: si una variable aparece como argumento de un predicado
26
+ * aritmético (`<`, `>`, `+`, `=`, etc.) la consideramos `nat`. Si aparece
27
+ * en un predicado simbólico, la consideramos `Prop`. Default: `Type`.
28
+ */
29
+ function inferDependentSorts(formula) {
30
+ const sorts = new Map();
31
+ if (!isFormulaLike(formula))
32
+ return sorts;
33
+ walkFormula(formula, (node) => {
34
+ // Quantifier: registra la variable bajo el sort heredado de cómo se usa.
35
+ if (node.kind === 'forall' || node.kind === 'exists') {
36
+ const v = node.variable ?? 'x';
37
+ if (!sorts.has(v)) {
38
+ const inferred = inferVarSortInBody(v, node.args?.[0]);
39
+ sorts.set(v, inferred);
40
+ }
41
+ }
42
+ });
43
+ return sorts;
44
+ }
45
+ function inferVarSortInBody(v, body) {
46
+ if (!body)
47
+ return 'Type';
48
+ let inferred = null;
49
+ walkFormula(body, (node) => {
50
+ if (inferred)
51
+ return;
52
+ if (node.kind === 'less' ||
53
+ node.kind === 'greater' ||
54
+ node.kind === 'less_eq' ||
55
+ node.kind === 'greater_eq' ||
56
+ node.kind === 'add' ||
57
+ node.kind === 'subtract' ||
58
+ node.kind === 'multiply' ||
59
+ node.kind === 'divide' ||
60
+ node.kind === 'modulo') {
61
+ // Si la variable aparece en algún arg numérico, asume nat.
62
+ if (formulaMentionsVar(node, v))
63
+ inferred = 'nat';
64
+ }
65
+ if (node.kind === 'equals') {
66
+ // Equality numérica si los args son números/aritméticos.
67
+ const a = node.args?.[0];
68
+ const b = node.args?.[1];
69
+ if ((a && (a.kind === 'number' || isArithmetic(a))) ||
70
+ (b && (b.kind === 'number' || isArithmetic(b)))) {
71
+ if (formulaMentionsVar(node, v))
72
+ inferred = 'nat';
73
+ }
74
+ }
75
+ });
76
+ return inferred ?? 'Type';
77
+ }
78
+ function isArithmetic(f) {
79
+ return (f.kind === 'add' ||
80
+ f.kind === 'subtract' ||
81
+ f.kind === 'multiply' ||
82
+ f.kind === 'divide' ||
83
+ f.kind === 'modulo');
84
+ }
85
+ function formulaMentionsVar(f, v) {
86
+ if (f.kind === 'atom' && f.name === v)
87
+ return true;
88
+ if (f.kind === 'predicate') {
89
+ const params = f.params ?? f.terms ?? [];
90
+ if (params.includes(v))
91
+ return true;
92
+ }
93
+ for (const child of f.args ?? []) {
94
+ if (formulaMentionsVar(child, v))
95
+ return true;
96
+ }
97
+ return false;
98
+ }
99
+ function walkFormula(f, visit) {
100
+ visit(f);
101
+ for (const child of f.args ?? []) {
102
+ walkFormula(child, visit);
103
+ }
104
+ }
105
+ function isFormulaLike(v) {
106
+ return !!v && typeof v === 'object' && typeof v.kind === 'string';
107
+ }
108
+ // ----------------------------------------------------------------
109
+ // Formula → Coq Type (dependent-aware)
110
+ // ----------------------------------------------------------------
111
+ /**
112
+ * Convierte una fórmula ST en un tipo Coq, con cuantificadores tipados según
113
+ * la inferencia dependiente. Caso por defecto: Prop.
114
+ */
115
+ function formulaToCoqType(formula) {
116
+ if (!isFormulaLike(formula))
117
+ return 'Prop';
118
+ const sorts = inferDependentSorts(formula);
119
+ return renderFormula(formula, sorts);
120
+ }
121
+ function renderFormula(formula, sorts) {
122
+ switch (formula.kind) {
123
+ case 'atom':
124
+ return formula.name ?? 'UnknownAtom';
125
+ case 'true':
126
+ return 'True';
127
+ case 'false':
128
+ return 'False';
129
+ case 'number':
130
+ return String(formula.value ?? 0);
131
+ case 'not': {
132
+ const inner = formula.args?.[0];
133
+ if (!inner)
134
+ return '(* missing arg for not *)';
135
+ const innerStr = renderFormula(inner, sorts);
136
+ return needsParens(inner) ? `(~ (${innerStr}))` : `(~ ${innerStr})`;
137
+ }
138
+ case 'and': {
139
+ const [l, r] = pair(formula);
140
+ if (!l || !r)
141
+ return '(* missing args for and *)';
142
+ return `(${renderFormula(l, sorts)} /\\ ${renderFormula(r, sorts)})`;
143
+ }
144
+ case 'or': {
145
+ const [l, r] = pair(formula);
146
+ if (!l || !r)
147
+ return '(* missing args for or *)';
148
+ return `(${renderFormula(l, sorts)} \\/ ${renderFormula(r, sorts)})`;
149
+ }
150
+ case 'implies': {
151
+ const [l, r] = pair(formula);
152
+ if (!l || !r)
153
+ return '(* missing args for implies *)';
154
+ return `(${renderFormula(l, sorts)} -> ${renderFormula(r, sorts)})`;
155
+ }
156
+ case 'biconditional': {
157
+ const [l, r] = pair(formula);
158
+ if (!l || !r)
159
+ return '(* missing args for biconditional *)';
160
+ return `(${renderFormula(l, sorts)} <-> ${renderFormula(r, sorts)})`;
161
+ }
162
+ case 'forall': {
163
+ const v = formula.variable ?? 'x';
164
+ const sort = sorts.get(v) ?? 'Prop';
165
+ const body = formula.args?.[0];
166
+ if (!body)
167
+ return `(* missing body for forall ${v} *)`;
168
+ return `(forall ${v} : ${sort}, ${renderFormula(body, sorts)})`;
169
+ }
170
+ case 'exists': {
171
+ const v = formula.variable ?? 'x';
172
+ const sort = sorts.get(v) ?? 'Prop';
173
+ const body = formula.args?.[0];
174
+ if (!body)
175
+ return `(* missing body for exists ${v} *)`;
176
+ return `(exists ${v} : ${sort}, ${renderFormula(body, sorts)})`;
177
+ }
178
+ case 'predicate': {
179
+ const name = formula.name ?? 'P';
180
+ const params = formula.params ?? formula.terms ?? [];
181
+ if (params.length === 0)
182
+ return name;
183
+ return `(${name} ${params.join(' ')})`;
184
+ }
185
+ case 'equals': {
186
+ const [l, r] = pair(formula);
187
+ if (!l || !r)
188
+ return '(* missing args for equals *)';
189
+ return `(${renderFormula(l, sorts)} = ${renderFormula(r, sorts)})`;
190
+ }
191
+ case 'less': {
192
+ const [l, r] = pair(formula);
193
+ if (!l || !r)
194
+ return '(* missing args for less *)';
195
+ return `(${renderFormula(l, sorts)} < ${renderFormula(r, sorts)})`;
196
+ }
197
+ case 'greater': {
198
+ const [l, r] = pair(formula);
199
+ if (!l || !r)
200
+ return '(* missing args for greater *)';
201
+ return `(${renderFormula(l, sorts)} > ${renderFormula(r, sorts)})`;
202
+ }
203
+ case 'less_eq': {
204
+ const [l, r] = pair(formula);
205
+ if (!l || !r)
206
+ return '(* missing args for less_eq *)';
207
+ return `(${renderFormula(l, sorts)} <= ${renderFormula(r, sorts)})`;
208
+ }
209
+ case 'greater_eq': {
210
+ const [l, r] = pair(formula);
211
+ if (!l || !r)
212
+ return '(* missing args for greater_eq *)';
213
+ return `(${renderFormula(l, sorts)} >= ${renderFormula(r, sorts)})`;
214
+ }
215
+ case 'add': {
216
+ const [l, r] = pair(formula);
217
+ if (!l || !r)
218
+ return '(* missing args for add *)';
219
+ return `(${renderFormula(l, sorts)} + ${renderFormula(r, sorts)})`;
220
+ }
221
+ case 'subtract': {
222
+ const [l, r] = pair(formula);
223
+ if (!l || !r)
224
+ return '(* missing args for subtract *)';
225
+ return `(${renderFormula(l, sorts)} - ${renderFormula(r, sorts)})`;
226
+ }
227
+ case 'multiply': {
228
+ const [l, r] = pair(formula);
229
+ if (!l || !r)
230
+ return '(* missing args for multiply *)';
231
+ return `(${renderFormula(l, sorts)} * ${renderFormula(r, sorts)})`;
232
+ }
233
+ default:
234
+ return `(* unsupported formula kind: ${formula.kind} *)`;
235
+ }
236
+ }
237
+ function pair(f) {
238
+ return [f.args?.[0], f.args?.[1]];
239
+ }
240
+ function needsParens(f) {
241
+ return (f.kind === 'and' ||
242
+ f.kind === 'or' ||
243
+ f.kind === 'implies' ||
244
+ f.kind === 'biconditional' ||
245
+ f.kind === 'forall' ||
246
+ f.kind === 'exists');
247
+ }
248
+ /**
249
+ * Elige la mejor tactic automática según las features de la fórmula.
250
+ * Reglas (ordenadas):
251
+ * 1. equality syntactically idéntica (a = a) → reflexivity.
252
+ * 2. aritmética puramente lineal (<, >, +, -, =, lia) → lia.
253
+ * 3. cuantificadores de primer orden con predicados → firstorder.
254
+ * 4. propositional clásico con ∨ + ¬ → tauto.
255
+ * 5. propositional con implicaciones encadenadas → intuition.
256
+ * 6. fallback → auto.
257
+ */
258
+ function chooseStrategy(formula) {
259
+ if (!isFormulaLike(formula))
260
+ return 'auto';
261
+ if (isTrivialReflexivity(formula))
262
+ return 'reflexivity';
263
+ if (hasArithmetic(formula))
264
+ return 'lia';
265
+ if (hasFirstOrderQuantifiers(formula))
266
+ return 'firstorder';
267
+ if (hasDisjunctionWithNegation(formula))
268
+ return 'tauto';
269
+ if (isPureImplicationChain(formula))
270
+ return 'intuition';
271
+ return 'auto';
272
+ }
273
+ function isTrivialReflexivity(f) {
274
+ // forall x, x = x
275
+ if (f.kind === 'forall') {
276
+ const body = f.args?.[0];
277
+ if (body?.kind === 'equals') {
278
+ const a = body.args?.[0];
279
+ const b = body.args?.[1];
280
+ if (a &&
281
+ b &&
282
+ a.kind === 'atom' &&
283
+ b.kind === 'atom' &&
284
+ a.name === b.name &&
285
+ a.name === f.variable) {
286
+ return true;
287
+ }
288
+ }
289
+ }
290
+ if (f.kind === 'equals') {
291
+ const a = f.args?.[0];
292
+ const b = f.args?.[1];
293
+ if (a && b && a.kind === 'atom' && b.kind === 'atom' && a.name === b.name)
294
+ return true;
295
+ }
296
+ return false;
297
+ }
298
+ function hasArithmetic(f) {
299
+ let found = false;
300
+ walkFormula(f, (node) => {
301
+ if (node.kind === 'less' ||
302
+ node.kind === 'greater' ||
303
+ node.kind === 'less_eq' ||
304
+ node.kind === 'greater_eq' ||
305
+ node.kind === 'add' ||
306
+ node.kind === 'subtract' ||
307
+ node.kind === 'multiply' ||
308
+ node.kind === 'modulo') {
309
+ found = true;
310
+ }
311
+ });
312
+ return found;
313
+ }
314
+ function hasFirstOrderQuantifiers(f) {
315
+ let hasQ = false;
316
+ let hasPred = false;
317
+ walkFormula(f, (node) => {
318
+ if (node.kind === 'forall' || node.kind === 'exists')
319
+ hasQ = true;
320
+ if (node.kind === 'predicate')
321
+ hasPred = true;
322
+ });
323
+ return hasQ && hasPred;
324
+ }
325
+ function hasDisjunctionWithNegation(f) {
326
+ let hasOr = false;
327
+ let hasNot = false;
328
+ walkFormula(f, (node) => {
329
+ if (node.kind === 'or')
330
+ hasOr = true;
331
+ if (node.kind === 'not')
332
+ hasNot = true;
333
+ });
334
+ return hasOr && hasNot;
335
+ }
336
+ function isPureImplicationChain(f) {
337
+ // (A -> B) -> (B -> C) -> A -> C — patrones encadenados
338
+ if (f.kind !== 'implies')
339
+ return false;
340
+ let hasNestedImp = false;
341
+ walkFormula(f, (node) => {
342
+ if (node.kind === 'implies' && node !== f)
343
+ hasNestedImp = true;
344
+ });
345
+ return hasNestedImp;
346
+ }
347
+ // ----------------------------------------------------------------
348
+ // Tactic block builder (per step)
349
+ // ----------------------------------------------------------------
350
+ function proofStepToTactics(step) {
351
+ const just = step.justification.toLowerCase();
352
+ if (just.includes('premise') || step.source === 'premise') {
353
+ return ` (* step ${step.stepNumber}: premise — already in context *)`;
354
+ }
355
+ if (just.includes('assumption') || step.source === 'assumption') {
356
+ return ` assumption.`;
357
+ }
358
+ if (just.includes('modus ponens') || just.includes('mp')) {
359
+ return ` apply H. (* MP — ajustar nombre de H *)`;
360
+ }
361
+ if (just.includes('intro') || just.includes('→i') || just.includes('implies intro')) {
362
+ return ` intro H.`;
363
+ }
364
+ if (just.includes('and intro') || just.includes('∧i'))
365
+ return ` split.`;
366
+ if (just.includes('and elim') || just.includes('∧e'))
367
+ return ` destruct H as [HL HR].`;
368
+ if (just.includes('or intro left') || just.includes('∨il'))
369
+ return ` left.`;
370
+ if (just.includes('or intro right') || just.includes('∨ir'))
371
+ return ` right.`;
372
+ if (just.includes('or elim') || just.includes('∨e'))
373
+ return ` destruct H as [HL | HR].`;
374
+ if (just.includes('not intro') || just.includes('¬i'))
375
+ return ` intro Habs.`;
376
+ if (just.includes('not elim') || just.includes('¬e') || just.includes('contradiction'))
377
+ return ` contradiction.`;
378
+ if (just.includes('forall intro') || just.includes('∀i'))
379
+ return ` intro x.`;
380
+ if (just.includes('forall elim') || just.includes('∀e'))
381
+ return ` apply H.`;
382
+ if (just.includes('exists intro') || just.includes('∃i'))
383
+ return ` exists x. (* instanciar con testigo real *)`;
384
+ if (just.includes('exists elim') || just.includes('∃e'))
385
+ return ` destruct H as [x Hx].`;
386
+ if (just.includes('reflex'))
387
+ return ` reflexivity.`;
388
+ if (just.includes('exact') || step.source === 'goal')
389
+ return ` exact H.`;
390
+ if (just.includes('auto'))
391
+ return ` auto.`;
392
+ if (just.includes('tauto'))
393
+ return ` tauto.`;
394
+ return ` auto. (* fallback step ${step.stepNumber}: ${step.justification} *)`;
395
+ }
396
+ function buildTacticBlock(proof, fallback, useAuto) {
397
+ if (proof.status !== 'complete' || proof.steps.length === 0) {
398
+ const tac = useAuto ? ` ${fallback}.` : ` admit.`;
399
+ return tac;
400
+ }
401
+ return proof.steps.map((step) => proofStepToTactics(step)).join('\n');
402
+ }
403
+ // ----------------------------------------------------------------
404
+ // Heuristic tactic for a bare formula
405
+ // ----------------------------------------------------------------
406
+ function heuristicTacticsForFormula(formula, useAuto) {
407
+ const strat = chooseStrategy(formula);
408
+ // strategies devuelven 1 tactic + Qed cierra. admit no usa Qed.
409
+ if (strat === 'reflexivity') {
410
+ if (formula.kind === 'forall')
411
+ return ` intros. reflexivity.`;
412
+ return ` reflexivity.`;
413
+ }
414
+ if (strat === 'lia')
415
+ return ` intros. lia.`;
416
+ if (strat === 'firstorder')
417
+ return ` firstorder.`;
418
+ if (strat === 'tauto')
419
+ return ` tauto.`;
420
+ if (strat === 'intuition')
421
+ return ` intuition.`;
422
+ if (strat === 'auto')
423
+ return useAuto ? ` intros. auto.` : ` admit.`;
424
+ return ` admit.`;
425
+ }
426
+ // ----------------------------------------------------------------
427
+ // Proof term reconstruction
428
+ // ----------------------------------------------------------------
429
+ /**
430
+ * Genera un proof term (lambda) directo desde un Proof object.
431
+ * Soporta patrones básicos: identidad, MP, conjunción/disyunción intro-elim.
432
+ * Para casos no manejados devuelve un placeholder con TODO.
433
+ */
434
+ function ndProofToProofTerm(proof) {
435
+ if (!proof || typeof proof !== 'object')
436
+ return '(* invalid proof *)';
437
+ const p = proof;
438
+ // Identity: P -> P
439
+ if (p.goal &&
440
+ p.goal.kind === 'implies' &&
441
+ p.goal.args?.[0]?.kind === 'atom' &&
442
+ p.goal.args?.[1]?.kind === 'atom' &&
443
+ p.goal.args[0].name === p.goal.args[1].name) {
444
+ return `fun (${p.goal.args[0].name} : Prop) (H : ${p.goal.args[0].name}) => H`;
445
+ }
446
+ // (A -> B) -> A -> B (modus ponens — curry full).
447
+ // En AST: implies(implies(A,B), implies(A, B)).
448
+ if (p.goal &&
449
+ p.goal.kind === 'implies' &&
450
+ p.goal.args?.[0]?.kind === 'implies' &&
451
+ p.goal.args?.[1]?.kind === 'implies') {
452
+ const ab = p.goal.args[0];
453
+ const ab2 = p.goal.args[1];
454
+ const a = ab.args?.[0];
455
+ const b = ab.args?.[1];
456
+ const a2 = ab2.args?.[0];
457
+ const b2 = ab2.args?.[1];
458
+ if (a?.kind === 'atom' &&
459
+ b?.kind === 'atom' &&
460
+ a2?.kind === 'atom' &&
461
+ b2?.kind === 'atom' &&
462
+ a.name === a2.name &&
463
+ b.name === b2.name) {
464
+ return `fun (H1 : ${a.name} -> ${b.name}) (H2 : ${a.name}) => H1 H2`;
465
+ }
466
+ }
467
+ // (P /\ Q) -> P (and elim left)
468
+ if (p.goal &&
469
+ p.goal.kind === 'implies' &&
470
+ p.goal.args?.[0]?.kind === 'and' &&
471
+ p.goal.args?.[1]?.kind === 'atom') {
472
+ const andF = p.goal.args[0];
473
+ const target = p.goal.args[1];
474
+ const left = andF.args?.[0];
475
+ const right = andF.args?.[1];
476
+ if (left?.kind === 'atom' && right?.kind === 'atom') {
477
+ if (left.name === target.name) {
478
+ return `fun (H : ${left.name} /\\ ${right.name}) => match H with | conj HL _ => HL end`;
479
+ }
480
+ if (right.name === target.name) {
481
+ return `fun (H : ${left.name} /\\ ${right.name}) => match H with | conj _ HR => HR end`;
482
+ }
483
+ }
484
+ }
485
+ // forall x : T, x = x → fun x => eq_refl x
486
+ if (p.goal?.kind === 'forall') {
487
+ const body = p.goal.args?.[0];
488
+ if (body?.kind === 'equals' &&
489
+ body.args?.[0]?.kind === 'atom' &&
490
+ body.args?.[1]?.kind === 'atom' &&
491
+ body.args[0].name === body.args[1].name) {
492
+ const v = p.goal.variable ?? 'x';
493
+ return `fun (${v} : nat) => eq_refl ${v}`;
494
+ }
495
+ }
496
+ return `(* TODO: proof term reconstruction not implemented for this shape *)`;
497
+ }
498
+ // ----------------------------------------------------------------
499
+ // Hints generation
500
+ // ----------------------------------------------------------------
501
+ /**
502
+ * Genera líneas `Hint Resolve` / `Hint Rewrite` para una base `stdb`.
503
+ * - Axiomas con head implicación → `Hint Resolve`.
504
+ * - Igualdades universales → `Hint Rewrite`.
505
+ * - Theorems "obvios" (identidad, P→P) también van como Hint Resolve.
506
+ */
507
+ function generateHints(axioms, theorems) {
508
+ const lines = [];
509
+ const axiomList = Array.isArray(axioms) ? axioms : [];
510
+ const theoremList = Array.isArray(theorems) ? theorems : [];
511
+ axiomList.forEach((ax, i) => {
512
+ if (!isFormulaLike(ax))
513
+ return;
514
+ const name = `Ax_${i + 1}`;
515
+ if (isEqualityRewrite(ax)) {
516
+ lines.push(`Hint Rewrite ${name} : stdb.`);
517
+ }
518
+ else {
519
+ lines.push(`Hint Resolve ${name} : stdb.`);
520
+ }
521
+ });
522
+ theoremList.forEach((th, i) => {
523
+ if (!isFormulaLike(th))
524
+ return;
525
+ const name = `Th_${i + 1}`;
526
+ lines.push(`Hint Resolve ${name} : stdb.`);
527
+ });
528
+ return lines;
529
+ }
530
+ function isEqualityRewrite(f) {
531
+ if (f.kind === 'equals')
532
+ return true;
533
+ if (f.kind === 'forall') {
534
+ const body = f.args?.[0];
535
+ if (body)
536
+ return isEqualityRewrite(body);
537
+ }
538
+ return false;
539
+ }
540
+ // ----------------------------------------------------------------
541
+ // Import inference
542
+ // ----------------------------------------------------------------
543
+ function inferImports(formula, opts) {
544
+ if (opts.imports && opts.imports.length > 0)
545
+ return opts.imports;
546
+ const set = new Set();
547
+ // Default classical for excluded middle
548
+ set.add('Classical');
549
+ if (formula) {
550
+ if (hasArithmetic(formula)) {
551
+ set.add('Arith');
552
+ set.add('Lia');
553
+ }
554
+ walkFormula(formula, (node) => {
555
+ if (node.kind === 'list')
556
+ set.add('List');
557
+ });
558
+ }
559
+ return Array.from(set);
560
+ }
561
+ // ----------------------------------------------------------------
562
+ // Main API
563
+ // ----------------------------------------------------------------
564
+ /**
565
+ * Exporta una fórmula ST a Coq como módulo V2 con tactic strategy automática.
566
+ */
567
+ function exportToCoqV2(formula, opts) {
568
+ const moduleName = opts?.moduleName ?? 'STExportV2';
569
+ const emitMode = opts?.emitMode ?? 'tactic';
570
+ const useAuto = opts?.useAuto ?? true;
571
+ const useHints = opts?.useHints ?? true;
572
+ const emitHints = opts?.emitHints ?? false;
573
+ if (!isFormulaLike(formula)) {
574
+ return `(* coq-v2: input is not a Formula AST *)`;
575
+ }
576
+ const term = formulaToCoqType(formula);
577
+ const imports = inferImports(formula, opts ?? {});
578
+ const lines = [];
579
+ for (const imp of imports) {
580
+ lines.push(`Require Import ${imp}.`);
581
+ }
582
+ lines.push('');
583
+ lines.push(`Module ${moduleName}.`);
584
+ lines.push(` Definition stmt : Prop := ${term}.`);
585
+ if (emitHints) {
586
+ lines.push(` (* hints registrados en base stdb *)`);
587
+ }
588
+ if (emitMode === 'tactic' || emitMode === 'both') {
589
+ lines.push(` Theorem stmt_proof : stmt.`);
590
+ lines.push(' Proof.');
591
+ lines.push(heuristicTacticsForFormula(formula, useAuto));
592
+ if (useHints) {
593
+ lines.push(` (* auto with stdb registered hints if needed *)`);
594
+ }
595
+ lines.push(' Qed.');
596
+ }
597
+ if (emitMode === 'proofterm' || emitMode === 'both') {
598
+ const fakeProof = { goal: formula, status: 'complete', steps: [] };
599
+ const term2 = ndProofToProofTerm(fakeProof);
600
+ lines.push(` Definition stmt_term : stmt := ${term2}.`);
601
+ }
602
+ lines.push(`End ${moduleName}.`);
603
+ return lines.join('\n');
604
+ }
605
+ /**
606
+ * Exporta un Proof ST a Coq como módulo V2, derivando tactics desde steps
607
+ * y, opcionalmente, un proof term reconstruido.
608
+ */
609
+ function exportProofToCoqV2(proof, opts) {
610
+ const moduleName = opts?.moduleName ?? 'STExportV2';
611
+ const emitMode = opts?.emitMode ?? 'tactic';
612
+ const useAuto = opts?.useAuto ?? true;
613
+ if (!proof || typeof proof !== 'object' || !('goal' in proof)) {
614
+ return `(* coq-v2: input is not a Proof *)`;
615
+ }
616
+ const p = proof;
617
+ const term = formulaToCoqType(p.goal);
618
+ const imports = inferImports(p.goal, opts ?? {});
619
+ const fallback = chooseStrategy(p.goal);
620
+ const lines = [];
621
+ for (const imp of imports) {
622
+ lines.push(`Require Import ${imp}.`);
623
+ }
624
+ lines.push('');
625
+ lines.push(`Module ${moduleName}.`);
626
+ lines.push(` Definition stmt : Prop := ${term}.`);
627
+ if (emitMode === 'tactic' || emitMode === 'both') {
628
+ lines.push(` Theorem stmt_proof : stmt.`);
629
+ lines.push(' Proof.');
630
+ lines.push(buildTacticBlock(p, fallback, useAuto));
631
+ lines.push(' Qed.');
632
+ }
633
+ if (emitMode === 'proofterm' || emitMode === 'both') {
634
+ const term2 = ndProofToProofTerm(p);
635
+ lines.push(` Definition stmt_term : stmt := ${term2}.`);
636
+ }
637
+ lines.push(`End ${moduleName}.`);
638
+ return lines.join('\n');
639
+ }
640
+ /**
641
+ * Exporta una teoría completa: axiomas + theorems con hints derivados.
642
+ */
643
+ function exportTheoryToCoqV2(axioms, theorems, opts) {
644
+ const moduleName = opts?.moduleName ?? 'STTheoryV2';
645
+ const emitHints = opts?.emitHints ?? true;
646
+ const useAuto = opts?.useAuto ?? true;
647
+ const lines = [];
648
+ // Imports: combinar de toda la teoría
649
+ const importsSet = new Set();
650
+ const all = [...axioms, ...theorems];
651
+ for (const f of all) {
652
+ if (!isFormulaLike(f))
653
+ continue;
654
+ const imp = inferImports(f, opts ?? {});
655
+ for (const i of imp)
656
+ importsSet.add(i);
657
+ }
658
+ for (const imp of importsSet) {
659
+ lines.push(`Require Import ${imp}.`);
660
+ }
661
+ lines.push('');
662
+ lines.push(`Module ${moduleName}.`);
663
+ // Axiomas
664
+ axioms.forEach((ax, i) => {
665
+ if (!isFormulaLike(ax))
666
+ return;
667
+ const t = formulaToCoqType(ax);
668
+ lines.push(` Axiom Ax_${i + 1} : ${t}.`);
669
+ });
670
+ // Theorems
671
+ theorems.forEach((th, i) => {
672
+ if (!isFormulaLike(th))
673
+ return;
674
+ const t = formulaToCoqType(th);
675
+ lines.push(` Theorem Th_${i + 1} : ${t}.`);
676
+ lines.push(' Proof.');
677
+ lines.push(heuristicTacticsForFormula(th, useAuto));
678
+ lines.push(' Qed.');
679
+ });
680
+ if (emitHints) {
681
+ const hints = generateHints(axioms, theorems);
682
+ if (hints.length > 0) {
683
+ lines.push('');
684
+ lines.push(` (* hints — base "stdb" *)`);
685
+ for (const h of hints)
686
+ lines.push(` ${h}`);
687
+ }
688
+ }
689
+ lines.push(`End ${moduleName}.`);
690
+ return lines.join('\n');
691
+ }
692
+ //# sourceMappingURL=index.js.map