Hyper–Dual Numbers: A Theoretical Foundation for Exact Second Derivatives
Abstract
1. Introduction
- Assumption transparency and algebraic clarity. We make the assumptions required for exactness explicit (smoothness, control-flow branching policies, floating-point limitations, and behavior at non-smooth points). We prove the exact second-order Taylor lift and multivariate chain rule in a concise, implementation-oriented style.
- Comprehensive experimental assessment. We supplement algebraic results with numerical stability tests under noise and ill-conditioning, runtime and memory profiling, and sensitivity analyses in FD step size and variable scaling. A curated set of benchmark problems—from low-dimensional analytic tests to classical optimization functions and higher-dimensional examples—illustrates accuracy and robustness. We also include minimal C++, Python 3.11.5, and MATLAB R2023b skeletons for rapid prototyping.
2. Hyper-Dual Algebra and Assumptions for Exactness
2.1. From Generalized Complex Numbers to Hyper-Duals
2.2. Definition of the Hyper-Dual Algebra
2.3. Assumptions for Exactness and Limitations at Non-Smooth Points
- (A1)
- Smoothness.We assume that is in a neighborhood of the evaluation point. This guarantees the existence of mixed partial derivatives and Schwarz symmetry of the Hessian.
- (A2)
- Real-path control flow. All branching in code is evaluated on real parts, i.e., conditionals use only. This ensures that the hyper-dual execution follows the same path as the real-valued code.
- (A3)
- Floating-point arithmetic. Numerical claims are qualified by floating-point arithmetic: hyper-dual coefficients are returned to working precision and are ultimately limited by the conditioning of the real evaluation and the underlying hardware/BLAS stack.
- (A4)
- Non-smooth points. At non-smooth points (e.g., absolute values, maximum/minimum, limiters), classical second derivatives may not exist or may depend on the approach direction. In such cases, hyper-dual coefficients represent the derivatives of the implemented procedure under (A2), not classical derivatives of an idealized continuous model. Smoothing or regularization should be applied when classical second derivatives are required.
A Practical Smoothing Remark
3. Exact Taylor Lift and Extraction of Derivatives
3.1. Scalar Case
3.2. Multivariate Case and Hessian Extraction
3.3. Chain Rule and Compositions
4. Implementation Patterns and Algorithms
4.1. Smooth Lifts of Elementary Functions
4.2. Hessian Extraction Algorithm
4.3. Branching, Non-Smooth Operators, and Reproducibility
- description of any non-smooth operators and the smoothing/regularization policies used.
- The scaling and units of variables and the nondimensionalization adopted.
- details of the linear algebra stack (factorizations, tolerances, BLAS/LAPACK backends).
- Seeds and distributions for randomized tests.
Implementation Cross-Reference
| Algorithm 1: Selected mixed second derivative or Hessian–vector product. |
|
| Algorithm 2: Dense Hessian via hyper-dual numbers. |
| Require: Function f: , point , step sizes h1, h2 1: Initialize to zero 2: for 1 ≤ i ≤ n do 3: for i ≤ j ≤ n do 4: Lift x to with real parts xk and nilpotent parts 6: Set Hij = Hji = 7: end for 8: end for 9: return H |
5. Numerical Experiments
5.1. Analytic Test Functions
Polynomial and Trigonometric Combinations
5.2. Optimization Benchmarks: Rosenbrock, Beale, and Himmelblau
- Analytic Hessians.
- Hyper-dual Hessians.
- Central FD Hessians (with tuned step sizes).
- Complex-step second-derivative formulas where applicable.
5.3. Higher-Dimensional and Stiff Problems
5.3.1. Structured PDE–Residual Benchmark (Toy Poisson Model)
5.3.2. Neural-Network Loss Benchmark (Small MLP)
5.4. Numerical Stability Under Noise and Ill-Conditioning
5.4.1. Experimental Protocol
5.4.2. Additive Noise in Function Values
- Central FD approximations to using .
- Hyper-dual extraction of using a single evaluation of in .
5.4.3. Complex-Step Under Noise
5.4.4. Ill-Conditioned Problems and Scaling
6. Cost, Floating-Point Effects, and Comparative Analysis
6.1. Operation Counts, Runtime, and Memory Profiling
6.1.1. Operation Counts
6.1.2. Runtime and Memory Profiling
6.1.3. Integration Pattern (“Real Converge, HD Sweep”)
6.1.4. Algebraic Foundation (Concise)
6.1.5. Implicit Maps
6.1.6. Wall-Clock Scaling and Crossover Regimes
6.2. Floating-Point Effects and Deviation from Theoretical Exactness
6.2.1. Numerical Deviation Sources
6.2.2. Quantifying Floating-Point Deviation
6.2.3. Scaling and Nondimensionalization
6.2.4. h-Sweep Sanity Check
6.3. Sensitivity to FD Step Size and Variable Scaling
6.3.1. FD Step-Size Policy Used Throughout
6.3.2. Verification Examples
6.3.3. Noise Sensitivity
6.3.4. Reporting Checklist (Condensed)
6.4. Method Selection in Practice
6.4.1. Positioning
6.4.2. Practical Guidance
- Gradients only, very high n: complex-step or reverse AD.
- Dense Hessians or selected entries in legacy codes: hyper-duals.
- PDE/CFD optimization: reverse AD for gradients + hyper-dual sweep for curvature at convergence.
- Nonsmooth models: use smoothing or interpret coefficients diagnostically at kinks.
6.4.3. Implementation Pattern and Hessian Extraction
function Hessian_HD(f, x):
n = length(x); H = zeros(n,n)
for j in 1..n:
for i in 1..j:
xHD = lift_to_HD(x)
xHD[i] += eps1*h; xHD[j] += eps2*h
yHD = f(xHD)
hij = coeff_eps1eps2(yHD)/(h*h)
H[i,j] = hij; H[j,i] = hij
return H
6.4.4. Pitfalls
7. Extensions and Outlook
7.1. Higher-Order Derivatives
Sketch: Third Derivatives via Tri-Dual Extension
7.2. Vector-Valued Functions and Jacobians
7.3. Integration with AD Frameworks
- Reverse-mode pipelines are impractical to retrofit into legacy codes.
- Only modest numbers of variables or Hessian entries are required.
- Reproducibility and robustness under noise are prioritized over absolute speed.
Discussion Bridge
8. Conclusions
Practical Takeaways
- Hyper-dual numbers deliver mixed second derivatives to working precision without step tuning, provided and real-path branching is enforced.
- In noisy or ill-conditioned regimes, FD and CS second derivatives inherit amplification, whereas hyper-dual coefficients remain essentially h-invariant and scale primarily with the real-path conditioning.
- For dense Hessians (or selected mixed entries) in legacy or black-box codes, hyper-dual sweeps offer a robust, reproducible alternative to differencing.
- When only gradients are needed at very large n, complex-step or reverse AD remains preferable; hyper-duals are most beneficial once curvature is required.
- At non-smooth points, hyper-dual outputs diagnose the discrete model’s directional behavior; smoothing surrogates restore classical Hessians if needed.
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Conflicts of Interest
Appendix A. C++ Skeleton with Operator Overloading
| Listing A1. Minimal hyper–dual type and selected overloads (header-only). |
![]() ![]() |
Appendix B. Python Skeleton for Rapid Prototyping
| Listing A2. Lightweight Python class for hyper–dual arithmetic. |
![]() ![]() |
Appendix C. MATLAB Skeleton for Rapid Prototyping
Appendix C.1. Minimal Driver for Dense Hessians (MATLAB)
References
- Squire, W.; Trapp, G. Using Complex Variables to Estimate Derivatives of Real Functions. SIAM Rev. 1998, 40, 110–112. [Google Scholar] [CrossRef]
- Fornberg, B. Generation of Finite Difference Formulas on Arbitrarily Spaced Grids. Math. Comput. 1988, 51, 699–706. [Google Scholar] [CrossRef]
- Higham, N.J. Accuracy and Stability of Numerical Algorithms, 2nd ed.; SIAM: Philadelphia, PA, USA, 2002. [Google Scholar] [CrossRef]
- Goldberg, D. What Every Computer Scientist Should Know About Floating-Point Arithmetic. ACM Comput. Surv. 1991, 23, 5–48. [Google Scholar] [CrossRef]
- Nocedal, J.; Wright, S.J. Numerical Optimization; Springer: New York, NY, USA, 2006. [Google Scholar] [CrossRef]
- Giles, M.B.; Pierce, N.A. An Introduction to the Adjoint Approach to Design. Flow Turbul. Combust. 2000, 65, 393–415. [Google Scholar] [CrossRef]
- Griewank, A.; Walther, A. Evaluating Derivatives: Principles and Techniques of Algorithmic Differentiation, 2nd ed.; SIAM: Philadelphia, PA, USA, 2008. [Google Scholar] [CrossRef]
- Naumann, U. The Art of Differentiating Computer Programs: An Introduction to Algorithmic Differentiation; SIAM: Philadelphia, PA, USA, 2012. [Google Scholar] [CrossRef]
- Martins, J.R.R.A.; Hwang, J.T. Review and Unification of Methods for Computing Derivatives of Multidisciplinary Computational Models. AIAA J. 2013, 51, 2582–2599. [Google Scholar] [CrossRef]
- Baydin, A.G.; Pearlmutter, B.A.; Radul, A.A.; Siskind, J.M. Automatic Differentiation in Machine Learning: A Survey. J. Mach. Learn. Res. 2018, 18, 5595–5637. [Google Scholar]
- Kim, J.E. Multidual Complex Numbers and the Hyperholomorphicity of Multidual Complex-Valued Functions. Axioms 2025, 14, 683. [Google Scholar] [CrossRef]
- Neidinger, R.D. Introduction to Automatic Differentiation and MATLAB Object-Oriented Programming. SIAM Rev. 2010, 52, 545–563. [Google Scholar] [CrossRef]
- Fike, J.A.; Alonso, J.J. The Development of Hyper–Dual Numbers for Exact Second–Derivative Calculations. In Proceedings of the 49th AIAA Aerospace Sciences Meeting, Orlando, FL, USA, 4–7 January 2011. AIAA-2011-886. [Google Scholar] [CrossRef]
- Rehner, P.; Bauer, G. Application of Generalized (Hyper–) Dual Numbers in Thermodynamics. Front. Chem. Eng. 2021, 3, 758090. [Google Scholar] [CrossRef]
- Pearlmutter, B.A. Fast Exact Multiplication by the Hessian. Neural Comput. 1994, 6, 147–160. [Google Scholar] [CrossRef]
- Fike, J.A. Derivative Calculations Using Hyper-Dual Numbers; No. SAND2016-5252PE; Sandia National Lab.(SNL-NM): Albuquerque, NM, USA, 2016. [Google Scholar]
- Smola, F. Mechanizing Hyperdual Numbers in Isabelle/HOL. Master’s Thesis, University of Edinburgh, Edinburgh, UK, 2020. [Google Scholar]
- Martins, J.R.R.A.; Ning, A. Engineering Design Optimization; Cambridge University Press: Cambridge, UK, 2021. [Google Scholar] [CrossRef]



