Average Error: 26.0 → 25.6
Time: 1.1m
Precision: 64
Internal Precision: 384
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
↓
\[\begin{array}{l}
\mathbf{if}\;c \le 9.444001219615834 \cdot 10^{+44}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{\sqrt{d \cdot d + c \cdot c}}\\
\end{array}\]
Target
| Original | 26.0 |
|---|
| Target | 0.5 |
|---|
| Herbie | 25.6 |
|---|
\[\begin{array}{l}
\mathbf{if}\;\left|d\right| \lt \left|c\right|:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}\]
Derivation
- Split input into 2 regimes
if c < 9.444001219615834e+44
Initial program 23.1
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
if 9.444001219615834e+44 < c
Initial program 35.9
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
- Using strategy
rm Applied add-sqr-sqrt35.9
\[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
Applied associate-/r*35.9
\[\leadsto \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}}\]
Taylor expanded around inf 37.6
\[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\color{blue}{c}}\]
Applied simplify34.1
\[\leadsto \color{blue}{\frac{b - a \cdot \frac{d}{c}}{\sqrt{d \cdot d + c \cdot c}}}\]
- Recombined 2 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1063282112 2455465480 4141627379 3773598652 1647277307 776739644)'
(FPCore (a b c d)
:name "Complex division, imag part"
:herbie-target
(if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))