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

Python sympy.posify函数代码示例

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

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



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

示例1: test_posify

def test_posify():
    from sympy import posify, Symbol, log
    from sympy.abc import x

    assert str(posify(x + Symbol("p", positive=True) + Symbol("n", negative=True))) == "(_x + n + p, {_x: x})"

    # log(1/x).expand() should be log(1/x) but it comes back as -log(x)
    # when it is corrected, posify will allow the change to be made:
    eq, rep = posify(1 / x)
    assert log(eq).expand().subs(rep) == -log(x)
    assert str(posify([x, 1 + x])) == "([_x, _x + 1], {_x: x})"
开发者ID:jegerjensen,项目名称:sympy,代码行数:11,代码来源:test_simplify.py


示例2: symbolic_equality

def symbolic_equality(test_expr, target_expr):
    """Test if two expressions are symbolically equivalent.

       Use the sympy 'simplify' function to test if the difference between two
       expressions is symbolically zero. This is known to be impossible in the general
       case, but should work well enough for most cases likely to be used on Isaac.
       A return value of 'False' thus does not necessarily mean the two expressions
       are not equal (sympy assumes complex number variables; so some simlifications
       may not occur).

       Returns True if sympy can determine that the two expressions are equal,
       and returns False if this cannot be determined OR if the two expressions
       are definitely not equal.

        - 'test_expr' should be the untrusted sympy expression to check.
        - 'target_expr' should be the trusted sympy expression to match against.
    """
    print "[SYMBOLIC TEST]"
    # Here we make the assumption that all variables are real and positive to
    # aid the simplification process. Since we do this for numeric checking anyway,
    # it doesn't seem like much of an issue. Removing 'sympy.posify()' below will
    # stop this.
    try:
        if sympy.simplify(sympy.posify(test_expr - target_expr)[0]) == 0:
            print "Symbolic match."
            print "INFO: Adding known pair (%s, %s)" % (target_expr, test_expr)
            KNOWN_PAIRS[(target_expr, test_expr)] = "symbolic"
            return True
        else:
            return False
    except NotImplementedError, e:
        print "%s: %s - Can't check symbolic equality!" % (type(e).__name__, e.message.capitalize())
        return False
开发者ID:ucam-cl-dtg,项目名称:equality-checker,代码行数:33,代码来源:api.py


示例3: test_posify

def test_posify():
    from sympy.abc import x

    assert str(posify(
        x +
        Symbol('p', positive=True) +
        Symbol('n', negative=True))) == '(_x + n + p, {_x: x})'

    eq, rep = posify(1/x)
    assert log(eq).expand().subs(rep) == -log(x)
    assert str(posify([x, 1 + x])) == '([_x, _x + 1], {_x: x})'

    x = symbols('x')
    p = symbols('p', positive=True)
    n = symbols('n', negative=True)
    orig = [x, n, p]
    modified, reps = posify(orig)
    assert str(modified) == '[_x, n, p]'
    assert [w.subs(reps) for w in modified] == orig

    assert str(Integral(posify(1/x + y)[0], (y, 1, 3)).expand()) == \
        'Integral(1/_x, (y, 1, 3)) + Integral(_y, (y, 1, 3))'
    assert str(Sum(posify(1/x**n)[0], (n,1,3)).expand()) == \
        'Sum(_x**(-n), (n, 1, 3))'

    # issue 16438
    k = Symbol('k', finite=True)
    eq, rep = posify(k)
    assert eq.assumptions0 == {'positive': True, 'zero': False, 'imaginary': False,
     'nonpositive': False, 'commutative': True, 'hermitian': True, 'real': True, 'nonzero': True,
     'nonnegative': True, 'negative': False, 'complex': True, 'finite': True, 'infinite': False}
开发者ID:bjodah,项目名称:sympy,代码行数:31,代码来源:test_simplify.py


示例4: test_posify

def test_posify():
    from sympy.abc import x

    assert str(posify(
        x +
        Symbol('p', positive=True) +
        Symbol('n', negative=True))) == '(_x + n + p, {_x: x})'

    # log(1/x).expand() should be log(1/x) but it comes back as -log(x)
    # when it is corrected, posify will allow the change to be made. The
    # force=True option can do so as well when it is implemented.
    eq, rep = posify(1/x)
    assert log(eq).expand().subs(rep) == -log(x)
    assert str(posify([x, 1 + x])) == '([_x, _x + 1], {_x: x})'

    x = symbols('x')
    p = symbols('p', positive=True)
    n = symbols('n', negative=True)
    orig = [x, n, p]
    modified, reps = posify(orig)
    assert str(modified) == '[_x, n, p]'
    assert [w.subs(reps) for w in modified] == orig

    assert str(Integral(posify(1/x + y)[0], (y, 1, 3)).expand()) == \
        'Integral(1/_x, (y, 1, 3)) + Integral(_y, (y, 1, 3))'
    assert str(Sum(posify(1/x**n)[0], (n,1,3)).expand()) == \
        'Sum(_x**(-n), (n, 1, 3))'
开发者ID:LuckyStrikes1090,项目名称:sympy,代码行数:27,代码来源:test_simplify.py


示例5: test_posify

