
(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 (/ 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-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6499.8
Applied rewrites99.8%
(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 (if (<= y 2.5e+36) (fma (* (* y y) x) -0.16666666666666666 x) (* (- y) (/ (- x) y))))
double code(double x, double y) {
double tmp;
if (y <= 2.5e+36) {
tmp = fma(((y * y) * x), -0.16666666666666666, x);
} else {
tmp = -y * (-x / y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= 2.5e+36) tmp = fma(Float64(Float64(y * y) * x), -0.16666666666666666, x); else tmp = Float64(Float64(-y) * Float64(Float64(-x) / y)); end return tmp end
code[x_, y_] := If[LessEqual[y, 2.5e+36], N[(N[(N[(y * y), $MachinePrecision] * x), $MachinePrecision] * -0.16666666666666666 + x), $MachinePrecision], N[((-y) * N[((-x) / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.5 \cdot 10^{+36}:\\
\;\;\;\;\mathsf{fma}\left(\left(y \cdot y\right) \cdot x, -0.16666666666666666, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-y\right) \cdot \frac{-x}{y}\\
\end{array}
\end{array}
if y < 2.49999999999999988e36Initial program 99.9%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
lift-/.f64N/A
*-rgt-identityN/A
remove-double-negN/A
lift-neg.f64N/A
neg-mul-1N/A
times-fracN/A
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
lift-neg.f64N/A
frac-2negN/A
lower-/.f64N/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
neg-mul-1N/A
lower-neg.f6499.7
Applied rewrites99.7%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6466.6
Applied rewrites66.6%
if 2.49999999999999988e36 < y Initial program 99.5%
lift-/.f64N/A
clear-numN/A
frac-2negN/A
associate-/r/N/A
lower-*.f64N/A
metadata-evalN/A
frac-2negN/A
lower-/.f64N/A
lower-neg.f6499.5
Applied rewrites99.5%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f644.7
Applied rewrites4.7%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*l/N/A
neg-mul-1N/A
lower-/.f64N/A
lower-neg.f6429.6
Applied rewrites29.6%
Final simplification55.9%
(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-*.f6461.4
Applied rewrites61.4%
(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 rewrites48.9%
Final simplification48.9%
herbie shell --seed 2024294
(FPCore (x y)
:name "Linear.Quaternion:$cexp from linear-1.19.1.3"
:precision binary64
(* x (/ (sin y) y)))