Gauss Approximate Number of Primes and eTCL demo example calculator, numerical analysis edit
This page is under development. Comments are welcome, but please load any comments in the comments section at the bottom of the page. Please include your wiki MONIKER in your comment with the same courtesy that I will give you. Its very hard to reply intelligibly without some background of the correspondent. Thanks,gold
gold Here is some eTCL starter code for Gauss approximate number of primes. The impetus for these calculations was checking approximations for the Riemann theorem. Most of the testcases involve assumptions and rules of thumb.
The Gauss approximation for number of primes is approx_number_primes = N1 / ln (N1), 15 percent average error. Gauss developed this formula at the age of 14! and formula was first published in 1863. If the exact solution is tabbed as one, the program is storing the exact solution in a list of limited size. The number one should not be counted as a prime and the number two is counted as prime, so some starting algorithm statements are tricky.
Legendre and Modified_Legendre approximations edit
The Legendre approximation for number of primes was approx_legendre_primes2 = N1 / (ln (N1)-1), 2 percent average error beyond 1E4. A variant of the Legendre equation was modified_legendre_primes3 = N1 / (ln (N1)-1.08366). In the modified Legendre error covering E6, no particular trends are seen leading from zero level, but there are some sawtooth patterns at intervals. Also the prime counting function is reported to have gaps between the primes, which might be difficult to see at this density.
# following statements can be pasted into TCL console
set project 1.0
proc gaussian_primes {n} { return [/ $n [log $n] ] }
puts "gaussian_primes [ gaussian_primes 100 ] " # answer 21.71472409516259
proc legendre_primes2 {n} { return [/ $n [- [log $n] 1.] ] }
puts "legendre_primes2 [ legendre_primes2 100 ] " # answer 27.73794157864211
proc modified_legendre_primes3 {n} { return [/ $n [- [log $n] 1.08366] ] }
puts "modified_legendre_primes3 [ modified_legendre_primes3 100 ] " # answer 28.39690778061494
# answer 25 prime_counting_functionx for 100 is 25 # answer 25
# nth prime f(x) =~~ 1.13*log(x)
proc mod_percent {n} { set aa [/ $n [- [log $n] 1.08366] ] ;return [* [/ $aa $n ] 100. ] }
# percentage of primes at given number n from modified_legendre_primes3
# shows increasing rarity of primes as n increases beyond 1E12
# Riemann Hypothesis Equivalent, For all x => 2.01,abs {prime_pi(x) − Li(x)} =< sqrt(x) * log(x).
# prime number theorem, Li(x)=∼~ prime_pi(x)
What causes the devil's notch in the prime counting function from numbers 550 to 650? This region is best seen on the graphs of the prime counting function or the difference curves between the prime counting function and the Gauss approximation. Maybe the notch is numerical coincidence in "random noise" or human misperception, but the notch can show some of the calculator uses. The calculator and some subroutines in the TCLLIB can be used to examine this region. Using the calculator in step intervals of (450 550), (550 650), and (550 650), there was a slight increase in the number of primes as steps 14,17,14. The gauss reported predictions of 13.505,13.191,12.936 primes in the notch and adjacent regions. The corrected legendre function reported predictions of 15.696,15.281,14.947 primes in the notch and adjacent regions. The slight increase in the devil's notch goes against the general trend that primes should become more rare either in the large numbers or as N increases. The corrected legendre function is one or two off in its prediction of prime numbers in the adjacent intervals, but the expectation from both the gauss and legendre functions is a gentle decrease in primes, not a bump up to 17 primes. As the calculator passes through the devil's notch, the prime numbers can be gathered in a list and printed out on the console. Try inserting lappend list and put statements in the prime_counting_functionx or the calculator . The prime number 601 is in the middle of the notch and its nearest integer root is 25, if a prime number has such baggage. Hinkley's Tables of primes has similar intervals of 100 mapped out, but no answer leaped from the pages. (Other pages are reporting a gap of primes, starting at 521, which may be relevant. Might be useful to have calculator report gaps in prime numbers.)
The Ribeiro paper models the error or correction function like the modified Legendre function. The modified Legendre function was $x/(log($x)-1.08366). Legendre was modeling the correction with a constant 1.08366. An equivalent expression for the Legendre function might be $x/(log($x) -1. -.08366) or $n/(log($n) -1. - error_fx($n)). Under consideration is a error model that uses the smaller quantity, ABS 0.08366 rather than ABS 1.08366 (which might allow simpler functions). The Ribeiro function starts with the setup $x/(log($x)-error_f($x)) and models the error with error_f($x) = 0.7013/$x – 4.964*exp (-0.9677*$x) + 0.98, condition that 0<+$x<10E22. The Ribeiro paper used a hand calculator or spreadsheet, effectively single precision constants. A prospective TCL procedure could be double precision TCL_17 or higher. There might be advantage in solving the error_f(x) as double precision or substituting a different modeling function with the autosolve.
Riemann fluctuatons in prime counting function edit
The Riemann translation mentioned periodic fluctuations past 1E5. There are periodic waves (or sawtooth ) of about 1E5 (100,000 on the number line) in a chart of the ABS(prime counting function -modified legendre approximation for pcf.) Show a graph of the prime counting function minus the modified legendre function (m. legendre error) over the interval zero to 1E6. There is no particular trend leading from zero to 1E6 , but there are sawtooth patterns in the trace at regular intervals (to the eyeball). In some computer docs, the prime counting function is called the number of primes less than. The modified Legendre prime approximation is MLPA = N/ ((LN(X)-1.08336). Essentially, the dots are the numbers of primes per number on the number line from zero to one million (1E6) with the rise or growth subtracted by the modified Legendre prime approximation (to a level trace). There are similar charts on the Wolfram system (for abs(PFC-LI)) on /mathworld.wolfram.com/PrimeCountingFunction.html and /mathworld.wolfram.com/RiemannPrimeCountingFunction.html, >except< that my chart is zero to 1E6 and the Wolfram chart is zero to 1000. The original Riemann paper quotes periodic terms. Apparently, certain periodic terms grow past 1E5, possibly fractions and powers of li. li-1/2*li(x^(1/2))-1/3*li(x^(1/3))-1/5*li(x^(1/50)+1/6*li*(x^(1/6)) ..... Might be helpful (or too much detail ) to expand or supplement the Wolfram charts to 1E6 or 3E6, as mentioned in the Riemann paper. (The periodic fluctuations are not seen much below 1E5 according to Riemann.).
Table: Rarity of Primes as percent reported from Modified_Legendre_primes function edit
table Rarity of Primes
mod_percent {n}
Modified Legendre P. Function
Prime Counting Function
printed in
tcl wiki format
testcase
power or order
TCL proc percent from mod legendre_primes
mod legendre_primes
prime_pi
percent prime_pi
comment if any
testcase 1
.5E1
not acc.
9.5097 not acc.
3
60.0
expr (3./5.)*100.
testcase 2
1E1
not acc.
8.2039 not acc.
4
40.
expr (4./10.)*100.
testcase 3
1E2
28.397
28.397
25
25.
expr (25./1E2)*100.
testcase 4
1E3
17.17
171.7
168
16.8
expr (168./1E3)*100.
testcase 5
1E4
12.3051
1230.514
1229
12.29
expr (1229./1E4)*100.
testcase 6
1E5
9.5884
9588.402
9592
9.592
expr (9592./1E5)*100.
testcase 7
1E6
7.854
78543.178
78498
7.8498
f(x) =(( prime_pi (x))/x)*100.
testcase 8
1E7
6.651
665139.699
664579
6.64579
testcase 9
1E8
5.768
5768003.712
5761455
5.761455
testcase 10
1E9
5.092
50917518.829
50847534
5.0847534
testcase 11
1E10
4.557
455743003.601
455052511
4.55052511
testcase 12
1E11
4.125
4124599868.665
4118054813
4.118054813
testcase 13
1E12
3.767
37668527415.329
37607912018
3.7607912018
testcase 11
1E13
3.466
346621096884.653
346065536839
3.46065536839
testcase 12
1E14
3.21
3210012022164.23
3204941750802
3.204941750802
testcase 13
1E15
2.989
29890794226981.8
29844570422669
2.9844570422669
Testcases Section
In planning any software, it is advisable to gather a number of testcases to check the results of the program. The math for the testcases can be checked by pasting statements in the TCL console. Aside from the TCL calculator display, when one presses the report button on the calculator, one will have console show access to the capacity functions (subroutines).
# pretty print from autoindent and ased editor
# Gauss approximate number of primes calculator
# written on Windows XP on eTCL
# working under TCL version 8.5.6 and eTCL 1.0.1
# gold on TCL WIKI, 15may2016
package require Tk
package require math::numtheory
#namespace path {math::numtheory}
namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory }
set tcl_precision 17
frame .frame -relief flat -bg aquamarine4
pack .frame -side top -fill y -anchor center
set names {{} {interval number L1 :} }
lappend names {end number L2 :}
lappend names {optional, if one & L2 < 190, invoke exact solution (? long!!): }
lappend names {answers: gauss function ~number_primes for N1 :}
lappend names {legendre function ~number_primes for N1 :}
lappend names {gauss approx number of primes from zero: }
lappend names {gauss approx number of primes from zero to interval start: }
lappend names {gauss number of primes over interval:}
foreach i {1 2 3 4 5 6 7 8} {
label .frame.label$i -text [lindex $names $i] -anchor e
entry .frame.entry$i -width 35 -textvariable side$i
grid .frame.label$i .frame.entry$i -sticky ew -pady 2 -padx 1 }
proc about {} {
set msg "Calculator for Gauss Approximate Number of Primes
from TCL WIKI,
written on eTCL "
tk_messageBox -title "About" -message $msg }
# ref. TCLLIB::math::numtheory::prime_counting_functionx
# ref. alternate TCLLIB::math::numtheory::isprime
proc prime_counting_function { start end } {
set start [int $start ]
set end [int $end ]
set counter 0
if { $start > 1 } { set counter $start }
set end $end
set prime_counting_function 0
while { $counter < $end } {
incr counter
incr prime_counting_function [isprime $counter ]
}
return $prime_counting_function }
proc calculate { } {
global answer2
global side1 side2 side3 side4 side5
global side6 side7 side8
global switch_factor big_giant_list legendre_function
global testcase_number
incr testcase_number
set side1 [* $side1 1. ]
set side2 [* $side2 1. ]
set side3 [* $side3 1. ]
set side4 [* $side4 1. ]
set side5 [* $side5 1. ]
set side6 [* $side6 1. ]
set side7 [* $side7 1. ]
set side8 [* $side8 1. ]
set L1 $side1
set L2 $side2
set N1 $side2
set switch_factor $side3
set approx_number_primes [/ $N1 [log $N1 ] ]
set legendre_function [/ $N1 [- [log $N1 ] 1.08366 ] ]
# conditions, all numbers real and positive.
# conditions L1 =! 1 and L2 > L1, otherwise division by zero and undefined Q's.
# if { $L1 == 1.0 } { set $L1 0.0 }
set approx_number_primes_interval_start [/ $L1 [log $L1 ] ]
set approx_number_primes_over_interval [- [/ $L2 [log $L2 ] ] [/ $L1 [log $L1 ] ] ]
set side4 $approx_number_primes
set side5 $legendre_function
set side6 $approx_number_primes
set side7 $approx_number_primes_interval_start
set side8 $approx_number_primes_over_interval
if { $switch_factor > 0 && $L2 < 200 } { exact_solution }
}
proc listprimes { aa bb} {lappend booboo 2.0; for {set i 1} {$i<=$bb} {incr i 2} { if {[isprime $i] } {lappend booboo [expr 1.*$i] } };return $booboo}
#returns list of prime numbers from aa to bb, usage [listprimes 0 25],
# answer is 2.0 3.0 5.0 7.0 11.0 13.0 17.0 19.0 23.0,
# list returned as real numbers, not counting 1.0 unity
proc exact_solution {} {
global side1 side2 side3 side4 side5
global side6 side7 side8 big_giant_list prime_counting
set big_giant_list [ listprimes $side1 $side2 ]
set side8 [ llength $big_giant_list ]
}
proc fillup {aa bb cc dd ee ff gg hh} {
.frame.entry1 insert 0 "$aa"
.frame.entry2 insert 0 "$bb"
.frame.entry3 insert 0 "$cc"
.frame.entry4 insert 0 "$dd"
.frame.entry5 insert 0 "$ee"
.frame.entry6 insert 0 "$ff"
.frame.entry7 insert 0 "$gg"
.frame.entry8 insert 0 "$hh"
}
proc clearx {} {
foreach i {1 2 3 4 5 6 7 8 } {
.frame.entry$i delete 0 end } }
proc reportx {} {
global side1 side2 side3 side4 side5
global side6 side7 side8
global switch_factor big_giant_list legendre_function
global testcase_number
console show;
puts "%|table $testcase_number|printed in| tcl wiki format|% "
puts "&| quantity| value| comment, if any|& "
puts "&| testcase number:|$testcase_number | |&"
puts "&| $side1 :|interval L1 | |&"
puts "&| $side2 :|end number L2 | |& "
puts "&| $side3 :|optional,if one, invoke exact solution (? long) | |& "
puts "&| $side4 :|answers: gauss function ~number_primes| |&"
puts "&| $side5 :|legendre function ~number_primes| |&"
puts "&| $side6 :|gauss approx_number_primes | |&"
puts "&| $side7 :|gauss approx_number_primes_interval_start | |&"
puts "&| $side8 :|gauss number_primes_over_interval | |&"
puts "&| $legendre_function :|legendre_function number_primes_N1| |&"
if {$switch_factor > 0.0} { puts "&| [prime_counting_function $side1 $side2 ] :|prime_counting_function over interval| |&" }
if {$switch_factor > 0.0 && $side2 < 190.} {puts "&| $big_giant_list :|list number_primes_over_interval | |&" }
}
frame .buttons -bg aquamarine4
::ttk::button .calculator -text "Solve" -command { calculate }
::ttk::button .test2 -text "Testcase1" -command {clearx;fillup 0.0 1E1 1.0 4.3 8.20 4.3 0.00 4.30}
::ttk::button .test3 -text "Testcase2" -command {clearx;fillup 0.0 5.0 1.0 3.1 9.50 3.1 0.00 3.10 }
::ttk::button .test4 -text "Testcase3" -command {clearx;fillup 1E3 1E6 1.0 7E5 7E5 72382.0 0.0 72382.0 }
::ttk::button .clearallx -text clear -command {clearx }
::ttk::button .about -text about -command {about}
::ttk::button .cons -text report -command { reportx }
::ttk::button .exit -text exit -command {exit}
pack .calculator -in .buttons -side top -padx 10 -pady 5
pack .clearallx .cons .about .exit .test4 .test3 .test2 -side bottom -in .buttons
grid .frame .buttons -sticky ns -pady {0 10}
. configure -background aquamarine4 -highlightcolor brown -relief raised -border 30
wm title . "Gauss Approximate Number of Primes Calculator"
Pushbutton Operation
For the push buttons, the recommended procedure is push testcase and fill frame, change first three entries etc, push solve, and then push report. Report allows copy and paste from console.For testcases in a computer session, the eTCL calculator increments a new testcase number internally, eg. TC(1), TC(2) , TC(3) , TC(N). The testcase number is internal to the calculator and will not be printed until the report button is pushed for the current result numbers. The current result numbers will be cleared on the next solve button. The command { calculate; reportx } or { calculate ; reportx; clearx } can be added or changed to report automatically. Another wrinkle would be to print out the current text, delimiters, and numbers in a TCL wiki style table as
puts " %| testcase $testcase_number | value| units |comment |%"
puts " &| volume| $volume| cubic meters |based on length $side1 and width $side2 |&"
Console program used to build csv spreadsheet charts.
# autoindent from ased editor
# console program for graph numbers
# written on Windows XP on eTCL
# working under TCL version 8.5.6 and eTCL 1.0.1
# TCL WIKI , 12dec2016
console show
package require math::numtheory
#namespace path {math::numtheory}
namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory }
set tcl_precision 17
proc factors {} {
set counter 0
set prime_counting_function 0
while {$counter < 500} {
puts " [* $counter 1.] , [/ [* $counter 1.] [log [* $counter 1.]] ], [isprime $counter ], $prime_counting_function "
incr counter
incr prime_counting_function [isprime $counter ]
}
return }
factors
# under test, biasing approx. from interval to save computer time
proc prime_counting_function { start end } {
set counter 0
if { $start > 1 } { set counter [int $start ] }
set end [int $end ]
set prime_counting_function 0
while { $counter < $end } {
incr counter
incr prime_counting_function [isprime $counter ]
}
return $prime_counting_function }
proc biased_count { N1 } {
set N1 [int $N1 ]
set bias1 [* 1. [ prime_counting_function [int [* $N1 .99] ] $N1 ]]
set bias2 [* 1. [ prime_counting_function $N1 [int [* $N1 1.01]] ]]
puts " $bias1 "
puts " $bias2 "
set bias 1.
set approx_number_primes 1.
set bias [expr $bias2/ double($bias1) ]
puts " $bias $bias2 $bias1 "
set approx_number_primes [* [/ $N1 [log $N1 ] ] $bias ]
return $approx_number_primes
}
Console program for devil's notch
# pretty print from autoindent and ased editor
# testing devil's notch
# prime number function from TCLLIB
# written on Windows XP
# working under TCL version 8.6.6
# gold on TCL WIKI , 20dec2017
package require Tk
package require math::numtheory
package require math::constants
#package require math::bigfloat
namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory math::constants }
console show
# corrected legendre_function
proc leg {N1 N2 } {
set legendre_function [/ $N1 [- [ ::tcl::mathfunc::log $N1 ] 1.08366 ] ]
set legendre_functionx [/ $N2 [- [ ::tcl::mathfunc::log $N2 ] 1.08366 ] ]
return [- $legendre_functionx $legendre_function ]
}
set numberx [ ::math::numtheory::prime_counting_functionx 450 550 ]
puts "prime counting function $numberx corrected legendre [ leg 450. 550. ] "
set numberx [ ::math::numtheory::prime_counting_functionx 550 650 ]
puts "prime counting function $numberx corrected legendre [ leg 550. 650. ] "
set numberx [ ::math::numtheory::prime_counting_functionx 650 750 ]
puts "prime counting function $numberx corrected legendre [ leg 650. 750. ] "
# padded statements into <local> ::math::numtheory::prime_counting_functionx
# for list of primes in interval
#if {[::math::numtheory::isprime $counter ] } { lappend lister $counter }
# }
# puts $lister
Alternate Console programs for prime_counting_function
# pretty print from autoindent and ased editor
# console program for prime_counting_function
# keywords prime counting function
# written on Windows XP on TCL
# working under TCL version 8.6
# gold on TCL WIKI, 4feb2018
package require Tk
package require math::numtheory
namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory }
set tcl_precision 17
console show
# adapted from sum_primes_to by dkf
# from Comparing Tcl and Python on TCL WIKI
# advantage: no dependency on expr or isprime.
# large numbers > 10E3 can take a long time.
proc prime_counting_function {n {i 1}} {
set total 0
incr n 0
for {set q [+ $i $i ]} {$q < $n} {incr q} {
if {![info exists d($q)]} {
incr total
lappend d([* $q $q ]) $q
} else {
foreach p $d($q) {
lappend d([+ $p $q ]) $p
}
unset -nocomplain d($q)
}
}
return $total
}
puts " prime_counting_function for 100 , answer [prime_counting_function 100]
puts " time note [ time {prime_counting_function 100} 100 ] "
# prime_counting_function for 100 , answer 25
# time note 273.35 microseconds per iteration
# pretty print from autoindent and ased editor
# written on Windows XP on TCL
# working under TCL version 8.6
# gold on TCL WIKI , 2feb2018
package require Tk
package require math::numtheory
namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory}
set tclprecision 17
console show
# based on all_primes proc in Sample Math Programs on TCL WIKI
proc prime_counting_functiont {max} {
# from rwt? on TCL WIKI
set counter 1
set primes [list 2]
for {set test 3} {$test <= $max} {incr test 2} {
set maxTest [int [sqrt $test ]]
foreach prime $primes {
if {$prime > $maxTest} {
# puts $test list omitted for time save
lappend primes $test
incr counter
break
}
if {![% $test $prime ]} {
break
}
}
}
return $counter
}
puts " prime_counting_functiont answer [ prime_counting_functiont 100]"
puts " prime_counting_functiont time note [ time { prime_counting_functiont 100 } 300 ] "
# prime_counting_functiont answer 25
# prime_counting_functiont time note 165.896 microseconds per iteration
table
timing on prime testers from TCL WIKI and “homebrew”
printed in
tcl wiki format
program
principle authors
time microseconds
comment, if any
ispprime
off_site caveat
1.75
testing n=100 for all, divisor algorithm,n<?
::numtheory::isprime
TCLLIB
2.623
testing n=100 for all
prime:
RS
3.313
testing n=100 for all
primeCheckFermat :
rwm
7.12
working fast, but checks all cases?
primetest :
WIKI?
21.443
primetest2 :
RS
21.853
isprimex :
perl_hacker
29.973
prime_counting_functiont :
modified all_primes from rwt? on TCL WIKI
159.25
Px (100)=25
prime_counting_function plus math::isprime :
homebrew
245.51
Px (100)=25
prime_counting_functionx minus math::isprime :
homebrew
263.5
Px (2 100)=25
Console program for sum of reciprocal squares of prime numbers.
The prime zeta function is a subset of the Riemann Zeta Function. Using powers of prime numbers in the denominator, a general TCL expression might be P(n)= 1./(** 2 n)+1./(** 3 n)+1./(** 5 n) ... with n as the positive power or order. P(1) is divergent.P(2), where P is the "prime zeta function," at infinity is 0.4522474200. Testcase1 is expr { 1./(2*2)+1./(3*3)+1./(5*5)}, 0.4011111111111111.TCL proc gives answer 0.4011 , time note 27.809 microseconds per iteration. Testcase2 is expr { 1./(2*2)+1./(3*3)+1./(5*5)+1./(7*7)+1./(11*11)+1./(13*13)}], 0.4357008969496481. TCL proc gives answer 0.4357, time note 38.409 microseconds per iteration. Testcase3 for 10000 , proc gives answer 0.4522376, time note 48100.309 microseconds per iteration.
# following statements can be pasted into TCL console
set project 1.0
set P_2 expr { 1./(2*2)+1./(3*3)+1./(5*5)} #0.40111
set P_2 expr { 1./(2*2)+1./(3*3)+1./(5*5)+1./(7*7)+1./(11*11)+1./(13*13)} # 0.43570
Proc could be modified with args to return P(2),P(3) etc. P(1) is divergent. I don't see this in math::numtheory::isprime, but TCLLIB is a big file system. Also checking division by 2 would eliminate some steps.
Table for prime_zeta_function
table testcases number
printed in
tcl wiki format
testcase
P(order)
TCL n value
TCL proc prime_zeta_function
P(order) standard at inf
comment, if any
testcase 1
2
1E6
0.45224735226537194
0.452247
testcase 2
3
1E6
0.17476263929927133
0.174763
testcase 3
4
1E6
0.076993139764243643
0.0769931
testcase 4
5
1E6
0.035755017483924012
0.035755
testcase 5
6
1E6
0.017070086850636487
0.0170701
testcase 6
7
1E6
0.0082838328561335856
0.00828383
testcase 7
8
1E6
0.0040614053665178288
0.00406141
---
# pretty print from autoindent and ased editor
# console program for prime_zeta_function
# keywords sum squares prime zeta function Sieve Eratosthenes
# written on Windows XP on TCL
# working under TCL version 8.6
# gold on TCL WIKI, 4feb2018
package require Tk
package require math::numtheory
namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory }
set tcl_precision 17
console show
# adapted from sum_primes_to by dkf
# from Comparing Tcl and Python on TCL WIKI
# advantage: no dependency on expr or isprime.
# large numbers n > 10E3 can take a long time.
# P(order 1) is divergent, P(n),n>1 should be convergent.
proc prime_zeta_function {bb n} {
# tally sequence of prime numbers via the Sieve of Eratosthenes.
# n is highest integer to test
# i subintegers to test as factors
# D() # map composite integers to primes witnessing their compositeness
# q = integer to test for primality (usually starts at 2 )
# total here, sum of reciprocals of prime squares or powers
# bb is square or power for reciprocal denominator
# prime zeta function P(1) is divergent at inf, higher P() converge
# if q and p are odd, q+2*p will always be odd.
# all even numbers n() are not prime, except 2.
set total 0
incr n 0
set i 1
for {set q [+ $i $i ]} {$q < $n} {incr q} {
if {![info exists d($q)]} {
# add 1/n**bb to tatal if n prime
set total [+ $total [/ 1. [* $q $q ] ]]
# add to current map
lappend d([* $q $q ]) $q
} else {
# move each witness to its next multiple
foreach p $d($q) {
lappend d([+ $p $q ]) $p
}
unset -nocomplain d($q)
# dump map
}
}
return $total
}
puts " prime_zeta_function for {2 6} , answer [prime_zeta_function 2 6] "
puts " time note [ time {prime_zeta_function 2 5} 100 ] "
puts " prime_zeta_function for {2 10000} , answer [prime_zeta_function 2 10000 ] "
puts " time note [ time {prime_zeta_function 2 10000} 100 ] "
# prime_zeta_function for {2 6} , answer 0.40111111111111108
# time note 11.390000000000001 microseconds per iteration
# prime_zeta_function for {2 10000} , answer 0.45223760433995064
# time note 71381.509999999995 microseconds per iteration
proc report {n} {
set count 1
set lister {}
set lister {0. 0.452247 0.174763 0.0769931 0.035755 0.0170701 0.00828383 0.00406141 0.00200447 0.000993604 }
puts "%|table testcases number||||printed in| tcl wiki format|% "
puts "%|testcase |P(order)|TCL n value |TCL proc prime_zeta_function |P() standard at inf | comment, if any|% "
foreach item { 2 3 4 5 6 7 8 } {
puts "&| testcase $count | $item |1E6 |[ prime_zeta_function $item 1000000 ] | [lindex $lister $count]||&"
incr count 1
}}
report 2