Skip to content

image and preimage of a set under an expression - #1442

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
image-and-preimage
Sep 21, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
image-and-preimage

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

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 is union({f(x)}, x in A) (#1435), so nothing new in the tree:

A answer
listed listed: image(x^2, x in {1, 2, 3}) is {1, 4, 9} (Ex 7.3.2's table as an expression)
an interval, x once in f interval arithmetic (#1423), exact for one occurrence: image(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]
otherwise the family, answering membership through the quantifiers: 1/2 in image(x^2/(1 + x^2), x in RR) is True (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) under x^2 excludes 0 where 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, preimage are 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. ParseHard reached +3.2% over the baseline recorded at 86af5774, 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

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
@Rafael-SOWNet
Rafael-SOWNet merged commit 897ba4b into master Sep 21, 2026
32 checks passed
@Rafael-SOWNet
Rafael-SOWNet deleted the image-and-preimage branch September 21, 2026 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant