MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / runCE

Function runCE

benchmarks/audit/audit.ts:82–134  ·  view source on GitHub ↗
(c: any)

Source from the content-addressed store, hash-verified

80
81// --- run CE in-process -----------------------------------------------------
82function runCE(c: any) {
83 const inp = c.ce, op = inp.op;
84 try {
85 if (op === 'factor' || op === 'expand') {
86 const head = op === 'factor' ? 'Factor' : 'Expand';
87 const timing = timeit(() => ce.expr([head, inp.mathjson]).evaluate());
88 const r = ce.expr([head, inp.mathjson]).evaluate();
89 if (c.verify.kind === 'mantexp') {
90 // constant expansion: grade the exact components (huge magnitudes —
91 // .N()/.re would overflow float64)
92 if (!r.isNumberLiteral)
93 return { status: 'unsolved', text: r.toString().slice(0, 200), values: [], ...timing };
94 const values = [...mantExp10(r.bignumRe?.toString()), ...mantExp10(r.bignumIm?.toString())];
95 return { status: 'ok', text: r.toString().slice(0, 200), values, ...timing };
96 }
97 return { status: 'ok', text: r.toString().slice(0, 200), values: sampleResult(r, c), ...timing };
98 }
99 if (op === 'gcd') {
100 const timing = timeit(() => ce.expr(inp.mathjson).evaluate());
101 const r = ce.expr(inp.mathjson).evaluate();
102 // unevaluated GCD comes back as a gcd(...) function node
103 const unsolved = r.operator === 'GCD' || /\bgcd\(/i.test(r.toString());
104 return { status: unsolved ? 'unsolved' : 'ok', text: r.toString(), values: sampleResult(r, c), ...timing };
105 }
106 if (op === 'simplify') {
107 const timing = timeit(() => ce.expr(inp.mathjson).simplify());
108 const r = ce.expr(inp.mathjson).simplify();
109 return { status: 'ok', text: r.toString(), values: sampleResult(r, c), ...timing };
110 }
111 if (op === 'integrate') {
112 const build = () => ce.expr(['Integrate', inp.mathjson, ['Tuple', inp.var]]).evaluate();
113 const timing = timeit(build);
114 const F = build();
115 if (F.operator === 'Integrate' || /\bint\(/.test(F.toString()))
116 return { status: 'unsolved', text: F.toString(), values: [], ...timing };
117 const dF = ce.expr(['D', F, inp.var]).evaluate();
118 return { status: 'ok', text: F.toString(), values: sampleResult(dF, c), ...timing };
119 }
120 if (op === 'limit') {
121 // CE evaluates limits to an exact symbolic closed form (e.g. 1/2, e); we
122 // sample that result numerically only to grade it against the reference.
123 const build = () => ce.expr(['Limit', ['Function', inp.mathjson, inp.var], inp.point]).evaluate();
124 const timing = timeit(build);
125 const L = build();
126 const val = num(L);
127 if (!isFinite(val)) return { status: 'unsolved', text: L.toString(), values: [], ...timing };
128 return { status: 'ok', text: L.toString(), values: [val], ...timing };
129 }
130 return { status: 'error', error: `unknown op ${op}` };
131 } catch (e: any) {
132 return { status: 'error', error: String(e?.message ?? e).slice(0, 160) };
133 }
134}
135
136// --- run SymPy batch -------------------------------------------------------
137function runSymPyAll(): Record<string, any> {

Callers 1

audit.tsFile · 0.70

Calls 11

mantExp10Function · 0.85
sampleResultFunction · 0.85
isFiniteFunction · 0.85
timeitFunction · 0.70
buildFunction · 0.70
numFunction · 0.70
evaluateMethod · 0.65
exprMethod · 0.65
sliceMethod · 0.65
toStringMethod · 0.65
simplifyMethod · 0.65

Tested by

no test coverage detected