
(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 8 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
(let* ((t_0 (sqrt (- (* b b) (* c (* a 4.0))))))
(if (<= b -4.2e+108)
(- (/ c b) (/ b a))
(if (<= b 2e-309)
(/ (- t_0 b) (* a 2.0))
(if (<= b 2.2e-28)
(/ (* (* a 4.0) (/ c (- (- b) t_0))) (* a 2.0))
(/ (- c) b))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (a * 4.0))));
double tmp;
if (b <= -4.2e+108) {
tmp = (c / b) - (b / a);
} else if (b <= 2e-309) {
tmp = (t_0 - b) / (a * 2.0);
} else if (b <= 2.2e-28) {
tmp = ((a * 4.0) * (c / (-b - t_0))) / (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) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - (c * (a * 4.0d0))))
if (b <= (-4.2d+108)) then
tmp = (c / b) - (b / a)
else if (b <= 2d-309) then
tmp = (t_0 - b) / (a * 2.0d0)
else if (b <= 2.2d-28) then
tmp = ((a * 4.0d0) * (c / (-b - t_0))) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - (c * (a * 4.0))));
double tmp;
if (b <= -4.2e+108) {
tmp = (c / b) - (b / a);
} else if (b <= 2e-309) {
tmp = (t_0 - b) / (a * 2.0);
} else if (b <= 2.2e-28) {
tmp = ((a * 4.0) * (c / (-b - t_0))) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (c * (a * 4.0)))) tmp = 0 if b <= -4.2e+108: tmp = (c / b) - (b / a) elif b <= 2e-309: tmp = (t_0 - b) / (a * 2.0) elif b <= 2.2e-28: tmp = ((a * 4.0) * (c / (-b - t_0))) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) tmp = 0.0 if (b <= -4.2e+108) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 2e-309) tmp = Float64(Float64(t_0 - b) / Float64(a * 2.0)); elseif (b <= 2.2e-28) tmp = Float64(Float64(Float64(a * 4.0) * Float64(c / Float64(Float64(-b) - t_0))) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - (c * (a * 4.0)))); tmp = 0.0; if (b <= -4.2e+108) tmp = (c / b) - (b / a); elseif (b <= 2e-309) tmp = (t_0 - b) / (a * 2.0); elseif (b <= 2.2e-28) tmp = ((a * 4.0) * (c / (-b - t_0))) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -4.2e+108], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2e-309], N[(N[(t$95$0 - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.2e-28], N[(N[(N[(a * 4.0), $MachinePrecision] * N[(c / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
\mathbf{if}\;b \leq -4.2 \cdot 10^{+108}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{-309}:\\
\;\;\;\;\frac{t_0 - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 2.2 \cdot 10^{-28}:\\
\;\;\;\;\frac{\left(a \cdot 4\right) \cdot \frac{c}{\left(-b\right) - t_0}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.20000000000000019e108Initial program 53.5%
neg-sub053.5%
associate-+l-53.5%
sub0-neg53.5%
neg-mul-153.5%
associate-*l/53.5%
*-commutative53.5%
associate-/r*53.5%
/-rgt-identity53.5%
metadata-eval53.5%
Simplified53.6%
Taylor expanded in b around -inf 96.7%
mul-1-neg96.7%
unsub-neg96.7%
Simplified96.7%
if -4.20000000000000019e108 < b < 1.9999999999999988e-309Initial program 88.9%
if 1.9999999999999988e-309 < b < 2.19999999999999996e-28Initial program 52.2%
flip-+51.5%
pow251.5%
add-sqr-sqrt51.5%
*-commutative51.5%
*-commutative51.5%
*-commutative51.5%
*-commutative51.5%
Applied egg-rr51.5%
Taylor expanded in b around 0 59.0%
*-commutative59.0%
associate-*r*59.1%
Simplified59.1%
add-exp-log55.9%
Applied egg-rr55.9%
expm1-log1p-u55.7%
expm1-udef32.4%
associate-/l*33.0%
add-exp-log33.2%
Applied egg-rr33.2%
expm1-def63.6%
expm1-log1p65.8%
associate-/r/65.7%
Simplified65.7%
if 2.19999999999999996e-28 < b Initial program 10.2%
neg-sub010.2%
associate-+l-10.2%
sub0-neg10.2%
neg-mul-110.2%
associate-*l/10.2%
*-commutative10.2%
associate-/r*10.2%
/-rgt-identity10.2%
metadata-eval10.2%
Simplified10.3%
Taylor expanded in b around inf 88.4%
associate-*r/88.4%
neg-mul-188.4%
Simplified88.4%
Final simplification86.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1.45e+107)
(- (/ c b) (/ b a))
(if (<= b 3.3e-50)
(* (- (sqrt (+ (* b b) (* a (* c -4.0)))) b) (/ 0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.45e+107) {
tmp = (c / b) - (b / a);
} else if (b <= 3.3e-50) {
tmp = (sqrt(((b * b) + (a * (c * -4.0)))) - b) * (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.45d+107)) then
tmp = (c / b) - (b / a)
else if (b <= 3.3d-50) then
tmp = (sqrt(((b * b) + (a * (c * (-4.0d0))))) - b) * (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.45e+107) {
tmp = (c / b) - (b / a);
} else if (b <= 3.3e-50) {
tmp = (Math.sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.45e+107: tmp = (c / b) - (b / a) elif b <= 3.3e-50: tmp = (math.sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.45e+107) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 3.3e-50) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(a * Float64(c * -4.0)))) - b) * 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.45e+107) tmp = (c / b) - (b / a); elseif (b <= 3.3e-50) tmp = (sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.45e+107], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.3e-50], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.45 \cdot 10^{+107}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 3.3 \cdot 10^{-50}:\\
\;\;\;\;\left(\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.44999999999999994e107Initial program 53.5%
neg-sub053.5%
associate-+l-53.5%
sub0-neg53.5%
neg-mul-153.5%
associate-*l/53.5%
*-commutative53.5%
associate-/r*53.5%
/-rgt-identity53.5%
metadata-eval53.5%
Simplified53.6%
Taylor expanded in b around -inf 96.7%
mul-1-neg96.7%
unsub-neg96.7%
Simplified96.7%
if -1.44999999999999994e107 < b < 3.2999999999999998e-50Initial program 78.3%
/-rgt-identity78.3%
metadata-eval78.3%
associate-/l*78.3%
associate-*r/78.2%
+-commutative78.2%
unsub-neg78.2%
fma-neg78.2%
associate-*l*78.1%
*-commutative78.1%
distribute-rgt-neg-in78.1%
metadata-eval78.1%
associate-/r*78.2%
metadata-eval78.2%
metadata-eval78.2%
Simplified78.2%
fma-udef78.2%
associate-*l*78.2%
Applied egg-rr78.2%
if 3.2999999999999998e-50 < b Initial program 11.0%
neg-sub011.0%
associate-+l-11.0%
sub0-neg11.0%
neg-mul-111.0%
associate-*l/11.0%
*-commutative11.0%
associate-/r*11.0%
/-rgt-identity11.0%
metadata-eval11.0%
Simplified11.0%
Taylor expanded in b around inf 86.8%
associate-*r/86.8%
neg-mul-186.8%
Simplified86.8%
Final simplification85.2%
(FPCore (a b c)
:precision binary64
(if (<= b -2.2e+105)
(- (/ c b) (/ b a))
(if (<= b 7e-52)
(/ (- (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 <= -2.2e+105) {
tmp = (c / b) - (b / a);
} else if (b <= 7e-52) {
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 <= (-2.2d+105)) then
tmp = (c / b) - (b / a)
else if (b <= 7d-52) 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 <= -2.2e+105) {
tmp = (c / b) - (b / a);
} else if (b <= 7e-52) {
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 <= -2.2e+105: tmp = (c / b) - (b / a) elif b <= 7e-52: 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 <= -2.2e+105) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 7e-52) 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 <= -2.2e+105) tmp = (c / b) - (b / a); elseif (b <= 7e-52) 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, -2.2e+105], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 7e-52], 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 -2.2 \cdot 10^{+105}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 7 \cdot 10^{-52}:\\
\;\;\;\;\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 < -2.20000000000000007e105Initial program 53.5%
neg-sub053.5%
associate-+l-53.5%
sub0-neg53.5%
neg-mul-153.5%
associate-*l/53.5%
*-commutative53.5%
associate-/r*53.5%
/-rgt-identity53.5%
metadata-eval53.5%
Simplified53.6%
Taylor expanded in b around -inf 96.7%
mul-1-neg96.7%
unsub-neg96.7%
Simplified96.7%
if -2.20000000000000007e105 < b < 7.0000000000000001e-52Initial program 78.3%
if 7.0000000000000001e-52 < b Initial program 11.0%
neg-sub011.0%
associate-+l-11.0%
sub0-neg11.0%
neg-mul-111.0%
associate-*l/11.0%
*-commutative11.0%
associate-/r*11.0%
/-rgt-identity11.0%
metadata-eval11.0%
Simplified11.0%
Taylor expanded in b around inf 86.8%
associate-*r/86.8%
neg-mul-186.8%
Simplified86.8%
Final simplification85.3%
(FPCore (a b c) :precision binary64 (if (<= b -3.8e-154) (- (/ c b) (/ b a)) (if (<= b 7e-52) (* (- b (sqrt (* c (* a -4.0)))) (/ -0.5 a)) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.8e-154) {
tmp = (c / b) - (b / a);
} else if (b <= 7e-52) {
tmp = (b - sqrt((c * (a * -4.0)))) * (-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 <= (-3.8d-154)) then
tmp = (c / b) - (b / a)
else if (b <= 7d-52) then
tmp = (b - sqrt((c * (a * (-4.0d0))))) * ((-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 <= -3.8e-154) {
tmp = (c / b) - (b / a);
} else if (b <= 7e-52) {
tmp = (b - Math.sqrt((c * (a * -4.0)))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.8e-154: tmp = (c / b) - (b / a) elif b <= 7e-52: tmp = (b - math.sqrt((c * (a * -4.0)))) * (-0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.8e-154) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 7e-52) tmp = Float64(Float64(b - sqrt(Float64(c * Float64(a * -4.0)))) * 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 <= -3.8e-154) tmp = (c / b) - (b / a); elseif (b <= 7e-52) tmp = (b - sqrt((c * (a * -4.0)))) * (-0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.8e-154], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 7e-52], N[(N[(b - N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.8 \cdot 10^{-154}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 7 \cdot 10^{-52}:\\
\;\;\;\;\left(b - \sqrt{c \cdot \left(a \cdot -4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.8000000000000001e-154Initial program 73.8%
neg-sub073.8%
associate-+l-73.8%
sub0-neg73.8%
neg-mul-173.8%
associate-*l/73.7%
*-commutative73.7%
associate-/r*73.7%
/-rgt-identity73.7%
metadata-eval73.7%
Simplified73.7%
Taylor expanded in b around -inf 84.8%
mul-1-neg84.8%
unsub-neg84.8%
Simplified84.8%
if -3.8000000000000001e-154 < b < 7.0000000000000001e-52Initial program 62.4%
neg-sub062.4%
associate-+l-62.4%
sub0-neg62.4%
neg-mul-162.4%
associate-*l/62.3%
*-commutative62.3%
associate-/r*62.4%
/-rgt-identity62.4%
metadata-eval62.4%
Simplified62.4%
Taylor expanded in a around inf 62.3%
*-commutative62.3%
associate-*r*62.3%
Simplified62.3%
if 7.0000000000000001e-52 < b Initial program 11.0%
neg-sub011.0%
associate-+l-11.0%
sub0-neg11.0%
neg-mul-111.0%
associate-*l/11.0%
*-commutative11.0%
associate-/r*11.0%
/-rgt-identity11.0%
metadata-eval11.0%
Simplified11.0%
Taylor expanded in b around inf 86.8%
associate-*r/86.8%
neg-mul-186.8%
Simplified86.8%
Final simplification80.7%
(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 73.9%
neg-sub073.9%
associate-+l-73.9%
sub0-neg73.9%
neg-mul-173.9%
associate-*l/73.8%
*-commutative73.8%
associate-/r*73.8%
/-rgt-identity73.8%
metadata-eval73.8%
Simplified73.8%
Taylor expanded in b around -inf 73.4%
mul-1-neg73.4%
unsub-neg73.4%
Simplified73.4%
if -9.999999999999969e-311 < b Initial program 22.9%
neg-sub022.9%
associate-+l-22.9%
sub0-neg22.9%
neg-mul-122.9%
associate-*l/22.9%
*-commutative22.9%
associate-/r*22.9%
/-rgt-identity22.9%
metadata-eval22.9%
Simplified22.9%
Taylor expanded in b around inf 69.9%
associate-*r/69.9%
neg-mul-169.9%
Simplified69.9%
Final simplification71.7%
(FPCore (a b c) :precision binary64 (if (<= b 1.3e+23) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.3e+23) {
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.3d+23) 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.3e+23) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.3e+23: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.3e+23) 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.3e+23) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.3e+23], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.3 \cdot 10^{+23}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 1.29999999999999996e23Initial program 65.6%
neg-sub065.6%
associate-+l-65.6%
sub0-neg65.6%
neg-mul-165.6%
associate-*l/65.4%
*-commutative65.4%
associate-/r*65.5%
/-rgt-identity65.5%
metadata-eval65.5%
Simplified65.5%
Taylor expanded in b around -inf 54.2%
associate-*r/54.2%
neg-mul-154.2%
Simplified54.2%
if 1.29999999999999996e23 < b Initial program 9.8%
neg-sub09.8%
associate-+l-9.8%
sub0-neg9.8%
neg-mul-19.8%
associate-*l/9.9%
*-commutative9.9%
associate-/r*9.9%
/-rgt-identity9.9%
metadata-eval9.9%
Simplified9.9%
Taylor expanded in b around -inf 1.9%
neg-mul-11.9%
unsub-neg1.9%
*-commutative1.9%
associate-/l*2.0%
associate-/r/2.0%
Simplified2.0%
Taylor expanded in b around 0 31.6%
Final simplification47.4%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-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 <= (-1d-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 <= -1e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-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 <= -1e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 73.9%
neg-sub073.9%
associate-+l-73.9%
sub0-neg73.9%
neg-mul-173.9%
associate-*l/73.8%
*-commutative73.8%
associate-/r*73.8%
/-rgt-identity73.8%
metadata-eval73.8%
Simplified73.8%
Taylor expanded in b around -inf 73.3%
associate-*r/73.3%
neg-mul-173.3%
Simplified73.3%
if -9.999999999999969e-311 < b Initial program 22.9%
neg-sub022.9%
associate-+l-22.9%
sub0-neg22.9%
neg-mul-122.9%
associate-*l/22.9%
*-commutative22.9%
associate-/r*22.9%
/-rgt-identity22.9%
metadata-eval22.9%
Simplified22.9%
Taylor expanded in b around inf 69.9%
associate-*r/69.9%
neg-mul-169.9%
Simplified69.9%
Final simplification71.6%
(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 48.8%
neg-sub048.8%
associate-+l-48.8%
sub0-neg48.8%
neg-mul-148.8%
associate-*l/48.7%
*-commutative48.7%
associate-/r*48.7%
/-rgt-identity48.7%
metadata-eval48.7%
Simplified48.8%
Taylor expanded in b around -inf 36.6%
neg-mul-136.6%
unsub-neg36.6%
*-commutative36.6%
associate-/l*38.2%
associate-/r/38.2%
Simplified38.2%
Taylor expanded in b around 0 11.8%
Final simplification11.8%
herbie shell --seed 2023207
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))