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


Python sympy.pi方法代码示例

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


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

示例1: _eigen_components

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import pi [as 别名]
def _eigen_components(self):
        components = [(0, np.diag([1, 1, 1, 0, 1, 0, 0, 1]))]
        nontrivial_part = np.zeros((3, 3), dtype=np.complex128)
        for ij, w in zip([(1, 2), (0, 2), (0, 1)], self.weights):
            nontrivial_part[ij] = w
            nontrivial_part[ij[::-1]] = w.conjugate()
        assert np.allclose(nontrivial_part, nontrivial_part.conj().T)
        eig_vals, eig_vecs = np.linalg.eigh(nontrivial_part)
        for eig_val, eig_vec in zip(eig_vals, eig_vecs.T):
            exp_factor = -eig_val / np.pi
            proj = np.zeros((8, 8), dtype=np.complex128)
            nontrivial_indices = np.array([3, 5, 6], dtype=np.intp)
            proj[nontrivial_indices[:, np.newaxis], nontrivial_indices] = (
                np.outer(eig_vec.conjugate(), eig_vec))
            components.append((exp_factor, proj))
        return components 
开发者ID:quantumlib,项目名称:OpenFermion-Cirq,代码行数:18,代码来源:fermionic_simulation.py

示例2: sympy_to_grim

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import pi [as 别名]
def sympy_to_grim(expr, **kwargs):
    import sympy
    assert isinstance(expr, sympy.Expr)
    if expr.is_Integer:
        return Expr(int(expr))
    if expr.is_Symbol:
        return Expr(symbol_name=expr.name)
    if expr is sympy.pi:
        return Pi
    if expr is sympy.E:
        return ConstE
    if expr is sympy.I:
        return ConstI
    if expr.is_Add:
        args = [sympy_to_grim(x, **kwargs) for x in expr.args]
        return Add(*args)
    if expr.is_Mul:
        args = [sympy_to_grim(x, **kwargs) for x in expr.args]
        return Mul(*args)
    if expr.is_Pow:
        args = [sympy_to_grim(x, **kwargs) for x in expr.args]
        b, e = args
        return Pow(b, e)
    raise NotImplementedError("converting %s to Grim", type(expr)) 
开发者ID:fredrik-johansson,项目名称:fungrim,代码行数:26,代码来源:sympy_interface.py

示例3: grad_log_norm_symbolic

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import pi [as 别名]
def grad_log_norm_symbolic(self):
        import sympy
        D = self.dimension
        X = self.eigenvalues_symbol
        B = [1] * D
        for d in range(D):
            for dd in range(D):
                if d != dd:
                    B[d] = B[d] * (X[d] - X[dd])
        B = [1 / b for b in B]

        p_D = sympy.pi ** D

        tmp = [b * sympy.exp(x_) for x_, b in zip(X, B)]
        tmp = sum(tmp)
        symbolic_norm_for_bingham = 2 * p_D * tmp

        return [
            sympy.simplify(sympy.diff(
                sympy.log(symbolic_norm_for_bingham),
                x_
            ))
            for x_ in X
        ] 
开发者ID:fgnt,项目名称:pb_bss,代码行数:26,代码来源:complex_bingham.py

示例4: test_constants

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import pi [as 别名]
def test_constants():
    assert sympify(sympy.E) == E
    assert sympy.E == E._sympy_()

    assert sympify(sympy.pi) == pi
    assert sympy.pi == pi._sympy_()

    assert sympify(sympy.GoldenRatio) == GoldenRatio
    assert sympy.GoldenRatio == GoldenRatio._sympy_()

    assert sympify(sympy.Catalan) == Catalan
    assert sympy.Catalan == Catalan._sympy_()

    assert sympify(sympy.EulerGamma) == EulerGamma
    assert sympy.EulerGamma == EulerGamma._sympy_()

    assert sympify(sympy.oo) == oo
    assert sympy.oo == oo._sympy_()

    assert sympify(sympy.zoo) == zoo
    assert sympy.zoo == zoo._sympy_()

    assert sympify(sympy.nan) == nan
    assert sympy.nan == nan._sympy_() 
开发者ID:symengine,项目名称:symengine.py,代码行数:26,代码来源:test_sympy_conv.py

