
(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 (* (sin x) (tan (/ x 2.0))))
double code(double x) {
return sin(x) * tan((x / 2.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sin(x) * tan((x / 2.0d0))
end function
public static double code(double x) {
return Math.sin(x) * Math.tan((x / 2.0));
}
def code(x): return math.sin(x) * math.tan((x / 2.0))
function code(x) return Float64(sin(x) * tan(Float64(x / 2.0))) end
function tmp = code(x) tmp = sin(x) * tan((x / 2.0)); end
code[x_] := N[(N[Sin[x], $MachinePrecision] * N[Tan[N[(x / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin x \cdot \tan \left(\frac{x}{2}\right)
\end{array}
Initial program 53.5%
flip--53.5%
div-inv53.5%
metadata-eval53.5%
1-sub-cos100.0%
pow2100.0%
Applied egg-rr100.0%
associate-*r/100.0%
*-rgt-identity100.0%
unpow2100.0%
associate-*r/100.0%
hang-0p-tan100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (* 0.5 (pow x 2.0)))
double code(double x) {
return 0.5 * pow(x, 2.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0 * (x ** 2.0d0)
end function
public static double code(double x) {
return 0.5 * Math.pow(x, 2.0);
}
def code(x): return 0.5 * math.pow(x, 2.0)
function code(x) return Float64(0.5 * (x ^ 2.0)) end
function tmp = code(x) tmp = 0.5 * (x ^ 2.0); end
code[x_] := N[(0.5 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot {x}^{2}
\end{array}
Initial program 53.5%
Taylor expanded in x around 0 99.5%
Final simplification99.5%
(FPCore (x) :precision binary64 (/ 1.0 (+ 0.16666666666666666 (/ -2.0 (* x (- x))))))
double code(double x) {
return 1.0 / (0.16666666666666666 + (-2.0 / (x * -x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (0.16666666666666666d0 + ((-2.0d0) / (x * -x)))
end function
public static double code(double x) {
return 1.0 / (0.16666666666666666 + (-2.0 / (x * -x)));
}
def code(x): return 1.0 / (0.16666666666666666 + (-2.0 / (x * -x)))
function code(x) return Float64(1.0 / Float64(0.16666666666666666 + Float64(-2.0 / Float64(x * Float64(-x))))) end
function tmp = code(x) tmp = 1.0 / (0.16666666666666666 + (-2.0 / (x * -x))); end
code[x_] := N[(1.0 / N[(0.16666666666666666 + N[(-2.0 / N[(x * (-x)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{0.16666666666666666 + \frac{-2}{x \cdot \left(-x\right)}}
\end{array}
Initial program 53.5%
flip--53.5%
clear-num53.5%
metadata-eval53.5%
1-sub-cos99.0%
pow299.0%
Applied egg-rr99.0%
Taylor expanded in x around 0 99.0%
associate-*r/99.0%
metadata-eval99.0%
Simplified99.0%
div-inv99.0%
*-commutative99.0%
add-sqr-sqrt98.6%
associate-*l*98.6%
sqrt-div98.7%
metadata-eval98.7%
unpow298.7%
sqrt-prod51.3%
add-sqr-sqrt76.5%
sqrt-div76.4%
metadata-eval76.4%
unpow276.4%
sqrt-prod51.3%
add-sqr-sqrt98.6%
Applied egg-rr98.6%
frac-2neg98.6%
metadata-eval98.6%
associate-*l/98.6%
metadata-eval98.6%
frac-times99.0%
metadata-eval99.0%
Applied egg-rr99.0%
Final simplification99.0%
(FPCore (x) :precision binary64 (/ 1.0 (+ 0.16666666666666666 (/ (/ 2.0 x) x))))
double code(double x) {
return 1.0 / (0.16666666666666666 + ((2.0 / x) / x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (0.16666666666666666d0 + ((2.0d0 / x) / x))
end function
public static double code(double x) {
return 1.0 / (0.16666666666666666 + ((2.0 / x) / x));
}
def code(x): return 1.0 / (0.16666666666666666 + ((2.0 / x) / x))
function code(x) return Float64(1.0 / Float64(0.16666666666666666 + Float64(Float64(2.0 / x) / x))) end
function tmp = code(x) tmp = 1.0 / (0.16666666666666666 + ((2.0 / x) / x)); end
code[x_] := N[(1.0 / N[(0.16666666666666666 + N[(N[(2.0 / x), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{0.16666666666666666 + \frac{\frac{2}{x}}{x}}
\end{array}
Initial program 53.5%
flip--53.5%
clear-num53.5%
metadata-eval53.5%
1-sub-cos99.0%
pow299.0%
Applied egg-rr99.0%
Taylor expanded in x around 0 99.0%
associate-*r/99.0%
metadata-eval99.0%
Simplified99.0%
div-inv99.0%
*-commutative99.0%
add-sqr-sqrt98.6%
associate-*l*98.6%
sqrt-div98.7%
metadata-eval98.7%
unpow298.7%
sqrt-prod51.3%
add-sqr-sqrt76.5%
sqrt-div76.4%
metadata-eval76.4%
unpow276.4%
sqrt-prod51.3%
add-sqr-sqrt98.6%
Applied egg-rr98.6%
associate-*l/98.8%
*-un-lft-identity98.8%
associate-*l/98.8%
metadata-eval98.8%
Applied egg-rr98.8%
Final simplification98.8%
(FPCore (x) :precision binary64 6.0)
double code(double x) {
return 6.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 6.0d0
end function
public static double code(double x) {
return 6.0;
}
def code(x): return 6.0
function code(x) return 6.0 end
function tmp = code(x) tmp = 6.0; end
code[x_] := 6.0
\begin{array}{l}
\\
6
\end{array}
Initial program 53.5%
flip--53.5%
clear-num53.5%
metadata-eval53.5%
1-sub-cos99.0%
pow299.0%
Applied egg-rr99.0%
Taylor expanded in x around 0 99.0%
associate-*r/99.0%
metadata-eval99.0%
Simplified99.0%
Taylor expanded in x around inf 4.1%
Final simplification4.1%
(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 2024024
(FPCore (x)
:name "ENA, Section 1.4, Mentioned, A"
:precision binary64
:pre (and (<= -0.01 x) (<= x 0.01))
:herbie-target
(/ (* (sin x) (sin x)) (+ 1.0 (cos x)))
(- 1.0 (cos x)))