
(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}
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 0.0002) (+ 0.5 (* (* x x) -0.041666666666666664)) (/ (/ (* (tan (* x 0.5)) (sin x)) x) x)))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.0002) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = ((tan((x * 0.5)) * sin(x)) / x) / x;
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.0002d0) then
tmp = 0.5d0 + ((x * x) * (-0.041666666666666664d0))
else
tmp = ((tan((x * 0.5d0)) * sin(x)) / x) / x
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 0.0002) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = ((Math.tan((x * 0.5)) * Math.sin(x)) / x) / x;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 0.0002: tmp = 0.5 + ((x * x) * -0.041666666666666664) else: tmp = ((math.tan((x * 0.5)) * math.sin(x)) / x) / x return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 0.0002) tmp = Float64(0.5 + Float64(Float64(x * x) * -0.041666666666666664)); else tmp = Float64(Float64(Float64(tan(Float64(x * 0.5)) * sin(x)) / x) / x); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 0.0002) tmp = 0.5 + ((x * x) * -0.041666666666666664); else tmp = ((tan((x * 0.5)) * sin(x)) / x) / x; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 0.0002], N[(0.5 + N[(N[(x * x), $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Tan[N[(x * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0002:\\
\;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\tan \left(x \cdot 0.5\right) \cdot \sin x}{x}}{x}\\
\end{array}
\end{array}
if x < 2.0000000000000001e-4Initial program 32.8%
Taylor expanded in x around 0 69.2%
*-commutative69.2%
unpow269.2%
Simplified69.2%
if 2.0000000000000001e-4 < x Initial program 96.6%
flip--96.4%
div-inv96.4%
metadata-eval96.4%
1-sub-cos96.4%
pow296.4%
Applied egg-rr96.4%
unpow296.4%
associate-*l*96.5%
associate-*r/96.5%
*-rgt-identity96.5%
hang-0p-tan96.9%
Simplified96.9%
expm1-log1p-u96.9%
expm1-udef58.8%
div-inv58.8%
div-inv58.8%
metadata-eval58.8%
pow258.8%
pow-flip58.8%
metadata-eval58.8%
Applied egg-rr58.8%
expm1-def99.7%
expm1-log1p99.7%
metadata-eval99.7%
pow-sqr99.6%
unpow-199.6%
unpow-199.6%
associate-*r*99.6%
associate-*r/99.7%
associate-*l/99.7%
*-rgt-identity99.7%
associate-*r/99.7%
*-rgt-identity99.7%
associate-*r/99.7%
associate-*r/99.7%
associate-/r*96.8%
*-commutative96.8%
Simplified96.8%
Applied egg-rr99.7%
Final simplification76.5%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 0.0046) (+ 0.5 (* (* x x) -0.041666666666666664)) (/ (/ 1.0 x) (/ x (- 1.0 (cos x))))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.0046) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = (1.0 / x) / (x / (1.0 - cos(x)));
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.0046d0) then
tmp = 0.5d0 + ((x * x) * (-0.041666666666666664d0))
else
tmp = (1.0d0 / x) / (x / (1.0d0 - cos(x)))
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 0.0046) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = (1.0 / x) / (x / (1.0 - Math.cos(x)));
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 0.0046: tmp = 0.5 + ((x * x) * -0.041666666666666664) else: tmp = (1.0 / x) / (x / (1.0 - math.cos(x))) return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 0.0046) tmp = Float64(0.5 + Float64(Float64(x * x) * -0.041666666666666664)); else tmp = Float64(Float64(1.0 / x) / Float64(x / Float64(1.0 - cos(x)))); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 0.0046) tmp = 0.5 + ((x * x) * -0.041666666666666664); else tmp = (1.0 / x) / (x / (1.0 - cos(x))); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 0.0046], N[(0.5 + N[(N[(x * x), $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] / N[(x / N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0046:\\
\;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x}}{\frac{x}{1 - \cos x}}\\
\end{array}
\end{array}
if x < 0.0045999999999999999Initial program 32.8%
Taylor expanded in x around 0 69.2%
*-commutative69.2%
unpow269.2%
Simplified69.2%
if 0.0045999999999999999 < x Initial program 96.6%
associate-/r*99.3%
div-inv99.4%
Applied egg-rr99.4%
*-commutative99.4%
clear-num99.3%
un-div-inv99.4%
Applied egg-rr99.4%
Final simplification76.4%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 0.0046) (+ 0.5 (* (* x x) -0.041666666666666664)) (/ (- 1.0 (cos x)) (* x x))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.0046) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = (1.0 - cos(x)) / (x * x);
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.0046d0) then
tmp = 0.5d0 + ((x * x) * (-0.041666666666666664d0))
else
tmp = (1.0d0 - cos(x)) / (x * x)
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 0.0046) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = (1.0 - Math.cos(x)) / (x * x);
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 0.0046: tmp = 0.5 + ((x * x) * -0.041666666666666664) else: tmp = (1.0 - math.cos(x)) / (x * x) return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 0.0046) tmp = Float64(0.5 + Float64(Float64(x * x) * -0.041666666666666664)); else tmp = Float64(Float64(1.0 - cos(x)) / Float64(x * x)); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 0.0046) tmp = 0.5 + ((x * x) * -0.041666666666666664); else tmp = (1.0 - cos(x)) / (x * x); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 0.0046], N[(0.5 + N[(N[(x * x), $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0046:\\
\;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - \cos x}{x \cdot x}\\
\end{array}
\end{array}
if x < 0.0045999999999999999Initial program 32.8%
Taylor expanded in x around 0 69.2%
*-commutative69.2%
unpow269.2%
Simplified69.2%
if 0.0045999999999999999 < x Initial program 96.6%
Final simplification75.7%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 0.0046) (+ 0.5 (* (* x x) -0.041666666666666664)) (/ (/ (- 1.0 (cos x)) x) x)))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.0046) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = ((1.0 - cos(x)) / x) / x;
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.0046d0) then
tmp = 0.5d0 + ((x * x) * (-0.041666666666666664d0))
else
tmp = ((1.0d0 - cos(x)) / x) / x
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 0.0046) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = ((1.0 - Math.cos(x)) / x) / x;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 0.0046: tmp = 0.5 + ((x * x) * -0.041666666666666664) else: tmp = ((1.0 - math.cos(x)) / x) / x return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 0.0046) tmp = Float64(0.5 + Float64(Float64(x * x) * -0.041666666666666664)); else tmp = Float64(Float64(Float64(1.0 - cos(x)) / x) / x); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 0.0046) tmp = 0.5 + ((x * x) * -0.041666666666666664); else tmp = ((1.0 - cos(x)) / x) / x; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 0.0046], N[(0.5 + N[(N[(x * x), $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0046:\\
\;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\
\end{array}
\end{array}
if x < 0.0045999999999999999Initial program 32.8%
Taylor expanded in x around 0 69.2%
*-commutative69.2%
unpow269.2%
Simplified69.2%
if 0.0045999999999999999 < x Initial program 96.6%
associate-/r*99.3%
div-inv99.4%
Applied egg-rr99.4%
un-div-inv99.3%
Applied egg-rr99.3%
Final simplification76.4%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 2.4) (+ 0.5 (* (* x x) -0.041666666666666664)) (* 2.0 (pow x -2.0))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 2.4) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = 2.0 * pow(x, -2.0);
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 2.4d0) then
tmp = 0.5d0 + ((x * x) * (-0.041666666666666664d0))
else
tmp = 2.0d0 * (x ** (-2.0d0))
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 2.4) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = 2.0 * Math.pow(x, -2.0);
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 2.4: tmp = 0.5 + ((x * x) * -0.041666666666666664) else: tmp = 2.0 * math.pow(x, -2.0) return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 2.4) tmp = Float64(0.5 + Float64(Float64(x * x) * -0.041666666666666664)); else tmp = Float64(2.0 * (x ^ -2.0)); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 2.4) tmp = 0.5 + ((x * x) * -0.041666666666666664); else tmp = 2.0 * (x ^ -2.0); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 2.4], N[(0.5 + N[(N[(x * x), $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[Power[x, -2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.4:\\
\;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\
\mathbf{else}:\\
\;\;\;\;2 \cdot {x}^{-2}\\
\end{array}
\end{array}
if x < 2.39999999999999991Initial program 32.8%
Taylor expanded in x around 0 69.2%
*-commutative69.2%
unpow269.2%
Simplified69.2%
if 2.39999999999999991 < x Initial program 96.6%
div-sub96.4%
pow296.4%
pow-flip96.2%
metadata-eval96.2%
div-inv96.4%
pow296.4%
pow-flip99.3%
metadata-eval99.3%
Applied egg-rr99.3%
Taylor expanded in x around 0 58.8%
unpow258.8%
Simplified58.8%
Applied egg-rr63.8%
count-263.8%
Simplified63.8%
Final simplification67.9%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 1.5e+77) 0.5 0.0))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 1.5e+77) {
tmp = 0.5;
} else {
tmp = 0.0;
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.5d+77) then
tmp = 0.5d0
else
tmp = 0.0d0
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 1.5e+77) {
tmp = 0.5;
} else {
tmp = 0.0;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 1.5e+77: tmp = 0.5 else: tmp = 0.0 return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 1.5e+77) tmp = 0.5; else tmp = 0.0; end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 1.5e+77) tmp = 0.5; else tmp = 0.0; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 1.5e+77], 0.5, 0.0]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.5 \cdot 10^{+77}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 1.4999999999999999e77Initial program 36.9%
Taylor expanded in x around 0 65.8%
if 1.4999999999999999e77 < x Initial program 96.0%
div-sub95.9%
pow295.9%
pow-flip95.7%
metadata-eval95.7%
div-inv95.8%
pow295.8%
pow-flip99.5%
metadata-eval99.5%
Applied egg-rr99.5%
Taylor expanded in x around 0 73.6%
unpow273.6%
Simplified73.6%
Taylor expanded in x around 0 73.7%
Final simplification67.2%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 0.0)
x = abs(x);
double code(double x) {
return 0.0;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = 0.0d0
end function
x = Math.abs(x);
public static double code(double x) {
return 0.0;
}
x = abs(x) def code(x): return 0.0
x = abs(x) function code(x) return 0.0 end
x = abs(x) function tmp = code(x) tmp = 0.0; end
NOTE: x should be positive before calling this function code[x_] := 0.0
\begin{array}{l}
x = |x|\\
\\
0
\end{array}
Initial program 48.0%
div-sub48.5%
pow248.5%
pow-flip48.5%
metadata-eval48.5%
div-inv48.5%
pow248.5%
pow-flip49.3%
metadata-eval49.3%
Applied egg-rr49.3%
Taylor expanded in x around 0 26.4%
unpow226.4%
Simplified26.4%
Taylor expanded in x around 0 27.2%
Final simplification27.2%
herbie shell --seed 2023274
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1.0 (cos x)) (* x x)))