elementary design
This page explains the elementary facade: which analytic traits it
exposes, how their derivative rules are justified, and where they stop.
Design goal
Make analytic code written against the arithmetic traits differentiable
without change, by exposing exactly the traits that Dual[T] implements
with a correct derivative rule.
Mathematical background
Every rule has the form (the dual design derives the chain rule from it). The derivatives used are the classical ones; for the inverse-function and base-change cases they follow from the chain rule:
Each formula holds on the open domain where is differentiable: for the square root and the logarithms, for the tangent, and everywhere for , and .
Design decisions
Expose what Dual[T] implements
The facade re-exports Sqrt, SqrtChecked, Exponential, Logarithmic,
Trigonometric and Constants, the analytic traits with an instance on
Dual[T]. arithmetic also defines Hyperbolic, InverseTrigonometric,
InverseHyperbolic, Cbrt and Power; Dual[T] has no instance for them
yet, so they are not re-exported.
Instances need the whole trait
A trait instance must provide all its methods. Exponential contains
exp2, whose rule needs , so the instance needs Logarithmic and
IntegralHomomorphism on T even if a caller only uses exp. The inherent
method Dual::exp has the smaller bound Exponential + Mul for that case.
Constants have tangent zero
, and do not depend on the differentiation variable, so the
Constants instance embeds them with Dual::constant. This is the
structure-preserving choice: the map , , is a ring homomorphism.
Correctness and invariants
- Each rule matches the derivative table above and is tested on
Double(sin,expand others insrc/tests/dual_test.mbt). - Outside the open domain, the result follows
T: forDouble,ln(0)is with tangent , andsqrtat has an infinite or NaN tangent. - The tangent error is the error of
T’s implementation of plus at most two roundings; see the dual design.
Alternatives rejected
- Re-exporting every analytic trait. Bounds such as
T : Hyperbolicwould type-check forTbut fail to instantiate atDual[T], which is confusing. - Checked logarithms in this repository.
arithmetichas no checked logarithm trait to implement; adding one locally would fork the error model.
Boundaries
- No hyperbolic, inverse trigonometric, inverse hyperbolic, cube-root or general power rules.
- No checked forms other than
SqrtChecked. - No branch-cut or complex-domain semantics; see luna-complex for complex functions.