
(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
(let* ((t_0 (/ (sinh y) y)))
(if (<= t_0 2.0)
(/ 1.0 (/ y (/ (cos x) (+ (* y -0.16666666666666666) (/ 1.0 y)))))
t_0)))
double code(double x, double y) {
double t_0 = sinh(y) / y;
double tmp;
if (t_0 <= 2.0) {
tmp = 1.0 / (y / (cos(x) / ((y * -0.16666666666666666) + (1.0 / y))));
} 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 = 1.0d0 / (y / (cos(x) / ((y * (-0.16666666666666666d0)) + (1.0d0 / y))))
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 = 1.0 / (y / (Math.cos(x) / ((y * -0.16666666666666666) + (1.0 / y))));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = math.sinh(y) / y tmp = 0 if t_0 <= 2.0: tmp = 1.0 / (y / (math.cos(x) / ((y * -0.16666666666666666) + (1.0 / y)))) 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 = Float64(1.0 / Float64(y / Float64(cos(x) / Float64(Float64(y * -0.16666666666666666) + Float64(1.0 / y))))); 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 = 1.0 / (y / (cos(x) / ((y * -0.16666666666666666) + (1.0 / y)))); 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[(1.0 / N[(y / N[(N[Cos[x], $MachinePrecision] / N[(N[(y * -0.16666666666666666), $MachinePrecision] + N[(1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sinh y}{y}\\
\mathbf{if}\;t_0 \leq 2:\\
\;\;\;\;\frac{1}{\frac{y}{\frac{\cos x}{y \cdot -0.16666666666666666 + \frac{1}{y}}}}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (/.f64 (sinh.f64 y) y) < 2Initial program 99.9%
associate-*r/99.8%
clear-num99.7%
Applied egg-rr99.7%
*-commutative99.7%
sinh-def7.1%
associate-*l/7.1%
sinh-undef99.7%
Applied egg-rr99.7%
*-commutative99.7%
associate-/l*99.6%
associate-/r*99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in y around 0 99.2%
if 2 < (/.f64 (sinh.f64 y) y) Initial program 100.0%
associate-*r/100.0%
associate-*l/100.0%
*-commutative100.0%
clear-num100.0%
un-div-inv100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 76.0%
Final simplification87.5%
(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 99.9%
Taylor expanded in y around 0 98.7%
if 2 < (/.f64 (sinh.f64 y) y) Initial program 100.0%
associate-*r/100.0%
associate-*l/100.0%
*-commutative100.0%
clear-num100.0%
un-div-inv100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 76.0%
Final simplification87.3%
(FPCore (x y) :precision binary64 (if (<= y 1.35e+20) (cos x) (* y (* -0.5 (* x (* x (/ 1.0 y)))))))
double code(double x, double y) {
double tmp;
if (y <= 1.35e+20) {
tmp = cos(x);
} else {
tmp = 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 <= 1.35d+20) then
tmp = cos(x)
else
tmp = 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 <= 1.35e+20) {
tmp = Math.cos(x);
} else {
tmp = y * (-0.5 * (x * (x * (1.0 / y))));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.35e+20: tmp = math.cos(x) else: tmp = y * (-0.5 * (x * (x * (1.0 / y)))) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.35e+20) tmp = cos(x); else tmp = Float64(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 <= 1.35e+20) tmp = cos(x); else tmp = y * (-0.5 * (x * (x * (1.0 / y)))); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.35e+20], N[Cos[x], $MachinePrecision], N[(y * N[(-0.5 * N[(x * N[(x * N[(1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.35 \cdot 10^{+20}:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-0.5 \cdot \left(x \cdot \left(x \cdot \frac{1}{y}\right)\right)\right)\\
\end{array}
\end{array}
if y < 1.35e20Initial program 100.0%
Taylor expanded in y around 0 67.0%
if 1.35e20 < 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 20.5%
*-commutative20.5%
Simplified20.5%
Taylor expanded in x around inf 19.7%
div-inv19.7%
unpow219.7%
associate-*l*18.5%
Applied egg-rr18.5%
Final simplification54.5%
(FPCore (x y) :precision binary64 (if (<= y 1.22e+20) 1.0 (* y (* -0.5 (* x (* x (/ 1.0 y)))))))
double code(double x, double y) {
double tmp;
if (y <= 1.22e+20) {
tmp = 1.0;
} else {
tmp = 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 <= 1.22d+20) then
tmp = 1.0d0
else
tmp = 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 <= 1.22e+20) {
tmp = 1.0;
} else {
tmp = y * (-0.5 * (x * (x * (1.0 / y))));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.22e+20: tmp = 1.0 else: tmp = y * (-0.5 * (x * (x * (1.0 / y)))) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.22e+20) tmp = 1.0; else tmp = Float64(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 <= 1.22e+20) tmp = 1.0; else tmp = y * (-0.5 * (x * (x * (1.0 / y)))); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.22e+20], 1.0, N[(y * N[(-0.5 * N[(x * N[(x * N[(1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.22 \cdot 10^{+20}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-0.5 \cdot \left(x \cdot \left(x \cdot \frac{1}{y}\right)\right)\right)\\
\end{array}
\end{array}
if y < 1.22e20Initial program 100.0%
associate-*r/99.8%
associate-*l/99.8%
Simplified99.8%
Taylor expanded in y around 0 66.9%
Taylor expanded in x around 0 35.6%
if 1.22e20 < 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 20.5%
*-commutative20.5%
Simplified20.5%
Taylor expanded in x around inf 19.7%
div-inv19.7%
unpow219.7%
associate-*l*18.5%
Applied egg-rr18.5%
Final simplification31.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%
associate-*r/99.9%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in y around 0 50.5%
Taylor expanded in x around 0 27.0%
Final simplification27.0%
herbie shell --seed 2023336
(FPCore (x y)
:name "Linear.Quaternion:$csin from linear-1.19.1.3"
:precision binary64
(* (cos x) (/ (sinh y) y)))