
(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 6 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 (* 0.5 x)) (sin x)) (cos (/ x -2.0))))
double code(double x) {
return (sin((0.5 * x)) * sin(x)) / cos((x / -2.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (sin((0.5d0 * x)) * sin(x)) / cos((x / (-2.0d0)))
end function
public static double code(double x) {
return (Math.sin((0.5 * x)) * Math.sin(x)) / Math.cos((x / -2.0));
}
def code(x): return (math.sin((0.5 * x)) * math.sin(x)) / math.cos((x / -2.0))
function code(x) return Float64(Float64(sin(Float64(0.5 * x)) * sin(x)) / cos(Float64(x / -2.0))) end
function tmp = code(x) tmp = (sin((0.5 * x)) * sin(x)) / cos((x / -2.0)); end
code[x_] := N[(N[(N[Sin[N[(0.5 * x), $MachinePrecision]], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[Cos[N[(x / -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin \left(0.5 \cdot x\right) \cdot \sin x}{\cos \left(\frac{x}{-2}\right)}
\end{array}
Initial program 50.1%
flip--50.1%
div-inv50.1%
metadata-eval50.1%
1-sub-cos100.0%
pow2100.0%
Applied egg-rr100.0%
associate-*r/100.0%
*-rgt-identity100.0%
unpow2100.0%
associate-/l*100.0%
hang-0p-tan100.0%
Simplified100.0%
*-commutative100.0%
tan-quot100.0%
associate-*l/100.0%
clear-num99.9%
associate-/r/100.0%
metadata-eval100.0%
frac-2neg100.0%
distribute-frac-neg100.0%
cos-neg100.0%
metadata-eval100.0%
Applied egg-rr100.0%
(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 50.1%
flip--50.1%
div-inv50.1%
metadata-eval50.1%
1-sub-cos100.0%
pow2100.0%
Applied egg-rr100.0%
associate-*r/100.0%
*-rgt-identity100.0%
unpow2100.0%
associate-/l*100.0%
hang-0p-tan100.0%
Simplified100.0%
(FPCore (x) :precision binary64 (* (* 0.5 x) (sin x)))
double code(double x) {
return (0.5 * x) * sin(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (0.5d0 * x) * sin(x)
end function
public static double code(double x) {
return (0.5 * x) * Math.sin(x);
}
def code(x): return (0.5 * x) * math.sin(x)
function code(x) return Float64(Float64(0.5 * x) * sin(x)) end
function tmp = code(x) tmp = (0.5 * x) * sin(x); end
code[x_] := N[(N[(0.5 * x), $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot x\right) \cdot \sin x
\end{array}
Initial program 50.1%
flip--50.1%
div-inv50.1%
metadata-eval50.1%
1-sub-cos100.0%
pow2100.0%
Applied egg-rr100.0%
associate-*r/100.0%
*-rgt-identity100.0%
unpow2100.0%
associate-/l*100.0%
hang-0p-tan100.0%
Simplified100.0%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
(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(x * Float64(0.5 * x)) end
function tmp = code(x) tmp = x * (0.5 * x); end
code[x_] := N[(x * N[(0.5 * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(0.5 \cdot x\right)
\end{array}
Initial program 50.1%
flip--50.1%
div-inv50.1%
metadata-eval50.1%
1-sub-cos100.0%
pow2100.0%
Applied egg-rr100.0%
associate-*r/100.0%
*-rgt-identity100.0%
unpow2100.0%
associate-/l*100.0%
hang-0p-tan100.0%
Simplified100.0%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around 0 99.8%
(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 50.1%
Taylor expanded in x around 0 99.8%
unpow299.8%
Applied egg-rr99.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 50.1%
Taylor expanded in x around 0 49.8%
metadata-eval49.8%
Applied egg-rr49.8%
(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 2024188
(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)))