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

Python integers.floor函数代码示例

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

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



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

示例1: eval

    def eval(cls, n, z):
        n, z = list(map(sympify, (n, z)))
        from sympy import unpolarify

        if n.is_integer:
            if n.is_nonnegative:
                nz = unpolarify(z)
                if z != nz:
                    return polygamma(n, nz)

            if n == -1:
                return loggamma(z)
            else:
                if z.is_Number:
                    if z is S.NaN:
                        return S.NaN
                    elif z is S.Infinity:
                        if n.is_Number:
                            if n is S.Zero:
                                return S.Infinity
                            else:
                                return S.Zero
                    elif z.is_Integer:
                        if z.is_nonpositive:
                            return S.ComplexInfinity
                        else:
                            if n is S.Zero:
                                return -S.EulerGamma + C.harmonic(z - 1, 1)
                            elif n.is_odd:
                                return (-1) ** (n + 1) * C.factorial(n) * zeta(n + 1, z)

        if n == 0:
            if z is S.NaN:
                return S.NaN
            elif z.is_Rational:
                # TODO actually *any* n/m can be done, but that is messy
                lookup = {
                    S(1) / 2: -2 * log(2) - S.EulerGamma,
                    S(1) / 3: -S.Pi / 2 / sqrt(3) - 3 * log(3) / 2 - S.EulerGamma,
                    S(1) / 4: -S.Pi / 2 - 3 * log(2) - S.EulerGamma,
                    S(3) / 4: -3 * log(2) - S.EulerGamma + S.Pi / 2,
                    S(2) / 3: -3 * log(3) / 2 + S.Pi / 2 / sqrt(3) - S.EulerGamma,
                }
                if z > 0:
                    n = floor(z)
                    z0 = z - n
                    if z0 in lookup:
                        return lookup[z0] + Add(*[1 / (z0 + k) for k in range(n)])
                elif z < 0:
                    n = floor(1 - z)
                    z0 = z + n
                    if z0 in lookup:
                        return lookup[z0] - Add(*[1 / (z0 - 1 - k) for k in range(n)])
            elif z in (S.Infinity, S.NegativeInfinity):
                return S.Infinity
            else:
                t = z.extract_multiplicatively(S.ImaginaryUnit)
                if t in (S.Infinity, S.NegativeInfinity):
                    return S.Infinity
开发者ID:Krastanov,项目名称:sympy,代码行数:59,代码来源:gamma_functions.py


示例2: test_slicing

def test_slicing():
    assert X[1:5, 2:4] == MatrixSlice(X, (1, 5), (2, 4))
    assert X[1, 2:4] == MatrixSlice(X, 1, (2, 4))
    assert X[1:5, :].shape == (4, X.shape[1])
    assert X[:, 1:5].shape == (X.shape[0], 4)

    assert X[::2, ::2].shape == (floor(n/2), floor(m/2))
    assert X[2, :] == MatrixSlice(X, 2, (0, m))
开发者ID:Maihj,项目名称:sympy,代码行数:8,代码来源:test_slice.py


示例3: test_issue_8413

def test_issue_8413():
    x = Symbol('x', real=True)
    # we can't evaluate in general because non-reals are not
    # comparable: Min(floor(3.2 + I), 3.2 + I) -> ValueError
    assert Min(floor(x), x) == floor(x)
    assert Min(ceiling(x), x) == x
    assert Max(floor(x), x) == x
    assert Max(ceiling(x), x) == ceiling(x)
开发者ID:Davidjohnwilson,项目名称:sympy,代码行数:8,代码来源:test_miscellaneous.py


示例4: real_root

