Section 6.1 Introduction to Primes
ΒΆSubsection 6.1.1 Definitions and examples
ΒΆDefinition 6.1.1.
A positive integer p greater than 1 is called prime if the only positive divisors of p are 1 and p itself.
Definition 6.1.2.
If an integer n>1 is not prime, it is called composite.
-
Is a given number prime?
xxxxxxxxxx
is_prime(6) # Is my number a prime?
-
Is it at least a power of a prime?
xxxxxxxxxx
is_prime_power(25) # Is my number a prime power?
-
List some primes for me!
xxxxxxxxxx
PR = prime_range(100) # What are all primes up to but not including 100?
print(PR)
-
List the first n primes β¦
xxxxxxxxxx
PFN = primes_first_n(100) # What are the first 100 primes?
print(PFN)
-
Give me prime factors.
xxxxxxxxxx
# What are the prime factors of a number?
factor( 2 * 3 * (2*3+1) * (2*3*(2*3+1)+1) * (2*3*(2*3+1)*(2*3*(2*3+1)+1)+1) )
Sage note 6.1.3. Making comments.
Sometimes we might want to have notes about the code included without being actual code. In the Python language, such comments must come after #
signs.
Subsection 6.1.2 Prime fun
ΒΆBefore getting to the serious material, let's have a little fun to start us thinking along the lines of what's to come. For instance, did you ever try to see if there was a formula for primes?xxxxxxxxxx
f(x)=x^2+x+41
def _(n=(0,[0..39])):
pretty_print(html("Is $%s$ for $x=%s$, which is $%s$, a prime number?"%(f(x),n,f(n))))
print(is_prime(f(n)))
xxxxxxxxxx
f(x)=x^2+x+41
f(40)
xxxxxxxxxx
is_prime(f(40)),factor(1681)
Fact 6.1.4.
There is no non-constant polynomial f(x) with integer coefficients such that f(x) is prime for all integers x.
Proof.
What is the reason no such polynomial can exist? It turns out to be directly related to our previous work on congruences. Namely, if \(f(a)=p\) for some \(a\text{,}\) then for any \(b\equiv a\) (mod \(p\)) we have \(f(b)\equiv f(a)\) (mod \(p\)) (by well-definedness of addition and subtraction) as well, so
Since we assume \(f(b)\) is actually prime, then \(f(b)=p\) as well.
But then the problem arises that
which contradicts the well-known calculus fact that all non-constant polynomials have \(\lim_{x\to\infty}f(x)= \infty\text{ or }-\infty\text{.}\) So \(f\) must be constant.
xxxxxxxxxx
g(x)=8*x^2-488*x+7243
for n in [0..30]:
print(g(n),is_prime(g(n)))
xxxxxxxxxx
h(x)=x^6+1091
for n in [0..3906]:
if is_prime(h(n)):
print((n,h(n)))