Universal and Existential Conditions in Programs

A universal condition requires a predicate for every eligible element. An existential condition requires at least one witness.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Read empty input mathematically
  2. Add a separate nonempty condition
  3. Trace how one witness determines an early result
  4. Check aggregate meaning for empty batches

Read empty input mathematically

For an empty collection, “all exceed five” is true because no counterexample exists. “Some exceeds five” is false because there is no witness. This is the behavior of any and all in Python.

Add a separate nonempty condition

A report accepting only nonempty batches with positive counts must check both conditions. A universal check alone would accept the empty batch. Guard clauses can state that prerequisite before scanning the input.[1]

Trace how one witness determines an early result

Consider batch values six, two and nine with test “greater than four.” An existential scan can return true after six. A universal scan can return false after two. Even though both use the same predicate, success and failure witnesses differ. See folding Boolean results.

Predicate values: true, false, true
Any is true, witnessed at index 0
All is false, contradicted at index 1
On empty input: any false, all true

Check aggregate meaning for empty batches

If the product requires at least one row and every row valid, combine a nonempty check with the universal predicate. Applying only the universal test accepts empty input under its mathematical meaning. Test absence separately from rejection of a present row.

References

  1. Eric Lehman, F. Thomson Leighton and Albert R. Meyer, Mathematics for Computer Science ↩