Average Error: 25.9 → 25.0
Time: 1.2m
Precision: 64
Internal Precision: 576
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
↓
\[\begin{array}{l}
\mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \le -3.607046218183898 \cdot 10^{+307}:\\
\;\;\;\;\frac{-b}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \le 6.205643929172327 \cdot 10^{+293}:\\
\;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{\sqrt{d \cdot d + c \cdot c}}\\
\end{array}\]
Try it out
Enter valid numbers for all inputs
Target
| Original | 25.9 |
|---|
| Target | 0.4 |
|---|
| Herbie | 25.0 |
|---|
\[\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 3 regimes
if (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) < -3.607046218183898e+307
Initial program 60.6
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
- Using strategy
rm Applied add-sqr-sqrt60.6
\[\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*60.6
\[\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 52.7
\[\leadsto \frac{\color{blue}{-1 \cdot b}}{\sqrt{c \cdot c + d \cdot d}}\]
Applied simplify52.7
\[\leadsto \color{blue}{\frac{-b}{\sqrt{c \cdot c + d \cdot d}}}\]
if -3.607046218183898e+307 < (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) < 6.205643929172327e+293
Initial program 11.4
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
- Using strategy
rm Applied add-sqr-sqrt11.4
\[\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*11.3
\[\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}}}\]
if 6.205643929172327e+293 < (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
Initial program 61.9
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
- Using strategy
rm Applied add-sqr-sqrt61.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*61.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 0 62.5
\[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\color{blue}{d}}\]
Applied simplify60.1
\[\leadsto \color{blue}{\frac{c \cdot \frac{b}{d} - a}{\sqrt{d \cdot d + c \cdot c}}}\]
- Recombined 3 regimes into one program.
Runtime
herbie shell --seed 2018201
(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))))