本文整理汇总了Python中sage.structure.element.parent函数的典型用法代码示例。如果您正苦于以下问题:Python parent函数的具体用法?Python parent怎么用?Python parent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parent函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _element_constructor_
def _element_constructor_(self, vectors):
"""
Construct an element of ``self`` from ``vectors``.
TESTS::
sage: E.<x,y> = ExteriorAlgebra(QQ)
sage: H = E.hochschild_complex(E)
sage: H(0)
Trivial chain
sage: H(2)
Chain(0: 2)
sage: H(x+2*y)
Chain(0: x + 2*y)
sage: H({0: H.module(0).an_element()})
Chain(0: 2 + 2*x + 3*y)
sage: H({2: H.module(2).an_element()})
Chain(2: 2*1 # 1 # 1 + 2*1 # 1 # x + 3*1 # 1 # y)
sage: H({0:x-y, 2: H.module(2).an_element()})
Chain with 2 nonzero terms over Rational Field
sage: H([2])
Traceback (most recent call last):
...
ValueError: cannot construct an element from [2]
"""
if not vectors: # special case: the zero chain
return self.element_class(self, {})
# special case: an element of the defining module
if self._M.has_coerce_map_from(parent(vectors)):
vectors = self._M(vectors)
if parent(vectors) is self._M:
mc = vectors.monomial_coefficients(copy=False)
vec = self.module(0)._from_dict({(k,): mc[k] for k in mc})
return self.element_class(self, {0: vec})
if isinstance(vectors, (Chain_class, self.element_class)):
vectors = vectors._vec
data = dict()
if not isinstance(vectors, dict):
raise ValueError("cannot construct an element from {}".format(vectors))
# Special handling for the 0 free module
# FIXME: Allow coercions between the 0 free module and the defining module
if 0 in vectors:
vec = vectors.pop(0)
if parent(vec) is self._M:
mc = vec.monomial_coefficients(copy=False)
data[0] = self.module(0)._from_dict({(k,): mc[k] for k in mc})
else:
data[0] = self.module(0)(vec)
for degree in vectors:
vec = self.module(degree)(vectors[degree])
if not vec:
continue
data[degree] = vec
return self.element_class(self, data)
开发者ID:mcognetta,项目名称:sage,代码行数:54,代码来源:hochschild_complex.py
示例2: __ge__
def __ge__(self, other):
"""
TESTS::
sage: A = crystals.KirillovReshetikhin(['C',2,1], 1,2).affinization()
sage: S = A.subcrystal(max_depth=2)
sage: ([(i,j) for i in range(len(S)) for j in range(len(S)) if S[i]>=S[j]]
....: == [(i,j) for i in range(len(S)) for j in range(len(S)) if
....: S[i].value>=S[j].value])
True
"""
return parent(self) is parent(other) and self.value >= other.value
开发者ID:Babyll,项目名称:sage,代码行数:12,代码来源:subcrystal.py
示例3: __cmp__
def __cmp__(self, other):
"""
TESTS::
sage: A = crystals.KirillovReshetikhin(['C',2,1], 1,2).affinization()
sage: S = A.subcrystal(max_depth=2)
sage: ([(i,j,cmp(S[i],S[j])) for i in range(len(S)) for j in range(len(S))]
....: == [(i,j,cmp(S[i].value,S[j].value)) for i in range(len(S)) for j in range(len(S))])
True
"""
if parent(self) is parent(other):
return cmp(self.value, other.value)
else:
return cmp(parent(self), parent(other))
开发者ID:Babyll,项目名称:sage,代码行数:14,代码来源:subcrystal.py
示例4: __lt__
def __lt__(self, other):
""""
EXAMPLES::
sage: K = crystals.KirillovReshetikhin(['A',2,1],1,1)
sage: b = K(rows=[[1]])
sage: c = K(rows=[[2]])
sage: c<b
False
sage: b<b
False
sage: b<c
True
"""
return parent(self) is parent(other) and self.value < other.value
开发者ID:Babyll,项目名称:sage,代码行数:15,代码来源:affine.py
示例5: __ge__
def __ge__(self, other):
""""
EXAMPLES::
sage: K = crystals.KirillovReshetikhin(['A',2,1],1,1)
sage: b = K(rows=[[1]])
sage: c = K(rows=[[2]])
sage: c>=b
True
sage: b>=b
True
sage: b>=c
False
"""
return parent(self) is parent(other) and self.value >= other.value
开发者ID:Babyll,项目名称:sage,代码行数:15,代码来源:affine.py
示例6: is_parent_of
def is_parent_of(self, element):
"""
Returns whether ``self`` is the parent of ``element``
INPUT:
- ``element`` -- any object
EXAMPLES::
sage: S = ZZ
sage: S.is_parent_of(1)
True
sage: S.is_parent_of(2/1)
False
This method differs from :meth:`__contains__` because it
does not attempt any coercion::
sage: 2/1 in S, S.is_parent_of(2/1)
(True, False)
sage: int(1) in S, S.is_parent_of(int(1))
(True, False)
"""
from sage.structure.element import parent
return parent(element) == self
开发者ID:jwbober,项目名称:sagelib,代码行数:25,代码来源:sets_cat.py
示例7: index_of_object
def index_of_object(self, i):
"""
Try to return the node of the Dynkin diagram indexing the object `i`.
OUTPUT: a node of the Dynkin diagram or ``None``
EXAMPLES::
sage: L = RootSystem(["A",3]).root_lattice()
sage: alpha = L.simple_roots()
sage: omega = RootSystem(["A",3]).weight_lattice().fundamental_weights()
sage: options = L.plot_parse_options(labels=False)
sage: options.index_of_object(3)
3
sage: options.index_of_object(alpha[1])
1
sage: options.index_of_object(omega[2])
2
sage: options.index_of_object(omega[2]+omega[3])
sage: options.index_of_object(30)
sage: options.index_of_object("bla")
"""
if parent(i) in RootLatticeRealizations and len(i) == 1 and i.leading_coefficient().is_one():
i = i.leading_support()
if i in self.space.cartan_type().index_set():
return i
return None
开发者ID:pombredanne,项目名称:sage,代码行数:27,代码来源:plot.py
示例8: _evalf_
def _evalf_(self, n, x, parent=None, algorithm=None):
"""
EXAMPLES::
sage: bessel_J(0.0, 1.0)
0.765197686557967
sage: bessel_J(0, 1).n(digits=20)
0.76519768655796655145
sage: bessel_J(0.5, 1.5)
0.649838074753747
Check for correct rounding (:trac:`17122`)::
sage: R = RealField(113)
sage: a = R("8.935761195587725798762818805462843676e-01")
sage: aa = RealField(200)(a)
sage: for n in [-10..10]:
....: b = bessel_J(R(n), a)
....: bb = R(bessel_J(n, aa))
....: if b != bb:
....: print n, b-bb
"""
if parent is not None:
x = parent(x)
try:
return x.jn(Integer(n))
except Exception:
pass
n, x = get_coercion_model().canonical_coercion(n, x)
import mpmath
return mpmath_utils.call(mpmath.besselj, n, x, parent=parent)
开发者ID:Findstat,项目名称:sage,代码行数:33,代码来源:bessel.py
示例9: _cmp_
def _cmp_(self, other):
"""
EXAMPLES::
sage: one = lisp(1); two = lisp(2)
sage: one == one
True
sage: one != two
True
sage: one < two
True
sage: two > one
True
sage: one < 1
False
sage: two == 2
True
"""
P = self._check_valid()
if parent(other) is not P:
other = P(other)
if P.eval('(= %s %s)'%(self.name(), other.name())) == P._true_symbol():
return 0
elif P.eval('(< %s %s)'%(self.name(), other.name())) == P._true_symbol():
return -1
else:
return 1
开发者ID:saraedum,项目名称:sage-renamed,代码行数:29,代码来源:lisp.py
示例10: __pow__
def __pow__(self, n):
"""
EXAMPLES::
sage: a = maxima('2')
sage: a^(3/4)
2^(3/4)
::
sage: f = maxima.function('x','sin(x)')
sage: g = maxima('-cos(x)')
sage: f^g
1/sin(x)^cos(x)
::
sage: f = maxima.function('x','sin(x)')
sage: g = maxima('-cos(x)') # not a function
sage: g^f
(-cos(x))^sin(x)
"""
P = self._check_valid()
if parent(n) is not P:
n = P(n)
return self._operation("^", n)
开发者ID:robertwb,项目名称:sage,代码行数:26,代码来源:interface.py
示例11: __contains__
def __contains__(self, x):
r"""
Test if x is an element of this group. This checks that x defines (is?) a 2x2 integer matrix of determinant 1, and
then hands over to the routine _contains_sl2, which derived classes should implement.
EXAMPLES::
sage: [1,2] in SL2Z # indirect doctest
False
sage: [1,2,0,1] in SL2Z # indirect doctest
True
sage: SL2Z([1,2,0,1]) in Gamma(3) # indirect doctest
False
sage: -1 in SL2Z
True
sage: 2 in SL2Z
False
"""
# Do not override this function! Derived classes should override
# _contains_sl2.
if isinstance(x, list) and len(x) == 4:
if not (x[0] in ZZ and x[1] in ZZ and x[2] in ZZ and x[3] in ZZ):
return False
a,b,c,d = map(ZZ, x)
if a*d - b*c != 1: return False
return self._contains_sl2(a,b,c,d)
else:
if parent(x) is not SL2Z:
try:
y = SL2Z(x)
except TypeError:
return False
x = y
return self._contains_sl2(x.a(),x.b(),x.c(),x.d())
开发者ID:Babyll,项目名称:sage,代码行数:34,代码来源:arithgroup_generic.py
示例12: strongly_finer
def strongly_finer(self):
"""
Return the set of ordered set partitions which are strongly
finer than ``self``.
See :meth:`is_strongly_finer` for the definition of "strongly
finer".
EXAMPLES::
sage: C = OrderedSetPartition([[1, 3], [2]]).strongly_finer()
sage: C.cardinality()
2
sage: C.list()
[[{1}, {3}, {2}], [{1, 3}, {2}]]
sage: OrderedSetPartition([]).strongly_finer()
{[]}
sage: W = OrderedSetPartition([[4, 9], [-1, 2]])
sage: W.strongly_finer().list()
[[{4}, {9}, {-1}, {2}],
[{4}, {9}, {-1, 2}],
[{4, 9}, {-1}, {2}],
[{4, 9}, {-1, 2}]]
"""
par = parent(self)
if not self:
return FiniteEnumeratedSet([self])
else:
buo = OrderedSetPartition.bottom_up_osp
return FiniteEnumeratedSet([par(sum((list(P) for P in C), []))
for C in cartesian_product([[buo(X, comp) for comp in Compositions(len(X))] for X in self])])
开发者ID:saraedum,项目名称:sage-renamed,代码行数:33,代码来源:set_partition_ordered.py
示例13: _element_constructor_
def _element_constructor_(self, element):
"""
Coerce ``element`` into ``self``
INPUT:
- ``element`` -- any object
This default implementation returns ``element`` if
``self`` is a facade for ``parent(element)`. Otherwise it
attempts in turn to coerce ``element`` into each parent
``self`` is a facade for.
This implementation is only valid for a facade parent
which models the full union of the parents it is a facade
for. Other facade parents should redefine
:meth:`element_constructor` appropriately.
EXAMPLES::
sage: S = Sets().Facades().example("union"); S
An example of a facade set: the integers completed by +-infinity
sage: S(1)
1
sage: S(1/2)
Traceback (most recent call last):
...
ValueError: Can't coerce `1/2` in any parent `An example of a facade set: the integers completed by +-infinity` is a facade for
sage: S(2/1)
2
sage: S(2/1).parent()
Integer Ring
sage: S(int(1))
1
sage: S(int(1)).parent()
Integer Ring
Facade parents that model strict subsets should redefine
:meth:`element_constructor`::
sage: S = Sets().Facades().example(); S
An example of facade set: the monoid of positive integers
sage: S(-1)
Traceback (most recent call last):
...
ValueError: %s should be positive
"""
if self.is_parent_of(element):
return element
else:
parents = self.facade_for()
if parents is True:
return NotImplementedError
for parent in self.facade_for():
try:
return parent(element)
except Exception:
pass
raise ValueError, "Can't coerce `%s` in any parent `%s` is a facade for"%(element, self)
开发者ID:jeromeca,项目名称:sagesmc,代码行数:59,代码来源:facade_sets.py
示例14: __cmp__
def __cmp__(self, other):
""""
EXAMPLES::
sage: K = crystals.KirillovReshetikhin(['A',2,1],1,1)
sage: b = K(rows=[[1]])
sage: c = K(rows=[[2]])
sage: cmp(b,c)
-1
sage: cmp(b,b)
0
If the parent are different, it uses comparison of the parents::
sage: cmp(b,1) == cmp(b.parent(), ZZ)
True
"""
return cmp(parent(self), parent(other)) or cmp(self.value, other.value)
开发者ID:Babyll,项目名称:sage,代码行数:18,代码来源:affine.py
示例15: __ne__
def __ne__(self, other):
r"""
TESTS::
sage: from flatsurf import *
sage: t = translation_surfaces.square_torus()
sage: F = t.fundamental_group()
sage: a,b = F.gens()
sage: a != b
True
sage: a*b != b*a
True
sage: a*b != a*b
False
"""
return parent(self) is not parent(other) or \
self._polys != other._polys or \
self._edges != other._edges
开发者ID:videlec,项目名称:sage-flatsurf,代码行数:18,代码来源:fundamental_group.py
示例16: __eq__
def __eq__(self, other):
r"""
TESTS::
sage: from flatsurf import *
sage: t = translation_surfaces.square_torus()
sage: F = t.fundamental_group()
sage: a,b = F.gens()
sage: a == b
False
sage: a*b == b*a
False
sage: a*b == a*b
True
"""
return parent(self) is parent(other) and \
self._polys == other._polys and \
self._edges == other._edges
开发者ID:videlec,项目名称:sage-flatsurf,代码行数:18,代码来源:fundamental_group.py
示例17: __eq__
def __eq__(self, other):
r"""
Equality test.
EXAMPLES::
sage: UCF = UniversalCyclotomicField()
sage: UCF.one() == 1
True
sage: 1 == UCF.one()
True
sage: UCF(2/3) == 2/3
True
sage: 2/3 == UCF(2/3)
True
sage: UCF.gen(3) == UCF.gen(5)
False
sage: UCF.gen(5) + UCF.gen(3) == UCF.gen(3) + UCF.gen(5)
True
sage: UCF.zero() == None
False
sage: QQbar.zeta(5) == UCF.gen(5)
True
sage: UCF.gen(5) == QQbar.zeta(5)
True
sage: QQbar.zeta(5) == UCF.gen(5,2)
False
sage: UCF.gen(5,2) == QQbar.zeta(5)
False
"""
if parent(self) is not parent(other):
from sage.structure.element import get_coercion_model
cm = get_coercion_model()
try:
self, other = cm.canonical_coercion(self, other)
except TypeError:
return False
return self == other
return self._obj == other._obj
开发者ID:novoselt,项目名称:sage,代码行数:44,代码来源:universal_cyclotomic_field.py
示例18: _test_codegrees
def _test_codegrees(self, **options):
"""
Test the method :meth:`degrees`.
INPUT:
- ``options`` -- any keyword arguments accepted by :meth:`_tester`
EXAMPLES::
sage: from sage.categories.complex_reflection_groups import ComplexReflectionGroups
sage: W = ComplexReflectionGroups().Finite().example(); W # optional - gap3
Reducible real reflection group of rank 4 and type A2 x B2
sage: W._test_codegrees() # optional - gap3
sage: W = SymmetricGroup(5)
sage: W._test_codegrees()
We now break the implementation of W.degrees and check that this is caught::
sage: W.codegrees = lambda: (1/1,5)
sage: W._test_codegrees()
Traceback (most recent call last):
...
AssertionError: the codegrees should be integers
sage: W.codegrees = lambda: (2,1,-1)
sage: W._test_codegrees()
Traceback (most recent call last):
...
AssertionError: the codegrees should be nonnegative
We restore W to its normal state::
sage: del W.codegrees
sage: W._test_codegrees()
See the documentation for :class:`TestSuite` for more information.
"""
from sage.structure.element import parent
from sage.rings.integer_ring import ZZ
tester = self._tester(**options)
codegrees = self.codegrees()
tester.assertIsInstance(codegrees, tuple,
"the codegrees method should return a tuple")
tester.assertTrue(all(parent(d) is ZZ for d in codegrees),
"the codegrees should be integers")
tester.assertTrue(all(d >= 0 for d in codegrees),
"the codegrees should be nonnegative")
tester.assertEqual(len(codegrees), self.rank(),
"the number of codegrees should coincide with the rank")
tester.assertEqual(sum(d + 1 for d in codegrees),
self.number_of_reflection_hyperplanes(),
"the sum of the codegrees should be consistent with the number of reflection hyperplanes")
开发者ID:sagemath,项目名称:sage,代码行数:55,代码来源:finite_complex_reflection_groups.py
示例19: __cmp__
def __cmp__(self, other):
"""
Comparison.
TESTS::
sage: A = crystals.KirillovReshetikhin(['A',2,1], 2, 2).affinization()
sage: mg = A.module_generators[0]
sage: mg == mg
True
sage: mg == mg.f(2).e(2)
True
sage: KT = crystals.TensorProductOfKirillovReshetikhinTableaux(['C',2,1], [[1,2],[2,1]])
sage: A = crystals.AffinizationOf(KT)
sage: A(KT.module_generators[3], 1).f(0) == A.module_generators[0]
True
sage: A = crystals.KirillovReshetikhin(['A',2,1], 2, 2).affinization()
sage: mg = A.module_generators[0]
sage: mg != mg.f(2)
True
sage: mg != mg.f(2).e(2)
False
sage: A = crystals.KirillovReshetikhin(['A',2,1], 2, 2).affinization()
sage: S = A.subcrystal(max_depth=2)
sage: sorted(S)
[[[1, 1], [2, 2]](0),
[[1, 1], [2, 3]](0),
[[1, 2], [2, 3]](0),
[[1, 1], [3, 3]](0),
[[1, 1], [2, 3]](1),
[[1, 2], [2, 3]](1),
[[1, 2], [3, 3]](1),
[[2, 2], [3, 3]](2)]
"""
if parent(self) is parent(other):
return cmp(self._m, other._m) or cmp(self._b, other._b)
else:
return cmp(parent(self), parent(other))
开发者ID:TaraFife,项目名称:sage,代码行数:42,代码来源:affinization.py
示例20: _evalf_
def _evalf_(self, u, m, parent=None, algorithm=None):
"""
EXAMPLES::
sage: elliptic_eu(1,1).n()
0.761594155955765
sage: elliptic_eu(1,1).n(200)
0.7615941559557648881194582...
"""
R = parent or parent(z)
return mpmath_utils.call(elliptic_eu_f, u, m, parent=R)
开发者ID:robertwb,项目名称:sage,代码行数:11,代码来源:special.py
注:本文中的sage.structure.element.parent函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论