
(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 3 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 (* (* x x) (fma -0.041666666666666664 (* x x) 0.5)))
double code(double x) {
return (x * x) * fma(-0.041666666666666664, (x * x), 0.5);
}
function code(x) return Float64(Float64(x * x) * fma(-0.041666666666666664, Float64(x * x), 0.5)) end
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(-0.041666666666666664 * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x\right) \cdot \mathsf{fma}\left(-0.041666666666666664, x \cdot x, 0.5\right)
\end{array}
Initial program 52.7%
Taylor expanded in x around 0 100.0%
fma-def100.0%
unpow2100.0%
Simplified100.0%
fma-udef100.0%
associate-*r*100.0%
metadata-eval100.0%
associate-/r/99.8%
clear-num100.0%
div-inv100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 100.0%
unpow2100.0%
*-commutative100.0%
*-commutative100.0%
metadata-eval100.0%
pow-sqr100.0%
unpow2100.0%
unpow2100.0%
associate-*r*100.0%
distribute-lft-out100.0%
+-commutative100.0%
*-commutative100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (+ (* (* x x) (* (* x x) -0.041666666666666664)) (* (* x x) 0.5)))
double code(double x) {
return ((x * x) * ((x * x) * -0.041666666666666664)) + ((x * x) * 0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((x * x) * ((x * x) * (-0.041666666666666664d0))) + ((x * x) * 0.5d0)
end function
public static double code(double x) {
return ((x * x) * ((x * x) * -0.041666666666666664)) + ((x * x) * 0.5);
}
def code(x): return ((x * x) * ((x * x) * -0.041666666666666664)) + ((x * x) * 0.5)
function code(x) return Float64(Float64(Float64(x * x) * Float64(Float64(x * x) * -0.041666666666666664)) + Float64(Float64(x * x) * 0.5)) end
function tmp = code(x) tmp = ((x * x) * ((x * x) * -0.041666666666666664)) + ((x * x) * 0.5); end
code[x_] := N[(N[(N[(x * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision] + N[(N[(x * x), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot -0.041666666666666664\right) + \left(x \cdot x\right) \cdot 0.5
\end{array}
Initial program 52.7%
Taylor expanded in x around 0 100.0%
fma-def100.0%
unpow2100.0%
Simplified100.0%
fma-udef100.0%
associate-*r*100.0%
metadata-eval100.0%
associate-/r/99.8%
clear-num100.0%
div-inv100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 100.0%
unpow2100.0%
*-commutative100.0%
*-commutative100.0%
metadata-eval100.0%
pow-sqr100.0%
unpow2100.0%
unpow2100.0%
associate-*r*100.0%
distribute-lft-out100.0%
+-commutative100.0%
*-commutative100.0%
fma-def100.0%
Simplified100.0%
fma-udef100.0%
distribute-rgt-in100.0%
*-commutative100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (* (* x x) 0.5))
double code(double x) {
return (x * x) * 0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * x) * 0.5d0
end function
public static double code(double x) {
return (x * x) * 0.5;
}
def code(x): return (x * x) * 0.5
function code(x) return Float64(Float64(x * x) * 0.5) end
function tmp = code(x) tmp = (x * x) * 0.5; end
code[x_] := N[(N[(x * x), $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x\right) \cdot 0.5
\end{array}
Initial program 52.7%
Taylor expanded in x around 0 99.6%
unpow299.6%
Simplified99.6%
Final simplification99.6%
(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 2023207
(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)))