﻿ Prime number and prime decomposition First P.I.CO file 　 Second 　 jsprime2.htm started at jspico2e.htm
Prime number and prime decomposition
program 　 Arndt 　 DocA 　 Update 2009-09-25
XYGraph v2.3 - web page graph   ☜☞   donate   get code
The Cauchy-Schwarz Master Class   J. Michael Steele   ★★★★★
This file is personal home work. No one
If you suspect any view point wrong,
Freeman 2009-06-19-10-46

Did not test other browser. This file is
written under MSIE 6.0

<a name="docA001">
jsprime2.htm was part of jspico2e.htm //9809151033
pico=Positive Integer power sum COefficient equation
The following is PICO document, relate to prime.

2009-09-07-14-55 start
To find more
Positive Integer power sum COefficient equation
We have
Coefficient triangle and
coefficient list
in hand. But based on these data, we are
unable to find next new higher power equation.
Second file
http://freeman2.com/jspico2e.htm
<a name="docA002">
First create program to build Prime numbers
and in huge number numerator/denominator
cancel common prime factor and reduce to
shorter rational number.
2009-09-07-15-04 stop
<a name="program0"> Prime, Prime Factor, Prime Gap.
This file is personal home work. Output
may contain error. Please verify first.

Prime decomposition output to box1
Huge rational
see below. Huge rational reduce to shorter rational.

Prime Upper Bound
 Box 1   Example: ; Calculator local
Prime per line ; Separator ;
NOT output to box1, just update internal data. Check here.
To save time, paste prime table to Box 1. get/list
To write 95051 primes thousand times slower than read.
Read prime from box 1, data separator is

If data has variable separator length, use "variable Blank".
begin: end:
 Box 2 Box 3
<a name="docA003">
2009-09-07-16-18 start
Program has three functions.
1. Find prime numbers.
input at [Prime Upper Bound] box
input at [Prime per line] box
value '0' not print ',', one prime/line
other integer print ','.
run button is [Find Prime]
output to box1
<a name="docA004">
2. huge number numerator/denominator
change to shorter num./deno.
cancel out common prime factors.
input at [Prime Upper Bound] box
input at [Huge rational] box
run button is [reduce]
run button is [r2]
output to one line below 'see below'
[reduce] give just new num./deno.
[r2] give num./deno. and factor.
<a name="docA005">
3. decompose integer into prime factors
input at [Prime Upper Bound] box
input at [Huge rational] box
run button is [Fact Number]
output to box1
*** program accept "/" as integer separator.
*** multiple "160392960/1209600/2200/1320" OK

Any integer can be expressed as multiplication
of primes. Function 3 do this work.
2009-09-07-16-27 stop

<a name="docA006">
2009-09-08-08-37 start
"Update 2009-09-08" improve code efficiency.

On
2009-09-07-20-53 LiuHH access
http://www.maths.gla.ac.uk/~wws/2N/2N8.pdf
save as prime_decomposition_~wws.pdf
On
prime_decomposition_~wws.pdf
found
<a name="docA007">
[[
Corollary
If the integer n > 1 has no divisor w in the
range 1 < w ≤ √n, then n is prime.
This speeds up the process of identifying primes.
For example √97 = 9.848…
If 97 were composite, the Corollary would imply
a divisor in the range 2, …, 9.
It is easy to check that none is a divisor.
Thus 97 is prime.
]]
<a name="docA008">
Based on
http://www.maths.gla.ac.uk/~wws/2N/2N8.pdf
LiuHH change code to speed up program and
remove '1' from Prime list.
2009-09-08-08-46 stop

<a name="docA009">
2009-09-08-08-57
change from
for(t0=20;t0<=upperBound;t0++)
to
for(t0=21;t0<=upperBound;t0+=2) //9809080857
Since all even number > 2 are not prime.
2009-09-08-09-06 record

<a name="docA010">
2009-09-08-10-38 start
Consider number 35. To find out whether 35 is
a prime. We need to check 35 with smaller
prime 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31

