Average Error: 33.4 → 8.8
Time: 1.8m
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 -57.05332371598462:\\
\;\;\;\;\frac{c}{b} \cdot \frac{-2}{2}\\
\mathbf{if}\;-b \le -6.041090339021061 \cdot 10^{-192}:\\
\;\;\;\;\frac{\frac{4 \cdot \left(a \cdot c\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\
\mathbf{if}\;-b \le 1.5285447525713952 \cdot 10^{+127}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c}{\frac{b}{a}} - b}{a}\\
\end{array}\]
Target
| Original | 33.4 |
|---|
| Target | 20.7 |
|---|
| Herbie | 8.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 4 regimes
if (- b) < -57.05332371598462
Initial program 55.4
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
Taylor expanded around inf 17.5
\[\leadsto \frac{\color{blue}{-2 \cdot \frac{c \cdot a}{b}}}{2 \cdot a}\]
Applied simplify6.1
\[\leadsto \color{blue}{\frac{c}{b} \cdot \frac{-2}{2}}\]
if -57.05332371598462 < (- b) < -6.041090339021061e-192
Initial program 31.0
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
- Using strategy
rm Applied flip-+31.1
\[\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 simplify18.3
\[\leadsto \frac{\frac{\color{blue}{4 \cdot \left(a \cdot c\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
if -6.041090339021061e-192 < (- b) < 1.5285447525713952e+127
Initial program 9.7
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
if 1.5285447525713952e+127 < (- b)
Initial program 52.7
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
- Using strategy
rm Applied div-inv52.7
\[\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 10.8
\[\leadsto \color{blue}{\left(2 \cdot \frac{c \cdot a}{b} - 2 \cdot b\right)} \cdot \frac{1}{2 \cdot a}\]
Applied simplify3.2
\[\leadsto \color{blue}{\frac{\frac{c}{\frac{b}{a}} - b}{a}}\]
- Recombined 4 regimes into one program.
Runtime
herbie shell --seed '#(1064300848 3212030778 2049303162 3567222883 2277747821 1384278011)'
(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)))