Average Error: 38.1 → 6.1
Time: 3.5m
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 -1.2837720874309055 \cdot 10^{-105}:\\
\;\;\;\;\frac{\frac{4 \cdot c}{\left(\left(-b\right) - b\right) + \frac{a}{b} \cdot \left(c + c\right)}}{2}\\
\mathbf{if}\;b \le 1.1498155483847317 \cdot 10^{+81}:\\
\;\;\;\;\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}\]
Target
| Original | 38.1 |
|---|
| Target | 25.7 |
|---|
| Herbie | 6.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 < -1.2837720874309055e-105
Initial program 58.7
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied flip--58.7
\[\leadsto \frac{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
Applied simplify35.5
\[\leadsto \frac{\frac{\color{blue}{\left(c \cdot a\right) \cdot 4}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
Taylor expanded around -inf 15.7
\[\leadsto \frac{\frac{\left(c \cdot a\right) \cdot 4}{\left(-b\right) + \color{blue}{\left(2 \cdot \frac{c \cdot a}{b} - b\right)}}}{2 \cdot a}\]
Applied simplify3.9
\[\leadsto \color{blue}{\frac{\frac{4 \cdot c}{\left(\left(-b\right) - b\right) + \frac{a}{b} \cdot \left(c + c\right)}}{2}}\]
if -1.2837720874309055e-105 < b < 1.1498155483847317e+81
Initial program 11.4
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied div-inv11.5
\[\leadsto \color{blue}{\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}}\]
if 1.1498155483847317e+81 < b
Initial program 43.9
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around inf 0
\[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
Applied simplify0
\[\leadsto \color{blue}{\frac{-b}{a}}\]
- Recombined 3 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1063027428 1192549564 1443466578 604016274 3637110559 1698629644)'
(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)))