Average Error: 33.9 → 8.2
Time: 20.5s
Precision: 64
Internal precision: 3200
\[\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.6651045154090737 \cdot 10^{+129}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{if}\;b \le 1.2279524673465372 \cdot 10^{-126}:\\
\;\;\;\;\left(\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}\\
\mathbf{if}\;b \le 4.513700515120415 \cdot 10^{+116}:\\
\;\;\;\;\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 | 33.9 |
| Comparison | 21.1 |
| Herbie | 8.2 |
\[ \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 < -2.6651045154090737e+129
Initial program 53.4
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied taylor 11.6
\[\leadsto \frac{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}{2 \cdot a}\]
Taylor expanded around -inf 11.6
\[\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 -2.6651045154090737e+129 < b < 1.2279524673465372e-126
Initial program 11.6
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm
Applied div-inv 11.7
\[\leadsto \color{blue}{\left(\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}}\]
if 1.2279524673465372e-126 < b < 4.513700515120415e+116
Initial program 39.8
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm
Applied flip-+ 39.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 15.1
\[\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 4.513700515120415e+116 < b
Initial program 60.6
\[\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 4 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie shell --seed '#(1065033997 2389885643 4100569014 2620012693 26800780 3144211646)'
(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)))