Average Error: 34.2 → 7.0
Time: 2.3m
Precision: 64
Internal Precision: 2944
\[\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.3176305970181619 \cdot 10^{+112}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{if}\;b \le 8.297707114940739 \cdot 10^{-172}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\mathbf{if}\;b \le 3.086328126725836 \cdot 10^{+85}:\\
\;\;\;\;\frac{\frac{\left(c \cdot a\right) \cdot 4}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot \frac{-2}{2}\\
\end{array}\]
Target
| Original | 34.2 |
|---|
| Target | 21.4 |
|---|
| Herbie | 7.0 |
|---|
\[\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 < -1.3176305970181619e+112
Initial program 49.1
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around -inf 10.3
\[\leadsto \frac{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}{2 \cdot a}\]
Applied simplify0.0
\[\leadsto \color{blue}{\frac{\frac{c}{b}}{1} - \frac{b}{a}}\]
Applied simplify0.0
\[\leadsto \color{blue}{\frac{c}{b}} - \frac{b}{a}\]
if -1.3176305970181619e+112 < b < 8.297707114940739e-172
Initial program 9.7
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
if 8.297707114940739e-172 < b < 3.086328126725836e+85
Initial program 37.8
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied flip-+37.8
\[\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.5
\[\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}\]
if 3.086328126725836e+85 < b
Initial program 58.9
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around inf 15.7
\[\leadsto \frac{\color{blue}{-2 \cdot \frac{c \cdot a}{b}}}{2 \cdot a}\]
Applied simplify0
\[\leadsto \color{blue}{\frac{c}{b} \cdot \frac{-2}{2}}\]
- Recombined 4 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1062900086 561157142 2241869825 1166610429 2484609072 2159574644)'
(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)))