Updated 2017-02-07 21:59:27 by gold

Sumerian Base 60 conversion and eTCL demo example calculator, numerical analysis  edit

This page is under development. Comments are welcome, but please load any comments in the comments section at the bottom of the page. Please include your wiki MONIKER in your comment with the same courtesy that I will give you. Its very hard to reply intelligibly without some background of the correspondent. Thanks,gold

gold Here is some eTCL starter code for Sumerian Base 60 conversion. Loaded RS routines from Based numbers into a slot calculator shell.

The textbook convention for 12**5 or decimal 248832 is 01 09 07 12 , as base 60 in two digit bins. The eTCL calculator gives 19712 for the first logic switch. If one switches 3 for the fixed digits and the fixed digits to 00 01 02 03 04 05 06 07 08 09 , the calculator gives 01090712 for a 2 character bin. Other conventions separate the two digit bins with periods or semicolons. Probably, TCL could invoke cuneiform characters as numbers, if those characters were loaded as fixed digits.

Loaded proc sreverse from FW, Additional string functions. Procedure number_prep should add expected periods in 2-character bins, modified from RS.

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 1printed in tcl wiki format
quantity value comment, if any
1:testcase_number
101.0 :number n
60.0 :optional base 60?
1.0 :optional logic switch (1,2,3?)
1.0 :optional
1.0 :optional
1.0 :optional
141 :base 60
3601 :base 60
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 :list other base symbols

Testcase 2

table 2printed in tcl wiki format
quantity value comment, if any
2:testcase_number
30.0 :number n
60.0 :optional base 60?
1.0 :optional logic switch (1,2,3?)
1.0 :optional
1.0 :optional
1.0 :optional
30 :base 60
180 :base 60
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 :list other base symbols

Testcase 3

table 3printed in tcl wiki format
quantity value comment, if any
3:testcase_number
90.0 :number n
60.0 :optional base 60?
1.0 :optional logic switch (1,2,3?)
1.0 :optional
1.0 :optional
1.0 :optional
130 :base 60
540 :base 60
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 :list other base symbols

Testcase 3

table 4printed in tcl wiki format
quantity value comment, if any
4:testcase_number
248832.0 :number n
60.0 :optional base 60?
5.0 :optional logic switch (1,2,3?) active, different fixed digits
1.0 :optional
1.0 :optional
1.0 :optional
01090712 :base 60
790779661 :base 60
00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 :list other base symbols


Screenshots Section

figure 1.


References:


Appendix Code edit

