Average Error: 33.3 → 10.5
Time: 1.6m
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 -1.1113098726408647 \cdot 10^{+115}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{if}\;b \le 4.3328766807005103 \cdot 10^{-103}:\\
\;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot \frac{-2}{2}\\
\end{array}\]
Target
| Original | 33.3 |
|---|
| Target | 20.5 |
|---|
| Herbie | 10.5 |
|---|
\[\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 3 regimes
if b < -1.1113098726408647e+115
Initial program 47.0
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around -inf 3.5
\[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
Applied simplify3.5
\[\leadsto \color{blue}{\frac{-b}{a}}\]
if -1.1113098726408647e+115 < b < 4.3328766807005103e-103
Initial program 12.5
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied clear-num12.6
\[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
if 4.3328766807005103e-103 < b
Initial program 51.3
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around inf 21.5
\[\leadsto \frac{\color{blue}{-2 \cdot \frac{c \cdot a}{b}}}{2 \cdot a}\]
Applied simplify10.6
\[\leadsto \color{blue}{\frac{c}{b} \cdot \frac{-2}{2}}\]
- Recombined 3 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1063282112 2455465480 4141627379 3773598652 1647277307 776739644)'
(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)))