Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Improve documentation for SymPy calculus on manifolds
Browse files Browse the repository at this point in the history
  • Loading branch information
egourgoulhon committed Oct 29, 2017
1 parent 426f98c commit 8ffa9c4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 83 deletions.
27 changes: 11 additions & 16 deletions src/sage/manifolds/continuous_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,26 +1163,22 @@ def coord_functions(self, chart1=None, chart2=None):
sage: Phi1.coord_functions(c_uv.restrict(A), c_xyz)
Coordinate functions (u*v, u/v, u + v) on the Chart (A, (u, v))
The same test with ``sympy``::
Same example with SymPy as the symbolic calculus engine::
# sage: X.set_calculus_method('sympy')
sage: M = Manifold(2, 'M', structure='topological')
sage: N = Manifold(3, 'N', structure='topological')
sage: c_uv.<u,v> = M.chart(calc_method='sympy')
sage: c_xyz.<x,y,z> = N.chart(calc_method='sympy')
sage: M.set_calculus_method('sympy')
sage: N.set_calculus_method('sympy')
sage: Phi = M.continuous_map(N, (u*v, u/v, u+v), name='Phi',
....: latex_name=r'\Phi')
sage: Phi.display()
Phi: M --> N
(u, v) |--> (x, y, z) = (u*v, u/v, u + v)
sage: Phi.coord_functions(c_uv, c_xyz)
Coordinate functions (u*v, u/v, u + v) on the Chart (M, (u, v))
sage: Phi.coord_functions() # equivalent to above since 'uv' and 'xyz' are default charts
Coordinate functions (u*v, u/v, u + v) on the Chart (M, (u, v))
sage: type(Phi.coord_functions())
<class 'sage.manifolds.chart_func.MultiCoordFunction'>
sage: Phi.coord_functions(c_UV, c_xyz)
Coordinate functions (-U**2/4 + V**2/4, -(U + V)/(U - V), V)
on the Chart (M, (U, V))
sage: Phi.coord_functions(c_UV, c_XYZ)
Coordinate functions ((-U**3 + U**2*V + U*V**2 + 2*U*V + 6*U - V**3
- 2*V**2 + 6*V)/(2*(U - V)), (U**3/4 - U**2*V/4 - U*V**2/4 + U*V
- U + V**3/4 - V**2 - V)/(U - V), (U**3 - U**2*V - U*V**2 - 4*U*V
- 8*U + V**3 + 4*V**2 - 8*V)/(4*(U - V))) on the Chart (M, (U, V))
"""
dom1 = self._domain; dom2 = self._codomain
Expand Down Expand Up @@ -1826,7 +1822,6 @@ def __invert__(self):
if not self._is_isomorphism:
raise ValueError("the {} is not an isomorphism".format(self))
coord_functions = {} # coordinate expressions of the result

for (chart1, chart2) in self._coord_expression:
coord_map = self._coord_expression[(chart1, chart2)]
n1 = len(chart1._xx)
Expand Down
12 changes: 1 addition & 11 deletions src/sage/manifolds/differentiable/affine_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,20 +293,11 @@ class AffineConnection(SageObject):
sage: nab.restrict(U)(a.restrict(V)) == da.restrict(W)
True
Same tests with ``sympy``::
Same examples with SymPy as the engine for symbolic calculus::
sage: M.set_calculus_method('sympy')
sage: nab = M.affine_connection('nabla', r'\nabla')
The connection is first defined on the open subset U by means of its
coefficients w.r.t. the frame eU (the manifold's default frame)::
sage: nab[0,0,0], nab[1,0,1] = x, x*y
The coefficients w.r.t the frame eV are deduced by continuation of the
coefficients w.r.t. the frame eVW on the open subset `W=U\cap V`::
sage: for i in M.irange():
....: for j in M.irange():
....: for k in M.irange():
Expand Down Expand Up @@ -338,7 +329,6 @@ class AffineConnection(SageObject):
manifold M
sage: da.display(eU)
nabla(a) = -x*y d/dx*dx - d/dx*dy + d/dy*dx - x*y**2 d/dy*dy
sage: da.display(eV)
nabla(a) = (-u**3/16 + u**2*v/16 - u**2/8 + u*v**2/16 - v**3/16 + v**2/8) d/du*du
+ (u**3/16 - u**2*v/16 - u**2/8 - u*v**2/16 + v**3/16 + v**2/8 + 1) d/du*dv
Expand Down
51 changes: 16 additions & 35 deletions src/sage/manifolds/differentiable/diff_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,16 @@ class DiffForm(TensorField):
1/2*u^2*v du - 1/2*u^3 dv
Same tests with ``sympy``::
.. RUBRIC:: Examples with SymPy as the symbolic engine
From now on, we ask that all symbolic calculus on manifold `M` are
performed by SymPy::
sage: M.set_calculus_method('sympy')
sage: U.set_calculus_method('sympy')
sage: V.set_calculus_method('sympy')
sage: W.set_calculus_method('sympy')
sage: a = M.diff_form(2, name='a') ; a
2-form a on the 2-dimensional differentiable manifold M
sage: a.parent()
Module Omega^2(M) of 2-forms on the 2-dimensional differentiable
manifold M
sage: a.degree()
2
Setting the components of ``a``::
We define a 2-form `a` as above::
sage: a = M.diff_form(2, name='a')
sage: a[eU,0,1] = x*y^2 + 2*x
sage: a.add_comp_by_continuation(eV, W, c_uv)
sage: a.display(eU)
Expand All @@ -231,27 +226,17 @@ class DiffForm(TensorField):
A 1-form on ``M``::
sage: a = M.one_form('a') ; a
1-form a on the 2-dimensional differentiable manifold M
sage: a.parent()
Module Omega^1(M) of 1-forms on the 2-dimensional differentiable
manifold M
sage: a.degree()
1
Setting the components of the 1-form in a consistent way::
sage: a = M.one_form('a')
sage: a[eU,:] = [-y, x]
sage: a.add_comp_by_continuation(eV, W, c_uv)
sage: a.display(eU)
a = -y dx + x dy
sage: a.display(eV)
a = v/2 du - u/2 dv
The exterior derivative of the 1-form is a 2-form::
The exterior derivative of ``a``::
sage: da = a.exterior_derivative() ; da
2-form da on the 2-dimensional differentiable manifold M
sage: da = a.exterior_derivative()
sage: da.display(eU)
da = 2 dx/\dy
sage: da.display(eV)
Expand All @@ -263,35 +248,31 @@ class DiffForm(TensorField):
sage: b[eU,:] = [1+x*y, x^2]
sage: b.add_comp_by_continuation(eV, W, c_uv)
Adding two 1-forms results in another 1-form::
Adding two 1-forms::
sage: s = a + b ; s
1-form a+b on the 2-dimensional differentiable manifold M
sage: s = a + b
sage: s.display(eU)
a+b = (x*y - y + 1) dx + x*(x + 1) dy
sage: s.display(eV)
a+b = (u**2/4 + u*v/4 + v/2 + 1/2) du + (-u*v/4 - u/2 - v**2/4 + 1/2) dv
The exterior product of two 1-forms is a 2-form::
The exterior product of two 1-forms::
sage: s = a.wedge(b) ; s
2-form a/\b on the 2-dimensional differentiable manifold M
sage: s = a.wedge(b)
sage: s.display(eU)
a/\b = -x*(2*x*y + 1) dx/\dy
sage: s.display(eV)
a/\b = (u**3/8 + u**2*v/8 - u*v**2/8 + u/4 - v**3/8 + v/4) du/\dv
Multiplying a 1-form by a scalar field results in another 1-form::
Multiplying a 1-form by a scalar field::
sage: f = M.scalar_field({c_xy: (x+y)^2, c_uv: u^2}, name='f')
sage: s = f*a ; s
1-form on the 2-dimensional differentiable manifold M
sage: s = f*a
sage: s.display(eU)
-y*(x**2 + 2*x*y + y**2) dx + x*(x**2 + 2*x*y + y**2) dy
sage: s.display(eV)
u**2*v/2 du - u**3/2 dv
"""
def __init__(self, vector_field_module, degree, name=None, latex_name=None):
r"""
Expand Down
3 changes: 2 additions & 1 deletion src/sage/manifolds/differentiable/levi_civita_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,8 @@ def ricci(self, name=None, latex_name=None):
sage: g[0,0], g[1,1] = -(1-2*m/r), 1/(1-2*m/r)
sage: g[2,2], g[3,3] = r^2, (r*sin(th))^2
sage: g.display()
g = (2*m/r - 1) dt*dt - 1/(2*m/r - 1) dr*dr + r^2 dth*dth + r^2*sin(th)^2 dph*dph
g = (2*m/r - 1) dt*dt - 1/(2*m/r - 1) dr*dr + r^2 dth*dth
+ r^2*sin(th)^2 dph*dph
sage: nab = g.connection() ; nab
Levi-Civita connection nabla_g associated with the Lorentzian
metric g on the 4-dimensional differentiable manifold M
Expand Down
14 changes: 0 additions & 14 deletions src/sage/manifolds/manifold.py
Original file line number Diff line number Diff line change
Expand Up @@ -1655,20 +1655,6 @@ def scalar_field(self, coord_expression=None, chart=None, name=None,
F: U --> R
(x, y, z) |--> cos(y)*sin(x) + z
Same tests with ``sympy``::
sage: c_xyz.set_calculus_method('sympy')
sage: f = U.scalar_field(sin(x)*cos(y) + z, name='F'); f
Scalar field F on the Open subset U of the 3-dimensional topological manifold M
sage: f.display()
F: U --> R
(x, y, z) |--> z + sin(x)*cos(y)
sage: type(f.coord_function(c_xyz).expr())
<class 'sympy.core.add.Add'>
See the documentation of class
:class:`~sage.manifolds.scalarfield.ScalarField` for more
examples.
Expand Down
7 changes: 1 addition & 6 deletions src/sage/manifolds/scalarfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ class ScalarField(CommutativeAlgebraElement):
.. RUBRIC:: Examples with SymPy as the symbolic engine
From now on, we ask that all symbolic calculus on manifold `M` is
From now on, we ask that all symbolic calculus on manifold `M` are
performed by SymPy::
sage: M.set_calculus_method('sympy')
Expand Down Expand Up @@ -1544,7 +1544,6 @@ def coord_function(self, chart=None, from_chart=None):
new_expr = self._express[known_chart].expr()
self._express[chart] = chart.function(new_expr)
return self._express[chart]

# If this point is reached, the expression must be computed
# from that in the chart from_chart, by means of a
# change-of-coordinates formula:
Expand All @@ -1567,15 +1566,12 @@ def coord_function(self, chart=None, from_chart=None):
if not found:
raise ValueError("no starting chart could be found to " +
"compute the expression in the {}".format(chart))

change = self._domain._coord_changes[(chart, from_chart)]

# old coordinates expressed in terms of the new ones:
coords = [ change._transf._functions[i].expr()
for i in range(self._manifold.dim()) ]
new_expr = self._express[from_chart](*coords)
self._express[chart] = chart.function(new_expr)

self._del_derived()
return self._express[chart]

Expand Down Expand Up @@ -1902,7 +1898,6 @@ def _display_expression(self, chart, result):
result._latex = r"\begin{array}{llcl} " + symbol + r"&" + \
latex(self._domain) + r"& \longrightarrow & " + \
field_latex_name + r" \\"

if chart is None:
for ch in self._domain._top_charts:
_display_expression(self, ch, result)
Expand Down

0 comments on commit 8ffa9c4

Please sign in to comment.