コード例 #1
0
def fast_findanalytic_BT_newton(x,
                                y,
                                xp,
                                yp,
                                q,
                                weights,
                                r_y,
                                final_run=False):
    y = quaternion.as_float_array(y)[:, 1:]
    H = np.zeros((6, 6))
    h_bb = 8 * np.einsum('ij,mj,kl->imkl', x, y, np.eye(3)) - 4 * \
        np.einsum('ij,mk->imjk', x, y)-4 * np.einsum('ij,mk->imkj', x, y)
    H[:3, :3] = np.einsum('ij,ijkl->kl', weights, h_bb)
    h_bt = 4 * np.einsum(
        'ij,klj->ikl', y,
        np.array([[[LeviCivita(i, j, k) for k in range(3)] for j in range(3)]
                  for i in range(3)],
                 dtype=np.double))
    H[:3, 3:] = np.einsum('ij,jkl->kl', weights, h_bt)
    H[3:, 3:] = 2 * np.eye(3) * np.sum(weights)
    H[3:, :3] = np.transpose(H[:3, 3:])
    L = np.zeros(6)
    l = np.zeros((len(xp), len(xp), 6))
    l[:, :, :3] = 4 * np.einsum(
        'ik,jl,mkl->ijm', x, y,
        np.array([[[LeviCivita(i, j, k) for k in range(3)] for j in range(3)]
                  for i in range(3)],
                 dtype=np.double))
    l[:, :,
      3:] = 2 * (np.reshape(np.hstack(len(x) * [x]), (len(x), len(x), 3)) -
                 np.reshape(np.vstack(len(y) * [y]), (len(y), len(y), 3)))
    L = np.einsum('ij,ijk->k', weights, l)
    if final_run:
        dLdrx = np.zeros((len(x), 6))
        dLdrx[:, :3] = 4 * np.einsum(
            'ij,ik,jl,mkl->im', weights, xp, y,
            np.array([[[LeviCivita(i, j, k) for k in range(3)]
                       for j in range(3)] for i in range(3)],
                     dtype=np.double))
        dLdrx[:, 3:] = 2 * np.einsum('ij,ik->ik', weights, xp)
        ytilde = quaternion.as_float_array(
            [q * np.quaternion(*yi) * np.conjugate(q) for yi in yp])[:, 1:]
        dLdry = np.zeros((len(y), 6))
        dLdry[:, :3] = 4 * np.einsum(
            'ij,ik,jl,mkl->jm', weights, x, ytilde,
            np.array([[[LeviCivita(i, j, k) for k in range(3)]
                       for j in range(3)] for i in range(3)],
                     dtype=np.double))
        dLdry[:, 3:] = -2 * np.einsum('ij,jk->jk', weights, ytilde)
        return -np.linalg.inv(H) @ L, l, dLdrx, dLdry, np.linalg.inv(H)
    return -np.linalg.inv(H) @ L
コード例 #2
0
def OP3(in_state, in_state_norm):
    # f_abc ε_ijk (A_ia * A†_jb * A†_kc) | in state, in_state_norm >
    # For ex: Operator 3 on 2 on vac
    # f_abc ε_ijk (A_ia * A†_jb * A†_kc)
    # f_584 ε_321 (A_35 * A†_28 * A†_14)
    # -sqrt(3)/2 (A_35 * A†_28 * A†_14) | O2state >
    num = 0

    for i, a in itertools.product(range(3), range(dimG)):
        for j, b in itertools.product(range(3), range(dimG)):
            for k, c in itertools.product(range(3), range(dimG)):

                tmp = fSU3((a, b, c)) * LeviCivita(i, j, k)
                if tmp != 0:

                    O3state[num] = in_state[num]
                    O3norm[num] = in_state_norm[num]

                    O3state[num], O3norm[num] = action_A_or_Adag(
                        (k, c), O3state[num], O3norm[num], 1)
                    O3state[num], O3norm[num] = action_A_or_Adag(
                        (j, b), O3state[num], O3norm[num], 1)
                    O3state[num], O3norm[num] = action_A_or_Adag(
                        (i, a), O3state[num], O3norm[num], 0)
                    O3norm[num] *= tmp
                    num += 1

    return O3state, O3norm
