def YlmTensor(ell, m, OrthogonalRightHandedBasis=DefaultOrthogonalRightHandedBasis):
    if(ell<0 or abs(m)>ell):
        raise ValueError("YlmTensor({0},{1}) is undefined.".format(ell,m))
    from sympy import prod
    xHat, yHat, zHat = OrthogonalRightHandedBasis
    if(m<0):
        mVec = Tensor(SymmetricTensorProduct(xHat), SymmetricTensorProduct(yHat,coefficient=-sympy.I))
        #mVec = VectorFactory('mBarVec', [1,-sympy.I,0])(t)
    else:
        mVec = Tensor(SymmetricTensorProduct(xHat), SymmetricTensorProduct(yHat,coefficient=sympy.I))
        #mVec = VectorFactory('mVec', [1,sympy.I,0])(t)
    def TensorPart(ell,m,j):
        return sympy.prod((mVec,)*m) * SymmetricTensorProduct(*((zHat,)*(ell-2*j-m))) \
            * sympy.prod([sum([SymmetricTensorProduct(vHat, vHat) for vHat in OrthogonalRightHandedBasis]) for i in range(j)])
    if(m<0):
        Y = sum([TensorPart(ell,-m,j) * (C(ell,-m) * a(ell,-m,j))
                 for j in range(floor(frac(ell+m,2))+1) ]) * (-1)**(-m)
    else:
        Y = sum([TensorPart(ell,m,j) * (C(ell,m) * a(ell,m,j))
                 for j in range(floor(frac(ell-m,2))+1) ])
    try:
        Y.compress()
    except AttributeError:
        pass
    return Y
示例#2
0
def mclaren_10():
    degree = 14

    r, s = [sqrt((5 - pm_ * sqrt(5)) / 10) for pm_ in [+1, -1]]
    B = frac(125, 10080)
    C = frac(143, 10080)

    # The roots of
    #
    # 2556125 y^6 - 5112250 y^5 + 3578575 y^4 - 1043900 y^3
    #     + 115115 y^2 - 3562 y + 9 =0
    #
    # in decreasing order.
    y = [
        0.8318603575087328951583062165711519728388,
        0.5607526046766541293084396308069013490725,
        0.4118893592345073860321480490176804941547,
        0.1479981814629634692260834719469411619893,
        0.04473134613410273910111648293922113227845,
        0.002768150983039381173906148718103889666260,
    ]
    z = numpy.sqrt(y)

    u = (numpy.array(
        [z[3] - z[2], z[1] - z[4], z[5] - z[1], z[2] - z[5], z[4] - z[3]]) /
         2 / s)
    v = (numpy.array(
        [z[4] + z[5], z[5] + z[3], z[2] + z[4], z[3] + z[1], z[1] + z[2]]) /
         2 / s)
    w = (numpy.array(
        [z[0] + z[1], z[0] + z[2], z[0] + z[3], z[0] + z[4], z[0] + z[5]]) /
         2 / s)

    data = [
        (B, pm_roll([r, s, 0])),
        #
        (C, numpy.column_stack([+u, +v, +w])),
        (C, numpy.column_stack([+u, -v, -w])),
        (C, numpy.column_stack([-u, -v, +w])),
        (C, numpy.column_stack([-u, +v, -w])),
        #
        (C, numpy.column_stack([+v, +w, +u])),
        (C, numpy.column_stack([+v, -w, -u])),
        (C, numpy.column_stack([-v, -w, +u])),
        (C, numpy.column_stack([-v, +w, -u])),
        #
        (C, numpy.column_stack([+w, +u, +v])),
        (C, numpy.column_stack([+w, -u, -v])),
        (C, numpy.column_stack([-w, -u, +v])),
        (C, numpy.column_stack([-w, +u, -v])),
    ]

    points, weights = untangle(data)
    points = numpy.ascontiguousarray(points.T)
    return U3Scheme("McLaren 10", {"plain": numpy.vstack([weights, points])},
                    degree, source)
