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 3/8/2024
gold Update 3/7/2024. The Twin Primes procedure is loaded on the Tcllib math::primes module. Reference Routines are listPrimePairs and listPrimeProgressions on Tcllib. Study of Twin Primes features using pseudocode. Console program outputs data as table in TCL table format and comma delimited spreadsheet. These auxiliary decks are used to proof features or subroutines. The Monopoly page from GWM seems closest in theme to what I was trying to learn. Using dice and running with random throws along a track or path like Snakes and Ladders.
gold Update 3/7/2024. The author is retired engineer on Windows 10 and no longer has proofing access to Unix machines. Unix is respected after use of so many decades in engineering, but my wings are lost. I did find a useful online IDE, jdoodle. I can paste from a text file, edit, and run an output using this online IDE.
gold Npte: Some tickets for prime numbers are closed and functions available in Tcllib. Many thanks to Arjen Markus arjen AM & Andreas Kupries for the heavy lifting.
closer: arjenmarkus AM
Emailed comment from AM: I used the sample code to create two new procedures:
listPrimePairs listPrimeProgressions
The first proc listPrimePairs returns a list of pairs of primes that differ by a given number and the second proc listPrimeProgressions returns a list of arithmetic progressions of primes that differ by the given number.
This page on developing pseudocode examples and one line procedures is not a replacement for the current Tcl core and Tcllib, which is much improved since Tcl version 4, and other <faster> language constructs. math ops, Tcllib routines, and other compiled routines can reduce the cost of big-data tasks by about 1/3. The time savings of the core are not always obvious on small quantities of data, like 4 or 5 numbers. Performance of one-line programs may suffer degradation due to lengthy recursion calls, and may be limited by constraints on recursion. Dependence on math operator notation, helper procedures, math check examples, degradation due to lengthy recursion calls, and special library functions should be noted in the comment lines.
gold 3/8/2024 Draft & Check.
# Pseudocode # Procedure: listPrimePairs # Note dependency here on Tcllib proc isprime # Parameters: # lower - lower limit for the interval # upper - upper limit for the interval # step - difference between successive primes (default: 2) # Return: # list of pairs of primes differing the given step procedure listPrimePairs(lower, upper, step=2): # Validation card if upper <= lower: return error: "The upper limit must be larger than the lower limit" if step <= 0: return error: "The step must be at least 1" # Initialize output variable here, list in TCL output = [] # for next loop in TCL for i in range(lower, upper+1): next = i + step if isPrime(i) and isPrime(next): output.append([i, next]) return output End
Pseudocode generates a list of prime number pairs that differ by the given step within the specified interval. The pseudocode uses a similar logic to the original Tcllib script, with some minor modifications to match the pseudocode syntax.
The first 60 prime gaps are:
1, 2, 2, 4, 2, 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 4, 2, 4, 14, 4, 6, 2, 10, 2, 6, 6, 4, 6, 6, 2, 10, 2, 4, 2, 12, 12, 4, 2, 4, 6, 2, 10, 6, 6, 6, 2, 6, 4, 2, ... (sequence A001223 in the OEIS).
The average gap between primes increases as the natural logarithm of these primes, and therefore the ratio of the prime gap to the primes involved decreases (and is asymptotically zero). This is a consequence of the prime number theorem. --- Wikipedia
Taking averages between prime pairs, the positions of 2. what expected?
mean 2, 4, 6, 6, 2, mean 2, 4, 14, 4, 6, 2, mean 2, 10, 6, 6, 6, 2 puts " math_mean = [math_mean 2 4 6 6 2 ]" # 4 puts " math_mean = [math_mean 2 4 14 4 6, 2 ]" # 5 puts " math_mean = [math_mean 2 10 6 6 6, 2 ]" # 5
Omitting outside links here, too transitory on internet.
#Puesdocode function geometric_mean(args): product = 1 N = length(args) for each val in args: product = product * val exponent = 1/N geometric_mean = product ^ exponent return geometric_mean output = geometric_mean([1, 2, 3, 4]) print output # TESTCASES # (1*2)**(1/2) = 1.41421356237 # (1*2*3)**(1/3) = 1.81712059283 # (1*2*3*4)**(1/4) = 2.2133638394 # (4*36*45*50*75)**(1/5) =30
Draft. The procedure ::math::geometric_mean takes two or more values as input and calculates their geometric mean. The code first initializes a variable product to 1, which will be used to store the product of all the input values. The procedure then determines the number of values in the input list args and stores it in the variable N. The code then iterates through each value in the input list, multiplying the current value by the product variable. After the loop, the code calculates the exponent by dividing 1 by the number of values (N). Finally, the code calculates the geometric mean by raising the product variable to the power of the exponent and returns the result. The example usage demonstrates how to call the procedure with values 1, 2, 3, and 4, and prints the result (2.2133638).
set N [ expr { [ llength $args ] + 1 } ] if { $N == 1 } { return 0 } # gm (1 2 3 4) = 2.213363839400643 # gm (1 2 3 ) = 1.8171205928321397 # gm (1 2 ) = 1.4142135623730951 # gm (4 36 45 50 75) = 30.000 # gm {blank } = 0
# geometric_mean arithmetic geometric_mean value proc geometric_mean { args } { set N [ expr { [ llength $args ] + 1 } ] if { $N == 1 } { return 0 } 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 } puts " gm (1 2 3 4) = [ geometric_mean 1 2 3 4 ] " puts " gm (1 2 3 ) = [ geometric_mean 1 2 3 ] " puts " gm (1 2) = [ geometric_mean 1 2 ] " puts " gm (4 36 45 50 75) = [ geometric_mean 4 36 45 50 75 ] " puts " gm {blank } = [ geometric_mean ] "
Please include your wiki MONIKER and date in your comment with the same courtesy that I will give you. Thanks, gold 12Aug2020
test edit
Functional and Imperative Programming Functional programming computes an expression, while imperative programming is a sequence of instructions modifying memory. The former relies on an automatic garbage collector, while the latter requires explicit memory allocation and deallocation. Memory and Execution Control Imperative programming provides greater control over execution and memory representation, but can be less efficient. Functional programming offers higher abstraction and execution safety, with stricter typing and automatic storage reclamation. Historical Perspectives Historically, functional programming was associated with symbolic applications, and imperative programming with numerical applications. However, advances in compiling and garbage collection have improved efficiency and execution safety for both paradigms. The Appeal of Tool Control Language TCL TCL emphasizes that efficiency need not preempt assurance, as long as efficiency remains reasonably good. This approach is gaining popularity among software producers.
gold prompt? Improve, elaborate, explain steps, and explain definitions in numbered steps with numbered steps with details, dates, and elaboration in regard to computer applications, and Tool Control Language TCL ; use titles on each paragraph consisting of 1,2,3 or 4 words? Restrict each paragraph to 30 words or less?
gold prompt? improve, condense, elaborate, explain steps, and explain definitions in numbered steps with numbered steps with details, dates, and elaboration in regard to computer applications, and Tool Control Language TCL ; use titles on each paragraph consisting of 1,2,3 or 4 words? Restrict each paragraph to 30 words or less? Restrict text to third person and impersonal discussion text, substitute one for you, substitute ones for your, use one for he, use ones for his?
..
gold Prompt: improve, condense, elaborate, explain steps, and explain definitions in numbered steps with numbered steps with details, dates, and elaboration in regard to computer applications, and Tool Control Language TCL ; use titles on each paragraph consisting of 1,2,3 or 4 words? Omit blank lines? Restrict each paragraph to 30 words or less? Restrict text to third person and impersonal discussion text, substitute one for you, substitute ones for your, use one for he, use ones for his?
Note. What about all negative values or mixed positive/negative values. Under definitions of arithmetic mean? Under math check. The procedure calculates the mean by summing all values and then dividing the sum by the number of values, regardless of the signs of the values. The arithmetic mean, also known as the average, is calculated by adding up all the values and then dividing the sum by the number of values. This definition applies to all types of values, including negative or mixed positive/negative values. The pseudocode accurately follows this definition by summing all values, regardless of their signs, and then dividing the sum by the number of values.
When calculating the arithmetic mean of a set of values, whether they are all negative, all positive, or a mix of positive and negative values, the process remains the same. The arithmetic mean is calculated by summing all the values and then dividing by the total number of values.
For example, if you have a set of negative values such as (-1, -2, -3), the arithmetic mean would be calculated by adding -1, -2, and -3 together to get -6, and then dividing by 3 (the total number of values) to get an arithmetic mean of -2.
Similarly, if you have a mix of positive and negative values (e.g., 1, -2, 3), you would sum the values (1 + (-2) + 3 = 2) and then divide by 3 to get an arithmetic mean of approximately 0.67.
The arithmetic mean calculation is not affected by the sign of the values, as it is a measure of central tendency that considers the magnitude of the values rather than their sign. ---
# pseudocode # example to illustrate this process: # Function to check if a number is prime function is_prime(n): if n < 2: return False for i from 2 to sqrt(n): if n % i == 0: return False return True # Function to find twin prime pairs and calculate the gap function find_twin_primes(): twin_primes = [] for i from 2 to MAX_NUMBER: if is_prime(i) and is_prime(i + 2): twin_primes.append((i, i + 2)) prime_gaps = [] for pair in twin_primes: gap = pair[1] - pair[0] prime_gaps.append(gap) return prime_gaps # Function to calculate the average of prime gaps function calculate_average(gaps): total = 0 for gap in gaps: total += gap average = total / len(gaps) return average # Main program twin_prime_gaps = find_twin_primes() average_gap = calculate_average(twin_prime_gaps) print("Average gap between twin primes: ", average_gap)
Category Numerical Analysis | Category Toys | Category Calculator | Category Mathematics | Category Example | Toys and Games | Category Games | Category Application | Category GUI |