Average Error: 34.4 → 5.6
Time: 1.2m
Precision: 64
Internal precision: 128
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
⬇
\[\begin{array}{l}
\mathbf{if}\;b \le -4.319226994044875 \cdot 10^{+67}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{if}\;b \le 3.4158607390551766 \cdot 10^{-208}:\\
\;\;\;\;\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 1.0905893076356243 \cdot 10^{+100}:\\
\;\;\;\;\frac{1}{\left(\left(-b\right) - {\left(\sqrt{\sqrt{{b}^2 - \left(4 \cdot a\right) \cdot c}}\right)}^2\right) \cdot \frac{\frac{2}{4}}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \left(-b\right)}{a + a} - \frac{c}{b}\\
\end{array}\]
Target
| Original | 34.4 |
| Comparison | 22.2 |
| Herbie | 5.6 |
\[ \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 < -4.319226994044875e+67
Initial program 43.2
\[\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 -4.319226994044875e+67 < b < 3.4158607390551766e-208
Initial program 11.1
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm
Applied div-inv 11.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}}\]
if 3.4158607390551766e-208 < b < 1.0905893076356243e+100
Initial program 35.3
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm
Applied flip-+ 35.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.4
\[\leadsto \frac{\frac{\color{blue}{4 \cdot \left(a \cdot c\right)}}{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
- Using strategy
rm
Applied clear-num 16.5
\[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\frac{4 \cdot \left(a \cdot c\right)}{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}}}\]
Applied simplify 7.8
\[\leadsto \frac{1}{\color{blue}{\left(\left(-b\right) - \sqrt{{b}^2 - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{\frac{2}{4}}{c}}}\]
- Using strategy
rm
Applied add-sqr-sqrt 7.9
\[\leadsto \frac{1}{\left(\left(-b\right) - \color{blue}{{\left(\sqrt{\sqrt{{b}^2 - \left(4 \cdot a\right) \cdot c}}\right)}^2}\right) \cdot \frac{\frac{2}{4}}{c}}\]
if 1.0905893076356243e+100 < b
Initial program 58.9
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied taylor 40.7
\[\leadsto \frac{\left(-b\right) + \left(b - 2 \cdot \frac{a \cdot c}{b}\right)}{2 \cdot a}\]
Taylor expanded around inf 40.7
\[\leadsto \frac{\left(-b\right) + \color{blue}{\left(b - 2 \cdot \frac{a \cdot c}{b}\right)}}{2 \cdot a}\]
Applied simplify 0
\[\leadsto \color{blue}{\frac{b + \left(-b\right)}{a + a} - \frac{c}{1 \cdot b}}\]
Applied simplify 0
\[\leadsto \frac{b + \left(-b\right)}{a + a} - \color{blue}{\frac{c}{b}}\]
- Recombined 4 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie --seed '#(1459318687 3783235169 3882486712 3306245629 1782328778 3817826396)'
(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)))