Average Error: 25.7 → 18.1
Time: 1.0m
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 -8.782063150292355 \cdot 10^{+66}:\\
\;\;\;\;\frac{b}{c} - \frac{d \cdot a}{{c}^{2}}\\
\mathbf{if}\;c \le 2.1671779352292058 \cdot 10^{+42}:\\
\;\;\;\;\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{b}{c} - \frac{d \cdot a}{{c}^{2}}\\
\end{array}\]
Target
| Original | 25.7 |
|---|
| Target | 0.5 |
|---|
| Herbie | 18.1 |
|---|
\[\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 < -8.782063150292355e+66 or 2.1671779352292058e+42 < c
Initial program 35.2
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
- Using strategy
rm Applied add-cube-cbrt35.4
\[\leadsto \frac{b \cdot c - a \cdot d}{\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}}}\]
Applied *-un-lft-identity35.4
\[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\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}}\]
Applied times-frac35.4
\[\leadsto \color{blue}{\frac{1}{\sqrt[3]{c \cdot c + d \cdot d} \cdot \sqrt[3]{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt[3]{c \cdot c + d \cdot d}}}\]
Taylor expanded around inf 17.9
\[\leadsto \color{blue}{\frac{b}{c} - \frac{d \cdot a}{{c}^{2}}}\]
if -8.782063150292355e+66 < c < 2.1671779352292058e+42
Initial program 18.3
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
- Using strategy
rm Applied add-sqr-sqrt18.3
\[\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*18.2
\[\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}}}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed '#(1070833653 108281690 3330367898 3632331308 3494323072 43156186)'
(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))))