
(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%
(FPCore (a b_2 c)
:precision binary64
(let* ((t_0 (* (sqrt (fabs a)) (sqrt (fabs c))))
(t_1
(if (== (copysign a c) a)
(if (> (fabs b_2) t_0)
(* (sqrt (- (fabs b_2) t_0)) (sqrt (+ (fabs b_2) t_0)))
NAN)
(hypot b_2 t_0))))
(if (< b_2 0.0) (/ (- t_1 (/ b_2 2.0)) a) (/ (- c) (+ (/ b_2 2.0) t_1)))))
double code(double a, double b_2, double c) {
double t_0 = sqrt(fabs(a)) * sqrt(fabs(c));
double tmp_1;
if (copysign(a, c) == a) {
double tmp_2;
if (fabs(b_2) > t_0) {
tmp_2 = sqrt((fabs(b_2) - t_0)) * sqrt((fabs(b_2) + t_0));
} else {
tmp_2 = (double) NAN;
}
tmp_1 = tmp_2;
} else {
tmp_1 = hypot(b_2, t_0);
}
double t_1 = tmp_1;
double tmp_3;
if (b_2 < 0.0) {
tmp_3 = (t_1 - (b_2 / 2.0)) / a;
} else {
tmp_3 = -c / ((b_2 / 2.0) + t_1);
}
return tmp_3;
}
public static double code(double a, double b_2, double c) {
double t_0 = Math.sqrt(Math.abs(a)) * Math.sqrt(Math.abs(c));
double tmp_1;
if (Math.copySign(a, c) == a) {
double tmp_2;
if (Math.abs(b_2) > t_0) {
tmp_2 = Math.sqrt((Math.abs(b_2) - t_0)) * Math.sqrt((Math.abs(b_2) + t_0));
} else {
tmp_2 = Double.NaN;
}
tmp_1 = tmp_2;
} else {
tmp_1 = Math.hypot(b_2, t_0);
}
double t_1 = tmp_1;
double tmp_3;
if (b_2 < 0.0) {
tmp_3 = (t_1 - (b_2 / 2.0)) / a;
} else {
tmp_3 = -c / ((b_2 / 2.0) + t_1);
}
return tmp_3;
}
def code(a, b_2, c): t_0 = math.sqrt(math.fabs(a)) * math.sqrt(math.fabs(c)) tmp_1 = 0 if math.copysign(a, c) == a: tmp_2 = 0 if math.fabs(b_2) > t_0: tmp_2 = math.sqrt((math.fabs(b_2) - t_0)) * math.sqrt((math.fabs(b_2) + t_0)) else: tmp_2 = math.nan tmp_1 = tmp_2 else: tmp_1 = math.hypot(b_2, t_0) t_1 = tmp_1 tmp_3 = 0 if b_2 < 0.0: tmp_3 = (t_1 - (b_2 / 2.0)) / a else: tmp_3 = -c / ((b_2 / 2.0) + t_1) return tmp_3
function code(a, b_2, c) t_0 = Float64(sqrt(abs(a)) * sqrt(abs(c))) tmp_1 = 0.0 if (copysign(a, c) == a) tmp_2 = 0.0 if (abs(b_2) > t_0) tmp_2 = Float64(sqrt(Float64(abs(b_2) - t_0)) * sqrt(Float64(abs(b_2) + t_0))); else tmp_2 = NaN; end tmp_1 = tmp_2; else tmp_1 = hypot(b_2, t_0); end t_1 = tmp_1 tmp_3 = 0.0 if (b_2 < 0.0) tmp_3 = Float64(Float64(t_1 - Float64(b_2 / 2.0)) / a); else tmp_3 = Float64(Float64(-c) / Float64(Float64(b_2 / 2.0) + t_1)); end return tmp_3 end
function tmp_5 = code(a, b_2, c) t_0 = sqrt(abs(a)) * sqrt(abs(c)); tmp_2 = 0.0; if ((sign(c) * abs(a)) == a) tmp_3 = 0.0; if (abs(b_2) > t_0) tmp_3 = sqrt((abs(b_2) - t_0)) * sqrt((abs(b_2) + t_0)); else tmp_3 = NaN; end tmp_2 = tmp_3; else tmp_2 = hypot(b_2, t_0); end t_1 = tmp_2; tmp_4 = 0.0; if (b_2 < 0.0) tmp_4 = (t_1 - (b_2 / 2.0)) / a; else tmp_4 = -c / ((b_2 / 2.0) + t_1); end tmp_5 = tmp_4; end
code[a_, b$95$2_, c_] := Block[{t$95$0 = N[(N[Sqrt[N[Abs[a], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[c], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = If[Equal[N[With[{TMP1 = Abs[a], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], a], If[Greater[N[Abs[b$95$2], $MachinePrecision], t$95$0], N[(N[Sqrt[N[(N[Abs[b$95$2], $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(N[Abs[b$95$2], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], Indeterminate], N[Sqrt[b$95$2 ^ 2 + t$95$0 ^ 2], $MachinePrecision]]}, If[Less[b$95$2, 0.0], N[(N[(t$95$1 - N[(b$95$2 / 2.0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[((-c) / N[(N[(b$95$2 / 2.0), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\left|a\right|} \cdot \sqrt{\left|c\right|}\\
t_1 := \begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(a, c\right) = a:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;\left|b_2\right| > t_0:\\
\;\;\;\;\sqrt{\left|b_2\right| - t_0} \cdot \sqrt{\left|b_2\right| + t_0}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{NaN}\\
\end{array}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(b_2, t_0\right)\\
\end{array}\\
\mathbf{if}\;b_2 < 0:\\
\;\;\;\;\frac{t_1 - \frac{b_2}{2}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{\frac{b_2}{2} + t_1}\\
\end{array}
\end{array}
herbie shell --seed 2023287
(FPCore (a b_2 c)
:name "quad2p (problem 3.2.1, positive)"
:precision binary64
:herbie-target
(if (< b_2 0.0) (/ (- (if (== (copysign a c) a) (if (> (fabs b_2) (* (sqrt (fabs a)) (sqrt (fabs c)))) (* (sqrt (- (fabs b_2) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs b_2) (* (sqrt (fabs a)) (sqrt (fabs c)))))) NAN) (hypot b_2 (* (sqrt (fabs a)) (sqrt (fabs c))))) (/ b_2 2.0)) a) (/ (- c) (+ (/ b_2 2.0) (if (== (copysign a c) a) (if (> (fabs b_2) (* (sqrt (fabs a)) (sqrt (fabs c)))) (* (sqrt (- (fabs b_2) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs b_2) (* (sqrt (fabs a)) (sqrt (fabs c)))))) NAN) (hypot b_2 (* (sqrt (fabs a)) (sqrt (fabs c))))))))
(/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))