def frobs(K): frob_at_p = residue_field_degrees_function(K) D = K.disc() ans = [] seeram = False for p in primes(2, 60): if not ZZ(p).divides(D): # [3] , [2,1] dec = frob_at_p(p) vals = list(set(dec)) vals = sorted(vals, reverse=True) dec = [[x, dec.count(x)] for x in vals] dec2 = ["$" + str(x[0]) + ('^{' + str(x[1]) + '}$' if x[1] > 1 else '$') for x in dec] s = '$' old = 2 for j in dec: if old == 1: s += '\: ' s += str(j[0]) if j[1] > 1: s += '^{' + str(j[1]) + '}' old = j[1] s += '$' ans.append([p, s]) else: ans.append([p, 'R']) seeram = True return ans, seeram
def frobs(K): frob_at_p = residue_field_degrees_function(K) D = K.disc() ans = [] seeram = False for p in primes(2, 60): if not ZZ(p).divides(D): # [3] , [2,1] dec = frob_at_p(p) vals = list(set(dec)) vals = sorted(vals, reverse=True) dec = [[x, dec.count(x)] for x in vals] dec2 = [ "$" + str(x[0]) + ('^{' + str(x[1]) + '}$' if x[1] > 1 else '$') for x in dec ] s = '$' old = 2 for j in dec: if old == 1: s += '\: ' s += str(j[0]) if j[1] > 1: s += '^{' + str(j[1]) + '}' old = j[1] s += '$' ans.append([p, s]) else: ans.append([p, 'R']) seeram = True return ans, seeram
def frobs(K): frob_at_p = residue_field_degrees_function(K) D = K.disc() ans = [] seeram = False for p in primes(2, 60): if not ZZ(p).divides(D): # [3] , [2,1] dec = frob_at_p(p) vals = list(set(dec)) vals = sorted(vals, reverse=True) dec = [[x, dec.count(x)] for x in vals] dec2 = ["$" + str(x[0]) + ("^{" + str(x[1]) + "}$" if x[1] > 1 else "$") for x in dec] s = "$" firstone = 1 for j in dec: if firstone == 0: s += "{,}\," s += str(j[0]) if j[1] > 1: s += "^{" + str(j[1]) + "}" firstone = 0 s += "$" ans.append([p, s]) else: ans.append([p, "R"]) seeram = True return ans, seeram
def primes_of_bounded_norm_iter(self, B): r""" Iterator yielding all primes less than or equal to `B`. INPUT: - ``B`` -- a positive integer; upper bound on the primes generated. OUTPUT: An iterator over all integer primes less than or equal to `B`. .. note:: This function exists for compatibility with the related number field method, though it returns prime integers, not ideals. EXAMPLES:: sage: it = QQ.primes_of_bounded_norm_iter(10) sage: list(it) [2, 3, 5, 7] sage: list(QQ.primes_of_bounded_norm_iter(1)) [] """ try: B = ZZ(B.ceil()) except (TypeError, AttributeError): raise TypeError("%s is not valid bound on prime ideals" % B) if B < 2: raise StopIteration from sage.rings.arith import primes for p in primes(B + 1): yield p
def has_blum_prime(lbound, ubound): """ Determine whether or not there is a Blum prime within the specified closed interval. INPUT: - ``lbound`` -- positive integer; the lower bound on how small a Blum prime can be. The lower bound must be distinct from the upper bound. - ``ubound`` -- positive integer; the upper bound on how large a Blum prime can be. The lower bound must be distinct from the upper bound. OUTPUT: - ``True`` if there is a Blum prime ``p`` such that ``lbound <= p <= ubound``. ``False`` otherwise. ALGORITHM: Let `L` and `U` be distinct positive integers. Let `P` be the set of all odd primes `p` such that `L \leq p \leq U`. Our main focus is on Blum primes, i.e. odd primes that are congruent to 3 modulo 4, so we assume that the lower bound `L > 2`. The closed interval `[L, U]` has a Blum prime if and only if the set `P` has a Blum prime. EXAMPLES: Testing for the presence of Blum primes within some closed intervals. The interval `[4, 100]` has a Blum prime, the smallest such prime being 7. The interval `[24, 28]` has no primes, hence no Blum primes. :: sage: from sage.crypto.util import has_blum_prime sage: from sage.crypto.util import is_blum_prime sage: has_blum_prime(4, 100) True sage: for n in xrange(4, 100): ... if is_blum_prime(n): ... print n ... break ... 7 sage: has_blum_prime(24, 28) False TESTS: Both the lower and upper bounds must be greater than 2:: sage: from sage.crypto.util import has_blum_prime sage: has_blum_prime(2, 3) Traceback (most recent call last): ... ValueError: Both the lower and upper bounds must be > 2. sage: has_blum_prime(3, 2) Traceback (most recent call last): ... ValueError: Both the lower and upper bounds must be > 2. sage: has_blum_prime(2, 2) Traceback (most recent call last): ... ValueError: Both the lower and upper bounds must be > 2. The lower and upper bounds must be distinct from each other:: sage: has_blum_prime(3, 3) Traceback (most recent call last): ... ValueError: The lower and upper bounds must be distinct. The lower bound must be less than the upper bound:: sage: has_blum_prime(4, 3) Traceback (most recent call last): ... ValueError: The lower bound must be less than the upper bound. """ # sanity checks if (lbound < 3) or (ubound < 3): raise ValueError("Both the lower and upper bounds must be > 2.") if lbound == ubound: raise ValueError("The lower and upper bounds must be distinct.") if lbound > ubound: raise ValueError("The lower bound must be less than the upper bound.") # now test for presence of a Blum prime for p in primes(lbound, ubound + 1): if mod(p, 4).lift() == 3: return True return False