当前位置: 首页>>代码示例>>Python>>正文


Python sympy.refine函数代码示例

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


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

示例1: test_exp_values

def test_exp_values():
    k = Symbol('k', integer=True)

    assert exp(nan) == nan

    assert exp(oo) == oo
    assert exp(-oo) == 0

    assert exp(0) == 1
    assert exp(1) == E
    assert exp(-1 + x).as_base_exp() == (S.Exp1, x - 1)
    assert exp(1 + x).as_base_exp() == (S.Exp1, x + 1)

    assert exp(pi*I/2) == I
    assert exp(pi*I) == -1
    assert exp(3*pi*I/2) == -I
    assert exp(2*pi*I) == 1

    assert refine(exp(pi*I*2*k)) == 1
    assert refine(exp(pi*I*2*(k + Rational(1, 2)))) == -1
    assert refine(exp(pi*I*2*(k + Rational(1, 4)))) == I
    assert refine(exp(pi*I*2*(k + Rational(3, 4)))) == -I

    assert exp(log(x)) == x
    assert exp(2*log(x)) == x**2
    assert exp(pi*log(x)) == x**pi

    assert exp(17*log(x) + E*log(y)) == x**17 * y**E

    assert exp(x*log(x)) != x**x
    assert exp(sin(x)*log(x)) != x

    assert exp(3*log(x) + oo*x) == exp(oo*x) * x**3
    assert exp(4*log(x)*log(y) + 3*log(x)) == x**3 * exp(4*log(x)*log(y))
开发者ID:asmeurer,项目名称:sympy,代码行数:34,代码来源:test_exponential.py

示例2: test_pow2

def test_pow2():
    # powers of (-1)
    assert refine((-1)**(x + y), Q.even(x)) == (-1)**y
    assert refine((-1)**(x + y + z), Q.odd(x) & Q.odd(z)) == (-1)**y
    assert refine((-1)**(x + y + 1), Q.odd(x)) == (-1)**y
    assert refine((-1)**(x + y + 2), Q.odd(x)) == (-1)**(y + 1)
    assert refine((-1)**(x + 3)) == (-1)**(x + 1)
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:7,代码来源:test_refine.py

示例3: test_pow4

def test_pow4():
    assert refine((-1)**((-1)**x/2 - 7*S.Half), Q.integer(x)) == (-1)**(x + 1)
    assert refine((-1)**((-1)**x/2 - 9*S.Half), Q.integer(x)) == (-1)**x

    # powers of Abs
    assert refine(Abs(x)**2, Q.real(x)) == x**2
    assert refine(Abs(x)**3, Q.real(x)) == Abs(x)**3
    assert refine(Abs(x)**2) == Abs(x)**2
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:8,代码来源:test_refine.py

示例4: test_refine_issue_12724

def test_refine_issue_12724():
    expr1 = refine(Abs(x * y), Q.positive(x))
    expr2 = refine(Abs(x * y * z), Q.positive(x))
    assert expr1 == x * Abs(y)
    assert expr2 == x * Abs(y * z)
    y1 = Symbol('y1', real = True)
    expr3 = refine(Abs(x * y1**2 * z), Q.positive(x))
    assert expr3 == x * y1**2 * Abs(z)
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:8,代码来源:test_refine.py

示例5: test_Abs

def test_Abs():
    x = Symbol('x', positive=True)
    assert Abs(x) == x
    assert 1 + Abs(x) == 1 + x
    x = Symbol('x', negative=True)
    assert Abs(x) == -x
    assert 1 + Abs(x) == 1 - x
    x = Symbol('x')
    assert refine(Abs(x**2)) != x**2
    x = Symbol('x', real=True)
    assert refine(Abs(x**2)) == x**2
开发者ID:preetskhalsa97,项目名称:sympy,代码行数:11,代码来源:test_refine.py

示例6: test_issue_8545

def test_issue_8545():
    from sympy import refine
    eq = 1 - x - abs(1 - x)
    ans = And(Lt(1, x), Lt(x, oo))
    assert reduce_abs_inequality(eq, '<', x) == ans
    eq = 1 - x - sqrt((1 - x)**2)
    assert reduce_inequalities(refine(eq) < 0) == ans
开发者ID:GolimarOurHero,项目名称:sympy,代码行数:7,代码来源:test_inequalities.py

示例7: test_atan2

def test_atan2():
    assert refine(atan2(y, x), Q.real(y) & Q.positive(x)) == atan(y/x)
    assert refine(atan2(y, x), Q.negative(y) & Q.positive(x)) == atan(y/x)
    assert refine(atan2(y, x), Q.negative(y) & Q.negative(x)) == atan(y/x) - pi
    assert refine(atan2(y, x), Q.positive(y) & Q.negative(x)) == atan(y/x) + pi
    assert refine(atan2(y, x), Q.zero(y) & Q.negative(x)) == pi
    assert refine(atan2(y, x), Q.positive(y) & Q.zero(x)) == pi/2
    assert refine(atan2(y, x), Q.negative(y) & Q.zero(x)) == -pi/2
    assert refine(atan2(y, x), Q.zero(y) & Q.zero(x)) == nan
