Average Error: 34.0 → 5.2
Time: 2.3m
Precision: 64
Internal Precision: 2688
\[\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.4471521473484649 \cdot 10^{+72}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{if}\;b \le -4.239755032742612 \cdot 10^{-273}:\\
\;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}\\
\mathbf{if}\;b \le 1.1498155483847317 \cdot 10^{+81}:\\
\;\;\;\;\frac{1}{2} \cdot \frac{4 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{4}{\frac{2}{c}}}{\frac{c + c}{\frac{b}{a}} - \left(b + b\right)}\\
\end{array}\]
Target
| Original | 34.0 |
|---|
| Target | 21.3 |
|---|
| Herbie | 5.2 |
|---|
\[\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.4471521473484649e+72
Initial program 40.5
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around -inf 9.8
\[\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.4471521473484649e+72 < b < -4.239755032742612e-273
Initial program 8.9
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied div-inv9.0
\[\leadsto \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}}\]
if -4.239755032742612e-273 < b < 1.1498155483847317e+81
Initial program 29.3
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied flip-+29.4
\[\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 simplify14.9
\[\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}\]
- Using strategy
rm Applied *-un-lft-identity14.9
\[\leadsto \frac{\color{blue}{1 \cdot \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}\]
Applied times-frac14.9
\[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{\frac{\left(c \cdot a\right) \cdot 4}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{a}}\]
Applied simplify8.5
\[\leadsto \frac{1}{2} \cdot \color{blue}{\frac{4 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}}}\]
if 1.1498155483847317e+81 < b
Initial program 58.4
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied flip-+58.4
\[\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 simplify32.3
\[\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}\]
Taylor expanded around inf 14.8
\[\leadsto \frac{\frac{\left(c \cdot a\right) \cdot 4}{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}}{2 \cdot a}\]
Applied simplify1.7
\[\leadsto \color{blue}{\frac{\left(1 \cdot \frac{c}{2}\right) \cdot 4}{\frac{c + c}{\frac{b}{a}} - \left(b + b\right)}}\]
Applied simplify1.8
\[\leadsto \frac{\color{blue}{\frac{4}{\frac{2}{c}}}}{\frac{c + c}{\frac{b}{a}} - \left(b + b\right)}\]
- Recombined 4 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1063027428 1192549564 1443466578 604016274 3637110559 1698629644)'
(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)))