To improve code efficiency, pay attention to
35 = 5*7 = lowP*highP
35 is not a prime,
35 is rejected at 5 < sqrt(35)
35 is NOT tested at 7 > sqrt(35)

<a name="docA011">
Next see 121=11*11 = lowP*highP (lowP=highP=11)
121 is rejected at 11=sqrt(121)

Therefore to exam whether 53 is a prime, we
check lower prime 2, 3, 5, 7 < 7.2801=sqrt(53)
For 53 we stop at 7 and no need check for 11.
We need to check lowP, no need to check highP.
lowP ≦ √(target_number) ≦ highP

<a name="docA012">
This observation let us save a lot calculation.
For example to check whether 10007 is a prime
we stop at done 97 < 100.03=sqrt(10007)
Check only 2 to 97 total 25 primes.
From 101 to 9973 there are 1204 prime skipped.
Ratio skipped:used = 48:1  Great saving!!
2009-09-08-10-56 stop

related code is
//# http://www.maths.gla.ac.uk/~wws/2N/2N8.pdf
if(chkUpTo<newPrime[t1])break; //done one number 9809081141
2009-09-08-11-41

<a name="docA013">
2009-09-08-14-34
after improve code. Test run [Find Prime]
for Prime Upper Bound 1230000
start run 2009-09-08-14-23-20
stop run 2009-09-08-14-31-12
run time : 7 minutes 52 seconds
Prime number: (total=95051)
09/08/2009  02:32 PM  765,972 prime_120wan.txt
Computer is HP pavilian a255c
Intel Pentium 4.
2009-09-08-14-39

<a name="docA014">
2009-09-08-19-16 start
From previous example 35 and 10007, we know
lowP and highP (lower Prime and higher Prime)
occur in pair. lowP ≦ √(number) ≦ highP
10007 is a prime.
2009-09-08-19-21 stop

<a name="docA015">
2009-09-09-20-51 start
Improve code efficiency. Please see source
code, find '9809091955', '9809091956',
explanation at '9809091959' to '9809092007'
Real working line is at '9809091958'
2009-09-09-20-53 stop

<a name="docA016">
2009-09-10-20-00 start
A non-prime number may have lowP but no
matching highP. For example 2^10=1024 have
ten '2' only.
If a non-prime number have a highP, this
highP must have a lowP as pair.
2009-09-10-20-05 stop

<a name="docA017">
2009-09-10-20-10 start
Huge rational box expand to longer size.
http://freeman2.com/complex2.htm#calculator
file:///C:/myfolder/jsProgram/complex2.htm#calculator
save in one folder, then 'local' link works.

<a name="docA018">
complex2.htm#calculator accept complex number
and real number. If you find output
2*2*2*2*2*2*2*2*3*3*3*5*5*7
suspicious, please use calculator to find
2*2*2*2*2*2*2*2*3*3*3*5*5*7
and paste to box3 in complex2.htm#calculator
then click 'test box3 command output to box4'
button.
2009-09-10-20-22 stop

<a name="docA019">
2009-09-11-10-44 start
"Update 2009-09-11" made the following change
1. Not rebuild prime table each time run.
now smarter, before run, see if Prime Upper
Bound is greater than existing prime table
largest element. If it is, rebuild prime
table.
Related code has time stamp '98091108' + two
more digit.
MSIE status bar print update prime table or not.

<a name="docA020">
2. If rebuild prime table, not start from 21.
Start from existing prime table largest
element plus two.
Related code has time stamp '98091109' + two
more digit.
Print message "Start build prime table at 2005"

Both improve code efficiency.

<a name="docA021">
On Internet, you can find prime evaluation
http://freeman2.com/jsprime2.htm
Those page return message as
or
"your number is not a prime"
They do not do integer prime decomposition.
They do not give you prime table.
They do not do reduction from long rational
to shorter rational.

