
(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
(fma
(/
(fma
(* -1.0546875 (pow c 4.0))
(* a a)
(* (* (fma (* a c) -0.5625 (* (* b b) -0.375)) (* c c)) (* b b)))
(pow b 7.0))
a
(* (/ c b) -0.5)))
double code(double a, double b, double c) {
return fma((fma((-1.0546875 * pow(c, 4.0)), (a * a), ((fma((a * c), -0.5625, ((b * b) * -0.375)) * (c * c)) * (b * b))) / pow(b, 7.0)), a, ((c / b) * -0.5));
}
function code(a, b, c) return fma(Float64(fma(Float64(-1.0546875 * (c ^ 4.0)), Float64(a * a), Float64(Float64(fma(Float64(a * c), -0.5625, Float64(Float64(b * b) * -0.375)) * Float64(c * c)) * Float64(b * b))) / (b ^ 7.0)), a, Float64(Float64(c / b) * -0.5)) end
code[a_, b_, c_] := N[(N[(N[(N[(-1.0546875 * N[Power[c, 4.0], $MachinePrecision]), $MachinePrecision] * N[(a * a), $MachinePrecision] + N[(N[(N[(N[(a * c), $MachinePrecision] * -0.5625 + N[(N[(b * b), $MachinePrecision] * -0.375), $MachinePrecision]), $MachinePrecision] * N[(c * c), $MachinePrecision]), $MachinePrecision] * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision] * a + N[(N[(c / b), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{\mathsf{fma}\left(-1.0546875 \cdot {c}^{4}, a \cdot a, \left(\mathsf{fma}\left(a \cdot c, -0.5625, \left(b \cdot b\right) \cdot -0.375\right) \cdot \left(c \cdot c\right)\right) \cdot \left(b \cdot b\right)\right)}{{b}^{7}}, a, \frac{c}{b} \cdot -0.5\right)
\end{array}
Initial program 57.1%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites91.1%
Taylor expanded in b around 0
Applied rewrites91.1%
Taylor expanded in a around 0
Applied rewrites91.1%
Final simplification91.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* (fma -3.0 c (/ (* b b) a)) a)))
(if (<= b 75.0)
(/ (- (* b b) t_0) (* (+ b (sqrt t_0)) (- (* a 3.0))))
(fma
(* (fma (* a (/ c (pow b 5.0))) -0.5625 (/ -0.375 (pow b 3.0))) (* c c))
a
(* (/ c b) -0.5)))))
double code(double a, double b, double c) {
double t_0 = fma(-3.0, c, ((b * b) / a)) * a;
double tmp;
if (b <= 75.0) {
tmp = ((b * b) - t_0) / ((b + sqrt(t_0)) * -(a * 3.0));
} else {
tmp = fma((fma((a * (c / pow(b, 5.0))), -0.5625, (-0.375 / pow(b, 3.0))) * (c * c)), a, ((c / b) * -0.5));
}
return tmp;
}
function code(a, b, c) t_0 = Float64(fma(-3.0, c, Float64(Float64(b * b) / a)) * a) tmp = 0.0 if (b <= 75.0) tmp = Float64(Float64(Float64(b * b) - t_0) / Float64(Float64(b + sqrt(t_0)) * Float64(-Float64(a * 3.0)))); else tmp = fma(Float64(fma(Float64(a * Float64(c / (b ^ 5.0))), -0.5625, Float64(-0.375 / (b ^ 3.0))) * Float64(c * c)), a, Float64(Float64(c / b) * -0.5)); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(-3.0 * c + N[(N[(b * b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision]}, If[LessEqual[b, 75.0], N[(N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision] * (-N[(a * 3.0), $MachinePrecision])), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(a * N[(c / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.5625 + N[(-0.375 / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(c * c), $MachinePrecision]), $MachinePrecision] * a + N[(N[(c / b), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-3, c, \frac{b \cdot b}{a}\right) \cdot a\\
\mathbf{if}\;b \leq 75:\\
\;\;\;\;\frac{b \cdot b - t\_0}{\left(b + \sqrt{t\_0}\right) \cdot \left(-a \cdot 3\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(a \cdot \frac{c}{{b}^{5}}, -0.5625, \frac{-0.375}{{b}^{3}}\right) \cdot \left(c \cdot c\right), a, \frac{c}{b} \cdot -0.5\right)\\
\end{array}
\end{array}
if b < 75Initial program 81.4%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6481.1
Applied rewrites81.1%
lift-/.f64N/A
lift-+.f64N/A
flip-+N/A
associate-/l/N/A
lower-/.f64N/A
Applied rewrites82.1%
if 75 < b Initial program 49.1%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites94.9%
Taylor expanded in b around 0
Applied rewrites94.9%
Taylor expanded in a around 0
Applied rewrites94.9%
Taylor expanded in c around 0
Applied rewrites92.6%
Final simplification90.0%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* (fma -3.0 c (/ (* b b) a)) a)))
(if (<= b 75.0)
(/ (- (* b b) t_0) (* (+ b (sqrt t_0)) (- (* a 3.0))))
(*
(fma
(fma (* c -0.5625) (* a (/ a (pow b 5.0))) (* (/ a (pow b 3.0)) -0.375))
c
(/ -0.5 b))
c))))
double code(double a, double b, double c) {
double t_0 = fma(-3.0, c, ((b * b) / a)) * a;
double tmp;
if (b <= 75.0) {
tmp = ((b * b) - t_0) / ((b + sqrt(t_0)) * -(a * 3.0));
} else {
tmp = fma(fma((c * -0.5625), (a * (a / pow(b, 5.0))), ((a / pow(b, 3.0)) * -0.375)), c, (-0.5 / b)) * c;
}
return tmp;
}
function code(a, b, c) t_0 = Float64(fma(-3.0, c, Float64(Float64(b * b) / a)) * a) tmp = 0.0 if (b <= 75.0) tmp = Float64(Float64(Float64(b * b) - t_0) / Float64(Float64(b + sqrt(t_0)) * Float64(-Float64(a * 3.0)))); else tmp = Float64(fma(fma(Float64(c * -0.5625), Float64(a * Float64(a / (b ^ 5.0))), Float64(Float64(a / (b ^ 3.0)) * -0.375)), c, Float64(-0.5 / b)) * c); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(-3.0 * c + N[(N[(b * b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision]}, If[LessEqual[b, 75.0], N[(N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision] * (-N[(a * 3.0), $MachinePrecision])), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(c * -0.5625), $MachinePrecision] * N[(a * N[(a / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(a / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision] * -0.375), $MachinePrecision]), $MachinePrecision] * c + N[(-0.5 / b), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-3, c, \frac{b \cdot b}{a}\right) \cdot a\\
\mathbf{if}\;b \leq 75:\\
\;\;\;\;\frac{b \cdot b - t\_0}{\left(b + \sqrt{t\_0}\right) \cdot \left(-a \cdot 3\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(c \cdot -0.5625, a \cdot \frac{a}{{b}^{5}}, \frac{a}{{b}^{3}} \cdot -0.375\right), c, \frac{-0.5}{b}\right) \cdot c\\
\end{array}
\end{array}
if b < 75Initial program 81.4%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6481.1
Applied rewrites81.1%
lift-/.f64N/A
lift-+.f64N/A
flip-+N/A
associate-/l/N/A
lower-/.f64N/A
Applied rewrites82.1%
if 75 < b Initial program 49.1%
Taylor expanded in c around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites92.3%
Final simplification89.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* (fma -3.0 c (/ (* b b) a)) a)))
(if (<= b 75.0)
(/ (- (* b b) t_0) (* (+ b (sqrt t_0)) (- (* a 3.0))))
(fma (* -0.375 a) (* c (/ c (pow b 3.0))) (* (/ c b) -0.5)))))
double code(double a, double b, double c) {
double t_0 = fma(-3.0, c, ((b * b) / a)) * a;
double tmp;
if (b <= 75.0) {
tmp = ((b * b) - t_0) / ((b + sqrt(t_0)) * -(a * 3.0));
} else {
tmp = fma((-0.375 * a), (c * (c / pow(b, 3.0))), ((c / b) * -0.5));
}
return tmp;
}
function code(a, b, c) t_0 = Float64(fma(-3.0, c, Float64(Float64(b * b) / a)) * a) tmp = 0.0 if (b <= 75.0) tmp = Float64(Float64(Float64(b * b) - t_0) / Float64(Float64(b + sqrt(t_0)) * Float64(-Float64(a * 3.0)))); else tmp = fma(Float64(-0.375 * a), Float64(c * Float64(c / (b ^ 3.0))), Float64(Float64(c / b) * -0.5)); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(-3.0 * c + N[(N[(b * b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision]}, If[LessEqual[b, 75.0], N[(N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision] * (-N[(a * 3.0), $MachinePrecision])), $MachinePrecision]), $MachinePrecision], N[(N[(-0.375 * a), $MachinePrecision] * N[(c * N[(c / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(c / b), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-3, c, \frac{b \cdot b}{a}\right) \cdot a\\
\mathbf{if}\;b \leq 75:\\
\;\;\;\;\frac{b \cdot b - t\_0}{\left(b + \sqrt{t\_0}\right) \cdot \left(-a \cdot 3\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-0.375 \cdot a, c \cdot \frac{c}{{b}^{3}}, \frac{c}{b} \cdot -0.5\right)\\
\end{array}
\end{array}
if b < 75Initial program 81.4%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6481.1
Applied rewrites81.1%
lift-/.f64N/A
lift-+.f64N/A
flip-+N/A
associate-/l/N/A
lower-/.f64N/A
Applied rewrites82.1%
if 75 < b Initial program 49.1%
Taylor expanded in a around 0
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-pow.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6488.0
Applied rewrites88.0%
Final simplification86.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* (fma -3.0 c (/ (* b b) a)) a)))
(if (<= b 75.0)
(/ (- (* b b) t_0) (* (+ b (sqrt t_0)) (- (* a 3.0))))
(/ (fma (/ (* -0.375 a) b) (/ (* c c) b) (* -0.5 c)) b))))
double code(double a, double b, double c) {
double t_0 = fma(-3.0, c, ((b * b) / a)) * a;
double tmp;
if (b <= 75.0) {
tmp = ((b * b) - t_0) / ((b + sqrt(t_0)) * -(a * 3.0));
} else {
tmp = fma(((-0.375 * a) / b), ((c * c) / b), (-0.5 * c)) / b;
}
return tmp;
}
function code(a, b, c) t_0 = Float64(fma(-3.0, c, Float64(Float64(b * b) / a)) * a) tmp = 0.0 if (b <= 75.0) tmp = Float64(Float64(Float64(b * b) - t_0) / Float64(Float64(b + sqrt(t_0)) * Float64(-Float64(a * 3.0)))); else tmp = Float64(fma(Float64(Float64(-0.375 * a) / b), Float64(Float64(c * c) / b), Float64(-0.5 * c)) / b); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(-3.0 * c + N[(N[(b * b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision]}, If[LessEqual[b, 75.0], N[(N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision] * (-N[(a * 3.0), $MachinePrecision])), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(-0.375 * a), $MachinePrecision] / b), $MachinePrecision] * N[(N[(c * c), $MachinePrecision] / b), $MachinePrecision] + N[(-0.5 * c), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-3, c, \frac{b \cdot b}{a}\right) \cdot a\\
\mathbf{if}\;b \leq 75:\\
\;\;\;\;\frac{b \cdot b - t\_0}{\left(b + \sqrt{t\_0}\right) \cdot \left(-a \cdot 3\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{-0.375 \cdot a}{b}, \frac{c \cdot c}{b}, -0.5 \cdot c\right)}{b}\\
\end{array}
\end{array}
if b < 75Initial program 81.4%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6481.1
Applied rewrites81.1%
lift-/.f64N/A
lift-+.f64N/A
flip-+N/A
associate-/l/N/A
lower-/.f64N/A
Applied rewrites82.1%
if 75 < b Initial program 49.1%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites94.9%
Taylor expanded in b around inf
lower-/.f64N/A
+-commutativeN/A
associate-*r/N/A
associate-*r*N/A
unpow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6487.8
Applied rewrites87.8%
Final simplification86.4%
(FPCore (a b c) :precision binary64 (if (<= (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)) -1.2e-6) (/ (+ (- b) (sqrt (fma b b (* (* -3.0 a) c)))) (* 3.0 a)) (* (/ c b) -0.5)))
double code(double a, double b, double c) {
double tmp;
if (((-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)) <= -1.2e-6) {
tmp = (-b + sqrt(fma(b, b, ((-3.0 * a) * c)))) / (3.0 * a);
} else {
tmp = (c / b) * -0.5;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a)) <= -1.2e-6) tmp = Float64(Float64(Float64(-b) + sqrt(fma(b, b, Float64(Float64(-3.0 * a) * c)))) / Float64(3.0 * a)); else tmp = Float64(Float64(c / b) * -0.5); end return tmp end
code[a_, b_, c_] := If[LessEqual[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], -1.2e-6], N[(N[((-b) + N[Sqrt[N[(b * b + N[(N[(-3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \leq -1.2 \cdot 10^{-6}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot a\right) \cdot c\right)}}{3 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot -0.5\\
\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)) < -1.1999999999999999e-6Initial program 73.5%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval73.6
Applied rewrites73.6%
if -1.1999999999999999e-6 < (/.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 33.8%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f6482.4
Applied rewrites82.4%
Final simplification77.3%
(FPCore (a b c) :precision binary64 (if (<= b 75.0) (/ (+ (- b) (sqrt (fma (* -3.0 a) c (* b b)))) (* 3.0 a)) (/ (fma (/ (* -0.375 a) b) (/ (* c c) b) (* -0.5 c)) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 75.0) {
tmp = (-b + sqrt(fma((-3.0 * a), c, (b * b)))) / (3.0 * a);
} else {
tmp = fma(((-0.375 * a) / b), ((c * c) / b), (-0.5 * c)) / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 75.0) tmp = Float64(Float64(Float64(-b) + sqrt(fma(Float64(-3.0 * a), c, Float64(b * b)))) / Float64(3.0 * a)); else tmp = Float64(fma(Float64(Float64(-0.375 * a) / b), Float64(Float64(c * c) / b), Float64(-0.5 * c)) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 75.0], N[(N[((-b) + N[Sqrt[N[(N[(-3.0 * a), $MachinePrecision] * c + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(-0.375 * a), $MachinePrecision] / b), $MachinePrecision] * N[(N[(c * c), $MachinePrecision] / b), $MachinePrecision] + N[(-0.5 * c), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 75:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)}}{3 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{-0.375 \cdot a}{b}, \frac{c \cdot c}{b}, -0.5 \cdot c\right)}{b}\\
\end{array}
\end{array}
if b < 75Initial program 81.4%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval81.4
Applied rewrites81.4%
if 75 < b Initial program 49.1%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites94.9%
Taylor expanded in b around inf
lower-/.f64N/A
+-commutativeN/A
associate-*r/N/A
associate-*r*N/A
unpow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6487.8
Applied rewrites87.8%
Final simplification86.3%
(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 57.1%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f6463.1
Applied rewrites63.1%
Final simplification63.1%
(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(c * Float64(-0.5 / b)) end
function tmp = code(a, b, c) tmp = c * (-0.5 / b); end
code[a_, b_, c_] := N[(c * N[(-0.5 / b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
c \cdot \frac{-0.5}{b}
\end{array}
Initial program 57.1%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f6463.1
Applied rewrites63.1%
Applied rewrites63.1%
Final simplification63.1%
(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 57.1%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6456.8
Applied rewrites56.8%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
lift-*.f64N/A
associate-/r*N/A
lift-*.f64N/A
associate-/r*N/A
frac-addN/A
lower-/.f64N/A
Applied rewrites56.9%
Taylor expanded in a around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
+-inversesN/A
div03.2
Applied rewrites3.2%
herbie shell --seed 2024326
(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)))