Average Error: 34.2 → 5.4
Time: 28.9s
Precision: 64
Internal precision: 2944
\[\frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
⬇
\[\begin{array}{l}
\mathbf{if}\;b \le -1.718982199476945 \cdot 10^{+89}:\\
\;\;\;\;\frac{\left(-b\right) + b}{a + a} - \frac{c}{b}\\
\mathbf{if}\;b \le -2.321564696919607 \cdot 10^{-245}:\\
\;\;\;\;{\left(\sqrt[3]{\frac{\frac{1}{2} \cdot \left(c \cdot 4\right)}{{\left(\sqrt[3]{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}\right)}^3 + \left(-b\right)}}\right)}^3\\
\mathbf{if}\;b \le 9.141549925217606 \cdot 10^{+73}:\\
\;\;\;\;\frac{-b}{2 \cdot a} - \frac{\sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}\]
Target
| Original | 34.2 |
| Comparison | 22.3 |
| Herbie | 5.4 |
\[ \begin{array}{l}
\mathbf{if}\;b \lt 0:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\end{array} \]
Derivation
- Split input into 4 regimes.
-
if b < -1.718982199476945e+89
Initial program 59.4
\[\frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied taylor 41.9
\[\leadsto \frac{\left(-b\right) - \left(2 \cdot \frac{c \cdot a}{b} - b\right)}{2 \cdot a}\]
Taylor expanded around -inf 41.9
\[\leadsto \frac{\left(-b\right) - \color{blue}{\left(2 \cdot \frac{c \cdot a}{b} - b\right)}}{2 \cdot a}\]
Applied simplify 0
\[\leadsto \color{blue}{\frac{\left(-b\right) + b}{a + a} - \frac{\frac{c}{b}}{1}}\]
Applied simplify 0
\[\leadsto \frac{\left(-b\right) + b}{a + a} - \color{blue}{\frac{c}{b}}\]
if -1.718982199476945e+89 < b < -2.321564696919607e-245
Initial program 33.7
\[\frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm
Applied flip-- 33.8
\[\leadsto \frac{\color{blue}{\frac{{\left(-b\right)}^2 - {\left(\sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}\right)}^2}{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
Applied simplify 17.2
\[\leadsto \frac{\frac{\color{blue}{a \cdot \left(4 \cdot c\right)}}{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
- Using strategy
rm
Applied add-cube-cbrt 17.9
\[\leadsto \color{blue}{{\left(\sqrt[3]{\frac{\frac{a \cdot \left(4 \cdot c\right)}{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}}\right)}^3}\]
Applied simplify 9.4
\[\leadsto {\color{blue}{\left(\sqrt[3]{\frac{\frac{1}{2} \cdot \left(c \cdot 4\right)}{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} + \left(-b\right)}}\right)}}^3\]
- Using strategy
rm
Applied add-cube-cbrt 9.5
\[\leadsto {\left(\sqrt[3]{\frac{\frac{1}{2} \cdot \left(c \cdot 4\right)}{\color{blue}{{\left(\sqrt[3]{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}\right)}^3} + \left(-b\right)}}\right)}^3\]
if -2.321564696919607e-245 < b < 9.141549925217606e+73
Initial program 9.7
\[\frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm
Applied div-sub 9.7
\[\leadsto \color{blue}{\frac{-b}{2 \cdot a} - \frac{\sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\]
if 9.141549925217606e+73 < b
Initial program 42.2
\[\frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied taylor 10.8
\[\leadsto \frac{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}{2 \cdot a}\]
Taylor expanded around inf 10.8
\[\leadsto \frac{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}{2 \cdot a}\]
Applied simplify 0.0
\[\leadsto \color{blue}{\frac{\frac{c}{b}}{1} - \frac{b}{a}}\]
Applied simplify 0.0
\[\leadsto \color{blue}{\frac{c}{b}} - \frac{b}{a}\]
- Recombined 4 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie shell --seed '#(1064524629 4159152179 2999149171 575749698 4006532819 692958815)'
(FPCore (a b c)
:name "The quadratic formula (r2)"
:target
(if (< b 0) (/ c (* a (/ (+ (- b) (sqrt (- (sqr b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (sqr b) (* 4 (* a c))))) (* 2 a)))
(/ (- (- b) (sqrt (- (sqr b) (* 4 (* a c))))) (* 2 a)))