Skip to main content

dual_numbers

2D Dual numbers for python, can trivially use complex numbers as scalars.

What are dual numbers?

Python uses j for the imaginary unit, here we use d for the dual unit, in order to differentiate it from scientific notation.

d^2 = 0

exp(a*d)=1+a*d

Since complex numbers can make rotations be done as multiplication, dual numbers can make posible translation as multiplication. As the dual part squares to 0, they can also be used for automatic differentiation:

f(x+d) = f(x) + f'(x)d Note: in complex numbers, f(x+i)=f(x)+f'(x)i

More info in wikipedia.

How to use:

To declare a dual number:

a=dual(1,2)
a
>>> (1+2d)
b=3 .d + 1
b
>>> (1+3d)
c=dual(1) # same as complex(1)
c
>>> (1+0d)
c.real
>>> 1
c.dl
>>> 0
dual(1+1j,2).real
>>> (1+1j) # This is not a bug, but a feature.

To add them, make sure the dual number comes first, since we cannot modify python's integer and float methods for adding:

a=1 .d + 2
b=1
a+b
>>> (3+1d) # CORRECT!!
b+a
>>> Error: "+" not defined for int with dual

So make sure to declare all your numbers as dual if you dont want to deal with these.

Basic arithmetic operations +,-,*,/,exp,log work as intended if both operands are dual. See docs or code for the cases when numbers are promoted.

  • a+b,a-b,a*b, etc
  • a.exp() and a.log() return their respective values. See docs or code for extending to other algebras ex.: exp(self,f=mathmodule).

Requirements

Install these with pip install as usual:

  • custom_literals (for easy dual declaration with .d)
  • forbiddenfruit (dependency for the former)

TODO

  • Test the library
  • Make literals optional
  • Add wheel
  • Make docs
  • Put more use cases
  • Give more links

Metadata

Release files for dual-numbers 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dual-numbers 0.0.2
File Size Uploaded Provenance Actions
dual_numbers-0.0.2.tar.gz 4.3 kB Without provenance Details for dual_numbers-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dual-numbers 0.0.2
File Interpreter ABI Platform Actions
dual_numbers-0.0.2-py3-none-any.whl Python 3 none any Details for dual_numbers-0.0.2-py3-none-any.whl

Total release size: 8.0 kB

Release files / dual_numbers-0.0.2.tar.gz

Download URL dual_numbers-0.0.2.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a399c0a30e51e7de2d48e572be62866972aec6f0245b71812204b8353ca72ec9
BLAKE2b-256 checksum
How to use checksums
4e80edabbec1c538069af647179ac066d1b4b6ae446c453c7d018325b45f3e3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release files / dual_numbers-0.0.2-py3-none-any.whl

Download URL dual_numbers-0.0.2-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d4671fce689f949ee50641f15696f550cbb9227878b5f5bdd600bde0102405cf
BLAKE2b-256 checksum
How to use checksums
7fd020343b82b937c5669917817840b3c39d45dbfc059f56d0cf98cd2572cd6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Security for dual-numbers 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page