mesomath 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mesomath-1.1.0/LICENSE +121 -0
- mesomath-1.1.0/PKG-INFO +227 -0
- mesomath-1.1.0/README.md +1 -0
- mesomath-1.1.0/READMEmesomath.md +199 -0
- mesomath-1.1.0/mesomath/__about__.py +10 -0
- mesomath-1.1.0/mesomath/__init__.py +8 -0
- mesomath-1.1.0/mesomath/babcalc.py +20 -0
- mesomath-1.1.0/mesomath/babcalc2.py +38 -0
- mesomath-1.1.0/mesomath/babn.py +684 -0
- mesomath-1.1.0/mesomath/hamming.py +141 -0
- mesomath-1.1.0/mesomath/mesolib.py +384 -0
- mesomath-1.1.0/mesomath/metrotable.py +340 -0
- mesomath-1.1.0/mesomath/mtlookup.py +178 -0
- mesomath-1.1.0/mesomath/npvs.py +809 -0
- mesomath-1.1.0/mesomath/test/__init__.py +1 -0
- mesomath-1.1.0/mesomath/test/createDB.py +72 -0
- mesomath-1.1.0/mesomath/test/example-melville.py +54 -0
- mesomath-1.1.0/mesomath/test/test-babn.py +105 -0
- mesomath-1.1.0/mesomath/test/test-hamming.py +7 -0
- mesomath-1.1.0/mesomath/test/test-mesolib.py +19 -0
- mesomath-1.1.0/mesomath/test/test-npvs.py +31 -0
- mesomath-1.1.0/pyproject.toml +88 -0
mesomath-1.1.0/LICENSE
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Creative Commons Legal Code
|
|
2
|
+
|
|
3
|
+
CC0 1.0 Universal
|
|
4
|
+
|
|
5
|
+
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
|
6
|
+
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
|
7
|
+
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
|
8
|
+
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
|
9
|
+
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
|
10
|
+
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
|
11
|
+
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
|
12
|
+
HEREUNDER.
|
|
13
|
+
|
|
14
|
+
Statement of Purpose
|
|
15
|
+
|
|
16
|
+
The laws of most jurisdictions throughout the world automatically confer
|
|
17
|
+
exclusive Copyright and Related Rights (defined below) upon the creator
|
|
18
|
+
and subsequent owner(s) (each and all, an "owner") of an original work of
|
|
19
|
+
authorship and/or a database (each, a "Work").
|
|
20
|
+
|
|
21
|
+
Certain owners wish to permanently relinquish those rights to a Work for
|
|
22
|
+
the purpose of contributing to a commons of creative, cultural and
|
|
23
|
+
scientific works ("Commons") that the public can reliably and without fear
|
|
24
|
+
of later claims of infringement build upon, modify, incorporate in other
|
|
25
|
+
works, reuse and redistribute as freely as possible in any form whatsoever
|
|
26
|
+
and for any purposes, including without limitation commercial purposes.
|
|
27
|
+
These owners may contribute to the Commons to promote the ideal of a free
|
|
28
|
+
culture and the further production of creative, cultural and scientific
|
|
29
|
+
works, or to gain reputation or greater distribution for their Work in
|
|
30
|
+
part through the use and efforts of others.
|
|
31
|
+
|
|
32
|
+
For these and/or other purposes and motivations, and without any
|
|
33
|
+
expectation of additional consideration or compensation, the person
|
|
34
|
+
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
|
35
|
+
is an owner of Copyright and Related Rights in the Work, voluntarily
|
|
36
|
+
elects to apply CC0 to the Work and publicly distribute the Work under its
|
|
37
|
+
terms, with knowledge of his or her Copyright and Related Rights in the
|
|
38
|
+
Work and the meaning and intended legal effect of CC0 on those rights.
|
|
39
|
+
|
|
40
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
|
41
|
+
protected by copyright and related or neighboring rights ("Copyright and
|
|
42
|
+
Related Rights"). Copyright and Related Rights include, but are not
|
|
43
|
+
limited to, the following:
|
|
44
|
+
|
|
45
|
+
i. the right to reproduce, adapt, distribute, perform, display,
|
|
46
|
+
communicate, and translate a Work;
|
|
47
|
+
ii. moral rights retained by the original author(s) and/or performer(s);
|
|
48
|
+
iii. publicity and privacy rights pertaining to a person's image or
|
|
49
|
+
likeness depicted in a Work;
|
|
50
|
+
iv. rights protecting against unfair competition in regards to a Work,
|
|
51
|
+
subject to the limitations in paragraph 4(a), below;
|
|
52
|
+
v. rights protecting the extraction, dissemination, use and reuse of data
|
|
53
|
+
in a Work;
|
|
54
|
+
vi. database rights (such as those arising under Directive 96/9/EC of the
|
|
55
|
+
European Parliament and of the Council of 11 March 1996 on the legal
|
|
56
|
+
protection of databases, and under any national implementation
|
|
57
|
+
thereof, including any amended or successor version of such
|
|
58
|
+
directive); and
|
|
59
|
+
vii. other similar, equivalent or corresponding rights throughout the
|
|
60
|
+
world based on applicable law or treaty, and any national
|
|
61
|
+
implementations thereof.
|
|
62
|
+
|
|
63
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention
|
|
64
|
+
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
|
65
|
+
irrevocably and unconditionally waives, abandons, and surrenders all of
|
|
66
|
+
Affirmer's Copyright and Related Rights and associated claims and causes
|
|
67
|
+
of action, whether now known or unknown (including existing as well as
|
|
68
|
+
future claims and causes of action), in the Work (i) in all territories
|
|
69
|
+
worldwide, (ii) for the maximum duration provided by applicable law or
|
|
70
|
+
treaty (including future time extensions), (iii) in any current or future
|
|
71
|
+
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
|
72
|
+
including without limitation commercial, advertising or promotional
|
|
73
|
+
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
|
74
|
+
member of the public at large and to the detriment of Affirmer's heirs and
|
|
75
|
+
successors, fully intending that such Waiver shall not be subject to
|
|
76
|
+
revocation, rescission, cancellation, termination, or any other legal or
|
|
77
|
+
equitable action to disrupt the quiet enjoyment of the Work by the public
|
|
78
|
+
as contemplated by Affirmer's express Statement of Purpose.
|
|
79
|
+
|
|
80
|
+
3. Public License Fallback. Should any part of the Waiver for any reason
|
|
81
|
+
be judged legally invalid or ineffective under applicable law, then the
|
|
82
|
+
Waiver shall be preserved to the maximum extent permitted taking into
|
|
83
|
+
account Affirmer's express Statement of Purpose. In addition, to the
|
|
84
|
+
extent the Waiver is so judged Affirmer hereby grants to each affected
|
|
85
|
+
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
|
86
|
+
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
|
87
|
+
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
|
88
|
+
maximum duration provided by applicable law or treaty (including future
|
|
89
|
+
time extensions), (iii) in any current or future medium and for any number
|
|
90
|
+
of copies, and (iv) for any purpose whatsoever, including without
|
|
91
|
+
limitation commercial, advertising or promotional purposes (the
|
|
92
|
+
"License"). The License shall be deemed effective as of the date CC0 was
|
|
93
|
+
applied by Affirmer to the Work. Should any part of the License for any
|
|
94
|
+
reason be judged legally invalid or ineffective under applicable law, such
|
|
95
|
+
partial invalidity or ineffectiveness shall not invalidate the remainder
|
|
96
|
+
of the License, and in such case Affirmer hereby affirms that he or she
|
|
97
|
+
will not (i) exercise any of his or her remaining Copyright and Related
|
|
98
|
+
Rights in the Work or (ii) assert any associated claims and causes of
|
|
99
|
+
action with respect to the Work, in either case contrary to Affirmer's
|
|
100
|
+
express Statement of Purpose.
|
|
101
|
+
|
|
102
|
+
4. Limitations and Disclaimers.
|
|
103
|
+
|
|
104
|
+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
|
105
|
+
surrendered, licensed or otherwise affected by this document.
|
|
106
|
+
b. Affirmer offers the Work as-is and makes no representations or
|
|
107
|
+
warranties of any kind concerning the Work, express, implied,
|
|
108
|
+
statutory or otherwise, including without limitation warranties of
|
|
109
|
+
title, merchantability, fitness for a particular purpose, non
|
|
110
|
+
infringement, or the absence of latent or other defects, accuracy, or
|
|
111
|
+
the present or absence of errors, whether or not discoverable, all to
|
|
112
|
+
the greatest extent permissible under applicable law.
|
|
113
|
+
c. Affirmer disclaims responsibility for clearing rights of other persons
|
|
114
|
+
that may apply to the Work or any use thereof, including without
|
|
115
|
+
limitation any person's Copyright and Related Rights in the Work.
|
|
116
|
+
Further, Affirmer disclaims responsibility for obtaining any necessary
|
|
117
|
+
consents, permissions or other rights required for any use of the
|
|
118
|
+
Work.
|
|
119
|
+
d. Affirmer understands and acknowledges that Creative Commons is not a
|
|
120
|
+
party to this document and has no duty or obligation with respect to
|
|
121
|
+
this CC0 or use of the Work.
|
mesomath-1.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mesomath
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Mesopotamian Calculator
|
|
5
|
+
Project-URL: Homepage, https:mesomath.readthedocs.io
|
|
6
|
+
Project-URL: Issues, https://github.com/jccsvq/mesomath/issues
|
|
7
|
+
Project-URL: Source, https://github.com/jccsvq/mesomath
|
|
8
|
+
Author-email: Jesús Cabrera <jccsvq@gmail.com>
|
|
9
|
+
License-Expression: CC0-1.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: arithmetic,calculator,command-line,mesopotamia,metrology,sexagesimal
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Education
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
24
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
25
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
26
|
+
Requires-Python: >=3.8
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
## Overview
|
|
30
|
+
|
|
31
|
+
This package is intended for:
|
|
32
|
+
|
|
33
|
+
* 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.
|
|
34
|
+
|
|
35
|
+
* the arithmetic of physical quantities, length, surface, etc. described using the metrology of the Old Babylonian Period.
|
|
36
|
+
|
|
37
|
+
Inspired by the arithmetic and metrological parts of Baptiste Mélès' [MesoCalc](https://github.com/BapMel/mesocalc), it aims to bring this type of calculation to `Python3` programming and to the `Python3` command line as an interactive calculator.
|
|
38
|
+
|
|
39
|
+
`mesomath` module contains four submodules:
|
|
40
|
+
|
|
41
|
+
* `babn.py`
|
|
42
|
+
* `hamming.py`
|
|
43
|
+
* `mesolib.py`
|
|
44
|
+
* `npvs`
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
one utility script:
|
|
48
|
+
|
|
49
|
+
* `createDB.py`
|
|
50
|
+
|
|
51
|
+
one example script:
|
|
52
|
+
|
|
53
|
+
* `example-melville.py`
|
|
54
|
+
|
|
55
|
+
four test/demo scripts:
|
|
56
|
+
|
|
57
|
+
* `test-babn.py`
|
|
58
|
+
* `test-hamming.py`
|
|
59
|
+
* `test-mesolib.py`
|
|
60
|
+
* `test-npvs.py`
|
|
61
|
+
|
|
62
|
+
and two applications in the `progs` subdirectory:
|
|
63
|
+
|
|
64
|
+
* `metrotable.py` to print segments of metrological tables.
|
|
65
|
+
* `mtlookup.py` to search for the abstract number that corresponds to a measure or to list measures that correspond to a given abstract number.
|
|
66
|
+
|
|
67
|
+
## Documentation
|
|
68
|
+
|
|
69
|
+
Documentation for this package is in [Read the Docs](https://mesomath.readthedocs.io/index.html),
|
|
70
|
+
|
|
71
|
+
Includes:
|
|
72
|
+
|
|
73
|
+
* A [tutorial on using this package as a command-line calculator](https://mesomath.readthedocs.io/tutorial.html).
|
|
74
|
+
* Tutorials for the two included applications:
|
|
75
|
+
* * [`metrotable`](https://mesomath.readthedocs.io/progs/metrotable.html)
|
|
76
|
+
* * [`mtlookup`](https://mesomath.readthedocs.io/progs/mtlookup.html)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
## Dependencies
|
|
80
|
+
|
|
81
|
+
`mesomath` only uses standard Python modules: `math`, `itertools`, `argparse`, `sys`, `re` and `sqlite3`.
|
|
82
|
+
|
|
83
|
+
Tested with Python 3.11.2 under Debian GNU/Linux 12 (bookworm) in x86_64 and aarch64 (raspberrypi 5).
|
|
84
|
+
|
|
85
|
+
## `babn.py`
|
|
86
|
+
|
|
87
|
+
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.
|
|
88
|
+
|
|
89
|
+
### Note:
|
|
90
|
+
|
|
91
|
+
* Operator `/` return the approximate floating division of `a/b` for any pair of numbers.
|
|
92
|
+
* Operator `//` is for the "Babylonian Division" of `a` by `b`, i.e. `a//b` returns `a` times the reciprocal of `b`, which requires `b` to be regular.
|
|
93
|
+
|
|
94
|
+
### Use as an interactive calculator
|
|
95
|
+
|
|
96
|
+
Consult the [tutorial](https://mesomath.readthedocs.io/tutorial.html)!
|
|
97
|
+
|
|
98
|
+
The easiest way is to invoque the interactive python interpreter and import the class BabN; for instance
|
|
99
|
+
|
|
100
|
+
$ python3 -i
|
|
101
|
+
Python 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0] on linux
|
|
102
|
+
Type "help", "copyright", "credits" or "license" for more information.
|
|
103
|
+
>>> from mesomath.babn import BabN as bn
|
|
104
|
+
>>> a = bn(405)
|
|
105
|
+
>>> a
|
|
106
|
+
6:45
|
|
107
|
+
>>> (etc.)
|
|
108
|
+
|
|
109
|
+
or, with ipython:
|
|
110
|
+
|
|
111
|
+
$ ipython3
|
|
112
|
+
Python 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0]
|
|
113
|
+
Type 'copyright', 'credits' or 'license' for more information
|
|
114
|
+
IPython 8.5.0 -- An enhanced Interactive Python. Type '?' for help.
|
|
115
|
+
|
|
116
|
+
In [1]: from mesomath.babn import BabN as bn
|
|
117
|
+
|
|
118
|
+
In [2]: a = bn(405)
|
|
119
|
+
|
|
120
|
+
In [3]: a
|
|
121
|
+
Out[3]: 6:45
|
|
122
|
+
|
|
123
|
+
In [4]: a.explain()
|
|
124
|
+
| Sexagesimal number: [6, 45] is the decimal number: 405.
|
|
125
|
+
| It may be written as 2^0 * 3^4 * 5^1 * 1),
|
|
126
|
+
| so, it is a regular number with reciprocal: 8:53:20
|
|
127
|
+
|
|
128
|
+
In [5]: (etc.)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
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) :
|
|
132
|
+
|
|
133
|
+
#!/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")'
|
|
134
|
+
|
|
135
|
+
then, after making it executable and instaling it somewhere on the PATH:
|
|
136
|
+
|
|
137
|
+
$ babcalc
|
|
138
|
+
|
|
139
|
+
Welcome to Babylonian Calculator
|
|
140
|
+
...the calculator that every scribe should have!
|
|
141
|
+
Use: bn(number)
|
|
142
|
+
|
|
143
|
+
>>> a = bn(405)
|
|
144
|
+
>>> a
|
|
145
|
+
6:45
|
|
146
|
+
>>> (etc.)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
## `hamming.py`
|
|
150
|
+
|
|
151
|
+
Regular or Hamming numbers are numbers of the form:
|
|
152
|
+
|
|
153
|
+
H = 2^i * 3^j × 5^k
|
|
154
|
+
|
|
155
|
+
where i, j, k ≥ 0
|
|
156
|
+
|
|
157
|
+
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`.
|
|
158
|
+
|
|
159
|
+
## `mesolib.py`
|
|
160
|
+
|
|
161
|
+
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.
|
|
162
|
+
|
|
163
|
+
## `npvs.py`
|
|
164
|
+
|
|
165
|
+
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:
|
|
166
|
+
|
|
167
|
+
* class `BsyG`: Babylonian counting System G (iku ese bur bur_u sar sar_u sar_gal)
|
|
168
|
+
* class `BsyS`: Babylonian counting System S (dis u ges gesu sar sar_u sar_gal)
|
|
169
|
+
* class `MesoM`: To represent physical quantities, inherited by:
|
|
170
|
+
* class `Blen`: Babylonian length system (susi kus ninda us danna)
|
|
171
|
+
* class `Bsur`: Babylonian surface system (se gin sar gan)
|
|
172
|
+
* class `Bvol`: Babylonian volume system (se gin sar gan)
|
|
173
|
+
* class `Bcap`: Babylonian capacity system (se gin sila ban bariga gur)
|
|
174
|
+
* class `Bwei`: Babylonian weight system (se gin mana gu)
|
|
175
|
+
* class `Bbri`: Babylonian brick counting system (se gin sar gan)
|
|
176
|
+
|
|
177
|
+
Please, read the [tutorial](https://mesomath.readthedocs.io/tutorial.html) to see how to use all these classes.
|
|
178
|
+
|
|
179
|
+
## `createDB.py`
|
|
180
|
+
|
|
181
|
+
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.
|
|
182
|
+
|
|
183
|
+
Use:
|
|
184
|
+
|
|
185
|
+
$ python3 createDB.py
|
|
186
|
+
|
|
187
|
+
to create the default regular number database `regular.db3` in your directory. You can also use:
|
|
188
|
+
|
|
189
|
+
$ python3 createDB.py -o 'path/name'
|
|
190
|
+
|
|
191
|
+
to create it in a non-standar location. In this case, think of using:
|
|
192
|
+
|
|
193
|
+
BabN.database = 'path/name'
|
|
194
|
+
|
|
195
|
+
to inform `BabN` of its location.
|
|
196
|
+
|
|
197
|
+
## `example-melville.py`
|
|
198
|
+
|
|
199
|
+
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)](https://www.researchgate.net/publication/237309438_RECIPROCALS_AND_RECIPROCAL_ALGORITHMS_IN_MESOPOTAMIAN_MATHEMATICS)
|
|
200
|
+
|
|
201
|
+
$ python3 example-melville.py
|
|
202
|
+
|
|
203
|
+
Output:
|
|
204
|
+
|
|
205
|
+
Searching the reciprocal of 2:5 according to D. J. Melville (2005)
|
|
206
|
+
|
|
207
|
+
Example 1: from Table 2. Simple Reciprocal algorithm
|
|
208
|
+
|
|
209
|
+
d1 = BabN('2:5')
|
|
210
|
+
r1 = d1.tail()
|
|
211
|
+
r2 = r1.rec()
|
|
212
|
+
r3 = d1 * r2
|
|
213
|
+
r4 = r3.rec()
|
|
214
|
+
r5 = r4 * r2
|
|
215
|
+
|
|
216
|
+
Result r5 = 28:48
|
|
217
|
+
|
|
218
|
+
Example 2: from Table 3. using "The Technique"
|
|
219
|
+
|
|
220
|
+
r1 = d1.tail()
|
|
221
|
+
r2 = r1.rec()
|
|
222
|
+
r3 = d1.head() * r2
|
|
223
|
+
r4 = r3+BabN(1)
|
|
224
|
+
r5 = r4.rec()
|
|
225
|
+
r6 = r5 * r2
|
|
226
|
+
|
|
227
|
+
Result r6 = 28:48
|
mesomath-1.1.0/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
This is a companion project to [MesoMath](https://github.com/jccsvq/mesomath) intended to provide a [PyPI](https://pypi.org/) installation package. It contains a more convenient restructuring of the source files. For additional information on MesoMath, please refer to the [original project](https://github.com/jccsvq/mesomath) or its [documentation.](https://mesomath.readthedocs.io/).
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
## Overview
|
|
2
|
+
|
|
3
|
+
This package is intended for:
|
|
4
|
+
|
|
5
|
+
* 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.
|
|
6
|
+
|
|
7
|
+
* the arithmetic of physical quantities, length, surface, etc. described using the metrology of the Old Babylonian Period.
|
|
8
|
+
|
|
9
|
+
Inspired by the arithmetic and metrological parts of Baptiste Mélès' [MesoCalc](https://github.com/BapMel/mesocalc), it aims to bring this type of calculation to `Python3` programming and to the `Python3` command line as an interactive calculator.
|
|
10
|
+
|
|
11
|
+
`mesomath` module contains four submodules:
|
|
12
|
+
|
|
13
|
+
* `babn.py`
|
|
14
|
+
* `hamming.py`
|
|
15
|
+
* `mesolib.py`
|
|
16
|
+
* `npvs`
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
one utility script:
|
|
20
|
+
|
|
21
|
+
* `createDB.py`
|
|
22
|
+
|
|
23
|
+
one example script:
|
|
24
|
+
|
|
25
|
+
* `example-melville.py`
|
|
26
|
+
|
|
27
|
+
four test/demo scripts:
|
|
28
|
+
|
|
29
|
+
* `test-babn.py`
|
|
30
|
+
* `test-hamming.py`
|
|
31
|
+
* `test-mesolib.py`
|
|
32
|
+
* `test-npvs.py`
|
|
33
|
+
|
|
34
|
+
and two applications in the `progs` subdirectory:
|
|
35
|
+
|
|
36
|
+
* `metrotable.py` to print segments of metrological tables.
|
|
37
|
+
* `mtlookup.py` to search for the abstract number that corresponds to a measure or to list measures that correspond to a given abstract number.
|
|
38
|
+
|
|
39
|
+
## Documentation
|
|
40
|
+
|
|
41
|
+
Documentation for this package is in [Read the Docs](https://mesomath.readthedocs.io/index.html),
|
|
42
|
+
|
|
43
|
+
Includes:
|
|
44
|
+
|
|
45
|
+
* A [tutorial on using this package as a command-line calculator](https://mesomath.readthedocs.io/tutorial.html).
|
|
46
|
+
* Tutorials for the two included applications:
|
|
47
|
+
* * [`metrotable`](https://mesomath.readthedocs.io/progs/metrotable.html)
|
|
48
|
+
* * [`mtlookup`](https://mesomath.readthedocs.io/progs/mtlookup.html)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
## Dependencies
|
|
52
|
+
|
|
53
|
+
`mesomath` only uses standard Python modules: `math`, `itertools`, `argparse`, `sys`, `re` and `sqlite3`.
|
|
54
|
+
|
|
55
|
+
Tested with Python 3.11.2 under Debian GNU/Linux 12 (bookworm) in x86_64 and aarch64 (raspberrypi 5).
|
|
56
|
+
|
|
57
|
+
## `babn.py`
|
|
58
|
+
|
|
59
|
+
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.
|
|
60
|
+
|
|
61
|
+
### Note:
|
|
62
|
+
|
|
63
|
+
* Operator `/` return the approximate floating division of `a/b` for any pair of numbers.
|
|
64
|
+
* Operator `//` is for the "Babylonian Division" of `a` by `b`, i.e. `a//b` returns `a` times the reciprocal of `b`, which requires `b` to be regular.
|
|
65
|
+
|
|
66
|
+
### Use as an interactive calculator
|
|
67
|
+
|
|
68
|
+
Consult the [tutorial](https://mesomath.readthedocs.io/tutorial.html)!
|
|
69
|
+
|
|
70
|
+
The easiest way is to invoque the interactive python interpreter and import the class BabN; for instance
|
|
71
|
+
|
|
72
|
+
$ python3 -i
|
|
73
|
+
Python 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0] on linux
|
|
74
|
+
Type "help", "copyright", "credits" or "license" for more information.
|
|
75
|
+
>>> from mesomath.babn import BabN as bn
|
|
76
|
+
>>> a = bn(405)
|
|
77
|
+
>>> a
|
|
78
|
+
6:45
|
|
79
|
+
>>> (etc.)
|
|
80
|
+
|
|
81
|
+
or, with ipython:
|
|
82
|
+
|
|
83
|
+
$ ipython3
|
|
84
|
+
Python 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0]
|
|
85
|
+
Type 'copyright', 'credits' or 'license' for more information
|
|
86
|
+
IPython 8.5.0 -- An enhanced Interactive Python. Type '?' for help.
|
|
87
|
+
|
|
88
|
+
In [1]: from mesomath.babn import BabN as bn
|
|
89
|
+
|
|
90
|
+
In [2]: a = bn(405)
|
|
91
|
+
|
|
92
|
+
In [3]: a
|
|
93
|
+
Out[3]: 6:45
|
|
94
|
+
|
|
95
|
+
In [4]: a.explain()
|
|
96
|
+
| Sexagesimal number: [6, 45] is the decimal number: 405.
|
|
97
|
+
| It may be written as 2^0 * 3^4 * 5^1 * 1),
|
|
98
|
+
| so, it is a regular number with reciprocal: 8:53:20
|
|
99
|
+
|
|
100
|
+
In [5]: (etc.)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
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) :
|
|
104
|
+
|
|
105
|
+
#!/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")'
|
|
106
|
+
|
|
107
|
+
then, after making it executable and instaling it somewhere on the PATH:
|
|
108
|
+
|
|
109
|
+
$ babcalc
|
|
110
|
+
|
|
111
|
+
Welcome to Babylonian Calculator
|
|
112
|
+
...the calculator that every scribe should have!
|
|
113
|
+
Use: bn(number)
|
|
114
|
+
|
|
115
|
+
>>> a = bn(405)
|
|
116
|
+
>>> a
|
|
117
|
+
6:45
|
|
118
|
+
>>> (etc.)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
## `hamming.py`
|
|
122
|
+
|
|
123
|
+
Regular or Hamming numbers are numbers of the form:
|
|
124
|
+
|
|
125
|
+
H = 2^i * 3^j × 5^k
|
|
126
|
+
|
|
127
|
+
where i, j, k ≥ 0
|
|
128
|
+
|
|
129
|
+
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`.
|
|
130
|
+
|
|
131
|
+
## `mesolib.py`
|
|
132
|
+
|
|
133
|
+
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.
|
|
134
|
+
|
|
135
|
+
## `npvs.py`
|
|
136
|
+
|
|
137
|
+
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:
|
|
138
|
+
|
|
139
|
+
* class `BsyG`: Babylonian counting System G (iku ese bur bur_u sar sar_u sar_gal)
|
|
140
|
+
* class `BsyS`: Babylonian counting System S (dis u ges gesu sar sar_u sar_gal)
|
|
141
|
+
* class `MesoM`: To represent physical quantities, inherited by:
|
|
142
|
+
* class `Blen`: Babylonian length system (susi kus ninda us danna)
|
|
143
|
+
* class `Bsur`: Babylonian surface system (se gin sar gan)
|
|
144
|
+
* class `Bvol`: Babylonian volume system (se gin sar gan)
|
|
145
|
+
* class `Bcap`: Babylonian capacity system (se gin sila ban bariga gur)
|
|
146
|
+
* class `Bwei`: Babylonian weight system (se gin mana gu)
|
|
147
|
+
* class `Bbri`: Babylonian brick counting system (se gin sar gan)
|
|
148
|
+
|
|
149
|
+
Please, read the [tutorial](https://mesomath.readthedocs.io/tutorial.html) to see how to use all these classes.
|
|
150
|
+
|
|
151
|
+
## `createDB.py`
|
|
152
|
+
|
|
153
|
+
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.
|
|
154
|
+
|
|
155
|
+
Use:
|
|
156
|
+
|
|
157
|
+
$ python3 createDB.py
|
|
158
|
+
|
|
159
|
+
to create the default regular number database `regular.db3` in your directory. You can also use:
|
|
160
|
+
|
|
161
|
+
$ python3 createDB.py -o 'path/name'
|
|
162
|
+
|
|
163
|
+
to create it in a non-standar location. In this case, think of using:
|
|
164
|
+
|
|
165
|
+
BabN.database = 'path/name'
|
|
166
|
+
|
|
167
|
+
to inform `BabN` of its location.
|
|
168
|
+
|
|
169
|
+
## `example-melville.py`
|
|
170
|
+
|
|
171
|
+
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)](https://www.researchgate.net/publication/237309438_RECIPROCALS_AND_RECIPROCAL_ALGORITHMS_IN_MESOPOTAMIAN_MATHEMATICS)
|
|
172
|
+
|
|
173
|
+
$ python3 example-melville.py
|
|
174
|
+
|
|
175
|
+
Output:
|
|
176
|
+
|
|
177
|
+
Searching the reciprocal of 2:5 according to D. J. Melville (2005)
|
|
178
|
+
|
|
179
|
+
Example 1: from Table 2. Simple Reciprocal algorithm
|
|
180
|
+
|
|
181
|
+
d1 = BabN('2:5')
|
|
182
|
+
r1 = d1.tail()
|
|
183
|
+
r2 = r1.rec()
|
|
184
|
+
r3 = d1 * r2
|
|
185
|
+
r4 = r3.rec()
|
|
186
|
+
r5 = r4 * r2
|
|
187
|
+
|
|
188
|
+
Result r5 = 28:48
|
|
189
|
+
|
|
190
|
+
Example 2: from Table 3. using "The Technique"
|
|
191
|
+
|
|
192
|
+
r1 = d1.tail()
|
|
193
|
+
r2 = r1.rec()
|
|
194
|
+
r3 = d1.head() * r2
|
|
195
|
+
r4 = r3+BabN(1)
|
|
196
|
+
r5 = r4.rec()
|
|
197
|
+
r6 = r5 * r2
|
|
198
|
+
|
|
199
|
+
Result r6 = 28:48
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2025-present jccsvq <jccsvq@gmail.com>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
__title__ = "MesoMath"
|
|
5
|
+
__version__ = "1.1.0"
|
|
6
|
+
__author__ = "Jesús Cabrera"
|
|
7
|
+
__email__ = "jccsvq@gmail.com"
|
|
8
|
+
__license__ = "CC0-1.0"
|
|
9
|
+
__uri__ = "https://mesomath.readthedocs.io"
|
|
10
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""This package is intended for the arithmetic of natural sexagesimal numbers,
|
|
2
|
+
mainly in their "floating" aspect (i.e., by removing all possible trailing
|
|
3
|
+
sexagesimal zeros from the right), as performed by the Babylonian scribes and
|
|
4
|
+
their apprentices in ancient times.
|
|
5
|
+
|
|
6
|
+
Inpired by the arithmetic part of Baptiste Mélès' MesoCalc, it aims to bring
|
|
7
|
+
this type of calculation to Python programming and to the command line as a
|
|
8
|
+
calculator."""
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from mesomath.babn import BabN as bn
|
|
2
|
+
from mesomath.npvs import Bbri as bb
|
|
3
|
+
from mesomath.npvs import Bcap as bc
|
|
4
|
+
from mesomath.npvs import Blen as bl
|
|
5
|
+
from mesomath.npvs import Bsur as bs
|
|
6
|
+
from mesomath.npvs import BsyG as bG
|
|
7
|
+
from mesomath.npvs import BsyS as bS
|
|
8
|
+
from mesomath.npvs import Bvol as bv
|
|
9
|
+
from mesomath.npvs import Bwei as bw
|
|
10
|
+
|
|
11
|
+
message = """\nWelcome to Babylonian Calculator v1.1.0
|
|
12
|
+
...the calculator that every scribe should have!
|
|
13
|
+
|
|
14
|
+
Use: bn(number) for sexagesimal calculations
|
|
15
|
+
Metrological classes: bl, bs, bv, bc, bw, bG, bS and bb loaded.
|
|
16
|
+
|
|
17
|
+
jccsvq fecit, 2025."""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
print(message)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import code
|
|
2
|
+
|
|
3
|
+
from mesomath.__about__ import __version__ as VERSION
|
|
4
|
+
|
|
5
|
+
from mesomath.babn import BabN as bn
|
|
6
|
+
from mesomath.npvs import Blen as bl
|
|
7
|
+
from mesomath.npvs import Bsur as bs
|
|
8
|
+
from mesomath.npvs import Bvol as bv
|
|
9
|
+
from mesomath.npvs import Bcap as bc
|
|
10
|
+
from mesomath.npvs import Bwei as bw
|
|
11
|
+
from mesomath.npvs import BsyG as bG
|
|
12
|
+
from mesomath.npvs import BsyS as bS
|
|
13
|
+
from mesomath.npvs import Bbri as bb
|
|
14
|
+
|
|
15
|
+
message = f"""\nWelcome to Babylonian Calculator {VERSION}
|
|
16
|
+
...the calculator that every scribe should have!
|
|
17
|
+
|
|
18
|
+
Use: bn(number) for sexagesimal calculations
|
|
19
|
+
Metrological classes: bl, bs, bv, bc, bw, bG, bS and bb loaded.
|
|
20
|
+
|
|
21
|
+
jccsvq fecit, 2025."""
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def main():
|
|
25
|
+
"""Entry point for babcalc"""
|
|
26
|
+
|
|
27
|
+
local_vars = globals().copy() # Start with all global variables
|
|
28
|
+
local_vars.update(locals()) # Add all local variables at this point
|
|
29
|
+
|
|
30
|
+
code.interact(
|
|
31
|
+
banner=message,
|
|
32
|
+
local=local_vars,
|
|
33
|
+
exitmsg="\n--- Exiting Babylonian Calculator, Bye! ---\n",
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
if __name__ == "__main__":
|
|
38
|
+
main()
|