
(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 8 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 (* (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}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= (cosh x) 1.000000000001) (/ (sin y) y) (cosh x)))
double code(double x, double y) {
double tmp;
if (cosh(x) <= 1.000000000001) {
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.000000000001d0) 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.000000000001) {
tmp = Math.sin(y) / y;
} else {
tmp = Math.cosh(x);
}
return tmp;
}
def code(x, y): tmp = 0 if math.cosh(x) <= 1.000000000001: tmp = math.sin(y) / y else: tmp = math.cosh(x) return tmp
function code(x, y) tmp = 0.0 if (cosh(x) <= 1.000000000001) 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.000000000001) tmp = sin(y) / y; else tmp = cosh(x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[Cosh[x], $MachinePrecision], 1.000000000001], N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], N[Cosh[x], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cosh x \leq 1.000000000001:\\
\;\;\;\;\frac{\sin y}{y}\\
\mathbf{else}:\\
\;\;\;\;\cosh x\\
\end{array}
\end{array}
if (cosh.f64 x) < 1.0000000000010001Initial program 99.8%
Taylor expanded in x around 0 99.6%
if 1.0000000000010001 < (cosh.f64 x) Initial program 100.0%
Taylor expanded in y around 0 76.2%
Final simplification87.4%
(FPCore (x y)
:precision binary64
(if (<= x 1.6e-6)
(/ (sin y) y)
(if (<= x 1e+58)
(cosh x)
(if (<= x 7.5e+147)
(* (cosh x) (+ 1.0 (* -0.16666666666666666 (* y y))))
(* (sin y) (* (* x x) (/ 0.5 y)))))))
double code(double x, double y) {
double tmp;
if (x <= 1.6e-6) {
tmp = sin(y) / y;
} else if (x <= 1e+58) {
tmp = cosh(x);
} else if (x <= 7.5e+147) {
tmp = cosh(x) * (1.0 + (-0.16666666666666666 * (y * y)));
} else {
tmp = sin(y) * ((x * x) * (0.5 / y));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 1.6d-6) then
tmp = sin(y) / y
else if (x <= 1d+58) then
tmp = cosh(x)
else if (x <= 7.5d+147) then
tmp = cosh(x) * (1.0d0 + ((-0.16666666666666666d0) * (y * y)))
else
tmp = sin(y) * ((x * x) * (0.5d0 / y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 1.6e-6) {
tmp = Math.sin(y) / y;
} else if (x <= 1e+58) {
tmp = Math.cosh(x);
} else if (x <= 7.5e+147) {
tmp = Math.cosh(x) * (1.0 + (-0.16666666666666666 * (y * y)));
} else {
tmp = Math.sin(y) * ((x * x) * (0.5 / y));
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1.6e-6: tmp = math.sin(y) / y elif x <= 1e+58: tmp = math.cosh(x) elif x <= 7.5e+147: tmp = math.cosh(x) * (1.0 + (-0.16666666666666666 * (y * y))) else: tmp = math.sin(y) * ((x * x) * (0.5 / y)) return tmp
function code(x, y) tmp = 0.0 if (x <= 1.6e-6) tmp = Float64(sin(y) / y); elseif (x <= 1e+58) tmp = cosh(x); elseif (x <= 7.5e+147) tmp = Float64(cosh(x) * Float64(1.0 + Float64(-0.16666666666666666 * Float64(y * y)))); else tmp = Float64(sin(y) * Float64(Float64(x * x) * Float64(0.5 / y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1.6e-6) tmp = sin(y) / y; elseif (x <= 1e+58) tmp = cosh(x); elseif (x <= 7.5e+147) tmp = cosh(x) * (1.0 + (-0.16666666666666666 * (y * y))); else tmp = sin(y) * ((x * x) * (0.5 / y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1.6e-6], N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], If[LessEqual[x, 1e+58], N[Cosh[x], $MachinePrecision], If[LessEqual[x, 7.5e+147], N[(N[Cosh[x], $MachinePrecision] * N[(1.0 + N[(-0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * N[(0.5 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.6 \cdot 10^{-6}:\\
\;\;\;\;\frac{\sin y}{y}\\
\mathbf{elif}\;x \leq 10^{+58}:\\
\;\;\;\;\cosh x\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{+147}:\\
\;\;\;\;\cosh x \cdot \left(1 + -0.16666666666666666 \cdot \left(y \cdot y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot \left(\left(x \cdot x\right) \cdot \frac{0.5}{y}\right)\\
\end{array}
\end{array}
if x < 1.5999999999999999e-6Initial program 99.9%
Taylor expanded in x around 0 62.1%
if 1.5999999999999999e-6 < x < 9.99999999999999944e57Initial program 100.0%
Taylor expanded in y around 0 87.3%
if 9.99999999999999944e57 < x < 7.50000000000000037e147Initial program 100.0%
Taylor expanded in y around 0 87.5%
unpow233.0%
Simplified87.5%
if 7.50000000000000037e147 < x Initial program 100.0%
clear-num100.0%
un-div-inv100.0%
Applied egg-rr100.0%
associate-/r/100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
unpow2100.0%
associate-*l/71.3%
*-commutative71.3%
associate-*l/100.0%
unpow2100.0%
*-lft-identity100.0%
associate-*l/100.0%
*-commutative100.0%
associate-*r*100.0%
unpow2100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification69.0%
(FPCore (x y)
:precision binary64
(if (<= x 9.6)
(/ (+ 1.0 (* 0.5 (* x x))) (/ y (sin y)))
(if (<= x 1.1e+64)
(cosh x)
(if (<= x 7.5e+147)
(* (cosh x) (+ 1.0 (* -0.16666666666666666 (* y y))))
(* (sin y) (* (* x x) (/ 0.5 y)))))))
double code(double x, double y) {
double tmp;
if (x <= 9.6) {
tmp = (1.0 + (0.5 * (x * x))) / (y / sin(y));
} else if (x <= 1.1e+64) {
tmp = cosh(x);
} else if (x <= 7.5e+147) {
tmp = cosh(x) * (1.0 + (-0.16666666666666666 * (y * y)));
} else {
tmp = sin(y) * ((x * x) * (0.5 / y));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 9.6d0) then
tmp = (1.0d0 + (0.5d0 * (x * x))) / (y / sin(y))
else if (x <= 1.1d+64) then
tmp = cosh(x)
else if (x <= 7.5d+147) then
tmp = cosh(x) * (1.0d0 + ((-0.16666666666666666d0) * (y * y)))
else
tmp = sin(y) * ((x * x) * (0.5d0 / y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 9.6) {
tmp = (1.0 + (0.5 * (x * x))) / (y / Math.sin(y));
} else if (x <= 1.1e+64) {
tmp = Math.cosh(x);
} else if (x <= 7.5e+147) {
tmp = Math.cosh(x) * (1.0 + (-0.16666666666666666 * (y * y)));
} else {
tmp = Math.sin(y) * ((x * x) * (0.5 / y));
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 9.6: tmp = (1.0 + (0.5 * (x * x))) / (y / math.sin(y)) elif x <= 1.1e+64: tmp = math.cosh(x) elif x <= 7.5e+147: tmp = math.cosh(x) * (1.0 + (-0.16666666666666666 * (y * y))) else: tmp = math.sin(y) * ((x * x) * (0.5 / y)) return tmp
function code(x, y) tmp = 0.0 if (x <= 9.6) tmp = Float64(Float64(1.0 + Float64(0.5 * Float64(x * x))) / Float64(y / sin(y))); elseif (x <= 1.1e+64) tmp = cosh(x); elseif (x <= 7.5e+147) tmp = Float64(cosh(x) * Float64(1.0 + Float64(-0.16666666666666666 * Float64(y * y)))); else tmp = Float64(sin(y) * Float64(Float64(x * x) * Float64(0.5 / y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 9.6) tmp = (1.0 + (0.5 * (x * x))) / (y / sin(y)); elseif (x <= 1.1e+64) tmp = cosh(x); elseif (x <= 7.5e+147) tmp = cosh(x) * (1.0 + (-0.16666666666666666 * (y * y))); else tmp = sin(y) * ((x * x) * (0.5 / y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 9.6], N[(N[(1.0 + N[(0.5 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(y / N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.1e+64], N[Cosh[x], $MachinePrecision], If[LessEqual[x, 7.5e+147], N[(N[Cosh[x], $MachinePrecision] * N[(1.0 + N[(-0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * N[(0.5 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 9.6:\\
\;\;\;\;\frac{1 + 0.5 \cdot \left(x \cdot x\right)}{\frac{y}{\sin y}}\\
\mathbf{elif}\;x \leq 1.1 \cdot 10^{+64}:\\
\;\;\;\;\cosh x\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{+147}:\\
\;\;\;\;\cosh x \cdot \left(1 + -0.16666666666666666 \cdot \left(y \cdot y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot \left(\left(x \cdot x\right) \cdot \frac{0.5}{y}\right)\\
\end{array}
\end{array}
if x < 9.59999999999999964Initial program 99.9%
clear-num99.8%
un-div-inv99.8%
Applied egg-rr99.8%
associate-/r/99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 85.8%
unpow285.8%
Simplified85.8%
Taylor expanded in y around inf 82.1%
associate-/l*82.1%
unpow282.1%
Simplified82.1%
if 9.59999999999999964 < x < 1.10000000000000001e64Initial program 100.0%
Taylor expanded in y around 0 86.4%
if 1.10000000000000001e64 < x < 7.50000000000000037e147Initial program 100.0%
Taylor expanded in y around 0 87.5%
unpow233.0%
Simplified87.5%
if 7.50000000000000037e147 < x Initial program 100.0%
clear-num100.0%
un-div-inv100.0%
Applied egg-rr100.0%
associate-/r/100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
unpow2100.0%
associate-*l/71.3%
*-commutative71.3%
associate-*l/100.0%
unpow2100.0%
*-lft-identity100.0%
associate-*l/100.0%
*-commutative100.0%
associate-*r*100.0%
unpow2100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification84.5%
(FPCore (x y) :precision binary64 (cosh x))
double code(double x, double y) {
return cosh(x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = cosh(x)
end function
public static double code(double x, double y) {
return Math.cosh(x);
}
def code(x, y): return math.cosh(x)
function code(x, y) return cosh(x) end
function tmp = code(x, y) tmp = cosh(x); end
code[x_, y_] := N[Cosh[x], $MachinePrecision]
\begin{array}{l}
\\
\cosh x
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 64.8%
Final simplification64.8%
(FPCore (x y) :precision binary64 (if (<= y 5.5e+239) (+ 1.0 (* 0.5 (* x x))) (+ 1.0 (* -0.16666666666666666 (* y y)))))
double code(double x, double y) {
double tmp;
if (y <= 5.5e+239) {
tmp = 1.0 + (0.5 * (x * x));
} 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 <= 5.5d+239) then
tmp = 1.0d0 + (0.5d0 * (x * x))
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 <= 5.5e+239) {
tmp = 1.0 + (0.5 * (x * x));
} else {
tmp = 1.0 + (-0.16666666666666666 * (y * y));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 5.5e+239: tmp = 1.0 + (0.5 * (x * x)) else: tmp = 1.0 + (-0.16666666666666666 * (y * y)) return tmp
function code(x, y) tmp = 0.0 if (y <= 5.5e+239) tmp = Float64(1.0 + Float64(0.5 * Float64(x * x))); 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 <= 5.5e+239) tmp = 1.0 + (0.5 * (x * x)); else tmp = 1.0 + (-0.16666666666666666 * (y * y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 5.5e+239], N[(1.0 + N[(0.5 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5.5 \cdot 10^{+239}:\\
\;\;\;\;1 + 0.5 \cdot \left(x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;1 + -0.16666666666666666 \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if y < 5.5000000000000004e239Initial program 99.9%
clear-num99.8%
un-div-inv99.8%
Applied egg-rr99.8%
associate-/r/99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 80.8%
unpow280.8%
Simplified80.8%
Taylor expanded in y around 0 49.9%
unpow249.9%
Simplified49.9%
if 5.5000000000000004e239 < y Initial program 99.7%
Taylor expanded in x around 0 39.6%
Taylor expanded in y around 0 39.5%
unpow239.5%
Simplified39.5%
Final simplification49.1%
(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 x around 0 49.2%
Taylor expanded in y around 0 32.9%
unpow232.9%
Simplified32.9%
Final simplification32.9%
(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 x around 0 49.2%
Taylor expanded in y around 0 26.5%
Final simplification26.5%
(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 2023229
(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)))