
(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 6 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.02e+155)
(/ (* b_2 -2.0) a)
(if (<= b_2 5.5e-57)
(/ (- (sqrt (- (* b_2 b_2) (* a c))) b_2) a)
(* -0.5 (/ c b_2)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.02e+155) {
tmp = (b_2 * -2.0) / a;
} else if (b_2 <= 5.5e-57) {
tmp = (sqrt(((b_2 * b_2) - (a * c))) - 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 <= (-1.02d+155)) then
tmp = (b_2 * (-2.0d0)) / a
else if (b_2 <= 5.5d-57) then
tmp = (sqrt(((b_2 * b_2) - (a * c))) - 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 <= -1.02e+155) {
tmp = (b_2 * -2.0) / a;
} else if (b_2 <= 5.5e-57) {
tmp = (Math.sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1.02e+155: tmp = (b_2 * -2.0) / a elif b_2 <= 5.5e-57: tmp = (math.sqrt(((b_2 * b_2) - (a * c))) - b_2) / a else: tmp = -0.5 * (c / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.02e+155) tmp = Float64(Float64(b_2 * -2.0) / a); elseif (b_2 <= 5.5e-57) tmp = Float64(Float64(sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c))) - 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 <= -1.02e+155) tmp = (b_2 * -2.0) / a; elseif (b_2 <= 5.5e-57) tmp = (sqrt(((b_2 * b_2) - (a * c))) - 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, -1.02e+155], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b$95$2, 5.5e-57], 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[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -1.02 \cdot 10^{+155}:\\
\;\;\;\;\frac{b_2 \cdot -2}{a}\\
\mathbf{elif}\;b_2 \leq 5.5 \cdot 10^{-57}:\\
\;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\
\end{array}
\end{array}
if b_2 < -1.02e155Initial program 27.0%
+-commutative27.0%
unsub-neg27.0%
Simplified27.0%
Taylor expanded in b_2 around -inf 100.0%
*-commutative100.0%
Simplified100.0%
if -1.02e155 < b_2 < 5.50000000000000011e-57Initial program 86.3%
+-commutative86.3%
unsub-neg86.3%
Simplified86.3%
if 5.50000000000000011e-57 < b_2 Initial program 10.6%
+-commutative10.6%
unsub-neg10.6%
Simplified10.6%
Taylor expanded in b_2 around inf 92.5%
Final simplification90.5%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -2.5e-40) (+ (* -2.0 (/ b_2 a)) (* (/ c b_2) 0.5)) (if (<= b_2 2e-56) (/ (- (sqrt (* a (- c))) b_2) a) (* -0.5 (/ c b_2)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2.5e-40) {
tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
} else if (b_2 <= 2e-56) {
tmp = (sqrt((a * -c)) - 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 <= (-2.5d-40)) then
tmp = ((-2.0d0) * (b_2 / a)) + ((c / b_2) * 0.5d0)
else if (b_2 <= 2d-56) then
tmp = (sqrt((a * -c)) - 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 <= -2.5e-40) {
tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
} else if (b_2 <= 2e-56) {
tmp = (Math.sqrt((a * -c)) - b_2) / a;
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2.5e-40: tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5) elif b_2 <= 2e-56: tmp = (math.sqrt((a * -c)) - b_2) / a else: tmp = -0.5 * (c / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2.5e-40) tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(Float64(c / b_2) * 0.5)); elseif (b_2 <= 2e-56) tmp = Float64(Float64(sqrt(Float64(a * Float64(-c))) - 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 <= -2.5e-40) tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5); elseif (b_2 <= 2e-56) tmp = (sqrt((a * -c)) - 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, -2.5e-40], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(N[(c / b$95$2), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 2e-56], N[(N[(N[Sqrt[N[(a * (-c)), $MachinePrecision]], $MachinePrecision] - b$95$2), $MachinePrecision] / a), $MachinePrecision], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -2.5 \cdot 10^{-40}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a} + \frac{c}{b_2} \cdot 0.5\\
\mathbf{elif}\;b_2 \leq 2 \cdot 10^{-56}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)} - b_2}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\
\end{array}
\end{array}
if b_2 < -2.49999999999999982e-40Initial program 60.5%
+-commutative60.5%
unsub-neg60.5%
Simplified60.5%
Taylor expanded in b_2 around -inf 93.9%
if -2.49999999999999982e-40 < b_2 < 2.0000000000000001e-56Initial program 82.7%
+-commutative82.7%
unsub-neg82.7%
Simplified82.7%
Taylor expanded in b_2 around 0 68.1%
mul-1-neg68.1%
distribute-rgt-neg-out68.1%
Simplified68.1%
if 2.0000000000000001e-56 < b_2 Initial program 10.6%
+-commutative10.6%
unsub-neg10.6%
Simplified10.6%
Taylor expanded in b_2 around inf 92.5%
Final simplification84.2%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -1e-311) (+ (* -2.0 (/ b_2 a)) (* (/ c b_2) 0.5)) (* -0.5 (/ c b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1e-311) {
tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
} 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 <= (-1d-311)) then
tmp = ((-2.0d0) * (b_2 / a)) + ((c / b_2) * 0.5d0)
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 <= -1e-311) {
tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1e-311: tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5) else: tmp = -0.5 * (c / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1e-311) tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(Float64(c / b_2) * 0.5)); 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 <= -1e-311) tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5); else tmp = -0.5 * (c / b_2); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1e-311], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(N[(c / b$95$2), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -1 \cdot 10^{-311}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a} + \frac{c}{b_2} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\
\end{array}
\end{array}
if b_2 < -9.99999999999948e-312Initial program 70.3%
+-commutative70.3%
unsub-neg70.3%
Simplified70.3%
Taylor expanded in b_2 around -inf 69.6%
if -9.99999999999948e-312 < b_2 Initial program 33.5%
+-commutative33.5%
unsub-neg33.5%
Simplified33.5%
Taylor expanded in b_2 around inf 66.3%
Final simplification68.0%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 3.7e-302) (/ (- b_2) a) (* -0.5 (/ c b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= 3.7e-302) {
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 <= 3.7d-302) 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 <= 3.7e-302) {
tmp = -b_2 / a;
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= 3.7e-302: 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 <= 3.7e-302) 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 <= 3.7e-302) 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, 3.7e-302], 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 3.7 \cdot 10^{-302}:\\
\;\;\;\;\frac{-b_2}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\
\end{array}
\end{array}
if b_2 < 3.7e-302Initial program 70.6%
+-commutative70.6%
unsub-neg70.6%
Simplified70.6%
Taylor expanded in b_2 around 0 37.0%
mul-1-neg37.0%
distribute-rgt-neg-out37.0%
Simplified37.0%
Taylor expanded in c around 0 22.6%
associate-*r/22.6%
neg-mul-122.6%
Simplified22.6%
if 3.7e-302 < b_2 Initial program 33.0%
+-commutative33.0%
unsub-neg33.0%
Simplified33.0%
Taylor expanded in b_2 around inf 66.8%
Final simplification44.5%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 3.7e-302) (/ (* b_2 -2.0) a) (* -0.5 (/ c b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= 3.7e-302) {
tmp = (b_2 * -2.0) / 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 <= 3.7d-302) then
tmp = (b_2 * (-2.0d0)) / 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 <= 3.7e-302) {
tmp = (b_2 * -2.0) / a;
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= 3.7e-302: tmp = (b_2 * -2.0) / a else: tmp = -0.5 * (c / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= 3.7e-302) tmp = Float64(Float64(b_2 * -2.0) / 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 <= 3.7e-302) tmp = (b_2 * -2.0) / a; else tmp = -0.5 * (c / b_2); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, 3.7e-302], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq 3.7 \cdot 10^{-302}:\\
\;\;\;\;\frac{b_2 \cdot -2}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\
\end{array}
\end{array}
if b_2 < 3.7e-302Initial program 70.6%
+-commutative70.6%
unsub-neg70.6%
Simplified70.6%
Taylor expanded in b_2 around -inf 68.5%
*-commutative68.5%
Simplified68.5%
if 3.7e-302 < b_2 Initial program 33.0%
+-commutative33.0%
unsub-neg33.0%
Simplified33.0%
Taylor expanded in b_2 around inf 66.8%
Final simplification67.7%
(FPCore (a b_2 c) :precision binary64 (/ (- b_2) a))
double code(double a, double b_2, double c) {
return -b_2 / 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 / a
end function
public static double code(double a, double b_2, double c) {
return -b_2 / a;
}
def code(a, b_2, c): return -b_2 / a
function code(a, b_2, c) return Float64(Float64(-b_2) / a) end
function tmp = code(a, b_2, c) tmp = -b_2 / a; end
code[a_, b$95$2_, c_] := N[((-b$95$2) / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{-b_2}{a}
\end{array}
Initial program 51.9%
+-commutative51.9%
unsub-neg51.9%
Simplified51.9%
Taylor expanded in b_2 around 0 32.8%
mul-1-neg32.8%
distribute-rgt-neg-out32.8%
Simplified32.8%
Taylor expanded in c around 0 12.9%
associate-*r/12.9%
neg-mul-112.9%
Simplified12.9%
Final simplification12.9%
herbie shell --seed 2023193
(FPCore (a b_2 c)
:name "quad2p (problem 3.2.1, positive)"
:precision binary64
(/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))