def test_posify():
    from sympy.abc import x

    assert str(posify(x + Symbol("p", positive=True) + Symbol("n", negative=True))) == "(_x + n + p, {_x: x})"

    eq, rep = posify(1 / x)
    assert log(eq).expand().subs(rep) == -log(x)
    assert str(posify([x, 1 + x])) == "([_x, _x + 1], {_x: x})"

    x = symbols("x")
    p = symbols("p", positive=True)
    n = symbols("n", negative=True)
    orig = [x, n, p]
    modified, reps = posify(orig)
    assert str(modified) == "[_x, n, p]"
    assert [w.subs(reps) for w in modified] == orig

    assert (
        str(Integral(posify(1 / x + y)[0], (y, 1, 3)).expand()) == "Integral(1/_x, (y, 1, 3)) + Integral(_y, (y, 1, 3))"
    )
    assert str(Sum(posify(1 / x ** n)[0], (n, 1, 3)).expand()) == "Sum(_x**(-n), (n, 1, 3))"
开发者ID:pabloferz,项目名称:sympy,代码行数:21,代码来源:test_simplify.py


示例6: test_random

def test_random():
    from sympy import posify

    assert posify(x)[0]._random() is not None
开发者ID:Botouls,项目名称:sympy,代码行数:4,代码来源:test_expr.py


示例7: test_posify

def test_posify():
    assert posify(A)[0].is_commutative == False
    for q in (A*B/A, (A*B/A)**2, (A*B)**2, A*B - B*A):
        p = posify(q)
        assert p[0].subs(p[1]) == q
开发者ID:BDGLunde,项目名称:sympy,代码行数:5,代码来源:test_noncommutative.py


示例8: test_random

def test_random():
    from sympy import posify
    assert posify(x)[0]._random() is not None
    assert S('-pi*Abs(1/log(n!)) + 1')._random(2, -2, 0, -1, 0) is None
开发者ID:FireJade,项目名称:sympy,代码行数:4,代码来源:test_expr.py


示例9: __new__

    def __new__(cls, unit_expr=None, cgs_value=None, dimensions=None,
                **assumptions):
        """
        Build a new unit. May be an atomic unit (like a gram) or a combination
        of other units (like g / cm**3). Either way, you can make the unit
        symbol anything.

        Parameters
        ----------
        unit_expr : string or sympy.core.expr.Expr
            The symbolic expression. Symbol("g") for gram.
        cgs_value : float
            This unit's value in cgs. 1.0 for gram.
        dimensions : sympy.core.expr.Expr
            A sympy expression representing the dimensionality of this unit.
            Should just be a sympy.core.mul.Mul object of mass, length, time,
            and temperature objects to various powers. mass for gram.

        """
        # Check for no args
        if not unit_expr:
            unit_expr = sympify(1)

        # if we have a string, parse into an expression
        if isinstance(unit_expr, str):
            unit_expr = parse_expr(unit_expr)

        if not isinstance(unit_expr, Expr):
            raise Exception("Unit representation must be a string or sympy Expr. %s is a %s" % (unit_expr, type(unit_expr)))
        # done with argument checking...

        # sympify, posify, and nsimplify the expr
        unit_expr = sympify(unit_expr)
        p, r = posify(unit_expr)
        unit_expr = p.subs(r)
        unit_expr = nsimplify(unit_expr)

        # see if the unit is atomic.
        is_atomic = False
        if isinstance(unit_expr, Symbol):
            is_atomic = True

        # did they supply cgs_value and dimensions?
        if cgs_value and not dimensions or dimensions and not cgs_value:
            raise Exception("If you provide cgs_vale or dimensions, you must provide both! cgs_value is %s, dimensions is %s." % (cgs_value, dimensions))

        if cgs_value and dimensions:
            # check that cgs_vale is a float or can be converted to one
            try:
                cgs_value = float(cgs_value)
            except ValueError:
                raise ValueError("Please provide a float for the cgs_value kwarg. I got a '%s'." % cgs_value)
            # check that dimensions is valid
            dimensions = verify_dimensions(sympify(dimensions))
            # save the values
            this_cgs_value, this_dimensions = cgs_value, dimensions

        else:  # lookup the unit symbols
            this_cgs_value, this_dimensions = \
                get_unit_data_from_expr(unit_expr)

        # cool trick to get dimensions powers as Rationals
        this_dimensions = nsimplify(this_dimensions)

        # init obj with superclass construct
        obj = Expr.__new__(cls, **assumptions)

        # attach attributes to obj
        obj.expr = unit_expr
        obj.is_atomic = is_atomic
        obj.cgs_value = this_cgs_value
        obj.dimensions = this_dimensions

        # return `obj` so __init__ can handle it.
        return obj
开发者ID:caseywstark,项目名称:dimensionful,代码行数:75,代码来源:units.py


示例10: test_random

def test_random():
    from sympy import posify, lucas
    assert posify(x)[0]._random() is not None
    assert lucas(n)._random(2, -2, 0, -1, 1) is None
开发者ID:Abhityagi16,项目名称:sympy,代码行数:4,代码来源:test_expr.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python sympy.powdenest函数代码示例发布时间:2022-05-27
下一篇:
Python sympy.polylog函数代码示例发布时间: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