Beispiel #1
0
def main1():
    S = PolynomialRing(GF(Integer(13)), names=('x',))
    (x,) = S.gens()
    R = S.quotient(x**Integer(2) - Integer(3), names=('alpha',))
    (alpha,) = R.gens()
    print((Integer(2) + Integer(3) * alpha)
          * (Integer(1) + Integer(2) * alpha))
Beispiel #2
0
def dict_to_pol(dct, bd=global_prec, base_ring=QQ):
    R = PolynomialRing(base_ring, "u1, u2, q1, q2")
    (u1, u2, q1, q2) = R.gens()
    S = R.quotient(u1 * u2 - 1)
    (uu1, uu2, qq1, qq2) = S.gens()

    l = PrecisionDeg2(bd)
    if not hasattr(dct, "__getitem__"):
        return dct
    return sum([dct[(n, r, m)] * uu1 ** r * qq1 ** n * qq2 ** m
                if r > 0 else dct[(n, r, m)]
                * uu2 ** (-r) * qq1 ** n * qq2 ** m for n, r, m in l])
Beispiel #3
0
def pol_to_dict(pl, bd=global_prec, base_ring=QQ):
    R = PolynomialRing(base_ring, "u1,u2,q1,q2")
    (u1, u2, q1, q2) = R.gens()
    S = R.quotient(u1 * u2 - 1)
    (uu1, uu2, qq1, qq2) = S.gens()
    l = PrecisionDeg2(bd)
    pl_lft = pl.lift()
    dct = dict()
    for n, r, m in l:
        if r >= 0:
            cfs = pl_lft.coefficient({u1: r, u2: 0, q1: n, q2: m})
        else:
            cfs = pl_lft.coefficient({u1: 0, u2: -r, q1: n, q2: m})
        dct[(n, r, m)] = cfs
    for t in l:
        if not t in dct.keys():
            dct[t] = 0
    return dct
Beispiel #4
0
def find_sqrt(a, p):
    assert (p - Integer(1)) % Integer(4) == Integer(0)
    assert legendre_symbol(a, p) == Integer(1)

    S = PolynomialRing(GF(p), names=('x',))
    (x,) = S.gens()
    R = S.quotient(x**Integer(2) - a, names=('alpha',))
    (alpha,) = R.gens()

    while True:
        z = GF(p).random_element()
        w = (Integer(1) + z * alpha)**((p - Integer(1)) // Integer(2))
        (u, v) = (w[Integer(0)], w[Integer(1)])
        if v != Integer(0):
            break

    if (-u / v)**Integer(2) == a:
        return -u / v
    if ((Integer(1) - u) / v)**Integer(2) == a:
        return (Integer(1) - u) / v
    if ((-Integer(1) - u) / v)**Integer(2) == a:
        return (-Integer(1) - u) / v