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


Python sympy.sqrtdenest函数代码示例

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


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

示例1: test_sqrtdenest

def test_sqrtdenest():
    d = {sqrt(5 + 2 * sqrt(6)): sqrt(2) + sqrt(3),
        sqrt(sqrt(2)): sqrt(sqrt(2)),
        sqrt(5+sqrt(7)): sqrt(5+sqrt(7)),
        sqrt(3+sqrt(5+2*sqrt(7))):
            sqrt(6+3*sqrt(7))/(sqrt(2)*(5+2*sqrt(7))**Rational(1,4)) +
            3*(5+2*sqrt(7))**Rational(1,4)/(sqrt(2)*sqrt(6+3*sqrt(7))),
        sqrt(3+2*sqrt(3)): 3**Rational(1,4)/sqrt(2)+3/(sqrt(2)*3**Rational(1,4))}
    for i in d:
        assert sqrtdenest(i) == d[i] or denester([i])[0] == d[i]

    # this test caused a pattern recognition failure in sqrtdenest
    # nest = sqrt(2) + sqrt(5) - sqrt(7)
    nest = symbols('nest')
    x0, x1, x2, x3, x4, x5, x6 = symbols('x:7')
    l = sqrt(2) + sqrt(5)
    r = sqrt(7) + nest
    s = (l**2 - r**2).expand() + nest**2 # == nest**2
    ok = solve(nest**4 - s**2, nest)[1] # this will change if results order changes
    assert abs((l - r).subs(nest, ok).n()) < 1e-12
    x0 = sqrt(3)
    x2 = root(45*I*x0 - 28, 3)
    x3 = 19/x2
    x4 = x2 + x3
    x5 = -x4 - 14
    x6 = sqrt(-x5)
    ans = -x0*x6/3 + x0*sqrt(-x4 + 28 - 6*sqrt(210)*x6/x5)/3
    assert expand_mul(radsimp(ok) - ans) == 0
    # issue 2554
    eq = sqrt(sqrt(sqrt(2) + 2) + 2)
    assert sqrtdenest(eq) == eq
开发者ID:AlexandruFlorescu,项目名称:sympy,代码行数:31,代码来源:test_sqrtdenest.py

示例2: test_trig

def test_trig():
    arg = FiniteSet(0, *(pi/x for x in (12, 6, 4, 3, 2, 1)))
    arg += FiniteSet(*sum(((pi-x, pi+x, 2*pi-x) for x in arg), ()))
    arg += FiniteSet(*(-x for x in arg))

    def emit(name, func):
        for x in sorted(arg):
            if func(x) != sp.zoo:
                test(name, x, sp.simplify(sp.sqrtdenest(func(x))))
        test(name, S.NaN, S.NaN)

    def aemit(aname, func, domain):
        for x, y in sorted((sp.simplify(sp.sqrtdenest(func(x))), x)
                           for x in arg & domain):
            test(aname, x, y)
        test(aname, S.NaN, S.NaN)

    emit("sin", sp.sin)
    emit("cos", sp.cos)
    emit("tan", sp.tan)
    aemit("asin", sp.sin, Interval(-pi/2, pi/2))
    aemit("acos", sp.cos, Interval(0, pi))
    aemit("atan", sp.tan, Interval(-pi/2, pi/2, True, True))

    for x in sorted(arg & Interval(-pi, pi, True, True)):
        a = sp.simplify(sp.sqrtdenest(sp.sin(x)))
        b = sp.simplify(sp.sqrtdenest(sp.cos(x)))
        f = sp.sqrt(3) if \
            sp.sqrt(3) == abs(sp.simplify(a/b).as_numer_denom()[0]) else 1
        if b:
            test("atan2", sp.simplify(a/abs(b))*f, sp.sign(b)*f, x)
        if a and a != b:
            test("atan2", sp.sign(a)*f, sp.simplify(b/abs(a))*f, x)
    test("atan2", S.NaN, 1, S.NaN)
    test("atan2", 1, S.NaN, S.NaN)
开发者ID:zholos,项目名称:qml,代码行数:35,代码来源:libm.py

示例3: test_issue_2758

def test_issue_2758():
    from sympy.abc import x, y
    z = sqrt(1/(4*sqrt(3) + 7) + 1)
    ans = (sqrt(2) + sqrt(6))/(sqrt(3) + 2)
    assert sqrtdenest(z) == ans
    assert sqrtdenest(1 + z) == 1 + ans
    assert sqrtdenest(Integral(z + 1, (x, 1, 2))) == Integral(1 + ans, (x, 1, 2))
    assert sqrtdenest(x + sqrt(y)) == x + sqrt(y)
