Skip to content

Commit

Permalink
sagemathgh-36568: sage.manifolds, sage.tensor: Update # needs
Browse files Browse the repository at this point in the history
    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->

Also some `try... except` for the sympy imports.

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
- Cherry picked from sagemath#35095
- Part of sagemath#29705
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [ ] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36568
Reported by: Matthias Köppe
Reviewer(s): David Coudert, Matthias Köppe
  • Loading branch information
Release Manager committed Oct 31, 2023
2 parents 159cb85 + f3f4416 commit 6e9fd5b
Show file tree
Hide file tree
Showing 17 changed files with 285 additions and 206 deletions.
9 changes: 7 additions & 2 deletions src/sage/manifolds/calculus_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
simplify_chain_real_sympy,
simplify_chain_generic_sympy,)
from sage.misc.latex import latex
import sympy

try:
import sympy
from sympy import latex as sympy_latex
except ImportError:
sympy_latex = None


# Conversion functions
Expand Down Expand Up @@ -202,7 +207,7 @@ def __init__(self, current=None, base_field_type='real'):
self._simplify_dict['SR'] = simplify_chain_generic
# The default simplifying functions are saved:
self._simplify_dict_default = self._simplify_dict.copy()
self._latex_dict = {'sympy': sympy.latex, 'SR': latex}
self._latex_dict = {'sympy': sympy_latex, 'SR': latex}

