Skip to content

daamath

a mathematician's spellbook: cross-language math library specification, with implementations across various programming languages

install

python python -m pip install daamath
c
c++
javascript
julia

why?

"does integer division do floor rounding or trunc rounding?"

"why does pow(2, 3) return a float? i expected an int"

"why do i have to know powf, pow and powl in C? cant they just make one pow?"

"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!"

"i wish i could translate my math code from C to Python but it gives me different results"

"why is there no log(num, base) in C?"

"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"

"why is it log(num, base) in python but log(base, num) in julia?"

"why were my calculations wrong? is log base 10 or base e?"

"where is acot(x)??? how do i make acot from atan??"

"where is nand(x, y)? not (x and y) is so unnecessary"

"i wish this math library had the golden ratio constant"

this is very ugly to me. so i made daamath.

features

  • cross-language consistency: daamath is designed to behave the same across languages.
  • true functions: faithful to the mathematics, you can define the domain, codomain, and mapping of functions. 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-degenerate boolean gates to arity 2, all 16 derived functions per relation, 12 rounding functions, …
  • clean namespace: no aliases, datatype naming conventions, underscore-binding, …
  • unicode characters: math-related unicode characters, presented in an elegant tree
  • mathematical constants: e, π, τ,
  • documentation website

examples

for our python examples, first import daamath as dm

# by default, daamath does complex arithmetic in f64:

dm.log(-5, 2)
# 4.532360141827194j
# you can do integer arithmetic with floats
dm.context.div.codomain = dm.domains.INTEGER
dm.div(5, 2)
# CodomainViolation: div(float 5, float 2) returned float 2.5 ∉ INTEGER
# create your own domains
NONZERO_REAL = lambda x: dm.REAL(x) and x != 0
NONZERO_REAL(1.0)
# True
NONZERO_REAL(0)
# False
# you can do matrix arithmetic naturally:
dm.context = dm.contexts.matrix
dm.mul([1,2,3], [2,3,4])
# 20

you also have cool tidbits like this:

dm.PI_F64 - dm.PI_F32
# 
dm.symbols.lowercase.tau
# τ
dm.symbols.infinity + dm.symbols.not.in.right + dm.symbols.latin.doublestruck.uppercase.r
# ∞ ∉ ℝ