Average Error: 33.5 → 9.7
Time: 1.4m
Precision: 64
Internal Precision: 3456
\[\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 -5.733532428534779 \cdot 10^{+153}:\\
\;\;\;\;\frac{\frac{c}{b}}{1} - \frac{b}{a}\\
\mathbf{if}\;b \le 1.433933074635301 \cdot 10^{-91}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot \frac{-2}{2}\\
\end{array}\]
Target
| Original | 33.5 |
|---|
| Target | 20.9 |
|---|
| Herbie | 9.7 |
|---|
\[\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 < -5.733532428534779e+153
Initial program 60.9
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{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 simplify2.0
\[\leadsto \color{blue}{\frac{\frac{c}{b}}{1} - \frac{b}{a}}\]
if -5.733532428534779e+153 < b < 1.433933074635301e-91
Initial program 11.7
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
if 1.433933074635301e-91 < b
Initial program 51.7
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
Taylor expanded around inf 20.3
\[\leadsto \frac{\color{blue}{-2 \cdot \frac{c \cdot a}{b}}}{2 \cdot a}\]
Applied simplify9.5
\[\leadsto \color{blue}{\frac{c}{b} \cdot \frac{-2}{2}}\]
- Recombined 3 regimes into one program.
Runtime
herbie shell --seed '#(1064269945 2896236262 301053905 1701069080 1701464310 1614783279)'
(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)))