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.
- package/LICENSE +21 -0
- package/README.md +339 -0
- package/package.json +75 -0
- package/src/index.ts +38 -0
- package/src/lib/cache.ts +246 -0
- package/src/lib/compression.ts +804 -0
- package/src/lib/compute/cache.ts +86 -0
- package/src/lib/compute/classifier.ts +555 -0
- package/src/lib/compute/confidence.ts +79 -0
- package/src/lib/compute/context.ts +154 -0
- package/src/lib/compute/extract.ts +200 -0
- package/src/lib/compute/filter.ts +224 -0
- package/src/lib/compute/index.ts +171 -0
- package/src/lib/compute/math.ts +247 -0
- package/src/lib/compute/patterns.ts +564 -0
- package/src/lib/compute/registry.ts +145 -0
- package/src/lib/compute/solvers/arithmetic.ts +65 -0
- package/src/lib/compute/solvers/calculus.ts +249 -0
- package/src/lib/compute/solvers/derivation-core.ts +371 -0
- package/src/lib/compute/solvers/derivation-latex.ts +160 -0
- package/src/lib/compute/solvers/derivation-mistakes.ts +1046 -0
- package/src/lib/compute/solvers/derivation-simplify.ts +451 -0
- package/src/lib/compute/solvers/derivation-transform.ts +620 -0
- package/src/lib/compute/solvers/derivation.ts +67 -0
- package/src/lib/compute/solvers/facts.ts +120 -0
- package/src/lib/compute/solvers/formula.ts +728 -0
- package/src/lib/compute/solvers/index.ts +36 -0
- package/src/lib/compute/solvers/logic.ts +422 -0
- package/src/lib/compute/solvers/probability.ts +307 -0
- package/src/lib/compute/solvers/statistics.ts +262 -0
- package/src/lib/compute/solvers/word-problems.ts +408 -0
- package/src/lib/compute/types.ts +107 -0
- package/src/lib/concepts.ts +111 -0
- package/src/lib/domain.ts +731 -0
- package/src/lib/extraction.ts +912 -0
- package/src/lib/index.ts +122 -0
- package/src/lib/judge.ts +260 -0
- package/src/lib/math/ast.ts +842 -0
- package/src/lib/math/index.ts +8 -0
- package/src/lib/math/operators.ts +171 -0
- package/src/lib/math/tokenizer.ts +477 -0
- package/src/lib/patterns.ts +200 -0
- package/src/lib/session.ts +825 -0
- package/src/lib/think/challenge.ts +323 -0
- package/src/lib/think/complexity.ts +504 -0
- package/src/lib/think/confidence-drift.ts +507 -0
- package/src/lib/think/consistency.ts +347 -0
- package/src/lib/think/guidance.ts +188 -0
- package/src/lib/think/helpers.ts +568 -0
- package/src/lib/think/hypothesis.ts +216 -0
- package/src/lib/think/index.ts +127 -0
- package/src/lib/think/prompts.ts +262 -0
- package/src/lib/think/route.ts +358 -0
- package/src/lib/think/schema.ts +98 -0
- package/src/lib/think/scratchpad-schema.ts +662 -0
- package/src/lib/think/spot-check.ts +961 -0
- package/src/lib/think/types.ts +93 -0
- package/src/lib/think/verification.ts +260 -0
- package/src/lib/tokens.ts +177 -0
- package/src/lib/verification.ts +620 -0
- package/src/prompts/index.ts +10 -0
- package/src/prompts/templates.ts +336 -0
- package/src/resources/index.ts +8 -0
- package/src/resources/sessions.ts +196 -0
- package/src/tools/compress.ts +138 -0
- package/src/tools/index.ts +5 -0
- package/src/tools/scratchpad.ts +2659 -0
- 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
|
+
};
|