Average Error: 33.8 → 10.4
Time: 2.1m
Precision: 64
Internal Precision: 3456
\[\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.8467051498896273 \cdot 10^{+80}:\\
\;\;\;\;\frac{c}{b} \cdot \frac{-2}{2}\\
\mathbf{if}\;b \le -6.8370322578253936 \cdot 10^{-105}:\\
\;\;\;\;\frac{c}{b} \cdot \frac{-2}{2}\\
\mathbf{if}\;b \le 2.739372012628897 \cdot 10^{+83}:\\
\;\;\;\;\frac{(\left(\sqrt[3]{-b} \cdot \sqrt[3]{-b}\right) \cdot \left(\sqrt[3]{-b}\right) + \left(-\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right))_*}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;(\left(\frac{1}{a + a}\right) \cdot \left(\left(-b\right) - b\right) + \left(\frac{c}{b}\right))_*\\
\end{array}\]
Target
| Original | 33.8 |
|---|
| Target | 21.0 |
|---|
| Herbie | 10.4 |
|---|
\[\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 < -1.8467051498896273e+80
Initial program 57.9
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around -inf 14.8
\[\leadsto \frac{\color{blue}{-2 \cdot \frac{c \cdot a}{b}}}{2 \cdot a}\]
Applied simplify2.9
\[\leadsto \color{blue}{\frac{c}{b} \cdot \frac{-2}{2}}\]
if -1.8467051498896273e+80 < b < -6.8370322578253936e-105
Initial program 41.5
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around -inf 31.8
\[\leadsto \frac{\color{blue}{-2 \cdot \frac{c \cdot a}{b}}}{2 \cdot a}\]
Applied simplify21.9
\[\leadsto \color{blue}{\frac{c}{b} \cdot \frac{-2}{2}}\]
if -6.8370322578253936e-105 < b < 2.739372012628897e+83
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 add-cube-cbrt12.6
\[\leadsto \frac{\color{blue}{\left(\sqrt[3]{-b} \cdot \sqrt[3]{-b}\right) \cdot \sqrt[3]{-b}} - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied fma-neg12.6
\[\leadsto \frac{\color{blue}{(\left(\sqrt[3]{-b} \cdot \sqrt[3]{-b}\right) \cdot \left(\sqrt[3]{-b}\right) + \left(-\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right))_*}}{2 \cdot a}\]
if 2.739372012628897e+83 < b
Initial program 42.3
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied clear-num42.3
\[\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 inf 11.3
\[\leadsto \frac{1}{\frac{2 \cdot a}{\left(-b\right) - \color{blue}{\left(b - 2 \cdot \frac{c \cdot a}{b}\right)}}}\]
Applied simplify5.5
\[\leadsto \color{blue}{(\left(\frac{1}{a + a}\right) \cdot \left(\left(-b\right) - b\right) + \left(\frac{c}{b}\right))_*}\]
- Recombined 4 regimes into one program.
Runtime
herbie shell --seed '#(1064300848 3212030778 2049303162 3567222883 2277747821 1384278011)' +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)))