
(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 7 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%
(FPCore (x y) :precision binary64 (if (or (<= y 0.062) (not (<= y 1.4e+154))) (* (cos x) (+ 1.0 (* 0.16666666666666666 (* y y)))) (/ (sinh y) y)))
double code(double x, double y) {
double tmp;
if ((y <= 0.062) || !(y <= 1.4e+154)) {
tmp = cos(x) * (1.0 + (0.16666666666666666 * (y * y)));
} else {
tmp = sinh(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 <= 0.062d0) .or. (.not. (y <= 1.4d+154))) then
tmp = cos(x) * (1.0d0 + (0.16666666666666666d0 * (y * y)))
else
tmp = sinh(y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= 0.062) || !(y <= 1.4e+154)) {
tmp = Math.cos(x) * (1.0 + (0.16666666666666666 * (y * y)));
} else {
tmp = Math.sinh(y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 0.062) or not (y <= 1.4e+154): tmp = math.cos(x) * (1.0 + (0.16666666666666666 * (y * y))) else: tmp = math.sinh(y) / y return tmp
function code(x, y) tmp = 0.0 if ((y <= 0.062) || !(y <= 1.4e+154)) tmp = Float64(cos(x) * Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y)))); else tmp = Float64(sinh(y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= 0.062) || ~((y <= 1.4e+154))) tmp = cos(x) * (1.0 + (0.16666666666666666 * (y * y))); else tmp = sinh(y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 0.062], N[Not[LessEqual[y, 1.4e+154]], $MachinePrecision]], N[(N[Cos[x], $MachinePrecision] * N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.062 \lor \neg \left(y \leq 1.4 \cdot 10^{+154}\right):\\
\;\;\;\;\cos x \cdot \left(1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\sinh y}{y}\\
\end{array}
\end{array}
if y < 0.062 or 1.4e154 < y Initial program 100.0%
Taylor expanded in y around 0 85.5%
unpow285.5%
Applied egg-rr85.5%
if 0.062 < y < 1.4e154Initial program 100.0%
Taylor expanded in x around 0 84.8%
*-un-lft-identity84.8%
expm1-log1p-u84.6%
expm1-undefine84.6%
Applied egg-rr84.6%
sub-neg84.6%
metadata-eval84.6%
+-commutative84.6%
log1p-undefine84.6%
rem-exp-log84.8%
associate-+r+84.8%
metadata-eval84.8%
+-lft-identity84.8%
Simplified84.8%
Final simplification85.4%
(FPCore (x y) :precision binary64 (if (<= y 0.0053) (cos x) (/ (sinh y) y)))
double code(double x, double y) {
double tmp;
if (y <= 0.0053) {
tmp = cos(x);
} else {
tmp = sinh(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 <= 0.0053d0) then
tmp = cos(x)
else
tmp = sinh(y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 0.0053) {
tmp = Math.cos(x);
} else {
tmp = Math.sinh(y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 0.0053: tmp = math.cos(x) else: tmp = math.sinh(y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 0.0053) tmp = cos(x); else tmp = Float64(sinh(y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 0.0053) tmp = cos(x); else tmp = sinh(y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 0.0053], N[Cos[x], $MachinePrecision], N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.0053:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;\frac{\sinh y}{y}\\
\end{array}
\end{array}
if y < 0.00530000000000000002Initial program 100.0%
Taylor expanded in y around 0 67.1%
if 0.00530000000000000002 < y Initial program 100.0%
Taylor expanded in x around 0 85.2%
*-un-lft-identity85.2%
expm1-log1p-u85.1%
expm1-undefine85.1%
Applied egg-rr85.1%
sub-neg85.1%
metadata-eval85.1%
+-commutative85.1%
log1p-undefine85.1%
rem-exp-log85.2%
associate-+r+85.2%
metadata-eval85.2%
+-lft-identity85.2%
Simplified85.2%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ 1.0 (* 0.16666666666666666 (* y y)))))
(if (<= y 245.0)
(cos x)
(if (<= y 4e+163) (* t_0 (+ 1.0 (* (* x x) -0.5))) t_0))))
double code(double x, double y) {
double t_0 = 1.0 + (0.16666666666666666 * (y * y));
double tmp;
if (y <= 245.0) {
tmp = cos(x);
} else if (y <= 4e+163) {
tmp = t_0 * (1.0 + ((x * x) * -0.5));
} 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 = 1.0d0 + (0.16666666666666666d0 * (y * y))
if (y <= 245.0d0) then
tmp = cos(x)
else if (y <= 4d+163) then
tmp = t_0 * (1.0d0 + ((x * x) * (-0.5d0)))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 + (0.16666666666666666 * (y * y));
double tmp;
if (y <= 245.0) {
tmp = Math.cos(x);
} else if (y <= 4e+163) {
tmp = t_0 * (1.0 + ((x * x) * -0.5));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 + (0.16666666666666666 * (y * y)) tmp = 0 if y <= 245.0: tmp = math.cos(x) elif y <= 4e+163: tmp = t_0 * (1.0 + ((x * x) * -0.5)) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y))) tmp = 0.0 if (y <= 245.0) tmp = cos(x); elseif (y <= 4e+163) tmp = Float64(t_0 * Float64(1.0 + Float64(Float64(x * x) * -0.5))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 + (0.16666666666666666 * (y * y)); tmp = 0.0; if (y <= 245.0) tmp = cos(x); elseif (y <= 4e+163) tmp = t_0 * (1.0 + ((x * x) * -0.5)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 245.0], N[Cos[x], $MachinePrecision], If[LessEqual[y, 4e+163], N[(t$95$0 * N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\\
\mathbf{if}\;y \leq 245:\\
\;\;\;\;\cos x\\
\mathbf{elif}\;y \leq 4 \cdot 10^{+163}:\\
\;\;\;\;t\_0 \cdot \left(1 + \left(x \cdot x\right) \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < 245Initial program 100.0%
Taylor expanded in y around 0 67.1%
if 245 < y < 3.9999999999999998e163Initial program 100.0%
Taylor expanded in y around 0 11.2%
unpow211.2%
Applied egg-rr11.2%
Taylor expanded in x around 0 20.6%
*-commutative20.6%
Simplified20.6%
unpow220.6%
Applied egg-rr20.6%
if 3.9999999999999998e163 < y Initial program 100.0%
Taylor expanded in x around 0 88.5%
Taylor expanded in y around 0 88.5%
unpow2100.0%
Applied egg-rr88.5%
Final simplification62.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ 1.0 (* 0.16666666666666666 (* y y)))))
(if (<= y 1.1e-8)
1.0
(if (<= y 6e+163) (* t_0 (+ 1.0 (* (* x x) -0.5))) t_0))))
double code(double x, double y) {
double t_0 = 1.0 + (0.16666666666666666 * (y * y));
double tmp;
if (y <= 1.1e-8) {
tmp = 1.0;
} else if (y <= 6e+163) {
tmp = t_0 * (1.0 + ((x * x) * -0.5));
} 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 = 1.0d0 + (0.16666666666666666d0 * (y * y))
if (y <= 1.1d-8) then
tmp = 1.0d0
else if (y <= 6d+163) then
tmp = t_0 * (1.0d0 + ((x * x) * (-0.5d0)))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 + (0.16666666666666666 * (y * y));
double tmp;
if (y <= 1.1e-8) {
tmp = 1.0;
} else if (y <= 6e+163) {
tmp = t_0 * (1.0 + ((x * x) * -0.5));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 + (0.16666666666666666 * (y * y)) tmp = 0 if y <= 1.1e-8: tmp = 1.0 elif y <= 6e+163: tmp = t_0 * (1.0 + ((x * x) * -0.5)) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y))) tmp = 0.0 if (y <= 1.1e-8) tmp = 1.0; elseif (y <= 6e+163) tmp = Float64(t_0 * Float64(1.0 + Float64(Float64(x * x) * -0.5))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 + (0.16666666666666666 * (y * y)); tmp = 0.0; if (y <= 1.1e-8) tmp = 1.0; elseif (y <= 6e+163) tmp = t_0 * (1.0 + ((x * x) * -0.5)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 1.1e-8], 1.0, If[LessEqual[y, 6e+163], N[(t$95$0 * N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\\
\mathbf{if}\;y \leq 1.1 \cdot 10^{-8}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 6 \cdot 10^{+163}:\\
\;\;\;\;t\_0 \cdot \left(1 + \left(x \cdot x\right) \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < 1.0999999999999999e-8Initial program 100.0%
Taylor expanded in x around 0 53.8%
Taylor expanded in y around 0 30.2%
if 1.0999999999999999e-8 < y < 6.00000000000000027e163Initial program 100.0%
Taylor expanded in y around 0 18.1%
unpow218.1%
Applied egg-rr18.1%
Taylor expanded in x around 0 23.6%
*-commutative23.6%
Simplified23.6%
unpow223.6%
Applied egg-rr23.6%
if 6.00000000000000027e163 < y Initial program 100.0%
Taylor expanded in x around 0 88.5%
Taylor expanded in y around 0 88.5%
unpow2100.0%
Applied egg-rr88.5%
Final simplification35.1%
(FPCore (x y) :precision binary64 (+ 1.0 (* 0.16666666666666666 (* y y))))
double code(double x, double y) {
return 1.0 + (0.16666666666666666 * (y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 + (0.16666666666666666d0 * (y * y))
end function
public static double code(double x, double y) {
return 1.0 + (0.16666666666666666 * (y * y));
}
def code(x, y): return 1.0 + (0.16666666666666666 * (y * y))
function code(x, y) return Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y))) end
function tmp = code(x, y) tmp = 1.0 + (0.16666666666666666 * (y * y)); end
code[x_, y_] := N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + 0.16666666666666666 \cdot \left(y \cdot y\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 61.2%
Taylor expanded in y around 0 42.5%
unpow275.2%
Applied egg-rr42.5%
(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 x around 0 61.2%
Taylor expanded in y around 0 23.7%
herbie shell --seed 2024181
(FPCore (x y)
:name "Linear.Quaternion:$csin from linear-1.19.1.3"
:precision binary64
(* (cos x) (/ (sinh y) y)))