Another Approximation of Square Root of a Prime

SQUARE ROOT OF A PRIME: A MONTE-CARLO APPROXIMATION
MANZIA JAMIL, PARTHA PRATIM DEY
Department of Computer Science
North South University
12 Kemal Ataturk Avenue, Banani, Dhaka
BANGLADESH
Abstract:- In this paper we suggest a method that can be used to approximate square root of an arbitrary prime
number p . The method makes use of Monte Carlo Simulation Technique in order to estimate the probability p es of
the event that a point chosen randomly from the square S  [0, p]  [0, p] in R 2 lies in U  {( x, y  S | y 
x} .
The estimation of p es requires the knowledge of the sample size i.e. the number of points that need to be chosen
from the square S in order for p es to be a reliable estimate of the exact probability p ex of the aforesaid event. In
Section 2, we are able to determine a sample size N , which given an error level r , approximates p ex at
99% confidence. In Section 3, we show that for a given error level e a sample size of N 
obtain an approximation p of
6.6 p 2
is enough to
e2
p satisfying p  p  e .
Key-Words:- Approximation, error, sample, probability, confidence, random, root.
1 Introduction
The necessity for approximation of the square root of a
prime p comes from the fact [1] that p is an
irrational number i.e. it is non-repeating and nonterminating. In this paper we describe a method that
can be successfully implemented to achieve a rational
approximation of the square root of an arbitrary prime
at any desired level of accuracy. The method is
stochastic in nature and among many other things it
uses the Monte Carlo Simulation Method. The term,
Monte Carlo Simulation was coined during World War
II by S. Ulam and J. von Neumann at the Los Alamos
Scientific Laboratory. In order to design nuclear shields
they needed to simulate an experiment, which involves
penetration of neutrons through various materials. The
simulation required the use of random numbers and a
gambling principle practiced in the Casino of Monaco.
That is why the method was code named Monte Carlo.
It consists of picking points at random and counting
those that satisfy certain criteria. The number of points
that are picked is called the sample size of the
simulation.
We
pick
points
from
the
square
2
S  [0, p]  [0, p] in R and count those that lie in
U  {( x, y  S | y  x } . Let N denote the number
of points that are picked and NU the number of those
which come from U . Let p ex be the exact probability
that a point chosen randomly from S lies in U . In
Section 2, we show that for any error level r the
NU
is capable of approximating p ex
N
1.65
such that pes  pex  r if N  2 . In Section 3,
r
e
we show that given an error level e , if r is set at
2p
2
6.6 p
then a sample size of N 
is enough to
e2
2
approximate p by p where p 
.
3 p es
proportion pes 
2 Sample Size that Approximates pex by
pes for an Error Level r
We begin this section with a couple of observations
stated in the form of Lemma (2.1) and Lemma (2.2).
Lemma (2.1). If we pick a point from the
square S  [0, p]  [0, p] , the probability pex that it
comes from U  {( x, y )  S | y 
Notice that
therefore
x } is
2
.
pex 
p
2
1
x
(1 
.
3 p
2
3 x
proof
3 p
2
and
(1 
standard
error
2

), x  0
of
.
asymptotically normal. Below we show how this fact
can be used to approximate pex by pes .
3
16
attains an absolute maximum of
at x 
on the
8
9
interval (0, ) .
The
3 p
)
3 p
3 p 12
pex (1  pex )
 [
] [
] . Moreover
N
N
p  pex
the
standardized
variable
is
Z  es
Lemma (2.2). The function
f ( x) 
2
pex 
mean
1
2

2
2
Then by the Theorem on Sampling Distribution of the
Sample Proportion [2], the sampling distribution of pes
pex = (area of U ) /( area of S ) and
x dx
0
that the point chosen comes from U ) is pex 
has
3 p
p

where the proportion of success (i.e., the probability
this
lemma
is
quite
straightforward. We just observe that as 4  3 x is
16
16
] and negative on [ ,  ) , the same
9
9
is true about f ' ( x)  (4  3 x ) / 6 x 2 . Hence f (x )
16
16
increases on (0, ] and decreases on [ ,  ) , which
9
9
16
proves that x 
is indeed the point of absolute
9
maximum for f (x ) on (0, ) .
positive on (0,
Next we produce a theorem that provides us
with an approximation of p ex .
Theorem (2.3). Suppose we are conducting an
experiment of picking N points randomly from a
square S  [0, p]  [0, p] where p is a given prime
Suppose we want pes to approximate pex with
an assurance of k % at an error level of r . Then
Note
that
k  P( pes  pex  r ) .
P ( p es  p ex  r )  P ( Z  r )  P( Z 
 2 P (0  Z 

)

)
1
r
)  ]  2 P( Z  )  1 .
Then

2

r
1 k
P( Z  ) 
.
For k we
take .99 and

