Average Error: 33.2 → 12.6
Time: 3.6m
Precision: 64
Internal Precision: 3392
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
↓
\[\begin{array}{l}
\mathbf{if}\;\frac{e^{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)}}{2 \cdot a} \le -1.4033975884233095 \cdot 10^{+308}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{if}\;\frac{e^{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)}}{2 \cdot a} \le -5.83011416967328 \cdot 10^{-306}:\\
\;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}}\\
\mathbf{if}\;\frac{e^{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)}}{2 \cdot a} \le 3.6398482477558652 \cdot 10^{-301}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{if}\;\frac{e^{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)}}{2 \cdot a} \le 1.4976730521633131 \cdot 10^{+308}:\\
\;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}\]
Target
| Original | 33.2 |
|---|
| Target | 20.4 |
|---|
| Herbie | 12.6 |
|---|
\[\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 2 regimes
if (/ (exp (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (* 2 a)) < -1.4033975884233095e+308 or -5.83011416967328e-306 < (/ (exp (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (* 2 a)) < 3.6398482477558652e-301 or 1.4976730521633131e+308 < (/ (exp (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (* 2 a))
Initial program 59.0
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied simplify59.0
\[\leadsto \color{blue}{\frac{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}}\]
- Using strategy
rm Applied flip--59.4
\[\leadsto \frac{\color{blue}{\frac{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} \cdot \sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b \cdot b}{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} + b}}}{2 \cdot a}\]
Applied simplify39.2
\[\leadsto \frac{\frac{\color{blue}{\left(c \cdot a\right) \cdot \left(-4\right)}}{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} + b}}{2 \cdot a}\]
- Using strategy
rm Applied clear-num39.3
\[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\frac{\left(c \cdot a\right) \cdot \left(-4\right)}{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} + b}}}}\]
Taylor expanded around 0 21.8
\[\leadsto \frac{1}{\color{blue}{-1 \cdot \frac{b}{c}}}\]
Applied simplify21.3
\[\leadsto \color{blue}{\frac{c}{-b}}\]
if -1.4033975884233095e+308 < (/ (exp (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (* 2 a)) < -5.83011416967328e-306 or 3.6398482477558652e-301 < (/ (exp (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (* 2 a)) < 1.4976730521633131e+308
Initial program 2.1
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied simplify2.1
\[\leadsto \color{blue}{\frac{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}}\]
- Using strategy
rm Applied clear-num2.2
\[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}}}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed 2018199 +o rules:numerics
(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)))