
(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%
(FPCore (x y) :precision binary64 (if (<= (cosh x) 1.02) (/ 1.0 (/ y (sin y))) (cosh x)))
double code(double x, double y) {
double tmp;
if (cosh(x) <= 1.02) {
tmp = 1.0 / (y / sin(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.02d0) then
tmp = 1.0d0 / (y / sin(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.02) {
tmp = 1.0 / (y / Math.sin(y));
} else {
tmp = Math.cosh(x);
}
return tmp;
}
def code(x, y): tmp = 0 if math.cosh(x) <= 1.02: tmp = 1.0 / (y / math.sin(y)) else: tmp = math.cosh(x) return tmp
function code(x, y) tmp = 0.0 if (cosh(x) <= 1.02) tmp = Float64(1.0 / Float64(y / sin(y))); else tmp = cosh(x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (cosh(x) <= 1.02) tmp = 1.0 / (y / sin(y)); else tmp = cosh(x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[Cosh[x], $MachinePrecision], 1.02], N[(1.0 / N[(y / N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Cosh[x], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cosh x \leq 1.02:\\
\;\;\;\;\frac{1}{\frac{y}{\sin y}}\\
\mathbf{else}:\\
\;\;\;\;\cosh x\\
\end{array}
\end{array}
if (cosh.f64 x) < 1.02Initial program 99.8%
*-commutative99.8%
associate-*l/99.8%
associate-/l*99.5%
Simplified99.5%
Taylor expanded in x around 0 98.9%
div-inv99.2%
clear-num99.2%
Applied egg-rr99.2%
if 1.02 < (cosh.f64 x) Initial program 100.0%
associate-*r/100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 71.0%
associate-/l*71.0%
*-inverses71.0%
Applied egg-rr71.0%
*-rgt-identity71.0%
Simplified71.0%
(FPCore (x y) :precision binary64 (if (<= (cosh x) 1.02) (/ (sin y) y) (cosh x)))
double code(double x, double y) {
double tmp;
if (cosh(x) <= 1.02) {
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.02d0) 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.02) {
tmp = Math.sin(y) / y;
} else {
tmp = Math.cosh(x);
}
return tmp;
}
def code(x, y): tmp = 0 if math.cosh(x) <= 1.02: tmp = math.sin(y) / y else: tmp = math.cosh(x) return tmp
function code(x, y) tmp = 0.0 if (cosh(x) <= 1.02) 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.02) tmp = sin(y) / y; else tmp = cosh(x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[Cosh[x], $MachinePrecision], 1.02], N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], N[Cosh[x], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cosh x \leq 1.02:\\
\;\;\;\;\frac{\sin y}{y}\\
\mathbf{else}:\\
\;\;\;\;\cosh x\\
\end{array}
\end{array}
if (cosh.f64 x) < 1.02Initial program 99.8%
Taylor expanded in x around 0 99.2%
if 1.02 < (cosh.f64 x) Initial program 100.0%
associate-*r/100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 71.0%
associate-/l*71.0%
*-inverses71.0%
Applied egg-rr71.0%
*-rgt-identity71.0%
Simplified71.0%
(FPCore (x y) :precision binary64 (if (<= y 5e+230) (cosh x) (+ 1.0 (* (* y y) -0.16666666666666666))))
double code(double x, double y) {
double tmp;
if (y <= 5e+230) {
tmp = cosh(x);
} else {
tmp = 1.0 + ((y * y) * -0.16666666666666666);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 5d+230) then
tmp = cosh(x)
else
tmp = 1.0d0 + ((y * y) * (-0.16666666666666666d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 5e+230) {
tmp = Math.cosh(x);
} else {
tmp = 1.0 + ((y * y) * -0.16666666666666666);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 5e+230: tmp = math.cosh(x) else: tmp = 1.0 + ((y * y) * -0.16666666666666666) return tmp
function code(x, y) tmp = 0.0 if (y <= 5e+230) tmp = cosh(x); else tmp = Float64(1.0 + Float64(Float64(y * y) * -0.16666666666666666)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 5e+230) tmp = cosh(x); else tmp = 1.0 + ((y * y) * -0.16666666666666666); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 5e+230], N[Cosh[x], $MachinePrecision], N[(1.0 + N[(N[(y * y), $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5 \cdot 10^{+230}:\\
\;\;\;\;\cosh x\\
\mathbf{else}:\\
\;\;\;\;1 + \left(y \cdot y\right) \cdot -0.16666666666666666\\
\end{array}
\end{array}
if y < 5.0000000000000003e230Initial program 99.9%
associate-*r/99.9%
Applied egg-rr99.9%
Taylor expanded in y around 0 66.8%
associate-/l*66.8%
*-inverses66.8%
Applied egg-rr66.8%
*-rgt-identity66.8%
Simplified66.8%
if 5.0000000000000003e230 < y Initial program 99.8%
*-commutative99.8%
associate-*l/99.8%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around 0 57.6%
Taylor expanded in y around 0 29.5%
*-commutative29.5%
Simplified29.5%
unpow229.5%
Applied egg-rr29.5%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ 1.0 (* y (- (* y (+ 0.3333333333333333 (* y -0.25))) 0.5)))))
(if (<= x 8.2e+89)
t_0
(if (<= x 3.2e+121)
(/ (* y (+ 1.0 (* y (- (* y 0.3333333333333333) 0.5)))) y)
(/ (* y t_0) y)))))
double code(double x, double y) {
double t_0 = 1.0 + (y * ((y * (0.3333333333333333 + (y * -0.25))) - 0.5));
double tmp;
if (x <= 8.2e+89) {
tmp = t_0;
} else if (x <= 3.2e+121) {
tmp = (y * (1.0 + (y * ((y * 0.3333333333333333) - 0.5)))) / y;
} else {
tmp = (y * t_0) / y;
}
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 = 1.0d0 + (y * ((y * (0.3333333333333333d0 + (y * (-0.25d0)))) - 0.5d0))
if (x <= 8.2d+89) then
tmp = t_0
else if (x <= 3.2d+121) then
tmp = (y * (1.0d0 + (y * ((y * 0.3333333333333333d0) - 0.5d0)))) / y
else
tmp = (y * t_0) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 + (y * ((y * (0.3333333333333333 + (y * -0.25))) - 0.5));
double tmp;
if (x <= 8.2e+89) {
tmp = t_0;
} else if (x <= 3.2e+121) {
tmp = (y * (1.0 + (y * ((y * 0.3333333333333333) - 0.5)))) / y;
} else {
tmp = (y * t_0) / y;
}
return tmp;
}
def code(x, y): t_0 = 1.0 + (y * ((y * (0.3333333333333333 + (y * -0.25))) - 0.5)) tmp = 0 if x <= 8.2e+89: tmp = t_0 elif x <= 3.2e+121: tmp = (y * (1.0 + (y * ((y * 0.3333333333333333) - 0.5)))) / y else: tmp = (y * t_0) / y return tmp
function code(x, y) t_0 = Float64(1.0 + Float64(y * Float64(Float64(y * Float64(0.3333333333333333 + Float64(y * -0.25))) - 0.5))) tmp = 0.0 if (x <= 8.2e+89) tmp = t_0; elseif (x <= 3.2e+121) tmp = Float64(Float64(y * Float64(1.0 + Float64(y * Float64(Float64(y * 0.3333333333333333) - 0.5)))) / y); else tmp = Float64(Float64(y * t_0) / y); end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 + (y * ((y * (0.3333333333333333 + (y * -0.25))) - 0.5)); tmp = 0.0; if (x <= 8.2e+89) tmp = t_0; elseif (x <= 3.2e+121) tmp = (y * (1.0 + (y * ((y * 0.3333333333333333) - 0.5)))) / y; else tmp = (y * t_0) / y; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(y * N[(N[(y * N[(0.3333333333333333 + N[(y * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 8.2e+89], t$95$0, If[LessEqual[x, 3.2e+121], N[(N[(y * N[(1.0 + N[(y * N[(N[(y * 0.3333333333333333), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], N[(N[(y * t$95$0), $MachinePrecision] / y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + y \cdot \left(y \cdot \left(0.3333333333333333 + y \cdot -0.25\right) - 0.5\right)\\
\mathbf{if}\;x \leq 8.2 \cdot 10^{+89}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{+121}:\\
\;\;\;\;\frac{y \cdot \left(1 + y \cdot \left(y \cdot 0.3333333333333333 - 0.5\right)\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot t\_0}{y}\\
\end{array}
\end{array}
if x < 8.1999999999999997e89Initial program 99.9%
Taylor expanded in x around 0 64.7%
add-log-exp31.9%
Applied egg-rr31.9%
Taylor expanded in y around 0 3.6%
Taylor expanded in y around 0 42.3%
if 8.1999999999999997e89 < x < 3.1999999999999999e121Initial program 100.0%
Taylor expanded in x around 0 2.3%
add-log-exp1.8%
Applied egg-rr1.8%
Taylor expanded in y around 0 1.3%
Taylor expanded in y around 0 59.4%
if 3.1999999999999999e121 < x Initial program 100.0%
Taylor expanded in x around 0 2.7%
add-log-exp2.1%
Applied egg-rr2.1%
Taylor expanded in y around 0 1.2%
Taylor expanded in y around 0 30.5%
Final simplification41.3%
(FPCore (x y) :precision binary64 (+ 1.0 (* y (- (* y (+ 0.3333333333333333 (* y -0.25))) 0.5))))
double code(double x, double y) {
return 1.0 + (y * ((y * (0.3333333333333333 + (y * -0.25))) - 0.5));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 + (y * ((y * (0.3333333333333333d0 + (y * (-0.25d0)))) - 0.5d0))
end function
public static double code(double x, double y) {
return 1.0 + (y * ((y * (0.3333333333333333 + (y * -0.25))) - 0.5));
}
def code(x, y): return 1.0 + (y * ((y * (0.3333333333333333 + (y * -0.25))) - 0.5))
function code(x, y) return Float64(1.0 + Float64(y * Float64(Float64(y * Float64(0.3333333333333333 + Float64(y * -0.25))) - 0.5))) end
function tmp = code(x, y) tmp = 1.0 + (y * ((y * (0.3333333333333333 + (y * -0.25))) - 0.5)); end
code[x_, y_] := N[(1.0 + N[(y * N[(N[(y * N[(0.3333333333333333 + N[(y * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + y \cdot \left(y \cdot \left(0.3333333333333333 + y \cdot -0.25\right) - 0.5\right)
\end{array}
Initial program 99.9%
Taylor expanded in x around 0 52.6%
add-log-exp26.0%
Applied egg-rr26.0%
Taylor expanded in y around 0 3.2%
Taylor expanded in y around 0 39.8%
Final simplification39.8%
(FPCore (x y) :precision binary64 (+ 1.0 (* (* y y) -0.16666666666666666)))
double code(double x, double y) {
return 1.0 + ((y * y) * -0.16666666666666666);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 + ((y * y) * (-0.16666666666666666d0))
end function
public static double code(double x, double y) {
return 1.0 + ((y * y) * -0.16666666666666666);
}
def code(x, y): return 1.0 + ((y * y) * -0.16666666666666666)
function code(x, y) return Float64(1.0 + Float64(Float64(y * y) * -0.16666666666666666)) end
function tmp = code(x, y) tmp = 1.0 + ((y * y) * -0.16666666666666666); end
code[x_, y_] := N[(1.0 + N[(N[(y * y), $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \left(y \cdot y\right) \cdot -0.16666666666666666
\end{array}
Initial program 99.9%
*-commutative99.9%
associate-*l/99.9%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around 0 52.4%
Taylor expanded in y around 0 37.3%
*-commutative37.3%
Simplified37.3%
unpow237.3%
Applied egg-rr37.3%
(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%
*-commutative99.9%
associate-*l/99.9%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around 0 52.4%
Taylor expanded in y around 0 29.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 2024182
(FPCore (x y)
:name "Linear.Quaternion:$csinh from linear-1.19.1.3"
:precision binary64
:alt
(! :herbie-platform default (/ (* (cosh x) (sin y)) y))
(* (cosh x) (/ (sin y) y)))