
(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 (/ (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) 0.019444444444444445 0.16666666666666666)) 1.0)))
double code(double x, double y) {
return x / fma(y, (y * fma((y * y), 0.019444444444444445, 0.16666666666666666)), 1.0);
}
function code(x, y) return Float64(x / fma(y, Float64(y * fma(Float64(y * y), 0.019444444444444445, 0.16666666666666666)), 1.0)) end
code[x_, y_] := N[(x / N[(y * N[(y * N[(N[(y * y), $MachinePrecision] * 0.019444444444444445 + 0.16666666666666666), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, 0.019444444444444445, 0.16666666666666666\right), 1\right)}
\end{array}
Initial program 99.8%
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
sin-lowering-sin.f6499.8
Applied egg-rr99.8%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f6464.6
Simplified64.6%
(FPCore (x y) :precision binary64 (if (<= y 3.1) (* x (fma y (* y -0.16666666666666666) 1.0)) (/ x (* (* y y) -0.16666666666666666))))
double code(double x, double y) {
double tmp;
if (y <= 3.1) {
tmp = x * fma(y, (y * -0.16666666666666666), 1.0);
} else {
tmp = x / ((y * y) * -0.16666666666666666);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= 3.1) tmp = Float64(x * fma(y, Float64(y * -0.16666666666666666), 1.0)); else tmp = Float64(x / Float64(Float64(y * y) * -0.16666666666666666)); end return tmp end
code[x_, y_] := If[LessEqual[y, 3.1], N[(x * N[(y * N[(y * -0.16666666666666666), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(x / N[(N[(y * y), $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.1:\\
\;\;\;\;x \cdot \mathsf{fma}\left(y, y \cdot -0.16666666666666666, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\left(y \cdot y\right) \cdot -0.16666666666666666}\\
\end{array}
\end{array}
if y < 3.10000000000000009Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6471.7
Simplified71.7%
if 3.10000000000000009 < y Initial program 99.6%
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
sin-lowering-sin.f6499.4
Applied egg-rr99.4%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6423.8
Simplified23.8%
Applied egg-rr24.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6424.0
Simplified24.0%
Final simplification60.2%
(FPCore (x y) :precision binary64 (if (<= y 5.5e+36) (* x (fma y (* y -0.16666666666666666) 1.0)) (* x (/ 6.0 (* y y)))))
double code(double x, double y) {
double tmp;
if (y <= 5.5e+36) {
tmp = x * fma(y, (y * -0.16666666666666666), 1.0);
} else {
tmp = x * (6.0 / (y * y));
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= 5.5e+36) tmp = Float64(x * fma(y, Float64(y * -0.16666666666666666), 1.0)); else tmp = Float64(x * Float64(6.0 / Float64(y * y))); end return tmp end
code[x_, y_] := If[LessEqual[y, 5.5e+36], N[(x * N[(y * N[(y * -0.16666666666666666), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(x * N[(6.0 / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5.5 \cdot 10^{+36}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(y, y \cdot -0.16666666666666666, 1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{6}{y \cdot y}\\
\end{array}
\end{array}
if y < 5.5000000000000002e36Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6470.5
Simplified70.5%
if 5.5000000000000002e36 < y Initial program 99.6%
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
sin-lowering-sin.f6499.5
Applied egg-rr99.5%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6425.4
Simplified25.4%
Taylor expanded in y around inf
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6425.4
Simplified25.4%
(FPCore (x y) :precision binary64 (if (<= y 3.6e+36) (* x (fma y (* y -0.16666666666666666) 1.0)) (* y (/ x y))))
double code(double x, double y) {
double tmp;
if (y <= 3.6e+36) {
tmp = x * fma(y, (y * -0.16666666666666666), 1.0);
} else {
tmp = y * (x / y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= 3.6e+36) tmp = Float64(x * fma(y, Float64(y * -0.16666666666666666), 1.0)); else tmp = Float64(y * Float64(x / y)); end return tmp end
code[x_, y_] := If[LessEqual[y, 3.6e+36], N[(x * N[(y * N[(y * -0.16666666666666666), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.6 \cdot 10^{+36}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(y, y \cdot -0.16666666666666666, 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{y}\\
\end{array}
\end{array}
if y < 3.5999999999999997e36Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6470.5
Simplified70.5%
if 3.5999999999999997e36 < y Initial program 99.6%
associate-*r/N/A
associate-*l/N/A
*-lft-identityN/A
associate-*l/N/A
*-lowering-*.f64N/A
associate-*l/N/A
*-lft-identityN/A
/-lowering-/.f64N/A
sin-lowering-sin.f6499.4
Applied egg-rr99.4%
Taylor expanded in y around 0
Simplified23.6%
Final simplification59.8%
(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%
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
sin-lowering-sin.f6499.8
Applied egg-rr99.8%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6464.5
Simplified64.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
Simplified55.2%
herbie shell --seed 2024204
(FPCore (x y)
:name "Linear.Quaternion:$cexp from linear-1.19.1.3"
:precision binary64
(* x (/ (sin y) y)))