示例#3
0
def stroud_1966_a(n):
    r = sqrt(frac(5 * n + 4, 30))
    s = sqrt(frac(5 * n + 4, 15 * n - 12))
    data = [
        (frac(40, (5 * n + 4) ** 2), fsd(n, (r, 1))),
        (frac(5 * n - 4, (5 * n + 4)) ** 2 / 2 ** n, pm(n * [s])),
    ]

    points, weights = untangle(data)
    return CnScheme("Stroud 1966a", n, weights, points, 5, _source, 1.600e-14)
示例#4
0
def hammer_stroud_2_2():
    alpha = sqrt(frac(3, 5))
    data = [
        (frac(64, 81), [[0, 0]]),
        (frac(40, 81), fsd(2, (alpha, 1))),
        (frac(25, 81), pm([alpha, alpha])),
    ]
    points, weights = untangle(data)
    weights /= 4
    return C2Scheme("Hammer-Stroud 2-2", weights, points, 5, source)
示例#5
0
def hammer_stroud_3_2():
    xi1, xi2 = [sqrt(frac(3, 287) * (38 - i * sqrt(583))) for i in [+1, -1]]
    data = [
        (frac(98, 405), fsd(2, (sqrt(frac(6, 7)), 1))),
        (0.5205929166673945, pm([xi1, xi1])),
        (0.2374317746906302, pm([xi2, xi2])),
    ]
    points, weights = untangle(data)
    weights /= 4
    return C2Scheme("Hammer-Stroud 3-2", weights, points, 7, source)
示例#6
0
文件: _tyler.py 项目: whzup/quadpy
def tyler_2():
    data = [
        (-frac(62, 45), z()),
        (frac(16, 45), fs_r00(frac(1, 2))),
        (frac(1, 45), fs_r00(1)),
        (frac(1, 72), pm_rrr(1)),
    ]
    points, weights = untangle(data)
    weights *= 8
    return HexahedronScheme("Tyler 2", weights, points, 5, citation)
示例#7
0
def walkington_3(d):
    degree = 3
    data = [
        (frac(-((d + 1)**3), 4 * factorial(d + 2)), _c(d, frac)),
        (frac(+((d + 3)**3), 4 * factorial(d + 3)), _xi1(d, frac(1, (d + 3)))),
    ]
    points, weights = untangle(data)
    # normalize weights
    weights /= numpy.sum(weights)
    return TnScheme("Walkington 3", d, weights, points, degree, source)
示例#8
0
def hammer_stroud_2_2():
    alpha = sqrt(frac(3, 5))
    data = [
        (frac(64, 81), z(2)),
        (frac(40, 81), fsd(2, (alpha, 1))),
        (frac(25, 81), pm(2, alpha)),
    ]
    points, weights = untangle(data)
    return QuadrilateralScheme("Hammer-Stroud 2-2", weights, points, 5,
                               citation)
示例#9
0
def hammer_stroud_3_2():
    xi1, xi2 = [sqrt(frac(3, 287) * (38 - i * sqrt(583))) for i in [+1, -1]]
    data = [
        (frac(98, 405), fsd(2, (sqrt(frac(6, 7)), 1))),
        (0.5205929166673945, pm(2, xi1)),
        (0.2374317746906302, pm(2, xi2)),
    ]
    points, weights = untangle(data)
    return QuadrilateralScheme("Hammer-Stroud 3-2", weights, points, 7,
                               citation)
示例#10
0
def hammer_stroud_2n(n):
    r = sqrt(frac(3, 5))
    data = [
        (frac(25 * n**2 - 115 * n + 162, 162), z(n)),
        (frac(70 - 25 * n, 162), fsd(n, (r, 1))),
        (frac(25, 324), fsd(n, (r, 2))),
    ]
    points, weights = untangle(data)
    weights *= 2**n
    return NCubeScheme("Hammer-Stroud 2n", n, weights, points, 5, _citation)
示例#11
0
def albrecht_collatz_3():
    r = sqrt(frac(7, 15))
    s, t = [sqrt((7 + i * sqrt(24)) / 15) for i in [+1, -1]]
    weights, points = concat(
        zero(frac(2, 7)),
        pm([frac(25, 168), r, r], [frac(5, 48), +s, -t],
           [frac(5, 48), +t, -s]),
    )
    return C2Scheme("Albrecht-Collatz 3", weights, points, 5, source,
                    4.442e-16)
