Average Error: 34.7 → 5.1
Time: 22.2s
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 -8.631899346984487 \cdot 10^{+78}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{if}\;b \le 2.0911561750607134 \cdot 10^{-260}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\mathbf{if}\;b \le 3.356118893853414 \cdot 10^{+78}:\\
\;\;\;\;\frac{1}{\frac{\frac{2}{1}}{c \cdot 4} \cdot \left(\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot \frac{-2}{2}\\
\end{array}\]
Target
| Original | 34.7 |
| Comparison | 21.8 |
| Herbie | 5.1 |
\[ \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 < -8.631899346984487e+78
Initial program 42.9
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied taylor 0
\[\leadsto -1 \cdot \frac{b}{a}\]
Taylor expanded around -inf 0
\[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
Applied simplify 0
\[\leadsto \color{blue}{\frac{-b}{a}}\]
if -8.631899346984487e+78 < b < 2.0911561750607134e-260
Initial program 9.5
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
if 2.0911561750607134e-260 < b < 3.356118893853414e+78
Initial program 33.1
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm
Applied clear-num 33.1
\[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}}\]
- Using strategy
rm
Applied flip-+ 33.2
\[\leadsto \frac{1}{\frac{2 \cdot a}{\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)}}}}}\]
Applied associate-/r/ 33.3
\[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{{\left(-b\right)}^2 - {\left(\sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}\right)}^2} \cdot \left(\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}\right)}}\]
Applied simplify 8.9
\[\leadsto \frac{1}{\color{blue}{\frac{\frac{a + a}{a}}{c \cdot 4}} \cdot \left(\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}\right)}\]
Applied simplify 8.9
\[\leadsto \frac{1}{\frac{\color{blue}{\frac{2}{1}}}{c \cdot 4} \cdot \left(\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}\right)}\]
if 3.356118893853414e+78 < b
Initial program 58.7
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied taylor 14.7
\[\leadsto \frac{-2 \cdot \frac{c \cdot a}{b}}{2 \cdot a}\]
Taylor expanded around inf 14.7
\[\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 '#(1064875752 1442698706 3150723005 1316518582 2592983078 3835530843)'
(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)))