Average Error: 33.4 → 13.5
Time: 2.3m
Precision: 64
Internal Precision: 3200
\[\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 -1.9324923085818654 \cdot 10^{+245}:\\
\;\;\;\;\frac{(\left(\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*}}\right) \cdot \left(\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*}}\right) + \left(-b\right))_*}{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 -1.2831059250423066 \cdot 10^{-06}:\\
\;\;\;\;\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}\\
\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.0687528142207784 \cdot 10^{-257}:\\
\;\;\;\;(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 2.6034978300094934 \cdot 10^{-299}:\\
\;\;\;\;\frac{c}{-b}\\
\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.4092286300368768 \cdot 10^{+163}:\\
\;\;\;\;(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{1}{\frac{2 \cdot a}{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}}\\
\end{array}\]
Target
| Original | 33.4 |
|---|
| Target | 20.0 |
|---|
| Herbie | 13.5 |
|---|
\[\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 5 regimes
if (/ (* (* 4 (- c)) (/ 1 2)) (+ (sqrt (fma (- c) (* 4 a) (* b b))) b)) < -1.9324923085818654e+245
Initial program 0.4
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied simplify0.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 add-sqr-sqrt0.4
\[\leadsto \frac{\sqrt{\color{blue}{\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}{2 \cdot a}\]
Applied sqrt-prod0.6
\[\leadsto \frac{\color{blue}{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*}} \cdot \sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*}}} - b}{2 \cdot a}\]
Applied fma-neg0.5
\[\leadsto \frac{\color{blue}{(\left(\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*}}\right) \cdot \left(\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*}}\right) + \left(-b\right))_*}}{2 \cdot a}\]
if -1.9324923085818654e+245 < (/ (* (* 4 (- c)) (/ 1 2)) (+ (sqrt (fma (- c) (* 4 a) (* b b))) b)) < -1.2831059250423066e-06
Initial program 18.4
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied simplify18.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--19.1
\[\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.7
\[\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}\]
if -1.2831059250423066e-06 < (/ (* (* 4 (- c)) (/ 1 2)) (+ (sqrt (fma (- c) (* 4 a) (* b b))) b)) < -1.0687528142207784e-257 or 2.6034978300094934e-299 < (/ (* (* 4 (- c)) (/ 1 2)) (+ (sqrt (fma (- c) (* 4 a) (* b b))) b)) < 1.4092286300368768e+163
Initial program 25.9
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied simplify25.9
\[\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--26.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 simplify10.9
\[\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-u11.8
\[\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 simplify4.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 -1.0687528142207784e-257 < (/ (* (* 4 (- c)) (/ 1 2)) (+ (sqrt (fma (- c) (* 4 a) (* b b))) b)) < 2.6034978300094934e-299
Initial program 58.1
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied simplify58.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-num58.1
\[\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}}}\]
Taylor expanded around 0 29.0
\[\leadsto \frac{1}{\color{blue}{-1 \cdot \frac{b}{c}}}\]
Applied simplify28.3
\[\leadsto \color{blue}{\frac{c}{-b}}\]
if 1.4092286300368768e+163 < (/ (* (* 4 (- c)) (/ 1 2)) (+ (sqrt (fma (- c) (* 4 a) (* b b))) b))
Initial program 2.9
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied simplify2.9
\[\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-num3.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 5 regimes into one program.
Runtime
herbie shell --seed '#(1070833653 108281690 3330367898 3632331308 3494323072 43156186)' +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)))