
(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 6 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) z)) x))
double code(double x, double y, double z) {
return (y * (cosh(x) / z)) / x;
}
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) / z)) / x
end function
public static double code(double x, double y, double z) {
return (y * (Math.cosh(x) / z)) / x;
}
def code(x, y, z): return (y * (math.cosh(x) / z)) / x
function code(x, y, z) return Float64(Float64(y * Float64(cosh(x) / z)) / x) end
function tmp = code(x, y, z) tmp = (y * (cosh(x) / z)) / x; end
code[x_, y_, z_] := N[(N[(y * N[(N[Cosh[x], $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{y \cdot \frac{\cosh x}{z}}{x}
\end{array}
Initial program 85.3%
associate-/l*77.9%
associate-/l/77.5%
Simplified77.5%
associate-*r/86.1%
frac-times85.3%
*-commutative85.3%
associate-*l/99.0%
Applied egg-rr99.0%
(FPCore (x y z) :precision binary64 (if (<= x 5.7e-52) (/ (/ y z) x) (* (/ (cosh x) z) (/ y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= 5.7e-52) {
tmp = (y / z) / x;
} else {
tmp = (cosh(x) / z) * (y / 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 (x <= 5.7d-52) then
tmp = (y / z) / x
else
tmp = (cosh(x) / z) * (y / x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 5.7e-52) {
tmp = (y / z) / x;
} else {
tmp = (Math.cosh(x) / z) * (y / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 5.7e-52: tmp = (y / z) / x else: tmp = (math.cosh(x) / z) * (y / x) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 5.7e-52) tmp = Float64(Float64(y / z) / x); else tmp = Float64(Float64(cosh(x) / z) * Float64(y / x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 5.7e-52) tmp = (y / z) / x; else tmp = (cosh(x) / z) * (y / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 5.7e-52], N[(N[(y / z), $MachinePrecision] / x), $MachinePrecision], N[(N[(N[Cosh[x], $MachinePrecision] / z), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.7 \cdot 10^{-52}:\\
\;\;\;\;\frac{\frac{y}{z}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\cosh x}{z} \cdot \frac{y}{x}\\
\end{array}
\end{array}
if x < 5.6999999999999997e-52Initial program 88.7%
associate-/l*84.2%
associate-/l/81.3%
Simplified81.3%
associate-*r/85.9%
frac-times88.7%
*-commutative88.7%
associate-*l/98.6%
Applied egg-rr98.6%
Taylor expanded in x around 0 64.5%
associate-/l/70.2%
Simplified70.2%
if 5.6999999999999997e-52 < x Initial program 77.8%
*-commutative77.8%
associate-/l*77.8%
Simplified77.8%
Final simplification72.6%
(FPCore (x y z) :precision binary64 (if (<= x 7e-139) (/ (/ y z) x) (* (cosh x) (/ y (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= 7e-139) {
tmp = (y / z) / x;
} else {
tmp = cosh(x) * (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 (x <= 7d-139) then
tmp = (y / z) / x
else
tmp = cosh(x) * (y / (x * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 7e-139) {
tmp = (y / z) / x;
} else {
tmp = Math.cosh(x) * (y / (x * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 7e-139: tmp = (y / z) / x else: tmp = math.cosh(x) * (y / (x * z)) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 7e-139) tmp = Float64(Float64(y / z) / x); else tmp = Float64(cosh(x) * Float64(y / Float64(x * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 7e-139) tmp = (y / z) / x; else tmp = cosh(x) * (y / (x * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 7e-139], N[(N[(y / z), $MachinePrecision] / x), $MachinePrecision], N[(N[Cosh[x], $MachinePrecision] * N[(y / N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 7 \cdot 10^{-139}:\\
\;\;\;\;\frac{\frac{y}{z}}{x}\\
\mathbf{else}:\\
\;\;\;\;\cosh x \cdot \frac{y}{x \cdot z}\\
\end{array}
\end{array}
if x < 7.00000000000000002e-139Initial program 88.2%
associate-/l*83.2%
associate-/l/79.5%
Simplified79.5%
associate-*r/84.5%
frac-times88.2%
*-commutative88.2%
associate-*l/99.1%
Applied egg-rr99.1%
Taylor expanded in x around 0 61.0%
associate-/l/67.8%
Simplified67.8%
if 7.00000000000000002e-139 < x Initial program 80.4%
associate-/l*69.1%
associate-/l/74.1%
Simplified74.1%
Final simplification70.2%
(FPCore (x y z) :precision binary64 (if (<= z 5e+52) (/ (/ y x) z) (/ y (* x z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 5e+52) {
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 (z <= 5d+52) 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 (z <= 5e+52) {
tmp = (y / x) / z;
} else {
tmp = y / (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 5e+52: tmp = (y / x) / z else: tmp = y / (x * z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 5e+52) 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 (z <= 5e+52) tmp = (y / x) / z; else tmp = y / (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 5e+52], N[(N[(y / x), $MachinePrecision] / z), $MachinePrecision], N[(y / N[(x * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 5 \cdot 10^{+52}:\\
\;\;\;\;\frac{\frac{y}{x}}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{x \cdot z}\\
\end{array}
\end{array}
if z < 5e52Initial program 88.3%
Taylor expanded in x around 0 52.2%
if 5e52 < z Initial program 72.7%
associate-/l*52.7%
associate-/l/57.9%
Simplified57.9%
Taylor expanded in x around 0 48.8%
(FPCore (x y z) :precision binary64 (/ (/ y z) x))
double code(double x, double y, double z) {
return (y / z) / x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (y / z) / x
end function
public static double code(double x, double y, double z) {
return (y / z) / x;
}
def code(x, y, z): return (y / z) / x
function code(x, y, z) return Float64(Float64(y / z) / x) end
function tmp = code(x, y, z) tmp = (y / z) / x; end
code[x_, y_, z_] := N[(N[(y / z), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{y}{z}}{x}
\end{array}
Initial program 85.3%
associate-/l*77.9%
associate-/l/77.5%
Simplified77.5%
associate-*r/86.1%
frac-times85.3%
*-commutative85.3%
associate-*l/99.0%
Applied egg-rr99.0%
Taylor expanded in x around 0 48.9%
associate-/l/56.1%
Simplified56.1%
(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 85.3%
associate-/l*77.9%
associate-/l/77.5%
Simplified77.5%
Taylor expanded in x around 0 48.9%
(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 2024114
(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))