
(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 10 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 -3e-120)
(/ c (- b))
(if (<= b 2.8e+72)
(/ (+ b (sqrt (- (* b b) (* (* c 4.0) a)))) (* a (- 2.0)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3e-120) {
tmp = c / -b;
} else if (b <= 2.8e+72) {
tmp = (b + sqrt(((b * b) - ((c * 4.0) * 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 <= (-3d-120)) then
tmp = c / -b
else if (b <= 2.8d+72) then
tmp = (b + sqrt(((b * b) - ((c * 4.0d0) * 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 <= -3e-120) {
tmp = c / -b;
} else if (b <= 2.8e+72) {
tmp = (b + Math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * -2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3e-120: tmp = c / -b elif b <= 2.8e+72: tmp = (b + math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * -2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3e-120) tmp = Float64(c / Float64(-b)); elseif (b <= 2.8e+72) tmp = Float64(Float64(b + sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * a)))) / Float64(a * Float64(-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 <= -3e-120) tmp = c / -b; elseif (b <= 2.8e+72) tmp = (b + sqrt(((b * b) - ((c * 4.0) * a)))) / (a * -2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3e-120], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.8e+72], N[(N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(c * 4.0), $MachinePrecision] * a), $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 -3 \cdot 10^{-120}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.8 \cdot 10^{+72}:\\
\;\;\;\;\frac{b + \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a \cdot \left(-2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.00000000000000011e-120Initial program 18.7%
div-sub18.4%
sub-neg18.4%
neg-mul-118.4%
*-commutative18.4%
associate-/l*17.0%
distribute-neg-frac17.0%
neg-mul-117.0%
*-commutative17.0%
associate-/l*18.3%
distribute-rgt-out18.7%
associate-/r*18.7%
metadata-eval18.7%
sub-neg18.7%
+-commutative18.7%
Simplified18.7%
Taylor expanded in b around -inf 81.4%
mul-1-neg81.4%
distribute-neg-frac281.4%
Simplified81.4%
if -3.00000000000000011e-120 < b < 2.7999999999999999e72Initial program 88.0%
*-commutative88.0%
*-commutative88.0%
sqr-neg88.0%
*-commutative88.0%
sqr-neg88.0%
*-commutative88.0%
associate-*r*88.0%
Simplified88.0%
if 2.7999999999999999e72 < b Initial program 52.2%
div-sub52.2%
sub-neg52.2%
neg-mul-152.2%
*-commutative52.2%
associate-/l*52.2%
distribute-neg-frac52.2%
neg-mul-152.2%
*-commutative52.2%
associate-/l*52.2%
distribute-rgt-out52.2%
associate-/r*52.2%
metadata-eval52.2%
sub-neg52.2%
+-commutative52.2%
Simplified52.3%
Taylor expanded in c around 0 95.9%
+-commutative95.9%
mul-1-neg95.9%
unsub-neg95.9%
Simplified95.9%
Final simplification87.9%
(FPCore (a b c)
:precision binary64
(if (<= b -3e-120)
(/ c (- b))
(if (<= b 1.8e+72)
(/ (- (- 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 <= -3e-120) {
tmp = c / -b;
} else if (b <= 1.8e+72) {
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 <= (-3d-120)) then
tmp = c / -b
else if (b <= 1.8d+72) 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 <= -3e-120) {
tmp = c / -b;
} else if (b <= 1.8e+72) {
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 <= -3e-120: tmp = c / -b elif b <= 1.8e+72: 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 <= -3e-120) tmp = Float64(c / Float64(-b)); elseif (b <= 1.8e+72) 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 <= -3e-120) tmp = c / -b; elseif (b <= 1.8e+72) 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, -3e-120], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.8e+72], 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 -3 \cdot 10^{-120}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.8 \cdot 10^{+72}:\\
\;\;\;\;\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 < -3.00000000000000011e-120Initial program 18.7%
div-sub18.4%
sub-neg18.4%
neg-mul-118.4%
*-commutative18.4%
associate-/l*17.0%
distribute-neg-frac17.0%
neg-mul-117.0%
*-commutative17.0%
associate-/l*18.3%
distribute-rgt-out18.7%
associate-/r*18.7%
metadata-eval18.7%
sub-neg18.7%
+-commutative18.7%
Simplified18.7%
Taylor expanded in b around -inf 81.4%
mul-1-neg81.4%
distribute-neg-frac281.4%
Simplified81.4%
if -3.00000000000000011e-120 < b < 1.80000000000000017e72Initial program 88.0%
if 1.80000000000000017e72 < b Initial program 52.2%
div-sub52.2%
sub-neg52.2%
neg-mul-152.2%
*-commutative52.2%
associate-/l*52.2%
distribute-neg-frac52.2%
neg-mul-152.2%
*-commutative52.2%
associate-/l*52.2%
distribute-rgt-out52.2%
associate-/r*52.2%
metadata-eval52.2%
sub-neg52.2%
+-commutative52.2%
Simplified52.3%
Taylor expanded in c around 0 95.9%
+-commutative95.9%
mul-1-neg95.9%
unsub-neg95.9%
Simplified95.9%
Final simplification87.8%
(FPCore (a b c)
:precision binary64
(if (<= b -3e-120)
(/ c (- b))
(if (<= b 3.1e-92)
(/ (- (- b) (sqrt (* a (* c -4.0)))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3e-120) {
tmp = c / -b;
} else if (b <= 3.1e-92) {
tmp = (-b - sqrt((a * (c * -4.0)))) / (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 <= (-3d-120)) then
tmp = c / -b
else if (b <= 3.1d-92) then
tmp = (-b - sqrt((a * (c * (-4.0d0))))) / (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 <= -3e-120) {
tmp = c / -b;
} else if (b <= 3.1e-92) {
tmp = (-b - Math.sqrt((a * (c * -4.0)))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3e-120: tmp = c / -b elif b <= 3.1e-92: tmp = (-b - math.sqrt((a * (c * -4.0)))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3e-120) tmp = Float64(c / Float64(-b)); elseif (b <= 3.1e-92) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(a * Float64(c * -4.0)))) / 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 <= -3e-120) tmp = c / -b; elseif (b <= 3.1e-92) tmp = (-b - sqrt((a * (c * -4.0)))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3e-120], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 3.1e-92], N[(N[((-b) - N[Sqrt[N[(a * N[(c * -4.0), $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 -3 \cdot 10^{-120}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 3.1 \cdot 10^{-92}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.00000000000000011e-120Initial program 18.7%
div-sub18.4%
sub-neg18.4%
neg-mul-118.4%
*-commutative18.4%
associate-/l*17.0%
distribute-neg-frac17.0%
neg-mul-117.0%
*-commutative17.0%
associate-/l*18.3%
distribute-rgt-out18.7%
associate-/r*18.7%
metadata-eval18.7%
sub-neg18.7%
+-commutative18.7%
Simplified18.7%
Taylor expanded in b around -inf 81.4%
mul-1-neg81.4%
distribute-neg-frac281.4%
Simplified81.4%
if -3.00000000000000011e-120 < b < 3.1000000000000001e-92Initial program 84.9%
*-commutative84.9%
*-commutative84.9%
sqr-neg84.9%
*-commutative84.9%
sqr-neg84.9%
*-commutative84.9%
associate-*r*85.0%
Simplified85.0%
add-cube-cbrt84.4%
pow384.5%
*-commutative84.5%
associate-*l*84.5%
Applied egg-rr84.5%
Taylor expanded in c around -inf 0.0%
mul-1-neg0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt81.6%
distribute-lft-neg-in81.6%
metadata-eval81.6%
rem-cube-cbrt82.1%
Simplified82.1%
neg-mul-182.1%
fma-neg82.1%
*-un-lft-identity82.1%
Applied egg-rr82.1%
fma-undefine82.1%
unsub-neg82.1%
mul-1-neg82.1%
Simplified82.1%
if 3.1000000000000001e-92 < b Initial program 67.8%
div-sub67.8%
sub-neg67.8%
neg-mul-167.8%
*-commutative67.8%
associate-/l*67.7%
distribute-neg-frac67.7%
neg-mul-167.7%
*-commutative67.7%
associate-/l*67.6%
distribute-rgt-out67.6%
associate-/r*67.6%
metadata-eval67.6%
sub-neg67.6%
+-commutative67.6%
Simplified67.6%
Taylor expanded in c around 0 86.7%
+-commutative86.7%
mul-1-neg86.7%
unsub-neg86.7%
Simplified86.7%
(FPCore (a b c)
:precision binary64
(if (<= b -3e-120)
(/ c (- b))
(if (<= b 1.32e-92)
(* (/ -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 <= -3e-120) {
tmp = c / -b;
} else if (b <= 1.32e-92) {
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 <= (-3d-120)) then
tmp = c / -b
else if (b <= 1.32d-92) 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 <= -3e-120) {
tmp = c / -b;
} else if (b <= 1.32e-92) {
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 <= -3e-120: tmp = c / -b elif b <= 1.32e-92: 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 <= -3e-120) tmp = Float64(c / Float64(-b)); elseif (b <= 1.32e-92) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(c * Float64(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 <= -3e-120) tmp = c / -b; elseif (b <= 1.32e-92) 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, -3e-120], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.32e-92], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3 \cdot 10^{-120}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.32 \cdot 10^{-92}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.00000000000000011e-120Initial program 18.7%
div-sub18.4%
sub-neg18.4%
neg-mul-118.4%
*-commutative18.4%
associate-/l*17.0%
distribute-neg-frac17.0%
neg-mul-117.0%
*-commutative17.0%
associate-/l*18.3%
distribute-rgt-out18.7%
associate-/r*18.7%
metadata-eval18.7%
sub-neg18.7%
+-commutative18.7%
Simplified18.7%
Taylor expanded in b around -inf 81.4%
mul-1-neg81.4%
distribute-neg-frac281.4%
Simplified81.4%
if -3.00000000000000011e-120 < b < 1.3200000000000001e-92Initial program 84.9%
div-sub84.9%
sub-neg84.9%
neg-mul-184.9%
*-commutative84.9%
associate-/l*84.9%
distribute-neg-frac84.9%
neg-mul-184.9%
*-commutative84.9%
associate-/l*84.8%
distribute-rgt-out84.8%
associate-/r*84.8%
metadata-eval84.8%
sub-neg84.8%
+-commutative84.8%
Simplified84.9%
Taylor expanded in a around inf 82.0%
metadata-eval82.0%
distribute-lft-neg-in82.0%
associate-*r*82.0%
*-commutative82.0%
distribute-rgt-neg-in82.0%
distribute-lft-neg-in82.0%
metadata-eval82.0%
*-commutative82.0%
Simplified82.0%
if 1.3200000000000001e-92 < b Initial program 67.8%
div-sub67.8%
sub-neg67.8%
neg-mul-167.8%
*-commutative67.8%
associate-/l*67.7%
distribute-neg-frac67.7%
neg-mul-167.7%
*-commutative67.7%
associate-/l*67.6%
distribute-rgt-out67.6%
associate-/r*67.6%
metadata-eval67.6%
sub-neg67.6%
+-commutative67.6%
Simplified67.6%
Taylor expanded in c around 0 86.7%
+-commutative86.7%
mul-1-neg86.7%
unsub-neg86.7%
Simplified86.7%
(FPCore (a b c)
:precision binary64
(if (<= b -2.7e-120)
(/ c (- b))
(if (<= b 2.85e-92)
(/ (sqrt (* a (* c -4.0))) (* a (- 2.0)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.7e-120) {
tmp = c / -b;
} else if (b <= 2.85e-92) {
tmp = sqrt((a * (c * -4.0))) / (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 <= (-2.7d-120)) then
tmp = c / -b
else if (b <= 2.85d-92) then
tmp = sqrt((a * (c * (-4.0d0)))) / (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 <= -2.7e-120) {
tmp = c / -b;
} else if (b <= 2.85e-92) {
tmp = Math.sqrt((a * (c * -4.0))) / (a * -2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.7e-120: tmp = c / -b elif b <= 2.85e-92: tmp = math.sqrt((a * (c * -4.0))) / (a * -2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.7e-120) tmp = Float64(c / Float64(-b)); elseif (b <= 2.85e-92) tmp = Float64(sqrt(Float64(a * Float64(c * -4.0))) / Float64(a * Float64(-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 <= -2.7e-120) tmp = c / -b; elseif (b <= 2.85e-92) tmp = sqrt((a * (c * -4.0))) / (a * -2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.7e-120], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.85e-92], N[(N[Sqrt[N[(a * N[(c * -4.0), $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 -2.7 \cdot 10^{-120}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.85 \cdot 10^{-92}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot \left(-2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.6999999999999999e-120Initial program 18.7%
div-sub18.4%
sub-neg18.4%
neg-mul-118.4%
*-commutative18.4%
associate-/l*17.0%
distribute-neg-frac17.0%
neg-mul-117.0%
*-commutative17.0%
associate-/l*18.3%
distribute-rgt-out18.7%
associate-/r*18.7%
metadata-eval18.7%
sub-neg18.7%
+-commutative18.7%
Simplified18.7%
Taylor expanded in b around -inf 81.4%
mul-1-neg81.4%
distribute-neg-frac281.4%
Simplified81.4%
if -2.6999999999999999e-120 < b < 2.85000000000000004e-92Initial program 84.9%
*-commutative84.9%
*-commutative84.9%
sqr-neg84.9%
*-commutative84.9%
sqr-neg84.9%
*-commutative84.9%
associate-*r*85.0%
Simplified85.0%
add-cube-cbrt84.4%
pow384.5%
*-commutative84.5%
associate-*l*84.5%
Applied egg-rr84.5%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt81.3%
mul-1-neg81.3%
rem-cube-cbrt81.8%
Simplified81.8%
if 2.85000000000000004e-92 < b Initial program 67.8%
div-sub67.8%
sub-neg67.8%
neg-mul-167.8%
*-commutative67.8%
associate-/l*67.7%
distribute-neg-frac67.7%
neg-mul-167.7%
*-commutative67.7%
associate-/l*67.6%
distribute-rgt-out67.6%
associate-/r*67.6%
metadata-eval67.6%
sub-neg67.6%
+-commutative67.6%
Simplified67.6%
Taylor expanded in c around 0 86.7%
+-commutative86.7%
mul-1-neg86.7%
unsub-neg86.7%
Simplified86.7%
Final simplification83.7%
(FPCore (a b c)
:precision binary64
(if (<= b -5.9e-211)
(/ c (- b))
(if (<= b 2.15e-124)
(* (sqrt (* c (/ -4.0 a))) (- 0.5))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.9e-211) {
tmp = c / -b;
} else if (b <= 2.15e-124) {
tmp = sqrt((c * (-4.0 / a))) * -0.5;
} 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 <= (-5.9d-211)) then
tmp = c / -b
else if (b <= 2.15d-124) then
tmp = sqrt((c * ((-4.0d0) / a))) * -0.5d0
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 <= -5.9e-211) {
tmp = c / -b;
} else if (b <= 2.15e-124) {
tmp = Math.sqrt((c * (-4.0 / a))) * -0.5;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.9e-211: tmp = c / -b elif b <= 2.15e-124: tmp = math.sqrt((c * (-4.0 / a))) * -0.5 else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.9e-211) tmp = Float64(c / Float64(-b)); elseif (b <= 2.15e-124) tmp = Float64(sqrt(Float64(c * Float64(-4.0 / a))) * Float64(-0.5)); 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 <= -5.9e-211) tmp = c / -b; elseif (b <= 2.15e-124) tmp = sqrt((c * (-4.0 / a))) * -0.5; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.9e-211], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.15e-124], N[(N[Sqrt[N[(c * N[(-4.0 / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-0.5)), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.9 \cdot 10^{-211}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.15 \cdot 10^{-124}:\\
\;\;\;\;\sqrt{c \cdot \frac{-4}{a}} \cdot \left(-0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -5.9000000000000002e-211Initial program 27.9%
div-sub27.6%
sub-neg27.6%
neg-mul-127.6%
*-commutative27.6%
associate-/l*26.4%
distribute-neg-frac26.4%
neg-mul-126.4%
*-commutative26.4%
associate-/l*27.6%
distribute-rgt-out27.9%
associate-/r*27.9%
metadata-eval27.9%
sub-neg27.9%
+-commutative27.9%
Simplified27.9%
Taylor expanded in b around -inf 72.4%
mul-1-neg72.4%
distribute-neg-frac272.4%
Simplified72.4%
if -5.9000000000000002e-211 < b < 2.15e-124Initial program 84.6%
*-commutative84.6%
*-commutative84.6%
sqr-neg84.6%
*-commutative84.6%
sqr-neg84.6%
*-commutative84.6%
associate-*r*84.7%
Simplified84.7%
add-cube-cbrt84.1%
pow384.1%
*-commutative84.1%
associate-*l*84.1%
Applied egg-rr84.1%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt41.7%
neg-mul-141.7%
rem-cube-cbrt42.2%
associate-/l*42.1%
Simplified42.1%
if 2.15e-124 < b Initial program 69.5%
div-sub69.5%
sub-neg69.5%
neg-mul-169.5%
*-commutative69.5%
associate-/l*69.4%
distribute-neg-frac69.4%
neg-mul-169.4%
*-commutative69.4%
associate-/l*69.3%
distribute-rgt-out69.3%
associate-/r*69.3%
metadata-eval69.3%
sub-neg69.3%
+-commutative69.3%
Simplified69.3%
Taylor expanded in c around 0 83.3%
+-commutative83.3%
mul-1-neg83.3%
unsub-neg83.3%
Simplified83.3%
Final simplification72.1%
(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 30.6%
div-sub30.3%
sub-neg30.3%
neg-mul-130.3%
*-commutative30.3%
associate-/l*29.2%
distribute-neg-frac29.2%
neg-mul-129.2%
*-commutative29.2%
associate-/l*30.2%
distribute-rgt-out30.5%
associate-/r*30.5%
metadata-eval30.5%
sub-neg30.5%
+-commutative30.5%
Simplified30.5%
Taylor expanded in b around -inf 67.4%
mul-1-neg67.4%
distribute-neg-frac267.4%
Simplified67.4%
if -5.00000000000023e-311 < b Initial program 74.2%
div-sub74.2%
sub-neg74.2%
neg-mul-174.2%
*-commutative74.2%
associate-/l*74.1%
distribute-neg-frac74.1%
neg-mul-174.1%
*-commutative74.1%
associate-/l*74.0%
distribute-rgt-out74.0%
associate-/r*74.0%
metadata-eval74.0%
sub-neg74.0%
+-commutative74.0%
Simplified74.1%
Taylor expanded in c around 0 65.1%
+-commutative65.1%
mul-1-neg65.1%
unsub-neg65.1%
Simplified65.1%
(FPCore (a b c) :precision binary64 (if (<= b -3.2e-299) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.2e-299) {
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 <= (-3.2d-299)) 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 <= -3.2e-299) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.2e-299: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.2e-299) 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 <= -3.2e-299) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.2e-299], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.2 \cdot 10^{-299}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -3.20000000000000008e-299Initial program 29.9%
div-sub29.6%
sub-neg29.6%
neg-mul-129.6%
*-commutative29.6%
associate-/l*28.5%
distribute-neg-frac28.5%
neg-mul-128.5%
*-commutative28.5%
associate-/l*29.6%
distribute-rgt-out29.9%
associate-/r*29.9%
metadata-eval29.9%
sub-neg29.9%
+-commutative29.9%
Simplified29.9%
Taylor expanded in b around -inf 68.0%
mul-1-neg68.0%
distribute-neg-frac268.0%
Simplified68.0%
if -3.20000000000000008e-299 < b Initial program 74.4%
div-sub74.4%
sub-neg74.4%
neg-mul-174.4%
*-commutative74.4%
associate-/l*74.3%
distribute-neg-frac74.3%
neg-mul-174.3%
*-commutative74.3%
associate-/l*74.2%
distribute-rgt-out74.2%
associate-/r*74.2%
metadata-eval74.2%
sub-neg74.2%
+-commutative74.2%
Simplified74.2%
Taylor expanded in a around 0 64.1%
associate-*r/64.1%
mul-1-neg64.1%
Simplified64.1%
Final simplification65.7%
(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 55.8%
div-sub55.7%
sub-neg55.7%
neg-mul-155.7%
*-commutative55.7%
associate-/l*55.2%
distribute-neg-frac55.2%
neg-mul-155.2%
*-commutative55.2%
associate-/l*55.5%
distribute-rgt-out55.7%
associate-/r*55.7%
metadata-eval55.7%
sub-neg55.7%
+-commutative55.7%
Simplified55.7%
Taylor expanded in b around -inf 29.8%
mul-1-neg29.8%
distribute-neg-frac229.8%
Simplified29.8%
(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 55.8%
div-sub55.7%
sub-neg55.7%
neg-mul-155.7%
*-commutative55.7%
associate-/l*55.2%
distribute-neg-frac55.2%
neg-mul-155.2%
*-commutative55.2%
associate-/l*55.5%
distribute-rgt-out55.7%
associate-/r*55.7%
metadata-eval55.7%
sub-neg55.7%
+-commutative55.7%
Simplified55.7%
Taylor expanded in b around -inf 12.0%
mul-1-neg12.0%
Simplified12.0%
Taylor expanded in a around 0 12.0%
(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 2024137
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:alt
(! :herbie-platform default (let ((d (sqrt (- (* b b) (* 4 (* a c)))))) (let ((r1 (/ (+ (- b) d) (* 2 a)))) (let ((r2 (/ (- (- b) d) (* 2 a)))) (if (< b 0) (/ c (* a r1)) r2)))))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))