
(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 (if (<= (/ (sin y) y) 0.05) (* y (/ x y)) (* x (fma y (* y -0.16666666666666666) 1.0))))
double code(double x, double y) {
double tmp;
if ((sin(y) / y) <= 0.05) {
tmp = y * (x / y);
} else {
tmp = x * fma(y, (y * -0.16666666666666666), 1.0);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(sin(y) / y) <= 0.05) tmp = Float64(y * Float64(x / y)); else tmp = Float64(x * fma(y, Float64(y * -0.16666666666666666), 1.0)); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], 0.05], N[(y * N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x * N[(y * N[(y * -0.16666666666666666), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sin y}{y} \leq 0.05:\\
\;\;\;\;y \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(y, y \cdot -0.16666666666666666, 1\right)\\
\end{array}
\end{array}
if (/.f64 (sin.f64 y) y) < 0.050000000000000003Initial program 99.5%
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.7
Applied egg-rr99.7%
Taylor expanded in y around 0
Simplified22.5%
if 0.050000000000000003 < (/.f64 (sin.f64 y) y) Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6499.4
Simplified99.4%
Final simplification65.2%
(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(y, Float64(y * fma(Float64(y * y), fma(y, Float64(y * 0.00205026455026455), 0.019444444444444445), 0.16666666666666666)), 1.0)) end
code[x_, y_] := N[(x / N[(y * N[(y * N[(N[(y * y), $MachinePrecision] * N[(y * N[(y * 0.00205026455026455), $MachinePrecision] + 0.019444444444444445), $MachinePrecision] + 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, \mathsf{fma}\left(y, y \cdot 0.00205026455026455, 0.019444444444444445\right), 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.4
Applied egg-rr99.4%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*l*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f64N/A
+-commutativeN/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6466.5
Simplified66.5%
(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.4
Applied egg-rr99.4%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*l*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f6466.5
Simplified66.5%
(FPCore (x y) :precision binary64 (if (<= y 2.35) (fma -0.16666666666666666 (* y (* x y)) x) (* y (/ x y))))
double code(double x, double y) {
double tmp;
if (y <= 2.35) {
tmp = fma(-0.16666666666666666, (y * (x * y)), x);
} else {
tmp = y * (x / y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= 2.35) tmp = fma(-0.16666666666666666, Float64(y * Float64(x * y)), x); else tmp = Float64(y * Float64(x / y)); end return tmp end
code[x_, y_] := If[LessEqual[y, 2.35], N[(-0.16666666666666666 * N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(y * N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.35:\\
\;\;\;\;\mathsf{fma}\left(-0.16666666666666666, y \cdot \left(x \cdot y\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{y}\\
\end{array}
\end{array}
if y < 2.35000000000000009Initial program 99.8%
clear-numN/A
associate-/r/N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
sin-lowering-sin.f6499.7
Applied egg-rr99.7%
Taylor expanded in y around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f6472.8
Simplified72.8%
if 2.35000000000000009 < 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.6
Applied egg-rr99.6%
Taylor expanded in y around 0
Simplified19.9%
Final simplification60.4%
(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.4
Applied egg-rr99.4%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6466.3
Simplified66.3%
(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
Simplified56.4%
herbie shell --seed 2024198
(FPCore (x y)
:name "Linear.Quaternion:$cexp from linear-1.19.1.3"
:precision binary64
(* x (/ (sin y) y)))