
(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.0005) (+ 0.5 (* (* x x) -0.041666666666666664)) (* (* (sin x) (tan (/ x 2.0))) (pow x -2.0))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.0005) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = (sin(x) * tan((x / 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 <= 0.0005d0) then
tmp = 0.5d0 + ((x * x) * (-0.041666666666666664d0))
else
tmp = (sin(x) * tan((x / 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 <= 0.0005) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = (Math.sin(x) * Math.tan((x / 2.0))) * Math.pow(x, -2.0);
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 0.0005: tmp = 0.5 + ((x * x) * -0.041666666666666664) else: tmp = (math.sin(x) * math.tan((x / 2.0))) * math.pow(x, -2.0) return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 0.0005) tmp = Float64(0.5 + Float64(Float64(x * x) * -0.041666666666666664)); else tmp = Float64(Float64(sin(x) * tan(Float64(x / 2.0))) * (x ^ -2.0)); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 0.0005) tmp = 0.5 + ((x * x) * -0.041666666666666664); else tmp = (sin(x) * tan((x / 2.0))) * (x ^ -2.0); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 0.0005], N[(0.5 + N[(N[(x * x), $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[x], $MachinePrecision] * N[Tan[N[(x / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Power[x, -2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0005:\\
\;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\
\mathbf{else}:\\
\;\;\;\;\left(\sin x \cdot \tan \left(\frac{x}{2}\right)\right) \cdot {x}^{-2}\\
\end{array}
\end{array}
if x < 5.0000000000000001e-4Initial program 31.6%
Taylor expanded in x around 0 69.6%
*-commutative69.6%
Simplified69.6%
pow269.6%
Applied egg-rr69.6%
if 5.0000000000000001e-4 < x Initial program 98.8%
flip--98.3%
clear-num98.2%
metadata-eval98.2%
pow298.2%
Applied egg-rr98.2%
unpow298.2%
1-sub-cos98.5%
Applied egg-rr98.5%
div-inv98.5%
associate-/r/98.5%
associate-*l*98.4%
pow298.4%
pow298.4%
pow-flip99.0%
metadata-eval99.0%
Applied egg-rr99.0%
associate-*l/99.1%
*-lft-identity99.1%
associate-*l/99.0%
unpow299.0%
associate-*r/99.0%
hang-0p-tan99.6%
Simplified99.6%
Final simplification77.2%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 0.0004) (+ 0.5 (* (* x x) -0.041666666666666664)) (* (/ (* (sin x) (tan (/ x 2.0))) x) (/ 1.0 x))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.0004) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = ((sin(x) * tan((x / 2.0))) / x) * (1.0 / 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.0004d0) then
tmp = 0.5d0 + ((x * x) * (-0.041666666666666664d0))
else
tmp = ((sin(x) * tan((x / 2.0d0))) / x) * (1.0d0 / x)
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 0.0004) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = ((Math.sin(x) * Math.tan((x / 2.0))) / x) * (1.0 / x);
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 0.0004: tmp = 0.5 + ((x * x) * -0.041666666666666664) else: tmp = ((math.sin(x) * math.tan((x / 2.0))) / x) * (1.0 / x) return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 0.0004) tmp = Float64(0.5 + Float64(Float64(x * x) * -0.041666666666666664)); else tmp = Float64(Float64(Float64(sin(x) * tan(Float64(x / 2.0))) / x) * Float64(1.0 / x)); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 0.0004) tmp = 0.5 + ((x * x) * -0.041666666666666664); else tmp = ((sin(x) * tan((x / 2.0))) / x) * (1.0 / x); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 0.0004], N[(0.5 + N[(N[(x * x), $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Sin[x], $MachinePrecision] * N[Tan[N[(x / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0004:\\
\;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\
\mathbf{else}:\\
\;\;\;\;\frac{\sin x \cdot \tan \left(\frac{x}{2}\right)}{x} \cdot \frac{1}{x}\\
\end{array}
\end{array}
if x < 4.00000000000000019e-4Initial program 31.6%
Taylor expanded in x around 0 69.6%
*-commutative69.6%
Simplified69.6%
pow269.6%
Applied egg-rr69.6%
if 4.00000000000000019e-4 < x Initial program 98.8%
associate-/r*99.4%
div-inv99.3%
Applied egg-rr99.3%
clear-num99.2%
associate-/r/99.2%
Applied egg-rr99.2%
flip--98.6%
metadata-eval98.6%
1-sub-cos98.9%
frac-times99.0%
*-un-lft-identity99.0%
pow299.0%
Applied egg-rr99.0%
*-commutative99.0%
associate-/r*98.9%
unpow298.9%
associate-*r/99.0%
hang-0p-tan99.6%
Simplified99.6%
Final simplification77.2%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 0.005) (+ 0.5 (* (* x x) -0.041666666666666664)) (* (pow x -2.0) (- 1.0 (cos x)))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.005) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = pow(x, -2.0) * (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.005d0) then
tmp = 0.5d0 + ((x * x) * (-0.041666666666666664d0))
else
tmp = (x ** (-2.0d0)) * (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.005) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = Math.pow(x, -2.0) * (1.0 - Math.cos(x));
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 0.005: tmp = 0.5 + ((x * x) * -0.041666666666666664) else: tmp = math.pow(x, -2.0) * (1.0 - math.cos(x)) return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 0.005) tmp = Float64(0.5 + Float64(Float64(x * x) * -0.041666666666666664)); else tmp = Float64((x ^ -2.0) * Float64(1.0 - cos(x))); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 0.005) tmp = 0.5 + ((x * x) * -0.041666666666666664); else tmp = (x ^ -2.0) * (1.0 - cos(x)); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 0.005], N[(0.5 + N[(N[(x * x), $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -2.0], $MachinePrecision] * N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.005:\\
\;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\
\mathbf{else}:\\
\;\;\;\;{x}^{-2} \cdot \left(1 - \cos x\right)\\
\end{array}
\end{array}
if x < 0.0050000000000000001Initial program 31.6%
Taylor expanded in x around 0 69.6%
*-commutative69.6%
Simplified69.6%
pow269.6%
Applied egg-rr69.6%
if 0.0050000000000000001 < x Initial program 98.8%
clear-num98.6%
associate-/r/98.7%
pow298.7%
pow-flip99.3%
metadata-eval99.3%
Applied egg-rr99.3%
Final simplification77.1%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 0.005) (+ 0.5 (* (* x x) -0.041666666666666664)) (/ (- 1.0 (cos x)) (* x x))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.005) {
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.005d0) 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.005) {
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.005: 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.005) 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.005) 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.005], 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.005:\\
\;\;\;\;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.0050000000000000001Initial program 31.6%
Taylor expanded in x around 0 69.6%
*-commutative69.6%
Simplified69.6%
pow269.6%
Applied egg-rr69.6%
if 0.0050000000000000001 < x Initial program 98.8%
Final simplification77.0%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 0.005) (+ 0.5 (* (* x x) -0.041666666666666664)) (/ (/ (- 1.0 (cos x)) x) x)))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.005) {
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.005d0) 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.005) {
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.005: 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.005) 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.005) 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.005], 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.005:\\
\;\;\;\;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.0050000000000000001Initial program 31.6%
Taylor expanded in x around 0 69.6%
*-commutative69.6%
Simplified69.6%
pow269.6%
Applied egg-rr69.6%
if 0.0050000000000000001 < x Initial program 98.8%
associate-/r*99.4%
div-inv99.3%
Applied egg-rr99.3%
un-div-inv99.4%
Applied egg-rr99.4%
Final simplification77.2%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 8.8e+76) 0.5 0.0))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 8.8e+76) {
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 <= 8.8d+76) 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 <= 8.8e+76) {
tmp = 0.5;
} else {
tmp = 0.0;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 8.8e+76: tmp = 0.5 else: tmp = 0.0 return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 8.8e+76) tmp = 0.5; else tmp = 0.0; end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 8.8e+76) 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, 8.8e+76], 0.5, 0.0]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 8.8 \cdot 10^{+76}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 8.8000000000000002e76Initial program 36.8%
Taylor expanded in x around 0 65.2%
if 8.8000000000000002e76 < x Initial program 98.8%
add-log-exp98.8%
Applied egg-rr98.8%
Taylor expanded in x around 0 69.0%
Taylor expanded in x around 0 69.0%
Final simplification65.9%
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.6%
add-log-exp48.6%
Applied egg-rr48.6%
Taylor expanded in x around 0 27.9%
Taylor expanded in x around 0 28.6%
Final simplification28.6%
herbie shell --seed 2023311
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1.0 (cos x)) (* x x)))