Average Error: 33.2 → 13.0
Time: 3.0m
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 -7.800203871611098 \cdot 10^{+307}:\\
\;\;\;\;\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 -2.0061841269910144 \cdot 10^{-307}:\\
\;\;\;\;\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 5.715336273106866 \cdot 10^{-231}:\\
\;\;\;\;\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.6689973109210984 \cdot 10^{+307}:\\
\;\;\;\;\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 | 13.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 2 regimes
if (/ (exp (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (* 2 a)) < -7.800203871611098e+307 or -2.0061841269910144e-307 < (/ (exp (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (* 2 a)) < 5.715336273106866e-231 or 1.6689973109210984e+307 < (/ (exp (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (* 2 a))
Initial program 58.3
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied simplify58.3
\[\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--58.8
\[\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 simplify38.8
\[\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-num38.9
\[\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 22.3
\[\leadsto \frac{1}{\color{blue}{-1 \cdot \frac{b}{c}}}\]
Applied simplify21.7
\[\leadsto \color{blue}{\frac{c}{-b}}\]
if -7.800203871611098e+307 < (/ (exp (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (* 2 a)) < -2.0061841269910144e-307 or 5.715336273106866e-231 < (/ (exp (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (* 2 a)) < 1.6689973109210984e+307
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)))