
(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 8 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 -4.6e+59)
(/ b (- a))
(if (<= b 8.4e-35)
(/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e+59) {
tmp = b / -a;
} else if (b <= 8.4e-35) {
tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
} 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 <= (-4.6d+59)) then
tmp = b / -a
else if (b <= 8.4d-35) then
tmp = (sqrt(((b * b) - (4.0d0 * (a * c)))) - b) / (a * 2.0d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e+59) {
tmp = b / -a;
} else if (b <= 8.4e-35) {
tmp = (Math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.6e+59: tmp = b / -a elif b <= 8.4e-35: tmp = (math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.6e+59) tmp = Float64(b / Float64(-a)); elseif (b <= 8.4e-35) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.6e+59) tmp = b / -a; elseif (b <= 8.4e-35) tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.6e+59], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 8.4e-35], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.6 \cdot 10^{+59}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 8.4 \cdot 10^{-35}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -4.60000000000000016e59Initial program 66.0%
*-commutative66.0%
Simplified66.0%
Taylor expanded in b around -inf 93.6%
associate-*r/93.6%
mul-1-neg93.6%
Simplified93.6%
if -4.60000000000000016e59 < b < 8.3999999999999999e-35Initial program 82.9%
if 8.3999999999999999e-35 < b Initial program 17.3%
*-commutative17.3%
Simplified17.3%
Taylor expanded in b around inf 87.2%
associate-*r/87.2%
neg-mul-187.2%
Simplified87.2%
Final simplification87.0%
(FPCore (a b c) :precision binary64 (if (<= b -2.9e-78) (/ b (- a)) (if (<= b 7e-40) (/ (- (sqrt (* c (* a -4.0))) b) (* a 2.0)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.9e-78) {
tmp = b / -a;
} else if (b <= 7e-40) {
tmp = (sqrt((c * (a * -4.0))) - b) / (a * 2.0);
} 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 <= (-2.9d-78)) then
tmp = b / -a
else if (b <= 7d-40) then
tmp = (sqrt((c * (a * (-4.0d0)))) - b) / (a * 2.0d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.9e-78) {
tmp = b / -a;
} else if (b <= 7e-40) {
tmp = (Math.sqrt((c * (a * -4.0))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.9e-78: tmp = b / -a elif b <= 7e-40: tmp = (math.sqrt((c * (a * -4.0))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.9e-78) tmp = Float64(b / Float64(-a)); elseif (b <= 7e-40) tmp = Float64(Float64(sqrt(Float64(c * Float64(a * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.9e-78) tmp = b / -a; elseif (b <= 7e-40) tmp = (sqrt((c * (a * -4.0))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.9e-78], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 7e-40], N[(N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.9 \cdot 10^{-78}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 7 \cdot 10^{-40}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -2.9000000000000001e-78Initial program 74.5%
*-commutative74.5%
Simplified74.5%
Taylor expanded in b around -inf 86.8%
associate-*r/86.8%
mul-1-neg86.8%
Simplified86.8%
if -2.9000000000000001e-78 < b < 7.0000000000000003e-40Initial program 79.8%
*-commutative79.8%
Simplified79.8%
Taylor expanded in b around 0 78.7%
associate-*r*78.7%
*-commutative78.7%
*-commutative78.7%
Simplified78.7%
if 7.0000000000000003e-40 < b Initial program 17.3%
*-commutative17.3%
Simplified17.3%
Taylor expanded in b around inf 87.2%
associate-*r/87.2%
neg-mul-187.2%
Simplified87.2%
Final simplification84.9%
(FPCore (a b c) :precision binary64 (if (<= b -1.45e-78) (/ b (- a)) (if (<= b 1.32e-37) (/ (sqrt (* c (* a -4.0))) (* a 2.0)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.45e-78) {
tmp = b / -a;
} else if (b <= 1.32e-37) {
tmp = sqrt((c * (a * -4.0))) / (a * 2.0);
} 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 <= (-1.45d-78)) then
tmp = b / -a
else if (b <= 1.32d-37) then
tmp = sqrt((c * (a * (-4.0d0)))) / (a * 2.0d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.45e-78) {
tmp = b / -a;
} else if (b <= 1.32e-37) {
tmp = Math.sqrt((c * (a * -4.0))) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.45e-78: tmp = b / -a elif b <= 1.32e-37: tmp = math.sqrt((c * (a * -4.0))) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.45e-78) tmp = Float64(b / Float64(-a)); elseif (b <= 1.32e-37) tmp = Float64(sqrt(Float64(c * Float64(a * -4.0))) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.45e-78) tmp = b / -a; elseif (b <= 1.32e-37) tmp = sqrt((c * (a * -4.0))) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.45e-78], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 1.32e-37], N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.45 \cdot 10^{-78}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 1.32 \cdot 10^{-37}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.45e-78Initial program 74.5%
*-commutative74.5%
Simplified74.5%
Taylor expanded in b around -inf 86.8%
associate-*r/86.8%
mul-1-neg86.8%
Simplified86.8%
if -1.45e-78 < b < 1.3200000000000001e-37Initial program 79.8%
*-commutative79.8%
Simplified79.8%
add-cube-cbrt78.9%
pow378.8%
*-commutative78.8%
associate-*l*78.8%
Applied egg-rr78.8%
Taylor expanded in a around -inf 0.0%
mul-1-neg0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt77.1%
distribute-lft-neg-in77.1%
metadata-eval77.1%
rem-cube-cbrt77.7%
Simplified77.7%
*-un-lft-identity77.7%
add-sqr-sqrt77.2%
*-un-lft-identity77.2%
times-frac77.3%
pow1/277.3%
sqrt-pow177.3%
associate-*r*77.3%
*-commutative77.3%
associate-*l*77.3%
metadata-eval77.3%
pow1/277.3%
sqrt-pow177.3%
associate-*r*77.3%
*-commutative77.3%
associate-*l*77.3%
metadata-eval77.3%
Applied egg-rr77.3%
/-rgt-identity77.3%
associate-*r/77.2%
pow-sqr77.7%
metadata-eval77.7%
unpow1/277.7%
Simplified77.7%
if 1.3200000000000001e-37 < b Initial program 17.3%
*-commutative17.3%
Simplified17.3%
Taylor expanded in b around inf 87.2%
associate-*r/87.2%
neg-mul-187.2%
Simplified87.2%
Final simplification84.6%
(FPCore (a b c) :precision binary64 (if (<= b -4.3e-78) (/ b (- a)) (if (<= b 5e-37) (* (sqrt (* c (* a -4.0))) (/ 0.5 a)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.3e-78) {
tmp = b / -a;
} else if (b <= 5e-37) {
tmp = sqrt((c * (a * -4.0))) * (0.5 / 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 <= (-4.3d-78)) then
tmp = b / -a
else if (b <= 5d-37) then
tmp = sqrt((c * (a * (-4.0d0)))) * (0.5d0 / 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 <= -4.3e-78) {
tmp = b / -a;
} else if (b <= 5e-37) {
tmp = Math.sqrt((c * (a * -4.0))) * (0.5 / a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.3e-78: tmp = b / -a elif b <= 5e-37: tmp = math.sqrt((c * (a * -4.0))) * (0.5 / a) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.3e-78) tmp = Float64(b / Float64(-a)); elseif (b <= 5e-37) tmp = Float64(sqrt(Float64(c * Float64(a * -4.0))) * Float64(0.5 / a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.3e-78) tmp = b / -a; elseif (b <= 5e-37) tmp = sqrt((c * (a * -4.0))) * (0.5 / a); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.3e-78], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 5e-37], N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.3 \cdot 10^{-78}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{-37}:\\
\;\;\;\;\sqrt{c \cdot \left(a \cdot -4\right)} \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -4.29999999999999994e-78Initial program 74.5%
*-commutative74.5%
Simplified74.5%
Taylor expanded in b around -inf 86.8%
associate-*r/86.8%
mul-1-neg86.8%
Simplified86.8%
if -4.29999999999999994e-78 < b < 4.9999999999999997e-37Initial program 79.8%
*-commutative79.8%
Simplified79.8%
add-cube-cbrt78.9%
pow378.8%
*-commutative78.8%
associate-*l*78.8%
Applied egg-rr78.8%
Taylor expanded in a around -inf 0.0%
mul-1-neg0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt77.1%
distribute-lft-neg-in77.1%
metadata-eval77.1%
rem-cube-cbrt77.7%
Simplified77.7%
*-commutative77.7%
associate-*r/77.5%
add-sqr-sqrt77.1%
associate-*l*77.1%
pow1/277.1%
sqrt-pow177.2%
associate-*r*77.2%
*-commutative77.2%
associate-*l*77.2%
metadata-eval77.2%
pow1/277.2%
sqrt-pow177.1%
associate-*r*77.1%
*-commutative77.1%
associate-*l*77.1%
metadata-eval77.1%
*-commutative77.1%
associate-/r*77.1%
metadata-eval77.1%
Applied egg-rr77.1%
associate-*r*77.1%
pow-sqr77.5%
metadata-eval77.5%
unpow1/277.5%
Simplified77.5%
if 4.9999999999999997e-37 < b Initial program 17.3%
*-commutative17.3%
Simplified17.3%
Taylor expanded in b around inf 87.2%
associate-*r/87.2%
neg-mul-187.2%
Simplified87.2%
Final simplification84.5%
(FPCore (a b c) :precision binary64 (if (<= b -3e-119) (/ b (- a)) (if (<= b 6.2e-40) (* -0.5 (- (sqrt (* c (/ -4.0 a))))) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3e-119) {
tmp = b / -a;
} else if (b <= 6.2e-40) {
tmp = -0.5 * -sqrt((c * (-4.0 / 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 <= (-3d-119)) then
tmp = b / -a
else if (b <= 6.2d-40) then
tmp = (-0.5d0) * -sqrt((c * ((-4.0d0) / 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 <= -3e-119) {
tmp = b / -a;
} else if (b <= 6.2e-40) {
tmp = -0.5 * -Math.sqrt((c * (-4.0 / a)));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3e-119: tmp = b / -a elif b <= 6.2e-40: tmp = -0.5 * -math.sqrt((c * (-4.0 / a))) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3e-119) tmp = Float64(b / Float64(-a)); elseif (b <= 6.2e-40) tmp = Float64(-0.5 * Float64(-sqrt(Float64(c * Float64(-4.0 / a))))); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3e-119) tmp = b / -a; elseif (b <= 6.2e-40) tmp = -0.5 * -sqrt((c * (-4.0 / a))); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3e-119], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 6.2e-40], N[(-0.5 * (-N[Sqrt[N[(c * N[(-4.0 / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3 \cdot 10^{-119}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 6.2 \cdot 10^{-40}:\\
\;\;\;\;-0.5 \cdot \left(-\sqrt{c \cdot \frac{-4}{a}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -3.0000000000000002e-119Initial program 74.5%
*-commutative74.5%
Simplified74.5%
Taylor expanded in b around -inf 83.5%
associate-*r/83.5%
mul-1-neg83.5%
Simplified83.5%
if -3.0000000000000002e-119 < b < 6.20000000000000021e-40Initial program 80.0%
*-commutative80.0%
Simplified80.0%
add-cube-cbrt79.0%
pow379.0%
*-commutative79.0%
associate-*l*79.0%
Applied egg-rr79.0%
Taylor expanded in a around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt32.3%
rem-cube-cbrt32.6%
associate-/l*32.5%
Simplified32.5%
if 6.20000000000000021e-40 < b Initial program 17.3%
*-commutative17.3%
Simplified17.3%
Taylor expanded in b around inf 87.2%
associate-*r/87.2%
neg-mul-187.2%
Simplified87.2%
Final simplification72.5%
(FPCore (a b c) :precision binary64 (if (<= b 6.5e-301) (/ b (- a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 6.5e-301) {
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 <= 6.5d-301) 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 <= 6.5e-301) {
tmp = b / -a;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 6.5e-301: tmp = b / -a else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 6.5e-301) tmp = Float64(b / Float64(-a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 6.5e-301) tmp = b / -a; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 6.5e-301], N[(b / (-a)), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.5 \cdot 10^{-301}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < 6.49999999999999991e-301Initial program 77.2%
*-commutative77.2%
Simplified77.2%
Taylor expanded in b around -inf 67.9%
associate-*r/67.9%
mul-1-neg67.9%
Simplified67.9%
if 6.49999999999999991e-301 < b Initial program 32.7%
*-commutative32.7%
Simplified32.7%
Taylor expanded in b around inf 67.4%
associate-*r/67.4%
neg-mul-167.4%
Simplified67.4%
Final simplification67.6%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ b (- a)) 0.0))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-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 <= (-5d-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 <= -5e-310) {
tmp = b / -a;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = b / -a else: tmp = 0.0 return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(b / Float64(-a)); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = b / -a; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(b / (-a)), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 77.0%
*-commutative77.0%
Simplified77.0%
Taylor expanded in b around -inf 68.4%
associate-*r/68.4%
mul-1-neg68.4%
Simplified68.4%
if -4.999999999999985e-310 < b Initial program 33.2%
*-commutative33.2%
Simplified33.2%
add-cube-cbrt32.8%
pow332.8%
*-commutative32.8%
associate-*l*32.8%
Applied egg-rr32.8%
clear-num32.8%
inv-pow32.8%
neg-mul-132.8%
fma-define32.8%
pow232.8%
unpow332.8%
add-cube-cbrt33.1%
Applied egg-rr33.1%
unpow-133.1%
associate-/l*33.0%
Simplified33.0%
Taylor expanded in a around 0 17.6%
distribute-rgt1-in17.6%
metadata-eval17.6%
mul0-lft17.6%
div017.6%
metadata-eval17.6%
Simplified17.6%
Final simplification42.2%
(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 54.4%
*-commutative54.4%
Simplified54.4%
add-cube-cbrt54.1%
pow354.1%
*-commutative54.1%
associate-*l*54.1%
Applied egg-rr54.1%
clear-num54.0%
inv-pow54.0%
neg-mul-154.0%
fma-define54.0%
pow254.0%
unpow354.0%
add-cube-cbrt54.2%
Applied egg-rr54.2%
unpow-154.2%
associate-/l*54.1%
Simplified54.1%
Taylor expanded in a around 0 10.4%
distribute-rgt1-in10.4%
metadata-eval10.4%
mul0-lft10.4%
div010.4%
metadata-eval10.4%
Simplified10.4%
(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 2024136
(FPCore (a b c)
:name "quadp (p42, positive)"
:precision binary64
:herbie-expected 10
:alt
(! :herbie-platform default (let ((sqtD (let ((x (* (sqrt (fabs a)) (sqrt (fabs c))))) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2)) x)) (sqrt (+ (fabs (/ b 2)) x))) (hypot (/ b 2) x))))) (if (< b 0) (/ (- sqtD (/ b 2)) a) (/ (- c) (+ (/ b 2) sqtD)))))
(/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))