
(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
(*
(*
(fma
(* x x)
(* -0.003472222222222222 (* x x))
(/ (- -0.25) (fma 0.041666666666666664 (* x x) 0.5)))
x)
x))
double code(double x) {
return (fma((x * x), (-0.003472222222222222 * (x * x)), (-(-0.25) / fma(0.041666666666666664, (x * x), 0.5))) * x) * x;
}
function code(x) return Float64(Float64(fma(Float64(x * x), Float64(-0.003472222222222222 * Float64(x * x)), Float64(Float64(-(-0.25)) / fma(0.041666666666666664, Float64(x * x), 0.5))) * x) * x) end
code[x_] := N[(N[(N[(N[(x * x), $MachinePrecision] * N[(-0.003472222222222222 * N[(x * x), $MachinePrecision]), $MachinePrecision] + N[((--0.25) / N[(0.041666666666666664 * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\left(\mathsf{fma}\left(x \cdot x, -0.003472222222222222 \cdot \left(x \cdot x\right), \frac{--0.25}{\mathsf{fma}\left(0.041666666666666664, x \cdot x, 0.5\right)}\right) \cdot x\right) \cdot x
\end{array}
Initial program 51.5%
Taylor expanded in x around 0
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (* (* (fma -0.041666666666666664 (* x x) 0.5) x) x))
double code(double x) {
return (fma(-0.041666666666666664, (x * x), 0.5) * x) * x;
}
function code(x) return Float64(Float64(fma(-0.041666666666666664, Float64(x * x), 0.5) * x) * x) end
code[x_] := N[(N[(N[(-0.041666666666666664 * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\left(\mathsf{fma}\left(-0.041666666666666664, x \cdot x, 0.5\right) \cdot x\right) \cdot x
\end{array}
Initial program 51.5%
Taylor expanded in x around 0
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
(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(Float64(0.5 * x) * x) end
function tmp = code(x) tmp = (0.5 * x) * x; end
code[x_] := N[(N[(0.5 * x), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot x\right) \cdot x
\end{array}
Initial program 51.5%
Taylor expanded in x around 0
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites99.9%
(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 51.5%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (- 1.0 1.0))
double code(double x) {
return 1.0 - 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 - 1.0d0
end function
public static double code(double x) {
return 1.0 - 1.0;
}
def code(x): return 1.0 - 1.0
function code(x) return Float64(1.0 - 1.0) end
function tmp = code(x) tmp = 1.0 - 1.0; end
code[x_] := N[(1.0 - 1.0), $MachinePrecision]
\begin{array}{l}
\\
1 - 1
\end{array}
Initial program 51.5%
Taylor expanded in x around 0
Applied rewrites51.2%
(FPCore (x) :precision binary64 2.0)
double code(double x) {
return 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0
end function
public static double code(double x) {
return 2.0;
}
def code(x): return 2.0
function code(x) return 2.0 end
function tmp = code(x) tmp = 2.0; end
code[x_] := 2.0
\begin{array}{l}
\\
2
\end{array}
Initial program 51.5%
Taylor expanded in x around 0
Applied rewrites51.2%
lift--.f64N/A
sub-negN/A
flip3-+N/A
sqr-powN/A
unpow-prod-downN/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
sqr-negN/A
Applied rewrites4.1%
Taylor expanded in x around 0
Applied rewrites4.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 2024255
(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)))