
(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
(let* ((t_0 (* c (* a 3.0))))
(/
(/ (- (- (pow b 2.0) (pow b 2.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 * 3.0);
return (((pow(b, 2.0) - pow(b, 2.0)) - t_0) / (b + sqrt((pow(b, 2.0) - t_0)))) / (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
real(8) :: t_0
t_0 = c * (a * 3.0d0)
code = ((((b ** 2.0d0) - (b ** 2.0d0)) - t_0) / (b + sqrt(((b ** 2.0d0) - t_0)))) / (a * 3.0d0)
end function
public static double code(double a, double b, double c) {
double t_0 = c * (a * 3.0);
return (((Math.pow(b, 2.0) - Math.pow(b, 2.0)) - t_0) / (b + Math.sqrt((Math.pow(b, 2.0) - t_0)))) / (a * 3.0);
}
def code(a, b, c): t_0 = c * (a * 3.0) return (((math.pow(b, 2.0) - math.pow(b, 2.0)) - 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 * 3.0)) return Float64(Float64(Float64(Float64((b ^ 2.0) - (b ^ 2.0)) - t_0) / Float64(b + sqrt(Float64((b ^ 2.0) - t_0)))) / Float64(a * 3.0)) end
function tmp = code(a, b, c) t_0 = c * (a * 3.0); tmp = ((((b ^ 2.0) - (b ^ 2.0)) - t_0) / (b + sqrt(((b ^ 2.0) - t_0)))) / (a * 3.0); end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[(N[Power[b, 2.0], $MachinePrecision] - N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision] / 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 3\right)\\
\frac{\frac{\left({b}^{2} - {b}^{2}\right) - t\_0}{b + \sqrt{{b}^{2} - t\_0}}}{a \cdot 3}
\end{array}
\end{array}
Initial program 53.4%
add-cbrt-cube52.6%
pow1/350.4%
pow350.4%
pow250.4%
pow-pow50.4%
metadata-eval50.4%
Applied egg-rr50.4%
unpow1/352.7%
Simplified52.7%
flip-+52.5%
pow252.5%
add-sqr-sqrt53.0%
pow1/350.4%
pow-pow54.7%
metadata-eval54.7%
*-commutative54.7%
*-commutative54.7%
pow1/354.7%
pow-pow54.7%
metadata-eval54.7%
*-commutative54.7%
*-commutative54.7%
Applied egg-rr54.7%
pow254.7%
associate--r-99.4%
neg-mul-199.4%
metadata-eval99.4%
unpow-prod-down99.4%
metadata-eval99.4%
metadata-eval99.4%
*-un-lft-identity99.4%
pow299.4%
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (a b c) :precision binary64 (/ (/ (* 3.0 (* c a)) (+ b (sqrt (- (pow b 2.0) (* c (* a 3.0)))))) (* a (- 3.0))))
double code(double a, double b, double c) {
return ((3.0 * (c * a)) / (b + sqrt((pow(b, 2.0) - (c * (a * 3.0)))))) / (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 = ((3.0d0 * (c * a)) / (b + sqrt(((b ** 2.0d0) - (c * (a * 3.0d0)))))) / (a * -3.0d0)
end function
public static double code(double a, double b, double c) {
return ((3.0 * (c * a)) / (b + Math.sqrt((Math.pow(b, 2.0) - (c * (a * 3.0)))))) / (a * -3.0);
}
def code(a, b, c): return ((3.0 * (c * a)) / (b + math.sqrt((math.pow(b, 2.0) - (c * (a * 3.0)))))) / (a * -3.0)
function code(a, b, c) return Float64(Float64(Float64(3.0 * Float64(c * a)) / Float64(b + sqrt(Float64((b ^ 2.0) - Float64(c * Float64(a * 3.0)))))) / Float64(a * Float64(-3.0))) end
function tmp = code(a, b, c) tmp = ((3.0 * (c * a)) / (b + sqrt(((b ^ 2.0) - (c * (a * 3.0)))))) / (a * -3.0); end
code[a_, b_, c_] := N[(N[(N[(3.0 * N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(N[Power[b, 2.0], $MachinePrecision] - N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * (-3.0)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{3 \cdot \left(c \cdot a\right)}{b + \sqrt{{b}^{2} - c \cdot \left(a \cdot 3\right)}}}{a \cdot \left(-3\right)}
\end{array}
Initial program 53.4%
add-cbrt-cube52.6%
pow1/350.4%
pow350.4%
pow250.4%
pow-pow50.4%
metadata-eval50.4%
Applied egg-rr50.4%
unpow1/352.7%
Simplified52.7%
flip-+52.5%
pow252.5%
add-sqr-sqrt53.0%
pow1/350.4%
pow-pow54.7%
metadata-eval54.7%
*-commutative54.7%
*-commutative54.7%
pow1/354.7%
pow-pow54.7%
metadata-eval54.7%
*-commutative54.7%
*-commutative54.7%
Applied egg-rr54.7%
Taylor expanded in b around 0 99.2%
Final simplification99.2%
(FPCore (a b c) :precision binary64 (if (<= b 0.7) (* (- b (sqrt (fma b b (* c (* a -3.0))))) (/ 1.0 (* a -3.0))) (/ (fma -0.375 (* a (pow (/ c b) 2.0)) (* c -0.5)) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 0.7) {
tmp = (b - sqrt(fma(b, b, (c * (a * -3.0))))) * (1.0 / (a * -3.0));
} else {
tmp = fma(-0.375, (a * pow((c / b), 2.0)), (c * -0.5)) / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 0.7) tmp = Float64(Float64(b - sqrt(fma(b, b, Float64(c * Float64(a * -3.0))))) * Float64(1.0 / Float64(a * -3.0))); else tmp = Float64(fma(-0.375, Float64(a * (Float64(c / b) ^ 2.0)), Float64(c * -0.5)) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 0.7], N[(N[(b - N[Sqrt[N[(b * b + N[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(a * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-0.375 * N[(a * N[Power[N[(c / b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[(c * -0.5), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.7:\\
\;\;\;\;\left(b - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}\right) \cdot \frac{1}{a \cdot -3}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-0.375, a \cdot {\left(\frac{c}{b}\right)}^{2}, c \cdot -0.5\right)}{b}\\
\end{array}
\end{array}
if b < 0.69999999999999996Initial program 84.4%
add-cbrt-cube84.3%
pow1/384.3%
pow384.3%
Applied egg-rr84.3%
pow-pow84.4%
metadata-eval84.4%
pow184.4%
log1p-expm1-u81.6%
log1p-undefine73.6%
*-commutative73.6%
Applied egg-rr73.6%
log1p-define81.6%
log1p-expm1-u84.4%
frac-2neg84.4%
div-inv84.5%
Applied egg-rr84.4%
if 0.69999999999999996 < b Initial program 48.8%
add-cbrt-cube48.8%
pow1/348.7%
pow348.7%
Applied egg-rr48.7%
Taylor expanded in b around inf 87.4%
+-commutative87.4%
fma-define87.4%
associate-/l*87.4%
unpow287.4%
unpow287.4%
times-frac87.4%
unpow187.4%
pow-plus87.4%
metadata-eval87.4%
*-commutative87.4%
Simplified87.4%
(FPCore (a b c) :precision binary64 (if (<= b 0.72) (/ (- (sqrt (fma b b (* a (* c -3.0)))) b) (* a 3.0)) (/ (fma -0.375 (* a (pow (/ c b) 2.0)) (* c -0.5)) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 0.72) {
tmp = (sqrt(fma(b, b, (a * (c * -3.0)))) - b) / (a * 3.0);
} else {
tmp = fma(-0.375, (a * pow((c / b), 2.0)), (c * -0.5)) / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 0.72) tmp = Float64(Float64(sqrt(fma(b, b, Float64(a * Float64(c * -3.0)))) - b) / Float64(a * 3.0)); else tmp = Float64(fma(-0.375, Float64(a * (Float64(c / b) ^ 2.0)), Float64(c * -0.5)) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 0.72], 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.375 * N[(a * N[Power[N[(c / b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[(c * -0.5), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.72:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-0.375, a \cdot {\left(\frac{c}{b}\right)}^{2}, c \cdot -0.5\right)}{b}\\
\end{array}
\end{array}
if b < 0.71999999999999997Initial program 84.4%
Simplified84.4%
if 0.71999999999999997 < b Initial program 48.8%
add-cbrt-cube48.8%
pow1/348.7%
pow348.7%
Applied egg-rr48.7%
Taylor expanded in b around inf 87.4%
+-commutative87.4%
fma-define87.4%
associate-/l*87.4%
unpow287.4%
unpow287.4%
times-frac87.4%
unpow187.4%
pow-plus87.4%
metadata-eval87.4%
*-commutative87.4%
Simplified87.4%
Final simplification87.0%
(FPCore (a b c) :precision binary64 (if (<= b 0.72) (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0)) (/ (fma -0.375 (* a (pow (/ c b) 2.0)) (* c -0.5)) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 0.72) {
tmp = (sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0);
} else {
tmp = fma(-0.375, (a * pow((c / b), 2.0)), (c * -0.5)) / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 0.72) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))) - b) / Float64(a * 3.0)); else tmp = Float64(fma(-0.375, Float64(a * (Float64(c / b) ^ 2.0)), Float64(c * -0.5)) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 0.72], 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], N[(N[(-0.375 * N[(a * N[Power[N[(c / b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[(c * -0.5), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.72:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-0.375, a \cdot {\left(\frac{c}{b}\right)}^{2}, c \cdot -0.5\right)}{b}\\
\end{array}
\end{array}
if b < 0.71999999999999997Initial program 84.4%
if 0.71999999999999997 < b Initial program 48.8%
add-cbrt-cube48.8%
pow1/348.7%
pow348.7%
Applied egg-rr48.7%
Taylor expanded in b around inf 87.4%
+-commutative87.4%
fma-define87.4%
associate-/l*87.4%
unpow287.4%
unpow287.4%
times-frac87.4%
unpow187.4%
pow-plus87.4%
metadata-eval87.4%
*-commutative87.4%
Simplified87.4%
Final simplification87.0%
(FPCore (a b c) :precision binary64 (if (<= b 0.72) (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0)) (* c (- (* -0.375 (* a (/ c (pow b 3.0)))) (/ 0.5 b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= 0.72) {
tmp = (sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0);
} else {
tmp = c * ((-0.375 * (a * (c / pow(b, 3.0)))) - (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 (b <= 0.72d0) then
tmp = (sqrt(((b * b) - (c * (a * 3.0d0)))) - b) / (a * 3.0d0)
else
tmp = c * (((-0.375d0) * (a * (c / (b ** 3.0d0)))) - (0.5d0 / b))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 0.72) {
tmp = (Math.sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0);
} else {
tmp = c * ((-0.375 * (a * (c / Math.pow(b, 3.0)))) - (0.5 / b));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 0.72: tmp = (math.sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0) else: tmp = c * ((-0.375 * (a * (c / math.pow(b, 3.0)))) - (0.5 / b)) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 0.72) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))) - b) / Float64(a * 3.0)); else tmp = Float64(c * Float64(Float64(-0.375 * Float64(a * Float64(c / (b ^ 3.0)))) - Float64(0.5 / b))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 0.72) tmp = (sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0); else tmp = c * ((-0.375 * (a * (c / (b ^ 3.0)))) - (0.5 / b)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 0.72], 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], N[(c * N[(N[(-0.375 * N[(a * N[(c / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(0.5 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.72:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;c \cdot \left(-0.375 \cdot \left(a \cdot \frac{c}{{b}^{3}}\right) - \frac{0.5}{b}\right)\\
\end{array}
\end{array}
if b < 0.71999999999999997Initial program 84.4%
if 0.71999999999999997 < b Initial program 48.8%
Simplified48.9%
Taylor expanded in c around 0 87.3%
associate-/l*87.3%
associate-*r/87.3%
metadata-eval87.3%
Simplified87.3%
Final simplification86.9%
(FPCore (a b c) :precision binary64 (if (<= b 0.72) (/ (- (sqrt (- (* b b) (* 3.0 (* c a)))) b) (* a 3.0)) (* c (- (* -0.375 (* a (/ c (pow b 3.0)))) (/ 0.5 b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= 0.72) {
tmp = (sqrt(((b * b) - (3.0 * (c * a)))) - b) / (a * 3.0);
} else {
tmp = c * ((-0.375 * (a * (c / pow(b, 3.0)))) - (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 (b <= 0.72d0) then
tmp = (sqrt(((b * b) - (3.0d0 * (c * a)))) - b) / (a * 3.0d0)
else
tmp = c * (((-0.375d0) * (a * (c / (b ** 3.0d0)))) - (0.5d0 / b))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 0.72) {
tmp = (Math.sqrt(((b * b) - (3.0 * (c * a)))) - b) / (a * 3.0);
} else {
tmp = c * ((-0.375 * (a * (c / Math.pow(b, 3.0)))) - (0.5 / b));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 0.72: tmp = (math.sqrt(((b * b) - (3.0 * (c * a)))) - b) / (a * 3.0) else: tmp = c * ((-0.375 * (a * (c / math.pow(b, 3.0)))) - (0.5 / b)) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 0.72) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(3.0 * Float64(c * a)))) - b) / Float64(a * 3.0)); else tmp = Float64(c * Float64(Float64(-0.375 * Float64(a * Float64(c / (b ^ 3.0)))) - Float64(0.5 / b))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 0.72) tmp = (sqrt(((b * b) - (3.0 * (c * a)))) - b) / (a * 3.0); else tmp = c * ((-0.375 * (a * (c / (b ^ 3.0)))) - (0.5 / b)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 0.72], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(3.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(c * N[(N[(-0.375 * N[(a * N[(c / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(0.5 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.72:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 3 \cdot \left(c \cdot a\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;c \cdot \left(-0.375 \cdot \left(a \cdot \frac{c}{{b}^{3}}\right) - \frac{0.5}{b}\right)\\
\end{array}
\end{array}
if b < 0.71999999999999997Initial program 84.4%
sqr-neg84.4%
sqr-neg84.4%
associate-*l*84.3%
Simplified84.3%
if 0.71999999999999997 < b Initial program 48.8%
Simplified48.9%
Taylor expanded in c around 0 87.3%
associate-/l*87.3%
associate-*r/87.3%
metadata-eval87.3%
Simplified87.3%
Final simplification86.9%
(FPCore (a b c) :precision binary64 (* c (- (* -0.375 (* a (/ c (pow b 3.0)))) (/ 0.5 b))))
double code(double a, double b, double c) {
return c * ((-0.375 * (a * (c / pow(b, 3.0)))) - (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.375d0) * (a * (c / (b ** 3.0d0)))) - (0.5d0 / b))
end function
public static double code(double a, double b, double c) {
return c * ((-0.375 * (a * (c / Math.pow(b, 3.0)))) - (0.5 / b));
}
def code(a, b, c): return c * ((-0.375 * (a * (c / math.pow(b, 3.0)))) - (0.5 / b))
function code(a, b, c) return Float64(c * Float64(Float64(-0.375 * Float64(a * Float64(c / (b ^ 3.0)))) - Float64(0.5 / b))) end
function tmp = code(a, b, c) tmp = c * ((-0.375 * (a * (c / (b ^ 3.0)))) - (0.5 / b)); end
code[a_, b_, c_] := N[(c * N[(N[(-0.375 * N[(a * N[(c / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(0.5 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
c \cdot \left(-0.375 \cdot \left(a \cdot \frac{c}{{b}^{3}}\right) - \frac{0.5}{b}\right)
\end{array}
Initial program 53.4%
Simplified53.4%
Taylor expanded in c around 0 83.6%
associate-/l*83.6%
associate-*r/83.6%
metadata-eval83.6%
Simplified83.6%
(FPCore (a b c) :precision binary64 (* (/ c b) -0.5))
double code(double a, double b, double c) {
return (c / b) * -0.5;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (c / b) * (-0.5d0)
end function
public static double code(double a, double b, double c) {
return (c / b) * -0.5;
}
def code(a, b, c): return (c / b) * -0.5
function code(a, b, c) return Float64(Float64(c / b) * -0.5) end
function tmp = code(a, b, c) tmp = (c / b) * -0.5; end
code[a_, b_, c_] := N[(N[(c / b), $MachinePrecision] * -0.5), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{b} \cdot -0.5
\end{array}
Initial program 53.4%
Simplified53.4%
Taylor expanded in b around inf 66.6%
Final simplification66.6%
(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 53.4%
add-cbrt-cube53.4%
pow1/353.3%
pow353.3%
Applied egg-rr53.3%
pow253.3%
metadata-eval53.3%
pow-pow50.4%
pow1/352.7%
pow-pow52.7%
metadata-eval52.7%
pow152.7%
add-log-exp48.2%
Applied egg-rr48.6%
Taylor expanded in c around 0 3.2%
associate-*r/3.2%
distribute-rgt1-in3.2%
metadata-eval3.2%
mul0-lft3.2%
metadata-eval3.2%
Simplified3.2%
Taylor expanded in a around 0 3.2%
herbie shell --seed 2024151
(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)))