Esempio n. 1
0
def recursivelyUpdateB(lamb, phi, B, n):
    psi = phi // 2

    for beta in range(2**(n - lamb)):
        B[lamb - 1, idx(psi, 2 * beta, lamb -
                        1)] = (B[lamb, idx(phi - 1, beta, lamb)]
                               ^ B[lamb, idx(phi, beta, lamb)])
        B[lamb - 1, idx(psi, 2 * beta + 1, lamb - 1)] = B[lamb,
                                                          idx(phi, beta, lamb)]

    if psi % 2 == 1:
        recursivelyUpdateB(lamb - 1, psi, B, n)
Esempio n. 2
0
def recursivlyCalcP(lamb, phi, P, B, n):
    if lamb == 0:
        return


#    print(f"RCP ({n - lamb}, {phi})")
    psi = phi // 2
    if phi % 2 == 0:
        recursivlyCalcP(lamb - 1, psi, P, B, n)

    for beta in range(2**(n - lamb)):
        idx_main = beta
        idx0 = 2 * beta
        idx1 = 2 * beta + 1

        if phi % 2 == 0:
            P[lamb, idx_main] = f_op_p1(P[lamb - 1, idx0], P[lamb - 1, idx1])
            P[lamb, idx_main] /= (P[lamb, idx_main, 0] + P[lamb, idx_main, 1])

        else:
            u_dot = B[lamb, idx(phi - 1, beta, lamb)]

            P[lamb, idx_main] = g_op_p1(P[lamb - 1, idx0], P[lamb - 1, idx1],
                                        u_dot)
            P[lamb, idx_main] /= (P[lamb, idx_main, 0] + P[lamb, idx_main, 1])
Esempio n. 3
0
def recursivelyUpdateB_debug(lamb, phi, B, n, B_idx):
    psi = phi // 2

#    print(f"RCB ({lamb}, {phi})")
    for beta in range(2**(n - lamb)):
        B[lamb - 1, idx(psi, 2 * beta,     lamb - 1)] = (B[lamb, idx(phi - 1, beta, lamb)] ^
                                                         B[lamb, idx(phi    , beta, lamb)])
        B[lamb - 1, idx(psi, 2 * beta + 1, lamb - 1)] =  B[lamb, idx(phi,     beta, lamb)]

        print(f"B[{lamb-1},{idx(psi, 2 * beta,     lamb - 1)}] = B[{lamb}, {idx(phi - 1, beta, lamb)}] ^ B[{lamb}, {idx(phi, beta, lamb)}]")
        print(f"B[{lamb-1},{idx(psi, 2 * beta + 1, lamb - 1)}] = B[{lamb}, {idx(phi, beta, lamb)}]")

        B_idx[lamb - 1, idx(psi, 2 * beta,     lamb - 1)] = (B_idx[lamb, idx(phi - 1, beta, lamb)] +
                                                             B_idx[lamb, idx(phi    , beta, lamb)])
        B_idx[lamb - 1, idx(psi, 2 * beta + 1, lamb - 1)] =  B_idx[lamb, idx(phi,     beta, lamb)]


    if psi % 2 == 1:
        recursivelyUpdateB_debug(lamb - 1, psi, B, n, B_idx)
Esempio n. 4
0
def recursivlyCalcP_debug(lamb, phi, P, B, n):
    if lamb == 0:
        return

#    print(f"RCP ({lamb}, {phi})")

    psi = phi // 2
    if phi % 2 == 0:
        recursivlyCalcP_debug(lamb - 1, psi, P, B, n)

    for beta in range(2**(n - lamb)):
        idx0 = 2*beta
        idx1 = 2*beta + 1

        if phi % 2 == 0:
            P[lamb, beta] = f_op_llr(P[lamb - 1, idx0], P[lamb - 1, idx1])
            print(f"P[{lamb},{beta}] <= f(P[{lamb-1},{idx0}], P[{lamb-1},{idx1}])")

        else:
            u_dot = B[lamb, idx(phi-1, beta, lamb)]
            P[lamb, beta] = g_op_llr(P[lamb - 1, idx0], P[lamb - 1, idx1], u_dot)
            print(f"P[{lamb},{beta}] <= g(P[{lamb-1},{idx0}], P[{lamb-1},{idx1}], B[{lamb}, {idx(phi-1, beta, lamb)}])")
Esempio n. 5
0
def recursivlyCalcP_llr(lamb, phi, P, B, n, use_f_exact=False):
    if lamb == 0:
        return

#    print(f"RCP ({lamb}, {phi})")

    psi = phi // 2
    if phi % 2 == 0:
        recursivlyCalcP_llr(lamb - 1, psi, P, B, n)

    for beta in range(2**(n - lamb)):
        idx0 = 2*beta
        idx1 = 2*beta + 1

        if phi % 2 == 0:
            if use_f_exact:
                P[lamb, beta] = f_op_exact(P[lamb - 1, idx0], P[lamb - 1, idx1])
            else:
                P[lamb, beta] = f_op_llr(P[lamb - 1, idx0], P[lamb - 1, idx1])

        else:
            u_dot = B[lamb, idx(phi-1, beta, lamb)]
            P[lamb, beta] = g_op_llr(P[lamb - 1, idx0], P[lamb - 1, idx1], u_dot)