Average Error: 33.2 → 10.8
Time: 2.2m
Precision: 64
Internal Precision: 3392
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
↓
\[\begin{array}{l}
\mathbf{if}\;b \le -1.2004129928316368 \cdot 10^{+154}:\\
\;\;\;\;\frac{\frac{c}{b} \cdot \left(2 \cdot a\right) - \left(b + b\right)}{2 \cdot a}\\
\mathbf{if}\;b \le 756484004754347.6:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\frac{4}{a} \cdot \frac{a}{2}\right) \cdot c}{(\left(\frac{a}{\frac{b}{c}}\right) \cdot 2 + \left(\left(-b\right) - b\right))_*}\\
\end{array}\]
Target
| Original | 33.2 |
|---|
| Target | 20.6 |
|---|
| Herbie | 10.8 |
|---|
\[\begin{array}{l}
\mathbf{if}\;b \lt 0:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\
\end{array}\]
Derivation
- Split input into 3 regimes
if b < -1.2004129928316368e+154
Initial program 60.9
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
- Using strategy
rm Applied div-inv60.9
\[\leadsto \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}}\]
Taylor expanded around -inf 11.1
\[\leadsto \left(\left(-b\right) + \color{blue}{\left(2 \cdot \frac{c \cdot a}{b} - b\right)}\right) \cdot \frac{1}{2 \cdot a}\]
Applied simplify2.2
\[\leadsto \color{blue}{\frac{\frac{c}{b} \cdot \left(2 \cdot a\right) - \left(b + b\right)}{2 \cdot a}}\]
if -1.2004129928316368e+154 < b < 756484004754347.6
Initial program 15.5
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
if 756484004754347.6 < b
Initial program 55.5
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
- Using strategy
rm Applied flip-+55.6
\[\leadsto \frac{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{2 \cdot a}\]
Applied simplify27.4
\[\leadsto \frac{\frac{\color{blue}{c \cdot \left(a \cdot 4\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
Taylor expanded around inf 17.0
\[\leadsto \frac{\frac{c \cdot \left(a \cdot 4\right)}{\left(-b\right) - \color{blue}{\left(b - 2 \cdot \frac{c \cdot a}{b}\right)}}}{2 \cdot a}\]
Applied simplify5.3
\[\leadsto \color{blue}{\frac{\left(\frac{4}{a} \cdot \frac{a}{2}\right) \cdot c}{(\left(\frac{a}{\frac{b}{c}}\right) \cdot 2 + \left(\left(-b\right) - b\right))_*}}\]
- Recombined 3 regimes into one program.
Runtime
herbie shell --seed '#(1072840222 1305617769 1692503039 1353360431 4178980589 1488672652)' +o rules:numerics
(FPCore (a b c)
:name "The quadratic formula (r1)"
: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)))