示例#12
0
def dunavant_03():
    weights, points = concat(
        symm_r0([frac(98, 405), sqrt(frac(6, 7))]),
        symm_s(
            [0.237431774690630, 0.805979782918599],
            [0.520592916667394, 0.380554433208316],
        ),
    )
    weights /= 4
    return C2Scheme("Dunavant 3", weights, points, 7, source)
示例#13
0
def mustard_lyness_blatt(n):
    r = sqrt(frac(2, 5))
    d = {
        "0": [[frac(8 - 5 * n, 9)]],
        "a0": [[frac(5, 18)], [r]],
        "a": [[frac(1, 9 * 2**n)], [1]],
    }
    points, weights = expand_symmetries(d, n)
    return CnScheme("Mustard-Lyness-Blatt", n, weights, points, 5, _source,
                    6.312e-14)
示例#14
0
def hillion_10():
    lambda1, lambda2 = [(16 + i * 2 * sqrt(14)) / 25 for i in [+1, -1]]
    w1, w2 = [(161 + i * 17 * sqrt(14)) / 2688 for i in [+1, -1]]
    weights, points = concat(
        mirror([w2, lambda1, 0], [w1, 0, lambda2]),
        ([frac(25, 96)], [[frac(2, 5), frac(2, 5),
                           frac(1, 5)]]),
    )
    weights *= 2
    return TriangleScheme("Hillion 10", weights, points, 3, citation)
示例#15
0
def phillips():
    c = 3 * sqrt(385)
    r, s = [sqrt((105 + i * c) / 140) for i in [+1, -1]]
    t = sqrt(frac(3, 5))

    B1, B2 = [(77 - i * c) / 891 for i in [+1, -1]]
    B3 = frac(25, 324)

    weights, points = concat(symm_r0([B1, r], [B2, s]), pm2([B3, t, t]))
    return C2Scheme("Phillips", weights, points, 7, source)
示例#16
0
def hammer_stroud_6_3():
    alpha = sqrt(frac(6, 7))
    data = [
        (frac(1078, 3645), fsd(3, (alpha, 1))),
        (frac(343, 3645), fsd(3, (alpha, 2))),
        (0.2247031747656014, pm(3, 0.7341125287521153)),
        (0.4123338622714356, pm(3, 0.4067031864267161)),
    ]
    points, weights = untangle(data)
    return HexahedronScheme("Hammer-Stroud 6-3", weights, points, 7, _citation)
示例#17
0
def stroud_secrest_09():
    eta = sqrt(10)
    xi, nu = [sqrt(15 - p_m * 5 * sqrt(5)) for p_m in [+1, -1]]
    A = frac(3, 5)
    B = frac(1, 50)

    data = [(A, numpy.array([[0, 0, 0]])), (B, pm(3, eta)), (B, pm_roll(3, [xi, nu]))]
    points, weights = untangle(data)
    weights *= 8 * pi
    return E3rScheme("Stroud-Secrest IX", weights, points, 5, citation)
示例#18
0
def _generate_jk(n, pm_type, j, k):
    M = fact(n) // fact(j) // fact(k) // fact(n - j - k) * 2**(j + k)
    G = frac(1, M)

    t = 1 if pm_type == "I" else -1
    b = sqrt(
        frac(1, j + k) * (1 + t * (k / j * sqrt(3 * (j + k) / (n + 2) - 1))))
    c = sqrt(
        frac(1, j + k) * (1 - t * (j / k * sqrt(3 * (j + k) / (n + 2) - 1))))
    return G, b, c
示例#19
0
文件: _stroud.py 项目: whzup/quadpy
def stroud_enr_5_4(n):
    r = sqrt(((n + 2) * (n + 3) + (n - 1) * (n + 3) * sqrt(2 * (n + 2))) / n)
    s = sqrt(((n + 2) * (n + 3) - (n + 3) * sqrt(2 * (n + 2))) / n)
    A = frac(4 * n + 6, (n + 2) * (n + 3))
    B = frac(n + 1, (n + 2) * (n + 3) * 2**n)
    data = [(A, numpy.full((1, n), 0)), (B, fsd(n, (r, 1), (s, n - 1)))]

    points, weights = untangle(data)
    weights *= 2 * sqrt(pi)**n * gamma(n) / gamma(frac(n, 2))
    return EnrScheme("Stroud Enr 5-4", n, weights, points, 5, citation)
