
(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 0.0036) (cos x) (if (<= y 1.05e+148) (/ (sinh y) y) (/ (/ (* y (* (cos x) y)) y) y))))
double code(double x, double y) {
double tmp;
if (y <= 0.0036) {
tmp = cos(x);
} else if (y <= 1.05e+148) {
tmp = sinh(y) / y;
} else {
tmp = ((y * (cos(x) * 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 <= 0.0036d0) then
tmp = cos(x)
else if (y <= 1.05d+148) then
tmp = sinh(y) / y
else
tmp = ((y * (cos(x) * y)) / y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 0.0036) {
tmp = Math.cos(x);
} else if (y <= 1.05e+148) {
tmp = Math.sinh(y) / y;
} else {
tmp = ((y * (Math.cos(x) * y)) / y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 0.0036: tmp = math.cos(x) elif y <= 1.05e+148: tmp = math.sinh(y) / y else: tmp = ((y * (math.cos(x) * y)) / y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 0.0036) tmp = cos(x); elseif (y <= 1.05e+148) tmp = Float64(sinh(y) / y); else tmp = Float64(Float64(Float64(y * Float64(cos(x) * y)) / y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 0.0036) tmp = cos(x); elseif (y <= 1.05e+148) tmp = sinh(y) / y; else tmp = ((y * (cos(x) * y)) / y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 0.0036], N[Cos[x], $MachinePrecision], If[LessEqual[y, 1.05e+148], N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision], N[(N[(N[(y * N[(N[Cos[x], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.0036:\\
\;\;\;\;\cos x\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{+148}:\\
\;\;\;\;\frac{\sinh y}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{y \cdot \left(\cos x \cdot y\right)}{y}}{y}\\
\end{array}
\end{array}
if y < 0.0035999999999999999Initial program 100.0%
Taylor expanded in y around 0 65.1%
if 0.0035999999999999999 < y < 1.04999999999999999e148Initial program 100.0%
associate-*r/100.0%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in x around 0 71.4%
expm1-log1p-u71.4%
expm1-udef71.4%
associate-*l/71.4%
*-un-lft-identity71.4%
Applied egg-rr71.4%
expm1-def71.4%
expm1-log1p71.4%
Simplified71.4%
if 1.04999999999999999e148 < y Initial program 100.0%
associate-*r/100.0%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in y around 0 3.1%
*-commutative3.1%
associate-*r/3.1%
Applied egg-rr3.1%
*-un-lft-identity3.1%
*-commutative3.1%
lft-mult-inverse3.1%
associate-*l*3.1%
div-inv3.1%
associate-*l/100.0%
Applied egg-rr100.0%
Final simplification70.8%
(FPCore (x y) :precision binary64 (if (<= y 0.0048) (cos x) (/ (sinh y) y)))
double code(double x, double y) {
double tmp;
if (y <= 0.0048) {
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.0048d0) 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.0048) {
tmp = Math.cos(x);
} else {
tmp = Math.sinh(y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 0.0048: tmp = math.cos(x) else: tmp = math.sinh(y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 0.0048) 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.0048) tmp = cos(x); else tmp = sinh(y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 0.0048], N[Cos[x], $MachinePrecision], N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.0048:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;\frac{\sinh y}{y}\\
\end{array}
\end{array}
if y < 0.00479999999999999958Initial program 100.0%
Taylor expanded in y around 0 65.1%
if 0.00479999999999999958 < y Initial program 100.0%
associate-*r/100.0%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in x around 0 80.0%
expm1-log1p-u80.0%
expm1-udef80.0%
associate-*l/80.0%
*-un-lft-identity80.0%
Applied egg-rr80.0%
expm1-def80.0%
expm1-log1p80.0%
Simplified80.0%
Final simplification68.9%
(FPCore (x y) :precision binary64 (if (<= y 500.0) (cos x) (* y (+ (/ 1.0 y) (* -0.5 (* x (* x (/ 1.0 y))))))))
double code(double x, double y) {
double tmp;
if (y <= 500.0) {
tmp = cos(x);
} else {
tmp = y * ((1.0 / y) + (-0.5 * (x * (x * (1.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 <= 500.0d0) then
tmp = cos(x)
else
tmp = y * ((1.0d0 / y) + ((-0.5d0) * (x * (x * (1.0d0 / y)))))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 500.0) {
tmp = Math.cos(x);
} else {
tmp = y * ((1.0 / y) + (-0.5 * (x * (x * (1.0 / y)))));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 500.0: tmp = math.cos(x) else: tmp = y * ((1.0 / y) + (-0.5 * (x * (x * (1.0 / y))))) return tmp
function code(x, y) tmp = 0.0 if (y <= 500.0) tmp = cos(x); else tmp = Float64(y * Float64(Float64(1.0 / y) + Float64(-0.5 * Float64(x * Float64(x * Float64(1.0 / y)))))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 500.0) tmp = cos(x); else tmp = y * ((1.0 / y) + (-0.5 * (x * (x * (1.0 / y))))); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 500.0], N[Cos[x], $MachinePrecision], N[(y * N[(N[(1.0 / y), $MachinePrecision] + N[(-0.5 * N[(x * N[(x * N[(1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 500:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(\frac{1}{y} + -0.5 \cdot \left(x \cdot \left(x \cdot \frac{1}{y}\right)\right)\right)\\
\end{array}
\end{array}
if y < 500Initial program 100.0%
Taylor expanded in y around 0 64.8%
if 500 < y Initial program 100.0%
associate-*r/100.0%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in y around 0 3.1%
Taylor expanded in x around 0 13.0%
div-inv13.0%
unpow213.0%
associate-*l*13.0%
Applied egg-rr13.0%
Final simplification51.9%
(FPCore (x y) :precision binary64 (if (<= y 3.2e-12) 1.0 (* y (+ (/ 1.0 y) (* -0.5 (* x (* x (/ 1.0 y))))))))
double code(double x, double y) {
double tmp;
if (y <= 3.2e-12) {
tmp = 1.0;
} else {
tmp = y * ((1.0 / y) + (-0.5 * (x * (x * (1.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 <= 3.2d-12) then
tmp = 1.0d0
else
tmp = y * ((1.0d0 / y) + ((-0.5d0) * (x * (x * (1.0d0 / y)))))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 3.2e-12) {
tmp = 1.0;
} else {
tmp = y * ((1.0 / y) + (-0.5 * (x * (x * (1.0 / y)))));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.2e-12: tmp = 1.0 else: tmp = y * ((1.0 / y) + (-0.5 * (x * (x * (1.0 / y))))) return tmp
function code(x, y) tmp = 0.0 if (y <= 3.2e-12) tmp = 1.0; else tmp = Float64(y * Float64(Float64(1.0 / y) + Float64(-0.5 * Float64(x * Float64(x * Float64(1.0 / y)))))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.2e-12) tmp = 1.0; else tmp = y * ((1.0 / y) + (-0.5 * (x * (x * (1.0 / y))))); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.2e-12], 1.0, N[(y * N[(N[(1.0 / y), $MachinePrecision] + N[(-0.5 * N[(x * N[(x * N[(1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.2 \cdot 10^{-12}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(\frac{1}{y} + -0.5 \cdot \left(x \cdot \left(x \cdot \frac{1}{y}\right)\right)\right)\\
\end{array}
\end{array}
if y < 3.2000000000000001e-12Initial program 100.0%
associate-*r/99.9%
associate-*l/99.8%
Simplified99.8%
Taylor expanded in x around 0 61.5%
Taylor expanded in y around 0 38.5%
Taylor expanded in y around 0 38.5%
if 3.2000000000000001e-12 < y Initial program 100.0%
associate-*r/100.0%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in y around 0 4.8%
Taylor expanded in x around 0 14.4%
div-inv14.4%
unpow214.4%
associate-*l*14.4%
Applied egg-rr14.4%
Final simplification32.3%
(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%
associate-*r/99.9%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in x around 0 66.4%
Taylor expanded in y around 0 29.7%
Taylor expanded in y around 0 29.7%
Final simplification29.7%
herbie shell --seed 2023333
(FPCore (x y)
:name "Linear.Quaternion:$csin from linear-1.19.1.3"
:precision binary64
(* (cos x) (/ (sinh y) y)))