def real_root(arg, n=None):
    """Return the real nth-root of arg if possible. If n is omitted then
    all instances of (-n)**(1/odd) will be changed to -n**(1/odd); this
    will only create a real root of a principle root -- the presence of
    other factors may cause the result to not be real.

    Examples
    ========

    >>> from sympy import root, real_root, Rational
    >>> from sympy.abc import x, n

    >>> real_root(-8, 3)
    -2
    >>> root(-8, 3)
    2*(-1)**(1/3)
    >>> real_root(_)
    -2

    If one creates a non-principle root and applies real_root, the
    result will not be real (so use with caution):

    >>> root(-8, 3, 2)
    -2*(-1)**(2/3)
    >>> real_root(_)
    -2*(-1)**(2/3)


    See Also
    ========

    sympy.polys.rootoftools.RootOf
    sympy.core.power.integer_nthroot
    root, sqrt
    """
    from sympy import im, Piecewise
    if n is not None:
        try:
            n = as_int(n)
            arg = sympify(arg)
            if arg.is_positive or arg.is_negative:
                rv = root(arg, n)
            else:
                raise ValueError
        except ValueError:
            return root(arg, n)*Piecewise(
                (S.One, ~Equality(im(arg), 0)),
                (Pow(S.NegativeOne, S.One/n)**(2*floor(n/2)), And(
                    Equality(n % 2, 1),
                    arg < 0)),
                (S.One, True))
    else:
        rv = sympify(arg)
    n1pow = Transform(lambda x: -(-x.base)**x.exp,
                      lambda x:
                      x.is_Pow and
                      x.base.is_negative and
                      x.exp.is_Rational and
                      x.exp.p == 1 and x.exp.q % 2)
    return rv.xreplace(n1pow)
开发者ID:ChaliZhg,项目名称:sympy,代码行数:60,代码来源:miscellaneous.py


示例5: _intersect

    def _intersect(self, other):
        from sympy.functions.elementary.integers import floor, ceiling
        from sympy.functions.elementary.miscellaneous import Min, Max
        if other.is_Interval:
            osup = other.sup
            oinf = other.inf
            # if other is [0, 10) we can only go up to 9
            if osup.is_integer and other.right_open:
                osup -= 1
            if oinf.is_integer and other.left_open:
                oinf += 1

            # Take the most restrictive of the bounds set by the two sets
            # round inwards
            inf = ceiling(Max(self.inf, oinf))
            sup = floor(Min(self.sup, osup))
            # if we are off the sequence, get back on
            off = (inf - self.inf) % self.step
            if off:
                inf += self.step - off

            return Range(inf, sup + 1, self.step)

        if other == S.Naturals:
            return self._intersect(Interval(1, S.Infinity))

        if other == S.Integers:
            return self

        return None
开发者ID:Jeyatharsini,项目名称:sympy,代码行数:30,代码来源:fancysets.py


示例6: sample

 def sample(self):
     """ A random realization from the distribution """
     icdf = self._inverse_cdf_expression()
     while True:
         sample_ = floor(list(icdf(random.uniform(0, 1)))[0])
         if sample_ >= self.set.inf:
             return sample_
开发者ID:carstimon,项目名称:sympy,代码行数:7,代码来源:drv.py


示例7: _eval_expand_func

    def _eval_expand_func(self, **hints):
        from sympy import Sum
        n = self.args[0]
        m = self.args[1] if len(self.args) == 2 else 1

        if m == S.One:
            if n.is_Add:
                off = n.args[0]
                nnew = n - off
                if off.is_Integer and off.is_positive:
                    result = [S.One/(nnew + i) for i in range(off, 0, -1)] + [harmonic(nnew)]
                    return Add(*result)
                elif off.is_Integer and off.is_negative:
                    result = [-S.One/(nnew + i) for i in range(0, off, -1)] + [harmonic(nnew)]
                    return Add(*result)

            if n.is_Rational:
                # Expansions for harmonic numbers at general rational arguments (u + p/q)
                # Split n as u + p/q with p < q
                p, q = n.as_numer_denom()
                u = p // q
                p = p - u * q
                if u.is_nonnegative and p.is_positive and q.is_positive and p < q:
                    k = Dummy("k")
                    t1 = q * Sum(1 / (q * k + p), (k, 0, u))
                    t2 = 2 * Sum(cos((2 * pi * p * k) / S(q)) *
                                   log(sin((pi * k) / S(q))),
                                   (k, 1, floor((q - 1) / S(2))))
                    t3 = (pi / 2) * cot((pi * p) / q) + log(2 * q)
                    return t1 + t2 - t3

        return self
