image and preimage of a set under an expression - #1442
Merged
Merged
Conversation
Item 6 of the reference's docket (#1409), the half that needs no pair. image(f(x), x in A) is { f(x) : x in A }, which is union({f(x)}, x in A): listed over a listed A, an interval by interval arithmetic where x occurs once in f -- exact for one occurrence and the operations that have images (#1423); the reference's 9c/5 + 32 on (0, 100) is (32, 212) -- and otherwise the family, which answers membership through the quantifiers. preimage(f(x), x in A, Y) is { x in A : f(x) in Y }, and a set builder of that shape is solved on evaluation where the statement solver reads the membership (a listed Y, an interval; #1440), the solutions cut by A: the pre-images of x^2 (Ex 7.3.10), with the one of (0, 1) excluding 0 where the book prints (-1, 1). That shape only: a set builder is not solved on evaluation in general, that being a search on every evaluation. The performance baseline moves to this run. ParseHard reached +3.2% over the baseline recorded at 86af577, and it is the ten function tokens added to the grammar since -- about 12 KB/op each, whatever the input, measured by removing the two of this change and nothing else (3,727,130 to 3,703,015 B/op): a cost in the ANTLR runtime's per-parse work, filed as #1441. Every other row is within 1% of the old baseline. #1409 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
This was referenced Sep 21, 2026
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.
Item 6 of the docket on #1409, the half that needs no pair (the pair, and with it a function as a set of pairs and item 5, waits for v3's point per your note there).
image(f(x), x in A)is{ f(x) : x in A }— which isunion({f(x)}, x in A)(#1435), so nothing new in the tree:Aimage(x^2, x in {1, 2, 3})is{1, 4, 9}(Ex 7.3.2's table as an expression)xonce infimage(9 c / 5 + 32, c in (0; 100))is(32; 212)(Ex 7.3.3),image(x^2, x in [-1; 2])is[0; 4]1/2 in image(x^2/(1 + x^2), x in RR)isTrue(Ex 7.3.4 — two occurrences, so no arithmetic)preimage(f(x), x in A, Y)is{ x in A : f(x) in Y }, and a set builder of exactly that shape is solved on evaluation where the statement solver reads the membership (#1440):preimage(x^2, x in RR, {1})is{1, -1},preimage(x^2, x in ZZ, {1, 4})is{1, -1, 2, -2},preimage(2 x, x in ZZ+, [1; 5])is{1, 2}, and the pre-image of(0; 1)underx^2excludes0where the book's Ex 7.3.10 prints(-1, 1). A pre-image the solver cannot read stays the builder it is and answers membership itself (2 in preimage(x^2, x in RR, ZZ)). Only that shape: a set builder is not solved on evaluation in general — that would be a search on every evaluation.MathS.Sets.Image,MathS.Sets.PreImage;image,preimageare keywords now. Syntax.md, BREAKING-CHANGES.md (rows measured on a v2.5.0 build), PublicApi.txt, parser regenerated and post-processed.ImageAndPreImageTest, 14 rows. Full suite 12226 passed, 0 failed; benchmark gate: the baseline moves to this run.ParseHardreached +3.2% over the baseline recorded at86af5774, and it is the ten function tokens added to the grammar since — about 12 KB/op each, whatever the input, measured by removing the two of this PR and nothing else (3,727,130 → 3,703,015 B/op): a cost in the ANTLR runtime's per-parse work, filed as #1441. Every other row is within 1% of the old baseline (SimplifyHard +1.0% since #1432, reported there).Needs #1440 (merged) for the pre-images.
Part of #1409.
🤖 Generated with Claude Code
https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura