
(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 (<= y 59.0)
(cos x)
(if (<= y 7.6e+151)
(+ 1.0 (* (pow x 2.0) -0.5))
(+ 1.0 (* 0.16666666666666666 (pow y 2.0))))))
double code(double x, double y) {
double tmp;
if (y <= 59.0) {
tmp = cos(x);
} else if (y <= 7.6e+151) {
tmp = 1.0 + (pow(x, 2.0) * -0.5);
} else {
tmp = 1.0 + (0.16666666666666666 * pow(y, 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 <= 59.0d0) then
tmp = cos(x)
else if (y <= 7.6d+151) then
tmp = 1.0d0 + ((x ** 2.0d0) * (-0.5d0))
else
tmp = 1.0d0 + (0.16666666666666666d0 * (y ** 2.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 59.0) {
tmp = Math.cos(x);
} else if (y <= 7.6e+151) {
tmp = 1.0 + (Math.pow(x, 2.0) * -0.5);
} else {
tmp = 1.0 + (0.16666666666666666 * Math.pow(y, 2.0));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 59.0: tmp = math.cos(x) elif y <= 7.6e+151: tmp = 1.0 + (math.pow(x, 2.0) * -0.5) else: tmp = 1.0 + (0.16666666666666666 * math.pow(y, 2.0)) return tmp
function code(x, y) tmp = 0.0 if (y <= 59.0) tmp = cos(x); elseif (y <= 7.6e+151) tmp = Float64(1.0 + Float64((x ^ 2.0) * -0.5)); else tmp = Float64(1.0 + Float64(0.16666666666666666 * (y ^ 2.0))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 59.0) tmp = cos(x); elseif (y <= 7.6e+151) tmp = 1.0 + ((x ^ 2.0) * -0.5); else tmp = 1.0 + (0.16666666666666666 * (y ^ 2.0)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 59.0], N[Cos[x], $MachinePrecision], If[LessEqual[y, 7.6e+151], N[(1.0 + N[(N[Power[x, 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(0.16666666666666666 * N[Power[y, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 59:\\
\;\;\;\;\cos x\\
\mathbf{elif}\;y \leq 7.6 \cdot 10^{+151}:\\
\;\;\;\;1 + {x}^{2} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;1 + 0.16666666666666666 \cdot {y}^{2}\\
\end{array}
\end{array}
if y < 59Initial program 100.0%
Taylor expanded in y around 0 64.0%
if 59 < y < 7.6000000000000001e151Initial program 100.0%
Taylor expanded in y around 0 3.3%
Taylor expanded in x around 0 12.5%
*-commutative12.5%
Simplified12.5%
if 7.6000000000000001e151 < y Initial program 100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around 0 95.7%
(FPCore (x y)
:precision binary64
(if (<= y 700.0)
(cos x)
(if (<= y 2.8e+153)
(* (pow x 2.0) -0.5)
(+ 1.0 (* 0.16666666666666666 (pow y 2.0))))))
double code(double x, double y) {
double tmp;
if (y <= 700.0) {
tmp = cos(x);
} else if (y <= 2.8e+153) {
tmp = pow(x, 2.0) * -0.5;
} else {
tmp = 1.0 + (0.16666666666666666 * pow(y, 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 <= 700.0d0) then
tmp = cos(x)
else if (y <= 2.8d+153) then
tmp = (x ** 2.0d0) * (-0.5d0)
else
tmp = 1.0d0 + (0.16666666666666666d0 * (y ** 2.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 700.0) {
tmp = Math.cos(x);
} else if (y <= 2.8e+153) {
tmp = Math.pow(x, 2.0) * -0.5;
} else {
tmp = 1.0 + (0.16666666666666666 * Math.pow(y, 2.0));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 700.0: tmp = math.cos(x) elif y <= 2.8e+153: tmp = math.pow(x, 2.0) * -0.5 else: tmp = 1.0 + (0.16666666666666666 * math.pow(y, 2.0)) return tmp
function code(x, y) tmp = 0.0 if (y <= 700.0) tmp = cos(x); elseif (y <= 2.8e+153) tmp = Float64((x ^ 2.0) * -0.5); else tmp = Float64(1.0 + Float64(0.16666666666666666 * (y ^ 2.0))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 700.0) tmp = cos(x); elseif (y <= 2.8e+153) tmp = (x ^ 2.0) * -0.5; else tmp = 1.0 + (0.16666666666666666 * (y ^ 2.0)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 700.0], N[Cos[x], $MachinePrecision], If[LessEqual[y, 2.8e+153], N[(N[Power[x, 2.0], $MachinePrecision] * -0.5), $MachinePrecision], N[(1.0 + N[(0.16666666666666666 * N[Power[y, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 700:\\
\;\;\;\;\cos x\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{+153}:\\
\;\;\;\;{x}^{2} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;1 + 0.16666666666666666 \cdot {y}^{2}\\
\end{array}
\end{array}
if y < 700Initial program 100.0%
Taylor expanded in y around 0 63.7%
if 700 < y < 2.79999999999999985e153Initial program 100.0%
*-commutative100.0%
associate-*l/100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 3.1%
*-commutative3.1%
Simplified3.1%
Taylor expanded in x around 0 14.8%
Taylor expanded in x around inf 11.7%
*-commutative11.7%
Simplified11.7%
if 2.79999999999999985e153 < y Initial program 100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around 0 95.7%
(FPCore (x y) :precision binary64 (if (<= y 4.5e-5) (cos x) (/ (/ 1.0 y) (/ 1.0 (sinh y)))))
double code(double x, double y) {
double tmp;
if (y <= 4.5e-5) {
tmp = cos(x);
} else {
tmp = (1.0 / y) / (1.0 / sinh(y));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 4.5d-5) then
tmp = cos(x)
else
tmp = (1.0d0 / y) / (1.0d0 / sinh(y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 4.5e-5) {
tmp = Math.cos(x);
} else {
tmp = (1.0 / y) / (1.0 / Math.sinh(y));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 4.5e-5: tmp = math.cos(x) else: tmp = (1.0 / y) / (1.0 / math.sinh(y)) return tmp
function code(x, y) tmp = 0.0 if (y <= 4.5e-5) tmp = cos(x); else tmp = Float64(Float64(1.0 / y) / Float64(1.0 / sinh(y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 4.5e-5) tmp = cos(x); else tmp = (1.0 / y) / (1.0 / sinh(y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 4.5e-5], N[Cos[x], $MachinePrecision], N[(N[(1.0 / y), $MachinePrecision] / N[(1.0 / N[Sinh[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.5 \cdot 10^{-5}:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{y}}{\frac{1}{\sinh y}}\\
\end{array}
\end{array}
if y < 4.50000000000000028e-5Initial program 100.0%
Taylor expanded in y around 0 64.1%
if 4.50000000000000028e-5 < y Initial program 100.0%
add-cube-cbrt99.9%
pow399.9%
Applied egg-rr99.9%
rem-cube-cbrt100.0%
remove-double-div100.0%
Applied egg-rr100.0%
associate-/l/100.0%
div-inv99.9%
associate-/r*100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 79.1%
(FPCore (x y) :precision binary64 (if (<= y 720.0) (cos x) (* (pow x 2.0) -0.5)))
double code(double x, double y) {
double tmp;
if (y <= 720.0) {
tmp = cos(x);
} else {
tmp = pow(x, 2.0) * -0.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 720.0d0) then
tmp = cos(x)
else
tmp = (x ** 2.0d0) * (-0.5d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 720.0) {
tmp = Math.cos(x);
} else {
tmp = Math.pow(x, 2.0) * -0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 720.0: tmp = math.cos(x) else: tmp = math.pow(x, 2.0) * -0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 720.0) tmp = cos(x); else tmp = Float64((x ^ 2.0) * -0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 720.0) tmp = cos(x); else tmp = (x ^ 2.0) * -0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 720.0], N[Cos[x], $MachinePrecision], N[(N[Power[x, 2.0], $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 720:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;{x}^{2} \cdot -0.5\\
\end{array}
\end{array}
if y < 720Initial program 100.0%
Taylor expanded in y around 0 63.7%
if 720 < y Initial program 100.0%
*-commutative100.0%
associate-*l/100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 3.1%
*-commutative3.1%
Simplified3.1%
Taylor expanded in x around 0 12.0%
Taylor expanded in x around inf 9.5%
*-commutative9.5%
Simplified9.5%
(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 48.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%
*-commutative100.0%
associate-*l/99.9%
Applied egg-rr99.9%
Taylor expanded in y around 0 48.5%
*-commutative48.5%
Simplified48.5%
*-commutative48.5%
associate-/l*48.4%
Applied egg-rr48.4%
Taylor expanded in x around 0 28.4%
herbie shell --seed 2024108
(FPCore (x y)
:name "Linear.Quaternion:$csin from linear-1.19.1.3"
:precision binary64
(* (cos x) (/ (sinh y) y)))