def simplify(self, expression, method=None):
r"""
Expand Down
82 changes: 46 additions & 36 deletions src/sage/manifolds/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,7 @@ def preimage(self, codomain_subset, name=None, latex_name=None):
Pulling back a polytope under a chart::
sage: # needs sage.geometry.polyhedron
sage: P = Polyhedron(vertices=[[0, 0], [1, 2], [2, 1]]); P
A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices
sage: McP = c_cart.preimage(P); McP
Expand All @@ -1176,6 +1177,7 @@ def preimage(self, codomain_subset, name=None, latex_name=None):
Pulling back the interior of a polytope under a chart::
sage: # needs sage.geometry.polyhedron
sage: int_P = P.interior(); int_P
Relative interior of
a 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices
Expand Down Expand Up @@ -1384,6 +1386,7 @@ def zero_function(self):
Zero function on a p-adic manifold::
sage: # needs sage.rings.padics
sage: M = Manifold(2, 'M', structure='topological', field=Qp(5)); M
2-dimensional topological manifold M over the 5-adic Field with
capped relative precision 20
Expand Down Expand Up @@ -1438,6 +1441,7 @@ def one_function(self):
One function on a p-adic manifold::
sage: # needs sage.rings.padics
sage: M = Manifold(2, 'M', structure='topological', field=Qp(5)); M
2-dimensional topological manifold M over the 5-adic Field with
capped relative precision 20
Expand Down Expand Up @@ -2754,10 +2758,9 @@ def plot(self, chart=None, ambient_coords=None, mapping=None,
A 2-dimensional chart plotted in terms of itself results in a
rectangular grid::
sage: R2 = Manifold(2, 'R^2', structure='topological') # the Euclidean plane
sage: c_cart.<x,y> = R2.chart() # Cartesian coordinates
sage: g = c_cart.plot() # equivalent to c_cart.plot(c_cart)
sage: g
sage: R2 = Manifold(2, 'R^2', structure='topological') # the Euclidean plane
sage: c_cart.<x,y> = R2.chart() # Cartesian coordinates
sage: g = c_cart.plot(); g # equivalent to c_cart.plot(c_cart) # needs sage.plot
Graphics object consisting of 18 graphics primitives
.. PLOT::
Expand All @@ -2770,11 +2773,10 @@ def plot(self, chart=None, ambient_coords=None, mapping=None,
Grid of polar coordinates in terms of Cartesian coordinates in the
Euclidean plane::
sage: U = R2.open_subset('U', coord_def={c_cart: (y!=0, x<0)}) # the complement of the segment y=0 and x>0
sage: c_pol.<r,ph> = U.chart(r'r:(0,+oo) ph:(0,2*pi):\phi') # polar coordinates on U
sage: U = R2.open_subset('U', coord_def={c_cart: (y!=0, x<0)}) # the complement of the segment y=0 and x>0
sage: c_pol.<r,ph> = U.chart(r'r:(0,+oo) ph:(0,2*pi):\phi') # polar coordinates on U
sage: pol_to_cart = c_pol.transition_map(c_cart, [r*cos(ph), r*sin(ph)])
sage: g = c_pol.plot(c_cart)
sage: g
sage: g = c_pol.plot(c_cart); g # needs sage.plot
Graphics object consisting of 18 graphics primitives
.. PLOT::
Expand All @@ -2789,7 +2791,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None,
Call with non-default values::
sage: g = c_pol.plot(c_cart, ranges={ph:(pi/4,pi)},
sage: g = c_pol.plot(c_cart, ranges={ph:(pi/4,pi)}, # needs sage.plot
....: number_values={r:7, ph:17},
....: color={r:'red', ph:'green'},
....: style={r:'-', ph:'--'})
Expand All @@ -2807,7 +2809,8 @@ def plot(self, chart=None, ambient_coords=None, mapping=None,
A single coordinate line can be drawn::
sage: g = c_pol.plot(c_cart, fixed_coords={r: 2}) # draw a circle of radius r=2
sage: g = c_pol.plot(c_cart, # draw a circle of radius r=2 # needs sage.plot
....: fixed_coords={r: 2})
.. PLOT::
Expand All @@ -2821,7 +2824,8 @@ def plot(self, chart=None, ambient_coords=None, mapping=None,
::
sage: g = c_pol.plot(c_cart, fixed_coords={ph: pi/4}) # draw a segment at phi=pi/4
sage: g = c_pol.plot(c_cart, # draw a segment at phi=pi/4 # needs sage.plot
....: fixed_coords={ph: pi/4})
.. PLOT::
Expand All @@ -2838,24 +2842,23 @@ def plot(self, chart=None, ambient_coords=None, mapping=None,
argument ``mapping``): 3D plot of the stereographic charts on the
2-sphere::
sage: S2 = Manifold(2, 'S^2', structure='topological') # the 2-sphere
sage: U = S2.open_subset('U') ; V = S2.open_subset('V') # complement of the North and South pole, respectively
sage: S2 = Manifold(2, 'S^2', structure='topological') # the 2-sphere
sage: U = S2.open_subset('U'); V = S2.open_subset('V') # complement of the North and South pole, respectively
sage: S2.declare_union(U,V)
sage: c_xy.<x,y> = U.chart() # stereographic coordinates from the North pole
sage: c_uv.<u,v> = V.chart() # stereographic coordinates from the South pole
sage: c_xy.<x,y> = U.chart() # stereographic coordinates from the North pole
sage: c_uv.<u,v> = V.chart() # stereographic coordinates from the South pole
sage: xy_to_uv = c_xy.transition_map(c_uv, (x/(x^2+y^2), y/(x^2+y^2)),
....: intersection_name='W', restrictions1= x^2+y^2!=0,
....: restrictions2= u^2+v^2!=0)
sage: uv_to_xy = xy_to_uv.inverse()
sage: R3 = Manifold(3, 'R^3', structure='topological') # the Euclidean space R^3
sage: R3 = Manifold(3, 'R^3', structure='topological') # the Euclidean space R^3
sage: c_cart.<X,Y,Z> = R3.chart() # Cartesian coordinates on R^3
sage: Phi = S2.continuous_map(R3, {(c_xy, c_cart): [2*x/(1+x^2+y^2),
....: 2*y/(1+x^2+y^2), (x^2+y^2-1)/(1+x^2+y^2)],
....: (c_uv, c_cart): [2*u/(1+u^2+v^2),
....: 2*v/(1+u^2+v^2), (1-u^2-v^2)/(1+u^2+v^2)]},
....: name='Phi', latex_name=r'\Phi') # Embedding of S^2 in R^3
sage: g = c_xy.plot(c_cart, mapping=Phi)
sage: g
....: name='Phi', latex_name=r'\Phi') # Embedding of S^2 in R^3
sage: g = c_xy.plot(c_cart, mapping=Phi); g # needs sage.plot
Graphics3d Object
.. PLOT::
Expand Down Expand Up @@ -2885,12 +2888,12 @@ def plot(self, chart=None, ambient_coords=None, mapping=None,
The same plot without the ``(X,Y,Z)`` axes labels::
sage: g = c_xy.plot(c_cart, mapping=Phi, label_axes=False)
sage: g = c_xy.plot(c_cart, mapping=Phi, label_axes=False) # needs sage.plot
The North and South stereographic charts on the same plot::
sage: g2 = c_uv.plot(c_cart, mapping=Phi, color='green')
sage: g + g2
sage: g2 = c_uv.plot(c_cart, mapping=Phi, color='green') # needs sage.plot
sage: g + g2 # needs sage.plot
Graphics3d Object
.. PLOT::
Expand All @@ -2915,16 +2918,17 @@ def plot(self, chart=None, ambient_coords=None, mapping=None,
g2 = c_uv.plot(c_cart, mapping=Phi, color='green')
sphinx_plot(g+g2)
South stereographic chart drawned in terms of the North one (we split
South stereographic chart drawn in terms of the North one (we split
the plot in four parts to avoid the singularity at `(u,v)=(0,0)`)::
sage: # long time, needs sage.plot
sage: W = U.intersection(V) # the subset common to both charts
sage: c_uvW = c_uv.restrict(W) # chart (W,(u,v))
sage: gSN1 = c_uvW.plot(c_xy, ranges={u:[-6.,-0.02], v:[-6.,-0.02]}) # long time
sage: gSN2 = c_uvW.plot(c_xy, ranges={u:[-6.,-0.02], v:[0.02,6.]}) # long time
sage: gSN3 = c_uvW.plot(c_xy, ranges={u:[0.02,6.], v:[-6.,-0.02]}) # long time
sage: gSN4 = c_uvW.plot(c_xy, ranges={u:[0.02,6.], v:[0.02,6.]}) # long time
sage: show(gSN1+gSN2+gSN3+gSN4, xmin=-1.5, xmax=1.5, ymin=-1.5, ymax=1.5) # long time
sage: gSN1 = c_uvW.plot(c_xy, ranges={u:[-6.,-0.02], v:[-6.,-0.02]})
sage: gSN2 = c_uvW.plot(c_xy, ranges={u:[-6.,-0.02], v:[0.02,6.]})
sage: gSN3 = c_uvW.plot(c_xy, ranges={u:[0.02,6.], v:[-6.,-0.02]})
sage: gSN4 = c_uvW.plot(c_xy, ranges={u:[0.02,6.], v:[0.02,6.]})
sage: show(gSN1+gSN2+gSN3+gSN4, xmin=-1.5, xmax=1.5, ymin=-1.5, ymax=1.5)
.. PLOT::
Expand All @@ -2947,9 +2951,12 @@ def plot(self, chart=None, ambient_coords=None, mapping=None,
The coordinate line `u = 1` (red) and the coordinate line `v = 1`
(green) on the same plot::
sage: gu1 = c_uvW.plot(c_xy, fixed_coords={u: 1}, max_range=20, plot_points=300) # long time
sage: gv1 = c_uvW.plot(c_xy, fixed_coords={v: 1}, max_range=20, plot_points=300, color='green') # long time
sage: gu1 + gv1 # long time
sage: # long time, needs sage.plot
sage: gu1 = c_uvW.plot(c_xy, fixed_coords={u: 1}, max_range=20,
....: plot_points=300)
sage: gv1 = c_uvW.plot(c_xy, fixed_coords={v: 1}, max_range=20,
....: plot_points=300, color='green')
sage: gu1 + gv1
Graphics object consisting of 2 graphics primitives
.. PLOT::
Expand All @@ -2975,8 +2982,9 @@ def plot(self, chart=None, ambient_coords=None, mapping=None,
A 3-dimensional chart plotted in terms of itself results in a 3D
rectangular grid::
sage: g = c_cart.plot() # equivalent to c_cart.plot(c_cart) # long time
sage: g # long time
sage: # long time, needs sage.plot
sage: g = c_cart.plot() # equivalent to c_cart.plot(c_cart)
sage: g
Graphics3d Object
.. PLOT::
Expand All @@ -2989,10 +2997,11 @@ def plot(self, chart=None, ambient_coords=None, mapping=None,
performed for at most 3 coordinates, which must be specified via
the argument ``ambient_coords``)::
sage: # needs sage.plot
sage: M = Manifold(4, 'M', structure='topological')
sage: X.<t,x,y,z> = M.chart()
sage: g = X.plot(ambient_coords=(t,x,y)) # the coordinate z is not depicted # long time
sage: g # long time
sage: g = X.plot(ambient_coords=(t,x,y)) # the coordinate z is not depicted # long time
sage: g # long time
Graphics3d Object
.. PLOT::
Expand All @@ -3004,7 +3013,8 @@ def plot(self, chart=None, ambient_coords=None, mapping=None,
::
sage: g = X.plot(ambient_coords=(t,y)) # the coordinates x and z are not depicted
sage: # needs sage.plot
sage: g = X.plot(ambient_coords=(t,y)) # the coordinates x and z are not depicted
sage: g
Graphics object consisting of 18 graphics primitives
Expand Down
7 changes: 6 additions & 1 deletion src/sage/manifolds/chart_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@
from sage.categories.commutative_algebras import CommutativeAlgebras
from sage.manifolds.utilities import ExpressionNice
from sage.misc.cachefunc import cached_method
from sage.misc.lazy_import import lazy_import
from sage.symbolic.ring import SR
from sage.structure.mutability import Mutability
import sympy

try:
import sympy
except ImportError:
pass


class ChartFunction(AlgebraElement, ModuleElementWithMutability):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,11 @@
Let us check whether this form represents the Euler class correctly::
sage: expr = e_class_form[2][[1,2]].expr() # long time
sage: expr = integrate(expr, x, -infinity, infinity) # long time
sage: expr = expr.simplify_full() # long time
sage: integrate(expr, y, -infinity, infinity) # long time
sage: # long time
sage: expr = e_class_form[2][[1,2]].expr()
sage: expr = integrate(expr, x, -infinity, infinity)
sage: expr = expr.simplify_full()
sage: integrate(expr, y, -infinity, infinity)
2
As we can see, the integral coincides with the Euler characteristic of `S^2` so
Expand Down
2 changes: 1 addition & 1 deletion src/sage/manifolds/differentiable/curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class DifferentiableCurve(DiffMap):
A graphical view of the curve is provided by the method :meth:`plot`::
sage: c.plot(aspect_ratio=1)
sage: c.plot(aspect_ratio=1) # needs sage.plot
Graphics object consisting of 1 graphics primitive
.. PLOT::
Expand Down
33 changes: 18 additions & 15 deletions src/sage/manifolds/differentiable/examples/euclidean.py
Original file line number Diff line number Diff line change
Expand Up @@ -1879,14 +1879,15 @@ def _transition_spherical_cartesian(self):
Tests of the change-of-frame formulas::
sage: spher = E.spherical_coordinates() # long time
sage: spher_f = E.spherical_frame() # long time
sage: cart_f = E.cartesian_frame() # long time
sage: E.change_of_frame(cart_f, spher_f)[:,spher] # long time
sage: # long time
sage: spher = E.spherical_coordinates()
sage: spher_f = E.spherical_frame()
sage: cart_f = E.cartesian_frame()
sage: E.change_of_frame(cart_f, spher_f)[:,spher]
[cos(ph)*sin(th) cos(ph)*cos(th) -sin(ph)]
[sin(ph)*sin(th) cos(th)*sin(ph) cos(ph)]
[ cos(th) -sin(th) 0]
sage: E.change_of_frame(spher_f, cart_f)[:,spher] # long time
sage: E.change_of_frame(spher_f, cart_f)[:,spher]
[cos(ph)*sin(th) sin(ph)*sin(th) cos(th)]
[cos(ph)*cos(th) cos(th)*sin(ph) -sin(th)]
[ -sin(ph) cos(ph) 0]
Expand Down Expand Up @@ -1958,14 +1959,15 @@ def _transition_cylindrical_cartesian(self):
Tests of the change-of-frame formulas::
sage: cylind = E.cylindrical_coordinates() # long time
sage: cylind_f = E.cylindrical_frame() # long time
sage: cart_f= E.cartesian_frame() # long time
sage: E.change_of_frame(cart_f, cylind_f)[:,cylind] # long time
sage: # long time
sage: cylind = E.cylindrical_coordinates()
sage: cylind_f = E.cylindrical_frame()
sage: cart_f= E.cartesian_frame()
sage: E.change_of_frame(cart_f, cylind_f)[:,cylind]
[ cos(ph) -sin(ph) 0]
[ sin(ph) cos(ph) 0]
[ 0 0 1]
sage: E.change_of_frame(cylind_f, cart_f)[:,cylind] # long time
sage: E.change_of_frame(cylind_f, cart_f)[:,cylind]
[ cos(ph) sin(ph) 0]
[-sin(ph) cos(ph) 0]
[ 0 0 1]
Expand Down Expand Up @@ -2035,14 +2037,15 @@ def _transition_spherical_cylindrical(self):
Tests of the change-of-frame formulas::
sage: spher = E.spherical_coordinates() # long time
sage: spher_f = E.spherical_frame() # long time
sage: cylind_f = E.cylindrical_frame() # long time
sage: E.change_of_frame(cylind_f, spher_f)[:, spher] # long time
sage: # long time
sage: spher = E.spherical_coordinates()
sage: spher_f = E.spherical_frame()
sage: cylind_f = E.cylindrical_frame()
sage: E.change_of_frame(cylind_f, spher_f)[:, spher]
[ sin(th) cos(th) 0]
[ 0 0 1]
[ cos(th) -sin(th) 0]
sage: E.change_of_frame(spher_f, cylind_f)[:, spher] # long time
sage: E.change_of_frame(spher_f, cylind_f)[:, spher]
[ sin(th) 0 cos(th)]
[ cos(th) 0 -sin(th)]
[ 0 1 0]
Expand Down
Loading

0 comments on commit 6e9fd5b

Please sign in to comment.