
(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 (<= y 7.2e+18) (* x (+ 1.0 (* -0.16666666666666666 (* y y)))) (/ (/ (* x 6.0) y) y)))
double code(double x, double y) {
double tmp;
if (y <= 7.2e+18) {
tmp = x * (1.0 + (-0.16666666666666666 * (y * y)));
} else {
tmp = ((x * 6.0) / y) / y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 7.2d+18) then
tmp = x * (1.0d0 + ((-0.16666666666666666d0) * (y * y)))
else
tmp = ((x * 6.0d0) / y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 7.2e+18) {
tmp = x * (1.0 + (-0.16666666666666666 * (y * y)));
} else {
tmp = ((x * 6.0) / y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 7.2e+18: tmp = x * (1.0 + (-0.16666666666666666 * (y * y))) else: tmp = ((x * 6.0) / y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 7.2e+18) tmp = Float64(x * Float64(1.0 + Float64(-0.16666666666666666 * Float64(y * y)))); else tmp = Float64(Float64(Float64(x * 6.0) / y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 7.2e+18) tmp = x * (1.0 + (-0.16666666666666666 * (y * y))); else tmp = ((x * 6.0) / y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 7.2e+18], N[(x * N[(1.0 + N[(-0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * 6.0), $MachinePrecision] / y), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 7.2 \cdot 10^{+18}:\\
\;\;\;\;x \cdot \left(1 + -0.16666666666666666 \cdot \left(y \cdot y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x \cdot 6}{y}}{y}\\
\end{array}
\end{array}
if y < 7.2e18Initial program 99.9%
Taylor expanded in y around 0
*-rgt-identityN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-inN/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6473.7%
Simplified73.7%
if 7.2e18 < y Initial program 99.5%
Taylor expanded in y around 0
*-rgt-identityN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-inN/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f642.0%
Simplified2.0%
*-commutativeN/A
flip-+N/A
associate-*l/N/A
associate-/l*N/A
*-lowering-*.f64N/A
Applied egg-rr6.1%
Taylor expanded in y around 0
Simplified30.4%
Taylor expanded in y around inf
associate-*r/N/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6430.5%
Simplified30.5%
(FPCore (x y) :precision binary64 (if (<= y 2.5) x (/ (/ (* x 6.0) y) y)))
double code(double x, double y) {
double tmp;
if (y <= 2.5) {
tmp = x;
} else {
tmp = ((x * 6.0) / y) / y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 2.5d0) then
tmp = x
else
tmp = ((x * 6.0d0) / y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.5) {
tmp = x;
} else {
tmp = ((x * 6.0) / y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.5: tmp = x else: tmp = ((x * 6.0) / y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 2.5) tmp = x; else tmp = Float64(Float64(Float64(x * 6.0) / y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.5) tmp = x; else tmp = ((x * 6.0) / y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.5], x, N[(N[(N[(x * 6.0), $MachinePrecision] / y), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.5:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x \cdot 6}{y}}{y}\\
\end{array}
\end{array}
if y < 2.5Initial program 99.9%
Taylor expanded in y around 0
Simplified75.1%
if 2.5 < y Initial program 99.5%
Taylor expanded in y around 0
*-rgt-identityN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-inN/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f642.4%
Simplified2.4%
*-commutativeN/A
flip-+N/A
associate-*l/N/A
associate-/l*N/A
*-lowering-*.f64N/A
Applied egg-rr6.2%
Taylor expanded in y around 0
Simplified28.6%
Taylor expanded in y around inf
associate-*r/N/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6428.7%
Simplified28.7%
(FPCore (x y) :precision binary64 (/ (- 0.0 x) (+ (* y (* y 0.16666666666666666)) -1.0)))
double code(double x, double y) {
return (0.0 - x) / ((y * (y * 0.16666666666666666)) + -1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (0.0d0 - x) / ((y * (y * 0.16666666666666666d0)) + (-1.0d0))
end function
public static double code(double x, double y) {
return (0.0 - x) / ((y * (y * 0.16666666666666666)) + -1.0);
}
def code(x, y): return (0.0 - x) / ((y * (y * 0.16666666666666666)) + -1.0)
function code(x, y) return Float64(Float64(0.0 - x) / Float64(Float64(y * Float64(y * 0.16666666666666666)) + -1.0)) end
function tmp = code(x, y) tmp = (0.0 - x) / ((y * (y * 0.16666666666666666)) + -1.0); end
code[x_, y_] := N[(N[(0.0 - x), $MachinePrecision] / N[(N[(y * N[(y * 0.16666666666666666), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0 - x}{y \cdot \left(y \cdot 0.16666666666666666\right) + -1}
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
*-rgt-identityN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-inN/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6458.5%
Simplified58.5%
*-commutativeN/A
flip-+N/A
associate-*l/N/A
associate-/l*N/A
*-lowering-*.f64N/A
Applied egg-rr59.5%
Taylor expanded in y around 0
Simplified68.4%
Applied egg-rr68.5%
Final simplification68.5%
(FPCore (x y) :precision binary64 (/ x (+ (* y (* y 0.16666666666666666)) 1.0)))
double code(double x, double y) {
return x / ((y * (y * 0.16666666666666666)) + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x / ((y * (y * 0.16666666666666666d0)) + 1.0d0)
end function
public static double code(double x, double y) {
return x / ((y * (y * 0.16666666666666666)) + 1.0);
}
def code(x, y): return x / ((y * (y * 0.16666666666666666)) + 1.0)
function code(x, y) return Float64(x / Float64(Float64(y * Float64(y * 0.16666666666666666)) + 1.0)) end
function tmp = code(x, y) tmp = x / ((y * (y * 0.16666666666666666)) + 1.0); end
code[x_, y_] := N[(x / N[(N[(y * N[(y * 0.16666666666666666), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{y \cdot \left(y \cdot 0.16666666666666666\right) + 1}
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
*-rgt-identityN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-inN/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6458.5%
Simplified58.5%
*-commutativeN/A
flip-+N/A
associate-*l/N/A
associate-/l*N/A
*-lowering-*.f64N/A
Applied egg-rr59.5%
Taylor expanded in y around 0
Simplified68.4%
*-lft-identityN/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6468.4%
Applied egg-rr68.4%
Final simplification68.4%
(FPCore (x y) :precision binary64 (if (<= y 2.8e+41) x 0.0))
double code(double x, double y) {
double tmp;
if (y <= 2.8e+41) {
tmp = x;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 2.8d+41) then
tmp = x
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.8e+41) {
tmp = x;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.8e+41: tmp = x else: tmp = 0.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 2.8e+41) tmp = x; else tmp = 0.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.8e+41) tmp = x; else tmp = 0.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.8e+41], x, 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.8 \cdot 10^{+41}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if y < 2.7999999999999999e41Initial program 99.9%
Taylor expanded in y around 0
Simplified72.8%
if 2.7999999999999999e41 < y Initial program 99.5%
Applied egg-rr31.5%
(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.8%
Applied egg-rr13.2%
herbie shell --seed 2024152
(FPCore (x y)
:name "Linear.Quaternion:$cexp from linear-1.19.1.3"
:precision binary64
(* x (/ (sin y) y)))