本文整理汇总了Python中sympy.re方法的典型用法代码示例。如果您正苦于以下问题:Python sympy.re方法的具体用法?Python sympy.re怎么用?Python sympy.re使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy
的用法示例。
在下文中一共展示了sympy.re方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: qubo_to_matrix
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import re [as 别名]
def qubo_to_matrix(self,qubo):
try:
import sympy
except ImportError:
raise ImportError("optm() requires sympy. Please install before call this function.")
qubo = self.expand_qubo(qubo)
numN = len(qubo.free_symbols)
optm = np.zeros((numN,numN))
for i in qubo.free_symbols:
for j in qubo.free_symbols:
if(i!=j):
optm[int(repr(i)[1:])][int(repr(j)[1:])] = qubo.coeff(i*j)
else:
f2 =sympy.re(qubo.coeff(i))
for k in qubo.free_symbols:
f2 = f2.subs(k,0)
optm[int(repr(i)[1:])][int(repr(i)[1:])] = f2
return np.triu(optm)
示例2: test_WignerDRecursion_accuracy
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import re [as 别名]
def test_WignerDRecursion_accuracy():
from sympy.physics.quantum.spin import WignerD as sympyWignerD
"""Eq. (29) of arxiv:1403.7698: d^{m',m}_{n}(β) = ϵ(m') ϵ(-m) H^{m',m}_{n}(β)"""
def ϵ(m):
m = np.asarray(m)
eps = np.ones_like(m)
eps[m >= 0] = (-1)**m[m >= 0]
return eps
ell_max = 4
alpha, beta, gamma = 0.0, 0.1, 0.0
hcalc = HCalculator(ell_max)
Hnmpm = hcalc(np.cos(beta))
max_error = 0.0
# errors = np.empty(hcalc.nmpm_total_size)
i = 0
print()
for n in range(hcalc.n_max+1):
print('Testing n={} compared to sympy'.format(n))
for mp in range(-n, n+1):
for m in range(-n, n+1):
sympyd = sympy.re(sympy.N(sympyWignerD(n, mp, m, alpha, -beta, gamma).doit()))
myd = ϵ(mp) * ϵ(-m) * Hnmpm[i]
error = float(min(abs(sympyd+myd), abs(sympyd-myd)))
assert error < 1e-14, "Testing Wigner d recursion: n={}, m'={}, m={}, v1={}, v2={}, error={}".format(n, mp, m, sympyd, myd, error)
max_error = max(error, max_error)
# errors[i] = float(min(abs(sympyd+myd), abs(sympyd-myd)))
# print("{:>5} {:>5} {:>5} {:24} {:24} {:24}".format(n, mp, m, float(sympyd), myd, errors[i]))
i += 1
print("Testing Wigner d recursion: max error = {}".format(max_error))