
(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 -3.5e+43)
(/ (- b) a)
(if (<= b 1.25e-137)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.5e+43) {
tmp = -b / a;
} else if (b <= 1.25e-137) {
tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - 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.5d+43)) then
tmp = -b / a
else if (b <= 1.25d-137) then
tmp = (sqrt(((b * b) - ((a * 4.0d0) * c))) - 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.5e+43) {
tmp = -b / a;
} else if (b <= 1.25e-137) {
tmp = (Math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.5e+43: tmp = -b / a elif b <= 1.25e-137: tmp = (math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.5e+43) tmp = Float64(Float64(-b) / a); elseif (b <= 1.25e-137) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - 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.5e+43) tmp = -b / a; elseif (b <= 1.25e-137) tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.5e+43], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.25e-137], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $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.5 \cdot 10^{+43}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.25 \cdot 10^{-137}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.5000000000000001e43Initial program 61.5%
neg-sub061.5%
associate-+l-61.5%
sub0-neg61.5%
neg-mul-161.5%
associate-*l/61.2%
*-commutative61.2%
associate-/r*61.3%
/-rgt-identity61.3%
metadata-eval61.3%
Simplified61.5%
Taylor expanded in b around -inf 95.3%
associate-*r/95.3%
mul-1-neg95.3%
Simplified95.3%
if -3.5000000000000001e43 < b < 1.25e-137Initial program 82.3%
if 1.25e-137 < b Initial program 19.1%
neg-sub019.1%
associate-+l-19.1%
sub0-neg19.1%
neg-mul-119.1%
associate-*l/19.1%
*-commutative19.1%
associate-/r*19.1%
/-rgt-identity19.1%
metadata-eval19.1%
Simplified19.1%
Taylor expanded in b around inf 83.9%
mul-1-neg83.9%
distribute-neg-frac83.9%
Simplified83.9%
Final simplification86.0%
(FPCore (a b c)
:precision binary64
(if (<= b -1.35e+42)
(/ (- b) a)
(if (<= b 1.25e-137)
(* (- b (sqrt (- (* b b) (* a (* 4.0 c))))) (/ -0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.35e+42) {
tmp = -b / a;
} else if (b <= 1.25e-137) {
tmp = (b - sqrt(((b * b) - (a * (4.0 * c))))) * (-0.5 / 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.35d+42)) then
tmp = -b / a
else if (b <= 1.25d-137) then
tmp = (b - sqrt(((b * b) - (a * (4.0d0 * c))))) * ((-0.5d0) / 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.35e+42) {
tmp = -b / a;
} else if (b <= 1.25e-137) {
tmp = (b - Math.sqrt(((b * b) - (a * (4.0 * c))))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.35e+42: tmp = -b / a elif b <= 1.25e-137: tmp = (b - math.sqrt(((b * b) - (a * (4.0 * c))))) * (-0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.35e+42) tmp = Float64(Float64(-b) / a); elseif (b <= 1.25e-137) tmp = Float64(Float64(b - sqrt(Float64(Float64(b * b) - Float64(a * Float64(4.0 * c))))) * Float64(-0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.35e+42) tmp = -b / a; elseif (b <= 1.25e-137) tmp = (b - sqrt(((b * b) - (a * (4.0 * c))))) * (-0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.35e+42], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.25e-137], N[(N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(4.0 * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.35 \cdot 10^{+42}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.25 \cdot 10^{-137}:\\
\;\;\;\;\left(b - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.35e42Initial program 62.7%
neg-sub062.7%
associate-+l-62.7%
sub0-neg62.7%
neg-mul-162.7%
associate-*l/62.5%
*-commutative62.5%
associate-/r*62.5%
/-rgt-identity62.5%
metadata-eval62.5%
Simplified62.7%
Taylor expanded in b around -inf 95.4%
associate-*r/95.4%
mul-1-neg95.4%
Simplified95.4%
if -1.35e42 < b < 1.25e-137Initial program 81.9%
neg-sub081.9%
associate-+l-81.9%
sub0-neg81.9%
neg-mul-181.9%
associate-*l/81.7%
*-commutative81.7%
associate-/r*81.7%
/-rgt-identity81.7%
metadata-eval81.7%
Simplified81.7%
fma-udef81.7%
*-commutative81.7%
associate-*r*81.7%
metadata-eval81.7%
distribute-rgt-neg-in81.7%
*-commutative81.7%
distribute-lft-neg-in81.7%
+-commutative81.7%
sub-neg81.7%
*-commutative81.7%
associate-*l*81.7%
Applied egg-rr81.7%
*-commutative81.7%
Simplified81.7%
if 1.25e-137 < b Initial program 19.1%
neg-sub019.1%
associate-+l-19.1%
sub0-neg19.1%
neg-mul-119.1%
associate-*l/19.1%
*-commutative19.1%
associate-/r*19.1%
/-rgt-identity19.1%
metadata-eval19.1%
Simplified19.1%
Taylor expanded in b around inf 83.9%
mul-1-neg83.9%
distribute-neg-frac83.9%
Simplified83.9%
Final simplification86.0%
(FPCore (a b c)
:precision binary64
(if (<= b -8e-38)
(/ (- b) a)
(if (<= b 1.2e-137)
(* (/ -0.5 a) (- b (sqrt (* a (* c -4.0)))))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8e-38) {
tmp = -b / a;
} else if (b <= 1.2e-137) {
tmp = (-0.5 / a) * (b - sqrt((a * (c * -4.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 <= (-8d-38)) then
tmp = -b / a
else if (b <= 1.2d-137) then
tmp = ((-0.5d0) / a) * (b - sqrt((a * (c * (-4.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 <= -8e-38) {
tmp = -b / a;
} else if (b <= 1.2e-137) {
tmp = (-0.5 / a) * (b - Math.sqrt((a * (c * -4.0))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8e-38: tmp = -b / a elif b <= 1.2e-137: tmp = (-0.5 / a) * (b - math.sqrt((a * (c * -4.0)))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8e-38) tmp = Float64(Float64(-b) / a); elseif (b <= 1.2e-137) tmp = Float64(Float64(-0.5 / a) * Float64(b - sqrt(Float64(a * Float64(c * -4.0))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -8e-38) tmp = -b / a; elseif (b <= 1.2e-137) tmp = (-0.5 / a) * (b - sqrt((a * (c * -4.0)))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8e-38], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.2e-137], N[(N[(-0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8 \cdot 10^{-38}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.2 \cdot 10^{-137}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -7.9999999999999997e-38Initial program 67.4%
neg-sub067.4%
associate-+l-67.4%
sub0-neg67.4%
neg-mul-167.4%
associate-*l/67.2%
*-commutative67.2%
associate-/r*67.2%
/-rgt-identity67.2%
metadata-eval67.2%
Simplified67.4%
Taylor expanded in b around -inf 91.1%
associate-*r/91.1%
mul-1-neg91.1%
Simplified91.1%
if -7.9999999999999997e-38 < b < 1.2e-137Initial program 80.2%
neg-sub080.2%
associate-+l-80.2%
sub0-neg80.2%
neg-mul-180.2%
associate-*l/80.1%
*-commutative80.1%
associate-/r*80.1%
/-rgt-identity80.1%
metadata-eval80.1%
Simplified80.1%
Taylor expanded in a around inf 73.0%
*-commutative73.0%
*-commutative73.0%
associate-*r*73.0%
Simplified73.0%
if 1.2e-137 < b Initial program 19.1%
neg-sub019.1%
associate-+l-19.1%
sub0-neg19.1%
neg-mul-119.1%
associate-*l/19.1%
*-commutative19.1%
associate-/r*19.1%
/-rgt-identity19.1%
metadata-eval19.1%
Simplified19.1%
Taylor expanded in b around inf 83.9%
mul-1-neg83.9%
distribute-neg-frac83.9%
Simplified83.9%
Final simplification82.9%
(FPCore (a b c)
:precision binary64
(if (<= b -2.5e-39)
(/ (- b) a)
(if (<= b 1.25e-137)
(/ (* -0.5 (- b (sqrt (* a (* c -4.0))))) a)
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.5e-39) {
tmp = -b / a;
} else if (b <= 1.25e-137) {
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 <= (-2.5d-39)) then
tmp = -b / a
else if (b <= 1.25d-137) 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 <= -2.5e-39) {
tmp = -b / a;
} else if (b <= 1.25e-137) {
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 <= -2.5e-39: tmp = -b / a elif b <= 1.25e-137: 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 <= -2.5e-39) tmp = Float64(Float64(-b) / a); elseif (b <= 1.25e-137) tmp = Float64(Float64(-0.5 * 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 <= -2.5e-39) tmp = -b / a; elseif (b <= 1.25e-137) 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, -2.5e-39], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.25e-137], N[(N[(-0.5 * N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.5 \cdot 10^{-39}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.25 \cdot 10^{-137}:\\
\;\;\;\;\frac{-0.5 \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.4999999999999999e-39Initial program 67.4%
neg-sub067.4%
associate-+l-67.4%
sub0-neg67.4%
neg-mul-167.4%
associate-*l/67.2%
*-commutative67.2%
associate-/r*67.2%
/-rgt-identity67.2%
metadata-eval67.2%
Simplified67.4%
Taylor expanded in b around -inf 91.1%
associate-*r/91.1%
mul-1-neg91.1%
Simplified91.1%
if -2.4999999999999999e-39 < b < 1.25e-137Initial program 80.2%
neg-sub080.2%
associate-+l-80.2%
sub0-neg80.2%
neg-mul-180.2%
associate-*l/80.1%
*-commutative80.1%
associate-/r*80.1%
/-rgt-identity80.1%
metadata-eval80.1%
Simplified80.1%
Taylor expanded in a around inf 73.0%
*-commutative73.0%
*-commutative73.0%
associate-*r*73.0%
Simplified73.0%
associate-*r/73.1%
Applied egg-rr73.1%
if 1.25e-137 < b Initial program 19.1%
neg-sub019.1%
associate-+l-19.1%
sub0-neg19.1%
neg-mul-119.1%
associate-*l/19.1%
*-commutative19.1%
associate-/r*19.1%
/-rgt-identity19.1%
metadata-eval19.1%
Simplified19.1%
Taylor expanded in b around inf 83.9%
mul-1-neg83.9%
distribute-neg-frac83.9%
Simplified83.9%
Final simplification82.9%
(FPCore (a b c) :precision binary64 (if (<= b -2.75e-304) (/ (- b) a) 0.0))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.75e-304) {
tmp = -b / a;
} else {
tmp = 0.0;
}
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.75d-304)) then
tmp = -b / a
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.75e-304) {
tmp = -b / a;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.75e-304: tmp = -b / a else: tmp = 0.0 return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.75e-304) tmp = Float64(Float64(-b) / a); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.75e-304) tmp = -b / a; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.75e-304], N[((-b) / a), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.75 \cdot 10^{-304}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -2.75000000000000017e-304Initial program 72.6%
neg-sub072.6%
associate-+l-72.6%
sub0-neg72.6%
neg-mul-172.6%
associate-*l/72.4%
*-commutative72.4%
associate-/r*72.4%
/-rgt-identity72.4%
metadata-eval72.4%
Simplified72.5%
Taylor expanded in b around -inf 64.2%
associate-*r/64.2%
mul-1-neg64.2%
Simplified64.2%
if -2.75000000000000017e-304 < b Initial program 30.8%
neg-sub030.8%
associate-+l-30.8%
sub0-neg30.8%
neg-mul-130.8%
associate-*l/30.8%
*-commutative30.8%
associate-/r*30.8%
/-rgt-identity30.8%
metadata-eval30.8%
Simplified30.8%
*-commutative30.8%
sub-neg30.8%
distribute-lft-in29.8%
Applied egg-rr29.8%
Taylor expanded in c around 0 9.4%
distribute-rgt-out9.4%
metadata-eval9.4%
mul0-rgt16.4%
Simplified16.4%
Final simplification38.7%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
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 <= (-5d-310)) 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 <= -5e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) 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 <= -5e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 73.0%
neg-sub073.0%
associate-+l-73.0%
sub0-neg73.0%
neg-mul-173.0%
associate-*l/72.8%
*-commutative72.8%
associate-/r*72.8%
/-rgt-identity72.8%
metadata-eval72.8%
Simplified72.9%
Taylor expanded in b around -inf 63.2%
associate-*r/63.2%
mul-1-neg63.2%
Simplified63.2%
if -4.999999999999985e-310 < b Initial program 29.8%
neg-sub029.8%
associate-+l-29.8%
sub0-neg29.8%
neg-mul-129.8%
associate-*l/29.8%
*-commutative29.8%
associate-/r*29.8%
/-rgt-identity29.8%
metadata-eval29.8%
Simplified29.8%
Taylor expanded in b around inf 70.6%
mul-1-neg70.6%
distribute-neg-frac70.6%
Simplified70.6%
Final simplification67.2%
(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 50.3%
neg-sub050.3%
associate-+l-50.3%
sub0-neg50.3%
neg-mul-150.3%
associate-*l/50.1%
*-commutative50.1%
associate-/r*50.2%
/-rgt-identity50.2%
metadata-eval50.2%
Simplified50.2%
*-commutative50.2%
sub-neg50.2%
distribute-lft-in49.6%
Applied egg-rr49.6%
Taylor expanded in c around 0 6.2%
distribute-rgt-out6.2%
metadata-eval6.2%
mul0-rgt10.1%
Simplified10.1%
Final simplification10.1%
herbie shell --seed 2023257
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))