Mesopotamian Calculator
Project description
Overview
This package is intended for:
-
the arithmetic of natural sexagesimal numbers, mainly in their “floating” aspect (i.e., by removing all possible trailing sexagesimal zeros from the right), as performed by the Babylonian scribes and their apprentices in ancient times.
-
the arithmetic of physical quantities, length, surface, etc. described using the metrology of the Old Babylonian Period.
Inspired by the arithmetic and metrological parts of Baptiste Mélès' MesoCalc, it aims to bring this type of calculation to Python3 programming and to the Python3 command line as an interactive calculator.
mesomath module contains four submodules:
babn.pyhamming.pymesolib.pynpvs
one utility script:
createDB.py
one example script:
example-melville.py
four test/demo scripts:
test-babn.pytest-hamming.pytest-mesolib.pytest-npvs.py
and two applications in the progs subdirectory:
metrotable.pyto print segments of metrological tables.mtlookup.pyto search for the abstract number that corresponds to a measure or to list measures that correspond to a given abstract number.
Documentation
Documentation for this package is in Read the Docs,
Includes:
- A tutorial on using this package as a command-line calculator.
- Tutorials for the two included applications:
Dependencies
mesomath only uses standard Python modules: math, itertools, argparse, sys, re and sqlite3.
Tested with Python 3.11.2 under Debian GNU/Linux 12 (bookworm) in x86_64 and aarch64 (raspberrypi 5).
babn.py
This is the main module defining the BabN class for representing sexagesimal natural numbers. You can perform mathematical operations on objects of the BabN class using the operators +, -, *, **, /, and //, and combine them using parentheses, both in a program and interactively on the Python command line. It also allows you to obtain their reciprocals in the case of regular numbers, their approximate inverses in the general case, approximate square and cube floating roots and obtain divisors and lists of "nearest" regular numbers. See the test-babn.py script.
Note:
- Operator
/return the approximate floating division ofa/bfor any pair of numbers. - Operator
//is for the "Babylonian Division" ofabyb, i.e.a//breturnsatimes the reciprocal ofb, which requiresbto be regular.
Use as an interactive calculator
Consult the tutorial!
The easiest way is to invoque the interactive python interpreter and import the class BabN; for instance
$ python3 -i
Python 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from mesomath.babn import BabN as bn
>>> a = bn(405)
>>> a
6:45
>>> (etc.)
or, with ipython:
$ ipython3
Python 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.5.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from mesomath.babn import BabN as bn
In [2]: a = bn(405)
In [3]: a
Out[3]: 6:45
In [4]: a.explain()
| Sexagesimal number: [6, 45] is the decimal number: 405.
| It may be written as 2^0 * 3^4 * 5^1 * 1),
| so, it is a regular number with reciprocal: 8:53:20
In [5]: (etc.)
But you can also create an executable script for your operating system that invokes the interpreter; for example, on Linux, create a file named babcal containing (customize PYTHONPATH below to your needs) :
#!/usr/bin/env -S PYTHONPATH={path to directory containing mesomath module} python3 -i -c 'from mesomath.babn import BabN as bn; print("\nWelcome to Babylonian Calculator\n ...the calculator that every scribe should have!\nUse: bn(number)\n")'
then, after making it executable and instaling it somewhere on the PATH:
$ babcalc
Welcome to Babylonian Calculator
...the calculator that every scribe should have!
Use: bn(number)
>>> a = bn(405)
>>> a
6:45
>>> (etc.)
hamming.py
Regular or Hamming numbers are numbers of the form:
H = 2^i * 3^j × 5^k
where i, j, k ≥ 0
This module is used to obtain lists of such numbers and ultimately build a SQLite3 database of them up to 20 sexagesimal digits. This database is used by BabN to search for regular numbers close to a given one. See the scripts: createDB.py and test-hamming.py.
mesolib.py
This is a rather obsolete module, as its functionality has been moved to the methods of the BabN class. It can be safely ignored and will likely be removed in the future. In any case, please refer to the test-mesolib.py script.
npvs.py
This module defines the generic class Npvs for handling measurements in various units within a system. It is built using length measurements in the imperial system of units, from inches to leagues, as an example. This class is inherited by the _MesoM class which adapts it to Mesopotamian metrological use. The _MesoM class, in turn, is inherited by:
- class
BsyG: Babylonian counting System G (iku ese bur bur_u sar sar_u sar_gal) - class
BsyS: Babylonian counting System S (dis u ges gesu sar sar_u sar_gal) - class
MesoM: To represent physical quantities, inherited by:- class
Blen: Babylonian length system (susi kus ninda us danna) - class
Bsur: Babylonian surface system (se gin sar gan) - class
Bvol: Babylonian volume system (se gin sar gan) - class
Bcap: Babylonian capacity system (se gin sila ban bariga gur) - class
Bwei: Babylonian weight system (se gin mana gu) - class
Bbri: Babylonian brick counting system (se gin sar gan)
- class
Please, read the tutorial to see how to use all these classes.
createDB.py
This script has become more or less obsolete since its functionality was incorporated into the BabN class, which now creates the regular number database if it cannot find it when needed.
Use:
$ python3 createDB.py
to create the default regular number database regular.db3 in your directory. You can also use:
$ python3 createDB.py -o 'path/name'
to create it in a non-standar location. In this case, think of using:
BabN.database = 'path/name'
to inform BabN of its location.
example-melville.py
This script shows the application of mesomath to the solution of two real examples given by Duncan J. Melville in: Reciprocals and Reciprocal algorithms in Mesopotamian Mathematics (2005)
$ python3 example-melville.py
Output:
Searching the reciprocal of 2:5 according to D. J. Melville (2005)
Example 1: from Table 2. Simple Reciprocal algorithm
d1 = BabN('2:5')
r1 = d1.tail()
r2 = r1.rec()
r3 = d1 * r2
r4 = r3.rec()
r5 = r4 * r2
Result r5 = 28:48
Example 2: from Table 3. using "The Technique"
r1 = d1.tail()
r2 = r1.rec()
r3 = d1.head() * r2
r4 = r3+BabN(1)
r5 = r4.rec()
r6 = r5 * r2
Result r6 = 28:48
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mesomath-1.1.0.tar.gz.
File metadata
- Download URL: mesomath-1.1.0.tar.gz
- Upload date:
- Size: 26.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4902b7fed7678719b02e787cefa5400138451fcb63afc910aab222d078325fe2
|
|
| MD5 |
4a326f1571c82c1153dfb254cb630f3f
|
|
| BLAKE2b-256 |
962ac8329942da56c8399f3ce1ed6f4b325843997c68eb5619065822f171f911
|
File details
Details for the file mesomath-1.1.0-py3-none-any.whl.
File metadata
- Download URL: mesomath-1.1.0-py3-none-any.whl
- Upload date:
- Size: 32.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de7fbee429dd93b11cce4a94a6faeefe9f315a654bcde13a598bb560a730a732
|
|
| MD5 |
20e6d86e578413a4d8357f62359b52df
|
|
| BLAKE2b-256 |
5618e5e6aeba6ce33dadd202f3b2868e7f627b3b7fa15fd7ecaccdc772c80958
|