Average Error: 33.4 → 16.8
Time: 2.4m
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}\;\frac{\left(4 \cdot \left(-c\right)\right) \cdot \frac{1}{2}}{\sqrt{(\left(-c\right) \cdot \left(4 \cdot a\right) + \left(b \cdot b\right))_*} + b} \le -2.917130434005371 \cdot 10^{+221}:\\
\;\;\;\;\frac{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*}}{2 \cdot a} - \frac{b}{2 \cdot a}\\
\mathbf{if}\;\frac{\left(4 \cdot \left(-c\right)\right) \cdot \frac{1}{2}}{\sqrt{(\left(-c\right) \cdot \left(4 \cdot a\right) + \left(b \cdot b\right))_*} + b} \le -0.6203542294033277:\\
\;\;\;\;\frac{\frac{\left(c \cdot a\right) \cdot \left(-4\right)}{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} + b} \cdot \sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} + b}}}{2 \cdot a}\\
\mathbf{if}\;\frac{\left(4 \cdot \left(-c\right)\right) \cdot \frac{1}{2}}{\sqrt{(\left(-c\right) \cdot \left(4 \cdot a\right) + \left(b \cdot b\right))_*} + b} \le -9.7608597123688 \cdot 10^{-319}:\\
\;\;\;\;(e^{\log_* (1 + \frac{\left(4 \cdot \left(-c\right)\right) \cdot \frac{1}{2}}{\sqrt{(\left(-c\right) \cdot \left(4 \cdot a\right) + \left(b \cdot b\right))_*} + b})} - 1)^*\\
\mathbf{if}\;\frac{\left(4 \cdot \left(-c\right)\right) \cdot \frac{1}{2}}{\sqrt{(\left(-c\right) \cdot \left(4 \cdot a\right) + \left(b \cdot b\right))_*} + b} \le 1.655766096544357 \cdot 10^{-290}:\\
\;\;\;\;\frac{\frac{\left(c \cdot a\right) \cdot \left(-4\right)}{b + b}}{2 \cdot a}\\
\mathbf{if}\;\frac{\left(4 \cdot \left(-c\right)\right) \cdot \frac{1}{2}}{\sqrt{(\left(-c\right) \cdot \left(4 \cdot a\right) + \left(b \cdot b\right))_*} + b} \le 6.496019890407578 \cdot 10^{+197}:\\
\;\;\;\;(e^{\log_* (1 + \frac{\left(4 \cdot \left(-c\right)\right) \cdot \frac{1}{2}}{\sqrt{(\left(-c\right) \cdot \left(4 \cdot a\right) + \left(b \cdot b\right))_*} + b})} - 1)^*\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*}}{2 \cdot a} - \frac{b}{2 \cdot a}\\
\end{array}\]
Target
| Original | 33.4 |
|---|
| Target | 21.0 |
|---|
| Herbie | 16.8 |
|---|
\[\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 (/ (* (* 4 (- c)) (/ 1 2)) (+ (sqrt (fma (- c) (* 4 a) (* b b))) b)) < -2.917130434005371e+221 or 6.496019890407578e+197 < (/ (* (* 4 (- c)) (/ 1 2)) (+ (sqrt (fma (- c) (* 4 a) (* b b))) b))
Initial program 1.2
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied simplify1.2
\[\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 div-sub1.2
\[\leadsto \color{blue}{\frac{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*}}{2 \cdot a} - \frac{b}{2 \cdot a}}\]
if -2.917130434005371e+221 < (/ (* (* 4 (- c)) (/ 1 2)) (+ (sqrt (fma (- c) (* 4 a) (* b b))) b)) < -0.6203542294033277
Initial program 17.1
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied simplify17.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 flip--17.9
\[\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 simplify5.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 add-sqr-sqrt6.3
\[\leadsto \frac{\frac{\left(c \cdot a\right) \cdot \left(-4\right)}{\color{blue}{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} + b} \cdot \sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} + b}}}}{2 \cdot a}\]
if -0.6203542294033277 < (/ (* (* 4 (- c)) (/ 1 2)) (+ (sqrt (fma (- c) (* 4 a) (* b b))) b)) < -9.7608597123688e-319 or 1.655766096544357e-290 < (/ (* (* 4 (- c)) (/ 1 2)) (+ (sqrt (fma (- c) (* 4 a) (* b b))) b)) < 6.496019890407578e+197
Initial program 26.4
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied simplify26.4
\[\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--27.3
\[\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 simplify12.1
\[\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 expm1-log1p-u13.0
\[\leadsto \color{blue}{(e^{\log_* (1 + \frac{\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}}{2 \cdot a})} - 1)^*}\]
Applied simplify5.6
\[\leadsto (e^{\color{blue}{\log_* (1 + \frac{\left(4 \cdot \left(-c\right)\right) \cdot \frac{1}{2}}{\sqrt{(\left(-c\right) \cdot \left(4 \cdot a\right) + \left(b \cdot b\right))_*} + b})}} - 1)^*\]
if -9.7608597123688e-319 < (/ (* (* 4 (- c)) (/ 1 2)) (+ (sqrt (fma (- c) (* 4 a) (* b b))) b)) < 1.655766096544357e-290
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.5
\[\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 simplify48.4
\[\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}\]
Taylor expanded around 0 36.8
\[\leadsto \frac{\frac{\left(c \cdot a\right) \cdot \left(-4\right)}{\color{blue}{b} + b}}{2 \cdot a}\]
- Recombined 4 regimes into one program.
Runtime
herbie shell --seed '#(1070578969 3140398606 632207097 462683394 1189254563 964980650)' +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)))