
(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 4 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 (/ (* a c) (* a (- (- b) (sqrt (fma a (* c -3.0) (* b b)))))))
double code(double a, double b, double c) {
return (a * c) / (a * (-b - sqrt(fma(a, (c * -3.0), (b * b)))));
}
function code(a, b, c) return Float64(Float64(a * c) / Float64(a * Float64(Float64(-b) - sqrt(fma(a, Float64(c * -3.0), Float64(b * b)))))) end
code[a_, b_, c_] := N[(N[(a * c), $MachinePrecision] / N[(a * N[((-b) - N[Sqrt[N[(a * N[(c * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c}{a \cdot \left(\left(-b\right) - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}
\end{array}
Initial program 31.0%
Applied rewrites31.0%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-/.f64N/A
div-invN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites31.0%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-sqrt.f64N/A
flip--N/A
associate-*l/N/A
metadata-evalN/A
frac-timesN/A
lower-/.f64N/A
Applied rewrites32.3%
Taylor expanded in b around 0
mul-1-negN/A
lower-neg.f64N/A
lower-*.f6499.4
Applied rewrites99.4%
Final simplification99.4%
(FPCore (a b c) :precision binary64 (/ (fma a (/ (* (* c c) -0.375) (* b b)) (* c -0.5)) b))
double code(double a, double b, double c) {
return fma(a, (((c * c) * -0.375) / (b * b)), (c * -0.5)) / b;
}
function code(a, b, c) return Float64(fma(a, Float64(Float64(Float64(c * c) * -0.375) / Float64(b * b)), Float64(c * -0.5)) / b) end
code[a_, b_, c_] := N[(N[(a * N[(N[(N[(c * c), $MachinePrecision] * -0.375), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] + N[(c * -0.5), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(a, \frac{\left(c \cdot c\right) \cdot -0.375}{b \cdot b}, c \cdot -0.5\right)}{b}
\end{array}
Initial program 31.0%
Taylor expanded in b around inf
lower-/.f64N/A
Applied rewrites91.2%
(FPCore (a b c) :precision binary64 (/ (* c (fma -0.375 (/ (* a c) (* b b)) -0.5)) b))
double code(double a, double b, double c) {
return (c * fma(-0.375, ((a * c) / (b * b)), -0.5)) / b;
}
function code(a, b, c) return Float64(Float64(c * fma(-0.375, Float64(Float64(a * c) / Float64(b * b)), -0.5)) / b) end
code[a_, b_, c_] := N[(N[(c * N[(-0.375 * N[(N[(a * c), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c \cdot \mathsf{fma}\left(-0.375, \frac{a \cdot c}{b \cdot b}, -0.5\right)}{b}
\end{array}
Initial program 31.0%
Taylor expanded in b around inf
Applied rewrites96.9%
Taylor expanded in c around 0
lower-*.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6491.1
Applied rewrites91.1%
Final simplification91.1%
(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 31.0%
Taylor expanded in b around inf
lower-*.f64N/A
lower-/.f6481.5
Applied rewrites81.5%
herbie shell --seed 2024219
(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)))