示例5: xiu

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import pi [as 别名]
def xiu(n):
    points = []
    for k in range(n + 1):
        pt = []
        # Slight adaptation:
        # The article has points for the weight 1/sqrt(2*pi) exp(−x**2/2)
        # so divide by sqrt(2) to adapt for 1/sqrt(pi) exp(−x ** 2)
        for r in range(1, n // 2 + 1):
            alpha = (2 * r * k * pi) / (n + 1)
            pt += [cos(alpha), sin(alpha)]
        if n % 2 == 1:
            pt += [(-1) ** k / sqrt(2)]
        points.append(pt)

    points = numpy.array(points)
    weights = numpy.full(n + 1, frac(1, n + 1))
    return Enr2Scheme("Xiu", n, weights, points, 2, source) 
开发者ID:nschloe,项目名称:quadpy,代码行数:19,代码来源:_xiu.py

示例6: stroud_s2_9_3

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import pi [as 别名]
def stroud_s2_9_3():
    # spherical product gauss 9
    sqrt = numpy.vectorize(sympy.sqrt)
    pm_ = numpy.array([+1, -1])
    cos = numpy.vectorize(sympy.cos)
    sin = numpy.vectorize(sympy.sin)
    frac = sympy.Rational
    pi = sympy.pi

    r1, r2 = sqrt((6 - pm_ * sqrt(6)) / 10)

    a = (numpy.arange(10) + 1) * pi / 5
    x = numpy.array([cos(a), sin(a)]).T

    B0 = frac(1, 9)
    B1, B2 = (16 + pm_ * sqrt(6)) / 360

    data = [(B0, z(2)), (B1, r1 * x), (B2, r2 * x)]
    points, weights = untangle(data)
    return S2Scheme("Stroud S2 9-3", weights, points, 9, _source) 
开发者ID:nschloe,项目名称:quadpy,代码行数:22,代码来源:_stroud.py

示例7: albrecht_4

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import pi [as 别名]
def albrecht_4():
    sqrt111 = sqrt(111)
    rho1, rho2 = sqrt((96 - pm_ * 4 * sqrt(111)) / 155)

    alpha = 2 * numpy.arange(6) * pi / 6
    s = numpy.array([cos(alpha), sin(alpha)]).T

    alpha = (2 * numpy.arange(6) + 1) * pi / 6
    t = numpy.array([cos(alpha), sin(alpha)]).T

    B0 = frac(251, 2304)
    B1, B2 = (110297 + pm_ * 5713 * sqrt111) / 2045952
    C = frac(125, 3072)

    data = [(B0, z(2)), (B1, rho1 * s), (B2, rho2 * s), (C, sqrt(frac(4, 5)) * t)]

    points, weights = untangle(data)
    return S2Scheme("Albrecht 4", weights, points, 9, _source) 
开发者ID:nschloe,项目名称:quadpy,代码行数:20,代码来源:_albrecht.py

示例8: hammer_stroud_18

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import pi [as 别名]
def hammer_stroud_18():
    # ENH The article only gives floats, but really this is the spherical-product gauss
    # formula as described in Strouds book, S2 7-2.
    #
    # data = [
    #     (frac(1, 16), fs([0.4247082002778669, 0.1759198966061612])),
    #     (frac(1, 16), fs([0.8204732385702833, 0.3398511429799874])),
    # ]
    r1, r2 = sqrt((3 - pm_ * sqrt(3)) / 6)

    a = (2 * numpy.arange(8) + 1) * pi / 8
    x = numpy.array([cos(a), sin(a)]).T

    data = [(frac(1, 16), r1 * x), (frac(1, 16), r2 * x)]
    points, weights = untangle(data)
    return S2Scheme("Hammer-Stroud 18", weights, points, 7, _source) 
开发者ID:nschloe,项目名称:quadpy,代码行数:18,代码来源:_hammer_stroud.py

示例9: hammer_stroud_21

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import pi [as 别名]
def hammer_stroud_21():
    alpha0 = 0.0341505695624825 / numpy.pi
    alpha1 = 0.0640242008621985 / numpy.pi
    alpha2 = 0.0341505695624825 / numpy.pi

    data = [
        (alpha0, fs([0.2584361661674054, 0.0514061496288813])),
        (alpha1, fs([0.5634263397544869, 0.1120724670846205])),
        (alpha1, fs([0.4776497869993547, 0.3191553840796721])),
        (alpha1, fs([0.8028016728473508, 0.1596871812824163])),
        (alpha1, fs([0.6805823955716280, 0.4547506180649039])),
        (alpha2, fs([0.2190916025980981, 0.1463923286035535])),
        (alpha2, fs([0.9461239423417719, 0.1881957532057769])),
        (alpha2, fs([0.8020851487551318, 0.5359361621905023])),
    ]

    points, weights = untangle(data)
    return S2Scheme("Hammer-Stroud 21", weights, points, 15, _source) 
开发者ID:nschloe,项目名称:quadpy,代码行数:20,代码来源:_hammer_stroud.py

示例10: chebyshev_gauss_1

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import pi [as 别名]
def chebyshev_gauss_1(n, mode="numpy"):
    """Chebyshev-Gauss quadrature for \\int_{-1}^1 f(x) / sqrt(1+x^2) dx.
    """
    degree = n if n % 2 == 1 else n + 1

    if mode == "numpy":
        points = numpy.cos((2 * numpy.arange(1, n + 1) - 1) / (2 * n) * numpy.pi)
        weights = numpy.full(n, numpy.pi / n)
    elif mode == "sympy":
        points = numpy.array(
            [
                sympy.cos(sympy.Rational(2 * k - 1, 2 * n) * sympy.pi)
                for k in range(1, n + 1)
            ]
        )
        weights = numpy.full(n, sympy.pi / n)
    else:
        assert mode == "mpmath"
        points = numpy.array(
            [mp.cos(mp.mpf(2 * k - 1) / (2 * n) * mp.pi) for k in range(1, n + 1)]
        )
        weights = numpy.full(n, mp.pi / n)
    return C1Scheme("Chebyshev-Gauss 1", degree, weights, points) 
开发者ID:nschloe,项目名称:quadpy,代码行数:25,代码来源:_chebyshev_gauss.py

示例11: integrate_monomial_over_unit_nsphere

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import pi [as 别名]
def integrate_monomial_over_unit_nsphere(k, symbolic=False):
    frac = sympy.Rational if symbolic else lambda a, b: a / b
    if any(a % 2 == 1 for a in k):
        return 0

    n = len(k)
    if all(a == 0 for a in k):
        return volume_nsphere(n - 1, symbolic, r=1)

    # find first nonzero
    idx = next(i for i, j in enumerate(k) if j > 0)
    alpha = frac(k[idx] - 1, sum(k) + n - 2)
    k2 = k.copy()
    k2[idx] -= 2
    return integrate_monomial_over_unit_nsphere(k2, symbolic) * alpha


# n sqrt(pi) ** 2 / gamma(n/2 + 1) 
开发者ID:nschloe,项目名称:quadpy,代码行数:20,代码来源:_helpers.py

示例12: _format_exponent_as_angle

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import pi [as 别名]
def _format_exponent_as_angle(
            self,
            args: 'protocols.CircuitDiagramInfoArgs',
            order: int = 2,
    ) -> str:
        """Returns string with exponent expressed as angle in radians.

        Args:
            args: CircuitDiagramInfoArgs describing the desired drawing style.
            order: Exponent corresponding to full rotation by 2π.

        Returns:
            Angle in radians corresponding to the exponent of self and
            formatted according to style described by args.
        """
        exponent = self._diagram_exponent(args, ignore_global_phase=False)
        pi = sympy.pi if protocols.is_parameterized(exponent) else np.pi
        return args.format_radians(radians=2 * pi * exponent / order)

    # virtual method 
开发者ID:quantumlib,项目名称:Cirq,代码行数:22,代码来源:eigen_gate.py

示例13: __repr__

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import pi [as 别名]
def __repr__(self) -> str:
        if self._global_shift == -0.5:
            if protocols.is_parameterized(self._exponent):
                return 'cirq.rz({})'.format(
                    proper_repr(sympy.pi * self._exponent))

            return 'cirq.rz(np.pi*{!r})'.format(self._exponent)
        if self._global_shift == 0:
            if self._exponent == 0.25:
                return 'cirq.T'
            if self._exponent == -0.25:
                return '(cirq.T**-1)'
            if self._exponent == 0.5:
                return 'cirq.S'
            if self._exponent == -0.5:
                return '(cirq.S**-1)'
            if self._exponent == 1:
                return 'cirq.Z'
            return '(cirq.Z**{})'.format(proper_repr(self._exponent))
        return (
            'cirq.ZPowGate(exponent={}, '
            'global_shift={!r})'
        ).format(proper_repr(self._exponent), self._global_shift) 
开发者ID:quantumlib,项目名称:Cirq,代码行数:25,代码来源:common_gates.py

示例14: _apply_unitary_

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import pi [as 别名]
def _apply_unitary_(self, args: 'protocols.ApplyUnitaryArgs'
                       ) -> Optional[np.ndarray]:
        if protocols.is_parameterized(self):
            return NotImplemented

        c = np.cos(np.pi * self._exponent / 2)
        s = np.sin(np.pi * self._exponent / 2)
        f = np.exp(2j * np.pi * self._phase_exponent)
        matrix = np.array([[c, 1j * s * f], [1j * s * f.conjugate(), c]])

        zo = args.subspace_index(0b01)
        oz = args.subspace_index(0b10)
        linalg.apply_matrix_to_slices(args.target_tensor,
                                      matrix, [oz, zo],
                                      out=args.available_buffer)
        return args.available_buffer 
开发者ID:quantumlib,项目名称:Cirq,代码行数:18,代码来源:phased_iswap_gate.py

示例15: _pauli_expansion_

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import pi [as 别名]
def _pauli_expansion_(self) -> value.LinearDict[str]:
        if self._is_parameterized_():
            return NotImplemented
        expansion = protocols.pauli_expansion(self._iswap)
        assert set(expansion.keys()).issubset({'II', 'XX', 'YY', 'ZZ'})
        assert np.isclose(expansion['XX'], expansion['YY'])

        v = (expansion['XX'] + expansion['YY']) / 2
        phase_angle = np.pi * self.phase_exponent
        c, s = np.cos(2 * phase_angle), np.sin(2 * phase_angle)

        return value.LinearDict({
            'II': expansion['II'],
            'XX': c * v,
            'YY': c * v,
            'XY': s * v,
            'YX': -s * v,
            'ZZ': expansion['ZZ'],
        }) 
开发者ID:quantumlib,项目名称:Cirq,代码行数:21,代码来源:phased_iswap_gate.py


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