Average Error: 25.9 → 26.0
Time: 48.5s
Precision: 64
Internal Precision: 384
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
↓
\[\begin{array}{l}
\mathbf{if}\;d \le 4.5667974641861144 \cdot 10^{+70}:\\
\;\;\;\;\frac{\frac{c \cdot b - a \cdot d}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\\
\end{array}\]
Target
| Original | 25.9 |
|---|
| Target | 0.5 |
|---|
| Herbie | 26.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 2 regimes
if d < 4.5667974641861144e+70
Initial program 23.0
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
Applied simplify23.0
\[\leadsto \color{blue}{\frac{c \cdot b - a \cdot d}{(d \cdot d + \left(c \cdot c\right))_*}}\]
- Using strategy
rm Applied add-sqr-sqrt23.0
\[\leadsto \frac{c \cdot b - a \cdot d}{\color{blue}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*} \cdot \sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
Applied associate-/r*23.0
\[\leadsto \color{blue}{\frac{\frac{c \cdot b - a \cdot d}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
if 4.5667974641861144e+70 < d
Initial program 36.9
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
Applied simplify36.9
\[\leadsto \color{blue}{\frac{c \cdot b - a \cdot d}{(d \cdot d + \left(c \cdot c\right))_*}}\]
- Using strategy
rm Applied add-sqr-sqrt36.9
\[\leadsto \frac{c \cdot b - a \cdot d}{\color{blue}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*} \cdot \sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
Applied associate-/r*36.9
\[\leadsto \color{blue}{\frac{\frac{c \cdot b - a \cdot d}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
Taylor expanded around 0 37.6
\[\leadsto \frac{\color{blue}{-1 \cdot a}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]
Applied simplify37.6
\[\leadsto \color{blue}{\frac{-a}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed '#(1070355188 2193211668 3977393919 3454156579 3755371326 1656365382)' +o rules:numerics
(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))))