
(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 8 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 -7.5e-90)
(/ c (- b))
(if (<= b 1.85e+24)
(/ (- (- 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.5e-90) {
tmp = c / -b;
} else if (b <= 1.85e+24) {
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.5d-90)) then
tmp = c / -b
else if (b <= 1.85d+24) 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.5e-90) {
tmp = c / -b;
} else if (b <= 1.85e+24) {
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.5e-90: tmp = c / -b elif b <= 1.85e+24: 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.5e-90) tmp = Float64(c / Float64(-b)); elseif (b <= 1.85e+24) 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.5e-90) tmp = c / -b; elseif (b <= 1.85e+24) 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.5e-90], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.85e+24], 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.5 \cdot 10^{-90}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.85 \cdot 10^{+24}:\\
\;\;\;\;\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.4999999999999999e-90Initial program 18.1%
div-sub16.5%
sub-neg16.5%
neg-mul-116.5%
*-commutative16.5%
associate-/l*16.3%
distribute-neg-frac16.3%
neg-mul-116.3%
*-commutative16.3%
associate-/l*16.5%
distribute-rgt-out18.1%
associate-/r*18.1%
metadata-eval18.1%
sub-neg18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in b around -inf 87.1%
mul-1-neg87.1%
distribute-neg-frac287.1%
Simplified87.1%
if -7.4999999999999999e-90 < b < 1.85e24Initial program 83.5%
*-commutative83.5%
sqr-neg83.5%
*-commutative83.5%
sqr-neg83.5%
*-commutative83.5%
associate-*r*83.8%
*-commutative83.8%
Simplified83.8%
if 1.85e24 < b Initial program 69.5%
div-sub69.5%
sub-neg69.5%
neg-mul-169.5%
*-commutative69.5%
associate-/l*69.4%
distribute-neg-frac69.4%
neg-mul-169.4%
*-commutative69.4%
associate-/l*69.3%
distribute-rgt-out69.3%
associate-/r*69.3%
metadata-eval69.3%
sub-neg69.3%
+-commutative69.3%
Simplified69.5%
Taylor expanded in c around 0 91.3%
+-commutative91.3%
mul-1-neg91.3%
unsub-neg91.3%
Simplified91.3%
Final simplification87.2%
(FPCore (a b c)
:precision binary64
(if (<= b -2.35e-89)
(/ c (- b))
(if (<= b 1.85e+24)
(/ (- (- 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 <= -2.35e-89) {
tmp = c / -b;
} else if (b <= 1.85e+24) {
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 <= (-2.35d-89)) then
tmp = c / -b
else if (b <= 1.85d+24) 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 <= -2.35e-89) {
tmp = c / -b;
} else if (b <= 1.85e+24) {
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 <= -2.35e-89: tmp = c / -b elif b <= 1.85e+24: 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 <= -2.35e-89) tmp = Float64(c / Float64(-b)); elseif (b <= 1.85e+24) 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 <= -2.35e-89) tmp = c / -b; elseif (b <= 1.85e+24) 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, -2.35e-89], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.85e+24], 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 -2.35 \cdot 10^{-89}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.85 \cdot 10^{+24}:\\
\;\;\;\;\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 < -2.34999999999999998e-89Initial program 18.1%
div-sub16.5%
sub-neg16.5%
neg-mul-116.5%
*-commutative16.5%
associate-/l*16.3%
distribute-neg-frac16.3%
neg-mul-116.3%
*-commutative16.3%
associate-/l*16.5%
distribute-rgt-out18.1%
associate-/r*18.1%
metadata-eval18.1%
sub-neg18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in b around -inf 87.1%
mul-1-neg87.1%
distribute-neg-frac287.1%
Simplified87.1%
if -2.34999999999999998e-89 < b < 1.85e24Initial program 83.5%
if 1.85e24 < b Initial program 69.5%
div-sub69.5%
sub-neg69.5%
neg-mul-169.5%
*-commutative69.5%
associate-/l*69.4%
distribute-neg-frac69.4%
neg-mul-169.4%
*-commutative69.4%
associate-/l*69.3%
distribute-rgt-out69.3%
associate-/r*69.3%
metadata-eval69.3%
sub-neg69.3%
+-commutative69.3%
Simplified69.5%
Taylor expanded in c around 0 91.3%
+-commutative91.3%
mul-1-neg91.3%
unsub-neg91.3%
Simplified91.3%
Final simplification87.2%
(FPCore (a b c)
:precision binary64
(if (<= b -3.8e-104)
(/ c (- b))
(if (<= b 1.1e-81)
(/ (- (- b) (pow (* a (* c -4.0)) 0.5)) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.8e-104) {
tmp = c / -b;
} else if (b <= 1.1e-81) {
tmp = (-b - pow((a * (c * -4.0)), 0.5)) / (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 <= (-3.8d-104)) then
tmp = c / -b
else if (b <= 1.1d-81) then
tmp = (-b - ((a * (c * (-4.0d0))) ** 0.5d0)) / (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 <= -3.8e-104) {
tmp = c / -b;
} else if (b <= 1.1e-81) {
tmp = (-b - Math.pow((a * (c * -4.0)), 0.5)) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.8e-104: tmp = c / -b elif b <= 1.1e-81: tmp = (-b - math.pow((a * (c * -4.0)), 0.5)) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.8e-104) tmp = Float64(c / Float64(-b)); elseif (b <= 1.1e-81) tmp = Float64(Float64(Float64(-b) - (Float64(a * Float64(c * -4.0)) ^ 0.5)) / 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 <= -3.8e-104) tmp = c / -b; elseif (b <= 1.1e-81) tmp = (-b - ((a * (c * -4.0)) ^ 0.5)) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.8e-104], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.1e-81], N[(N[((-b) - N[Power[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision], 0.5], $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 -3.8 \cdot 10^{-104}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.1 \cdot 10^{-81}:\\
\;\;\;\;\frac{\left(-b\right) - {\left(a \cdot \left(c \cdot -4\right)\right)}^{0.5}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.8000000000000001e-104Initial program 18.9%
div-sub17.3%
sub-neg17.3%
neg-mul-117.3%
*-commutative17.3%
associate-/l*17.1%
distribute-neg-frac17.1%
neg-mul-117.1%
*-commutative17.1%
associate-/l*17.3%
distribute-rgt-out18.9%
associate-/r*18.9%
metadata-eval18.9%
sub-neg18.9%
+-commutative18.9%
Simplified18.9%
Taylor expanded in b around -inf 86.4%
mul-1-neg86.4%
distribute-neg-frac286.4%
Simplified86.4%
if -3.8000000000000001e-104 < b < 1.1e-81Initial program 76.8%
*-commutative76.8%
sqr-neg76.8%
*-commutative76.8%
sqr-neg76.8%
*-commutative76.8%
associate-*r*77.1%
*-commutative77.1%
Simplified77.1%
Taylor expanded in b around 0 71.1%
associate-*r*71.4%
*-commutative71.4%
Simplified71.4%
pow1/271.4%
associate-*l*71.4%
*-commutative71.4%
Applied egg-rr71.4%
if 1.1e-81 < b Initial program 76.8%
div-sub76.8%
sub-neg76.8%
neg-mul-176.8%
*-commutative76.8%
associate-/l*76.7%
distribute-neg-frac76.7%
neg-mul-176.7%
*-commutative76.7%
associate-/l*76.5%
distribute-rgt-out76.5%
associate-/r*76.5%
metadata-eval76.5%
sub-neg76.5%
+-commutative76.5%
Simplified76.7%
Taylor expanded in c around 0 87.8%
+-commutative87.8%
mul-1-neg87.8%
unsub-neg87.8%
Simplified87.8%
Final simplification83.4%
(FPCore (a b c)
:precision binary64
(if (<= b -3.2e-104)
(/ c (- b))
(if (<= b 8e-79)
(* -0.5 (/ (+ b (sqrt (* a (* c -4.0)))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.2e-104) {
tmp = c / -b;
} else if (b <= 8e-79) {
tmp = -0.5 * ((b + sqrt((a * (c * -4.0)))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-3.2d-104)) then
tmp = c / -b
else if (b <= 8d-79) then
tmp = (-0.5d0) * ((b + sqrt((a * (c * (-4.0d0))))) / a)
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.2e-104) {
tmp = c / -b;
} else if (b <= 8e-79) {
tmp = -0.5 * ((b + Math.sqrt((a * (c * -4.0)))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.2e-104: tmp = c / -b elif b <= 8e-79: tmp = -0.5 * ((b + math.sqrt((a * (c * -4.0)))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.2e-104) tmp = Float64(c / Float64(-b)); elseif (b <= 8e-79) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(a * Float64(c * -4.0)))) / a)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.2e-104) tmp = c / -b; elseif (b <= 8e-79) tmp = -0.5 * ((b + sqrt((a * (c * -4.0)))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.2e-104], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 8e-79], N[(-0.5 * N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.2 \cdot 10^{-104}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 8 \cdot 10^{-79}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.19999999999999989e-104Initial program 18.9%
div-sub17.3%
sub-neg17.3%
neg-mul-117.3%
*-commutative17.3%
associate-/l*17.1%
distribute-neg-frac17.1%
neg-mul-117.1%
*-commutative17.1%
associate-/l*17.3%
distribute-rgt-out18.9%
associate-/r*18.9%
metadata-eval18.9%
sub-neg18.9%
+-commutative18.9%
Simplified18.9%
Taylor expanded in b around -inf 86.4%
mul-1-neg86.4%
distribute-neg-frac286.4%
Simplified86.4%
if -3.19999999999999989e-104 < b < 8e-79Initial program 76.8%
*-commutative76.8%
sqr-neg76.8%
*-commutative76.8%
sqr-neg76.8%
*-commutative76.8%
associate-*r*77.1%
*-commutative77.1%
Simplified77.1%
Taylor expanded in b around 0 71.1%
associate-*r*71.4%
*-commutative71.4%
Simplified71.4%
frac-2neg71.4%
distribute-frac-neg271.4%
neg-sub071.4%
add-sqr-sqrt21.8%
sqrt-unprod70.0%
sqr-neg70.0%
sqrt-prod48.1%
add-sqr-sqrt70.0%
associate-+l-70.0%
neg-sub070.0%
add-sqr-sqrt21.9%
sqrt-unprod70.9%
sqr-neg70.9%
sqrt-prod49.6%
add-sqr-sqrt71.4%
associate-*l*71.4%
*-commutative71.4%
Applied egg-rr71.4%
distribute-neg-frac71.4%
neg-mul-171.4%
*-commutative71.4%
times-frac71.4%
metadata-eval71.4%
Simplified71.4%
if 8e-79 < b Initial program 76.8%
div-sub76.8%
sub-neg76.8%
neg-mul-176.8%
*-commutative76.8%
associate-/l*76.7%
distribute-neg-frac76.7%
neg-mul-176.7%
*-commutative76.7%
associate-/l*76.5%
distribute-rgt-out76.5%
associate-/r*76.5%
metadata-eval76.5%
sub-neg76.5%
+-commutative76.5%
Simplified76.7%
Taylor expanded in c around 0 87.8%
+-commutative87.8%
mul-1-neg87.8%
unsub-neg87.8%
Simplified87.8%
Final simplification83.4%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1d-310)) then
tmp = c / -b
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-310) tmp = Float64(c / Float64(-b)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e-310) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], N[(c / (-b)), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 27.4%
div-sub26.1%
sub-neg26.1%
neg-mul-126.1%
*-commutative26.1%
associate-/l*25.9%
distribute-neg-frac25.9%
neg-mul-125.9%
*-commutative25.9%
associate-/l*26.1%
distribute-rgt-out27.4%
associate-/r*27.4%
metadata-eval27.4%
sub-neg27.4%
+-commutative27.4%
Simplified27.4%
Taylor expanded in b around -inf 74.4%
mul-1-neg74.4%
distribute-neg-frac274.4%
Simplified74.4%
if -9.999999999999969e-311 < b Initial program 77.3%
div-sub77.3%
sub-neg77.3%
neg-mul-177.3%
*-commutative77.3%
associate-/l*77.2%
distribute-neg-frac77.2%
neg-mul-177.2%
*-commutative77.2%
associate-/l*77.1%
distribute-rgt-out77.1%
associate-/r*77.1%
metadata-eval77.1%
sub-neg77.1%
+-commutative77.1%
Simplified77.4%
Taylor expanded in c around 0 66.8%
+-commutative66.8%
mul-1-neg66.8%
unsub-neg66.8%
Simplified66.8%
Final simplification70.2%
(FPCore (a b c) :precision binary64 (if (<= b -1.4e-307) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.4e-307) {
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 <= (-1.4d-307)) 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 <= -1.4e-307) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.4e-307: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.4e-307) 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 <= -1.4e-307) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.4e-307], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.4 \cdot 10^{-307}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -1.4e-307Initial program 27.4%
div-sub26.1%
sub-neg26.1%
neg-mul-126.1%
*-commutative26.1%
associate-/l*25.9%
distribute-neg-frac25.9%
neg-mul-125.9%
*-commutative25.9%
associate-/l*26.1%
distribute-rgt-out27.4%
associate-/r*27.4%
metadata-eval27.4%
sub-neg27.4%
+-commutative27.4%
Simplified27.4%
Taylor expanded in b around -inf 74.4%
mul-1-neg74.4%
distribute-neg-frac274.4%
Simplified74.4%
if -1.4e-307 < b Initial program 77.3%
div-sub77.3%
sub-neg77.3%
neg-mul-177.3%
*-commutative77.3%
associate-/l*77.2%
distribute-neg-frac77.2%
neg-mul-177.2%
*-commutative77.2%
associate-/l*77.1%
distribute-rgt-out77.1%
associate-/r*77.1%
metadata-eval77.1%
sub-neg77.1%
+-commutative77.1%
Simplified77.4%
Taylor expanded in a around 0 66.5%
associate-*r/66.5%
mul-1-neg66.5%
Simplified66.5%
Final simplification70.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 55.1%
div-sub54.5%
sub-neg54.5%
neg-mul-154.5%
*-commutative54.5%
associate-/l*54.4%
distribute-neg-frac54.4%
neg-mul-154.4%
*-commutative54.4%
associate-/l*54.4%
distribute-rgt-out55.0%
associate-/r*55.0%
metadata-eval55.0%
sub-neg55.0%
+-commutative55.0%
Simplified55.1%
Taylor expanded in b around -inf 34.3%
mul-1-neg34.3%
distribute-neg-frac234.3%
Simplified34.3%
Final simplification34.3%
(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 55.1%
div-sub54.5%
sub-neg54.5%
neg-mul-154.5%
*-commutative54.5%
associate-/l*54.4%
distribute-neg-frac54.4%
neg-mul-154.4%
*-commutative54.4%
associate-/l*54.4%
distribute-rgt-out55.0%
associate-/r*55.0%
metadata-eval55.0%
sub-neg55.0%
+-commutative55.0%
Simplified55.1%
Taylor expanded in a around 0 35.3%
Taylor expanded in b around 0 12.3%
Final simplification12.3%
(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 2024110
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-expected 10
:alt
(if (< b 0.0) (/ c (- (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c))))) (/ b 2.0))) (/ (+ (/ b 2.0) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (- a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))