<a name="docA022">
If you ONLY want to know a number is prime
or not.
You can find other simpler faster pages
around. Search
[[
"prime number" program OR creator OR builder
]]

<a name="docA023">
On the other hand, online has professional
program.
Their largest acceptable number is much
(They use C++, LiuHH use Javascript)

<a name="docA024">
They charge only a little fee.
If you want powerful function, you can
consider those professional programs.
2009-09-11-11-12 stop

<a name="docA025">
2009-09-15-15-08 start
This file
http://freeman2.com/jsprime2.htm
was part of
http://freeman2.com/jspico2e.htm
pico=Positive Integer power sum COefficient equation

Because prime number is an important tool.
Because jspico2e.htm file size grow bigger.
LiuHH decide to separate prime code from
jspico2e.htm.

<a name="docA026">
On 2009-09-15 add one more small function.
Now it is possible to run and save large
number of primes in another file. For example
LiuHH saved 95051 primes from 2,3,5,7 ...
up to 1229999 save in a file prime_120wan.txt
when use prime function open prime_120wan.txt
paste 95051 primes to box1, click [Read Prime]
button, program read prime table and save time.

Hope you find jsprime2.htm useful.
Thank you for visiting Freeman's web site.
Freeman (Liu, Hsinhan) 2009-09-15-15-42

<a name="docA027">
2009-09-15-16-12
prime from 2,3,5,7 ... up to 1229999, continue
build new prime. Paste old primes to box1,
set Prime Upper Bound box to 1233333 for example
primes), not output whole range 95051+232=95283
primes. Make new adding life easier.
2009-09-15-16-17

<a name="docA028">
2009-09-15-18-12
Early version has
[[
//9809111604 next 30+ lines improve code
//efficiency.
.....
]]
that time LiuHH did not test huge prime table,
small prime table do not feel any delay. Now
test huge prime table (95051 primes from 2,3,5
up to 1229999) found those "improve" code
actually delay time. The number LiuHH put in
is "160392960/1209603" use 95051 prime table,
click "r2" (reduce2) button. Screen freeze
completely. Remove "9809111604 next 30+ lines"
the speed increase to normal, one to two seconds.
2009-09-15-18-21

<a name="docA029">
2009-09-18-20-07
"Update 2009-09-19" add one more check to
user supplied prime table. That is
each prime must end with '1', '3', '7', '9'
four digits. If user supplied prime table
not comply with this rule, then not accept
user's prime. Please see code date stamp
from '9809181936' to '9809181948'
2009-09-18-20-12

<a name="docA030">
2009-09-18-22-53
From 2009-09-18-20-10 to 2009-09-18-22-20
write prime gap summary code.
Click "Find Prime" to create prime table.
In Begin[  ]  End[  ] box fill in number
Click "primeGap" button. Output to Box2
and Box3.
2009-09-18-22-57

<a name="docA031">
2009-09-22-18-11
http://freeman2.com/prime1m2.htm
Copy paste prime to box 1 and read prime
is easier than to create prime each time.
2009-09-22-18-14

<a name="docA032">
2009-09-23-16-46
"Update 2009-09-23" add [Separator] box and
[Now Max] button. Also corrected code error.

On 2009-09-23-08-57 accessed
http://www.math.utah.edu/~pa/math/primelist.html
paste prime list to
http://freeman2.com/jsprime2.htm
found jsprime2.htm can not read user prime list!

Now program read user prime. Program use
userPrime=userPrime.split('\n');
userPrime=userPrime.split(',');
two lines. Those two lines take care only
'\n' or ',' separated data. But many list
use ' ' to separate data.

<a name="docA033">
If you fill " // " to [Separator] box,
output show
2 // 3 // 5 // 7 // 11 // 13 // 17 .....
add one more bigger number after this string
. click [Read Prime] button, program will
accept this style data. Now more flexible.

If you find code error, possibly LiuHH will
correct it at later time.

Thank you for visiting Freeman's web site.
Freeman (Liu, Hsinhan) 2009-09-23-17-00

