• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python polyclasses.DMP类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sympy.polys.polyclasses.DMP的典型用法代码示例。如果您正苦于以下问题:Python DMP类的具体用法?Python DMP怎么用?Python DMP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了DMP类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: chebyshevu_poly

def chebyshevu_poly(n, x=None, polys=False):
    """Generates Chebyshev polynomial of the second kind of degree `n` in `x`.

    Parameters
    ==========

    n : int
        `n` decides the degree of polynomial
    x : optional
    polys : bool, optional
        ``polys=True`` returns an expression, otherwise
        (default) returns an expression.
    """
    if n < 0:
        raise ValueError(
            "can't generate 2nd kind Chebyshev polynomial of degree %s" % n)

    poly = DMP(dup_chebyshevu(int(n), ZZ), ZZ)

    if x is not None:
        poly = Poly.new(poly, x)
    else:
        poly = PurePoly.new(poly, Dummy('x'))

    return poly if polys else poly.as_expr()
开发者ID:asmeurer,项目名称:sympy,代码行数:25,代码来源:orthopolys.py


示例2: gegenbauer_poly

def gegenbauer_poly(n, a, x=None, polys=False):
    """Generates Gegenbauer polynomial of degree `n` in `x`.

    Parameters
    ==========

    n : int
        `n` decides the degree of polynomial
    x : optional
    a
        Decides minimal domain for the list of
        coefficients.
    polys : bool, optional
        ``polys=True`` returns an expression, otherwise
        (default) returns an expression.
    """
    if n < 0:
        raise ValueError(
            "can't generate Gegenbauer polynomial of degree %s" % n)

    K, a = construct_domain(a, field=True)
    poly = DMP(dup_gegenbauer(int(n), a, K), K)

    if x is not None:
        poly = Poly.new(poly, x)
    else:
        poly = PurePoly.new(poly, Dummy('x'))

    return poly if polys else poly.as_expr()
开发者ID:asmeurer,项目名称:sympy,代码行数:29,代码来源:orthopolys.py


示例3: test_DUP_to_dict

def test_DUP_to_dict():
    f = DMP([[3],[],[2],[],[8]], ZZ)

    assert f.to_dict() == \
        {(4, 0): 3, (2, 0): 2, (0, 0): 8}
    assert f.to_sympy_dict() == \
        {(4, 0): ZZ.to_sympy(3), (2, 0): ZZ.to_sympy(2), (0, 0): ZZ.to_sympy(8)}
开发者ID:Aang,项目名称:sympy,代码行数:7,代码来源:test_polyclasses.py


示例4: jacobi_poly

def jacobi_poly(n, a, b, x=None, polys=False):
    """Generates Jacobi polynomial of degree `n` in `x`.

    Parameters
    ==========

    n : int
        `n` decides the degree of polynomial
    a
        Lower limit of minimal domain for the list of
        coefficients.
    b
        Upper limit of minimal domain for the list of
        coefficients.
    x : optional
    polys : bool, optional
        ``polys=True`` returns an expression, otherwise
        (default) returns an expression.
    """
    if n < 0:
        raise ValueError("can't generate Jacobi polynomial of degree %s" % n)

    K, v = construct_domain([a, b], field=True)
    poly = DMP(dup_jacobi(int(n), v[0], v[1], K), K)

    if x is not None:
        poly = Poly.new(poly, x)
    else:
        poly = PurePoly.new(poly, Dummy('x'))

    return poly if polys else poly.as_expr()
开发者ID:asmeurer,项目名称:sympy,代码行数:31,代码来源:orthopolys.py


示例5: laguerre_poly

def laguerre_poly(n, x=None, alpha=None, polys=False):
    """Generates Laguerre polynomial of degree `n` in `x`.

    Parameters
    ==========

    n : int
        `n` decides the degree of polynomial
    x : optional
    alpha
        Decides minimal domain for the list
        of coefficients.
    polys : bool, optional
        ``polys=True`` returns an expression, otherwise
        (default) returns an expression.
    """
    if n < 0:
        raise ValueError("can't generate Laguerre polynomial of degree %s" % n)

    if alpha is not None:
        K, alpha = construct_domain(
            alpha, field=True)  # XXX: ground_field=True
    else:
        K, alpha = QQ, QQ(0)

    poly = DMP(dup_laguerre(int(n), alpha, K), K)

    if x is not None:
        poly = Poly.new(poly, x)
    else:
        poly = PurePoly.new(poly, Dummy('x'))

    return poly if polys else poly.as_expr()
