本文整理汇总了Python中sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing.fraction_field方法的典型用法代码示例。如果您正苦于以下问题:Python PolynomialRing.fraction_field方法的具体用法?Python PolynomialRing.fraction_field怎么用?Python PolynomialRing.fraction_field使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing
的用法示例。
在下文中一共展示了PolynomialRing.fraction_field方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing [as 别名]
# 或者: from sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing import fraction_field [as 别名]
def __init__(self, ogf, *args, **kwargs):
"""
Create a C-finite sequence given its ordinary generating function.
INPUT:
- ``ogf`` -- the ordinary generating function, a fraction of polynomials over the rationals
OUTPUT:
- A CFiniteSequence object
EXAMPLES::
sage: R.<x> = QQ[]
sage: CFiniteSequence((2-x)/(1-x-x^2)) # the Lucas sequence
C-finite sequence, generated by (-x + 2)/(-x^2 - x + 1)
sage: CFiniteSequence(x/(1-x)^3) # triangular numbers
C-finite sequence, generated by x/(-x^3 + 3*x^2 - 3*x + 1)
Polynomials are interpreted as finite sequences, or recurrences of degree 0::
sage: CFiniteSequence(x^2-4*x^5)
Finite sequence [1, 0, 0, -4], offset = 2
sage: CFiniteSequence(1)
Finite sequence [1], offset = 0
This implementation allows any polynomial fraction as o.g.f. by interpreting
any power of `x` dividing the o.g.f. numerator or denominator as a right or left shift
of the sequence offset::
sage: CFiniteSequence(x^2+3/x)
Finite sequence [3, 0, 0, 1], offset = -1
sage: CFiniteSequence(1/x+4/x^3)
Finite sequence [4, 0, 1], offset = -3
sage: P = LaurentPolynomialRing(QQ.fraction_field(), 'X')
sage: X=P.gen()
sage: CFiniteSequence(1/(1-X))
C-finite sequence, generated by 1/(-x + 1)
The o.g.f. is always normalized to get a denominator constant coefficient of `+1`::
sage: CFiniteSequence(1/(x-2))
C-finite sequence, generated by -1/2/(-1/2*x + 1)
TESTS::
sage: P.<x> = QQ[]
sage: CFiniteSequence(0.1/(1-x))
Traceback (most recent call last):
...
ValueError: O.g.f. base not rational.
sage: P.<x,y> = QQ[]
sage: CFiniteSequence(x*y)
Traceback (most recent call last):
...
NotImplementedError: Multidimensional o.g.f. not implemented.
"""
self._br = ogf.base_ring()
if (self._br <> QQ) and (self._br <> ZZ) and not is_FiniteField(self._br):
raise ValueError('O.g.f. base not proper.')
P = PolynomialRing(self._br, 'x')
if ogf in QQ:
ogf = P(ogf)
if hasattr(ogf,'numerator'):
try:
num = P(ogf.numerator())
den = P(ogf.denominator())
except TypeError:
if ogf.numerator().parent().ngens() > 1:
raise NotImplementedError('Multidimensional o.g.f. not implemented.')
else:
raise ValueError('Numerator and denominator must be polynomials.')
else:
num = P(ogf)
den = 1
# Transform the ogf numerator and denominator to canonical form
# to get the correct offset, degree, and recurrence coeffs and
# start values.
self._off = 0
self._deg = 0
if isinstance (ogf, FractionFieldElement) and den == 1:
ogf = num # case p(x)/1: fall through
if isinstance (ogf, (FractionFieldElement, FpTElement)):
x = P.gen()
if num.constant_coefficient() == 0:
self._off = num.valuation()
num = P(num / x**self._off)
elif den.constant_coefficient() == 0:
self._off = -den.valuation()
den = P(den * x**self._off)
f = den.constant_coefficient()
num = P(num / f)
den = P(den / f)
#.........这里部分代码省略.........