开发者ID:SungSingSong,项目名称:sympy,代码行数:32,代码来源:numbers.py


示例8: _intersect

 def _intersect(self, other):
     from sympy.functions.elementary.integers import floor, ceiling
     if other is Interval(S.NegativeInfinity, S.Infinity) or other is S.Reals:
         return self
     elif other.is_Interval:
         s = Range(ceiling(other.left), floor(other.right) + 1)
         return s.intersect(other)  # take out endpoints if open interval
     return None
开发者ID:atsao72,项目名称:sympy,代码行数:8,代码来源:fancysets.py


示例9: _eval_expand_func

    def _eval_expand_func(self, **hints):
        n, z = self.args

        if n.is_Integer and n.is_nonnegative:
            if z.is_Add:
                coeff = z.args[0]
                if coeff.is_Integer:
                    e = -(n + 1)
                    if coeff > 0:
                        tail = Add(*[Pow(
                            z - i, e) for i in range(1, int(coeff) + 1)])
                    else:
                        tail = -Add(*[Pow(
                            z + i, e) for i in range(0, int(-coeff))])
                    return polygamma(n, z - coeff) + (-1)**n*factorial(n)*tail

            elif z.is_Mul:
                coeff, z = z.as_two_terms()
                if coeff.is_Integer and coeff.is_positive:
                    tail = [ polygamma(n, z + Rational(
                        i, coeff)) for i in range(0, int(coeff)) ]
                    if n == 0:
                        return Add(*tail)/coeff + log(coeff)
                    else:
                        return Add(*tail)/coeff**(n + 1)
                z *= coeff

        if n == 0 and z.is_Rational:
            p, q = z.as_numer_denom()

            # Reference:
            #   Values of the polygamma functions at rational arguments, J. Choi, 2007
            part_1 = -S.EulerGamma - pi * cot(p * pi / q) / 2 - log(q) + Add(
                *[cos(2 * k * pi * p / q) * log(2 * sin(k * pi / q)) for k in range(1, q)])

            if z > 0:
                n = floor(z)
                z0 = z - n
                return part_1 + Add(*[1 / (z0 + k) for k in range(n)])
            elif z < 0:
                n = floor(1 - z)
                z0 = z + n
                return part_1 - Add(*[1 / (z0 - 1 - k) for k in range(n)])

        return polygamma(n, z)
开发者ID:gamechanger98,项目名称:sympy,代码行数:45,代码来源:gamma_functions.py


示例10: _eval_expand_func

    def _eval_expand_func(self, deep=True, **hints):
        if deep:
            arg = self.args[0].expand(deep, **hints)
        else:
            arg = self.args[0]

        if arg.is_Add:
            coeff, tail = arg.as_coeff_add()
            if coeff and coeff.q != 1:
                tail = (C.Rational(1, coeff.q),) + tail
                coeff = floor(coeff)
            tail = arg._new_rawargs(*tail, **dict(reeval=False))
            return gamma(tail)*C.RisingFactorial(tail, coeff)

        return self.func(*self.args)
开发者ID:Grahack,项目名称:geophar,代码行数:15,代码来源:gamma_functions.py


示例11: eval_prob

 def eval_prob(self, _domain):
     if isinstance(_domain, Range):
         n = symbols('n')
         inf, sup, step = (r for r in _domain.args)
         summand = ((self.pdf).replace(
             self.symbol, inf + n*step))
         rv = summation(summand,
             (n, 0, floor((sup - inf)/step - 1))).doit()
         return rv
     elif isinstance(_domain, FiniteSet):
         pdf = Lambda(self.symbol, self.pdf)
         rv = sum(pdf(x) for x in _domain)
         return rv
     elif isinstance(_domain, Union):
         rv = sum(self.eval_prob(x) for x in _domain.args)
         return rv
     else:
         raise NotImplementedError(filldedent('''Probability for
             the domain %s cannot be calculated.'''%(_domain)))
