
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
double code(double x) {
return (1.0 - cos(x)) / (x * x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 - cos(x)) / (x * x)
end function
public static double code(double x) {
return (1.0 - Math.cos(x)) / (x * x);
}
def code(x): return (1.0 - math.cos(x)) / (x * x)
function code(x) return Float64(Float64(1.0 - cos(x)) / Float64(x * x)) end
function tmp = code(x) tmp = (1.0 - cos(x)) / (x * x); end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 - \cos x}{x \cdot x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
double code(double x) {
return (1.0 - cos(x)) / (x * x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 - cos(x)) / (x * x)
end function
public static double code(double x) {
return (1.0 - Math.cos(x)) / (x * x);
}
def code(x): return (1.0 - math.cos(x)) / (x * x)
function code(x) return Float64(Float64(1.0 - cos(x)) / Float64(x * x)) end
function tmp = code(x) tmp = (1.0 - cos(x)) / (x * x); end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 - \cos x}{x \cdot x}
\end{array}
(FPCore (x) :precision binary64 (/ (* (/ (sin x) x) (tan (* x 0.5))) x))
double code(double x) {
return ((sin(x) / x) * tan((x * 0.5))) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((sin(x) / x) * tan((x * 0.5d0))) / x
end function
public static double code(double x) {
return ((Math.sin(x) / x) * Math.tan((x * 0.5))) / x;
}
def code(x): return ((math.sin(x) / x) * math.tan((x * 0.5))) / x
function code(x) return Float64(Float64(Float64(sin(x) / x) * tan(Float64(x * 0.5))) / x) end
function tmp = code(x) tmp = ((sin(x) / x) * tan((x * 0.5))) / x; end
code[x_] := N[(N[(N[(N[Sin[x], $MachinePrecision] / x), $MachinePrecision] * N[Tan[N[(x * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\sin x}{x} \cdot \tan \left(x \cdot 0.5\right)}{x}
\end{array}
Initial program 55.0%
lift-/.f64N/A
lift--.f64N/A
flip--N/A
associate-/l/N/A
metadata-evalN/A
lift-cos.f64N/A
lift-cos.f64N/A
1-sub-cosN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lift-cos.f64N/A
hang-0p-tanN/A
lower-tan.f64N/A
lower-/.f6480.0
Applied rewrites80.0%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
associate-*l/N/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f6499.8
lift-/.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6499.8
Applied rewrites99.8%
(FPCore (x) :precision binary64 (/ (tan (* x 0.5)) (* x (/ x (sin x)))))
double code(double x) {
return tan((x * 0.5)) / (x * (x / sin(x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = tan((x * 0.5d0)) / (x * (x / sin(x)))
end function
public static double code(double x) {
return Math.tan((x * 0.5)) / (x * (x / Math.sin(x)));
}
def code(x): return math.tan((x * 0.5)) / (x * (x / math.sin(x)))
function code(x) return Float64(tan(Float64(x * 0.5)) / Float64(x * Float64(x / sin(x)))) end
function tmp = code(x) tmp = tan((x * 0.5)) / (x * (x / sin(x))); end
code[x_] := N[(N[Tan[N[(x * 0.5), $MachinePrecision]], $MachinePrecision] / N[(x * N[(x / N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\tan \left(x \cdot 0.5\right)}{x \cdot \frac{x}{\sin x}}
\end{array}
Initial program 50.3%
lift-/.f64N/A
lift--.f64N/A
flip--N/A
associate-/l/N/A
metadata-evalN/A
lift-cos.f64N/A
lift-cos.f64N/A
1-sub-cosN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lift-cos.f64N/A
hang-0p-tanN/A
lower-tan.f64N/A
lower-/.f6475.3
Applied rewrites75.3%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6499.3
Applied rewrites99.3%
herbie shell --seed 2024219
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1.0 (cos x)) (* x x)))