开发者ID:asmeurer,项目名称:sympy,代码行数:33,代码来源:orthopolys.py


示例6: spherical_bessel_fn

def spherical_bessel_fn(n, x=None, polys=False):
    """
    Coefficients for the spherical Bessel functions.

    Those are only needed in the jn() function.

    The coefficients are calculated from:

    fn(0, z) = 1/z
    fn(1, z) = 1/z**2
    fn(n-1, z) + fn(n+1, z) == (2*n+1)/z * fn(n, z)

    Parameters
    ==========

    n : int
        `n` decides the degree of polynomial
    x : optional
    polys : bool, optional
        ``polys=True`` returns an expression, otherwise
        (default) returns an expression.

    Examples
    ========

    >>> from sympy.polys.orthopolys import spherical_bessel_fn as fn
    >>> from sympy import Symbol
    >>> z = Symbol("z")
    >>> fn(1, z)
    z**(-2)
    >>> fn(2, z)
    -1/z + 3/z**3
    >>> fn(3, z)
    -6/z**2 + 15/z**4
    >>> fn(4, z)
    1/z - 45/z**3 + 105/z**5

    """

    if n < 0:
        dup = dup_spherical_bessel_fn_minus(-int(n), ZZ)
    else:
        dup = dup_spherical_bessel_fn(int(n), ZZ)

    poly = DMP(dup, ZZ)

    if x is not None:
        poly = Poly.new(poly, 1/x)
    else:
        poly = PurePoly.new(poly, 1/Dummy('x'))

    return poly if polys else poly.as_expr()
开发者ID:asmeurer,项目名称:sympy,代码行数:52,代码来源:orthopolys.py


示例7: __new__

    def __new__(cls, expr, coeffs=Tuple(), alias=None, **args):
        """Construct a new algebraic number. """
        expr = sympify(expr)

        if isinstance(expr, (tuple, Tuple)):
            minpoly, root = expr

            if not minpoly.is_Poly:
                minpoly = Poly(minpoly)
        elif expr.is_AlgebraicNumber:
            minpoly, root = expr.minpoly, expr.root
        else:
            minpoly, root = minimal_polynomial(
                expr, args.get('gen'), polys=True), expr

        dom = minpoly.get_domain()

        if coeffs != Tuple():
            if not isinstance(coeffs, ANP):
                rep = DMP.from_sympy_list(sympify(coeffs), 0, dom)
                scoeffs = Tuple(*coeffs)
            else:
                rep = DMP.from_list(coeffs.to_list(), 0, dom)
                scoeffs = Tuple(*coeffs.to_list())

            if rep.degree() >= minpoly.degree():
                rep = rep.rem(minpoly.rep)

            sargs = (root, scoeffs)

        else:
            rep = DMP.from_list([1, 0], 0, dom)

            if ask(Q.negative(root)):
                rep = -rep

            sargs = (root, coeffs)

        if alias is not None:
            if not isinstance(alias, Symbol):
                alias = Symbol(alias)
            sargs = sargs + (alias,)

        obj = Expr.__new__(cls, *sargs)

        obj.rep = rep
        obj.root = root
        obj.alias = alias
        obj.minpoly = minpoly

        return obj
开发者ID:thilinarmtb,项目名称:sympy,代码行数:51,代码来源:numberfields.py


示例8: legendre_poly

def legendre_poly(n, x=None, **args):
    """Generates Legendre polynomial of degree `n` in `x`. """
    if n < 0:
        raise ValueError("can't generate Legendre polynomial of degree %s" % n)

    poly = DMP(dup_legendre(int(n), QQ), QQ)

    if x is not None:
        poly = Poly.new(poly, x)
    else:
        poly = PurePoly.new(poly, Dummy('x'))

    if not args.get('polys', False):
        return poly.as_expr()
    else:
        return poly
开发者ID:A-turing-machine,项目名称:sympy,代码行数:16,代码来源:orthopolys.py


