Average Error: 33.4 → 13.1
Time: 3.8m
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.286013373950679 \cdot 10^{+115}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{if}\;b \le 1.5130832338357297 \cdot 10^{-246}:\\
\;\;\;\;\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 1.293965168376474 \cdot 10^{+84}:\\
\;\;\;\;\frac{\frac{4}{2} \cdot c}{\frac{a + a}{\frac{b}{c}} + \left(\left(-b\right) - b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{4}{2} \cdot c}{\frac{a + a}{\frac{b}{c}} + \left(\left(-b\right) - b\right)}\\
\end{array}\]
Target
| Original | 33.4 |
|---|
| Target | 20.7 |
|---|
| Herbie | 13.1 |
|---|
\[\begin{array}{l}
\mathbf{if}\;b \lt 0:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \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.286013373950679e+115
Initial program 48.2
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around -inf 10.1
\[\leadsto \frac{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}{2 \cdot a}\]
Applied simplify3.7
\[\leadsto \color{blue}{\frac{\frac{c}{b}}{1} - \frac{b}{a}}\]
Applied simplify3.7
\[\leadsto \color{blue}{\frac{c}{b}} - \frac{b}{a}\]
if -4.286013373950679e+115 < b < 1.5130832338357297e-246
Initial program 10.0
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied div-inv10.1
\[\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 1.5130832338357297e-246 < b < 1.293965168376474e+84
Initial program 32.6
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied flip-+32.7
\[\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.9
\[\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 clear-num16.1
\[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\frac{\left(c \cdot a\right) \cdot 4}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}}\]
Applied simplify8.3
\[\leadsto \frac{1}{\color{blue}{\frac{2}{c \cdot 4} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}\right)}}\]
Taylor expanded around inf 33.3
\[\leadsto \frac{1}{\frac{2}{c \cdot 4} \cdot \left(\left(-b\right) - \color{blue}{\left(b - 2 \cdot \frac{c \cdot a}{b}\right)}\right)}\]
Applied simplify32.8
\[\leadsto \color{blue}{\frac{\frac{4}{2} \cdot c}{\frac{a + a}{\frac{b}{c}} + \left(\left(-b\right) - b\right)}}\]
if 1.293965168376474e+84 < b
Initial program 57.9
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied flip-+58.0
\[\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 simplify31.2
\[\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 clear-num31.4
\[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\frac{\left(c \cdot a\right) \cdot 4}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}}\]
Applied simplify28.9
\[\leadsto \frac{1}{\color{blue}{\frac{2}{c \cdot 4} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}\right)}}\]
Taylor expanded around inf 7.7
\[\leadsto \frac{1}{\frac{2}{c \cdot 4} \cdot \left(\left(-b\right) - \color{blue}{\left(b - 2 \cdot \frac{c \cdot a}{b}\right)}\right)}\]
Applied simplify2.9
\[\leadsto \color{blue}{\frac{\frac{4}{2} \cdot c}{\frac{a + a}{\frac{b}{c}} + \left(\left(-b\right) - b\right)}}\]
- Recombined 4 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1063313015 2771194459 1594909340 1344785158 2223560818 546365448)'
(FPCore (a b c)
:name "quadp (p42, positive)"
:herbie-target
(if (< b 0) (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))