
(FPCore (x y z) :precision binary64 (/ (* (cosh x) (/ y x)) z))
double code(double x, double y, double z) {
return (cosh(x) * (y / x)) / z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (cosh(x) * (y / x)) / z
end function
public static double code(double x, double y, double z) {
return (Math.cosh(x) * (y / x)) / z;
}
def code(x, y, z): return (math.cosh(x) * (y / x)) / z
function code(x, y, z) return Float64(Float64(cosh(x) * Float64(y / x)) / z) end
function tmp = code(x, y, z) tmp = (cosh(x) * (y / x)) / z; end
code[x_, y_, z_] := N[(N[(N[Cosh[x], $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{\cosh x \cdot \frac{y}{x}}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 17 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* (cosh x) (/ y x)) z))
double code(double x, double y, double z) {
return (cosh(x) * (y / x)) / z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (cosh(x) * (y / x)) / z
end function
public static double code(double x, double y, double z) {
return (Math.cosh(x) * (y / x)) / z;
}
def code(x, y, z): return (math.cosh(x) * (y / x)) / z
function code(x, y, z) return Float64(Float64(cosh(x) * Float64(y / x)) / z) end
function tmp = code(x, y, z) tmp = (cosh(x) * (y / x)) / z; end
code[x_, y_, z_] := N[(N[(N[Cosh[x], $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{\cosh x \cdot \frac{y}{x}}{z}
\end{array}
z\_m = (fabs.f64 z)
z\_s = (copysign.f64 #s(literal 1 binary64) z)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s y_s z_s x_m y_m z_m)
:precision binary64
(*
x_s
(*
y_s
(*
z_s
(if (<= (/ (* (/ y_m x_m) (cosh x_m)) z_m) 5e+94)
(/ (cosh x_m) (* (/ x_m y_m) z_m))
(/ (* (/ (cosh x_m) z_m) y_m) x_m))))))z\_m = fabs(z);
z\_s = copysign(1.0, z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double y_s, double z_s, double x_m, double y_m, double z_m) {
double tmp;
if ((((y_m / x_m) * cosh(x_m)) / z_m) <= 5e+94) {
tmp = cosh(x_m) / ((x_m / y_m) * z_m);
} else {
tmp = ((cosh(x_m) / z_m) * y_m) / x_m;
}
return x_s * (y_s * (z_s * tmp));
}
z\_m = abs(z)
z\_s = copysign(1.0d0, z)
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, y_s, z_s, x_m, y_m, z_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: y_s
real(8), intent (in) :: z_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y_m
real(8), intent (in) :: z_m
real(8) :: tmp
if ((((y_m / x_m) * cosh(x_m)) / z_m) <= 5d+94) then
tmp = cosh(x_m) / ((x_m / y_m) * z_m)
else
tmp = ((cosh(x_m) / z_m) * y_m) / x_m
end if
code = x_s * (y_s * (z_s * tmp))
end function
z\_m = Math.abs(z);
z\_s = Math.copySign(1.0, z);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double y_s, double z_s, double x_m, double y_m, double z_m) {
double tmp;
if ((((y_m / x_m) * Math.cosh(x_m)) / z_m) <= 5e+94) {
tmp = Math.cosh(x_m) / ((x_m / y_m) * z_m);
} else {
tmp = ((Math.cosh(x_m) / z_m) * y_m) / x_m;
}
return x_s * (y_s * (z_s * tmp));
}
z\_m = math.fabs(z) z\_s = math.copysign(1.0, z) y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, y_s, z_s, x_m, y_m, z_m): tmp = 0 if (((y_m / x_m) * math.cosh(x_m)) / z_m) <= 5e+94: tmp = math.cosh(x_m) / ((x_m / y_m) * z_m) else: tmp = ((math.cosh(x_m) / z_m) * y_m) / x_m return x_s * (y_s * (z_s * tmp))
z\_m = abs(z) z\_s = copysign(1.0, z) y\_m = abs(y) y\_s = copysign(1.0, y) x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, y_s, z_s, x_m, y_m, z_m) tmp = 0.0 if (Float64(Float64(Float64(y_m / x_m) * cosh(x_m)) / z_m) <= 5e+94) tmp = Float64(cosh(x_m) / Float64(Float64(x_m / y_m) * z_m)); else tmp = Float64(Float64(Float64(cosh(x_m) / z_m) * y_m) / x_m); end return Float64(x_s * Float64(y_s * Float64(z_s * tmp))) end
z\_m = abs(z); z\_s = sign(z) * abs(1.0); y\_m = abs(y); y\_s = sign(y) * abs(1.0); x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, y_s, z_s, x_m, y_m, z_m) tmp = 0.0; if ((((y_m / x_m) * cosh(x_m)) / z_m) <= 5e+94) tmp = cosh(x_m) / ((x_m / y_m) * z_m); else tmp = ((cosh(x_m) / z_m) * y_m) / x_m; end tmp_2 = x_s * (y_s * (z_s * tmp)); end
z\_m = N[Abs[z], $MachinePrecision]
z\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, y$95$s_, z$95$s_, x$95$m_, y$95$m_, z$95$m_] := N[(x$95$s * N[(y$95$s * N[(z$95$s * If[LessEqual[N[(N[(N[(y$95$m / x$95$m), $MachinePrecision] * N[Cosh[x$95$m], $MachinePrecision]), $MachinePrecision] / z$95$m), $MachinePrecision], 5e+94], N[(N[Cosh[x$95$m], $MachinePrecision] / N[(N[(x$95$m / y$95$m), $MachinePrecision] * z$95$m), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Cosh[x$95$m], $MachinePrecision] / z$95$m), $MachinePrecision] * y$95$m), $MachinePrecision] / x$95$m), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z\_m = \left|z\right|
\\
z\_s = \mathsf{copysign}\left(1, z\right)
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \left(y\_s \cdot \left(z\_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{\frac{y\_m}{x\_m} \cdot \cosh x\_m}{z\_m} \leq 5 \cdot 10^{+94}:\\
\;\;\;\;\frac{\cosh x\_m}{\frac{x\_m}{y\_m} \cdot z\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\cosh x\_m}{z\_m} \cdot y\_m}{x\_m}\\
\end{array}\right)\right)
\end{array}
if (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z) < 5.0000000000000001e94Initial program 99.6%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
div-invN/A
lift-/.f64N/A
clear-numN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6499.7
Applied rewrites99.7%
if 5.0000000000000001e94 < (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z) Initial program 79.6%
lift-/.f64N/A
div-invN/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
associate-*l*N/A
div-invN/A
lower-*.f64N/A
lower-/.f6499.5
Applied rewrites99.5%
Final simplification99.5%
z\_m = (fabs.f64 z)
z\_s = (copysign.f64 #s(literal 1 binary64) z)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s y_s z_s x_m y_m z_m)
:precision binary64
(*
x_s
(*
y_s
(*
z_s
(if (<= (/ (* (/ y_m x_m) (cosh x_m)) z_m) 4e-51)
(*
(/
y_m
(/
-1.0
(fma
(*
(fma
(* x_m x_m)
(fma (* x_m x_m) 0.001388888888888889 0.041666666666666664)
0.5)
x_m)
x_m
1.0)))
(/ (/ -1.0 x_m) z_m))
(/
(/
y_m
(/
z_m
(fma
(fma
(* (fma (* 0.001388888888888889 x_m) x_m 0.041666666666666664) x_m)
x_m
0.5)
(* x_m x_m)
1.0)))
x_m))))))z\_m = fabs(z);
z\_s = copysign(1.0, z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double y_s, double z_s, double x_m, double y_m, double z_m) {
double tmp;
if ((((y_m / x_m) * cosh(x_m)) / z_m) <= 4e-51) {
tmp = (y_m / (-1.0 / fma((fma((x_m * x_m), fma((x_m * x_m), 0.001388888888888889, 0.041666666666666664), 0.5) * x_m), x_m, 1.0))) * ((-1.0 / x_m) / z_m);
} else {
tmp = (y_m / (z_m / fma(fma((fma((0.001388888888888889 * x_m), x_m, 0.041666666666666664) * x_m), x_m, 0.5), (x_m * x_m), 1.0))) / x_m;
}
return x_s * (y_s * (z_s * tmp));
}
z\_m = abs(z) z\_s = copysign(1.0, z) y\_m = abs(y) y\_s = copysign(1.0, y) x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, y_s, z_s, x_m, y_m, z_m) tmp = 0.0 if (Float64(Float64(Float64(y_m / x_m) * cosh(x_m)) / z_m) <= 4e-51) tmp = Float64(Float64(y_m / Float64(-1.0 / fma(Float64(fma(Float64(x_m * x_m), fma(Float64(x_m * x_m), 0.001388888888888889, 0.041666666666666664), 0.5) * x_m), x_m, 1.0))) * Float64(Float64(-1.0 / x_m) / z_m)); else tmp = Float64(Float64(y_m / Float64(z_m / fma(fma(Float64(fma(Float64(0.001388888888888889 * x_m), x_m, 0.041666666666666664) * x_m), x_m, 0.5), Float64(x_m * x_m), 1.0))) / x_m); end return Float64(x_s * Float64(y_s * Float64(z_s * tmp))) end
z\_m = N[Abs[z], $MachinePrecision]
z\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, y$95$s_, z$95$s_, x$95$m_, y$95$m_, z$95$m_] := N[(x$95$s * N[(y$95$s * N[(z$95$s * If[LessEqual[N[(N[(N[(y$95$m / x$95$m), $MachinePrecision] * N[Cosh[x$95$m], $MachinePrecision]), $MachinePrecision] / z$95$m), $MachinePrecision], 4e-51], N[(N[(y$95$m / N[(-1.0 / N[(N[(N[(N[(x$95$m * x$95$m), $MachinePrecision] * N[(N[(x$95$m * x$95$m), $MachinePrecision] * 0.001388888888888889 + 0.041666666666666664), $MachinePrecision] + 0.5), $MachinePrecision] * x$95$m), $MachinePrecision] * x$95$m + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(-1.0 / x$95$m), $MachinePrecision] / z$95$m), $MachinePrecision]), $MachinePrecision], N[(N[(y$95$m / N[(z$95$m / N[(N[(N[(N[(N[(0.001388888888888889 * x$95$m), $MachinePrecision] * x$95$m + 0.041666666666666664), $MachinePrecision] * x$95$m), $MachinePrecision] * x$95$m + 0.5), $MachinePrecision] * N[(x$95$m * x$95$m), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x$95$m), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z\_m = \left|z\right|
\\
z\_s = \mathsf{copysign}\left(1, z\right)
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \left(y\_s \cdot \left(z\_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{\frac{y\_m}{x\_m} \cdot \cosh x\_m}{z\_m} \leq 4 \cdot 10^{-51}:\\
\;\;\;\;\frac{y\_m}{\frac{-1}{\mathsf{fma}\left(\mathsf{fma}\left(x\_m \cdot x\_m, \mathsf{fma}\left(x\_m \cdot x\_m, 0.001388888888888889, 0.041666666666666664\right), 0.5\right) \cdot x\_m, x\_m, 1\right)}} \cdot \frac{\frac{-1}{x\_m}}{z\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{y\_m}{\frac{z\_m}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889 \cdot x\_m, x\_m, 0.041666666666666664\right) \cdot x\_m, x\_m, 0.5\right), x\_m \cdot x\_m, 1\right)}}}{x\_m}\\
\end{array}\right)\right)
\end{array}
if (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z) < 4e-51Initial program 99.6%
lift-/.f64N/A
div-invN/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
associate-*l*N/A
div-invN/A
lower-*.f64N/A
lower-/.f6471.7
Applied rewrites71.7%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6470.7
Applied rewrites70.7%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6470.7
Applied rewrites70.7%
Applied rewrites98.5%
if 4e-51 < (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z) Initial program 82.1%
lift-/.f64N/A
div-invN/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
associate-*l*N/A
div-invN/A
lower-*.f64N/A
lower-/.f6499.8
Applied rewrites99.8%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6493.7
Applied rewrites93.7%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6493.6
Applied rewrites93.6%
Final simplification94.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (/ (/ y z) x) (cosh x))))
(if (< y -4.618902267687042e-52)
t_0
(if (< y 1.038530535935153e-39) (/ (/ (* (cosh x) y) x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = ((y / z) / x) * cosh(x);
double tmp;
if (y < -4.618902267687042e-52) {
tmp = t_0;
} else if (y < 1.038530535935153e-39) {
tmp = ((cosh(x) * y) / x) / z;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = ((y / z) / x) * cosh(x)
if (y < (-4.618902267687042d-52)) then
tmp = t_0
else if (y < 1.038530535935153d-39) then
tmp = ((cosh(x) * y) / x) / z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = ((y / z) / x) * Math.cosh(x);
double tmp;
if (y < -4.618902267687042e-52) {
tmp = t_0;
} else if (y < 1.038530535935153e-39) {
tmp = ((Math.cosh(x) * y) / x) / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = ((y / z) / x) * math.cosh(x) tmp = 0 if y < -4.618902267687042e-52: tmp = t_0 elif y < 1.038530535935153e-39: tmp = ((math.cosh(x) * y) / x) / z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(Float64(y / z) / x) * cosh(x)) tmp = 0.0 if (y < -4.618902267687042e-52) tmp = t_0; elseif (y < 1.038530535935153e-39) tmp = Float64(Float64(Float64(cosh(x) * y) / x) / z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = ((y / z) / x) * cosh(x); tmp = 0.0; if (y < -4.618902267687042e-52) tmp = t_0; elseif (y < 1.038530535935153e-39) tmp = ((cosh(x) * y) / x) / z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[(y / z), $MachinePrecision] / x), $MachinePrecision] * N[Cosh[x], $MachinePrecision]), $MachinePrecision]}, If[Less[y, -4.618902267687042e-52], t$95$0, If[Less[y, 1.038530535935153e-39], N[(N[(N[(N[Cosh[x], $MachinePrecision] * y), $MachinePrecision] / x), $MachinePrecision] / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\frac{y}{z}}{x} \cdot \cosh x\\
\mathbf{if}\;y < -4.618902267687042 \cdot 10^{-52}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y < 1.038530535935153 \cdot 10^{-39}:\\
\;\;\;\;\frac{\frac{\cosh x \cdot y}{x}}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
herbie shell --seed 2024230
(FPCore (x y z)
:name "Linear.Quaternion:$ctan from linear-1.19.1.3"
:precision binary64
:alt
(! :herbie-platform default (if (< y -2309451133843521/5000000000000000000000000000000000000000000000000000000000000000000) (* (/ (/ y z) x) (cosh x)) (if (< y 1038530535935153/1000000000000000000000000000000000000000000000000000000) (/ (/ (* (cosh x) y) x) z) (* (/ (/ y z) x) (cosh x)))))
(/ (* (cosh x) (/ y x)) z))