
(FPCore (a b_2 c) :precision binary64 (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))
double code(double a, double b_2, double c) {
return (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
code = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a
end function
public static double code(double a, double b_2, double c) {
return (-b_2 + Math.sqrt(((b_2 * b_2) - (a * c)))) / a;
}
def code(a, b_2, c): return (-b_2 + math.sqrt(((b_2 * b_2) - (a * c)))) / a
function code(a, b_2, c) return Float64(Float64(Float64(-b_2) + sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c)))) / a) end
function tmp = code(a, b_2, c) tmp = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a; end
code[a_, b$95$2_, c_] := N[(N[((-b$95$2) + N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b_2 c) :precision binary64 (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))
double code(double a, double b_2, double c) {
return (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
code = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a
end function
public static double code(double a, double b_2, double c) {
return (-b_2 + Math.sqrt(((b_2 * b_2) - (a * c)))) / a;
}
def code(a, b_2, c): return (-b_2 + math.sqrt(((b_2 * b_2) - (a * c)))) / a
function code(a, b_2, c) return Float64(Float64(Float64(-b_2) + sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c)))) / a) end
function tmp = code(a, b_2, c) tmp = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a; end
code[a_, b$95$2_, c_] := N[(N[((-b$95$2) + N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\end{array}
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -1.65e+145)
(/ (* b_2 -2.0) a)
(if (<= b_2 6e-139)
(/ (- (sqrt (- (* b_2 b_2) (* a c))) b_2) a)
(/ (* c -0.5) b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.65e+145) {
tmp = (b_2 * -2.0) / a;
} else if (b_2 <= 6e-139) {
tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-1.65d+145)) then
tmp = (b_2 * (-2.0d0)) / a
else if (b_2 <= 6d-139) then
tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a
else
tmp = (c * (-0.5d0)) / b_2
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.65e+145) {
tmp = (b_2 * -2.0) / a;
} else if (b_2 <= 6e-139) {
tmp = (Math.sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1.65e+145: tmp = (b_2 * -2.0) / a elif b_2 <= 6e-139: tmp = (math.sqrt(((b_2 * b_2) - (a * c))) - b_2) / a else: tmp = (c * -0.5) / b_2 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.65e+145) tmp = Float64(Float64(b_2 * -2.0) / a); elseif (b_2 <= 6e-139) tmp = Float64(Float64(sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c))) - b_2) / a); else tmp = Float64(Float64(c * -0.5) / b_2); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -1.65e+145) tmp = (b_2 * -2.0) / a; elseif (b_2 <= 6e-139) tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a; else tmp = (c * -0.5) / b_2; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.65e+145], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b$95$2, 6e-139], N[(N[(N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b$95$2), $MachinePrecision] / a), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -1.65 \cdot 10^{+145}:\\
\;\;\;\;\frac{b_2 \cdot -2}{a}\\
\mathbf{elif}\;b_2 \leq 6 \cdot 10^{-139}:\\
\;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b_2}\\
\end{array}
\end{array}
if b_2 < -1.65000000000000013e145Initial program 36.6%
+-commutative36.6%
unsub-neg36.6%
Simplified36.6%
Taylor expanded in b_2 around -inf 97.8%
*-commutative97.8%
Simplified97.8%
if -1.65000000000000013e145 < b_2 < 5.9999999999999998e-139Initial program 82.1%
+-commutative82.1%
unsub-neg82.1%
Simplified82.1%
if 5.9999999999999998e-139 < b_2 Initial program 20.0%
+-commutative20.0%
unsub-neg20.0%
Simplified20.0%
Taylor expanded in b_2 around inf 84.7%
associate-*r/84.7%
Applied egg-rr84.7%
Final simplification85.8%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -8.5e-70) (/ (* b_2 -2.0) a) (if (<= b_2 6e-139) (/ (- (sqrt (* c (- a))) b_2) a) (/ (* c -0.5) b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -8.5e-70) {
tmp = (b_2 * -2.0) / a;
} else if (b_2 <= 6e-139) {
tmp = (sqrt((c * -a)) - b_2) / a;
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-8.5d-70)) then
tmp = (b_2 * (-2.0d0)) / a
else if (b_2 <= 6d-139) then
tmp = (sqrt((c * -a)) - b_2) / a
else
tmp = (c * (-0.5d0)) / b_2
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -8.5e-70) {
tmp = (b_2 * -2.0) / a;
} else if (b_2 <= 6e-139) {
tmp = (Math.sqrt((c * -a)) - b_2) / a;
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -8.5e-70: tmp = (b_2 * -2.0) / a elif b_2 <= 6e-139: tmp = (math.sqrt((c * -a)) - b_2) / a else: tmp = (c * -0.5) / b_2 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -8.5e-70) tmp = Float64(Float64(b_2 * -2.0) / a); elseif (b_2 <= 6e-139) tmp = Float64(Float64(sqrt(Float64(c * Float64(-a))) - b_2) / a); else tmp = Float64(Float64(c * -0.5) / b_2); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -8.5e-70) tmp = (b_2 * -2.0) / a; elseif (b_2 <= 6e-139) tmp = (sqrt((c * -a)) - b_2) / a; else tmp = (c * -0.5) / b_2; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -8.5e-70], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b$95$2, 6e-139], N[(N[(N[Sqrt[N[(c * (-a)), $MachinePrecision]], $MachinePrecision] - b$95$2), $MachinePrecision] / a), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -8.5 \cdot 10^{-70}:\\
\;\;\;\;\frac{b_2 \cdot -2}{a}\\
\mathbf{elif}\;b_2 \leq 6 \cdot 10^{-139}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(-a\right)} - b_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b_2}\\
\end{array}
\end{array}
if b_2 < -8.5000000000000002e-70Initial program 69.6%
+-commutative69.6%
unsub-neg69.6%
Simplified69.6%
Taylor expanded in b_2 around -inf 88.8%
*-commutative88.8%
Simplified88.8%
if -8.5000000000000002e-70 < b_2 < 5.9999999999999998e-139Initial program 68.9%
+-commutative68.9%
unsub-neg68.9%
Simplified68.9%
Taylor expanded in b_2 around 0 66.1%
mul-1-neg66.1%
distribute-rgt-neg-out66.1%
Simplified66.1%
if 5.9999999999999998e-139 < b_2 Initial program 20.0%
+-commutative20.0%
unsub-neg20.0%
Simplified20.0%
Taylor expanded in b_2 around inf 84.7%
associate-*r/84.7%
Applied egg-rr84.7%
Final simplification81.9%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -5e-310) (/ (- b_2) a) (* -0.5 (/ c b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -5e-310) {
tmp = -b_2 / a;
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-5d-310)) then
tmp = -b_2 / a
else
tmp = (-0.5d0) * (c / b_2)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -5e-310) {
tmp = -b_2 / a;
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -5e-310: tmp = -b_2 / a else: tmp = -0.5 * (c / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -5e-310) tmp = Float64(Float64(-b_2) / a); else tmp = Float64(-0.5 * Float64(c / b_2)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -5e-310) tmp = -b_2 / a; else tmp = -0.5 * (c / b_2); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -5e-310], N[((-b$95$2) / a), $MachinePrecision], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b_2}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\
\end{array}
\end{array}
if b_2 < -4.999999999999985e-310Initial program 68.7%
+-commutative68.7%
unsub-neg68.7%
Simplified68.7%
div-sub68.7%
add-sqr-sqrt68.5%
*-un-lft-identity68.5%
times-frac68.4%
fma-neg68.5%
Applied egg-rr68.6%
Taylor expanded in b_2 around inf 27.8%
mul-1-neg27.8%
distribute-frac-neg27.8%
Simplified27.8%
if -4.999999999999985e-310 < b_2 Initial program 31.0%
+-commutative31.0%
unsub-neg31.0%
Simplified31.0%
Taylor expanded in b_2 around inf 70.1%
Final simplification49.9%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -5e-310) (/ (- b_2) a) (/ (* c -0.5) b_2)))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -5e-310) {
tmp = -b_2 / a;
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-5d-310)) then
tmp = -b_2 / a
else
tmp = (c * (-0.5d0)) / b_2
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -5e-310) {
tmp = -b_2 / a;
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -5e-310: tmp = -b_2 / a else: tmp = (c * -0.5) / b_2 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -5e-310) tmp = Float64(Float64(-b_2) / a); else tmp = Float64(Float64(c * -0.5) / b_2); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -5e-310) tmp = -b_2 / a; else tmp = (c * -0.5) / b_2; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -5e-310], N[((-b$95$2) / a), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b_2}\\
\end{array}
\end{array}
if b_2 < -4.999999999999985e-310Initial program 68.7%
+-commutative68.7%
unsub-neg68.7%
Simplified68.7%
div-sub68.7%
add-sqr-sqrt68.5%
*-un-lft-identity68.5%
times-frac68.4%
fma-neg68.5%
Applied egg-rr68.6%
Taylor expanded in b_2 around inf 27.8%
mul-1-neg27.8%
distribute-frac-neg27.8%
Simplified27.8%
if -4.999999999999985e-310 < b_2 Initial program 31.0%
+-commutative31.0%
unsub-neg31.0%
Simplified31.0%
Taylor expanded in b_2 around inf 70.1%
associate-*r/70.1%
Applied egg-rr70.1%
Final simplification50.0%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -5e-310) (/ (* b_2 -2.0) a) (/ (* c -0.5) b_2)))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -5e-310) {
tmp = (b_2 * -2.0) / a;
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-5d-310)) then
tmp = (b_2 * (-2.0d0)) / a
else
tmp = (c * (-0.5d0)) / b_2
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -5e-310) {
tmp = (b_2 * -2.0) / a;
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -5e-310: tmp = (b_2 * -2.0) / a else: tmp = (c * -0.5) / b_2 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -5e-310) tmp = Float64(Float64(b_2 * -2.0) / a); else tmp = Float64(Float64(c * -0.5) / b_2); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -5e-310) tmp = (b_2 * -2.0) / a; else tmp = (c * -0.5) / b_2; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -5e-310], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{b_2 \cdot -2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b_2}\\
\end{array}
\end{array}
if b_2 < -4.999999999999985e-310Initial program 68.7%
+-commutative68.7%
unsub-neg68.7%
Simplified68.7%
Taylor expanded in b_2 around -inf 69.7%
*-commutative69.7%
Simplified69.7%
if -4.999999999999985e-310 < b_2 Initial program 31.0%
+-commutative31.0%
unsub-neg31.0%
Simplified31.0%
Taylor expanded in b_2 around inf 70.1%
associate-*r/70.1%
Applied egg-rr70.1%
Final simplification69.9%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -1.65e-298) (/ (- b_2) a) 0.0))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.65e-298) {
tmp = -b_2 / a;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-1.65d-298)) then
tmp = -b_2 / a
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.65e-298) {
tmp = -b_2 / a;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1.65e-298: tmp = -b_2 / a else: tmp = 0.0 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.65e-298) tmp = Float64(Float64(-b_2) / a); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -1.65e-298) tmp = -b_2 / a; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.65e-298], N[((-b$95$2) / a), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -1.65 \cdot 10^{-298}:\\
\;\;\;\;\frac{-b_2}{a}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b_2 < -1.6500000000000001e-298Initial program 69.0%
+-commutative69.0%
unsub-neg69.0%
Simplified69.0%
div-sub69.0%
add-sqr-sqrt68.8%
*-un-lft-identity68.8%
times-frac68.7%
fma-neg68.8%
Applied egg-rr68.9%
Taylor expanded in b_2 around inf 28.2%
mul-1-neg28.2%
distribute-frac-neg28.2%
Simplified28.2%
if -1.6500000000000001e-298 < b_2 Initial program 31.3%
+-commutative31.3%
unsub-neg31.3%
Simplified31.3%
div-sub30.2%
add-sqr-sqrt28.8%
*-un-lft-identity28.8%
times-frac27.8%
fma-neg25.9%
Applied egg-rr26.0%
Taylor expanded in b_2 around inf 14.0%
distribute-rgt1-in14.0%
metadata-eval14.0%
mul0-lft19.0%
Simplified19.0%
Final simplification23.3%
(FPCore (a b_2 c) :precision binary64 0.0)
double code(double a, double b_2, double c) {
return 0.0;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
code = 0.0d0
end function
public static double code(double a, double b_2, double c) {
return 0.0;
}
def code(a, b_2, c): return 0.0
function code(a, b_2, c) return 0.0 end
function tmp = code(a, b_2, c) tmp = 0.0; end
code[a_, b$95$2_, c_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 48.9%
+-commutative48.9%
unsub-neg48.9%
Simplified48.9%
div-sub48.4%
add-sqr-sqrt47.6%
*-un-lft-identity47.6%
times-frac47.0%
fma-neg46.0%
Applied egg-rr46.1%
Taylor expanded in b_2 around inf 8.5%
distribute-rgt1-in8.5%
metadata-eval8.5%
mul0-lft11.3%
Simplified11.3%
Final simplification11.3%
herbie shell --seed 2023181
(FPCore (a b_2 c)
:name "quad2p (problem 3.2.1, positive)"
:precision binary64
(/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))