Average Error: 37.4 → 5.4
Time: 17.0s
Precision: 64
Internal precision: 2176
\[\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.0713433718164824 \cdot 10^{+85}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{if}\;b \le 6.611638496230363 \cdot 10^{-143}:\\
\;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}\\
\mathbf{if}\;b \le 2.353344202188118 \cdot 10^{-100}:\\
\;\;\;\;\frac{c}{b} \cdot \frac{-2}{2}\\
\mathbf{if}\;b \le 4.3383085193935005 \cdot 10^{-09}:\\
\;\;\;\;\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.4 |
| Comparison | 25.4 |
| Herbie | 5.4 |
\[ \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.0713433718164824e+85
Initial program 44.5
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied taylor 11.5
\[\leadsto \frac{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}{2 \cdot a}\]
Taylor expanded around -inf 11.5
\[\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.0713433718164824e+85 < b < 6.611638496230363e-143
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 clear-num 11.7
\[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}}\]
if 6.611638496230363e-143 < b < 2.353344202188118e-100 or 4.3383085193935005e-09 < b
Initial program 58.4
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied taylor 15.6
\[\leadsto \frac{-2 \cdot \frac{c \cdot a}{b}}{2 \cdot a}\]
Taylor expanded around inf 15.6
\[\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}}\]
if 2.353344202188118e-100 < b < 4.3383085193935005e-09
Initial program 37.3
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm
Applied flip-+ 37.4
\[\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 16.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}\]
- Recombined 4 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie shell --seed '#(1067773715 2765207660 218871639 3688798924 2755544087 2054563380)'
(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)))