
(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+150)
(* -2.0 (/ b_2 a))
(if (<= b_2 1.22e-11)
(/ (- (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 <= -5e+150) {
tmp = -2.0 * (b_2 / a);
} else if (b_2 <= 1.22e-11) {
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 <= (-5d+150)) then
tmp = (-2.0d0) * (b_2 / a)
else if (b_2 <= 1.22d-11) 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 <= -5e+150) {
tmp = -2.0 * (b_2 / a);
} else if (b_2 <= 1.22e-11) {
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 <= -5e+150: tmp = -2.0 * (b_2 / a) elif b_2 <= 1.22e-11: 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 <= -5e+150) tmp = Float64(-2.0 * Float64(b_2 / a)); elseif (b_2 <= 1.22e-11) 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 <= -5e+150) tmp = -2.0 * (b_2 / a); elseif (b_2 <= 1.22e-11) 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, -5e+150], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 1.22e-11], 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 -5 \cdot 10^{+150}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a}\\
\mathbf{elif}\;b_2 \leq 1.22 \cdot 10^{-11}:\\
\;\;\;\;\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 < -5.00000000000000009e150Initial program 32.3%
+-commutative32.3%
unsub-neg32.3%
Simplified32.3%
Taylor expanded in b_2 around -inf 97.8%
if -5.00000000000000009e150 < b_2 < 1.2200000000000001e-11Initial program 75.8%
+-commutative75.8%
unsub-neg75.8%
Simplified75.8%
if 1.2200000000000001e-11 < b_2 Initial program 14.8%
+-commutative14.8%
unsub-neg14.8%
Simplified14.8%
Taylor expanded in b_2 around inf 89.6%
Final simplification83.8%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -2.85e-42) (+ (* -2.0 (/ b_2 a)) (* (/ c b_2) 0.5)) (if (<= b_2 1.22e-11) (/ (- (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.85e-42) {
tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
} else if (b_2 <= 1.22e-11) {
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.85d-42)) then
tmp = ((-2.0d0) * (b_2 / a)) + ((c / b_2) * 0.5d0)
else if (b_2 <= 1.22d-11) 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.85e-42) {
tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
} else if (b_2 <= 1.22e-11) {
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.85e-42: tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5) elif b_2 <= 1.22e-11: 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.85e-42) tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(Float64(c / b_2) * 0.5)); elseif (b_2 <= 1.22e-11) 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.85e-42) tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5); elseif (b_2 <= 1.22e-11) 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.85e-42], 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, 1.22e-11], 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.85 \cdot 10^{-42}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a} + \frac{c}{b_2} \cdot 0.5\\
\mathbf{elif}\;b_2 \leq 1.22 \cdot 10^{-11}:\\
\;\;\;\;\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.85e-42Initial program 63.8%
+-commutative63.8%
unsub-neg63.8%
Simplified63.8%
Taylor expanded in b_2 around -inf 91.1%
if -2.85e-42 < b_2 < 1.2200000000000001e-11Initial program 66.7%
+-commutative66.7%
unsub-neg66.7%
Simplified66.7%
Taylor expanded in b_2 around 0 60.9%
associate-*r*60.9%
neg-mul-160.9%
*-commutative60.9%
Simplified60.9%
if 1.2200000000000001e-11 < b_2 Initial program 14.8%
+-commutative14.8%
unsub-neg14.8%
Simplified14.8%
Taylor expanded in b_2 around inf 89.6%
Final simplification80.0%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -4.7e-70) (+ (* -2.0 (/ b_2 a)) (* (/ c b_2) 0.5)) (if (<= b_2 1.75e-11) (/ (sqrt (* a (- c))) a) (* -0.5 (/ c b_2)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -4.7e-70) {
tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
} else if (b_2 <= 1.75e-11) {
tmp = sqrt((a * -c)) / 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 <= (-4.7d-70)) then
tmp = ((-2.0d0) * (b_2 / a)) + ((c / b_2) * 0.5d0)
else if (b_2 <= 1.75d-11) then
tmp = sqrt((a * -c)) / 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 <= -4.7e-70) {
tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
} else if (b_2 <= 1.75e-11) {
tmp = Math.sqrt((a * -c)) / a;
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -4.7e-70: tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5) elif b_2 <= 1.75e-11: tmp = math.sqrt((a * -c)) / a else: tmp = -0.5 * (c / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -4.7e-70) tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(Float64(c / b_2) * 0.5)); elseif (b_2 <= 1.75e-11) tmp = Float64(sqrt(Float64(a * Float64(-c))) / 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 <= -4.7e-70) tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5); elseif (b_2 <= 1.75e-11) tmp = sqrt((a * -c)) / a; else tmp = -0.5 * (c / b_2); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -4.7e-70], 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, 1.75e-11], N[(N[Sqrt[N[(a * (-c)), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -4.7 \cdot 10^{-70}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a} + \frac{c}{b_2} \cdot 0.5\\
\mathbf{elif}\;b_2 \leq 1.75 \cdot 10^{-11}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\
\end{array}
\end{array}
if b_2 < -4.6999999999999998e-70Initial program 63.9%
+-commutative63.9%
unsub-neg63.9%
Simplified63.9%
Taylor expanded in b_2 around -inf 89.2%
if -4.6999999999999998e-70 < b_2 < 1.7500000000000001e-11Initial program 66.7%
+-commutative66.7%
unsub-neg66.7%
Simplified66.7%
prod-diff66.1%
*-commutative66.1%
fma-def66.1%
associate-+l+66.1%
distribute-rgt-neg-in66.1%
fma-def66.2%
*-commutative66.2%
fma-udef66.1%
distribute-lft-neg-in66.1%
*-commutative66.1%
distribute-rgt-neg-in66.1%
fma-def66.2%
Applied egg-rr66.2%
Taylor expanded in b_2 around 0 60.5%
*-commutative60.5%
associate-*r/60.4%
*-rgt-identity60.4%
distribute-lft1-in60.9%
metadata-eval60.9%
neg-mul-160.9%
*-commutative60.9%
distribute-rgt-neg-out60.9%
Simplified60.9%
if 1.7500000000000001e-11 < b_2 Initial program 14.8%
+-commutative14.8%
unsub-neg14.8%
Simplified14.8%
Taylor expanded in b_2 around inf 89.6%
Final simplification79.7%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -4e-310) (+ (* -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 <= -4e-310) {
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 <= (-4d-310)) 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 <= -4e-310) {
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 <= -4e-310: 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 <= -4e-310) 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 <= -4e-310) 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, -4e-310], 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 -4 \cdot 10^{-310}:\\
\;\;\;\;-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 < -3.999999999999988e-310Initial program 68.5%
+-commutative68.5%
unsub-neg68.5%
Simplified68.5%
Taylor expanded in b_2 around -inf 70.5%
if -3.999999999999988e-310 < b_2 Initial program 32.3%
+-commutative32.3%
unsub-neg32.3%
Simplified32.3%
Taylor expanded in b_2 around inf 63.2%
Final simplification66.6%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 2.9e-289) (* -2.0 (/ b_2 a)) (* -0.5 (/ c b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= 2.9e-289) {
tmp = -2.0 * (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.9d-289) then
tmp = (-2.0d0) * (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.9e-289) {
tmp = -2.0 * (b_2 / a);
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= 2.9e-289: tmp = -2.0 * (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.9e-289) tmp = Float64(-2.0 * 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 <= 2.9e-289) tmp = -2.0 * (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.9e-289], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq 2.9 \cdot 10^{-289}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\
\end{array}
\end{array}
if b_2 < 2.90000000000000006e-289Initial program 68.5%
+-commutative68.5%
unsub-neg68.5%
Simplified68.5%
Taylor expanded in b_2 around -inf 68.7%
if 2.90000000000000006e-289 < b_2 Initial program 31.5%
+-commutative31.5%
unsub-neg31.5%
Simplified31.5%
Taylor expanded in b_2 around inf 64.5%
Final simplification66.5%
(FPCore (a b_2 c) :precision binary64 (* -2.0 (/ b_2 a)))
double code(double a, double b_2, double c) {
return -2.0 * (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 = (-2.0d0) * (b_2 / a)
end function
public static double code(double a, double b_2, double c) {
return -2.0 * (b_2 / a);
}
def code(a, b_2, c): return -2.0 * (b_2 / a)
function code(a, b_2, c) return Float64(-2.0 * Float64(b_2 / a)) end
function tmp = code(a, b_2, c) tmp = -2.0 * (b_2 / a); end
code[a_, b$95$2_, c_] := N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \frac{b_2}{a}
\end{array}
Initial program 49.1%
+-commutative49.1%
unsub-neg49.1%
Simplified49.1%
Taylor expanded in b_2 around -inf 33.9%
Final simplification33.9%
herbie shell --seed 2023287
(FPCore (a b_2 c)
:name "quad2p (problem 3.2.1, positive)"
:precision binary64
(/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))