<a name="docA034">
2009-09-23-19-35
If in "Prime per line" box fill in a negative
number then program print all primes, include
user supplied prime. The danger is that if
user defined ten thousand primes still output
what user have in hand? Output 10000 primes
will freeze screen for few minutes. Provide
this force output function for the case user
really need prime list back from memory.
LiuHH 2009-09-23-19-39

<a name="docA035">
2009-09-23-20-22
Program do not check whether user supplied prime
list are all primes. User is responsible for the
true definition.
If you want program to check whether true prime,
then do not supply user prime list. Simply assign
a number to "Prime Upper Bound" and click
"Find Prime" button.
To build (check) 95051 primes from 2 to 1229999
spend 7 minutes 52 seconds in Intel Pentium 4
To read same numbers, less than ten seconds.
Please get a prime list from
http://freeman2.com/prime1m2.htm
You can find longer list from other site.

<a name="docA036">
You can build longer prime from this file.
In "Prime Upper Bound" fill in a new bound
in "Prime per line" box fill in a POSITIVE
number. (not repeat output what you have.)
uncheck the check box at
NOT output to box1, just update internal data. Check  here
then click "Find Prime" button.
Output at box 1, copy and paste to your
old prime list.
2009-09-23-20-30

<a name="docA037">
2009-09-24-15-18
Use command
userPrime=e2.split('\n');
or
userPrime=e2.split(',');
to read 95051 primes from 2,3,5,7 ... up to
1229999 need 9 to 10 seconds (Intel Pentium 4)
data. Run time is 5 to 8 minutes. Much slow
than
userPrime=e2.split('\n');

<a name="docA038">
Today 2009-09-24 create four button to read
user supplied prime list.
First  button is "Read Prime, Separator BOX"
Second button is "Read Prime, Sep=NewLine"
Third  button is "Read Prime, Sep=OneBlank"
Fourth button is "Read Prime SLOW, variable blank"

User can define separator string in Separator box.
Include tab byte. Do not type tab key when cursor
is in Separator box. Type tab here, tab is a jump
command. In box 1, copy a tab byte and paste to
Separator box. Then tab is used as separator string.

<a name="docA039">
If data is one prime one line. You can not type a
new line byte in Separator box. This case, click
second button.

If data is separated by one blank. You can fill in
one blank to Separator box and click first button.
But third button is ready for use.

First, second and third button all use fast split()
userPrime=e2.split(primeSepByte.value);
or
userPrime=e2.split('\n');
or
userPrime=e2.split(' ');

<a name="docA040">
Fourth button use
To exam variable length separator is slower.
Although button marked "variable blank". It
works with variable-any-non-digit-string.
2009-09-24-15-48

<a name="docA041">
2009-09-25-12-48
If your prime definition is short, for example
5000 primes from 2 to 48611. You can always
click "Read prime SLOW variable Blank" button.
Because for short list, you do not feel slow.
click "Read prime SLOW" button, you do not need
worry what separator used in your list.

If you have a very long prime list and do not
want to wait, then give precise separator
definition, click a proper button, program
use e2.split('proper_separator_string') for
faster job.
2009-09-25-12-58

Javascript index
http://freeman2.com/jsindex2.htm
Space Curve Projector
http://freeman2.com/curve3d2.htm
foot of perpendicular
http://freeman2.com/eyefoot2.htm
Gram-Schmidt Process
http://freeman2.com/gramsch2.htm
complex polynomial root
http://freeman2.com/polyroot.htm
complex variable functions
http://freeman2.com/complex2.htm
Hilbert's Inequality and Schur Constant
http://freeman2.com/tute0009.htm
Positive Integer power sum COefficient equation.
http://freeman2.com/jspico_e.htm
∑i^1 i=1 to n; up to ∑i^14 i=1 to n
http://freeman2.com/jspico2e.htm
Binomial factorial, double factorial
http://freeman2.com/binomial.htm

Prime number and prime decomposition
http://freeman2.com/jsprime2.htm