开发者ID:101man,项目名称:sympy,代码行数:8,代码来源:test_sqrtdenest.py

示例4: test_sqrtdenest4

def test_sqrtdenest4():
    # see Denest_en.pdf in http://code.google.com/p/sympy/issues/detail?id=93
    z = sqrt(8 - r2*sqrt(5 - r5) - sqrt(3)*(1 + r5))
    z1 = sqrtdenest(z)
    c = sqrt(-r5 + 5)
    z1 = ((-r15*c - r3*c + c + r5*c - r6 - r2 + r10 + sqrt(30))/4).expand()
    assert sqrtdenest(z) == z1

    z= sqrt(2*r2*sqrt(r2 + 2) + 5*r2 + 4*sqrt(r2 + 2) + 8)
    assert sqrtdenest(z) == r2 + sqrt(r2 + 2) + 2

    w = 2 + r2 + r3 + (1 + r3)*sqrt(2 + r2 + 5*r3)
    z = sqrt((w**2).expand())
    assert sqrtdenest(z) == w.expand()
开发者ID:greensnake,项目名称:sympy,代码行数:14,代码来源:test_sqrtdenest.py

示例5: test_sqrtdenest4

def test_sqrtdenest4():
    # see Denest_en.pdf in https://github.com/sympy/sympy/issues/3192
    z = sqrt(8 - r2*sqrt(5 - r5) - sqrt(3)*(1 + r5))
    z1 = sqrtdenest(z)
    c = sqrt(-r5 + 5)
    z1 = ((-r15*c - r3*c + c + r5*c - r6 - r2 + r10 + sqrt(30))/4).expand()
    assert sqrtdenest(z) == z1

    z = sqrt(2*r2*sqrt(r2 + 2) + 5*r2 + 4*sqrt(r2 + 2) + 8)
    assert sqrtdenest(z) == r2 + sqrt(r2 + 2) + 2

    w = 2 + r2 + r3 + (1 + r3)*sqrt(2 + r2 + 5*r3)
    z = sqrt((w**2).expand())
    assert sqrtdenest(z) == w.expand()
开发者ID:A-turing-machine,项目名称:sympy,代码行数:14,代码来源:test_sqrtdenest.py

示例6: test_sqrtdenest_fail

def test_sqrtdenest_fail():
    # see Denest_en.pdf in http://code.google.com/p/sympy/issues/detail?id=93
    # z = 4*sin(pi/60)
    z = sqrt(8 - r2*sqrt(5 - r5) - sqrt(3)*(1 + r5))
    # z can be denested to an expression with depth 2; here are two forms
    # (-sqrt(6) - r2 + r10 + sqrt(30))/4 - sqrt(5+r5 -5*r3/2 - sqrt(15)/2)
    # r2/4*(-r3 - 1 + r5 + sqrt(15)) - (r3-1)*sqrt(5+r5)/2
    z1 = sqrtdenest(z)
    assert sqrt_depth(z1) == 2
开发者ID:ENuge,项目名称:sympy,代码行数:9,代码来源:test_sqrtdenest.py

示例7: test_sqrtdenest

def test_sqrtdenest():
    d = {sqrt(5 + 2 * sqrt(6)): sqrt(2) + sqrt(3),
        sqrt(sqrt(2)): sqrt(sqrt(2)),
        sqrt(5+sqrt(7)): sqrt(5+sqrt(7)),
        sqrt(3+sqrt(5+2*sqrt(7))):
            sqrt(6+3*sqrt(7))/(sqrt(2)*(5+2*sqrt(7))**Rational(1,4)) +
            3*(5+2*sqrt(7))**Rational(1,4)/(sqrt(2)*sqrt(6+3*sqrt(7))),
        sqrt(3+2*sqrt(3)): 3**Rational(1,4)/sqrt(2)+3/(sqrt(2)*3**Rational(1,4))}
    for i in d:
        assert sqrtdenest(i) == d[i] or denester([i])[0] == d[i]
开发者ID:101man,项目名称:sympy,代码行数:10,代码来源:test_sqrtdenest.py

示例8: test_sqrtdenest

