Average Error: 34.3 → 7.0
Time: 18.7s
Precision: 64
Internal precision: 1920
\[\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.278271000091618 \cdot 10^{+41}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{if}\;b \le 4.8000916602446076 \cdot 10^{-307}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\mathbf{if}\;b \le 3.098493351351191 \cdot 10^{+149}:\\
\;\;\;\;\frac{\frac{a}{1} \cdot \frac{4 \cdot c}{\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 | 34.3 |
| Comparison | 22.0 |
| Herbie | 7.0 |
\[ \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.278271000091618e+41
Initial program 40.3
\[\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.278271000091618e+41 < b < 4.8000916602446076e-307
Initial program 8.9
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
if 4.8000916602446076e-307 < b < 3.098493351351191e+149
Initial program 34.0
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm
Applied flip-+ 34.2
\[\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.9
\[\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}\]
- Using strategy
rm
Applied *-un-lft-identity 15.9
\[\leadsto \frac{\frac{a \cdot \left(4 \cdot c\right)}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}\right)}}}{2 \cdot a}\]
Applied times-frac 13.8
\[\leadsto \frac{\color{blue}{\frac{a}{1} \cdot \frac{4 \cdot c}{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
if 3.098493351351191e+149 < b
Initial program 62.3
\[\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 '#(1066785882 2324371342 4059510649 1466361199 2701357084 1216585281)'
(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)))