
(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 9 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 -7.8e+141)
(- (/ c b) (/ b a))
(if (<= b 1.7e-203)
(/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (* a 2.0))
(if (<= b 2.2e-108)
(/ (- b (hypot b (* (sqrt (* c -4.0)) (sqrt a)))) (* a -2.0))
(if (<= b 1.5e+77)
(* (- b (sqrt (fma b b (* a (* c -4.0))))) (/ 1.0 (* a -2.0)))
(/ 0.0 (* a 2.0)))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.8e+141) {
tmp = (c / b) - (b / a);
} else if (b <= 1.7e-203) {
tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else if (b <= 2.2e-108) {
tmp = (b - hypot(b, (sqrt((c * -4.0)) * sqrt(a)))) / (a * -2.0);
} else if (b <= 1.5e+77) {
tmp = (b - sqrt(fma(b, b, (a * (c * -4.0))))) * (1.0 / (a * -2.0));
} else {
tmp = 0.0 / (a * 2.0);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -7.8e+141) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.7e-203) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a)))) - b) / Float64(a * 2.0)); elseif (b <= 2.2e-108) tmp = Float64(Float64(b - hypot(b, Float64(sqrt(Float64(c * -4.0)) * sqrt(a)))) / Float64(a * -2.0)); elseif (b <= 1.5e+77) tmp = Float64(Float64(b - sqrt(fma(b, b, Float64(a * Float64(c * -4.0))))) * Float64(1.0 / Float64(a * -2.0))); else tmp = Float64(0.0 / Float64(a * 2.0)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -7.8e+141], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.7e-203], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.2e-108], N[(N[(b - N[Sqrt[b ^ 2 + N[(N[Sqrt[N[(c * -4.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[a], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] / N[(a * -2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.5e+77], N[(N[(b - N[Sqrt[N[(b * b + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(a * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.8 \cdot 10^{+141}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.7 \cdot 10^{-203}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 2.2 \cdot 10^{-108}:\\
\;\;\;\;\frac{b - \mathsf{hypot}\left(b, \sqrt{c \cdot -4} \cdot \sqrt{a}\right)}{a \cdot -2}\\
\mathbf{elif}\;b \leq 1.5 \cdot 10^{+77}:\\
\;\;\;\;\left(b - \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)}\right) \cdot \frac{1}{a \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a \cdot 2}\\
\end{array}
\end{array}
if b < -7.79999999999999983e141Initial program 54.3%
*-commutative54.3%
Simplified54.3%
Taylor expanded in b around -inf 96.3%
+-commutative96.3%
mul-1-neg96.3%
unsub-neg96.3%
Simplified96.3%
if -7.79999999999999983e141 < b < 1.6999999999999999e-203Initial program 85.7%
if 1.6999999999999999e-203 < b < 2.2000000000000001e-108Initial program 39.2%
*-commutative39.2%
Simplified39.2%
frac-2neg39.2%
div-inv39.2%
Applied egg-rr39.2%
expm1-log1p-u38.9%
expm1-udef15.4%
Applied egg-rr27.9%
expm1-def51.4%
expm1-log1p51.4%
*-commutative51.4%
metadata-eval51.4%
times-frac51.4%
*-rgt-identity51.4%
*-commutative51.4%
*-commutative51.4%
Simplified51.4%
*-commutative51.4%
*-commutative51.4%
associate-*r*51.4%
sqrt-prod99.4%
*-commutative99.4%
Applied egg-rr99.4%
if 2.2000000000000001e-108 < b < 1.4999999999999999e77Initial program 89.7%
*-commutative89.7%
Simplified89.7%
frac-2neg89.7%
div-inv89.8%
Applied egg-rr89.8%
if 1.4999999999999999e77 < b Initial program 27.0%
*-commutative27.0%
Simplified27.0%
add-sqr-sqrt9.8%
pow29.8%
pow1/29.8%
sqrt-pow19.8%
fma-neg9.8%
distribute-lft-neg-in9.8%
*-commutative9.8%
associate-*r*9.8%
metadata-eval9.8%
metadata-eval9.8%
Applied egg-rr9.8%
Taylor expanded in b around inf 95.3%
distribute-rgt1-in95.3%
metadata-eval95.3%
mul0-lft95.3%
Simplified95.3%
Final simplification91.1%
(FPCore (a b c)
:precision binary64
(if (<= b -1.05e+141)
(- (/ c b) (/ b a))
(if (<= b 1.5e+77)
(/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (* a 2.0))
(/ 0.0 (* a 2.0)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.05e+141) {
tmp = (c / b) - (b / a);
} else if (b <= 1.5e+77) {
tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else {
tmp = 0.0 / (a * 2.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 <= (-1.05d+141)) then
tmp = (c / b) - (b / a)
else if (b <= 1.5d+77) then
tmp = (sqrt(((b * b) - (4.0d0 * (c * a)))) - b) / (a * 2.0d0)
else
tmp = 0.0d0 / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.05e+141) {
tmp = (c / b) - (b / a);
} else if (b <= 1.5e+77) {
tmp = (Math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else {
tmp = 0.0 / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.05e+141: tmp = (c / b) - (b / a) elif b <= 1.5e+77: tmp = (math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0) else: tmp = 0.0 / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.05e+141) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.5e+77) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a)))) - b) / Float64(a * 2.0)); else tmp = Float64(0.0 / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.05e+141) tmp = (c / b) - (b / a); elseif (b <= 1.5e+77) tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0); else tmp = 0.0 / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.05e+141], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.5e+77], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(0.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.05 \cdot 10^{+141}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.5 \cdot 10^{+77}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a \cdot 2}\\
\end{array}
\end{array}
if b < -1.0499999999999999e141Initial program 54.3%
*-commutative54.3%
Simplified54.3%
Taylor expanded in b around -inf 96.3%
+-commutative96.3%
mul-1-neg96.3%
unsub-neg96.3%
Simplified96.3%
if -1.0499999999999999e141 < b < 1.4999999999999999e77Initial program 84.1%
if 1.4999999999999999e77 < b Initial program 27.0%
*-commutative27.0%
Simplified27.0%
add-sqr-sqrt9.8%
pow29.8%
pow1/29.8%
sqrt-pow19.8%
fma-neg9.8%
distribute-lft-neg-in9.8%
*-commutative9.8%
associate-*r*9.8%
metadata-eval9.8%
metadata-eval9.8%
Applied egg-rr9.8%
Taylor expanded in b around inf 95.3%
distribute-rgt1-in95.3%
metadata-eval95.3%
mul0-lft95.3%
Simplified95.3%
Final simplification89.2%
(FPCore (a b c)
:precision binary64
(if (<= b -3.2e-86)
(- (/ c b) (/ b a))
(if (<= b 1.26e-182)
(/ 1.0 (/ (* a -2.0) (- b (sqrt (* a (* c -4.0))))))
(/ 0.0 (* a 2.0)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.2e-86) {
tmp = (c / b) - (b / a);
} else if (b <= 1.26e-182) {
tmp = 1.0 / ((a * -2.0) / (b - sqrt((a * (c * -4.0)))));
} else {
tmp = 0.0 / (a * 2.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 <= (-3.2d-86)) then
tmp = (c / b) - (b / a)
else if (b <= 1.26d-182) then
tmp = 1.0d0 / ((a * (-2.0d0)) / (b - sqrt((a * (c * (-4.0d0))))))
else
tmp = 0.0d0 / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.2e-86) {
tmp = (c / b) - (b / a);
} else if (b <= 1.26e-182) {
tmp = 1.0 / ((a * -2.0) / (b - Math.sqrt((a * (c * -4.0)))));
} else {
tmp = 0.0 / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.2e-86: tmp = (c / b) - (b / a) elif b <= 1.26e-182: tmp = 1.0 / ((a * -2.0) / (b - math.sqrt((a * (c * -4.0))))) else: tmp = 0.0 / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.2e-86) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.26e-182) tmp = Float64(1.0 / Float64(Float64(a * -2.0) / Float64(b - sqrt(Float64(a * Float64(c * -4.0)))))); else tmp = Float64(0.0 / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.2e-86) tmp = (c / b) - (b / a); elseif (b <= 1.26e-182) tmp = 1.0 / ((a * -2.0) / (b - sqrt((a * (c * -4.0))))); else tmp = 0.0 / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.2e-86], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.26e-182], N[(1.0 / N[(N[(a * -2.0), $MachinePrecision] / N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.2 \cdot 10^{-86}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.26 \cdot 10^{-182}:\\
\;\;\;\;\frac{1}{\frac{a \cdot -2}{b - \sqrt{a \cdot \left(c \cdot -4\right)}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a \cdot 2}\\
\end{array}
\end{array}
if b < -3.20000000000000006e-86Initial program 74.4%
*-commutative74.4%
Simplified74.4%
Taylor expanded in b around -inf 88.5%
+-commutative88.5%
mul-1-neg88.5%
unsub-neg88.5%
Simplified88.5%
if -3.20000000000000006e-86 < b < 1.26e-182Initial program 76.0%
*-commutative76.0%
Simplified76.0%
frac-2neg76.0%
div-inv76.0%
Applied egg-rr76.0%
Taylor expanded in b around 0 72.8%
*-commutative72.8%
Simplified72.8%
un-div-inv72.9%
clear-num72.9%
associate-*r*72.9%
Applied egg-rr72.9%
if 1.26e-182 < b Initial program 48.8%
*-commutative48.8%
Simplified48.8%
add-sqr-sqrt28.9%
pow228.9%
pow1/228.9%
sqrt-pow129.0%
fma-neg29.0%
distribute-lft-neg-in29.0%
*-commutative29.0%
associate-*r*29.0%
metadata-eval29.0%
metadata-eval29.0%
Applied egg-rr29.0%
Taylor expanded in b around inf 80.3%
distribute-rgt1-in80.3%
metadata-eval80.3%
mul0-lft80.3%
Simplified80.3%
Final simplification82.0%
(FPCore (a b c)
:precision binary64
(if (<= b -3.8e-88)
(- (/ c b) (/ b a))
(if (<= b 1.26e-182)
(* (- b (sqrt (* a (* c -4.0)))) (/ -0.5 a))
(/ 0.0 (* a 2.0)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.8e-88) {
tmp = (c / b) - (b / a);
} else if (b <= 1.26e-182) {
tmp = (b - sqrt((a * (c * -4.0)))) * (-0.5 / a);
} else {
tmp = 0.0 / (a * 2.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 <= (-3.8d-88)) then
tmp = (c / b) - (b / a)
else if (b <= 1.26d-182) then
tmp = (b - sqrt((a * (c * (-4.0d0))))) * ((-0.5d0) / a)
else
tmp = 0.0d0 / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.8e-88) {
tmp = (c / b) - (b / a);
} else if (b <= 1.26e-182) {
tmp = (b - Math.sqrt((a * (c * -4.0)))) * (-0.5 / a);
} else {
tmp = 0.0 / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.8e-88: tmp = (c / b) - (b / a) elif b <= 1.26e-182: tmp = (b - math.sqrt((a * (c * -4.0)))) * (-0.5 / a) else: tmp = 0.0 / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.8e-88) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.26e-182) tmp = Float64(Float64(b - sqrt(Float64(a * Float64(c * -4.0)))) * Float64(-0.5 / a)); else tmp = Float64(0.0 / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.8e-88) tmp = (c / b) - (b / a); elseif (b <= 1.26e-182) tmp = (b - sqrt((a * (c * -4.0)))) * (-0.5 / a); else tmp = 0.0 / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.8e-88], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.26e-182], N[(N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[(0.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.8 \cdot 10^{-88}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.26 \cdot 10^{-182}:\\
\;\;\;\;\left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a \cdot 2}\\
\end{array}
\end{array}
if b < -3.80000000000000011e-88Initial program 74.4%
*-commutative74.4%
Simplified74.4%
Taylor expanded in b around -inf 88.5%
+-commutative88.5%
mul-1-neg88.5%
unsub-neg88.5%
Simplified88.5%
if -3.80000000000000011e-88 < b < 1.26e-182Initial program 76.0%
*-commutative76.0%
Simplified76.0%
frac-2neg76.0%
div-inv76.0%
Applied egg-rr76.0%
Taylor expanded in b around 0 72.8%
*-commutative72.8%
Simplified72.8%
*-commutative72.8%
sub-neg72.8%
distribute-rgt-in72.8%
*-commutative72.8%
associate-/r*72.8%
metadata-eval72.8%
associate-*r*72.8%
add-cube-cbrt72.3%
unpow372.3%
unpow372.3%
add-cube-cbrt72.8%
*-commutative72.8%
associate-/r*72.8%
metadata-eval72.8%
Applied egg-rr72.8%
distribute-rgt-out72.8%
sub-neg72.8%
Simplified72.8%
if 1.26e-182 < b Initial program 48.8%
*-commutative48.8%
Simplified48.8%
add-sqr-sqrt28.9%
pow228.9%
pow1/228.9%
sqrt-pow129.0%
fma-neg29.0%
distribute-lft-neg-in29.0%
*-commutative29.0%
associate-*r*29.0%
metadata-eval29.0%
metadata-eval29.0%
Applied egg-rr29.0%
Taylor expanded in b around inf 80.3%
distribute-rgt1-in80.3%
metadata-eval80.3%
mul0-lft80.3%
Simplified80.3%
Final simplification82.0%
(FPCore (a b c)
:precision binary64
(if (<= b -9.6e-87)
(- (/ c b) (/ b a))
(if (<= b 1.26e-182)
(/ (/ (- b (sqrt (* a (* c -4.0)))) a) -2.0)
(/ 0.0 (* a 2.0)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9.6e-87) {
tmp = (c / b) - (b / a);
} else if (b <= 1.26e-182) {
tmp = ((b - sqrt((a * (c * -4.0)))) / a) / -2.0;
} else {
tmp = 0.0 / (a * 2.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 <= (-9.6d-87)) then
tmp = (c / b) - (b / a)
else if (b <= 1.26d-182) then
tmp = ((b - sqrt((a * (c * (-4.0d0))))) / a) / (-2.0d0)
else
tmp = 0.0d0 / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -9.6e-87) {
tmp = (c / b) - (b / a);
} else if (b <= 1.26e-182) {
tmp = ((b - Math.sqrt((a * (c * -4.0)))) / a) / -2.0;
} else {
tmp = 0.0 / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9.6e-87: tmp = (c / b) - (b / a) elif b <= 1.26e-182: tmp = ((b - math.sqrt((a * (c * -4.0)))) / a) / -2.0 else: tmp = 0.0 / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9.6e-87) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.26e-182) tmp = Float64(Float64(Float64(b - sqrt(Float64(a * Float64(c * -4.0)))) / a) / -2.0); else tmp = Float64(0.0 / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9.6e-87) tmp = (c / b) - (b / a); elseif (b <= 1.26e-182) tmp = ((b - sqrt((a * (c * -4.0)))) / a) / -2.0; else tmp = 0.0 / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9.6e-87], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.26e-182], N[(N[(N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision] / -2.0), $MachinePrecision], N[(0.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9.6 \cdot 10^{-87}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.26 \cdot 10^{-182}:\\
\;\;\;\;\frac{\frac{b - \sqrt{a \cdot \left(c \cdot -4\right)}}{a}}{-2}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a \cdot 2}\\
\end{array}
\end{array}
if b < -9.5999999999999998e-87Initial program 74.4%
*-commutative74.4%
Simplified74.4%
Taylor expanded in b around -inf 88.5%
+-commutative88.5%
mul-1-neg88.5%
unsub-neg88.5%
Simplified88.5%
if -9.5999999999999998e-87 < b < 1.26e-182Initial program 76.0%
*-commutative76.0%
Simplified76.0%
frac-2neg76.0%
div-inv76.0%
Applied egg-rr76.0%
Taylor expanded in b around 0 72.8%
*-commutative72.8%
Simplified72.8%
un-div-inv72.9%
associate-/r*72.9%
associate-*r*72.9%
Applied egg-rr72.9%
if 1.26e-182 < b Initial program 48.8%
*-commutative48.8%
Simplified48.8%
add-sqr-sqrt28.9%
pow228.9%
pow1/228.9%
sqrt-pow129.0%
fma-neg29.0%
distribute-lft-neg-in29.0%
*-commutative29.0%
associate-*r*29.0%
metadata-eval29.0%
metadata-eval29.0%
Applied egg-rr29.0%
Taylor expanded in b around inf 80.3%
distribute-rgt1-in80.3%
metadata-eval80.3%
mul0-lft80.3%
Simplified80.3%
Final simplification82.0%
(FPCore (a b c) :precision binary64 (if (<= b -1.6e-296) (- (/ c b) (/ b a)) (/ 0.0 (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.6e-296) {
tmp = (c / b) - (b / a);
} else {
tmp = 0.0 / (a * 2.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 <= (-1.6d-296)) then
tmp = (c / b) - (b / a)
else
tmp = 0.0d0 / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.6e-296) {
tmp = (c / b) - (b / a);
} else {
tmp = 0.0 / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.6e-296: tmp = (c / b) - (b / a) else: tmp = 0.0 / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.6e-296) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(0.0 / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.6e-296) tmp = (c / b) - (b / a); else tmp = 0.0 / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.6e-296], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(0.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.6 \cdot 10^{-296}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a \cdot 2}\\
\end{array}
\end{array}
if b < -1.60000000000000006e-296Initial program 73.6%
*-commutative73.6%
Simplified73.6%
Taylor expanded in b around -inf 70.7%
+-commutative70.7%
mul-1-neg70.7%
unsub-neg70.7%
Simplified70.7%
if -1.60000000000000006e-296 < b Initial program 54.3%
*-commutative54.3%
Simplified54.3%
add-sqr-sqrt37.5%
pow237.5%
pow1/237.5%
sqrt-pow137.5%
fma-neg37.6%
distribute-lft-neg-in37.6%
*-commutative37.6%
associate-*r*37.6%
metadata-eval37.6%
metadata-eval37.6%
Applied egg-rr37.6%
Taylor expanded in b around inf 68.3%
distribute-rgt1-in68.3%
metadata-eval68.3%
mul0-lft68.3%
Simplified68.3%
Final simplification69.6%
(FPCore (a b c) :precision binary64 (if (<= b -9.5e-301) (/ (- b) a) (/ 0.0 (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9.5e-301) {
tmp = -b / a;
} else {
tmp = 0.0 / (a * 2.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 <= (-9.5d-301)) then
tmp = -b / a
else
tmp = 0.0d0 / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -9.5e-301) {
tmp = -b / a;
} else {
tmp = 0.0 / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9.5e-301: tmp = -b / a else: tmp = 0.0 / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9.5e-301) tmp = Float64(Float64(-b) / a); else tmp = Float64(0.0 / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9.5e-301) tmp = -b / a; else tmp = 0.0 / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9.5e-301], N[((-b) / a), $MachinePrecision], N[(0.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9.5 \cdot 10^{-301}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a \cdot 2}\\
\end{array}
\end{array}
if b < -9.50000000000000032e-301Initial program 73.8%
*-commutative73.8%
Simplified73.8%
Taylor expanded in b around -inf 69.4%
associate-*r/69.4%
mul-1-neg69.4%
Simplified69.4%
if -9.50000000000000032e-301 < b Initial program 54.0%
*-commutative54.0%
Simplified54.0%
add-sqr-sqrt37.0%
pow237.0%
pow1/237.0%
sqrt-pow137.0%
fma-neg37.0%
distribute-lft-neg-in37.0%
*-commutative37.0%
associate-*r*37.0%
metadata-eval37.0%
metadata-eval37.0%
Applied egg-rr37.0%
Taylor expanded in b around inf 68.8%
distribute-rgt1-in68.8%
metadata-eval68.8%
mul0-lft68.8%
Simplified68.8%
Final simplification69.2%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
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 = -c / b
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 = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 74.2%
*-commutative74.2%
Simplified74.2%
Taylor expanded in b around -inf 68.5%
associate-*r/68.5%
mul-1-neg68.5%
Simplified68.5%
if -1.999999999999994e-310 < b Initial program 53.2%
*-commutative53.2%
Simplified53.2%
Taylor expanded in b around inf 22.6%
associate-*r/22.6%
neg-mul-122.6%
Simplified22.6%
Final simplification47.2%
(FPCore (a b c) :precision binary64 (/ (- b) a))
double code(double a, double b, double c) {
return -b / 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 / a
end function
public static double code(double a, double b, double c) {
return -b / a;
}
def code(a, b, c): return -b / a
function code(a, b, c) return Float64(Float64(-b) / a) end
function tmp = code(a, b, c) tmp = -b / a; end
code[a_, b_, c_] := N[((-b) / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{-b}{a}
\end{array}
Initial program 64.4%
*-commutative64.4%
Simplified64.4%
Taylor expanded in b around -inf 37.9%
associate-*r/37.9%
mul-1-neg37.9%
Simplified37.9%
Final simplification37.9%
(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 2024023
(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)))