
(FPCore (x y) :precision binary64 (* (cosh x) (/ (sin y) y)))
double code(double x, double y) {
return cosh(x) * (sin(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = cosh(x) * (sin(y) / y)
end function
public static double code(double x, double y) {
return Math.cosh(x) * (Math.sin(y) / y);
}
def code(x, y): return math.cosh(x) * (math.sin(y) / y)
function code(x, y) return Float64(cosh(x) * Float64(sin(y) / y)) end
function tmp = code(x, y) tmp = cosh(x) * (sin(y) / y); end
code[x_, y_] := N[(N[Cosh[x], $MachinePrecision] * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cosh x \cdot \frac{\sin y}{y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* (cosh x) (/ (sin y) y)))
double code(double x, double y) {
return cosh(x) * (sin(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = cosh(x) * (sin(y) / y)
end function
public static double code(double x, double y) {
return Math.cosh(x) * (Math.sin(y) / y);
}
def code(x, y): return math.cosh(x) * (math.sin(y) / y)
function code(x, y) return Float64(cosh(x) * Float64(sin(y) / y)) end
function tmp = code(x, y) tmp = cosh(x) * (sin(y) / y); end
code[x_, y_] := N[(N[Cosh[x], $MachinePrecision] * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cosh x \cdot \frac{\sin y}{y}
\end{array}
(FPCore (x y) :precision binary64 (/ (/ (sin y) y) (/ 1.0 (cosh x))))
double code(double x, double y) {
return (sin(y) / y) / (1.0 / cosh(x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (sin(y) / y) / (1.0d0 / cosh(x))
end function
public static double code(double x, double y) {
return (Math.sin(y) / y) / (1.0 / Math.cosh(x));
}
def code(x, y): return (math.sin(y) / y) / (1.0 / math.cosh(x))
function code(x, y) return Float64(Float64(sin(y) / y) / Float64(1.0 / cosh(x))) end
function tmp = code(x, y) tmp = (sin(y) / y) / (1.0 / cosh(x)); end
code[x_, y_] := N[(N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision] / N[(1.0 / N[Cosh[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\sin y}{y}}{\frac{1}{\cosh x}}
\end{array}
Initial program 99.9%
*-commutative99.9%
associate-/r/99.9%
div-inv99.9%
associate-/r*99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= (cosh x) 1.01) (/ (sin y) (+ y (* -0.5 (* y (* x x))))) (cosh x)))
double code(double x, double y) {
double tmp;
if (cosh(x) <= 1.01) {
tmp = sin(y) / (y + (-0.5 * (y * (x * x))));
} else {
tmp = cosh(x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (cosh(x) <= 1.01d0) then
tmp = sin(y) / (y + ((-0.5d0) * (y * (x * x))))
else
tmp = cosh(x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (Math.cosh(x) <= 1.01) {
tmp = Math.sin(y) / (y + (-0.5 * (y * (x * x))));
} else {
tmp = Math.cosh(x);
}
return tmp;
}
def code(x, y): tmp = 0 if math.cosh(x) <= 1.01: tmp = math.sin(y) / (y + (-0.5 * (y * (x * x)))) else: tmp = math.cosh(x) return tmp
function code(x, y) tmp = 0.0 if (cosh(x) <= 1.01) tmp = Float64(sin(y) / Float64(y + Float64(-0.5 * Float64(y * Float64(x * x))))); else tmp = cosh(x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (cosh(x) <= 1.01) tmp = sin(y) / (y + (-0.5 * (y * (x * x)))); else tmp = cosh(x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[Cosh[x], $MachinePrecision], 1.01], N[(N[Sin[y], $MachinePrecision] / N[(y + N[(-0.5 * N[(y * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Cosh[x], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cosh x \leq 1.01:\\
\;\;\;\;\frac{\sin y}{y + -0.5 \cdot \left(y \cdot \left(x \cdot x\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\cosh x\\
\end{array}
\end{array}
if (cosh.f64 x) < 1.01000000000000001Initial program 99.8%
*-commutative99.8%
associate-/r/99.9%
Simplified99.9%
Taylor expanded in x around 0 99.4%
*-commutative99.4%
unpow299.4%
Simplified99.4%
if 1.01000000000000001 < (cosh.f64 x) Initial program 100.0%
Taylor expanded in y around 0 72.6%
Final simplification83.4%
(FPCore (x y) :precision binary64 (if (<= (cosh x) 1.01) (/ (sin y) y) (cosh x)))
double code(double x, double y) {
double tmp;
if (cosh(x) <= 1.01) {
tmp = sin(y) / y;
} else {
tmp = cosh(x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (cosh(x) <= 1.01d0) then
tmp = sin(y) / y
else
tmp = cosh(x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (Math.cosh(x) <= 1.01) {
tmp = Math.sin(y) / y;
} else {
tmp = Math.cosh(x);
}
return tmp;
}
def code(x, y): tmp = 0 if math.cosh(x) <= 1.01: tmp = math.sin(y) / y else: tmp = math.cosh(x) return tmp
function code(x, y) tmp = 0.0 if (cosh(x) <= 1.01) tmp = Float64(sin(y) / y); else tmp = cosh(x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (cosh(x) <= 1.01) tmp = sin(y) / y; else tmp = cosh(x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[Cosh[x], $MachinePrecision], 1.01], N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], N[Cosh[x], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cosh x \leq 1.01:\\
\;\;\;\;\frac{\sin y}{y}\\
\mathbf{else}:\\
\;\;\;\;\cosh x\\
\end{array}
\end{array}
if (cosh.f64 x) < 1.01000000000000001Initial program 99.8%
Taylor expanded in x around 0 98.3%
if 1.01000000000000001 < (cosh.f64 x) Initial program 100.0%
Taylor expanded in y around 0 72.6%
Final simplification83.0%
(FPCore (x y) :precision binary64 (* (/ (sin y) y) (cosh x)))
double code(double x, double y) {
return (sin(y) / y) * cosh(x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (sin(y) / y) * cosh(x)
end function
public static double code(double x, double y) {
return (Math.sin(y) / y) * Math.cosh(x);
}
def code(x, y): return (math.sin(y) / y) * math.cosh(x)
function code(x, y) return Float64(Float64(sin(y) / y) * cosh(x)) end
function tmp = code(x, y) tmp = (sin(y) / y) * cosh(x); end
code[x_, y_] := N[(N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision] * N[Cosh[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin y}{y} \cdot \cosh x
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (or (<= y 4.5e+184) (and (not (<= y 7.5e+238)) (<= y 1.5e+262))) (cosh x) (* -0.16666666666666666 (* y y))))
double code(double x, double y) {
double tmp;
if ((y <= 4.5e+184) || (!(y <= 7.5e+238) && (y <= 1.5e+262))) {
tmp = cosh(x);
} 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 <= 4.5d+184) .or. (.not. (y <= 7.5d+238)) .and. (y <= 1.5d+262)) then
tmp = cosh(x)
else
tmp = (-0.16666666666666666d0) * (y * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= 4.5e+184) || (!(y <= 7.5e+238) && (y <= 1.5e+262))) {
tmp = Math.cosh(x);
} else {
tmp = -0.16666666666666666 * (y * y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 4.5e+184) or (not (y <= 7.5e+238) and (y <= 1.5e+262)): tmp = math.cosh(x) else: tmp = -0.16666666666666666 * (y * y) return tmp
function code(x, y) tmp = 0.0 if ((y <= 4.5e+184) || (!(y <= 7.5e+238) && (y <= 1.5e+262))) tmp = cosh(x); else tmp = Float64(-0.16666666666666666 * Float64(y * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= 4.5e+184) || (~((y <= 7.5e+238)) && (y <= 1.5e+262))) tmp = cosh(x); else tmp = -0.16666666666666666 * (y * y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 4.5e+184], And[N[Not[LessEqual[y, 7.5e+238]], $MachinePrecision], LessEqual[y, 1.5e+262]]], N[Cosh[x], $MachinePrecision], N[(-0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.5 \cdot 10^{+184} \lor \neg \left(y \leq 7.5 \cdot 10^{+238}\right) \land y \leq 1.5 \cdot 10^{+262}:\\
\;\;\;\;\cosh x\\
\mathbf{else}:\\
\;\;\;\;-0.16666666666666666 \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if y < 4.50000000000000036e184 or 7.4999999999999996e238 < y < 1.5e262Initial program 99.9%
Taylor expanded in y around 0 69.2%
if 4.50000000000000036e184 < y < 7.4999999999999996e238 or 1.5e262 < y Initial program 99.9%
Taylor expanded in y around 0 40.7%
unpow240.7%
Simplified40.7%
Taylor expanded in x around 0 40.7%
+-commutative40.7%
unpow240.7%
fma-udef40.7%
Simplified40.7%
Taylor expanded in y around inf 40.7%
unpow240.7%
Simplified40.7%
Final simplification66.4%
(FPCore (x y) :precision binary64 (let* ((t_0 (* -0.16666666666666666 (* y y)))) (if (<= y 6.8e+118) (/ (+ (* t_0 t_0) -1.0) (+ t_0 -1.0)) t_0)))
double code(double x, double y) {
double t_0 = -0.16666666666666666 * (y * y);
double tmp;
if (y <= 6.8e+118) {
tmp = ((t_0 * t_0) + -1.0) / (t_0 + -1.0);
} 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 = (-0.16666666666666666d0) * (y * y)
if (y <= 6.8d+118) then
tmp = ((t_0 * t_0) + (-1.0d0)) / (t_0 + (-1.0d0))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = -0.16666666666666666 * (y * y);
double tmp;
if (y <= 6.8e+118) {
tmp = ((t_0 * t_0) + -1.0) / (t_0 + -1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = -0.16666666666666666 * (y * y) tmp = 0 if y <= 6.8e+118: tmp = ((t_0 * t_0) + -1.0) / (t_0 + -1.0) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(-0.16666666666666666 * Float64(y * y)) tmp = 0.0 if (y <= 6.8e+118) tmp = Float64(Float64(Float64(t_0 * t_0) + -1.0) / Float64(t_0 + -1.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = -0.16666666666666666 * (y * y); tmp = 0.0; if (y <= 6.8e+118) tmp = ((t_0 * t_0) + -1.0) / (t_0 + -1.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(-0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 6.8e+118], N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] + -1.0), $MachinePrecision] / N[(t$95$0 + -1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -0.16666666666666666 \cdot \left(y \cdot y\right)\\
\mathbf{if}\;y \leq 6.8 \cdot 10^{+118}:\\
\;\;\;\;\frac{t_0 \cdot t_0 + -1}{t_0 + -1}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < 6.79999999999999973e118Initial program 100.0%
Taylor expanded in y around 0 71.8%
unpow271.8%
Simplified71.8%
Taylor expanded in x around 0 31.8%
+-commutative31.8%
unpow231.8%
fma-udef31.8%
Simplified31.8%
fma-udef31.8%
flip-+28.2%
metadata-eval28.2%
Applied egg-rr28.2%
if 6.79999999999999973e118 < y Initial program 99.8%
Taylor expanded in y around 0 26.3%
unpow226.3%
Simplified26.3%
Taylor expanded in x around 0 26.3%
+-commutative26.3%
unpow226.3%
fma-udef26.3%
Simplified26.3%
Taylor expanded in y around inf 26.3%
unpow226.3%
Simplified26.3%
Final simplification27.9%
(FPCore (x y) :precision binary64 (if (<= y 1.98e+149) 1.0 (* -0.16666666666666666 (* y y))))
double code(double x, double y) {
double tmp;
if (y <= 1.98e+149) {
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.98d+149) 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.98e+149) {
tmp = 1.0;
} else {
tmp = -0.16666666666666666 * (y * y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.98e+149: tmp = 1.0 else: tmp = -0.16666666666666666 * (y * y) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.98e+149) 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.98e+149) tmp = 1.0; else tmp = -0.16666666666666666 * (y * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.98e+149], 1.0, N[(-0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.98 \cdot 10^{+149}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-0.16666666666666666 \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if y < 1.97999999999999995e149Initial program 99.9%
Taylor expanded in y around 0 68.9%
unpow268.9%
Simplified68.9%
Taylor expanded in x around 0 30.5%
+-commutative30.5%
unpow230.5%
fma-udef30.5%
Simplified30.5%
Taylor expanded in y around 0 25.2%
if 1.97999999999999995e149 < y Initial program 99.9%
Taylor expanded in y around 0 33.2%
unpow233.2%
Simplified33.2%
Taylor expanded in x around 0 33.2%
+-commutative33.2%
unpow233.2%
fma-udef33.2%
Simplified33.2%
Taylor expanded in y around inf 33.2%
unpow233.2%
Simplified33.2%
Final simplification26.2%
(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 99.9%
Taylor expanded in y around 0 64.1%
unpow264.1%
Simplified64.1%
Taylor expanded in x around 0 30.8%
+-commutative30.8%
unpow230.8%
fma-udef30.8%
Simplified30.8%
fma-udef30.8%
Applied egg-rr30.8%
Final simplification30.8%
(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 99.9%
Taylor expanded in y around 0 64.1%
unpow264.1%
Simplified64.1%
Taylor expanded in x around 0 30.8%
+-commutative30.8%
unpow230.8%
fma-udef30.8%
Simplified30.8%
Taylor expanded in y around 0 22.1%
Final simplification22.1%
(FPCore (x y) :precision binary64 (/ (* (cosh x) (sin y)) y))
double code(double x, double y) {
return (cosh(x) * sin(y)) / y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (cosh(x) * sin(y)) / y
end function
public static double code(double x, double y) {
return (Math.cosh(x) * Math.sin(y)) / y;
}
def code(x, y): return (math.cosh(x) * math.sin(y)) / y
function code(x, y) return Float64(Float64(cosh(x) * sin(y)) / y) end
function tmp = code(x, y) tmp = (cosh(x) * sin(y)) / y; end
code[x_, y_] := N[(N[(N[Cosh[x], $MachinePrecision] * N[Sin[y], $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]
\begin{array}{l}
\\
\frac{\cosh x \cdot \sin y}{y}
\end{array}
herbie shell --seed 2023291
(FPCore (x y)
:name "Linear.Quaternion:$csinh from linear-1.19.1.3"
:precision binary64
:herbie-target
(/ (* (cosh x) (sin y)) y)
(* (cosh x) (/ (sin y) y)))