开发者ID:carstimon,项目名称:sympy,代码行数:19,代码来源:drv.py


示例12: intersection_sets

def intersection_sets(a, b):
    from sympy.functions.elementary.integers import floor, ceiling
    from sympy.functions.elementary.miscellaneous import Min, Max
    if not all(i.is_number for i in b.args[:2]):
        return

    # In case of null Range, return an EmptySet.
    if a.size == 0:
        return S.EmptySet

    # trim down to self's size, and represent
    # as a Range with step 1.
    start = ceiling(max(b.inf, a.inf))
    if start not in b:
        start += 1
    end = floor(min(b.sup, a.sup))
    if end not in b:
        end -= 1
    return intersection_sets(a, Range(start, end + 1))
开发者ID:bjodah,项目名称:sympy,代码行数:19,代码来源:intersection.py


示例13: _eval_expand_func

    def _eval_expand_func(self, **hints):
        arg = self.args[0]
        if arg.is_Rational:
            if abs(arg.p) > arg.q:
                x = Dummy("x")
                n = arg.p // arg.q
                p = arg.p - n * arg.q
                return gamma(x + n)._eval_expand_func().subs(x, Rational(p, arg.q))

        if arg.is_Add:
            coeff, tail = arg.as_coeff_add()
            if coeff and coeff.q != 1:
                intpart = floor(coeff)
                tail = (coeff - intpart,) + tail
                coeff = intpart
            tail = arg._new_rawargs(*tail, reeval=False)
            return gamma(tail) * C.RisingFactorial(tail, coeff)

        return self.func(*self.args)
开发者ID:Krastanov,项目名称:sympy,代码行数:19,代码来源:gamma_functions.py


示例14: update

	def update(self):
		filled_length = round(self.width * self.progress, self.tenths)
		filled_length_int = floor(self.width * self.progress)
		_int = round(filled_length - filled_length_int, self.tenths)
		phase = self.nphases[_int]
		#print(filled_length)
		#print(filled_length_int)
		#print(_int)
		#print(phase)
		percent = "{:.0%} ".format(self.progress)
		empty_length = round(self.width - filled_length, 1)
		message = self.message
		if filled_length == 0:
			bar = ' '
		else:
			bar = self.COLOR.format('█'* int(filled_length)+ phase)
		empty = ' ' * int(empty_length)
		#suffix = self.suffix
		line = ''.join([message, percent, self.bar_prefix, bar, empty, self.bar_prefix])
		self.file.writelines(line)
		self.file.flush()
开发者ID:KGerring,项目名称:RevealMe,代码行数:21,代码来源:progress.py


示例15: _eval_rewrite_as_polynomial

 def _eval_rewrite_as_polynomial(self, n, m, x):
     from sympy import Sum
     k = Dummy("k")
     kern = factorial(2*n - 2*k)/(2**n*factorial(n - k)*factorial(
         k)*factorial(n - 2*k - m))*(-1)**k*x**(n - m - 2*k)
     return (1 - x**2)**(m/2) * Sum(kern, (k, 0, floor((n - m)*S.Half)))
开发者ID:ChaliZhg,项目名称:sympy,代码行数:6,代码来源:polynomials.py


示例16: shape

 def shape(self):
     rows = self.rowslice[1] - self.rowslice[0]
     rows = rows if self.rowslice[2] == 1 else floor(rows/self.rowslice[2])
     cols = self.colslice[1] - self.colslice[0]
     cols = cols if self.colslice[2] == 1 else floor(cols/self.colslice[2])
     return rows, cols
开发者ID:asmeurer,项目名称:sympy,代码行数:6,代码来源:slice.py


示例17: _intersect

 def _intersect(self, other):
     if other.is_Interval:
         s = FiniteSet(range(ceiling(other.left), floor(other.right) + 1))
         return s.intersect(other) # take out endpoints if open interval
     return None
