
(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 5 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.9%
(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.9%
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
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f6465.2
Simplified65.2%
(FPCore (x y) :precision binary64 (if (<= y 95000000000000.0) (* x (fma y (* y -0.16666666666666666) 1.0)) (* y (/ x y))))
double code(double x, double y) {
double tmp;
if (y <= 95000000000000.0) {
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 <= 95000000000000.0) 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, 95000000000000.0], 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 95000000000000:\\
\;\;\;\;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 < 9.5e13Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6467.2
Simplified67.2%
if 9.5e13 < y Initial program 99.7%
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
Simplified23.4%
Final simplification57.1%
(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.9%
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-*.f6465.2
Simplified65.2%
(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.9%
Taylor expanded in y around 0
Simplified52.9%
herbie shell --seed 2024205
(FPCore (x y)
:name "Linear.Quaternion:$cexp from linear-1.19.1.3"
:precision binary64
(* x (/ (sin y) y)))