
(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 (* (cosh x) (/ (/ y z) x)))
double code(double x, double y, double z) {
return cosh(x) * ((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 = cosh(x) * ((y / z) / x)
end function
public static double code(double x, double y, double z) {
return Math.cosh(x) * ((y / z) / x);
}
def code(x, y, z): return math.cosh(x) * ((y / z) / x)
function code(x, y, z) return Float64(cosh(x) * Float64(Float64(y / z) / x)) end
function tmp = code(x, y, z) tmp = cosh(x) * ((y / z) / x); end
code[x_, y_, z_] := N[(N[Cosh[x], $MachinePrecision] * N[(N[(y / z), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cosh x \cdot \frac{\frac{y}{z}}{x}
\end{array}
Initial program 99.4%
associate-*r/99.4%
associate-/l/83.3%
associate-/r*99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (<= x -1.4e-44) (* y (/ (cosh x) (* x z))) (* (/ y z) (+ (/ 1.0 x) (* x 0.5)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.4e-44) {
tmp = y * (cosh(x) / (x * z));
} else {
tmp = (y / z) * ((1.0 / x) + (x * 0.5));
}
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 <= (-1.4d-44)) then
tmp = y * (cosh(x) / (x * z))
else
tmp = (y / z) * ((1.0d0 / x) + (x * 0.5d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.4e-44) {
tmp = y * (Math.cosh(x) / (x * z));
} else {
tmp = (y / z) * ((1.0 / x) + (x * 0.5));
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.4e-44: tmp = y * (math.cosh(x) / (x * z)) else: tmp = (y / z) * ((1.0 / x) + (x * 0.5)) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.4e-44) tmp = Float64(y * Float64(cosh(x) / Float64(x * z))); else tmp = Float64(Float64(y / z) * Float64(Float64(1.0 / x) + Float64(x * 0.5))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.4e-44) tmp = y * (cosh(x) / (x * z)); else tmp = (y / z) * ((1.0 / x) + (x * 0.5)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.4e-44], N[(y * N[(N[Cosh[x], $MachinePrecision] / N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y / z), $MachinePrecision] * N[(N[(1.0 / x), $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{-44}:\\
\;\;\;\;y \cdot \frac{\cosh x}{x \cdot z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z} \cdot \left(\frac{1}{x} + x \cdot 0.5\right)\\
\end{array}
\end{array}
if x < -1.4e-44Initial program 99.7%
associate-*r/99.6%
associate-/l/99.8%
associate-*l/99.7%
*-commutative99.7%
*-commutative99.7%
Simplified99.7%
if -1.4e-44 < x Initial program 99.4%
associate-*r/99.4%
associate-/l/81.2%
associate-*l/79.6%
*-commutative79.6%
*-commutative79.6%
Simplified79.6%
Taylor expanded in x around 0 80.2%
+-commutative80.2%
associate-/l*80.2%
*-commutative80.2%
Simplified80.2%
clear-num80.2%
un-div-inv80.2%
associate-/l/80.2%
Applied egg-rr80.2%
Taylor expanded in y around 0 78.7%
distribute-rgt-in78.7%
associate-/l/78.7%
associate-*l/98.4%
associate-*r/98.9%
associate-*r/98.9%
associate-*l/98.9%
associate-*r/98.9%
associate-*r*98.9%
associate-*r*98.9%
distribute-rgt-out98.9%
Simplified98.9%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (* (/ y z) (+ (/ 1.0 x) (* x 0.5))))
double code(double x, double y, double z) {
return (y / z) * ((1.0 / x) + (x * 0.5));
}
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) * ((1.0d0 / x) + (x * 0.5d0))
end function
public static double code(double x, double y, double z) {
return (y / z) * ((1.0 / x) + (x * 0.5));
}
def code(x, y, z): return (y / z) * ((1.0 / x) + (x * 0.5))
function code(x, y, z) return Float64(Float64(y / z) * Float64(Float64(1.0 / x) + Float64(x * 0.5))) end
function tmp = code(x, y, z) tmp = (y / z) * ((1.0 / x) + (x * 0.5)); end
code[x_, y_, z_] := N[(N[(y / z), $MachinePrecision] * N[(N[(1.0 / x), $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{y}{z} \cdot \left(\frac{1}{x} + x \cdot 0.5\right)
\end{array}
Initial program 99.4%
associate-*r/99.4%
associate-/l/83.3%
associate-*l/81.9%
*-commutative81.9%
*-commutative81.9%
Simplified81.9%
Taylor expanded in x around 0 78.8%
+-commutative78.8%
associate-/l*78.8%
*-commutative78.8%
Simplified78.8%
clear-num78.8%
un-div-inv78.8%
associate-/l/78.8%
Applied egg-rr78.8%
Taylor expanded in y around 0 77.4%
distribute-rgt-in77.4%
associate-/l/77.4%
associate-*l/94.9%
associate-*r/95.3%
associate-*r/95.3%
associate-*l/95.3%
associate-*r/95.3%
associate-*r*95.3%
associate-*r*95.3%
distribute-rgt-out95.3%
Simplified95.3%
Final simplification95.3%
(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 99.4%
associate-*r/99.4%
associate-/l/83.3%
associate-*l/81.9%
*-commutative81.9%
*-commutative81.9%
Simplified81.9%
Taylor expanded in x around 0 78.3%
Final simplification78.3%
(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(Float64(y / x) / z) end
function tmp = code(x, y, z) tmp = (y / x) / z; end
code[x_, y_, z_] := N[(N[(y / x), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{y}{x}}{z}
\end{array}
Initial program 99.4%
*-commutative99.4%
associate-*r/99.4%
Simplified99.4%
Taylor expanded in x around 0 94.4%
un-div-inv94.4%
Applied egg-rr94.4%
Final simplification94.4%
(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 99.4%
associate-/l*99.4%
associate-/r/99.7%
Simplified99.7%
*-commutative99.7%
clear-num99.7%
div-inv99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 78.3%
associate-/r*94.8%
Simplified94.8%
Final simplification94.8%
(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 2023278
(FPCore (x y z)
:name "Linear.Quaternion:$ctan from linear-1.19.1.3"
:precision binary64
:herbie-target
(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))