开发者ID:BDGLunde,项目名称:sympy,代码行数:5,代码来源:fancysets.py


示例18: test_issue_13749

def test_issue_13749():
    assert integrate(1 / (2 + cos(x)), (x, 0, pi)) == pi/sqrt(3)
    assert integrate(1/(2 + cos(x))) == 2*sqrt(3)*(atan(sqrt(3)*tan(x/2)/3) + pi*floor((x/2 - pi/2)/pi))/3
开发者ID:normalhuman,项目名称:sympy,代码行数:3,代码来源:test_integrals.py


示例19: test_issue_8623

def test_issue_8623():
    assert integrate((1 + cos(2*x)) / (3 - 2*cos(2*x)), (x, 0, pi)) == -pi/2 + sqrt(5)*pi/2
    assert integrate((1 + cos(2*x))/(3 - 2*cos(2*x))) == -x/2 + sqrt(5)*(atan(sqrt(5)*tan(x)) + \
        pi*floor((x - pi/2)/pi))/2
开发者ID:normalhuman,项目名称:sympy,代码行数:4,代码来源:test_integrals.py


示例20: _intersect

    def _intersect(self, other):
        from sympy.functions.elementary.integers import ceiling, floor
        from sympy.functions.elementary.complexes import sign

        if other is S.Naturals:
            return self._intersect(Interval(1, S.Infinity))

        if other is S.Integers:
            return self

        if other.is_Interval:
            if not all(i.is_number for i in other.args[:2]):
                return

            # In case of null Range, return an EmptySet.
            if self.size == 0:
                return S.EmptySet

            # trim down to self's size, and represent
            # as a Range with step 1.
            start = ceiling(max(other.inf, self.inf))
            if start not in other:
                start += 1
            end = floor(min(other.sup, self.sup))
            if end not in other:
                end -= 1
            return self.intersect(Range(start, end + 1))

        if isinstance(other, Range):
            from sympy.solvers.diophantine import diop_linear
            from sympy.core.numbers import ilcm

            # non-overlap quick exits
            if not other:
                return S.EmptySet
            if not self:
                return S.EmptySet
            if other.sup < self.inf:
                return S.EmptySet
            if other.inf > self.sup:
                return S.EmptySet

            # work with finite end at the start
            r1 = self
            if r1.start.is_infinite:
                r1 = r1.reversed
            r2 = other
            if r2.start.is_infinite:
                r2 = r2.reversed

            # this equation represents the values of the Range;
            # it's a linear equation
            eq = lambda r, i: r.start + i*r.step

            # we want to know when the two equations might
            # have integer solutions so we use the diophantine
            # solver
            a, b = diop_linear(eq(r1, Dummy()) - eq(r2, Dummy()))

            # check for no solution
            no_solution = a is None and b is None
            if no_solution:
                return S.EmptySet

            # there is a solution
            # -------------------

            # find the coincident point, c
            a0 = a.as_coeff_Add()[0]
            c = eq(r1, a0)

            # find the first point, if possible, in each range
            # since c may not be that point
            def _first_finite_point(r1, c):
                if c == r1.start:
                    return c
                # st is the signed step we need to take to
                # get from c to r1.start
                st = sign(r1.start - c)*step
                # use Range to calculate the first point:
                # we want to get as close as possible to
                # r1.start; the Range will not be null since
                # it will at least contain c
                s1 = Range(c, r1.start + st, st)[-1]
                if s1 == r1.start:
                    pass
                else:
                    # if we didn't hit r1.start then, if the
                    # sign of st didn't match the sign of r1.step
                    # we are off by one and s1 is not in r1
                    if sign(r1.step) != sign(st):
                        s1 -= st
                if s1 not in r1:
                    return
                return s1

            # calculate the step size of the new Range
            step = abs(ilcm(r1.step, r2.step))
            s1 = _first_finite_point(r1, c)
            if s1 is None:
#.........这里部分代码省略.........
开发者ID:pkgodara,项目名称:sympy,代码行数:101,代码来源:fancysets.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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