Average Error: 33.7 → 9.9
Time: 11.4s
Precision: binary64
Cost: 8258
Math TeX FPCore C \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
↓
\[\begin{array}{l}
\mathbf{if}\;b \leq -9.934253510808862 \cdot 10^{+120}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.7658541670298186 \cdot 10^{-38}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2} - \frac{b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\
\end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} ↓
\begin{array}{l}
\mathbf{if}\;b \leq -9.934253510808862 \cdot 10^{+120}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.7658541670298186 \cdot 10^{-38}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2} - \frac{b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\
\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 -9.934253510808862e+120)
(- (/ c b) (/ b a))
(if (<= b 2.7658541670298186e-38)
(- (/ (sqrt (- (* b b) (* c (* a 4.0)))) (* a 2.0)) (/ b (* a 2.0)))
(- (/ c b))))) 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 <= -9.934253510808862e+120) {
tmp = (c / b) - (b / a);
} else if (b <= 2.7658541670298186e-38) {
tmp = (sqrt((b * b) - (c * (a * 4.0))) / (a * 2.0)) - (b / (a * 2.0));
} else {
tmp = -(c / b);
}
return tmp;
}
Try it out Enter valid numbers for all inputs
Target Original 33.7 Target 20.3 Herbie 9.9
\[\begin{array}{l}
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\
\end{array}\]
Alternatives Alternative 1 Error 34.4 Cost 79936
\[\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{\sqrt[3]{a} \cdot \sqrt[3]{a}}{\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b} \cdot \sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}} \cdot \frac{\sqrt[3]{1}}{\frac{\sqrt[3]{a}}{\frac{\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{2}}}\]
Alternative 2 Error 34.1 Cost 47040
\[\left(\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}\right) \cdot \frac{\sqrt[3]{1}}{\frac{a}{\sqrt{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}}}\]
Alternative 3 Error 34.2 Cost 40896
\[\frac{\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b} \cdot \sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{\frac{a}{\frac{\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{2}}}\]
Alternative 4 Error 34.2 Cost 40896
\[\frac{\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{2} \cdot \frac{\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b} \cdot \sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{a}\]
Alternative 5 Error 34.2 Cost 40896
\[\frac{\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b} \cdot \left(\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b} \cdot \sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\right)}{a \cdot 2}\]
Alternative 6 Error 35.5 Cost 40640
\[\frac{\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \left(\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right) - b}{a \cdot 2}\]
Alternative 7 Error 34.1 Cost 39872
\[\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\sqrt{2}} \cdot \frac{\sqrt[3]{1}}{\frac{a}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{\sqrt{2}}}}\]
Alternative 8 Error 52.6 Cost 34176
\[\frac{\frac{\sqrt{{b}^{6} - {\left(\left(4 \cdot a\right) \cdot c\right)}^{3}}}{\sqrt{{b}^{4} + 4 \cdot \left(\left(b \cdot b + \left(4 \cdot a\right) \cdot c\right) \cdot \left(a \cdot c\right)\right)}} - b}{a \cdot 2}\]
Alternative 9 Error 52.5 Cost 27776
\[\frac{\sqrt{\frac{{b}^{6} - {\left(\left(4 \cdot a\right) \cdot c\right)}^{3}}{{b}^{4} + 4 \cdot \left(\left(b \cdot b + \left(4 \cdot a\right) \cdot c\right) \cdot \left(a \cdot c\right)\right)}} - b}{a \cdot 2}\]
Alternative 10 Error 34.1 Cost 27456
\[\frac{\sqrt{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}}{\frac{a}{\sqrt{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}}}\]
Alternative 11 Error 34.1 Cost 27456
\[\sqrt{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}} \cdot \frac{\sqrt{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}}{a}\]
Alternative 12 Error 34.1 Cost 27328
\[\frac{\sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{a} \cdot \frac{\sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{2}\]
Alternative 13 Error 34.1 Cost 27328
\[\frac{\sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{a \cdot 2}\]
Alternative 14 Error 45.3 Cost 27200
\[\frac{\sqrt{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}}{\frac{a}{\sqrt{\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{2}}}}\]
Alternative 15 Error 35.0 Cost 27200
\[\frac{\left|\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}\right| \cdot \sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}} - b}{a \cdot 2}\]
Alternative 16 Error 34.5 Cost 27200
\[\frac{\sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} - b}{a \cdot 2}\]
Alternative 17 Error 45.1 Cost 27072
\[\frac{\sqrt{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}}{\frac{a}{\sqrt{\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{2}}}}\]
Alternative 18 Error 42.8 Cost 20352
\[\frac{1}{\frac{a}{\frac{\sqrt[3]{{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}^{3}} - b}{2}}}\]
Alternative 19 Error 52.0 Cost 20224
\[\frac{\sqrt{\sqrt[3]{{\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}^{3}}} - b}{a \cdot 2}\]
Alternative 20 Error 42.7 Cost 20224
\[\frac{\sqrt[3]{{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}^{3}} - b}{a \cdot 2}\]
Alternative 21 Error 37.0 Cost 20160
\[\frac{e^{\log \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)} - b}{a \cdot 2}\]
Alternative 22 Error 61.5 Cost 20160
\[\frac{\log \left(e^{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right) - b}{a \cdot 2}\]
Alternative 23 Error 35.8 Cost 20160
\[\frac{e^{\log \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right)}}{a \cdot 2}\]
Alternative 24 Error 60.5 Cost 20160
\[\frac{\log \left(e^{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\right)}{a \cdot 2}\]
Alternative 25 Error 53.8 Cost 14592
\[\frac{\sqrt{\frac{{b}^{4} - \left(\left(c \cdot c\right) \cdot \left(a \cdot a\right)\right) \cdot 16}{b \cdot b + \left(4 \cdot a\right) \cdot c}} - b}{a \cdot 2}\]
Alternative 26 Error 46.1 Cost 14272
\[\frac{\left(\sqrt{a \cdot \left(c \cdot -4\right)} + 0.5 \cdot \frac{b \cdot b}{\sqrt{a \cdot \left(c \cdot -4\right)}}\right) - b}{a \cdot 2}\]
Alternative 27 Error 44.0 Cost 8384
\[\frac{1}{\frac{a}{\frac{\frac{b \cdot b - \left(b \cdot b + \left(4 \cdot a\right) \cdot c\right)}{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2}}}\]
Alternative 28 Error 44.0 Cost 8256
\[\frac{\frac{b \cdot b - \left(b \cdot b + \left(4 \cdot a\right) \cdot c\right)}{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a \cdot 2}\]
Alternative 29 Error 34.0 Cost 7616
\[\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2} - \frac{b}{a \cdot 2}\]
Alternative 30 Error 33.8 Cost 7488
\[\frac{1}{\frac{a}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}}\]
Alternative 31 Error 33.8 Cost 7488
\[\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2} \cdot \frac{1}{a}\]
Alternative 32 Error 50.1 Cost 7424
\[\frac{a \cdot \left(c \cdot c\right)}{{b}^{3}} + \left(\frac{c}{b} - \frac{b}{a}\right)\]
Alternative 33 Error 33.7 Cost 7360
\[\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2}\]
Alternative 34 Error 33.8 Cost 7360
\[\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{0.5}{a}\]
Alternative 35 Error 44.5 Cost 7232
\[\frac{1}{\frac{a}{\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{2}}}\]
Alternative 36 Error 43.8 Cost 7104
\[\frac{1}{\frac{a}{\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{2}}}\]
Alternative 37 Error 44.5 Cost 7104
\[\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\]
Alternative 38 Error 43.8 Cost 6976
\[\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot 2}\]
Alternative 39 Error 45.3 Cost 704
\[\frac{-2 \cdot \frac{a \cdot c}{b}}{a \cdot 2}\]
Alternative 40 Error 45.2 Cost 640
\[\frac{1}{\frac{a}{\frac{\left(-b\right) - b}{2}}}\]
Alternative 41 Error 45.2 Cost 576
\[\frac{1}{\frac{a}{\frac{b \cdot -2}{2}}}\]
Alternative 42 Error 45.1 Cost 512
\[\frac{\left(-b\right) - b}{a \cdot 2}\]
Alternative 43 Error 45.3 Cost 448
\[\frac{c}{b} - \frac{b}{a}\]
Alternative 44 Error 45.1 Cost 448
\[\frac{b \cdot -2}{a \cdot 2}\]
Alternative 45 Error 56.4 Cost 448
\[\frac{b - b}{a \cdot 2}\]
Alternative 46 Error 45.1 Cost 256
\[\frac{-b}{a}\]
Alternative 47 Error 39.8 Cost 256
\[-\frac{c}{b}\]
Alternative 48 Error 61.6 Cost 64
\[1\]
Alternative 49 Error 56.4 Cost 64
\[0\]
Alternative 50 Error 61.6 Cost 64
\[-1\]
Error Derivation Split input into 3 regimes if b < -9.9342535108088619e120 Initial program 51.6
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
Simplified51.6
\[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2}}\]
Taylor expanded around -inf 2.8
\[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}}\]
Simplified2.8
\[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}}\]
if -9.9342535108088619e120 < b < 2.7658541670298186e-38 Initial program 13.5
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
Simplified13.5
\[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2}}\]
Using strategy rm Applied div-sub_binary64_76 13.5
\[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2} - \frac{b}{a \cdot 2}}\]
Simplified13.5
\[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2} - \frac{b}{a \cdot 2}}\]
if 2.7658541670298186e-38 < b Initial program 54.8
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
Simplified54.8
\[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2}}\]
Taylor expanded around inf 7.4
\[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
Simplified7.4
\[\leadsto \color{blue}{-\frac{c}{b}}\]
Simplified7.4
\[\leadsto \color{blue}{-\frac{c}{b}}\]
Recombined 3 regimes into one program. Final simplification9.9
\[\leadsto \begin{array}{l}
\mathbf{if}\;b \leq -9.934253510808862 \cdot 10^{+120}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.7658541670298186 \cdot 10^{-38}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2} - \frac{b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\
\end{array}\]
Reproduce herbie shell --seed 2021042
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))