
(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 -5e+153)
(/ (* b_2 -2.0) a)
(if (<= b_2 8.2e-113)
(/ (- (sqrt (- (* b_2 b_2) (* a c))) b_2) a)
(/ 1.0 (fma 0.5 (/ a b_2) (* -2.0 (/ b_2 c)))))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -5e+153) {
tmp = (b_2 * -2.0) / a;
} else if (b_2 <= 8.2e-113) {
tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
} else {
tmp = 1.0 / fma(0.5, (a / b_2), (-2.0 * (b_2 / c)));
}
return tmp;
}
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -5e+153) tmp = Float64(Float64(b_2 * -2.0) / a); elseif (b_2 <= 8.2e-113) tmp = Float64(Float64(sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c))) - b_2) / a); else tmp = Float64(1.0 / fma(0.5, Float64(a / b_2), Float64(-2.0 * Float64(b_2 / c)))); end return tmp end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -5e+153], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b$95$2, 8.2e-113], 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[(1.0 / N[(0.5 * N[(a / b$95$2), $MachinePrecision] + N[(-2.0 * N[(b$95$2 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -5 \cdot 10^{+153}:\\
\;\;\;\;\frac{b_2 \cdot -2}{a}\\
\mathbf{elif}\;b_2 \leq 8.2 \cdot 10^{-113}:\\
\;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(0.5, \frac{a}{b_2}, -2 \cdot \frac{b_2}{c}\right)}\\
\end{array}
\end{array}
if b_2 < -5.00000000000000018e153Initial program 36.0%
+-commutative36.0%
unsub-neg36.0%
Simplified36.0%
Taylor expanded in b_2 around -inf 100.0%
*-commutative100.0%
Simplified100.0%
if -5.00000000000000018e153 < b_2 < 8.1999999999999999e-113Initial program 85.9%
+-commutative85.9%
unsub-neg85.9%
Simplified85.9%
if 8.1999999999999999e-113 < b_2 Initial program 17.7%
+-commutative17.7%
unsub-neg17.7%
Simplified17.7%
clear-num17.7%
inv-pow17.7%
sub-neg17.7%
add-sqr-sqrt14.3%
hypot-def25.8%
*-commutative25.8%
distribute-rgt-neg-in25.8%
Applied egg-rr25.8%
unpow-125.8%
Applied egg-rr25.8%
Taylor expanded in b_2 around inf 0.0%
fma-def0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt82.5%
times-frac82.5%
metadata-eval82.5%
Simplified82.5%
Final simplification86.8%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -5.5e-23)
(+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2)))
(if (<= b_2 5.5e-115)
(/ (- (sqrt (* c (- a))) b_2) a)
(/ 1.0 (fma 0.5 (/ a b_2) (* -2.0 (/ b_2 c)))))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -5.5e-23) {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
} else if (b_2 <= 5.5e-115) {
tmp = (sqrt((c * -a)) - b_2) / a;
} else {
tmp = 1.0 / fma(0.5, (a / b_2), (-2.0 * (b_2 / c)));
}
return tmp;
}
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -5.5e-23) tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(0.5 * Float64(c / b_2))); elseif (b_2 <= 5.5e-115) tmp = Float64(Float64(sqrt(Float64(c * Float64(-a))) - b_2) / a); else tmp = Float64(1.0 / fma(0.5, Float64(a / b_2), Float64(-2.0 * Float64(b_2 / c)))); end return tmp end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -5.5e-23], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 5.5e-115], N[(N[(N[Sqrt[N[(c * (-a)), $MachinePrecision]], $MachinePrecision] - b$95$2), $MachinePrecision] / a), $MachinePrecision], N[(1.0 / N[(0.5 * N[(a / b$95$2), $MachinePrecision] + N[(-2.0 * N[(b$95$2 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -5.5 \cdot 10^{-23}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\
\mathbf{elif}\;b_2 \leq 5.5 \cdot 10^{-115}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(-a\right)} - b_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(0.5, \frac{a}{b_2}, -2 \cdot \frac{b_2}{c}\right)}\\
\end{array}
\end{array}
if b_2 < -5.5000000000000001e-23Initial program 64.7%
+-commutative64.7%
unsub-neg64.7%
Simplified64.7%
Taylor expanded in b_2 around -inf 94.1%
if -5.5000000000000001e-23 < b_2 < 5.50000000000000028e-115Initial program 81.8%
+-commutative81.8%
unsub-neg81.8%
Simplified81.8%
Taylor expanded in b_2 around 0 69.5%
mul-1-neg69.5%
distribute-rgt-neg-out69.5%
Simplified69.5%
if 5.50000000000000028e-115 < b_2 Initial program 17.7%
+-commutative17.7%
unsub-neg17.7%
Simplified17.7%
clear-num17.7%
inv-pow17.7%
sub-neg17.7%
add-sqr-sqrt14.3%
hypot-def25.8%
*-commutative25.8%
distribute-rgt-neg-in25.8%
Applied egg-rr25.8%
unpow-125.8%
Applied egg-rr25.8%
Taylor expanded in b_2 around inf 0.0%
fma-def0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt82.5%
times-frac82.5%
metadata-eval82.5%
Simplified82.5%
Final simplification81.7%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -3.2e-23) (+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2))) (if (<= b_2 8.2e-113) (/ (- (sqrt (* c (- a))) b_2) a) (* (/ c b_2) -0.5))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -3.2e-23) {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
} else if (b_2 <= 8.2e-113) {
tmp = (sqrt((c * -a)) - b_2) / a;
} else {
tmp = (c / b_2) * -0.5;
}
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.2d-23)) then
tmp = ((-2.0d0) * (b_2 / a)) + (0.5d0 * (c / b_2))
else if (b_2 <= 8.2d-113) then
tmp = (sqrt((c * -a)) - b_2) / a
else
tmp = (c / b_2) * (-0.5d0)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -3.2e-23) {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
} else if (b_2 <= 8.2e-113) {
tmp = (Math.sqrt((c * -a)) - b_2) / a;
} else {
tmp = (c / b_2) * -0.5;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -3.2e-23: tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)) elif b_2 <= 8.2e-113: tmp = (math.sqrt((c * -a)) - b_2) / a else: tmp = (c / b_2) * -0.5 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -3.2e-23) tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(0.5 * Float64(c / b_2))); elseif (b_2 <= 8.2e-113) tmp = Float64(Float64(sqrt(Float64(c * Float64(-a))) - b_2) / a); else tmp = Float64(Float64(c / b_2) * -0.5); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -3.2e-23) tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)); elseif (b_2 <= 8.2e-113) tmp = (sqrt((c * -a)) - b_2) / a; else tmp = (c / b_2) * -0.5; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -3.2e-23], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 8.2e-113], N[(N[(N[Sqrt[N[(c * (-a)), $MachinePrecision]], $MachinePrecision] - b$95$2), $MachinePrecision] / a), $MachinePrecision], N[(N[(c / b$95$2), $MachinePrecision] * -0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -3.2 \cdot 10^{-23}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\
\mathbf{elif}\;b_2 \leq 8.2 \cdot 10^{-113}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(-a\right)} - b_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b_2} \cdot -0.5\\
\end{array}
\end{array}
if b_2 < -3.19999999999999976e-23Initial program 64.7%
+-commutative64.7%
unsub-neg64.7%
Simplified64.7%
Taylor expanded in b_2 around -inf 94.1%
if -3.19999999999999976e-23 < b_2 < 8.1999999999999999e-113Initial program 81.8%
+-commutative81.8%
unsub-neg81.8%
Simplified81.8%
Taylor expanded in b_2 around 0 69.5%
mul-1-neg69.5%
distribute-rgt-neg-out69.5%
Simplified69.5%
if 8.1999999999999999e-113 < b_2 Initial program 17.7%
+-commutative17.7%
unsub-neg17.7%
Simplified17.7%
Taylor expanded in b_2 around inf 82.3%
Final simplification81.7%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -5e-310) (* b_2 (/ -2.0 a)) (* (/ c b_2) -0.5)))
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 / b_2) * -0.5;
}
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 / b_2) * (-0.5d0)
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 / b_2) * -0.5;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -5e-310: tmp = b_2 * (-2.0 / a) else: tmp = (c / b_2) * -0.5 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -5e-310) tmp = Float64(b_2 * Float64(-2.0 / a)); else tmp = Float64(Float64(c / b_2) * -0.5); 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 / b_2) * -0.5; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -5e-310], N[(b$95$2 * N[(-2.0 / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b$95$2), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -5 \cdot 10^{-310}:\\
\;\;\;\;b_2 \cdot \frac{-2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b_2} \cdot -0.5\\
\end{array}
\end{array}
if b_2 < -4.999999999999985e-310Initial program 73.7%
+-commutative73.7%
unsub-neg73.7%
Simplified73.7%
clear-num73.5%
inv-pow73.5%
sub-neg73.5%
add-sqr-sqrt57.5%
hypot-def70.7%
*-commutative70.7%
distribute-rgt-neg-in70.7%
Applied egg-rr70.7%
Taylor expanded in b_2 around -inf 67.1%
*-commutative67.1%
Simplified67.1%
unpow-167.1%
clear-num67.3%
*-un-lft-identity67.3%
times-frac67.0%
/-rgt-identity67.0%
Applied egg-rr67.0%
if -4.999999999999985e-310 < b_2 Initial program 30.8%
+-commutative30.8%
unsub-neg30.8%
Simplified30.8%
Taylor expanded in b_2 around inf 65.4%
Final simplification66.3%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -5e-310) (/ (* b_2 -2.0) a) (* (/ c b_2) -0.5)))
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 / b_2) * -0.5;
}
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 / b_2) * (-0.5d0)
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 / b_2) * -0.5;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -5e-310: tmp = (b_2 * -2.0) / a else: tmp = (c / b_2) * -0.5 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 / b_2) * -0.5); 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 / b_2) * -0.5; 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 / b$95$2), $MachinePrecision] * -0.5), $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}{b_2} \cdot -0.5\\
\end{array}
\end{array}
if b_2 < -4.999999999999985e-310Initial program 73.7%
+-commutative73.7%
unsub-neg73.7%
Simplified73.7%
Taylor expanded in b_2 around -inf 67.3%
*-commutative67.3%
Simplified67.3%
if -4.999999999999985e-310 < b_2 Initial program 30.8%
+-commutative30.8%
unsub-neg30.8%
Simplified30.8%
Taylor expanded in b_2 around inf 65.4%
Final simplification66.4%
(FPCore (a b_2 c) :precision binary64 (* (/ c b_2) -0.5))
double code(double a, double b_2, double c) {
return (c / b_2) * -0.5;
}
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 = (c / b_2) * (-0.5d0)
end function
public static double code(double a, double b_2, double c) {
return (c / b_2) * -0.5;
}
def code(a, b_2, c): return (c / b_2) * -0.5
function code(a, b_2, c) return Float64(Float64(c / b_2) * -0.5) end
function tmp = code(a, b_2, c) tmp = (c / b_2) * -0.5; end
code[a_, b$95$2_, c_] := N[(N[(c / b$95$2), $MachinePrecision] * -0.5), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{b_2} \cdot -0.5
\end{array}
Initial program 53.1%
+-commutative53.1%
unsub-neg53.1%
Simplified53.1%
Taylor expanded in b_2 around inf 32.6%
Final simplification32.6%
herbie shell --seed 2023200
(FPCore (a b_2 c)
:name "quad2p (problem 3.2.1, positive)"
:precision binary64
(/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))