
(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 (if (<= y 6e+42) (cos x) (/ (+ y (* -0.5 (* y (pow x 2.0)))) y)))
double code(double x, double y) {
double tmp;
if (y <= 6e+42) {
tmp = cos(x);
} else {
tmp = (y + (-0.5 * (y * pow(x, 2.0)))) / y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 6d+42) then
tmp = cos(x)
else
tmp = (y + ((-0.5d0) * (y * (x ** 2.0d0)))) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 6e+42) {
tmp = Math.cos(x);
} else {
tmp = (y + (-0.5 * (y * Math.pow(x, 2.0)))) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 6e+42: tmp = math.cos(x) else: tmp = (y + (-0.5 * (y * math.pow(x, 2.0)))) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 6e+42) tmp = cos(x); else tmp = Float64(Float64(y + Float64(-0.5 * Float64(y * (x ^ 2.0)))) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 6e+42) tmp = cos(x); else tmp = (y + (-0.5 * (y * (x ^ 2.0)))) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 6e+42], N[Cos[x], $MachinePrecision], N[(N[(y + N[(-0.5 * N[(y * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6 \cdot 10^{+42}:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;\frac{y + -0.5 \cdot \left(y \cdot {x}^{2}\right)}{y}\\
\end{array}
\end{array}
if y < 6.00000000000000058e42Initial program 100.0%
Taylor expanded in y around 0 70.1%
if 6.00000000000000058e42 < y Initial program 100.0%
add-log-exp100.0%
*-un-lft-identity100.0%
log-prod100.0%
metadata-eval100.0%
add-log-exp100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in y around 0 3.1%
Taylor expanded in x around 0 20.0%
Final simplification59.3%
(FPCore (x y) :precision binary64 (if (<= y 7.6e+42) (cos x) (+ 1.0 (* -0.5 (pow x 2.0)))))
double code(double x, double y) {
double tmp;
if (y <= 7.6e+42) {
tmp = cos(x);
} else {
tmp = 1.0 + (-0.5 * pow(x, 2.0));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 7.6d+42) then
tmp = cos(x)
else
tmp = 1.0d0 + ((-0.5d0) * (x ** 2.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 7.6e+42) {
tmp = Math.cos(x);
} else {
tmp = 1.0 + (-0.5 * Math.pow(x, 2.0));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 7.6e+42: tmp = math.cos(x) else: tmp = 1.0 + (-0.5 * math.pow(x, 2.0)) return tmp
function code(x, y) tmp = 0.0 if (y <= 7.6e+42) tmp = cos(x); else tmp = Float64(1.0 + Float64(-0.5 * (x ^ 2.0))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 7.6e+42) tmp = cos(x); else tmp = 1.0 + (-0.5 * (x ^ 2.0)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 7.6e+42], N[Cos[x], $MachinePrecision], N[(1.0 + N[(-0.5 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 7.6 \cdot 10^{+42}:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;1 + -0.5 \cdot {x}^{2}\\
\end{array}
\end{array}
if y < 7.5999999999999997e42Initial program 100.0%
Taylor expanded in y around 0 70.1%
if 7.5999999999999997e42 < y Initial program 100.0%
add-log-exp100.0%
*-un-lft-identity100.0%
log-prod100.0%
metadata-eval100.0%
add-log-exp100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in y around 0 3.1%
Taylor expanded in x around 0 14.9%
Final simplification58.3%
(FPCore (x y) :precision binary64 (if (<= y 7.2e+54) (cos x) (* -0.5 (pow x 2.0))))
double code(double x, double y) {
double tmp;
if (y <= 7.2e+54) {
tmp = cos(x);
} else {
tmp = -0.5 * pow(x, 2.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 7.2d+54) then
tmp = cos(x)
else
tmp = (-0.5d0) * (x ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 7.2e+54) {
tmp = Math.cos(x);
} else {
tmp = -0.5 * Math.pow(x, 2.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 7.2e+54: tmp = math.cos(x) else: tmp = -0.5 * math.pow(x, 2.0) return tmp
function code(x, y) tmp = 0.0 if (y <= 7.2e+54) tmp = cos(x); else tmp = Float64(-0.5 * (x ^ 2.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 7.2e+54) tmp = cos(x); else tmp = -0.5 * (x ^ 2.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 7.2e+54], N[Cos[x], $MachinePrecision], N[(-0.5 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 7.2 \cdot 10^{+54}:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot {x}^{2}\\
\end{array}
\end{array}
if y < 7.2000000000000003e54Initial program 100.0%
Taylor expanded in y around 0 68.5%
if 7.2000000000000003e54 < y Initial program 100.0%
add-log-exp100.0%
*-un-lft-identity100.0%
log-prod100.0%
metadata-eval100.0%
add-log-exp100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in y around 0 3.1%
Taylor expanded in x around 0 16.1%
Taylor expanded in x around inf 15.4%
Final simplification58.1%
(FPCore (x y) :precision binary64 (cos x))
double code(double x, double y) {
return cos(x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = cos(x)
end function
public static double code(double x, double y) {
return Math.cos(x);
}
def code(x, y): return math.cos(x)
function code(x, y) return cos(x) end
function tmp = code(x, y) tmp = cos(x); end
code[x_, y_] := N[Cos[x], $MachinePrecision]
\begin{array}{l}
\\
\cos x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 55.7%
Final simplification55.7%
(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%
add-log-exp99.7%
*-un-lft-identity99.7%
log-prod99.7%
metadata-eval99.7%
add-log-exp100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
associate-*r/99.9%
Simplified99.9%
Taylor expanded in y around 0 55.7%
Taylor expanded in x around 0 35.0%
Final simplification35.0%
herbie shell --seed 2024081
(FPCore (x y)
:name "Linear.Quaternion:$csin from linear-1.19.1.3"
:precision binary64
(* (cos x) (/ (sinh y) y)))