
(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 9 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 -1.52e-93)
(/ c (- b))
(if (<= b 8.2e+71)
(/ (- (- 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 <= -1.52e-93) {
tmp = c / -b;
} else if (b <= 8.2e+71) {
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 <= (-1.52d-93)) then
tmp = c / -b
else if (b <= 8.2d+71) 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 <= -1.52e-93) {
tmp = c / -b;
} else if (b <= 8.2e+71) {
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 <= -1.52e-93: tmp = c / -b elif b <= 8.2e+71: 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 <= -1.52e-93) tmp = Float64(c / Float64(-b)); elseif (b <= 8.2e+71) 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 <= -1.52e-93) tmp = c / -b; elseif (b <= 8.2e+71) 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, -1.52e-93], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 8.2e+71], 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 -1.52 \cdot 10^{-93}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 8.2 \cdot 10^{+71}:\\
\;\;\;\;\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.52e-93Initial program 17.9%
div-sub17.2%
sub-neg17.2%
neg-mul-117.2%
*-commutative17.2%
associate-/l*13.9%
distribute-neg-frac13.9%
neg-mul-113.9%
*-commutative13.9%
associate-/l*17.3%
distribute-rgt-out17.9%
associate-/r*17.9%
metadata-eval17.9%
sub-neg17.9%
+-commutative17.9%
Simplified17.9%
Taylor expanded in b around -inf 83.5%
mul-1-neg83.5%
distribute-neg-frac283.5%
Simplified83.5%
if -1.52e-93 < b < 8.2000000000000004e71Initial program 85.6%
if 8.2000000000000004e71 < b Initial program 46.1%
div-sub46.1%
sub-neg46.1%
neg-mul-146.1%
*-commutative46.1%
associate-/l*46.0%
distribute-neg-frac46.0%
neg-mul-146.0%
*-commutative46.0%
associate-/l*46.0%
distribute-rgt-out46.0%
associate-/r*46.0%
metadata-eval46.0%
sub-neg46.0%
+-commutative46.0%
Simplified46.2%
Taylor expanded in c around 0 90.9%
+-commutative90.9%
mul-1-neg90.9%
unsub-neg90.9%
Simplified90.9%
Final simplification86.2%
(FPCore (a b c)
:precision binary64
(if (<= b -1.75e-90)
(/ c (- b))
(if (<= b 5.6e-79)
(/ (* -0.5 (+ b (sqrt (* a (* c -4.0))))) a)
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.75e-90) {
tmp = c / -b;
} else if (b <= 5.6e-79) {
tmp = (-0.5 * (b + sqrt((a * (c * -4.0))))) / a;
} 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 <= (-1.75d-90)) then
tmp = c / -b
else if (b <= 5.6d-79) then
tmp = ((-0.5d0) * (b + sqrt((a * (c * (-4.0d0)))))) / a
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 <= -1.75e-90) {
tmp = c / -b;
} else if (b <= 5.6e-79) {
tmp = (-0.5 * (b + Math.sqrt((a * (c * -4.0))))) / a;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.75e-90: tmp = c / -b elif b <= 5.6e-79: tmp = (-0.5 * (b + math.sqrt((a * (c * -4.0))))) / a else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.75e-90) tmp = Float64(c / Float64(-b)); elseif (b <= 5.6e-79) tmp = Float64(Float64(-0.5 * Float64(b + sqrt(Float64(a * Float64(c * -4.0))))) / a); 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 <= -1.75e-90) tmp = c / -b; elseif (b <= 5.6e-79) tmp = (-0.5 * (b + sqrt((a * (c * -4.0))))) / a; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.75e-90], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 5.6e-79], N[(N[(-0.5 * N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.75 \cdot 10^{-90}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 5.6 \cdot 10^{-79}:\\
\;\;\;\;\frac{-0.5 \cdot \left(b + \sqrt{a \cdot \left(c \cdot -4\right)}\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.7499999999999999e-90Initial program 17.9%
div-sub17.2%
sub-neg17.2%
neg-mul-117.2%
*-commutative17.2%
associate-/l*13.9%
distribute-neg-frac13.9%
neg-mul-113.9%
*-commutative13.9%
associate-/l*17.3%
distribute-rgt-out17.9%
associate-/r*17.9%
metadata-eval17.9%
sub-neg17.9%
+-commutative17.9%
Simplified17.9%
Taylor expanded in b around -inf 83.5%
mul-1-neg83.5%
distribute-neg-frac283.5%
Simplified83.5%
if -1.7499999999999999e-90 < b < 5.60000000000000023e-79Initial program 83.8%
div-sub83.8%
sub-neg83.8%
neg-mul-183.8%
*-commutative83.8%
associate-/l*83.9%
distribute-neg-frac83.9%
neg-mul-183.9%
*-commutative83.9%
associate-/l*83.6%
distribute-rgt-out83.6%
associate-/r*83.6%
metadata-eval83.6%
sub-neg83.6%
+-commutative83.6%
Simplified83.6%
Taylor expanded in a around inf 76.0%
*-commutative76.0%
Simplified76.0%
associate-*l/76.2%
associate-*l*76.2%
Applied egg-rr76.2%
if 5.60000000000000023e-79 < b Initial program 61.9%
div-sub61.9%
sub-neg61.9%
neg-mul-161.9%
*-commutative61.9%
associate-/l*61.8%
distribute-neg-frac61.8%
neg-mul-161.8%
*-commutative61.8%
associate-/l*61.8%
distribute-rgt-out61.7%
associate-/r*61.7%
metadata-eval61.7%
sub-neg61.7%
+-commutative61.7%
Simplified61.9%
Taylor expanded in c around 0 81.8%
+-commutative81.8%
mul-1-neg81.8%
unsub-neg81.8%
Simplified81.8%
(FPCore (a b c)
:precision binary64
(if (<= b -1.6e-93)
(/ c (- b))
(if (<= b 1.9e-81)
(* (/ -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 <= -1.6e-93) {
tmp = c / -b;
} else if (b <= 1.9e-81) {
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 <= (-1.6d-93)) then
tmp = c / -b
else if (b <= 1.9d-81) 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 <= -1.6e-93) {
tmp = c / -b;
} else if (b <= 1.9e-81) {
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 <= -1.6e-93: tmp = c / -b elif b <= 1.9e-81: 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 <= -1.6e-93) tmp = Float64(c / Float64(-b)); elseif (b <= 1.9e-81) 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 <= -1.6e-93) tmp = c / -b; elseif (b <= 1.9e-81) 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, -1.6e-93], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.9e-81], 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 -1.6 \cdot 10^{-93}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.9 \cdot 10^{-81}:\\
\;\;\;\;\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.5999999999999999e-93Initial program 17.9%
div-sub17.2%
sub-neg17.2%
neg-mul-117.2%
*-commutative17.2%
associate-/l*13.9%
distribute-neg-frac13.9%
neg-mul-113.9%
*-commutative13.9%
associate-/l*17.3%
distribute-rgt-out17.9%
associate-/r*17.9%
metadata-eval17.9%
sub-neg17.9%
+-commutative17.9%
Simplified17.9%
Taylor expanded in b around -inf 83.5%
mul-1-neg83.5%
distribute-neg-frac283.5%
Simplified83.5%
if -1.5999999999999999e-93 < b < 1.8999999999999999e-81Initial program 83.8%
div-sub83.8%
sub-neg83.8%
neg-mul-183.8%
*-commutative83.8%
associate-/l*83.9%
distribute-neg-frac83.9%
neg-mul-183.9%
*-commutative83.9%
associate-/l*83.6%
distribute-rgt-out83.6%
associate-/r*83.6%
metadata-eval83.6%
sub-neg83.6%
+-commutative83.6%
Simplified83.6%
Taylor expanded in a around inf 76.0%
*-commutative76.0%
Simplified76.0%
if 1.8999999999999999e-81 < b Initial program 61.9%
div-sub61.9%
sub-neg61.9%
neg-mul-161.9%
*-commutative61.9%
associate-/l*61.8%
distribute-neg-frac61.8%
neg-mul-161.8%
*-commutative61.8%
associate-/l*61.8%
distribute-rgt-out61.7%
associate-/r*61.7%
metadata-eval61.7%
sub-neg61.7%
+-commutative61.7%
Simplified61.9%
Taylor expanded in c around 0 81.8%
+-commutative81.8%
mul-1-neg81.8%
unsub-neg81.8%
Simplified81.8%
Final simplification80.9%
(FPCore (a b c)
:precision binary64
(if (<= b -3.75e-97)
(/ c (- b))
(if (<= b 5.5e-156)
(* 0.5 (- (sqrt (/ (* c -4.0) a))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.75e-97) {
tmp = c / -b;
} else if (b <= 5.5e-156) {
tmp = 0.5 * -sqrt(((c * -4.0) / a));
} 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 <= (-3.75d-97)) then
tmp = c / -b
else if (b <= 5.5d-156) then
tmp = 0.5d0 * -sqrt(((c * (-4.0d0)) / a))
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 <= -3.75e-97) {
tmp = c / -b;
} else if (b <= 5.5e-156) {
tmp = 0.5 * -Math.sqrt(((c * -4.0) / a));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.75e-97: tmp = c / -b elif b <= 5.5e-156: tmp = 0.5 * -math.sqrt(((c * -4.0) / a)) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.75e-97) tmp = Float64(c / Float64(-b)); elseif (b <= 5.5e-156) tmp = Float64(0.5 * Float64(-sqrt(Float64(Float64(c * -4.0) / a)))); 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 <= -3.75e-97) tmp = c / -b; elseif (b <= 5.5e-156) tmp = 0.5 * -sqrt(((c * -4.0) / a)); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.75e-97], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 5.5e-156], N[(0.5 * (-N[Sqrt[N[(N[(c * -4.0), $MachinePrecision] / a), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.75 \cdot 10^{-97}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 5.5 \cdot 10^{-156}:\\
\;\;\;\;0.5 \cdot \left(-\sqrt{\frac{c \cdot -4}{a}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.75e-97Initial program 18.8%
div-sub18.1%
sub-neg18.1%
neg-mul-118.1%
*-commutative18.1%
associate-/l*14.8%
distribute-neg-frac14.8%
neg-mul-114.8%
*-commutative14.8%
associate-/l*18.1%
distribute-rgt-out18.8%
associate-/r*18.8%
metadata-eval18.8%
sub-neg18.8%
+-commutative18.8%
Simplified18.8%
Taylor expanded in b around -inf 82.8%
mul-1-neg82.8%
distribute-neg-frac282.8%
Simplified82.8%
if -3.75e-97 < b < 5.4999999999999998e-156Initial program 81.4%
*-commutative81.4%
*-commutative81.4%
sqr-neg81.4%
*-commutative81.4%
sqr-neg81.4%
*-commutative81.4%
associate-*r*81.4%
Simplified81.4%
add-cube-cbrt80.9%
pow380.9%
*-commutative80.9%
associate-*l*80.9%
Applied egg-rr80.9%
Taylor expanded in c around -inf 0.0%
rem-cube-cbrt0.0%
unpow20.0%
rem-square-sqrt39.2%
Simplified39.2%
if 5.4999999999999998e-156 < b Initial program 65.4%
div-sub65.4%
sub-neg65.4%
neg-mul-165.4%
*-commutative65.4%
associate-/l*65.3%
distribute-neg-frac65.3%
neg-mul-165.3%
*-commutative65.3%
associate-/l*65.2%
distribute-rgt-out65.2%
associate-/r*65.2%
metadata-eval65.2%
sub-neg65.2%
+-commutative65.2%
Simplified65.3%
Taylor expanded in c around 0 77.6%
+-commutative77.6%
mul-1-neg77.6%
unsub-neg77.6%
Simplified77.6%
Final simplification71.7%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
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 <= (-1d-310)) 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 <= -1e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-310) 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 <= -1e-310) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], N[(c / (-b)), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 34.0%
div-sub33.5%
sub-neg33.5%
neg-mul-133.5%
*-commutative33.5%
associate-/l*31.1%
distribute-neg-frac31.1%
neg-mul-131.1%
*-commutative31.1%
associate-/l*33.4%
distribute-rgt-out33.9%
associate-/r*33.9%
metadata-eval33.9%
sub-neg33.9%
+-commutative33.9%
Simplified33.9%
Taylor expanded in b around -inf 65.8%
mul-1-neg65.8%
distribute-neg-frac265.8%
Simplified65.8%
if -9.999999999999969e-311 < b Initial program 67.8%
div-sub67.8%
sub-neg67.8%
neg-mul-167.8%
*-commutative67.8%
associate-/l*67.8%
distribute-neg-frac67.8%
neg-mul-167.8%
*-commutative67.8%
associate-/l*67.7%
distribute-rgt-out67.7%
associate-/r*67.7%
metadata-eval67.7%
sub-neg67.7%
+-commutative67.7%
Simplified67.8%
Taylor expanded in c around 0 65.9%
+-commutative65.9%
mul-1-neg65.9%
unsub-neg65.9%
Simplified65.9%
(FPCore (a b c) :precision binary64 (if (<= b -5e-309) (/ c (- b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-309) {
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 <= (-5d-309)) 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 <= -5e-309) {
tmp = c / -b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-309: tmp = c / -b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-309) tmp = Float64(c / Float64(-b)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-309) tmp = c / -b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-309], N[(c / (-b)), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-309}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -4.9999999999999995e-309Initial program 34.0%
div-sub33.5%
sub-neg33.5%
neg-mul-133.5%
*-commutative33.5%
associate-/l*31.1%
distribute-neg-frac31.1%
neg-mul-131.1%
*-commutative31.1%
associate-/l*33.4%
distribute-rgt-out33.9%
associate-/r*33.9%
metadata-eval33.9%
sub-neg33.9%
+-commutative33.9%
Simplified33.9%
Taylor expanded in b around -inf 65.8%
mul-1-neg65.8%
distribute-neg-frac265.8%
Simplified65.8%
if -4.9999999999999995e-309 < b Initial program 67.8%
div-sub67.8%
sub-neg67.8%
neg-mul-167.8%
*-commutative67.8%
associate-/l*67.8%
distribute-neg-frac67.8%
neg-mul-167.8%
*-commutative67.8%
associate-/l*67.7%
distribute-rgt-out67.7%
associate-/r*67.7%
metadata-eval67.7%
sub-neg67.7%
+-commutative67.7%
Simplified67.8%
Taylor expanded in a around 0 65.2%
associate-*r/65.2%
mul-1-neg65.2%
Simplified65.2%
(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 51.7%
div-sub51.5%
sub-neg51.5%
neg-mul-151.5%
*-commutative51.5%
associate-/l*50.3%
distribute-neg-frac50.3%
neg-mul-150.3%
*-commutative50.3%
associate-/l*51.4%
distribute-rgt-out51.6%
associate-/r*51.6%
metadata-eval51.6%
sub-neg51.6%
+-commutative51.6%
Simplified51.7%
Taylor expanded in b around -inf 32.6%
mul-1-neg32.6%
distribute-neg-frac232.6%
Simplified32.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 51.7%
div-sub51.5%
sub-neg51.5%
neg-mul-151.5%
*-commutative51.5%
associate-/l*50.3%
distribute-neg-frac50.3%
neg-mul-150.3%
*-commutative50.3%
associate-/l*51.4%
distribute-rgt-out51.6%
associate-/r*51.6%
metadata-eval51.6%
sub-neg51.6%
+-commutative51.6%
Simplified51.7%
Taylor expanded in b around -inf 32.6%
mul-1-neg32.6%
distribute-neg-frac232.6%
Simplified32.6%
*-un-lft-identity32.6%
add-sqr-sqrt31.2%
sqrt-unprod24.3%
sqr-neg24.3%
sqrt-prod1.9%
add-sqr-sqrt11.4%
Applied egg-rr11.4%
*-lft-identity11.4%
Simplified11.4%
(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 51.7%
div-sub51.5%
sub-neg51.5%
neg-mul-151.5%
*-commutative51.5%
associate-/l*50.3%
distribute-neg-frac50.3%
neg-mul-150.3%
*-commutative50.3%
associate-/l*51.4%
distribute-rgt-out51.6%
associate-/r*51.6%
metadata-eval51.6%
sub-neg51.6%
+-commutative51.6%
Simplified51.7%
Taylor expanded in a around 0 35.4%
associate-*r/35.4%
mul-1-neg35.4%
Simplified35.4%
add-sqr-sqrt1.3%
sqrt-unprod2.0%
sqr-neg2.0%
sqrt-prod0.8%
add-sqr-sqrt2.7%
div-inv2.7%
Applied egg-rr2.7%
associate-*r/2.7%
*-rgt-identity2.7%
Simplified2.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fabs (/ b 2.0)))
(t_1 (* (sqrt (fabs a)) (sqrt (fabs c))))
(t_2
(if (== (copysign a c) a)
(* (sqrt (- t_0 t_1)) (sqrt (+ t_0 t_1)))
(hypot (/ b 2.0) t_1))))
(if (< b 0.0) (/ c (- t_2 (/ b 2.0))) (/ (+ (/ b 2.0) t_2) (- a)))))
double code(double a, double b, double c) {
double t_0 = fabs((b / 2.0));
double t_1 = sqrt(fabs(a)) * sqrt(fabs(c));
double tmp;
if (copysign(a, c) == a) {
tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1));
} else {
tmp = hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = c / (t_2 - (b / 2.0));
} else {
tmp_1 = ((b / 2.0) + t_2) / -a;
}
return tmp_1;
}
public static double code(double a, double b, double c) {
double t_0 = Math.abs((b / 2.0));
double t_1 = Math.sqrt(Math.abs(a)) * Math.sqrt(Math.abs(c));
double tmp;
if (Math.copySign(a, c) == a) {
tmp = Math.sqrt((t_0 - t_1)) * Math.sqrt((t_0 + t_1));
} else {
tmp = Math.hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = c / (t_2 - (b / 2.0));
} else {
tmp_1 = ((b / 2.0) + t_2) / -a;
}
return tmp_1;
}
def code(a, b, c): t_0 = math.fabs((b / 2.0)) t_1 = math.sqrt(math.fabs(a)) * math.sqrt(math.fabs(c)) tmp = 0 if math.copysign(a, c) == a: tmp = math.sqrt((t_0 - t_1)) * math.sqrt((t_0 + t_1)) else: tmp = math.hypot((b / 2.0), t_1) t_2 = tmp tmp_1 = 0 if b < 0.0: tmp_1 = c / (t_2 - (b / 2.0)) else: tmp_1 = ((b / 2.0) + t_2) / -a return tmp_1
function code(a, b, c) t_0 = abs(Float64(b / 2.0)) t_1 = Float64(sqrt(abs(a)) * sqrt(abs(c))) tmp = 0.0 if (copysign(a, c) == a) tmp = Float64(sqrt(Float64(t_0 - t_1)) * sqrt(Float64(t_0 + t_1))); else tmp = hypot(Float64(b / 2.0), t_1); end t_2 = tmp tmp_1 = 0.0 if (b < 0.0) tmp_1 = Float64(c / Float64(t_2 - Float64(b / 2.0))); else tmp_1 = Float64(Float64(Float64(b / 2.0) + t_2) / Float64(-a)); end return tmp_1 end
function tmp_3 = code(a, b, c) t_0 = abs((b / 2.0)); t_1 = sqrt(abs(a)) * sqrt(abs(c)); tmp = 0.0; if ((sign(c) * abs(a)) == a) tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1)); else tmp = hypot((b / 2.0), t_1); end t_2 = tmp; tmp_2 = 0.0; if (b < 0.0) tmp_2 = c / (t_2 - (b / 2.0)); else tmp_2 = ((b / 2.0) + t_2) / -a; end tmp_3 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[Abs[N[(b / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Sqrt[N[Abs[a], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[c], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = If[Equal[N[With[{TMP1 = Abs[a], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], a], N[(N[Sqrt[N[(t$95$0 - t$95$1), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(b / 2.0), $MachinePrecision] ^ 2 + t$95$1 ^ 2], $MachinePrecision]]}, If[Less[b, 0.0], N[(c / N[(t$95$2 - N[(b / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(b / 2.0), $MachinePrecision] + t$95$2), $MachinePrecision] / (-a)), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{b}{2}\right|\\
t_1 := \sqrt{\left|a\right|} \cdot \sqrt{\left|c\right|}\\
t_2 := \begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(a, c\right) = a:\\
\;\;\;\;\sqrt{t\_0 - t\_1} \cdot \sqrt{t\_0 + t\_1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\frac{b}{2}, t\_1\right)\\
\end{array}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{t\_2 - \frac{b}{2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b}{2} + t\_2}{-a}\\
\end{array}
\end{array}
herbie shell --seed 2024133
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-expected 10
:alt
(! :herbie-platform default (let ((sqtD (let ((x (* (sqrt (fabs a)) (sqrt (fabs c))))) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2)) x)) (sqrt (+ (fabs (/ b 2)) x))) (hypot (/ b 2) x))))) (if (< b 0) (/ c (- sqtD (/ b 2))) (/ (+ (/ b 2) sqtD) (- a)))))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))