Outline on Pseudocode V3

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 20Aug2020



Outline on Pseudocode V3


Preface


gold Update 3/7/2024. Here are some calculations with Pseudocode outline reference to TCL Procedures. Console program outputs data as table in TCL table format and comma delimited spreadsheet. These auxiliary decks are used to proof features or subroutines of the prospective gui program. 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.



Introduction



Not a Replacement for TCL Core


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.




Quick Start on Pseudocode



1. Convert the tasks lists into a formal design that can be used as the basis for coding. Break each task into smaller subtasks or sub-subtasks, and then convert each of these detailed elements into lines of pseudocode. Each pseudocode line will represent one "action."



Pseudocode Example:

    START
    GET user input
    IF user input is valid
        CALL process user input
        DISPLAY processed user input
    ELSE
        DISPLAY invalid input message
    END IF
    END

2. Capitalize initial keywords: The keywords in the pseudocode should be written in all capital letters, as they begin the statement and give special meaning to the operation. READ, WRITE, IF, WHILE, and UNTIL are examples of keywords that should be written in all capital letters.



    START
    GET user input
    IF user input is valid
        CALL process user input
        DISPLAY processed user input
    ELSE
        DISPLAY invalid input message
    END IF
    END


3. Use indentation to show hierarchy: Indentation helps indicate the "boundaries" of the structure within the pseudocode. Sequence structures do not require indentation, but loop or selection structures must indicate which statements are executed within the structure.



    START
        GET user input
        IF user input is valid
            CALL process user input
            DISPLAY processed user input
        ELSE
            DISPLAY invalid input message
        END IF
    END


4. End multiline structures: Structures, such as loops or selections, should be ended to provide clarity. Indentation helps indicate the beginning and end of these structures.


    START
        GET user input
        IF user input is valid
            CALL process user input
            DISPLAY processed user input
        ELSE
            DISPLAY invalid input message
        END IF
    END

5. Keep statements language-independent: This rule does not mean that pseudocode should be written in a specific language; it means that the pseudocode should be designed in a way that is free of special requirements or capabilities unique to specific programming languages. This ensures that the pseudocode can be translated into any programming language.


gold Update 2/29/2024. Note. The term "language independent statements" has caused debate in either a positive or negative light. There has been some heartburn over the meaning of the phrase " language independent statements". Notice the hyphen is zapped here. The term "language independent" as defined here refers to statements in "natural language" that has no known dependencies on the classic computer programming compilers and interpreters. I say classic programming languages, because there were experimental "natural language programs" used in the 1960's. Some well meaning students are taking "language independent statements" to mean not using a human language at all. Well, getting down into the weeds, that is possible in the math and graphic methods and solutions. There are a number of trials that show crows, squirrels, frogs, and rats solving problems with no involvement of human languages. And subject to interpretation, some of the language independent statements and algorithms were chipped on stone and clay tablets in Sumer Ur III, current Iraq.


Pseudocode is a method of describing the steps in an algorithm or other computed process written in plain "natural" language. Pseudocode does not rely on any particular implementation of a computer programming language In other words, the ugly math is off the table and kept out of sight. There are examples of pseudocode solutions for translating into the TCL script, but use includes possible exercises for translating into other computer languages such as Python or C++.


Study on rand procedure in TCL

David T. Ashley From wiki page on rand, D.A. recommends the recurrence. Reference the C. code definition for rand in TCL.


Draft. From this C. code snippet, the variable x is set to an initial seed value (e.g., 12345). The random number is generated by multiplying the seed value by 16807, taking the modulus division by 2147483647, and storing the result in the variable randx. This approach uses modulus division to ensure that the generated random number falls within a specific range. The modulus operator % in TCL returns the remainder of the division operation, which will be an integer value. """ Lehmer suggested that the (Mersenne) prime m = (2**31) - 1 might be an appropriate choice for the modulus. a = 7**5 = 16807 was first suggested by Lewis, Goodman and Miller in 1969 , based largely on the fact that j(z) = 168072 mod 2147483645 """" >>> ? But I am seeing a fraction from expr {rand} in TCL? <<<< In TCL, it's important to note that the rand function in TCL generates a random floating-point number between 0 and 1. If one needs an integer random number, one can multiply the result of rand by a suitable range and then convert it to an integer using the int function. This can help in generating integer random numbers within a desired range.


# ~~~~  C. code definition for rand
x = (16807 * x) MOD 2147483647
# C. code pronounced as “x mod y”. For example, 10 % 2 will be pronounced as ” Ten mod Two”.
# not sure C. code mod is exactly as TCL % or fmod?
# set a 2.9999383 
# expr {fmod($a,1)}  result 0.9999383000000002

puts " Mersenne  prime m = (2**31) - 1 [ expr { (2**31) - 1 } ]"
# 2147483647
puts " seven**5 = [ expr {  7**5  } ]"
# seven**5 = 16807


# Pseudocode
# this is the  "Lehmer" algorithm in Pseudocode 
#   
const a = 16807.0
const m = 2147483647.0
function Random(seed):
    temp = a * seed
    seed = temp - m * Truncate (temp / m)
    return seed / m
