examples: add all_any.pf (list_all / list_any correctness)#788
Merged
Conversation
A new introductory-functional-programming worked example defining the
classic `all`/`any` higher-order predicates over lists (named
`list_all`/`list_any` since `all`/`some` are Deduce keywords) and
proving three correctness properties:
1. list_all_append: list_all(xs ++ ys, p) = (list_all(xs,p) and list_all(ys,p))
2. list_any_append: list_any(xs ++ ys, p) = (list_any(xs,p) or list_any(ys,p))
3. list_all_any_de_morgan: (not list_all(xs,p)) = list_any(xs, fun z { not p(z) })
Validates under both the recursive-descent and LALR parsers.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a new introductory-functional-programming worked example to
examples/:the classic higher-order predicates
all/anyover lists.Because
allandsomeare reserved keywords in Deduce, the functions arenamed
list_allandlist_any. The file defines both by structural recursion,includes a handful of
assertsanity checks (using anis_evenpredicate), andproves three correctness properties:
list_alldistributes over++as a conjunction:list_all(xs ++ ys, p) = (list_all(xs, p) and list_all(ys, p))list_anydistributes over++as a disjunction:list_any(xs ++ ys, p) = (list_any(xs, p) or list_any(ys, p))(not list_all(xs, p)) = list_any(xs, fun z { not p(z) })All proofs go by induction on the list and a
switchonp(x). This fills a gapin the existing
examples/set, which hassum,count,maximum,partition,take_while, etc., but no Boolean-quantifier example.Testing
python deduce.py examples/all_any.pf→ validmake tests-examples→ all example files valid under both therecursive-descent and LALR parsers.
Notes
While writing this I hit one genuine beginner trap and filed two issues for it:
=insideand/orwithout disambiguating parens (hides a common beginner mistake) #786 —=binds tighter thanand/or; the goal printer shows it ambiguously.=vsand/or) #787 — the Reference has no operator-precedence table.Claude session