
(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 10 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 (* (/ (/ (sin x) x) x) (tan (/ x 2.0))))
double code(double x) {
return ((sin(x) / x) / x) * tan((x / 2.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((sin(x) / x) / x) * tan((x / 2.0d0))
end function
public static double code(double x) {
return ((Math.sin(x) / x) / x) * Math.tan((x / 2.0));
}
def code(x): return ((math.sin(x) / x) / x) * math.tan((x / 2.0))
function code(x) return Float64(Float64(Float64(sin(x) / x) / x) * tan(Float64(x / 2.0))) end
function tmp = code(x) tmp = ((sin(x) / x) / x) * tan((x / 2.0)); end
code[x_] := N[(N[(N[(N[Sin[x], $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision] * N[Tan[N[(x / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\sin x}{x}}{x} \cdot \tan \left(\frac{x}{2}\right)
\end{array}
Initial program 45.9%
clear-num45.9%
associate-/r/45.9%
pow245.9%
pow-flip46.3%
metadata-eval46.3%
Applied egg-rr46.3%
metadata-eval46.3%
pow-flip45.9%
pow245.9%
associate-/r/45.9%
clear-num45.9%
flip--45.7%
associate-/l/45.7%
metadata-eval45.7%
1-sub-cos72.2%
pow272.2%
Applied egg-rr72.2%
unpow272.2%
times-frac72.1%
hang-0p-tan72.5%
Simplified72.5%
*-un-lft-identity72.5%
times-frac99.6%
Applied egg-rr99.6%
associate-*l/99.7%
*-lft-identity99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x) :precision binary64 (if (<= (/ (- 1.0 (cos x)) (* x x)) 0.04) (* (tan (/ x 2.0)) (/ (sin x) (* x x))) (+ 0.5 (* (* x x) -0.041666666666666664))))
double code(double x) {
double tmp;
if (((1.0 - cos(x)) / (x * x)) <= 0.04) {
tmp = tan((x / 2.0)) * (sin(x) / (x * x));
} else {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((1.0d0 - cos(x)) / (x * x)) <= 0.04d0) then
tmp = tan((x / 2.0d0)) * (sin(x) / (x * x))
else
tmp = 0.5d0 + ((x * x) * (-0.041666666666666664d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((1.0 - Math.cos(x)) / (x * x)) <= 0.04) {
tmp = Math.tan((x / 2.0)) * (Math.sin(x) / (x * x));
} else {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
}
return tmp;
}
def code(x): tmp = 0 if ((1.0 - math.cos(x)) / (x * x)) <= 0.04: tmp = math.tan((x / 2.0)) * (math.sin(x) / (x * x)) else: tmp = 0.5 + ((x * x) * -0.041666666666666664) return tmp
function code(x) tmp = 0.0 if (Float64(Float64(1.0 - cos(x)) / Float64(x * x)) <= 0.04) tmp = Float64(tan(Float64(x / 2.0)) * Float64(sin(x) / Float64(x * x))); else tmp = Float64(0.5 + Float64(Float64(x * x) * -0.041666666666666664)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((1.0 - cos(x)) / (x * x)) <= 0.04) tmp = tan((x / 2.0)) * (sin(x) / (x * x)); else tmp = 0.5 + ((x * x) * -0.041666666666666664); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision], 0.04], N[(N[Tan[N[(x / 2.0), $MachinePrecision]], $MachinePrecision] * N[(N[Sin[x], $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(N[(x * x), $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{x \cdot x} \leq 0.04:\\
\;\;\;\;\tan \left(\frac{x}{2}\right) \cdot \frac{\sin x}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\
\end{array}
\end{array}
if (/.f64 (-.f64 1 (cos.f64 x)) (*.f64 x x)) < 0.0400000000000000008Initial program 63.3%
clear-num63.2%
associate-/r/63.2%
pow263.2%
pow-flip63.7%
metadata-eval63.7%
Applied egg-rr63.7%
metadata-eval63.7%
pow-flip63.2%
pow263.2%
associate-/r/63.2%
clear-num63.3%
flip--63.0%
associate-/l/62.9%
metadata-eval62.9%
1-sub-cos98.8%
pow298.8%
Applied egg-rr98.8%
unpow298.8%
times-frac97.6%
hang-0p-tan98.0%
Simplified98.0%
if 0.0400000000000000008 < (/.f64 (-.f64 1 (cos.f64 x)) (*.f64 x x)) Initial program 0.8%
Taylor expanded in x around 0 100.0%
unpow2100.0%
Simplified100.0%
Final simplification98.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (- 1.0 (cos x))))
(if (<= x -0.0048)
(* t_0 (pow x -2.0))
(if (<= x 0.0053)
(+ 0.5 (* (* x x) -0.041666666666666664))
(/ t_0 (* x x))))))
double code(double x) {
double t_0 = 1.0 - cos(x);
double tmp;
if (x <= -0.0048) {
tmp = t_0 * pow(x, -2.0);
} else if (x <= 0.0053) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = t_0 / (x * x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = 1.0d0 - cos(x)
if (x <= (-0.0048d0)) then
tmp = t_0 * (x ** (-2.0d0))
else if (x <= 0.0053d0) then
tmp = 0.5d0 + ((x * x) * (-0.041666666666666664d0))
else
tmp = t_0 / (x * x)
end if
code = tmp
end function
public static double code(double x) {
double t_0 = 1.0 - Math.cos(x);
double tmp;
if (x <= -0.0048) {
tmp = t_0 * Math.pow(x, -2.0);
} else if (x <= 0.0053) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = t_0 / (x * x);
}
return tmp;
}
def code(x): t_0 = 1.0 - math.cos(x) tmp = 0 if x <= -0.0048: tmp = t_0 * math.pow(x, -2.0) elif x <= 0.0053: tmp = 0.5 + ((x * x) * -0.041666666666666664) else: tmp = t_0 / (x * x) return tmp
function code(x) t_0 = Float64(1.0 - cos(x)) tmp = 0.0 if (x <= -0.0048) tmp = Float64(t_0 * (x ^ -2.0)); elseif (x <= 0.0053) tmp = Float64(0.5 + Float64(Float64(x * x) * -0.041666666666666664)); else tmp = Float64(t_0 / Float64(x * x)); end return tmp end
function tmp_2 = code(x) t_0 = 1.0 - cos(x); tmp = 0.0; if (x <= -0.0048) tmp = t_0 * (x ^ -2.0); elseif (x <= 0.0053) tmp = 0.5 + ((x * x) * -0.041666666666666664); else tmp = t_0 / (x * x); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.0048], N[(t$95$0 * N[Power[x, -2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.0053], N[(0.5 + N[(N[(x * x), $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision], N[(t$95$0 / N[(x * x), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \cos x\\
\mathbf{if}\;x \leq -0.0048:\\
\;\;\;\;t_0 \cdot {x}^{-2}\\
\mathbf{elif}\;x \leq 0.0053:\\
\;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{x \cdot x}\\
\end{array}
\end{array}
if x < -0.00479999999999999958Initial program 97.3%
clear-num97.3%
associate-/r/97.3%
pow297.3%
pow-flip98.9%
metadata-eval98.9%
Applied egg-rr98.9%
if -0.00479999999999999958 < x < 0.00530000000000000002Initial program 1.9%
Taylor expanded in x around 0 100.0%
unpow2100.0%
Simplified100.0%
if 0.00530000000000000002 < x Initial program 99.3%
Final simplification99.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (- 1.0 (cos x))))
(if (<= x -0.0048)
(* t_0 (/ (/ -1.0 x) (- x)))
(if (<= x 0.0053)
(+ 0.5 (* (* x x) -0.041666666666666664))
(/ t_0 (* x x))))))
double code(double x) {
double t_0 = 1.0 - cos(x);
double tmp;
if (x <= -0.0048) {
tmp = t_0 * ((-1.0 / x) / -x);
} else if (x <= 0.0053) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = t_0 / (x * x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = 1.0d0 - cos(x)
if (x <= (-0.0048d0)) then
tmp = t_0 * (((-1.0d0) / x) / -x)
else if (x <= 0.0053d0) then
tmp = 0.5d0 + ((x * x) * (-0.041666666666666664d0))
else
tmp = t_0 / (x * x)
end if
code = tmp
end function
public static double code(double x) {
double t_0 = 1.0 - Math.cos(x);
double tmp;
if (x <= -0.0048) {
tmp = t_0 * ((-1.0 / x) / -x);
} else if (x <= 0.0053) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = t_0 / (x * x);
}
return tmp;
}
def code(x): t_0 = 1.0 - math.cos(x) tmp = 0 if x <= -0.0048: tmp = t_0 * ((-1.0 / x) / -x) elif x <= 0.0053: tmp = 0.5 + ((x * x) * -0.041666666666666664) else: tmp = t_0 / (x * x) return tmp
function code(x) t_0 = Float64(1.0 - cos(x)) tmp = 0.0 if (x <= -0.0048) tmp = Float64(t_0 * Float64(Float64(-1.0 / x) / Float64(-x))); elseif (x <= 0.0053) tmp = Float64(0.5 + Float64(Float64(x * x) * -0.041666666666666664)); else tmp = Float64(t_0 / Float64(x * x)); end return tmp end
function tmp_2 = code(x) t_0 = 1.0 - cos(x); tmp = 0.0; if (x <= -0.0048) tmp = t_0 * ((-1.0 / x) / -x); elseif (x <= 0.0053) tmp = 0.5 + ((x * x) * -0.041666666666666664); else tmp = t_0 / (x * x); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.0048], N[(t$95$0 * N[(N[(-1.0 / x), $MachinePrecision] / (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.0053], N[(0.5 + N[(N[(x * x), $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision], N[(t$95$0 / N[(x * x), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \cos x\\
\mathbf{if}\;x \leq -0.0048:\\
\;\;\;\;t_0 \cdot \frac{\frac{-1}{x}}{-x}\\
\mathbf{elif}\;x \leq 0.0053:\\
\;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{x \cdot x}\\
\end{array}
\end{array}
if x < -0.00479999999999999958Initial program 97.3%
frac-2neg97.3%
div-inv97.3%
distribute-rgt-neg-in97.3%
Applied egg-rr97.3%
distribute-lft-neg-out97.3%
associate-/r*98.9%
Simplified98.9%
if -0.00479999999999999958 < x < 0.00530000000000000002Initial program 1.9%
Taylor expanded in x around 0 100.0%
unpow2100.0%
Simplified100.0%
if 0.00530000000000000002 < x Initial program 99.3%
Final simplification99.6%
(FPCore (x) :precision binary64 (if (or (<= x -0.0048) (not (<= x 0.0053))) (/ (- 1.0 (cos x)) (* x x)) (+ 0.5 (* (* x x) -0.041666666666666664))))
double code(double x) {
double tmp;
if ((x <= -0.0048) || !(x <= 0.0053)) {
tmp = (1.0 - cos(x)) / (x * x);
} else {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-0.0048d0)) .or. (.not. (x <= 0.0053d0))) then
tmp = (1.0d0 - cos(x)) / (x * x)
else
tmp = 0.5d0 + ((x * x) * (-0.041666666666666664d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -0.0048) || !(x <= 0.0053)) {
tmp = (1.0 - Math.cos(x)) / (x * x);
} else {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
}
return tmp;
}
def code(x): tmp = 0 if (x <= -0.0048) or not (x <= 0.0053): tmp = (1.0 - math.cos(x)) / (x * x) else: tmp = 0.5 + ((x * x) * -0.041666666666666664) return tmp
function code(x) tmp = 0.0 if ((x <= -0.0048) || !(x <= 0.0053)) tmp = Float64(Float64(1.0 - cos(x)) / Float64(x * x)); else tmp = Float64(0.5 + Float64(Float64(x * x) * -0.041666666666666664)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -0.0048) || ~((x <= 0.0053))) tmp = (1.0 - cos(x)) / (x * x); else tmp = 0.5 + ((x * x) * -0.041666666666666664); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -0.0048], N[Not[LessEqual[x, 0.0053]], $MachinePrecision]], N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(N[(x * x), $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0048 \lor \neg \left(x \leq 0.0053\right):\\
\;\;\;\;\frac{1 - \cos x}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\
\end{array}
\end{array}
if x < -0.00479999999999999958 or 0.00530000000000000002 < x Initial program 98.2%
if -0.00479999999999999958 < x < 0.00530000000000000002Initial program 1.9%
Taylor expanded in x around 0 100.0%
unpow2100.0%
Simplified100.0%
Final simplification99.2%
(FPCore (x)
:precision binary64
(let* ((t_0 (- 1.0 (cos x))))
(if (<= x -0.0048)
(/ (/ t_0 x) x)
(if (<= x 0.0053)
(+ 0.5 (* (* x x) -0.041666666666666664))
(/ t_0 (* x x))))))
double code(double x) {
double t_0 = 1.0 - cos(x);
double tmp;
if (x <= -0.0048) {
tmp = (t_0 / x) / x;
} else if (x <= 0.0053) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = t_0 / (x * x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = 1.0d0 - cos(x)
if (x <= (-0.0048d0)) then
tmp = (t_0 / x) / x
else if (x <= 0.0053d0) then
tmp = 0.5d0 + ((x * x) * (-0.041666666666666664d0))
else
tmp = t_0 / (x * x)
end if
code = tmp
end function
public static double code(double x) {
double t_0 = 1.0 - Math.cos(x);
double tmp;
if (x <= -0.0048) {
tmp = (t_0 / x) / x;
} else if (x <= 0.0053) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = t_0 / (x * x);
}
return tmp;
}
def code(x): t_0 = 1.0 - math.cos(x) tmp = 0 if x <= -0.0048: tmp = (t_0 / x) / x elif x <= 0.0053: tmp = 0.5 + ((x * x) * -0.041666666666666664) else: tmp = t_0 / (x * x) return tmp
function code(x) t_0 = Float64(1.0 - cos(x)) tmp = 0.0 if (x <= -0.0048) tmp = Float64(Float64(t_0 / x) / x); elseif (x <= 0.0053) tmp = Float64(0.5 + Float64(Float64(x * x) * -0.041666666666666664)); else tmp = Float64(t_0 / Float64(x * x)); end return tmp end
function tmp_2 = code(x) t_0 = 1.0 - cos(x); tmp = 0.0; if (x <= -0.0048) tmp = (t_0 / x) / x; elseif (x <= 0.0053) tmp = 0.5 + ((x * x) * -0.041666666666666664); else tmp = t_0 / (x * x); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.0048], N[(N[(t$95$0 / x), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[x, 0.0053], N[(0.5 + N[(N[(x * x), $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision], N[(t$95$0 / N[(x * x), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \cos x\\
\mathbf{if}\;x \leq -0.0048:\\
\;\;\;\;\frac{\frac{t_0}{x}}{x}\\
\mathbf{elif}\;x \leq 0.0053:\\
\;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{x \cdot x}\\
\end{array}
\end{array}
if x < -0.00479999999999999958Initial program 97.3%
clear-num97.3%
associate-/r/97.3%
pow297.3%
pow-flip98.9%
metadata-eval98.9%
Applied egg-rr98.9%
metadata-eval98.9%
pow-flip97.3%
pow297.3%
associate-/r/97.3%
clear-num97.3%
associate-/r*98.8%
Applied egg-rr98.8%
if -0.00479999999999999958 < x < 0.00530000000000000002Initial program 1.9%
Taylor expanded in x around 0 100.0%
unpow2100.0%
Simplified100.0%
if 0.00530000000000000002 < x Initial program 99.3%
Final simplification99.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (- 1.0 (cos x))))
(if (<= x -0.0048)
(/ (/ 1.0 x) (/ x t_0))
(if (<= x 0.0053)
(+ 0.5 (* (* x x) -0.041666666666666664))
(/ t_0 (* x x))))))
double code(double x) {
double t_0 = 1.0 - cos(x);
double tmp;
if (x <= -0.0048) {
tmp = (1.0 / x) / (x / t_0);
} else if (x <= 0.0053) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = t_0 / (x * x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = 1.0d0 - cos(x)
if (x <= (-0.0048d0)) then
tmp = (1.0d0 / x) / (x / t_0)
else if (x <= 0.0053d0) then
tmp = 0.5d0 + ((x * x) * (-0.041666666666666664d0))
else
tmp = t_0 / (x * x)
end if
code = tmp
end function
public static double code(double x) {
double t_0 = 1.0 - Math.cos(x);
double tmp;
if (x <= -0.0048) {
tmp = (1.0 / x) / (x / t_0);
} else if (x <= 0.0053) {
tmp = 0.5 + ((x * x) * -0.041666666666666664);
} else {
tmp = t_0 / (x * x);
}
return tmp;
}
def code(x): t_0 = 1.0 - math.cos(x) tmp = 0 if x <= -0.0048: tmp = (1.0 / x) / (x / t_0) elif x <= 0.0053: tmp = 0.5 + ((x * x) * -0.041666666666666664) else: tmp = t_0 / (x * x) return tmp
function code(x) t_0 = Float64(1.0 - cos(x)) tmp = 0.0 if (x <= -0.0048) tmp = Float64(Float64(1.0 / x) / Float64(x / t_0)); elseif (x <= 0.0053) tmp = Float64(0.5 + Float64(Float64(x * x) * -0.041666666666666664)); else tmp = Float64(t_0 / Float64(x * x)); end return tmp end
function tmp_2 = code(x) t_0 = 1.0 - cos(x); tmp = 0.0; if (x <= -0.0048) tmp = (1.0 / x) / (x / t_0); elseif (x <= 0.0053) tmp = 0.5 + ((x * x) * -0.041666666666666664); else tmp = t_0 / (x * x); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.0048], N[(N[(1.0 / x), $MachinePrecision] / N[(x / t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.0053], N[(0.5 + N[(N[(x * x), $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision], N[(t$95$0 / N[(x * x), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \cos x\\
\mathbf{if}\;x \leq -0.0048:\\
\;\;\;\;\frac{\frac{1}{x}}{\frac{x}{t_0}}\\
\mathbf{elif}\;x \leq 0.0053:\\
\;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{x \cdot x}\\
\end{array}
\end{array}
if x < -0.00479999999999999958Initial program 97.3%
associate-/r*98.8%
div-inv98.8%
Applied egg-rr98.8%
clear-num98.8%
associate-*l/98.8%
*-un-lft-identity98.8%
Applied egg-rr98.8%
if -0.00479999999999999958 < x < 0.00530000000000000002Initial program 1.9%
Taylor expanded in x around 0 100.0%
unpow2100.0%
Simplified100.0%
if 0.00530000000000000002 < x Initial program 99.3%
Final simplification99.6%
(FPCore (x) :precision binary64 (if (or (<= x -9.5e+76) (not (<= x 5.4e+76))) (/ (+ (/ 1.0 x) (/ -1.0 x)) x) 0.5))
double code(double x) {
double tmp;
if ((x <= -9.5e+76) || !(x <= 5.4e+76)) {
tmp = ((1.0 / x) + (-1.0 / x)) / x;
} else {
tmp = 0.5;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-9.5d+76)) .or. (.not. (x <= 5.4d+76))) then
tmp = ((1.0d0 / x) + ((-1.0d0) / x)) / x
else
tmp = 0.5d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -9.5e+76) || !(x <= 5.4e+76)) {
tmp = ((1.0 / x) + (-1.0 / x)) / x;
} else {
tmp = 0.5;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -9.5e+76) or not (x <= 5.4e+76): tmp = ((1.0 / x) + (-1.0 / x)) / x else: tmp = 0.5 return tmp
function code(x) tmp = 0.0 if ((x <= -9.5e+76) || !(x <= 5.4e+76)) tmp = Float64(Float64(Float64(1.0 / x) + Float64(-1.0 / x)) / x); else tmp = 0.5; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -9.5e+76) || ~((x <= 5.4e+76))) tmp = ((1.0 / x) + (-1.0 / x)) / x; else tmp = 0.5; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -9.5e+76], N[Not[LessEqual[x, 5.4e+76]], $MachinePrecision]], N[(N[(N[(1.0 / x), $MachinePrecision] + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], 0.5]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{+76} \lor \neg \left(x \leq 5.4 \cdot 10^{+76}\right):\\
\;\;\;\;\frac{\frac{1}{x} + \frac{-1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -9.5000000000000003e76 or 5.3999999999999998e76 < x Initial program 98.3%
clear-num98.2%
associate-/r/98.2%
pow298.2%
pow-flip99.4%
metadata-eval99.4%
Applied egg-rr99.4%
metadata-eval99.4%
pow-flip98.2%
pow298.2%
associate-/r/98.2%
clear-num98.3%
associate-/r*99.3%
Applied egg-rr99.3%
*-un-lft-identity99.3%
associate-*l/99.3%
sub-neg99.3%
distribute-lft-in99.3%
associate-/r/99.3%
clear-num99.3%
Applied egg-rr99.3%
Taylor expanded in x around 0 66.4%
if -9.5000000000000003e76 < x < 5.3999999999999998e76Initial program 18.0%
Taylor expanded in x around 0 84.3%
Final simplification78.1%
(FPCore (x) :precision binary64 (/ (/ 1.0 x) (+ (* x 0.16666666666666666) (* 2.0 (/ 1.0 x)))))
double code(double x) {
return (1.0 / x) / ((x * 0.16666666666666666) + (2.0 * (1.0 / x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / x) / ((x * 0.16666666666666666d0) + (2.0d0 * (1.0d0 / x)))
end function
public static double code(double x) {
return (1.0 / x) / ((x * 0.16666666666666666) + (2.0 * (1.0 / x)));
}
def code(x): return (1.0 / x) / ((x * 0.16666666666666666) + (2.0 * (1.0 / x)))
function code(x) return Float64(Float64(1.0 / x) / Float64(Float64(x * 0.16666666666666666) + Float64(2.0 * Float64(1.0 / x)))) end
function tmp = code(x) tmp = (1.0 / x) / ((x * 0.16666666666666666) + (2.0 * (1.0 / x))); end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] / N[(N[(x * 0.16666666666666666), $MachinePrecision] + N[(2.0 * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x}}{x \cdot 0.16666666666666666 + 2 \cdot \frac{1}{x}}
\end{array}
Initial program 45.9%
associate-/r*47.1%
div-inv47.1%
Applied egg-rr47.1%
clear-num47.1%
associate-*l/47.2%
*-un-lft-identity47.2%
Applied egg-rr47.2%
Taylor expanded in x around 0 80.2%
Final simplification80.2%
(FPCore (x) :precision binary64 0.5)
double code(double x) {
return 0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0
end function
public static double code(double x) {
return 0.5;
}
def code(x): return 0.5
function code(x) return 0.5 end
function tmp = code(x) tmp = 0.5; end
code[x_] := 0.5
\begin{array}{l}
\\
0.5
\end{array}
Initial program 45.9%
Taylor expanded in x around 0 56.2%
Final simplification56.2%
herbie shell --seed 2023195
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1.0 (cos x)) (* x x)))