コード例 #3
0
def OP2(in_state, in_state_norm):
    # O2 | . > = f_abc ε_ijk (A†_ia * A†_jb * A†_kc) | in state, in_state_norm >
    # Note that out of possible 8^3 x 27 = 512 x 27 = 13824  combinations
    # of a,b,c,i,j,k -- only 324 (=6 x 54) are non-zero!

    st_num = 0
    for i, a in itertools.product(range(3), range(dimG)):
        for j, b in itertools.product(range(3), range(dimG)):
            for k, c in itertools.product(range(3), range(dimG)):

                tmp = fSU3((a, b, c)) * LeviCivita(i, j, k)
                if tmp != 0:

                    O2state[st_num] = in_state
                    O2norm[st_num] = in_state_norm
                    O2state[st_num], O2norm[st_num] = action_A_or_Adag(
                        (k, c), O2state[st_num], O2norm[st_num], 1)
                    O2state[st_num], O2norm[st_num] = action_A_or_Adag(
                        (j, b), O2state[st_num], O2norm[st_num], 1)
                    O2state[st_num], O2norm[st_num] = action_A_or_Adag(
                        (i, a), O2state[st_num], O2norm[st_num], 1)
                    O2norm[st_num] *= tmp
                    st_num += 1

    return O2state, O2norm
コード例 #4
0
def fast_findanalytic_R(q, t, weights, xp, yp, hdx_R, hdy_R, hnd_raw_R):
    q = quaternion.as_float_array(q)
    t = quaternion.as_float_array(t)[1:]
    a = 2 * np.arccos(q[0])
    if a != 0:
        u = q[1:] / np.sin(a / 2)
    else:
        u = np.array([0, 0, 0])
    angle_mat = (np.cos(a) - 1) * np.einsum('i,j->ij', u, u)\
        + np.sin(a) * np.einsum('ijk,k->ij', np.array([[[LeviCivita(i, j, k) for k in range(3)] for j in range(3)] for i in range(3)], dtype=np.double), u)\
        - np.cos(a) * np.eye(3)
    hnd_R = 2 * np.einsum('ijkl,kl->ij', hnd_raw_R, angle_mat)
    Hdx_R = np.einsum('i,ij->i', hdx_R, weights)
    Hdy_R = np.einsum('i,ji->i', hdy_R, weights)
    #Hnd_R= np.array([hnd_R[f(ind)] *weights(ind) for ind,_ in np.denumerate(weights)])
    Hnd_R = hnd_R * weights
    Hnd_R_inv = (np.linalg.inv(((Hnd_R / Hdy_R) @ np.transpose(Hnd_R)) -
                               np.diag(Hdx_R)) @ Hnd_R) / Hdy_R
    Hdy_R_inv = np.einsum('i,ij->ij', 1 / Hdy_R,
                          np.eye(len(xp)) - np.transpose(Hnd_R) @ Hnd_R_inv)
    Hdx_R_inv = np.einsum('i,ij->ij', 1 / Hdx_R,
                          np.eye(len(xp)) - Hnd_R @ np.transpose(Hnd_R_inv))
    l_x = 2 * np.einsum('ij,j->i', xp, t)
    l_y_vec = t * np.cos(a) + (u @ t) * (1 - np.cos(a)) * \
        u + np.sin(a) * np.cross(t, u)
    l_y = -2 * np.einsum('ij,j->i', yp, l_y_vec)
    L_x = np.einsum('ij,i->i', weights, l_x)
    L_y = np.einsum('ji,i->i', weights, l_y)
    r_x = -Hdx_R_inv @ L_x - Hnd_R_inv @ L_y
    r_y = -L_x @ Hnd_R_inv - Hdy_R_inv @ L_y
    return r_x, r_y, hnd_R, l_x, l_y, Hdx_R_inv, Hdy_R_inv, Hnd_R_inv