开发者ID:preetskhalsa97,项目名称:sympy,代码行数:9,代码来源:test_refine.py

示例8: test_eval_refine

def test_eval_refine():
    from sympy.core.expr import Expr
    class MockExpr(Expr):
        def _eval_refine(self):
            return True

    mock_obj = MockExpr()
    assert refine(mock_obj)
开发者ID:preetskhalsa97,项目名称:sympy,代码行数:8,代码来源:test_refine.py

示例9: test_atan2

def test_atan2():
    assert atan2.nargs == FiniteSet(2)
    assert atan2(0, 0) == S.NaN
    assert atan2(0, 1) == 0
    assert atan2(1, 1) == pi/4
    assert atan2(1, 0) == pi/2
    assert atan2(1, -1) == 3*pi/4
    assert atan2(0, -1) == pi
    assert atan2(-1, -1) == -3*pi/4
    assert atan2(-1, 0) == -pi/2
    assert atan2(-1, 1) == -pi/4
    i = symbols('i', imaginary=True)
    r = symbols('r', real=True)
    eq = atan2(r, i)
    ans = -I*log((i + I*r)/sqrt(i**2 + r**2))
    reps = ((r, 2), (i, I))
    assert eq.subs(reps) == ans.subs(reps)

    x = Symbol('x', negative=True)
    y = Symbol('y', negative=True)
    assert atan2(y, x) == atan(y/x) - pi
    y = Symbol('y', nonnegative=True)
    assert atan2(y, x) == atan(y/x) + pi
    y = Symbol('y')
    assert atan2(y, x) == atan2(y, x, evaluate=False)

    u = Symbol("u", positive=True)
    assert atan2(0, u) == 0
    u = Symbol("u", negative=True)
    assert atan2(0, u) == pi

    assert atan2(y, oo) ==  0
    assert atan2(y, -oo)==  2*pi*Heaviside(re(y)) - pi

    assert atan2(y, x).rewrite(log) == -I*log((x + I*y)/sqrt(x**2 + y**2))
    assert atan2(y, x).rewrite(atan) == 2*atan(y/(x + sqrt(x**2 + y**2)))

    ex = atan2(y, x) - arg(x + I*y)
    assert ex.subs({x:2, y:3}).rewrite(arg) == 0
    assert ex.subs({x:2, y:3*I}).rewrite(arg) == -pi - I*log(sqrt(5)*I/5)
    assert ex.subs({x:2*I, y:3}).rewrite(arg) == -pi/2 - I*log(sqrt(5)*I)
    assert ex.subs({x:2*I, y:3*I}).rewrite(arg) == -pi + atan(2/S(3)) + atan(3/S(2))
    i = symbols('i', imaginary=True)
    r = symbols('r', real=True)
    e = atan2(i, r)
    rewrite = e.rewrite(arg)
    reps = {i: I, r: -2}
    assert rewrite == -I*log(abs(I*i + r)/sqrt(abs(i**2 + r**2))) + arg((I*i + r)/sqrt(i**2 + r**2))
    assert refine((e - rewrite).subs(reps)).equals(0)

    assert conjugate(atan2(x, y)) == atan2(conjugate(x), conjugate(y))

    assert diff(atan2(y, x), x) == -y/(x**2 + y**2)
    assert diff(atan2(y, x), y) == x/(x**2 + y**2)

    assert simplify(diff(atan2(y, x).rewrite(log), x)) == -y/(x**2 + y**2)
    assert simplify(diff(atan2(y, x).rewrite(log), y)) ==  x/(x**2 + y**2)
开发者ID:Davidjohnwilson,项目名称:sympy,代码行数:57,代码来源:test_trigonometric.py

示例10: test_issue_8514

def test_issue_8514():
    from sympy import simplify, refine

    a, b, c, = symbols("a b c", positive=True)
    t = symbols("t", positive=True)
    ft = simplify(inverse_laplace_transform(1 / (a * s ** 2 + b * s + c), s, t))
    assert ft == (
        (
            exp(
                t
                * (exp(I * atan2(0, -4 * a * c + b ** 2) / 2) - exp(-I * atan2(0, -4 * a * c + b ** 2) / 2))
                * sqrt(refine(Abs(4 * a * c - b ** 2)))
                / (4 * a)
            )
            * exp(t * cos(atan2(0, -4 * a * c + b ** 2) / 2) * sqrt(refine(Abs(4 * a * c - b ** 2))) / a)
            + I * sin(t * sin(atan2(0, -4 * a * c + b ** 2) / 2) * sqrt(refine(Abs(4 * a * c - b ** 2))) / (2 * a))
            - cos(t * sin(atan2(0, -4 * a * c + b ** 2) / 2) * sqrt(refine(Abs(4 * a * c - b ** 2))) / (2 * a))
        )
        * exp(-t * (b + cos(atan2(0, -4 * a * c + b ** 2) / 2) * sqrt(refine(Abs(4 * a * c - b ** 2)))) / (2 * a))
        / sqrt(-4 * a * c + b ** 2)
    )
