Average Error: 34.3 → 7.3
Time: 43.6s
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 -1.6984829603276024 \cdot 10^{+97}:\\
\;\;\;\;\frac{\left(-b\right) + b}{a + a} - \frac{c}{b}\\
\mathbf{if}\;b \le -2.1555069951410637 \cdot 10^{-127}:\\
\;\;\;\;\frac{\frac{a}{1} \cdot \frac{c \cdot 4}{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\\
\mathbf{if}\;b \le 2.6854465913894807 \cdot 10^{+99}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}\]
Target
| Original | 34.3 |
| Comparison | 21.5 |
| Herbie | 7.3 |
\[ \begin{array}{l}
\mathbf{if}\;b \lt 0:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\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 < -1.6984829603276024e+97
Initial program 59.1
\[\frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied taylor 40.4
\[\leadsto \frac{\left(-b\right) - \left(2 \cdot \frac{c \cdot a}{b} - b\right)}{2 \cdot a}\]
Taylor expanded around -inf 40.4
\[\leadsto \frac{\left(-b\right) - \color{blue}{\left(2 \cdot \frac{c \cdot a}{b} - b\right)}}{2 \cdot a}\]
Applied simplify 0
\[\leadsto \color{blue}{\frac{\left(-b\right) + b}{a + a} - \frac{\frac{c}{b}}{1}}\]
Applied simplify 0
\[\leadsto \frac{\left(-b\right) + b}{a + a} - \color{blue}{\frac{c}{b}}\]
if -1.6984829603276024e+97 < b < -2.1555069951410637e-127
Initial program 39.4
\[\frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm
Applied flip-- 39.5
\[\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.6
\[\leadsto \frac{\frac{\color{blue}{a \cdot \left(c \cdot 4\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.6
\[\leadsto \frac{\frac{a \cdot \left(c \cdot 4\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.2
\[\leadsto \frac{\color{blue}{\frac{a}{1} \cdot \frac{c \cdot 4}{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
if -2.1555069951410637e-127 < b < 2.6854465913894807e+99
Initial program 12.0
\[\frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
if 2.6854465913894807e+99 < b
Initial program 46.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}}\]
- Recombined 4 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 "quadm (p42, negative)"
:target
(if (< b 0) (/ c (* a (/ (+ (- b) (sqrt (- (sqr b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (sqr b) (* 4 (* a c))))) (* 2 a)))
(/ (- (- b) (sqrt (- (sqr b) (* 4 (* a c))))) (* 2 a)))