Average Error: 33.2 → 10.1
Time: 2.6m
Precision: 64
Internal Precision: 3456
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
↓
\[\begin{array}{l}
\mathbf{if}\;b \le -4.1387147105899953 \cdot 10^{+136}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{if}\;b \le 1.056111401872344 \cdot 10^{-129}:\\
\;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{4}{\frac{2}{c}}}{\frac{a}{b} \cdot \left(c + c\right) + \left(\left(-b\right) - b\right)}\\
\end{array}\]
Target
| Original | 33.2 |
|---|
| Target | 20.3 |
|---|
| Herbie | 10.1 |
|---|
\[\begin{array}{l}
\mathbf{if}\;b \lt 0:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\
\end{array}\]
Derivation
- Split input into 3 regimes
if b < -4.1387147105899953e+136
Initial program 55.1
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{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}}\]
if -4.1387147105899953e+136 < b < 1.056111401872344e-129
Initial program 10.6
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
- Using strategy
rm Applied clear-num10.8
\[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\]
if 1.056111401872344e-129 < b
Initial program 50.6
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
- Using strategy
rm Applied flip-+50.7
\[\leadsto \frac{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{2 \cdot a}\]
Applied simplify24.2
\[\leadsto \frac{\frac{\color{blue}{4 \cdot \left(a \cdot c\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
Taylor expanded around inf 22.0
\[\leadsto \frac{\frac{4 \cdot \left(a \cdot c\right)}{\left(-b\right) - \color{blue}{\left(b - 2 \cdot \frac{c \cdot a}{b}\right)}}}{2 \cdot a}\]
Applied simplify11.4
\[\leadsto \color{blue}{\frac{\frac{4}{2} \cdot \left(1 \cdot c\right)}{\frac{a}{b} \cdot \left(c + c\right) + \left(\left(-b\right) - b\right)}}\]
Applied simplify11.5
\[\leadsto \frac{\color{blue}{\frac{4}{\frac{2}{c}}}}{\frac{a}{b} \cdot \left(c + c\right) + \left(\left(-b\right) - b\right)}\]
- Recombined 3 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1063185673 2139736501 2393378123 1907444849 1070993796 1007244912)'
(FPCore (a b c)
:name "The quadratic formula (r1)"
:herbie-target
(if (< b 0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))