
(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 (* (/ (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
(let* ((t_0 (* (sin y) (+ (/ 1.0 y) (/ (* 0.5 (* x x)) y)))))
(if (<= x 7000000.0)
t_0
(if (<= x 4.2e+55)
(* (+ 1.0 (* -0.16666666666666666 (* y y))) (cosh x))
(if (<= x 1.8e+147) (cosh x) t_0)))))
double code(double x, double y) {
double t_0 = sin(y) * ((1.0 / y) + ((0.5 * (x * x)) / y));
double tmp;
if (x <= 7000000.0) {
tmp = t_0;
} else if (x <= 4.2e+55) {
tmp = (1.0 + (-0.16666666666666666 * (y * y))) * cosh(x);
} else if (x <= 1.8e+147) {
tmp = cosh(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 = sin(y) * ((1.0d0 / y) + ((0.5d0 * (x * x)) / y))
if (x <= 7000000.0d0) then
tmp = t_0
else if (x <= 4.2d+55) then
tmp = (1.0d0 + ((-0.16666666666666666d0) * (y * y))) * cosh(x)
else if (x <= 1.8d+147) then
tmp = cosh(x)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = Math.sin(y) * ((1.0 / y) + ((0.5 * (x * x)) / y));
double tmp;
if (x <= 7000000.0) {
tmp = t_0;
} else if (x <= 4.2e+55) {
tmp = (1.0 + (-0.16666666666666666 * (y * y))) * Math.cosh(x);
} else if (x <= 1.8e+147) {
tmp = Math.cosh(x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = math.sin(y) * ((1.0 / y) + ((0.5 * (x * x)) / y)) tmp = 0 if x <= 7000000.0: tmp = t_0 elif x <= 4.2e+55: tmp = (1.0 + (-0.16666666666666666 * (y * y))) * math.cosh(x) elif x <= 1.8e+147: tmp = math.cosh(x) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(sin(y) * Float64(Float64(1.0 / y) + Float64(Float64(0.5 * Float64(x * x)) / y))) tmp = 0.0 if (x <= 7000000.0) tmp = t_0; elseif (x <= 4.2e+55) tmp = Float64(Float64(1.0 + Float64(-0.16666666666666666 * Float64(y * y))) * cosh(x)); elseif (x <= 1.8e+147) tmp = cosh(x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = sin(y) * ((1.0 / y) + ((0.5 * (x * x)) / y)); tmp = 0.0; if (x <= 7000000.0) tmp = t_0; elseif (x <= 4.2e+55) tmp = (1.0 + (-0.16666666666666666 * (y * y))) * cosh(x); elseif (x <= 1.8e+147) tmp = cosh(x); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * N[(N[(1.0 / y), $MachinePrecision] + N[(N[(0.5 * N[(x * x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 7000000.0], t$95$0, If[LessEqual[x, 4.2e+55], N[(N[(1.0 + N[(-0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cosh[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.8e+147], N[Cosh[x], $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot \left(\frac{1}{y} + \frac{0.5 \cdot \left(x \cdot x\right)}{y}\right)\\
\mathbf{if}\;x \leq 7000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{+55}:\\
\;\;\;\;\left(1 + -0.16666666666666666 \cdot \left(y \cdot y\right)\right) \cdot \cosh x\\
\mathbf{elif}\;x \leq 1.8 \cdot 10^{+147}:\\
\;\;\;\;\cosh x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < 7e6 or 1.8000000000000001e147 < x Initial program 99.9%
add-log-exp77.9%
*-un-lft-identity77.9%
log-prod77.9%
metadata-eval77.9%
add-log-exp99.9%
*-commutative99.9%
associate-*l/99.9%
Applied egg-rr99.9%
+-lft-identity99.9%
*-commutative99.9%
associate-*l/99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in x around 0 90.6%
associate-*r/90.6%
unpow290.6%
Simplified90.6%
if 7e6 < x < 4.2000000000000001e55Initial program 100.0%
Taylor expanded in y around 0 93.3%
unpow293.3%
Simplified93.3%
if 4.2000000000000001e55 < x < 1.8000000000000001e147Initial program 100.0%
Taylor expanded in y around 0 76.2%
Final simplification89.6%
(FPCore (x y)
:precision binary64
(if (<= x 1.15e-5)
(/ (sin y) y)
(if (<= x 2e+52)
(* (+ 1.0 (* -0.16666666666666666 (* y y))) (cosh x))
(cosh x))))
double code(double x, double y) {
double tmp;
if (x <= 1.15e-5) {
tmp = sin(y) / y;
} else if (x <= 2e+52) {
tmp = (1.0 + (-0.16666666666666666 * (y * y))) * cosh(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 (x <= 1.15d-5) then
tmp = sin(y) / y
else if (x <= 2d+52) then
tmp = (1.0d0 + ((-0.16666666666666666d0) * (y * y))) * cosh(x)
else
tmp = cosh(x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 1.15e-5) {
tmp = Math.sin(y) / y;
} else if (x <= 2e+52) {
tmp = (1.0 + (-0.16666666666666666 * (y * y))) * Math.cosh(x);
} else {
tmp = Math.cosh(x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1.15e-5: tmp = math.sin(y) / y elif x <= 2e+52: tmp = (1.0 + (-0.16666666666666666 * (y * y))) * math.cosh(x) else: tmp = math.cosh(x) return tmp
function code(x, y) tmp = 0.0 if (x <= 1.15e-5) tmp = Float64(sin(y) / y); elseif (x <= 2e+52) tmp = Float64(Float64(1.0 + Float64(-0.16666666666666666 * Float64(y * y))) * cosh(x)); else tmp = cosh(x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1.15e-5) tmp = sin(y) / y; elseif (x <= 2e+52) tmp = (1.0 + (-0.16666666666666666 * (y * y))) * cosh(x); else tmp = cosh(x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1.15e-5], N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], If[LessEqual[x, 2e+52], N[(N[(1.0 + N[(-0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cosh[x], $MachinePrecision]), $MachinePrecision], N[Cosh[x], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.15 \cdot 10^{-5}:\\
\;\;\;\;\frac{\sin y}{y}\\
\mathbf{elif}\;x \leq 2 \cdot 10^{+52}:\\
\;\;\;\;\left(1 + -0.16666666666666666 \cdot \left(y \cdot y\right)\right) \cdot \cosh x\\
\mathbf{else}:\\
\;\;\;\;\cosh x\\
\end{array}
\end{array}
if x < 1.15e-5Initial program 99.9%
Taylor expanded in x around 0 69.0%
if 1.15e-5 < x < 2e52Initial program 100.0%
Taylor expanded in y around 0 93.3%
unpow293.3%
Simplified93.3%
if 2e52 < x Initial program 100.0%
Taylor expanded in y around 0 79.2%
Final simplification72.5%
(FPCore (x y) :precision binary64 (if (<= x 1.15e-5) (/ (sin y) y) (cosh x)))
double code(double x, double y) {
double tmp;
if (x <= 1.15e-5) {
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 (x <= 1.15d-5) 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 (x <= 1.15e-5) {
tmp = Math.sin(y) / y;
} else {
tmp = Math.cosh(x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1.15e-5: tmp = math.sin(y) / y else: tmp = math.cosh(x) return tmp
function code(x, y) tmp = 0.0 if (x <= 1.15e-5) tmp = Float64(sin(y) / y); else tmp = cosh(x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1.15e-5) tmp = sin(y) / y; else tmp = cosh(x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1.15e-5], N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], N[Cosh[x], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.15 \cdot 10^{-5}:\\
\;\;\;\;\frac{\sin y}{y}\\
\mathbf{else}:\\
\;\;\;\;\cosh x\\
\end{array}
\end{array}
if x < 1.15e-5Initial program 99.9%
Taylor expanded in x around 0 69.0%
if 1.15e-5 < x Initial program 100.0%
Taylor expanded in y around 0 76.5%
Final simplification71.0%
(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 68.9%
Final simplification68.9%
(FPCore (x y) :precision binary64 (if (<= x 7.2e+140) (+ 1.0 (* -0.16666666666666666 (* y y))) (+ 1.0 (* 0.5 (* x x)))))
double code(double x, double y) {
double tmp;
if (x <= 7.2e+140) {
tmp = 1.0 + (-0.16666666666666666 * (y * y));
} else {
tmp = 1.0 + (0.5 * (x * x));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 7.2d+140) then
tmp = 1.0d0 + ((-0.16666666666666666d0) * (y * y))
else
tmp = 1.0d0 + (0.5d0 * (x * x))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 7.2e+140) {
tmp = 1.0 + (-0.16666666666666666 * (y * y));
} else {
tmp = 1.0 + (0.5 * (x * x));
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 7.2e+140: tmp = 1.0 + (-0.16666666666666666 * (y * y)) else: tmp = 1.0 + (0.5 * (x * x)) return tmp
function code(x, y) tmp = 0.0 if (x <= 7.2e+140) tmp = Float64(1.0 + Float64(-0.16666666666666666 * Float64(y * y))); else tmp = Float64(1.0 + Float64(0.5 * Float64(x * x))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 7.2e+140) tmp = 1.0 + (-0.16666666666666666 * (y * y)); else tmp = 1.0 + (0.5 * (x * x)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 7.2e+140], N[(1.0 + N[(-0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(0.5 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 7.2 \cdot 10^{+140}:\\
\;\;\;\;1 + -0.16666666666666666 \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;1 + 0.5 \cdot \left(x \cdot x\right)\\
\end{array}
\end{array}
if x < 7.1999999999999999e140Initial program 99.9%
associate-*r/99.9%
add-sqr-sqrt53.6%
associate-/r*53.5%
*-commutative53.5%
Applied egg-rr53.5%
Taylor expanded in x around 0 31.8%
Taylor expanded in y around 0 40.6%
*-commutative40.6%
unpow240.6%
Simplified40.6%
if 7.1999999999999999e140 < x Initial program 100.0%
add-log-exp100.0%
*-un-lft-identity100.0%
log-prod100.0%
metadata-eval100.0%
add-log-exp100.0%
*-commutative100.0%
associate-*l/100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
*-commutative100.0%
associate-*l/100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 91.9%
associate-*r/91.9%
unpow291.9%
Simplified91.9%
Taylor expanded in y around 0 72.2%
unpow272.2%
Simplified72.2%
Final simplification44.9%
(FPCore (x y) :precision binary64 (+ 1.0 (* 0.5 (* x x))))
double code(double x, double y) {
return 1.0 + (0.5 * (x * x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 + (0.5d0 * (x * x))
end function
public static double code(double x, double y) {
return 1.0 + (0.5 * (x * x));
}
def code(x, y): return 1.0 + (0.5 * (x * x))
function code(x, y) return Float64(1.0 + Float64(0.5 * Float64(x * x))) end
function tmp = code(x, y) tmp = 1.0 + (0.5 * (x * x)); end
code[x_, y_] := N[(1.0 + N[(0.5 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + 0.5 \cdot \left(x \cdot x\right)
\end{array}
Initial program 99.9%
add-log-exp81.0%
*-un-lft-identity81.0%
log-prod81.0%
metadata-eval81.0%
add-log-exp99.9%
*-commutative99.9%
associate-*l/99.9%
Applied egg-rr99.9%
+-lft-identity99.9%
*-commutative99.9%
associate-*l/99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in x around 0 79.9%
associate-*r/79.9%
unpow279.9%
Simplified79.9%
Taylor expanded in y around 0 50.4%
unpow250.4%
Simplified50.4%
Final simplification50.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 99.9%
associate-*r/99.9%
add-sqr-sqrt53.3%
associate-/r*53.2%
*-commutative53.2%
Applied egg-rr53.2%
Taylor expanded in x around 0 27.7%
Taylor expanded in y around 0 31.4%
Final simplification31.4%
(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 2023242
(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)))