
(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 8 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
(if (<= (/ (sin y) y) 1e-21)
0.0
(*
x
(fma
(* (* (* 0.008333333333333333 y) y) y)
y
(fma (* -0.16666666666666666 y) y 1.0)))))
double code(double x, double y) {
double tmp;
if ((sin(y) / y) <= 1e-21) {
tmp = 0.0;
} else {
tmp = x * fma((((0.008333333333333333 * y) * y) * y), y, fma((-0.16666666666666666 * y), y, 1.0));
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(sin(y) / y) <= 1e-21) tmp = 0.0; else tmp = Float64(x * fma(Float64(Float64(Float64(0.008333333333333333 * y) * y) * y), y, fma(Float64(-0.16666666666666666 * y), y, 1.0))); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], 1e-21], 0.0, N[(x * N[(N[(N[(N[(0.008333333333333333 * y), $MachinePrecision] * y), $MachinePrecision] * y), $MachinePrecision] * y + N[(N[(-0.16666666666666666 * y), $MachinePrecision] * y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sin y}{y} \leq 10^{-21}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(\left(\left(0.008333333333333333 \cdot y\right) \cdot y\right) \cdot y, y, \mathsf{fma}\left(-0.16666666666666666 \cdot y, y, 1\right)\right)\\
\end{array}
\end{array}
if (/.f64 (sin.f64 y) y) < 9.99999999999999908e-22Initial 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 rewrites98.7%
Taylor expanded in y around 0
*-commutativeN/A
associate-/l*N/A
sin-negN/A
sin-PIN/A
metadata-evalN/A
mul0-lft28.0
Applied rewrites28.0%
if 9.99999999999999908e-22 < (/.f64 (sin.f64 y) y) Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-+l+N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
distribute-lft1-inN/A
+-commutativeN/A
distribute-rgt-outN/A
lower-*.f64N/A
Applied rewrites98.8%
Applied rewrites98.8%
Final simplification68.6%
(FPCore (x y)
:precision binary64
(if (<= (/ (sin y) y) 1e-21)
0.0
(*
x
(fma
(* y y)
(fma (* 0.008333333333333333 y) y -0.16666666666666666)
1.0))))
double code(double x, double y) {
double tmp;
if ((sin(y) / y) <= 1e-21) {
tmp = 0.0;
} else {
tmp = x * fma((y * y), fma((0.008333333333333333 * y), y, -0.16666666666666666), 1.0);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(sin(y) / y) <= 1e-21) tmp = 0.0; else tmp = Float64(x * fma(Float64(y * y), fma(Float64(0.008333333333333333 * y), y, -0.16666666666666666), 1.0)); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], 1e-21], 0.0, N[(x * N[(N[(y * y), $MachinePrecision] * N[(N[(0.008333333333333333 * y), $MachinePrecision] * y + -0.16666666666666666), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sin y}{y} \leq 10^{-21}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(0.008333333333333333 \cdot y, y, -0.16666666666666666\right), 1\right)\\
\end{array}
\end{array}
if (/.f64 (sin.f64 y) y) < 9.99999999999999908e-22Initial 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 rewrites98.7%
Taylor expanded in y around 0
*-commutativeN/A
associate-/l*N/A
sin-negN/A
sin-PIN/A
metadata-evalN/A
mul0-lft28.0
Applied rewrites28.0%
if 9.99999999999999908e-22 < (/.f64 (sin.f64 y) y) Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-+l+N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
distribute-lft1-inN/A
+-commutativeN/A
distribute-rgt-outN/A
lower-*.f64N/A
Applied rewrites98.8%
Final simplification68.6%
(FPCore (x y) :precision binary64 (if (<= (* x (/ (sin y) y)) 5e-307) 0.0 x))
double code(double x, double y) {
double tmp;
if ((x * (sin(y) / y)) <= 5e-307) {
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 ((x * (sin(y) / y)) <= 5d-307) then
tmp = 0.0d0
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x * (Math.sin(y) / y)) <= 5e-307) {
tmp = 0.0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x * (math.sin(y) / y)) <= 5e-307: tmp = 0.0 else: tmp = x return tmp
function code(x, y) tmp = 0.0 if (Float64(x * Float64(sin(y) / y)) <= 5e-307) tmp = 0.0; else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x * (sin(y) / y)) <= 5e-307) tmp = 0.0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], 5e-307], 0.0, x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot \frac{\sin y}{y} \leq 5 \cdot 10^{-307}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 x (/.f64 (sin.f64 y) y)) < 5.00000000000000014e-307Initial 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 rewrites53.7%
Taylor expanded in y around 0
*-commutativeN/A
associate-/l*N/A
sin-negN/A
sin-PIN/A
metadata-evalN/A
mul0-lft20.5
Applied rewrites20.5%
if 5.00000000000000014e-307 < (*.f64 x (/.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 rewrites38.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
+-commutativeN/A
sin-negN/A
sin-PIN/A
metadata-evalN/A
+-lft-identityN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
associate-/l*N/A
*-inversesN/A
*-rgt-identity66.2
Applied rewrites66.2%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (* y y) x)))
(if (<= y 50000000000.0)
(fma
(fma -0.0001984126984126984 (* y y) 0.008333333333333333)
(* (* y y) t_0)
(fma -0.16666666666666666 t_0 x))
0.0)))
double code(double x, double y) {
double t_0 = (y * y) * x;
double tmp;
if (y <= 50000000000.0) {
tmp = fma(fma(-0.0001984126984126984, (y * y), 0.008333333333333333), ((y * y) * t_0), fma(-0.16666666666666666, t_0, x));
} else {
tmp = 0.0;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(y * y) * x) tmp = 0.0 if (y <= 50000000000.0) tmp = fma(fma(-0.0001984126984126984, Float64(y * y), 0.008333333333333333), Float64(Float64(y * y) * t_0), fma(-0.16666666666666666, t_0, x)); else tmp = 0.0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, 50000000000.0], N[(N[(-0.0001984126984126984 * N[(y * y), $MachinePrecision] + 0.008333333333333333), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * t$95$0), $MachinePrecision] + N[(-0.16666666666666666 * t$95$0 + x), $MachinePrecision]), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y \cdot y\right) \cdot x\\
\mathbf{if}\;y \leq 50000000000:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.0001984126984126984, y \cdot y, 0.008333333333333333\right), \left(y \cdot y\right) \cdot t\_0, \mathsf{fma}\left(-0.16666666666666666, t\_0, x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if y < 5e10Initial program 99.9%
Taylor expanded in y around 0
Applied rewrites74.0%
Applied rewrites74.0%
if 5e10 < y 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 rewrites98.7%
Taylor expanded in y around 0
*-commutativeN/A
associate-/l*N/A
sin-negN/A
sin-PIN/A
metadata-evalN/A
mul0-lft24.5
Applied rewrites24.5%
Final simplification62.8%
(FPCore (x y)
:precision binary64
(if (<= y 50000000000.0)
(fma
(* (* y y) x)
(fma
(* (fma -0.0001984126984126984 (* y y) 0.008333333333333333) y)
y
-0.16666666666666666)
x)
0.0))
double code(double x, double y) {
double tmp;
if (y <= 50000000000.0) {
tmp = fma(((y * y) * x), fma((fma(-0.0001984126984126984, (y * y), 0.008333333333333333) * y), y, -0.16666666666666666), x);
} else {
tmp = 0.0;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= 50000000000.0) tmp = fma(Float64(Float64(y * y) * x), fma(Float64(fma(-0.0001984126984126984, Float64(y * y), 0.008333333333333333) * y), y, -0.16666666666666666), x); else tmp = 0.0; end return tmp end
code[x_, y_] := If[LessEqual[y, 50000000000.0], N[(N[(N[(y * y), $MachinePrecision] * x), $MachinePrecision] * N[(N[(N[(-0.0001984126984126984 * N[(y * y), $MachinePrecision] + 0.008333333333333333), $MachinePrecision] * y), $MachinePrecision] * y + -0.16666666666666666), $MachinePrecision] + x), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 50000000000:\\
\;\;\;\;\mathsf{fma}\left(\left(y \cdot y\right) \cdot x, \mathsf{fma}\left(\mathsf{fma}\left(-0.0001984126984126984, y \cdot y, 0.008333333333333333\right) \cdot y, y, -0.16666666666666666\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if y < 5e10Initial program 99.9%
Taylor expanded in y around 0
Applied rewrites74.0%
if 5e10 < y 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 rewrites98.7%
Taylor expanded in y around 0
*-commutativeN/A
associate-/l*N/A
sin-negN/A
sin-PIN/A
metadata-evalN/A
mul0-lft24.5
Applied rewrites24.5%
Final simplification62.8%
(FPCore (x y) :precision binary64 (if (<= y 27000000000000.0) (fma y (* (* x y) -0.16666666666666666) x) 0.0))
double code(double x, double y) {
double tmp;
if (y <= 27000000000000.0) {
tmp = fma(y, ((x * y) * -0.16666666666666666), x);
} else {
tmp = 0.0;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= 27000000000000.0) tmp = fma(y, Float64(Float64(x * y) * -0.16666666666666666), x); else tmp = 0.0; end return tmp end
code[x_, y_] := If[LessEqual[y, 27000000000000.0], N[(y * N[(N[(x * y), $MachinePrecision] * -0.16666666666666666), $MachinePrecision] + x), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 27000000000000:\\
\;\;\;\;\mathsf{fma}\left(y, \left(x \cdot y\right) \cdot -0.16666666666666666, x\right)\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if y < 2.7e13Initial program 99.9%
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-*.f6485.9
Applied rewrites85.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6473.4
Applied rewrites73.4%
Applied rewrites73.4%
if 2.7e13 < y 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 rewrites98.7%
Taylor expanded in y around 0
*-commutativeN/A
associate-/l*N/A
sin-negN/A
sin-PIN/A
metadata-evalN/A
mul0-lft24.8
Applied rewrites24.8%
Final simplification62.6%
(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.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 rewrites47.7%
Taylor expanded in y around 0
*-commutativeN/A
associate-/l*N/A
sin-negN/A
sin-PIN/A
metadata-evalN/A
mul0-lft14.0
Applied rewrites14.0%
herbie shell --seed 2024326
(FPCore (x y)
:name "Linear.Quaternion:$cexp from linear-1.19.1.3"
:precision binary64
(* x (/ (sin y) y)))