
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.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) - ((3.0d0 * a) * c)))) / (3.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.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) - ((3.0d0 * a) * c)))) / (3.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\end{array}
(FPCore (a b c) :precision binary64 (/ (/ (+ (- (pow b 2.0) (pow b 2.0)) (* c (* a (pow 27.0 0.3333333333333333)))) (- (- b) (sqrt (- (pow b 2.0) (* c (* a (cbrt 27.0))))))) (* a 3.0)))
double code(double a, double b, double c) {
return (((pow(b, 2.0) - pow(b, 2.0)) + (c * (a * pow(27.0, 0.3333333333333333)))) / (-b - sqrt((pow(b, 2.0) - (c * (a * cbrt(27.0))))))) / (a * 3.0);
}
public static double code(double a, double b, double c) {
return (((Math.pow(b, 2.0) - Math.pow(b, 2.0)) + (c * (a * Math.pow(27.0, 0.3333333333333333)))) / (-b - Math.sqrt((Math.pow(b, 2.0) - (c * (a * Math.cbrt(27.0))))))) / (a * 3.0);
}
function code(a, b, c) return Float64(Float64(Float64(Float64((b ^ 2.0) - (b ^ 2.0)) + Float64(c * Float64(a * (27.0 ^ 0.3333333333333333)))) / Float64(Float64(-b) - sqrt(Float64((b ^ 2.0) - Float64(c * Float64(a * cbrt(27.0))))))) / Float64(a * 3.0)) end
code[a_, b_, c_] := N[(N[(N[(N[(N[Power[b, 2.0], $MachinePrecision] - N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] + N[(c * N[(a * N[Power[27.0, 0.3333333333333333], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[Power[b, 2.0], $MachinePrecision] - N[(c * N[(a * N[Power[27.0, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\left({b}^{2} - {b}^{2}\right) + c \cdot \left(a \cdot {27}^{0.3333333333333333}\right)}{\left(-b\right) - \sqrt{{b}^{2} - c \cdot \left(a \cdot \sqrt[3]{27}\right)}}}{a \cdot 3}
\end{array}
Initial program 53.7%
add-cbrt-cube53.6%
pow1/353.5%
pow353.5%
associate-*l*53.6%
unpow-prod-down53.6%
metadata-eval53.6%
Applied egg-rr53.6%
unpow1/353.7%
cube-prod53.6%
*-commutative53.6%
cube-prod53.7%
Simplified53.7%
flip-+53.8%
pow253.8%
add-sqr-sqrt55.2%
pow255.2%
cbrt-prod55.2%
unpow355.2%
add-cbrt-cube55.2%
pow255.2%
cbrt-prod55.2%
Applied egg-rr55.2%
associate--r-98.6%
unpow298.6%
sqr-neg98.6%
unpow298.6%
*-commutative98.6%
associate-*l*98.6%
*-commutative98.6%
associate-*l*98.6%
Simplified98.6%
pow1/399.3%
Applied egg-rr99.3%
Final simplification99.3%
(FPCore (a b c) :precision binary64 (/ (/ (+ (- (pow b 2.0) (pow b 2.0)) (* c (* a (pow 27.0 0.3333333333333333)))) (- (- b) (sqrt (+ (pow b 2.0) (* -3.0 (* c a)))))) (* a 3.0)))
double code(double a, double b, double c) {
return (((pow(b, 2.0) - pow(b, 2.0)) + (c * (a * pow(27.0, 0.3333333333333333)))) / (-b - sqrt((pow(b, 2.0) + (-3.0 * (c * a)))))) / (a * 3.0);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = ((((b ** 2.0d0) - (b ** 2.0d0)) + (c * (a * (27.0d0 ** 0.3333333333333333d0)))) / (-b - sqrt(((b ** 2.0d0) + ((-3.0d0) * (c * a)))))) / (a * 3.0d0)
end function
public static double code(double a, double b, double c) {
return (((Math.pow(b, 2.0) - Math.pow(b, 2.0)) + (c * (a * Math.pow(27.0, 0.3333333333333333)))) / (-b - Math.sqrt((Math.pow(b, 2.0) + (-3.0 * (c * a)))))) / (a * 3.0);
}
def code(a, b, c): return (((math.pow(b, 2.0) - math.pow(b, 2.0)) + (c * (a * math.pow(27.0, 0.3333333333333333)))) / (-b - math.sqrt((math.pow(b, 2.0) + (-3.0 * (c * a)))))) / (a * 3.0)
function code(a, b, c) return Float64(Float64(Float64(Float64((b ^ 2.0) - (b ^ 2.0)) + Float64(c * Float64(a * (27.0 ^ 0.3333333333333333)))) / Float64(Float64(-b) - sqrt(Float64((b ^ 2.0) + Float64(-3.0 * Float64(c * a)))))) / Float64(a * 3.0)) end
function tmp = code(a, b, c) tmp = ((((b ^ 2.0) - (b ^ 2.0)) + (c * (a * (27.0 ^ 0.3333333333333333)))) / (-b - sqrt(((b ^ 2.0) + (-3.0 * (c * a)))))) / (a * 3.0); end
code[a_, b_, c_] := N[(N[(N[(N[(N[Power[b, 2.0], $MachinePrecision] - N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] + N[(c * N[(a * N[Power[27.0, 0.3333333333333333], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[Power[b, 2.0], $MachinePrecision] + N[(-3.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\left({b}^{2} - {b}^{2}\right) + c \cdot \left(a \cdot {27}^{0.3333333333333333}\right)}{\left(-b\right) - \sqrt{{b}^{2} + -3 \cdot \left(c \cdot a\right)}}}{a \cdot 3}
\end{array}
Initial program 53.7%
add-cbrt-cube53.6%
pow1/353.5%
pow353.5%
associate-*l*53.6%
unpow-prod-down53.6%
metadata-eval53.6%
Applied egg-rr53.6%
unpow1/353.7%
cube-prod53.6%
*-commutative53.6%
cube-prod53.7%
Simplified53.7%
flip-+53.8%
pow253.8%
add-sqr-sqrt55.2%
pow255.2%
cbrt-prod55.2%
unpow355.2%
add-cbrt-cube55.2%
pow255.2%
cbrt-prod55.2%
Applied egg-rr55.2%
associate--r-98.6%
unpow298.6%
sqr-neg98.6%
unpow298.6%
*-commutative98.6%
associate-*l*98.6%
*-commutative98.6%
associate-*l*98.6%
Simplified98.6%
pow1/399.3%
Applied egg-rr99.3%
Taylor expanded in b around 0 99.3%
Final simplification99.3%
(FPCore (a b c) :precision binary64 (let* ((t_0 (* c (* a (cbrt 27.0))))) (/ (/ 1.0 (/ (- (- b) (sqrt (- (pow b 2.0) t_0))) t_0)) (* a 3.0))))
double code(double a, double b, double c) {
double t_0 = c * (a * cbrt(27.0));
return (1.0 / ((-b - sqrt((pow(b, 2.0) - t_0))) / t_0)) / (a * 3.0);
}
public static double code(double a, double b, double c) {
double t_0 = c * (a * Math.cbrt(27.0));
return (1.0 / ((-b - Math.sqrt((Math.pow(b, 2.0) - t_0))) / t_0)) / (a * 3.0);
}
function code(a, b, c) t_0 = Float64(c * Float64(a * cbrt(27.0))) return Float64(Float64(1.0 / Float64(Float64(Float64(-b) - sqrt(Float64((b ^ 2.0) - t_0))) / t_0)) / Float64(a * 3.0)) end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * N[Power[27.0, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(1.0 / N[(N[((-b) - N[Sqrt[N[(N[Power[b, 2.0], $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(a \cdot \sqrt[3]{27}\right)\\
\frac{\frac{1}{\frac{\left(-b\right) - \sqrt{{b}^{2} - t_0}}{t_0}}}{a \cdot 3}
\end{array}
\end{array}
Initial program 53.7%
add-cbrt-cube53.6%
pow1/353.5%
pow353.5%
associate-*l*53.6%
unpow-prod-down53.6%
metadata-eval53.6%
Applied egg-rr53.6%
unpow1/353.7%
cube-prod53.6%
*-commutative53.6%
cube-prod53.7%
Simplified53.7%
flip-+53.8%
pow253.8%
add-sqr-sqrt55.2%
pow255.2%
cbrt-prod55.2%
unpow355.2%
add-cbrt-cube55.2%
pow255.2%
cbrt-prod55.2%
Applied egg-rr55.2%
associate--r-98.6%
unpow298.6%
sqr-neg98.6%
unpow298.6%
*-commutative98.6%
associate-*l*98.6%
*-commutative98.6%
associate-*l*98.6%
Simplified98.6%
pow1/399.3%
Applied egg-rr99.3%
clear-num99.3%
inv-pow99.3%
+-commutative99.3%
pow1/398.7%
fma-def98.7%
+-inverses98.7%
Applied egg-rr98.7%
unpow-198.7%
fma-udef98.7%
+-rgt-identity98.7%
Simplified98.7%
Final simplification98.7%
(FPCore (a b c) :precision binary64 (let* ((t_0 (* c (* a (cbrt 27.0))))) (/ (/ t_0 (* a 3.0)) (- (- b) (sqrt (- (pow b 2.0) t_0))))))
double code(double a, double b, double c) {
double t_0 = c * (a * cbrt(27.0));
return (t_0 / (a * 3.0)) / (-b - sqrt((pow(b, 2.0) - t_0)));
}
public static double code(double a, double b, double c) {
double t_0 = c * (a * Math.cbrt(27.0));
return (t_0 / (a * 3.0)) / (-b - Math.sqrt((Math.pow(b, 2.0) - t_0)));
}
function code(a, b, c) t_0 = Float64(c * Float64(a * cbrt(27.0))) return Float64(Float64(t_0 / Float64(a * 3.0)) / Float64(Float64(-b) - sqrt(Float64((b ^ 2.0) - t_0)))) end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * N[Power[27.0, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(t$95$0 / N[(a * 3.0), $MachinePrecision]), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[Power[b, 2.0], $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(a \cdot \sqrt[3]{27}\right)\\
\frac{\frac{t_0}{a \cdot 3}}{\left(-b\right) - \sqrt{{b}^{2} - t_0}}
\end{array}
\end{array}
Initial program 53.7%
add-cbrt-cube53.6%
pow1/353.5%
pow353.5%
associate-*l*53.6%
unpow-prod-down53.6%
metadata-eval53.6%
Applied egg-rr53.6%
unpow1/353.7%
cube-prod53.6%
*-commutative53.6%
cube-prod53.7%
Simplified53.7%
flip-+53.8%
pow253.8%
add-sqr-sqrt55.2%
pow255.2%
cbrt-prod55.2%
unpow355.2%
add-cbrt-cube55.2%
pow255.2%
cbrt-prod55.2%
Applied egg-rr55.2%
associate--r-98.6%
unpow298.6%
sqr-neg98.6%
unpow298.6%
*-commutative98.6%
associate-*l*98.6%
*-commutative98.6%
associate-*l*98.6%
Simplified98.6%
pow1/399.3%
Applied egg-rr99.3%
expm1-log1p-u86.9%
expm1-udef62.3%
Applied egg-rr62.3%
expm1-def86.3%
expm1-log1p98.6%
associate-/r*98.6%
fma-udef98.6%
+-rgt-identity98.6%
Simplified98.6%
Final simplification98.6%
(FPCore (a b c) :precision binary64 (let* ((t_0 (* c (* a (cbrt 27.0))))) (/ (/ t_0 (- (- b) (sqrt (- (pow b 2.0) t_0)))) (* a 3.0))))
double code(double a, double b, double c) {
double t_0 = c * (a * cbrt(27.0));
return (t_0 / (-b - sqrt((pow(b, 2.0) - t_0)))) / (a * 3.0);
}
public static double code(double a, double b, double c) {
double t_0 = c * (a * Math.cbrt(27.0));
return (t_0 / (-b - Math.sqrt((Math.pow(b, 2.0) - t_0)))) / (a * 3.0);
}
function code(a, b, c) t_0 = Float64(c * Float64(a * cbrt(27.0))) return Float64(Float64(t_0 / Float64(Float64(-b) - sqrt(Float64((b ^ 2.0) - t_0)))) / Float64(a * 3.0)) end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * N[Power[27.0, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(t$95$0 / N[((-b) - N[Sqrt[N[(N[Power[b, 2.0], $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(a \cdot \sqrt[3]{27}\right)\\
\frac{\frac{t_0}{\left(-b\right) - \sqrt{{b}^{2} - t_0}}}{a \cdot 3}
\end{array}
\end{array}
Initial program 53.7%
add-cbrt-cube53.6%
pow1/353.5%
pow353.5%
associate-*l*53.6%
unpow-prod-down53.6%
metadata-eval53.6%
Applied egg-rr53.6%
unpow1/353.7%
cube-prod53.6%
*-commutative53.6%
cube-prod53.7%
Simplified53.7%
flip-+53.8%
pow253.8%
add-sqr-sqrt55.2%
pow255.2%
cbrt-prod55.2%
unpow355.2%
add-cbrt-cube55.2%
pow255.2%
cbrt-prod55.2%
Applied egg-rr55.2%
associate--r-98.6%
unpow298.6%
sqr-neg98.6%
unpow298.6%
*-commutative98.6%
associate-*l*98.6%
*-commutative98.6%
associate-*l*98.6%
Simplified98.6%
pow1/399.3%
Applied egg-rr99.3%
expm1-log1p-u88.5%
expm1-udef58.3%
+-commutative58.3%
pow1/358.3%
fma-def58.3%
+-inverses58.3%
Applied egg-rr58.3%
expm1-def87.9%
expm1-log1p98.6%
fma-udef98.6%
+-rgt-identity98.6%
Simplified98.6%
Final simplification98.6%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0)) -5.5e-7) (/ (- (sqrt (fma b b (* a (* c -3.0)))) b) (* a 3.0)) (/ (* c -0.5) b)))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -5.5e-7) {
tmp = (sqrt(fma(b, b, (a * (c * -3.0)))) - b) / (a * 3.0);
} else {
tmp = (c * -0.5) / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))) - b) / Float64(a * 3.0)) <= -5.5e-7) tmp = Float64(Float64(sqrt(fma(b, b, Float64(a * Float64(c * -3.0)))) - b) / Float64(a * 3.0)); else tmp = Float64(Float64(c * -0.5) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], -5.5e-7], N[(N[(N[Sqrt[N[(b * b + N[(a * N[(c * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -5.5 \cdot 10^{-7}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -5.5000000000000003e-7Initial program 71.8%
+-commutative71.8%
sqr-neg71.8%
unsub-neg71.8%
div-sub71.1%
--rgt-identity71.1%
div-sub71.8%
Simplified71.9%
if -5.5000000000000003e-7 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) Initial program 27.1%
Taylor expanded in b around inf 86.8%
*-commutative86.8%
associate-*l/86.8%
Simplified86.8%
Final simplification78.0%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0)) -5.5e-7) (/ (- (sqrt (- (* b b) (* a (* c 3.0)))) b) (* a 3.0)) (/ (* c -0.5) b)))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -5.5e-7) {
tmp = (sqrt(((b * b) - (a * (c * 3.0)))) - b) / (a * 3.0);
} else {
tmp = (c * -0.5) / 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 (((sqrt(((b * b) - (c * (a * 3.0d0)))) - b) / (a * 3.0d0)) <= (-5.5d-7)) then
tmp = (sqrt(((b * b) - (a * (c * 3.0d0)))) - b) / (a * 3.0d0)
else
tmp = (c * (-0.5d0)) / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (((Math.sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -5.5e-7) {
tmp = (Math.sqrt(((b * b) - (a * (c * 3.0)))) - b) / (a * 3.0);
} else {
tmp = (c * -0.5) / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if ((math.sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -5.5e-7: tmp = (math.sqrt(((b * b) - (a * (c * 3.0)))) - b) / (a * 3.0) else: tmp = (c * -0.5) / b return tmp
function code(a, b, c) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))) - b) / Float64(a * 3.0)) <= -5.5e-7) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 3.0)))) - b) / Float64(a * 3.0)); else tmp = Float64(Float64(c * -0.5) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (((sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -5.5e-7) tmp = (sqrt(((b * b) - (a * (c * 3.0)))) - b) / (a * 3.0); else tmp = (c * -0.5) / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], -5.5e-7], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -5.5 \cdot 10^{-7}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - a \cdot \left(c \cdot 3\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -5.5000000000000003e-7Initial program 71.8%
add-cbrt-cube71.8%
pow1/371.6%
pow371.6%
associate-*l*71.7%
unpow-prod-down71.7%
metadata-eval71.7%
Applied egg-rr71.7%
unpow1/371.8%
cube-prod71.8%
*-commutative71.8%
cube-prod71.8%
Simplified71.8%
Taylor expanded in a around 0 71.8%
associate-*r*71.8%
*-commutative71.8%
associate-*l*71.8%
Simplified71.8%
if -5.5000000000000003e-7 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) Initial program 27.1%
Taylor expanded in b around inf 86.8%
*-commutative86.8%
associate-*l/86.8%
Simplified86.8%
Final simplification77.9%
(FPCore (a b c) :precision binary64 (if (<= b 6.4) (/ (- (sqrt (fma b b (* a (* c -3.0)))) b) (* a 3.0)) (+ (* -0.5 (/ c b)) (* -0.375 (/ (* a (pow c 2.0)) (pow b 3.0))))))
double code(double a, double b, double c) {
double tmp;
if (b <= 6.4) {
tmp = (sqrt(fma(b, b, (a * (c * -3.0)))) - b) / (a * 3.0);
} else {
tmp = (-0.5 * (c / b)) + (-0.375 * ((a * pow(c, 2.0)) / pow(b, 3.0)));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 6.4) tmp = Float64(Float64(sqrt(fma(b, b, Float64(a * Float64(c * -3.0)))) - b) / Float64(a * 3.0)); else tmp = Float64(Float64(-0.5 * Float64(c / b)) + Float64(-0.375 * Float64(Float64(a * (c ^ 2.0)) / (b ^ 3.0)))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 6.4], N[(N[(N[Sqrt[N[(b * b + N[(a * N[(c * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(-0.375 * N[(N[(a * N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.4:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}}\\
\end{array}
\end{array}
if b < 6.4000000000000004Initial program 81.7%
+-commutative81.7%
sqr-neg81.7%
unsub-neg81.7%
div-sub81.0%
--rgt-identity81.0%
div-sub81.7%
Simplified81.7%
if 6.4000000000000004 < b Initial program 43.9%
Taylor expanded in b around inf 88.0%
Final simplification86.4%
(FPCore (a b c) :precision binary64 (/ (* c -0.5) b))
double code(double a, double b, double c) {
return (c * -0.5) / b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (c * (-0.5d0)) / b
end function
public static double code(double a, double b, double c) {
return (c * -0.5) / b;
}
def code(a, b, c): return (c * -0.5) / b
function code(a, b, c) return Float64(Float64(c * -0.5) / b) end
function tmp = code(a, b, c) tmp = (c * -0.5) / b; end
code[a_, b_, c_] := N[(N[(c * -0.5), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c \cdot -0.5}{b}
\end{array}
Initial program 53.7%
Taylor expanded in b around inf 65.4%
*-commutative65.4%
associate-*l/65.4%
Simplified65.4%
Final simplification65.4%
(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 53.7%
add-cbrt-cube53.6%
pow1/353.5%
pow353.5%
associate-*l*53.6%
unpow-prod-down53.6%
metadata-eval53.6%
Applied egg-rr53.6%
unpow1/353.7%
cube-prod53.6%
*-commutative53.6%
cube-prod53.7%
Simplified53.7%
clear-num53.7%
inv-pow53.7%
*-commutative53.7%
neg-mul-153.7%
fma-def53.7%
pow253.7%
cbrt-prod53.6%
unpow353.6%
add-cbrt-cube53.6%
Applied egg-rr53.6%
unpow-153.6%
associate-/l*53.7%
fma-udef53.7%
*-commutative53.7%
fma-def53.7%
*-commutative53.7%
associate-*l*53.7%
Simplified53.7%
Taylor expanded in a around 0 3.2%
associate-*r/3.2%
distribute-rgt1-in3.2%
metadata-eval3.2%
mul0-lft3.2%
metadata-eval3.2%
Simplified3.2%
Final simplification3.2%
herbie shell --seed 2023322
(FPCore (a b c)
:name "Cubic critical, narrow range"
:precision binary64
:pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))