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

Python sympy.floor函数代码示例

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

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



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

示例1: test_frac

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))
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:28,代码来源:test_integers.py


示例2: find_period_sqrt

def find_period_sqrt(x, ITS_MAX=20):
    #x = S(sqrt(x))
    x = np.sqrt(x)

    seq = array([], dtype=float64)
    for its in arange(ITS_MAX):
        # subtract the integer part
        y = x - floor(x)

        # put that into an array
        seq = hstack(( seq, floor(x).n() ))

        # take the inverse
        x = 1/y

    # boom, we have the sequence
    seq = seq[1:]
    l = len(seq)

    # find out how periodic it is
    for i in arange(0,10):
        # repeat some sequence
        tiled_array = tile(seq[:i-1], 10*l//i)
        # make it the right len
        tiled_array = tiled_array[:l]
        # see if they're equal
        if array_equal(tiled_array, seq):
            length = len(seq[:i-1])
            #print length
            #break
            return length
    #print -1
    return -1
开发者ID:stsievert,项目名称:side-projects,代码行数:33,代码来源:euler.py


示例3: round_afz

def round_afz(val, ndigits=0):
    u"""Round using round-away-from-zero strategy for halfway cases.

    Python 3+ implements round-half-even, and Python 2.7 has a random behaviour
    from end user point of view (in fact, result depends on internal
    representation in floating point arithmetic).
    """
    ceil = math.ceil
    floor = math.floor
    val = float(val)
    if isnan(val) or isinf(val):
        return val
    s = repr(val).rstrip('0')
    if 'e' in s:
        # XXX: implement round-away-from-zero in this case too.
        return round(val, ndigits)
    sep = s.find('.')
    pos = sep + ndigits
    if ndigits <= 0:
        pos -= 1
    # Skip dot if needed to reach next digit.
    next_pos = (pos + 1 if pos + 1 != sep else pos + 2)
    if next_pos < 0 or next_pos == 0 and s[next_pos] == '-':
        return 0.
    if len(s) <= next_pos:
        # No need to round (no digit after).
        return val
    power = 10**ndigits
    if s[next_pos] in '01234':
        return (floor(val*power)/power if val > 0 else ceil(val*power)/power)
    else:
        return (ceil(val*power)/power if val > 0 else floor(val*power)/power)
开发者ID:wxgeo,项目名称:geophar,代码行数:32,代码来源:custom_functions.py


示例4: _eval_expand_func

    def _eval_expand_func(self, **hints):
        from sympy import exp, I, floor, Add, Poly, Dummy, exp_polar, unpolarify
        z, s, a = self.args
        if z == 1:
            return zeta(s, a)
        if s.is_Integer and s <= 0:
            t = Dummy('t')
            p = Poly((t + a)**(-s), t)
            start = 1/(1 - t)
            res = S(0)
            for c in reversed(p.all_coeffs()):
                res += c*start
                start = t*start.diff(t)
            return res.subs(t, z)

        if a.is_Rational:
            # See section 18 of
            #   Kelly B. Roach.  Hypergeometric Function Representations.
            #   In: Proceedings of the 1997 International Symposium on Symbolic and
            #   Algebraic Computation, pages 205-211, New York, 1997. ACM.
            # TODO should something be polarified here?
            add = S(0)
            mul = S(1)
            # First reduce a to the interaval (0, 1]
            if a > 1:
                n = floor(a)
                if n == a:
                    n -= 1
                a -= n
                mul = z**(-n)
                add = Add(*[-z**(k - n)/(a + k)**s for k in xrange(n)])
            elif a <= 0:
                n = floor(-a) + 1
                a += n
                mul = z**n
                add = Add(*[z**(n - 1 - k)/(a - k - 1)**s for k in xrange(n)])

            m, n = S([a.p, a.q])
            zet = exp_polar(2*pi*I/n)
            root = z**(1/n)
            return add + mul*n**(s - 1)*Add(
                *[polylog(s, zet**k*root)._eval_expand_func(**hints)
                  / (unpolarify(zet)**k*root)**m for k in xrange(n)])

        # TODO use minpoly instead of ad-hoc methods when issue 2789 is fixed
        if z.func is exp and (z.args[0]/(pi*I)).is_Rational or z in [-1, I, -I]:
            # TODO reference?
            if z == -1:
                p, q = S([1, 2])
            elif z == I:
                p, q = S([1, 4])
            elif z == -I:
                p, q = S([-1, 4])
            else:
                arg = z.args[0]/(2*pi*I)
                p, q = S([arg.p, arg.q])
            return Add(*[exp(2*pi*I*k*p/q)/q**s*zeta(s, (k + a)/q)
                         for k in xrange(q)])

        return lerchphi(z, s, a)
开发者ID:abhishekkumawat23,项目名称:sympy,代码行数:60,代码来源:zeta_functions.py


示例5: rationalize

def rationalize(x, maxcoeff=10000):
    """
    Helps identifying a rational number from a float (or mpmath.mpf) value by
    using a continued fraction. The algorithm stops as soon as a large partial
    quotient is detected (greater than 10000 by default).

    Examples
    ========

    >>> from sympy.concrete.guess import rationalize
    >>> from mpmath import cos, pi
    >>> rationalize(cos(pi/3))
    1/2

    >>> from mpmath import mpf
    >>> rationalize(mpf("0.333333333333333"))
    1/3

    While the function is rather intended to help 'identifying' rational
    values, it may be used in some cases for approximating real numbers.
    (Though other functions may be more relevant in that case.)

    >>> rationalize(pi, maxcoeff = 250)
    355/113

    See also
    ========
    Several other methods can approximate a real number as a rational, like:

      * fractions.Fraction.from_decimal
      * fractions.Fraction.from_float
      * mpmath.identify
      * mpmath.pslq by using the following syntax: mpmath.pslq([x, 1])
      * mpmath.findpoly by using the following syntax: mpmath.findpoly(x, 1)
      * sympy.simplify.nsimplify (which is a more general function)

    The main difference between the current function and all these variants is
    that control focuses on magnitude of partial quotients here rather than on
    global precision of the approximation. If the real is "known to be" a
    rational number, the current function should be able to detect it correctly
    with the default settings even when denominator is great (unless its
    expansion contains unusually big partial quotients) which may occur
    when studying sequences of increasing numbers. If the user cares more
    on getting simple fractions, other methods may be more convenient.

    """
    p0, p1 = 0, 1
    q0, q1 = 1, 0
    a = floor(x)
    while a < maxcoeff or q1 == 0:
        p = a * p1 + p0
        q = a * q1 + q0
        p0, p1 = p1, p
        q0, q1 = q1, q
        if x == a:
            break
        x = 1 / (x - a)
        a = floor(x)
    return sympify(p) / q
开发者ID:Carreau,项目名称:sympy,代码行数:59,代码来源:guess.py


示例6: test_dir

def test_dir():
    assert abs(x).series(x, 0, dir="+") == x
    assert abs(x).series(x, 0, dir="-") == -x
    assert floor(x + 2).series(x, 0, dir='+') == 2
    assert floor(x + 2).series(x, 0, dir='-') == 1
    assert floor(x + 2.2).series(x, 0, dir='-') == 2
    assert ceiling(x + 2.2).series(x, 0, dir='-') == 3
    assert sin(x + y).series(x, 0, dir='-') == sin(x + y).series(x, 0, dir='+')
开发者ID:QuaBoo,项目名称:sympy,代码行数:8,代码来源:test_nseries.py


示例7: rightshift

def rightshift(a, b):
    if issig('rr', a, b):
        return Real(int(sym.floor(a)) >> int(sym.floor(b)))

    if issig('qr', a, b):
        b = sym.floor(b)
        return a[-b:] + a[:-b]

    raise BadTypeCombinationError('rightshift', a, b)
开发者ID:Maltysen,项目名称:pyth5,代码行数:9,代码来源:env.py


示例8: leftshift

def leftshift(a, b):
    if issig('rr', a, b):
        return Real(int(sym.floor(a)) << int(sym.floor(b)))

    if issig('qr', a, b):
        b = sym.floor(b)
        return a[b:] + a[:b]

    raise BadTypeCombinationError('leftshift', a, b)
开发者ID:Maltysen,项目名称:pyth5,代码行数:9,代码来源:env.py


示例9: test_issue_8444_workingtests

def test_issue_8444_workingtests():
    x = symbols('x')
    assert Gt(x, floor(x)) == Gt(x, floor(x), evaluate=False)
    assert Ge(x, floor(x)) == Ge(x, floor(x), evaluate=False)
    assert Lt(x, ceiling(x)) == Lt(x, ceiling(x), evaluate=False)
    assert Le(x, ceiling(x)) == Le(x, ceiling(x), evaluate=False)
    i = symbols('i', integer=True)
    assert (i > floor(i)) == False
    assert (i < ceiling(i)) == False
开发者ID:asmeurer,项目名称:sympy,代码行数:9,代码来源:test_relational.py


示例10: test_issue_8444_nonworkingtests

def test_issue_8444_nonworkingtests():
    x = symbols('x', real=True)
    assert (x <= oo) == (x >= -oo) == True

    x = symbols('x')
    assert x >= floor(x)
    assert (x < floor(x)) == False
    assert x <= ceiling(x)
    assert (x > ceiling(x)) == False
开发者ID:asmeurer,项目名称:sympy,代码行数:9,代码来源:test_relational.py


示例11: test_dir

def test_dir():
    x = Symbol('x')
    y = Symbol('y')
    assert abs(x).series(x, 0, dir="+") == x
    assert abs(x).series(x, 0, dir="-") == -x
    assert floor(x+2).series(x,0,dir='+') == 2
    assert floor(x+2).series(x,0,dir='-') == 1
    assert floor(x+2.2).series(x,0,dir='-') == 2
    assert sin(x+y).series(x,0,dir='-') == sin(x+y).series(x,0,dir='+')
开发者ID:jcockayne,项目名称:sympy-rkern,代码行数:9,代码来源:test_nseries.py


示例12: length

def length(P, Q, D):
    """
    Returns the length of aperiodic part + length of periodic part of
    continued fraction representation of (P + sqrt(D))/Q. It is important
    to remember that this does NOT return the length of the periodic
    part but the addition of the legths of the two parts as mentioned above.

    Usage
    =====

        length(P, Q, D) -> P, Q and D are integers corresponding to the
        continued fraction (P + sqrt(D))/Q.

    Details
    =======

        ``P`` corresponds to the P in the continued fraction, (P + sqrt(D))/ Q
        ``D`` corresponds to the D in the continued fraction, (P + sqrt(D))/ Q
        ``Q`` corresponds to the Q in the continued fraction, (P + sqrt(D))/ Q

    Examples
    ========

    >>> from sympy.solvers.diophantine import length
    >>> length(-2 , 4, 5) # (-2 + sqrt(5))/4
    3
    >>> length(-5, 4, 17) # (-5 + sqrt(17))/4
    4
    """
    x = P + sqrt(D)
    y = Q

    x = sympify(x)
    v, res = [], []
    q = x/y

    if q < 0:
        v.append(q)
        res.append(floor(q))
        q = q - floor(q)
        num, den = rad_rationalize(1, q)
        q = num / den

    while 1:
        v.append(q)
        a = int(q)
        res.append(a)

        if q == a:
            return len(res)

        num, den = rad_rationalize(1,(q - a))
        q = num / den

        if q in v:
            return len(res)
开发者ID:twobitlogic,项目名称:sympy,代码行数:56,代码来源:diophantine.py


示例13: test_dir

def test_dir():
    x = Symbol("x")
    y = Symbol("y")
    assert abs(x).series(x, 0, dir="+") == x
    assert abs(x).series(x, 0, dir="-") == -x
    assert floor(x + 2).series(x, 0, dir="+") == 2
    assert floor(x + 2).series(x, 0, dir="-") == 1
    assert floor(x + 2.2).series(x, 0, dir="-") == 2
    assert ceiling(x + 2.2).series(x, 0, dir="-") == 3
    assert sin(x + y).series(x, 0, dir="-") == sin(x + y).series(x, 0, dir="+")
开发者ID:hitej,项目名称:meta-core,代码行数:10,代码来源:test_nseries.py


示例14: test_series

def test_series():
    x, y = symbols('x,y')
    assert floor(x).nseries(x, y, 100) == floor(y)
    assert ceiling(x).nseries(x, y, 100) == ceiling(y)
    assert floor(x).nseries(x, pi, 100) == 3
    assert ceiling(x).nseries(x, pi, 100) == 4
    assert floor(x).nseries(x, 0, 100) == 0
    assert ceiling(x).nseries(x, 0, 100) == 1
    assert floor(-x).nseries(x, 0, 100) == -1
    assert ceiling(-x).nseries(x, 0, 100) == 0
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:10,代码来源:test_integers.py


示例15: test_upretty_floor

def test_upretty_floor():
    assert upretty(floor(x)) == u'⌊x⌋'

    u = upretty( floor(1 / (y - floor(x))) )
    s = \
u"""\
⎢   1   ⎥
⎢───────⎥
⎣y - ⌊x⌋⎦\
"""
    assert u == s
开发者ID:Praveen-Ramanujam,项目名称:MobRAVE,代码行数:11,代码来源:test_pretty_unicode.py


示例16: power

def power(a, b):
    if issig('rr', a, b):
        return sym.Pow(a, b)

    if issig('sr', a, b):
        return [p + q for p, q in itertools.product(a, repeat=sym.floor(b))]

    if issig('qr', a, b):
        return [list(tup) for tup in itertools.product(a, repeat=sym.floor(b))]

    raise BadTypeCombinationError('power', a, b)
开发者ID:Maltysen,项目名称:pyth5,代码行数:11,代码来源:env.py


示例17: test_issue_8853

def test_issue_8853():
    p = Symbol('x', even=True, positive=True)
    assert floor(-p - S.Half).is_even == False
    assert floor(-p + S.Half).is_even == True
    assert ceiling(p - S.Half).is_even == True
    assert ceiling(p + S.Half).is_even == False

    assert get_integer_part(S.Half, -1, {}, True) == (0, 0)
    assert get_integer_part(S.Half, 1, {}, True) == (1, 0)
    assert get_integer_part(-S.Half, -1, {}, True) == (-1, 0)
    assert get_integer_part(-S.Half, 1, {}, True) == (0, 0)
开发者ID:nickle8424,项目名称:sympy,代码行数:11,代码来源:test_evalf.py


示例18: test_evalf_integer_parts

def test_evalf_integer_parts():
    a = floor(log(8)/log(2) - exp(-1000), evaluate=False)
    b = floor(log(8)/log(2), evaluate=False)
    raises(PrecisionExhausted, "a.evalf()")
    assert a.evalf(chop=True) == 3
    assert a.evalf(maxprec=500) == 2
    raises(PrecisionExhausted, "b.evalf()")
    raises(PrecisionExhausted, "b.evalf(maxprec=500)")
    assert b.evalf(chop=True) == 3
    assert int(floor(factorial(50)/E,evaluate=False).evalf()) == \
        11188719610782480504630258070757734324011354208865721592720336800L
    assert int(ceiling(factorial(50)/E,evaluate=False).evalf()) == \
        11188719610782480504630258070757734324011354208865721592720336801L
    assert int(floor((GoldenRatio**999 / sqrt(5) + Rational(1,2))).evalf(1000)) == fibonacci(999)
    assert int(floor((GoldenRatio**1000 / sqrt(5) + Rational(1,2))).evalf(1000)) == fibonacci(1000)
开发者ID:jcockayne,项目名称:sympy-rkern,代码行数:15,代码来源:test_evalf.py


示例19: test_ansi_math1_codegen

def test_ansi_math1_codegen():
    # not included: log10
    from sympy import acos, asin, atan, ceiling, cos, cosh, floor, log, ln, \
        sin, sinh, sqrt, tan, tanh, N
    x = symbols('x')
    name_expr = [
        ("test_fabs", abs(x)),
        ("test_acos", acos(x)),
        ("test_asin", asin(x)),
        ("test_atan", atan(x)),
        ("test_ceil", ceiling(x)),
        ("test_cos", cos(x)),
        ("test_cosh", cosh(x)),
        ("test_floor", floor(x)),
        ("test_log", log(x)),
        ("test_ln", ln(x)),
        ("test_sin", sin(x)),
        ("test_sinh", sinh(x)),
        ("test_sqrt", sqrt(x)),
        ("test_tan", tan(x)),
        ("test_tanh", tanh(x)),
    ]
    numerical_tests = []
    for name, expr in name_expr:
        for xval in 0.2, 0.5, 0.8:
            expected = N(expr.subs(x, xval))
            numerical_tests.append((name, (xval,), expected, 1e-14))
    run_cc_test("ansi_math1", name_expr, numerical_tests)
开发者ID:Praveen-Ramanujam,项目名称:MobRAVE,代码行数:28,代码来源:test_codegen_c_cc.py


示例20: test_latex_functions

def test_latex_functions():
    assert latex(exp(x)) == "$e^{x}$"
    assert latex(exp(1) + exp(2)) == "$e + e^{2}$"

    f = Function("f")
    assert latex(f(x)) == "$\\operatorname{f}\\left(x\\right)$"

    beta = Function("beta")

    assert latex(beta(x)) == r"$\operatorname{beta}\left(x\right)$"
    assert latex(sin(x)) == r"$\operatorname{sin}\left(x\right)$"
    assert latex(sin(x), fold_func_brackets=True) == r"$\operatorname{sin}x$"
    assert latex(sin(2 * x ** 2), fold_func_brackets=True) == r"$\operatorname{sin}2 x^{2}$"
    assert latex(sin(x ** 2), fold_func_brackets=True) == r"$\operatorname{sin}x^{2}$"

    assert latex(asin(x) ** 2) == r"$\operatorname{asin}^{2}\left(x\right)$"
    assert latex(asin(x) ** 2, inv_trig_style="full") == r"$\operatorname{arcsin}^{2}\left(x\right)$"
    assert latex(asin(x) ** 2, inv_trig_style="power") == r"$\operatorname{sin}^{-1}\left(x\right)^{2}$"
    assert latex(asin(x ** 2), inv_trig_style="power", fold_func_brackets=True) == r"$\operatorname{sin}^{-1}x^{2}$"

    assert latex(factorial(k)) == r"$k!$"
    assert latex(factorial(-k)) == r"$\left(- k\right)!$"

    assert latex(floor(x)) == r"$\lfloor{x}\rfloor$"
    assert latex(ceiling(x)) == r"$\lceil{x}\rceil$"
    assert latex(abs(x)) == r"$\lvert{x}\rvert$"
    assert latex(re(x)) == r"$\Re{x}$"
    assert latex(im(x)) == r"$\Im{x}$"
    assert latex(conjugate(x)) == r"$\overline{x}$"
    assert latex(gamma(x)) == r"$\operatorname{\Gamma}\left(x\right)$"
    assert latex(Order(x)) == r"$\operatorname{\mathcal{O}}\left(x\right)$"
开发者ID:hazelnusse,项目名称:sympy-old,代码行数:31,代码来源:test_latex.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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