
(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%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (sinh y) y))) (if (<= t_0 2.0) (cos x) t_0)))
double code(double x, double y) {
double t_0 = sinh(y) / y;
double tmp;
if (t_0 <= 2.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 <= 2.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 <= 2.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 <= 2.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 <= 2.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 <= 2.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, 2.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 2:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (/.f64 (sinh.f64 y) y) < 2Initial program 100.0%
Taylor expanded in y around 0 99.8%
if 2 < (/.f64 (sinh.f64 y) y) Initial program 100.0%
Taylor expanded in x around 0 67.0%
*-un-lft-identity67.0%
add-log-exp66.1%
*-un-lft-identity66.1%
log-prod66.1%
metadata-eval66.1%
add-log-exp67.0%
Applied egg-rr67.0%
+-lft-identity67.0%
Simplified67.0%
(FPCore (x y) :precision binary64 (if (<= y 2.15e+38) (cos x) (/ (+ y (* -0.5 (* y (* x x)))) y)))
double code(double x, double y) {
double tmp;
if (y <= 2.15e+38) {
tmp = cos(x);
} else {
tmp = (y + (-0.5 * (y * (x * x)))) / 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.15d+38) then
tmp = cos(x)
else
tmp = (y + ((-0.5d0) * (y * (x * x)))) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.15e+38) {
tmp = Math.cos(x);
} else {
tmp = (y + (-0.5 * (y * (x * x)))) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.15e+38: tmp = math.cos(x) else: tmp = (y + (-0.5 * (y * (x * x)))) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 2.15e+38) tmp = cos(x); else tmp = Float64(Float64(y + Float64(-0.5 * Float64(y * Float64(x * x)))) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.15e+38) tmp = cos(x); else tmp = (y + (-0.5 * (y * (x * x)))) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.15e+38], N[Cos[x], $MachinePrecision], N[(N[(y + N[(-0.5 * N[(y * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.15 \cdot 10^{+38}:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;\frac{y + -0.5 \cdot \left(y \cdot \left(x \cdot x\right)\right)}{y}\\
\end{array}
\end{array}
if y < 2.1499999999999998e38Initial program 100.0%
Taylor expanded in y around 0 72.5%
if 2.1499999999999998e38 < 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 36.7%
unpow236.7%
Applied egg-rr36.7%
Final simplification65.4%
(FPCore (x y) :precision binary64 (if (<= y 2.6e-24) 1.0 (/ (+ y (* -0.5 (* y (* x x)))) y)))
double code(double x, double y) {
double tmp;
if (y <= 2.6e-24) {
tmp = 1.0;
} else {
tmp = (y + (-0.5 * (y * (x * x)))) / 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.6d-24) then
tmp = 1.0d0
else
tmp = (y + ((-0.5d0) * (y * (x * x)))) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.6e-24) {
tmp = 1.0;
} else {
tmp = (y + (-0.5 * (y * (x * x)))) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.6e-24: tmp = 1.0 else: tmp = (y + (-0.5 * (y * (x * x)))) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 2.6e-24) tmp = 1.0; else tmp = Float64(Float64(y + Float64(-0.5 * Float64(y * Float64(x * x)))) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.6e-24) tmp = 1.0; else tmp = (y + (-0.5 * (y * (x * x)))) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.6e-24], 1.0, N[(N[(y + N[(-0.5 * N[(y * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.6 \cdot 10^{-24}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{y + -0.5 \cdot \left(y \cdot \left(x \cdot x\right)\right)}{y}\\
\end{array}
\end{array}
if y < 2.6e-24Initial program 100.0%
Taylor expanded in x around 0 61.2%
Taylor expanded in y around 0 42.6%
if 2.6e-24 < y Initial program 100.0%
add-log-exp98.5%
*-un-lft-identity98.5%
log-prod98.5%
metadata-eval98.5%
add-log-exp100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in y around 0 12.1%
Taylor expanded in x around 0 37.3%
unpow237.3%
Applied egg-rr37.3%
Final simplification41.3%
(FPCore (x y) :precision binary64 (if (<= y 2.6e-24) 1.0 (+ 1.0 (* -0.5 (* x x)))))
double code(double x, double y) {
double tmp;
if (y <= 2.6e-24) {
tmp = 1.0;
} else {
tmp = 1.0 + (-0.5 * (x * 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.6d-24) then
tmp = 1.0d0
else
tmp = 1.0d0 + ((-0.5d0) * (x * x))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.6e-24) {
tmp = 1.0;
} else {
tmp = 1.0 + (-0.5 * (x * x));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.6e-24: tmp = 1.0 else: tmp = 1.0 + (-0.5 * (x * x)) return tmp
function code(x, y) tmp = 0.0 if (y <= 2.6e-24) tmp = 1.0; else tmp = Float64(1.0 + Float64(-0.5 * Float64(x * x))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.6e-24) tmp = 1.0; else tmp = 1.0 + (-0.5 * (x * x)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.6e-24], 1.0, N[(1.0 + N[(-0.5 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.6 \cdot 10^{-24}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;1 + -0.5 \cdot \left(x \cdot x\right)\\
\end{array}
\end{array}
if y < 2.6e-24Initial program 100.0%
Taylor expanded in x around 0 61.2%
Taylor expanded in y around 0 42.6%
if 2.6e-24 < y Initial program 100.0%
Taylor expanded in y around 0 12.1%
Taylor expanded in x around 0 24.1%
*-commutative24.1%
Simplified24.1%
unpow237.3%
Applied egg-rr24.1%
Final simplification38.0%
(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.9%
Taylor expanded in y around 0 34.4%
herbie shell --seed 2024152
(FPCore (x y)
:name "Linear.Quaternion:$csin from linear-1.19.1.3"
:precision binary64
(* (cos x) (/ (sinh y) y)))