## Babylonian Combined Market Rate, Math Problems

gold 7/26/2020. I am shuffling some materials and reusing this older page.

### Preface

gold Here are some TCL calculations for math problems on Combined Market Rate. In modern algebraic notation, the conventional formula for combined market rate (CMR) equals N / (1/mr1 +1/mr2 +1/mr3...... +1/mr( N )), where mr are successive market rates from the first market rate mr1 to the Nth market rate. The units are not critical in the calculator internal math and any consistent input units and output units might be used like dollars to donuts.

### Introduction

A number of Babylonian math problems have been found on market rates and combined market rates, ref Friberg and Proust. The cuneiform word for “market rate” was mahirum, expressed in quantity per price, or usually quantity of oil , lard, or other product per shekel of silver. The market rate is the reciprocal of the market price as eval </ 1. market_price>. Here, the combined market rate of the combination of two or more market rates, effectively the reciprocal of the average price. Some of the problems seem directed towards calculating a combined market rate for a market basket of goods or stock on hand. Some of the problems are directed toward calculating profits in commodities like oil and lard from combined market rates. The Babylonian mathematicians are calculating the market prices, market rates, and unknowns in commodity markets that fluctuate in price over time. Including references to modern examples, buying different commodities and stocks at different prices over time may lead to combined market rate problems. Also, some combined market rate problems with unknowns may require solving either 1) a quadratic equation or 2) two or more simultaneous linear equations. A related math method or comparable problem type is the combined work norms, as seen in some old Babylonian math problems. Several linguists have developed alternate theories or methods on the Babylonian solutions for combined market rate. The TCL calculator appears to be working as it stands. Would like to firm up market rate concepts with some better testcases.

## Appendix Code

### appendix TCL programs and scripts

```        # 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 ]
# ::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
# 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 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 .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"```

#### Testcase 1

table 1printed in tcl format
quantity value comment, if any
1:testcase_number
1.0 :aa quantity per silver piece MR1:
2.0 :bb quantity per silver piece MR2:
3.0 :cc quantity per silver piece MR3:
4.0 :dd quantity per silver piece MR4:
1.0 :optional:
2.083 :sum_of_fractions
2.5 :average market rate:
1.920 :combined_market_rate

#### Testcase 2

table 2printed in tcl format
quantity value comment, if any
2:testcase_number
3.0 :aa quantity per silver piece MR1:
5.0 :bb quantity per silver piece MR2:
7.0 :cc quantity per silver piece MR3:
9.0 :dd quantity per silver piece MR4:
1.0 :optional:
0.787 :sum_of_fractions
6.0 :average market rate:
5.080 :combined_market_rate

#### Testcase 3

table 3printed in tcl Club format
quantity value comment, if any
3:testcase_number
3.0 :aa quantity per silver piece MR1:
4.0 :bb quantity per silver piece MR2:
5.0 :cc quantity per silver piece MR3:
7.0 :dd quantity per silver piece MR4:
1.0 :optional:
0.926 :sum_of_fractions
4.75 :average market rate:
4.318 :combined_market_rate