
(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 9 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.000112)
(cos x)
(if (<= y 1.35e+154)
(/ (sinh y) y)
(* 0.16666666666666666 (* (cos x) (* y y))))))
double code(double x, double y) {
double tmp;
if (y <= 0.000112) {
tmp = cos(x);
} else if (y <= 1.35e+154) {
tmp = sinh(y) / y;
} else {
tmp = 0.16666666666666666 * (cos(x) * (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.000112d0) then
tmp = cos(x)
else if (y <= 1.35d+154) then
tmp = sinh(y) / y
else
tmp = 0.16666666666666666d0 * (cos(x) * (y * y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 0.000112) {
tmp = Math.cos(x);
} else if (y <= 1.35e+154) {
tmp = Math.sinh(y) / y;
} else {
tmp = 0.16666666666666666 * (Math.cos(x) * (y * y));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 0.000112: tmp = math.cos(x) elif y <= 1.35e+154: tmp = math.sinh(y) / y else: tmp = 0.16666666666666666 * (math.cos(x) * (y * y)) return tmp
function code(x, y) tmp = 0.0 if (y <= 0.000112) tmp = cos(x); elseif (y <= 1.35e+154) tmp = Float64(sinh(y) / y); else tmp = Float64(0.16666666666666666 * Float64(cos(x) * Float64(y * y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 0.000112) tmp = cos(x); elseif (y <= 1.35e+154) tmp = sinh(y) / y; else tmp = 0.16666666666666666 * (cos(x) * (y * y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 0.000112], N[Cos[x], $MachinePrecision], If[LessEqual[y, 1.35e+154], N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision], N[(0.16666666666666666 * N[(N[Cos[x], $MachinePrecision] * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.000112:\\
\;\;\;\;\cos x\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\frac{\sinh y}{y}\\
\mathbf{else}:\\
\;\;\;\;0.16666666666666666 \cdot \left(\cos x \cdot \left(y \cdot y\right)\right)\\
\end{array}
\end{array}
if y < 1.11999999999999998e-4Initial program 100.0%
*-commutative100.0%
associate-/r/99.9%
Simplified99.9%
Taylor expanded in y around 0 68.3%
if 1.11999999999999998e-4 < y < 1.35000000000000003e154Initial program 99.9%
*-commutative99.9%
associate-/r/99.9%
Simplified99.9%
clear-num99.9%
inv-pow99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 78.9%
if 1.35000000000000003e154 < y Initial program 100.0%
Taylor expanded in y around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
unpow2100.0%
Simplified100.0%
Final simplification74.0%
(FPCore (x y)
:precision binary64
(if (<= y 0.038)
(* (cos x) (+ 1.0 (* 0.16666666666666666 (* y y))))
(if (<= y 1.35e+154)
(/ (sinh y) y)
(* 0.16666666666666666 (* (cos x) (* y y))))))
double code(double x, double y) {
double tmp;
if (y <= 0.038) {
tmp = cos(x) * (1.0 + (0.16666666666666666 * (y * y)));
} else if (y <= 1.35e+154) {
tmp = sinh(y) / y;
} else {
tmp = 0.16666666666666666 * (cos(x) * (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.038d0) then
tmp = cos(x) * (1.0d0 + (0.16666666666666666d0 * (y * y)))
else if (y <= 1.35d+154) then
tmp = sinh(y) / y
else
tmp = 0.16666666666666666d0 * (cos(x) * (y * y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 0.038) {
tmp = Math.cos(x) * (1.0 + (0.16666666666666666 * (y * y)));
} else if (y <= 1.35e+154) {
tmp = Math.sinh(y) / y;
} else {
tmp = 0.16666666666666666 * (Math.cos(x) * (y * y));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 0.038: tmp = math.cos(x) * (1.0 + (0.16666666666666666 * (y * y))) elif y <= 1.35e+154: tmp = math.sinh(y) / y else: tmp = 0.16666666666666666 * (math.cos(x) * (y * y)) return tmp
function code(x, y) tmp = 0.0 if (y <= 0.038) tmp = Float64(cos(x) * Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y)))); elseif (y <= 1.35e+154) tmp = Float64(sinh(y) / y); else tmp = Float64(0.16666666666666666 * Float64(cos(x) * Float64(y * y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 0.038) tmp = cos(x) * (1.0 + (0.16666666666666666 * (y * y))); elseif (y <= 1.35e+154) tmp = sinh(y) / y; else tmp = 0.16666666666666666 * (cos(x) * (y * y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 0.038], N[(N[Cos[x], $MachinePrecision] * N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.35e+154], N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision], N[(0.16666666666666666 * N[(N[Cos[x], $MachinePrecision] * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.038:\\
\;\;\;\;\cos x \cdot \left(1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\right)\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\frac{\sinh y}{y}\\
\mathbf{else}:\\
\;\;\;\;0.16666666666666666 \cdot \left(\cos x \cdot \left(y \cdot y\right)\right)\\
\end{array}
\end{array}
if y < 0.0379999999999999991Initial program 100.0%
Taylor expanded in y around 0 85.0%
unpow285.0%
Simplified85.0%
if 0.0379999999999999991 < y < 1.35000000000000003e154Initial program 99.9%
*-commutative99.9%
associate-/r/99.9%
Simplified99.9%
clear-num99.9%
inv-pow99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 80.7%
if 1.35000000000000003e154 < y Initial program 100.0%
Taylor expanded in y around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
unpow2100.0%
Simplified100.0%
Final simplification86.5%
(FPCore (x y) :precision binary64 (if (<= y 0.00015) (cos x) (/ (sinh y) y)))
double code(double x, double y) {
double tmp;
if (y <= 0.00015) {
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.00015d0) 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.00015) {
tmp = Math.cos(x);
} else {
tmp = Math.sinh(y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 0.00015: tmp = math.cos(x) else: tmp = math.sinh(y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 0.00015) 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.00015) tmp = cos(x); else tmp = sinh(y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 0.00015], N[Cos[x], $MachinePrecision], N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.00015:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;\frac{\sinh y}{y}\\
\end{array}
\end{array}
if y < 1.49999999999999987e-4Initial program 100.0%
*-commutative100.0%
associate-/r/99.9%
Simplified99.9%
Taylor expanded in y around 0 68.3%
if 1.49999999999999987e-4 < y Initial program 99.9%
*-commutative99.9%
associate-/r/100.0%
Simplified100.0%
clear-num100.0%
inv-pow100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 76.5%
Final simplification70.5%
(FPCore (x y)
:precision binary64
(if (<= y 6200.0)
(cos x)
(if (<= y 5.5e+153)
(+ 1.0 (* (* x x) -0.5))
(+ 1.0 (* 0.16666666666666666 (* y y))))))
double code(double x, double y) {
double tmp;
if (y <= 6200.0) {
tmp = cos(x);
} else if (y <= 5.5e+153) {
tmp = 1.0 + ((x * x) * -0.5);
} 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) :: tmp
if (y <= 6200.0d0) then
tmp = cos(x)
else if (y <= 5.5d+153) then
tmp = 1.0d0 + ((x * x) * (-0.5d0))
else
tmp = 1.0d0 + (0.16666666666666666d0 * (y * y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 6200.0) {
tmp = Math.cos(x);
} else if (y <= 5.5e+153) {
tmp = 1.0 + ((x * x) * -0.5);
} else {
tmp = 1.0 + (0.16666666666666666 * (y * y));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 6200.0: tmp = math.cos(x) elif y <= 5.5e+153: tmp = 1.0 + ((x * x) * -0.5) else: tmp = 1.0 + (0.16666666666666666 * (y * y)) return tmp
function code(x, y) tmp = 0.0 if (y <= 6200.0) tmp = cos(x); elseif (y <= 5.5e+153) tmp = Float64(1.0 + Float64(Float64(x * x) * -0.5)); else tmp = Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 6200.0) tmp = cos(x); elseif (y <= 5.5e+153) tmp = 1.0 + ((x * x) * -0.5); else tmp = 1.0 + (0.16666666666666666 * (y * y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 6200.0], N[Cos[x], $MachinePrecision], If[LessEqual[y, 5.5e+153], N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6200:\\
\;\;\;\;\cos x\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{+153}:\\
\;\;\;\;1 + \left(x \cdot x\right) \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if y < 6200Initial program 100.0%
*-commutative100.0%
associate-/r/99.9%
Simplified99.9%
Taylor expanded in y around 0 67.3%
if 6200 < y < 5.5000000000000003e153Initial program 100.0%
*-commutative100.0%
associate-/r/100.0%
Simplified100.0%
Taylor expanded in y around 0 3.1%
Taylor expanded in x around 0 9.1%
*-commutative9.1%
unpow29.1%
Simplified9.1%
if 5.5000000000000003e153 < y Initial program 100.0%
*-commutative100.0%
associate-/r/100.0%
Simplified100.0%
clear-num100.0%
inv-pow100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 74.3%
Taylor expanded in y around 0 74.3%
unpow2100.0%
Simplified74.3%
Final simplification61.9%
(FPCore (x y) :precision binary64 (if (<= x 1.45e+192) (+ 1.0 (* 0.16666666666666666 (* y y))) (+ 1.0 (* (* x x) -0.5))))
double code(double x, double y) {
double tmp;
if (x <= 1.45e+192) {
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 <= 1.45d+192) 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 <= 1.45e+192) {
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 <= 1.45e+192: 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 <= 1.45e+192) 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 <= 1.45e+192) 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, 1.45e+192], 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 1.45 \cdot 10^{+192}:\\
\;\;\;\;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 < 1.4500000000000001e192Initial program 100.0%
*-commutative100.0%
associate-/r/100.0%
Simplified100.0%
clear-num99.8%
inv-pow99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 74.4%
Taylor expanded in y around 0 56.6%
unpow279.0%
Simplified56.6%
if 1.4500000000000001e192 < x Initial program 100.0%
*-commutative100.0%
associate-/r/99.8%
Simplified99.8%
Taylor expanded in y around 0 39.3%
Taylor expanded in x around 0 38.3%
*-commutative38.3%
unpow238.3%
Simplified38.3%
Final simplification54.9%
(FPCore (x y) :precision binary64 (if (<= y 1.95) 1.0 (* 0.16666666666666666 (* y y))))
double code(double x, double y) {
double tmp;
if (y <= 1.95) {
tmp = 1.0;
} else {
tmp = 0.16666666666666666 * (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 <= 1.95d0) then
tmp = 1.0d0
else
tmp = 0.16666666666666666d0 * (y * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.95) {
tmp = 1.0;
} else {
tmp = 0.16666666666666666 * (y * y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.95: tmp = 1.0 else: tmp = 0.16666666666666666 * (y * y) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.95) tmp = 1.0; else tmp = Float64(0.16666666666666666 * Float64(y * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.95) tmp = 1.0; else tmp = 0.16666666666666666 * (y * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.95], 1.0, N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.95:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.16666666666666666 \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if y < 1.94999999999999996Initial program 100.0%
*-commutative100.0%
associate-/r/99.9%
Simplified99.9%
Taylor expanded in y around 0 67.8%
Taylor expanded in x around 0 43.8%
if 1.94999999999999996 < y Initial program 100.0%
Taylor expanded in y around 0 56.9%
unpow256.9%
Simplified56.9%
Taylor expanded in y around inf 56.7%
unpow256.7%
Simplified56.7%
Taylor expanded in x around 0 42.1%
unpow242.1%
Simplified42.1%
Final simplification43.4%
(FPCore (x y) :precision binary64 (+ 1.0 (* 0.16666666666666666 (* y y))))
double code(double x, double y) {
return 1.0 + (0.16666666666666666 * (y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 + (0.16666666666666666d0 * (y * y))
end function
public static double code(double x, double y) {
return 1.0 + (0.16666666666666666 * (y * y));
}
def code(x, y): return 1.0 + (0.16666666666666666 * (y * y))
function code(x, y) return Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y))) end
function tmp = code(x, y) tmp = 1.0 + (0.16666666666666666 * (y * y)); end
code[x_, y_] := N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + 0.16666666666666666 \cdot \left(y \cdot y\right)
\end{array}
Initial program 100.0%
*-commutative100.0%
associate-/r/99.9%
Simplified99.9%
clear-num99.8%
inv-pow99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 70.1%
Taylor expanded in y around 0 52.5%
unpow277.6%
Simplified52.5%
Final simplification52.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-/r/99.9%
Simplified99.9%
Taylor expanded in y around 0 51.5%
Taylor expanded in x around 0 33.3%
Final simplification33.3%
herbie shell --seed 2023268
(FPCore (x y)
:name "Linear.Quaternion:$csin from linear-1.19.1.3"
:precision binary64
(* (cos x) (/ (sinh y) y)))