Skip to content

Improve _element_constructor_ of image set #40250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/sage/sets/image_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ class ImageSubobject(Parent):
- ``True``: ``map`` is known to be injective
- ``'check'``: raise an error when ``map`` is not injective

- ``inverse`` -- a function (optional); a map from `f(X)` to `X`
- ``inverse`` -- a function (optional); a map from `f(X)` to `X`.
It is not recommended to provide this, if ``map.inverse_image`` exists,
it will be used automatically.

EXAMPLES::

Expand All @@ -80,6 +82,17 @@ def __init__(self, map, domain_subset, *, category=None, is_injective=None, inve
sage: Im = f.image()
sage: TestSuite(Im).run(skip=['_test_an_element', '_test_pickling',
....: '_test_some_elements', '_test_elements'])

TESTS:

Implementing ``inverse_image`` automatically makes :meth:`__contains__` work::

sage: R.<x> = QQ[]
sage: S.<y> = QQ[]
sage: R.hom([y^2]).inverse_image(y^4)
x^2
sage: y^4 in R.hom([y^2]).image()
True
"""
if not isinstance(domain_subset, Parent):
from sage.sets.set import Set
Expand Down Expand Up @@ -127,6 +140,11 @@ def map(arg):
Parent.__init__(self, category=category)

self._map = map
if inverse is None:
try:
inverse = map.inverse_image
except AttributeError:
pass
self._inverse = inverse
self._domain_subset = domain_subset
self._is_injective = is_injective
Expand Down
Loading