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.1.tar.gz (369.2 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.1-py3-none-any.whl (54.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: daamath-0.5.1.tar.gz
  • Upload date:
  • Size: 369.2 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.1.tar.gz
Algorithm Hash digest
SHA256 03948793685256f028fec7b5ded6ed16a1789979efeec51ac3442895d943d4ec
MD5 4db6d5de1911994d20debe6c304bd86a
BLAKE2b-256 1a7dc37c82f3eb68300e5c9a466a7fbcca1c6316b69c4278afb5775e1ec04730

See more details on using hashes here.

File details

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

File metadata

  • Download URL: daamath-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 54.1 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a023bcc2e6900e38cd79cf2e4ba01cbd6f913aed68952a9054c12753216385ec
MD5 4853874cf9e17894ec71e2ec4c964ec6
BLAKE2b-256 4cd3dc1ba13a0e600965c2310f6e519fd1e444999c66448cc97abf567e060a7b

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