def test_sqrtdenest():
    d = {sqrt(5 + 2 * r6): r2 + r3,
        sqrt(5. + 2 * r6): sqrt(5. + 2 * r6),
        sqrt(5. + 4*sqrt(5 + 2 * r6)): sqrt(5.0 + 4*r2 + 4*r3),
        sqrt(r2): sqrt(r2),
        sqrt(5 + r7): sqrt(5 + r7),
        sqrt(3 + sqrt(5 + 2*r7)):
            3*r2*(5 + 2*r7)**(S(1)/4)/(2*sqrt(6 + 3*r7)) +
            r2*sqrt(6 + 3*r7)/(2*(5 + 2*r7)**(S(1)/4)),
        sqrt(3 + 2*r3): 3**(S(3)/4)*(r6/2 + 3*r2/2)/3}
    for i in d:
        assert sqrtdenest(i) == d[i]
开发者ID:greensnake,项目名称:sympy,代码行数:12,代码来源:test_sqrtdenest.py

示例9: simplifier_racines

def simplifier_racines(expression):
    try:
        if getattr(expression, "is_Pow", False):
            return sqrtdenest(expression)
        elif getattr(expression, "is_Mul", False):
            return reduce(lambda x,y:x*y, [simplifier_racines(fact) for fact in expression.args], 1)
        elif getattr(expression, "is_Add", False):
            return reduce(lambda x,y:x+y, [simplifier_racines(term) for term in expression.args], 0)
        return expression
    except TypeError:
        if param.debug:
            print "Warning: error occured during expression denesting:", expression
        return expression
开发者ID:jpg32,项目名称:geophar,代码行数:13,代码来源:sympy_functions.py

示例10: test_sqrtdenest_four_terms

def test_sqrtdenest_four_terms():
    assert sqrtdenest(sqrt(-4*sqrt(14) - 2*r6 + 4*sqrt(21) + 33)) == \
      -r2 + r3 + 2*r7
    assert sqrtdenest(sqrt(-28*r7 - 14*r5 + 4*sqrt(35) + 82)) == \
      -7 + r5 + 2*r7
    assert sqrtdenest(sqrt(6*r2/11 + 2*sqrt(22)/11 + 6*sqrt(11)/11 + 2)) == \
      sqrt(11)*(r2 + 3 + sqrt(11))/11
    assert sqrtdenest(sqrt(468*r3 + 3024*r2 + 2912*r6 + 19735)) == \
      9*r3 + 26 + 56*r6
    z = sqrt(-490*r3 - 98*sqrt(115) - 98*sqrt(345) - 2107)
    assert sqrtdenest(z) == sqrt(-1)*(7*r5 + 7*sqrt(15) + 7*sqrt(23))
    z = sqrt(-4*sqrt(14) - 2*r6 + 4*sqrt(21) + 34)
    assert sqrtdenest(z) == z
    assert sqrtdenest(sqrt(-8*r2 - 2*r5 + 18)) == -r10 + 1 + r2 + r5
    assert sqrtdenest(sqrt(8*r2 + 2*r5 - 18)) == \
        sqrt(-1)*(-r10 + 1 + r2 + r5)
    assert sqrtdenest(sqrt(8*r2/3 + 14*r5/3 + S(154)/9)) == \
        -r10/3 + r2 + r5 + 3
    assert sqrtdenest(sqrt(sqrt(2*r6 + 5) + sqrt(2*r7 + 8))) == \
      sqrt(1 + r2 + r3 + r7)
    assert _sqrtdenest34(sqrt(4*sqrt(15) + 8*r5 + 12*r3 + 24)) == \
      1 + r3 + r5 + sqrt(15)
开发者ID:Anxuiz,项目名称:sympy,代码行数:22,代码来源:test_sqrtdenest.py

示例11: test_issue_2758

def test_issue_2758():
    from sympy.abc import x, y
    z = sqrt(1/(4*r3 + 7) + 1)
    ans = (r2 + r6)/(r3 + 2)
    assert sqrtdenest(z) == ans
    assert sqrtdenest(1 + z) == 1 + ans
    assert sqrtdenest(Integral(z + 1, (x, 1, 2))) == \
        Integral(1 + ans, (x, 1, 2))
    assert sqrtdenest(x + sqrt(y)) == x + sqrt(y)
    ans = (r2 + r6)/(r3 + 2)
    assert sqrtdenest(z) == ans
    assert sqrtdenest(1 + z) == 1 + ans
    assert sqrtdenest(Integral(z + 1, (x, 1, 2))) == \
        Integral(1 + ans, (x, 1, 2))
    assert sqrtdenest(x + sqrt(y)) == x + sqrt(y)
