Skip to main content

a mathematician's spellbook

Project description

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
# ∞ ∉ ℝ

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

daamath-0.5.0.tar.gz (369.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

daamath-0.5.0-py3-none-any.whl (53.8 kB view details)

Uploaded Python 3

File details

Details for the file daamath-0.5.0.tar.gz.

File metadata

  • Download URL: daamath-0.5.0.tar.gz
  • Upload date:
  • Size: 369.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for daamath-0.5.0.tar.gz
Algorithm Hash digest
SHA256 a41c92c85b033148a722b1a1088de8311c83df1b1955d33be31e94c042a1f46a
MD5 3f1896bfc890930d9e4258acca685f61
BLAKE2b-256 8e4e5a6747375794f5b2ee04ef74fad5dee2a759c5a6ee3b0d6230277ef0ffc7

See more details on using hashes here.

File details

Details for the file daamath-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: daamath-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 53.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for daamath-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7d4002556d9f17da1835f423685497d55f515b0960680e16d79204e801e04c6a
MD5 8521915b873c7724232ecaba935a643f
BLAKE2b-256 3d71e968d65ae148ab2c4db7365a881560c41d15ba60bc7386fba1b493c826c5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page