示例9: chebyshevu_poly

def chebyshevu_poly(n, x=None, **args):
    """Generates Chebyshev polynomial of the second kind of degree `n` in `x`. """
    if n < 0:
        raise ValueError("can't generate 2nd kind Chebyshev polynomial of degree %s" % n)

    poly = DMP(dup_chebyshevu(int(n), ZZ), ZZ)

    if x is not None:
        poly = Poly.new(poly, x)
    else:
        poly = PurePoly.new(poly, Dummy('x'))

    if not args.get('polys', False):
        return poly.as_expr()
    else:
        return poly
开发者ID:ALGHeArT,项目名称:sympy,代码行数:16,代码来源:orthopolys.py


示例10: cyclotomic_poly

def cyclotomic_poly(n, x=None, **args):
    """Generates cyclotomic polynomial of order `n` in `x`. """
    if n <= 0:
        raise ValueError("can't generate cyclotomic polynomial of order %s" % n)

    poly = DMP(dup_zz_cyclotomic_poly(int(n), ZZ), ZZ)

    if x is not None:
        poly = Poly.new(poly, x)
    else:
        poly = PurePoly.new(poly, Dummy('x'))

    if not args.get('polys', False):
        return poly.as_expr()
    else:
        return poly
开发者ID:ALGHeArT,项目名称:sympy,代码行数:16,代码来源:specialpolys.py


示例11: gegenbauer_poly

def gegenbauer_poly(n, a, x=None, **args):
    """Generates Gegenbauer polynomial of degree `n` in `x`. """
    if n < 0:
        raise ValueError("can't generate Gegenbauer polynomial of degree %s" % n)

    K, a = construct_domain(a, field=True)
    poly = DMP(dup_gegenbauer(int(n), a, K), K)

    if x is not None:
        poly = Poly.new(poly, x)
    else:
        poly = PurePoly.new(poly, Dummy('x'))

    if not args.get('polys', False):
        return poly.as_expr()
    else:
        return poly
开发者ID:StefenYin,项目名称:sympy,代码行数:17,代码来源:orthopolys.py


示例12: jacobi_poly

def jacobi_poly(n, a, b, x=None, **args):
    """Generates Jacobi polynomial of degree `n` in `x`. """
    if n < 0:
        raise ValueError("can't generate Jacobi polynomial of degree %s" % n)

    K, v = construct_domain([a, b], field=True)
    poly = DMP(dup_jacobi(int(n), v[0], v[1], K), K)

    if x is not None:
        poly = Poly.new(poly, x)
    else:
        poly = PurePoly.new(poly, Dummy('x'))

    if not args.get('polys', False):
        return poly.as_expr()
    else:
        return poly
开发者ID:A-turing-machine,项目名称:sympy,代码行数:17,代码来源:orthopolys.py


示例13: spherical_bessel_fn

def spherical_bessel_fn(n, x=None, **args):
    """
    Coefficients for the spherical Bessel functions.

    Those are only needed in the jn() function.

    The coefficients are calculated from:

    fn(0, z) = 1/z
    fn(1, z) = 1/z**2
    fn(n-1, z) + fn(n+1, z) == (2*n+1)/z * fn(n, z)

    Examples
    ========

    >>> from sympy.polys.orthopolys import spherical_bessel_fn as fn
    >>> from sympy import Symbol
    >>> z = Symbol("z")
    >>> fn(1, z)
    z**(-2)
    >>> fn(2, z)
    -1/z + 3/z**3
    >>> fn(3, z)
    -6/z**2 + 15/z**4
    >>> fn(4, z)
    1/z - 45/z**3 + 105/z**5

    """
    from sympy import sympify

    if n < 0:
        dup = dup_spherical_bessel_fn_minus(-int(n), ZZ)
    else:
        dup = dup_spherical_bessel_fn(int(n), ZZ)

    poly = DMP(dup, ZZ)

    if x is not None:
        poly = Poly.new(poly, 1/x)
    else:
        poly = PurePoly.new(poly, 1/Dummy('x'))

    if not args.get('polys', False):
        return poly.as_expr()
    else:
        return poly
开发者ID:SwaathiRamesh,项目名称:sympy,代码行数:46,代码来源:orthopolys.py