示例#20
0
def stroud_secrest_07():
    nu, xi = [sqrt(15 - p_m * 3 * sqrt(5)) for p_m in [+1, -1]]
    A = frac(3, 5)
    B = frac(1, 30)

    d = {
        "zero3": [[A]],
        "symm_rs0_roll": [[B], [xi], [nu]],
    }
    return E3rScheme("Stroud-Secrest VII", d, 5, source)
示例#21
0
def hillion_08():
    lambda2, lambda3 = [(32 + i * 2 * sqrt(46)) / 105 for i in [+1, -1]]
    w1, w2 = [(3266 + i * 19 * sqrt(46)) / 17664 for i in [+1, -1]]
    weights, points = concat(
        mirror([frac(25, 384), 0, frac(4, 5)]),
        ([w1], [[lambda2, lambda2, 1 - 2 * lambda2]]),
        ([w2], [[lambda3, lambda3, 1 - 2 * lambda3]]),
    )
    weights *= 2
    return TriangleScheme("Hillion 8", weights, points, 3, citation)
示例#22
0
def albrecht_collatz_3():
    r = 1
    s = sqrt(frac(1, 2))
    data = [(frac(1, 30), fsd(3, (r, 1))), (frac(2, 30), fsd(3, (s, 2)))]

    points, weights = untangle(data)
    azimuthal_polar = cartesian_to_spherical_sympy(points)
    return SphereScheme(
        "Albrecht-Collatz 3", weights, points, azimuthal_polar, 5, citation
    )
示例#23
0
def stroud_un_5_1(n):
    degree = 5

    B1 = frac(4 - n, 2 * n * (n + 2))
    B2 = frac(1, n * (n + 2))

    data = [(B1, fsd(n, (1, 1))), (B2, fsd(n, (sqrt(frac(1, 2)), 2)))]

    points, weights = untangle(data)
    return UnScheme("Stroud Un 5-1", n, weights, points, degree, source)
示例#24
0
def stroud_secrest_07():
    nu, xi = [sqrt(15 - p_m * 3 * sqrt(5)) for p_m in [+1, -1]]
    A = frac(3, 5)
    B = frac(1, 30)

    data = [(A, numpy.array([[0, 0, 0]])), (B, pm_roll(3, [xi, nu]))]

    points, weights = untangle(data)
    weights *= 8 * pi
    return E3rScheme("Stroud-Secrest VII", weights, points, 5, citation)
示例#25
0
def stroud_cn_5_9(n):
    lst = n * [[frac(5, 9), frac(8, 9), frac(5, 9)]]
    weights = numpy.product(numpy.array(numpy.meshgrid(*lst)).T.reshape(-1, n),
                            axis=-1)
    weights /= 2**n
    sqrt35 = sqrt(frac(3, 5))
    lst = n * [[-sqrt35, 0, sqrt35]]
    points = numpy.array(numpy.meshgrid(*lst)).T.reshape(-1, n)
    points = numpy.ascontiguousarray(points.T)
    return CnScheme("Stroud Cn 5-9", n, weights, points, 5, _source, 1.224e-14)
示例#26
0
def stroud_un_5_3(n):
    degree = 5

    s = sqrt(frac(1, n + 2))
    B = [frac(2 ** (k - n) * (n + 2), n * (k + 1) * (k + 2)) for k in range(1, n + 1)]
    r = [sqrt(frac(k + 2, n + 2)) for k in range(1, n + 1)]
    data = [(B[k], pm(k * [0] + [r[k]] + (n - k - 1) * [s])) for k in range(n)]

    points, weights = untangle(data)
    return UnScheme("Stroud Un 5-3", n, weights, points, degree, source)
