
(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 (if (<= y 155000000000.0) (cos x) (sqrt (* (pow x 4.0) 0.25))))
double code(double x, double y) {
double tmp;
if (y <= 155000000000.0) {
tmp = cos(x);
} else {
tmp = sqrt((pow(x, 4.0) * 0.25));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 155000000000.0d0) then
tmp = cos(x)
else
tmp = sqrt(((x ** 4.0d0) * 0.25d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 155000000000.0) {
tmp = Math.cos(x);
} else {
tmp = Math.sqrt((Math.pow(x, 4.0) * 0.25));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 155000000000.0: tmp = math.cos(x) else: tmp = math.sqrt((math.pow(x, 4.0) * 0.25)) return tmp
function code(x, y) tmp = 0.0 if (y <= 155000000000.0) tmp = cos(x); else tmp = sqrt(Float64((x ^ 4.0) * 0.25)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 155000000000.0) tmp = cos(x); else tmp = sqrt(((x ^ 4.0) * 0.25)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 155000000000.0], N[Cos[x], $MachinePrecision], N[Sqrt[N[(N[Power[x, 4.0], $MachinePrecision] * 0.25), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 155000000000:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;\sqrt{{x}^{4} \cdot 0.25}\\
\end{array}
\end{array}
if y < 1.55e11Initial program 100.0%
Taylor expanded in y around 0 69.0%
if 1.55e11 < y Initial program 100.0%
Taylor expanded in y around 0 3.1%
Taylor expanded in x around 0 16.1%
Taylor expanded in x around inf 15.3%
add-sqr-sqrt0.3%
sqrt-unprod22.0%
pow1/222.0%
*-commutative22.0%
*-commutative22.0%
swap-sqr22.0%
pow-prod-up22.0%
metadata-eval22.0%
metadata-eval22.0%
Applied egg-rr22.0%
unpow1/222.0%
Simplified22.0%
(FPCore (x y) :precision binary64 (if (<= y 80000000.0) (cos x) (+ 1.0 (* -0.5 (* x x)))))
double code(double x, double y) {
double tmp;
if (y <= 80000000.0) {
tmp = cos(x);
} 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 <= 80000000.0d0) then
tmp = cos(x)
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 <= 80000000.0) {
tmp = Math.cos(x);
} else {
tmp = 1.0 + (-0.5 * (x * x));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 80000000.0: tmp = math.cos(x) else: tmp = 1.0 + (-0.5 * (x * x)) return tmp
function code(x, y) tmp = 0.0 if (y <= 80000000.0) tmp = cos(x); 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 <= 80000000.0) tmp = cos(x); else tmp = 1.0 + (-0.5 * (x * x)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 80000000.0], N[Cos[x], $MachinePrecision], N[(1.0 + N[(-0.5 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 80000000:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;1 + -0.5 \cdot \left(x \cdot x\right)\\
\end{array}
\end{array}
if y < 8e7Initial program 100.0%
Taylor expanded in y around 0 69.7%
if 8e7 < y Initial program 100.0%
Taylor expanded in y around 0 3.1%
Taylor expanded in x around 0 17.1%
unpow217.1%
Applied egg-rr17.1%
(FPCore (x y) :precision binary64 (if (<= y 80000000.0) 1.0 (+ 1.0 (* -0.5 (* x x)))))
double code(double x, double y) {
double tmp;
if (y <= 80000000.0) {
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 <= 80000000.0d0) 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 <= 80000000.0) {
tmp = 1.0;
} else {
tmp = 1.0 + (-0.5 * (x * x));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 80000000.0: tmp = 1.0 else: tmp = 1.0 + (-0.5 * (x * x)) return tmp
function code(x, y) tmp = 0.0 if (y <= 80000000.0) 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 <= 80000000.0) tmp = 1.0; else tmp = 1.0 + (-0.5 * (x * x)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 80000000.0], 1.0, N[(1.0 + N[(-0.5 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 80000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;1 + -0.5 \cdot \left(x \cdot x\right)\\
\end{array}
\end{array}
if y < 8e7Initial program 100.0%
Taylor expanded in y around 0 69.7%
Taylor expanded in x around 0 37.4%
Taylor expanded in x around 0 37.7%
if 8e7 < y Initial program 100.0%
Taylor expanded in y around 0 3.1%
Taylor expanded in x around 0 17.1%
unpow217.1%
Applied egg-rr17.1%
(FPCore (x y) :precision binary64 (if (<= y 300000000.0) 1.0 (* -0.5 (* x x))))
double code(double x, double y) {
double tmp;
if (y <= 300000000.0) {
tmp = 1.0;
} else {
tmp = -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 <= 300000000.0d0) then
tmp = 1.0d0
else
tmp = (-0.5d0) * (x * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 300000000.0) {
tmp = 1.0;
} else {
tmp = -0.5 * (x * x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 300000000.0: tmp = 1.0 else: tmp = -0.5 * (x * x) return tmp
function code(x, y) tmp = 0.0 if (y <= 300000000.0) tmp = 1.0; else tmp = Float64(-0.5 * Float64(x * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 300000000.0) tmp = 1.0; else tmp = -0.5 * (x * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 300000000.0], 1.0, N[(-0.5 * N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 300000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(x \cdot x\right)\\
\end{array}
\end{array}
if y < 3e8Initial program 100.0%
Taylor expanded in y around 0 69.7%
Taylor expanded in x around 0 37.4%
Taylor expanded in x around 0 37.7%
if 3e8 < y Initial program 100.0%
Taylor expanded in y around 0 3.1%
Taylor expanded in x around 0 17.1%
Taylor expanded in x around inf 16.2%
unpow217.1%
Applied egg-rr16.2%
(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 y around 0 50.5%
Taylor expanded in x around 0 31.5%
Taylor expanded in x around 0 27.5%
herbie shell --seed 2024116
(FPCore (x y)
:name "Linear.Quaternion:$csin from linear-1.19.1.3"
:precision binary64
(* (cos x) (/ (sinh y) y)))