Average Error: 33.7 → 5.8
Time: 21.5s
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 -1.2104515124530692 \cdot 10^{+151}:\\
\;\;\;\;\frac{\left(-b\right) + b}{a + a} - \frac{c}{b}\\
\mathbf{if}\;b \le 4.042972997887706 \cdot 10^{-305}:\\
\;\;\;\;\frac{1}{2} \cdot \frac{4 \cdot c}{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} + \left(-b\right)}\\
\mathbf{if}\;b \le 2.3106113327966147 \cdot 10^{+121}:\\
\;\;\;\;\frac{-b}{2 \cdot a} - \frac{\sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}\]
Target
| Original | 33.7 |
| Comparison | 21.2 |
| Herbie | 5.8 |
\[ \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.2104515124530692e+151
Initial program 62.4
\[\frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied taylor 39.6
\[\leadsto \frac{\left(-b\right) - \left(2 \cdot \frac{c \cdot a}{b} - b\right)}{2 \cdot a}\]
Taylor expanded around -inf 39.6
\[\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.2104515124530692e+151 < b < 4.042972997887706e-305
Initial program 34.2
\[\frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm
Applied flip-- 34.3
\[\leadsto \frac{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)} \cdot \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
Applied simplify 15.8
\[\leadsto \frac{\frac{\color{blue}{\left(c \cdot a\right) \cdot 4}}{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
- Using strategy
rm
Applied *-un-lft-identity 15.8
\[\leadsto \frac{\color{blue}{1 \cdot \frac{\left(c \cdot a\right) \cdot 4}{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
Applied times-frac 15.7
\[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{\frac{\left(c \cdot a\right) \cdot 4}{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}{a}}\]
Applied simplify 8.2
\[\leadsto \frac{1}{2} \cdot \color{blue}{\frac{4 \cdot c}{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} + \left(-b\right)}}\]
if 4.042972997887706e-305 < b < 2.3106113327966147e+121
Initial program 8.9
\[\frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm
Applied div-sub 8.9
\[\leadsto \color{blue}{\frac{-b}{2 \cdot a} - \frac{\sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\]
if 2.3106113327966147e+121 < b
Initial program 52.1
\[\frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied taylor 13.3
\[\leadsto \frac{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}{2 \cdot a}\]
Taylor expanded around inf 13.3
\[\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}\]
- Recombined 4 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie shell --seed '#(1067901057 3396600083 3715501224 3126139233 3908045574 1593683916)'
(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)))