Skip to main content

Specular Differentiation

PyPI version Python 3.14 DOI License CodeFactor CodeQL Advanced Docs

The Python package specular implements specular differentiation, which generalizes classical differentiation. This implementation strictly follows the definitions, notations, and results in [1], [2], and [3].

A specular derivative (the red line) can be understood as the average of the inclination angles of the right and left derivatives. In contrast, a symmetric derivative (the purple line) is the average of the right and left derivatives. Their difference is illustrated in the animation.

Animation comparing specular and symmetric derivatives

Installation

Requirements

specular-differentiation requires:

  • Python >= 3.14
  • numpy >= 2.4

Additional backends are available through optional dependencies:

  • numba: numba
  • jax: jax, jaxlib

Standard Installation

pip install specular-differentiation

The package is distributed as specular-differentiation and imported in Python as specular.

This installs scaled_mean, derivative, gradient, and jacobian, using NumPy by default, as well as the scalar ODE methods and the SPEG optimizer. Backend selection is available through set_backend, get_backend, use_backend, and available_backends.

Optional features

pip install "specular-differentiation[numba]"           # Numba backend
pip install "specular-differentiation[jax]"             # JAX backend

Developer installation

pip install -e ".[dev]"

Documentation tools can be installed separately with:

pip install -e ".[docs]"

Backend support

The package is organized around a backend system. NumPy is the default backend, while accelerated backends are optional and may require extra dependencies.

Quick start

The following simple example calculates the specular derivative of the ReLU function $f(x) = max(0, x)$ at the origin.

import specular

ReLU = lambda x: max(x, 0)
print(specular.derivative(ReLU, x=0))
0.41421356237309503

Documentation

LaTeX Macro

To use the specular differentiation symbol in your LaTeX document, add the following code to your preamble (before \begin{document}):

% Required packages
\usepackage{graphicx}
\usepackage{amssymb}

% specular derivative symbol
\newcommand{\sd}{\mathord{\prime\mkern-2.5mu\reflectbox{$\scriptstyle\prime$}}}

% specular Gateaux derivative symbol
\newcommand{\sGd}{\widehat{\mkern-2mu d}\mkern1mu}

% specular gradient symbol
\newcommand{\sg}{%
  \mathchoice
    {\mathord{\raisebox{-0.05ex}{\rule{0pt}{1.3ex}\smash{\scalebox{1.37}[1.22]{\ensuremath{\displaystyle\blacktriangledown}}}}\mkern-1.2mu}}
    {\mathord{\raisebox{-0.05ex}{\rule{0pt}{1.3ex}\smash{\scalebox{1.37}[1.22]{\ensuremath{\textstyle\blacktriangledown}}}}\mkern-1.2mu}}
    {\mathord{\raisebox{-0.03ex}{\rule{0pt}{1.0ex}\smash{\scalebox{1.29}[1.15]{\ensuremath{\scriptstyle\blacktriangledown}}}}\mkern-0.8mu}}
    {\mathord{\raisebox{-0.02ex}{\rule{0pt}{0.8ex}\smash{\scalebox{1.18}[1.05]{\ensuremath{\scriptscriptstyle\blacktriangledown}}}}\mkern-0.5mu}}
}

Citing specular-differentiation

To cite this repository:

@software{specular_diff,
  author = {Jung, Kiyuob},
  title = {{specular-differentiation}},
  doi = {10.5281/zenodo.18246734},
  url = {https://github.com/kyjung2357/specular-differentiation},
  version = {1.3.2},
  year = {2026},
}

References

[1] K. Jung. Specular differentiation in one dimension: a quasi-mean value theorem, regularity, and discontinuities. arXiv preprint arXiv:2601.09900, 2026.

[2] K. Jung. The specular ellipse method for scalar ordinary differential equations: exactness and accuracy up to fourth order. arXiv preprint arXiv:2608.30280, 2026.

[3] K. Jung. Specular differentiation in normed vector spaces: Quasi-Mean Value and Quasi-Fermat Theorems. arXiv preprint arXiv:2601.10950, 2026.

[4] K. Jung. Specular gradient methods for nonsmooth convex optimization in Euclidean spaces: a subgradient selection strategy. arXiv preprint arXiv:2605.25490, 2026.

[5] K. Jung and J. Oh. Nonsmooth convex optimization using the specular gradient method with root-linear convergence. arXiv preprint arXiv:2412.20747, 2024.

Metadata

Release files for specular-differentiation 1.3.2

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

Built distribution (wheel)

Table of built distributions (wheels) for specular-differentiation 1.3.2
File Interpreter ABI Platform
specular_differentiation-1.3.2-py3-none-any.whl Python 3 none any Details

Release files / specular_differentiation-1.3.2-py3-none-any.whl

Download URL specular_differentiation-1.3.2-py3-none-any.whl
Size 55.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
566af36b91075bf18dad2ba101511642c25ea988009990c6a52dc8299d307ef8
BLAKE2b-256 checksum
How to use checksums
f20b0ece619d50bc85022d6580f91ded3fa55c6b4fcf9ebc3ad2d007d0c32346
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release history Release notifications | RSS feed

1.3.3

1 release file

This release

1.3.2 This release

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.2

2 release files

1.2.1

1 release file

1.2.0

2 release files

1.1.0

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.14.0

2 release files

0.13.0

2 release files

0.12.1

2 release files

0.12.0

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.7

2 release files

0.5.6

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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