2
r
r
obtain P ( Z  )  .995 . By [3], we get  2.57
 2[ P( Z 
r

i.e.,
to
pes  pex
2 
3 p
(1 
r  6.6(
2
3 p
N
2
2

achieve an assurance of 99% that
 r, we have to have r 2  6.6 2 . As
2
number. Let NU be the number of those points from
N that lie in U  {( x, y  S ) | y  x } . Then for any
N
error level r the proportion pes  U approximates
N
1.65
2
with an assurance of 99% if N  2 .
pex 
r
3 p
r
r
3 p
(1 
N
)
,we
2
3 p
get
)
) and
therefore
4.4 1
2
(
)(1 
).
2
r
p
3 p
As the error level r and sample size N are inversely
N
related, by increasing the sample size we can reduce the
Proof . Note that we are here concerned with a binomial
experiment and our sample comes from a population
error level as low as we wish i.e., pes can be made to
approximate pex as close as one desires. Consequently,
4.4 1
2
any sample of size  N  2 (
)(1 
) , will
r
p
3 p
make the inequality pes  pex  r hold. Recall from
f ( x) 
Lemma (2.1) that
1
x
(1 
2
3 x
) attains an
3
16
at x 
and decreases on
8
9
absolute maximum of
16
,  ) . So for our sample we will choose
9
3 4.4 1.65
a size of N   2  2 . For such a sample
8 r
r
pes  pex  r holds. ■
the interval [
p ex ( p ex  r )  p ex2  p ex r  (
2
3 p
In this section we will be concerned with a sample
size N
that
will
approximation of
be
required
to
find p ,
an
p , within an error level e i.e.
p  p  e . Towards that goal we prove the
2r
3 p
.
Next
4
2r
3
1
2r



(

)
9p 3 p 9p 9p 3 p
1
2r
we claim that

 0 . If the claim holds, then
9p 3 p
clearly
from
above pex ( pex  r ) 
the
equalities
3
1
,and

9 p 3p
1
as pes pex  pex ( pex  r ) .
3p
1
Now we prove our claim. Notice that r 2 
holds
36 p
therefore p es p ex 
as it is a hypothesis of the lemma. We multiply it on
both sides by 4 to obtain 4r 2 
3 Sample Size that Approximates p by
p for an Error Level e
)2 
yields 2r 
by
1
1
1
which in turn
9p
. Now we multiply the last inequality
3 p
to
obtain
3 p
3 p
equivalently
2r

1
or
9p
1
2r

 0 .■
9p 3 p
following lemma.
Lemma (3.1). Suppose we are conducting an
experiment of picking N points randomly from a
square S  [0, p]  [0, p] where p is a given prime
Theorem (3.2). Suppose we are conducting an
experiment of picking N points randomly from a
square S  [0, p]  [0, p] where p is a given prime
number. Let NU be the number of those points from
N that lie in U . Then for any error level e,
2
2
p
approximates p 
with an assurance
3 p es
3 p ex
U  {( x, y  S | y  x } , and
NU
2
let pex and pes be
and
respectively. If
N
3 p
N that
lie
in
1.65
,where
r2
1
then p es p ex 
.
3p
N
r 0
and
r2 
of 99% if N 
N
6.6 p 2
and pes  U .
2
e
N
Thus we have been able to devise a method that
computes the sample size for any prime p , which
provides us with an approximation p of
1.65
, by Theorem
r2
 r with 99% confidence.
Proof . As N has been chosen to be
(2.3), we obtain
1
36 p
number. Let NU be the number of those points from
pes  pex
Hence pes  pex  r ,or
equivalently pes pex  pex ( pex  r ) . Notice that
p satisfying
p  p  e for any error level e with a confidence
of 99% .
Proof
.
have p 
the
As
p 
p
2
and
3 p es
p
2
,
3 p ex
we
2 1
1
2 pes  pex
. Hence


3 pes pex
3 pes pex
condition p 
p  e holds
if
the
3
ep es p ex holds. Recall that by
2
1
1
Lemma (3.1), p es p ex 
if r 2 
. Hence if we
3p
36 p
e
set r 
and find a p es from a sample of
2p
inequality p ex  p es 
1.65
1.65  4 p 2 6.6 p 2
then
by


e 2
e2
e2
( )
2p
e
Theorem (2.3),
. Moreover if
pex  pes 
2p
1
1
then from Lemma (3.1)
r2 
 pes pex and we
36 p
3p
e
3e 1 3e
obtain
 .

pes pex . Notice that as
2 p 2 3p 2
e
1
then
and
r
r2 
e  1 if
2p
36 p
e
3e 1 3e
e
from pex  pes 
and
 .

pes pex ,
2 p 2 3p 2
2p
3
we easily obtain p ex  p es  ep es p ex . As a result
2
condition p  p  e becomes fulfilled. ■
size K 
References:
[1] Freek Wiedijk: "Irrationality of e" , Journal of
Formalized Mathematics, vol 11, Inst. of Computer
Science, Released 1999, pp 23-35,Published 2002.
[2] Paul Newbold: Statistics for Business & Economics,
4th ed., pp 234-235,Prentice-Hall, Inc.,Englewood
Cliffs, New Jersey.(1995)
[3] Paul Newbold: Statistics for Business & Economics,
4th ed., pp 835-836,Prentice-Hall, Inc., Englewood
Cliffs, New Jersey. (1995)