
(FPCore (x y) :precision binary64 (* x (/ (sin y) y)))
double code(double x, double y) {
return x * (sin(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (sin(y) / y)
end function
public static double code(double x, double y) {
return x * (Math.sin(y) / y);
}
def code(x, y): return x * (math.sin(y) / y)
function code(x, y) return Float64(x * Float64(sin(y) / y)) end
function tmp = code(x, y) tmp = x * (sin(y) / y); end
code[x_, y_] := N[(x * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{\sin y}{y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* x (/ (sin y) y)))
double code(double x, double y) {
return x * (sin(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (sin(y) / y)
end function
public static double code(double x, double y) {
return x * (Math.sin(y) / y);
}
def code(x, y): return x * (math.sin(y) / y)
function code(x, y) return Float64(x * Float64(sin(y) / y)) end
function tmp = code(x, y) tmp = x * (sin(y) / y); end
code[x_, y_] := N[(x * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{\sin y}{y}
\end{array}
(FPCore (x y) :precision binary64 (* (/ (sin y) y) x))
double code(double x, double y) {
return (sin(y) / y) * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (sin(y) / y) * x
end function
public static double code(double x, double y) {
return (Math.sin(y) / y) * x;
}
def code(x, y): return (math.sin(y) / y) * x
function code(x, y) return Float64(Float64(sin(y) / y) * x) end
function tmp = code(x, y) tmp = (sin(y) / y) * x; end
code[x_, y_] := N[(N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin y}{y} \cdot x
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y)
:precision binary64
(/
x
(fma
(fma
(fma 0.00205026455026455 (* y y) 0.019444444444444445)
(* y y)
0.16666666666666666)
(* y y)
1.0)))
double code(double x, double y) {
return x / fma(fma(fma(0.00205026455026455, (y * y), 0.019444444444444445), (y * y), 0.16666666666666666), (y * y), 1.0);
}
function code(x, y) return Float64(x / fma(fma(fma(0.00205026455026455, Float64(y * y), 0.019444444444444445), Float64(y * y), 0.16666666666666666), Float64(y * y), 1.0)) end
code[x_, y_] := N[(x / N[(N[(N[(0.00205026455026455 * N[(y * y), $MachinePrecision] + 0.019444444444444445), $MachinePrecision] * N[(y * y), $MachinePrecision] + 0.16666666666666666), $MachinePrecision] * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.00205026455026455, y \cdot y, 0.019444444444444445\right), y \cdot y, 0.16666666666666666\right), y \cdot y, 1\right)}
\end{array}
Initial program 99.8%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6499.8
Applied rewrites99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6464.4
Applied rewrites64.4%
(FPCore (x y) :precision binary64 (/ x (fma (fma 0.019444444444444445 (* y y) 0.16666666666666666) (* y y) 1.0)))
double code(double x, double y) {
return x / fma(fma(0.019444444444444445, (y * y), 0.16666666666666666), (y * y), 1.0);
}
function code(x, y) return Float64(x / fma(fma(0.019444444444444445, Float64(y * y), 0.16666666666666666), Float64(y * y), 1.0)) end
code[x_, y_] := N[(x / N[(N[(0.019444444444444445 * N[(y * y), $MachinePrecision] + 0.16666666666666666), $MachinePrecision] * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\mathsf{fma}\left(\mathsf{fma}\left(0.019444444444444445, y \cdot y, 0.16666666666666666\right), y \cdot y, 1\right)}
\end{array}
Initial program 99.8%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6499.8
Applied rewrites99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6464.3
Applied rewrites64.3%
(FPCore (x y) :precision binary64 (* (/ (- -1.0) (fma 0.16666666666666666 (* y y) 1.0)) x))
double code(double x, double y) {
return (-(-1.0) / fma(0.16666666666666666, (y * y), 1.0)) * x;
}
function code(x, y) return Float64(Float64(Float64(-(-1.0)) / fma(0.16666666666666666, Float64(y * y), 1.0)) * x) end
code[x_, y_] := N[(N[((--1.0) / N[(0.16666666666666666 * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\frac{--1}{\mathsf{fma}\left(0.16666666666666666, y \cdot y, 1\right)} \cdot x
\end{array}
Initial program 99.8%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6499.8
Applied rewrites99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6464.3
Applied rewrites64.3%
Taylor expanded in y around 0
Applied rewrites64.3%
lift-/.f64N/A
frac-2negN/A
div-invN/A
lower-*.f64N/A
lower-neg.f64N/A
frac-2negN/A
metadata-evalN/A
remove-double-negN/A
lower-/.f6464.3
Applied rewrites64.3%
Final simplification64.3%
(FPCore (x y) :precision binary64 (/ x (fma 0.16666666666666666 (* y y) 1.0)))
double code(double x, double y) {
return x / fma(0.16666666666666666, (y * y), 1.0);
}
function code(x, y) return Float64(x / fma(0.16666666666666666, Float64(y * y), 1.0)) end
code[x_, y_] := N[(x / N[(0.16666666666666666 * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\mathsf{fma}\left(0.16666666666666666, y \cdot y, 1\right)}
\end{array}
Initial program 99.8%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6499.8
Applied rewrites99.8%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6464.3
Applied rewrites64.3%
(FPCore (x y) :precision binary64 (* 1.0 x))
double code(double x, double y) {
return 1.0 * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 * x
end function
public static double code(double x, double y) {
return 1.0 * x;
}
def code(x, y): return 1.0 * x
function code(x, y) return Float64(1.0 * x) end
function tmp = code(x, y) tmp = 1.0 * x; end
code[x_, y_] := N[(1.0 * x), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot x
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites51.0%
Final simplification51.0%
herbie shell --seed 2024298
(FPCore (x y)
:name "Linear.Quaternion:$cexp from linear-1.19.1.3"
:precision binary64
(* x (/ (sin y) y)))