示例#27
0
def stroud_4_1():
    pts = (sqrt(2) * numpy.array([
        [cos(2 * i * numpy.pi / 5) for i in range(5)],
        [sin(2 * i * numpy.pi / 5) for i in range(5)],
    ]).T)
    data = [(frac(1, 2), numpy.array([[0, 0]])), (frac(1, 10), pts)]

    points, weights = untangle(data)
    weights *= pi
    return E2r2Scheme("Stroud 4-1", weights, points, 4, _citation)
示例#28
0
def stroud_secrest_08():
    nu = sqrt(30)
    eta = sqrt(10)
    A = frac(3, 5)
    B = frac(2, 75)
    C = frac(3, 100)

    data = [(A, [[0, 0, 0]]), (B, pm_roll([nu, 0, 0])), (C, pm([eta, eta, eta]))]
    points, weights = untangle(data)
    return E3rScheme("Stroud-Secrest VIII", weights, points, 5, source)
示例#29
0
def hillion_06():
    lm, mu = [(2 + i * sqrt(2 + i * sqrt(3))) / 6 for i in [+1, -1]]
    d = {
        "swap_ab": [
            [frac(1, 4), frac(1, 4)],
            [lm, frac(2, 3) - lm],
            [mu, frac(2, 3) - mu],
        ]
    }
    return T2Scheme("Hillion 6", d, 2, source)
示例#30
0
def stroud_secrest_08b():
    r = sqrt(frac(5, 2))
    s = sqrt(frac(5, 6))
    data = [
        (frac(2, 5), [[0, 0, 0]]),
        (frac(1, 25), fsd(3, (r, 1))),
        (frac(9, 200), pm([s, s, s])),
    ]
    points, weights = untangle(data)
    return E3r2Scheme("Stroud-Secrest VIIIb", weights, points, 5, source)
示例#31
0
def stroud_un_5_2(n):
    degree = 5

    B1 = frac(1, n * (n + 2))
    B2 = frac(n, 2 ** n * (n + 2))

    data = [(B1, fsd(n, (1, 1))), (B2, pm(n * [sqrt(frac(1, n))]))]

    points, weights = untangle(data)
    return UnScheme("Stroud Un 5-2", n, weights, points, degree, source)
示例#32
0
 def trace(self, j=-1, k=-1):
     # print("\nTP.trace({0}, {1}) running on rank {2} {3}tensor {4}".format(j,k,self.rank, ('symmetric ' if self.symmetric else ''), self))
     if(not self.symmetric and (j==-1 or k==-1)):
         raise TypeError("trace() takes exactly 3 arguments for non-symmetric tensor products (1 given)")
     coefficient = simplify(self.coefficient * (self.vectors[j]|self.vectors[k]))
     if(self.rank==2):
         # print("Finished TP.trace 1\n")
         return coefficient
     if(self.symmetric):
         from itertools import permutations
         T = 0
         for j,k in permutations(range(self.rank), 2):
             # print(j,k)
             coefficient = simplify( self.coefficient * (self.vectors[j]|self.vectors[k]) )
             if(coefficient==0):
                 continue
             T += TensorProduct(list(v for i,v in enumerate(self.vectors) if (i!=j and i!=k)),
                                coefficient = coefficient*frac(1,factorial(self.rank)),
                                symmetric=True)
         # print("Finished TP.trace 2\n")
         try:
             return T.compress()
         except AttributeError:
             return T
     elif(coefficient==0):
         # print("Finished TP.trace 3\n")
         return sympify(0)
     # print("Finished TP.trace 4\n")
     return TensorProduct(list(v for i,v in enumerate(self) if (i!=j and i!=k)),
                          coefficient=coefficient, symmetric=False)
示例#33
0
def test_AccumBounds():
    assert limit(sin(k) - sin(k + 1), k, oo) == AccumBounds(-2, 2)
    assert limit(cos(k) - cos(k + 1) + 1, k, oo) == AccumBounds(-1, 3)

    # not the exact bound
    assert limit(sin(k) - sin(k)*cos(k), k, oo) == AccumBounds(-2, 2)

    # test for issue #9934
    t1 = Mul(S(1)/2, 1/(-1 + cos(1)), Add(AccumBounds(-3, 1), cos(1)))
    assert limit(simplify(Sum(cos(n).rewrite(exp), (n, 0, k)).doit().rewrite(sin)), k, oo) == t1

    t2 = Mul(S(1)/2, Add(AccumBounds(-2, 2), sin(1)), 1/(-cos(1) + 1))
    assert limit(simplify(Sum(sin(n).rewrite(exp), (n, 0, k)).doit().rewrite(sin)), k, oo) == t2

    assert limit(frac(x)**x, x, oo) == AccumBounds(0, oo)
    assert limit(((sin(x) + 1)/2)**x, x, oo) == AccumBounds(0, oo)
