Average Error: 37.0 → 5.7
Time: 23.4s
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 -3.460964309611288 \cdot 10^{+19}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{if}\;b \le 5.3630996565742086 \cdot 10^{-235}:\\
\;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}\\
\mathbf{if}\;b \le 1.6164635363498484 \cdot 10^{-18}:\\
\;\;\;\;\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}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot \frac{-2}{2}\\
\end{array}\]
Target
| Original | 37.0 |
| Comparison | 24.8 |
| Herbie | 5.7 |
\[ \begin{array}{l}
\mathbf{if}\;b \lt 0:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \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 < -3.460964309611288e+19
Initial program 37.7
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied taylor 10.0
\[\leadsto \frac{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}{2 \cdot a}\]
Taylor expanded around -inf 10.0
\[\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}\]
if -3.460964309611288e+19 < b < 5.3630996565742086e-235
Initial program 11.7
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm
Applied clear-num 11.8
\[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}}\]
if 5.3630996565742086e-235 < b < 1.6164635363498484e-18
Initial program 26.8
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm
Applied flip-+ 26.9
\[\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 19.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}\]
if 1.6164635363498484e-18 < b
Initial program 57.9
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied taylor 15.2
\[\leadsto \frac{-2 \cdot \frac{c \cdot a}{b}}{2 \cdot a}\]
Taylor expanded around inf 15.2
\[\leadsto \frac{\color{blue}{-2 \cdot \frac{c \cdot a}{b}}}{2 \cdot a}\]
Applied simplify 0
\[\leadsto \color{blue}{\frac{c}{b} \cdot \frac{-2}{2}}\]
- Recombined 4 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie shell --seed '#(1064555532 179913862 452496668 2441903500 287849034 462453547)'
(FPCore (a b c)
:name "quadp (p42, positive)"
:target
(if (< b 0) (/ (+ (- b) (sqrt (- (sqr b) (* 4 (* a c))))) (* 2 a)) (/ c (* a (/ (- (- b) (sqrt (- (sqr b) (* 4 (* a c))))) (* 2 a)))))
(/ (+ (- b) (sqrt (- (sqr b) (* 4 (* a c))))) (* 2 a)))