ÿþ<HTML> <HEAD> <TITLE>Prime number and prime decomposition</TITLE> <META http-equiv=Content-Type content="text/html; charset=big5"> <style type="text/css"> v\:* { behavior: url(#default#VML); } </style> <!-- The Cauchy-Schwarz Master Class author --> <meta name="author" content="J. Michael Steele" /> <!-- XYGraph v2.3 code author --> <meta name="author" content="J. Gebelein" /> <!--jsprime2.htm author --> <meta name="author" content="Liu, HsinHan ‰Rk”"o &#21129;&#37995;&#28450;" /> <script type="text/javascript"> <!-- function initial0(linkNum, plotNum) { tuteLink(0); //9806231221 primeUpperBound.value=2000; spanSay1(); //9809071341 } function alert0() //9806161720 { document.write('<font color=red>' +'This file is personal home work. No one<br>' +'proofread. Cannot promise correctness.<br>' +'If you suspect any view point wrong,<br>' +'please ask a math expert near by. <br>' +'Freeman 2009-06-19-10-46</font><br>' ); } //9806161724 //--> </SCRIPT> <script src="http://freeman2.com/tutelink.js" language="javascript"></script><!--9806111210--> <script src="tutelink.js" language="javascript"></script><!--9806111211--> </HEAD> <body link="#FF0000" vlink="#0000FF" alink="#50A000" bgcolor="#ccfcfc" onload="javascript:initial0()" > <span id="gotoFM2msg"></span><!--9712091951--> <a href=jspico_e.htm#docA01> First P.I.CO file </a> 0 <a href=jspico2e.htm#docA01> Second </a> 0 jsprime2.htm started at jspico2e.htm <br> <a href=jsprime2.htm#docA001> <font color=red size=+2> Prime number and prime decomposition </font> </a> <br> <a href="jsprime2.htm#program0"> program </a> 0 <a href="jspico_e.htm#Arndt01">Arndt</a> 0 <a href=jsprime2.htm#docA001> DocA </a> 0 <a href=jsprime2.htm#docA041> Update 2009-09-25 </a> 0 <br> <a href=http://www.structura.info/XYGraph/XYGraphDemo.htm> XYGraph v2.3 - web page graph </a> &nbsp; <!--9506231219 add link--> <a href=http://www.structura.info/XYGraph/Links.htm> && <!--##9756;##9758;--> </a> &nbsp; <!--9506231216 add link--> <a href=http://www.structura.info/XYGraph/Purchase.htm> donate<!--9801031950 use donate ##9829;##9835; e&k&--> </a> &nbsp; <a href="http://www.structura.info/XYGraph/XYGraph.zip"> get code</a> <!-- 2006-06-12-18-21 download http://www.structura.info/XYGraph/XYGraph.zip C:\$fm\js\xygraph\XYGraph.zip 2006-06-19-08-21 record --> <br> <a href=http://www-stat.wharton.upenn.edu/~steele/Publications/Books/CSMC/CSMC_index.html> The Cauchy-Schwarz Master Class </a> &nbsp; <a href=http://www-stat.wharton.upenn.edu/~steele/index.html> J. Michael</a> <a href=http://www.wharton.upenn.edu/faculty/steele.html> Steele</a> &nbsp; <a href=http://www.amazon.com/review/product/052154677X/ref=cm_cr_dp_all_helpful?%5Fencoding=UTF8&coliid=&showViewpoints=1&colid=&sortBy=bySubmissionDateDescending> &&&&& </a><!--9806081839 add link--> <br> <font color=red> This file is personal home work. No one <br> proofread. Cannot promise correctness. <br> If you suspect any view point wrong, <br> please ask a math expert near by. <br> Freeman 2009-06-19-10-46</font> <br> Please use MSIE browser to read this file. <br> Did not test other browser. This file is <br> <!--9806081846--> written under MSIE 6.0 <br> <span id="tuteLink1"></span> <br> <script src="http://freeman2.com/rocsitee.js" language="javascript"></script> <br> <hr> <pre><font size=+2><a name="docA001">&lt;a name="docA001"&gt;</a><a name="docA01"></a> js<font color=red>prime</font>2.htm was part of jspico2e.htm //9809151033 pico=Positive Integer power sum COefficient equation The following is PICO document, relate to <font color=red>prime</font>. 2009-09-07-14-55 start To find more Positive Integer power sum COefficient equation We have Coefficient <a href=jspico_e.htm#docB04>triangle</a> and coefficient <a href=jspico_e.htm#docB110>list</a> in hand. But based on these data, we are unable to find next new higher power equation. Second file http://freeman2.com/jspico2e.htm attempt to find more information. <a name="docA002">&lt;a name="docA002"&gt;</a><a name="docA02"></a> First create <a href=jsprime2.htm#program0>program</a> 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 </font></pre> <a name="program0">&lt;a name="program0"&gt;</a> <font color=red> Prime, Prime Factor, Prime Gap. </font> <br> <font color=red size=+3>This file is personal home work. Output <br> may contain error. Please verify first.</font> <br> Prime decomposition <input onclick="javascript:boxc01.value=factNumb(hugeRational.value,primeUpperBound.value)" type="button" value="Factorize Number" /> output to box1 <br> Huge rational <input id="hugeRational" value="160392960/1209600" size=80 /> <br> <input onclick="javascript:spanNumDeno.innerHTML=reduceNumDeno(hugeRational.value)" type="button" value="Reduce Rational" /> <input onclick="javascript:spanNumDeno.innerHTML='Reduce rational is working ...',spanNumDeno.innerHTML=reduceNumDeno(hugeRational.value,1)" type="button" value="r2" /> see below. Huge rational reduce to shorter rational. <br> <span id=spanNumDeno> </span> <br> Prime Upper Bound <input id="primeUpperBound" value=2000 onchange='javascript:chkUpBound()' size=8 /> <input onclick="primeUpperBound.value=''" type="button" value="clear bound" /> &nbsp; <input onclick="hugeRational.value='',spanNumDeno.innerHTML=''" type="button" value="clear rational" /> <br> <a name="box0102"></a> <table border=0> <tr> <td> Box 1 &nbsp; <INPUT onclick='javascript:window.clipboardData.setData("Text",document.getElementById("boxc01").value.toString())' type=button value="copy 1"> <INPUT onclick='document.getElementById("boxc01").value=""' type=button value="del 1"> Example: <INPUT onclick='javascript:example0(1)' type=button value="1"> <INPUT onclick='javascript:example0(2)' type=button value="2"> <INPUT onclick='javascript:example0(3)' type=button value="3"> <INPUT onclick='javascript:example0(4)' type=button value="4"> <INPUT onclick='javascript:example0(5)' type=button value="5"> ; <a href=http://freeman2.com/complex2.htm#calculator>Calculator</a> <a href=complex2.htm#calculator>local</a> <!--9809092259 add link to calculator--> <INPUT onclick='javascript:spanNumDeno.innerHTML="calculate 2*2*3*5*5*7 to check result. Local, saved a copy? Thank you"' type=button value="?1"> <br> <TEXTAREA id=boxc01 name=boxc01 rows=10 cols=80 > </TEXTAREA> </td> <!--9809071044 use box 1--> </tr> </table> <a name="FindPrime"></a> <input onclick="javascript:boxc01.value=findPrime(primeUpperBound.value,1)" type="button" value="Find Prime" /> Prime per line<input id="primePerLine" value="1" size=3 /> ; Separator<input id="primeSepByte" value="," size=3 /><!--9809231635--> ; <input onclick="javascript:nowMaxPrime()" type="button" value="Now Max" /> <br> NOT output to box1, just update internal data. Check <input id="chkBx01" type="checkbox" checked /> here. <br> <span id=spanUserPrime> To save time, paste prime table to Box 1. </span> <a href=http://freeman2.com/prime1m2.htm> get</a>/<a href=prime1m2.htm>list</a> <br> <span id=spanCurrentMax> To write 95051 primes thousand times slower than read. </span> <!--9809151341--> <br> Read prime from box 1, data separator is &nbsp; <input onclick="javascript:readPrime(1)" type="button" value="Read prime Separator BOX" /> <br> <input onclick="javascript:readPrime(2)" type="button" value="Read prime Sep=NewLine" /> &nbsp; <input onclick="javascript:readPrime(3)" type="button" value="Read prime Sep=OneBlank" /> &nbsp; <input onclick="javascript:readPrime(4)" type="button" value="Read prime SLOW variable Blank" /> <br> If data has variable separator length, use "<a href="#docA037">variable Blank</a>".<!--9809241315--> <script lang="javascript"> <!-- var comFac0=2000; //9809071340 var newPrime=[2,3,5,7,11,13,17,19]; //9809080808use,9809110818 move to global var renew01=1; //9809110821 var userMax=0; /** 2009-09-24-13-06 read user defined prime rpArg1==1, Separator box string is separator rpArg1==2, new line is separator rpArg1==3, ONE blank is separator rpArg1==4, variable length separator. slow 2009-09-24-13-09 /**/ function readPrime(rpArg1) //9809151045 { //9809241023 use rpArg1 var userPrime=boxc01.value+'\n'; var e0,e1,e2,e3,e4,e5; var err01='' +'Please input prime table.\n' +'It start with [2, 3, 5, 7, 11, ... ]\n' +'Now box1 do not have prime table.\n'; spanUserPrime.innerHTML= 'To save time, paste prime table to box1. &nbsp; ' e0=userPrime.indexOf('2',0); if(e0<0) { boxc01.value=err01 +'Because did not find first prime "2"\n' ; return; } for(e1=e0;e1<e0+100&&userPrime.charAt(e1);e1++) if(isAlpha(userPrime.charAt(e1))) { boxc01.value=err01 +'Because found alphabet after first prime "2".\n' ; return; } //9809151109 //drop comment string before prime table userPrime=userPrime.substring(e0,userPrime.length) if(rpArg1==1) //9809241027 { //comma separate data for(e1=userPrime.length-1;e1>=0;e1--) if(isDigit(userPrime.charAt(e1)))break e2=userPrime.substring(0,e1+1); //9809240925 //userPrime=e2.split(','); userPrime=e2.split(primeSepByte.value); //9809241217 } else if(rpArg1==2) { //new line separate data for(e1=userPrime.length-1;e1>=0;e1--) if(userPrime.charCodeAt(e1)>=32)break e2=userPrime.substring(0,e1+1); //9809240922 userPrime=e2.split('\n'); } else if(rpArg1==3) { //one blank separate data for(e1=userPrime.length-1;e1>=0;e1--) if(isDigit(userPrime.charAt(e1)))break e2=userPrime.substring(0,e1+1); //9809240925 userPrime=e2.split(' '); //9809241034 } else if(rpArg1==4) { //two or more blank separate data //9809241256 re-use readdata() userPrime=readdata(userPrime); } //if(rpArg1==1) else ... if(rpArg1==4) //readdata() accept '1.2e3', '4.56' etc. //prime accept only integer. //parseInt() drop '\n' for(e1=0;e1<userPrime.length;e1++) //9809151116 userPrime[e1]=parseInt(userPrime[e1]) if(userPrime[0]!=2 ||userPrime[1]!=3 ||userPrime[2]!=5 ||userPrime[3]!=7 ||userPrime[4]!=11 ||userPrime[5]!=13 ||userPrime[6]!=17 ||userPrime[7]!=19 ) { boxc01.value=err01 +'User input is not [2,3,5,7 ...]\n' +'Program found the following.\n' +userPrime[0]+', ' +userPrime[1]+', ' +userPrime[2]+', ' +userPrime[3]+', ' +userPrime[4]+', ' +userPrime[5]+', ' +userPrime[6]+', ' +userPrime[7]+'\n' ; return; //9809151126 } if(newPrime.length>=userPrime.length) { spanUserPrime.innerHTML= //9809151255 'User prime is less equal to existing prime. ' spanCurrentMax.innerHTML= //9809231523 'User pasted prime max=['+userPrime[userPrime.length-1] +'], In-memory prime max=['+newPrime[newPrime.length-1] +']' return; } for(e1=1;e1<userPrime.length;e1++) { if(userPrime[e1-1]>=userPrime[e1]) { spanUserPrime.innerHTML= //9809151322 'Prime must be increasing. Check ' +userPrime[e1-1]+' ' ; spanCurrentMax.innerHTML='' //9809240928 dbg +'e1-1='+(e1-1)+', userPrime[e1-1]=['+userPrime[e1-1] +']<br>e1='+e1+', userPrime[e1]=['+userPrime[e1] return; } //9809181936 add one more check //e4=userPrime[e1]+''; //e5=e4.charAt(e4.length-1); //9809181939 e5=userPrime[e1]%10; //9809250359 if(e1>3) //9809181947 '5' is prime if(e5!='1'&&e5!='3'&&e5!='7'&&e5!='9') { spanUserPrime.innerHTML= //9809181941 'Prime must be end with 1,3,7,9. Check ' +userPrime[e1]+' ' ; spanCurrentMax.innerHTML='' //9809240909 dbg +'e1='+e1+', userPrime[e1-1]=['+userPrime[e1-1] +'], e4=['+e4+'], e5=['+e5+']' return; //9809181948 OK } } //for(e1=1;e1<userPrime.length;e1++) newPrime=userPrime; //accepte user prime chkUpBound(1); //9809151304 userMax=userPrime.length; //9809231627 nowMaxPrime(); //9809151350 spanUserPrime.innerHTML= //9809151142 'User prime from 2,3,5... to '+userPrime[userPrime.length-1]+' accepted.' } //function readPrime() function isAlpha(ch) //9809151101 { if((ch>='a'&&ch<='z') ||(ch>='A'&&ch<='Z') ) return true; return false; } function isDigit(ch) //9809190819 { if((ch>='0'&&ch<='9')) return true; return false; } //9809111433 use cuArg1 //if cuArg1>0, not print result message //if cuArg1>0, return to calling function. // function chkUpBound(cuArg1) //9809071515 { var default2k=2000; var upB0=primeUpperBound.value; if(isNaN(upB0)) { primeUpperBound.value= comFac0=default2k; if(cuArg1>0)return; spanSay1(); return; } upB0=parseInt(upB0); if(upB0<20) { primeUpperBound.value= comFac0=default2k; if(cuArg1>0)return; spanSay1(); return; } renew01=1; //9809110854 if(newPrime[newPrime.length-1]>=upB0) { renew01=0; //9809110822 } comFac0=upB0; if(cuArg1>0)return; spanSay1(); return; } //9809151349 function nowMaxPrime() { spanCurrentMax.innerHTML='' //9809151347 +'Current prime-in-memory maximum value is ' +newPrime[newPrime.length-1] ; spanUserPrime.innerHTML= //9809231842 '<font color=red>If Prime per line <a href="#docA034">box<0</a>, output all primes</font>.' } //9809081612 function example0(exArg1) { if(exArg1==1) { hugeRational.value='160392960/1209600' spanNumDeno.innerHTML='Recover default string' } else if(exArg1==2) { hugeRational.value='160392960/1209600/2200/1320' spanNumDeno.innerHTML='Four integers, click only [Fact Number]' } else if(exArg1==3) { hugeRational.value='82003/50773' spanNumDeno.innerHTML='Both are primes, must set [Prime Upper Bound] to 82003' } else if(exArg1==4) { //9809151845 hugeRational.value='73786976294838210000/36028797018963970' spanNumDeno.innerHTML='It is 2^66/2^55 = 2^11 = 2048' } else if(exArg1==5) { //9809151846 hugeRational.value='324005284963/212844993731' spanNumDeno.innerHTML='263423*1229981/(263423*807997) Need define prime to 263423' } } //9809081618 //9809071530 // fnArg1 is input string, for example // '160392960/1209600/2200/1320' // fnArg2 is prime upper bound // for example 2000 // function factNumb(fnArg1,fnArg2) { var inp0=fnArg1; var t0,t1,t2,t3; chkUpBound(1); //9809111435 inp0=inp0.replace(/-/g,''); //9809081335 inp0=inp0.split('/'); for(t0=0;t0<inp0.length;t0++) { if(isNaN(inp0[t0])) return 'Please input integer only.\nnow '+fnArg1 inp0[t0]=parseInt(inp0[t0]); //9809071738 } var upBound=parseInt(fnArg2); //9809071555 var prime0=findPrime(upBound); //9809081405 reuse //build prime table, use square root. BUT //to factorize integer, NOT use square root. //9809081410 var iter0; var ans0=''; //9809071600 var ans1=''; //9809071747 var newNum=inp0; //9809071602 var a3Prime=[2,3]; //9809071804 var a3Power=[1,1]; var a3Index=0; // 'a3' come from if(fnArg3==1) // if(fnArg3==1) output 2^8*3^3*5^2*7^1 // instead of 2*2*2*2*2*2*2*2*3*3*3*5*5*7 // 9809071806 cancel fnArg3. // fnArg3 function is routine now. var ans2wk=''; // 9809071831 var ans2=''; // 9809071848 //var smaller1; // 9809092251 //9809101950 delete smaller1, because // 82003/50773 = prime1/prime2 //prime table must extend to 82003 //can not use smaller1 for(t1=0;t1<inp0.length;t1++) { newNum=inp0[t1]; //smaller1=newNum/2; // 9809092252 for(t0=0;t0<prime0.length;t0++) //9809080816 { //if(smaller1<prime0[t0])break; // 9809092253 iter0=0; while(iter0<1000) { iter0++ if(newNum%prime0[t0]==0) { newNum=newNum/prime0[t0] ans0+=prime0[t0]+'*'; //9809071314 } else break; //9809071830 } // while(iter0<1000) iter0--; if(iter0) { ans2wk+='' +prime0[t0]+'^'+iter0+' * ' } } // for(t0=1;t0<prime0.length;t0++) ans1+=ans0.substring(0,ans0.length-1)+'\n'; //9809071748 ans0=''; //9809071750 ans2+=ans2wk.substring(0,ans2wk.length-3) //9809071850 +'\n' ; ans2wk=''; //9809071853 } // for(t1=0;t1<inp0.length;t1++) var answer0='' +'Answer may NOT be right. if\n' +'Prime Upper Bound '+fnArg2+' is small\n' +fnArg1+'\n' +ans1 +'Below is same as above. Change style.\n' +ans2 +'\n=====\n' +'bound : upBound='+upBound+'\n' ; answer0+='' +'Program use Prime Upper Bound to build\n' +'prime table. If this bound is small,\n' +'program run faster.\n' +'Answer could be right if numbers are\n' +'composed by small primes. (who knows?)\n' +'Answer could be wrong if numbers are\n' +'composed by large prime. (may happen)\n' +'If you suspect above answer is wrong,\n' +'please set Prime Upper Bound from '+upBound+'\n' +'to one of the input numbers that show\n' +'wrong solution. Use this input number\n' +'as upper bound that is because this\n' +'number itself may be a prime number.\n' return answer0; }//9809071751 decompose multiple integers OK //9809071857 "2^8 * 3^3 * 5^2 * 7^1" report OK //9809071229 //if ndArg1='160392960/1209600', program // find shorter ratio '663/5' //if ndArg2=1, program return // '663/5 ; common: 2*2*2*2*2*2*2*2*3*3*3*5*7' // otherwise, return '663/5' function reduceNumDeno(ndArg1,ndArg2) { var inp0=ndArg1; var t0,t1,t2,t3; t0=inp0.indexOf('/',0); if(t0<0) return 'need [integer/integer]\nmust have [/]\nnow '+ndArg1 inp0=inp0.split('/'); if(inp0.length!=2) return 'require [integer/integer]\nmust have one [/]\nnow '+ndArg1 chkUpBound(1); //9809111518 var prime0=findPrime(comFac0); //9809071259 var ans0=''; //var newNum=inp0[0]; //9809071302 //var newDem=inp0[1]; var newNum=parseInt(inp0[0]); //9809091952 var newDem=parseInt(inp0[1]); if(newNum<0)newNum=-newNum; if(newDem<0)newDem=-newDem; //9809091954 var smaller0=newNum; //9809091955, improve efficiency if(newDem<smaller0)smaller0=newDem; smaller0=smaller0/2; //9809091956, improve efficiency /**9809091959 suppose input is 223/93 smaller0=newDem=93 smaller0=smaller0/2=46.5 after check prime 43<46.5 no need check prime 47>46.5 since 93/43 has chance to be multiple of 43 and 93/47 has no chance to be multiple of 47 93/47=1.9787234042553192<2 2 is first prime to check !! 47>93/2=46.5 47 never get a chance to be common factor of 223/93 so, smaller0=smaller0/2 is reasonable. 9809092007 /**/ var iter0; var common0=''; //9809071312 for(t0=0;t0<prime0.length;t0++) { if(smaller0<prime0[t0]) { break; //9809091958, improve efficiency } iter0=0; while(iter0<1000) { iter0++ if(newNum%prime0[t0]==0 &&newDem%prime0[t0]==0) { newNum=newNum/prime0[t0] newDem=newDem/prime0[t0] common0+=prime0[t0]+'*'; //9809071314 } else break; //9809151752 } // while(iter0<1000) } // for(t0=0;t0<prime0.length;t0++) ans0+=newNum+'/'+newDem+'\n'; //9809071308 if(ndArg2==1) return ans0+' ; common: '+common0.substring(0,common0.length-1); return ans0; } // function reduceNumDeno(ndArg1,ndArg2) //9809071337 function spanSay1() { var greater0=comFac0; //9809111039 if(greater0<newPrime[newPrime.length-1]) greater0=newPrime[newPrime.length-1]; spanNumDeno.innerHTML= 'If num./deno common prime factor > ' //+comFac0 //9809111040del +greater0 //9809111040use +', program ignore it.' } //9809071054 //if pbArg1=2000, program build prime table // from 2,3,5 up to 1999 <= 2000 //if pbArg2=1, program return to web page box // otherwise, return newPrime array for // calling function to use. function findPrime(pbArg1,pbArg2) { if(isNaN(pbArg1)) return 'input must be an integer.\nnow '+pbArg1; var upperBound=parseInt(pbArg1); if(upperBound<2) return 'input must be > 1\nnow '+pbArg1; chkUpBound(1); //9809111647 var reDoTable=1; //9809110835 if(renew01==0) //9809110826 { reDoTable=0; } var t0,t1,t2,t3,t4; //# The integer 1 is regarded as neither prime nor composite. //# The first few primes are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, & . //# 2009-09-07-20-53 LiuHH access //# http://www.maths.gla.ac.uk/~wws/2N/2N8.pdf var chkUpTo; //# 9809081139 var np=newPrime.length; //9809080844 var primePLine=primePerLine.value primePLine=parseInt(primePLine); if(isNaN(primePLine) )primePLine=0; //9809081023 if(reDoTable) //9809110838 { /** 2009-09-11-07-53 ; 9809110753 need one more improvement first time run, create prime table second time run, create prime table again?! not good /**/ t0=newPrime[newPrime.length-1]+2; //9809110924 //if existing prime table end at 1999 //next longer prime table start at 1999+2 spanNumDeno.innerHTML= //9809110932 'Start build prime table at '+t0 while(1) //9809110801 { chkUpTo=Math.floor(Math.sqrt(t0)); //9809081140 t2=0; for(t1=0;t1<np;t1++) //9809080901 { //# http://www.maths.gla.ac.uk/~wws/2N/2N8.pdf if(chkUpTo<newPrime[t1])break; //done one number 9809081141 //9809111141 //How to determine a number is a prime or not? //for example, 51 is not a prime. //51%2 = 1 = 51/2 residual 1 //'residual 1' indicate 2 is not a prime factor of 51 //increase from 2 to next prime 3 //51%3=0 = 51/3 residual 0 //'residual 0' indicate 3 is a prime factor of 51=3*17 //confirmed 51 is not a prime. //Stop at done check 3, //no need to check '5' !! //break from for(t1=0;t1<np;t1++) loop //9809111147 // if(t0%newPrime[t1]==0)break; //9809071139 } // t0%newPrime[t1]==0 is "not a prime" condition. if(t0%newPrime[t1]==0) { t0+=2; //9809110816 if forget t0+=2 then cry forever!! continue; //9809071140 next while(1) iteration //following report new prime. Skip it. } //here, find a new prime newPrime[np]=t0; // add one new prime np++; //9809071141 success if(t0>upperBound) //9809110805 break; //want last one prime > upperBound //help determine if should update prime table t0+=2; //9809110806 } // while(1) //9809110807 } // if(reDoTable) 9809110840 np=newPrime.length; //9809110841 var outpBgn=userMax;//9809231836 var useComma=primeSepByte.value; //9809231639 if(primePLine==0) { useComma=''; primePLine=1; } else if(primePLine<0) { //9809231831 all prime printed outpBgn=0; //9809231837 primePLine=-primePLine; //9809231912 } nowMaxPrime(); //9809151351 if(pbArg2==1) //return to web page box if(chkBx01.checked) { spanCurrentMax.innerHTML= '<font color=red>Please see message in box 1</font>' return '[NOT output to box1, just update internal data.] Checked\n' +'no output allowed. Purpose is to save time. Huge table\n' +'freeze screen.\n' +'Please uncheck the box, then output prime table\n' +'right here in box1. Please be alert: if output huge\n' +'size table, screen freeze for few minutes.\n' +'Freeman 2009-09-15-15-32.\n\n' +'userMax='+userMax+' ; ' +'newPrime[userMax-1]='+newPrime[userMax-1]+'\n' ; } else //9809231854 del if(np>userMax) //9809151559 { if(outpBgn>0) //9809231838 spanUserPrime.innerHTML= //9809231734 '<font color=red>Part output. You have user supplied prime</font>.' var ans0='Prime number: [total='+np+']\n' if(userMax>0) { if(outpBgn==0) ans0='Prime number: {total='+(np)+'}\n' //9809231948 else ans0='Prime number: (total='+(np-userMax)+')\n' } if(outpBgn>0) //9809231839 if(outpBgn!=np) ans0='' +'Section output, start from ' +(newPrime[userMax-1]+2) //9809231903 +' to '+newPrime[np-1]+'\n' //9809151600 +'You have user supplied prime.\n' //9809231905 else ans0='' +'Section output, start from '+newPrime[userMax-1] //9809231903 +' to '+newPrime[np-1]+'\n' //9809151600 +'You have user supplied prime.\n' //9809231905 +newPrime[userMax-1] ; for(t1=outpBgn;t1<np;t1++) //9809231840 { //9809071110 ans0+='' +newPrime[t1] + ((t1+1)%primePLine?useComma:useComma+'\n') //9809081028 } return ans0; //return to output box. } // if(pbArg2==1) if(chkBx01.checked) //next return to other calling function return newPrime //9809071242 } // function findPrime(pbArg1,pbArg2) function primeGap() //9809182027 { var gapBgn0=prGapBgn.value; var gapEnd0=prGapEnd.value; if(isNaN(gapBgn0)) { boxc02.value= 'Prime gap begin box must be\n' +'an integer. Now read "'+gapBgn0+'"'; return; } if(isNaN(gapEnd0)) { boxc02.value= 'Prime gap end box must be\n' +'an integer. Now read "'+gapEnd0+'"'; return; } gapBgn0=parseInt(gapBgn0); gapEnd0=parseInt(gapEnd0); //9809182035 if(gapBgn0>newPrime[newPrime.length-1]) { boxc02.value= 'Prime gap begin box value is greater\n' +'than prime-in-memory maximum value\n' +newPrime[newPrime.length-1] ; return; } if(gapEnd0>newPrime[newPrime.length-1]) { boxc02.value= 'Prime gap end-box value is greater\n' +'than prime-in-memory maximum value\n' +newPrime[newPrime.length-1]+'\n' +'Please fill larger number in\n' +'Prime Upper Bound box and click\n' +'"Find Prime" button to update\n' +'prime table and click "primeGap"\n' +'Or paste prime table to Box 1 and\n' +'click "Read Prime", "primeGap".\n' ; return; } if(gapBgn0>gapEnd0) { //9809182041 boxc02.value= 'Prime gap begin box value '+gapBgn0 +' is\n' +'greater than gap end box value '+gapEnd0+'\n' ; return; } var w0,w1,w2,w3,w4,w5; var bgnIndex=endIndex=-1; for(w0=1;w0<newPrime.length;w0++) // 9809182126 delete '-1' { if(newPrime[w0-1]<=gapBgn0 &&newPrime[w0] > gapBgn0) bgnIndex=w0-1; else if(newPrime[w0-1]<=gapEnd0 &&newPrime[w0] > gapEnd0) { endIndex=w0; break; } } //for(w0=1;w0<newPrime.length;w0++) if(endIndex==-1)endIndex=newPrime.length-1; //9809201241 var ans0=''; var maxGap='' var maxArray=100 var gapArray=new Array(maxArray); //9809182207 var gapIndex=0; var maxIndex=0; for(w0=0;w0<maxArray;w0++) // 9809182208 gapArray[w0]=0; for(w0=bgnIndex+1;w0<=endIndex;w0++) // 9809182132 { w3=newPrime[w0]-newPrime[w0-1]; w4=' '; if(w3>999)w4=''; else if(w3>99)w4=' '; else if(w3>9)w4=' '; ans0+=w4+w3+', '+newPrime[w0-1]+'\n'; // 9809182137 if(w3>maxIndex) { maxIndex=w3; maxGap=''+maxIndex+', '+newPrime[w0-1]; } gapIndex=w3/2-1; //9809182210 if(gapIndex<maxArray) gapArray[gapIndex]++; //9809182211 } //for(w0=bgnIndex;w0<endIndex;w0++) var ans1=''; for(w0=0;w0<maxArray;w0++) { w3=gapArray[w0]; w4=' '; if(w3>999)w4=''; else if(w3>99)w4=' '; else if(w3>9)w4=' '; ans1+=w4 +gapArray[w0]+', '+(w0+1)*2+'\n' } //for(w0=0;w0<maxArray;w0++) boxc02.value='' +'Prime gap, start from '+gapBgn0+'\n' +'end at '+gapEnd0+'. In a line, it is\n' +'gap size comma gap_begin_prime.\n' +'bgnIndex='+bgnIndex+'\n' +'endIndex='+endIndex+'\n' +'ans0.length='+ans0.length+'\n' +ans0; //9809182159 boxc03.value='' +'Prime maximum gap_size occur at\n' +maxGap+' , It is\n' +'max_gap_size comma begin_prime.\n' +'Next gap_size increase sums. It is\n' +'number_of_gaps comma gap_size.\n' +ans1; //9809182216 } //function primeGap() 9809182218 //2009-09-23-15-01 from tute0009.htm //find function readdata(inStr0) // function readdata(inStr0) //9806101151 { //9807270955 read other's no-comment code //very headache, now back to my code, add //more comments. // //if input inStr0 is Not a Number (isNaN=true) //then inStr0 is an array or string of char. if(isNaN(inStr0) //9807161944 //and if inStr0[0] is a Number //(isNaN=false) (!isNaN=true) //inStr0 is a number array, return oroginal form &&!isNaN(inStr0[0])) return inStr0; //if input inStr0 is empty, return oroginal form if(inStr0.length==0)return inStr0; //9806101153 //if input inStr0 is a number, return oroginal form if(!isNaN(inStr0[0]))return inStr0; //9807271000 //up to here input inStr0 is one string of character //below change string of char '1.23 4.56 7.89 ...' //to number array aa[0]=1.23, aa[1]=4.56, aa[2]=7.89 ... //9807271010 here //assume input string is '1.23 4.56 7.89 ...' //oArray[0] store '1.23' this is a string //oArray[1] store '4.56' not a number yet //oArray[2] store '7.89' convert to number later //9807271043 var oArray=''; //9806101158 var w0,w1,numb0; for(w0=0;w0<inStr0.length;w0++) { numb0=''; //skip those char are NOT [0123456789-+.] // [!(...)] means [is not ...] // [!=] means [not equal] 9807271051 // w1=w0; //9802172117 while(!(inStr0.charAt(w1)>='0' &&inStr0.charAt(w1)<='9') &&inStr0.charAt(w1)!='-' &&inStr0.charAt(w1)!='+' &&inStr0.charAt(w1)!='.' &&w1<inStr0.length ) { //index w1 increase only, //no record what read 9807271058 w1++; } //above while() loop stop at reading //either one in the list [0123456789-+.] //then start next while loop. 9807271055 // while((inStr0.charAt(w1)>='0' &&inStr0.charAt(w1)<='9') ||inStr0.charAt(w1)=='-' ||inStr0.charAt(w1)=='+' ||inStr0.charAt(w1)=='.' ||inStr0.charAt(w1)=='e' ||inStr0.charAt(w1)=='E' &&w1<inStr0.length ) //9802171608 { //If it is either one of [0123456789-+.eE] //continue store data into numb0 . 9807271102 numb0+=inStr0.charAt(w1); w1++; } //if all I get is just '.' for example // 'aa.txt' it is not a number, //no need to build output oArray //9807271106 if(numb0.length==1&&numb0.charAt(0)=='.') { w0=w1; //9802172218 //update index w0=w1 continue; //continue to next iteration. } //skip the following building code. //up to this point, numb0 is useful number //build output string oArray //9807271111 w0=w1; //9806101210 update index //string numb0 to output string oArray //add a newline byte '\n' to separate data // 9807271113 oArray+=numb0+'\n'; //9806101159 } // for(w0=0;w0<inStr0.length;w0++) //done for() loop, done output string oArray //use newline byte '\n' to separate numbers. // oArray.split('\n') in oArray cut data at //newline byte '\n' and change string // '1.23\n4.56\n7.89\n...' //to array oArray[0]='1.23', oArray[1]='4.56', //oArray[2]='7.89' ... //no matter input data use ',' or tab or //newline to separate data, here all done //9807271125 oArray=oArray.split('\n'); //9806101643 //string '1' + string '2' = '12' //number 1 + number 2 = 3 //above is string array oArray[0]='1.23', //below is number array w2[0]=1.23 //9807271130 var w2=[0,0]; for(w0=0;w0<oArray.length;w0++) { //9806101704 //parseFloat() convert string number // to number number. w1=parseFloat(oArray[w0]); //no more number? done if(isNaN(w1))break; //9806101714 w2[w0]=w1; //create number array. } return w2; } // function readdata() 9806101214 //from function update0() //9802171511 //--> </script> <br><a name="primeGap"></a> <INPUT onclick='javascript:primeGap()' type=button value="prime Gap"><!--9809182023--> begin: <INPUT id="prGapBgn" size=5 value="2"><!--9809182024--> end: <INPUT id="prGapEnd" size=5 value="2000"> <INPUT onclick='prGapBgn.value=prGapEnd.value=""' type=button value="del gap"><!--9809182026--> <br> <a name="box0203"></a> <table border=0> <tr> <td> Box 2 &nbsp; <INPUT onclick='javascript:window.clipboardData.setData("Text",document.getElementById("boxc02").value.toString())' type=button value="copy 2"> <INPUT onclick='document.getElementById("boxc02").value=""' type=button value="del 2"> <br> <TEXTAREA id=boxc02 name=boxc02 rows=10 cols=38 > </TEXTAREA> </td> <td> Box 3 &nbsp; <INPUT onclick='javascript:window.clipboardData.setData("Text",document.getElementById("boxc03").value.toString())' type=button value="copy 3"> <INPUT onclick='document.getElementById("boxc03").value=""' type=button value="del 3"> <br> <TEXTAREA id=boxc03 name=boxc03 rows=10 cols=38 > </TEXTAREA> </td> <!--9809182019 use box 2&3--> </tr> </table> <pre><font size=+2><a name="docA003">&lt;a name="docA003"&gt;</a><a name="docA03"></a> 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<!--9809090931start--> value '0' not print ',', one prime/line other integer print ','.<!--9809090932stop--> run button is [Find Prime] output to box1 <a name="docA004">&lt;a name="docA004"&gt;</a><a name="docA04"></a> 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">&lt;a name="docA005"&gt;</a><a name="docA05"></a> 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<!--9809090938--> Any integer can be expressed as multiplication of primes. Function 3 do this work. 2009-09-07-16-27 stop <a name="docA006">&lt;a name="docA006"&gt;</a> 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 2009-09-08-07-51 read prime_decomposition_~wws.pdf found <a name="docA007">&lt;a name="docA007"&gt;</a> [[ Corollary If the integer n > 1 has no divisor w in the range 1 < w d" "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">&lt;a name="docA008"&gt;</a> 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">&lt;a name="docA009"&gt;</a> 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">&lt;a name="docA010"&gt;</a> 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 &lt; sqrt(35) 35 is NOT tested at 7 > sqrt(35) <a name="docA011">&lt;a name="docA011"&gt;</a> 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 &lt; 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 f" "(target_number) f" highP <a name="docA012">&lt;a name="docA012"&gt;</a> This observation let us save a lot calculation. For example to check whether 10007 is a prime we stop at done 97 &lt; 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&lt;newPrime[t1])break; //done one number 9809081141 2009-09-08-11-41 <a name="docA013">&lt;a name="docA013"&gt;</a> 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">&lt;a name="docA014"&gt;</a> 2009-09-08-19-16 start From previous example <a href="#docA010">35</a> and <a href="#docA012">10007</a>, we know lowP and highP (lower Prime and higher Prime) occur in pair. lowP f" "(number) f" highP If not found lowP, highP can not exist alone. If not found lowP, we are done, this number 10007 is a prime. 2009-09-08-19-21 stop <a name="docA015">&lt;a name="docA015"&gt;</a> 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">&lt;a name="docA016"&gt;</a> 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">&lt;a name="docA017"&gt;</a> 2009-09-10-20-10 start Huge rational box expand to longer size. Box1 top add 'Calculator local' link. Calculator link to http://freeman2.com/complex2.htm#calculator local link to file:///C:/myfolder/jsProgram/complex2.htm#calculator If you download freeman2.com programs and save in one folder, then 'local' link works. <a name="docA018">&lt;a name="docA018"&gt;</a> 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 answer. Just copy 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">&lt;a name="docA019"&gt;</a> 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">&lt;a name="docA020"&gt;</a> 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">&lt;a name="docA021"&gt;</a> On Internet, you can find prime evaluation pages. Their speed is faster than this page http://freeman2.com/jsprime2.htm Those page return message as "your number is a prime" 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">&lt;a name="docA022"&gt;</a> 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">&lt;a name="docA023"&gt;</a> On the other hand, online has professional program. Do more function than this page. Do faster than this page. Their largest acceptable number is much larger than this page. (They use C++, LiuHH use Javascript) <a name="docA024">&lt;a name="docA024"&gt;</a> They charge only a little fee. If you want powerful function, you can consider those professional programs. 2009-09-11-11-12 stop <script language="javascript">alert0()</script> <a name="docA025">&lt;a name="docA025"&gt;</a> 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">&lt;a name="docA026"&gt;</a> 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">&lt;a name="docA027"&gt;</a> 2009-09-15-16-12 Add few more code lines. Now if already build 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 Now program output the new add part (add 232 new primes), not output whole range 95051+232=95283 primes. Make new adding life easier. 2009-09-15-16-17 <a name="docA028">&lt;a name="docA028"&gt;</a> 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">&lt;a name="docA029"&gt;</a> 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">&lt;a name="docA030"&gt;</a> 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">&lt;a name="docA031"&gt;</a> 2009-09-22-18-11 "Update 2009-09-22" add link to prime table<a href=http://freeman2.com/prime1m2.htm> http://freeman2.com</a>/<a href=prime1m2.htm>prime1m2.htm</a> 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">&lt;a name="docA032"&gt;</a> 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 function readdata(inStr0) to read data. and drop 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">&lt;a name="docA033"&gt;</a> 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">&lt;a name="docA034"&gt;</a> 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">&lt;a name="docA035"&gt;</a> 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<a href=http://freeman2.com/prime1m2.htm> http://freeman2.com/prime1m2.htm</a> You can find longer list from other site. <a name="docA036">&lt;a name="docA036"&gt;</a> 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">&lt;a name="docA037"&gt;</a> 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) use function readdata(inStr0) to read same data. Run time is 5 to 8 minutes. Much slow than userPrime=e2.split('\n'); <a name="docA038">&lt;a name="docA038"&gt;</a> 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">&lt;a name="docA039"&gt;</a> 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">&lt;a name="docA040"&gt;</a> Fourth button use userPrime=readdata(userPrime); 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">&lt;a name="docA041"&gt;</a> 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 <script language="javascript">alert0()</script> </font></pre> <hr><br> Javascript index <br> <a href=http://freeman2.com/jsindex2.htm> http://freeman2.com/jsindex2.htm </a> <br> Space Curve Projector <br> <a href=http://freeman2.com/curve3d2.htm > http://freeman2.com/curve3d2.htm </a> <br> foot of perpendicular <br> <a href=http://freeman2.com/eyefoot2.htm > http://freeman2.com/eyefoot2.htm </a> <br> Gram-Schmidt Process <br> <a href=http://freeman2.com/gramsch2.htm> http://freeman2.com/gramsch2.htm </a> <br> complex polynomial root <br> <a href=http://freeman2.com/polyroot.htm> http://freeman2.com/polyroot.htm </a> <br> complex variable functions <br> <a href=http://freeman2.com/complex2.htm> http://freeman2.com/complex2.htm </a> <br> Hilbert's Inequality and Schur Constant <br> <a href=http://freeman2.com/tute0009.htm> http://freeman2.com/tute0009.htm </a> <br> Positive Integer power sum COefficient equation. <br> <a href=http://freeman2.com/jspico_e.htm> http://freeman2.com/jspico_e.htm </a> <br> "i^1 i=1 to n; up to "i^14 i=1 to n <br> <a href=http://freeman2.com/jspico2e.htm> http://freeman2.com/jspico2e.htm </a> <br> Binomial factorial, double factorial <br> <a href=http://freeman2.com/binomial.htm> http://freeman2.com/binomial.htm </a> <br> <br> Prime number and prime decomposition <br> <a href=http://freeman2.com/jsprime2.htm> http://freeman2.com/jsprime2.htm </a> <br> First upload 2009-09-15 <br> <br> Program name in Chinese: (2009-09-15-10-12) <br> Brief name: }xeýQxe <br> Full name: }xeýQxeÊStexeKN }xeR㉠<br> <br> Thank you for visiting Freeman's page.0 <br> Freeman 02009-09-15-10-12 <br> <br> Please visit <a href=http://freeman2.com/jspico_e.htm>freeman2.com</a>/<a href=jspico_e.htm>jspico_e.htm</a> <!--9809071643--> <br> Please get prime list: <a href=http://freeman2.com/prime1m2.htm> http://freeman2.com</a>/<a href=prime1m2.htm>prime1m2.htm</a> <br> <br> <span id="tuteLink2"></span> </BODY> </HTML> <SCRIPT language=JavaScript><!-- // 9507121343 function stepf(t0,bgn0) { if(t0<bgn0) return 0.; return 1.; } // end function // 9507121346 // 9507121356 // stepf(t,3) get t<3 value 0 // stepf(t,3) get t>=3 value 1 // // (1-stepf(t,3)) get t<3 value 1 // (1-stepf(t,3)) get t>=3 value 0 // // (stepf(t,2)-stepf(t,3)) // get 2<=t<3 value 1 // t<2 and t>=3 value 0 // 9507121400 /* 95,07,08,14,55,00 http://www.univie.ac.at/future.media/moe/JavaCalc/jcintro.html c:\$fm\js\math9507\JavaCalc-jcintro.html 95,07,08,15,00 http://www.univie.ac.at/future.media/moe/JavaCalc/parser.js c:\$fm\js\math9507\JavaCalc-jcintro-parser.js Return to MathCollections Ken Kikuchi Comment me: kikuchi@mix.or.jp Last updated: 2/29/2000 9507132210 include function loggamma(x) and function gamma(x) /**/ // Ab hier (17. 3. 2000) von Ken's Script \áernommen: function factorial(n) { /* factorial */ with(Math) { if (n<0) /* if negative */ return gamma(n+1); else if ((n == 0) || (n == 1)) return 1; else if (abs(n)-floor(abs(n))==0 ) /* if positive integer */ return n * factorial(n-1) ; else /* if non-integer */ return gamma(n+1); } } function loggamma(x) { /* log gamma */ var u0; //9507142008 with(Math) { var v=1; var w=0; var z=0; while ( x<8 ) { v*=x; x++ } w=1/(x*x); u0= //9507142009 ((((((((-3617/122400)*w + 7/1092)*w -691/360360)*w + 5/5940)*w -1/1680)*w + 1/1260)*w -1/360)*w + 1/12)/x + 0.5 * log(2*PI)-log(v)-x+(x-0.5)*log(x) ; //status='x=['+x+']; w=['+w+']; u0=['+u0+'] 9507142010'; return u0; } } function gamma(x) { /* gamma */ //9507141940 var i0; var y0=''; var g0,g1,g2; //9507142019 for(i0=0;i0<(x+'').length;i0++) { if(i0==0&&(x+'').charAt(i0)=='(')continue; if((x+'').charAt(i0)==')')break; //9507141944 y0+=(x+'').charAt(i0); } x=parseFloat(y0); with(Math) { if ( x <= 0 ) { if (abs(x)-floor(abs(x))==0 ) return "ComplexInfinity" ; else { g0=loggamma(1-x); g1=PI/( sin(PI*x) * exp( g0 ) ); return g1; } } else { g0=loggamma(x); g1=exp( g0 ) ; return g1 ; } } } //ISBN 0-12-059820-5 page 307 line -4 // LiuHH 200904271706 //function binomialCoef(arg1,arg2) //function binoCoef(arg1,arg2) function bicof(arg1,arg2) { //9804271706 arg1=parseInt(arg1); arg2=parseInt(arg2); if(arg1<arg2)return 0; return factorial(arg1)/(factorial(arg2)*factorial(arg1-arg2)); } //9804271718 //function factorialDouble(arg1) //ISBN 0-12-059820-5 page 545 eqn. 10.33c // LiuHH 200904271746 //function factorialDouble(arg1) //function factorDbl(arg1) // // Double factorial facdb(arg1) // 9!!=9*7*5*3*1 // 8!!=8*6*4*2 function facdb(arg1) { //9804271746 arg1=parseInt(arg1); var i0,i1,i2; var n; if(arg1%2) { n=parseInt(arg1/2); for(i0=0,i1=1;i0<n;i0++) i1=i1*2; return factorial(arg1)/factorial(n)/i1; } //9804271752 n=arg1/2; for(i0=0,i1=1;i0<n;i0++) i1=i1*2; return factorial(n)*i1; } //9804271754 /** 2009-06-12-15-31 start Javascript use float number for calculation. Answer may contain long string of '000000' or '999999', for example 2.00000000000001 -25.999999999999996 On 2009-06-12-11-58 write a function function bye09(in09) //9806121158 To use this function, call as following coef2=bye09(coef2); where coef2 is a number. After call 2.00000000000001 change to 2 -25.999999999999996 change to -26 It is handy, you can use it too. If number is 1.23111111111 there is no change. function bye09(in09) handle output number for better looking. Do not call bye09() during calculation, that is just slow down process. If expect answer to be irrational Do not call bye09(). If expect answer to be integer or short decimal number like 1.2. In these case you can call bye09(). 2009-06-12-15-40 stop 2009-06-17-19-05 bye09() process only one number at a time. If you have a string of several numbers. Do not put number string as input argument bye09() will send string back immediately. This file has sample code at time stamp '9806171858' 2009-06-17-19-09 stop /**/ function bye09(in09) //9806121158 { // in09 is input number, // for example 2.0000000001 // If input is not a number, return here if(isNaN(in09)) return in09; // where is decimal point '.' ? var dotLoc=(in09+'').indexOf('.',0); // no decimal point? integer? return. if(dotLoc==-1) return in09; // change input string to number in09=parseFloat(in09); // if number has '000000' ÿ var zeroLoc=(in09+'').indexOf('000000',dotLoc); // find '000000' ÿcut start '000000' if(zeroLoc>0) //9806121216 return parseFloat((in09+'').substring(0,zeroLoc)); //9806121209 // if number has '999999' ÿ var nineLoc=(in09+'').indexOf('999999',dotLoc); // find '999999' ÿ cut start '999999' if(nineLoc>0) //9806121223 here { // copy number left to '999999' //but immediately neighbor digit not copy // nineLoc-1 because '999999' need increase // digit by one. //If input is 1.23999999999 copy only 1.2 //not copy 1.23 , because 3 will change to 4. var nine0=(in09+'').substring(0,nineLoc-1); //between '.' and '999999' has other digit. if(nineLoc-dotLoc>1) //9806121220 { //neighbor digit add one, paste to end nine0+=(parseInt((in09+'').charAt(nineLoc-1))+1); } else //between '.' and '999999' no other digit. {// modified number is an integer nine0=parseInt(nine0); //9806121313 if(nine0<0)nine0--; // negative integer minus one else nine0++; //9806121314 positive integer add one } return parseFloat(nine0); //9806121213 return new number } // no '000000' no '999999' return original form return parseFloat(in09); //9806121224 } //function bye09(in09) //--> </script> <!-- 2009-09-07-11-38 start record 2009-09-01-11-19 start jspico_e.htm copy tute0012.htm jspico_e.htm 2009-09-07-10-21 start jspico2e.htm copy jspico_e.htm jspico2e.htm 2009-09-07-11-41 done record 2009-09-15-10-05 from jspico2e.htm take out prime code section, save as jsprime2.htm -->