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


Python integers.floor函数代码示例

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


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


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