
(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 7 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 -7.5e-54)
(- (/ c b) (/ b a))
(if (<= b 3.5e-65)
(/ -1.0 (* a (/ 2.0 (- b (hypot (sqrt (* c (* a -4.0))) b)))))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.5e-54) {
tmp = (c / b) - (b / a);
} else if (b <= 3.5e-65) {
tmp = -1.0 / (a * (2.0 / (b - hypot(sqrt((c * (a * -4.0))), b))));
} else {
tmp = -c / b;
}
return tmp;
}
public static double code(double a, double b, double c) {
double tmp;
if (b <= -7.5e-54) {
tmp = (c / b) - (b / a);
} else if (b <= 3.5e-65) {
tmp = -1.0 / (a * (2.0 / (b - Math.hypot(Math.sqrt((c * (a * -4.0))), b))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.5e-54: tmp = (c / b) - (b / a) elif b <= 3.5e-65: tmp = -1.0 / (a * (2.0 / (b - math.hypot(math.sqrt((c * (a * -4.0))), b)))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.5e-54) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 3.5e-65) tmp = Float64(-1.0 / Float64(a * Float64(2.0 / Float64(b - hypot(sqrt(Float64(c * Float64(a * -4.0))), b))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7.5e-54) tmp = (c / b) - (b / a); elseif (b <= 3.5e-65) tmp = -1.0 / (a * (2.0 / (b - hypot(sqrt((c * (a * -4.0))), b)))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.5e-54], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.5e-65], N[(-1.0 / N[(a * N[(2.0 / N[(b - N[Sqrt[N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2 + b ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.5 \cdot 10^{-54}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 3.5 \cdot 10^{-65}:\\
\;\;\;\;\frac{-1}{a \cdot \frac{2}{b - \mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -4\right)}, b\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -7.5000000000000005e-54Initial program 68.4%
neg-sub068.4%
associate-+l-68.4%
sub0-neg68.4%
neg-mul-168.4%
associate-*l/68.1%
*-commutative68.1%
associate-/r*68.1%
/-rgt-identity68.1%
metadata-eval68.1%
Simplified68.2%
Taylor expanded in b around -inf 94.2%
mul-1-neg94.2%
unsub-neg94.2%
Simplified94.2%
if -7.5000000000000005e-54 < b < 3.50000000000000005e-65Initial program 76.6%
neg-sub076.6%
associate-+l-76.6%
sub0-neg76.6%
neg-mul-176.6%
associate-*l/76.5%
*-commutative76.5%
associate-/r*76.5%
/-rgt-identity76.5%
metadata-eval76.5%
Simplified76.5%
associate-*r/76.6%
clear-num76.5%
Applied egg-rr76.5%
*-un-lft-identity76.5%
times-frac76.4%
fma-udef76.4%
add-sqr-sqrt76.4%
hypot-def79.1%
Applied egg-rr79.1%
frac-2neg79.1%
metadata-eval79.1%
div-inv79.1%
*-commutative79.1%
div-inv79.2%
div-inv79.2%
metadata-eval79.2%
associate-*r*79.2%
Applied egg-rr79.2%
associate-*r/79.2%
metadata-eval79.2%
distribute-neg-frac79.2%
distribute-rgt-neg-in79.2%
metadata-eval79.2%
*-lft-identity79.2%
times-frac79.1%
/-rgt-identity79.1%
rem-square-sqrt0.0%
*-commutative0.0%
unpow20.0%
associate-*r*0.0%
unpow20.0%
rem-square-sqrt79.1%
Simplified79.1%
if 3.50000000000000005e-65 < b Initial program 14.6%
neg-sub014.6%
associate-+l-14.6%
sub0-neg14.6%
neg-mul-114.6%
associate-*l/14.5%
*-commutative14.5%
associate-/r*14.5%
/-rgt-identity14.5%
metadata-eval14.5%
Simplified14.5%
Taylor expanded in b around inf 87.8%
mul-1-neg87.8%
distribute-neg-frac87.8%
Simplified87.8%
Final simplification87.1%
(FPCore (a b c)
:precision binary64
(if (<= b -3.65e-6)
(/ (- b) a)
(if (<= b 8.8e-63)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.65e-6) {
tmp = -b / a;
} else if (b <= 8.8e-63) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = -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 <= (-3.65d-6)) then
tmp = -b / a
else if (b <= 8.8d-63) then
tmp = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.65e-6) {
tmp = -b / a;
} else if (b <= 8.8e-63) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.65e-6: tmp = -b / a elif b <= 8.8e-63: tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.65e-6) tmp = Float64(Float64(-b) / a); elseif (b <= 8.8e-63) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.65e-6) tmp = -b / a; elseif (b <= 8.8e-63) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.65e-6], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 8.8e-63], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.65 \cdot 10^{-6}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 8.8 \cdot 10^{-63}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.65000000000000021e-6Initial program 65.9%
neg-sub065.9%
associate-+l-65.9%
sub0-neg65.9%
neg-mul-165.9%
associate-*l/65.6%
*-commutative65.6%
associate-/r*65.6%
/-rgt-identity65.6%
metadata-eval65.6%
Simplified65.7%
Taylor expanded in b around -inf 96.1%
associate-*r/96.1%
mul-1-neg96.1%
Simplified96.1%
if -3.65000000000000021e-6 < b < 8.7999999999999998e-63Initial program 77.8%
if 8.7999999999999998e-63 < b Initial program 14.6%
neg-sub014.6%
associate-+l-14.6%
sub0-neg14.6%
neg-mul-114.6%
associate-*l/14.5%
*-commutative14.5%
associate-/r*14.5%
/-rgt-identity14.5%
metadata-eval14.5%
Simplified14.5%
Taylor expanded in b around inf 87.8%
mul-1-neg87.8%
distribute-neg-frac87.8%
Simplified87.8%
Final simplification86.6%
(FPCore (a b c)
:precision binary64
(if (<= b -1.02e-58)
(- (/ c b) (/ b a))
(if (<= b 2.9e-65)
(* -0.5 (/ (- b (sqrt (* a (* c -4.0)))) a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.02e-58) {
tmp = (c / b) - (b / a);
} else if (b <= 2.9e-65) {
tmp = -0.5 * ((b - sqrt((a * (c * -4.0)))) / a);
} else {
tmp = -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 <= (-1.02d-58)) then
tmp = (c / b) - (b / a)
else if (b <= 2.9d-65) then
tmp = (-0.5d0) * ((b - sqrt((a * (c * (-4.0d0))))) / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.02e-58) {
tmp = (c / b) - (b / a);
} else if (b <= 2.9e-65) {
tmp = -0.5 * ((b - Math.sqrt((a * (c * -4.0)))) / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.02e-58: tmp = (c / b) - (b / a) elif b <= 2.9e-65: tmp = -0.5 * ((b - math.sqrt((a * (c * -4.0)))) / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.02e-58) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 2.9e-65) tmp = Float64(-0.5 * Float64(Float64(b - sqrt(Float64(a * Float64(c * -4.0)))) / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.02e-58) tmp = (c / b) - (b / a); elseif (b <= 2.9e-65) tmp = -0.5 * ((b - sqrt((a * (c * -4.0)))) / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.02e-58], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.9e-65], N[(-0.5 * N[(N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.02 \cdot 10^{-58}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.9 \cdot 10^{-65}:\\
\;\;\;\;-0.5 \cdot \frac{b - \sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.0199999999999999e-58Initial program 68.4%
neg-sub068.4%
associate-+l-68.4%
sub0-neg68.4%
neg-mul-168.4%
associate-*l/68.1%
*-commutative68.1%
associate-/r*68.1%
/-rgt-identity68.1%
metadata-eval68.1%
Simplified68.2%
Taylor expanded in b around -inf 94.2%
mul-1-neg94.2%
unsub-neg94.2%
Simplified94.2%
if -1.0199999999999999e-58 < b < 2.8999999999999998e-65Initial program 76.6%
neg-sub076.6%
associate-+l-76.6%
sub0-neg76.6%
neg-mul-176.6%
associate-*l/76.5%
*-commutative76.5%
associate-/r*76.5%
/-rgt-identity76.5%
metadata-eval76.5%
Simplified76.5%
fma-udef76.5%
*-commutative76.5%
associate-*r*76.5%
metadata-eval76.5%
distribute-rgt-neg-in76.5%
*-commutative76.5%
distribute-lft-neg-in76.5%
+-commutative76.5%
sub-neg76.5%
add-sqr-sqrt76.2%
pow276.2%
Applied egg-rr76.2%
Taylor expanded in a around inf 41.3%
Simplified72.5%
if 2.8999999999999998e-65 < b Initial program 14.6%
neg-sub014.6%
associate-+l-14.6%
sub0-neg14.6%
neg-mul-114.6%
associate-*l/14.5%
*-commutative14.5%
associate-/r*14.5%
/-rgt-identity14.5%
metadata-eval14.5%
Simplified14.5%
Taylor expanded in b around inf 87.8%
mul-1-neg87.8%
distribute-neg-frac87.8%
Simplified87.8%
Final simplification85.0%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -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 <= (-2d-310)) then
tmp = (c / b) - (b / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 71.7%
neg-sub071.7%
associate-+l-71.7%
sub0-neg71.7%
neg-mul-171.7%
associate-*l/71.5%
*-commutative71.5%
associate-/r*71.5%
/-rgt-identity71.5%
metadata-eval71.5%
Simplified71.5%
Taylor expanded in b around -inf 67.3%
mul-1-neg67.3%
unsub-neg67.3%
Simplified67.3%
if -1.999999999999994e-310 < b Initial program 31.7%
neg-sub031.7%
associate-+l-31.7%
sub0-neg31.7%
neg-mul-131.7%
associate-*l/31.6%
*-commutative31.6%
associate-/r*31.6%
/-rgt-identity31.6%
metadata-eval31.6%
Simplified31.6%
Taylor expanded in b around inf 68.9%
mul-1-neg68.9%
distribute-neg-frac68.9%
Simplified68.9%
Final simplification68.1%
(FPCore (a b c) :precision binary64 (if (<= b 1.75e-16) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.75e-16) {
tmp = -b / a;
} else {
tmp = 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 <= 1.75d-16) then
tmp = -b / a
else
tmp = c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 1.75e-16) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.75e-16: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.75e-16) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 1.75e-16) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.75e-16], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.75 \cdot 10^{-16}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 1.75000000000000009e-16Initial program 70.8%
neg-sub070.8%
associate-+l-70.8%
sub0-neg70.8%
neg-mul-170.8%
associate-*l/70.6%
*-commutative70.6%
associate-/r*70.6%
/-rgt-identity70.6%
metadata-eval70.6%
Simplified70.6%
Taylor expanded in b around -inf 50.1%
associate-*r/50.1%
mul-1-neg50.1%
Simplified50.1%
if 1.75000000000000009e-16 < b Initial program 11.2%
neg-sub011.2%
associate-+l-11.2%
sub0-neg11.2%
neg-mul-111.2%
associate-*l/11.2%
*-commutative11.2%
associate-/r*11.2%
/-rgt-identity11.2%
metadata-eval11.2%
Simplified11.2%
Taylor expanded in b around inf 70.2%
expm1-log1p-u63.9%
expm1-udef28.0%
associate-*l*28.0%
*-commutative28.0%
Applied egg-rr28.0%
expm1-def63.9%
expm1-log1p70.2%
associate-*r*70.2%
associate-*r/70.3%
times-frac70.4%
*-commutative70.4%
associate-*r*70.4%
metadata-eval70.4%
*-commutative70.4%
neg-mul-170.4%
Simplified70.4%
expm1-log1p-u64.2%
expm1-udef27.9%
add-sqr-sqrt17.4%
sqrt-unprod26.3%
sqr-neg26.3%
sqrt-unprod16.9%
add-sqr-sqrt26.4%
*-commutative26.4%
*-commutative26.4%
times-frac26.6%
Applied egg-rr26.6%
expm1-def25.6%
expm1-log1p25.7%
*-inverses25.7%
*-lft-identity25.7%
Simplified25.7%
Final simplification42.3%
(FPCore (a b c) :precision binary64 (if (<= b 9.2e-281) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 9.2e-281) {
tmp = -b / a;
} else {
tmp = -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 <= 9.2d-281) then
tmp = -b / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 9.2e-281) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 9.2e-281: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 9.2e-281) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 9.2e-281) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 9.2e-281], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 9.2 \cdot 10^{-281}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 9.19999999999999956e-281Initial program 72.3%
neg-sub072.3%
associate-+l-72.3%
sub0-neg72.3%
neg-mul-172.3%
associate-*l/72.1%
*-commutative72.1%
associate-/r*72.1%
/-rgt-identity72.1%
metadata-eval72.1%
Simplified72.2%
Taylor expanded in b around -inf 65.6%
associate-*r/65.6%
mul-1-neg65.6%
Simplified65.6%
if 9.19999999999999956e-281 < b Initial program 30.0%
neg-sub030.0%
associate-+l-30.0%
sub0-neg30.0%
neg-mul-130.0%
associate-*l/30.0%
*-commutative30.0%
associate-/r*30.0%
/-rgt-identity30.0%
metadata-eval30.0%
Simplified30.0%
Taylor expanded in b around inf 70.5%
mul-1-neg70.5%
distribute-neg-frac70.5%
Simplified70.5%
Final simplification68.0%
(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 / 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 51.7%
neg-sub051.7%
associate-+l-51.7%
sub0-neg51.7%
neg-mul-151.7%
associate-*l/51.5%
*-commutative51.5%
associate-/r*51.5%
/-rgt-identity51.5%
metadata-eval51.5%
Simplified51.6%
Taylor expanded in b around inf 25.8%
expm1-log1p-u23.3%
expm1-udef11.1%
associate-*l*11.1%
*-commutative11.1%
Applied egg-rr11.1%
expm1-def23.3%
expm1-log1p25.8%
associate-*r*25.8%
associate-*r/25.8%
times-frac25.7%
*-commutative25.7%
associate-*r*25.7%
metadata-eval25.7%
*-commutative25.7%
neg-mul-125.7%
Simplified25.7%
expm1-log1p-u23.3%
expm1-udef10.9%
add-sqr-sqrt6.5%
sqrt-unprod9.5%
sqr-neg9.5%
sqrt-unprod5.8%
add-sqr-sqrt9.9%
*-commutative9.9%
*-commutative9.9%
times-frac10.1%
Applied egg-rr10.1%
expm1-def9.7%
expm1-log1p10.2%
*-inverses10.2%
*-lft-identity10.2%
Simplified10.2%
Final simplification10.2%
herbie shell --seed 2023252
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))