示例14: laguerre_poly

def laguerre_poly(n, x=None, alpha=None, **args):
    """Generates Laguerre polynomial of degree `n` in `x`. """
    if n < 0:
        raise ValueError("can't generate Laguerre polynomial of degree %s" % n)

    if alpha is not None:
        K, alpha = construct_domain(alpha, field=True) # XXX: ground_field=True
    else:
        K, alpha = QQ, QQ(0)

    poly = DMP(dup_laguerre(int(n), alpha, K), K)

    if x is not None:
        poly = Poly.new(poly, x)
    else:
        poly = PurePoly.new(poly, Dummy('x'))

    if not args.get('polys', False):
        return poly.as_expr()
    else:
        return poly
开发者ID:ALGHeArT,项目名称:sympy,代码行数:21,代码来源:orthopolys.py


示例15: legendre_poly

def legendre_poly(n, x=None, polys=False):
    """Generates Legendre polynomial of degree `n` in `x`.

    Parameters
    ----------
    n : int
        `n` decides the degree of polynomial
    x : optional
    polys : bool, optional
        ``polys=True`` returns an expression, otherwise
        (default) returns an expression.
    """
    if n < 0:
        raise ValueError("can't generate Legendre polynomial of degree %s" % n)

    poly = DMP(dup_legendre(int(n), QQ), QQ)

    if x is not None:
        poly = Poly.new(poly, x)
    else:
        poly = PurePoly.new(poly, Dummy('x'))

    return poly if polys else poly.as_expr()
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:23,代码来源:orthopolys.py


示例16: cyclotomic_poly

def cyclotomic_poly(n, x=None, polys=False):
    """Generates cyclotomic polynomial of order `n` in `x`.

    Parameters
    ----------
    n : int
        `n` decides the order of polynomial
    x : optional
    polys : bool, optional
        ``polys=True`` returns an expression, otherwise
        (default) returns an expression.
    """
    if n <= 0:
        raise ValueError(
            "can't generate cyclotomic polynomial of order %s" % n)

    poly = DMP(dup_zz_cyclotomic_poly(int(n), ZZ), ZZ)

    if x is not None:
        poly = Poly.new(poly, x)
    else:
        poly = PurePoly.new(poly, Dummy('x'))

    return poly if polys else poly.as_expr()
开发者ID:carstimon,项目名称:sympy,代码行数:24,代码来源:specialpolys.py


示例17: test_DMP_functionality

def test_DMP_functionality():
    f = DMP([[1],[2,0],[1,0,0]], ZZ)
    g = DMP([[1],[1,0]], ZZ)
    h = DMP([[1]], ZZ)

    assert f.degree() == 2
    assert f.degree_list() == (2, 2)
    assert f.total_degree() == 4

    assert f.LC() == ZZ(1)
    assert f.TC() == ZZ(0)
    assert f.nth(1, 1) == ZZ(2)

    raises(TypeError, "f.nth(0, 'x')")

    assert f.max_norm() == 2
    assert f.l1_norm() == 4

    u = DMP([[2],[2,0]], ZZ)

    assert f.diff(m=1, j=0) == u
    assert f.diff(m=1, j=1) == u

    raises(TypeError, "f.diff(m='x', j=0)")

    u = DMP([1,2,1], ZZ)
    v = DMP([1,2,1], ZZ)

    assert f.eval(a=1, j=0) == u
    assert f.eval(a=1, j=1) == v

    assert f.eval(1).eval(1) == ZZ(4)

    assert f.cofactors(g) == (g, g, h)
    assert f.gcd(g) == g
    assert f.lcm(g) == f

    u = DMP([[QQ(45),QQ(30),QQ(5)]], QQ)
    v = DMP([[QQ(1),QQ(2,3),QQ(1,9)]], QQ)

    assert u.monic() == v

    assert (4*f).content() == ZZ(4)
    assert (4*f).primitive() == (ZZ(4), f)

    f = DMP([[1],[2],[3],[4],[5],[6]], ZZ)

    assert f.trunc(3) == DMP([[1],[-1],[],[1],[-1],[]], ZZ)

    f = DMP(f_4, ZZ)

    assert f.sqf_part() == -f
    assert f.sqf_list() == (ZZ(-1), [(-f, 1)])

    f = DMP([[-1],[],[],[5]], ZZ)
    g = DMP([[3,1],[],[]], ZZ)
    h = DMP([[45,30,5]], ZZ)

    r = DMP([675,675,225,25], ZZ)

    assert f.subresultants(g) == [f, g, h]
    assert f.resultant(g) == r

    f = DMP([1,3,9,-13], ZZ)

    assert f.discriminant() == -11664

    f = DMP([QQ(2),QQ(0)], QQ)
    g = DMP([QQ(1),QQ(0),QQ(-16)], QQ)

    s = DMP([QQ(1,32),QQ(0)], QQ)
    t = DMP([QQ(-1,16)], QQ)
    h = DMP([QQ(1)], QQ)

    assert f.half_gcdex(g) == (s, h)
    assert f.gcdex(g) == (s, t, h)

    assert f.invert(g) == s

    f = DMP([[1],[2],[3]], QQ)

    raises(ValueError, "f.half_gcdex(f)")
    raises(ValueError, "f.gcdex(f)")

    raises(ValueError, "f.invert(f)")

    f = DMP([1,0,20,0,150,0,500,0,625,-2,0,-10,9], ZZ)
    g = DMP([1,0,0,-2,9], ZZ)
    h = DMP([1,0,5,0], ZZ)

    assert g.compose(h) == f
    assert f.decompose() == [g, h]

    f = DMP([[1],[2],[3]], QQ)

    raises(ValueError, "f.decompose()")
    raises(ValueError, "f.sturm()")
