
(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 -7.2e+63)
(/ b (- a))
(if (<= b 1.52e-93)
(/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* a 2.0))
(if (<= b 9.6e+60)
(/
(/ (* a (* c (- 4.0))) (+ b (sqrt (fma b b (* (* a c) -4.0)))))
(* a 2.0))
(/ c (- b))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.2e+63) {
tmp = b / -a;
} else if (b <= 1.52e-93) {
tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
} else if (b <= 9.6e+60) {
tmp = ((a * (c * -4.0)) / (b + sqrt(fma(b, b, ((a * c) * -4.0))))) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -7.2e+63) tmp = Float64(b / Float64(-a)); elseif (b <= 1.52e-93) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) - b) / Float64(a * 2.0)); elseif (b <= 9.6e+60) tmp = Float64(Float64(Float64(a * Float64(c * Float64(-4.0))) / Float64(b + sqrt(fma(b, b, Float64(Float64(a * c) * -4.0))))) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -7.2e+63], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 1.52e-93], 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], If[LessEqual[b, 9.6e+60], N[(N[(N[(a * N[(c * (-4.0)), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(b * b + N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.2 \cdot 10^{+63}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 1.52 \cdot 10^{-93}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 9.6 \cdot 10^{+60}:\\
\;\;\;\;\frac{\frac{a \cdot \left(c \cdot \left(-4\right)\right)}{b + \sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)}}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -7.19999999999999998e63Initial program 64.8%
*-commutative64.8%
Simplified64.8%
Taylor expanded in b around -inf 96.7%
mul-1-neg96.7%
distribute-neg-frac296.7%
Simplified96.7%
if -7.19999999999999998e63 < b < 1.52e-93Initial program 82.2%
if 1.52e-93 < b < 9.6000000000000001e60Initial program 44.0%
*-commutative44.0%
Simplified44.0%
add-cube-cbrt43.8%
pow343.9%
*-commutative43.9%
associate-*l*43.9%
Applied egg-rr43.9%
flip-+43.7%
pow243.7%
pow243.7%
pow243.7%
add-sqr-sqrt43.6%
unpow343.6%
add-cube-cbrt43.7%
Applied egg-rr43.7%
associate--r-79.6%
unpow279.6%
sqr-neg79.6%
unpow279.6%
Simplified79.6%
div-inv79.5%
+-commutative79.5%
fma-define79.5%
+-inverses79.5%
Applied egg-rr79.5%
associate-*r/79.6%
*-rgt-identity79.6%
fma-undefine79.6%
+-rgt-identity79.6%
unpow279.6%
fma-neg79.6%
associate-*r*79.6%
*-commutative79.6%
distribute-lft-neg-in79.6%
metadata-eval79.6%
Simplified79.6%
if 9.6000000000000001e60 < b Initial program 9.3%
*-commutative9.3%
Simplified9.3%
Taylor expanded in b around inf 96.1%
associate-*r/96.1%
neg-mul-196.1%
Simplified96.1%
Final simplification89.2%
(FPCore (a b c)
:precision binary64
(if (<= b -7.2e+63)
(/ b (- a))
(if (<= b 3.1e-79)
(/ (- (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 <= -7.2e+63) {
tmp = b / -a;
} else if (b <= 3.1e-79) {
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 <= (-7.2d+63)) then
tmp = b / -a
else if (b <= 3.1d-79) 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 <= -7.2e+63) {
tmp = b / -a;
} else if (b <= 3.1e-79) {
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 <= -7.2e+63: tmp = b / -a elif b <= 3.1e-79: 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 <= -7.2e+63) tmp = Float64(b / Float64(-a)); elseif (b <= 3.1e-79) 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 <= -7.2e+63) tmp = b / -a; elseif (b <= 3.1e-79) 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, -7.2e+63], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 3.1e-79], 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 -7.2 \cdot 10^{+63}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 3.1 \cdot 10^{-79}:\\
\;\;\;\;\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 < -7.19999999999999998e63Initial program 64.8%
*-commutative64.8%
Simplified64.8%
Taylor expanded in b around -inf 96.7%
mul-1-neg96.7%
distribute-neg-frac296.7%
Simplified96.7%
if -7.19999999999999998e63 < b < 3.0999999999999999e-79Initial program 82.4%
if 3.0999999999999999e-79 < b Initial program 18.6%
*-commutative18.6%
Simplified18.6%
Taylor expanded in b around inf 86.4%
associate-*r/86.4%
neg-mul-186.4%
Simplified86.4%
Final simplification87.5%
(FPCore (a b c) :precision binary64 (if (<= b -3.3e-27) (/ b (- a)) (if (<= b 6e-87) (/ (- (sqrt (* (* a c) -4.0)) b) (* a 2.0)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.3e-27) {
tmp = b / -a;
} else if (b <= 6e-87) {
tmp = (sqrt(((a * c) * -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 <= (-3.3d-27)) then
tmp = b / -a
else if (b <= 6d-87) then
tmp = (sqrt(((a * c) * (-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 <= -3.3e-27) {
tmp = b / -a;
} else if (b <= 6e-87) {
tmp = (Math.sqrt(((a * c) * -4.0)) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.3e-27: tmp = b / -a elif b <= 6e-87: tmp = (math.sqrt(((a * c) * -4.0)) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.3e-27) tmp = Float64(b / Float64(-a)); elseif (b <= 6e-87) tmp = Float64(Float64(sqrt(Float64(Float64(a * c) * -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 <= -3.3e-27) tmp = b / -a; elseif (b <= 6e-87) tmp = (sqrt(((a * c) * -4.0)) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.3e-27], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 6e-87], N[(N[(N[Sqrt[N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.3 \cdot 10^{-27}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 6 \cdot 10^{-87}:\\
\;\;\;\;\frac{\sqrt{\left(a \cdot c\right) \cdot -4} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -3.29999999999999998e-27Initial program 72.8%
*-commutative72.8%
Simplified72.8%
Taylor expanded in b around -inf 95.4%
mul-1-neg95.4%
distribute-neg-frac295.4%
Simplified95.4%
if -3.29999999999999998e-27 < b < 6.00000000000000033e-87Initial program 78.0%
*-commutative78.0%
Simplified78.0%
add-sqr-sqrt77.7%
pow277.7%
pow1/277.7%
sqrt-pow177.8%
sub-neg77.8%
+-commutative77.8%
distribute-lft-neg-in77.8%
*-commutative77.8%
associate-*r*77.8%
fma-define77.8%
metadata-eval77.8%
pow277.8%
metadata-eval77.8%
Applied egg-rr77.8%
Taylor expanded in b around 0 68.5%
pow-pow68.6%
pow-to-exp64.2%
associate-*r*64.2%
metadata-eval64.2%
Applied egg-rr64.2%
+-commutative64.2%
*-un-lft-identity64.2%
fma-define64.2%
exp-to-pow68.6%
pow1/268.6%
*-commutative68.6%
*-commutative68.6%
Applied egg-rr68.6%
fma-undefine68.6%
*-lft-identity68.6%
unsub-neg68.6%
associate-*r*68.6%
*-commutative68.6%
metadata-eval68.6%
distribute-rgt-neg-in68.6%
*-commutative68.6%
distribute-lft-neg-in68.6%
metadata-eval68.6%
Simplified68.6%
if 6.00000000000000033e-87 < b Initial program 19.2%
*-commutative19.2%
Simplified19.2%
Taylor expanded in b around inf 86.0%
associate-*r/86.0%
neg-mul-186.0%
Simplified86.0%
Final simplification83.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1.55e-27)
(/ b (- a))
(if (<= b 3.1e-83)
(* (/ 0.5 a) (+ b (sqrt (* c (* a -4.0)))))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.55e-27) {
tmp = b / -a;
} else if (b <= 3.1e-83) {
tmp = (0.5 / a) * (b + sqrt((c * (a * -4.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.55d-27)) then
tmp = b / -a
else if (b <= 3.1d-83) then
tmp = (0.5d0 / a) * (b + sqrt((c * (a * (-4.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.55e-27) {
tmp = b / -a;
} else if (b <= 3.1e-83) {
tmp = (0.5 / a) * (b + Math.sqrt((c * (a * -4.0))));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.55e-27: tmp = b / -a elif b <= 3.1e-83: tmp = (0.5 / a) * (b + math.sqrt((c * (a * -4.0)))) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.55e-27) tmp = Float64(b / Float64(-a)); elseif (b <= 3.1e-83) tmp = Float64(Float64(0.5 / a) * Float64(b + sqrt(Float64(c * Float64(a * -4.0))))); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.55e-27) tmp = b / -a; elseif (b <= 3.1e-83) tmp = (0.5 / a) * (b + sqrt((c * (a * -4.0)))); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.55e-27], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 3.1e-83], N[(N[(0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.55 \cdot 10^{-27}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 3.1 \cdot 10^{-83}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.5499999999999999e-27Initial program 72.8%
*-commutative72.8%
Simplified72.8%
Taylor expanded in b around -inf 95.4%
mul-1-neg95.4%
distribute-neg-frac295.4%
Simplified95.4%
if -1.5499999999999999e-27 < b < 3.09999999999999992e-83Initial program 78.0%
*-commutative78.0%
Simplified78.0%
add-sqr-sqrt77.7%
pow277.7%
pow1/277.7%
sqrt-pow177.8%
sub-neg77.8%
+-commutative77.8%
distribute-lft-neg-in77.8%
*-commutative77.8%
associate-*r*77.8%
fma-define77.8%
metadata-eval77.8%
pow277.8%
metadata-eval77.8%
Applied egg-rr77.8%
Taylor expanded in b around 0 68.5%
*-un-lft-identity68.5%
*-un-lft-identity68.5%
*-commutative68.5%
times-frac68.5%
metadata-eval68.5%
add-sqr-sqrt42.5%
sqrt-unprod68.1%
sqr-neg68.1%
sqrt-prod25.7%
add-sqr-sqrt66.9%
pow-pow67.0%
metadata-eval67.0%
pow1/267.0%
associate-*r*67.0%
Applied egg-rr67.0%
*-lft-identity67.0%
metadata-eval67.0%
times-frac67.0%
*-commutative67.0%
associate-*r/67.0%
*-commutative67.0%
associate-/r*67.0%
metadata-eval67.0%
*-commutative67.0%
*-commutative67.0%
Simplified67.0%
if 3.09999999999999992e-83 < b Initial program 19.2%
*-commutative19.2%
Simplified19.2%
Taylor expanded in b around inf 86.0%
associate-*r/86.0%
neg-mul-186.0%
Simplified86.0%
Final simplification83.4%
(FPCore (a b c) :precision binary64 (if (<= b -7.2e-158) (/ b (- a)) (if (<= b 1.85e-82) (* (sqrt (* c (/ -4.0 a))) (- -0.5)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.2e-158) {
tmp = b / -a;
} else if (b <= 1.85e-82) {
tmp = sqrt((c * (-4.0 / a))) * -(-0.5);
} 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 <= (-7.2d-158)) then
tmp = b / -a
else if (b <= 1.85d-82) then
tmp = sqrt((c * ((-4.0d0) / a))) * -(-0.5d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -7.2e-158) {
tmp = b / -a;
} else if (b <= 1.85e-82) {
tmp = Math.sqrt((c * (-4.0 / a))) * -(-0.5);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.2e-158: tmp = b / -a elif b <= 1.85e-82: tmp = math.sqrt((c * (-4.0 / a))) * -(-0.5) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.2e-158) tmp = Float64(b / Float64(-a)); elseif (b <= 1.85e-82) tmp = Float64(sqrt(Float64(c * Float64(-4.0 / a))) * Float64(-(-0.5))); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7.2e-158) tmp = b / -a; elseif (b <= 1.85e-82) tmp = sqrt((c * (-4.0 / a))) * -(-0.5); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.2e-158], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 1.85e-82], N[(N[Sqrt[N[(c * N[(-4.0 / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (--0.5)), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.2 \cdot 10^{-158}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 1.85 \cdot 10^{-82}:\\
\;\;\;\;\sqrt{c \cdot \frac{-4}{a}} \cdot \left(--0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -7.19999999999999982e-158Initial program 76.7%
*-commutative76.7%
Simplified76.7%
Taylor expanded in b around -inf 79.5%
mul-1-neg79.5%
distribute-neg-frac279.5%
Simplified79.5%
if -7.19999999999999982e-158 < b < 1.85e-82Initial program 72.0%
*-commutative72.0%
Simplified72.0%
add-cube-cbrt71.4%
pow371.4%
*-commutative71.4%
associate-*l*71.4%
Applied egg-rr71.4%
Taylor expanded in a around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt43.4%
rem-cube-cbrt43.8%
associate-/l*43.8%
Simplified43.8%
if 1.85e-82 < b Initial program 19.2%
*-commutative19.2%
Simplified19.2%
Taylor expanded in b around inf 86.0%
associate-*r/86.0%
neg-mul-186.0%
Simplified86.0%
Final simplification75.1%
(FPCore (a b c) :precision binary64 (if (<= b 3.5e-302) (/ b (- a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 3.5e-302) {
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 <= 3.5d-302) 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 <= 3.5e-302) {
tmp = b / -a;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 3.5e-302: tmp = b / -a else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 3.5e-302) 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 <= 3.5e-302) tmp = b / -a; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 3.5e-302], N[(b / (-a)), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.5 \cdot 10^{-302}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < 3.5000000000000001e-302Initial program 76.5%
*-commutative76.5%
Simplified76.5%
Taylor expanded in b around -inf 68.1%
mul-1-neg68.1%
distribute-neg-frac268.1%
Simplified68.1%
if 3.5000000000000001e-302 < b Initial program 30.9%
*-commutative30.9%
Simplified30.9%
Taylor expanded in b around inf 68.8%
associate-*r/68.8%
neg-mul-168.8%
Simplified68.8%
Final simplification68.4%
(FPCore (a b c) :precision binary64 (if (<= b -2e-311) (/ b (- a)) (/ 0.0 a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-311) {
tmp = b / -a;
} else {
tmp = 0.0 / a;
}
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-311)) then
tmp = b / -a
else
tmp = 0.0d0 / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2e-311) {
tmp = b / -a;
} else {
tmp = 0.0 / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-311: tmp = b / -a else: tmp = 0.0 / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-311) tmp = Float64(b / Float64(-a)); else tmp = Float64(0.0 / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-311) tmp = b / -a; else tmp = 0.0 / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-311], N[(b / (-a)), $MachinePrecision], N[(0.0 / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-311}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a}\\
\end{array}
\end{array}
if b < -1.9999999999999e-311Initial program 77.1%
*-commutative77.1%
Simplified77.1%
Taylor expanded in b around -inf 68.6%
mul-1-neg68.6%
distribute-neg-frac268.6%
Simplified68.6%
if -1.9999999999999e-311 < b Initial program 30.7%
*-commutative30.7%
Simplified30.7%
add-cube-cbrt30.5%
pow330.5%
*-commutative30.5%
associate-*l*30.5%
Applied egg-rr30.5%
clear-num30.6%
inv-pow30.6%
neg-mul-130.6%
fma-define30.6%
pow230.6%
unpow330.6%
add-cube-cbrt30.7%
Applied egg-rr30.7%
unpow-130.7%
Simplified30.7%
Taylor expanded in a around 0 21.2%
associate-*r/21.2%
distribute-rgt1-in21.2%
metadata-eval21.2%
mul0-lft21.2%
metadata-eval21.2%
Simplified21.2%
(FPCore (a b c) :precision binary64 (/ 0.0 a))
double code(double a, double b, double c) {
return 0.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 = 0.0d0 / a
end function
public static double code(double a, double b, double c) {
return 0.0 / a;
}
def code(a, b, c): return 0.0 / a
function code(a, b, c) return Float64(0.0 / a) end
function tmp = code(a, b, c) tmp = 0.0 / a; end
code[a_, b_, c_] := N[(0.0 / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{0}{a}
\end{array}
Initial program 54.2%
*-commutative54.2%
Simplified54.2%
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%
Simplified54.2%
Taylor expanded in a around 0 11.8%
associate-*r/11.8%
distribute-rgt1-in11.8%
metadata-eval11.8%
mul0-lft11.8%
metadata-eval11.8%
Simplified11.8%
(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 2024121
(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)))