
(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 7 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}
(FPCore (x y z) :precision binary64 (/ (/ (* y (cosh x)) x) z))
double code(double x, double y, double z) {
return ((y * cosh(x)) / 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 = ((y * cosh(x)) / x) / z
end function
public static double code(double x, double y, double z) {
return ((y * Math.cosh(x)) / x) / z;
}
def code(x, y, z): return ((y * math.cosh(x)) / x) / z
function code(x, y, z) return Float64(Float64(Float64(y * cosh(x)) / x) / z) end
function tmp = code(x, y, z) tmp = ((y * cosh(x)) / x) / z; end
code[x_, y_, z_] := N[(N[(N[(y * N[Cosh[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{y \cdot \cosh x}{x}}{z}
\end{array}
Initial program 84.2%
add-log-exp57.8%
*-un-lft-identity57.8%
log-prod57.8%
metadata-eval57.8%
add-log-exp84.2%
*-commutative84.2%
Applied egg-rr84.2%
+-lft-identity84.2%
associate-*l/95.9%
Simplified95.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (cosh x) (/ y x)))) (if (<= t_0 INFINITY) (/ t_0 z) (* y (/ (cosh x) (* x z))))))
double code(double x, double y, double z) {
double t_0 = cosh(x) * (y / x);
double tmp;
if (t_0 <= ((double) INFINITY)) {
tmp = t_0 / z;
} else {
tmp = y * (cosh(x) / (x * z));
}
return tmp;
}
public static double code(double x, double y, double z) {
double t_0 = Math.cosh(x) * (y / x);
double tmp;
if (t_0 <= Double.POSITIVE_INFINITY) {
tmp = t_0 / z;
} else {
tmp = y * (Math.cosh(x) / (x * z));
}
return tmp;
}
def code(x, y, z): t_0 = math.cosh(x) * (y / x) tmp = 0 if t_0 <= math.inf: tmp = t_0 / z else: tmp = y * (math.cosh(x) / (x * z)) return tmp
function code(x, y, z) t_0 = Float64(cosh(x) * Float64(y / x)) tmp = 0.0 if (t_0 <= Inf) tmp = Float64(t_0 / z); else tmp = Float64(y * Float64(cosh(x) / Float64(x * z))); end return tmp end
function tmp_2 = code(x, y, z) t_0 = cosh(x) * (y / x); tmp = 0.0; if (t_0 <= Inf) tmp = t_0 / z; else tmp = y * (cosh(x) / (x * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cosh[x], $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, Infinity], N[(t$95$0 / z), $MachinePrecision], N[(y * N[(N[Cosh[x], $MachinePrecision] / N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cosh x \cdot \frac{y}{x}\\
\mathbf{if}\;t\_0 \leq \infty:\\
\;\;\;\;\frac{t\_0}{z}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{\cosh x}{x \cdot z}\\
\end{array}
\end{array}
if (*.f64 (cosh.f64 x) (/.f64 y x)) < +inf.0Initial program 95.3%
if +inf.0 < (*.f64 (cosh.f64 x) (/.f64 y x)) Initial program 0.0%
*-commutative0.0%
associate-/l*0.0%
Simplified0.0%
add-log-exp0.0%
*-un-lft-identity0.0%
log-prod0.0%
metadata-eval0.0%
add-log-exp0.0%
clear-num0.0%
frac-times0.0%
*-un-lft-identity0.0%
Applied egg-rr0.0%
+-lft-identity0.0%
associate-/l/0.0%
associate-/r/100.0%
*-commutative100.0%
associate-/l/70.0%
Simplified70.0%
(FPCore (x y z) :precision binary64 (if (<= y 9.6e-113) (* y (/ (cosh x) (* x z))) (* (/ y x) (/ (cosh x) z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 9.6e-113) {
tmp = y * (cosh(x) / (x * z));
} else {
tmp = (y / x) * (cosh(x) / z);
}
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) :: tmp
if (y <= 9.6d-113) then
tmp = y * (cosh(x) / (x * z))
else
tmp = (y / x) * (cosh(x) / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 9.6e-113) {
tmp = y * (Math.cosh(x) / (x * z));
} else {
tmp = (y / x) * (Math.cosh(x) / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 9.6e-113: tmp = y * (math.cosh(x) / (x * z)) else: tmp = (y / x) * (math.cosh(x) / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 9.6e-113) tmp = Float64(y * Float64(cosh(x) / Float64(x * z))); else tmp = Float64(Float64(y / x) * Float64(cosh(x) / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 9.6e-113) tmp = y * (cosh(x) / (x * z)); else tmp = (y / x) * (cosh(x) / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 9.6e-113], N[(y * N[(N[Cosh[x], $MachinePrecision] / N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y / x), $MachinePrecision] * N[(N[Cosh[x], $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 9.6 \cdot 10^{-113}:\\
\;\;\;\;y \cdot \frac{\cosh x}{x \cdot z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{x} \cdot \frac{\cosh x}{z}\\
\end{array}
\end{array}
if y < 9.60000000000000049e-113Initial program 78.9%
*-commutative78.9%
associate-/l*78.9%
Simplified78.9%
add-log-exp46.7%
*-un-lft-identity46.7%
log-prod46.7%
metadata-eval46.7%
add-log-exp78.9%
clear-num78.2%
frac-times73.9%
*-un-lft-identity73.9%
Applied egg-rr73.9%
+-lft-identity73.9%
associate-/l/78.2%
associate-/r/95.2%
*-commutative95.2%
associate-/l/85.2%
Simplified85.2%
if 9.60000000000000049e-113 < y Initial program 93.1%
*-commutative93.1%
associate-/l*93.1%
Simplified93.1%
(FPCore (x y z) :precision binary64 (* y (/ (cosh x) (* x z))))
double code(double x, double y, double z) {
return y * (cosh(x) / (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 = y * (cosh(x) / (x * z))
end function
public static double code(double x, double y, double z) {
return y * (Math.cosh(x) / (x * z));
}
def code(x, y, z): return y * (math.cosh(x) / (x * z))
function code(x, y, z) return Float64(y * Float64(cosh(x) / Float64(x * z))) end
function tmp = code(x, y, z) tmp = y * (cosh(x) / (x * z)); end
code[x_, y_, z_] := N[(y * N[(N[Cosh[x], $MachinePrecision] / N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \frac{\cosh x}{x \cdot z}
\end{array}
Initial program 84.2%
*-commutative84.2%
associate-/l*84.1%
Simplified84.1%
add-log-exp57.2%
*-un-lft-identity57.2%
log-prod57.2%
metadata-eval57.2%
add-log-exp84.1%
clear-num83.7%
frac-times79.6%
*-un-lft-identity79.6%
Applied egg-rr79.6%
+-lft-identity79.6%
associate-/l/83.9%
associate-/r/96.6%
*-commutative96.6%
associate-/l/87.2%
Simplified87.2%
(FPCore (x y z) :precision binary64 (if (<= y 9e+59) (/ (/ y x) z) (/ (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= 9e+59) {
tmp = (y / x) / z;
} else {
tmp = (y / z) / x;
}
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) :: tmp
if (y <= 9d+59) then
tmp = (y / x) / z
else
tmp = (y / z) / x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 9e+59) {
tmp = (y / x) / z;
} else {
tmp = (y / z) / x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 9e+59: tmp = (y / x) / z else: tmp = (y / z) / x return tmp
function code(x, y, z) tmp = 0.0 if (y <= 9e+59) tmp = Float64(Float64(y / x) / z); else tmp = Float64(Float64(y / z) / x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 9e+59) tmp = (y / x) / z; else tmp = (y / z) / x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 9e+59], N[(N[(y / x), $MachinePrecision] / z), $MachinePrecision], N[(N[(y / z), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 9 \cdot 10^{+59}:\\
\;\;\;\;\frac{\frac{y}{x}}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{y}{z}}{x}\\
\end{array}
\end{array}
if y < 8.99999999999999919e59Initial program 82.4%
*-commutative82.4%
associate-/l*82.4%
Simplified82.4%
Taylor expanded in x around 0 51.2%
associate-/r*53.0%
Simplified53.0%
if 8.99999999999999919e59 < y Initial program 90.3%
*-commutative90.3%
associate-/l*90.3%
Simplified90.3%
Taylor expanded in x around 0 45.8%
associate-/l/60.7%
Simplified60.7%
(FPCore (x y z) :precision binary64 (if (<= y 2.25e+48) (/ (/ y x) z) (/ y (* x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.25e+48) {
tmp = (y / x) / z;
} else {
tmp = y / (x * z);
}
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) :: tmp
if (y <= 2.25d+48) then
tmp = (y / x) / z
else
tmp = y / (x * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 2.25e+48) {
tmp = (y / x) / z;
} else {
tmp = y / (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 2.25e+48: tmp = (y / x) / z else: tmp = y / (x * z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 2.25e+48) tmp = Float64(Float64(y / x) / z); else tmp = Float64(y / Float64(x * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 2.25e+48) tmp = (y / x) / z; else tmp = y / (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 2.25e+48], N[(N[(y / x), $MachinePrecision] / z), $MachinePrecision], N[(y / N[(x * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.25 \cdot 10^{+48}:\\
\;\;\;\;\frac{\frac{y}{x}}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{x \cdot z}\\
\end{array}
\end{array}
if y < 2.24999999999999998e48Initial program 82.3%
*-commutative82.3%
associate-/l*82.3%
Simplified82.3%
Taylor expanded in x around 0 51.4%
associate-/r*53.3%
Simplified53.3%
if 2.24999999999999998e48 < y Initial program 90.4%
*-commutative90.4%
associate-/l*90.5%
Simplified90.5%
Taylor expanded in x around 0 45.0%
(FPCore (x y z) :precision binary64 (/ y (* x z)))
double code(double x, double y, double z) {
return 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 = y / (x * z)
end function
public static double code(double x, double y, double z) {
return y / (x * z);
}
def code(x, y, z): return y / (x * z)
function code(x, y, z) return Float64(y / Float64(x * z)) end
function tmp = code(x, y, z) tmp = y / (x * z); end
code[x_, y_, z_] := N[(y / N[(x * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{y}{x \cdot z}
\end{array}
Initial program 84.2%
*-commutative84.2%
associate-/l*84.1%
Simplified84.1%
Taylor expanded in x around 0 50.0%
(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 2024111
(FPCore (x y z)
:name "Linear.Quaternion:$ctan from linear-1.19.1.3"
:precision binary64
:alt
(if (< y -4.618902267687042e-52) (* (/ (/ y z) x) (cosh x)) (if (< y 1.038530535935153e-39) (/ (/ (* (cosh x) y) x) z) (* (/ (/ y z) x) (cosh x))))
(/ (* (cosh x) (/ y x)) z))