(FPCore (x) :precision binary64 (cos (* (PI) x)))
\begin{array}{l} \\ \cos \left(\mathsf{PI}\left(\right) \cdot x\right) \end{array}
Sampling outcomes in binary64 precision:
Herbie found 2 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (x) :precision binary64 (cos (* (PI) x)))
\begin{array}{l} \\ \cos \left(\mathsf{PI}\left(\right) \cdot x\right) \end{array}
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (let* ((t_0 (* (PI) x_m))) (if (<= t_0 50000000000000.0) (cos t_0) 1.0)))
\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} t_0 := \mathsf{PI}\left(\right) \cdot x\_m\\ \mathbf{if}\;t\_0 \leq 50000000000000:\\ \;\;\;\;\cos t\_0\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array}
if (*.f64 (PI.f64) x) < 5e13
Initial program 72.7%
if 5e13 < (*.f64 (PI.f64) x)
Initial program 12.3%
Taylor expanded in x around 0
Applied rewrites100.0%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 1.0)
x_m = fabs(x); double code(double x_m) { return 1.0; }
x_m = abs(x) real(8) function code(x_m) real(8), intent (in) :: x_m code = 1.0d0 end function
x_m = Math.abs(x); public static double code(double x_m) { return 1.0; }
x_m = math.fabs(x) def code(x_m): return 1.0
x_m = abs(x) function code(x_m) return 1.0 end
x_m = abs(x); function tmp = code(x_m) tmp = 1.0; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := 1.0
\begin{array}{l} x_m = \left|x\right| \\ 1 \end{array}
Initial program 56.4%
Taylor expanded in x around 0
Applied rewrites97.7%
herbie shell --seed 1
(FPCore (x)
:name "cos(PI*x)"
:precision binary64
:pre (and (<= -1.79e+308 x) (<= x 1.79e+308))
(cos (* (PI) x)))