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

Function checkConstraints

src/compute-engine/sequence.ts:234–258  ·  view source on GitHub ↗

* Check constraint expression for multi-index sequences. * Returns true if constraints are satisfied or no constraints exist.

(
  ce: ComputeEngine,
  constraints: Expression,
  variables: string[],
  indices: number[]
)

Source from the content-addressed store, hash-verified

232 if (constraint.max !== undefined && index > constraint.max) return false;
233 }
234 }
235 return true;
236}
237
238/**
239 * Check constraint expression for multi-index sequences.
240 * Returns true if constraints are satisfied or no constraints exist.
241 */
242function checkConstraints(
243 ce: ComputeEngine,
244 constraints: Expression,
245 variables: string[],
246 indices: number[]
247): boolean {
248 // Substitute variable values
249 const subs: Record<string, Expression> = {};
250 for (let i = 0; i < variables.length; i++) {
251 subs[variables[i]] = ce.number(indices[i]);
252 }
253
254 const substituted = constraints.subs(subs);
255 const result = substituted.evaluate();
256
257 // Check if result is truthy (non-zero number or True)
258 if (isSymbol(result)) {
259 if (result.symbol === 'True') return true;
260 if (result.symbol === 'False') return false;
261 }

Callers 1

createSequenceHandlerFunction · 0.85

Calls 5

isSymbolFunction · 0.90
isNumberFunction · 0.90
numberMethod · 0.65
subsMethod · 0.65
evaluateMethod · 0.65

Tested by

no test coverage detected