
(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 9 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 (fma b b (* -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(fma(b, b, (-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(fma(b, b, Float64(-3.0 * Float64(c * a)))))) / 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[(b * b + 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{\mathsf{fma}\left(b, b, -3 \cdot \left(c \cdot a\right)\right)}}}{a \cdot 3}
\end{array}
Initial program 56.1%
add-cbrt-cube56.0%
pow1/355.9%
pow355.9%
associate-*l*55.9%
unpow-prod-down55.9%
metadata-eval55.9%
Applied egg-rr55.9%
flip-+56.0%
pow255.9%
add-sqr-sqrt57.2%
pow257.2%
unpow1/357.4%
*-commutative57.4%
cbrt-prod57.4%
unpow357.4%
add-cbrt-cube57.4%
Applied egg-rr57.4%
associate--r-98.5%
unpow298.4%
sqr-neg98.4%
unpow298.5%
*-commutative98.5%
associate-*l*98.6%
*-commutative98.6%
associate-*l*98.6%
Simplified98.6%
pow1/399.4%
Applied egg-rr99.4%
associate-*r*99.4%
*-commutative99.4%
add-cbrt-cube99.4%
cbrt-unprod99.3%
pow399.3%
metadata-eval99.3%
unpow-prod-down99.3%
*-commutative99.3%
pow399.4%
add-cbrt-cube99.4%
cancel-sign-sub-inv99.4%
pow299.4%
fma-def99.4%
metadata-eval99.4%
*-commutative99.4%
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (a b c) :precision binary64 (/ (/ 1.0 (/ (- (- b) (sqrt (fma -3.0 (* c a) (pow b 2.0)))) (* a (* c 3.0)))) (* a 3.0)))
double code(double a, double b, double c) {
return (1.0 / ((-b - sqrt(fma(-3.0, (c * a), pow(b, 2.0)))) / (a * (c * 3.0)))) / (a * 3.0);
}
function code(a, b, c) return Float64(Float64(1.0 / Float64(Float64(Float64(-b) - sqrt(fma(-3.0, Float64(c * a), (b ^ 2.0)))) / Float64(a * Float64(c * 3.0)))) / Float64(a * 3.0)) end
code[a_, b_, c_] := N[(N[(1.0 / N[(N[((-b) - N[Sqrt[N[(-3.0 * N[(c * a), $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * N[(c * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(-3, c \cdot a, {b}^{2}\right)}}{a \cdot \left(c \cdot 3\right)}}}{a \cdot 3}
\end{array}
Initial program 56.1%
add-cbrt-cube56.0%
pow1/355.9%
pow355.9%
associate-*l*55.9%
unpow-prod-down55.9%
metadata-eval55.9%
Applied egg-rr55.9%
flip-+56.0%
pow255.9%
add-sqr-sqrt57.2%
pow257.2%
unpow1/357.4%
*-commutative57.4%
cbrt-prod57.4%
unpow357.4%
add-cbrt-cube57.4%
Applied egg-rr57.4%
associate--r-98.5%
unpow298.4%
sqr-neg98.4%
unpow298.5%
*-commutative98.5%
associate-*l*98.6%
*-commutative98.6%
associate-*l*98.6%
Simplified98.6%
Applied egg-rr98.6%
unpow-198.6%
fma-udef98.6%
unpow298.6%
*-commutative98.6%
+-commutative98.6%
fma-def98.6%
fma-udef98.6%
+-rgt-identity98.6%
*-commutative98.6%
Simplified98.6%
Taylor expanded in a around 0 99.1%
associate-*r*99.2%
*-commutative99.2%
associate-*l*99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (a b c) :precision binary64 (/ (/ 1.0 (/ (- (- b) (sqrt (fma -3.0 (* c a) (pow b 2.0)))) (* 3.0 (* c a)))) (* a 3.0)))
double code(double a, double b, double c) {
return (1.0 / ((-b - sqrt(fma(-3.0, (c * a), pow(b, 2.0)))) / (3.0 * (c * a)))) / (a * 3.0);
}
function code(a, b, c) return Float64(Float64(1.0 / Float64(Float64(Float64(-b) - sqrt(fma(-3.0, Float64(c * a), (b ^ 2.0)))) / Float64(3.0 * Float64(c * a)))) / Float64(a * 3.0)) end
code[a_, b_, c_] := N[(N[(1.0 / N[(N[((-b) - N[Sqrt[N[(-3.0 * N[(c * a), $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(-3, c \cdot a, {b}^{2}\right)}}{3 \cdot \left(c \cdot a\right)}}}{a \cdot 3}
\end{array}
Initial program 56.1%
add-cbrt-cube56.0%
pow1/355.9%
pow355.9%
associate-*l*55.9%
unpow-prod-down55.9%
metadata-eval55.9%
Applied egg-rr55.9%
flip-+56.0%
pow255.9%
add-sqr-sqrt57.2%
pow257.2%
unpow1/357.4%
*-commutative57.4%
cbrt-prod57.4%
unpow357.4%
add-cbrt-cube57.4%
Applied egg-rr57.4%
associate--r-98.5%
unpow298.4%
sqr-neg98.4%
unpow298.5%
*-commutative98.5%
associate-*l*98.6%
*-commutative98.6%
associate-*l*98.6%
Simplified98.6%
Applied egg-rr98.6%
unpow-198.6%
fma-udef98.6%
unpow298.6%
*-commutative98.6%
+-commutative98.6%
fma-def98.6%
fma-udef98.6%
+-rgt-identity98.6%
*-commutative98.6%
Simplified98.6%
Taylor expanded in a around 0 99.1%
*-commutative99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (a b c)
:precision binary64
(if (<= b 2.0)
(/ (- (sqrt (fma b b (* c (* a -3.0)))) b) (* a 3.0))
(/
(/
1.0
(+
(* -0.6666666666666666 (/ b (* c a)))
(+ (* 0.375 (/ (* c a) (pow b 3.0))) (* 0.5 (/ 1.0 b)))))
(* a 3.0))))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.0) {
tmp = (sqrt(fma(b, b, (c * (a * -3.0)))) - b) / (a * 3.0);
} else {
tmp = (1.0 / ((-0.6666666666666666 * (b / (c * a))) + ((0.375 * ((c * a) / pow(b, 3.0))) + (0.5 * (1.0 / b))))) / (a * 3.0);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 2.0) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -3.0)))) - b) / Float64(a * 3.0)); else tmp = Float64(Float64(1.0 / Float64(Float64(-0.6666666666666666 * Float64(b / Float64(c * a))) + Float64(Float64(0.375 * Float64(Float64(c * a) / (b ^ 3.0))) + Float64(0.5 * Float64(1.0 / b))))) / Float64(a * 3.0)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 2.0], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(N[(-0.6666666666666666 * N[(b / N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(0.375 * N[(N[(c * a), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{-0.6666666666666666 \cdot \frac{b}{c \cdot a} + \left(0.375 \cdot \frac{c \cdot a}{{b}^{3}} + 0.5 \cdot \frac{1}{b}\right)}}{a \cdot 3}\\
\end{array}
\end{array}
if b < 2Initial program 82.7%
Simplified82.9%
if 2 < b Initial program 49.4%
add-cbrt-cube49.4%
pow1/349.3%
pow349.3%
associate-*l*49.3%
unpow-prod-down49.3%
metadata-eval49.3%
Applied egg-rr49.3%
flip-+49.3%
pow249.3%
add-sqr-sqrt50.6%
pow250.7%
unpow1/350.8%
*-commutative50.8%
cbrt-prod50.8%
unpow350.8%
add-cbrt-cube50.8%
Applied egg-rr50.8%
associate--r-98.5%
unpow298.4%
sqr-neg98.4%
unpow298.5%
*-commutative98.5%
associate-*l*98.6%
*-commutative98.6%
associate-*l*98.6%
Simplified98.6%
Applied egg-rr98.6%
unpow-198.6%
fma-udef98.5%
unpow298.5%
*-commutative98.5%
+-commutative98.5%
fma-def98.5%
fma-udef98.5%
+-rgt-identity98.5%
*-commutative98.5%
Simplified98.5%
Taylor expanded in b around inf 92.5%
Final simplification90.6%
(FPCore (a b c)
:precision binary64
(if (<= b 2.0)
(/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0))
(/
(/
1.0
(+
(* -0.6666666666666666 (/ b (* c a)))
(+ (* 0.375 (/ (* c a) (pow b 3.0))) (* 0.5 (/ 1.0 b)))))
(* a 3.0))))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.0) {
tmp = (sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0);
} else {
tmp = (1.0 / ((-0.6666666666666666 * (b / (c * a))) + ((0.375 * ((c * a) / pow(b, 3.0))) + (0.5 * (1.0 / b))))) / (a * 3.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 <= 2.0d0) then
tmp = (sqrt(((b * b) - (c * (a * 3.0d0)))) - b) / (a * 3.0d0)
else
tmp = (1.0d0 / (((-0.6666666666666666d0) * (b / (c * a))) + ((0.375d0 * ((c * a) / (b ** 3.0d0))) + (0.5d0 * (1.0d0 / b))))) / (a * 3.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 2.0) {
tmp = (Math.sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0);
} else {
tmp = (1.0 / ((-0.6666666666666666 * (b / (c * a))) + ((0.375 * ((c * a) / Math.pow(b, 3.0))) + (0.5 * (1.0 / b))))) / (a * 3.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.0: tmp = (math.sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0) else: tmp = (1.0 / ((-0.6666666666666666 * (b / (c * a))) + ((0.375 * ((c * a) / math.pow(b, 3.0))) + (0.5 * (1.0 / b))))) / (a * 3.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.0) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))) - b) / Float64(a * 3.0)); else tmp = Float64(Float64(1.0 / Float64(Float64(-0.6666666666666666 * Float64(b / Float64(c * a))) + Float64(Float64(0.375 * Float64(Float64(c * a) / (b ^ 3.0))) + Float64(0.5 * Float64(1.0 / b))))) / Float64(a * 3.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2.0) tmp = (sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0); else tmp = (1.0 / ((-0.6666666666666666 * (b / (c * a))) + ((0.375 * ((c * a) / (b ^ 3.0))) + (0.5 * (1.0 / b))))) / (a * 3.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.0], 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[(1.0 / N[(N[(-0.6666666666666666 * N[(b / N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(0.375 * N[(N[(c * a), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{-0.6666666666666666 \cdot \frac{b}{c \cdot a} + \left(0.375 \cdot \frac{c \cdot a}{{b}^{3}} + 0.5 \cdot \frac{1}{b}\right)}}{a \cdot 3}\\
\end{array}
\end{array}
if b < 2Initial program 82.7%
if 2 < b Initial program 49.4%
add-cbrt-cube49.4%
pow1/349.3%
pow349.3%
associate-*l*49.3%
unpow-prod-down49.3%
metadata-eval49.3%
Applied egg-rr49.3%
flip-+49.3%
pow249.3%
add-sqr-sqrt50.6%
pow250.7%
unpow1/350.8%
*-commutative50.8%
cbrt-prod50.8%
unpow350.8%
add-cbrt-cube50.8%
Applied egg-rr50.8%
associate--r-98.5%
unpow298.4%
sqr-neg98.4%
unpow298.5%
*-commutative98.5%
associate-*l*98.6%
*-commutative98.6%
associate-*l*98.6%
Simplified98.6%
Applied egg-rr98.6%
unpow-198.6%
fma-udef98.5%
unpow298.5%
*-commutative98.5%
+-commutative98.5%
fma-def98.5%
fma-udef98.5%
+-rgt-identity98.5%
*-commutative98.5%
Simplified98.5%
Taylor expanded in b around inf 92.5%
Final simplification90.5%
(FPCore (a b c)
:precision binary64
(if (<= b 2.05)
(/ (- (sqrt (- (* b b) (* 3.0 (* c a)))) b) (* a 3.0))
(/
(/ 1.0 (+ (* -0.6666666666666666 (/ b (* c a))) (* 0.5 (/ 1.0 b))))
(* a 3.0))))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.05) {
tmp = (sqrt(((b * b) - (3.0 * (c * a)))) - b) / (a * 3.0);
} else {
tmp = (1.0 / ((-0.6666666666666666 * (b / (c * a))) + (0.5 * (1.0 / b)))) / (a * 3.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 <= 2.05d0) then
tmp = (sqrt(((b * b) - (3.0d0 * (c * a)))) - b) / (a * 3.0d0)
else
tmp = (1.0d0 / (((-0.6666666666666666d0) * (b / (c * a))) + (0.5d0 * (1.0d0 / b)))) / (a * 3.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 2.05) {
tmp = (Math.sqrt(((b * b) - (3.0 * (c * a)))) - b) / (a * 3.0);
} else {
tmp = (1.0 / ((-0.6666666666666666 * (b / (c * a))) + (0.5 * (1.0 / b)))) / (a * 3.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.05: tmp = (math.sqrt(((b * b) - (3.0 * (c * a)))) - b) / (a * 3.0) else: tmp = (1.0 / ((-0.6666666666666666 * (b / (c * a))) + (0.5 * (1.0 / b)))) / (a * 3.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.05) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(3.0 * Float64(c * a)))) - b) / Float64(a * 3.0)); else tmp = Float64(Float64(1.0 / Float64(Float64(-0.6666666666666666 * Float64(b / Float64(c * a))) + Float64(0.5 * Float64(1.0 / b)))) / Float64(a * 3.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2.05) tmp = (sqrt(((b * b) - (3.0 * (c * a)))) - b) / (a * 3.0); else tmp = (1.0 / ((-0.6666666666666666 * (b / (c * a))) + (0.5 * (1.0 / b)))) / (a * 3.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.05], 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[(N[(1.0 / N[(N[(-0.6666666666666666 * N[(b / N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.05:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 3 \cdot \left(c \cdot a\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{-0.6666666666666666 \cdot \frac{b}{c \cdot a} + 0.5 \cdot \frac{1}{b}}}{a \cdot 3}\\
\end{array}
\end{array}
if b < 2.0499999999999998Initial program 82.7%
Taylor expanded in a around 0 82.6%
if 2.0499999999999998 < b Initial program 49.4%
add-cbrt-cube49.4%
pow1/349.3%
pow349.3%
associate-*l*49.3%
unpow-prod-down49.3%
metadata-eval49.3%
Applied egg-rr49.3%
flip-+49.3%
pow249.3%
add-sqr-sqrt50.6%
pow250.7%
unpow1/350.8%
*-commutative50.8%
cbrt-prod50.8%
unpow350.8%
add-cbrt-cube50.8%
Applied egg-rr50.8%
associate--r-98.5%
unpow298.4%
sqr-neg98.4%
unpow298.5%
*-commutative98.5%
associate-*l*98.6%
*-commutative98.6%
associate-*l*98.6%
Simplified98.6%
Applied egg-rr98.6%
unpow-198.6%
fma-udef98.5%
unpow298.5%
*-commutative98.5%
+-commutative98.5%
fma-def98.5%
fma-udef98.5%
+-rgt-identity98.5%
*-commutative98.5%
Simplified98.5%
Taylor expanded in b around inf 88.2%
Final simplification87.1%
(FPCore (a b c)
:precision binary64
(if (<= b 2.1)
(/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0))
(/
(/ 1.0 (+ (* -0.6666666666666666 (/ b (* c a))) (* 0.5 (/ 1.0 b))))
(* a 3.0))))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.1) {
tmp = (sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0);
} else {
tmp = (1.0 / ((-0.6666666666666666 * (b / (c * a))) + (0.5 * (1.0 / b)))) / (a * 3.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 <= 2.1d0) then
tmp = (sqrt(((b * b) - (c * (a * 3.0d0)))) - b) / (a * 3.0d0)
else
tmp = (1.0d0 / (((-0.6666666666666666d0) * (b / (c * a))) + (0.5d0 * (1.0d0 / b)))) / (a * 3.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 2.1) {
tmp = (Math.sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0);
} else {
tmp = (1.0 / ((-0.6666666666666666 * (b / (c * a))) + (0.5 * (1.0 / b)))) / (a * 3.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.1: tmp = (math.sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0) else: tmp = (1.0 / ((-0.6666666666666666 * (b / (c * a))) + (0.5 * (1.0 / b)))) / (a * 3.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.1) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))) - b) / Float64(a * 3.0)); else tmp = Float64(Float64(1.0 / Float64(Float64(-0.6666666666666666 * Float64(b / Float64(c * a))) + Float64(0.5 * Float64(1.0 / b)))) / Float64(a * 3.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2.1) tmp = (sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0); else tmp = (1.0 / ((-0.6666666666666666 * (b / (c * a))) + (0.5 * (1.0 / b)))) / (a * 3.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.1], 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[(1.0 / N[(N[(-0.6666666666666666 * N[(b / N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.1:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{-0.6666666666666666 \cdot \frac{b}{c \cdot a} + 0.5 \cdot \frac{1}{b}}}{a \cdot 3}\\
\end{array}
\end{array}
if b < 2.10000000000000009Initial program 82.7%
if 2.10000000000000009 < b Initial program 49.4%
add-cbrt-cube49.4%
pow1/349.3%
pow349.3%
associate-*l*49.3%
unpow-prod-down49.3%
metadata-eval49.3%
Applied egg-rr49.3%
flip-+49.3%
pow249.3%
add-sqr-sqrt50.6%
pow250.7%
unpow1/350.8%
*-commutative50.8%
cbrt-prod50.8%
unpow350.8%
add-cbrt-cube50.8%
Applied egg-rr50.8%
associate--r-98.5%
unpow298.4%
sqr-neg98.4%
unpow298.5%
*-commutative98.5%
associate-*l*98.6%
*-commutative98.6%
associate-*l*98.6%
Simplified98.6%
Applied egg-rr98.6%
unpow-198.6%
fma-udef98.5%
unpow298.5%
*-commutative98.5%
+-commutative98.5%
fma-def98.5%
fma-udef98.5%
+-rgt-identity98.5%
*-commutative98.5%
Simplified98.5%
Taylor expanded in b around inf 88.2%
Final simplification87.1%
(FPCore (a b c) :precision binary64 (/ (/ 1.0 (+ (* -0.6666666666666666 (/ b (* c a))) (* 0.5 (/ 1.0 b)))) (* a 3.0)))
double code(double a, double b, double c) {
return (1.0 / ((-0.6666666666666666 * (b / (c * a))) + (0.5 * (1.0 / b)))) / (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 = (1.0d0 / (((-0.6666666666666666d0) * (b / (c * a))) + (0.5d0 * (1.0d0 / b)))) / (a * 3.0d0)
end function
public static double code(double a, double b, double c) {
return (1.0 / ((-0.6666666666666666 * (b / (c * a))) + (0.5 * (1.0 / b)))) / (a * 3.0);
}
def code(a, b, c): return (1.0 / ((-0.6666666666666666 * (b / (c * a))) + (0.5 * (1.0 / b)))) / (a * 3.0)
function code(a, b, c) return Float64(Float64(1.0 / Float64(Float64(-0.6666666666666666 * Float64(b / Float64(c * a))) + Float64(0.5 * Float64(1.0 / b)))) / Float64(a * 3.0)) end
function tmp = code(a, b, c) tmp = (1.0 / ((-0.6666666666666666 * (b / (c * a))) + (0.5 * (1.0 / b)))) / (a * 3.0); end
code[a_, b_, c_] := N[(N[(1.0 / N[(N[(-0.6666666666666666 * N[(b / N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{-0.6666666666666666 \cdot \frac{b}{c \cdot a} + 0.5 \cdot \frac{1}{b}}}{a \cdot 3}
\end{array}
Initial program 56.1%
add-cbrt-cube56.0%
pow1/355.9%
pow355.9%
associate-*l*55.9%
unpow-prod-down55.9%
metadata-eval55.9%
Applied egg-rr55.9%
flip-+56.0%
pow255.9%
add-sqr-sqrt57.2%
pow257.2%
unpow1/357.4%
*-commutative57.4%
cbrt-prod57.4%
unpow357.4%
add-cbrt-cube57.4%
Applied egg-rr57.4%
associate--r-98.5%
unpow298.4%
sqr-neg98.4%
unpow298.5%
*-commutative98.5%
associate-*l*98.6%
*-commutative98.6%
associate-*l*98.6%
Simplified98.6%
Applied egg-rr98.6%
unpow-198.6%
fma-udef98.6%
unpow298.6%
*-commutative98.6%
+-commutative98.6%
fma-def98.6%
fma-udef98.6%
+-rgt-identity98.6%
*-commutative98.6%
Simplified98.6%
Taylor expanded in b around inf 82.6%
Final simplification82.6%
(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 56.1%
Taylor expanded in b around inf 64.0%
*-commutative64.0%
associate-*l/64.0%
Simplified64.0%
Final simplification64.0%
herbie shell --seed 2023301
(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)))