* Evaluate ForAll over a finite domain. * ∀x∈S. P(x) is true iff P(x) is true for all x in S. * * Symbolic simplifications: * - ∀x. True → True * - ∀x. False → False * - ∀x. P (where P doesn't contain x) → P * * Nested quantifiers: * - ∀x∈S. ∀y∈T. P(x,y) evaluates over the Cartesian product
(
args: ReadonlyArray<Expression>,
{ engine: ce }: { engine: ComputeEngine }
)
| 275 | ops: ReadonlyArray<Expression>, |
| 276 | options: EvaluateHandlerOptions |
| 277 | ) => Promise<Expression | undefined> { |
| 278 | return async (ops, options) => { |
| 279 | const ce = options.engine; |
| 280 | const evalOptions = evaluateOptionsOf(options); |
| 281 | const elementwise = ops.some(isCollectionShaped); |
| 282 | const values: Expression[] = []; |
| 283 | let failed: Expression | undefined = undefined; |
| 284 | for (let i = 0; i < ops.length; i++) { |
| 285 | const v = await ops[i].evaluateAsync(evalOptions); |
| 286 | if (!elementwise) { |
| 287 | const decided = decide(ce, v, i); |
| 288 | if (decided) return decided; |
| 289 | if (!v.isValid) { |
| 290 | failed ??= v; |
| 291 | continue; |
| 292 | } |
| 293 | } |
| 294 | values.push(v); |
| 295 | } |
| 296 | if (failed) return failed; |
| 297 | return finishShortCircuit( |
| 298 | ce, |
| 299 | name, |
| 300 | ops, |
| 301 | values, |
| 302 | decide, |
| 303 | reduce, |
| 304 | evalOptions |
| 305 | ); |
| 306 | }; |
| 307 | } |
| 308 | |
| 309 | type ShortCircuitOperator = 'And' | 'Or' | 'Nand' | 'Nor' | 'Implies'; |
| 310 | |
| 311 | /** Does the evaluated operand `v`, at position `i`, decide the result by |
| 312 | * itself? Returns the result if so, `undefined` otherwise. */ |
| 313 | type Decider = ( |
| 314 | ce: ComputeEngine, |
| 315 | v: Expression, |
| 316 | i: number |
| 317 | ) => Expression | undefined; |
| 318 | |
| 319 | /** The order-independent symbolic reducer applied to the surviving values. */ |
| 320 | type Reducer = ( |
| 321 | args: ReadonlyArray<Expression>, |
| 322 | options: { engine: ComputeEngine } |
| 323 | ) => Expression | undefined; |
| 324 | |
| 325 | /** Is `v` `False`, or an absent value (`Missing`), which a |
| 326 | * connective reads as `False`? The logic is two-valued: an absent value is |
| 327 | * not a third truth value (user decision 2026-11-02, `docs/ERROR-MODEL.md`, |
| 328 | * two-valued comparisons). */ |
| 329 | function readsFalse(v: Expression): boolean { |
| 330 | const s = sym(v); |
| 331 | return s === 'False' || s === 'Missing'; |
| 332 | } |
| 333 | /** `And` stops at the first `False` (result `False`). */ |
| 334 | const decideAnd: Decider = (ce, v) => (readsFalse(v) ? ce.False : undefined); |
no test coverage detected