
(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 -4.2e-42)
(/ c (- b))
(if (<= b 2.6e+58)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.2e-42) {
tmp = c / -b;
} else if (b <= 2.6e+58) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} 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 <= (-4.2d-42)) then
tmp = c / -b
else if (b <= 2.6d+58) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4.2e-42) {
tmp = c / -b;
} else if (b <= 2.6e+58) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.2e-42: tmp = c / -b elif b <= 2.6e+58: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.2e-42) tmp = Float64(c / Float64(-b)); elseif (b <= 2.6e+58) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.2e-42) tmp = c / -b; elseif (b <= 2.6e+58) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.2e-42], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.6e+58], 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[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.2 \cdot 10^{-42}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.6 \cdot 10^{+58}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -4.20000000000000013e-42Initial program 14.6%
div-sub13.9%
sub-neg13.9%
neg-mul-113.9%
*-commutative13.9%
associate-/l*12.7%
distribute-neg-frac12.7%
neg-mul-112.7%
*-commutative12.7%
associate-/l*13.9%
distribute-rgt-out14.6%
associate-/r*14.6%
metadata-eval14.6%
sub-neg14.6%
+-commutative14.6%
Simplified14.6%
Taylor expanded in b around -inf 86.6%
mul-1-neg86.6%
distribute-neg-frac286.6%
Simplified86.6%
if -4.20000000000000013e-42 < b < 2.59999999999999988e58Initial program 80.6%
if 2.59999999999999988e58 < b Initial program 57.0%
div-sub57.0%
sub-neg57.0%
neg-mul-157.0%
*-commutative57.0%
associate-/l*57.0%
distribute-neg-frac57.0%
neg-mul-157.0%
*-commutative57.0%
associate-/l*56.9%
distribute-rgt-out56.9%
associate-/r*56.9%
metadata-eval56.9%
sub-neg56.9%
+-commutative56.9%
Simplified57.2%
Taylor expanded in a around 0 93.5%
associate-*r/93.5%
mul-1-neg93.5%
Simplified93.5%
Final simplification85.7%
(FPCore (a b c)
:precision binary64
(if (<= b -4.4e-41)
(/ c (- b))
(if (<= b 5e-34)
(* (/ -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 <= -4.4e-41) {
tmp = c / -b;
} else if (b <= 5e-34) {
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 <= (-4.4d-41)) then
tmp = c / -b
else if (b <= 5d-34) 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 <= -4.4e-41) {
tmp = c / -b;
} else if (b <= 5e-34) {
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 <= -4.4e-41: tmp = c / -b elif b <= 5e-34: 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 <= -4.4e-41) tmp = Float64(c / Float64(-b)); elseif (b <= 5e-34) 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 <= -4.4e-41) tmp = c / -b; elseif (b <= 5e-34) 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, -4.4e-41], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 5e-34], 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 -4.4 \cdot 10^{-41}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{-34}:\\
\;\;\;\;\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 < -4.4e-41Initial program 14.6%
div-sub13.9%
sub-neg13.9%
neg-mul-113.9%
*-commutative13.9%
associate-/l*12.7%
distribute-neg-frac12.7%
neg-mul-112.7%
*-commutative12.7%
associate-/l*13.9%
distribute-rgt-out14.6%
associate-/r*14.6%
metadata-eval14.6%
sub-neg14.6%
+-commutative14.6%
Simplified14.6%
Taylor expanded in b around -inf 86.6%
mul-1-neg86.6%
distribute-neg-frac286.6%
Simplified86.6%
if -4.4e-41 < b < 5.0000000000000003e-34Initial program 77.2%
div-sub77.2%
sub-neg77.2%
neg-mul-177.2%
*-commutative77.2%
associate-/l*77.2%
distribute-neg-frac77.2%
neg-mul-177.2%
*-commutative77.2%
associate-/l*77.0%
distribute-rgt-out77.0%
associate-/r*77.0%
metadata-eval77.0%
sub-neg77.0%
+-commutative77.0%
Simplified77.0%
Taylor expanded in a around inf 68.8%
*-commutative68.8%
Simplified68.8%
if 5.0000000000000003e-34 < b Initial program 66.8%
div-sub66.8%
sub-neg66.8%
neg-mul-166.8%
*-commutative66.8%
associate-/l*66.7%
distribute-neg-frac66.7%
neg-mul-166.7%
*-commutative66.7%
associate-/l*66.6%
distribute-rgt-out66.7%
associate-/r*66.7%
metadata-eval66.7%
sub-neg66.7%
+-commutative66.7%
Simplified66.9%
Taylor expanded in c around 0 88.6%
+-commutative88.6%
mul-1-neg88.6%
unsub-neg88.6%
Simplified88.6%
Final simplification81.3%
(FPCore (a b c)
:precision binary64
(if (<= b -1e-40)
(/ c (- b))
(if (<= b 7e-73)
(/ (sqrt (* a (* c -4.0))) (* a (- 2.0)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-40) {
tmp = c / -b;
} else if (b <= 7e-73) {
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 <= (-1d-40)) then
tmp = c / -b
else if (b <= 7d-73) 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 <= -1e-40) {
tmp = c / -b;
} else if (b <= 7e-73) {
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 <= -1e-40: tmp = c / -b elif b <= 7e-73: 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 <= -1e-40) tmp = Float64(c / Float64(-b)); elseif (b <= 7e-73) 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 <= -1e-40) tmp = c / -b; elseif (b <= 7e-73) 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, -1e-40], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 7e-73], 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 -1 \cdot 10^{-40}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 7 \cdot 10^{-73}:\\
\;\;\;\;\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 < -9.9999999999999993e-41Initial program 14.6%
div-sub13.9%
sub-neg13.9%
neg-mul-113.9%
*-commutative13.9%
associate-/l*12.7%
distribute-neg-frac12.7%
neg-mul-112.7%
*-commutative12.7%
associate-/l*13.9%
distribute-rgt-out14.6%
associate-/r*14.6%
metadata-eval14.6%
sub-neg14.6%
+-commutative14.6%
Simplified14.6%
Taylor expanded in b around -inf 86.6%
mul-1-neg86.6%
distribute-neg-frac286.6%
Simplified86.6%
if -9.9999999999999993e-41 < b < 6.9999999999999995e-73Initial program 75.5%
*-commutative75.5%
sqr-neg75.5%
*-commutative75.5%
sqr-neg75.5%
*-commutative75.5%
associate-*r*75.5%
*-commutative75.5%
Simplified75.5%
add-cube-cbrt74.9%
pow374.9%
*-commutative74.9%
associate-*l*74.9%
Applied egg-rr74.9%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt68.3%
mul-1-neg68.3%
rem-cube-cbrt68.9%
Simplified68.9%
if 6.9999999999999995e-73 < b Initial program 69.1%
div-sub69.1%
sub-neg69.1%
neg-mul-169.1%
*-commutative69.1%
associate-/l*69.0%
distribute-neg-frac69.0%
neg-mul-169.0%
*-commutative69.0%
associate-/l*69.0%
distribute-rgt-out69.0%
associate-/r*69.0%
metadata-eval69.0%
sub-neg69.0%
+-commutative69.0%
Simplified69.2%
Taylor expanded in c around 0 86.1%
+-commutative86.1%
mul-1-neg86.1%
unsub-neg86.1%
Simplified86.1%
Final simplification81.0%
(FPCore (a b c)
:precision binary64
(if (<= b -2.9e-170)
(/ c (- b))
(if (<= b 8.8e-206)
(* 0.5 (- (sqrt (* c (/ -4.0 a)))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.9e-170) {
tmp = c / -b;
} else if (b <= 8.8e-206) {
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 <= (-2.9d-170)) then
tmp = c / -b
else if (b <= 8.8d-206) 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 <= -2.9e-170) {
tmp = c / -b;
} else if (b <= 8.8e-206) {
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 <= -2.9e-170: tmp = c / -b elif b <= 8.8e-206: 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 <= -2.9e-170) tmp = Float64(c / Float64(-b)); elseif (b <= 8.8e-206) tmp = Float64(0.5 * Float64(-sqrt(Float64(c * Float64(-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 <= -2.9e-170) tmp = c / -b; elseif (b <= 8.8e-206) 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, -2.9e-170], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 8.8e-206], N[(0.5 * (-N[Sqrt[N[(c * N[(-4.0 / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.9 \cdot 10^{-170}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 8.8 \cdot 10^{-206}:\\
\;\;\;\;0.5 \cdot \left(-\sqrt{c \cdot \frac{-4}{a}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.9e-170Initial program 21.3%
div-sub20.8%
sub-neg20.8%
neg-mul-120.8%
*-commutative20.8%
associate-/l*19.8%
distribute-neg-frac19.8%
neg-mul-119.8%
*-commutative19.8%
associate-/l*20.7%
distribute-rgt-out21.2%
associate-/r*21.2%
metadata-eval21.2%
sub-neg21.2%
+-commutative21.2%
Simplified21.2%
Taylor expanded in b around -inf 77.3%
mul-1-neg77.3%
distribute-neg-frac277.3%
Simplified77.3%
if -2.9e-170 < b < 8.7999999999999995e-206Initial program 88.6%
*-commutative88.6%
sqr-neg88.6%
*-commutative88.6%
sqr-neg88.6%
*-commutative88.6%
associate-*r*88.6%
*-commutative88.6%
Simplified88.6%
add-cube-cbrt87.8%
pow387.8%
*-commutative87.8%
associate-*l*87.8%
Applied egg-rr87.8%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt33.1%
neg-mul-133.1%
associate-/l*33.1%
rem-cube-cbrt33.3%
Simplified33.3%
if 8.7999999999999995e-206 < b Initial program 72.5%
div-sub72.5%
sub-neg72.5%
neg-mul-172.5%
*-commutative72.5%
associate-/l*72.4%
distribute-neg-frac72.4%
neg-mul-172.4%
*-commutative72.4%
associate-/l*72.4%
distribute-rgt-out72.4%
associate-/r*72.4%
metadata-eval72.4%
sub-neg72.4%
+-commutative72.4%
Simplified72.5%
Taylor expanded in c around 0 75.7%
+-commutative75.7%
mul-1-neg75.7%
unsub-neg75.7%
Simplified75.7%
(FPCore (a b c) :precision binary64 (if (<= b -1e-309) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
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-309)) 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-309) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-309: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-309) 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-309) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-309], 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^{-309}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.000000000000002e-309Initial program 28.8%
div-sub28.4%
sub-neg28.4%
neg-mul-128.4%
*-commutative28.4%
associate-/l*27.6%
distribute-neg-frac27.6%
neg-mul-127.6%
*-commutative27.6%
associate-/l*28.3%
distribute-rgt-out28.8%
associate-/r*28.8%
metadata-eval28.8%
sub-neg28.8%
+-commutative28.8%
Simplified28.8%
Taylor expanded in b around -inf 67.5%
mul-1-neg67.5%
distribute-neg-frac267.5%
Simplified67.5%
if -1.000000000000002e-309 < b Initial program 76.3%
div-sub76.3%
sub-neg76.3%
neg-mul-176.3%
*-commutative76.3%
associate-/l*76.3%
distribute-neg-frac76.3%
neg-mul-176.3%
*-commutative76.3%
associate-/l*76.1%
distribute-rgt-out76.2%
associate-/r*76.2%
metadata-eval76.2%
sub-neg76.2%
+-commutative76.2%
Simplified76.3%
Taylor expanded in c around 0 65.6%
+-commutative65.6%
mul-1-neg65.6%
unsub-neg65.6%
Simplified65.6%
(FPCore (a b c) :precision binary64 (if (<= b -2.9e-300) (/ c (- b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.9e-300) {
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 <= (-2.9d-300)) 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 <= -2.9e-300) {
tmp = c / -b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.9e-300: tmp = c / -b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.9e-300) 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 <= -2.9e-300) tmp = c / -b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.9e-300], N[(c / (-b)), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.9 \cdot 10^{-300}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -2.89999999999999992e-300Initial program 29.0%
div-sub28.6%
sub-neg28.6%
neg-mul-128.6%
*-commutative28.6%
associate-/l*27.7%
distribute-neg-frac27.7%
neg-mul-127.7%
*-commutative27.7%
associate-/l*28.5%
distribute-rgt-out29.0%
associate-/r*29.0%
metadata-eval29.0%
sub-neg29.0%
+-commutative29.0%
Simplified29.0%
Taylor expanded in b around -inf 68.0%
mul-1-neg68.0%
distribute-neg-frac268.0%
Simplified68.0%
if -2.89999999999999992e-300 < b Initial program 75.7%
div-sub75.7%
sub-neg75.7%
neg-mul-175.7%
*-commutative75.7%
associate-/l*75.7%
distribute-neg-frac75.7%
neg-mul-175.7%
*-commutative75.7%
associate-/l*75.5%
distribute-rgt-out75.6%
associate-/r*75.6%
metadata-eval75.6%
sub-neg75.6%
+-commutative75.6%
Simplified75.7%
Taylor expanded in a around 0 64.8%
associate-*r/64.8%
mul-1-neg64.8%
Simplified64.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 51.3%
div-sub51.0%
sub-neg51.0%
neg-mul-151.0%
*-commutative51.0%
associate-/l*50.6%
distribute-neg-frac50.6%
neg-mul-150.6%
*-commutative50.6%
associate-/l*50.9%
distribute-rgt-out51.2%
associate-/r*51.2%
metadata-eval51.2%
sub-neg51.2%
+-commutative51.2%
Simplified51.2%
Taylor expanded in b around -inf 36.6%
mul-1-neg36.6%
distribute-neg-frac236.6%
Simplified36.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.3%
div-sub51.0%
sub-neg51.0%
neg-mul-151.0%
*-commutative51.0%
associate-/l*50.6%
distribute-neg-frac50.6%
neg-mul-150.6%
*-commutative50.6%
associate-/l*50.9%
distribute-rgt-out51.2%
associate-/r*51.2%
metadata-eval51.2%
sub-neg51.2%
+-commutative51.2%
Simplified51.2%
Taylor expanded in a around 0 30.1%
*-commutative30.1%
associate-/l*32.1%
Simplified32.1%
Taylor expanded in a around inf 8.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.3%
div-sub51.0%
sub-neg51.0%
neg-mul-151.0%
*-commutative51.0%
associate-/l*50.6%
distribute-neg-frac50.6%
neg-mul-150.6%
*-commutative50.6%
associate-/l*50.9%
distribute-rgt-out51.2%
associate-/r*51.2%
metadata-eval51.2%
sub-neg51.2%
+-commutative51.2%
Simplified51.2%
Taylor expanded in a around 0 32.3%
associate-*r/32.3%
mul-1-neg32.3%
Simplified32.3%
div-inv32.2%
add-sqr-sqrt1.4%
sqrt-unprod2.0%
sqr-neg2.0%
sqrt-prod0.6%
add-sqr-sqrt2.6%
Applied egg-rr2.6%
associate-*r/2.6%
*-rgt-identity2.6%
Simplified2.6%
(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 2024181
(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)))