Average Error: 25.8 → 25.4
Time: 41.3s
Precision: 64
Internal Precision: 320
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
↓
\[\begin{array}{l}
\mathbf{if}\;c \le 5.800850945630825 \cdot 10^{+42}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{\sqrt{d \cdot d + c \cdot c}}\\
\end{array}\]
Target
| Original | 25.8 |
|---|
| Target | 0.5 |
|---|
| Herbie | 25.4 |
|---|
\[\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 < 5.800850945630825e+42
Initial program 22.8
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
if 5.800850945630825e+42 < c
Initial program 36.2
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
- Using strategy
rm Applied add-sqr-sqrt36.2
\[\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 *-un-lft-identity36.2
\[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}\]
Applied times-frac36.2
\[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}\]
Taylor expanded around inf 37.7
\[\leadsto \frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{c}}\]
Applied simplify34.3
\[\leadsto \color{blue}{\frac{b - d \cdot \frac{a}{c}}{\sqrt{d \cdot d + c \cdot c}}}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed '#(1071215679 2002590028 935158157 1944352234 2656991306 2955288481)'
(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))))