Linear.Quaternion:$ctan from linear-1.19.1.3

?

Percentage Accurate: 84.0% → 99.8%
Time: 12.7s
Precision: binary64
Cost: 20681

?

\[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
\[\begin{array}{l} t_0 := \frac{\cosh x \cdot \frac{y}{x}}{z}\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{+295} \lor \neg \left(t_0 \leq 2 \cdot 10^{+290}\right):\\ \;\;\;\;\frac{y \cdot \frac{\cosh x}{z}}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \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)) z)))
   (if (or (<= t_0 -1e+295) (not (<= t_0 2e+290)))
     (/ (* y (/ (cosh x) z)) x)
     t_0)))
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)) / z;
	double tmp;
	if ((t_0 <= -1e+295) || !(t_0 <= 2e+290)) {
		tmp = (y * (cosh(x) / z)) / x;
	} 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
    code = (cosh(x) * (y / x)) / z
end function
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 = (cosh(x) * (y / x)) / z
    if ((t_0 <= (-1d+295)) .or. (.not. (t_0 <= 2d+290))) then
        tmp = (y * (cosh(x) / z)) / x
    else
        tmp = t_0
    end if
    code = tmp
end function
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)) / z;
	double tmp;
	if ((t_0 <= -1e+295) || !(t_0 <= 2e+290)) {
		tmp = (y * (Math.cosh(x) / z)) / x;
	} else {
		tmp = t_0;
	}
	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)) / z
	tmp = 0
	if (t_0 <= -1e+295) or not (t_0 <= 2e+290):
		tmp = (y * (math.cosh(x) / z)) / x
	else:
		tmp = t_0
	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(Float64(cosh(x) * Float64(y / x)) / z)
	tmp = 0.0
	if ((t_0 <= -1e+295) || !(t_0 <= 2e+290))
		tmp = Float64(Float64(y * Float64(cosh(x) / z)) / x);
	else
		tmp = t_0;
	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)) / z;
	tmp = 0.0;
	if ((t_0 <= -1e+295) || ~((t_0 <= 2e+290)))
		tmp = (y * (cosh(x) / z)) / x;
	else
		tmp = t_0;
	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[(N[Cosh[x], $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -1e+295], N[Not[LessEqual[t$95$0, 2e+290]], $MachinePrecision]], N[(N[(y * N[(N[Cosh[x], $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], t$95$0]]
\frac{\cosh x \cdot \frac{y}{x}}{z}
\begin{array}{l}
t_0 := \frac{\cosh x \cdot \frac{y}{x}}{z}\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{+295} \lor \neg \left(t_0 \leq 2 \cdot 10^{+290}\right):\\
\;\;\;\;\frac{y \cdot \frac{\cosh x}{z}}{x}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\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 14 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.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original84.0%
Target96.9%
Herbie99.8%
\[\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 (*.f64 (cosh.f64 x) (/.f64 y x)) z) < -9.9999999999999998e294 or 2.00000000000000012e290 < (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z)

    1. Initial program 78.1%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Simplified78.1%

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

      [Start]78.1

      \[ \frac{\cosh x \cdot \frac{y}{x}}{z} \]

      *-commutative [=>]78.1

      \[ \frac{\color{blue}{\frac{y}{x} \cdot \cosh x}}{z} \]

      associate-*r/ [<=]78.1

      \[ \color{blue}{\frac{y}{x} \cdot \frac{\cosh x}{z}} \]
    3. Applied egg-rr99.9%

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

      [Start]78.1

      \[ \frac{y}{x} \cdot \frac{\cosh x}{z} \]

      associate-*l/ [=>]99.9

      \[ \color{blue}{\frac{y \cdot \frac{\cosh x}{z}}{x}} \]

    if -9.9999999999999998e294 < (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z) < 2.00000000000000012e290

    1. Initial program 99.6%

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

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

Alternatives

Alternative 1
Accuracy84.7%
Cost7113
\[\begin{array}{l} \mathbf{if}\;y \leq -1.7 \cdot 10^{+158} \lor \neg \left(y \leq 6.8 \cdot 10^{+198}\right):\\ \;\;\;\;\frac{y}{x \cdot z} + \frac{0.5}{\frac{z}{x \cdot y}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{\cosh x}{x \cdot z}\\ \end{array} \]
Alternative 2
Accuracy87.9%
Cost7113
\[\begin{array}{l} \mathbf{if}\;z \leq -5.4 \cdot 10^{-9} \lor \neg \left(z \leq 0.0046\right):\\ \;\;\;\;\frac{y}{x} \cdot \frac{\cosh x}{z}\\ \mathbf{else}:\\ \;\;\;\;\cosh x \cdot \frac{\frac{y}{z}}{x}\\ \end{array} \]
Alternative 3
Accuracy84.1%
Cost6980
\[\begin{array}{l} \mathbf{if}\;z \leq -3.2 \cdot 10^{-16}:\\ \;\;\;\;y \cdot \frac{\cosh x}{x \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\cosh x \cdot \frac{\frac{y}{z}}{x}\\ \end{array} \]
Alternative 4
Accuracy96.2%
Cost6848
\[\frac{y \cdot \frac{\cosh x}{z}}{x} \]
Alternative 5
Accuracy65.6%
Cost1100
\[\begin{array}{l} t_0 := 0.5 \cdot \frac{x \cdot y}{z}\\ \mathbf{if}\;x \leq -63000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.02 \cdot 10^{-262}:\\ \;\;\;\;\frac{1}{z \cdot \frac{x}{y}}\\ \mathbf{elif}\;x \leq 10^{+34}:\\ \;\;\;\;\frac{y}{z} \cdot \left(\frac{1}{x} + x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Accuracy64.5%
Cost976
\[\begin{array}{l} t_0 := 0.5 \cdot \frac{y}{\frac{z}{x}}\\ \mathbf{if}\;x \leq -63000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -8 \cdot 10^{-278}:\\ \;\;\;\;\frac{\frac{y}{z}}{x}\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-200}:\\ \;\;\;\;\frac{y}{x \cdot z}\\ \mathbf{elif}\;x \leq 1.4:\\ \;\;\;\;\frac{\frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Accuracy65.3%
Cost976
\[\begin{array}{l} t_0 := 0.5 \cdot \frac{x \cdot y}{z}\\ \mathbf{if}\;x \leq -63000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -8.2 \cdot 10^{-278}:\\ \;\;\;\;\frac{\frac{y}{z}}{x}\\ \mathbf{elif}\;x \leq 9.8 \cdot 10^{-209}:\\ \;\;\;\;\frac{y}{x \cdot z}\\ \mathbf{elif}\;x \leq 1.4:\\ \;\;\;\;\frac{\frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Accuracy65.2%
Cost976
\[\begin{array}{l} t_0 := 0.5 \cdot \frac{x \cdot y}{z}\\ \mathbf{if}\;x \leq -63000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -6.6 \cdot 10^{-278}:\\ \;\;\;\;\frac{1}{z \cdot \frac{x}{y}}\\ \mathbf{elif}\;x \leq 1.12 \cdot 10^{-198}:\\ \;\;\;\;\frac{y}{x \cdot z}\\ \mathbf{elif}\;x \leq 1.4:\\ \;\;\;\;\frac{\frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Accuracy66.3%
Cost964
\[\begin{array}{l} \mathbf{if}\;z \leq 1.35 \cdot 10^{+169}:\\ \;\;\;\;\frac{\frac{y}{x} + x \cdot \left(y \cdot 0.5\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x \cdot z} + \frac{0.5}{\frac{z}{x \cdot y}}\\ \end{array} \]
Alternative 10
Accuracy65.1%
Cost704
\[\frac{\frac{y}{x} + x \cdot \left(y \cdot 0.5\right)}{z} \]
Alternative 11
Accuracy50.0%
Cost452
\[\begin{array}{l} \mathbf{if}\;z \leq 4.6 \cdot 10^{+162}:\\ \;\;\;\;\frac{\frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x \cdot z}\\ \end{array} \]
Alternative 12
Accuracy54.8%
Cost452
\[\begin{array}{l} \mathbf{if}\;z \leq -6 \cdot 10^{-60}:\\ \;\;\;\;\frac{y}{x \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{z}}{x}\\ \end{array} \]
Alternative 13
Accuracy49.4%
Cost320
\[\frac{y}{x \cdot z} \]

Reproduce?

herbie shell --seed 2023163 
(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))