コード例 #5
0
ファイル: geometry2.py プロジェクト: Mschkin/slam
def get_rs(q, t, weights_not_normd, xp, yp, hdx_R, hdy_R, hnd_raw_R):
    weights = weights_not_normd * weights_not_normd / np.sum(
        weights_not_normd * weights_not_normd)
    q = quaternion.as_float_array(q)
    t = quaternion.as_float_array(t)[1:]
    a = 2 * np.arccos(q[0])
    if a != 0:
        u = q[1:] / np.sin(a / 2)
    else:
        u = np.array([0, 0, 0])
    angle_mat = (np.cos(a) - 1) * np.einsum('i,j->ij', u, u)\
        - np.sin(a) * np.einsum('ijk,k->ij', np.array([[[LeviCivita(i, j, k) for k in range(3)] for j in range(3)] for i in range(3)], dtype=np.double), u)\
        - np.cos(a) * np.eye(3)
    hnd_R = np.einsum('ijkl,kl->ij', hnd_raw_R, angle_mat)
    Hdx_R = np.einsum('j,ij->j', hdx_R, weights)
    Hdy_R = np.einsum('i,ij->i', hdy_R, weights)
    #Hnd_R= np.array([hnd_R[f(ind)] *weights(ind) for ind,_ in np.denumerate(weights)])
    Hnd_R = hnd_R * weights

    l_x = np.einsum('ij,j->i', xp, t)
    l_y_vec = t * np.cos(a) + (u@t) * (1 - np.cos(a)) * \
        u + np.sin(a) * np.cross(t, u)
    l_y = -np.einsum('ij,j->i', yp, l_y_vec)
    L_x = np.einsum('ij,j->j', weights, l_x)
    L_y = np.einsum('ij,i->i', weights, l_y)
    hnd_inter = ((Hnd_R / Hdx_R) @ np.transpose(Hnd_R) - np.diag(Hdy_R))
    inv = np.linalg.inv((Hnd_R / Hdx_R) @ np.transpose(Hnd_R) - np.diag(Hdy_R))
    Y = inv @ Hnd_R / Hdx_R
    ry = inv @ L_y - Y @ L_x
    rx = np.diag(-1 / Hdx_R) @ np.transpose(Hnd_R) @ ry - L_x / Hdx_R
    """
    #print('zero:',np.diag(Hdy_R) @ ry + Hnd_R @ rx + L_y)
    #print('zero:', np.transpose(Hnd_R) @ ry + np.diag(Hdx_R) @ rx + L_x)
    X = -inv
    Z = np.diag(1 / Hdx_R) @ (np.eye(len(Hdx_R)) - np.transpose(Hnd_R) @ Y)
    drydG = np.einsum('ij,j,j,k->ijk', X, hdy_R, -ry, np.ones_like(rx)) \
        + np.einsum('ij,jk,k->ijk', X, hnd_R, -rx) \
        + np.einsum('ik,jk,j->ijk', Y, hnd_R, -ry) \
        + np.einsum('ik,k,k,j->ijk', Y, hdx_R, -rx, np.ones_like(rx)) \
        - np.einsum('ji,j,k->ijk', X, l_y, np.ones_like(rx)) \
        - np.einsum('ik,k,j->ijk', Y, l_x, np.ones_like(rx))
    drxdG = np.einsum('ji,j,j,k->ijk', Y, hdy_R, -ry, np.ones_like(rx)) \
        + np.einsum('ji,jk,k->ijk', Y, hnd_R, -rx) \
        + np.einsum('ik,jk,j->ijk', Z, hnd_R, -ry) \
        + np.einsum('ik,k,k,j->ijk', Z, hdx_R, -rx, np.ones_like(rx)) \
        - np.einsum('ji,j,k->ijk', Y, l_y, np.ones_like(rx)) \
        - np.einsum('ik,k,j->ijk', Z, l_x, np.ones_like(rx))
    dG_dg = 2 / np.sum(weights_not_normd * weights_not_normd) * np.einsum('im,jn,ij->ijmn', np.eye(len(xp)), np.eye(len(xp)), weights_not_normd)\
            - 2 / np.sum(weights_not_normd * weights_not_normd)** 2 * np.einsum('ij,mn->ijmn', weights_not_normd ** 2, weights_not_normd)
    drxdg = np.einsum('ijk,jkmn->imn', drxdG, dG_dg)
    drydg = np.einsum('ijk,jkmn->imn', drydG, dG_dg)
    """
    return rx, ry
