Linear.Quaternion:$ctanh from linear-1.19.1.3

?

Percentage Accurate: 96.1% → 99.7%
Time: 15.1s
Precision: binary64
Cost: 7113

?

\[\frac{x \cdot \frac{\sin y}{y}}{z} \]
\[\begin{array}{l} \mathbf{if}\;z \leq -5 \cdot 10^{-34} \lor \neg \left(z \leq 65\right):\\ \;\;\;\;\frac{x \cdot \frac{\sin y}{y}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y \cdot \frac{z}{\sin y}}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (/ (sin y) y)) z))
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -5e-34) (not (<= z 65.0)))
   (/ (* x (/ (sin y) y)) z)
   (/ x (* y (/ z (sin y))))))
double code(double x, double y, double z) {
	return (x * (sin(y) / y)) / z;
}
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -5e-34) || !(z <= 65.0)) {
		tmp = (x * (sin(y) / y)) / z;
	} else {
		tmp = x / (y * (z / sin(y)));
	}
	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 = (x * (sin(y) / y)) / 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) :: tmp
    if ((z <= (-5d-34)) .or. (.not. (z <= 65.0d0))) then
        tmp = (x * (sin(y) / y)) / z
    else
        tmp = x / (y * (z / sin(y)))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	return (x * (Math.sin(y) / y)) / z;
}
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -5e-34) || !(z <= 65.0)) {
		tmp = (x * (Math.sin(y) / y)) / z;
	} else {
		tmp = x / (y * (z / Math.sin(y)));
	}
	return tmp;
}
def code(x, y, z):
	return (x * (math.sin(y) / y)) / z
def code(x, y, z):
	tmp = 0
	if (z <= -5e-34) or not (z <= 65.0):
		tmp = (x * (math.sin(y) / y)) / z
	else:
		tmp = x / (y * (z / math.sin(y)))
	return tmp
function code(x, y, z)
	return Float64(Float64(x * Float64(sin(y) / y)) / z)