示例#34
0
 def __or__(self,B):
     if(B.rank != self.rank):
         raise ValueError("Cannot contract rank-{0} tensor with rank-{1} tensor.".format(self.rank, B.rank))
     if(isinstance(B, TensorProductFunction)):
         if(self.symmetric):
             from itertools import permutations
             # It suffices to just iterate over rearrangements of `self`.
             coefficient = simplify(self.coefficient*B.coefficient*frac(1,factorial(self.rank)))
             if(coefficient==0): return sympify(0)
             return simplify( coefficient * sum([prod([v|w for v,w in zip(self.ordered_as(index_set), B)])
                                                 for index_set in permutations(range(self.rank))]) )
         return (self.coefficient*B.coefficient)*prod([v|w for v,w in zip(self, B)])
     else:
         try:
             return sum( [(self|t_p) for t_p in B] )
         except AttributeError:
             raise ValueError("Don't know how to contract TensorProductFunction with '{0}'".format(type(B)))
示例#35
0
def test_frac():
    assert isinstance(frac(x), frac)
    assert frac(oo) == AccumBounds(0, 1)
    assert frac(-oo) == AccumBounds(0, 1)

    assert frac(n) == 0
    assert frac(nan) == nan
    assert frac(Rational(4, 3)) == Rational(1, 3)
    assert frac(-Rational(4, 3)) == Rational(2, 3)

    r = Symbol('r', real=True)
    assert frac(I*r) == I*frac(r)
    assert frac(1 + I*r) == I*frac(r)
    assert frac(0.5 + I*r) == 0.5 + I*frac(r)
    assert frac(n + I*r) == I*frac(r)
    assert frac(n + I*k) == 0
    assert frac(x + I*x) == frac(x + I*x)
    assert frac(x + I*n) == frac(x)

    assert frac(x).rewrite(floor) == x - floor(x)
def Vlm(V_L, m):
    ell = V_L.rank
    return (alphalmTensor(ell, m) | V_L) * (frac(-8,factorial(ell))*sqrt(frac(ell*(ell+2), 2*(ell+1)*(ell-1))))
def Ulm(U_L, m):
    ell = U_L.rank
    return (alphalmTensor(ell, m) | U_L) * (frac(4,factorial(ell))*sqrt(frac((ell+1)*(ell+2), 2*ell*(ell-1))))
def C(ell,m):
    return (-1)**abs(m) * sympy.sqrt( frac(2*ell+1,4) * frac(factorial(ell-m), factorial(ell+m)) / sympy.pi )
def a(ell,m,j):
    return frac((-1)**j, 2**ell * factorial(j) * factorial(ell-j)) * frac(factorial(2*ell-2*j), factorial(ell-m-2*j))