コード例 #6
0
ファイル: geometry2.py プロジェクト: Mschkin/slam
def r_with_reduced_weights(q, t, weights_not_normd, xp, yp, hdx_R, hdy_R,
                           hnd_raw_R):
    q = quaternion.as_float_array(q)
    t = quaternion.as_float_array(t)[1:]
    a = 2 * np.arccos(q[0])
    if a != 0:
        u = q[1:] / np.sin(a / 2)
    else:
        u = np.array([0, 0, 0])
    angle_mat = (np.cos(a) - 1) * np.einsum('i,j->ij', u, u)\
        + np.sin(a) * np.einsum('ijk,k->ij', np.array([[[LeviCivita(i, j, k) for k in range(3)] for j in range(3)] for i in range(3)], dtype=np.double), u)\
        - np.cos(a) * np.eye(3)
    hnd_R = 2 * np.einsum('ijkl,kl->ij', hnd_raw_R, angle_mat)
コード例 #7
0
ファイル: vectores.py プロジェクト: medicendav/python
def componenteProdVectorial(x, y, l):

    e = np.zeros((3, 3, 3))

    for i in range(0, n + 1):
        for j in range(0, n + 1):
            for k in range(0, n + 1):
                e[i, j, k] = LeviCivita(i, j, k)

    cont = 0
    for a in range(0, n):
        for b in range(0, n + 1):
            cont = cont + x[a] * y[b] * e[a, b, l]
    return cont
コード例 #8
0
def fast_findanalytic_BT(x, y, weights):
    y = quaternion.as_float_array(y)[:, 1:]
    H = np.zeros((6, 6))
    h_bb = 8 * np.einsum('ij,ij,kl->ikl', y, y, np.eye(3)) - \
        8 * np.einsum('ij,ik->ijk', y, y)
    H[:3, :3] = np.einsum('ij,jkl->kl', weights, h_bb)
    h_bt = 4 * np.einsum(
        'ij,klj->ikl', y,
        np.array([[[LeviCivita(i, j, k) for k in range(3)] for j in range(3)]
                  for i in range(3)],
                 dtype=np.double))
    H[:3, 3:] = np.einsum('ij,jkl->kl', weights, h_bt)
    H[3:, 3:] = 2 * np.eye(3) * np.sum(weights)
    H[3:, :3] = np.transpose(H[:3, 3:])
    L = np.zeros(6)
    L[:3] = 4 * np.einsum(
        'ij,ik,jl,mkl->m', weights, x, y,
        np.array([[[LeviCivita(i, j, k) for k in range(3)] for j in range(3)]
                  for i in range(3)],
                 dtype=np.double))
    L[3:] = 2 * np.einsum('ij,ik->k', weights, x) - 2 * \
        np.einsum('ij,jk->k', weights, y)
    return -np.linalg.inv(H) @ L
コード例 #9
0
def test_su():
    su2 = SU(2)

    assert su2.dimension == 2
    assert su2.group == "SU"

    assert su2.generators() == [
        Matrix([[0, 1], [1, 0]]) / 2,
        Matrix([[0, -I], [I, 0]]) / 2,
        Matrix([[1, 0], [0, -1]]) / 2
    ]

    assert su2.algebra == A(1)

    for i in range(3):
        for j in range(3):
            for k in range(3):
                assert su2.structure_constants(i, j, k) == LeviCivita(i, j, k)

    for n in range(2, 5):
        g = SU(n)
        assert g.quadratic_casimir(n) == sympify(n**2 - 1) / sympify(2 * n)
