Error processing request

Parameters

CONTENT_LENGTH0
REQUEST_METHODGET
REQUEST_URI/revision/Babylonian+Square+Side+Rule+%26+Diagonal+Procedure+Algorithm+and+eTCL+demo+example+calculator%2C+numerical+analysis?V=65
QUERY_STRINGV=65
CONTENT_TYPE
DOCUMENT_URI/revision/Babylonian+Square+Side+Rule+&+Diagonal+Procedure+Algorithm+and+eTCL+demo+example+calculator,+numerical+analysis
DOCUMENT_ROOT/var/www/nikit/nikit/nginx/../docroot
SCGI1
SERVER_PROTOCOLHTTP/1.1
HTTPSon
REMOTE_ADDR172.70.100.79
REMOTE_PORT42602
SERVER_PORT4443
SERVER_NAMEwiki.tcl-lang.org
HTTP_HOSTwiki.tcl-lang.org
HTTP_CONNECTIONKeep-Alive
HTTP_ACCEPT_ENCODINGgzip, br
HTTP_X_FORWARDED_FOR3.144.252.140
HTTP_CF_RAY87eff50b7b055c93-ORD
HTTP_X_FORWARDED_PROTOhttps
HTTP_CF_VISITOR{"scheme":"https"}
HTTP_ACCEPT*/*
HTTP_USER_AGENTMozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; [email protected])
HTTP_CF_CONNECTING_IP3.144.252.140
HTTP_CDN_LOOPcloudflare
HTTP_CF_IPCOUNTRYUS

Body


Error

Unknow state transition: LINE -> END

-code

1

-level

0

-errorstack

INNER {returnImm {Unknow state transition: LINE -> END} {}} CALL {my render_wikit {Babylonian Square Side Rule & Diagonal Procedure Algorithm and eTCL demo example calculator, numerical analysis} {**Babylonian Square Side Rule & Diagonal Procedure Algorithm and eTCL demo example calculator, 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  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]
----

<<TOC>>

[gold] Here is some eTCL starter  code for Babylonian Square Side Rule & Diagonal Algorithm  in calculator shell. 

The Babylonian  Square Side Rule from clay tablets was loaded into an eTCL calculator shell. The Babylonian Square Side Rule is of historical interest, but the rule is not very accurate and dependent on an initial input or guess. The square side rule with a single trial input becomes less accurate with increasing N. In some math problems, the Babylonians used the Square Side Rule for calculating the diagonals of squares and rectangles. The Babylonians did not use algebra notation, so the reader will have to bear some anachronisms in the eTCL pseudocode.  Succesive or iterated math solutions are called algorithms and the Square Side Rule procedure is one of the earliest algorithms documented. The TCL procedures are descendants of this idea. 

In the Babylonian problem texts on clay tablets, there are numbers and coefficients which were used in determining geometric dimensions, the amount of materials, and the daily work rates of the workers.  One difficulty is determining the effective power of the numbers in base 60. For example, 20 could represent either 20*3600, 20*60, 20, 20/60, 20/3600, or even 1/20. The basic dimensions of geometric figures and final tallies were presented in the Babylonian accounts on clay tablets, but sometimes the calculations were left off the tablet, broken off, or garbled. At least one approach for the modern reader and using modern terminology is to develop the implied algebraic equations from the Babylonian numbers. Then the eTCL calculator can be run over a number of testcases to validate the algebraic equations. In the eTCL code, extra significant digits are retained to check the function errors, but not to imply greater precision in the algorithm. 

For the first testcase of sqrt 2, the initial trial_square_root entry of 2 gave an error of 6.06 percent. For the second testcase of sqrt 10, the initial trial_square_root entry of 3 gave an error of 0.138 percent. For the third testcase, the initial trial_square_root entry of 9 gave an error of 0.555 percent.
An iterative solution with successive trial_square_root entries loaded as 9, 10.05555, and 10.000153437 showed 1.177E-8 percent error in three interations.

In a previous wiki page, an eTCL calculator was used to generate Babylonian triplets  which are examples from the tablet Plimpton 322 and many other papers. Mansfield and Wildberger have postulated that the Babylonian triplet listings in Plimpton 322 and auxiliary triplets were used in determining the diagonals and side ratios of right triangles, ref below. Not sure I comprehend all the Mansfield and Wildberger efforts, but an eTCL calculator could be adapted to generate the  Babylonian triplet table and calculate the diagonals and side ratios of right triangles from a subset  of numbers, compatible with the standard reciprocal table. There is a infinite set of right triangles, but a finite subset of right triangle and side ratios that can be manipulated with the sexagesimal positive integer subset in  Babylonian standard reciprocal table.

Model problem) Setting up model problem with a priori knowledge. A right triangle has known sides of diagonal 15, base 12, and unknown short side (9). Pythagorean theorem gives in TCL format:

====== [sqrt [- [* 15. 15.] [* 12 12 ]] ] or 9.
======

By inspection in modern terms and decimal notation, the numbers on the remaining part of the tablet ranged in magnitude from 3 to 18548 and fitted into a right triangles give acute angles from 44.8 to 31.3 degrees. In the translations and this page, the term diagonal is preferred to hypotenuse of a right triangle. On the Plimpton tablet, there are many prime numbers in the extant triplets, as noticed in several papers. A triangle with common factors on the diagonal and the other two sides can be reduced into a similar triangle. A triangle with a prime number on any side (and the prime number not a common factor) cannot be reduced further.

----
**Pseudocode Section**
======
    # using  pseudocode for Babylonian procedure algorithm.
            3 quantities needed
            target number
            trial_square_root,   w.a. guess
            formula factor , usually 2 or 3
            set approximate_root [* [/ 1. $formula_factor ] [+ [* [/ 1. $trial_square_root ] $target_number] $trial_square_root ]   ]
            set side5  $trial_square_root
            set side6 [+ [* [/ 1. $trial_square_root ] $target_number] $trial_square_root ]  
            set side7 [* [/ 1. $formula_factor ]] 
     check approx. root from square side rule with sqrt function in TCL
     ref. errorx procedure        
     check_answer   new area =? desired goal , desired goal reached (yes/no)
     set answers and printout with resulting values
======
***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). 

**** Testcase 1   ****
%|table 1|printed in| tcl wiki format|% 
&| quantity| value| comment, if any|& 
&| 1:|testcase_number | |&
&| 2.0 :|target number N  |   |&
&| 2.0 :|trial square root | |& 
&| 2.0 :|function factor | |& 
&| 3.0 :|answers: intermediate term in formula| |&
&| 4.0 :|trial square | |&
&| 1.4142135623730951 :|square root from TCL sqrt function |  |&
&| 6.0660171779821193 :|percentage error |  |&
&| 1.5 :|approximate square root from square side rule |  |&

**** Testcase 2  ****
%|table 2|printed in| tcl wiki format|% 
&| quantity| value| comment, if any|& 
&| 2:|testcase_number | |&
&| 10.0 :|target number N  |   |&
&| 3.0 :|trial square root | |& 
&| 2.0 :|function factor | |& 
&| 6.333333333333333 :|answers: intermediate term in formula| |&
&| 9.0 :|trial square | |&
&| 3.1622776601683795 :|square root from TCL sqrt function |  |&
&| 0.13879257199866935 :|percentage error |  |&
&| 3.1666666666666665 :|approximate square root from square side rule |  |&

**** Testcase 3  ****
%|table 3|printed in| tcl wiki format|% 
&| quantity| value| comment, if any|& 
&| 3:|testcase_number | |&
&| 100.0 :|target number N  |   |&
&| 9.0 :|trial square root | |& 
&| 2.0 :|function factor | |& 
&| 20.111111111111111 :|answers: intermediate term in formula| |&
&| 81.0 :|trial square | |&
&| 10.0 :|square root from TCL sqrt function |  |&
&| 0.55555555555555358 :|percentage error |  |&
&| 10.055555555555555 :|approximate square root from square side rule |  |&

***Screenshots Section***
****figure 1.****

[Babylonian Square Side Rule png]

---- 
***References:***
   * Daniel F. Mansfield , N.J. Wildberger.
   * Plimpton 322 is Babylonian exact sexagesimal trigonometry.
   * Ref. square side rule
   * 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 
   * Plimpton 322 Tablet and the Babylonian Method of
   * Generating Pythagorean Triples,
   * Abdulrahman A. Abdulaziz, University of Balamand, 2010
   * [Seaching for Babylonian Triplets Slot Calculator Example]
   * [Babylonian trailing edge algorithm and reverse sequence algorithm for reciprocals, eTCL demo example calculator, numerical analysis]
   * [Babylonian Field Expansion Procedure Algorithm and eTCL demo example calculator, numerical analysis]
   * [Babylonian False Position Algorithm and eTCL demo example calculator, numerical analysis]
   * A Geometric Algorithm with Solutions to Quadratic Equations
   * in a Sumerian Juridical Document from Ur III Umma
   * Joran Friberg,  Chalmers University of Technology, Gothenburg, Sweden
   * google search engine <Trapezoid area bisection> 
   * Wikipedia search engine <Trapezoid area > 
   * mathworld.wolfram.com, Trapezoid and right trapezoid
   * Mathematical Treasure: Old Babylonian Area Calculation, uses ancient method
   * Frank J. Swetz , Pennsylvania State University
   * Wikipedia, see temple of Edfu, area method used as late as 200 BC in Egypt.
   * Wikipedia, Methods of computing square roots,
   * Ref. square side rule also known as Babylonian method or Heron's method
   * [Another simple database]
   * [Richard Suchenwirth] 
   * [editRecord]
   * [Oneliner's Pie in the Sky], ref. errorx procedure 
   * [One Liners] 
   * [Category Algorithm]
   * [Square Root]
   * [Babylonian Number Series and eTCL demo example calculator]
   * [Brahmagupta Area of Cyclic Quadrilateral and eTCL demo example calculator]
   * [Gauss Approximate Number of Primes and eTCL demo example calculator]
   * Land surveying in ancient Mesopotamia, M. A. R. Cooper
   * [Sumerian Approximate Area Quadrilateral and eTCL Slot Calculator Demo Example , numerical analysis] 
   * Thomas G. Edwards, Using the Ancient Method of False Position to Find Solutions
   * Joy B. Easton, rule of double false position
   * Vera Sanford, rule of false position
   * www.britannica.com, topic, mathematics trapezoid
   * [Sumerian Equivalency Values, Ratios, and the Law of Proportions with Demo Example Calculator]
   * [Babylonian Sexagesimal Notation for Math on Clay Tablets in Console Example] 
   * Late Babylonian Field Plans in the British Museum, books.google.com/books 
   * Karen Rhea Nemet-Nejat
   * Late Babylonian Surface Mensuration Author(s): Marvin A. Powell Source: jstor
   * Poles and walls in Mesopotamia and Egypt , Melville,
   * www.sciencedirect.com/science/article
   * Pythagorean ‘Rule’ and ‘Theorem’ – Mirror of the Relation Between Babylonian and Greek Mathematics,
   * Jens Høyrup, Roskilde University
   * On Plimpton 322. Pythagorean numbers in Babylonian mathematics, E. M. Bruins
   * PLIMPTON 322: A UNIVERSAL CUNEIFORM TABLE FOR OLD BABYLONIAN
   * MATHEMATICIANS, BUILDERS, SURVEYORS AND TEACHERS
   * Rudolf Hajossy

----
**Appendix Code**

***appendix TCL programs and scripts ***

======
        # pretty print from autoindent and ased editor
        # Babylonian Square Side Rule calculator
        # written on Windows XP on eTCL
        # working under TCL version 8.5.6 and eTCL 1.0.1
        # gold on TCL WIKI, 2oct2017
        package require Tk
        package require 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 {{} {target number N :} }
        lappend names {trial square root:}
        lappend names {formula factor: }
        lappend names {answers: intermediate term in formula }
        lappend names {trial square :}
        lappend names {square root from TCL sqrt function : }
        lappend names {percentage error: }
        lappend names {approximate square root from square side rule :} 
        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 Square Side Rule
            from TCL WIKI,
            written on eTCL "
            tk_messageBox -title "About" -message $msg } 
       proc ::tcl::mathfunc::precision {precision float}  {
            #  tcl:wiki:Floating-point formatting, [AM]
            set x [ format "%#.5g" $float ]
            return $x
           }   
            #proc errorx always returns a positive error. 
            #Normally assume $aa is human estimate,
            #assume $bb is divinely exact.
       proc errorx  {aa bb} {expr { $aa > $bb ?   (($aa*1.)/$bb -1.)*100. : (($bb*1.)/$aa -1.)*100.}}
       proc calculate {     } {
            global answer2
            global side1 side2 side3 side4 side5
            global side6 side7 side8 
            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 target_number $side1
            set trial_square_root $side2
            set formula_factor $side3
       set approximate_root [* [/ 1. $formula_factor ] [+ [* [/ 1. $trial_square_root ] $target_number] $trial_square_root ]   ]
            set side4 [+ [* [/ 1. $trial_square_root ] $target_number] $trial_square_root ]  
            set side5 [* $trial_square_root $trial_square_root]
            set side6 [sqrt $target_number ]  
            set side7 [ errorx $approximate_root [sqrt  $target_number ]   ]
            set side8 $approximate_root
                    }
        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 answer2
            global side1 side2 side3 side4 side5
            global side6 side7 side8
            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 :|target number N  |   |&"
            puts "&| $side2 :|trial square root | |& "  
            puts "&| $side3 :|function factor | |& "
            puts "&| $side4 :|answers: intermediate term in formula| |&"
            puts "&| $side5 :|trial square | |&"
            puts "&| $side6 :|square root from TCL sqrt function |  |&"
            puts "&| $side7 :|percentage error |  |&"
            puts "&| $side8 :|approximate square root from square side rule |  |&" 
            }
        frame .buttons -bg aquamarine4
        ::ttk::button .calculator -text "Solve" -command { set side8 0 ; calculate   }
        ::ttk::button .test2 -text "Testcase1" -command {clearx;fillup 2.  2.0  2.0 3.0  4.0   1.414    6.066  1.5}
        ::ttk::button .test3 -text "Testcase2" -command {clearx;fillup 10.0 3.0 2.0 6.333 9.0   3.162 0.138     3.166}
        ::ttk::button .test4 -text "Testcase3" -command {clearx;fillup 100.0 9.0 2.0  20.111  81.0    10.0  0.5555  10.0555}
        ::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 . "Babylonian Square Side Rule 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 for Newton's Method***
======
        # gold on TCL WIKI, 2oct2017
        # console program for square root
        # additional verbose Newton's Method
        package require Tk
        package require math::numtheory
        set tcl_precision 17
             console show
             namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory }
         proc square_root_function { number_for_root  } {   
             set counter 0
             set epsilon .0001
             while { $counter < 50.  } {
             if { [* $counter $counter 1. ]   > [* $number_for_root 1.] } {break}            
             incr counter 
             }   
             set  square_root_estimate $counter
             while {1} {
             set keeper $square_root_estimate        
             set starter $square_root_estimate
             set remainder   [* $starter $starter  1. ]  
             set remainder [- $number_for_root [* $starter $starter  1. ] ]
             set  square_root_estimate  [+ $starter [/ $remainder [* 2. $starter ]]]
             if {abs($keeper - $square_root_estimate) < $epsilon} break
                   }
             return $square_root_estimate
                }     
            puts " [ square_root_function 10. ] "
======
----

*** Version 2 Diagonal calculator with extended and modified Plimpton 322 dataset***
======
        # pretty print from autoindent and ased editor
        # Babylonian Square Side Rule & Diagonal calculator,  Version 2
        # Version 2 tests database invoke
        # from modified and extended Plimpton 322 dataset
        # dataset includes numbers not on original tablet
        # Using Suchenworth code from Another Database, TCL WIKI
        # written on Windows XP on eTCL
        # working under TCL version 8.5.6 and eTCL 1.0.1
        # gold on TCL WIKI, 2oct2017
        package require Tk
        package require 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 {{} {target number N :} }
        lappend names {trial square root:}
        lappend names {formula factor: }
        lappend names {answers: intermediate term in formula }
        lappend names {trial square :}
        lappend names {square root from TCL sqrt function : }
        lappend names {percentage error: }
        lappend names {approximate square root from square side rule :} 
        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 Square Side Rule
            from TCL WIKI,
            written on eTCL "
            tk_messageBox -title "About" -message $msg } 
       proc ::tcl::mathfunc::precision {precision float}  {
            #  tcl:wiki:Floating-point formatting, [AM]
            set x [ format "%#.5g" $float ]
            return $x
           }   
            #proc errorx always returns a positive error. 
            #Normally assume $aa is human estimate,
            #assume $bb is divinely exact.
       proc errorx  {aa bb} {expr { $aa > $bb ?   (($aa*1.)/$bb -1.)*100. : (($bb*1.)/$aa -1.)*100.}}
       proc calculate {     } {
            global answer2
            global side1 side2 side3 side4 side5
            global side6 side7 side8 
            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 target_number $side1
            set trial_square_root $side2
            set formula_factor $side3
       set approximate_root [* [/ 1. $formula_factor ] [+ [* [/ 1. $trial_square_root ] $target_number] $trial_square_root ]   ]
            set side4 [+ [* [/ 1. $trial_square_root ] $target_number] $trial_square_root ]  
            set side5 [* $trial_square_root $trial_square_root]
            set side6 [sqrt $target_number ]  
            set side7 [ errorx $approximate_root [sqrt  $target_number ]   ]
            set side8 $approximate_root
                    }
        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 answer2
            global side1 side2 side3 side4 side5
            global side6 side7 side8
            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 :|target number N  |   |&"
            puts "&| $side2 :|trial square root | |& "  
            puts "&| $side3 :|function factor | |& "
            puts "&| $side4 :|answers: intermediate term in formula| |&"
            puts "&| $side5 :|trial square | |&"
            puts "&| $side6 :|square root from TCL sqrt function |  |&"
            puts "&| $side7 :|percentage error |  |&"
            puts "&| $side8 :|approximate square root from square side rule |  |&" 
            }
        frame .buttons -bg aquamarine4
        ::ttk::button .calculator -text "Solve" -command { set side8 0 ; calculate   }
        ::ttk::button .test2 -text "Testcase1" -command {clearx;fillup 2.  2.0  2.0 3.0  4.0   1.414    6.066  1.5}
        ::ttk::button .test3 -text "Testcase2" -command {clearx;fillup 10.0 3.0 2.0 6.333 9.0   3.162 0.138     3.166}
        ::ttk::button .test4 -text "Testcase3" -command {clearx;fillup 100.0 9.0 2.0  20.111  81.0    10.0  0.5555  10.0555}
        ::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 . "Babylonian Square Side Rule Calculator"          
       # Start diagonal solver code
       proc select {fields "from" tbl "where" condition} {
       #Suchenworth subroutine code from Another Database, TCL WIKI
       set infields [lindex $tbl 0]
       if {$fields eq "*"} {set fields $infields}
       set res [list $fields]
       foreach inrow [lrange $tbl 1 end] {
          foreach $infields $inrow break
          if $condition {
            set row {}
            foreach field $fields {lappend row [set $field]}
            lappend res $row
        }
        }
       set res
       }
       set table {
      {number fraction_squares long_side short_side  diagonal_side suppose_angle line }
      { 1 .9834028 120 119 169 44.76 1 }
      { 2 .9491586 3456 3367 4825 44.25 2 }
      { 3 .9188021 4800 4601 6649 43.79 3 }
      { 4 .8862479 13500 12709 18541 43.27 4 }
      { 5 .8150077 72 65 97 42.08 5 }
      { 6 .7851929 360 319 481 41.54 6 }
      { 7 .7199837 2700 2291 3541 40.32 7 }
      { 8 .6927094 960 799 1249 39.77 8 }
      { 9 .6426694 600 481 769 38.72 9 }
      { 10 .5861226 6480 4961 8161 37.44 10 }
      { 11 .5625 60 45 75 36.87 11 }
      { 12 .4894168 2400 1679 2929 34.98 12 }
      { 13 .4500174 240 161 289 33.86 13 }
      { 14 .4302388 2700 1771 3229 33.26 14 }
      { 15 .3871605 90 56 106 31.89 15 }
      { 16 .1 1 175 337 1 16 }
      { 17 .1 1 473 985 1 17 }
      { 18 .1 1 1679 2929 1 18 }
      { 19 .1 1 161 289 1 19 }
      { 20 .1 1 1771 3229 1 20 }
      { 21 .1 1 56 106 1 21 }
      { 22 .1 1 4961 8161 1 22 }
      { 23 .1 1 1 75 1 23 }
      { 24 .1 1 1679 2929 1 24 }
      { 25 .1 1 161 289 1 25 }
      { 26 .1 1 1771 3049 1 26 }
      { 27 .1 1 301 949 1 27 }
      { 28 .1 1 329 1129 1 28 }
      { 29 .1 1 7 25 1 29 }
      { 30 .1 1 399 1649 1 30 }
      { 31 .1 1 9 41 1 31 }
      { 32 .1 1 11 61 1 32 }
      { 33 .1 1 295 1753 1 33 }
      { 34 .1 1 17 145 1 34 }
      { 35 .1 1 19 181 1 35 }
      { 36 .1 1 52 677 1 36 }
      { 37 .1 1 31 481 1 37 }
      { 38 .1 1 49 1201 1 38 }
      }
      puts [ select * from $table where {$line < 100} ]
      puts [ select {diagonal_side short_side } from $table where {$line != 15} ]
======
*** comma delimited spreadsheet of extended Plimpton 322 ***
======
number,fraction_squares,long_side,short_side,diagonal_side,suppose_angle,line
1,0.9834028,120,119,169,44.76,1
2,0.9491586,3456,3367,4825,44.25,2
3,0.9188021,4800,4601,6649,43.79,3
4,0.8862479,13500,12709,18541,43.27,4
5,0.8150077,72,65,97,42.08,5
6,0.7851929,360,319,481,41.54,6
7,0.7199837,2700,2291,3541,40.32,7
8,0.6927094,960,799,1249,39.77,8
9,0.6426694,600,481,769,38.72,9
10,0.5861226,6480,4961,8161,37.44,10
11,0.5625,60,45,75,36.87,11
12,0.4894168,2400,1679,2929,34.98,12
13,0.4500174,240,161,289,33.86,13
14,0.4302388,2700,1771,3229,33.26,14
15,0.3871605,90,56,106,31.89,15
16,0.369225019290123,288,175,337,1,16
17,0.299705557698903,864,473,985,1,17
18,0.489416840277778,2400,1679,2929,1,18
19,0.450017361111111,240,161,289,1,19
20,0.430238820301783,2700,1771,3229,1,20
21,0.387160493827161,90,56,106,1,21
22,0.586122566110349,6480,4961,8161,1,22
23,0.000177777777777778,75,1,75,1,23
24,0.489416840277778,2400,1679,2929,1,24
25,0.450017361111111,240,161,289,1,25
26,0.509135720783517,2482,1771,3049,1,26
27,0.111853086419753,900,301,949,1,27
28,0.0927992112482853,1080,329,1129,1,28
29,0.0850694444444444,24,7,25,1,29
30,0.062187890625,1600,399,1649,1,30
31,0.050625,40,9,41,1,31
32,0.0336111111111111,60,11,61,1,32
33,0.0291444964206104,1728,295,1753,1,33
34,0.0139371141975309,144,17,145,1,34
35,0.011141975308642,180,19,181,1,35
36,0.00593470507544582,675,52,677,1,36
37,0.00417100694444444,480,31,481,1,37
38,0.00166736111111111,1200,49,1201,1,38
======
----
*** comma delimited spreadsheet of TEST prime numbers & Plimpton 322 ***
======
number,fraction_squares,delta**2,long_side,is_prime,short_side,is_prime,diagonal_side,is_prime,side_ratio,acute_angle,complement_angle,line
1,0.9834028,1.9834028,120,FALSE,119,FALSE,169,FALSE,1.00840336134454,44.7602701039192,45.2397298960808,1
2,0.9491586,1.9491586,3456,FALSE,3367,FALSE,4825,FALSE,1.02643302643303,44.2526696187466,45.7473303812534,2
3,0.9188021,1.9188021,4800,FALSE,4601,FALSE,6649,FALSE,1.04325146707238,43.7873462834569,46.2126537165431,3
4,0.8862479,1.8862479,13500,FALSE,12709,FALSE,18541,TRUE,1.06223935793532,43.2713110478808,46.7286889521192,4
5,0.8150077,1.8150077,72,FALSE,65,FALSE,97,TRUE,1.10769230769231,42.0750220508436,47.9249779491564,5
6,0.7851929,1.7851929,360,FALSE,319,FALSE,481,FALSE,1.12852664576803,41.5445093640917,48.4554906359083,6
7,0.7199837,1.7199837,2700,FALSE,2291,FALSE,3541,TRUE,1.17852466171977,40.3152217890896,49.6847782109104,7
8,0.6927094,1.6927094,960,FALSE,799,FALSE,1249,TRUE,1.20150187734668,39.7703302277109,50.2296697722891,8
9,0.6426694,1.6426694,600,FALSE,481,FALSE,769,TRUE,1.24740124740125,38.7179883513894,51.2820116486106,9
10,0.5861226,1.5861226,6480,FALSE,4961,FALSE,8161,TRUE,1.30618826849426,37.4371779573597,52.5628220426403,10
11,0.5625,1.5625,60,FALSE,45,FALSE,75,FALSE,1.33333333333333,36.869897645844,53.130102354156,11
12,0.4894168,1.4894168,2400,FALSE,1679,FALSE,2929,FALSE,1.42942227516379,34.9759947522971,55.0240052477029,12
13,0.4500174,1.4500174,240,FALSE,161,FALSE,289,FALSE,1.49068322981366,33.8550261282941,56.1449738717059,13
14,0.4302388,1.4302388,2700,FALSE,1771,FALSE,3229,TRUE,1.52456239412761,33.2619074134428,56.7380925865572,14
15,0.3871605,1.3871605,90,FALSE,56,FALSE,106,FALSE,1.60714285714286,31.8907918018457,58.1092081981543,15
16,0.369225019290123,1.36922501929012,288,FALSE,175,FALSE,337,TRUE,1.64571428571429,31.2844929144175,58.7155070855825,16
17,0.299705557698903,1.2997055576989,864,FALSE,473,FALSE,985,FALSE,1.82663847780127,28.6986640858943,61.3013359141057,17
18,0.489416840277778,1.48941684027778,2400,FALSE,1679,FALSE,2929,FALSE,1.42942227516379,34.9759947522971,55.0240052477029,18
19,0.450017361111111,1.45001736111111,240,FALSE,161,FALSE,289,FALSE,1.49068322981366,33.8550261282941,56.1449738717059,19
20,0.430238820301783,1.43023882030178,2700,FALSE,1771,FALSE,3229,TRUE,1.52456239412761,33.2619074134428,56.7380925865572,20
21,0.387160493827161,1.38716049382716,90,FALSE,56,FALSE,106,FALSE,1.60714285714286,31.8907918018457,58.1092081981543,21
22,0.586122566110349,1.58612256611035,12,FALSE,5,TRUE,13,TRUE,2.4,22.619,67.381,22
23,0.000177777777777778,1.00017777777778,75,FALSE,871,FALSE,2329,FALSE,0.0861079219288175,21.9613,68.0387,23
24,0.489416840277778,1.48941684027778,2400,FALSE,1679,FALSE,2929,FALSE,1.42942227516379,34.9759947522971,55.0240052477029,24
25,0.450017361111111,1.45001736111111,240,FALSE,161,FALSE,289,FALSE,1.49068322981366,33.8550261282941,56.1449738717059,25
26,0.509135720783517,1.50913572078352,2482,FALSE,1771,FALSE,3049,TRUE,1.40146809712027,35.5100803990245,54.4899196009755,26
27,0.111853086419753,1.11185308641975,900,FALSE,301,FALSE,949,FALSE,2.99003322259136,18.4922254911265,71.5077745088735,27
28,0.0927992112482853,1.09279921124829,1080,FALSE,329,FALSE,1129,TRUE,3.28267477203647,16.9422892660297,73.0577107339703,28
29,0.0850694444444444,1.08506944444444,24,FALSE,7,TRUE,25,FALSE,3.42857142857143,16.260204708312,73.739795291688,29
30,0.062187890625,1.062187890625,1600,FALSE,399,FALSE,1649,FALSE,4.01002506265664,14.0025351149907,75.9974648850093,30
31,0.050625,1.050625,40,FALSE,9,FALSE,41,TRUE,4.44444444444444,12.6803834918198,77.3196165081802,31
32,0.0336111111111111,1.03361111111111,60,FALSE,11,TRUE,61,TRUE,5.45454545454545,10.3888578154696,79.6111421845304,32
33,0.0291444964206104,1.02914449642061,1728,FALSE,295,FALSE,1753,TRUE,5.85762711864407,9.68800075016136,80.3119992498386,33
34,0.0139371141975309,1.01393711419753,144,FALSE,17,TRUE,145,FALSE,8.47058823529412,6.7329213268596,83.2670786731404,34
35,0.011141975308642,1.01114197530864,180,FALSE,19,TRUE,181,TRUE,9.47368421052632,6.02557500836668,83.9744249916333,35
36,0.00593470507544582,1.00593470507545,675,FALSE,52,FALSE,677,TRUE,12.9807692307692,4.40519632353161,85.5948036764684,36
37,0.00417100694444444,1.00417100694444,480,FALSE,31,TRUE,481,FALSE,15.4838709677419,3.69522053198919,86.3047794680108,37
38,0.00166736111111111,1.00166736111111,1200,FALSE,49,FALSE,1201,TRUE,24.4897959183673,2.33827865581484,87.6617213441852,38
,,delta**2-1,,equals,,(l/d)**2,or,(b/d)**2,,,,

======

----
[gold] This page is copyrighted under the TCL/TK license terms, [http://tcl.tk/software/tcltk/license.html%|%this license]. 

**Comments Section**

<<discussion>>
Please place any comments here, Thanks.

                              
<<categories>> Numerical Analysis | Toys | Calculator | Mathematics| Example| Toys and Games | Games | Application | GUI

<<categories>> Development | Concept| Algorithm | Procedure} regexp2} CALL {my render {Babylonian Square Side Rule & Diagonal Procedure Algorithm and eTCL demo example calculator, numerical analysis} {**Babylonian Square Side Rule & Diagonal Procedure Algorithm and eTCL demo example calculator, 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  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]
----

<<TOC>>

[gold] Here is some eTCL starter  code for Babylonian Square Side Rule & Diagonal Algorithm  in calculator shell. 

The Babylonian  Square Side Rule from clay tablets was loaded into an eTCL calculator shell. The Babylonian Square Side Rule is of historical interest, but the rule is not very accurate and dependent on an initial input or guess. The square side rule with a single trial input becomes less accurate with increasing N. In some math problems, the Babylonians used the Square Side Rule for calculating the diagonals of squares and rectangles. The Babylonians did not use algebra notation, so the reader will have to bear some anachronisms in the eTCL pseudocode.  Succesive or iterated math solutions are called algorithms and the Square Side Rule procedure is one of the earliest algorithms documented. The TCL procedures are descendants of this idea. 

In the Babylonian problem texts on clay tablets, there are numbers and coefficients which were used in determining geometric dimensions, the amount of materials, and the daily work rates of the workers.  One difficulty is determining the effective power of the numbers in base 60. For example, 20 could represent either 20*3600, 20*60, 20, 20/60, 20/3600, or even 1/20. The basic dimensions of geometric figures and final tallies were presented in the Babylonian accounts on clay tablets, but sometimes the calculations were left off the tablet, broken off, or garbled. At least one approach for the modern reader and using modern terminology is to develop the implied algebraic equations from the Babylonian numbers. Then the eTCL calculator can be run over a number of testcases to validate the algebraic equations. In the eTCL code, extra significant digits are retained to check the function errors, but not to imply greater precision in the algorithm. 

For the first testcase of sqrt 2, the initial trial_square_root entry of 2 gave an error of 6.06 percent. For the second testcase of sqrt 10, the initial trial_square_root entry of 3 gave an error of 0.138 percent. For the third testcase, the initial trial_square_root entry of 9 gave an error of 0.555 percent.
An iterative solution with successive trial_square_root entries loaded as 9, 10.05555, and 10.000153437 showed 1.177E-8 percent error in three interations.

In a previous wiki page, an eTCL calculator was used to generate Babylonian triplets  which are examples from the tablet Plimpton 322 and many other papers. Mansfield and Wildberger have postulated that the Babylonian triplet listings in Plimpton 322 and auxiliary triplets were used in determining the diagonals and side ratios of right triangles, ref below. Not sure I comprehend all the Mansfield and Wildberger efforts, but an eTCL calculator could be adapted to generate the  Babylonian triplet table and calculate the diagonals and side ratios of right triangles from a subset  of numbers, compatible with the standard reciprocal table. There is a infinite set of right triangles, but a finite subset of right triangle and side ratios that can be manipulated with the sexagesimal positive integer subset in  Babylonian standard reciprocal table.

Model problem) Setting up model problem with a priori knowledge. A right triangle has known sides of diagonal 15, base 12, and unknown short side (9). Pythagorean theorem gives in TCL format:

====== [sqrt [- [* 15. 15.] [* 12 12 ]] ] or 9.
======

By inspection in modern terms and decimal notation, the numbers on the remaining part of the tablet ranged in magnitude from 3 to 18548 and fitted into a right triangles give acute angles from 44.8 to 31.3 degrees. In the translations and this page, the term diagonal is preferred to hypotenuse of a right triangle. On the Plimpton tablet, there are many prime numbers in the extant triplets, as noticed in several papers. A triangle with common factors on the diagonal and the other two sides can be reduced into a similar triangle. A triangle with a prime number on any side (and the prime number not a common factor) cannot be reduced further.

----
**Pseudocode Section**
======
    # using  pseudocode for Babylonian procedure algorithm.
            3 quantities needed
            target number
            trial_square_root,   w.a. guess
            formula factor , usually 2 or 3
            set approximate_root [* [/ 1. $formula_factor ] [+ [* [/ 1. $trial_square_root ] $target_number] $trial_square_root ]   ]
            set side5  $trial_square_root
            set side6 [+ [* [/ 1. $trial_square_root ] $target_number] $trial_square_root ]  
            set side7 [* [/ 1. $formula_factor ]] 
     check approx. root from square side rule with sqrt function in TCL
     ref. errorx procedure        
     check_answer   new area =? desired goal , desired goal reached (yes/no)
     set answers and printout with resulting values
======
***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). 

**** Testcase 1   ****
%|table 1|printed in| tcl wiki format|% 
&| quantity| value| comment, if any|& 
&| 1:|testcase_number | |&
&| 2.0 :|target number N  |   |&
&| 2.0 :|trial square root | |& 
&| 2.0 :|function factor | |& 
&| 3.0 :|answers: intermediate term in formula| |&
&| 4.0 :|trial square | |&
&| 1.4142135623730951 :|square root from TCL sqrt function |  |&
&| 6.0660171779821193 :|percentage error |  |&
&| 1.5 :|approximate square root from square side rule |  |&

**** Testcase 2  ****
%|table 2|printed in| tcl wiki format|% 
&| quantity| value| comment, if any|& 
&| 2:|testcase_number | |&
&| 10.0 :|target number N  |   |&
&| 3.0 :|trial square root | |& 
&| 2.0 :|function factor | |& 
&| 6.333333333333333 :|answers: intermediate term in formula| |&
&| 9.0 :|trial square | |&
&| 3.1622776601683795 :|square root from TCL sqrt function |  |&
&| 0.13879257199866935 :|percentage error |  |&
&| 3.1666666666666665 :|approximate square root from square side rule |  |&

**** Testcase 3  ****
%|table 3|printed in| tcl wiki format|% 
&| quantity| value| comment, if any|& 
&| 3:|testcase_number | |&
&| 100.0 :|target number N  |   |&
&| 9.0 :|trial square root | |& 
&| 2.0 :|function factor | |& 
&| 20.111111111111111 :|answers: intermediate term in formula| |&
&| 81.0 :|trial square | |&
&| 10.0 :|square root from TCL sqrt function |  |&
&| 0.55555555555555358 :|percentage error |  |&
&| 10.055555555555555 :|approximate square root from square side rule |  |&

***Screenshots Section***
****figure 1.****

[Babylonian Square Side Rule png]

---- 
***References:***
   * Daniel F. Mansfield , N.J. Wildberger.
   * Plimpton 322 is Babylonian exact sexagesimal trigonometry.
   * Ref. square side rule
   * 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 
   * Plimpton 322 Tablet and the Babylonian Method of
   * Generating Pythagorean Triples,
   * Abdulrahman A. Abdulaziz, University of Balamand, 2010
   * [Seaching for Babylonian Triplets Slot Calculator Example]
   * [Babylonian trailing edge algorithm and reverse sequence algorithm for reciprocals, eTCL demo example calculator, numerical analysis]
   * [Babylonian Field Expansion Procedure Algorithm and eTCL demo example calculator, numerical analysis]
   * [Babylonian False Position Algorithm and eTCL demo example calculator, numerical analysis]
   * A Geometric Algorithm with Solutions to Quadratic Equations
   * in a Sumerian Juridical Document from Ur III Umma
   * Joran Friberg,  Chalmers University of Technology, Gothenburg, Sweden
   * google search engine <Trapezoid area bisection> 
   * Wikipedia search engine <Trapezoid area > 
   * mathworld.wolfram.com, Trapezoid and right trapezoid
   * Mathematical Treasure: Old Babylonian Area Calculation, uses ancient method
   * Frank J. Swetz , Pennsylvania State University
   * Wikipedia, see temple of Edfu, area method used as late as 200 BC in Egypt.
   * Wikipedia, Methods of computing square roots,
   * Ref. square side rule also known as Babylonian method or Heron's method
   * [Another simple database]
   * [Richard Suchenwirth] 
   * [editRecord]
   * [Oneliner's Pie in the Sky], ref. errorx procedure 
   * [One Liners] 
   * [Category Algorithm]
   * [Square Root]
   * [Babylonian Number Series and eTCL demo example calculator]
   * [Brahmagupta Area of Cyclic Quadrilateral and eTCL demo example calculator]
   * [Gauss Approximate Number of Primes and eTCL demo example calculator]
   * Land surveying in ancient Mesopotamia, M. A. R. Cooper
   * [Sumerian Approximate Area Quadrilateral and eTCL Slot Calculator Demo Example , numerical analysis] 
   * Thomas G. Edwards, Using the Ancient Method of False Position to Find Solutions
   * Joy B. Easton, rule of double false position
   * Vera Sanford, rule of false position
   * www.britannica.com, topic, mathematics trapezoid
   * [Sumerian Equivalency Values, Ratios, and the Law of Proportions with Demo Example Calculator]
   * [Babylonian Sexagesimal Notation for Math on Clay Tablets in Console Example] 
   * Late Babylonian Field Plans in the British Museum, books.google.com/books 
   * Karen Rhea Nemet-Nejat
   * Late Babylonian Surface Mensuration Author(s): Marvin A. Powell Source: jstor
   * Poles and walls in Mesopotamia and Egypt , Melville,
   * www.sciencedirect.com/science/article
   * Pythagorean ‘Rule’ and ‘Theorem’ – Mirror of the Relation Between Babylonian and Greek Mathematics,
   * Jens Høyrup, Roskilde University
   * On Plimpton 322. Pythagorean numbers in Babylonian mathematics, E. M. Bruins
   * PLIMPTON 322: A UNIVERSAL CUNEIFORM TABLE FOR OLD BABYLONIAN
   * MATHEMATICIANS, BUILDERS, SURVEYORS AND TEACHERS
   * Rudolf Hajossy

----
**Appendix Code**

***appendix TCL programs and scripts ***

======
        # pretty print from autoindent and ased editor
        # Babylonian Square Side Rule calculator
        # written on Windows XP on eTCL
        # working under TCL version 8.5.6 and eTCL 1.0.1
        # gold on TCL WIKI, 2oct2017
        package require Tk
        package require 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 {{} {target number N :} }
        lappend names {trial square root:}
        lappend names {formula factor: }
        lappend names {answers: intermediate term in formula }
        lappend names {trial square :}
        lappend names {square root from TCL sqrt function : }
        lappend names {percentage error: }
        lappend names {approximate square root from square side rule :} 
        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 Square Side Rule
            from TCL WIKI,
            written on eTCL "
            tk_messageBox -title "About" -message $msg } 
       proc ::tcl::mathfunc::precision {precision float}  {
            #  tcl:wiki:Floating-point formatting, [AM]
            set x [ format "%#.5g" $float ]
            return $x
           }   
            #proc errorx always returns a positive error. 
            #Normally assume $aa is human estimate,
            #assume $bb is divinely exact.
       proc errorx  {aa bb} {expr { $aa > $bb ?   (($aa*1.)/$bb -1.)*100. : (($bb*1.)/$aa -1.)*100.}}
       proc calculate {     } {
            global answer2
            global side1 side2 side3 side4 side5
            global side6 side7 side8 
            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 target_number $side1
            set trial_square_root $side2
            set formula_factor $side3
       set approximate_root [* [/ 1. $formula_factor ] [+ [* [/ 1. $trial_square_root ] $target_number] $trial_square_root ]   ]
            set side4 [+ [* [/ 1. $trial_square_root ] $target_number] $trial_square_root ]  
            set side5 [* $trial_square_root $trial_square_root]
            set side6 [sqrt $target_number ]  
            set side7 [ errorx $approximate_root [sqrt  $target_number ]   ]
            set side8 $approximate_root
                    }
        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 answer2
            global side1 side2 side3 side4 side5
            global side6 side7 side8
            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 :|target number N  |   |&"
            puts "&| $side2 :|trial square root | |& "  
            puts "&| $side3 :|function factor | |& "
            puts "&| $side4 :|answers: intermediate term in formula| |&"
            puts "&| $side5 :|trial square | |&"
            puts "&| $side6 :|square root from TCL sqrt function |  |&"
            puts "&| $side7 :|percentage error |  |&"
            puts "&| $side8 :|approximate square root from square side rule |  |&" 
            }
        frame .buttons -bg aquamarine4
        ::ttk::button .calculator -text "Solve" -command { set side8 0 ; calculate   }
        ::ttk::button .test2 -text "Testcase1" -command {clearx;fillup 2.  2.0  2.0 3.0  4.0   1.414    6.066  1.5}
        ::ttk::button .test3 -text "Testcase2" -command {clearx;fillup 10.0 3.0 2.0 6.333 9.0   3.162 0.138     3.166}
        ::ttk::button .test4 -text "Testcase3" -command {clearx;fillup 100.0 9.0 2.0  20.111  81.0    10.0  0.5555  10.0555}
        ::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 . "Babylonian Square Side Rule 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 for Newton's Method***
======
        # gold on TCL WIKI, 2oct2017
        # console program for square root
        # additional verbose Newton's Method
        package require Tk
        package require math::numtheory
        set tcl_precision 17
             console show
             namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory }
         proc square_root_function { number_for_root  } {   
             set counter 0
             set epsilon .0001
             while { $counter < 50.  } {
             if { [* $counter $counter 1. ]   > [* $number_for_root 1.] } {break}            
             incr counter 
             }   
             set  square_root_estimate $counter
             while {1} {
             set keeper $square_root_estimate        
             set starter $square_root_estimate
             set remainder   [* $starter $starter  1. ]  
             set remainder [- $number_for_root [* $starter $starter  1. ] ]
             set  square_root_estimate  [+ $starter [/ $remainder [* 2. $starter ]]]
             if {abs($keeper - $square_root_estimate) < $epsilon} break
                   }
             return $square_root_estimate
                }     
            puts " [ square_root_function 10. ] "
======
----

*** Version 2 Diagonal calculator with extended and modified Plimpton 322 dataset***
======
        # pretty print from autoindent and ased editor
        # Babylonian Square Side Rule & Diagonal calculator,  Version 2
        # Version 2 tests database invoke
        # from modified and extended Plimpton 322 dataset
        # dataset includes numbers not on original tablet
        # Using Suchenworth code from Another Database, TCL WIKI
        # written on Windows XP on eTCL
        # working under TCL version 8.5.6 and eTCL 1.0.1
        # gold on TCL WIKI, 2oct2017
        package require Tk
        package require 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 {{} {target number N :} }
        lappend names {trial square root:}
        lappend names {formula factor: }
        lappend names {answers: intermediate term in formula }
        lappend names {trial square :}
        lappend names {square root from TCL sqrt function : }
        lappend names {percentage error: }
        lappend names {approximate square root from square side rule :} 
        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 Square Side Rule
            from TCL WIKI,
            written on eTCL "
            tk_messageBox -title "About" -message $msg } 
       proc ::tcl::mathfunc::precision {precision float}  {
            #  tcl:wiki:Floating-point formatting, [AM]
            set x [ format "%#.5g" $float ]
            return $x
           }   
            #proc errorx always returns a positive error. 
            #Normally assume $aa is human estimate,
            #assume $bb is divinely exact.
       proc errorx  {aa bb} {expr { $aa > $bb ?   (($aa*1.)/$bb -1.)*100. : (($bb*1.)/$aa -1.)*100.}}
       proc calculate {     } {
            global answer2
            global side1 side2 side3 side4 side5
            global side6 side7 side8 
            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 target_number $side1
            set trial_square_root $side2
            set formula_factor $side3
       set approximate_root [* [/ 1. $formula_factor ] [+ [* [/ 1. $trial_square_root ] $target_number] $trial_square_root ]   ]
            set side4 [+ [* [/ 1. $trial_square_root ] $target_number] $trial_square_root ]  
            set side5 [* $trial_square_root $trial_square_root]
            set side6 [sqrt $target_number ]  
            set side7 [ errorx $approximate_root [sqrt  $target_number ]   ]
            set side8 $approximate_root
                    }
        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 answer2
            global side1 side2 side3 side4 side5
            global side6 side7 side8
            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 :|target number N  |   |&"
            puts "&| $side2 :|trial square root | |& "  
            puts "&| $side3 :|function factor | |& "
            puts "&| $side4 :|answers: intermediate term in formula| |&"
            puts "&| $side5 :|trial square | |&"
            puts "&| $side6 :|square root from TCL sqrt function |  |&"
            puts "&| $side7 :|percentage error |  |&"
            puts "&| $side8 :|approximate square root from square side rule |  |&" 
            }
        frame .buttons -bg aquamarine4
        ::ttk::button .calculator -text "Solve" -command { set side8 0 ; calculate   }
        ::ttk::button .test2 -text "Testcase1" -command {clearx;fillup 2.  2.0  2.0 3.0  4.0   1.414    6.066  1.5}
        ::ttk::button .test3 -text "Testcase2" -command {clearx;fillup 10.0 3.0 2.0 6.333 9.0   3.162 0.138     3.166}
        ::ttk::button .test4 -text "Testcase3" -command {clearx;fillup 100.0 9.0 2.0  20.111  81.0    10.0  0.5555  10.0555}
        ::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 . "Babylonian Square Side Rule Calculator"          
       # Start diagonal solver code
       proc select {fields "from" tbl "where" condition} {
       #Suchenworth subroutine code from Another Database, TCL WIKI
       set infields [lindex $tbl 0]
       if {$fields eq "*"} {set fields $infields}
       set res [list $fields]
       foreach inrow [lrange $tbl 1 end] {
          foreach $infields $inrow break
          if $condition {
            set row {}
            foreach field $fields {lappend row [set $field]}
            lappend res $row
        }
        }
       set res
       }
       set table {
      {number fraction_squares long_side short_side  diagonal_side suppose_angle line }
      { 1 .9834028 120 119 169 44.76 1 }
      { 2 .9491586 3456 3367 4825 44.25 2 }
      { 3 .9188021 4800 4601 6649 43.79 3 }
      { 4 .8862479 13500 12709 18541 43.27 4 }
      { 5 .8150077 72 65 97 42.08 5 }
      { 6 .7851929 360 319 481 41.54 6 }
      { 7 .7199837 2700 2291 3541 40.32 7 }
      { 8 .6927094 960 799 1249 39.77 8 }
      { 9 .6426694 600 481 769 38.72 9 }
      { 10 .5861226 6480 4961 8161 37.44 10 }
      { 11 .5625 60 45 75 36.87 11 }
      { 12 .4894168 2400 1679 2929 34.98 12 }
      { 13 .4500174 240 161 289 33.86 13 }
      { 14 .4302388 2700 1771 3229 33.26 14 }
      { 15 .3871605 90 56 106 31.89 15 }
      { 16 .1 1 175 337 1 16 }
      { 17 .1 1 473 985 1 17 }
      { 18 .1 1 1679 2929 1 18 }
      { 19 .1 1 161 289 1 19 }
      { 20 .1 1 1771 3229 1 20 }
      { 21 .1 1 56 106 1 21 }
      { 22 .1 1 4961 8161 1 22 }
      { 23 .1 1 1 75 1 23 }
      { 24 .1 1 1679 2929 1 24 }
      { 25 .1 1 161 289 1 25 }
      { 26 .1 1 1771 3049 1 26 }
      { 27 .1 1 301 949 1 27 }
      { 28 .1 1 329 1129 1 28 }
      { 29 .1 1 7 25 1 29 }
      { 30 .1 1 399 1649 1 30 }
      { 31 .1 1 9 41 1 31 }
      { 32 .1 1 11 61 1 32 }
      { 33 .1 1 295 1753 1 33 }
      { 34 .1 1 17 145 1 34 }
      { 35 .1 1 19 181 1 35 }
      { 36 .1 1 52 677 1 36 }
      { 37 .1 1 31 481 1 37 }
      { 38 .1 1 49 1201 1 38 }
      }
      puts [ select * from $table where {$line < 100} ]
      puts [ select {diagonal_side short_side } from $table where {$line != 15} ]
======
*** comma delimited spreadsheet of extended Plimpton 322 ***
======
number,fraction_squares,long_side,short_side,diagonal_side,suppose_angle,line
1,0.9834028,120,119,169,44.76,1
2,0.9491586,3456,3367,4825,44.25,2
3,0.9188021,4800,4601,6649,43.79,3
4,0.8862479,13500,12709,18541,43.27,4
5,0.8150077,72,65,97,42.08,5
6,0.7851929,360,319,481,41.54,6
7,0.7199837,2700,2291,3541,40.32,7
8,0.6927094,960,799,1249,39.77,8
9,0.6426694,600,481,769,38.72,9
10,0.5861226,6480,4961,8161,37.44,10
11,0.5625,60,45,75,36.87,11
12,0.4894168,2400,1679,2929,34.98,12
13,0.4500174,240,161,289,33.86,13
14,0.4302388,2700,1771,3229,33.26,14
15,0.3871605,90,56,106,31.89,15
16,0.369225019290123,288,175,337,1,16
17,0.299705557698903,864,473,985,1,17
18,0.489416840277778,2400,1679,2929,1,18
19,0.450017361111111,240,161,289,1,19
20,0.430238820301783,2700,1771,3229,1,20
21,0.387160493827161,90,56,106,1,21
22,0.586122566110349,6480,4961,8161,1,22
23,0.000177777777777778,75,1,75,1,23
24,0.489416840277778,2400,1679,2929,1,24
25,0.450017361111111,240,161,289,1,25
26,0.509135720783517,2482,1771,3049,1,26
27,0.111853086419753,900,301,949,1,27
28,0.0927992112482853,1080,329,1129,1,28
29,0.0850694444444444,24,7,25,1,29
30,0.062187890625,1600,399,1649,1,30
31,0.050625,40,9,41,1,31
32,0.0336111111111111,60,11,61,1,32
33,0.0291444964206104,1728,295,1753,1,33
34,0.0139371141975309,144,17,145,1,34
35,0.011141975308642,180,19,181,1,35
36,0.00593470507544582,675,52,677,1,36
37,0.00417100694444444,480,31,481,1,37
38,0.00166736111111111,1200,49,1201,1,38
======
----
*** comma delimited spreadsheet of TEST prime numbers & Plimpton 322 ***
======
number,fraction_squares,delta**2,long_side,is_prime,short_side,is_prime,diagonal_side,is_prime,side_ratio,acute_angle,complement_angle,line
1,0.9834028,1.9834028,120,FALSE,119,FALSE,169,FALSE,1.00840336134454,44.7602701039192,45.2397298960808,1
2,0.9491586,1.9491586,3456,FALSE,3367,FALSE,4825,FALSE,1.02643302643303,44.2526696187466,45.7473303812534,2
3,0.9188021,1.9188021,4800,FALSE,4601,FALSE,6649,FALSE,1.04325146707238,43.7873462834569,46.2126537165431,3
4,0.8862479,1.8862479,13500,FALSE,12709,FALSE,18541,TRUE,1.06223935793532,43.2713110478808,46.7286889521192,4
5,0.8150077,1.8150077,72,FALSE,65,FALSE,97,TRUE,1.10769230769231,42.0750220508436,47.9249779491564,5
6,0.7851929,1.7851929,360,FALSE,319,FALSE,481,FALSE,1.12852664576803,41.5445093640917,48.4554906359083,6
7,0.7199837,1.7199837,2700,FALSE,2291,FALSE,3541,TRUE,1.17852466171977,40.3152217890896,49.6847782109104,7
8,0.6927094,1.6927094,960,FALSE,799,FALSE,1249,TRUE,1.20150187734668,39.7703302277109,50.2296697722891,8
9,0.6426694,1.6426694,600,FALSE,481,FALSE,769,TRUE,1.24740124740125,38.7179883513894,51.2820116486106,9
10,0.5861226,1.5861226,6480,FALSE,4961,FALSE,8161,TRUE,1.30618826849426,37.4371779573597,52.5628220426403,10
11,0.5625,1.5625,60,FALSE,45,FALSE,75,FALSE,1.33333333333333,36.869897645844,53.130102354156,11
12,0.4894168,1.4894168,2400,FALSE,1679,FALSE,2929,FALSE,1.42942227516379,34.9759947522971,55.0240052477029,12
13,0.4500174,1.4500174,240,FALSE,161,FALSE,289,FALSE,1.49068322981366,33.8550261282941,56.1449738717059,13
14,0.4302388,1.4302388,2700,FALSE,1771,FALSE,3229,TRUE,1.52456239412761,33.2619074134428,56.7380925865572,14
15,0.3871605,1.3871605,90,FALSE,56,FALSE,106,FALSE,1.60714285714286,31.8907918018457,58.1092081981543,15
16,0.369225019290123,1.36922501929012,288,FALSE,175,FALSE,337,TRUE,1.64571428571429,31.2844929144175,58.7155070855825,16
17,0.299705557698903,1.2997055576989,864,FALSE,473,FALSE,985,FALSE,1.82663847780127,28.6986640858943,61.3013359141057,17
18,0.489416840277778,1.48941684027778,2400,FALSE,1679,FALSE,2929,FALSE,1.42942227516379,34.9759947522971,55.0240052477029,18
19,0.450017361111111,1.45001736111111,240,FALSE,161,FALSE,289,FALSE,1.49068322981366,33.8550261282941,56.1449738717059,19
20,0.430238820301783,1.43023882030178,2700,FALSE,1771,FALSE,3229,TRUE,1.52456239412761,33.2619074134428,56.7380925865572,20
21,0.387160493827161,1.38716049382716,90,FALSE,56,FALSE,106,FALSE,1.60714285714286,31.8907918018457,58.1092081981543,21
22,0.586122566110349,1.58612256611035,12,FALSE,5,TRUE,13,TRUE,2.4,22.619,67.381,22
23,0.000177777777777778,1.00017777777778,75,FALSE,871,FALSE,2329,FALSE,0.0861079219288175,21.9613,68.0387,23
24,0.489416840277778,1.48941684027778,2400,FALSE,1679,FALSE,2929,FALSE,1.42942227516379,34.9759947522971,55.0240052477029,24
25,0.450017361111111,1.45001736111111,240,FALSE,161,FALSE,289,FALSE,1.49068322981366,33.8550261282941,56.1449738717059,25
26,0.509135720783517,1.50913572078352,2482,FALSE,1771,FALSE,3049,TRUE,1.40146809712027,35.5100803990245,54.4899196009755,26
27,0.111853086419753,1.11185308641975,900,FALSE,301,FALSE,949,FALSE,2.99003322259136,18.4922254911265,71.5077745088735,27
28,0.0927992112482853,1.09279921124829,1080,FALSE,329,FALSE,1129,TRUE,3.28267477203647,16.9422892660297,73.0577107339703,28
29,0.0850694444444444,1.08506944444444,24,FALSE,7,TRUE,25,FALSE,3.42857142857143,16.260204708312,73.739795291688,29
30,0.062187890625,1.062187890625,1600,FALSE,399,FALSE,1649,FALSE,4.01002506265664,14.0025351149907,75.9974648850093,30
31,0.050625,1.050625,40,FALSE,9,FALSE,41,TRUE,4.44444444444444,12.6803834918198,77.3196165081802,31
32,0.0336111111111111,1.03361111111111,60,FALSE,11,TRUE,61,TRUE,5.45454545454545,10.3888578154696,79.6111421845304,32
33,0.0291444964206104,1.02914449642061,1728,FALSE,295,FALSE,1753,TRUE,5.85762711864407,9.68800075016136,80.3119992498386,33
34,0.0139371141975309,1.01393711419753,144,FALSE,17,TRUE,145,FALSE,8.47058823529412,6.7329213268596,83.2670786731404,34
35,0.011141975308642,1.01114197530864,180,FALSE,19,TRUE,181,TRUE,9.47368421052632,6.02557500836668,83.9744249916333,35
36,0.00593470507544582,1.00593470507545,675,FALSE,52,FALSE,677,TRUE,12.9807692307692,4.40519632353161,85.5948036764684,36
37,0.00417100694444444,1.00417100694444,480,FALSE,31,TRUE,481,FALSE,15.4838709677419,3.69522053198919,86.3047794680108,37
38,0.00166736111111111,1.00166736111111,1200,FALSE,49,FALSE,1201,TRUE,24.4897959183673,2.33827865581484,87.6617213441852,38
,,delta**2-1,,equals,,(l/d)**2,or,(b/d)**2,,,,

======

----
[gold] This page is copyrighted under the TCL/TK license terms, [http://tcl.tk/software/tcltk/license.html%|%this license]. 

**Comments Section**

<<discussion>>
Please place any comments here, Thanks.

                              
<<categories>> Numerical Analysis | Toys | Calculator | Mathematics| Example| Toys and Games | Games | Application | GUI

<<categories>> Development | Concept| Algorithm | Procedure}} CALL {my revision {Babylonian Square Side Rule & Diagonal Procedure Algorithm and eTCL demo example calculator, numerical analysis}} CALL {::oo::Obj5958757 process revision/Babylonian+Square+Side+Rule+%26+Diagonal+Procedure+Algorithm+and+eTCL+demo+example+calculator%2C+numerical+analysis} CALL {::oo::Obj5958755 process}

-errorcode

NONE

-errorinfo

Unknow state transition: LINE -> END
    while executing
"error $msg"
    (class "::Wiki" method "render_wikit" line 6)
    invoked from within
"my render_$default_markup $N $C $mkup_rendering_engine"
    (class "::Wiki" method "render" line 8)
    invoked from within
"my render $name $C"
    (class "::Wiki" method "revision" line 31)
    invoked from within
"my revision $page"
    (class "::Wiki" method "process" line 56)
    invoked from within
"$server process [string trim $uri /]"

-errorline

4