示例#40
0
def test_floor():

    assert floor(nan) == nan

    assert floor(oo) == oo
    assert floor(-oo) == -oo
    assert floor(zoo) == zoo

    assert floor(0) == 0

    assert floor(1) == 1
    assert floor(-1) == -1

    assert floor(E) == 2
    assert floor(-E) == -3

    assert floor(2*E) == 5
    assert floor(-2*E) == -6

    assert floor(pi) == 3
    assert floor(-pi) == -4

    assert floor(Rational(1, 2)) == 0
    assert floor(-Rational(1, 2)) == -1

    assert floor(Rational(7, 3)) == 2
    assert floor(-Rational(7, 3)) == -3

    assert floor(Float(17.0)) == 17
    assert floor(-Float(17.0)) == -17

    assert floor(Float(7.69)) == 7
    assert floor(-Float(7.69)) == -8

    assert floor(I) == I
    assert floor(-I) == -I
    e = floor(i)
    assert e.func is floor and e.args[0] == i

    assert floor(oo*I) == oo*I
    assert floor(-oo*I) == -oo*I
    assert floor(exp(I*pi/4)*oo) == exp(I*pi/4)*oo

    assert floor(2*I) == 2*I
    assert floor(-2*I) == -2*I

    assert floor(I/2) == 0
    assert floor(-I/2) == -I

    assert floor(E + 17) == 19
    assert floor(pi + 2) == 5

    assert floor(E + pi) == floor(E + pi)
    assert floor(I + pi) == floor(I + pi)

    assert floor(floor(pi)) == 3
    assert floor(floor(y)) == floor(y)
    assert floor(floor(x)) == floor(floor(x))

    assert floor(x) == floor(x)
    assert floor(2*x) == floor(2*x)
    assert floor(k*x) == floor(k*x)

    assert floor(k) == k
    assert floor(2*k) == 2*k
    assert floor(k*n) == k*n

    assert floor(k/2) == floor(k/2)

    assert floor(x + y) == floor(x + y)

    assert floor(x + 3) == floor(x + 3)
    assert floor(x + k) == floor(x + k)

    assert floor(y + 3) == floor(y) + 3
    assert floor(y + k) == floor(y) + k

    assert floor(3 + I*y + pi) == 6 + floor(y)*I

    assert floor(k + n) == k + n

    assert floor(x*I) == floor(x*I)
    assert floor(k*I) == k*I

    assert floor(Rational(23, 10) - E*I) == 2 - 3*I

    assert floor(sin(1)) == 0
    assert floor(sin(-1)) == -1

    assert floor(exp(2)) == 7

    assert floor(log(8)/log(2)) != 2
    assert int(floor(log(8)/log(2)).evalf(chop=True)) == 3

    assert floor(factorial(50)/exp(1)) == \
        11188719610782480504630258070757734324011354208865721592720336800

    assert (floor(y) <= y) == True
    assert (floor(y) > y) == False
    assert (floor(x) <= x).is_Relational  # x could be non-real
    assert (floor(x) > x).is_Relational
    assert (floor(x) <= y).is_Relational  # arg is not same as rhs
    assert (floor(x) > y).is_Relational

    assert floor(y).rewrite(frac) == y - frac(y)
    assert floor(y).rewrite(ceiling) == -ceiling(-y)
    assert floor(y).rewrite(frac).subs(y, -pi) == floor(-pi)
    assert floor(y).rewrite(frac).subs(y, E) == floor(E)
    assert floor(y).rewrite(ceiling).subs(y, E) == -ceiling(-E)
    assert floor(y).rewrite(ceiling).subs(y, -pi) == -ceiling(pi)

    assert Eq(floor(y), y - frac(y))
    assert Eq(floor(y), -ceiling(-y))