コード例 #10
0
ファイル: leviCivita.py プロジェクト: medicendav/python
import numpy as np
from sympy import Eijk, LeviCivita

e = np.zeros((3, 3, 3))

for i in range(3):
    for j in range(3):
        for k in range(3):
            e[i, j, k] = LeviCivita(i, j, k)

print(e[0, 1, 2])
コード例 #11
0
def test_levicivita():
    assert Eijk(1, 2, 3) == LeviCivita(1, 2, 3)
    assert LeviCivita(1, 2, 3) == 1
    assert LeviCivita(long(1), long(2), long(3)) == 1
    assert LeviCivita(1, 3, 2) == -1
    assert LeviCivita(1, 2, 2) == 0
    i, j, k = symbols('i j k')
    assert LeviCivita(i, j, k) == LeviCivita(i, j, k, evaluate=False)
    assert LeviCivita(i, j, i) == 0
    assert LeviCivita(1, i, i) == 0
    assert LeviCivita(i, j, k).doit() == (j - i)*(k - i)*(k - j)/2
    assert LeviCivita(1, 2, 3, 1) == 0
    assert LeviCivita(4, 5, 1, 2, 3) == 1
    assert LeviCivita(4, 5, 2, 1, 3) == -1

    assert LeviCivita(i, j, k).is_integer is True

    assert adjoint(LeviCivita(i, j, k)) == LeviCivita(i, j, k)
    assert conjugate(LeviCivita(i, j, k)) == LeviCivita(i, j, k)
    assert transpose(LeviCivita(i, j, k)) == LeviCivita(i, j, k)
コード例 #12
0
def test_levicivita():
    assert Eijk(1, 2, 3) == LeviCivita(1, 2, 3)
    assert LeviCivita(1, 2, 3) == 1
    assert LeviCivita(1, 3, 2) == -1
    assert LeviCivita(1, 2, 2) == 0
    i, j, k = symbols('i j k')
    assert LeviCivita(i, j, k) == LeviCivita(i, j, k, evaluate=False)
    assert LeviCivita(i, j, i) == 0
    assert LeviCivita(1, i, i) == 0
    assert LeviCivita(i, j, k).doit() == (j - i) * (k - i) * (k - j) / 2
    assert LeviCivita(1, 2, 3, 1) == 0
    assert LeviCivita(4, 5, 1, 2, 3) == 1
    assert LeviCivita(4, 5, 2, 1, 3) == -1
コード例 #13
0
ファイル: permutaciones.py プロジェクト: medicendav/python
from sympy import Eijk, LeviCivita
from numpy.random import permutation

print(LeviCivita(3, 1, 2))
print(Eijk(3, 1, 2, 5, 4))
コード例 #14
0
L = L.expand(basic=true)
L.factor(v)
pprint(L)

# massa do boson Z
M = Matrix([[g1**2 / 4, -g1 * g2 / 2], [-g1 * g2 / 2, g2**2]])
M.det()
valores = M.eigenvals()
a_vet = Matrix([[Z], [A]])

a_va = Matrix([[valores.items()[0][0], 0], [0, valores.items()[1][0]]])
v**2 / 2 * a_vet.transpose() * a_va * a_vet

L = L.subs(B3, -Z * g1 / 2 - A * g2).expand(basic=true)
L = L.subs(C, Z * g2 - A * g1 / 2).expand(basic=true)

MO = 1 / sqrt(g1**2 / 4 + g2**2) * Matrix([[-g1 / 2, g2], [-g2, -g1 / 2]])
pprint(L)

#setor gauge FF
Bnu1, Bnu2, Bnu3 = symbols("{B_nu_1}, {B_nu_2}, {B_nu_3}")
Bmu = [B1, B2, B3]
Bnu = [Bnu1, Bnu2, Bnu3]

a = 1
G = sum([
    sum([LeviCivita(a, b, c) * Bmu[b] * Bnu[c] for b in range(3)])
    for c in range(3)
])
pprint(G)