
(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 -2.8e-56)
(/ c (- b))
(if (<= b 3.8e+28)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(*
(/ -0.5 a)
(+ b (fabs (* b (sqrt (fma (* a -4.0) (/ (/ c b) b) 1.0)))))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.8e-56) {
tmp = c / -b;
} else if (b <= 3.8e+28) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (-0.5 / a) * (b + fabs((b * sqrt(fma((a * -4.0), ((c / b) / b), 1.0)))));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -2.8e-56) tmp = Float64(c / Float64(-b)); elseif (b <= 3.8e+28) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(-0.5 / a) * Float64(b + abs(Float64(b * sqrt(fma(Float64(a * -4.0), Float64(Float64(c / b) / b), 1.0)))))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -2.8e-56], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 3.8e+28], 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[(-0.5 / a), $MachinePrecision] * N[(b + N[Abs[N[(b * N[Sqrt[N[(N[(a * -4.0), $MachinePrecision] * N[(N[(c / b), $MachinePrecision] / b), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.8 \cdot 10^{-56}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 3.8 \cdot 10^{+28}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \left|b \cdot \sqrt{\mathsf{fma}\left(a \cdot -4, \frac{\frac{c}{b}}{b}, 1\right)}\right|\right)\\
\end{array}
\end{array}
if b < -2.79999999999999993e-56Initial program 16.6%
div-sub16.1%
sub-neg16.1%
neg-mul-116.1%
*-commutative16.1%
associate-/l*13.1%
distribute-neg-frac13.1%
neg-mul-113.1%
*-commutative13.1%
associate-/l*16.1%
distribute-rgt-out16.6%
associate-/r*16.6%
metadata-eval16.6%
sub-neg16.6%
+-commutative16.6%
Simplified16.6%
Taylor expanded in b around -inf 89.4%
mul-1-neg89.4%
distribute-neg-frac289.4%
Simplified89.4%
if -2.79999999999999993e-56 < b < 3.7999999999999999e28Initial program 72.6%
if 3.7999999999999999e28 < b Initial program 65.6%
div-sub65.6%
sub-neg65.6%
neg-mul-165.6%
*-commutative65.6%
associate-/l*65.5%
distribute-neg-frac65.5%
neg-mul-165.5%
*-commutative65.5%
associate-/l*65.5%
distribute-rgt-out65.5%
associate-/r*65.5%
metadata-eval65.5%
sub-neg65.5%
+-commutative65.5%
Simplified65.6%
Taylor expanded in b around inf 65.2%
associate-/l*65.6%
Simplified65.6%
add-sqr-sqrt65.6%
rem-sqrt-square65.6%
sqrt-prod69.7%
sqrt-pow195.4%
metadata-eval95.4%
pow195.4%
+-commutative95.4%
associate-*r*95.4%
fma-define95.4%
div-inv95.4%
pow-flip95.4%
metadata-eval95.4%
Applied egg-rr95.4%
metadata-eval95.4%
pow-sqr95.4%
inv-pow95.4%
inv-pow95.4%
associate-*r*98.2%
div-inv98.2%
div-inv98.3%
Applied egg-rr98.3%
Final simplification86.3%
(FPCore (a b c)
:precision binary64
(if (<= b -9.5e-58)
(/ c (- b))
(if (<= b 3.15e+28)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(*
(/ -0.5 a)
(+ b (* b (sqrt (fma (* a -4.0) (* c (pow b -2.0)) 1.0))))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9.5e-58) {
tmp = c / -b;
} else if (b <= 3.15e+28) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (-0.5 / a) * (b + (b * sqrt(fma((a * -4.0), (c * pow(b, -2.0)), 1.0))));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -9.5e-58) tmp = Float64(c / Float64(-b)); elseif (b <= 3.15e+28) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(-0.5 / a) * Float64(b + Float64(b * sqrt(fma(Float64(a * -4.0), Float64(c * (b ^ -2.0)), 1.0))))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -9.5e-58], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 3.15e+28], 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[(-0.5 / a), $MachinePrecision] * N[(b + N[(b * N[Sqrt[N[(N[(a * -4.0), $MachinePrecision] * N[(c * N[Power[b, -2.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9.5 \cdot 10^{-58}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 3.15 \cdot 10^{+28}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + b \cdot \sqrt{\mathsf{fma}\left(a \cdot -4, c \cdot {b}^{-2}, 1\right)}\right)\\
\end{array}
\end{array}
if b < -9.4999999999999994e-58Initial program 16.6%
div-sub16.1%
sub-neg16.1%
neg-mul-116.1%
*-commutative16.1%
associate-/l*13.1%
distribute-neg-frac13.1%
neg-mul-113.1%
*-commutative13.1%
associate-/l*16.1%
distribute-rgt-out16.6%
associate-/r*16.6%
metadata-eval16.6%
sub-neg16.6%
+-commutative16.6%
Simplified16.6%
Taylor expanded in b around -inf 89.4%
mul-1-neg89.4%
distribute-neg-frac289.4%
Simplified89.4%
if -9.4999999999999994e-58 < b < 3.1500000000000001e28Initial program 72.6%
if 3.1500000000000001e28 < b Initial program 65.6%
div-sub65.6%
sub-neg65.6%
neg-mul-165.6%
*-commutative65.6%
associate-/l*65.5%
distribute-neg-frac65.5%
neg-mul-165.5%
*-commutative65.5%
associate-/l*65.5%
distribute-rgt-out65.5%
associate-/r*65.5%
metadata-eval65.5%
sub-neg65.5%
+-commutative65.5%
Simplified65.6%
Taylor expanded in b around inf 65.2%
associate-/l*65.6%
Simplified65.6%
*-commutative65.6%
sqrt-prod69.7%
+-commutative69.7%
associate-*r*69.7%
fma-define69.7%
div-inv69.7%
pow-flip69.7%
metadata-eval69.7%
sqrt-pow195.4%
metadata-eval95.4%
pow195.4%
Applied egg-rr95.4%
Final simplification85.5%
(FPCore (a b c)
:precision binary64
(if (<= b -1.55e-56)
(/ c (- b))
(if (<= b 3.3e+88)
(/ (- (- 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.55e-56) {
tmp = c / -b;
} else if (b <= 3.3e+88) {
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.55d-56)) then
tmp = c / -b
else if (b <= 3.3d+88) 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.55e-56) {
tmp = c / -b;
} else if (b <= 3.3e+88) {
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.55e-56: tmp = c / -b elif b <= 3.3e+88: 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.55e-56) tmp = Float64(c / Float64(-b)); elseif (b <= 3.3e+88) 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.55e-56) tmp = c / -b; elseif (b <= 3.3e+88) 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.55e-56], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 3.3e+88], 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.55 \cdot 10^{-56}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 3.3 \cdot 10^{+88}:\\
\;\;\;\;\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.54999999999999994e-56Initial program 16.6%
div-sub16.1%
sub-neg16.1%
neg-mul-116.1%
*-commutative16.1%
associate-/l*13.1%
distribute-neg-frac13.1%
neg-mul-113.1%
*-commutative13.1%
associate-/l*16.1%
distribute-rgt-out16.6%
associate-/r*16.6%
metadata-eval16.6%
sub-neg16.6%
+-commutative16.6%
Simplified16.6%
Taylor expanded in b around -inf 89.4%
mul-1-neg89.4%
distribute-neg-frac289.4%
Simplified89.4%
if -1.54999999999999994e-56 < b < 3.3000000000000003e88Initial program 73.8%
if 3.3000000000000003e88 < b Initial program 61.6%
div-sub61.6%
sub-neg61.6%
neg-mul-161.6%
*-commutative61.6%
associate-/l*61.5%
distribute-neg-frac61.5%
neg-mul-161.5%
*-commutative61.5%
associate-/l*61.4%
distribute-rgt-out61.4%
associate-/r*61.4%
metadata-eval61.4%
sub-neg61.4%
+-commutative61.4%
Simplified61.6%
Taylor expanded in c around 0 95.5%
+-commutative95.5%
mul-1-neg95.5%
unsub-neg95.5%
Simplified95.5%
Final simplification84.7%
(FPCore (a b c)
:precision binary64
(if (<= b -1.5e-57)
(/ c (- b))
(if (<= b 3.2e-32)
(* (/ -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.5e-57) {
tmp = c / -b;
} else if (b <= 3.2e-32) {
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.5d-57)) then
tmp = c / -b
else if (b <= 3.2d-32) 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.5e-57) {
tmp = c / -b;
} else if (b <= 3.2e-32) {
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.5e-57: tmp = c / -b elif b <= 3.2e-32: 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.5e-57) tmp = Float64(c / Float64(-b)); elseif (b <= 3.2e-32) 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.5e-57) tmp = c / -b; elseif (b <= 3.2e-32) 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.5e-57], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 3.2e-32], 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.5 \cdot 10^{-57}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 3.2 \cdot 10^{-32}:\\
\;\;\;\;\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.5e-57Initial program 16.6%
div-sub16.1%
sub-neg16.1%
neg-mul-116.1%
*-commutative16.1%
associate-/l*13.1%
distribute-neg-frac13.1%
neg-mul-113.1%
*-commutative13.1%
associate-/l*16.1%
distribute-rgt-out16.6%
associate-/r*16.6%
metadata-eval16.6%
sub-neg16.6%
+-commutative16.6%
Simplified16.6%
Taylor expanded in b around -inf 89.4%
mul-1-neg89.4%
distribute-neg-frac289.4%
Simplified89.4%
if -1.5e-57 < b < 3.2000000000000002e-32Initial program 70.4%
div-sub70.4%
sub-neg70.4%
neg-mul-170.4%
*-commutative70.4%
associate-/l*70.4%
distribute-neg-frac70.4%
neg-mul-170.4%
*-commutative70.4%
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 a around inf 61.7%
*-commutative61.7%
Simplified61.7%
if 3.2000000000000002e-32 < b Initial program 68.6%
div-sub68.6%
sub-neg68.6%
neg-mul-168.6%
*-commutative68.6%
associate-/l*68.5%
distribute-neg-frac68.5%
neg-mul-168.5%
*-commutative68.5%
associate-/l*68.4%
distribute-rgt-out68.4%
associate-/r*68.4%
metadata-eval68.4%
sub-neg68.4%
+-commutative68.4%
Simplified68.5%
Taylor expanded in c around 0 82.9%
+-commutative82.9%
mul-1-neg82.9%
unsub-neg82.9%
Simplified82.9%
Final simplification79.9%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-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 <= (-5d-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 <= -5e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-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 <= -5e-310) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-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 -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 26.5%
div-sub26.1%
sub-neg26.1%
neg-mul-126.1%
*-commutative26.1%
associate-/l*23.8%
distribute-neg-frac23.8%
neg-mul-123.8%
*-commutative23.8%
associate-/l*26.1%
distribute-rgt-out26.5%
associate-/r*26.5%
metadata-eval26.5%
sub-neg26.5%
+-commutative26.5%
Simplified26.5%
Taylor expanded in b around -inf 74.1%
mul-1-neg74.1%
distribute-neg-frac274.1%
Simplified74.1%
if -4.999999999999985e-310 < b Initial program 70.9%
div-sub70.9%
sub-neg70.9%
neg-mul-170.9%
*-commutative70.9%
associate-/l*70.8%
distribute-neg-frac70.8%
neg-mul-170.8%
*-commutative70.8%
associate-/l*70.7%
distribute-rgt-out70.7%
associate-/r*70.7%
metadata-eval70.7%
sub-neg70.7%
+-commutative70.7%
Simplified70.7%
Taylor expanded in c around 0 63.4%
+-commutative63.4%
mul-1-neg63.4%
unsub-neg63.4%
Simplified63.4%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ c (- b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
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-310)) 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-310) {
tmp = c / -b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = c / -b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) 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-310) tmp = c / -b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(c / (-b)), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 26.5%
div-sub26.1%
sub-neg26.1%
neg-mul-126.1%
*-commutative26.1%
associate-/l*23.8%
distribute-neg-frac23.8%
neg-mul-123.8%
*-commutative23.8%
associate-/l*26.1%
distribute-rgt-out26.5%
associate-/r*26.5%
metadata-eval26.5%
sub-neg26.5%
+-commutative26.5%
Simplified26.5%
Taylor expanded in b around -inf 74.1%
mul-1-neg74.1%
distribute-neg-frac274.1%
Simplified74.1%
if -4.999999999999985e-310 < b Initial program 70.9%
div-sub70.9%
sub-neg70.9%
neg-mul-170.9%
*-commutative70.9%
associate-/l*70.8%
distribute-neg-frac70.8%
neg-mul-170.8%
*-commutative70.8%
associate-/l*70.7%
distribute-rgt-out70.7%
associate-/r*70.7%
metadata-eval70.7%
sub-neg70.7%
+-commutative70.7%
Simplified70.7%
Taylor expanded in a around 0 62.8%
associate-*r/62.8%
mul-1-neg62.8%
Simplified62.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 48.4%
div-sub48.1%
sub-neg48.1%
neg-mul-148.1%
*-commutative48.1%
associate-/l*46.9%
distribute-neg-frac46.9%
neg-mul-146.9%
*-commutative46.9%
associate-/l*48.0%
distribute-rgt-out48.2%
associate-/r*48.2%
metadata-eval48.2%
sub-neg48.2%
+-commutative48.2%
Simplified48.3%
Taylor expanded in b around -inf 38.9%
mul-1-neg38.9%
distribute-neg-frac238.9%
Simplified38.9%
(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.4%
div-sub48.1%
sub-neg48.1%
neg-mul-148.1%
*-commutative48.1%
associate-/l*46.9%
distribute-neg-frac46.9%
neg-mul-146.9%
*-commutative46.9%
associate-/l*48.0%
distribute-rgt-out48.2%
associate-/r*48.2%
metadata-eval48.2%
sub-neg48.2%
+-commutative48.2%
Simplified48.3%
Taylor expanded in b around inf 31.6%
Taylor expanded in b around 0 12.6%
(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 48.4%
div-sub48.1%
sub-neg48.1%
neg-mul-148.1%
*-commutative48.1%
associate-/l*46.9%
distribute-neg-frac46.9%
neg-mul-146.9%
*-commutative46.9%
associate-/l*48.0%
distribute-rgt-out48.2%
associate-/r*48.2%
metadata-eval48.2%
sub-neg48.2%
+-commutative48.2%
Simplified48.3%
Taylor expanded in a around 0 32.3%
associate-*r/32.3%
mul-1-neg32.3%
Simplified32.3%
add-sqr-sqrt1.4%
sqrt-unprod2.1%
sqr-neg2.1%
sqrt-unprod0.8%
add-sqr-sqrt2.7%
*-un-lft-identity2.7%
Applied egg-rr2.7%
*-lft-identity2.7%
Simplified2.7%
(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 2024112
(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)))