end
function code(x, y, z)
	tmp = 0.0
	if ((z <= -5e-34) || !(z <= 65.0))
		tmp = Float64(Float64(x * Float64(sin(y) / y)) / z);
	else
		tmp = Float64(x / Float64(y * Float64(z / sin(y))));
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = (x * (sin(y) / y)) / z;
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -5e-34) || ~((z <= 65.0)))
		tmp = (x * (sin(y) / y)) / z;
	else
		tmp = x / (y * (z / sin(y)));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := N[(N[(x * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := If[Or[LessEqual[z, -5e-34], N[Not[LessEqual[z, 65.0]], $MachinePrecision]], N[(N[(x * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], N[(x / N[(y * N[(z / N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{x \cdot \frac{\sin y}{y}}{z}
\begin{array}{l}
\mathbf{if}\;z \leq -5 \cdot 10^{-34} \lor \neg \left(z \leq 65\right):\\
\;\;\;\;\frac{x \cdot \frac{\sin y}{y}}{z}\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{y \cdot \frac{z}{\sin y}}\\


\end{array}

Local Percentage Accuracy vs ?

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 alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original96.1%
Target99.6%
Herbie99.7%
\[\begin{array}{l} \mathbf{if}\;z < -4.2173720203427147 \cdot 10^{-29}:\\ \;\;\;\;\frac{x \cdot \frac{1}{\frac{y}{\sin y}}}{z}\\ \mathbf{elif}\;z < 4.446702369113811 \cdot 10^{+64}:\\ \;\;\;\;\frac{x}{z \cdot \frac{y}{\sin y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \frac{1}{\frac{y}{\sin y}}}{z}\\ \end{array} \]

Derivation?

  1. Split input into 2 regimes
  2. if z < -5.0000000000000003e-34 or 65 < z

    1. Initial program 99.9%

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

    if -5.0000000000000003e-34 < z < 65

    1. Initial program 91.8%

      \[\frac{x \cdot \frac{\sin y}{y}}{z} \]
    2. Simplified99.7%

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

      [Start]91.8%

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

      associate-/l* [=>]99.7%

      \[ \color{blue}{\frac{x}{\frac{z}{\frac{\sin y}{y}}}} \]

      associate-/r/ [=>]99.7%

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

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

Alternatives

Alternative 1
Accuracy99.7%
Cost7113
\[\begin{array}{l} \mathbf{if}\;z \leq -5 \cdot 10^{-34} \lor \neg \left(z \leq 65\right):\\ \;\;\;\;\frac{x \cdot \frac{\sin y}{y}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y \cdot \frac{z}{\sin y}}\\ \end{array} \]
Alternative 2
Accuracy95.8%
Cost7113
\[\begin{array}{l} \mathbf{if}\;y \leq -0.092 \lor \neg \left(y \leq 1.52 \cdot 10^{-10}\right):\\ \;\;\;\;\sin y \cdot \frac{x}{z \cdot y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z}\\ \end{array} \]
Alternative 3
Accuracy96.0%
Cost7113
\[\begin{array}{l} \mathbf{if}\;y \leq -0.092 \lor \neg \left(y \leq 1.52 \cdot 10^{-10}\right):\\ \;\;\;\;\sin y \cdot \frac{\frac{x}{y}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z}\\ \end{array} \]
Alternative 4
Accuracy96.1%
Cost7113
\[\begin{array}{l} \mathbf{if}\;y \leq -0.092 \lor \neg \left(y \leq 4 \cdot 10^{-5}\right):\\ \;\;\;\;\frac{\sin y}{z} \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(1 + -0.16666666666666666 \cdot \left(y \cdot y\right)\right)}{z}\\ \end{array} \]
Alternative 5
Accuracy97.6%
Cost7113
\[\begin{array}{l} \mathbf{if}\;z \leq -1.5 \cdot 10^{+114} \lor \neg \left(z \leq 6.2 \cdot 10^{+44}\right):\\ \;\;\;\;\frac{\sin y}{y \cdot \frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y \cdot \frac{z}{\sin y}}\\ \end{array} \]
Alternative 6
Accuracy97.9%
Cost7113
\[\begin{array}{l} \mathbf{if}\;z \leq -1.8 \cdot 10^{+110} \lor \neg \left(z \leq 1.4 \cdot 10^{+37}\right):\\ \;\;\;\;\frac{\sin y}{\frac{y}{\frac{x}{z}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y \cdot \frac{z}{\sin y}}\\ \end{array} \]
Alternative 7
Accuracy66.5%
Cost968
\[\begin{array}{l} t_0 := z \cdot \left(y \cdot 0.16666666666666666\right)\\ \mathbf{if}\;y \leq -2.45 \cdot 10^{+14}:\\ \;\;\;\;\frac{1}{y} \cdot \frac{x}{t_0}\\ \mathbf{elif}\;y \leq 2.5:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{y \cdot t_0}{x}}\\ \end{array} \]
Alternative 8
Accuracy65.7%
Cost968
\[\begin{array}{l} \mathbf{if}\;y \leq -3.1 \cdot 10^{+99}:\\ \;\;\;\;\left(\frac{x}{z} \cdot \frac{6}{y}\right) \cdot \frac{1}{y}\\ \mathbf{elif}\;y \leq 19:\\ \;\;\;\;\frac{x \cdot \left(1 + -0.16666666666666666 \cdot \left(y \cdot y\right)\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{y \cdot \left(z \cdot \left(y \cdot 0.16666666666666666\right)\right)}{x}}\\ \end{array} \]
Alternative 9
Accuracy65.9%
Cost841
\[\begin{array}{l} \mathbf{if}\;y \leq -1.45 \cdot 10^{+118} \lor \neg \left(y \leq 2.5\right):\\ \;\;\;\;6 \cdot \frac{x}{y \cdot \left(z \cdot y\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z}\\ \end{array} \]
Alternative 10
Accuracy66.7%
Cost841
\[\begin{array}{l} \mathbf{if}\;y \leq -390000000000 \lor \neg \left(y \leq 2.5\right):\\ \;\;\;\;\frac{6}{y \cdot \left(z \cdot \frac{y}{x}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z}\\ \end{array} \]
Alternative 11
Accuracy66.4%
Cost840
\[\begin{array}{l} \mathbf{if}\;y \leq -550000000000:\\ \;\;\;\;\frac{6}{y \cdot \left(z \cdot \frac{y}{x}\right)}\\ \mathbf{elif}\;y \leq 2.5:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y \cdot \left(y \cdot \left(z \cdot 0.16666666666666666\right)\right)}\\ \end{array} \]
Alternative 12
Accuracy66.5%
Cost840
\[\begin{array}{l} \mathbf{if}\;y \leq -390000000000:\\ \;\;\;\;\left(\frac{x}{z} \cdot \frac{6}{y}\right) \cdot \frac{1}{y}\\ \mathbf{elif}\;y \leq 2.5:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y \cdot \left(y \cdot \left(z \cdot 0.16666666666666666\right)\right)}\\ \end{array} \]
Alternative 13
Accuracy66.5%
Cost840
\[\begin{array}{l} \mathbf{if}\;y \leq -390000000000:\\ \;\;\;\;\frac{1}{y} \cdot \frac{x}{z \cdot \left(y \cdot 0.16666666666666666\right)}\\ \mathbf{elif}\;y \leq 2.5:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y \cdot \left(y \cdot \left(z \cdot 0.16666666666666666\right)\right)}\\ \end{array} \]
Alternative 14
Accuracy60.6%
Cost580
\[\begin{array}{l} \mathbf{if}\;z \leq 10000000000:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z \cdot y}{y}}\\ \end{array} \]
Alternative 15
Accuracy58.5%
Cost192
\[\frac{x}{z} \]

Reproduce?

herbie shell --seed 2023263 
(FPCore (x y z)
  :name "Linear.Quaternion:$ctanh from linear-1.19.1.3"
  :precision binary64

  :herbie-target
  (if (< z -4.2173720203427147e-29) (/ (* x (/ 1.0 (/ y (sin y)))) z) (if (< z 4.446702369113811e+64) (/ x (* z (/ y (sin y)))) (/ (* x (/ 1.0 (/ y (sin y)))) z)))

  (/ (* x (/ (sin y) y)) z))