gh-36531: Add preimage/inverse_image methods to Polyhedron_base5 - #42619
Open
Chaitanya140904 wants to merge 2 commits into
Open
gh-36531: Add preimage/inverse_image methods to Polyhedron_base5#42619Chaitanya140904 wants to merge 2 commits into
Chaitanya140904 wants to merge 2 commits into
Conversation
|
Documentation preview for this PR (built with commit 1eef6d6; changes) is ready! 🎉 |
Contributor
|
Can you rebase to lastest develop |
Adds two new methods to compute the preimage of a polyhedron
under a linear map f: R^n -> R^m:
- preimage(linear_transf, new_base_ring=None)
- inverse_image(linear_transf, new_base_ring=None) [alias]
Given Q = {y : Ay <= b} and f(x) = T*x, the preimage is
{x : (A*T)x <= b}, constructed directly from the H-representation.
Also cross-links preimage in linear_transformation's SEEALSO.
Fixes: sagemath#36531
- Fix first example output: P.preimage(A) returns QQ^2 with 1 vertex, 1 ray, 1 line (not ZZ^2 with 2 rays) - Fix projection example: matrix must have nrows == ambient_dim; use T = matrix([[1],[0]]) mapping R^1 -> R^2 instead of proj = matrix([[1,0]]) which has wrong shape - Fix Q.base_ring() expected output: returns Rational Field not Integer Ring due to base_extend normalization
Chaitanya140904
force-pushed
the
polyhedron-preimage
branch
from
August 7, 2026 22:39
460dc91 to
1eef6d6
Compare
Contributor
Author
|
Done, rebased onto latest develop |
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.
This PR implements the feature requested in #36531 by adding two new methods
to
Polyhedron_base5:preimage(linear_transf, new_base_ring=None)inverse_image(linear_transf, new_base_ring=None)(alias forpreimage)What problem does this solve?
Previously, SageMath provided
linear_transformationto compute the imageof a polyhedron under a linear map
f(x) = T·x. However, there was no methodto compute the preimage (inverse image) — i.e., given a polyhedron
Q ⊆ ℝᵐand a linear mapf : ℝⁿ → ℝᵐ, compute:This fills the gap and complements the existing
ConvexSet_base.linear_transformationAPI.How it works
Given the H-representation of
Q:and a linear map
f(x) = T·xwhereTis an(m × n)matrix,substituting
y = T·xgives directly:This is a valid H-representation of a polyhedron in
ℝⁿand is constructeddirectly from the H-representation without any V-representation conversion.
Changes
src/sage/geometry/polyhedron/base5.pypreimage(linear_transf, new_base_ring=None)with:r"""docstring including a LaTeX.. MATH::block showing the preimage formula(m × n)wherem = self.ambient_dim()EXAMPLES::block with 5 examples: half-space preimage, projection, scalar dilation, empty polyhedron, alias checkTESTS::block covering: ambient dim correctness, base ring check,ValueErrorfor incompatible matrix shape, backend preservation.. SEEALSO::links tolinear_transformationandinverse_imageinverse_image(linear_transf, new_base_ring=None)as a documented alias forpreimage,with its own docstring, examples, and
.. SEEALSO::linkslinear_transformation's.. SEEALSO::to cross-linkpreimageFixes #36531