
(FPCore (x y) :precision binary64 (* (cos x) (/ (sinh y) y)))
double code(double x, double y) {
return cos(x) * (sinh(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = cos(x) * (sinh(y) / y)
end function
public static double code(double x, double y) {
return Math.cos(x) * (Math.sinh(y) / y);
}
def code(x, y): return math.cos(x) * (math.sinh(y) / y)
function code(x, y) return Float64(cos(x) * Float64(sinh(y) / y)) end
function tmp = code(x, y) tmp = cos(x) * (sinh(y) / y); end
code[x_, y_] := N[(N[Cos[x], $MachinePrecision] * N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot \frac{\sinh y}{y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* (cos x) (/ (sinh y) y)))
double code(double x, double y) {
return cos(x) * (sinh(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = cos(x) * (sinh(y) / y)
end function
public static double code(double x, double y) {
return Math.cos(x) * (Math.sinh(y) / y);
}
def code(x, y): return math.cos(x) * (math.sinh(y) / y)
function code(x, y) return Float64(cos(x) * Float64(sinh(y) / y)) end
function tmp = code(x, y) tmp = cos(x) * (sinh(y) / y); end
code[x_, y_] := N[(N[Cos[x], $MachinePrecision] * N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot \frac{\sinh y}{y}
\end{array}
(FPCore (x y) :precision binary64 (* (cos x) (/ (sinh y) y)))
double code(double x, double y) {
return cos(x) * (sinh(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = cos(x) * (sinh(y) / y)
end function
public static double code(double x, double y) {
return Math.cos(x) * (Math.sinh(y) / y);
}
def code(x, y): return math.cos(x) * (math.sinh(y) / y)
function code(x, y) return Float64(cos(x) * Float64(sinh(y) / y)) end
function tmp = code(x, y) tmp = cos(x) * (sinh(y) / y); end
code[x_, y_] := N[(N[Cos[x], $MachinePrecision] * N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot \frac{\sinh y}{y}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (sinh y) y))) (if (<= t_0 1.0) (cos x) t_0)))
double code(double x, double y) {
double t_0 = sinh(y) / y;
double tmp;
if (t_0 <= 1.0) {
tmp = cos(x);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = sinh(y) / y
if (t_0 <= 1.0d0) then
tmp = cos(x)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = Math.sinh(y) / y;
double tmp;
if (t_0 <= 1.0) {
tmp = Math.cos(x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = math.sinh(y) / y tmp = 0 if t_0 <= 1.0: tmp = math.cos(x) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(sinh(y) / y) tmp = 0.0 if (t_0 <= 1.0) tmp = cos(x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = sinh(y) / y; tmp = 0.0; if (t_0 <= 1.0) tmp = cos(x); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[t$95$0, 1.0], N[Cos[x], $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sinh y}{y}\\
\mathbf{if}\;t\_0 \leq 1:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (/.f64 (sinh.f64 y) y) < 1Initial program 100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in y around 0 100.0%
if 1 < (/.f64 (sinh.f64 y) y) Initial program 100.0%
Taylor expanded in x around 0 67.2%
Final simplification84.8%
(FPCore (x y)
:precision binary64
(if (<= y 20500000.0)
(cos x)
(if (<= y 1.45e+96)
(* -0.5 (pow x 2.0))
(/ (* y (+ 1.0 (* 0.16666666666666666 (* y y)))) y))))
double code(double x, double y) {
double tmp;
if (y <= 20500000.0) {
tmp = cos(x);
} else if (y <= 1.45e+96) {
tmp = -0.5 * pow(x, 2.0);
} else {
tmp = (y * (1.0 + (0.16666666666666666 * (y * 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 <= 20500000.0d0) then
tmp = cos(x)
else if (y <= 1.45d+96) then
tmp = (-0.5d0) * (x ** 2.0d0)
else
tmp = (y * (1.0d0 + (0.16666666666666666d0 * (y * y)))) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 20500000.0) {
tmp = Math.cos(x);
} else if (y <= 1.45e+96) {
tmp = -0.5 * Math.pow(x, 2.0);
} else {
tmp = (y * (1.0 + (0.16666666666666666 * (y * y)))) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 20500000.0: tmp = math.cos(x) elif y <= 1.45e+96: tmp = -0.5 * math.pow(x, 2.0) else: tmp = (y * (1.0 + (0.16666666666666666 * (y * y)))) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 20500000.0) tmp = cos(x); elseif (y <= 1.45e+96) tmp = Float64(-0.5 * (x ^ 2.0)); else tmp = Float64(Float64(y * Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y)))) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 20500000.0) tmp = cos(x); elseif (y <= 1.45e+96) tmp = -0.5 * (x ^ 2.0); else tmp = (y * (1.0 + (0.16666666666666666 * (y * y)))) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 20500000.0], N[Cos[x], $MachinePrecision], If[LessEqual[y, 1.45e+96], N[(-0.5 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision], N[(N[(y * N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 20500000:\\
\;\;\;\;\cos x\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{+96}:\\
\;\;\;\;-0.5 \cdot {x}^{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot \left(1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\right)}{y}\\
\end{array}
\end{array}
if y < 2.05e7Initial program 100.0%
Taylor expanded in y around 0 89.5%
Taylor expanded in y around 0 69.7%
if 2.05e7 < y < 1.44999999999999989e96Initial program 100.0%
Taylor expanded in y around 0 4.1%
Taylor expanded in y around 0 3.1%
Taylor expanded in x around 0 29.7%
Taylor expanded in x around inf 29.3%
if 1.44999999999999989e96 < y Initial program 100.0%
Taylor expanded in x around 0 72.7%
Taylor expanded in y around 0 67.0%
unpow267.0%
Applied egg-rr67.0%
Final simplification66.0%
(FPCore (x y) :precision binary64 (if (<= y 1.02e+72) (cos x) (/ (* y (+ 1.0 (* 0.16666666666666666 (* y y)))) y)))
double code(double x, double y) {
double tmp;
if (y <= 1.02e+72) {
tmp = cos(x);
} else {
tmp = (y * (1.0 + (0.16666666666666666 * (y * 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.02d+72) then
tmp = cos(x)
else
tmp = (y * (1.0d0 + (0.16666666666666666d0 * (y * y)))) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.02e+72) {
tmp = Math.cos(x);
} else {
tmp = (y * (1.0 + (0.16666666666666666 * (y * y)))) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.02e+72: tmp = math.cos(x) else: tmp = (y * (1.0 + (0.16666666666666666 * (y * y)))) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 1.02e+72) tmp = cos(x); else tmp = Float64(Float64(y * Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y)))) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.02e+72) tmp = cos(x); else tmp = (y * (1.0 + (0.16666666666666666 * (y * y)))) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.02e+72], N[Cos[x], $MachinePrecision], N[(N[(y * N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.02 \cdot 10^{+72}:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot \left(1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\right)}{y}\\
\end{array}
\end{array}
if y < 1.02e72Initial program 100.0%
Taylor expanded in y around 0 83.3%
Taylor expanded in y around 0 64.8%
if 1.02e72 < y Initial program 100.0%
Taylor expanded in x around 0 73.7%
Taylor expanded in y around 0 58.7%
unpow258.7%
Applied egg-rr58.7%
Final simplification63.9%
(FPCore (x y) :precision binary64 (/ (* y (+ 1.0 (* 0.16666666666666666 (* y y)))) y))
double code(double x, double y) {
return (y * (1.0 + (0.16666666666666666 * (y * y)))) / y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * (1.0d0 + (0.16666666666666666d0 * (y * y)))) / y
end function
public static double code(double x, double y) {
return (y * (1.0 + (0.16666666666666666 * (y * y)))) / y;
}
def code(x, y): return (y * (1.0 + (0.16666666666666666 * (y * y)))) / y
function code(x, y) return Float64(Float64(y * Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y)))) / y) end
function tmp = code(x, y) tmp = (y * (1.0 + (0.16666666666666666 * (y * y)))) / y; end
code[x_, y_] := N[(N[(y * N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]
\begin{array}{l}
\\
\frac{y \cdot \left(1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\right)}{y}
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 59.2%
Taylor expanded in y around 0 48.4%
unpow248.4%
Applied egg-rr48.4%
Final simplification48.4%
(FPCore (x y) :precision binary64 1.0)
double code(double x, double y) {
return 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0
end function
public static double code(double x, double y) {
return 1.0;
}
def code(x, y): return 1.0
function code(x, y) return 1.0 end
function tmp = code(x, y) tmp = 1.0; end
code[x_, y_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 83.1%
Taylor expanded in y around 0 55.6%
Taylor expanded in x around 0 29.7%
Final simplification29.7%
herbie shell --seed 2024055
(FPCore (x y)
:name "Linear.Quaternion:$csin from linear-1.19.1.3"
:precision binary64
(* (cos x) (/ (sinh y) y)))