
(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 8 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 (<= (/ (sinh y) y) 1.0) (cos x) (/ (/ 2.0 (/ 2.0 (sinh y))) y)))
double code(double x, double y) {
double tmp;
if ((sinh(y) / y) <= 1.0) {
tmp = cos(x);
} else {
tmp = (2.0 / (2.0 / 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 ((sinh(y) / y) <= 1.0d0) then
tmp = cos(x)
else
tmp = (2.0d0 / (2.0d0 / sinh(y))) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((Math.sinh(y) / y) <= 1.0) {
tmp = Math.cos(x);
} else {
tmp = (2.0 / (2.0 / Math.sinh(y))) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if (math.sinh(y) / y) <= 1.0: tmp = math.cos(x) else: tmp = (2.0 / (2.0 / math.sinh(y))) / y return tmp
function code(x, y) tmp = 0.0 if (Float64(sinh(y) / y) <= 1.0) tmp = cos(x); else tmp = Float64(Float64(2.0 / Float64(2.0 / sinh(y))) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((sinh(y) / y) <= 1.0) tmp = cos(x); else tmp = (2.0 / (2.0 / sinh(y))) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision], 1.0], N[Cos[x], $MachinePrecision], N[(N[(2.0 / N[(2.0 / N[Sinh[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sinh y}{y} \leq 1:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{\frac{2}{\sinh y}}}{y}\\
\end{array}
\end{array}
if (/.f64 (sinh.f64 y) y) < 1Initial program 100.0%
Taylor expanded in y around 0 100.0%
if 1 < (/.f64 (sinh.f64 y) y) Initial program 100.0%
associate-*r/100.0%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in x around 0 73.9%
Taylor expanded in y around inf 73.9%
associate-*r/73.9%
Simplified73.9%
sinh-def73.9%
sinh-undef73.9%
associate-/l*73.9%
Applied egg-rr73.9%
Final simplification87.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (sinh y) y))) (if (<= t_0 1.0) (cos x) t_0)))
double code(double x, double y) {
double t_0 = sinh(y) / y;
double tmp;
if (t_0 <= 1.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 <= 1.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 <= 1.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 <= 1.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 <= 1.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 <= 1.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, 1.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 1:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (/.f64 (sinh.f64 y) y) < 1Initial program 100.0%
Taylor expanded in y around 0 100.0%
if 1 < (/.f64 (sinh.f64 y) y) Initial program 100.0%
associate-*r/100.0%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in x around 0 73.9%
Taylor expanded in y around inf 73.9%
associate-*r/73.9%
Simplified73.9%
Final simplification87.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ 2.0 (* x x))))
(if (<= y 4500.0)
(cos x)
(if (<= y 4.7e+70)
t_0
(if (<= y 2e+92)
(+ 1.0 (* (* x x) -0.5))
(if (<= y 2.45e+147) t_0 (+ 1.0 (* 0.16666666666666666 (* y y)))))))))
double code(double x, double y) {
double t_0 = 2.0 / (x * x);
double tmp;
if (y <= 4500.0) {
tmp = cos(x);
} else if (y <= 4.7e+70) {
tmp = t_0;
} else if (y <= 2e+92) {
tmp = 1.0 + ((x * x) * -0.5);
} else if (y <= 2.45e+147) {
tmp = t_0;
} else {
tmp = 1.0 + (0.16666666666666666 * (y * y));
}
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 = 2.0d0 / (x * x)
if (y <= 4500.0d0) then
tmp = cos(x)
else if (y <= 4.7d+70) then
tmp = t_0
else if (y <= 2d+92) then
tmp = 1.0d0 + ((x * x) * (-0.5d0))
else if (y <= 2.45d+147) then
tmp = t_0
else
tmp = 1.0d0 + (0.16666666666666666d0 * (y * y))
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 2.0 / (x * x);
double tmp;
if (y <= 4500.0) {
tmp = Math.cos(x);
} else if (y <= 4.7e+70) {
tmp = t_0;
} else if (y <= 2e+92) {
tmp = 1.0 + ((x * x) * -0.5);
} else if (y <= 2.45e+147) {
tmp = t_0;
} else {
tmp = 1.0 + (0.16666666666666666 * (y * y));
}
return tmp;
}
def code(x, y): t_0 = 2.0 / (x * x) tmp = 0 if y <= 4500.0: tmp = math.cos(x) elif y <= 4.7e+70: tmp = t_0 elif y <= 2e+92: tmp = 1.0 + ((x * x) * -0.5) elif y <= 2.45e+147: tmp = t_0 else: tmp = 1.0 + (0.16666666666666666 * (y * y)) return tmp
function code(x, y) t_0 = Float64(2.0 / Float64(x * x)) tmp = 0.0 if (y <= 4500.0) tmp = cos(x); elseif (y <= 4.7e+70) tmp = t_0; elseif (y <= 2e+92) tmp = Float64(1.0 + Float64(Float64(x * x) * -0.5)); elseif (y <= 2.45e+147) tmp = t_0; else tmp = Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y))); end return tmp end
function tmp_2 = code(x, y) t_0 = 2.0 / (x * x); tmp = 0.0; if (y <= 4500.0) tmp = cos(x); elseif (y <= 4.7e+70) tmp = t_0; elseif (y <= 2e+92) tmp = 1.0 + ((x * x) * -0.5); elseif (y <= 2.45e+147) tmp = t_0; else tmp = 1.0 + (0.16666666666666666 * (y * y)); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 4500.0], N[Cos[x], $MachinePrecision], If[LessEqual[y, 4.7e+70], t$95$0, If[LessEqual[y, 2e+92], N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.45e+147], t$95$0, N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{x \cdot x}\\
\mathbf{if}\;y \leq 4500:\\
\;\;\;\;\cos x\\
\mathbf{elif}\;y \leq 4.7 \cdot 10^{+70}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 2 \cdot 10^{+92}:\\
\;\;\;\;1 + \left(x \cdot x\right) \cdot -0.5\\
\mathbf{elif}\;y \leq 2.45 \cdot 10^{+147}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if y < 4500Initial program 100.0%
Taylor expanded in y around 0 67.4%
if 4500 < y < 4.6999999999999998e70 or 2.0000000000000001e92 < y < 2.4499999999999999e147Initial program 100.0%
associate-*r/100.0%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in y around 0 3.1%
*-commutative3.1%
clear-num3.1%
un-div-inv3.1%
Applied egg-rr3.1%
Taylor expanded in x around 0 2.6%
*-commutative2.6%
unpow22.6%
Simplified2.6%
Taylor expanded in x around inf 23.6%
unpow223.6%
Simplified23.6%
if 4.6999999999999998e70 < y < 2.0000000000000001e92Initial 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 51.0%
unpow251.0%
Simplified51.0%
if 2.4499999999999999e147 < y Initial program 100.0%
associate-*r/100.0%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in x around 0 75.8%
Taylor expanded in y around 0 73.1%
unpow273.1%
Simplified73.1%
Final simplification64.2%
(FPCore (x y)
:precision binary64
(if (<= y 4500.0)
1.0
(if (or (<= y 2.15e+70) (not (<= y 6.5e+95)))
(/ 2.0 (* x x))
(+ 1.0 (* (* x x) -0.5)))))
double code(double x, double y) {
double tmp;
if (y <= 4500.0) {
tmp = 1.0;
} else if ((y <= 2.15e+70) || !(y <= 6.5e+95)) {
tmp = 2.0 / (x * x);
} else {
tmp = 1.0 + ((x * x) * -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 <= 4500.0d0) then
tmp = 1.0d0
else if ((y <= 2.15d+70) .or. (.not. (y <= 6.5d+95))) then
tmp = 2.0d0 / (x * x)
else
tmp = 1.0d0 + ((x * x) * (-0.5d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 4500.0) {
tmp = 1.0;
} else if ((y <= 2.15e+70) || !(y <= 6.5e+95)) {
tmp = 2.0 / (x * x);
} else {
tmp = 1.0 + ((x * x) * -0.5);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 4500.0: tmp = 1.0 elif (y <= 2.15e+70) or not (y <= 6.5e+95): tmp = 2.0 / (x * x) else: tmp = 1.0 + ((x * x) * -0.5) return tmp
function code(x, y) tmp = 0.0 if (y <= 4500.0) tmp = 1.0; elseif ((y <= 2.15e+70) || !(y <= 6.5e+95)) tmp = Float64(2.0 / Float64(x * x)); else tmp = Float64(1.0 + Float64(Float64(x * x) * -0.5)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 4500.0) tmp = 1.0; elseif ((y <= 2.15e+70) || ~((y <= 6.5e+95))) tmp = 2.0 / (x * x); else tmp = 1.0 + ((x * x) * -0.5); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 4500.0], 1.0, If[Or[LessEqual[y, 2.15e+70], N[Not[LessEqual[y, 6.5e+95]], $MachinePrecision]], N[(2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4500:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.15 \cdot 10^{+70} \lor \neg \left(y \leq 6.5 \cdot 10^{+95}\right):\\
\;\;\;\;\frac{2}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;1 + \left(x \cdot x\right) \cdot -0.5\\
\end{array}
\end{array}
if y < 4500Initial program 100.0%
associate-*r/99.9%
associate-*l/99.8%
Simplified99.8%
Taylor expanded in x around 0 62.6%
Taylor expanded in y around 0 38.3%
if 4500 < y < 2.15e70 or 6.5e95 < 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%
clear-num3.1%
un-div-inv3.1%
Applied egg-rr3.1%
Taylor expanded in x around 0 2.3%
*-commutative2.3%
unpow22.3%
Simplified2.3%
Taylor expanded in x around inf 16.1%
unpow216.1%
Simplified16.1%
if 2.15e70 < y < 6.5e95Initial 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 51.0%
unpow251.0%
Simplified51.0%
Final simplification34.3%
(FPCore (x y) :precision binary64 (if (<= x 3.9e+164) (+ 1.0 (* 0.16666666666666666 (* y y))) (+ 1.0 (* (* x x) -0.5))))
double code(double x, double y) {
double tmp;
if (x <= 3.9e+164) {
tmp = 1.0 + (0.16666666666666666 * (y * y));
} else {
tmp = 1.0 + ((x * x) * -0.5);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 3.9d+164) then
tmp = 1.0d0 + (0.16666666666666666d0 * (y * y))
else
tmp = 1.0d0 + ((x * x) * (-0.5d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 3.9e+164) {
tmp = 1.0 + (0.16666666666666666 * (y * y));
} else {
tmp = 1.0 + ((x * x) * -0.5);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 3.9e+164: tmp = 1.0 + (0.16666666666666666 * (y * y)) else: tmp = 1.0 + ((x * x) * -0.5) return tmp
function code(x, y) tmp = 0.0 if (x <= 3.9e+164) tmp = Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y))); else tmp = Float64(1.0 + Float64(Float64(x * x) * -0.5)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 3.9e+164) tmp = 1.0 + (0.16666666666666666 * (y * y)); else tmp = 1.0 + ((x * x) * -0.5); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 3.9e+164], N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.9 \cdot 10^{+164}:\\
\;\;\;\;1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;1 + \left(x \cdot x\right) \cdot -0.5\\
\end{array}
\end{array}
if x < 3.89999999999999985e164Initial program 100.0%
associate-*r/100.0%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in x around 0 69.8%
Taylor expanded in y around 0 50.8%
unpow250.8%
Simplified50.8%
if 3.89999999999999985e164 < x Initial program 99.9%
associate-*r/99.9%
associate-*l/99.8%
Simplified99.8%
Taylor expanded in y around 0 43.9%
Taylor expanded in x around 0 35.1%
unpow235.1%
Simplified35.1%
Final simplification49.1%
(FPCore (x y) :precision binary64 (if (<= y 4500.0) 1.0 (/ 2.0 (* x x))))
double code(double x, double y) {
double tmp;
if (y <= 4500.0) {
tmp = 1.0;
} else {
tmp = 2.0 / (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 <= 4500.0d0) then
tmp = 1.0d0
else
tmp = 2.0d0 / (x * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 4500.0) {
tmp = 1.0;
} else {
tmp = 2.0 / (x * x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 4500.0: tmp = 1.0 else: tmp = 2.0 / (x * x) return tmp
function code(x, y) tmp = 0.0 if (y <= 4500.0) tmp = 1.0; else tmp = Float64(2.0 / Float64(x * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 4500.0) tmp = 1.0; else tmp = 2.0 / (x * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 4500.0], 1.0, N[(2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4500:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{x \cdot x}\\
\end{array}
\end{array}
if y < 4500Initial program 100.0%
associate-*r/99.9%
associate-*l/99.8%
Simplified99.8%
Taylor expanded in x around 0 62.6%
Taylor expanded in y around 0 38.3%
if 4500 < 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%
clear-num3.1%
un-div-inv3.1%
Applied egg-rr3.1%
Taylor expanded in x around 0 2.3%
*-commutative2.3%
unpow22.3%
Simplified2.3%
Taylor expanded in x around inf 13.9%
unpow213.9%
Simplified13.9%
Final simplification32.4%
(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/100.0%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in x around 0 65.0%
Taylor expanded in y around 0 29.6%
Final simplification29.6%
herbie shell --seed 2023297
(FPCore (x y)
:name "Linear.Quaternion:$csin from linear-1.19.1.3"
:precision binary64
(* (cos x) (/ (sinh y) y)))