a mathematician's spellbook
Project description
daamath
a mathematician's spellbook: cross-language math library specification, with implementations in various programming languages
install
| python | python -m pip install daamath |
| c | … |
| c++ | … |
| javascript | … |
| julia | … |
| … | … |
click on your language for full instructions
why does daamath exist?
"does integer division do floor rounding or trunc rounding?"
"why is there no log(num, base) in C?"
"why does pow(2, 3) return a float?"
"why do i have to know powf, pow and powl in C? cant they just make one pow?"
"i wish i could translate my math code from C to Python but they gives me different results"
"but log(-1) is defined in the complex numbers. you mean i have to use clog for that? log should be able to do that if i pass a complex number"
"where is acot(x)??? how do i make acot from atan??"
"where is nand(x, y)? not(and(x, y)) looks so unnecessary"
"i know my int is even so i divide it by 2. why did you promote it to a float? its still supposed to be an int!"
"why does log(2) give me 0.69314718056? is it base 10 or base e?"
"why is it log(num, base) in python but log(base, num) in julia?"
"i wish this math library had the golden ratio constant"
this is very ugly to me. so i made daamath.
what does daamath do?
- cross-language consistency: daamath is a language-agnostic specification. it has consistent behaviour and interface across languages
- domain-aware mathematics: operators respect the domain of discussion. for example, an integer divided by an integer can be set to return either an integer or rational number
- complete function sets: hyperoperations to n=4, trigonometry in all 2 non-degenerate geometries, all non-trivial boolean gates, ordering operators, quantization/rounding, …
- type preservation: daamath will never cast an
intto afloat. it will always preserve your contract of precision aka your datatype. - clean namespace: everything in daamath has one name only, and no aliases
- unicode characters: find math characters from unicode easily
- mathematical constants: e, τ, φ, …
- documentation website: everything in daamath has a dedicated documentation webpage
examples
by default, integer division raises an error if the result isnt an integer
dm.div(5, 2)
# OutOfDomainError: result 2.5 is not in INTEGERS
but if you enable rounding, no error is raised
dm.context.datatypes.rounding = dm.roundfloor
dm.div(5, 2)
# 2
by default, daamath enables nearest-even rounding for float operations. you can disable that to make sure all your operations are 100% accurate
dm.context.datatypes.rounding = None
dm.add(1.0, 2.0)
# 3.0
dm.add(0.1, 0.2)
# FidelityError: result 0.3000000000000000166533453693773481063544750213623046875 cannot be accurately represented by the float datatype
you also have cool tidbits like this:
print(dm.greek.lowercase.tau)
# τ
print(dm.infinity, dm.not.in.right, dm.latin.doublestruck.uppercase.r)
# ∞ ∉ ℝ
rant
i originally made daamath because when i designed gapprox, i wanted a math library that was both very functionally complete and had the same behaviour across languages. but i found that programmers made a lot of bad decisions about how to implement mathematics into code. i discovered a lot of maths along the way too. i hope daamath rewires how programmers think of maths, because its not like the real numbers are the only "real" numbers. ugh. or simply going along with IEEE's rounding without even acknowledging it. and they dont even know complex numbers exist. oh my gosh dont you know log(-1) exists??? youre just completely ignoring the complex domain. and 0/0 is not an error! your domain simply didnt define it. go look up what wheel algebra is. see the connection? NaN is just the IEEE 754 way to represent ⊥. they just didnt realize it. most of your "errors" can be represented as either a ClosureError (the result wasnt defined in the codomain) or a RepresentationError (you disabled rounding, and the datatype couldnt represent it accurately)
dont even get me started on how left out the unicode math characters are :( everyone slobbers over latex but they dont know about the fact that you can write things like eⁱᶿ = cos(θ) + i⋅sin(θ) or cosh²(θ) - sinh²(θ) = 1 or ln(x) = logₑ(x) or ∥z∥₂ = ²√(ℜ² + ℑ²) entirely with unicode
ok rant done
Project details
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 daamath-0.4.0.tar.gz.
File metadata
- Download URL: daamath-0.4.0.tar.gz
- Upload date:
- Size: 352.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
790f24a3a65659920de313bea78cb50d0c813d5afed919bc135a1cbf5d3da190
|
|
| MD5 |
f954709f86ab320d4f8b4558eb656e02
|
|
| BLAKE2b-256 |
b97f46139a869b20824e3136d1ddc89d28344f2a09c1e60db5fdab621b2d6b75
|
File details
Details for the file daamath-0.4.0-py3-none-any.whl.
File metadata
- Download URL: daamath-0.4.0-py3-none-any.whl
- Upload date:
- Size: 55.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9906df14615d5cca8f9520e56f0d6d45a5bbb1287556521269fa704c67177458
|
|
| MD5 |
8f63f8390d8b3f14c594367c36fff772
|
|
| BLAKE2b-256 |
0be70be9cec1d590aed891f8d4b71231ee3428529cff81f67a821f9c2bbab421
|