开发者ID:whimsy-Pan,项目名称:sympy,代码行数:21,代码来源:test_transforms.py

示例11: test_Abs

def test_Abs():
    assert refine(Abs(x), Q.positive(x)) == x
    assert refine(1 + Abs(x), Q.positive(x)) == 1 + x
    assert refine(Abs(x), Q.negative(x)) == -x
    assert refine(1 + Abs(x), Q.negative(x)) == 1 - x

    assert refine(Abs(x ** 2)) != x ** 2
    assert refine(Abs(x ** 2), Q.real(x)) == x ** 2
开发者ID:neitzke,项目名称:sympy,代码行数:8,代码来源:test_refine.py

示例12: test_abs

def test_abs():
    x = symbols('x')
    assert refine(abs(x), Assume(x, Q.positive)) == x
    assert refine(1+abs(x), Assume(x, Q.positive)) == 1+x
    assert refine(abs(x), Assume(x, Q.negative)) == -x
    assert refine(1+abs(x), Assume(x, Q.negative)) == 1-x

    assert refine(abs(x**2)) != x**2
    assert refine(abs(x**2), Assume(x, Q.real)) == x**2
开发者ID:Praveen-Ramanujam,项目名称:MobRAVE,代码行数:9,代码来源:test_refine.py

示例13: test_action_verbs

def test_action_verbs():
    assert nsimplify((1/(exp(3*pi*x/5)+1))) == (1/(exp(3*pi*x/5)+1)).nsimplify()
    assert ratsimp(1/x + 1/y) == (1/x + 1/y).ratsimp()
    assert trigsimp(log(x), deep=True) == (log(x)).trigsimp(deep = True)
    assert radsimp(1/(2+sqrt(2))) == (1/(2+sqrt(2))).radsimp()
    assert powsimp(x**y*x**z*y**z, combine='all') == (x**y*x**z*y**z).powsimp(combine='all')
    assert simplify(x**y*x**z*y**z) == (x**y*x**z*y**z).simplify()
    assert together(1/x + 1/y) == (1/x + 1/y).together()
    assert separate((x*(y*z)**3)**2) == ((x*(y*z)**3)**2).separate()
    assert collect(a*x**2 + b*x**2 + a*x - b*x + c, x) == (a*x**2 + b*x**2 + a*x - b*x + c).collect(x)
    assert apart(y/(y+2)/(y+1), y) == (y/(y+2)/(y+1)).apart(y)
    assert combsimp(y/(x+2)/(x+1)) == (y/(x+2)/(x+1)).combsimp()
    assert factor(x**2+5*x+6) == (x**2+5*x+6).factor()
    assert refine(sqrt(x**2)) == sqrt(x**2).refine()
    assert cancel((x**2+5*x+6)/(x+2)) == ((x**2+5*x+6)/(x+2)).cancel()
开发者ID:goodok,项目名称:sympy,代码行数:15,代码来源:test_expr.py

示例14: test_recursive

def test_recursive():
    from sympy import symbols, refine
    a, b, c = symbols('a b c', positive=True)
    r = exp(-(x - a)**2)*exp(-(x - b)**2)
    e = integrate(r, (x, 0, oo), meijerg=True)
    assert simplify(e.expand()) == (
        sqrt(2)*sqrt(pi)*(
        (erf(sqrt(2)*(a + b)/2) + 1)*exp(-a**2/2 + a*b - b**2/2))/4)
    e = integrate(exp(-(x - a)**2)*exp(-(x - b)**2)*exp(c*x), (x, 0, oo), meijerg=True)
    assert simplify(e) == (
        sqrt(2)*sqrt(pi)*(erf(sqrt(2)*(2*a + 2*b + c)/4) + 1)*exp(-a**2 - b**2
        + (2*a + 2*b + c)**2/8)/4)
    assert simplify(integrate(exp(-(x - a - b - c)**2), (x, 0, oo), meijerg=True)) == \
        sqrt(pi)/2*(1 + erf(a + b + c))
    assert simplify(refine(integrate(exp(-(x + a + b + c)**2), (x, 0, oo), meijerg=True))) == \
        sqrt(pi)/2*(1 - erf(a + b + c))
开发者ID:Davidjohnwilson,项目名称:sympy,代码行数:16,代码来源:test_meijerint.py

示例15: test_make_integral_01

def test_make_integral_01():
    integral, params = _make_integral_01()
    intgr = integral.doit()
    u0, k, l, t = params

    # eq: k == l, neq: k != l
    ref_eq = k*u0*t
    ref_neq = -k*u0/(k-l)*(exp(t*(l-k)) - 1)

    refined_eq = integral.subs({l: k}).doit()
    assert (refined_eq - ref_eq).simplify() == 0

    eq_assumption = sympy.Q.is_true(sympy.Eq(l, k))
    refined_neq = sympy.refine(intgr, ~eq_assumption).simplify()
    print(refined_neq)
    print(ref_neq)
    assert (refined_neq - ref_neq).simplify() == 0
开发者ID:dibus2,项目名称:sympy_benchmarks,代码行数:17,代码来源:test_integrate.py


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