verifiable-thinking-mcp 0.4.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 (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +339 -0
  3. package/package.json +75 -0
  4. package/src/index.ts +38 -0
  5. package/src/lib/cache.ts +246 -0
  6. package/src/lib/compression.ts +804 -0
  7. package/src/lib/compute/cache.ts +86 -0
  8. package/src/lib/compute/classifier.ts +555 -0
  9. package/src/lib/compute/confidence.ts +79 -0
  10. package/src/lib/compute/context.ts +154 -0
  11. package/src/lib/compute/extract.ts +200 -0
  12. package/src/lib/compute/filter.ts +224 -0
  13. package/src/lib/compute/index.ts +171 -0
  14. package/src/lib/compute/math.ts +247 -0
  15. package/src/lib/compute/patterns.ts +564 -0
  16. package/src/lib/compute/registry.ts +145 -0
  17. package/src/lib/compute/solvers/arithmetic.ts +65 -0
  18. package/src/lib/compute/solvers/calculus.ts +249 -0
  19. package/src/lib/compute/solvers/derivation-core.ts +371 -0
  20. package/src/lib/compute/solvers/derivation-latex.ts +160 -0
  21. package/src/lib/compute/solvers/derivation-mistakes.ts +1046 -0
  22. package/src/lib/compute/solvers/derivation-simplify.ts +451 -0
  23. package/src/lib/compute/solvers/derivation-transform.ts +620 -0
  24. package/src/lib/compute/solvers/derivation.ts +67 -0
  25. package/src/lib/compute/solvers/facts.ts +120 -0
  26. package/src/lib/compute/solvers/formula.ts +728 -0
  27. package/src/lib/compute/solvers/index.ts +36 -0
  28. package/src/lib/compute/solvers/logic.ts +422 -0
  29. package/src/lib/compute/solvers/probability.ts +307 -0
  30. package/src/lib/compute/solvers/statistics.ts +262 -0
  31. package/src/lib/compute/solvers/word-problems.ts +408 -0
  32. package/src/lib/compute/types.ts +107 -0
  33. package/src/lib/concepts.ts +111 -0
  34. package/src/lib/domain.ts +731 -0
  35. package/src/lib/extraction.ts +912 -0
  36. package/src/lib/index.ts +122 -0
  37. package/src/lib/judge.ts +260 -0
  38. package/src/lib/math/ast.ts +842 -0
  39. package/src/lib/math/index.ts +8 -0
  40. package/src/lib/math/operators.ts +171 -0
  41. package/src/lib/math/tokenizer.ts +477 -0
  42. package/src/lib/patterns.ts +200 -0
  43. package/src/lib/session.ts +825 -0
  44. package/src/lib/think/challenge.ts +323 -0
  45. package/src/lib/think/complexity.ts +504 -0
  46. package/src/lib/think/confidence-drift.ts +507 -0
  47. package/src/lib/think/consistency.ts +347 -0
  48. package/src/lib/think/guidance.ts +188 -0
  49. package/src/lib/think/helpers.ts +568 -0
  50. package/src/lib/think/hypothesis.ts +216 -0
  51. package/src/lib/think/index.ts +127 -0
  52. package/src/lib/think/prompts.ts +262 -0
  53. package/src/lib/think/route.ts +358 -0
  54. package/src/lib/think/schema.ts +98 -0
  55. package/src/lib/think/scratchpad-schema.ts +662 -0
  56. package/src/lib/think/spot-check.ts +961 -0
  57. package/src/lib/think/types.ts +93 -0
  58. package/src/lib/think/verification.ts +260 -0
  59. package/src/lib/tokens.ts +177 -0
  60. package/src/lib/verification.ts +620 -0
  61. package/src/prompts/index.ts +10 -0
  62. package/src/prompts/templates.ts +336 -0
  63. package/src/resources/index.ts +8 -0
  64. package/src/resources/sessions.ts +196 -0
  65. package/src/tools/compress.ts +138 -0
  66. package/src/tools/index.ts +5 -0
  67. package/src/tools/scratchpad.ts +2659 -0
  68. package/src/tools/sessions.ts +144 -0
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Mathematical Facts Solver
3
+ * Handles questions about known mathematical properties/facts
4
+ * that don't require computation - just knowledge lookup
5
+ */
6
+
7
+ import { SolverType } from "../classifier.ts";
8
+ import type { ComputeResult, Solver } from "../types.ts";
9
+
10
+ /**
11
+ * Known irrational numbers (common ones asked about)
12
+ */
13
+ const KNOWN_IRRATIONALS = new Set([
14
+ "sqrt(2)",
15
+ "√2",
16
+ "sqrt2",
17
+ "sqrt(3)",
18
+ "√3",
19
+ "sqrt3",
20
+ "sqrt(5)",
21
+ "√5",
22
+ "sqrt5",
23
+ "sqrt(7)",
24
+ "√7",
25
+ "sqrt7",
26
+ "sqrt(11)",
27
+ "√11",
28
+ "sqrt11",
29
+ "pi",
30
+ "π",
31
+ "e",
32
+ "euler",
33
+ "phi",
34
+ "φ",
35
+ "golden ratio",
36
+ ]);
37
+
38
+ /**
39
+ * Perfect squares (sqrt is rational)
40
+ */
41
+ const PERFECT_SQUARES = new Set([1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225]);
42
+
43
+ /**
44
+ * Try to answer rationality questions
45
+ * "Is sqrt(2) rational or irrational?"
46
+ * "Is pi rational?"
47
+ */
48
+ export function tryMathFacts(text: string): ComputeResult {
49
+ const start = performance.now();
50
+ const lower = text.toLowerCase();
51
+
52
+ // Check for rationality questions
53
+ if (lower.includes("rational") || lower.includes("irrational")) {
54
+ // Check for sqrt(n), √n, or "square root of n" patterns
55
+ const sqrtMatch = text.match(/sqrt\s*\(?\s*(\d+)\s*\)?|√(\d+)|square\s+root\s+of\s+(\d+)/i);
56
+ if (sqrtMatch) {
57
+ const n = parseInt(sqrtMatch[1] || sqrtMatch[2] || sqrtMatch[3] || "", 10);
58
+ if (!Number.isNaN(n)) {
59
+ const isRational = PERFECT_SQUARES.has(n);
60
+ return {
61
+ solved: true,
62
+ result: isRational ? "RATIONAL" : "IRRATIONAL",
63
+ method: "math_fact_rationality",
64
+ confidence: 1.0,
65
+ time_ms: performance.now() - start,
66
+ };
67
+ }
68
+ }
69
+
70
+ // Check for known irrationals by name
71
+ for (const irrational of KNOWN_IRRATIONALS) {
72
+ if (lower.includes(irrational.toLowerCase())) {
73
+ return {
74
+ solved: true,
75
+ result: "IRRATIONAL",
76
+ method: "math_fact_known_irrational",
77
+ confidence: 1.0,
78
+ time_ms: performance.now() - start,
79
+ };
80
+ }
81
+ }
82
+
83
+ // Check for integer rationality
84
+ const intMatch = lower.match(/is\s+(\d+)\s+rational/);
85
+ if (intMatch) {
86
+ return {
87
+ solved: true,
88
+ result: "RATIONAL",
89
+ method: "math_fact_integer",
90
+ confidence: 1.0,
91
+ time_ms: performance.now() - start,
92
+ };
93
+ }
94
+
95
+ // Check for fraction rationality
96
+ if (lower.includes("fraction") || /\d+\s*\/\s*\d+/.test(text)) {
97
+ return {
98
+ solved: true,
99
+ result: "RATIONAL",
100
+ method: "math_fact_fraction",
101
+ confidence: 1.0,
102
+ time_ms: performance.now() - start,
103
+ };
104
+ }
105
+ }
106
+
107
+ return { solved: false, confidence: 0 };
108
+ }
109
+
110
+ // =============================================================================
111
+ // SOLVER REGISTRATION
112
+ // =============================================================================
113
+
114
+ export const solver: Solver = {
115
+ name: "facts",
116
+ description: "Mathematical facts: rationality of sqrt, pi, e, integers, fractions",
117
+ types: SolverType.FACTS,
118
+ priority: 5, // Runs first - instant lookups
119
+ solve: (text, _lower) => tryMathFacts(text),
120
+ };