Exercise 2: Rewriting "not any(order.total < 0 ...)" as an ALL Statement — Possible Solution ==================================================================== IDENTIFYING THE ORIGINAL STATEMENT'S SHAPE ------------------------------ "any(order.total < 0 for order in orders)" is exactly Chapter 3's own ∃x P(x) pattern, where the domain is `orders` and P(order) is "order.total < 0". The full original expression, "not any(...)", is therefore ¬(∃x P(x)). APPLYING DE MORGAN'S LAW FOR QUANTIFIERS ------------------------------ Per this chapter, "¬(∃x P(x)) ≡ ∀x ¬P(x)" - negating an existence claim becomes a universal claim about the negated predicate. Applying this directly: not any(order.total < 0 for order in orders) == all(not (order.total < 0) for order in orders) Simplifying "not (order.total < 0)" to its more natural form, "order.total >= 0", gives the final rewrite: all(order.total >= 0 for order in orders) PLAIN ENGLISH FOR THE REWRITTEN VERSION ------------------------------ "Every order has a non-negative total" - equivalently, "no order has a negative total." Both phrasings describe the same underlying ∀ statement; the second is just the negated-∃ framing restated in ordinary English rather than formal ∀ notation. WHY THE TWO VERSIONS ARE GUARANTEED TO BEHAVE IDENTICALLY ------------------------------ This isn't a stylistic rewrite - it's the same logical equivalence Chapter 3 establishes explicitly as a "genuinely useful real refactor" in its own worked example (not all(...) == any(not ...)), applied here in its ∃-to-∀ direction instead. For any possible collection of orders, the two expressions will always evaluate to the same boolean result. WHY THIS REWRITE IS GENUINELY USEFUL, NOT JUST EQUIVALENT ------------------------------ The rewritten version reads more directly as a positive assertion about what should be true ("every total is non-negative") rather than a negated statement about what should NOT exist ("there's no negative total") - often easier to reason about correctly, especially once further conditions get added to the check later. WHY THIS WORKS AS AN ANSWER ------------------------------ It identifies the original expression's exact quantifier shape, applies the specific De Morgan's-for-quantifiers rule named in this chapter, shows the resulting code, and translates the result into plain English confirming it expresses the same underlying claim.