Average Error: 33.7 → 10.9
Time: 1.4m
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 -31555227915007636.0:\\
\;\;\;\;\frac{\left(-b\right) + b}{a + a} - \frac{\frac{c}{b}}{1}\\
\mathbf{if}\;b \le -4.544793631242834 \cdot 10^{-44}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a + a}\\
\mathbf{if}\;b \le -1.4045035563575462 \cdot 10^{-80}:\\
\;\;\;\;\frac{\left(-b\right) + b}{a + a} - \frac{\frac{c}{b}}{1}\\
\mathbf{if}\;b \le 2.7862180157814046 \cdot 10^{+101}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a + a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c}{b}}{1} - \frac{b}{a}\\
\end{array}\]
Target
| Original | 33.7 |
|---|
| Target | 20.4 |
|---|
| Herbie | 10.9 |
|---|
\[\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 4 regimes
if b < -31555227915007636.0 or -4.544793631242834e-44 < b < -1.4045035563575462e-80
Initial program 54.3
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around -inf 45.1
\[\leadsto \frac{\left(-b\right) - \color{blue}{\left(2 \cdot \frac{c \cdot a}{b} - b\right)}}{2 \cdot a}\]
Applied simplify7.2
\[\leadsto \color{blue}{\frac{\left(-b\right) + b}{a + a} - \frac{\frac{c}{b}}{1}}\]
if -31555227915007636.0 < b < -4.544793631242834e-44
Initial program 44.6
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied clear-num44.7
\[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
Taylor expanded around 0 44.7
\[\leadsto \frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{\color{blue}{{b}^{2} - 4 \cdot \left(c \cdot a\right)}}}}\]
Applied simplify44.6
\[\leadsto \color{blue}{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a + a}}\]
if -1.4045035563575462e-80 < b < 2.7862180157814046e+101
Initial program 12.4
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied clear-num12.6
\[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
Taylor expanded around 0 12.6
\[\leadsto \frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{\color{blue}{{b}^{2} - 4 \cdot \left(c \cdot a\right)}}}}\]
Applied simplify12.4
\[\leadsto \color{blue}{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a + a}}\]
if 2.7862180157814046e+101 < b
Initial program 44.4
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around inf 10.3
\[\leadsto \frac{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}{2 \cdot a}\]
Applied simplify4.0
\[\leadsto \color{blue}{\frac{\frac{c}{b}}{1} - \frac{b}{a}}\]
- Recombined 4 regimes into one program.
Runtime
herbie shell --seed '#(1064397287 3527694221 3797617954 1138343853 2854031332 1153838279)'
(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)))