Average Error: 34.2 → 9.4
Time: 2.8min
Precision: binary64
Cost: 8386
Math TeX FPCore C \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
↓
\[\begin{array}{l}
\mathbf{if}\;b \leq -1.615117109155005 \cdot 10^{+61}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq -1.3641711845431856 \cdot 10^{-290}:\\
\;\;\;\;\frac{\frac{a \cdot \left(c \cdot 4\right)}{\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b}}{a \cdot 2}\\
\mathbf{elif}\;b \leq 7.942031390488743 \cdot 10^{+46}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}\]
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} ↓
\begin{array}{l}
\mathbf{if}\;b \leq -1.615117109155005 \cdot 10^{+61}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq -1.3641711845431856 \cdot 10^{-290}:\\
\;\;\;\;\frac{\frac{a \cdot \left(c \cdot 4\right)}{\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b}}{a \cdot 2}\\
\mathbf{elif}\;b \leq 7.942031390488743 \cdot 10^{+46}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array} (FPCore (a b c)
:precision binary64
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a))) ↓
(FPCore (a b c)
:precision binary64
(if (<= b -1.615117109155005e+61)
(- (/ c b))
(if (<= b -1.3641711845431856e-290)
(/
(/ (* a (* c 4.0)) (- (sqrt (+ (* b b) (* a (* c -4.0)))) b))
(* a 2.0))
(if (<= b 7.942031390488743e+46)
(* -0.5 (/ (+ b (sqrt (- (* b b) (* 4.0 (* c a))))) a))
(/ (- b) a))))) double code(double a, double b, double c) {
return (-b - sqrt((b * b) - (4.0 * (a * c)))) / (2.0 * a);
}
↓
double code(double a, double b, double c) {
double tmp;
if (b <= -1.615117109155005e+61) {
tmp = -(c / b);
} else if (b <= -1.3641711845431856e-290) {
tmp = ((a * (c * 4.0)) / (sqrt((b * b) + (a * (c * -4.0))) - b)) / (a * 2.0);
} else if (b <= 7.942031390488743e+46) {
tmp = -0.5 * ((b + sqrt((b * b) - (4.0 * (c * a)))) / a);
} else {
tmp = -b / a;
}
return tmp;
}
Try it out Enter valid numbers for all inputs
Target Original 34.2 Target 20.4 Herbie 9.4
\[\begin{array}{l}
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\end{array}\]
Alternatives Alternative 1 Error 9.3 Cost 8386
\[\begin{array}{l}
\mathbf{if}\;b \leq -1.688687182540498 \cdot 10^{+61}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq -1.1049660614135754 \cdot 10^{-164}:\\
\;\;\;\;-0.5 \cdot \frac{\frac{4 \cdot \left(c \cdot a\right)}{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}{a}\\
\mathbf{elif}\;b \leq 7.942031390488743 \cdot 10^{+46}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}\]
Alternative 2 Error 10.9 Cost 8258
\[\begin{array}{l}
\mathbf{if}\;b \leq -1.1914175080084799 \cdot 10^{-29}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 6.852065077857368 \cdot 10^{+46}:\\
\;\;\;\;-0.5 \cdot \frac{b}{a} - \frac{\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}\]
Alternative 3 Error 10.9 Cost 8002
\[\begin{array}{l}
\mathbf{if}\;b \leq -1.1914175080084799 \cdot 10^{-29}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 7.397048234173055 \cdot 10^{+46}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}\]
Alternative 4 Error 11.0 Cost 8002
\[\begin{array}{l}
\mathbf{if}\;b \leq -1.165376592702905 \cdot 10^{-29}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 3.932388830389278 \cdot 10^{+44}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}\]
Alternative 5 Error 14.6 Cost 9030
\[\begin{array}{l}
\mathbf{if}\;b \leq -1.1132947620917554 \cdot 10^{-29}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq -2.0636023529259967 \cdot 10^{-75}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\
\mathbf{elif}\;b \leq -1.0958056759141235 \cdot 10^{-103}:\\
\;\;\;\;\left(-\frac{c}{b}\right) - \frac{a \cdot \left(c \cdot c\right)}{{b}^{3}}\\
\mathbf{elif}\;b \leq 4.5456072667014904 \cdot 10^{-73}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{elif}\;b \leq 5.941593363568897 \cdot 10^{-57}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 561226648.3438514:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}\]
Alternative 6 Error 14.5 Cost 9030
\[\begin{array}{l}
\mathbf{if}\;b \leq -1.1914175080084799 \cdot 10^{-29}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq -6.26166103267307 \cdot 10^{-66}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\
\mathbf{elif}\;b \leq -8.470867209365325 \cdot 10^{-104}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 3.076579487085727 \cdot 10^{-76}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{elif}\;b \leq 5.941593363568897 \cdot 10^{-57}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 561226648.3438514:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}\]
Alternative 7 Error 14.5 Cost 9030
\[\begin{array}{l}
\mathbf{if}\;b \leq -1.0872538467861805 \cdot 10^{-29}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq -2.5727230087426245 \cdot 10^{-66}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\
\mathbf{elif}\;b \leq -8.159968515643336 \cdot 10^{-104}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 1.3969847469406258 \cdot 10^{-70}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\
\mathbf{elif}\;b \leq 5.941593363568897 \cdot 10^{-57}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 561226648.3438514:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}\]
Alternative 8 Error 15.1 Cost 8902
\[\begin{array}{l}
\mathbf{if}\;b \leq -1.0872538467861805 \cdot 10^{-29}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq -2.551763611402685 \cdot 10^{-79}:\\
\;\;\;\;-0.5 \cdot \frac{\sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\
\mathbf{elif}\;b \leq -5.983677659589416 \cdot 10^{-104}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 2.631871001127332 \cdot 10^{-70}:\\
\;\;\;\;-0.5 \cdot \frac{\sqrt{c \cdot \left(a \cdot -4\right)}}{a}\\
\mathbf{elif}\;b \leq 5.941593363568897 \cdot 10^{-57}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 561226648.3438514:\\
\;\;\;\;-0.5 \cdot \frac{\sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}\]
Alternative 9 Error 15.0 Cost 8902
\[\begin{array}{l}
\mathbf{if}\;b \leq -1.0872538467861805 \cdot 10^{-29}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq -6.972674796872848 \cdot 10^{-72}:\\
\;\;\;\;-0.5 \cdot \frac{\sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\
\mathbf{elif}\;b \leq -1.0647158065419246 \cdot 10^{-103}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 3.2583865685001763 \cdot 10^{-76}:\\
\;\;\;\;-0.5 \cdot \frac{\sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\
\mathbf{elif}\;b \leq 5.941593363568897 \cdot 10^{-57}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 561226648.3438514:\\
\;\;\;\;-0.5 \cdot \frac{\sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}\]
Alternative 10 Error 22.6 Cost 7169
\[\begin{array}{l}
\mathbf{if}\;b \leq -3.081150325371919 \cdot 10^{-247}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{b + \left|b\right|}{a}\\
\end{array}\]
Alternative 11 Error 22.6 Cost 577
\[\begin{array}{l}
\mathbf{if}\;b \leq -2.4090299573481037 \cdot 10^{-268}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}\]
Alternative 12 Error 39.6 Cost 256
\[-\frac{c}{b}\]
Alternative 13 Error 56.4 Cost 64
\[0\]
Alternative 14 Error 61.5 Cost 64
\[-1\]
Error Derivation Split input into 4 regimes if b < -1.615117109155005e61 Initial program 57.8
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around -inf 3.7
\[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
Simplified3.7
\[\leadsto \color{blue}{-\frac{c}{b}}\]
Simplified3.7
\[\leadsto \color{blue}{-\frac{c}{b}}\]
if -1.615117109155005e61 < b < -1.36417118454318557e-290 Initial program 31.5
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Using strategy rm Applied sub-neg_binary64_753 31.5
\[\leadsto \frac{\left(-b\right) - \sqrt{\color{blue}{b \cdot b + \left(-4 \cdot \left(a \cdot c\right)\right)}}}{2 \cdot a}\]
Simplified31.5
\[\leadsto \frac{\left(-b\right) - \sqrt{b \cdot b + \color{blue}{a \cdot \left(c \cdot -4\right)}}}{2 \cdot a}\]
Using strategy rm Applied flip--_binary64_735 31.5
\[\leadsto \frac{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} \cdot \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}{\left(-b\right) + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}}}{2 \cdot a}\]
Simplified16.8
\[\leadsto \frac{\frac{\color{blue}{a \cdot \left(c \cdot 4\right)}}{\left(-b\right) + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}}{2 \cdot a}\]
Simplified16.8
\[\leadsto \frac{\frac{a \cdot \left(c \cdot 4\right)}{\color{blue}{\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b}}}{2 \cdot a}\]
Simplified16.8
\[\leadsto \color{blue}{\frac{\frac{a \cdot \left(c \cdot 4\right)}{\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b}}{2 \cdot a}}\]
if -1.36417118454318557e-290 < b < 7.94203139048874288e46 Initial program 10.5
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Simplified10.5
\[\leadsto \color{blue}{-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}}\]
Using strategy rm Applied pow1_binary64_821 10.5
\[\leadsto -0.5 \cdot \color{blue}{{\left(\frac{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}\right)}^{1}}\]
Simplified10.5
\[\leadsto \color{blue}{-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}}\]
if 7.94203139048874288e46 < b Initial program 36.4
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around inf 5.6
\[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
Simplified5.6
\[\leadsto \color{blue}{\frac{-b}{a}}\]
Simplified5.6
\[\leadsto \color{blue}{\frac{-b}{a}}\]
Recombined 4 regimes into one program. Final simplification9.4
\[\leadsto \begin{array}{l}
\mathbf{if}\;b \leq -1.615117109155005 \cdot 10^{+61}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq -1.3641711845431856 \cdot 10^{-290}:\\
\;\;\;\;\frac{\frac{a \cdot \left(c \cdot 4\right)}{\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b}}{a \cdot 2}\\
\mathbf{elif}\;b \leq 7.942031390488743 \cdot 10^{+46}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}\]
Reproduce herbie shell --seed 2021014
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-expected #f
:herbie-target
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))