Average Error: 33.8 → 6.5
Time: 1.7m
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 -4.00814757332535 \cdot 10^{+71}:\\
\;\;\;\;\frac{\frac{c}{b}}{1} - \frac{b}{a}\\
\mathbf{if}\;-b \le 3.0226235622241636 \cdot 10^{-280}:\\
\;\;\;\;\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}\\
\mathbf{if}\;-b \le 5.639709921649064 \cdot 10^{+148}:\\
\;\;\;\;\frac{1}{2} \cdot \frac{4 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + b}{a + a} - \frac{\frac{c}{b}}{1}\\
\end{array}\]
Target
| Original | 33.8 |
|---|
| Target | 20.7 |
|---|
| Herbie | 6.5 |
|---|
\[\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 4 regimes
if (- b) < -4.00814757332535e+71
Initial program 39.6
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around inf 10.4
\[\leadsto \frac{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}{2 \cdot a}\]
Applied simplify5.0
\[\leadsto \color{blue}{\frac{\frac{c}{b}}{1} - \frac{b}{a}}\]
if -4.00814757332535e+71 < (- b) < 3.0226235622241636e-280
Initial program 9.4
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied div-inv9.5
\[\leadsto \color{blue}{\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}}\]
if 3.0226235622241636e-280 < (- b) < 5.639709921649064e+148
Initial program 35.3
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 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) \cdot \left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
Applied simplify15.3
\[\leadsto \frac{\frac{\color{blue}{\left(c \cdot a\right) \cdot 4}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
- Using strategy
rm Applied *-un-lft-identity15.3
\[\leadsto \frac{\color{blue}{1 \cdot \frac{\left(c \cdot a\right) \cdot 4}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
Applied times-frac15.3
\[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{\frac{\left(c \cdot a\right) \cdot 4}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{a}}\]
Applied simplify7.3
\[\leadsto \frac{1}{2} \cdot \color{blue}{\frac{4 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}}\]
if 5.639709921649064e+148 < (- b)
Initial program 62.4
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around -inf 38.5
\[\leadsto \frac{\left(-b\right) - \color{blue}{\left(2 \cdot \frac{c \cdot a}{b} - b\right)}}{2 \cdot a}\]
Applied simplify1.6
\[\leadsto \color{blue}{\frac{\left(-b\right) + b}{a + a} - \frac{\frac{c}{b}}{1}}\]
- Recombined 4 regimes into one program.
Runtime
herbie shell --seed '#(212267722 3993171362 1093346726 3605783651 2106536041 3335990851)'
(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)))