开发者ID:greensnake,项目名称:sympy,代码行数:15,代码来源:test_sqrtdenest.py

示例12: simplifier_racines

def simplifier_racines(expression):
    try:
        if getattr(expression, "is_Pow", False):
            return sqrtdenest(expression)
        elif getattr(expression, "is_Mul", False):
            return reduce(lambda x,y:x*y, [simplifier_racines(fact) for fact in expression.args], 1)
        elif getattr(expression, "is_Add", False):
            return reduce(lambda x,y:x+y, [simplifier_racines(term) for term in expression.args], 0)
        return expression
    except Exception:
        # sqrtdenest() renvoie assez souvent des erreurs.
        if param.debug:
            print("Warning: error occured during expression denesting:", expression)
        return expression
开发者ID:wxgeo,项目名称:geophar,代码行数:14,代码来源:sympy_functions.py

示例13: test_sqrtdenest3

def test_sqrtdenest3():
    z = sqrt(13 - 2*r10 + 2*r2*sqrt(-2*r10 + 11))
    assert sqrtdenest(z) == -1 + r2 + r10
    assert sqrtdenest(z, max_iter=1) == -1 + sqrt(2) + sqrt(10)
    n = sqrt(2*r6/7 + 2*r7/7 + 2*sqrt(42)/7 + 2)
    d = sqrt(16 - 2*r29 + 2*sqrt(55 - 10*r29))
    assert sqrtdenest(n/d).equals(
        r7*(1 + r6 + r7)/(7*(sqrt(-2*r29 + 11) + r5)))
    z = sqrt(sqrt(r2 + 2) + 2)
    assert sqrtdenest(z) == z
    assert sqrtdenest(sqrt(-2*r10 + 4*r2*sqrt(-2*r10 + 11) + 20)) == \
        sqrt(-2*r10 - 4*r2 + 8*r5 + 20)
    assert sqrtdenest(sqrt((112 + 70*r2) + (46 + 34*r2)*r5)) == \
        r10 + 5 + 4*r2 + 3*r5
    z = sqrt(5 + sqrt(2*r6 + 5)*sqrt(-2*r29 + 2*sqrt(-10*r29 + 55) + 16))
    r = sqrt(-2*r29 + 11)
    assert sqrtdenest(z) == sqrt(r2*r + r3*r + r10 + r15 + 5)
开发者ID:greensnake,项目名称:sympy,代码行数:17,代码来源:test_sqrtdenest.py

示例14: test_sqrt_symbolic_denest

def test_sqrt_symbolic_denest():
    x = Symbol('x')
    z = sqrt(((1 + sqrt(sqrt(2 + x) + 3))**2).expand())
    assert sqrtdenest(z) == sqrt((1 + sqrt(sqrt(2 + x) + 3))**2)
    z = sqrt(((1 + sqrt(sqrt(2 + cos(1)) + 3))**2).expand())
    assert sqrtdenest(z) == 1 + sqrt(sqrt(2 + cos(1)) + 3)
    z = ((1 + cos(2))**4 + 1).expand()
    assert sqrtdenest(z) == z
    z = sqrt(((1 + sqrt(sqrt(2 + cos(3*x)) + 3))**2 + 1).expand())
    assert sqrtdenest(z) == z
    c = cos(3)
    c2 = c**2
    assert sqrtdenest(sqrt(2*sqrt(1 + r3)*c + c2 + 1 + r3*c2)) == \
        -1 - sqrt(1 + r3)*c
    ra = sqrt(1 + r3)
    z = sqrt(20*ra*sqrt(3 + 3*r3) + 12*r3*ra*sqrt(3 + 3*r3) + 64*r3 + 112)
    assert sqrtdenest(z) == z
开发者ID:greensnake,项目名称:sympy,代码行数:17,代码来源:test_sqrtdenest.py

示例15: emit

 def emit(name, func):
     for x in sorted(arg):
         if func(x) != sp.zoo:
             test(name, x, sp.simplify(sp.sqrtdenest(func(x))))
     test(name, S.NaN, S.NaN)
开发者ID:zholos,项目名称:qml,代码行数:5,代码来源:libm.py


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