-
Notifications
You must be signed in to change notification settings - Fork 11
Semialgebraic complex plot and other plotting methods #83
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
ComboProblem
wants to merge
2
commits into
mkoeppe:master
Choose a base branch
from
ComboProblem:semialgebraic_complex_plot_and_other_plotting_methods
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -749,13 +749,13 @@ def plot(self, alpha=0.5, plot_points=300, slice_value=None, color='blue', fill_ | |
| section = self.section(slice_value) | ||
| else: | ||
| raise NotImplementedError("Plotting with dimension not equal to 2 is not implemented.") | ||
| return section.plot(alpha=alpha, plot_points=plot_points, slice_value=None, | ||
| return BasicSemialgebraicSet_veronese.from_bsa(section).plot(alpha=alpha, plot_points=plot_points, slice_value=None, | ||
| color=color, fill_color=fill_color, | ||
| constraints_color=constraints_color, | ||
| constraints_fill_color=constraints_fill_color, | ||
| eq_constraints_kwds=eq_constraints_kwds, | ||
| le_constraints_kwds=le_constraints_kwds, | ||
| lt_constraints_kwds=lt_constraints_kwds, **kwds) | ||
| lt_constraints_kwds=lt_constraints_kwds, **kwds) # use a BSA that can prove emptiness and reduce inequalities | ||
| g = Graphics() | ||
| for bv in 'xmin', 'xmax', 'ymin', 'ymax': | ||
| b = kwds.get(bv, None) | ||
|
|
@@ -783,33 +783,35 @@ def plot(self, alpha=0.5, plot_points=300, slice_value=None, color='blue', fill_ | |
| x, y = SR.var('x, y') | ||
| x_range = (x, xmin-0.01, xmax+0.01) | ||
| y_range = (y, ymin-0.01, ymax+0.01) | ||
| eq_constraints = [ l(x, y) == 0 for l in self.eq_poly() ] | ||
| eq_constraints = [ l(x, y) == 0 for l in self.eq_poly() ] | ||
| lt_constraints = [ l(x, y) < 0 for l in self.lt_poly() ] | ||
| le_constraints = [ l(x, y) <= 0 for l in self.le_poly() ] | ||
| # note: region_plot does not plot inconsistent inequalites | ||
| # TO DO: Dealing with plotting R^2 as represetned as empty list in eq, lt, le constraints. | ||
| # TO DO: Special case for dealing when the 2d constraints that reduce to a point. For now region_plot can handle it with a warning. | ||
| # note region_plot has issues with zorder keyword see issue #35992 in sagemath/sage | ||
| if constraints_fill_color: | ||
| for c in chain(lt_constraints, le_constraints): | ||
| if not isinstance(c, bool): | ||
| g += region_plot([c], x_range, y_range, | ||
| alpha=0.1, plot_points=plot_points, | ||
| incol=constraints_fill_color, bordercol=None, **kwds) | ||
| alpha=0.1, plot_points=plot_points, | ||
| incol=constraints_fill_color, bordercol=None, **kwds) | ||
| if color or fill_color: | ||
| all_constraints = eq_constraints + lt_constraints + le_constraints | ||
| non_trivial_constraints = [ c for c in all_constraints if not isinstance(c, bool) ] | ||
| if not any(c is False for c in all_constraints): | ||
| g += region_plot(non_trivial_constraints, x_range, y_range, | ||
| alpha=alpha, plot_points=plot_points, | ||
| incol=fill_color, bordercol=color, **kwds) | ||
| all_constraints = eq_constraints + lt_constraints + le_constraints | ||
| g += region_plot(all_constraints, x_range, y_range, | ||
| alpha=alpha, plot_points=plot_points, | ||
| incol=fill_color, bordercol=color, **kwds) | ||
| if constraints_color: | ||
| for polys, plot_kwds in [(self.eq_poly(), eq_constraints_kwds), | ||
| (self.lt_poly(), lt_constraints_kwds), | ||
| (self.le_poly(), le_constraints_kwds)]: | ||
| (self.lt_poly(), lt_constraints_kwds), | ||
| (self.le_poly(), le_constraints_kwds)]: | ||
| for l in polys: | ||
| c = l(x, y) == 0 | ||
| if not isinstance(c, bool): | ||
| effective_kwds = copy(kwds) | ||
| effective_kwds['color'] = constraints_color | ||
| effective_kwds.update(plot_kwds) | ||
| g += implicit_plot(c, x_range, y_range, **effective_kwds) | ||
| g += implicit_plot(c, x_range, y_range, **effective_kwds) # implicit_plot has no zorder information. | ||
| return g | ||
|
|
||
| class BasicSemialgebraicSet_polyhedral(BasicSemialgebraicSet_base): | ||
|
|
@@ -1015,13 +1017,14 @@ def eq_poly(self): | |
|
|
||
| Together, ``eq_poly``, ``lt_poly``, and ``le_poly`` describe ``self``. | ||
| """ | ||
| ## add tests | ||
| for c in self._polyhedron.minimized_constraints(): | ||
| if c.is_equality(): | ||
| coeff = c.coefficients() | ||
| # observe: coeffients in a constraint of NNC_Polyhedron could have gcd != 1. # take care of this. | ||
| gcd_c = gcd(gcd(coeff), c.inhomogeneous_term()) | ||
| t = sum(QQ(x)/gcd_c*y for x, y in zip(coeff, self.poly_ring().gens())) + QQ(c.inhomogeneous_term())/gcd_c | ||
| yield t | ||
| t = sum(QQ(x)/gcd_c*y for x, y in zip(coeff, self.poly_ring().gens())) + QQ(c.inhomogeneous_term())/gcd_c # not type stable, make it type stable | ||
| yield self.poly_ring()(t) | ||
|
|
||
| def lt_poly(self): | ||
| r""" | ||
|
|
@@ -1036,7 +1039,7 @@ def lt_poly(self): | |
| gcd_c = gcd(gcd(coeff), c.inhomogeneous_term()) | ||
| # constraint is written with '>', while lt_poly records '<' relation | ||
| t = sum(-QQ(x)/gcd_c*y for x, y in zip(coeff, self.poly_ring().gens())) - QQ(c.inhomogeneous_term())/gcd_c | ||
| yield t | ||
| yield self.poly_ring()(t) | ||
|
|
||
| def le_poly(self): | ||
| r""" | ||
|
|
@@ -1051,7 +1054,7 @@ def le_poly(self): | |
| gcd_c = gcd(gcd(coeff), c.inhomogeneous_term()) | ||
| # constraint is written with '>=', while lt_poly records '<=' relation | ||
| t = sum(-QQ(x)/gcd_c*y for x, y in zip(coeff, self.poly_ring().gens())) - QQ(c.inhomogeneous_term())/gcd_c | ||
| yield t | ||
| yield self.poly_ring()(t) | ||
|
|
||
| # override the default implementation | ||
| def __contains__(self, point): | ||
|
|
@@ -1733,7 +1736,7 @@ def __init__(self, upstairs_bsa, polynomial_map, poly_ring=None, ambient_dim=Non | |
| super(BasicSemialgebraicSet_section, self).__init__(base_ring=base_ring, ambient_dim=ambient_dim, names=names, poly_ring=poly_ring) | ||
| self._upstairs_bsa = upstairs_bsa | ||
| self._polynomial_map = polynomial_map | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keep this empty line
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed. |
||
| def __copy__(self): | ||
| r""" | ||
| Make a copy of ``self``. | ||
|
|
@@ -1744,15 +1747,15 @@ def __copy__(self): | |
|
|
||
| def eq_poly(self): | ||
| for p in self._upstairs_bsa.eq_poly(): | ||
| yield p(self._polynomial_map) | ||
| yield self.poly_ring()(p(self._polynomial_map)) # these need to be type stable | ||
|
|
||
| def le_poly(self): | ||
| for p in self._upstairs_bsa.le_poly(): | ||
| yield p(self._polynomial_map) | ||
| yield self.poly_ring()(p(self._polynomial_map)) | ||
|
|
||
| def lt_poly(self): | ||
| for p in self._upstairs_bsa.lt_poly(): | ||
| yield p(self._polynomial_map) | ||
| yield self.poly_ring()(p(self._polynomial_map)) | ||
|
|
||
| def _repr_(self): | ||
| return 'BasicSemialgebraicSet_section({}, polynomial_map={})'.format(self._upstairs_bsa, self._polynomial_map) | ||
|
|
@@ -1939,7 +1942,7 @@ def __init__(self, upstairs_bsa=None, polynomial_map=None, v_dict=None, | |
| self._v_dict = v_dict | ||
|
|
||
| @classmethod | ||
| def from_bsa(cls, bsa, poly_ring=None, **init_kwds): | ||
| def from_bsa(cls, bsa, poly_ring=None, **init_kwds): #add example | ||
| if poly_ring is None: | ||
| poly_ring = bsa.poly_ring() | ||
| return super(BasicSemialgebraicSet_veronese, cls).from_bsa(bsa, poly_ring=poly_ring, **init_kwds) | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this change (test for is_empty) necessary again? Is something wrong with the minimized_constraints?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember exactly. I think it was there as a fix from before we knew that BasicSemialgebraicSet_section wasn't stable and when we had fixed that. I've done a few quick tests and it seems like the test for emptiness is not longer necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's back out this change then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've backed out those changes.