示例#41
0
def test_ceiling():

    assert ceiling(nan) == nan

    assert ceiling(oo) == oo
    assert ceiling(-oo) == -oo
    assert ceiling(zoo) == zoo

    assert ceiling(0) == 0

    assert ceiling(1) == 1
    assert ceiling(-1) == -1

    assert ceiling(E) == 3
    assert ceiling(-E) == -2

    assert ceiling(2*E) == 6
    assert ceiling(-2*E) == -5

    assert ceiling(pi) == 4
    assert ceiling(-pi) == -3

    assert ceiling(Rational(1, 2)) == 1
    assert ceiling(-Rational(1, 2)) == 0

    assert ceiling(Rational(7, 3)) == 3
    assert ceiling(-Rational(7, 3)) == -2

    assert ceiling(Float(17.0)) == 17
    assert ceiling(-Float(17.0)) == -17

    assert ceiling(Float(7.69)) == 8
    assert ceiling(-Float(7.69)) == -7

    assert ceiling(I) == I
    assert ceiling(-I) == -I
    e = ceiling(i)
    assert e.func is ceiling and e.args[0] == i

    assert ceiling(oo*I) == oo*I
    assert ceiling(-oo*I) == -oo*I
    assert ceiling(exp(I*pi/4)*oo) == exp(I*pi/4)*oo

    assert ceiling(2*I) == 2*I
    assert ceiling(-2*I) == -2*I

    assert ceiling(I/2) == I
    assert ceiling(-I/2) == 0

    assert ceiling(E + 17) == 20
    assert ceiling(pi + 2) == 6

    assert ceiling(E + pi) == ceiling(E + pi)
    assert ceiling(I + pi) == ceiling(I + pi)

    assert ceiling(ceiling(pi)) == 4
    assert ceiling(ceiling(y)) == ceiling(y)
    assert ceiling(ceiling(x)) == ceiling(ceiling(x))

    assert ceiling(x) == ceiling(x)
    assert ceiling(2*x) == ceiling(2*x)
    assert ceiling(k*x) == ceiling(k*x)

    assert ceiling(k) == k
    assert ceiling(2*k) == 2*k
    assert ceiling(k*n) == k*n

    assert ceiling(k/2) == ceiling(k/2)

    assert ceiling(x + y) == ceiling(x + y)

    assert ceiling(x + 3) == ceiling(x + 3)
    assert ceiling(x + k) == ceiling(x + k)

    assert ceiling(y + 3) == ceiling(y) + 3
    assert ceiling(y + k) == ceiling(y) + k

    assert ceiling(3 + pi + y*I) == 7 + ceiling(y)*I

    assert ceiling(k + n) == k + n

    assert ceiling(x*I) == ceiling(x*I)
    assert ceiling(k*I) == k*I

    assert ceiling(Rational(23, 10) - E*I) == 3 - 2*I

    assert ceiling(sin(1)) == 1
    assert ceiling(sin(-1)) == 0

    assert ceiling(exp(2)) == 8

    assert ceiling(-log(8)/log(2)) != -2
    assert int(ceiling(-log(8)/log(2)).evalf(chop=True)) == -3

    assert ceiling(factorial(50)/exp(1)) == \
        11188719610782480504630258070757734324011354208865721592720336801

    assert (ceiling(y) >= y) == True
    assert (ceiling(y) < y) == False
    assert (ceiling(x) >= x).is_Relational  # x could be non-real
    assert (ceiling(x) < x).is_Relational
    assert (ceiling(x) >= y).is_Relational  # arg is not same as rhs
    assert (ceiling(x) < y).is_Relational

    assert ceiling(y).rewrite(floor) == -floor(-y)
    assert ceiling(y).rewrite(frac) == y + frac(-y)
    assert ceiling(y).rewrite(floor).subs(y, -pi) == -floor(pi)
    assert ceiling(y).rewrite(floor).subs(y, E) == -floor(-E)
    assert ceiling(y).rewrite(frac).subs(y, pi) == ceiling(pi)
    assert ceiling(y).rewrite(frac).subs(y, -E) == ceiling(-E)

    assert Eq(ceiling(y), y + frac(-y))
    assert Eq(ceiling(y), -floor(-y))
示例#42
0
def test_frac():
    assert isinstance(frac(x), frac)
    assert frac(oo) == AccumBounds(0, 1)
    assert frac(-oo) == AccumBounds(0, 1)

    assert frac(n) == 0
    assert frac(nan) == nan
    assert frac(Rational(4, 3)) == Rational(1, 3)
    assert frac(-Rational(4, 3)) == Rational(2, 3)

    r = Symbol('r', real=True)
    assert frac(I*r) == I*frac(r)
    assert frac(1 + I*r) == I*frac(r)
    assert frac(0.5 + I*r) == 0.5 + I*frac(r)
    assert frac(n + I*r) == I*frac(r)
    assert frac(n + I*k) == 0
    assert frac(x + I*x) == frac(x + I*x)
    assert frac(x + I*n) == frac(x)

    assert frac(x).rewrite(floor) == x - floor(x)
    assert frac(x).rewrite(ceiling) == x + ceiling(-x)
    assert frac(y).rewrite(floor).subs(y, pi) == frac(pi)
    assert frac(y).rewrite(floor).subs(y, -E) == frac(-E)
    assert frac(y).rewrite(ceiling).subs(y, -pi) == frac(-pi)
    assert frac(y).rewrite(ceiling).subs(y, E) == frac(E)

    assert Eq(frac(y), y - floor(y))
    assert Eq(frac(y), y + ceiling(-y))