
(FPCore (x) :precision binary64 (- 1.0 (cos x)))
double code(double x) {
return 1.0 - cos(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 - cos(x)
end function
public static double code(double x) {
return 1.0 - Math.cos(x);
}
def code(x): return 1.0 - math.cos(x)
function code(x) return Float64(1.0 - cos(x)) end
function tmp = code(x) tmp = 1.0 - cos(x); end
code[x_] := N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \cos x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- 1.0 (cos x)))
double code(double x) {
return 1.0 - cos(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 - cos(x)
end function
public static double code(double x) {
return 1.0 - Math.cos(x);
}
def code(x): return 1.0 - math.cos(x)
function code(x) return Float64(1.0 - cos(x)) end
function tmp = code(x) tmp = 1.0 - cos(x); end
code[x_] := N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \cos x
\end{array}
(FPCore (x) :precision binary64 (fma (* x 0.5) x (* -0.041666666666666664 (pow x 4.0))))
double code(double x) {
return fma((x * 0.5), x, (-0.041666666666666664 * pow(x, 4.0)));
}
function code(x) return fma(Float64(x * 0.5), x, Float64(-0.041666666666666664 * (x ^ 4.0))) end
code[x_] := N[(N[(x * 0.5), $MachinePrecision] * x + N[(-0.041666666666666664 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot 0.5, x, -0.041666666666666664 \cdot {x}^{4}\right)
\end{array}
Initial program 54.6%
Taylor expanded in x around 0 100.0%
unpow2100.0%
Applied egg-rr100.0%
distribute-rgt-in100.0%
pow2100.0%
associate-*r*100.0%
fma-define100.0%
*-commutative100.0%
pow2100.0%
associate-*l*100.0%
pow-prod-up100.0%
metadata-eval100.0%
Applied egg-rr100.0%
(FPCore (x) :precision binary64 (* (* x x) (+ 0.5 (* -0.041666666666666664 (* x x)))))
double code(double x) {
return (x * x) * (0.5 + (-0.041666666666666664 * (x * x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * x) * (0.5d0 + ((-0.041666666666666664d0) * (x * x)))
end function
public static double code(double x) {
return (x * x) * (0.5 + (-0.041666666666666664 * (x * x)));
}
def code(x): return (x * x) * (0.5 + (-0.041666666666666664 * (x * x)))
function code(x) return Float64(Float64(x * x) * Float64(0.5 + Float64(-0.041666666666666664 * Float64(x * x)))) end
function tmp = code(x) tmp = (x * x) * (0.5 + (-0.041666666666666664 * (x * x))); end
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(0.5 + N[(-0.041666666666666664 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x\right) \cdot \left(0.5 + -0.041666666666666664 \cdot \left(x \cdot x\right)\right)
\end{array}
Initial program 54.6%
Taylor expanded in x around 0 100.0%
unpow2100.0%
Applied egg-rr100.0%
pow2100.0%
Applied egg-rr100.0%
(FPCore (x) :precision binary64 (* (* x 0.5) x))
double code(double x) {
return (x * 0.5) * x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * 0.5d0) * x
end function
public static double code(double x) {
return (x * 0.5) * x;
}
def code(x): return (x * 0.5) * x
function code(x) return Float64(Float64(x * 0.5) * x) end
function tmp = code(x) tmp = (x * 0.5) * x; end
code[x_] := N[(N[(x * 0.5), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 0.5\right) \cdot x
\end{array}
Initial program 54.6%
flip--54.6%
clear-num54.6%
metadata-eval54.6%
1-sub-cos98.8%
pow298.8%
Applied egg-rr98.8%
Taylor expanded in x around 0 98.3%
associate-/r/99.4%
metadata-eval99.4%
pow299.4%
associate-*r*99.5%
*-commutative99.5%
Applied egg-rr99.5%
(FPCore (x) :precision binary64 (* 0.5 (* x x)))
double code(double x) {
return 0.5 * (x * x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0 * (x * x)
end function
public static double code(double x) {
return 0.5 * (x * x);
}
def code(x): return 0.5 * (x * x)
function code(x) return Float64(0.5 * Float64(x * x)) end
function tmp = code(x) tmp = 0.5 * (x * x); end
code[x_] := N[(0.5 * N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(x \cdot x\right)
\end{array}
Initial program 54.6%
Taylor expanded in x around 0 99.4%
unpow2100.0%
Applied egg-rr99.4%
(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 54.6%
Taylor expanded in x around 0 53.4%
metadata-eval53.4%
Applied egg-rr53.4%
(FPCore (x) :precision binary64 (/ (* (sin x) (sin x)) (+ 1.0 (cos x))))
double code(double x) {
return (sin(x) * sin(x)) / (1.0 + cos(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (sin(x) * sin(x)) / (1.0d0 + cos(x))
end function
public static double code(double x) {
return (Math.sin(x) * Math.sin(x)) / (1.0 + Math.cos(x));
}
def code(x): return (math.sin(x) * math.sin(x)) / (1.0 + math.cos(x))
function code(x) return Float64(Float64(sin(x) * sin(x)) / Float64(1.0 + cos(x))) end
function tmp = code(x) tmp = (sin(x) * sin(x)) / (1.0 + cos(x)); end
code[x_] := N[(N[(N[Sin[x], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin x \cdot \sin x}{1 + \cos x}
\end{array}
herbie shell --seed 2024116 -o generate:simplify
(FPCore (x)
:name "ENA, Section 1.4, Mentioned, A"
:precision binary64
:pre (and (<= -0.01 x) (<= x 0.01))
:alt
(! :herbie-platform default (/ (* (sin x) (sin x)) (+ 1 (cos x))))
(- 1.0 (cos x)))