
(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 (/ (* (/ c a) -0.3333333333333333) (- (* (/ 0.3333333333333333 a) (sqrt (fma (* -3.0 c) a (* b b)))) (/ b (* -3.0 a)))))
double code(double a, double b, double c) {
return ((c / a) * -0.3333333333333333) / (((0.3333333333333333 / a) * sqrt(fma((-3.0 * c), a, (b * b)))) - (b / (-3.0 * a)));
}
function code(a, b, c) return Float64(Float64(Float64(c / a) * -0.3333333333333333) / Float64(Float64(Float64(0.3333333333333333 / a) * sqrt(fma(Float64(-3.0 * c), a, Float64(b * b)))) - Float64(b / Float64(-3.0 * a)))) end
code[a_, b_, c_] := N[(N[(N[(c / a), $MachinePrecision] * -0.3333333333333333), $MachinePrecision] / N[(N[(N[(0.3333333333333333 / a), $MachinePrecision] * N[Sqrt[N[(N[(-3.0 * c), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(b / N[(-3.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{c}{a} \cdot -0.3333333333333333}{\frac{0.3333333333333333}{a} \cdot \sqrt{\mathsf{fma}\left(-3 \cdot c, a, b \cdot b\right)} - \frac{b}{-3 \cdot a}}
\end{array}
Initial program 52.6%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
div-subN/A
lower--.f64N/A
Applied rewrites51.7%
lift--.f64N/A
sub-negN/A
flip-+N/A
lower-/.f64N/A
Applied rewrites52.2%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f6499.1
Applied rewrites99.1%
(FPCore (a b c) :precision binary64 (if (<= (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)) -5e-6) (/ (+ (- b) (sqrt (fma b b (* (* -3.0 a) c)))) (* 3.0 a)) (* -0.5 (/ c b))))
double code(double a, double b, double c) {
double tmp;
if (((-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)) <= -5e-6) {
tmp = (-b + sqrt(fma(b, b, ((-3.0 * a) * c)))) / (3.0 * a);
} else {
tmp = -0.5 * (c / b);
}
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)) <= -5e-6) tmp = Float64(Float64(Float64(-b) + sqrt(fma(b, b, Float64(Float64(-3.0 * a) * c)))) / Float64(3.0 * a)); else tmp = Float64(-0.5 * Float64(c / b)); 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], -5e-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[(-0.5 * N[(c / b), $MachinePrecision]), $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 -5 \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}:\\
\;\;\;\;-0.5 \cdot \frac{c}{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)) < -5.00000000000000041e-6Initial program 71.8%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval71.9
Applied rewrites71.9%
if -5.00000000000000041e-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
lower-*.f64N/A
lower-/.f6483.4
Applied rewrites83.4%
(FPCore (a b c) :precision binary64 (if (<= (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)) -5e-6) (/ (- (sqrt (fma (* -3.0 c) a (* b b))) b) (* a 3.0)) (* -0.5 (/ c b))))
double code(double a, double b, double c) {
double tmp;
if (((-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)) <= -5e-6) {
tmp = (sqrt(fma((-3.0 * c), a, (b * b))) - b) / (a * 3.0);
} else {
tmp = -0.5 * (c / b);
}
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)) <= -5e-6) tmp = Float64(Float64(sqrt(fma(Float64(-3.0 * c), a, Float64(b * b))) - b) / Float64(a * 3.0)); else tmp = Float64(-0.5 * Float64(c / b)); 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], -5e-6], N[(N[(N[Sqrt[N[(N[(-3.0 * c), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(c / b), $MachinePrecision]), $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 -5 \cdot 10^{-6}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-3 \cdot c, a, b \cdot b\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{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)) < -5.00000000000000041e-6Initial program 71.8%
Applied rewrites71.8%
if -5.00000000000000041e-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
lower-*.f64N/A
lower-/.f6483.4
Applied rewrites83.4%
(FPCore (a b c) :precision binary64 (if (<= (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)) -5e-6) (* (/ 0.3333333333333333 a) (- (sqrt (fma (* -3.0 c) a (* b b))) b)) (* -0.5 (/ c b))))
double code(double a, double b, double c) {
double tmp;
if (((-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)) <= -5e-6) {
tmp = (0.3333333333333333 / a) * (sqrt(fma((-3.0 * c), a, (b * b))) - b);
} else {
tmp = -0.5 * (c / b);
}
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)) <= -5e-6) tmp = Float64(Float64(0.3333333333333333 / a) * Float64(sqrt(fma(Float64(-3.0 * c), a, Float64(b * b))) - b)); else tmp = Float64(-0.5 * Float64(c / b)); 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], -5e-6], N[(N[(0.3333333333333333 / a), $MachinePrecision] * N[(N[Sqrt[N[(N[(-3.0 * c), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(c / b), $MachinePrecision]), $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 -5 \cdot 10^{-6}:\\
\;\;\;\;\frac{0.3333333333333333}{a} \cdot \left(\sqrt{\mathsf{fma}\left(-3 \cdot c, a, b \cdot b\right)} - b\right)\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{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)) < -5.00000000000000041e-6Initial program 71.8%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
metadata-eval71.8
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6471.8
Applied rewrites71.8%
if -5.00000000000000041e-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
lower-*.f64N/A
lower-/.f6483.4
Applied rewrites83.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma (* -3.0 a) c (* b b))))
(if (<= b 7.6)
(/ (/ (- t_0 (* b b)) (* (+ (sqrt t_0) b) a)) 3.0)
(/ (fma (* -0.375 a) (/ (* c c) (* b b)) (* -0.5 c)) b))))
double code(double a, double b, double c) {
double t_0 = fma((-3.0 * a), c, (b * b));
double tmp;
if (b <= 7.6) {
tmp = ((t_0 - (b * b)) / ((sqrt(t_0) + b) * a)) / 3.0;
} else {
tmp = fma((-0.375 * a), ((c * c) / (b * b)), (-0.5 * c)) / b;
}
return tmp;
}
function code(a, b, c) t_0 = fma(Float64(-3.0 * a), c, Float64(b * b)) tmp = 0.0 if (b <= 7.6) tmp = Float64(Float64(Float64(t_0 - Float64(b * b)) / Float64(Float64(sqrt(t_0) + b) * a)) / 3.0); else tmp = Float64(fma(Float64(-0.375 * a), Float64(Float64(c * c) / Float64(b * b)), Float64(-0.5 * c)) / b); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(-3.0 * a), $MachinePrecision] * c + N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 7.6], N[(N[(N[(t$95$0 - N[(b * b), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Sqrt[t$95$0], $MachinePrecision] + b), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / 3.0), $MachinePrecision], N[(N[(N[(-0.375 * a), $MachinePrecision] * N[(N[(c * c), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] + N[(-0.5 * c), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)\\
\mathbf{if}\;b \leq 7.6:\\
\;\;\;\;\frac{\frac{t\_0 - b \cdot b}{\left(\sqrt{t\_0} + b\right) \cdot a}}{3}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-0.375 \cdot a, \frac{c \cdot c}{b \cdot b}, -0.5 \cdot c\right)}{b}\\
\end{array}
\end{array}
if b < 7.5999999999999996Initial program 79.2%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lift-*.f64N/A
associate-/l/N/A
inv-powN/A
associate-*l/N/A
lower-/.f64N/A
Applied rewrites79.2%
Applied rewrites80.8%
if 7.5999999999999996 < b Initial program 45.8%
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-*.f6489.8
Applied rewrites89.8%
Applied rewrites89.8%
Final simplification88.0%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma (* -3.0 a) c (* b b))))
(if (<= b 7.6)
(/ (- (* b b) t_0) (* (* 3.0 a) (- (- b) (sqrt t_0))))
(/ (fma (* -0.375 a) (/ (* c c) (* b b)) (* -0.5 c)) b))))
double code(double a, double b, double c) {
double t_0 = fma((-3.0 * a), c, (b * b));
double tmp;
if (b <= 7.6) {
tmp = ((b * b) - t_0) / ((3.0 * a) * (-b - sqrt(t_0)));
} else {
tmp = fma((-0.375 * a), ((c * c) / (b * b)), (-0.5 * c)) / b;
}
return tmp;
}
function code(a, b, c) t_0 = fma(Float64(-3.0 * a), c, Float64(b * b)) tmp = 0.0 if (b <= 7.6) tmp = Float64(Float64(Float64(b * b) - t_0) / Float64(Float64(3.0 * a) * Float64(Float64(-b) - sqrt(t_0)))); else tmp = Float64(fma(Float64(-0.375 * a), Float64(Float64(c * c) / Float64(b * b)), Float64(-0.5 * c)) / b); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(-3.0 * a), $MachinePrecision] * c + N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 7.6], N[(N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(3.0 * a), $MachinePrecision] * N[((-b) - N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(-0.375 * a), $MachinePrecision] * N[(N[(c * c), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] + N[(-0.5 * c), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)\\
\mathbf{if}\;b \leq 7.6:\\
\;\;\;\;\frac{b \cdot b - t\_0}{\left(3 \cdot a\right) \cdot \left(\left(-b\right) - \sqrt{t\_0}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-0.375 \cdot a, \frac{c \cdot c}{b \cdot b}, -0.5 \cdot c\right)}{b}\\
\end{array}
\end{array}
if b < 7.5999999999999996Initial program 79.2%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lift-*.f64N/A
associate-/l/N/A
inv-powN/A
associate-*l/N/A
lower-/.f64N/A
Applied rewrites79.2%
Applied rewrites80.7%
if 7.5999999999999996 < b Initial program 45.8%
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-*.f6489.8
Applied rewrites89.8%
Applied rewrites89.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma (* -3.0 c) a (* b b))))
(if (<= b 7.6)
(/ (- t_0 (* b b)) (* (* a 3.0) (+ (sqrt t_0) b)))
(/ (fma (* -0.375 a) (/ (* c c) (* b b)) (* -0.5 c)) b))))
double code(double a, double b, double c) {
double t_0 = fma((-3.0 * c), a, (b * b));
double tmp;
if (b <= 7.6) {
tmp = (t_0 - (b * b)) / ((a * 3.0) * (sqrt(t_0) + b));
} else {
tmp = fma((-0.375 * a), ((c * c) / (b * b)), (-0.5 * c)) / b;
}
return tmp;
}
function code(a, b, c) t_0 = fma(Float64(-3.0 * c), a, Float64(b * b)) tmp = 0.0 if (b <= 7.6) tmp = Float64(Float64(t_0 - Float64(b * b)) / Float64(Float64(a * 3.0) * Float64(sqrt(t_0) + b))); else tmp = Float64(fma(Float64(-0.375 * a), Float64(Float64(c * c) / Float64(b * b)), Float64(-0.5 * c)) / b); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(-3.0 * c), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 7.6], N[(N[(t$95$0 - N[(b * b), $MachinePrecision]), $MachinePrecision] / N[(N[(a * 3.0), $MachinePrecision] * N[(N[Sqrt[t$95$0], $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(-0.375 * a), $MachinePrecision] * N[(N[(c * c), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] + N[(-0.5 * c), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-3 \cdot c, a, b \cdot b\right)\\
\mathbf{if}\;b \leq 7.6:\\
\;\;\;\;\frac{t\_0 - b \cdot b}{\left(a \cdot 3\right) \cdot \left(\sqrt{t\_0} + b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-0.375 \cdot a, \frac{c \cdot c}{b \cdot b}, -0.5 \cdot c\right)}{b}\\
\end{array}
\end{array}
if b < 7.5999999999999996Initial program 79.2%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
div-subN/A
lower--.f64N/A
Applied rewrites78.2%
lift--.f64N/A
lift-/.f64N/A
lift-/.f64N/A
sub-divN/A
flip--N/A
associate-/l/N/A
lower-/.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
lift-*.f64N/A
lower--.f64N/A
Applied rewrites80.7%
if 7.5999999999999996 < b Initial program 45.8%
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-*.f6489.8
Applied rewrites89.8%
Applied rewrites89.8%
(FPCore (a b c) :precision binary64 (if (<= b 7.6) (/ (+ (- b) (sqrt (fma b b (* (* -3.0 a) c)))) (* 3.0 a)) (/ (fma (* -0.375 a) (/ (* c c) (* b b)) (* -0.5 c)) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 7.6) {
tmp = (-b + sqrt(fma(b, b, ((-3.0 * a) * c)))) / (3.0 * a);
} else {
tmp = fma((-0.375 * a), ((c * c) / (b * b)), (-0.5 * c)) / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 7.6) tmp = Float64(Float64(Float64(-b) + sqrt(fma(b, b, Float64(Float64(-3.0 * a) * c)))) / Float64(3.0 * a)); else tmp = Float64(fma(Float64(-0.375 * a), Float64(Float64(c * c) / Float64(b * b)), Float64(-0.5 * c)) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 7.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[(N[(-0.375 * a), $MachinePrecision] * N[(N[(c * c), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] + N[(-0.5 * c), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.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{\mathsf{fma}\left(-0.375 \cdot a, \frac{c \cdot c}{b \cdot b}, -0.5 \cdot c\right)}{b}\\
\end{array}
\end{array}
if b < 7.5999999999999996Initial program 79.2%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval79.3
Applied rewrites79.3%
if 7.5999999999999996 < b Initial program 45.8%
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-*.f6489.8
Applied rewrites89.8%
Applied rewrites89.8%
(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 52.6%
Taylor expanded in a around 0
lower-*.f64N/A
lower-/.f6467.6
Applied rewrites67.6%
(FPCore (a b c) :precision binary64 0.0)
double code(double a, double b, double c) {
return 0.0;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = 0.0d0
end function
public static double code(double a, double b, double c) {
return 0.0;
}
def code(a, b, c): return 0.0
function code(a, b, c) return 0.0 end
function tmp = code(a, b, c) tmp = 0.0; end
code[a_, b_, c_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 52.6%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
div-subN/A
lower--.f64N/A
Applied rewrites51.7%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
metadata-evalN/A
lower-/.f6451.5
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
metadata-evalN/A
lower-/.f6453.2
Applied rewrites53.2%
Taylor expanded in c around 0
distribute-rgt-outN/A
metadata-evalN/A
mul0-rgt3.2
Applied rewrites3.2%
herbie shell --seed 2024318
(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)))