
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -2e+156)
(/ (- (- (* 2.0 (* a (/ c b))) b) b) (* 2.0 a))
(if (<= b 2e+89)
(/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* 2.0 a))
0.0)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e+156) {
tmp = (((2.0 * (a * (c / b))) - b) - b) / (2.0 * a);
} else if (b <= 2e+89) {
tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (2.0 * a);
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2d+156)) then
tmp = (((2.0d0 * (a * (c / b))) - b) - b) / (2.0d0 * a)
else if (b <= 2d+89) then
tmp = (sqrt(((b * b) - (4.0d0 * (a * c)))) - b) / (2.0d0 * a)
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2e+156) {
tmp = (((2.0 * (a * (c / b))) - b) - b) / (2.0 * a);
} else if (b <= 2e+89) {
tmp = (Math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (2.0 * a);
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e+156: tmp = (((2.0 * (a * (c / b))) - b) - b) / (2.0 * a) elif b <= 2e+89: tmp = (math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (2.0 * a) else: tmp = 0.0 return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e+156) tmp = Float64(Float64(Float64(Float64(2.0 * Float64(a * Float64(c / b))) - b) - b) / Float64(2.0 * a)); elseif (b <= 2e+89) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) - b) / Float64(2.0 * a)); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e+156) tmp = (((2.0 * (a * (c / b))) - b) - b) / (2.0 * a); elseif (b <= 2e+89) tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (2.0 * a); else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e+156], N[(N[(N[(N[(2.0 * N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2e+89], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{+156}:\\
\;\;\;\;\frac{\left(2 \cdot \left(a \cdot \frac{c}{b}\right) - b\right) - b}{2 \cdot a}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+89}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -2e156Initial program 36.8%
*-commutative36.8%
Simplified36.8%
add-sqr-sqrt36.8%
pow236.8%
pow1/236.8%
sqrt-pow136.8%
sub-neg36.8%
+-commutative36.8%
distribute-lft-neg-in36.8%
*-commutative36.8%
associate-*r*36.8%
fma-define37.1%
metadata-eval37.1%
pow237.1%
metadata-eval37.1%
Applied egg-rr37.1%
Taylor expanded in b around -inf 87.7%
mul-1-neg87.7%
+-commutative87.7%
unsub-neg87.7%
associate-/l*99.9%
Simplified99.9%
if -2e156 < b < 1.99999999999999999e89Initial program 84.3%
if 1.99999999999999999e89 < b Initial program 27.6%
*-commutative27.6%
Simplified27.6%
add-sqr-sqrt18.3%
pow218.3%
pow1/218.3%
sqrt-pow118.3%
sub-neg18.3%
+-commutative18.3%
distribute-lft-neg-in18.3%
*-commutative18.3%
associate-*r*18.3%
fma-define18.4%
metadata-eval18.4%
pow218.4%
metadata-eval18.4%
Applied egg-rr18.4%
Taylor expanded in b around inf 60.5%
distribute-rgt-out60.5%
metadata-eval60.5%
mul0-rgt98.2%
Simplified98.2%
Final simplification90.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (- (/ c b) (/ b a)))
(t_1 (* (- (sqrt (* c (* a -4.0))) b) (/ 0.5 a))))
(if (<= b -3.35e-31)
t_0
(if (<= b -4e-75)
t_1
(if (<= b -1.55e-102) t_0 (if (<= b 1.5e-146) t_1 0.0))))))
double code(double a, double b, double c) {
double t_0 = (c / b) - (b / a);
double t_1 = (sqrt((c * (a * -4.0))) - b) * (0.5 / a);
double tmp;
if (b <= -3.35e-31) {
tmp = t_0;
} else if (b <= -4e-75) {
tmp = t_1;
} else if (b <= -1.55e-102) {
tmp = t_0;
} else if (b <= 1.5e-146) {
tmp = t_1;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (c / b) - (b / a)
t_1 = (sqrt((c * (a * (-4.0d0)))) - b) * (0.5d0 / a)
if (b <= (-3.35d-31)) then
tmp = t_0
else if (b <= (-4d-75)) then
tmp = t_1
else if (b <= (-1.55d-102)) then
tmp = t_0
else if (b <= 1.5d-146) then
tmp = t_1
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (c / b) - (b / a);
double t_1 = (Math.sqrt((c * (a * -4.0))) - b) * (0.5 / a);
double tmp;
if (b <= -3.35e-31) {
tmp = t_0;
} else if (b <= -4e-75) {
tmp = t_1;
} else if (b <= -1.55e-102) {
tmp = t_0;
} else if (b <= 1.5e-146) {
tmp = t_1;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b, c): t_0 = (c / b) - (b / a) t_1 = (math.sqrt((c * (a * -4.0))) - b) * (0.5 / a) tmp = 0 if b <= -3.35e-31: tmp = t_0 elif b <= -4e-75: tmp = t_1 elif b <= -1.55e-102: tmp = t_0 elif b <= 1.5e-146: tmp = t_1 else: tmp = 0.0 return tmp
function code(a, b, c) t_0 = Float64(Float64(c / b) - Float64(b / a)) t_1 = Float64(Float64(sqrt(Float64(c * Float64(a * -4.0))) - b) * Float64(0.5 / a)) tmp = 0.0 if (b <= -3.35e-31) tmp = t_0; elseif (b <= -4e-75) tmp = t_1; elseif (b <= -1.55e-102) tmp = t_0; elseif (b <= 1.5e-146) tmp = t_1; else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b, c) t_0 = (c / b) - (b / a); t_1 = (sqrt((c * (a * -4.0))) - b) * (0.5 / a); tmp = 0.0; if (b <= -3.35e-31) tmp = t_0; elseif (b <= -4e-75) tmp = t_1; elseif (b <= -1.55e-102) tmp = t_0; elseif (b <= 1.5e-146) tmp = t_1; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -3.35e-31], t$95$0, If[LessEqual[b, -4e-75], t$95$1, If[LessEqual[b, -1.55e-102], t$95$0, If[LessEqual[b, 1.5e-146], t$95$1, 0.0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c}{b} - \frac{b}{a}\\
t_1 := \left(\sqrt{c \cdot \left(a \cdot -4\right)} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{if}\;b \leq -3.35 \cdot 10^{-31}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq -4 \cdot 10^{-75}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;b \leq -1.55 \cdot 10^{-102}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq 1.5 \cdot 10^{-146}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -3.35000000000000002e-31 or -3.9999999999999998e-75 < b < -1.55000000000000006e-102Initial program 65.2%
*-commutative65.2%
Simplified65.2%
Taylor expanded in b around -inf 90.5%
+-commutative90.5%
mul-1-neg90.5%
unsub-neg90.5%
Simplified90.5%
if -3.35000000000000002e-31 < b < -3.9999999999999998e-75 or -1.55000000000000006e-102 < b < 1.50000000000000009e-146Initial program 80.8%
*-commutative80.8%
Simplified80.8%
add-sqr-sqrt80.3%
pow280.3%
pow1/280.3%
sqrt-pow180.4%
sub-neg80.4%
+-commutative80.4%
distribute-lft-neg-in80.4%
*-commutative80.4%
associate-*r*80.4%
fma-define80.4%
metadata-eval80.4%
pow280.4%
metadata-eval80.4%
Applied egg-rr80.4%
Taylor expanded in c around inf 52.2%
Simplified79.3%
div-inv79.3%
*-commutative79.3%
*-commutative79.3%
associate-/r*79.3%
metadata-eval79.3%
Applied egg-rr79.3%
if 1.50000000000000009e-146 < b Initial program 51.9%
*-commutative51.9%
Simplified51.9%
add-sqr-sqrt35.6%
pow235.6%
pow1/235.6%
sqrt-pow135.6%
sub-neg35.6%
+-commutative35.6%
distribute-lft-neg-in35.6%
*-commutative35.6%
associate-*r*35.6%
fma-define35.6%
metadata-eval35.6%
pow235.6%
metadata-eval35.6%
Applied egg-rr35.6%
Taylor expanded in b around inf 56.9%
distribute-rgt-out56.9%
metadata-eval56.9%
mul0-rgt79.8%
Simplified79.8%
Final simplification84.0%
(FPCore (a b c) :precision binary64 (if (<= b -2.35e-293) (- (/ c b) (/ b a)) 0.0))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.35e-293) {
tmp = (c / b) - (b / a);
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2.35d-293)) then
tmp = (c / b) - (b / a)
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.35e-293) {
tmp = (c / b) - (b / a);
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.35e-293: tmp = (c / b) - (b / a) else: tmp = 0.0 return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.35e-293) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.35e-293) tmp = (c / b) - (b / a); else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.35e-293], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.35 \cdot 10^{-293}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -2.35000000000000006e-293Initial program 69.7%
*-commutative69.7%
Simplified69.7%
Taylor expanded in b around -inf 68.3%
+-commutative68.3%
mul-1-neg68.3%
unsub-neg68.3%
Simplified68.3%
if -2.35000000000000006e-293 < b Initial program 56.0%
*-commutative56.0%
Simplified56.0%
add-sqr-sqrt42.2%
pow242.2%
pow1/242.2%
sqrt-pow142.2%
sub-neg42.2%
+-commutative42.2%
distribute-lft-neg-in42.2%
*-commutative42.2%
associate-*r*42.2%
fma-define42.2%
metadata-eval42.2%
pow242.2%
metadata-eval42.2%
Applied egg-rr42.2%
Taylor expanded in b around inf 48.5%
distribute-rgt-out48.5%
metadata-eval48.5%
mul0-rgt67.8%
Simplified67.8%
Final simplification68.1%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (- (/ b a)) 0.0))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = -(b / a);
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2d-310)) then
tmp = -(b / a)
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = -(b / a);
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = -(b / a) else: tmp = 0.0 return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(-Float64(b / a)); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-310) tmp = -(b / a); else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], (-N[(b / a), $MachinePrecision]), 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 69.9%
*-commutative69.9%
Simplified69.9%
Taylor expanded in b around -inf 67.1%
associate-*r/67.1%
mul-1-neg67.1%
Simplified67.1%
if -1.999999999999994e-310 < b Initial program 55.7%
*-commutative55.7%
Simplified55.7%
add-sqr-sqrt41.7%
pow241.7%
pow1/241.7%
sqrt-pow141.7%
sub-neg41.7%
+-commutative41.7%
distribute-lft-neg-in41.7%
*-commutative41.7%
associate-*r*41.7%
fma-define41.7%
metadata-eval41.7%
pow241.7%
metadata-eval41.7%
Applied egg-rr41.7%
Taylor expanded in b around inf 48.9%
distribute-rgt-out48.9%
metadata-eval48.9%
mul0-rgt68.4%
Simplified68.4%
Final simplification67.7%
(FPCore (a b c) :precision binary64 0.0)
double code(double a, double b, double c) {
return 0.0;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = 0.0d0
end function
public static double code(double a, double b, double c) {
return 0.0;
}
def code(a, b, c): return 0.0
function code(a, b, c) return 0.0 end
function tmp = code(a, b, c) tmp = 0.0; end
code[a_, b_, c_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 63.6%
*-commutative63.6%
Simplified63.6%
add-sqr-sqrt57.4%
pow257.4%
pow1/257.4%
sqrt-pow157.4%
sub-neg57.4%
+-commutative57.4%
distribute-lft-neg-in57.4%
*-commutative57.4%
associate-*r*57.4%
fma-define57.4%
metadata-eval57.4%
pow257.4%
metadata-eval57.4%
Applied egg-rr57.4%
Taylor expanded in b around inf 22.9%
distribute-rgt-out22.9%
metadata-eval22.9%
mul0-rgt31.6%
Simplified31.6%
Final simplification31.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fabs (/ b 2.0)))
(t_1 (* (sqrt (fabs a)) (sqrt (fabs c))))
(t_2
(if (== (copysign a c) a)
(* (sqrt (- t_0 t_1)) (sqrt (+ t_0 t_1)))
(hypot (/ b 2.0) t_1))))
(if (< b 0.0) (/ (- t_2 (/ b 2.0)) a) (/ (- c) (+ (/ b 2.0) t_2)))))
double code(double a, double b, double c) {
double t_0 = fabs((b / 2.0));
double t_1 = sqrt(fabs(a)) * sqrt(fabs(c));
double tmp;
if (copysign(a, c) == a) {
tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1));
} else {
tmp = hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = (t_2 - (b / 2.0)) / a;
} else {
tmp_1 = -c / ((b / 2.0) + t_2);
}
return tmp_1;
}
public static double code(double a, double b, double c) {
double t_0 = Math.abs((b / 2.0));
double t_1 = Math.sqrt(Math.abs(a)) * Math.sqrt(Math.abs(c));
double tmp;
if (Math.copySign(a, c) == a) {
tmp = Math.sqrt((t_0 - t_1)) * Math.sqrt((t_0 + t_1));
} else {
tmp = Math.hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = (t_2 - (b / 2.0)) / a;
} else {
tmp_1 = -c / ((b / 2.0) + t_2);
}
return tmp_1;
}
def code(a, b, c): t_0 = math.fabs((b / 2.0)) t_1 = math.sqrt(math.fabs(a)) * math.sqrt(math.fabs(c)) tmp = 0 if math.copysign(a, c) == a: tmp = math.sqrt((t_0 - t_1)) * math.sqrt((t_0 + t_1)) else: tmp = math.hypot((b / 2.0), t_1) t_2 = tmp tmp_1 = 0 if b < 0.0: tmp_1 = (t_2 - (b / 2.0)) / a else: tmp_1 = -c / ((b / 2.0) + t_2) return tmp_1
function code(a, b, c) t_0 = abs(Float64(b / 2.0)) t_1 = Float64(sqrt(abs(a)) * sqrt(abs(c))) tmp = 0.0 if (copysign(a, c) == a) tmp = Float64(sqrt(Float64(t_0 - t_1)) * sqrt(Float64(t_0 + t_1))); else tmp = hypot(Float64(b / 2.0), t_1); end t_2 = tmp tmp_1 = 0.0 if (b < 0.0) tmp_1 = Float64(Float64(t_2 - Float64(b / 2.0)) / a); else tmp_1 = Float64(Float64(-c) / Float64(Float64(b / 2.0) + t_2)); end return tmp_1 end
function tmp_3 = code(a, b, c) t_0 = abs((b / 2.0)); t_1 = sqrt(abs(a)) * sqrt(abs(c)); tmp = 0.0; if ((sign(c) * abs(a)) == a) tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1)); else tmp = hypot((b / 2.0), t_1); end t_2 = tmp; tmp_2 = 0.0; if (b < 0.0) tmp_2 = (t_2 - (b / 2.0)) / a; else tmp_2 = -c / ((b / 2.0) + t_2); end tmp_3 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[Abs[N[(b / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Sqrt[N[Abs[a], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[c], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = If[Equal[N[With[{TMP1 = Abs[a], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], a], N[(N[Sqrt[N[(t$95$0 - t$95$1), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(b / 2.0), $MachinePrecision] ^ 2 + t$95$1 ^ 2], $MachinePrecision]]}, If[Less[b, 0.0], N[(N[(t$95$2 - N[(b / 2.0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[((-c) / N[(N[(b / 2.0), $MachinePrecision] + t$95$2), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{b}{2}\right|\\
t_1 := \sqrt{\left|a\right|} \cdot \sqrt{\left|c\right|}\\
t_2 := \begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(a, c\right) = a:\\
\;\;\;\;\sqrt{t\_0 - t\_1} \cdot \sqrt{t\_0 + t\_1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\frac{b}{2}, t\_1\right)\\
\end{array}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{t\_2 - \frac{b}{2}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{\frac{b}{2} + t\_2}\\
\end{array}
\end{array}
herbie shell --seed 2024052
(FPCore (a b c)
:name "quadp (p42, positive)"
:precision binary64
:herbie-expected 10
:herbie-target
(if (< b 0.0) (/ (- (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c))))) (/ b 2.0)) a) (/ (- c) (+ (/ b 2.0) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c))))))))
(/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))