| Example Class | Dimension n | Analytic Hessian? | Purpose |
|---|---|---|---|
| Analytic scalar/bivariate tests | Yes | Validate exact coefficient readout; step invariance | |
| Rosenbrock/Beale/Himmelblau | 2 | Yes | Coupling, nonlinearity, benchmark comparability |
| Quadratic-oscillatory high-n | 10–200 | Yes | Scaling and ill-conditioning sensitivity |
| Stiff solver/structured residual | problem-dependent | Partial/reference | Real-path branching and black-box robustness |
| Noise & step-sensitivity sweeps | 1 (representative) | Yes | Quantify FD/CS U-shape vs. HD stability |
| Noise Level | Step h | FD (Central 2nd) | CS (2nd) | HD (Coef-Based) | |||
|---|---|---|---|---|---|---|---|
| (Sweep) | |||||||
| FD | CS | HD | ||||
|---|---|---|---|---|---|---|
| float32 | float64 | float32 | float64 | float32 | float64 | |
| Quantity | Real | Hyper-Dual |
|---|---|---|
| Scalar storage | 1 | 4 |
| Addition flops | 1 | 4 (componentwise) |
| Multiplication flops | 1 | ≈9 mult. + 5 add. |
| Array of size N | N reals | reals |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Park, S.B.; Kim, J.E. Hyper–Dual Numbers: A Theoretical Foundation for Exact Second Derivatives. Mathematics 2025, 13, 3909. https://doi.org/10.3390/math13243909
Park SB, Kim JE. Hyper–Dual Numbers: A Theoretical Foundation for Exact Second Derivatives. Mathematics. 2025; 13(24):3909. https://doi.org/10.3390/math13243909
Chicago/Turabian StylePark, Sung Bum, and Ji Eun Kim. 2025. "Hyper–Dual Numbers: A Theoretical Foundation for Exact Second Derivatives" Mathematics 13, no. 24: 3909. https://doi.org/10.3390/math13243909
APA StylePark, S. B., & Kim, J. E. (2025). Hyper–Dual Numbers: A Theoretical Foundation for Exact Second Derivatives. Mathematics, 13(24), 3909. https://doi.org/10.3390/math13243909





