Average Error: 33.9 → 10.4
Time: 1.6m
Precision: 64
Internal Precision: 3456
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
↓
\[\begin{array}{l}
\mathbf{if}\;b \le -1.2200045799418502 \cdot 10^{-68}:\\
\;\;\;\;\frac{c}{b} \cdot \frac{-2}{2}\\
\mathbf{if}\;b \le 9.622889278670843 \cdot 10^{+25}:\\
\;\;\;\;\frac{-b}{2 \cdot a} - \frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c}{b}}{1} - \frac{b}{a}\\
\end{array}\]
Target
| Original | 33.9 |
|---|
| Target | 20.8 |
|---|
| Herbie | 10.4 |
|---|
\[\begin{array}{l}
\mathbf{if}\;b \lt 0:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\end{array}\]
Derivation
- Split input into 3 regimes
if b < -1.2200045799418502e-68
Initial program 53.1
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around -inf 19.1
\[\leadsto \frac{\color{blue}{-2 \cdot \frac{c \cdot a}{b}}}{2 \cdot a}\]
Applied simplify8.6
\[\leadsto \color{blue}{\frac{c}{b} \cdot \frac{-2}{2}}\]
if -1.2200045799418502e-68 < b < 9.622889278670843e+25
Initial program 14.4
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied div-sub14.4
\[\leadsto \color{blue}{\frac{-b}{2 \cdot a} - \frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\]
if 9.622889278670843e+25 < b
Initial program 34.0
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around inf 10.7
\[\leadsto \frac{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}{2 \cdot a}\]
Applied simplify6.4
\[\leadsto \color{blue}{\frac{\frac{c}{b}}{1} - \frac{b}{a}}\]
- Recombined 3 regimes into one program.
Runtime
herbie shell --seed '#(1064269945 2896236262 301053905 1701069080 1701464310 1614783279)' +o rules:numerics
(FPCore (a b c)
:name "quadm (p42, negative)"
:herbie-target
(if (< b 0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))