Average Error: 35.5 → 7.9
Time: 32.3s
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 -2.8335922143007058 \cdot 10^{+135}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{if}\;b \le 2.4971715086460685 \cdot 10^{-08}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)} + \left(-b\right)}{a + a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot \frac{-2}{2}\\
\end{array}\]
Target
| Original | 35.5 |
| Comparison | 23.3 |
| Herbie | 7.9 |
\[ \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 3 regimes.
-
if b < -2.8335922143007058e+135
Initial program 54.7
\[\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 -2.8335922143007058e+135 < b < 2.4971715086460685e-08
Initial program 15.1
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm
Applied div-inv 15.3
\[\leadsto \color{blue}{\left(\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}}\]
Applied taylor 15.3
\[\leadsto \left(\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(c \cdot a\right)}\right) \cdot \frac{1}{2 \cdot a}\]
Taylor expanded around 0 15.3
\[\leadsto \left(\left(-b\right) + \sqrt{\color{blue}{{b}^2 - 4 \cdot \left(c \cdot a\right)}}\right) \cdot \frac{1}{2 \cdot a}\]
Applied simplify 15.2
\[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)} + \left(-b\right)}{a + a}}\]
if 2.4971715086460685e-08 < b
Initial program 58.3
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied taylor 15.4
\[\leadsto \frac{-2 \cdot \frac{c \cdot a}{b}}{2 \cdot a}\]
Taylor expanded around inf 15.4
\[\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 3 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie shell --seed '#(644180380 3784176976 401987740 22459203 1940947670 3323606534)'
(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)))