***Math proc templates for Prime Number generation and TCL demo example, numerical analysis*** 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 and date in your comment with the same courtesy that I will give you. Aside from your courtesy, your wiki MONIKER and date as a signature and minimal good faith of any internet post are the rules of this TCL-WIKI. Its very hard to reply reasonably without some background of the correspondent on his WIKI bio page. Thanks,[gold] 30Apr2021 ---- <> *** Introduction*** ---- [gold] Here are some Math proc templates for Prime Number generation. These Math proc templates are intended to be compatible with the format of existing subroutines in the TCLLIB:math library. The new Math proc should be checked in TCLLIB::math local copy before submission to TCLLIB ticket pipeline. Morfing these math proc templates into Prime Number generation subroutines should be feasible. I have found it easier and more tidy to start with a working TCL templates and morf a few lines into a new purpose.If one completes and tests the new TCL subroutine in a console program, then usually one can load the new TCL subroutine into a graphical user interface (gui). ---- ***prime number formula '''< 16n+15 >''' *** ---- Maybe coincidence, but '''sequence {7 11 13 14 }''' has been found on Sumerian '''Tablet AO8862'''. The On-Line Encyclopedia of Integer Sequences '''A014311 Oeis {7 11 13 14}''' cited sequence property as Numbers n such that '''<16n+15>''' are prime. '''Tablet YBC10722''' uses the input quantity '''15''' with the sequence '''{7 11 13 14}'''! [KWJ] in [Monster Prime Predicting Formula] has posted on the Wiki for this formula '''< 16n+15 >'''. ---- This prime number formula '''< 16n+15 >''' as a prime number filtering mechanism produces some primes and some duds. [KWJ] reported the prime number formula '''< 16n+15 >''' had an efficiency of '''0.166''' for filtering primes out of the numberline,for the data set, ''''''. For N > 2, about half of numbers on the numberline are even, which could never be defined as primes. If the formula added two even numbers, then only even numbers would result in the sum with no primes produced. If the formula added an even number and odd number, then some odd numbers might result with some primes produced. -------- ***primes on clay tablets *** ---- In some sense, the Plimpton 322 clay tablet is also generating a set of prime numbers in the available triplet collection on the clay tablet. The Babylonian regular numbers in base_60 between 0 and 60 have a limited set of triplets that satisfy 1< X-1/X < 1+sqrt(2) which appears to be the role of Plimpton 322. The limit 1< X-1/X < 1+sqrt(2) may explain the 1 small,medium, giant #pseudocode: need testcases within range of expected operation. #pseudocode: are there any cases too small or large to be solved? ====== ---- *** Subroutine Template 4, geometric_mean *** ---- ---- ====== # pretty print from autoindent and ased editor # geometric_mean for math::stats? package # working under TCL version 8.5.6 and eTCL 1.0.1 # console program written on Windows XP on eTCL # gold on TCL WIKI, 2Mar2017 package require Tk console show package require math::numtheory namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory } set tcl_precision 17 # adapted from tcl-wiki Stats 2011-05-22, arithmetic mean [RLE] console show # ::math::geometric_mean -- # # Return the geometric_mean of two or more values # # Arguments: # val first value # args other values # # Results: # geometric_mean arithmetic geometric_mean value proc ::math::geometric_mean { args } { set product 1. set N [ expr { [ llength $args ] } ] foreach val $args { set product [ expr { $product*$val } ] } set exponent [ expr { 1./$N } ] set geometric_mean [ expr { $product**$exponent } ] #puts " $N $exponent $product $args " set geometric_mean } ;# end of working deck ;# add cosmetics below to bottom of file console show console eval {.console config -bg palegreen} console eval {.console config -font {fixed 20 bold}} console eval {wm geometry . 40x20} console eval {wm title . " Console wrapper for ::math::geometric_mean proc"} console eval {. configure -background orange -highlightcolor brown -relief raised -border 30} puts " Console wrapper for ::math::geometric_mean proc" puts " Return the quantities from list of ratios" puts " ::math::geometric_mean ( 1 2 3 4 ) answer 2.2133638 " puts " [ ::math::geometric_mean 1 2 3 4 ] answer 2.2133638 " ====== ---- *** Possible Errors, Predefined Entries, Break Lines, Possible Wild_Cards in TCLLIB::math local copy *** ---- ====== # Arguments: # limit1 The limit for the largest prime to be included in the estimate # if { $limit1 <= 1 } { return -code error "The limit must be larger than 1" } if { $limit2 <= 1 } { return -code error "The upper limit must be larger than 1" } if { $n == 0 } {return 0} if { $n < 1 } {return 0} if { $n == 1 } {return 1} if {$n<2} then {return -code return 2} if {$n<4} then {return -code return 4} if {$n<9} then {return -code return 9} # forgivable error but no entry forwarded for calculation if { [ isprime $limit3 ] < 1 } { break } # Add the additional procedures to TCLLIB::math local copy # proc ::math::numtheory::call {args} {uplevel catch [list $args]} proc ::math::numtheory::mathx { args } { set tcl_precision 17; puts [ expr [ expr { $args } ] ] } ;# translating Fortran and Qbasic control flow statements proc ::math::numtheory::stop {} { return } proc ::math::numtheory::end {} { exit } proc ::math::numtheory::pause {} { wait .00010} ;# set comment lines from Fortran proc ::math::numtheory::C {args} { set C # } proc ::math::numtheory::REM {args} { set REM # } ;# attack of bots from Qbasic proc ::math::numtheory::write {args} { puts $args } proc ::math::numtheory::print {args} { puts $args } ;# attack of bots from Quickbasic proc ::math::numtheory::SUBROUTINE {args} { proc $args } proc ::math::numtheory::SUB {args} { proc $args } ;# attack of bots from Quickbasic ;# namespace eval ::math::constants { variable constants { pi 3.14159265358979323846 "ratio of circle circumference and diameter" e 2.71828182845904523536 "base for natural logarithm" ln10 2.30258509299404568402 "natural logarithm of 10" phi 1.61803398874989484820 "golden ratio" phi_2 0.61803398874989484820 "golden ratio conjugate" tcl_precision_1 17 "tcl_precision number" ) set result {} ;# set list for calculation results lappend result $number } return $result ====== ---- ***Testcases Section*** In planning any software, it is advisable to gather a number of testcases to check the results of the program. ---- **** Testcase 1 **** ---- %|table testcase 1 | |printed in| tcl wiki format|% &| quantity| value| comment, if any|& &| set_number:|percent of prime numbers in set | percent primes in set of 10 over / set of N | |& &| set 10 :|44.44 |1.0 | Modern base_10|& &| set 20 :|42.10 |1.05 | Archaic IndoEuropean base_20|& &| set 30 :|34.48 |1.28 | |& &| set 40 :|30.76 |1.44 ||& &| set 50 :|30.61 |1.45 ||& &| set 60 :|28.81 |1.54 | Babylonian base_60 |& &| set 70 :|27.53 |1.61 ||& &| set 80 :|27.84 |1.59 ||& &| set 90 :|26.96 |1.64 ||& &| set 100 :|25.25 |1.76 | |& &| set 110 :|26.60 |1.67 | |& &| set 120 :|25.21 |1.76 | |& ---- ***Screenshots Section*** ---- ***Screenshots Section*** ****figure 1a. Console wrapper for prime_formula proc **** [Prime_Number_generation] ---- ****figure 1b, Console wrapper for sqrt_sum_of_squares **** [console_wrapper] ---- ****figure 1c, Console wrapper for sqrt_sum_of_squares **** ---- [PERCENTAGE_PRIMES_RELATIVE] ---- ****figure 1d, Market_Rate_Problem **** ---- [Market_Rate_Problem] ---- ****figure 1e, Gauss Approximate Number of Primes **** ---- [gauss approximation of number of primes etcl caluclator PNG] ****figure 2.**** [Gauss Approximate Number of Primes and eTCL demo example calculator graph approx no primes] ****figure 3.**** [Gauss Approximate Number of Primes and eTCL demo example graphr] ****figure 4.**** [Gauss Approximate Number of Primes and eTCL demo example grapSSS] ****figure 5.**** [Gauss Approximate Number of Primes and eTCL LEGENDRE APPROXIMATION] ****figure 6.**** [Gauss Approximate Number of Primes and eTCL demo example absolute error] ****figure 7.**** [Gauss Approximate Number of Primes and eTCL large scale absolute error] ****figure 8.**** [Gauss Approximate Number of Primes and eTCL demo example relative error] ****figure 9.**** ****figure 10.**** [Gauss Approximate Number of Primes regular legendre error] ****figure 11.**** [Gauss Approximate Number of Primes modified legrendre error] ****figure 12.**** [Gauss Approximate Number of Primes riemann traces] ---- ***References:*** * [Primes] * [Oneliner's Pie in the Sky] * [One Liners] * [Comparing Tcl and Python] * [Primes Sieve - on a resizable canvas] from [uniquename] * [TCLLIB] ::math::numtheory * https://en.wikipedia.org/wiki/Prime-counting_function * http://sweet.ua.pt/tos/primes.html#i * http://mathworld.wolfram.com/PrimeCountingFunction.html * http://www.math.uni-bonn.de/people/jbuethe/topics/AnalyticPiX.html * http://primes.utm.edu/notes/rh.html * http://numbers.computation.free.fr/Constants/Primes/pixtable.html * http://numbers.computation.free.fr/Constants/constants.html * on line prime number generator, see * http://www.miniwebtool.com/list-of-prime-numbers/?to=50 * Mathematician pair find prime numbers aren't as random as thought, March 15, 2016 by Bob Yirka, * ref Robert Lemke Oliver and Kannan Soundararajan, Stanford University * google < Prime number theorem Wikipedia > * Probability that a number is prime, John D. Cook, 6 October 2010 * Probability of Next Prime Digit, Kevin's Math Page, Kevin Gong,March 17th, 2016 * Mathematicians Discover Prime Conspiracy, Erica Klarreich , March 13, 2016, Quanta Magazine * Prime Probability: Catch the Wave, Michael M. Ross , Excel spreadsheet, Jan2008 * Prime Numbers and Their Statistical Properties,Dr. Phillip M. Feldman * 19TH CENTURY MATHEMATICS - GAUSS, The Story of Mathematics * A Conjecture about the Density of Prime Numbers, * Lincoln Almir AMARANTE RIBEIRO, Departamento de Física, * Universidade Federal de Minas Gerais, good explanation * Dan Rockmore Stalking the Riemann Hypothesis, The Quest to Find the Hidden Law of Prime Numbers * J. Pintz. On Legendre's prime number formula. Amer. Math. Monthly 87 (1980) * Dusart, Pierre. Estimates of some functions over primes without r.h * Ref. proc sum_primes_to by [dkf] * from [Comparing Tcl and Python] on TCL WIKI * Ref. Sieve of Eratosthenes « Python recipes « = code.activestate.com/recipes/117119/ ---- ---- ***References:*** * Wikipedia search engine < TCL programs > * Wikipedia search engine < TCL introduction > * Wikipedia search engine < prime number > * Google search engine < prime number formulas > * [Seaching for Babylonian Triplets Slot Calculator Example] * [Gauss Approximate Number of Primes and eTCL demo example calculator, numerical analysis] * [KWJ] in [Monster Prime Predicting Formula] ---- * http://scidiv.bcc.ctc.edu/math/pythagoras.html * http://www.saltire.com/applets/pythag/incircle.html * http://math.uic.edu/~fields/puzzle/triples.html * http://rle-vlsi.mit.edu/people/gjcoram/triples.html * http://bsuvc.bsu.edu/home/00lcsapp/maths460.html * http://www.math.utah.edu/~alfeld/teaching/pt.html * http://138.25.60.81/numericon/triples.html * http://www.geom.umn.edu/~demo5337/Group3/ti4.html * http://www-groups.dcs.st-and.ac.uk/~history/PrintHT/Babylonian_Pythagoras.html * Daniel F. Mansfield , N.J. Wildberger. * Plimpton 322 is Babylonian exact sexagesimal trigonometry. * Historia Mathematica, August 2017 DOI: 10.1016/j.hm.2017.08.001 * Newsweek, Babylonian Tablet Could Hold Mathematical * Secrets For Today's Researchers, Josh Lowe , 8/25/17 ---- * Unexpected biases in the distribution of consecutive primes * Robert J. Lemke Oliver, Kannan Soundararajan ,Department of Mathematics, Stanford University * The Last Digit of Prime Numbers - Numberphile on Youtube * Lecture on “Rock, paper, scissors in probability, Tadashi Tokieda * Hardy-Littlewood conjectures. * MATHEMATICS SCIENCE, A new pattern in primes, Shubashree Desikan, Hindu Times * en.wikipedia.org wiki search on Tadashi_Tokieda * https://www.ncbi.nlm.nih.gov articles/PMC4978288/ * Distribution of the units digit of primes, C. M. Ko, National Central University * www.wired.com tadashi-tokieda-finds-startling-objects-in-plain-sight/ ---- ====== ;# References ;# current TCLLIB routines in Math Module math::numtheory::numberPrimesGauss N math::numtheory::numberPrimesLegendre N math::numtheory::numberPrimesLegendreModified N math::numtheory::differenceNumberPrimesLegendreModified lower upper math::numtheory::listPrimePairs lower upper step math::numtheory::listPrimeProgressions lower upper step ====== ---- ---- **Appendix Code** ***appendix TCL programs and scripts *** ---- *** Subroutine Template 5, prime_formula *** ---- ====== # pretty print from autoindent and ased editor # easy eye format, large black type on green # used as testbed for one liners programs # written on Windows 10 on TCL # working under TCL version 8.6 # gold on TCL WIKI , 5/15/2021 package require Tk package require math::numtheory package require math::constants package require math::trig package require math namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory math::trig math::constants } # adapted from tcl-wiki Stats 2011-05-22, arithmetic mean [RLE] # # prime_formula -- # # Return the possible primes in list by one or more # # Arguments: # # args other values are one or more # # Results: prime_formula # proc prime_formula { args} { set list_new [list ] set N [ expr { [ llength $args ] + 1 } ] if { $N == 1 } { return 0 } foreach val $args { lappend list_new [ expr { 16*$val + 15. } ] } return $list_new } # end of initial deck # add cosmetics below to bottom of file console show console eval {.console config -bg palegreen} console eval {.console config -font {fixed 20 bold}} console eval {wm geometry . 40x20} console eval {wm title . " Console wrapper for prime_formula proc"} console eval {. configure -background orange -highlightcolor brown -relief raised -border 30} puts " Console wrapper for prime_formula proc" puts " Return the possible primes in list " puts " formula < 7 11 13 14 > equals possible primes? [ prime_formula 7 11 13 14 ]" ====== ---- ---- *** Subroutine Template 6, Combined Market Rate formula *** ---- ---- ====== ;# pretty print from autoindent and ased editor ;# easy eye console, large black type on green ;# used as testbed for one liners programs ;# written on Windows 10 on TCL ;# working under TCL version 8.6 ;# gold on TCL WIKI , 10Sep2020 ;# Babylonian Combined Market Rate V6 package require Tk package require math::numtheory package require math::constants package require math::trig package require math namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory math::trig math::constants } ;# adapted from tcl Stats 2011-05-22, arithmetic mean ;# ::math::combined_market_rate -- ;# ;# Return the combined_market_rate by one,two, or more given rates ;# market rate defined as quantity per price ;# or 1 over (price per quantity) ;# ;# Arguments: ;# ;# args values are one, two, or more given rates ;# ;# Results: combined_market_rate ;# works for positive numbers, negative numbers, ;# and mixed positive & negative numbers. ;# arg of zero returns zero ;# arg of null returns zero ;# filter foreach drops irregular zero elements from argument proc ::math::combined_market_rate { args} { set sum 0. set N [ expr { [ llength $args ] } ] if { $N == 0 } { return 0 } if { $N == 1 || [ lindex $args 0 ] == 0 } { return 0 } set res {};set counter2 0; ;# filter foreach drops irregular zero elements foreach item $args {if {$item != 0 } {incr counter2 1; lappend res $item } } set counter 0 foreach val $res { set sum [ expr { $sum + 1./$val } ] incr counter 1 } set combined_market_rate1 [ expr { 1./(($sum*1.)/$counter2) } ] return $combined_market_rate1 } ;# various testcases on combined_market_rate ;# puts [::math::combined_market_rate 0.5524 0.4807 0.42918 0.47846 ] ;# answer 0.48131 " ;# puts [ ::math::combined_market_rate .1 .2 .3 .4 ] ;# answer 0.192 ;# ::math::combined_market_rate -.1 -.2 -.3 -.4 ;# answer -0.192, correct ;# operator math formula follows ;# check [/ 1. [/ [+ [/ 1. -.1] [/ 1. -.2] [/ 1. -0.3 ] [/ 1. -0.4] ] 4. ] ] ;# returns -0.192, correct ;# puts " [ ::math::combined_market_rate .1 ] " ;# :math::combined_market_rate -.1 -.2 .3 .4 ;# answer -0.4363636363636364 ;# operator math formula follows ;# set check [/ 1. [/ [+ [/ 1. -.1] [/ 1. -.2] [/ 1. 0.3 ] [/ 1. 0.4] ] 4. ] ] ;# check equals -0.4363636363636364 ;# puts " for (::math::combined_market_rates .1) ;# returns .1 " ;# ::math::combined_market_rate {} ;# null returns zero, correct. ;# ::math::combined_market_rate 0 ;# arg 0 returns zero, correct. ;# addition dated 24sep2018 ;# added filter foreach to remove zero's ;# irregular zeros, ;# test on zero's 0.1 0.0 0.0 0.2 0.3 0.4 ;# returns 0.192 , correct ;# test on zero's 0.1 0.0 0.0 0.2 0.3 0.4 ;# returns 0.192 , correct # end of initial deck # add cosmetics below to bottom of file console show console eval {.console config -bg palegreen} console eval {.console config -font {fixed 20 bold}} console eval {wm geometry . 40x20} console eval {wm title . " Console wrapper for combined market rate proc"} console eval {. configure -background orange -highlightcolor brown -relief raised -border 30} puts " Console wrapper for combined market rate proc" puts " Return the combined market rate from list " puts " formula < 0.5524 0.4807 0.42918 0.47846 > equals market rate? [ ::math::combined_market_rate 0.5524 0.4807 0.42918 0.47846 ]" puts " formula < 7. 11. 13. 14. > equals market rate? [ ::math::combined_market_rate 7. 11. 13. 14. ]" ====== ---- **Hidden Comments Section** <> Please place any comments here, Thanks, [gold] 30Apr2021 <> Numerical Analysis | Toys | Calculator | Mathematics| Example| Toys and Games | Games | Application | GUI ---- <> Development | Concept| Algorithm