Average Error: 25.9 → 26.0
Time: 1.1m
Precision: 64
Internal Precision: 320
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
↓
\[\begin{array}{l}
\mathbf{if}\;d \le 2.287685333116204 \cdot 10^{+71}:\\
\;\;\;\;\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{if}\;d \le 2.6646868450529295 \cdot 10^{+148}:\\
\;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt[3]{a \cdot c + b \cdot d} \cdot \sqrt[3]{a \cdot c + b \cdot d}}{\sqrt[3]{c \cdot c + d \cdot d} \cdot \sqrt[3]{c \cdot c + d \cdot d}} \cdot \frac{\sqrt[3]{a \cdot c + b \cdot d}}{\sqrt[3]{c \cdot c + d \cdot d}}\\
\end{array}\]
Try it out
Enter valid numbers for all inputs
Target
| Original | 25.9 |
|---|
| Target | 0.5 |
|---|
| Herbie | 26.0 |
|---|
\[\begin{array}{l}
\mathbf{if}\;\left|d\right| \lt \left|c\right|:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}\]
Derivation
- Split input into 3 regimes
if d < 2.287685333116204e+71
Initial program 22.6
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
- Using strategy
rm Applied add-sqr-sqrt22.6
\[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
Applied associate-/r*22.5
\[\leadsto \color{blue}{\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}}\]
if 2.287685333116204e+71 < d < 2.6646868450529295e+148
Initial program 22.8
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
- Using strategy
rm Applied add-sqr-sqrt22.8
\[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
Applied associate-/r*22.6
\[\leadsto \color{blue}{\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}}\]
Taylor expanded around 0 25.2
\[\leadsto \frac{\color{blue}{b}}{\sqrt{c \cdot c + d \cdot d}}\]
if 2.6646868450529295e+148 < d
Initial program 46.4
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
- Using strategy
rm Applied add-cube-cbrt46.4
\[\leadsto \frac{a \cdot c + b \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 add-cube-cbrt46.4
\[\leadsto \frac{\color{blue}{\left(\sqrt[3]{a \cdot c + b \cdot d} \cdot \sqrt[3]{a \cdot c + b \cdot d}\right) \cdot \sqrt[3]{a \cdot c + b \cdot d}}}{\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-frac46.4
\[\leadsto \color{blue}{\frac{\sqrt[3]{a \cdot c + b \cdot d} \cdot \sqrt[3]{a \cdot c + b \cdot d}}{\sqrt[3]{c \cdot c + d \cdot d} \cdot \sqrt[3]{c \cdot c + d \cdot d}} \cdot \frac{\sqrt[3]{a \cdot c + b \cdot d}}{\sqrt[3]{c \cdot c + d \cdot d}}}\]
- Recombined 3 regimes into one program.
Runtime
herbie shell --seed 2019053
(FPCore (a b c d)
:name "Complex division, real part"
:herbie-target
(if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))