
(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 11 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 3.0))) (+ b (sqrt (+ (pow b 2.0) (* -3.0 (* c a)))))) (pow (sqrt (* a 3.0)) 2.0)))
double code(double a, double b, double c) {
return (((pow(b, 2.0) - pow(-b, 2.0)) - (c * (a * 3.0))) / (b + sqrt((pow(b, 2.0) + (-3.0 * (c * a)))))) / pow(sqrt((a * 3.0)), 2.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 * 3.0d0))) / (b + sqrt(((b ** 2.0d0) + ((-3.0d0) * (c * a)))))) / (sqrt((a * 3.0d0)) ** 2.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 * 3.0))) / (b + Math.sqrt((Math.pow(b, 2.0) + (-3.0 * (c * a)))))) / Math.pow(Math.sqrt((a * 3.0)), 2.0);
}
def code(a, b, c): return (((math.pow(b, 2.0) - math.pow(-b, 2.0)) - (c * (a * 3.0))) / (b + math.sqrt((math.pow(b, 2.0) + (-3.0 * (c * a)))))) / math.pow(math.sqrt((a * 3.0)), 2.0)
function code(a, b, c) return Float64(Float64(Float64(Float64((b ^ 2.0) - (Float64(-b) ^ 2.0)) - Float64(c * Float64(a * 3.0))) / Float64(b + sqrt(Float64((b ^ 2.0) + Float64(-3.0 * Float64(c * a)))))) / (sqrt(Float64(a * 3.0)) ^ 2.0)) end
function tmp = code(a, b, c) tmp = ((((b ^ 2.0) - (-b ^ 2.0)) - (c * (a * 3.0))) / (b + sqrt(((b ^ 2.0) + (-3.0 * (c * a)))))) / (sqrt((a * 3.0)) ^ 2.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 * 3.0), $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[Power[N[Sqrt[N[(a * 3.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\left({b}^{2} - {\left(-b\right)}^{2}\right) - c \cdot \left(a \cdot 3\right)}{b + \sqrt{{b}^{2} + -3 \cdot \left(c \cdot a\right)}}}{{\left(\sqrt{a \cdot 3}\right)}^{2}}
\end{array}
Initial program 58.0%
add-sqr-sqrt58.0%
pow258.0%
Applied egg-rr58.0%
log1p-expm1-u50.3%
neg-mul-150.3%
fma-define50.3%
pow250.3%
*-commutative50.3%
*-commutative50.3%
Applied egg-rr50.3%
log1p-expm1-u58.0%
fma-undefine58.0%
neg-mul-158.0%
pow258.0%
*-commutative58.0%
*-commutative58.0%
flip-+57.8%
pow257.8%
add-sqr-sqrt59.1%
*-commutative59.1%
pow259.1%
*-commutative59.1%
Applied egg-rr59.1%
associate--r-99.0%
associate-*r*99.0%
*-commutative99.0%
*-commutative99.0%
cancel-sign-sub-inv99.0%
metadata-eval99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (a b c)
:precision binary64
(if (<= (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0)) -0.0068)
(* 0.3333333333333333 (/ (- (sqrt (fma b b (* -3.0 (* c a)))) b) a))
(+
(* -0.5 (/ c b))
(*
a
(+
(* -0.5625 (/ (* a (pow c 3.0)) (pow b 5.0)))
(* -0.375 (/ (pow c 2.0) (pow b 3.0))))))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -0.0068) {
tmp = 0.3333333333333333 * ((sqrt(fma(b, b, (-3.0 * (c * a)))) - b) / a);
} else {
tmp = (-0.5 * (c / b)) + (a * ((-0.5625 * ((a * pow(c, 3.0)) / pow(b, 5.0))) + (-0.375 * (pow(c, 2.0) / pow(b, 3.0)))));
}
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)) <= -0.0068) tmp = Float64(0.3333333333333333 * Float64(Float64(sqrt(fma(b, b, Float64(-3.0 * Float64(c * a)))) - b) / a)); else tmp = Float64(Float64(-0.5 * Float64(c / b)) + Float64(a * Float64(Float64(-0.5625 * Float64(Float64(a * (c ^ 3.0)) / (b ^ 5.0))) + Float64(-0.375 * Float64((c ^ 2.0) / (b ^ 3.0)))))); 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], -0.0068], N[(0.3333333333333333 * N[(N[(N[Sqrt[N[(b * b + N[(-3.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(a * N[(N[(-0.5625 * N[(N[(a * N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.375 * N[(N[Power[c, 2.0], $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 -0.0068:\\
\;\;\;\;0.3333333333333333 \cdot \frac{\sqrt{\mathsf{fma}\left(b, b, -3 \cdot \left(c \cdot a\right)\right)} - b}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b} + a \cdot \left(-0.5625 \cdot \frac{a \cdot {c}^{3}}{{b}^{5}} + -0.375 \cdot \frac{{c}^{2}}{{b}^{3}}\right)\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 3 binary64) a) c)))) (*.f64 #s(literal 3 binary64) a)) < -0.00679999999999999962Initial program 81.3%
add-log-exp66.1%
*-commutative66.1%
exp-prod65.1%
Applied egg-rr65.1%
pow-exp66.1%
add-log-exp81.3%
*-un-lft-identity81.3%
neg-mul-181.3%
*-commutative81.3%
*-commutative81.3%
pow281.3%
fma-undefine81.3%
Applied egg-rr81.3%
associate-*r/81.3%
*-commutative81.3%
times-frac81.3%
metadata-eval81.3%
Simplified81.4%
if -0.00679999999999999962 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 3 binary64) a) c)))) (*.f64 #s(literal 3 binary64) a)) Initial program 46.6%
Simplified46.6%
Taylor expanded in a around 0 92.8%
Final simplification89.1%
(FPCore (a b c)
:precision binary64
(if (<= (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0)) -0.0068)
(* 0.3333333333333333 (/ (- (sqrt (fma b b (* -3.0 (* c a)))) b) a))
(+
(* -0.5 (/ c b))
(*
a
(*
(pow c 3.0)
(- (* -0.5625 (/ a (pow b 5.0))) (/ 0.375 (* c (pow b 3.0)))))))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -0.0068) {
tmp = 0.3333333333333333 * ((sqrt(fma(b, b, (-3.0 * (c * a)))) - b) / a);
} else {
tmp = (-0.5 * (c / b)) + (a * (pow(c, 3.0) * ((-0.5625 * (a / pow(b, 5.0))) - (0.375 / (c * pow(b, 3.0))))));
}
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)) <= -0.0068) tmp = Float64(0.3333333333333333 * Float64(Float64(sqrt(fma(b, b, Float64(-3.0 * Float64(c * a)))) - b) / a)); else tmp = Float64(Float64(-0.5 * Float64(c / b)) + Float64(a * Float64((c ^ 3.0) * Float64(Float64(-0.5625 * Float64(a / (b ^ 5.0))) - Float64(0.375 / Float64(c * (b ^ 3.0))))))); 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], -0.0068], N[(0.3333333333333333 * N[(N[(N[Sqrt[N[(b * b + N[(-3.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(a * N[(N[Power[c, 3.0], $MachinePrecision] * N[(N[(-0.5625 * N[(a / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(0.375 / N[(c * N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 -0.0068:\\
\;\;\;\;0.3333333333333333 \cdot \frac{\sqrt{\mathsf{fma}\left(b, b, -3 \cdot \left(c \cdot a\right)\right)} - b}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b} + a \cdot \left({c}^{3} \cdot \left(-0.5625 \cdot \frac{a}{{b}^{5}} - \frac{0.375}{c \cdot {b}^{3}}\right)\right)\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 3 binary64) a) c)))) (*.f64 #s(literal 3 binary64) a)) < -0.00679999999999999962Initial program 81.3%
add-log-exp66.1%
*-commutative66.1%
exp-prod65.1%
Applied egg-rr65.1%
pow-exp66.1%
add-log-exp81.3%
*-un-lft-identity81.3%
neg-mul-181.3%
*-commutative81.3%
*-commutative81.3%
pow281.3%
fma-undefine81.3%
Applied egg-rr81.3%
associate-*r/81.3%
*-commutative81.3%
times-frac81.3%
metadata-eval81.3%
Simplified81.4%
if -0.00679999999999999962 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 3 binary64) a) c)))) (*.f64 #s(literal 3 binary64) a)) Initial program 46.6%
Simplified46.6%
Taylor expanded in a around 0 92.8%
Taylor expanded in c around inf 92.8%
associate-*r/92.8%
metadata-eval92.8%
*-commutative92.8%
Simplified92.8%
Final simplification89.1%
(FPCore (a b c) :precision binary64 (/ (/ (- (* 0.0 (+ b b)) (* c (* a 3.0))) (+ b (sqrt (fma b b (* -3.0 (* c a)))))) (pow (sqrt (* a 3.0)) 2.0)))
double code(double a, double b, double c) {
return (((0.0 * (b + b)) - (c * (a * 3.0))) / (b + sqrt(fma(b, b, (-3.0 * (c * a)))))) / pow(sqrt((a * 3.0)), 2.0);
}
function code(a, b, c) return Float64(Float64(Float64(Float64(0.0 * Float64(b + b)) - Float64(c * Float64(a * 3.0))) / Float64(b + sqrt(fma(b, b, Float64(-3.0 * Float64(c * a)))))) / (sqrt(Float64(a * 3.0)) ^ 2.0)) end
code[a_, b_, c_] := N[(N[(N[(N[(0.0 * N[(b + b), $MachinePrecision]), $MachinePrecision] - N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(b * b + N[(-3.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[N[Sqrt[N[(a * 3.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{0 \cdot \left(b + b\right) - c \cdot \left(a \cdot 3\right)}{b + \sqrt{\mathsf{fma}\left(b, b, -3 \cdot \left(c \cdot a\right)\right)}}}{{\left(\sqrt{a \cdot 3}\right)}^{2}}
\end{array}
Initial program 58.0%
add-sqr-sqrt58.0%
pow258.0%
Applied egg-rr58.0%
log1p-expm1-u50.3%
neg-mul-150.3%
fma-define50.3%
pow250.3%
*-commutative50.3%
*-commutative50.3%
Applied egg-rr50.3%
log1p-expm1-u58.0%
fma-undefine58.0%
neg-mul-158.0%
pow258.0%
*-commutative58.0%
*-commutative58.0%
flip-+57.8%
pow257.8%
add-sqr-sqrt59.1%
*-commutative59.1%
pow259.1%
*-commutative59.1%
Applied egg-rr59.1%
associate--r-99.0%
unpow299.0%
unpow299.0%
difference-of-squares99.0%
neg-mul-199.0%
distribute-lft1-in99.0%
metadata-eval99.0%
mul0-lft99.0%
associate-*r*99.0%
*-commutative99.0%
*-commutative99.0%
unpow299.0%
*-commutative99.0%
*-commutative99.0%
associate-*r*99.0%
fmm-def99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0)) -0.0034) (* 0.3333333333333333 (/ (- (sqrt (fma b b (* -3.0 (* c a)))) b) a)) (+ (* -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 (((sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -0.0034) {
tmp = 0.3333333333333333 * ((sqrt(fma(b, b, (-3.0 * (c * a)))) - b) / a);
} 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 (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))) - b) / Float64(a * 3.0)) <= -0.0034) tmp = Float64(0.3333333333333333 * Float64(Float64(sqrt(fma(b, b, Float64(-3.0 * Float64(c * a)))) - b) / a)); 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[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], -0.0034], N[(0.3333333333333333 * N[(N[(N[Sqrt[N[(b * b + N[(-3.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / a), $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}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -0.0034:\\
\;\;\;\;0.3333333333333333 \cdot \frac{\sqrt{\mathsf{fma}\left(b, b, -3 \cdot \left(c \cdot a\right)\right)} - b}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 3 binary64) a) c)))) (*.f64 #s(literal 3 binary64) a)) < -0.00339999999999999981Initial program 81.0%
add-log-exp63.9%
*-commutative63.9%
exp-prod63.0%
Applied egg-rr63.0%
pow-exp63.9%
add-log-exp81.0%
*-un-lft-identity81.0%
neg-mul-181.0%
*-commutative81.0%
*-commutative81.0%
pow281.0%
fma-undefine81.0%
Applied egg-rr81.0%
associate-*r/81.0%
*-commutative81.0%
times-frac81.0%
metadata-eval81.0%
Simplified81.1%
if -0.00339999999999999981 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 3 binary64) a) c)))) (*.f64 #s(literal 3 binary64) a)) Initial program 45.5%
Simplified45.5%
Taylor expanded in a around 0 90.0%
Final simplification86.9%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0)) -0.0034) (* 0.3333333333333333 (/ (- (sqrt (fma b b (* -3.0 (* c a)))) b) a)) (/ (fma -0.5 c (* -0.375 (* a (pow (/ c b) 2.0)))) b)))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -0.0034) {
tmp = 0.3333333333333333 * ((sqrt(fma(b, b, (-3.0 * (c * a)))) - b) / a);
} else {
tmp = fma(-0.5, c, (-0.375 * (a * pow((c / b), 2.0)))) / 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)) <= -0.0034) tmp = Float64(0.3333333333333333 * Float64(Float64(sqrt(fma(b, b, Float64(-3.0 * Float64(c * a)))) - b) / a)); else tmp = Float64(fma(-0.5, c, Float64(-0.375 * Float64(a * (Float64(c / b) ^ 2.0)))) / 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], -0.0034], N[(0.3333333333333333 * N[(N[(N[Sqrt[N[(b * b + N[(-3.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * c + N[(-0.375 * N[(a * N[Power[N[(c / b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 -0.0034:\\
\;\;\;\;0.3333333333333333 \cdot \frac{\sqrt{\mathsf{fma}\left(b, b, -3 \cdot \left(c \cdot a\right)\right)} - b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-0.5, c, -0.375 \cdot \left(a \cdot {\left(\frac{c}{b}\right)}^{2}\right)\right)}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 3 binary64) a) c)))) (*.f64 #s(literal 3 binary64) a)) < -0.00339999999999999981Initial program 81.0%
add-log-exp63.9%
*-commutative63.9%
exp-prod63.0%
Applied egg-rr63.0%
pow-exp63.9%
add-log-exp81.0%
*-un-lft-identity81.0%
neg-mul-181.0%
*-commutative81.0%
*-commutative81.0%
pow281.0%
fma-undefine81.0%
Applied egg-rr81.0%
associate-*r/81.0%
*-commutative81.0%
times-frac81.0%
metadata-eval81.0%
Simplified81.1%
if -0.00339999999999999981 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 3 binary64) a) c)))) (*.f64 #s(literal 3 binary64) a)) Initial program 45.5%
Simplified45.5%
Taylor expanded in a around 0 89.6%
Taylor expanded in b around inf 90.0%
fma-define90.0%
associate-*r/90.0%
unpow290.0%
unpow290.0%
times-frac90.0%
unpow190.0%
pow-plus90.0%
metadata-eval90.0%
Simplified90.0%
Final simplification86.9%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0))))
(if (<= t_0 -0.0034)
t_0
(/ (fma -0.5 c (* -0.375 (* a (pow (/ c b) 2.0)))) b))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0);
double tmp;
if (t_0 <= -0.0034) {
tmp = t_0;
} else {
tmp = fma(-0.5, c, (-0.375 * (a * pow((c / b), 2.0)))) / b;
}
return tmp;
}
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))) - b) / Float64(a * 3.0)) tmp = 0.0 if (t_0 <= -0.0034) tmp = t_0; else tmp = Float64(fma(-0.5, c, Float64(-0.375 * Float64(a * (Float64(c / b) ^ 2.0)))) / b); end return tmp end
code[a_, b_, c_] := Block[{t$95$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]}, If[LessEqual[t$95$0, -0.0034], t$95$0, N[(N[(-0.5 * c + N[(-0.375 * N[(a * N[Power[N[(c / b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\
\mathbf{if}\;t\_0 \leq -0.0034:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-0.5, c, -0.375 \cdot \left(a \cdot {\left(\frac{c}{b}\right)}^{2}\right)\right)}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 3 binary64) a) c)))) (*.f64 #s(literal 3 binary64) a)) < -0.00339999999999999981Initial program 81.0%
if -0.00339999999999999981 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 3 binary64) a) c)))) (*.f64 #s(literal 3 binary64) a)) Initial program 45.5%
Simplified45.5%
Taylor expanded in a around 0 89.6%
Taylor expanded in b around inf 90.0%
fma-define90.0%
associate-*r/90.0%
unpow290.0%
unpow290.0%
times-frac90.0%
unpow190.0%
pow-plus90.0%
metadata-eval90.0%
Simplified90.0%
Final simplification86.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0))))
(if (<= t_0 -0.0034)
t_0
(/ (* c (- (* -0.375 (/ (* c a) (pow b 2.0))) 0.5)) b))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0);
double tmp;
if (t_0 <= -0.0034) {
tmp = t_0;
} else {
tmp = (c * ((-0.375 * ((c * a) / pow(b, 2.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) :: t_0
real(8) :: tmp
t_0 = (sqrt(((b * b) - (c * (a * 3.0d0)))) - b) / (a * 3.0d0)
if (t_0 <= (-0.0034d0)) then
tmp = t_0
else
tmp = (c * (((-0.375d0) * ((c * a) / (b ** 2.0d0))) - 0.5d0)) / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (Math.sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0);
double tmp;
if (t_0 <= -0.0034) {
tmp = t_0;
} else {
tmp = (c * ((-0.375 * ((c * a) / Math.pow(b, 2.0))) - 0.5)) / b;
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0) tmp = 0 if t_0 <= -0.0034: tmp = t_0 else: tmp = (c * ((-0.375 * ((c * a) / math.pow(b, 2.0))) - 0.5)) / b return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))) - b) / Float64(a * 3.0)) tmp = 0.0 if (t_0 <= -0.0034) tmp = t_0; else tmp = Float64(Float64(c * Float64(Float64(-0.375 * Float64(Float64(c * a) / (b ^ 2.0))) - 0.5)) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0); tmp = 0.0; if (t_0 <= -0.0034) tmp = t_0; else tmp = (c * ((-0.375 * ((c * a) / (b ^ 2.0))) - 0.5)) / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$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]}, If[LessEqual[t$95$0, -0.0034], t$95$0, N[(N[(c * N[(N[(-0.375 * N[(N[(c * a), $MachinePrecision] / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\
\mathbf{if}\;t\_0 \leq -0.0034:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \left(-0.375 \cdot \frac{c \cdot a}{{b}^{2}} - 0.5\right)}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 3 binary64) a) c)))) (*.f64 #s(literal 3 binary64) a)) < -0.00339999999999999981Initial program 81.0%
if -0.00339999999999999981 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 3 binary64) a) c)))) (*.f64 #s(literal 3 binary64) a)) Initial program 45.5%
Simplified45.5%
Taylor expanded in b around inf 95.1%
+-commutative95.1%
*-un-lft-identity95.1%
fma-define95.1%
Applied egg-rr95.1%
fma-undefine95.1%
*-lft-identity95.1%
times-frac95.1%
*-commutative95.1%
associate-*r/95.1%
associate-*r/95.1%
unpow295.1%
unpow295.1%
times-frac95.1%
unpow195.1%
pow-plus95.1%
metadata-eval95.1%
Simplified95.1%
Taylor expanded in c around 0 89.9%
Final simplification86.8%
(FPCore (a b c) :precision binary64 (if (<= b 19.5) (/ (- (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 <= 19.5) {
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 <= 19.5d0) 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 <= 19.5) {
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 <= 19.5: 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 <= 19.5) 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 <= 19.5) 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, 19.5], 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 19.5:\\
\;\;\;\;\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 < 19.5Initial program 79.7%
sqr-neg79.7%
sqr-neg79.7%
associate-*l*79.8%
Simplified79.8%
if 19.5 < b Initial program 49.8%
Simplified49.8%
Taylor expanded in c around 0 86.1%
associate-/l*86.1%
associate-*r/86.1%
metadata-eval86.1%
Simplified86.1%
Final simplification84.4%
(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 58.0%
Simplified58.0%
Taylor expanded in c around 0 79.4%
associate-/l*79.4%
associate-*r/79.4%
metadata-eval79.4%
Simplified79.4%
(FPCore (a b c) :precision binary64 (* -0.5 (/ c b)))
double code(double a, double b, double c) {
return -0.5 * (c / b);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-0.5d0) * (c / b)
end function
public static double code(double a, double b, double c) {
return -0.5 * (c / b);
}
def code(a, b, c): return -0.5 * (c / b)
function code(a, b, c) return Float64(-0.5 * Float64(c / b)) end
function tmp = code(a, b, c) tmp = -0.5 * (c / b); end
code[a_, b_, c_] := N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.5 \cdot \frac{c}{b}
\end{array}
Initial program 58.0%
Simplified58.0%
Taylor expanded in b around inf 62.3%
herbie shell --seed 2024165
(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)))