开发者ID:Aang,项目名称:sympy,代码行数:97,代码来源:test_polyclasses.py


示例18: test_DMP_arithmetics

def test_DMP_arithmetics():
    f = DMP([[2],[2,0]], ZZ)

    assert f.mul_ground(2) == DMP([[4],[4,0]], ZZ)
    assert f.exquo_ground(2) == DMP([[1],[1,0]], ZZ)

    raises(ExactQuotientFailed, 'f.quo_ground(3)')

    f = DMP([[-5]], ZZ)
    g = DMP([[5]], ZZ)

    assert f.abs() == g
    assert abs(f) == g

    assert g.neg() == f
    assert -g == f

    h = DMP([[]], ZZ)

    assert f.add(g) == h
    assert f + g == h
    assert g + f == h
    assert f + 5 == h
    assert 5 + f == h

    h = DMP([[-10]], ZZ)

    assert f.sub(g) == h
    assert f - g ==  h
    assert g - f == -h
    assert f - 5 ==  h
    assert 5 - f == -h

    h = DMP([[-25]], ZZ)

    assert f.mul(g) == h
    assert f * g == h
    assert g * f == h
    assert f * 5 == h
    assert 5 * f == h

    h = DMP([[25]], ZZ)

    assert f.sqr() == h
    assert f.pow(2) == h
    assert f**2 == h

    raises(TypeError, "f.pow('x')")

    f = DMP([[1],[],[1,0,0]], ZZ)
    g = DMP([[2],[-2,0]], ZZ)

    q = DMP([[2],[2,0]], ZZ)
    r = DMP([[8,0,0]], ZZ)

    assert f.pdiv(g) == (q, r)
    assert f.pexquo(g) == q
    assert f.prem(g) == r

    raises(ExactQuotientFailed, 'f.pquo(g)')

    f = DMP([[1],[],[1,0,0]], ZZ)
    g = DMP([[1],[-1,0]], ZZ)

    q = DMP([[1],[1,0]], ZZ)
    r = DMP([[2,0,0]], ZZ)

    assert f.div(g) == (q, r)
    assert f.exquo(g) == q
    assert f.rem(g) == r

    assert divmod(f, g) == (q, r)
    assert f // g == q
    assert f % g == r

    raises(ExactQuotientFailed, 'f.quo(g)')
开发者ID:Aang,项目名称:sympy,代码行数:76,代码来源:test_polyclasses.py



注:本文中的sympy.polys.polyclasses.DMP类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python polyconfig.query函数代码示例发布时间:2022-05-27
下一篇:
Python partfrac.apart函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap