
(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 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(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 -0.000176)
(/ c (- b))
(if (<= b 6e+109)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -0.000176) {
tmp = c / -b;
} else if (b <= 6e+109) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / 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) :: tmp
if (b <= (-0.000176d0)) then
tmp = c / -b
else if (b <= 6d+109) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -0.000176) {
tmp = c / -b;
} else if (b <= 6e+109) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -0.000176: tmp = c / -b elif b <= 6e+109: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -0.000176) tmp = Float64(c / Float64(-b)); elseif (b <= 6e+109) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -0.000176) tmp = c / -b; elseif (b <= 6e+109) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -0.000176], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 6e+109], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.000176:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 6 \cdot 10^{+109}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.76e-4Initial program 9.3%
div-sub7.6%
sub-neg7.6%
neg-mul-17.6%
*-commutative7.6%
associate-/l*5.3%
distribute-neg-frac5.3%
neg-mul-15.3%
*-commutative5.3%
associate-/l*7.6%
distribute-rgt-out9.3%
associate-/r*9.3%
metadata-eval9.3%
sub-neg9.3%
+-commutative9.3%
Simplified9.3%
Taylor expanded in b around -inf 87.8%
mul-1-neg87.8%
distribute-neg-frac287.8%
Simplified87.8%
if -1.76e-4 < b < 6.00000000000000031e109Initial program 85.2%
if 6.00000000000000031e109 < b Initial program 56.6%
div-sub56.6%
sub-neg56.6%
neg-mul-156.6%
*-commutative56.6%
associate-/l*56.5%
distribute-neg-frac56.5%
neg-mul-156.5%
*-commutative56.5%
associate-/l*56.4%
distribute-rgt-out56.4%
associate-/r*56.4%
metadata-eval56.4%
sub-neg56.4%
+-commutative56.4%
Simplified56.4%
Taylor expanded in c around 0 94.3%
+-commutative94.3%
mul-1-neg94.3%
unsub-neg94.3%
Simplified94.3%
Final simplification87.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* (/ -0.5 a) (+ b (sqrt (* (* c a) -4.0))))))
(if (<= b -2.95e-5)
(/ c (- b))
(if (<= b 4e-127)
t_0
(if (<= b 9.2e-59)
(- (/ c b) (/ b a))
(if (<= b 7e-15)
t_0
(- (* c (+ (/ 1.0 b) (* a (/ c (pow b 3.0))))) (/ b a))))))))
double code(double a, double b, double c) {
double t_0 = (-0.5 / a) * (b + sqrt(((c * a) * -4.0)));
double tmp;
if (b <= -2.95e-5) {
tmp = c / -b;
} else if (b <= 4e-127) {
tmp = t_0;
} else if (b <= 9.2e-59) {
tmp = (c / b) - (b / a);
} else if (b <= 7e-15) {
tmp = t_0;
} else {
tmp = (c * ((1.0 / b) + (a * (c / pow(b, 3.0))))) - (b / 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 = ((-0.5d0) / a) * (b + sqrt(((c * a) * (-4.0d0))))
if (b <= (-2.95d-5)) then
tmp = c / -b
else if (b <= 4d-127) then
tmp = t_0
else if (b <= 9.2d-59) then
tmp = (c / b) - (b / a)
else if (b <= 7d-15) then
tmp = t_0
else
tmp = (c * ((1.0d0 / b) + (a * (c / (b ** 3.0d0))))) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (-0.5 / a) * (b + Math.sqrt(((c * a) * -4.0)));
double tmp;
if (b <= -2.95e-5) {
tmp = c / -b;
} else if (b <= 4e-127) {
tmp = t_0;
} else if (b <= 9.2e-59) {
tmp = (c / b) - (b / a);
} else if (b <= 7e-15) {
tmp = t_0;
} else {
tmp = (c * ((1.0 / b) + (a * (c / Math.pow(b, 3.0))))) - (b / a);
}
return tmp;
}
def code(a, b, c): t_0 = (-0.5 / a) * (b + math.sqrt(((c * a) * -4.0))) tmp = 0 if b <= -2.95e-5: tmp = c / -b elif b <= 4e-127: tmp = t_0 elif b <= 9.2e-59: tmp = (c / b) - (b / a) elif b <= 7e-15: tmp = t_0 else: tmp = (c * ((1.0 / b) + (a * (c / math.pow(b, 3.0))))) - (b / a) return tmp
function code(a, b, c) t_0 = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(Float64(c * a) * -4.0)))) tmp = 0.0 if (b <= -2.95e-5) tmp = Float64(c / Float64(-b)); elseif (b <= 4e-127) tmp = t_0; elseif (b <= 9.2e-59) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 7e-15) tmp = t_0; else tmp = Float64(Float64(c * Float64(Float64(1.0 / b) + Float64(a * Float64(c / (b ^ 3.0))))) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (-0.5 / a) * (b + sqrt(((c * a) * -4.0))); tmp = 0.0; if (b <= -2.95e-5) tmp = c / -b; elseif (b <= 4e-127) tmp = t_0; elseif (b <= 9.2e-59) tmp = (c / b) - (b / a); elseif (b <= 7e-15) tmp = t_0; else tmp = (c * ((1.0 / b) + (a * (c / (b ^ 3.0))))) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -2.95e-5], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 4e-127], t$95$0, If[LessEqual[b, 9.2e-59], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 7e-15], t$95$0, N[(N[(c * N[(N[(1.0 / b), $MachinePrecision] + N[(a * N[(c / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-0.5}{a} \cdot \left(b + \sqrt{\left(c \cdot a\right) \cdot -4}\right)\\
\mathbf{if}\;b \leq -2.95 \cdot 10^{-5}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{-127}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq 9.2 \cdot 10^{-59}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 7 \cdot 10^{-15}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;c \cdot \left(\frac{1}{b} + a \cdot \frac{c}{{b}^{3}}\right) - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.9499999999999999e-5Initial program 9.3%
div-sub7.6%
sub-neg7.6%
neg-mul-17.6%
*-commutative7.6%
associate-/l*5.3%
distribute-neg-frac5.3%
neg-mul-15.3%
*-commutative5.3%
associate-/l*7.6%
distribute-rgt-out9.3%
associate-/r*9.3%
metadata-eval9.3%
sub-neg9.3%
+-commutative9.3%
Simplified9.3%
Taylor expanded in b around -inf 87.8%
mul-1-neg87.8%
distribute-neg-frac287.8%
Simplified87.8%
if -2.9499999999999999e-5 < b < 4.0000000000000001e-127 or 9.19999999999999918e-59 < b < 7.0000000000000001e-15Initial program 80.2%
div-sub80.2%
sub-neg80.2%
neg-mul-180.2%
*-commutative80.2%
associate-/l*80.2%
distribute-neg-frac80.2%
neg-mul-180.2%
*-commutative80.2%
associate-/l*80.2%
distribute-rgt-out80.2%
associate-/r*80.2%
metadata-eval80.2%
sub-neg80.2%
+-commutative80.2%
Simplified80.3%
Taylor expanded in a around inf 75.4%
*-commutative75.4%
Simplified75.4%
if 4.0000000000000001e-127 < b < 9.19999999999999918e-59Initial program 94.3%
div-sub94.3%
sub-neg94.3%
neg-mul-194.3%
*-commutative94.3%
associate-/l*94.2%
distribute-neg-frac94.2%
neg-mul-194.2%
*-commutative94.2%
associate-/l*94.0%
distribute-rgt-out94.0%
associate-/r*94.0%
metadata-eval94.0%
sub-neg94.0%
+-commutative94.0%
Simplified94.0%
Taylor expanded in c around 0 66.7%
+-commutative66.7%
mul-1-neg66.7%
unsub-neg66.7%
Simplified66.7%
if 7.0000000000000001e-15 < b Initial program 70.4%
div-sub70.4%
sub-neg70.4%
neg-mul-170.4%
*-commutative70.4%
associate-/l*70.3%
distribute-neg-frac70.3%
neg-mul-170.3%
*-commutative70.3%
associate-/l*70.2%
distribute-rgt-out70.2%
associate-/r*70.2%
metadata-eval70.2%
sub-neg70.2%
+-commutative70.2%
Simplified70.2%
Taylor expanded in c around 0 87.1%
+-commutative87.1%
mul-1-neg87.1%
unsub-neg87.1%
associate-/l*90.0%
Simplified90.0%
Final simplification83.3%
(FPCore (a b c)
:precision binary64
(if (<= b -0.000145)
(/ c (- b))
(if (<= b 3.8e-127)
(* (/ -0.5 a) (+ b (sqrt (* (* c a) -4.0))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -0.000145) {
tmp = c / -b;
} else if (b <= 3.8e-127) {
tmp = (-0.5 / a) * (b + sqrt(((c * a) * -4.0)));
} else {
tmp = (c / b) - (b / 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) :: tmp
if (b <= (-0.000145d0)) then
tmp = c / -b
else if (b <= 3.8d-127) then
tmp = ((-0.5d0) / a) * (b + sqrt(((c * a) * (-4.0d0))))
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -0.000145) {
tmp = c / -b;
} else if (b <= 3.8e-127) {
tmp = (-0.5 / a) * (b + Math.sqrt(((c * a) * -4.0)));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -0.000145: tmp = c / -b elif b <= 3.8e-127: tmp = (-0.5 / a) * (b + math.sqrt(((c * a) * -4.0))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -0.000145) tmp = Float64(c / Float64(-b)); elseif (b <= 3.8e-127) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(Float64(c * a) * -4.0)))); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -0.000145) tmp = c / -b; elseif (b <= 3.8e-127) tmp = (-0.5 / a) * (b + sqrt(((c * a) * -4.0))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -0.000145], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 3.8e-127], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.000145:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 3.8 \cdot 10^{-127}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{\left(c \cdot a\right) \cdot -4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.45e-4Initial program 9.3%
div-sub7.6%
sub-neg7.6%
neg-mul-17.6%
*-commutative7.6%
associate-/l*5.3%
distribute-neg-frac5.3%
neg-mul-15.3%
*-commutative5.3%
associate-/l*7.6%
distribute-rgt-out9.3%
associate-/r*9.3%
metadata-eval9.3%
sub-neg9.3%
+-commutative9.3%
Simplified9.3%
Taylor expanded in b around -inf 87.8%
mul-1-neg87.8%
distribute-neg-frac287.8%
Simplified87.8%
if -1.45e-4 < b < 3.80000000000000003e-127Initial program 77.9%
div-sub77.9%
sub-neg77.9%
neg-mul-177.9%
*-commutative77.9%
associate-/l*77.9%
distribute-neg-frac77.9%
neg-mul-177.9%
*-commutative77.9%
associate-/l*78.0%
distribute-rgt-out78.0%
associate-/r*78.0%
metadata-eval78.0%
sub-neg78.0%
+-commutative78.0%
Simplified78.0%
Taylor expanded in a around inf 75.2%
*-commutative75.2%
Simplified75.2%
if 3.80000000000000003e-127 < b Initial program 76.7%
div-sub76.7%
sub-neg76.7%
neg-mul-176.7%
*-commutative76.7%
associate-/l*76.6%
distribute-neg-frac76.6%
neg-mul-176.6%
*-commutative76.6%
associate-/l*76.5%
distribute-rgt-out76.5%
associate-/r*76.5%
metadata-eval76.5%
sub-neg76.5%
+-commutative76.5%
Simplified76.5%
Taylor expanded in c around 0 81.2%
+-commutative81.2%
mul-1-neg81.2%
unsub-neg81.2%
Simplified81.2%
Final simplification81.8%
(FPCore (a b c) :precision binary64 (if (<= b -5e-311) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-311) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / 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) :: tmp
if (b <= (-5d-311)) then
tmp = c / -b
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5e-311) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-311: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-311) tmp = Float64(c / Float64(-b)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-311) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-311], N[(c / (-b)), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-311}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -5.00000000000023e-311Initial program 29.4%
div-sub28.2%
sub-neg28.2%
neg-mul-128.2%
*-commutative28.2%
associate-/l*26.6%
distribute-neg-frac26.6%
neg-mul-126.6%
*-commutative26.6%
associate-/l*28.3%
distribute-rgt-out29.4%
associate-/r*29.4%
metadata-eval29.4%
sub-neg29.4%
+-commutative29.4%
Simplified29.5%
Taylor expanded in b around -inf 67.1%
mul-1-neg67.1%
distribute-neg-frac267.1%
Simplified67.1%
if -5.00000000000023e-311 < b Initial program 78.0%
div-sub78.0%
sub-neg78.0%
neg-mul-178.0%
*-commutative78.0%
associate-/l*77.9%
distribute-neg-frac77.9%
neg-mul-177.9%
*-commutative77.9%
associate-/l*77.8%
distribute-rgt-out77.8%
associate-/r*77.8%
metadata-eval77.8%
sub-neg77.8%
+-commutative77.8%
Simplified77.8%
Taylor expanded in c around 0 65.5%
+-commutative65.5%
mul-1-neg65.5%
unsub-neg65.5%
Simplified65.5%
Final simplification66.3%
(FPCore (a b c) :precision binary64 (if (<= b -1.3e-277) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.3e-277) {
tmp = c / -b;
} else {
tmp = b / -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) :: tmp
if (b <= (-1.3d-277)) then
tmp = c / -b
else
tmp = b / -a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.3e-277) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.3e-277: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.3e-277) tmp = Float64(c / Float64(-b)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.3e-277) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.3e-277], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.3 \cdot 10^{-277}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -1.3e-277Initial program 28.4%
div-sub27.3%
sub-neg27.3%
neg-mul-127.3%
*-commutative27.3%
associate-/l*25.6%
distribute-neg-frac25.6%
neg-mul-125.6%
*-commutative25.6%
associate-/l*27.3%
distribute-rgt-out28.5%
associate-/r*28.5%
metadata-eval28.5%
sub-neg28.5%
+-commutative28.5%
Simplified28.5%
Taylor expanded in b around -inf 68.7%
mul-1-neg68.7%
distribute-neg-frac268.7%
Simplified68.7%
if -1.3e-277 < b Initial program 77.7%
div-sub77.8%
sub-neg77.8%
neg-mul-177.8%
*-commutative77.8%
associate-/l*77.7%
distribute-neg-frac77.7%
neg-mul-177.7%
*-commutative77.7%
associate-/l*77.6%
distribute-rgt-out77.6%
associate-/r*77.6%
metadata-eval77.6%
sub-neg77.6%
+-commutative77.6%
Simplified77.6%
Taylor expanded in a around 0 63.2%
associate-*r/63.2%
mul-1-neg63.2%
Simplified63.2%
Final simplification65.8%
(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 54.6%
div-sub54.1%
sub-neg54.1%
neg-mul-154.1%
*-commutative54.1%
associate-/l*53.3%
distribute-neg-frac53.3%
neg-mul-153.3%
*-commutative53.3%
associate-/l*54.0%
distribute-rgt-out54.6%
associate-/r*54.6%
metadata-eval54.6%
sub-neg54.6%
+-commutative54.6%
Simplified54.6%
Taylor expanded in b around -inf 33.3%
mul-1-neg33.3%
distribute-neg-frac233.3%
Simplified33.3%
Final simplification33.3%
(FPCore (a b c) :precision binary64 (/ b a))
double code(double a, double b, double c) {
return b / 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 / a
end function
public static double code(double a, double b, double c) {
return b / a;
}
def code(a, b, c): return b / a
function code(a, b, c) return Float64(b / a) end
function tmp = code(a, b, c) tmp = b / a; end
code[a_, b_, c_] := N[(b / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{a}
\end{array}
Initial program 54.6%
div-sub54.1%
sub-neg54.1%
neg-mul-154.1%
*-commutative54.1%
associate-/l*53.3%
distribute-neg-frac53.3%
neg-mul-153.3%
*-commutative53.3%
associate-/l*54.0%
distribute-rgt-out54.6%
associate-/r*54.6%
metadata-eval54.6%
sub-neg54.6%
+-commutative54.6%
Simplified54.6%
Applied egg-rr33.7%
Taylor expanded in b around -inf 2.5%
Final simplification2.5%
(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 54.6%
div-sub54.1%
sub-neg54.1%
neg-mul-154.1%
*-commutative54.1%
associate-/l*53.3%
distribute-neg-frac53.3%
neg-mul-153.3%
*-commutative53.3%
associate-/l*54.0%
distribute-rgt-out54.6%
associate-/r*54.6%
metadata-eval54.6%
sub-neg54.6%
+-commutative54.6%
Simplified54.6%
Taylor expanded in c around 0 35.1%
+-commutative35.1%
mul-1-neg35.1%
unsub-neg35.1%
Simplified35.1%
Taylor expanded in c around inf 12.2%
Final simplification12.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ c (* a (/ (+ (- b) t_0) (* 2.0 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 = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-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 = c / (a * ((-b + t_0) / (2.0d0 * a)))
else
tmp = (-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 = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-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 = c / (a * ((-b + t_0) / (2.0 * a))) else: tmp = (-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(c / Float64(a * Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)))); else tmp = 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 = c / (a * ((-b + t_0) / (2.0 * a))); else tmp = (-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[(c / N[(a * N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $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{c}{a \cdot \frac{\left(-b\right) + t\_0}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - t\_0}{2 \cdot a}\\
\end{array}
\end{array}
herbie shell --seed 2024095
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:alt
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))