
(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 4 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.7%
(FPCore (x y) :precision binary64 (if (<= (/ (sin y) y) 4e-84) 0.0 x))
double code(double x, double y) {
double tmp;
if ((sin(y) / y) <= 4e-84) {
tmp = 0.0;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((sin(y) / y) <= 4d-84) then
tmp = 0.0d0
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((Math.sin(y) / y) <= 4e-84) {
tmp = 0.0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (math.sin(y) / y) <= 4e-84: tmp = 0.0 else: tmp = x return tmp
function code(x, y) tmp = 0.0 if (Float64(sin(y) / y) <= 4e-84) tmp = 0.0; else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((sin(y) / y) <= 4e-84) tmp = 0.0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], 4e-84], 0.0, x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sin y}{y} \leq 4 \cdot 10^{-84}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (/.f64 (sin.f64 y) y) < 4.0000000000000001e-84Initial program 99.5%
remove-double-negN/A
lift-sin.f64N/A
sin-+PI-revN/A
sin-neg-revN/A
+-commutativeN/A
distribute-neg-inN/A
sin-sumN/A
cos-neg-revN/A
cos-neg-revN/A
sin-neg-revN/A
lift-sin.f64N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lift-sin.f64N/A
sin-neg-revN/A
lower-fma.f64N/A
Applied rewrites98.5%
Taylor expanded in y around 0
*-commutativeN/A
associate-/l*N/A
sin-negN/A
sin-PIN/A
metadata-evalN/A
mul0-lft26.0
Applied rewrites26.0%
if 4.0000000000000001e-84 < (/.f64 (sin.f64 y) y) Initial program 99.9%
remove-double-negN/A
lift-sin.f64N/A
sin-+PI-revN/A
sin-neg-revN/A
+-commutativeN/A
distribute-neg-inN/A
sin-sumN/A
cos-neg-revN/A
cos-neg-revN/A
sin-neg-revN/A
lift-sin.f64N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lift-sin.f64N/A
sin-neg-revN/A
lower-fma.f64N/A
Applied rewrites16.4%
Taylor expanded in y around 0
div-addN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
associate-/l*N/A
distribute-rgt-outN/A
sin-negN/A
sin-PIN/A
metadata-evalN/A
+-rgt-identityN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
associate-/l*N/A
*-inversesN/A
*-rgt-identity90.2
Applied rewrites90.2%
Final simplification59.8%
(FPCore (x y) :precision binary64 (if (<= y 2.05e+29) (fma y (* y (* -0.16666666666666666 x)) x) 0.0))
double code(double x, double y) {
double tmp;
if (y <= 2.05e+29) {
tmp = fma(y, (y * (-0.16666666666666666 * x)), x);
} else {
tmp = 0.0;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= 2.05e+29) tmp = fma(y, Float64(y * Float64(-0.16666666666666666 * x)), x); else tmp = 0.0; end return tmp end
code[x_, y_] := If[LessEqual[y, 2.05e+29], N[(y * N[(y * N[(-0.16666666666666666 * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.05 \cdot 10^{+29}:\\
\;\;\;\;\mathsf{fma}\left(y, y \cdot \left(-0.16666666666666666 \cdot x\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if y < 2.0500000000000002e29Initial program 99.8%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
frac-2negN/A
frac-2negN/A
remove-double-negN/A
lower-/.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
distribute-lft-neg-inN/A
remove-double-negN/A
lower-*.f6479.8
Applied rewrites79.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6464.1
Applied rewrites64.1%
Applied rewrites64.1%
if 2.0500000000000002e29 < y Initial program 99.4%
remove-double-negN/A
lift-sin.f64N/A
sin-+PI-revN/A
sin-neg-revN/A
+-commutativeN/A
distribute-neg-inN/A
sin-sumN/A
cos-neg-revN/A
cos-neg-revN/A
sin-neg-revN/A
lift-sin.f64N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lift-sin.f64N/A
sin-neg-revN/A
lower-fma.f64N/A
Applied rewrites98.6%
Taylor expanded in y around 0
*-commutativeN/A
associate-/l*N/A
sin-negN/A
sin-PIN/A
metadata-evalN/A
mul0-lft25.3
Applied rewrites25.3%
Final simplification54.4%
(FPCore (x y) :precision binary64 0.0)
double code(double x, double y) {
return 0.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.0d0
end function
public static double code(double x, double y) {
return 0.0;
}
def code(x, y): return 0.0
function code(x, y) return 0.0 end
function tmp = code(x, y) tmp = 0.0; end
code[x_, y_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 99.7%
remove-double-negN/A
lift-sin.f64N/A
sin-+PI-revN/A
sin-neg-revN/A
+-commutativeN/A
distribute-neg-inN/A
sin-sumN/A
cos-neg-revN/A
cos-neg-revN/A
sin-neg-revN/A
lift-sin.f64N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lift-sin.f64N/A
sin-neg-revN/A
lower-fma.f64N/A
Applied rewrites55.2%
Taylor expanded in y around 0
*-commutativeN/A
associate-/l*N/A
sin-negN/A
sin-PIN/A
metadata-evalN/A
mul0-lft14.6
Applied rewrites14.6%
Final simplification14.6%
herbie shell --seed 2024338
(FPCore (x y)
:name "Linear.Quaternion:$cexp from linear-1.19.1.3"
:precision binary64
(* x (/ (sin y) y)))