Skip to content

real, imag, conj for Hyper{<:Complex}; sincos for Hyper - #43

Open
rcalxrc08 wants to merge 1 commit into
JuliaDiff:masterfrom
rcalxrc08:real-imag-conj-sincos
Open

rcalxrc08 wants to merge 1 commit into
JuliaDiff:masterfrom
rcalxrc08:real-imag-conj-sincos

Conversation

@rcalxrc08

Copy link
Copy Markdown
Contributor

Closes #38.

  • real, imag, conj for Hyper{<:Complex}, applied to every part. A hyperdual with complex parts holds the value and the first and second derivatives of a complex function of real parameters: the ε₁ and ε₂ directions are real perturbations. These three maps are real-linear, so ∂(real f)/∂x = real(∂f/∂x), and the same for imag and conj. That they are not holomorphic in the complex argument does not matter here, because that is not what the ε parts differentiate. The comment that explained their absence is replaced by one on abs and angle, which stay undefined.
  • real and imag for Hyper{<:Real}: h and zero(h), so generic code that calls them works on real hyperduals too.
  • Base.sincos(h::Hyper): previously the generic fallback called sin and cos separately, each with its own sincos of the value. Now one sincos of the value gives both results, and the product b*c is shared. sin and cos are unchanged.

Tests in test/test_complex_parts.jl:

  • the parts of real, imag and conj;
  • real(h) + im*imag(h) == h;
  • a second derivative of real ∘ f for a complex f of a real argument, against finite differences;
  • sincos against the derivative formulas, on real and complex hyperduals.

The full suite passes locally (Julia 1.13).

Motivation: FinancialFFT.jl differentiates Fourier pricing methods generically over number types, and currently carries these overloads as hooks in its HyperDualNumbers extension.

🤖 Generated with Claude Code

real, imag and conj are real-linear, so they act on every part of a
hyperdual whose parts are complex (the derivatives of a complex function
of real parameters). real and imag of a real hyperdual are h and 0.
sincos computes sin and cos from one sincos of the value, sharing b*c.

Closes JuliaDiff#38.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add real (and imag)

1 participant