**Babylonian Combined Market Rate, Math Problems** This page is under development. Comments are welcome, but please load any constructive comments in the comments section at the bottom of the page. Please include your wiki MONIKER and date in your constructive 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] 12Jul2020 ---- <> **Introduction** [gold] I am shuffling some materials and reusing this older page. ====== # pretty print from autoindent and ased editor # Babylonian Combined Market Rate calculator V3 # written on Windows 10 on TCL # working under TCL version 8.6 # gold on TCL Club, 15jul2020 # combined_market_rate proc adapted from TCLLIB 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 {{} {aa quantity per silver piece MR1:} } lappend names {bb quantity per silver piece MR2:} lappend names {cc quantity per silver piece MR3: } lappend names {dd quantity per silver piece MR4: } lappend names {optional usually 1. :} lappend names {answers: sum_of_fractions : } lappend names {average market rate: } lappend names {combined market rate:} 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 } # adapted from tcl Stats 2011-05-22, arithmetic mean [RLE] # plus other contributors from TCLLIB math library, [AM] Arjen Markus # ::math::combined_market_rate -- # # Return the combined_market_rate by one,two, or more given rates # market rate defined as quantity per price # or 1 over (price per quantity) # # Arguments: # # args values are one, two, or more given rates # # Results: combined_market_rate # works for positive numbers, negative numbers, # and mixed positive & negative numbers. # arg of zero returns zero # arg of null returns zero # filter foreach drops irregular zero elements from argument proc ::math::combined_market_rate { args} { set sum 0. set N [ expr { [ llength $args ] } ] if { $N == 0 } { return 0 } if { $N == 1 || [ lindex $args 0 ] == 0 } { return 0 } set res {};set counter2 0; # filter foreach drops irregular zero elements foreach item $args {if {$item != 0 } {incr counter2 1; lappend res $item } } set counter 0 foreach val $res { set sum [ expr { $sum + 1./$val } ] incr counter 1 } #set combined_market_rate1 [ expr { 1./(($sum*1.)/$counter2) } ] set combined_market_rate1 [ expr { 1./(($sum*1.)/$counter2) } ] return $combined_market_rate1 } # various testcases on combined_market_rate # puts [::math::combined_market_rate 0.5524 0.4807 0.42918 0.47846 ] # answer 0.48131 " # puts [ ::math::combined_market_rate .1 .2 .3 .4 ] # answer 0.192 # ::math::combined_market_rate -.1 -.2 -.3 -.4 # answer -0.192, correct # operator math formula follows # check [/ 1. [/ [+ [/ 1. -.1] [/ 1. -.2] [/ 1. -0.3 ] [/ 1. -0.4] ] 4. ] ] # returns -0.192, correct # puts " [ ::math::combined_market_rate .1 ] " # :math::combined_market_rate -.1 -.2 .3 .4 # answer -0.4363636363636364 # operator math formula follows # set check [/ 1. [/ [+ [/ 1. -.1] [/ 1. -.2] [/ 1. 0.3 ] [/ 1. 0.4] ] 4. ] ] # check equals -0.4363636363636364 # puts " for (::math::combined_market_rates .1) # returns .1 " # ::math::combined_market_rate {} # null returns zero, correct. # ::math::combined_market_rate 0 # arg 0 returns zero, correct. # addition dated 24sep2018 # added filter foreach to remove zeros # and irregular zeros in inputs, # test on zero's 0.1 0.0 0.0 0.2 0.3 0.4 # returns 0.192 , correct # test on zero's 0.1 0.0 0.0 0.2 0.3 0.4 # returns 0.192 , correct proc about {} { set msg "Calculator for Babylonian Combined Market Rate V3 from TCL Club, written on TCL " tk_messageBox -title "About" -message $msg } proc self_help {} { set msg "Calculator for Babylonian Combined Market Rate V3 from TCL , # self help listing # 4 givens follow. 1) aa quantity per silver piece MR1 2) bb quantity per silver piece MR2 3) cc quantity per silver piece MR3 4) dd quantity per silver piece MR4 The answer is combined market rate: The solution from the clay tablets is genuine antique method from 1600 BCE and different looking from modern math methods. # The Babylonians did not use modern algebraic notation, # so the reader will have to bear some anachronisms in the TCL code. # The Bablylonian math problems used base_60, but # the TCL procedures use base_10 in calculator. # The moderns normally use price per quantity, rather # than the Babylonian market rate, defined as quantity per price. # For comparison, TCL code may include redundant paths & formulas. # The TCL calculator normally uses modern # units for convenience to modern users and textbooks. # Any convenient and consistent in/output units might be used # like inches, feet, nindas, cubits, or dollars to donuts. # 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 to conventional texteditor. For testcases # testcase number is internal to the calculator and # will not be printed until the report button is pushed # for the current result numbers. # This posting, screenshots, and TCL source code is # copyrighted under the TCL/TK 8.6 license terms. # Editorial rights retained under the TCL/TK license terms # and will be defended as necessary in court. Conventional text editor formulas or grabbed from internet screens can be pasted into green console. Try copy and paste following into green screen console set answer \[* 1. 2. 3. 4. 5. \] returns 120 Try invoking subroutine inside package set answer2 \[ ::math::combined_market_rate 1. 2. 3. 4. 5. \] returns 2.189 # gold on TCL Club, 10jul2020 " tk_messageBox -title "self_help" -message $msg } 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 sum_of_fractions [+ [/ 1. $side1 ] [/ 1. $side2 ] [/ 1. $side3 ] [/ 1. $side4 ] ] set average_market_ratex [/ [+ $side1 $side2 $side3 $side4 ] 4. ] set combined_market_rate [ ::math::combined_market_rate $side1 $side2 $side3 $side4 ] set side6 $sum_of_fractions set side7 $average_market_ratex set side8 $combined_market_rate } 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 console show; console eval {.console config -bg palegreen} console eval {.console config -font {fixed 20 bold}} console eval {wm geometry . 40x20} console eval {wm title . " Babylonian Market Rate Report , screen grab and paste from console 2 to texteditor"} console eval {. configure -background orange -highlightcolor brown -relief raised -border 30} puts "%|table $testcase_number|printed in| tcl Club format|% " puts "&| quantity| value| comment, if any|& " puts "&| $testcase_number:|testcase_number | |&" puts "&| $side1 :|aa quantity per silver piece MR1: | |&" puts "&| $side2 :|bb quantity per silver piece MR2: | |& " puts "&| $side3 :|cc quantity per silver piece MR3: | |& " puts "&| $side4 :|dd quantity per silver piece MR4: | |&" puts "&| $side5 :|optional: | |&" puts "&| $side6 :|sum_of_fractions | |&" puts "&| $side7 :|average market rate: | |&" puts "&| $side8 :|combined_market_rate | |&" } frame .buttons -bg aquamarine4 ::ttk::button .calculator -text "Solve" -command { calculate } ::ttk::button .test2 -text "Testcase1" -command {clearx;fillup 1. 2. 3.0 4. 1.0 2.083 2.5 1.92} ::ttk::button .test3 -text "Testcase2" -command {clearx;fillup 3.0 5.0 7.0 9.0 1.0 .787 6. 5.08 } ::ttk::button .test4 -text "Testcase3" -command {clearx;fillup 3.0 4. 5.0 7.0 1.0 0.986 4.75 4.318 } ::ttk::button .clearallx -text clear -command {clearx } ::ttk::button .about -text about -command {about} ::ttk::button .self_help -text self_help -command {self_help } ::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 .self_help .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 Combined Market Rate Calculator V3" ====== <> Numerical Analysis | Toys | Calculator | Mathematics| Example| Toys and Games | Games | Application | GUI ---- <> Development | Concept| Algorithm | Human Language