
(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 7 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 (/ x (/ y (sin y))))
double code(double x, double y) {
return x / (y / sin(y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x / (y / sin(y))
end function
public static double code(double x, double y) {
return x / (y / Math.sin(y));
}
def code(x, y): return x / (y / math.sin(y))
function code(x, y) return Float64(x / Float64(y / sin(y))) end
function tmp = code(x, y) tmp = x / (y / sin(y)); end
code[x_, y_] := N[(x / N[(y / N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{y}{\sin y}}
\end{array}
Initial program 99.8%
lift-sin.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6499.8
Applied rewrites99.8%
(FPCore (x y) :precision binary64 (if (<= (/ (sin y) y) 5e-6) (* (/ x (* y y)) 6.0) (fma x (* (* y y) -0.16666666666666666) x)))
double code(double x, double y) {
double tmp;
if ((sin(y) / y) <= 5e-6) {
tmp = (x / (y * y)) * 6.0;
} else {
tmp = fma(x, ((y * y) * -0.16666666666666666), x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(sin(y) / y) <= 5e-6) tmp = Float64(Float64(x / Float64(y * y)) * 6.0); else tmp = fma(x, Float64(Float64(y * y) * -0.16666666666666666), x); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], 5e-6], N[(N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision] * 6.0), $MachinePrecision], N[(x * N[(N[(y * y), $MachinePrecision] * -0.16666666666666666), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sin y}{y} \leq 5 \cdot 10^{-6}:\\
\;\;\;\;\frac{x}{y \cdot y} \cdot 6\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \left(y \cdot y\right) \cdot -0.16666666666666666, x\right)\\
\end{array}
\end{array}
if (/.f64 (sin.f64 y) y) < 5.00000000000000041e-6Initial program 99.6%
lift-sin.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6499.7
Applied rewrites99.7%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f6428.7
Applied rewrites28.7%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6428.7
Applied rewrites28.7%
*-rgt-identityN/A
lift-*.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
metadata-eval28.7
Applied rewrites28.7%
if 5.00000000000000041e-6 < (/.f64 (sin.f64 y) y) Initial program 100.0%
Taylor expanded in y around 0
associate-*r*N/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.1
Applied rewrites99.1%
Final simplification65.5%
(FPCore (x y) :precision binary64 (if (<= (/ (sin y) y) 5e-6) (* x (/ 6.0 (* y y))) (fma x (* (* y y) -0.16666666666666666) x)))
double code(double x, double y) {
double tmp;
if ((sin(y) / y) <= 5e-6) {
tmp = x * (6.0 / (y * y));
} else {
tmp = fma(x, ((y * y) * -0.16666666666666666), x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(sin(y) / y) <= 5e-6) tmp = Float64(x * Float64(6.0 / Float64(y * y))); else tmp = fma(x, Float64(Float64(y * y) * -0.16666666666666666), x); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], 5e-6], N[(x * N[(6.0 / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(y * y), $MachinePrecision] * -0.16666666666666666), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sin y}{y} \leq 5 \cdot 10^{-6}:\\
\;\;\;\;x \cdot \frac{6}{y \cdot y}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \left(y \cdot y\right) \cdot -0.16666666666666666, x\right)\\
\end{array}
\end{array}
if (/.f64 (sin.f64 y) y) < 5.00000000000000041e-6Initial program 99.6%
lift-sin.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6499.7
Applied rewrites99.7%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f6428.7
Applied rewrites28.7%
Taylor expanded in y around inf
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6428.7
Applied rewrites28.7%
if 5.00000000000000041e-6 < (/.f64 (sin.f64 y) y) Initial program 100.0%
Taylor expanded in y around 0
associate-*r*N/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.1
Applied rewrites99.1%
Final simplification65.5%
(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}
Initial program 99.8%
(FPCore (x y)
:precision binary64
(/
x
(fma
(* y y)
(fma
(* y y)
(fma (* y y) 0.00205026455026455 0.019444444444444445)
0.16666666666666666)
1.0)))
double code(double x, double y) {
return x / fma((y * y), fma((y * y), fma((y * y), 0.00205026455026455, 0.019444444444444445), 0.16666666666666666), 1.0);
}
function code(x, y) return Float64(x / fma(Float64(y * y), fma(Float64(y * y), fma(Float64(y * y), 0.00205026455026455, 0.019444444444444445), 0.16666666666666666), 1.0)) end
code[x_, y_] := N[(x / N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * 0.00205026455026455 + 0.019444444444444445), $MachinePrecision] + 0.16666666666666666), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, 0.00205026455026455, 0.019444444444444445\right), 0.16666666666666666\right), 1\right)}
\end{array}
Initial program 99.8%
lift-sin.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-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6465.6
Applied rewrites65.6%
(FPCore (x y) :precision binary64 (/ x (fma y (* y 0.16666666666666666) 1.0)))
double code(double x, double y) {
return x / fma(y, (y * 0.16666666666666666), 1.0);
}
function code(x, y) return Float64(x / fma(y, Float64(y * 0.16666666666666666), 1.0)) end
code[x_, y_] := N[(x / N[(y * N[(y * 0.16666666666666666), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\mathsf{fma}\left(y, y \cdot 0.16666666666666666, 1\right)}
\end{array}
Initial program 99.8%
lift-sin.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
unpow2N/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f6465.5
Applied rewrites65.5%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites53.8%
*-rgt-identity53.8
Applied rewrites53.8%
herbie shell --seed 2024216
(FPCore (x y)
:name "Linear.Quaternion:$cexp from linear-1.19.1.3"
:precision binary64
(* x (/ (sin y) y)))