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. See References for more details.

The specular derivative is defined by averaging the angles associated with the forward and backward difference quotients:

The specular derivative of f at x is the tangent of the average of arctan of the right derivative and arctan of the left derivative.

where $f_{+}'(x)$ and $f_{-}'(x)$ are the right and left derivatives of $f$ at $x$, respectively. In contrast, the symmetric derivative takes the arithmetic mean of these derivatives. The animation below compares the two: the dashed blue and green lines have slopes equal to the specular and symmetric derivatives, respectively.

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

Backend support

Backend Availability Minimum version
NumPy Default numpy >= 2.4
Numba Optional numba >= 0.65
JAX Optional jax >= 0.10, jaxlib >= 0.10

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[T1]{fontenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{amssymb}

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

% specular Gateaux derivative symbol
\newcommand{\sGd}{%
    \mathord{\text{\normalfont\UseTextSymbol{T1}{\dj}}}%
}

% specular Frechet derivative symbol
\newcommand{\sFd}{%
    \mathord{\text{\normalfont\UseTextSymbol{T1}{\DJ}}}%
}

% 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}}
}

For usage examples and Markdown notation, see LaTeX Macro in the User Guide.

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.4},
  year = {2026},
}

References

One dimension

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

[2] K. Jung and J. Oh. Regular specular differentiation in Euclidean spaces. arXiv preprint arXiv:2210.06062v3, 2022.

Higher dimensions

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

Applications

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

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

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

Metadata

Release files for specular-differentiation 1.3.4

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.4
File Interpreter ABI Platform Actions
specular_differentiation-1.3.4-py3-none-any.whl Python 3 none any Details for specular_differentiation-1.3.4-py3-none-any.whl

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

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

Security for specular-differentiation 1.3.4

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.

Release history Release notifications | RSS feed

This release

1.3.4 This release

1 release file No provenance

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