
(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 (or (<= y -1.95) (not (<= y 1.25e+19))) (/ 1.0 (* (+ (/ 1.0 y) (* y 0.16666666666666666)) (/ y x))) (* x (+ 1.0 (* -0.16666666666666666 (* y y))))))
double code(double x, double y) {
double tmp;
if ((y <= -1.95) || !(y <= 1.25e+19)) {
tmp = 1.0 / (((1.0 / y) + (y * 0.16666666666666666)) * (y / x));
} else {
tmp = x * (1.0 + (-0.16666666666666666 * (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 <= (-1.95d0)) .or. (.not. (y <= 1.25d+19))) then
tmp = 1.0d0 / (((1.0d0 / y) + (y * 0.16666666666666666d0)) * (y / x))
else
tmp = x * (1.0d0 + ((-0.16666666666666666d0) * (y * y)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.95) || !(y <= 1.25e+19)) {
tmp = 1.0 / (((1.0 / y) + (y * 0.16666666666666666)) * (y / x));
} else {
tmp = x * (1.0 + (-0.16666666666666666 * (y * y)));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.95) or not (y <= 1.25e+19): tmp = 1.0 / (((1.0 / y) + (y * 0.16666666666666666)) * (y / x)) else: tmp = x * (1.0 + (-0.16666666666666666 * (y * y))) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.95) || !(y <= 1.25e+19)) tmp = Float64(1.0 / Float64(Float64(Float64(1.0 / y) + Float64(y * 0.16666666666666666)) * Float64(y / x))); else tmp = Float64(x * Float64(1.0 + Float64(-0.16666666666666666 * Float64(y * y)))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.95) || ~((y <= 1.25e+19))) tmp = 1.0 / (((1.0 / y) + (y * 0.16666666666666666)) * (y / x)); else tmp = x * (1.0 + (-0.16666666666666666 * (y * y))); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.95], N[Not[LessEqual[y, 1.25e+19]], $MachinePrecision]], N[(1.0 / N[(N[(N[(1.0 / y), $MachinePrecision] + N[(y * 0.16666666666666666), $MachinePrecision]), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 + N[(-0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \lor \neg \left(y \leq 1.25 \cdot 10^{+19}\right):\\
\;\;\;\;\frac{1}{\left(\frac{1}{y} + y \cdot 0.16666666666666666\right) \cdot \frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 + -0.16666666666666666 \cdot \left(y \cdot y\right)\right)\\
\end{array}
\end{array}
if y < -1.94999999999999996 or 1.25e19 < y Initial program 99.6%
associate-*r/99.6%
clear-num98.5%
*-commutative98.5%
Applied egg-rr98.5%
*-un-lft-identity98.5%
times-frac98.4%
Applied egg-rr98.4%
Taylor expanded in y around 0 21.0%
if -1.94999999999999996 < y < 1.25e19Initial program 100.0%
Taylor expanded in y around 0 98.5%
unpow298.5%
Simplified98.5%
Final simplification59.2%
(FPCore (x y) :precision binary64 (if (or (<= y -2.3) (not (<= y 2.7e+22))) (/ y (/ y x)) (* x (+ 1.0 (* -0.16666666666666666 (* y y))))))
double code(double x, double y) {
double tmp;
if ((y <= -2.3) || !(y <= 2.7e+22)) {
tmp = y / (y / x);
} else {
tmp = x * (1.0 + (-0.16666666666666666 * (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.3d0)) .or. (.not. (y <= 2.7d+22))) then
tmp = y / (y / x)
else
tmp = x * (1.0d0 + ((-0.16666666666666666d0) * (y * y)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2.3) || !(y <= 2.7e+22)) {
tmp = y / (y / x);
} else {
tmp = x * (1.0 + (-0.16666666666666666 * (y * y)));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.3) or not (y <= 2.7e+22): tmp = y / (y / x) else: tmp = x * (1.0 + (-0.16666666666666666 * (y * y))) return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.3) || !(y <= 2.7e+22)) tmp = Float64(y / Float64(y / x)); else tmp = Float64(x * Float64(1.0 + Float64(-0.16666666666666666 * Float64(y * y)))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2.3) || ~((y <= 2.7e+22))) tmp = y / (y / x); else tmp = x * (1.0 + (-0.16666666666666666 * (y * y))); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.3], N[Not[LessEqual[y, 2.7e+22]], $MachinePrecision]], N[(y / N[(y / x), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 + N[(-0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \lor \neg \left(y \leq 2.7 \cdot 10^{+22}\right):\\
\;\;\;\;\frac{y}{\frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 + -0.16666666666666666 \cdot \left(y \cdot y\right)\right)\\
\end{array}
\end{array}
if y < -2.2999999999999998 or 2.7000000000000002e22 < y Initial program 99.6%
Taylor expanded in x around 0 99.6%
Taylor expanded in y around 0 4.2%
associate-/l*20.0%
div-inv20.0%
clear-num19.5%
Applied egg-rr19.5%
clear-num20.0%
un-div-inv20.0%
Applied egg-rr20.0%
if -2.2999999999999998 < y < 2.7000000000000002e22Initial program 100.0%
Taylor expanded in y around 0 98.5%
unpow298.5%
Simplified98.5%
Final simplification58.7%
(FPCore (x y) :precision binary64 (if (or (<= y -9.8e-8) (not (<= y 5e+27))) (* y (/ x y)) x))
double code(double x, double y) {
double tmp;
if ((y <= -9.8e-8) || !(y <= 5e+27)) {
tmp = y * (x / y);
} 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 ((y <= (-9.8d-8)) .or. (.not. (y <= 5d+27))) then
tmp = y * (x / y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -9.8e-8) || !(y <= 5e+27)) {
tmp = y * (x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -9.8e-8) or not (y <= 5e+27): tmp = y * (x / y) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -9.8e-8) || !(y <= 5e+27)) tmp = Float64(y * Float64(x / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -9.8e-8) || ~((y <= 5e+27))) tmp = y * (x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -9.8e-8], N[Not[LessEqual[y, 5e+27]], $MachinePrecision]], N[(y * N[(x / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.8 \cdot 10^{-8} \lor \neg \left(y \leq 5 \cdot 10^{+27}\right):\\
\;\;\;\;y \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -9.8000000000000004e-8 or 4.99999999999999979e27 < y Initial program 99.6%
Taylor expanded in x around 0 99.6%
Taylor expanded in y around 0 4.9%
associate-/l*20.8%
div-inv20.8%
clear-num20.3%
Applied egg-rr20.3%
if -9.8000000000000004e-8 < y < 4.99999999999999979e27Initial program 100.0%
Taylor expanded in y around 0 96.9%
Final simplification58.3%
(FPCore (x y) :precision binary64 (if (or (<= y -3.6e-8) (not (<= y 2e-50))) (/ y (/ y x)) x))
double code(double x, double y) {
double tmp;
if ((y <= -3.6e-8) || !(y <= 2e-50)) {
tmp = y / (y / x);
} 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 ((y <= (-3.6d-8)) .or. (.not. (y <= 2d-50))) then
tmp = y / (y / x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -3.6e-8) || !(y <= 2e-50)) {
tmp = y / (y / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3.6e-8) or not (y <= 2e-50): tmp = y / (y / x) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -3.6e-8) || !(y <= 2e-50)) tmp = Float64(y / Float64(y / x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -3.6e-8) || ~((y <= 2e-50))) tmp = y / (y / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3.6e-8], N[Not[LessEqual[y, 2e-50]], $MachinePrecision]], N[(y / N[(y / x), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.6 \cdot 10^{-8} \lor \neg \left(y \leq 2 \cdot 10^{-50}\right):\\
\;\;\;\;\frac{y}{\frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.59999999999999981e-8 or 2.00000000000000002e-50 < y Initial program 99.7%
Taylor expanded in x around 0 99.6%
Taylor expanded in y around 0 12.0%
associate-/l*26.3%
div-inv26.3%
clear-num25.9%
Applied egg-rr25.9%
clear-num26.3%
un-div-inv26.3%
Applied egg-rr26.3%
if -3.59999999999999981e-8 < y < 2.00000000000000002e-50Initial program 100.0%
Taylor expanded in y around 0 100.0%
Final simplification58.6%
(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 50.6%
Final simplification50.6%
herbie shell --seed 2023195
(FPCore (x y)
:name "Linear.Quaternion:$cexp from linear-1.19.1.3"
:precision binary64
(* x (/ (sin y) y)))