
(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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -2e+148)
(/ (- b) a)
(if (<= b 3.9e-118)
(/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e+148) {
tmp = -b / a;
} else if (b <= 3.9e-118) {
tmp = (sqrt(((b * b) - (4.0 * (a * 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 <= (-2d+148)) then
tmp = -b / a
else if (b <= 3.9d-118) then
tmp = (sqrt(((b * b) - (4.0d0 * (a * 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 <= -2e+148) {
tmp = -b / a;
} else if (b <= 3.9e-118) {
tmp = (Math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e+148: tmp = -b / a elif b <= 3.9e-118: tmp = (math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e+148) tmp = Float64(Float64(-b) / a); elseif (b <= 3.9e-118) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * 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 <= -2e+148) tmp = -b / a; elseif (b <= 3.9e-118) tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e+148], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 3.9e-118], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $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 -2 \cdot 10^{+148}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 3.9 \cdot 10^{-118}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.0000000000000001e148Initial program 42.2%
neg-sub042.2%
associate-+l-42.2%
sub0-neg42.2%
neg-mul-142.2%
*-commutative42.2%
associate-*r/42.2%
Simplified42.2%
Taylor expanded in b around -inf 97.8%
associate-*r/97.8%
mul-1-neg97.8%
Simplified97.8%
if -2.0000000000000001e148 < b < 3.90000000000000001e-118Initial program 82.8%
if 3.90000000000000001e-118 < b Initial program 17.8%
neg-sub017.8%
associate-+l-17.8%
sub0-neg17.8%
neg-mul-117.8%
*-commutative17.8%
associate-*r/17.8%
Simplified17.8%
Taylor expanded in b around inf 86.6%
associate-*r/86.6%
neg-mul-186.6%
Simplified86.6%
Final simplification86.7%
(FPCore (a b c)
:precision binary64
(if (<= b -1.35e-58)
(- (/ c b) (/ b a))
(if (<= b 1.5e-117)
(* -0.5 (- (/ b a) (/ (sqrt (* a (* c -4.0))) a)))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.35e-58) {
tmp = (c / b) - (b / a);
} else if (b <= 1.5e-117) {
tmp = -0.5 * ((b / a) - (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.35d-58)) then
tmp = (c / b) - (b / a)
else if (b <= 1.5d-117) then
tmp = (-0.5d0) * ((b / a) - (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.35e-58) {
tmp = (c / b) - (b / a);
} else if (b <= 1.5e-117) {
tmp = -0.5 * ((b / a) - (Math.sqrt((a * (c * -4.0))) / a));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.35e-58: tmp = (c / b) - (b / a) elif b <= 1.5e-117: tmp = -0.5 * ((b / a) - (math.sqrt((a * (c * -4.0))) / a)) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.35e-58) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.5e-117) tmp = Float64(-0.5 * Float64(Float64(b / a) - Float64(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.35e-58) tmp = (c / b) - (b / a); elseif (b <= 1.5e-117) tmp = -0.5 * ((b / a) - (sqrt((a * (c * -4.0))) / a)); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.35e-58], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.5e-117], N[(-0.5 * N[(N[(b / a), $MachinePrecision] - N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.35 \cdot 10^{-58}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.5 \cdot 10^{-117}:\\
\;\;\;\;-0.5 \cdot \left(\frac{b}{a} - \frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.3499999999999999e-58Initial program 73.1%
neg-sub073.1%
associate-+l-73.1%
sub0-neg73.1%
neg-mul-173.1%
*-commutative73.1%
associate-*r/72.9%
Simplified72.9%
Taylor expanded in b around -inf 90.4%
mul-1-neg90.4%
unsub-neg90.4%
Simplified90.4%
if -1.3499999999999999e-58 < b < 1.49999999999999996e-117Initial program 70.7%
neg-sub070.7%
associate-+l-70.7%
sub0-neg70.7%
neg-mul-170.7%
*-commutative70.7%
associate-*r/70.6%
Simplified70.6%
fma-udef70.6%
associate-*r*70.6%
metadata-eval70.6%
distribute-rgt-neg-in70.6%
*-commutative70.6%
+-commutative70.6%
sub-neg70.6%
add-sqr-sqrt70.4%
pow270.4%
Applied egg-rr70.5%
Taylor expanded in a around inf 46.1%
Simplified66.4%
div-sub66.4%
Applied egg-rr66.4%
if 1.49999999999999996e-117 < b Initial program 17.8%
neg-sub017.8%
associate-+l-17.8%
sub0-neg17.8%
neg-mul-117.8%
*-commutative17.8%
associate-*r/17.8%
Simplified17.8%
Taylor expanded in b around inf 86.6%
associate-*r/86.6%
neg-mul-186.6%
Simplified86.6%
Final simplification82.9%
(FPCore (a b c)
:precision binary64
(if (<= b -7.2e-59)
(- (/ c b) (/ b a))
(if (<= b 1.5e-117)
(* -0.5 (/ (- b (sqrt (* a (* c -4.0)))) a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.2e-59) {
tmp = (c / b) - (b / a);
} else if (b <= 1.5e-117) {
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 <= (-7.2d-59)) then
tmp = (c / b) - (b / a)
else if (b <= 1.5d-117) 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 <= -7.2e-59) {
tmp = (c / b) - (b / a);
} else if (b <= 1.5e-117) {
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 <= -7.2e-59: tmp = (c / b) - (b / a) elif b <= 1.5e-117: 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 <= -7.2e-59) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.5e-117) 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 <= -7.2e-59) tmp = (c / b) - (b / a); elseif (b <= 1.5e-117) 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, -7.2e-59], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.5e-117], 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 -7.2 \cdot 10^{-59}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.5 \cdot 10^{-117}:\\
\;\;\;\;-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 < -7.20000000000000001e-59Initial program 73.1%
neg-sub073.1%
associate-+l-73.1%
sub0-neg73.1%
neg-mul-173.1%
*-commutative73.1%
associate-*r/72.9%
Simplified72.9%
Taylor expanded in b around -inf 90.4%
mul-1-neg90.4%
unsub-neg90.4%
Simplified90.4%
if -7.20000000000000001e-59 < b < 1.49999999999999996e-117Initial program 70.7%
neg-sub070.7%
associate-+l-70.7%
sub0-neg70.7%
neg-mul-170.7%
*-commutative70.7%
associate-*r/70.6%
Simplified70.6%
fma-udef70.6%
associate-*r*70.6%
metadata-eval70.6%
distribute-rgt-neg-in70.6%
*-commutative70.6%
+-commutative70.6%
sub-neg70.6%
add-sqr-sqrt70.4%
pow270.4%
Applied egg-rr70.5%
Taylor expanded in a around inf 46.1%
Simplified66.4%
if 1.49999999999999996e-117 < b Initial program 17.8%
neg-sub017.8%
associate-+l-17.8%
sub0-neg17.8%
neg-mul-117.8%
*-commutative17.8%
associate-*r/17.8%
Simplified17.8%
Taylor expanded in b around inf 86.6%
associate-*r/86.6%
neg-mul-186.6%
Simplified86.6%
Final simplification82.9%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-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 <= (-1d-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 <= -1e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-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 <= -1e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-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 -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 70.7%
neg-sub070.7%
associate-+l-70.7%
sub0-neg70.7%
neg-mul-170.7%
*-commutative70.7%
associate-*r/70.5%
Simplified70.5%
Taylor expanded in b around -inf 70.1%
mul-1-neg70.1%
unsub-neg70.1%
Simplified70.1%
if -9.999999999999969e-311 < b Initial program 31.5%
neg-sub031.5%
associate-+l-31.5%
sub0-neg31.5%
neg-mul-131.5%
*-commutative31.5%
associate-*r/31.4%
Simplified31.4%
Taylor expanded in b around inf 69.0%
associate-*r/69.0%
neg-mul-169.0%
Simplified69.0%
Final simplification69.6%
(FPCore (a b c) :precision binary64 (if (<= b 7.4e+47) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 7.4e+47) {
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 <= 7.4d+47) 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 <= 7.4e+47) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 7.4e+47: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 7.4e+47) 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 <= 7.4e+47) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 7.4e+47], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.4 \cdot 10^{+47}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 7.40000000000000081e47Initial program 65.7%
neg-sub065.7%
associate-+l-65.7%
sub0-neg65.7%
neg-mul-165.7%
*-commutative65.7%
associate-*r/65.6%
Simplified65.6%
Taylor expanded in b around -inf 49.6%
associate-*r/49.6%
mul-1-neg49.6%
Simplified49.6%
if 7.40000000000000081e47 < b Initial program 12.2%
neg-sub012.2%
associate-+l-12.2%
sub0-neg12.2%
neg-mul-112.2%
*-commutative12.2%
associate-*r/12.2%
Simplified12.2%
Taylor expanded in b around inf 85.7%
associate-*r/84.3%
frac-2neg84.3%
metadata-eval84.3%
metadata-eval84.3%
frac-times73.3%
*-commutative73.3%
metadata-eval73.3%
Applied egg-rr73.3%
associate-/r*84.4%
*-commutative84.4%
associate-*r*85.9%
metadata-eval85.9%
*-commutative85.9%
*-lft-identity85.9%
associate-*r/80.7%
Simplified80.7%
expm1-log1p-u76.9%
expm1-udef49.1%
associate-/l*49.1%
add-sqr-sqrt25.3%
sqrt-unprod32.4%
sqr-neg32.4%
sqrt-unprod15.4%
add-sqr-sqrt34.0%
Applied egg-rr34.0%
expm1-def33.5%
expm1-log1p33.7%
associate-/r/33.5%
*-inverses33.5%
*-lft-identity33.5%
Simplified33.5%
Final simplification45.3%
(FPCore (a b c) :precision binary64 (if (<= b 1.1e-301) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.1e-301) {
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.1d-301) 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.1e-301) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.1e-301: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.1e-301) 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 <= 1.1e-301) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.1e-301], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.1 \cdot 10^{-301}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 1.1e-301Initial program 70.9%
neg-sub070.9%
associate-+l-70.9%
sub0-neg70.9%
neg-mul-170.9%
*-commutative70.9%
associate-*r/70.8%
Simplified70.8%
Taylor expanded in b around -inf 69.4%
associate-*r/69.4%
mul-1-neg69.4%
Simplified69.4%
if 1.1e-301 < b Initial program 30.9%
neg-sub030.9%
associate-+l-30.9%
sub0-neg30.9%
neg-mul-130.9%
*-commutative30.9%
associate-*r/30.9%
Simplified30.9%
Taylor expanded in b around inf 69.5%
associate-*r/69.5%
neg-mul-169.5%
Simplified69.5%
Final simplification69.4%
(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.5%
neg-sub051.5%
associate-+l-51.5%
sub0-neg51.5%
neg-mul-151.5%
*-commutative51.5%
associate-*r/51.4%
Simplified51.4%
Taylor expanded in b around inf 30.8%
associate-*r/30.4%
frac-2neg30.4%
metadata-eval30.4%
metadata-eval30.4%
frac-times27.0%
*-commutative27.0%
metadata-eval27.0%
Applied egg-rr27.0%
associate-/r*30.5%
*-commutative30.5%
associate-*r*30.9%
metadata-eval30.9%
*-commutative30.9%
*-lft-identity30.9%
associate-*r/29.8%
Simplified29.8%
expm1-log1p-u27.8%
expm1-udef16.1%
associate-/l*16.1%
add-sqr-sqrt7.9%
sqrt-unprod10.5%
sqr-neg10.5%
sqrt-unprod5.2%
add-sqr-sqrt10.7%
Applied egg-rr10.7%
expm1-def10.6%
expm1-log1p11.1%
associate-/r/11.1%
*-inverses11.1%
*-lft-identity11.1%
Simplified11.1%
Final simplification11.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ (+ (- b) t_0) (* 2.0 a))
(/ c (* a (/ (- (- b) t_0) (* 2.0 a)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (4.0 * (a * c))));
double tmp;
if (b < 0.0) {
tmp = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-b - t_0) / (2.0 * a)));
}
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) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - (4.0d0 * (a * c))))
if (b < 0.0d0) then
tmp = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-b - t_0) / (2.0d0 * a)))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - (4.0 * (a * c))));
double tmp;
if (b < 0.0) {
tmp = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-b - t_0) / (2.0 * a)));
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (4.0 * (a * c)))) tmp = 0 if b < 0.0: tmp = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-b - t_0) / (2.0 * a))) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) tmp = 0.0 if (b < 0.0) tmp = Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); else tmp = Float64(c / Float64(a * Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)))); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - (4.0 * (a * c)))); tmp = 0.0; if (b < 0.0) tmp = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-b - t_0) / (2.0 * a))); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{\left(-b\right) + t_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t_0}{2 \cdot a}}\\
\end{array}
\end{array}
herbie shell --seed 2023181
(FPCore (a b c)
:name "quadp (p42, positive)"
: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)))