Average Error: 24.7 → 23.3
Time: 26.0s
Precision: 64
Internal Precision: 384
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
↓
\[\begin{array}{l}
\mathbf{if}\;a \le -4.853005009166494 \cdot 10^{-283}:\\
\;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a}{1} \cdot \frac{d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;a \le 4.9595495246039594 \cdot 10^{+63}:\\
\;\;\;\;\frac{b}{\sqrt[3]{c \cdot c + d \cdot d} \cdot \sqrt[3]{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt[3]{c \cdot c + d \cdot d}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;a \le +\infty:\\
\;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}\]
Target
| Original | 24.7 |
|---|
| Target | 0.4 |
|---|
| Herbie | 23.3 |
|---|
\[\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 a < -4.853005009166494e-283
Initial program 24.8
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
- Using strategy
rm Applied div-sub24.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 *-un-lft-identity24.8
\[\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}}\]
if -4.853005009166494e-283 < a < 4.9595495246039594e+63
Initial program 19.8
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
- Using strategy
rm Applied div-sub19.9
\[\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-cube-cbrt20.2
\[\leadsto \frac{b \cdot c}{\color{blue}{\left(\sqrt[3]{c \cdot c + d \cdot d} \cdot \sqrt[3]{c \cdot c + d \cdot d}\right) \cdot \sqrt[3]{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
Applied times-frac19.4
\[\leadsto \color{blue}{\frac{b}{\sqrt[3]{c \cdot c + d \cdot d} \cdot \sqrt[3]{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt[3]{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
if 4.9595495246039594e+63 < a
Initial program 32.7
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
- Using strategy
rm Applied div-sub32.7
\[\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-sqrt32.7
\[\leadsto \frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
Applied times-frac29.7
\[\leadsto \frac{b \cdot c}{c \cdot c + d \cdot d} - \color{blue}{\frac{a}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}}\]
- Recombined 3 regimes into one program.
Runtime
herbie shell --seed '#(1070131407 1246090267 3027482374 2150728003 2026520792 2347815650)'
(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))))