
(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 (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 2024181
(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)))