
(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 9 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 (/ y (sin y))))
double code(double x, double y) {
return x / (y / sin(y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x / (y / sin(y))
end function
public static double code(double x, double y) {
return x / (y / Math.sin(y));
}
def code(x, y): return x / (y / math.sin(y))
function code(x, y) return Float64(x / Float64(y / sin(y))) end
function tmp = code(x, y) tmp = x / (y / sin(y)); end
code[x_, y_] := N[(x / N[(y / N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{y}{\sin y}}
\end{array}
Initial program 99.8%
clear-num99.7%
un-div-inv99.8%
Applied egg-rr99.8%
Final simplification99.8%
(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 -1e+15) (not (<= y 1.3e+35))) (* 6.0 (/ x (* y y))) (* x (+ 1.0 (* (* y y) -0.16666666666666666)))))
double code(double x, double y) {
double tmp;
if ((y <= -1e+15) || !(y <= 1.3e+35)) {
tmp = 6.0 * (x / (y * y));
} else {
tmp = x * (1.0 + ((y * y) * -0.16666666666666666));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-1d+15)) .or. (.not. (y <= 1.3d+35))) then
tmp = 6.0d0 * (x / (y * y))
else
tmp = x * (1.0d0 + ((y * y) * (-0.16666666666666666d0)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1e+15) || !(y <= 1.3e+35)) {
tmp = 6.0 * (x / (y * y));
} else {
tmp = x * (1.0 + ((y * y) * -0.16666666666666666));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1e+15) or not (y <= 1.3e+35): tmp = 6.0 * (x / (y * y)) else: tmp = x * (1.0 + ((y * y) * -0.16666666666666666)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1e+15) || !(y <= 1.3e+35)) tmp = Float64(6.0 * Float64(x / Float64(y * y))); else tmp = Float64(x * Float64(1.0 + Float64(Float64(y * y) * -0.16666666666666666))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1e+15) || ~((y <= 1.3e+35))) tmp = 6.0 * (x / (y * y)); else tmp = x * (1.0 + ((y * y) * -0.16666666666666666)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1e+15], N[Not[LessEqual[y, 1.3e+35]], $MachinePrecision]], N[(6.0 * N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 + N[(N[(y * y), $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{+15} \lor \neg \left(y \leq 1.3 \cdot 10^{+35}\right):\\
\;\;\;\;6 \cdot \frac{x}{y \cdot y}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 + \left(y \cdot y\right) \cdot -0.16666666666666666\right)\\
\end{array}
\end{array}
if y < -1e15 or 1.30000000000000003e35 < y Initial program 99.6%
clear-num99.5%
un-div-inv99.6%
Applied egg-rr99.6%
clear-num99.5%
associate-/r/99.6%
Applied egg-rr99.6%
Taylor expanded in y around 0 27.4%
Taylor expanded in y around inf 27.4%
unpow227.4%
Simplified27.4%
if -1e15 < y < 1.30000000000000003e35Initial program 99.9%
Taylor expanded in y around 0 93.0%
unpow293.0%
Simplified93.0%
Final simplification65.3%
(FPCore (x y) :precision binary64 (if (or (<= y -1e+15) (not (<= y 1.16e+35))) (* 6.0 (/ x (* y y))) (+ x (* (* y y) (* x -0.16666666666666666)))))
double code(double x, double y) {
double tmp;
if ((y <= -1e+15) || !(y <= 1.16e+35)) {
tmp = 6.0 * (x / (y * y));
} else {
tmp = x + ((y * y) * (x * -0.16666666666666666));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-1d+15)) .or. (.not. (y <= 1.16d+35))) then
tmp = 6.0d0 * (x / (y * y))
else
tmp = x + ((y * y) * (x * (-0.16666666666666666d0)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1e+15) || !(y <= 1.16e+35)) {
tmp = 6.0 * (x / (y * y));
} else {
tmp = x + ((y * y) * (x * -0.16666666666666666));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1e+15) or not (y <= 1.16e+35): tmp = 6.0 * (x / (y * y)) else: tmp = x + ((y * y) * (x * -0.16666666666666666)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1e+15) || !(y <= 1.16e+35)) tmp = Float64(6.0 * Float64(x / Float64(y * y))); else tmp = Float64(x + Float64(Float64(y * y) * Float64(x * -0.16666666666666666))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1e+15) || ~((y <= 1.16e+35))) tmp = 6.0 * (x / (y * y)); else tmp = x + ((y * y) * (x * -0.16666666666666666)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1e+15], N[Not[LessEqual[y, 1.16e+35]], $MachinePrecision]], N[(6.0 * N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(y * y), $MachinePrecision] * N[(x * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{+15} \lor \neg \left(y \leq 1.16 \cdot 10^{+35}\right):\\
\;\;\;\;6 \cdot \frac{x}{y \cdot y}\\
\mathbf{else}:\\
\;\;\;\;x + \left(y \cdot y\right) \cdot \left(x \cdot -0.16666666666666666\right)\\
\end{array}
\end{array}
if y < -1e15 or 1.1600000000000001e35 < y Initial program 99.6%
clear-num99.5%
un-div-inv99.6%
Applied egg-rr99.6%
clear-num99.5%
associate-/r/99.6%
Applied egg-rr99.6%
Taylor expanded in y around 0 27.4%
Taylor expanded in y around inf 27.4%
unpow227.4%
Simplified27.4%
if -1e15 < y < 1.1600000000000001e35Initial program 99.9%
add-cube-cbrt97.8%
pow397.8%
Applied egg-rr97.8%
Taylor expanded in y around 0 93.1%
pow-base-193.1%
*-lft-identity93.1%
unpow293.1%
distribute-rgt-out93.1%
pow-base-193.1%
*-lft-identity93.1%
metadata-eval93.1%
Simplified93.1%
Final simplification65.4%
(FPCore (x y) :precision binary64 (if (or (<= y -2.4) (not (<= y 2.4))) (* 6.0 (/ x (* y y))) x))
double code(double x, double y) {
double tmp;
if ((y <= -2.4) || !(y <= 2.4)) {
tmp = 6.0 * (x / (y * 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 <= (-2.4d0)) .or. (.not. (y <= 2.4d0))) then
tmp = 6.0d0 * (x / (y * y))
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2.4) || !(y <= 2.4)) {
tmp = 6.0 * (x / (y * y));
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.4) or not (y <= 2.4): tmp = 6.0 * (x / (y * y)) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.4) || !(y <= 2.4)) tmp = Float64(6.0 * Float64(x / Float64(y * y))); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2.4) || ~((y <= 2.4))) tmp = 6.0 * (x / (y * y)); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.4], N[Not[LessEqual[y, 2.4]], $MachinePrecision]], N[(6.0 * N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \lor \neg \left(y \leq 2.4\right):\\
\;\;\;\;6 \cdot \frac{x}{y \cdot y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.39999999999999991 or 2.39999999999999991 < y Initial program 99.6%
clear-num99.5%
un-div-inv99.6%
Applied egg-rr99.6%
clear-num99.5%
associate-/r/99.6%
Applied egg-rr99.6%
Taylor expanded in y around 0 25.2%
Taylor expanded in y around inf 25.2%
unpow225.2%
Simplified25.2%
if -2.39999999999999991 < y < 2.39999999999999991Initial program 100.0%
Taylor expanded in y around 0 98.9%
Final simplification64.7%
(FPCore (x y) :precision binary64 (if (or (<= y -2.55e+161) (not (<= y 4e+20))) (* y (/ x y)) x))
double code(double x, double y) {
double tmp;
if ((y <= -2.55e+161) || !(y <= 4e+20)) {
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 <= (-2.55d+161)) .or. (.not. (y <= 4d+20))) 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 <= -2.55e+161) || !(y <= 4e+20)) {
tmp = y * (x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.55e+161) or not (y <= 4e+20): tmp = y * (x / y) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.55e+161) || !(y <= 4e+20)) tmp = Float64(y * Float64(x / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2.55e+161) || ~((y <= 4e+20))) tmp = y * (x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.55e+161], N[Not[LessEqual[y, 4e+20]], $MachinePrecision]], N[(y * N[(x / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.55 \cdot 10^{+161} \lor \neg \left(y \leq 4 \cdot 10^{+20}\right):\\
\;\;\;\;y \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.54999999999999982e161 or 4e20 < y Initial program 99.6%
Taylor expanded in x around 0 99.6%
Taylor expanded in y around 0 4.3%
associate-/l*29.8%
div-inv29.8%
clear-num28.2%
Applied egg-rr28.2%
if -2.54999999999999982e161 < y < 4e20Initial program 99.9%
Taylor expanded in y around 0 80.7%
Final simplification63.0%
(FPCore (x y) :precision binary64 (if (or (<= y -5e+59) (not (<= y 5e-19))) (/ y (/ y x)) x))
double code(double x, double y) {
double tmp;
if ((y <= -5e+59) || !(y <= 5e-19)) {
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 <= (-5d+59)) .or. (.not. (y <= 5d-19))) 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 <= -5e+59) || !(y <= 5e-19)) {
tmp = y / (y / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -5e+59) or not (y <= 5e-19): tmp = y / (y / x) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -5e+59) || !(y <= 5e-19)) tmp = Float64(y / Float64(y / x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -5e+59) || ~((y <= 5e-19))) tmp = y / (y / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -5e+59], N[Not[LessEqual[y, 5e-19]], $MachinePrecision]], N[(y / N[(y / x), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+59} \lor \neg \left(y \leq 5 \cdot 10^{-19}\right):\\
\;\;\;\;\frac{y}{\frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.9999999999999997e59 or 5.0000000000000004e-19 < y Initial program 99.6%
Taylor expanded in x around 0 99.6%
Taylor expanded in y around 0 8.7%
associate-/l*29.7%
div-inv29.7%
clear-num26.9%
Applied egg-rr26.9%
clear-num29.7%
un-div-inv29.7%
Applied egg-rr29.7%
if -4.9999999999999997e59 < y < 5.0000000000000004e-19Initial program 99.9%
Taylor expanded in y around 0 91.6%
Final simplification64.3%
(FPCore (x y) :precision binary64 (/ x (+ 1.0 (* (* y y) 0.16666666666666666))))
double code(double x, double y) {
return x / (1.0 + ((y * y) * 0.16666666666666666));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x / (1.0d0 + ((y * y) * 0.16666666666666666d0))
end function
public static double code(double x, double y) {
return x / (1.0 + ((y * y) * 0.16666666666666666));
}
def code(x, y): return x / (1.0 + ((y * y) * 0.16666666666666666))
function code(x, y) return Float64(x / Float64(1.0 + Float64(Float64(y * y) * 0.16666666666666666))) end
function tmp = code(x, y) tmp = x / (1.0 + ((y * y) * 0.16666666666666666)); end
code[x_, y_] := N[(x / N[(1.0 + N[(N[(y * y), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{1 + \left(y \cdot y\right) \cdot 0.16666666666666666}
\end{array}
Initial program 99.8%
clear-num99.7%
un-div-inv99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 65.2%
*-commutative65.2%
unpow265.2%
Simplified65.2%
Final simplification65.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 55.1%
Final simplification55.1%
herbie shell --seed 2023173
(FPCore (x y)
:name "Linear.Quaternion:$cexp from linear-1.19.1.3"
:precision binary64
(* x (/ (sin y) y)))