
(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
(+
(* -0.5625 (/ (* (pow a 2.0) (pow c 3.0)) (pow b 5.0)))
(+
(* -0.5 (/ c b))
(+
(* -0.375 (/ (* a (pow c 2.0)) (pow b 3.0)))
(*
-0.16666666666666666
(/
(* (pow a 3.0) (+ (* 1.265625 (pow c 4.0)) (* (pow c 4.0) 5.0625)))
(pow b 7.0)))))))
double code(double a, double b, double c) {
return (-0.5625 * ((pow(a, 2.0) * pow(c, 3.0)) / pow(b, 5.0))) + ((-0.5 * (c / b)) + ((-0.375 * ((a * pow(c, 2.0)) / pow(b, 3.0))) + (-0.16666666666666666 * ((pow(a, 3.0) * ((1.265625 * pow(c, 4.0)) + (pow(c, 4.0) * 5.0625))) / pow(b, 7.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.5625d0) * (((a ** 2.0d0) * (c ** 3.0d0)) / (b ** 5.0d0))) + (((-0.5d0) * (c / b)) + (((-0.375d0) * ((a * (c ** 2.0d0)) / (b ** 3.0d0))) + ((-0.16666666666666666d0) * (((a ** 3.0d0) * ((1.265625d0 * (c ** 4.0d0)) + ((c ** 4.0d0) * 5.0625d0))) / (b ** 7.0d0)))))
end function
public static double code(double a, double b, double c) {
return (-0.5625 * ((Math.pow(a, 2.0) * Math.pow(c, 3.0)) / Math.pow(b, 5.0))) + ((-0.5 * (c / b)) + ((-0.375 * ((a * Math.pow(c, 2.0)) / Math.pow(b, 3.0))) + (-0.16666666666666666 * ((Math.pow(a, 3.0) * ((1.265625 * Math.pow(c, 4.0)) + (Math.pow(c, 4.0) * 5.0625))) / Math.pow(b, 7.0)))));
}
def code(a, b, c): return (-0.5625 * ((math.pow(a, 2.0) * math.pow(c, 3.0)) / math.pow(b, 5.0))) + ((-0.5 * (c / b)) + ((-0.375 * ((a * math.pow(c, 2.0)) / math.pow(b, 3.0))) + (-0.16666666666666666 * ((math.pow(a, 3.0) * ((1.265625 * math.pow(c, 4.0)) + (math.pow(c, 4.0) * 5.0625))) / math.pow(b, 7.0)))))
function code(a, b, c) return Float64(Float64(-0.5625 * Float64(Float64((a ^ 2.0) * (c ^ 3.0)) / (b ^ 5.0))) + Float64(Float64(-0.5 * Float64(c / b)) + Float64(Float64(-0.375 * Float64(Float64(a * (c ^ 2.0)) / (b ^ 3.0))) + Float64(-0.16666666666666666 * Float64(Float64((a ^ 3.0) * Float64(Float64(1.265625 * (c ^ 4.0)) + Float64((c ^ 4.0) * 5.0625))) / (b ^ 7.0)))))) end
function tmp = code(a, b, c) tmp = (-0.5625 * (((a ^ 2.0) * (c ^ 3.0)) / (b ^ 5.0))) + ((-0.5 * (c / b)) + ((-0.375 * ((a * (c ^ 2.0)) / (b ^ 3.0))) + (-0.16666666666666666 * (((a ^ 3.0) * ((1.265625 * (c ^ 4.0)) + ((c ^ 4.0) * 5.0625))) / (b ^ 7.0))))); end
code[a_, b_, c_] := N[(N[(-0.5625 * N[(N[(N[Power[a, 2.0], $MachinePrecision] * N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(N[(-0.375 * N[(N[(a * N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.16666666666666666 * N[(N[(N[Power[a, 3.0], $MachinePrecision] * N[(N[(1.265625 * N[Power[c, 4.0], $MachinePrecision]), $MachinePrecision] + N[(N[Power[c, 4.0], $MachinePrecision] * 5.0625), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.5625 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} + \left(-0.5 \cdot \frac{c}{b} + \left(-0.375 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}} + -0.16666666666666666 \cdot \frac{{a}^{3} \cdot \left(1.265625 \cdot {c}^{4} + {c}^{4} \cdot 5.0625\right)}{{b}^{7}}\right)\right)
\end{array}
Initial program 32.1%
Taylor expanded in b around inf 94.4%
Taylor expanded in a around 0 94.9%
Final simplification94.9%
(FPCore (a b c) :precision binary64 (+ (* -0.5625 (/ (* (pow a 2.0) (pow c 3.0)) (pow b 5.0))) (+ (* -0.5 (/ c b)) (* -0.375 (/ (* a (pow c 2.0)) (pow b 3.0))))))
double code(double a, double b, double c) {
return (-0.5625 * ((pow(a, 2.0) * pow(c, 3.0)) / pow(b, 5.0))) + ((-0.5 * (c / b)) + (-0.375 * ((a * pow(c, 2.0)) / pow(b, 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 = ((-0.5625d0) * (((a ** 2.0d0) * (c ** 3.0d0)) / (b ** 5.0d0))) + (((-0.5d0) * (c / b)) + ((-0.375d0) * ((a * (c ** 2.0d0)) / (b ** 3.0d0))))
end function
public static double code(double a, double b, double c) {
return (-0.5625 * ((Math.pow(a, 2.0) * Math.pow(c, 3.0)) / Math.pow(b, 5.0))) + ((-0.5 * (c / b)) + (-0.375 * ((a * Math.pow(c, 2.0)) / Math.pow(b, 3.0))));
}
def code(a, b, c): return (-0.5625 * ((math.pow(a, 2.0) * math.pow(c, 3.0)) / math.pow(b, 5.0))) + ((-0.5 * (c / b)) + (-0.375 * ((a * math.pow(c, 2.0)) / math.pow(b, 3.0))))
function code(a, b, c) return Float64(Float64(-0.5625 * Float64(Float64((a ^ 2.0) * (c ^ 3.0)) / (b ^ 5.0))) + Float64(Float64(-0.5 * Float64(c / b)) + Float64(-0.375 * Float64(Float64(a * (c ^ 2.0)) / (b ^ 3.0))))) end
function tmp = code(a, b, c) tmp = (-0.5625 * (((a ^ 2.0) * (c ^ 3.0)) / (b ^ 5.0))) + ((-0.5 * (c / b)) + (-0.375 * ((a * (c ^ 2.0)) / (b ^ 3.0)))); end
code[a_, b_, c_] := N[(N[(-0.5625 * N[(N[(N[Power[a, 2.0], $MachinePrecision] * N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $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]), $MachinePrecision]
\begin{array}{l}
\\
-0.5625 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} + \left(-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}}\right)
\end{array}
Initial program 32.1%
Taylor expanded in b around inf 93.6%
Final simplification93.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0))))
(if (<= t_0 -0.086)
t_0
(if (<= t_0 -3e-6)
(/ (* c (* a (/ -1.5 b))) (* a 3.0))
(if (<= t_0 -6e-11) t_0 (/ (* c -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.086) {
tmp = t_0;
} else if (t_0 <= -3e-6) {
tmp = (c * (a * (-1.5 / b))) / (a * 3.0);
} else if (t_0 <= -6e-11) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = (sqrt(((b * b) - (c * (a * 3.0d0)))) - b) / (a * 3.0d0)
if (t_0 <= (-0.086d0)) then
tmp = t_0
else if (t_0 <= (-3d-6)) then
tmp = (c * (a * ((-1.5d0) / b))) / (a * 3.0d0)
else if (t_0 <= (-6d-11)) then
tmp = t_0
else
tmp = (c * (-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.086) {
tmp = t_0;
} else if (t_0 <= -3e-6) {
tmp = (c * (a * (-1.5 / b))) / (a * 3.0);
} else if (t_0 <= -6e-11) {
tmp = t_0;
} else {
tmp = (c * -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.086: tmp = t_0 elif t_0 <= -3e-6: tmp = (c * (a * (-1.5 / b))) / (a * 3.0) elif t_0 <= -6e-11: tmp = t_0 else: tmp = (c * -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.086) tmp = t_0; elseif (t_0 <= -3e-6) tmp = Float64(Float64(c * Float64(a * Float64(-1.5 / b))) / Float64(a * 3.0)); elseif (t_0 <= -6e-11) tmp = t_0; else tmp = Float64(Float64(c * -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.086) tmp = t_0; elseif (t_0 <= -3e-6) tmp = (c * (a * (-1.5 / b))) / (a * 3.0); elseif (t_0 <= -6e-11) tmp = t_0; else tmp = (c * -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.086], t$95$0, If[LessEqual[t$95$0, -3e-6], N[(N[(c * N[(a * N[(-1.5 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -6e-11], t$95$0, N[(N[(c * -0.5), $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.086:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq -3 \cdot 10^{-6}:\\
\;\;\;\;\frac{c \cdot \left(a \cdot \frac{-1.5}{b}\right)}{a \cdot 3}\\
\mathbf{elif}\;t_0 \leq -6 \cdot 10^{-11}:\\
\;\;\;\;t_0\\
\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)) < -0.085999999999999993 or -3.0000000000000001e-6 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -6e-11Initial program 71.0%
if -0.085999999999999993 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -3.0000000000000001e-6Initial program 55.1%
Simplified55.1%
Taylor expanded in b around inf 41.2%
associate-*r/41.2%
associate-*r*41.2%
Simplified41.2%
Taylor expanded in b around 0 68.0%
associate-*r/68.0%
associate-*r*68.0%
*-commutative68.0%
associate-*l/68.1%
*-commutative68.1%
*-rgt-identity68.1%
associate-*r/68.1%
associate-*l*68.1%
associate-*r/68.1%
metadata-eval68.1%
Simplified68.1%
if -6e-11 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) Initial program 12.3%
Taylor expanded in b around inf 94.7%
associate-*r/94.7%
*-commutative94.7%
Simplified94.7%
Final simplification85.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0))))
(if (<= t_0 -0.086)
(* (- b (sqrt (fma b b (* a (* c -3.0))))) (/ -0.3333333333333333 a))
(if (<= t_0 -3e-6)
(/ (* c (* a (/ -1.5 b))) (* a 3.0))
(if (<= t_0 -6e-11) t_0 (/ (* c -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.086) {
tmp = (b - sqrt(fma(b, b, (a * (c * -3.0))))) * (-0.3333333333333333 / a);
} else if (t_0 <= -3e-6) {
tmp = (c * (a * (-1.5 / b))) / (a * 3.0);
} else if (t_0 <= -6e-11) {
tmp = t_0;
} else {
tmp = (c * -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.086) tmp = Float64(Float64(b - sqrt(fma(b, b, Float64(a * Float64(c * -3.0))))) * Float64(-0.3333333333333333 / a)); elseif (t_0 <= -3e-6) tmp = Float64(Float64(c * Float64(a * Float64(-1.5 / b))) / Float64(a * 3.0)); elseif (t_0 <= -6e-11) tmp = t_0; else tmp = Float64(Float64(c * -0.5) / 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.086], N[(N[(b - N[Sqrt[N[(b * b + N[(a * N[(c * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.3333333333333333 / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -3e-6], N[(N[(c * N[(a * N[(-1.5 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -6e-11], t$95$0, N[(N[(c * -0.5), $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.086:\\
\;\;\;\;\left(b - \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)}\right) \cdot \frac{-0.3333333333333333}{a}\\
\mathbf{elif}\;t_0 \leq -3 \cdot 10^{-6}:\\
\;\;\;\;\frac{c \cdot \left(a \cdot \frac{-1.5}{b}\right)}{a \cdot 3}\\
\mathbf{elif}\;t_0 \leq -6 \cdot 10^{-11}:\\
\;\;\;\;t_0\\
\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)) < -0.085999999999999993Initial program 70.4%
expm1-log1p-u70.3%
expm1-udef56.2%
associate-*l*56.2%
Applied egg-rr56.2%
frac-2neg56.2%
div-inv56.2%
Applied egg-rr70.5%
associate-*l*70.5%
*-commutative70.5%
*-commutative70.5%
associate-/r*70.5%
metadata-eval70.5%
Simplified70.5%
if -0.085999999999999993 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -3.0000000000000001e-6Initial program 55.1%
Simplified55.1%
Taylor expanded in b around inf 41.2%
associate-*r/41.2%
associate-*r*41.2%
Simplified41.2%
Taylor expanded in b around 0 68.0%
associate-*r/68.0%
associate-*r*68.0%
*-commutative68.0%
associate-*l/68.1%
*-commutative68.1%
*-rgt-identity68.1%
associate-*r/68.1%
associate-*l*68.1%
associate-*r/68.1%
metadata-eval68.1%
Simplified68.1%
if -3.0000000000000001e-6 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -6e-11Initial program 72.1%
if -6e-11 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) Initial program 12.3%
Taylor expanded in b around inf 94.7%
associate-*r/94.7%
*-commutative94.7%
Simplified94.7%
Final simplification85.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0))))
(if (<= t_0 -0.086)
(* (- b (sqrt (fma b b (* a (* c -3.0))))) (/ -0.3333333333333333 a))
(if (<= t_0 -3e-6)
(*
(* c (* a (/ -1.5 b)))
(cbrt (/ (/ 0.037037037037037035 a) (pow a 2.0))))
(if (<= t_0 -6e-11) t_0 (/ (* c -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.086) {
tmp = (b - sqrt(fma(b, b, (a * (c * -3.0))))) * (-0.3333333333333333 / a);
} else if (t_0 <= -3e-6) {
tmp = (c * (a * (-1.5 / b))) * cbrt(((0.037037037037037035 / a) / pow(a, 2.0)));
} else if (t_0 <= -6e-11) {
tmp = t_0;
} else {
tmp = (c * -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.086) tmp = Float64(Float64(b - sqrt(fma(b, b, Float64(a * Float64(c * -3.0))))) * Float64(-0.3333333333333333 / a)); elseif (t_0 <= -3e-6) tmp = Float64(Float64(c * Float64(a * Float64(-1.5 / b))) * cbrt(Float64(Float64(0.037037037037037035 / a) / (a ^ 2.0)))); elseif (t_0 <= -6e-11) tmp = t_0; else tmp = Float64(Float64(c * -0.5) / 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.086], N[(N[(b - N[Sqrt[N[(b * b + N[(a * N[(c * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.3333333333333333 / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -3e-6], N[(N[(c * N[(a * N[(-1.5 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(0.037037037037037035 / a), $MachinePrecision] / N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -6e-11], t$95$0, N[(N[(c * -0.5), $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.086:\\
\;\;\;\;\left(b - \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)}\right) \cdot \frac{-0.3333333333333333}{a}\\
\mathbf{elif}\;t_0 \leq -3 \cdot 10^{-6}:\\
\;\;\;\;\left(c \cdot \left(a \cdot \frac{-1.5}{b}\right)\right) \cdot \sqrt[3]{\frac{\frac{0.037037037037037035}{a}}{{a}^{2}}}\\
\mathbf{elif}\;t_0 \leq -6 \cdot 10^{-11}:\\
\;\;\;\;t_0\\
\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)) < -0.085999999999999993Initial program 70.4%
expm1-log1p-u70.3%
expm1-udef56.2%
associate-*l*56.2%
Applied egg-rr56.2%
frac-2neg56.2%
div-inv56.2%
Applied egg-rr70.5%
associate-*l*70.5%
*-commutative70.5%
*-commutative70.5%
associate-/r*70.5%
metadata-eval70.5%
Simplified70.5%
if -0.085999999999999993 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -3.0000000000000001e-6Initial program 55.1%
Simplified55.1%
Taylor expanded in b around inf 41.2%
associate-*r/41.2%
associate-*r*41.2%
Simplified41.2%
div-sub40.7%
sub-neg40.7%
div-inv40.5%
associate-*l*40.5%
associate-*r/40.5%
associate-*l/40.5%
*-commutative40.5%
metadata-eval40.5%
associate-/r*40.6%
metadata-eval40.6%
metadata-eval40.6%
div-inv40.9%
metadata-eval40.9%
associate-/r*40.8%
metadata-eval40.8%
metadata-eval40.8%
Applied egg-rr40.8%
sub-neg40.8%
distribute-rgt-out--41.2%
+-commutative41.2%
associate-+r-68.0%
*-commutative68.0%
+-inverses68.0%
+-rgt-identity68.0%
*-commutative68.0%
associate-*l*68.0%
associate-*r/68.0%
*-commutative68.0%
*-rgt-identity68.0%
associate-*r/68.0%
*-commutative68.0%
associate-*l*68.0%
associate-*r/68.0%
metadata-eval68.0%
Simplified68.0%
add-cbrt-cube68.1%
*-commutative68.1%
frac-times68.1%
metadata-eval68.1%
pow168.1%
pow168.1%
pow-sqr68.1%
metadata-eval68.1%
Applied egg-rr68.1%
associate-*r/68.1%
associate-*l/68.1%
metadata-eval68.1%
Simplified68.1%
if -3.0000000000000001e-6 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -6e-11Initial program 72.1%
if -6e-11 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) Initial program 12.3%
Taylor expanded in b around inf 94.7%
associate-*r/94.7%
*-commutative94.7%
Simplified94.7%
Final simplification85.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0))))
(if (<= t_0 -0.086)
(* (- b (sqrt (fma b b (* c (* a -3.0))))) (/ 1.0 (* a -3.0)))
(if (<= t_0 -3e-6)
(*
(* c (* a (/ -1.5 b)))
(cbrt (/ (/ 0.037037037037037035 a) (pow a 2.0))))
(if (<= t_0 -6e-11) t_0 (/ (* c -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.086) {
tmp = (b - sqrt(fma(b, b, (c * (a * -3.0))))) * (1.0 / (a * -3.0));
} else if (t_0 <= -3e-6) {
tmp = (c * (a * (-1.5 / b))) * cbrt(((0.037037037037037035 / a) / pow(a, 2.0)));
} else if (t_0 <= -6e-11) {
tmp = t_0;
} else {
tmp = (c * -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.086) tmp = Float64(Float64(b - sqrt(fma(b, b, Float64(c * Float64(a * -3.0))))) * Float64(1.0 / Float64(a * -3.0))); elseif (t_0 <= -3e-6) tmp = Float64(Float64(c * Float64(a * Float64(-1.5 / b))) * cbrt(Float64(Float64(0.037037037037037035 / a) / (a ^ 2.0)))); elseif (t_0 <= -6e-11) tmp = t_0; else tmp = Float64(Float64(c * -0.5) / 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.086], 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], If[LessEqual[t$95$0, -3e-6], N[(N[(c * N[(a * N[(-1.5 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(0.037037037037037035 / a), $MachinePrecision] / N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -6e-11], t$95$0, N[(N[(c * -0.5), $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.086:\\
\;\;\;\;\left(b - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}\right) \cdot \frac{1}{a \cdot -3}\\
\mathbf{elif}\;t_0 \leq -3 \cdot 10^{-6}:\\
\;\;\;\;\left(c \cdot \left(a \cdot \frac{-1.5}{b}\right)\right) \cdot \sqrt[3]{\frac{\frac{0.037037037037037035}{a}}{{a}^{2}}}\\
\mathbf{elif}\;t_0 \leq -6 \cdot 10^{-11}:\\
\;\;\;\;t_0\\
\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)) < -0.085999999999999993Initial program 70.4%
expm1-log1p-u70.3%
expm1-udef56.2%
associate-*l*56.2%
Applied egg-rr56.2%
frac-2neg56.2%
div-inv56.2%
Applied egg-rr70.5%
if -0.085999999999999993 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -3.0000000000000001e-6Initial program 55.1%
Simplified55.1%
Taylor expanded in b around inf 41.2%
associate-*r/41.2%
associate-*r*41.2%
Simplified41.2%
div-sub40.7%
sub-neg40.7%
div-inv40.5%
associate-*l*40.5%
associate-*r/40.5%
associate-*l/40.5%
*-commutative40.5%
metadata-eval40.5%
associate-/r*40.6%
metadata-eval40.6%
metadata-eval40.6%
div-inv40.9%
metadata-eval40.9%
associate-/r*40.8%
metadata-eval40.8%
metadata-eval40.8%
Applied egg-rr40.8%
sub-neg40.8%
distribute-rgt-out--41.2%
+-commutative41.2%
associate-+r-68.0%
*-commutative68.0%
+-inverses68.0%
+-rgt-identity68.0%
*-commutative68.0%
associate-*l*68.0%
associate-*r/68.0%
*-commutative68.0%
*-rgt-identity68.0%
associate-*r/68.0%
*-commutative68.0%
associate-*l*68.0%
associate-*r/68.0%
metadata-eval68.0%
Simplified68.0%
add-cbrt-cube68.1%
*-commutative68.1%
frac-times68.1%
metadata-eval68.1%
pow168.1%
pow168.1%
pow-sqr68.1%
metadata-eval68.1%
Applied egg-rr68.1%
associate-*r/68.1%
associate-*l/68.1%
metadata-eval68.1%
Simplified68.1%
if -3.0000000000000001e-6 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -6e-11Initial program 72.1%
if -6e-11 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) Initial program 12.3%
Taylor expanded in b around inf 94.7%
associate-*r/94.7%
*-commutative94.7%
Simplified94.7%
Final simplification85.6%
(FPCore (a b c) :precision binary64 (/ (fma -1.6875 (/ (pow (* a c) 3.0) (pow b 5.0)) (fma -1.5 (* c (/ a b)) (* -1.125 (/ (/ (* (* a c) (* a (/ c b))) b) b)))) (* a 3.0)))
double code(double a, double b, double c) {
return fma(-1.6875, (pow((a * c), 3.0) / pow(b, 5.0)), fma(-1.5, (c * (a / b)), (-1.125 * ((((a * c) * (a * (c / b))) / b) / b)))) / (a * 3.0);
}
function code(a, b, c) return Float64(fma(-1.6875, Float64((Float64(a * c) ^ 3.0) / (b ^ 5.0)), fma(-1.5, Float64(c * Float64(a / b)), Float64(-1.125 * Float64(Float64(Float64(Float64(a * c) * Float64(a * Float64(c / b))) / b) / b)))) / Float64(a * 3.0)) end
code[a_, b_, c_] := N[(N[(-1.6875 * N[(N[Power[N[(a * c), $MachinePrecision], 3.0], $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision] + N[(-1.5 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision] + N[(-1.125 * N[(N[(N[(N[(a * c), $MachinePrecision] * N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(-1.6875, \frac{{\left(a \cdot c\right)}^{3}}{{b}^{5}}, \mathsf{fma}\left(-1.5, c \cdot \frac{a}{b}, -1.125 \cdot \frac{\frac{\left(a \cdot c\right) \cdot \left(a \cdot \frac{c}{b}\right)}{b}}{b}\right)\right)}{a \cdot 3}
\end{array}
Initial program 32.1%
Taylor expanded in b around inf 93.1%
fma-def93.1%
cube-prod93.1%
fma-def93.1%
associate-/l*93.0%
associate-/r/93.1%
associate-/l*93.1%
associate-/r/93.1%
Simplified93.1%
associate-*l/93.1%
unpow393.1%
associate-/r*93.1%
unpow293.1%
unpow293.1%
swap-sqr93.1%
frac-times93.1%
associate-*l/93.1%
associate-*l/93.1%
pow193.1%
metadata-eval93.1%
pow193.1%
metadata-eval93.1%
pow-sqr93.1%
*-commutative93.1%
metadata-eval93.1%
metadata-eval93.1%
Applied egg-rr93.1%
unpow293.1%
associate-*r/93.1%
*-commutative93.1%
associate-*r/93.1%
associate-*r/93.1%
*-commutative93.1%
*-un-lft-identity93.1%
times-frac93.1%
/-rgt-identity93.1%
Applied egg-rr93.1%
Final simplification93.1%
(FPCore (a b c) :precision binary64 (+ (* -0.5 (/ c b)) (* -0.375 (/ (* a (pow c 2.0)) (pow b 3.0)))))
double code(double a, double b, double c) {
return (-0.5 * (c / b)) + (-0.375 * ((a * pow(c, 2.0)) / pow(b, 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 = ((-0.5d0) * (c / b)) + ((-0.375d0) * ((a * (c ** 2.0d0)) / (b ** 3.0d0)))
end function
public static double code(double a, double b, double c) {
return (-0.5 * (c / b)) + (-0.375 * ((a * Math.pow(c, 2.0)) / Math.pow(b, 3.0)));
}
def code(a, b, c): return (-0.5 * (c / b)) + (-0.375 * ((a * math.pow(c, 2.0)) / math.pow(b, 3.0)))
function code(a, b, c) return Float64(Float64(-0.5 * Float64(c / b)) + Float64(-0.375 * Float64(Float64(a * (c ^ 2.0)) / (b ^ 3.0)))) end
function tmp = code(a, b, c) tmp = (-0.5 * (c / b)) + (-0.375 * ((a * (c ^ 2.0)) / (b ^ 3.0))); end
code[a_, b_, c_] := 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}
\\
-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}}
\end{array}
Initial program 32.1%
Taylor expanded in b around inf 90.4%
Final simplification90.4%
(FPCore (a b c) :precision binary64 (/ -0.5 (/ b c)))
double code(double a, double b, double c) {
return -0.5 / (b / c);
}
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) / (b / c)
end function
public static double code(double a, double b, double c) {
return -0.5 / (b / c);
}
def code(a, b, c): return -0.5 / (b / c)
function code(a, b, c) return Float64(-0.5 / Float64(b / c)) end
function tmp = code(a, b, c) tmp = -0.5 / (b / c); end
code[a_, b_, c_] := N[(-0.5 / N[(b / c), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-0.5}{\frac{b}{c}}
\end{array}
Initial program 32.1%
Taylor expanded in b around inf 94.4%
Taylor expanded in a around 0 80.7%
associate-*r/80.7%
associate-/l*80.5%
Simplified80.5%
Final simplification80.5%
(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 32.1%
Taylor expanded in b around inf 80.7%
associate-*r/80.7%
*-commutative80.7%
Simplified80.7%
Final simplification80.7%
herbie shell --seed 2023336
(FPCore (a b c)
:name "Cubic critical, medium range"
:precision binary64
:pre (and (and (and (< 1.1102230246251565e-16 a) (< a 9007199254740992.0)) (and (< 1.1102230246251565e-16 b) (< b 9007199254740992.0))) (and (< 1.1102230246251565e-16 c) (< c 9007199254740992.0)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))