
(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 (/ (/ (* -3.0 (* c a)) (+ b (sqrt (* b (fma (* a (/ c (* b b))) (* -3.0 b) b))))) (* a 3.0)))
double code(double a, double b, double c) {
return ((-3.0 * (c * a)) / (b + sqrt((b * fma((a * (c / (b * b))), (-3.0 * b), b))))) / (a * 3.0);
}
function code(a, b, c) return Float64(Float64(Float64(-3.0 * Float64(c * a)) / Float64(b + sqrt(Float64(b * fma(Float64(a * Float64(c / Float64(b * b))), Float64(-3.0 * b), b))))) / Float64(a * 3.0)) end
code[a_, b_, c_] := N[(N[(N[(-3.0 * N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(b * N[(N[(a * N[(c / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-3.0 * b), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{-3 \cdot \left(c \cdot a\right)}{b + \sqrt{b \cdot \mathsf{fma}\left(a \cdot \frac{c}{b \cdot b}, -3 \cdot b, b\right)}}}{a \cdot 3}
\end{array}
Initial program 55.9%
Taylor expanded in b around inf
unpow2N/A
associate-*l*N/A
lower-*.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6456.0
Applied rewrites56.0%
lift-neg.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
unpow1N/A
sqrt-pow1N/A
metadata-evalN/A
pow1/2N/A
lift-sqrt.f64N/A
Applied rewrites56.7%
Taylor expanded in b around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6499.1
Applied rewrites99.1%
Final simplification99.1%
(FPCore (a b c)
:precision binary64
(if (<= b 12.0)
(/ (- (sqrt (fma b b (* c (* a -3.0)))) b) (* a 3.0))
(*
c
(fma
c
(/ (fma -0.5625 (/ (* a (* c a)) (* b b)) (* a -0.375)) (* b (* b b)))
(/ -0.5 b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= 12.0) {
tmp = (sqrt(fma(b, b, (c * (a * -3.0)))) - b) / (a * 3.0);
} else {
tmp = c * fma(c, (fma(-0.5625, ((a * (c * a)) / (b * b)), (a * -0.375)) / (b * (b * b))), (-0.5 / b));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 12.0) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -3.0)))) - b) / Float64(a * 3.0)); else tmp = Float64(c * fma(c, Float64(fma(-0.5625, Float64(Float64(a * Float64(c * a)) / Float64(b * b)), Float64(a * -0.375)) / Float64(b * Float64(b * b))), Float64(-0.5 / b))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 12.0], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(c * N[(c * N[(N[(-0.5625 * N[(N[(a * N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] + N[(a * -0.375), $MachinePrecision]), $MachinePrecision] / N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.5 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 12:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;c \cdot \mathsf{fma}\left(c, \frac{\mathsf{fma}\left(-0.5625, \frac{a \cdot \left(c \cdot a\right)}{b \cdot b}, a \cdot -0.375\right)}{b \cdot \left(b \cdot b\right)}, \frac{-0.5}{b}\right)\\
\end{array}
\end{array}
if b < 12Initial program 84.7%
Taylor expanded in b around inf
unpow2N/A
associate-*l*N/A
lower-*.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6484.7
Applied rewrites84.7%
Taylor expanded in b around 0
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6484.8
Applied rewrites84.8%
if 12 < b Initial program 47.3%
Taylor expanded in c around 0
lower-*.f64N/A
sub-negN/A
associate-*r/N/A
associate-*r*N/A
associate-*l/N/A
associate-*r/N/A
+-commutativeN/A
lower-fma.f64N/A
Applied rewrites91.0%
Taylor expanded in b around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6491.0
Applied rewrites91.0%
Final simplification89.6%
(FPCore (a b c) :precision binary64 (if (<= b 1200.0) (/ (- (sqrt (fma b b (* c (* a -3.0)))) b) (* a 3.0)) (fma a (/ (* -0.375 (* c c)) (* b (* b b))) (* -0.5 (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= 1200.0) {
tmp = (sqrt(fma(b, b, (c * (a * -3.0)))) - b) / (a * 3.0);
} else {
tmp = fma(a, ((-0.375 * (c * c)) / (b * (b * b))), (-0.5 * (c / b)));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 1200.0) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -3.0)))) - b) / Float64(a * 3.0)); else tmp = fma(a, Float64(Float64(-0.375 * Float64(c * c)) / Float64(b * Float64(b * b))), Float64(-0.5 * Float64(c / b))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 1200.0], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(a * N[(N[(-0.375 * N[(c * c), $MachinePrecision]), $MachinePrecision] / N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1200:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, \frac{-0.375 \cdot \left(c \cdot c\right)}{b \cdot \left(b \cdot b\right)}, -0.5 \cdot \frac{c}{b}\right)\\
\end{array}
\end{array}
if b < 1200Initial program 78.7%
Taylor expanded in b around inf
unpow2N/A
associate-*l*N/A
lower-*.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6478.7
Applied rewrites78.7%
Taylor expanded in b around 0
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6478.8
Applied rewrites78.8%
if 1200 < b Initial program 40.4%
Taylor expanded in a around 0
Applied rewrites97.3%
Taylor expanded in a around 0
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6491.8
Applied rewrites91.8%
Final simplification86.5%
(FPCore (a b c) :precision binary64 (if (<= b 1200.0) (/ (- (sqrt (fma b b (* c (* a -3.0)))) b) (* a 3.0)) (/ (fma a (/ (* -0.375 (* c c)) (* b b)) (* c -0.5)) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1200.0) {
tmp = (sqrt(fma(b, b, (c * (a * -3.0)))) - b) / (a * 3.0);
} else {
tmp = fma(a, ((-0.375 * (c * c)) / (b * b)), (c * -0.5)) / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 1200.0) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -3.0)))) - b) / Float64(a * 3.0)); else tmp = Float64(fma(a, Float64(Float64(-0.375 * Float64(c * c)) / Float64(b * b)), Float64(c * -0.5)) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 1200.0], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(a * N[(N[(-0.375 * N[(c * c), $MachinePrecision]), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] + N[(c * -0.5), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1200:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{-0.375 \cdot \left(c \cdot c\right)}{b \cdot b}, c \cdot -0.5\right)}{b}\\
\end{array}
\end{array}
if b < 1200Initial program 78.7%
Taylor expanded in b around inf
unpow2N/A
associate-*l*N/A
lower-*.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6478.7
Applied rewrites78.7%
Taylor expanded in b around 0
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6478.8
Applied rewrites78.8%
if 1200 < b Initial program 40.4%
Taylor expanded in b around inf
lower-/.f64N/A
Applied rewrites91.7%
Final simplification86.5%
(FPCore (a b c) :precision binary64 (if (<= b 1200.0) (/ (- (sqrt (fma b b (* c (* a -3.0)))) b) (* a 3.0)) (/ (* c (fma (* c a) (/ -0.375 (* b b)) -0.5)) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1200.0) {
tmp = (sqrt(fma(b, b, (c * (a * -3.0)))) - b) / (a * 3.0);
} else {
tmp = (c * fma((c * a), (-0.375 / (b * b)), -0.5)) / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 1200.0) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -3.0)))) - b) / Float64(a * 3.0)); else tmp = Float64(Float64(c * fma(Float64(c * a), Float64(-0.375 / Float64(b * b)), -0.5)) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 1200.0], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * N[(N[(c * a), $MachinePrecision] * N[(-0.375 / N[(b * b), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1200:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \mathsf{fma}\left(c \cdot a, \frac{-0.375}{b \cdot b}, -0.5\right)}{b}\\
\end{array}
\end{array}
if b < 1200Initial program 78.7%
Taylor expanded in b around inf
unpow2N/A
associate-*l*N/A
lower-*.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6478.7
Applied rewrites78.7%
Taylor expanded in b around 0
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6478.8
Applied rewrites78.8%
if 1200 < b Initial program 40.4%
Taylor expanded in b around inf
lower-/.f64N/A
Applied rewrites91.7%
Taylor expanded in c around 0
lower-*.f64N/A
sub-negN/A
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6491.7
Applied rewrites91.7%
Final simplification86.4%
(FPCore (a b c) :precision binary64 (if (<= b 115.0) (/ (- (sqrt (fma b b (* a (* c -3.0)))) b) (* a 3.0)) (/ (* c (fma (* c a) (/ -0.375 (* b b)) -0.5)) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 115.0) {
tmp = (sqrt(fma(b, b, (a * (c * -3.0)))) - b) / (a * 3.0);
} else {
tmp = (c * fma((c * a), (-0.375 / (b * b)), -0.5)) / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 115.0) tmp = Float64(Float64(sqrt(fma(b, b, Float64(a * Float64(c * -3.0)))) - b) / Float64(a * 3.0)); else tmp = Float64(Float64(c * fma(Float64(c * a), Float64(-0.375 / Float64(b * b)), -0.5)) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 115.0], N[(N[(N[Sqrt[N[(b * b + N[(a * N[(c * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * N[(N[(c * a), $MachinePrecision] * N[(-0.375 / N[(b * b), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 115:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \mathsf{fma}\left(c \cdot a, \frac{-0.375}{b \cdot b}, -0.5\right)}{b}\\
\end{array}
\end{array}
if b < 115Initial program 81.9%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval81.9
Applied rewrites81.9%
if 115 < b Initial program 44.3%
Taylor expanded in b around inf
lower-/.f64N/A
Applied rewrites88.4%
Taylor expanded in c around 0
lower-*.f64N/A
sub-negN/A
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6488.4
Applied rewrites88.4%
Final simplification86.4%
(FPCore (a b c) :precision binary64 (if (<= b 115.0) (/ (- (sqrt (fma a (* c -3.0) (* b b))) b) (* a 3.0)) (/ (* c (fma (* c a) (/ -0.375 (* b b)) -0.5)) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 115.0) {
tmp = (sqrt(fma(a, (c * -3.0), (b * b))) - b) / (a * 3.0);
} else {
tmp = (c * fma((c * a), (-0.375 / (b * b)), -0.5)) / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 115.0) tmp = Float64(Float64(sqrt(fma(a, Float64(c * -3.0), Float64(b * b))) - b) / Float64(a * 3.0)); else tmp = Float64(Float64(c * fma(Float64(c * a), Float64(-0.375 / Float64(b * b)), -0.5)) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 115.0], N[(N[(N[Sqrt[N[(a * N[(c * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * N[(N[(c * a), $MachinePrecision] * N[(-0.375 / N[(b * b), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 115:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \mathsf{fma}\left(c \cdot a, \frac{-0.375}{b \cdot b}, -0.5\right)}{b}\\
\end{array}
\end{array}
if b < 115Initial program 81.9%
lift-neg.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6481.9
Applied rewrites81.9%
if 115 < b Initial program 44.3%
Taylor expanded in b around inf
lower-/.f64N/A
Applied rewrites88.4%
Taylor expanded in c around 0
lower-*.f64N/A
sub-negN/A
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6488.4
Applied rewrites88.4%
Final simplification86.4%
(FPCore (a b c) :precision binary64 (if (<= b 115.0) (* (/ -0.3333333333333333 a) (- b (sqrt (fma a (* c -3.0) (* b b))))) (/ (* c (fma (* c a) (/ -0.375 (* b b)) -0.5)) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 115.0) {
tmp = (-0.3333333333333333 / a) * (b - sqrt(fma(a, (c * -3.0), (b * b))));
} else {
tmp = (c * fma((c * a), (-0.375 / (b * b)), -0.5)) / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 115.0) tmp = Float64(Float64(-0.3333333333333333 / a) * Float64(b - sqrt(fma(a, Float64(c * -3.0), Float64(b * b))))); else tmp = Float64(Float64(c * fma(Float64(c * a), Float64(-0.375 / Float64(b * b)), -0.5)) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 115.0], N[(N[(-0.3333333333333333 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(a * N[(c * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c * N[(N[(c * a), $MachinePrecision] * N[(-0.375 / N[(b * b), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 115:\\
\;\;\;\;\frac{-0.3333333333333333}{a} \cdot \left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \mathsf{fma}\left(c \cdot a, \frac{-0.375}{b \cdot b}, -0.5\right)}{b}\\
\end{array}
\end{array}
if b < 115Initial program 81.9%
Applied rewrites81.9%
if 115 < b Initial program 44.3%
Taylor expanded in b around inf
lower-/.f64N/A
Applied rewrites88.4%
Taylor expanded in c around 0
lower-*.f64N/A
sub-negN/A
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6488.4
Applied rewrites88.4%
Final simplification86.4%
(FPCore (a b c) :precision binary64 (* c (/ (fma (* c a) (/ -0.375 (* b b)) -0.5) b)))
double code(double a, double b, double c) {
return c * (fma((c * a), (-0.375 / (b * b)), -0.5) / b);
}
function code(a, b, c) return Float64(c * Float64(fma(Float64(c * a), Float64(-0.375 / Float64(b * b)), -0.5) / b)) end
code[a_, b_, c_] := N[(c * N[(N[(N[(c * a), $MachinePrecision] * N[(-0.375 / N[(b * b), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
c \cdot \frac{\mathsf{fma}\left(c \cdot a, \frac{-0.375}{b \cdot b}, -0.5\right)}{b}
\end{array}
Initial program 55.9%
Taylor expanded in b around inf
lower-/.f64N/A
Applied rewrites78.5%
Taylor expanded in c around 0
lower-*.f64N/A
unpow3N/A
unpow2N/A
associate-/r*N/A
associate-/l*N/A
associate-*r/N/A
metadata-evalN/A
div-subN/A
lower-/.f64N/A
Applied rewrites78.5%
Final simplification78.5%
(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 55.9%
Taylor expanded in b around inf
lower-*.f64N/A
lower-/.f6463.5
Applied rewrites63.5%
herbie shell --seed 2024214
(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)))