
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b 2.0)
(/ (- (sqrt (* c (+ (* -4.0 a) (/ (pow b 2.0) c)))) b) (* 2.0 a))
(-
(*
a
(+
(/ (* c c) (pow (- b) 3.0))
(*
a
(+
(* -2.0 (/ (pow c 3.0) (pow b 5.0)))
(* -5.0 (/ (* a (pow c 4.0)) (pow b 7.0)))))))
(/ c b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.0) {
tmp = (sqrt((c * ((-4.0 * a) + (pow(b, 2.0) / c)))) - b) / (2.0 * a);
} else {
tmp = (a * (((c * c) / pow(-b, 3.0)) + (a * ((-2.0 * (pow(c, 3.0) / pow(b, 5.0))) + (-5.0 * ((a * pow(c, 4.0)) / pow(b, 7.0))))))) - (c / b);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= 2.0d0) then
tmp = (sqrt((c * (((-4.0d0) * a) + ((b ** 2.0d0) / c)))) - b) / (2.0d0 * a)
else
tmp = (a * (((c * c) / (-b ** 3.0d0)) + (a * (((-2.0d0) * ((c ** 3.0d0) / (b ** 5.0d0))) + ((-5.0d0) * ((a * (c ** 4.0d0)) / (b ** 7.0d0))))))) - (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 2.0) {
tmp = (Math.sqrt((c * ((-4.0 * a) + (Math.pow(b, 2.0) / c)))) - b) / (2.0 * a);
} else {
tmp = (a * (((c * c) / Math.pow(-b, 3.0)) + (a * ((-2.0 * (Math.pow(c, 3.0) / Math.pow(b, 5.0))) + (-5.0 * ((a * Math.pow(c, 4.0)) / Math.pow(b, 7.0))))))) - (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.0: tmp = (math.sqrt((c * ((-4.0 * a) + (math.pow(b, 2.0) / c)))) - b) / (2.0 * a) else: tmp = (a * (((c * c) / math.pow(-b, 3.0)) + (a * ((-2.0 * (math.pow(c, 3.0) / math.pow(b, 5.0))) + (-5.0 * ((a * math.pow(c, 4.0)) / math.pow(b, 7.0))))))) - (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.0) tmp = Float64(Float64(sqrt(Float64(c * Float64(Float64(-4.0 * a) + Float64((b ^ 2.0) / c)))) - b) / Float64(2.0 * a)); else tmp = Float64(Float64(a * Float64(Float64(Float64(c * c) / (Float64(-b) ^ 3.0)) + Float64(a * Float64(Float64(-2.0 * Float64((c ^ 3.0) / (b ^ 5.0))) + Float64(-5.0 * Float64(Float64(a * (c ^ 4.0)) / (b ^ 7.0))))))) - Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2.0) tmp = (sqrt((c * ((-4.0 * a) + ((b ^ 2.0) / c)))) - b) / (2.0 * a); else tmp = (a * (((c * c) / (-b ^ 3.0)) + (a * ((-2.0 * ((c ^ 3.0) / (b ^ 5.0))) + (-5.0 * ((a * (c ^ 4.0)) / (b ^ 7.0))))))) - (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.0], N[(N[(N[Sqrt[N[(c * N[(N[(-4.0 * a), $MachinePrecision] + N[(N[Power[b, 2.0], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(a * N[(N[(N[(c * c), $MachinePrecision] / N[Power[(-b), 3.0], $MachinePrecision]), $MachinePrecision] + N[(a * N[(N[(-2.0 * N[(N[Power[c, 3.0], $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-5.0 * N[(N[(a * N[Power[c, 4.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(-4 \cdot a + \frac{{b}^{2}}{c}\right)} - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;a \cdot \left(\frac{c \cdot c}{{\left(-b\right)}^{3}} + a \cdot \left(-2 \cdot \frac{{c}^{3}}{{b}^{5}} + -5 \cdot \frac{a \cdot {c}^{4}}{{b}^{7}}\right)\right) - \frac{c}{b}\\
\end{array}
\end{array}
if b < 2Initial program 86.0%
*-commutative86.0%
+-commutative86.0%
sqr-neg86.0%
unsub-neg86.0%
sqr-neg86.0%
fma-neg86.0%
distribute-lft-neg-in86.0%
*-commutative86.0%
*-commutative86.0%
distribute-rgt-neg-in86.0%
metadata-eval86.0%
Simplified86.0%
Taylor expanded in c around inf 86.0%
if 2 < b Initial program 45.8%
*-commutative45.8%
+-commutative45.8%
sqr-neg45.8%
unsub-neg45.8%
sqr-neg45.8%
fma-neg45.9%
distribute-lft-neg-in45.9%
*-commutative45.9%
*-commutative45.9%
distribute-rgt-neg-in45.9%
metadata-eval45.9%
Simplified45.9%
Taylor expanded in a around 0 95.5%
Taylor expanded in c around 0 95.5%
associate-*r/95.5%
Applied egg-rr95.5%
associate-*r/95.5%
mul-1-neg95.5%
distribute-neg-frac295.5%
cube-neg95.5%
Simplified95.5%
unpow295.5%
Applied egg-rr95.5%
Final simplification93.7%
(FPCore (a b c)
:precision binary64
(if (<= b 2.0)
(/ (- (sqrt (* c (+ (* -4.0 a) (/ (pow b 2.0) c)))) b) (* 2.0 a))
(/
(fma
a
(- (* a (/ (* -2.0 (pow c 3.0)) (pow b 4.0))) (pow (/ c b) 2.0))
(- c))
b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.0) {
tmp = (sqrt((c * ((-4.0 * a) + (pow(b, 2.0) / c)))) - b) / (2.0 * a);
} else {
tmp = fma(a, ((a * ((-2.0 * pow(c, 3.0)) / pow(b, 4.0))) - pow((c / b), 2.0)), -c) / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 2.0) tmp = Float64(Float64(sqrt(Float64(c * Float64(Float64(-4.0 * a) + Float64((b ^ 2.0) / c)))) - b) / Float64(2.0 * a)); else tmp = Float64(fma(a, Float64(Float64(a * Float64(Float64(-2.0 * (c ^ 3.0)) / (b ^ 4.0))) - (Float64(c / b) ^ 2.0)), Float64(-c)) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 2.0], N[(N[(N[Sqrt[N[(c * N[(N[(-4.0 * a), $MachinePrecision] + N[(N[Power[b, 2.0], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(a * N[(N[(a * N[(N[(-2.0 * N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Power[N[(c / b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + (-c)), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(-4 \cdot a + \frac{{b}^{2}}{c}\right)} - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, a \cdot \frac{-2 \cdot {c}^{3}}{{b}^{4}} - {\left(\frac{c}{b}\right)}^{2}, -c\right)}{b}\\
\end{array}
\end{array}
if b < 2Initial program 86.0%
*-commutative86.0%
+-commutative86.0%
sqr-neg86.0%
unsub-neg86.0%
sqr-neg86.0%
fma-neg86.0%
distribute-lft-neg-in86.0%
*-commutative86.0%
*-commutative86.0%
distribute-rgt-neg-in86.0%
metadata-eval86.0%
Simplified86.0%
Taylor expanded in c around inf 86.0%
if 2 < b Initial program 45.8%
*-commutative45.8%
+-commutative45.8%
sqr-neg45.8%
unsub-neg45.8%
sqr-neg45.8%
fma-neg45.9%
distribute-lft-neg-in45.9%
*-commutative45.9%
*-commutative45.9%
distribute-rgt-neg-in45.9%
metadata-eval45.9%
Simplified45.9%
Taylor expanded in b around inf 93.2%
expm1-log1p-u61.5%
expm1-undefine51.9%
neg-mul-151.9%
+-commutative51.9%
fma-define51.9%
associate-/l*51.9%
Applied egg-rr51.9%
sub-neg51.9%
metadata-eval51.9%
+-commutative51.9%
log1p-undefine51.9%
rem-exp-log83.5%
fma-undefine83.5%
neg-mul-183.5%
distribute-neg-in83.5%
+-commutative83.5%
unsub-neg83.5%
+-commutative83.5%
fma-define83.5%
Simplified83.5%
Taylor expanded in c around 0 93.0%
Taylor expanded in a around 0 93.2%
neg-mul-193.2%
+-commutative93.2%
fma-define93.2%
mul-1-neg93.2%
unpow293.2%
unpow293.2%
times-frac93.2%
unpow293.2%
unsub-neg93.2%
*-commutative93.2%
associate-/l*93.2%
associate-*l*93.2%
*-commutative93.2%
associate-*r/93.2%
Simplified93.2%
Final simplification91.8%
(FPCore (a b c)
:precision binary64
(if (<= b 2.1)
(/ (- (sqrt (* c (+ (* -4.0 a) (/ (pow b 2.0) c)))) b) (* 2.0 a))
(*
c
(+
(* c (- (* -2.0 (/ (* c (pow a 2.0)) (pow b 5.0))) (/ a (pow b 3.0))))
(/ -1.0 b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.1) {
tmp = (sqrt((c * ((-4.0 * a) + (pow(b, 2.0) / c)))) - b) / (2.0 * a);
} else {
tmp = c * ((c * ((-2.0 * ((c * pow(a, 2.0)) / pow(b, 5.0))) - (a / pow(b, 3.0)))) + (-1.0 / b));
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= 2.1d0) then
tmp = (sqrt((c * (((-4.0d0) * a) + ((b ** 2.0d0) / c)))) - b) / (2.0d0 * a)
else
tmp = c * ((c * (((-2.0d0) * ((c * (a ** 2.0d0)) / (b ** 5.0d0))) - (a / (b ** 3.0d0)))) + ((-1.0d0) / b))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 2.1) {
tmp = (Math.sqrt((c * ((-4.0 * a) + (Math.pow(b, 2.0) / c)))) - b) / (2.0 * a);
} else {
tmp = c * ((c * ((-2.0 * ((c * Math.pow(a, 2.0)) / Math.pow(b, 5.0))) - (a / Math.pow(b, 3.0)))) + (-1.0 / b));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.1: tmp = (math.sqrt((c * ((-4.0 * a) + (math.pow(b, 2.0) / c)))) - b) / (2.0 * a) else: tmp = c * ((c * ((-2.0 * ((c * math.pow(a, 2.0)) / math.pow(b, 5.0))) - (a / math.pow(b, 3.0)))) + (-1.0 / b)) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.1) tmp = Float64(Float64(sqrt(Float64(c * Float64(Float64(-4.0 * a) + Float64((b ^ 2.0) / c)))) - b) / Float64(2.0 * a)); else tmp = Float64(c * Float64(Float64(c * Float64(Float64(-2.0 * Float64(Float64(c * (a ^ 2.0)) / (b ^ 5.0))) - Float64(a / (b ^ 3.0)))) + Float64(-1.0 / b))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2.1) tmp = (sqrt((c * ((-4.0 * a) + ((b ^ 2.0) / c)))) - b) / (2.0 * a); else tmp = c * ((c * ((-2.0 * ((c * (a ^ 2.0)) / (b ^ 5.0))) - (a / (b ^ 3.0)))) + (-1.0 / b)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.1], N[(N[(N[Sqrt[N[(c * N[(N[(-4.0 * a), $MachinePrecision] + N[(N[Power[b, 2.0], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c * N[(N[(c * N[(N[(-2.0 * N[(N[(c * N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.1:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(-4 \cdot a + \frac{{b}^{2}}{c}\right)} - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;c \cdot \left(c \cdot \left(-2 \cdot \frac{c \cdot {a}^{2}}{{b}^{5}} - \frac{a}{{b}^{3}}\right) + \frac{-1}{b}\right)\\
\end{array}
\end{array}
if b < 2.10000000000000009Initial program 86.0%
*-commutative86.0%
+-commutative86.0%
sqr-neg86.0%
unsub-neg86.0%
sqr-neg86.0%
fma-neg86.0%
distribute-lft-neg-in86.0%
*-commutative86.0%
*-commutative86.0%
distribute-rgt-neg-in86.0%
metadata-eval86.0%
Simplified86.0%
Taylor expanded in c around inf 86.0%
if 2.10000000000000009 < b Initial program 45.8%
*-commutative45.8%
+-commutative45.8%
sqr-neg45.8%
unsub-neg45.8%
sqr-neg45.8%
fma-neg45.9%
distribute-lft-neg-in45.9%
*-commutative45.9%
*-commutative45.9%
distribute-rgt-neg-in45.9%
metadata-eval45.9%
Simplified45.9%
Taylor expanded in c around 0 93.0%
Final simplification91.7%
(FPCore (a b c)
:precision binary64
(if (<= b 2.0)
(/ (- (sqrt (* c (+ (* -4.0 a) (/ (pow b 2.0) c)))) b) (* 2.0 a))
(/
(*
c
(+
-1.0
(* c (* a (+ (* -2.0 (/ (* c a) (pow b 4.0))) (/ -1.0 (pow b 2.0)))))))
b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.0) {
tmp = (sqrt((c * ((-4.0 * a) + (pow(b, 2.0) / c)))) - b) / (2.0 * a);
} else {
tmp = (c * (-1.0 + (c * (a * ((-2.0 * ((c * a) / pow(b, 4.0))) + (-1.0 / pow(b, 2.0))))))) / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= 2.0d0) then
tmp = (sqrt((c * (((-4.0d0) * a) + ((b ** 2.0d0) / c)))) - b) / (2.0d0 * a)
else
tmp = (c * ((-1.0d0) + (c * (a * (((-2.0d0) * ((c * a) / (b ** 4.0d0))) + ((-1.0d0) / (b ** 2.0d0))))))) / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 2.0) {
tmp = (Math.sqrt((c * ((-4.0 * a) + (Math.pow(b, 2.0) / c)))) - b) / (2.0 * a);
} else {
tmp = (c * (-1.0 + (c * (a * ((-2.0 * ((c * a) / Math.pow(b, 4.0))) + (-1.0 / Math.pow(b, 2.0))))))) / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.0: tmp = (math.sqrt((c * ((-4.0 * a) + (math.pow(b, 2.0) / c)))) - b) / (2.0 * a) else: tmp = (c * (-1.0 + (c * (a * ((-2.0 * ((c * a) / math.pow(b, 4.0))) + (-1.0 / math.pow(b, 2.0))))))) / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.0) tmp = Float64(Float64(sqrt(Float64(c * Float64(Float64(-4.0 * a) + Float64((b ^ 2.0) / c)))) - b) / Float64(2.0 * a)); else tmp = Float64(Float64(c * Float64(-1.0 + Float64(c * Float64(a * Float64(Float64(-2.0 * Float64(Float64(c * a) / (b ^ 4.0))) + Float64(-1.0 / (b ^ 2.0))))))) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2.0) tmp = (sqrt((c * ((-4.0 * a) + ((b ^ 2.0) / c)))) - b) / (2.0 * a); else tmp = (c * (-1.0 + (c * (a * ((-2.0 * ((c * a) / (b ^ 4.0))) + (-1.0 / (b ^ 2.0))))))) / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.0], N[(N[(N[Sqrt[N[(c * N[(N[(-4.0 * a), $MachinePrecision] + N[(N[Power[b, 2.0], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(c * N[(-1.0 + N[(c * N[(a * N[(N[(-2.0 * N[(N[(c * a), $MachinePrecision] / N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(-4 \cdot a + \frac{{b}^{2}}{c}\right)} - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \left(-1 + c \cdot \left(a \cdot \left(-2 \cdot \frac{c \cdot a}{{b}^{4}} + \frac{-1}{{b}^{2}}\right)\right)\right)}{b}\\
\end{array}
\end{array}
if b < 2Initial program 86.0%
*-commutative86.0%
+-commutative86.0%
sqr-neg86.0%
unsub-neg86.0%
sqr-neg86.0%
fma-neg86.0%
distribute-lft-neg-in86.0%
*-commutative86.0%
*-commutative86.0%
distribute-rgt-neg-in86.0%
metadata-eval86.0%
Simplified86.0%
Taylor expanded in c around inf 86.0%
if 2 < b Initial program 45.8%
*-commutative45.8%
+-commutative45.8%
sqr-neg45.8%
unsub-neg45.8%
sqr-neg45.8%
fma-neg45.9%
distribute-lft-neg-in45.9%
*-commutative45.9%
*-commutative45.9%
distribute-rgt-neg-in45.9%
metadata-eval45.9%
Simplified45.9%
Taylor expanded in b around inf 93.2%
expm1-log1p-u61.5%
expm1-undefine51.9%
neg-mul-151.9%
+-commutative51.9%
fma-define51.9%
associate-/l*51.9%
Applied egg-rr51.9%
sub-neg51.9%
metadata-eval51.9%
+-commutative51.9%
log1p-undefine51.9%
rem-exp-log83.5%
fma-undefine83.5%
neg-mul-183.5%
distribute-neg-in83.5%
+-commutative83.5%
unsub-neg83.5%
+-commutative83.5%
fma-define83.5%
Simplified83.5%
Taylor expanded in c around 0 93.0%
Taylor expanded in a around 0 93.0%
Final simplification91.7%
(FPCore (a b c) :precision binary64 (if (<= b 5.6) (/ (- (sqrt (fma b b (* c (* -4.0 a)))) b) (* 2.0 a)) (/ (+ c (* a (pow (/ c (- b)) 2.0))) (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 5.6) {
tmp = (sqrt(fma(b, b, (c * (-4.0 * a)))) - b) / (2.0 * a);
} else {
tmp = (c + (a * pow((c / -b), 2.0))) / -b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 5.6) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(-4.0 * a)))) - b) / Float64(2.0 * a)); else tmp = Float64(Float64(c + Float64(a * (Float64(c / Float64(-b)) ^ 2.0))) / Float64(-b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 5.6], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(-4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(c + N[(a * N[Power[N[(c / (-b)), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5.6:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(-4 \cdot a\right)\right)} - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c + a \cdot {\left(\frac{c}{-b}\right)}^{2}}{-b}\\
\end{array}
\end{array}
if b < 5.5999999999999996Initial program 84.1%
*-commutative84.1%
+-commutative84.1%
sqr-neg84.1%
unsub-neg84.1%
sqr-neg84.1%
fma-neg84.1%
distribute-lft-neg-in84.1%
*-commutative84.1%
*-commutative84.1%
distribute-rgt-neg-in84.1%
metadata-eval84.1%
Simplified84.1%
if 5.5999999999999996 < b Initial program 44.3%
*-commutative44.3%
+-commutative44.3%
sqr-neg44.3%
unsub-neg44.3%
sqr-neg44.3%
fma-neg44.4%
distribute-lft-neg-in44.4%
*-commutative44.4%
*-commutative44.4%
distribute-rgt-neg-in44.4%
metadata-eval44.4%
Simplified44.4%
Taylor expanded in a around 0 89.7%
mul-1-neg89.7%
unsub-neg89.7%
mul-1-neg89.7%
distribute-neg-frac289.7%
associate-/l*89.7%
Simplified89.7%
Taylor expanded in b around inf 89.7%
distribute-lft-out89.7%
associate-*r/89.7%
mul-1-neg89.7%
associate-*r/89.7%
distribute-neg-frac289.7%
+-commutative89.7%
fma-define89.7%
unpow289.7%
unpow289.7%
times-frac89.7%
sqr-neg89.7%
distribute-frac-neg289.7%
distribute-frac-neg289.7%
unpow289.7%
Simplified89.7%
fma-undefine89.7%
Applied egg-rr89.7%
Final simplification88.5%
(FPCore (a b c) :precision binary64 (if (<= b 5.6) (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a)) (/ (+ c (* a (pow (/ c (- b)) 2.0))) (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 5.6) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a);
} else {
tmp = (c + (a * pow((c / -b), 2.0))) / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= 5.6d0) then
tmp = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (2.0d0 * a)
else
tmp = (c + (a * ((c / -b) ** 2.0d0))) / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 5.6) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a);
} else {
tmp = (c + (a * Math.pow((c / -b), 2.0))) / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 5.6: tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a) else: tmp = (c + (a * math.pow((c / -b), 2.0))) / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 5.6) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(2.0 * a)); else tmp = Float64(Float64(c + Float64(a * (Float64(c / Float64(-b)) ^ 2.0))) / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 5.6) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a); else tmp = (c + (a * ((c / -b) ^ 2.0))) / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 5.6], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(c + N[(a * N[Power[N[(c / (-b)), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5.6:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c + a \cdot {\left(\frac{c}{-b}\right)}^{2}}{-b}\\
\end{array}
\end{array}
if b < 5.5999999999999996Initial program 84.1%
if 5.5999999999999996 < b Initial program 44.3%
*-commutative44.3%
+-commutative44.3%
sqr-neg44.3%
unsub-neg44.3%
sqr-neg44.3%
fma-neg44.4%
distribute-lft-neg-in44.4%
*-commutative44.4%
*-commutative44.4%
distribute-rgt-neg-in44.4%
metadata-eval44.4%
Simplified44.4%
Taylor expanded in a around 0 89.7%
mul-1-neg89.7%
unsub-neg89.7%
mul-1-neg89.7%
distribute-neg-frac289.7%
associate-/l*89.7%
Simplified89.7%
Taylor expanded in b around inf 89.7%
distribute-lft-out89.7%
associate-*r/89.7%
mul-1-neg89.7%
associate-*r/89.7%
distribute-neg-frac289.7%
+-commutative89.7%
fma-define89.7%
unpow289.7%
unpow289.7%
times-frac89.7%
sqr-neg89.7%
distribute-frac-neg289.7%
distribute-frac-neg289.7%
unpow289.7%
Simplified89.7%
fma-undefine89.7%
Applied egg-rr89.7%
Final simplification88.5%
(FPCore (a b c) :precision binary64 (/ (+ c (* a (pow (/ c (- b)) 2.0))) (- b)))
double code(double a, double b, double c) {
return (c + (a * pow((c / -b), 2.0))) / -b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (c + (a * ((c / -b) ** 2.0d0))) / -b
end function
public static double code(double a, double b, double c) {
return (c + (a * Math.pow((c / -b), 2.0))) / -b;
}
def code(a, b, c): return (c + (a * math.pow((c / -b), 2.0))) / -b
function code(a, b, c) return Float64(Float64(c + Float64(a * (Float64(c / Float64(-b)) ^ 2.0))) / Float64(-b)) end
function tmp = code(a, b, c) tmp = (c + (a * ((c / -b) ^ 2.0))) / -b; end
code[a_, b_, c_] := N[(N[(c + N[(a * N[Power[N[(c / (-b)), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-b)), $MachinePrecision]
\begin{array}{l}
\\
\frac{c + a \cdot {\left(\frac{c}{-b}\right)}^{2}}{-b}
\end{array}
Initial program 53.3%
*-commutative53.3%
+-commutative53.3%
sqr-neg53.3%
unsub-neg53.3%
sqr-neg53.3%
fma-neg53.4%
distribute-lft-neg-in53.4%
*-commutative53.4%
*-commutative53.4%
distribute-rgt-neg-in53.4%
metadata-eval53.4%
Simplified53.4%
Taylor expanded in a around 0 81.9%
mul-1-neg81.9%
unsub-neg81.9%
mul-1-neg81.9%
distribute-neg-frac281.9%
associate-/l*81.9%
Simplified81.9%
Taylor expanded in b around inf 81.9%
distribute-lft-out81.9%
associate-*r/81.9%
mul-1-neg81.9%
associate-*r/81.9%
distribute-neg-frac281.9%
+-commutative81.9%
fma-define81.9%
unpow281.9%
unpow281.9%
times-frac81.9%
sqr-neg81.9%
distribute-frac-neg281.9%
distribute-frac-neg281.9%
unpow281.9%
Simplified81.9%
fma-undefine81.9%
Applied egg-rr81.9%
Final simplification81.9%
(FPCore (a b c) :precision binary64 (/ c (- b)))
double code(double a, double b, double c) {
return c / -b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / -b
end function
public static double code(double a, double b, double c) {
return c / -b;
}
def code(a, b, c): return c / -b
function code(a, b, c) return Float64(c / Float64(-b)) end
function tmp = code(a, b, c) tmp = c / -b; end
code[a_, b_, c_] := N[(c / (-b)), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{-b}
\end{array}
Initial program 53.3%
*-commutative53.3%
+-commutative53.3%
sqr-neg53.3%
unsub-neg53.3%
sqr-neg53.3%
fma-neg53.4%
distribute-lft-neg-in53.4%
*-commutative53.4%
*-commutative53.4%
distribute-rgt-neg-in53.4%
metadata-eval53.4%
Simplified53.4%
Taylor expanded in b around inf 66.0%
associate-*r/66.0%
mul-1-neg66.0%
Simplified66.0%
Final simplification66.0%
(FPCore (a b c) :precision binary64 0.0)
double code(double a, double b, double c) {
return 0.0;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = 0.0d0
end function
public static double code(double a, double b, double c) {
return 0.0;
}
def code(a, b, c): return 0.0
function code(a, b, c) return 0.0 end
function tmp = code(a, b, c) tmp = 0.0; end
code[a_, b_, c_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 53.3%
*-commutative53.3%
+-commutative53.3%
sqr-neg53.3%
unsub-neg53.3%
sqr-neg53.3%
fma-neg53.4%
distribute-lft-neg-in53.4%
*-commutative53.4%
*-commutative53.4%
distribute-rgt-neg-in53.4%
metadata-eval53.4%
Simplified53.4%
Taylor expanded in b around inf 66.0%
associate-*r/66.0%
mul-1-neg66.0%
Simplified66.0%
distribute-frac-neg66.0%
distribute-frac-neg266.0%
expm1-log1p-u60.3%
expm1-undefine46.2%
Applied egg-rr46.2%
sub-neg46.2%
metadata-eval46.2%
+-commutative46.2%
log1p-undefine46.2%
rem-exp-log51.9%
distribute-frac-neg251.9%
unsub-neg51.9%
Simplified51.9%
Taylor expanded in c around 0 3.2%
Final simplification3.2%
herbie shell --seed 2024143
(FPCore (a b c)
:name "Quadratic roots, narrow range"
:precision binary64
:pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))