appendix TCL programs and scripts

        # pretty print from autoindent and ased editor
        # Base 60 Conversion
        # written on Windows XP on eTCL
        # working under TCL version 8.5.6 and eTCL 1.0.1
        # gold on TCL WIKI, 15jan2017
        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 {{} {number $n :} }
        lappend names {optional base 60?:}
        lappend names {optional logic switch (1,2,3?): }
        lappend names {answers : mantissa: }
        lappend names {read left to right:}
        lappend names {read left to right: }
        lappend names {to base, read r/l : }
        lappend names {from base, read r/l :} 
        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 Base 60 Conversion
            from TCL WIKI,
            written on eTCL "
            tk_messageBox -title "About" -message $msg } 
        proc sreverse str {
            set res ""
            for {set i [string length $str]} {$i > 0} {} {
            append res [string index $str [incr i -1]]
            } 
             set res
            }
         proc number_prep {n} {
             set res {}
             foreach { a b } [split $n {} ] {lappend res "$a$b." }
             set res [ join $res ]
             set res [string map {" " ""} $res]
             return $res
             }
        proc list_base_numbers { aa bb} { for {set i 0} {$i<=$bb} {incr i} {lappend list_n [ int  $i] };return $list_n}
        proc base {base number} {
            global side1 side2 side3 side4 side5
            global side6 side7 side8 digits5
            set negative [regexp ^-(.+) $number -> number] ;# (1)
            set digits $digits5
            set res {}
            while {$number} {
            set digit [expr {$number % $base}]
            set res [lindex $digits $digit]$res
            set number [expr {$number / $base}]
            }
            if $negative {set res -$res}
            set res
            }
       proc frombase {base number} {
            global side1 side2 side3 side4 side5
            global side6 side7 side8 digits5
            set digits $digits5
            set negative [regexp ^-(.+) $number -> number]
            set res 0
            foreach digit [split $number ""] {
            set decimalvalue [lsearch $digits $digit]
            set res [expr {$res*$base + $decimalvalue}]
            }
            if $negative {set res -$res}
            set res
            }  
       proc calculate {     } {
            global answer2
            global side1 side2 side3 side4 side5
            global side6 side7 side8 
            global testcase_number
            global digits5 base60notation notation_60bins
            global base60_mantissa
            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 digits { [ list_numbers 0 $base ] }
            set digits_fixed_symbols {00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39         40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60}
            set digits_alfa_numbers {0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z}
            set base60_mantissa [- $side1 [int $side1 ] ]
            set base [int $side2 ]
            set digits5  [ list_base_numbers 0 $base ] 
            if {$side3 > 1.  }  { set digits5 $digits_alfa_numbers }
            if {$side3 > 2.  }  { set digits5 $digits_fixed_symbols }
            set base60notation [number_prep [abs [ frombase $base [  int $side1 ] ] ] ]
            set notation_60bins [number_prep [ base $base [int $side1 ] ] ]
            set side4 $base60_mantissa
            set side5 [sreverse [ base $base [int $side1 ] ]]
            set side6 [sreverse [abs [ frombase $base [  int $side1 ] ] ]]
            set side7 [ base $base [int $side1 ] ]
            set side8 [abs [ frombase $base [  int $side1 ] ] ]
                    }
        proc fillup {aa bb cc dd ee ff gg hh} {
            .frame.entry1 insert 0 "$aa"
            .frame.entry2 insert 0 "$bb"
            .frame.entry3 insert 0 "$cc"
            .frame.entry4 insert 0 "$dd"
            .frame.entry5 insert 0 "$ee"
            .frame.entry6 insert 0 "$ff" 
            .frame.entry7 insert 0 "$gg"
            .frame.entry8 insert 0 "$hh" 
             }
        proc clearx {} {
            foreach i {1 2 3 4 5 6 7 8 } {
                .frame.entry$i delete 0 end } }
        proc reportx {} {
            global side1 side2 side3 side4 side5
            global side6 side7 side8
            global testcase_number digits5 
            global digits5 base60notation notation_60bins
            global base60_mantissa
            console show;
            puts "%|table $testcase_number|printed in| tcl wiki format|% "
            puts "&| quantity| value| comment, if any|& "
            puts "&| $testcase_number:|testcase_number | |&"
            puts "&| $side1 :|number  n|   |&"
            puts "&| $side2 :|optional base 60? | |& "  
            puts "&| $side3 :|optional logic switch (1,2,3?) | |& "
            puts "&| $base60_mantissa :|base60_mantissa | |&"
            puts "&| $side5 :|read left to right | |&"
            puts "&| $side6 :|read left to right | |&"
            puts "&| $notation_60bins :|number_prep notation_bins | |&"
            puts "&| $base60notation :|number_prep base60notation|  |&"
            puts "&| $side7 :|base 60 |  |&"
            puts "&| $side8 :|base 60 |  |&" 
            puts "&| $digits5 :|list other base symbols |  |&" 
            }
        frame .buttons -bg aquamarine4
        ::ttk::button .calculator -text "Solve" -command { calculate   }
        ::ttk::button .test2 -text "Testcase1" -command {clearx;fillup 101.0 60.  1.0 1.0  1.0  1. 141. 3601.}
        ::ttk::button .test3 -text "Testcase2" -command {clearx;fillup 30.0 60.0 1.0 1.0  1.0  1. 30. 180. }
        ::ttk::button .test4 -text "Testcase3" -command {clearx;fillup 248832.111110 60.  3.0 1.0  1.0  1. 130. 540. }
        ::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 . "Base 60 Conversion 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   |&"  

gold This page is copyrighted under the TCL/TK license terms, this license.

Comments Section edit

Please place any comments here, Thanks.