# tcl
# this is the  "Lehmer" algorithm translated in TCL 
#  
# constants field
# real constants, not integer arithmetic?
# a = 7**5 = 16807
# Lehmer  suggested that the 
# Mersenne  prime m = (2**31) - 1
set a 16807.0
set m 2147483647.0
# proc to generate random number
proc randomx {seed} {
    set a 16807.0
    set m 2147483647.0
    set temp [expr {$a * $seed}]
    set seed [expr {$temp - $m * int($temp / $m)}]
    return [expr {$seed / $m}]
}
# Usage example
set seed 12345
set random_num [randomx $seed]
puts "Random number generated: $random_num"
# Random number generated: 0.09661652850760917
# Unlike rand in Tcl, this randomx procedure expects a seed value
# every time invoked. Proc is not defaulted to blank entry, though a default 
# & entry error could be loaded up.  


References:


  • GoDuck search engine < Functional Programming >
  • GoDuck search engine < Imperative Programming >
  • GoDuck search engine < Programming Examples >
  • Google search engine < vaporware >
  • Tcllib math::special Special mathematical functions
  • Tcllib math::figurate Evaluate figurate numbers
  • Tcllib simulation::random Pseudo-random number generators
  • Tcllib simulation::montecarlo Monte Carlo simulations
  • Wikipedia search engine < Lehmer random number generator >
  • Professor Frisby's Mostly Adequate Guide to Functional Programming on internet archive
  • Writing code using the Pseudocode Programming Process, article by David Zych
  • Mathematical Methods in Large-scale Computing Units
  • by Derrick H. Lehmer
  • L’Ecuyer, Pierre (January 1999). "Tables of linear congruential generators of different sizes and good lattice structure"
  • Mathematics of Computation. 68
  • A Comprehensive Review of Quantum Random Number PDF
  • Good Pedagogical Random Number Generators
  • from J. Stanley Warford
  • Coding the Lehmer Pseudo random Number Generator
  • from W. H. PAYNE
  • The most commonly used version of the Mersenne Twister algorithm
  • is based on the Mersenne prime expr { 2**19937-1 }
  • TWISTER = 431542479738816264805523551633791983905393504322.....
  • GoDuck search engine < TCL version >
  • One Liners Programs Pie in the Sky
  • One Liners
  • One Liners Programs Compendium [L1 ]
  • WIKI BOOKS, Programming_Examples pdf
  • WIKI BOOKS, Tcl_Programming_Introduction pdf
  • Note. I did find a useful online IDE, jdoodle
  • Note. I can paste, edit, and run an output using this online IDE.
  • How Do I Write Pseudocode? video by Mr. Brown CS
  • Refers to rand, RandMT, Mersenne Twister, & random
  • Suchenworth RS on Horseracing in Tcl.
  • Random Number Generators: Good Ones Are Hard to Find, Keith Willam Miller, pdf online
  • Throwing Two Dice GWM and Dice by Keith Vetter.
  • int from RLE has dice expression expr {1 + int(rand()*6)} RLE.
  • Several Dr. Math emails may reduce some dice issues to simple paths, internet archive.
  • Counting Elements in a List from RWT.


Extra Credit on One Line Procedures




  • Wikipedia search engine < random >
  • Wikipedia search engine < dice >
  • Wikipedia search engine < Programming Examples >
  • Google search engine < vaporware >
  • One Liners Programs Pie in the Sky
  • One Liners
  • One Liners Programs Compendium [L3 ]
  • WIKI BOOKS, Programming_Examples pdf
  • WIKI BOOKS, Tcl_Programming_Introduction pdf
  • google search engine < HgA1c to Average Blood Glucose>
  • Tcllib 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





Hidden Comments Section

Please include your wiki MONIKER and date in your comment with the same courtesy that I will give you. Thanks, gold 12Aug2020


test edit


Coding the Lehmer Pseudorandom Number Generator W. H. PAYNE, J. 1~. RABUNG, AND T. P. BOGYO Washington State University, Pullman, Washington An algorithm and coding technique is presented for quick evaluation of the Lehmer pseudo-random number generator modulo 2 ** 31 -- 1, a prime Mersenne number which produces 2 ** 31 -- 2 numbers, on a p-bit (greater than 31) computer. The computation method is extendible to limited problems in modular arithmetic. Prime factorization for 2 ** 61 -- 2 and a primitive root for 2 ** 61 -- 1, the next largest prime Mersenne number, are given for possible construction of a pseudo-random number generator of increased cycle length. KEY WORDS AND PHRASES: pseudo-random number, random number, modular arithmetic,


# pseudocode
function randomxxx():
    m = 13
    x = array of size m
    a = 7
    i = 0
    c = 0
    p = 1
    temp = 0
    
    x[1] = 1
    
    for i = 1 to m-1:
        x[i+1] = (a^i * x[1]) mod m
    
    print x
    
    p = 1
    temp = a
    
    while temp != 1:
        p = p + 1
        temp = (a * temp) mod m