
(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 4 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 (+ 0.5 (* (pow x 2.0) -0.041666666666666664)))
double code(double x) {
return 0.5 + (pow(x, 2.0) * -0.041666666666666664);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0 + ((x ** 2.0d0) * (-0.041666666666666664d0))
end function
public static double code(double x) {
return 0.5 + (Math.pow(x, 2.0) * -0.041666666666666664);
}
def code(x): return 0.5 + (math.pow(x, 2.0) * -0.041666666666666664)
function code(x) return Float64(0.5 + Float64((x ^ 2.0) * -0.041666666666666664)) end
function tmp = code(x) tmp = 0.5 + ((x ^ 2.0) * -0.041666666666666664); end
code[x_] := N[(0.5 + N[(N[Power[x, 2.0], $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 + {x}^{2} \cdot -0.041666666666666664
\end{array}
Initial program 48.6%
Taylor expanded in x around 0 53.1%
*-commutative53.1%
Simplified53.1%
Final simplification53.1%
(FPCore (x) :precision binary64 (/ 2.0 (pow x 2.0)))
double code(double x) {
return 2.0 / pow(x, 2.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / (x ** 2.0d0)
end function
public static double code(double x) {
return 2.0 / Math.pow(x, 2.0);
}
def code(x): return 2.0 / math.pow(x, 2.0)
function code(x) return Float64(2.0 / (x ^ 2.0)) end
function tmp = code(x) tmp = 2.0 / (x ^ 2.0); end
code[x_] := N[(2.0 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{{x}^{2}}
\end{array}
Initial program 48.6%
associate-/r*49.7%
div-inv49.7%
Applied egg-rr49.7%
associate-*l/49.7%
associate-*r/49.7%
*-rgt-identity49.7%
sub-neg49.7%
add-sqr-sqrt26.3%
distribute-rgt-neg-in26.3%
add-sqr-sqrt0.0%
sqrt-unprod18.8%
sqr-neg18.8%
add-sqr-sqrt18.8%
add-sqr-sqrt32.2%
Applied egg-rr32.2%
Taylor expanded in x around 0 32.9%
Final simplification32.9%
(FPCore (x) :precision binary64 (/ (/ 2.0 x) x))
double code(double x) {
return (2.0 / x) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (2.0d0 / x) / x
end function
public static double code(double x) {
return (2.0 / x) / x;
}
def code(x): return (2.0 / x) / x
function code(x) return Float64(Float64(2.0 / x) / x) end
function tmp = code(x) tmp = (2.0 / x) / x; end
code[x_] := N[(N[(2.0 / x), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{2}{x}}{x}
\end{array}
Initial program 48.6%
associate-/r*49.7%
div-inv49.7%
Applied egg-rr49.7%
associate-*l/49.7%
associate-*r/49.7%
*-rgt-identity49.7%
sub-neg49.7%
add-sqr-sqrt26.3%
distribute-rgt-neg-in26.3%
add-sqr-sqrt0.0%
sqrt-unprod18.8%
sqr-neg18.8%
add-sqr-sqrt18.8%
add-sqr-sqrt32.2%
Applied egg-rr32.2%
Taylor expanded in x around 0 32.8%
Final simplification32.8%
(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.6%
Taylor expanded in x around 0 28.3%
Taylor expanded in x around 0 29.1%
Final simplification29.1%
herbie shell --seed 2024033
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1.0 (cos x)) (* x x)))