
(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 9 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.105)
(+
0.5
(+
(* -0.041666666666666664 (pow x 2.0))
(+
(* -2.48015873015873e-5 (pow x 6.0))
(* 0.001388888888888889 (pow x 4.0)))))
(/ (fma (/ 1.0 x) (cos x) (/ -1.0 x)) (- x))))x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.105) {
tmp = 0.5 + ((-0.041666666666666664 * pow(x, 2.0)) + ((-2.48015873015873e-5 * pow(x, 6.0)) + (0.001388888888888889 * pow(x, 4.0))));
} else {
tmp = fma((1.0 / x), cos(x), (-1.0 / x)) / -x;
}
return tmp;
}
x = abs(x) function code(x) tmp = 0.0 if (x <= 0.105) tmp = Float64(0.5 + Float64(Float64(-0.041666666666666664 * (x ^ 2.0)) + Float64(Float64(-2.48015873015873e-5 * (x ^ 6.0)) + Float64(0.001388888888888889 * (x ^ 4.0))))); else tmp = Float64(fma(Float64(1.0 / x), cos(x), Float64(-1.0 / x)) / Float64(-x)); end return tmp end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 0.105], N[(0.5 + N[(N[(-0.041666666666666664 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[(-2.48015873015873e-5 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision] + N[(0.001388888888888889 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 / x), $MachinePrecision] * N[Cos[x], $MachinePrecision] + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / (-x)), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.105:\\
\;\;\;\;0.5 + \left(-0.041666666666666664 \cdot {x}^{2} + \left(-2.48015873015873 \cdot 10^{-5} \cdot {x}^{6} + 0.001388888888888889 \cdot {x}^{4}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{1}{x}, \cos x, \frac{-1}{x}\right)}{-x}\\
\end{array}
\end{array}
if x < 0.104999999999999996Initial program 33.9%
Taylor expanded in x around 0 67.9%
if 0.104999999999999996 < x Initial program 96.2%
associate-/r*99.2%
div-inv99.2%
Applied egg-rr99.2%
*-commutative99.2%
frac-2neg99.2%
associate-*r/99.2%
sub-neg99.2%
+-commutative99.2%
distribute-neg-in99.2%
add-sqr-sqrt52.3%
distribute-rgt-neg-in52.3%
distribute-lft-neg-out52.3%
sqr-neg52.3%
add-sqr-sqrt99.2%
metadata-eval99.2%
Applied egg-rr99.2%
distribute-lft-in99.2%
fma-def99.3%
Applied egg-rr99.3%
Final simplification77.6%
NOTE: x should be positive before calling this function
(FPCore (x)
:precision binary64
(if (<= x 0.032)
(+
0.5
(+
(* -0.041666666666666664 (pow x 2.0))
(* 0.001388888888888889 (pow x 4.0))))
(/ (/ (+ (cos x) -1.0) x) (- x))))x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.032) {
tmp = 0.5 + ((-0.041666666666666664 * pow(x, 2.0)) + (0.001388888888888889 * pow(x, 4.0)));
} else {
tmp = ((cos(x) + -1.0) / 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.032d0) then
tmp = 0.5d0 + (((-0.041666666666666664d0) * (x ** 2.0d0)) + (0.001388888888888889d0 * (x ** 4.0d0)))
else
tmp = ((cos(x) + (-1.0d0)) / x) / -x
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 0.032) {
tmp = 0.5 + ((-0.041666666666666664 * Math.pow(x, 2.0)) + (0.001388888888888889 * Math.pow(x, 4.0)));
} else {
tmp = ((Math.cos(x) + -1.0) / x) / -x;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 0.032: tmp = 0.5 + ((-0.041666666666666664 * math.pow(x, 2.0)) + (0.001388888888888889 * math.pow(x, 4.0))) else: tmp = ((math.cos(x) + -1.0) / x) / -x return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 0.032) tmp = Float64(0.5 + Float64(Float64(-0.041666666666666664 * (x ^ 2.0)) + Float64(0.001388888888888889 * (x ^ 4.0)))); else tmp = Float64(Float64(Float64(cos(x) + -1.0) / x) / Float64(-x)); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 0.032) tmp = 0.5 + ((-0.041666666666666664 * (x ^ 2.0)) + (0.001388888888888889 * (x ^ 4.0))); else tmp = ((cos(x) + -1.0) / x) / -x; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 0.032], N[(0.5 + N[(N[(-0.041666666666666664 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] + N[(0.001388888888888889 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Cos[x], $MachinePrecision] + -1.0), $MachinePrecision] / x), $MachinePrecision] / (-x)), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.032:\\
\;\;\;\;0.5 + \left(-0.041666666666666664 \cdot {x}^{2} + 0.001388888888888889 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\cos x + -1}{x}}{-x}\\
\end{array}
\end{array}
if x < 0.032000000000000001Initial program 33.9%
Taylor expanded in x around 0 68.4%
if 0.032000000000000001 < x Initial program 96.2%
associate-/r*99.2%
div-inv99.2%
Applied egg-rr99.2%
*-commutative99.2%
frac-2neg99.2%
associate-*r/99.2%
sub-neg99.2%
+-commutative99.2%
distribute-neg-in99.2%
add-sqr-sqrt52.3%
distribute-rgt-neg-in52.3%
distribute-lft-neg-out52.3%
sqr-neg52.3%
add-sqr-sqrt99.2%
metadata-eval99.2%
Applied egg-rr99.2%
Taylor expanded in x around inf 99.2%
Final simplification77.9%
NOTE: x should be positive before calling this function
(FPCore (x)
:precision binary64
(if (<= x 0.032)
(+
0.5
(+
(* -0.041666666666666664 (pow x 2.0))
(* 0.001388888888888889 (pow x 4.0))))
(/ (fma (/ 1.0 x) (cos x) (/ -1.0 x)) (- x))))x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.032) {
tmp = 0.5 + ((-0.041666666666666664 * pow(x, 2.0)) + (0.001388888888888889 * pow(x, 4.0)));
} else {
tmp = fma((1.0 / x), cos(x), (-1.0 / x)) / -x;
}
return tmp;
}
x = abs(x) function code(x) tmp = 0.0 if (x <= 0.032) tmp = Float64(0.5 + Float64(Float64(-0.041666666666666664 * (x ^ 2.0)) + Float64(0.001388888888888889 * (x ^ 4.0)))); else tmp = Float64(fma(Float64(1.0 / x), cos(x), Float64(-1.0 / x)) / Float64(-x)); end return tmp end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 0.032], N[(0.5 + N[(N[(-0.041666666666666664 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] + N[(0.001388888888888889 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 / x), $MachinePrecision] * N[Cos[x], $MachinePrecision] + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / (-x)), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.032:\\
\;\;\;\;0.5 + \left(-0.041666666666666664 \cdot {x}^{2} + 0.001388888888888889 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{1}{x}, \cos x, \frac{-1}{x}\right)}{-x}\\
\end{array}
\end{array}
if x < 0.032000000000000001Initial program 33.9%
Taylor expanded in x around 0 68.4%
if 0.032000000000000001 < x Initial program 96.2%
associate-/r*99.2%
div-inv99.2%
Applied egg-rr99.2%
*-commutative99.2%
frac-2neg99.2%
associate-*r/99.2%
sub-neg99.2%
+-commutative99.2%
distribute-neg-in99.2%
add-sqr-sqrt52.3%
distribute-rgt-neg-in52.3%
distribute-lft-neg-out52.3%
sqr-neg52.3%
add-sqr-sqrt99.2%
metadata-eval99.2%
Applied egg-rr99.2%
distribute-lft-in99.2%
fma-def99.3%
Applied egg-rr99.3%
Final simplification77.9%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 0.005) (+ 0.5 (* -0.041666666666666664 (pow x 2.0))) (/ (/ (+ (cos x) -1.0) x) (- x))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.005) {
tmp = 0.5 + (-0.041666666666666664 * pow(x, 2.0));
} else {
tmp = ((cos(x) + -1.0) / 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 + ((-0.041666666666666664d0) * (x ** 2.0d0))
else
tmp = ((cos(x) + (-1.0d0)) / 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 + (-0.041666666666666664 * Math.pow(x, 2.0));
} else {
tmp = ((Math.cos(x) + -1.0) / x) / -x;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 0.005: tmp = 0.5 + (-0.041666666666666664 * math.pow(x, 2.0)) else: tmp = ((math.cos(x) + -1.0) / x) / -x return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 0.005) tmp = Float64(0.5 + Float64(-0.041666666666666664 * (x ^ 2.0))); else tmp = Float64(Float64(Float64(cos(x) + -1.0) / x) / Float64(-x)); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 0.005) tmp = 0.5 + (-0.041666666666666664 * (x ^ 2.0)); else tmp = ((cos(x) + -1.0) / 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[(-0.041666666666666664 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Cos[x], $MachinePrecision] + -1.0), $MachinePrecision] / x), $MachinePrecision] / (-x)), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.005:\\
\;\;\;\;0.5 + -0.041666666666666664 \cdot {x}^{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\cos x + -1}{x}}{-x}\\
\end{array}
\end{array}
if x < 0.0050000000000000001Initial program 33.9%
Taylor expanded in x around 0 68.0%
if 0.0050000000000000001 < x Initial program 96.2%
associate-/r*99.2%
div-inv99.2%
Applied egg-rr99.2%
*-commutative99.2%
frac-2neg99.2%
associate-*r/99.2%
sub-neg99.2%
+-commutative99.2%
distribute-neg-in99.2%
add-sqr-sqrt52.3%
distribute-rgt-neg-in52.3%
distribute-lft-neg-out52.3%
sqr-neg52.3%
add-sqr-sqrt99.2%
metadata-eval99.2%
Applied egg-rr99.2%
Taylor expanded in x around inf 99.2%
Final simplification77.6%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 0.005) (+ 0.5 (* -0.041666666666666664 (pow x 2.0))) (/ (- 1.0 (cos x)) (* x x))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.005) {
tmp = 0.5 + (-0.041666666666666664 * pow(x, 2.0));
} 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 + ((-0.041666666666666664d0) * (x ** 2.0d0))
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 + (-0.041666666666666664 * Math.pow(x, 2.0));
} 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 + (-0.041666666666666664 * math.pow(x, 2.0)) 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(-0.041666666666666664 * (x ^ 2.0))); 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 + (-0.041666666666666664 * (x ^ 2.0)); 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[(-0.041666666666666664 * N[Power[x, 2.0], $MachinePrecision]), $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 + -0.041666666666666664 \cdot {x}^{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - \cos x}{x \cdot x}\\
\end{array}
\end{array}
if x < 0.0050000000000000001Initial program 33.9%
Taylor expanded in x around 0 68.0%
if 0.0050000000000000001 < x Initial program 96.2%
Final simplification76.7%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 3.05) (+ 0.5 (* -0.041666666666666664 (pow x 2.0))) (* (/ 1.0 x) (/ 1.0 x))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 3.05) {
tmp = 0.5 + (-0.041666666666666664 * pow(x, 2.0));
} else {
tmp = (1.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 <= 3.05d0) then
tmp = 0.5d0 + ((-0.041666666666666664d0) * (x ** 2.0d0))
else
tmp = (1.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 <= 3.05) {
tmp = 0.5 + (-0.041666666666666664 * Math.pow(x, 2.0));
} else {
tmp = (1.0 / x) * (1.0 / x);
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 3.05: tmp = 0.5 + (-0.041666666666666664 * math.pow(x, 2.0)) else: tmp = (1.0 / x) * (1.0 / x) return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 3.05) tmp = Float64(0.5 + Float64(-0.041666666666666664 * (x ^ 2.0))); else tmp = Float64(Float64(1.0 / x) * Float64(1.0 / x)); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 3.05) tmp = 0.5 + (-0.041666666666666664 * (x ^ 2.0)); else tmp = (1.0 / x) * (1.0 / x); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 3.05], N[(0.5 + N[(-0.041666666666666664 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.05:\\
\;\;\;\;0.5 + -0.041666666666666664 \cdot {x}^{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x} \cdot \frac{1}{x}\\
\end{array}
\end{array}
if x < 3.0499999999999998Initial program 33.9%
Taylor expanded in x around 0 68.0%
if 3.0499999999999998 < x Initial program 96.2%
associate-/r*99.2%
div-inv99.2%
Applied egg-rr99.2%
div-sub99.1%
add-sqr-sqrt98.9%
fma-neg99.0%
inv-pow99.0%
sqrt-pow199.2%
metadata-eval99.2%
inv-pow99.2%
sqrt-pow199.0%
metadata-eval99.0%
Applied egg-rr99.0%
Taylor expanded in x around inf 58.8%
Final simplification65.2%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 1.42) 0.5 (* (/ 1.0 x) (/ 1.0 x))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 1.42) {
tmp = 0.5;
} else {
tmp = (1.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 <= 1.42d0) then
tmp = 0.5d0
else
tmp = (1.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 <= 1.42) {
tmp = 0.5;
} else {
tmp = (1.0 / x) * (1.0 / x);
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 1.42: tmp = 0.5 else: tmp = (1.0 / x) * (1.0 / x) return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 1.42) tmp = 0.5; else tmp = Float64(Float64(1.0 / x) * Float64(1.0 / x)); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 1.42) tmp = 0.5; else tmp = (1.0 / x) * (1.0 / x); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 1.42], 0.5, N[(N[(1.0 / x), $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.42:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x} \cdot \frac{1}{x}\\
\end{array}
\end{array}
if x < 1.4199999999999999Initial program 33.9%
Taylor expanded in x around 0 68.4%
if 1.4199999999999999 < x Initial program 96.2%
associate-/r*99.2%
div-inv99.2%
Applied egg-rr99.2%
div-sub99.1%
add-sqr-sqrt98.9%
fma-neg99.0%
inv-pow99.0%
sqrt-pow199.2%
metadata-eval99.2%
inv-pow99.2%
sqrt-pow199.0%
metadata-eval99.0%
Applied egg-rr99.0%
Taylor expanded in x around inf 58.8%
Final simplification65.5%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 1.4e+77) 0.5 (* (/ 1.0 x) 0.0)))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 1.4e+77) {
tmp = 0.5;
} else {
tmp = (1.0 / x) * 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.4d+77) then
tmp = 0.5d0
else
tmp = (1.0d0 / x) * 0.0d0
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 1.4e+77) {
tmp = 0.5;
} else {
tmp = (1.0 / x) * 0.0;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 1.4e+77: tmp = 0.5 else: tmp = (1.0 / x) * 0.0 return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 1.4e+77) tmp = 0.5; else tmp = Float64(Float64(1.0 / x) * 0.0); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 1.4e+77) tmp = 0.5; else tmp = (1.0 / x) * 0.0; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 1.4e+77], 0.5, N[(N[(1.0 / x), $MachinePrecision] * 0.0), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.4 \cdot 10^{+77}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x} \cdot 0\\
\end{array}
\end{array}
if x < 1.4e77Initial program 41.3%
Taylor expanded in x around 0 61.4%
if 1.4e77 < x Initial program 95.3%
associate-/r*99.6%
div-inv99.6%
Applied egg-rr99.6%
div-sub99.5%
add-sqr-sqrt99.4%
fma-neg99.5%
inv-pow99.5%
sqrt-pow199.6%
metadata-eval99.6%
inv-pow99.6%
sqrt-pow199.5%
metadata-eval99.5%
Applied egg-rr99.5%
Taylor expanded in x around 0 72.8%
Final simplification63.9%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 0.5)
x = abs(x);
double code(double x) {
return 0.5;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0
end function
x = Math.abs(x);
public static double code(double x) {
return 0.5;
}
x = abs(x) def code(x): return 0.5
x = abs(x) function code(x) return 0.5 end
x = abs(x) function tmp = code(x) tmp = 0.5; end
NOTE: x should be positive before calling this function code[x_] := 0.5
\begin{array}{l}
x = |x|\\
\\
0.5
\end{array}
Initial program 53.1%
Taylor expanded in x around 0 48.7%
Final simplification48.7%
herbie shell --seed 2023320
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1.0 (cos x)) (* x x)))