| Alternative 1 | |
|---|---|
| Accuracy | 91.9% |
| Cost | 13636 |
\[\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}
\]

(FPCore (x y z) :precision binary64 (/ (* (cosh x) (/ y x)) z))
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cosh x) (/ y x))))
(if (or (<= t_0 (- INFINITY)) (not (<= t_0 5e+120)))
(/ (/ (* (cosh x) y) z) x)
(/ t_0 z))))double code(double x, double y, double z) {
return (cosh(x) * (y / x)) / z;
}
double code(double x, double y, double z) {
double t_0 = cosh(x) * (y / x);
double tmp;
if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 5e+120)) {
tmp = ((cosh(x) * y) / z) / x;
} else {
tmp = t_0 / z;
}
return tmp;
}
public static double code(double x, double y, double z) {
return (Math.cosh(x) * (y / x)) / z;
}
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) || !(t_0 <= 5e+120)) {
tmp = ((Math.cosh(x) * y) / z) / x;
} else {
tmp = t_0 / z;
}
return tmp;
}
def code(x, y, z): return (math.cosh(x) * (y / x)) / z
def code(x, y, z): t_0 = math.cosh(x) * (y / x) tmp = 0 if (t_0 <= -math.inf) or not (t_0 <= 5e+120): tmp = ((math.cosh(x) * y) / z) / x else: tmp = t_0 / z return tmp
function code(x, y, z) return Float64(Float64(cosh(x) * Float64(y / x)) / z) end
function code(x, y, z) t_0 = Float64(cosh(x) * Float64(y / x)) tmp = 0.0 if ((t_0 <= Float64(-Inf)) || !(t_0 <= 5e+120)) tmp = Float64(Float64(Float64(cosh(x) * y) / z) / x); else tmp = Float64(t_0 / z); end return tmp end
function tmp = code(x, y, z) tmp = (cosh(x) * (y / x)) / z; end
function tmp_2 = code(x, y, z) t_0 = cosh(x) * (y / x); tmp = 0.0; if ((t_0 <= -Inf) || ~((t_0 <= 5e+120))) tmp = ((cosh(x) * y) / z) / x; else tmp = t_0 / z; end tmp_2 = tmp; end
code[x_, y_, z_] := N[(N[(N[Cosh[x], $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cosh[x], $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 5e+120]], $MachinePrecision]], N[(N[(N[(N[Cosh[x], $MachinePrecision] * y), $MachinePrecision] / z), $MachinePrecision] / x), $MachinePrecision], N[(t$95$0 / z), $MachinePrecision]]]
\frac{\cosh x \cdot \frac{y}{x}}{z}
\begin{array}{l}
t_0 := \cosh x \cdot \frac{y}{x}\\
\mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 5 \cdot 10^{+120}\right):\\
\;\;\;\;\frac{\frac{\cosh x \cdot y}{z}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{z}\\
\end{array}
Herbie found 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 84.6% |
|---|---|
| Target | 97.0% |
| Herbie | 99.6% |
if (*.f64 (cosh.f64 x) (/.f64 y x)) < -inf.0 or 5.00000000000000019e120 < (*.f64 (cosh.f64 x) (/.f64 y x)) Initial program 73.9%
Simplified82.7%
[Start]73.9 | \[ \frac{\cosh x \cdot \frac{y}{x}}{z}
\] |
|---|---|
associate-*r/ [=>]93.5 | \[ \frac{\color{blue}{\frac{\cosh x \cdot y}{x}}}{z}
\] |
associate-/l/ [=>]82.8 | \[ \color{blue}{\frac{\cosh x \cdot y}{z \cdot x}}
\] |
associate-*l/ [<=]82.7 | \[ \color{blue}{\frac{\cosh x}{z \cdot x} \cdot y}
\] |
*-commutative [=>]82.7 | \[ \color{blue}{y \cdot \frac{\cosh x}{z \cdot x}}
\] |
*-commutative [=>]82.7 | \[ y \cdot \frac{\cosh x}{\color{blue}{x \cdot z}}
\] |
Applied egg-rr100.0%
[Start]82.7 | \[ y \cdot \frac{\cosh x}{x \cdot z}
\] |
|---|---|
associate-*r/ [=>]82.8 | \[ \color{blue}{\frac{y \cdot \cosh x}{x \cdot z}}
\] |
*-commutative [=>]82.8 | \[ \frac{y \cdot \cosh x}{\color{blue}{z \cdot x}}
\] |
associate-/r* [=>]100.0 | \[ \color{blue}{\frac{\frac{y \cdot \cosh x}{z}}{x}}
\] |
*-commutative [=>]100.0 | \[ \frac{\frac{\color{blue}{\cosh x \cdot y}}{z}}{x}
\] |
if -inf.0 < (*.f64 (cosh.f64 x) (/.f64 y x)) < 5.00000000000000019e120Initial program 99.7%
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 91.9% |
| Cost | 13636 |
| Alternative 2 | |
|---|---|
| Accuracy | 83.2% |
| Cost | 7113 |
| Alternative 3 | |
|---|---|
| Accuracy | 82.7% |
| Cost | 7113 |
| Alternative 4 | |
|---|---|
| Accuracy | 69.7% |
| Cost | 1229 |
| Alternative 5 | |
|---|---|
| Accuracy | 69.4% |
| Cost | 1229 |
| Alternative 6 | |
|---|---|
| Accuracy | 69.6% |
| Cost | 1229 |
| Alternative 7 | |
|---|---|
| Accuracy | 71.1% |
| Cost | 1229 |
| Alternative 8 | |
|---|---|
| Accuracy | 69.5% |
| Cost | 1101 |
| Alternative 9 | |
|---|---|
| Accuracy | 65.4% |
| Cost | 713 |
| Alternative 10 | |
|---|---|
| Accuracy | 52.7% |
| Cost | 585 |
| Alternative 11 | |
|---|---|
| Accuracy | 56.2% |
| Cost | 585 |
| Alternative 12 | |
|---|---|
| Accuracy | 49.2% |
| Cost | 320 |
| Alternative 13 | |
|---|---|
| Accuracy | 2.4% |
| Cost | 64 |
| Alternative 14 | |
|---|---|
| Accuracy | 4.1% |
| Cost | 64 |
herbie shell --seed 2023160
(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))