本文整理匯總了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))