Average Error: 25.6 → 24.0
Time: 33.6s
Precision: 64
Internal Precision: 576
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
↓
\[\begin{array}{l}
\mathbf{if}\;b \le 2.176663814799802 \cdot 10^{+217}:\\
\;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - a \cdot \frac{d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\\
\end{array}\]
Target
| Original | 25.6 |
|---|
| Target | 0.4 |
|---|
| Herbie | 24.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 b < 2.176663814799802e+217
Initial program 24.6
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
- Using strategy
rm Applied div-sub24.6
\[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}\]
- Using strategy
rm Applied *-un-lft-identity24.6
\[\leadsto \frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{\color{blue}{1 \cdot \left(c \cdot c + d \cdot d\right)}}\]
Applied times-frac23.3
\[\leadsto \frac{b \cdot c}{c \cdot c + d \cdot d} - \color{blue}{\frac{a}{1} \cdot \frac{d}{c \cdot c + d \cdot d}}\]
Applied simplify23.3
\[\leadsto \frac{b \cdot c}{c \cdot c + d \cdot d} - \color{blue}{a} \cdot \frac{d}{c \cdot c + d \cdot d}\]
if 2.176663814799802e+217 < b
Initial program 40.8
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
- Using strategy
rm Applied div-sub40.8
\[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}\]
- Using strategy
rm Applied add-sqr-sqrt40.8
\[\leadsto \frac{b \cdot c}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
Applied times-frac33.3
\[\leadsto \color{blue}{\frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed '#(1071725047 233389029 2036512464 3988615230 2972226563 1111574017)'
(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))))