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

Commit

Permalink
Trac #30209: display method + merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Jung committed Jul 28, 2020
2 parents 56996fd + 6a55a0b commit ef8ac4b
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 81 deletions.
6 changes: 4 additions & 2 deletions src/sage/manifolds/differentiable/automorphismfield_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

from sage.structure.unique_representation import UniqueRepresentation
from sage.structure.parent import Parent
from sage.symbolic.ring import ZZ
from sage.categories.groups import Groups
from sage.misc.cachefunc import cached_method
from sage.tensor.modules.free_module_linear_group import FreeModuleLinearGroup
Expand Down Expand Up @@ -209,7 +208,10 @@ def _element_constructor_(self, comp=[], frame=None, name=None,
a = (x^2 + 1) d/dx*dx + (y^2 + 1) d/dy*dy
"""
if comp in ZZ and comp == 1:
if hasattr(comp, 'is_trivial_zero'):
if (comp - 1).is_trivial_zero():
return self.one()
elif comp == 1:
return self.one()
if not isinstance(comp, (list, tuple)):
raise TypeError("cannot convert the {} ".format(comp) +
Expand Down
33 changes: 26 additions & 7 deletions src/sage/manifolds/differentiable/bundle_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def __ne__(self, other):
TESTS::
sage: M = Manifold(2, 'M')
sage: M = Manifold(2, 'M')
sage: X.<x,y> = M.chart()
sage: E = M.vector_bundle(2, 'E')
sage: e = E.local_frame('e') # standard frame for E
Expand Down Expand Up @@ -412,7 +412,7 @@ def _new_forms(self, frame):
dict of forms
"""
dom = frame._domain
dom = frame.domain()
forms_dict = {}
for i in self._vbundle.irange():
for j in self._vbundle.irange():
Expand Down Expand Up @@ -487,7 +487,7 @@ def connection_forms(self, frame=None):
comp_store = self._connection_forms[frame]
ocomp_store = self._connection_forms[oframe]
for ind, value in ocomp_store.items():
comp_store[ind] = value.restrict(frame._domain)
comp_store[ind] = value.restrict(frame.domain())
break
else:
# If not, the forms must be computed from scratch:
Expand Down Expand Up @@ -660,7 +660,7 @@ def _derive_trivial(self, v, s):
res[frame, j] = res_comp
return res

def add_connection_form(self, i, j, frame=None):
def add_connection_form(self, i, j, form=None, frame=None):
r"""
Return the connection form `\omega^j_i` in a given frame for
assignment.
Expand Down Expand Up @@ -741,9 +741,16 @@ def add_connection_form(self, i, j, frame=None):
" a frame on the {}".format(self._base_space))
self._connection_forms[frame] = self._new_forms(frame)
self._del_derived() # deletes the derived quantities
if form:
# TODO: Remove input `form` in Sage 9.3
from sage.misc.superseded import deprecation
msg = "the input 'form' is outdated and will be removed in a "
msg += "future version of Sage"
deprecation(30208, msg)
self._connection_forms[frame][(i, j)] = form.copy()
return self._connection_forms[frame][(i, j)]

def set_connection_form(self, i, j, frame=None):
def set_connection_form(self, i, j, form=None, frame=None):
r"""
Return the connection form `\omega^j_i` in a given frame for
assignment.
Expand Down Expand Up @@ -812,7 +819,13 @@ def set_connection_form(self, i, j, frame=None):
To keep them, use the method :meth:`add_connection_form` instead.
"""
omega = self.add_connection_form(i, j, frame=frame)
if form:
# TODO: Remove input `form` in Sage 9.3
from sage.misc.superseded import deprecation
msg = "the input 'form' is outdated and will be removed in a "
msg += "future version of Sage"
deprecation(30208, msg)
omega = self.add_connection_form(i, j, form=None, frame=frame)
self.del_other_forms(frame)
return omega

Expand Down Expand Up @@ -1138,7 +1151,7 @@ def __setitem__(self, args, value):
"of value must contain lists/tuples")
else:
# check lenghts:
rk = vb._rank
rk = vb.rank()
if len(value) != rk:
raise ValueError("value must have "
"length {}".format(rk))
Expand All @@ -1153,3 +1166,9 @@ def __setitem__(self, args, value):
else:
raise NotImplementedError("[start:stop] syntax not "
"implemented")

def display(self, frame=None, vector_frame=None, chart=None, symbol=None,
latex_symbol=None, only_nonzero=True):
r"""
"""
17 changes: 12 additions & 5 deletions src/sage/manifolds/differentiable/diff_form_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
from sage.structure.unique_representation import UniqueRepresentation
from sage.structure.parent import Parent
from sage.categories.modules import Modules
from sage.symbolic.ring import ZZ
from sage.tensor.modules.ext_pow_free_module import ExtPowerDualFreeModule
from sage.manifolds.differentiable.diff_form import DiffForm, DiffFormParal
from sage.manifolds.differentiable.tensorfield import TensorField
Expand Down Expand Up @@ -331,8 +330,12 @@ def _element_constructor_(self, comp=[], frame=None, name=None,
True
"""
if comp in ZZ and comp == 0:
return self.zero()
try:
if comp.is_trivial_zero():
return self.zero()
except AttributeError:
if comp == 0:
return self.zero()
if isinstance(comp, (DiffForm, DiffFormParal)):
# coercion by domain restriction
if (self._degree == comp._tensor_type[1]
Expand Down Expand Up @@ -800,8 +803,12 @@ def _element_constructor_(self, comp=[], frame=None, name=None,
False
"""
if comp in ZZ and comp == 0:
return self.zero()
try:
if comp.is_trivial_zero():
return self.zero()
except AttributeError:
if comp == 0:
return self.zero()
if isinstance(comp, (DiffForm, DiffFormParal)):
# coercion by domain restriction
if (self._degree == comp._tensor_type[1]
Expand Down
16 changes: 11 additions & 5 deletions src/sage/manifolds/differentiable/mixed_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,11 +896,17 @@ def _lmul_(self, other):
y/\(x/\F) = [0] + [x^2*y^2 dx] + [0]
"""
# Simple checks:
if other.is_trivial_zero():
return self.parent().zero()
elif (other - 1).is_trivial_zero():
return self
try:
if other.is_trivial_zero():
return self.parent().zero()
if (other - 1).is_trivial_zero():
return self
except AttributeError:
# in case base ring is not SR:
if other == 0:
return self.parent().zero()
if other == 1:
return self
resu = self._new_instance()
resu[:] = [other * form for form in self._comp]
# Compose name:
Expand Down
63 changes: 35 additions & 28 deletions src/sage/manifolds/differentiable/mixed_form_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
from sage.structure.parent import Parent
from sage.categories.graded_algebras import GradedAlgebras
from sage.structure.unique_representation import UniqueRepresentation
from sage.symbolic.ring import ZZ, SR
from sage.symbolic.ring import SR
from sage.manifolds.differentiable.mixed_form import MixedForm

class MixedFormAlgebra(Parent, UniqueRepresentation):
r"""
An instance of this class represents the graded algebra of mixed form. That
is, if `\varphi: M \to N` is a differentiable map between two differentiable
manifolds `M` and `N`, the *graded algebra of mixed forms*
is, if `\varphi: M \to N` is a differentiable map between two
differentiable manifolds `M` and `N`, the *graded algebra of mixed forms*
`\Omega^*(M,\varphi)` *along* `\varphi` is defined via the direct sum
`\bigoplus^{n}_{j=0} \Omega^j(M,\varphi)` consisting of differential form
modules
Expand Down Expand Up @@ -112,8 +112,8 @@ class MixedFormAlgebra(Parent, UniqueRepresentation):
sage: U = M.open_subset('U'); U
Open subset U of the 3-dimensional differentiable manifold M
sage: OmegaU = U.mixed_form_algebra(); OmegaU
Graded algebra Omega^*(U) of mixed differential forms on the Open subset
U of the 3-dimensional differentiable manifold M
Graded algebra Omega^*(U) of mixed differential forms on the Open
subset U of the 3-dimensional differentiable manifold M
sage: OmegaU.has_coerce_map_from(Omega)
True
Expand All @@ -137,8 +137,8 @@ def __init__(self, vector_field_module):
....: intersection_name='W', restrictions1= x>0,
....: restrictions2= u+v>0)
sage: inv = transf.inverse()
sage: from sage.manifolds.differentiable.mixed_form_algebra import (
....: MixedFormAlgebra)
sage: from sage.manifolds.differentiable.mixed_form_algebra \
....: import MixedFormAlgebra
sage: A = MixedFormAlgebra(M.vector_field_module())
sage: TestSuite(A).run()
Expand Down Expand Up @@ -174,7 +174,7 @@ def __init__(self, vector_field_module):
self._vmodule = vector_field_module
self._max_deg = vector_field_module._ambient_domain.dim()

def _element_constructor_(self, comp=None, name=None, latex_name=None):
def _element_constructor_(self, comp, name=None, latex_name=None):
r"""
Construct a mixed form.
Expand All @@ -190,34 +190,38 @@ def _element_constructor_(self, comp=None, name=None, latex_name=None):
manifold M
"""
try:
if comp.is_trivial_zero():
return self.zero()
elif (comp - 1).is_trivial_zero():
return self.one()
except AttributeError:
if comp == 0:
return self.zero()
if comp == 1:
return self.one()
res = self.element_class(self, name=name, latex_name=latex_name)
if comp is None:
return res
elif comp in ZZ and comp == 0:
return self.zero()
elif comp in ZZ and comp == 1:
return self.one()
elif isinstance(comp, (tuple, list)):
if isinstance(comp, (tuple, list)):
if len(comp) != self._max_deg + 1:
raise IndexError("input list must have "
"length {}".format(self._max_deg + 1))
if isinstance(comp, tuple):
comp = list(comp)
res[:] = comp[:]
elif isinstance(comp, self.Element):
res[:] = comp[:]
else:
for d in self.irange():
dmodule = self._domain.diff_form_module(d, dest_map=self._dest_map)
dom = self._domain
dmodule = dom.diff_form_module(d, dest_map=self._dest_map)
if dmodule.has_coerce_map_from(comp.parent()):
deg = d
break
else:
raise TypeError("cannot convert {} into an element of "
"the {}".format(comp, self))
res[:] = [0] * (self._max_deg + 1) # fill up with zeroes...
res[deg] = comp # ...and set comp at deg of res;
# the coercion is performed here
# fill up with zeroes:
res[:] = [0] * (self._max_deg + 1)
# set comp where it belongs:
res[deg] = comp # coercion is performed here
# In case, no other name is given, use name of comp:
if name is None:
if hasattr(comp, '_name'):
Expand All @@ -244,7 +248,8 @@ def _an_element_(self):
"""
res = self.element_class(self)
res[:] = [self._domain.diff_form_module(j, self._dest_map)._an_element_()
dom = self._domain
res[:] = [dom.diff_form_module(j, self._dest_map)._an_element_()
for j in self.irange()]
return res

Expand Down Expand Up @@ -277,7 +282,7 @@ def _coerce_map_from_(self, S):
if isinstance(S, type(self)):
# coercion by domain restriction
if (self._domain.is_subset(S._domain) and
self._ambient_domain.is_subset(S._ambient_domain)):
self._ambient_domain.is_subset(S._ambient_domain)):
return True
# Still, there could be a coerce map
if self.irange() != S.irange():
Expand All @@ -291,8 +296,9 @@ def _coerce_map_from_(self, S):
# Each degree is coercible so there must be a coerce map:
return True
# Let us check for each degree consecutively:
return any(self._domain.diff_form_module(deg,
self._dest_map).has_coerce_map_from(S)
dom = self._domain
return any(dom.diff_form_module(deg,
self._dest_map).has_coerce_map_from(S)
for deg in self.irange())

@cached_method
Expand Down Expand Up @@ -371,12 +377,13 @@ def _repr_(self):
3-dimensional differentiable manifold M
"""
desc = ("Graded algebra " + self._name + " of mixed differential forms ")
desc = "Graded algebra " + self._name
desc += " of mixed differential forms "
if self._dest_map is self._domain.identity_map():
desc += "on the {}".format(self._domain)
else:
desc += "along the {} mapped into the {} ".format(self._domain,
self._ambient_domain)
desc += "along the {} mapped ".format(self._domain)
desc += "into the {} ".format(self._ambient_domain)
if self._dest_map._name is None:
dm_name = "unnamed map"
else:
Expand Down
17 changes: 12 additions & 5 deletions src/sage/manifolds/differentiable/multivector_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from sage.misc.cachefunc import cached_method
from sage.structure.unique_representation import UniqueRepresentation
from sage.structure.parent import Parent
from sage.symbolic.ring import ZZ
from sage.categories.modules import Modules
from sage.tensor.modules.ext_pow_free_module import ExtPowerFreeModule
from sage.manifolds.differentiable.multivectorfield import (
Expand Down Expand Up @@ -301,8 +300,12 @@ def _element_constructor_(self, comp=[], frame=None, name=None,
True
"""
if comp in ZZ and comp == 0:
return self.zero()
try:
if comp.is_trivial_zero():
return self.zero()
except AttributeError:
if comp == 0:
return self.zero()
if isinstance(comp, (MultivectorField, MultivectorFieldParal)):
# coercion by domain restriction
if (self._degree == comp._tensor_type[0]
Expand Down Expand Up @@ -725,8 +728,12 @@ def _element_constructor_(self, comp=[], frame=None, name=None,
True
"""
if comp in ZZ and comp == 0:
return self.zero()
try:
if comp.is_trivial_zero():
return self.zero()
except AttributeError:
if comp == 0:
return self.zero()
if isinstance(comp, (MultivectorField, MultivectorFieldParal)):
# coercion by domain restriction
if (self._degree == comp._tensor_type[0]
Expand Down
4 changes: 2 additions & 2 deletions src/sage/manifolds/differentiable/scalarfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,9 @@ class DiffScalarField(ScalarField):
field::
sage: s = f + 1 ; s
Scalar field on the 2-dimensional differentiable manifold M
Scalar field f+1 on the 2-dimensional differentiable manifold M
sage: s.display()
M --> R
f+1: M --> R
on U: (x, y) |--> (x^2 + y^2 + 2)/(x^2 + y^2 + 1)
on V: (u, v) |--> (2*u^2 + 2*v^2 + 1)/(u^2 + v^2 + 1)
sage: (f+1)-1 == f
Expand Down
Loading

0 comments on commit ef8ac4b

Please sign in to comment.