Linear.Quaternion:$ctan from linear-1.19.1.3

?

Percentage Accurate: 84.6% → 99.6%
Time: 10.6s
Precision: binary64
Cost: 20425

?

\[\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} \]
(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}

Local Percentage Accuracy?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 15 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each of Herbie's proposed alternatives. Up and to the right is better. Each dot represents an alternative program; the red square represents the initial program.

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original84.6%
Target97.0%
Herbie99.6%
\[\begin{array}{l} \mathbf{if}\;y < -4.618902267687042 \cdot 10^{-52}:\\ \;\;\;\;\frac{\frac{y}{z}}{x} \cdot \cosh x\\ \mathbf{elif}\;y < 1.038530535935153 \cdot 10^{-39}:\\ \;\;\;\;\frac{\frac{\cosh x \cdot y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{z}}{x} \cdot \cosh x\\ \end{array} \]

Derivation?

  1. Split input into 2 regimes
  2. if (*.f64 (cosh.f64 x) (/.f64 y x)) < -inf.0 or 5.00000000000000019e120 < (*.f64 (cosh.f64 x) (/.f64 y x))

    1. Initial program 73.9%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Simplified82.7%

      \[\leadsto \color{blue}{y \cdot \frac{\cosh x}{x \cdot z}} \]
      Step-by-step derivation

      [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}} \]
    3. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{\frac{\cosh x \cdot y}{z}}{x}} \]
      Step-by-step derivation

      [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.00000000000000019e120

    1. Initial program 99.7%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cosh x \cdot \frac{y}{x} \leq -\infty \lor \neg \left(\cosh x \cdot \frac{y}{x} \leq 5 \cdot 10^{+120}\right):\\ \;\;\;\;\frac{\frac{\cosh x \cdot y}{z}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cosh x \cdot \frac{y}{x}}{z}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy91.9%
Cost13636
\[\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} \]
Alternative 2
Accuracy83.2%
Cost7113
\[\begin{array}{l} \mathbf{if}\;x \leq -2.5 \cdot 10^{-244} \lor \neg \left(x \leq 2 \cdot 10^{-35}\right):\\ \;\;\;\;y \cdot \frac{\cosh x}{x \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{z}}{x}\\ \end{array} \]
Alternative 3
Accuracy82.7%
Cost7113
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+199} \lor \neg \left(x \leq 1.7 \cdot 10^{-34}\right):\\ \;\;\;\;y \cdot \frac{\cosh x}{x \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\cosh x \cdot \frac{\frac{y}{z}}{x}\\ \end{array} \]
Alternative 4
Accuracy69.7%
Cost1229
\[\begin{array}{l} \mathbf{if}\;x \leq -3.1 \cdot 10^{+203}:\\ \;\;\;\;0.5 \cdot \left(y \cdot \frac{x}{z}\right)\\ \mathbf{elif}\;x \leq -1.6 \cdot 10^{-109} \lor \neg \left(x \leq 4.3 \cdot 10^{-33}\right):\\ \;\;\;\;0.5 \cdot \left(\frac{y}{x} \cdot \frac{2 + x \cdot x}{z}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{z}}{x}\\ \end{array} \]
Alternative 5
Accuracy69.4%
Cost1229
\[\begin{array}{l} \mathbf{if}\;y \leq -5.6 \cdot 10^{+178} \lor \neg \left(y \leq -4.4 \cdot 10^{-203}\right) \land y \leq 5.6 \cdot 10^{-98}:\\ \;\;\;\;y \cdot \left(\frac{1}{x \cdot z} + 0.5 \cdot \frac{x}{z}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\frac{y}{x} \cdot \frac{2 + x \cdot x}{z}\right)\\ \end{array} \]
Alternative 6
Accuracy69.6%
Cost1229
\[\begin{array}{l} \mathbf{if}\;y \leq -6.5 \cdot 10^{+178} \lor \neg \left(y \leq -4.4 \cdot 10^{-198}\right) \land y \leq 7.4 \cdot 10^{-98}:\\ \;\;\;\;\frac{y}{x \cdot z} + 0.5 \cdot \left(y \cdot \frac{x}{z}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\frac{y}{x} \cdot \frac{2 + x \cdot x}{z}\right)\\ \end{array} \]
Alternative 7
Accuracy71.1%
Cost1229
\[\begin{array}{l} t_0 := \frac{y}{x \cdot z}\\ \mathbf{if}\;y \leq -1.76 \cdot 10^{+139}:\\ \;\;\;\;t_0 + 0.5 \cdot \left(\frac{1}{z} \cdot \frac{y}{\frac{1}{x}}\right)\\ \mathbf{elif}\;y \leq -2.05 \cdot 10^{-187} \lor \neg \left(y \leq 2.7 \cdot 10^{-98}\right):\\ \;\;\;\;0.5 \cdot \left(\frac{y}{x} \cdot \frac{2 + x \cdot x}{z}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0 + 0.5 \cdot \left(y \cdot \frac{x}{z}\right)\\ \end{array} \]
Alternative 8
Accuracy69.5%
Cost1101
\[\begin{array}{l} \mathbf{if}\;x \leq -2.4 \cdot 10^{+203}:\\ \;\;\;\;0.5 \cdot \left(y \cdot \frac{x}{z}\right)\\ \mathbf{elif}\;x \leq -1.4 \lor \neg \left(x \leq 1.4\right):\\ \;\;\;\;0.5 \cdot \left(\frac{y}{x} \cdot \frac{x \cdot x}{z}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{z}}{x}\\ \end{array} \]
Alternative 9
Accuracy65.4%
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -1.4 \lor \neg \left(x \leq 1.4\right):\\ \;\;\;\;0.5 \cdot \left(y \cdot \frac{x}{z}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{z}}{x}\\ \end{array} \]
Alternative 10
Accuracy52.7%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -62 \lor \neg \left(y \leq 7.2 \cdot 10^{+28}\right):\\ \;\;\;\;\frac{y}{x \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{x}}{z}\\ \end{array} \]
Alternative 11
Accuracy56.2%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -20 \lor \neg \left(y \leq 3.4 \cdot 10^{+26}\right):\\ \;\;\;\;\frac{\frac{y}{z}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{x}}{z}\\ \end{array} \]
Alternative 12
Accuracy49.2%
Cost320
\[\frac{y}{x \cdot z} \]
Alternative 13
Accuracy2.4%
Cost64
\[-2 \]
Alternative 14
Accuracy4.1%
Cost64
\[0 \]

Reproduce?

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))