
(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 6 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%
Final simplification99.8%
(FPCore (x y) :precision binary64 (if (<= y 6.4) (* x (+ 1.0 (* -0.16666666666666666 (* y y)))) (/ 1.0 (/ (/ y x) y))))
double code(double x, double y) {
double tmp;
if (y <= 6.4) {
tmp = x * (1.0 + (-0.16666666666666666 * (y * y)));
} else {
tmp = 1.0 / ((y / x) / y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 6.4d0) then
tmp = x * (1.0d0 + ((-0.16666666666666666d0) * (y * y)))
else
tmp = 1.0d0 / ((y / x) / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 6.4) {
tmp = x * (1.0 + (-0.16666666666666666 * (y * y)));
} else {
tmp = 1.0 / ((y / x) / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 6.4: tmp = x * (1.0 + (-0.16666666666666666 * (y * y))) else: tmp = 1.0 / ((y / x) / y) return tmp
function code(x, y) tmp = 0.0 if (y <= 6.4) tmp = Float64(x * Float64(1.0 + Float64(-0.16666666666666666 * Float64(y * y)))); else tmp = Float64(1.0 / Float64(Float64(y / x) / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 6.4) tmp = x * (1.0 + (-0.16666666666666666 * (y * y))); else tmp = 1.0 / ((y / x) / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 6.4], N[(x * N[(1.0 + N[(-0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(y / x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.4:\\
\;\;\;\;x \cdot \left(1 + -0.16666666666666666 \cdot \left(y \cdot y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\frac{y}{x}}{y}}\\
\end{array}
\end{array}
if y < 6.4000000000000004Initial program 99.9%
Taylor expanded in y around 0 65.3%
unpow265.3%
Simplified65.3%
if 6.4000000000000004 < y Initial program 99.6%
*-commutative99.6%
associate-*l/99.7%
associate-*r/99.7%
Simplified99.7%
Taylor expanded in y around 0 29.0%
clear-num30.7%
un-div-inv30.7%
Applied egg-rr30.7%
frac-2neg30.7%
div-inv30.7%
distribute-neg-frac30.7%
Applied egg-rr30.7%
un-div-inv30.7%
clear-num30.7%
add-sqr-sqrt0.0%
sqrt-unprod30.8%
sqr-neg30.8%
sqrt-unprod30.1%
add-sqr-sqrt30.1%
add-sqr-sqrt0.0%
sqrt-unprod11.8%
sqr-neg11.8%
sqrt-unprod30.7%
add-sqr-sqrt30.7%
Applied egg-rr30.7%
Final simplification58.0%
(FPCore (x y) :precision binary64 (if (<= y 0.0305) x (/ 1.0 (/ (/ y x) y))))
double code(double x, double y) {
double tmp;
if (y <= 0.0305) {
tmp = x;
} else {
tmp = 1.0 / ((y / x) / y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 0.0305d0) then
tmp = x
else
tmp = 1.0d0 / ((y / x) / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 0.0305) {
tmp = x;
} else {
tmp = 1.0 / ((y / x) / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 0.0305: tmp = x else: tmp = 1.0 / ((y / x) / y) return tmp
function code(x, y) tmp = 0.0 if (y <= 0.0305) tmp = x; else tmp = Float64(1.0 / Float64(Float64(y / x) / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 0.0305) tmp = x; else tmp = 1.0 / ((y / x) / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 0.0305], x, N[(1.0 / N[(N[(y / x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.0305:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\frac{y}{x}}{y}}\\
\end{array}
\end{array}
if y < 0.030499999999999999Initial program 99.9%
Taylor expanded in y around 0 65.8%
if 0.030499999999999999 < y Initial program 99.6%
*-commutative99.6%
associate-*l/99.7%
associate-*r/99.7%
Simplified99.7%
Taylor expanded in y around 0 28.8%
clear-num30.5%
un-div-inv30.5%
Applied egg-rr30.5%
frac-2neg30.5%
div-inv30.5%
distribute-neg-frac30.5%
Applied egg-rr30.5%
un-div-inv30.5%
clear-num30.5%
add-sqr-sqrt0.0%
sqrt-unprod30.3%
sqr-neg30.3%
sqrt-unprod29.6%
add-sqr-sqrt29.6%
add-sqr-sqrt0.0%
sqrt-unprod11.9%
sqr-neg11.9%
sqrt-unprod30.5%
add-sqr-sqrt30.5%
Applied egg-rr30.5%
Final simplification58.2%
(FPCore (x y) :precision binary64 (if (<= y 6.5e-18) x (* y (/ x y))))
double code(double x, double y) {
double tmp;
if (y <= 6.5e-18) {
tmp = x;
} else {
tmp = y * (x / y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 6.5d-18) then
tmp = x
else
tmp = y * (x / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 6.5e-18) {
tmp = x;
} else {
tmp = y * (x / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 6.5e-18: tmp = x else: tmp = y * (x / y) return tmp
function code(x, y) tmp = 0.0 if (y <= 6.5e-18) tmp = x; else tmp = Float64(y * Float64(x / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 6.5e-18) tmp = x; else tmp = y * (x / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 6.5e-18], x, N[(y * N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.5 \cdot 10^{-18}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{y}\\
\end{array}
\end{array}
if y < 6.50000000000000008e-18Initial program 99.9%
Taylor expanded in y around 0 65.1%
if 6.50000000000000008e-18 < y Initial program 99.6%
*-commutative99.6%
associate-*l/99.7%
associate-*r/99.8%
Simplified99.8%
Taylor expanded in y around 0 35.0%
Final simplification57.8%
(FPCore (x y) :precision binary64 (if (<= y 8000000.0) x (/ y (/ y x))))
double code(double x, double y) {
double tmp;
if (y <= 8000000.0) {
tmp = x;
} else {
tmp = y / (y / x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 8000000.0d0) then
tmp = x
else
tmp = y / (y / x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 8000000.0) {
tmp = x;
} else {
tmp = y / (y / x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 8000000.0: tmp = x else: tmp = y / (y / x) return tmp
function code(x, y) tmp = 0.0 if (y <= 8000000.0) tmp = x; else tmp = Float64(y / Float64(y / x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 8000000.0) tmp = x; else tmp = y / (y / x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 8000000.0], x, N[(y / N[(y / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8000000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{y}{x}}\\
\end{array}
\end{array}
if y < 8e6Initial program 99.9%
Taylor expanded in y around 0 65.3%
if 8e6 < y Initial program 99.6%
*-commutative99.6%
associate-*l/99.6%
associate-*r/99.8%
Simplified99.8%
Taylor expanded in y around 0 29.3%
clear-num31.0%
un-div-inv31.0%
Applied egg-rr31.0%
Final simplification58.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.8%
Taylor expanded in y around 0 52.7%
Final simplification52.7%
herbie shell --seed 2023279
(FPCore (x y)
:name "Linear.Quaternion:$cexp from linear-1.19.1.3"
:precision binary64
(* x (/ (sin y) y)))