Average Error: 33.6 → 10.1
Time: 2.7m
Precision: 64
Internal Precision: 3200
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
↓
\[\begin{array}{l}
\mathbf{if}\;b \le -6.885163307120034 \cdot 10^{-42}:\\
\;\;\;\;\frac{-c}{\frac{b}{1}}\\
\mathbf{if}\;b \le 7.271467974516448 \cdot 10^{+121}:\\
\;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}\]
Target
| Original | 33.6 |
|---|
| Target | 20.9 |
|---|
| Herbie | 10.1 |
|---|
\[\begin{array}{l}
\mathbf{if}\;b \lt 0:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\end{array}\]
Derivation
- Split input into 3 regimes
if b < -6.885163307120034e-42
Initial program 54.2
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around -inf 46.8
\[\leadsto \frac{\left(-b\right) - \color{blue}{\left(2 \cdot \frac{c \cdot a}{b} - b\right)}}{2 \cdot a}\]
Applied simplify7.3
\[\leadsto \color{blue}{\frac{-c}{\frac{b}{1}}}\]
if -6.885163307120034e-42 < b < 7.271467974516448e+121
Initial program 14.0
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied clear-num14.2
\[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
if 7.271467974516448e+121 < b
Initial program 49.8
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around inf 2.7
\[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
Applied simplify2.7
\[\leadsto \color{blue}{\frac{-b}{a}}\]
- Recombined 3 regimes into one program.
Runtime
herbie shell --seed '#(1070609872 3456127585 2380521889 2328837196 1765472538 734540918)' +o rules:numerics
(FPCore (a b c)
:name "The quadratic formula (r2)"
:herbie-target
(if (< b 0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))