
(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 7 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 (/ (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 48.1%
lift-cos.f64N/A
flip--N/A
lift-*.f64N/A
associate-/l/N/A
metadata-evalN/A
lift-cos.f64N/A
lift-cos.f64N/A
1-sub-cosN/A
associate-/l*N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-+.f6475.4
Applied egg-rr75.4%
Taylor expanded in x around inf
associate-/l/N/A
lower-/.f64N/A
unpow2N/A
associate-/l*N/A
lower-*.f64N/A
lower-sin.f64N/A
hang-0p-tanN/A
lower-tan.f64N/A
*-rgt-identityN/A
associate-/l*N/A
metadata-evalN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6475.3
Simplified75.3%
lift-sin.f64N/A
lift-*.f64N/A
lift-tan.f64N/A
times-fracN/A
associate-*r/N/A
clear-numN/A
lower-/.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f6499.6
Applied egg-rr99.6%
lift-sin.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-tan.f64N/A
lift-*.f64N/A
lift-/.f64N/A
/-rgt-identityN/A
clear-numN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
clear-numN/A
lower-/.f64N/A
div-invN/A
lift-/.f64N/A
clear-numN/A
lower-*.f64N/A
lower-/.f6499.7
Applied egg-rr99.7%
(FPCore (x) :precision binary64 (if (<= x 4e-5) (fma x (* x -0.041666666666666664) 0.5) (* (/ 1.0 (* x x)) (* (tan (* x 0.5)) (sin x)))))
double code(double x) {
double tmp;
if (x <= 4e-5) {
tmp = fma(x, (x * -0.041666666666666664), 0.5);
} else {
tmp = (1.0 / (x * x)) * (tan((x * 0.5)) * sin(x));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 4e-5) tmp = fma(x, Float64(x * -0.041666666666666664), 0.5); else tmp = Float64(Float64(1.0 / Float64(x * x)) * Float64(tan(Float64(x * 0.5)) * sin(x))); end return tmp end
code[x_] := If[LessEqual[x, 4e-5], N[(x * N[(x * -0.041666666666666664), $MachinePrecision] + 0.5), $MachinePrecision], N[(N[(1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision] * N[(N[Tan[N[(x * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot x} \cdot \left(\tan \left(x \cdot 0.5\right) \cdot \sin x\right)\\
\end{array}
\end{array}
if x < 4.00000000000000033e-5Initial program 31.7%
Taylor expanded in x around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6470.0
Simplified70.0%
if 4.00000000000000033e-5 < x Initial program 99.6%
lift-cos.f64N/A
flip--N/A
lift-*.f64N/A
associate-/l/N/A
metadata-evalN/A
lift-cos.f64N/A
lift-cos.f64N/A
1-sub-cosN/A
associate-/l*N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-+.f6498.7
Applied egg-rr98.7%
Taylor expanded in x around inf
associate-/l/N/A
lower-/.f64N/A
unpow2N/A
associate-/l*N/A
lower-*.f64N/A
lower-sin.f64N/A
hang-0p-tanN/A
lower-tan.f64N/A
*-rgt-identityN/A
associate-/l*N/A
metadata-evalN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.6
Simplified99.6%
lift-sin.f64N/A
lift-*.f64N/A
lift-tan.f64N/A
lift-*.f64N/A
lift-*.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
lower-/.f6499.8
Applied egg-rr99.8%
Final simplification77.2%
(FPCore (x) :precision binary64 (if (<= x 0.0051) (fma x (* x -0.041666666666666664) 0.5) (/ (/ (- 1.0 (cos x)) x) x)))
double code(double x) {
double tmp;
if (x <= 0.0051) {
tmp = fma(x, (x * -0.041666666666666664), 0.5);
} else {
tmp = ((1.0 - cos(x)) / x) / x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 0.0051) tmp = fma(x, Float64(x * -0.041666666666666664), 0.5); else tmp = Float64(Float64(Float64(1.0 - cos(x)) / x) / x); end return tmp end
code[x_] := If[LessEqual[x, 0.0051], N[(x * N[(x * -0.041666666666666664), $MachinePrecision] + 0.5), $MachinePrecision], N[(N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0051:\\
\;\;\;\;\mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\
\end{array}
\end{array}
if x < 0.0051000000000000004Initial program 31.7%
Taylor expanded in x around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6470.0
Simplified70.0%
if 0.0051000000000000004 < x Initial program 99.6%
Applied egg-rr99.7%
lift-cos.f64N/A
lift-+.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
lift-/.f64N/A
associate-*l/N/A
*-commutativeN/A
neg-mul-1N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-neg-inN/A
metadata-evalN/A
sub-negN/A
lower--.f6499.7
Applied egg-rr99.7%
(FPCore (x) :precision binary64 (if (<= x 0.0051) (fma x (* x -0.041666666666666664) 0.5) (/ (- 1.0 (cos x)) (* x x))))
double code(double x) {
double tmp;
if (x <= 0.0051) {
tmp = fma(x, (x * -0.041666666666666664), 0.5);
} else {
tmp = (1.0 - cos(x)) / (x * x);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 0.0051) tmp = fma(x, Float64(x * -0.041666666666666664), 0.5); else tmp = Float64(Float64(1.0 - cos(x)) / Float64(x * x)); end return tmp end
code[x_] := If[LessEqual[x, 0.0051], N[(x * N[(x * -0.041666666666666664), $MachinePrecision] + 0.5), $MachinePrecision], N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0051:\\
\;\;\;\;\mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - \cos x}{x \cdot x}\\
\end{array}
\end{array}
if x < 0.0051000000000000004Initial program 31.7%
Taylor expanded in x around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6470.0
Simplified70.0%
if 0.0051000000000000004 < x Initial program 99.6%
(FPCore (x) :precision binary64 (/ -1.0 (fma x (* x -0.16666666666666666) -2.0)))
double code(double x) {
return -1.0 / fma(x, (x * -0.16666666666666666), -2.0);
}
function code(x) return Float64(-1.0 / fma(x, Float64(x * -0.16666666666666666), -2.0)) end
code[x_] := N[(-1.0 / N[(x * N[(x * -0.16666666666666666), $MachinePrecision] + -2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{\mathsf{fma}\left(x, x \cdot -0.16666666666666666, -2\right)}
\end{array}
Initial program 48.1%
Applied egg-rr49.1%
lift-cos.f64N/A
lift-+.f64N/A
clear-numN/A
frac-timesN/A
metadata-evalN/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f6448.8
Applied egg-rr48.8%
Taylor expanded in x around 0
sub-negN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6478.5
Simplified78.5%
(FPCore (x) :precision binary64 (if (<= x 1.35e+77) 0.5 0.0))
double code(double x) {
double tmp;
if (x <= 1.35e+77) {
tmp = 0.5;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.35d+77) then
tmp = 0.5d0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.35e+77) {
tmp = 0.5;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.35e+77: tmp = 0.5 else: tmp = 0.0 return tmp
function code(x) tmp = 0.0 if (x <= 1.35e+77) tmp = 0.5; else tmp = 0.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.35e+77) tmp = 0.5; else tmp = 0.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.35e+77], 0.5, 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.35 \cdot 10^{+77}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 1.3499999999999999e77Initial program 36.2%
Taylor expanded in x around 0
Simplified66.4%
if 1.3499999999999999e77 < x Initial program 99.7%
Taylor expanded in x around 0
Simplified65.0%
metadata-evalN/A
lift-*.f64N/A
div065.0
Applied egg-rr65.0%
(FPCore (x) :precision binary64 0.0)
double code(double x) {
return 0.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.0d0
end function
public static double code(double x) {
return 0.0;
}
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 48.1%
Taylor expanded in x around 0
Simplified23.9%
metadata-evalN/A
lift-*.f64N/A
div024.7
Applied egg-rr24.7%
herbie shell --seed 2024215
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1.0 (cos x)) (* x x)))