
(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.22e-110)
(/ c (- b))
(if (<= b 2.5e+98)
(/ (- (/ (* b b) (- 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 <= -1.22e-110) {
tmp = c / -b;
} else if (b <= 2.5e+98) {
tmp = (((b * b) / -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 <= (-1.22d-110)) then
tmp = c / -b
else if (b <= 2.5d+98) then
tmp = (((b * b) / -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 <= -1.22e-110) {
tmp = c / -b;
} else if (b <= 2.5e+98) {
tmp = (((b * b) / -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 <= -1.22e-110: tmp = c / -b elif b <= 2.5e+98: tmp = (((b * b) / -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 <= -1.22e-110) tmp = Float64(c / Float64(-b)); elseif (b <= 2.5e+98) tmp = Float64(Float64(Float64(Float64(b * b) / Float64(-b)) - sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * 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.22e-110) tmp = c / -b; elseif (b <= 2.5e+98) tmp = (((b * b) / -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, -1.22e-110], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.5e+98], N[(N[(N[(N[(b * b), $MachinePrecision] / (-b)), $MachinePrecision] - 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 -1.22 \cdot 10^{-110}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.5 \cdot 10^{+98}:\\
\;\;\;\;\frac{\frac{b \cdot b}{-b} - \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.22e-110Initial program 17.6%
div-sub16.2%
sub-neg16.2%
neg-mul-116.2%
*-commutative16.2%
associate-/l*15.6%
distribute-neg-frac15.6%
neg-mul-115.6%
*-commutative15.6%
associate-/l*16.2%
distribute-rgt-out17.6%
associate-/r*17.6%
metadata-eval17.6%
sub-neg17.6%
+-commutative17.6%
Simplified17.6%
Taylor expanded in b around -inf 80.0%
mul-1-neg80.0%
distribute-neg-frac280.0%
Simplified80.0%
if -1.22e-110 < b < 2.4999999999999999e98Initial program 82.0%
*-commutative82.0%
*-commutative82.0%
sqr-neg82.0%
*-commutative82.0%
sqr-neg82.0%
*-commutative82.0%
associate-*r*82.0%
Simplified82.0%
neg-sub082.0%
flip--82.0%
metadata-eval82.0%
pow282.0%
add-sqr-sqrt56.4%
sqrt-prod49.1%
sqr-neg49.1%
sqrt-unprod24.9%
add-sqr-sqrt57.6%
sub-neg57.6%
neg-sub057.6%
add-sqr-sqrt24.9%
sqrt-unprod49.1%
sqr-neg49.1%
sqrt-prod56.4%
add-sqr-sqrt82.0%
Applied egg-rr82.0%
neg-sub082.0%
Simplified82.0%
pow282.0%
Applied egg-rr82.0%
if 2.4999999999999999e98 < b Initial program 61.2%
div-sub61.2%
sub-neg61.2%
neg-mul-161.2%
*-commutative61.2%
associate-/l*61.2%
distribute-neg-frac61.2%
neg-mul-161.2%
*-commutative61.2%
associate-/l*61.0%
distribute-rgt-out61.0%
associate-/r*61.0%
metadata-eval61.0%
sub-neg61.0%
+-commutative61.0%
Simplified61.0%
Taylor expanded in c around 0 96.6%
+-commutative96.6%
mul-1-neg96.6%
unsub-neg96.6%
Simplified96.6%
Final simplification84.3%
(FPCore (a b c)
:precision binary64
(if (<= b -7.2e-116)
(/ c (- b))
(if (<= b 9.2e+97)
(/ (- (- 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 <= -7.2e-116) {
tmp = c / -b;
} else if (b <= 9.2e+97) {
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 <= (-7.2d-116)) then
tmp = c / -b
else if (b <= 9.2d+97) 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 <= -7.2e-116) {
tmp = c / -b;
} else if (b <= 9.2e+97) {
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 <= -7.2e-116: tmp = c / -b elif b <= 9.2e+97: 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 <= -7.2e-116) tmp = Float64(c / Float64(-b)); elseif (b <= 9.2e+97) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * 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 <= -7.2e-116) tmp = c / -b; elseif (b <= 9.2e+97) 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, -7.2e-116], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 9.2e+97], 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 -7.2 \cdot 10^{-116}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 9.2 \cdot 10^{+97}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -7.19999999999999951e-116Initial program 17.6%
div-sub16.2%
sub-neg16.2%
neg-mul-116.2%
*-commutative16.2%
associate-/l*15.6%
distribute-neg-frac15.6%
neg-mul-115.6%
*-commutative15.6%
associate-/l*16.2%
distribute-rgt-out17.6%
associate-/r*17.6%
metadata-eval17.6%
sub-neg17.6%
+-commutative17.6%
Simplified17.6%
Taylor expanded in b around -inf 80.0%
mul-1-neg80.0%
distribute-neg-frac280.0%
Simplified80.0%
if -7.19999999999999951e-116 < b < 9.20000000000000022e97Initial program 82.0%
*-commutative82.0%
*-commutative82.0%
sqr-neg82.0%
*-commutative82.0%
sqr-neg82.0%
*-commutative82.0%
associate-*r*82.0%
Simplified82.0%
if 9.20000000000000022e97 < b Initial program 61.2%
div-sub61.2%
sub-neg61.2%
neg-mul-161.2%
*-commutative61.2%
associate-/l*61.2%
distribute-neg-frac61.2%
neg-mul-161.2%
*-commutative61.2%
associate-/l*61.0%
distribute-rgt-out61.0%
associate-/r*61.0%
metadata-eval61.0%
sub-neg61.0%
+-commutative61.0%
Simplified61.0%
Taylor expanded in c around 0 96.6%
+-commutative96.6%
mul-1-neg96.6%
unsub-neg96.6%
Simplified96.6%
Final simplification84.3%
(FPCore (a b c)
:precision binary64
(if (<= b -1.22e-110)
(/ c (- b))
(if (<= b 2.6e+98)
(/ (- (- 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.22e-110) {
tmp = c / -b;
} else if (b <= 2.6e+98) {
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.22d-110)) then
tmp = c / -b
else if (b <= 2.6d+98) 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.22e-110) {
tmp = c / -b;
} else if (b <= 2.6e+98) {
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.22e-110: tmp = c / -b elif b <= 2.6e+98: 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.22e-110) tmp = Float64(c / Float64(-b)); elseif (b <= 2.6e+98) 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.22e-110) tmp = c / -b; elseif (b <= 2.6e+98) 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.22e-110], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.6e+98], 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.22 \cdot 10^{-110}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.6 \cdot 10^{+98}:\\
\;\;\;\;\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.22e-110Initial program 17.6%
div-sub16.2%
sub-neg16.2%
neg-mul-116.2%
*-commutative16.2%
associate-/l*15.6%
distribute-neg-frac15.6%
neg-mul-115.6%
*-commutative15.6%
associate-/l*16.2%
distribute-rgt-out17.6%
associate-/r*17.6%
metadata-eval17.6%
sub-neg17.6%
+-commutative17.6%
Simplified17.6%
Taylor expanded in b around -inf 80.0%
mul-1-neg80.0%
distribute-neg-frac280.0%
Simplified80.0%
if -1.22e-110 < b < 2.6e98Initial program 82.0%
if 2.6e98 < b Initial program 61.2%
div-sub61.2%
sub-neg61.2%
neg-mul-161.2%
*-commutative61.2%
associate-/l*61.2%
distribute-neg-frac61.2%
neg-mul-161.2%
*-commutative61.2%
associate-/l*61.0%
distribute-rgt-out61.0%
associate-/r*61.0%
metadata-eval61.0%
sub-neg61.0%
+-commutative61.0%
Simplified61.0%
Taylor expanded in c around 0 96.6%
+-commutative96.6%
mul-1-neg96.6%
unsub-neg96.6%
Simplified96.6%
Final simplification84.3%
(FPCore (a b c)
:precision binary64
(if (<= b -5.8e-113)
(/ c (- b))
(if (<= b 5.6e-48)
(* (/ -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 <= -5.8e-113) {
tmp = c / -b;
} else if (b <= 5.6e-48) {
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 <= (-5.8d-113)) then
tmp = c / -b
else if (b <= 5.6d-48) 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 <= -5.8e-113) {
tmp = c / -b;
} else if (b <= 5.6e-48) {
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 <= -5.8e-113: tmp = c / -b elif b <= 5.6e-48: 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 <= -5.8e-113) tmp = Float64(c / Float64(-b)); elseif (b <= 5.6e-48) 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 <= -5.8e-113) tmp = c / -b; elseif (b <= 5.6e-48) 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, -5.8e-113], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 5.6e-48], 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 -5.8 \cdot 10^{-113}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 5.6 \cdot 10^{-48}:\\
\;\;\;\;\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 < -5.80000000000000008e-113Initial program 17.6%
div-sub16.2%
sub-neg16.2%
neg-mul-116.2%
*-commutative16.2%
associate-/l*15.6%
distribute-neg-frac15.6%
neg-mul-115.6%
*-commutative15.6%
associate-/l*16.2%
distribute-rgt-out17.6%
associate-/r*17.6%
metadata-eval17.6%
sub-neg17.6%
+-commutative17.6%
Simplified17.6%
Taylor expanded in b around -inf 80.0%
mul-1-neg80.0%
distribute-neg-frac280.0%
Simplified80.0%
if -5.80000000000000008e-113 < b < 5.6000000000000001e-48Initial program 77.8%
div-sub77.7%
sub-neg77.7%
neg-mul-177.7%
*-commutative77.7%
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 inf 73.7%
*-commutative73.7%
Simplified73.7%
if 5.6000000000000001e-48 < b Initial program 72.4%
div-sub72.5%
sub-neg72.5%
neg-mul-172.5%
*-commutative72.5%
associate-/l*72.5%
distribute-neg-frac72.5%
neg-mul-172.5%
*-commutative72.5%
associate-/l*72.3%
distribute-rgt-out72.3%
associate-/r*72.3%
metadata-eval72.3%
sub-neg72.3%
+-commutative72.3%
Simplified72.3%
Taylor expanded in c around 0 84.6%
+-commutative84.6%
mul-1-neg84.6%
unsub-neg84.6%
Simplified84.6%
Final simplification79.9%
(FPCore (a b c) :precision binary64 (if (<= b -2e-311) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-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 <= (-2d-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 <= -2e-311) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-311: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-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 <= -2e-311) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-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 -2 \cdot 10^{-311}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.9999999999999e-311Initial program 32.3%
div-sub31.2%
sub-neg31.2%
neg-mul-131.2%
*-commutative31.2%
associate-/l*30.8%
distribute-neg-frac30.8%
neg-mul-130.8%
*-commutative30.8%
associate-/l*31.2%
distribute-rgt-out32.2%
associate-/r*32.2%
metadata-eval32.2%
sub-neg32.2%
+-commutative32.2%
Simplified32.2%
Taylor expanded in b around -inf 62.4%
mul-1-neg62.4%
distribute-neg-frac262.4%
Simplified62.4%
if -1.9999999999999e-311 < b Initial program 75.0%
div-sub75.0%
sub-neg75.0%
neg-mul-175.0%
*-commutative75.0%
associate-/l*75.0%
distribute-neg-frac75.0%
neg-mul-175.0%
*-commutative75.0%
associate-/l*74.8%
distribute-rgt-out74.8%
associate-/r*74.8%
metadata-eval74.8%
sub-neg74.8%
+-commutative74.8%
Simplified74.8%
Taylor expanded in c around 0 63.8%
+-commutative63.8%
mul-1-neg63.8%
unsub-neg63.8%
Simplified63.8%
(FPCore (a b c) :precision binary64 (if (<= b -7.8e-302) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.8e-302) {
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 <= (-7.8d-302)) 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 <= -7.8e-302) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.8e-302: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.8e-302) 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 <= -7.8e-302) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.8e-302], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.8 \cdot 10^{-302}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -7.7999999999999998e-302Initial program 31.2%
div-sub30.2%
sub-neg30.2%
neg-mul-130.2%
*-commutative30.2%
associate-/l*29.7%
distribute-neg-frac29.7%
neg-mul-129.7%
*-commutative29.7%
associate-/l*30.1%
distribute-rgt-out31.2%
associate-/r*31.2%
metadata-eval31.2%
sub-neg31.2%
+-commutative31.2%
Simplified31.2%
Taylor expanded in b around -inf 63.3%
mul-1-neg63.3%
distribute-neg-frac263.3%
Simplified63.3%
if -7.7999999999999998e-302 < b Initial program 75.4%
div-sub75.4%
sub-neg75.4%
neg-mul-175.4%
*-commutative75.4%
associate-/l*75.4%
distribute-neg-frac75.4%
neg-mul-175.4%
*-commutative75.4%
associate-/l*75.2%
distribute-rgt-out75.2%
associate-/r*75.2%
metadata-eval75.2%
sub-neg75.2%
+-commutative75.2%
Simplified75.2%
Taylor expanded in a around 0 62.7%
associate-*r/62.7%
mul-1-neg62.7%
Simplified62.7%
Final simplification63.0%
(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 52.4%
div-sub51.9%
sub-neg51.9%
neg-mul-151.9%
*-commutative51.9%
associate-/l*51.7%
distribute-neg-frac51.7%
neg-mul-151.7%
*-commutative51.7%
associate-/l*51.8%
distribute-rgt-out52.3%
associate-/r*52.3%
metadata-eval52.3%
sub-neg52.3%
+-commutative52.3%
Simplified52.4%
Taylor expanded in b around -inf 33.8%
mul-1-neg33.8%
distribute-neg-frac233.8%
Simplified33.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 / 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 52.4%
div-sub51.9%
sub-neg51.9%
neg-mul-151.9%
*-commutative51.9%
associate-/l*51.7%
distribute-neg-frac51.7%
neg-mul-151.7%
*-commutative51.7%
associate-/l*51.8%
distribute-rgt-out52.3%
associate-/r*52.3%
metadata-eval52.3%
sub-neg52.3%
+-commutative52.3%
Simplified52.4%
Applied egg-rr36.7%
Taylor expanded in a around 0 9.9%
(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 52.4%
div-sub51.9%
sub-neg51.9%
neg-mul-151.9%
*-commutative51.9%
associate-/l*51.7%
distribute-neg-frac51.7%
neg-mul-151.7%
*-commutative51.7%
associate-/l*51.8%
distribute-rgt-out52.3%
associate-/r*52.3%
metadata-eval52.3%
sub-neg52.3%
+-commutative52.3%
Simplified52.4%
Applied egg-rr36.7%
Taylor expanded in b around -inf 2.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 2024146
(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)))