Linear.Quaternion:$ccosh from linear-1.19.1.3

Percentage Accurate: 89.3% → 99.9%
Time: 13.6s
Alternatives: 22
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \frac{\sin x \cdot \sinh y}{x} \end{array} \]
(FPCore (x y) :precision binary64 (/ (* (sin x) (sinh y)) x))
double code(double x, double y) {
	return (sin(x) * sinh(y)) / x;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (sin(x) * sinh(y)) / x
end function
public static double code(double x, double y) {
	return (Math.sin(x) * Math.sinh(y)) / x;
}
def code(x, y):
	return (math.sin(x) * math.sinh(y)) / x
function code(x, y)
	return Float64(Float64(sin(x) * sinh(y)) / x)
end
function tmp = code(x, y)
	tmp = (sin(x) * sinh(y)) / x;
end
code[x_, y_] := N[(N[(N[Sin[x], $MachinePrecision] * N[Sinh[y], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}

\\
\frac{\sin x \cdot \sinh y}{x}
\end{array}

Sampling outcomes in binary64 precision:

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.

Accuracy vs Speed?

Herbie found 22 alternatives:

AlternativeAccuracySpeedup
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.

Initial Program: 89.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\sin x \cdot \sinh y}{x} \end{array} \]
(FPCore (x y) :precision binary64 (/ (* (sin x) (sinh y)) x))
double code(double x, double y) {
	return (sin(x) * sinh(y)) / x;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (sin(x) * sinh(y)) / x
end function
public static double code(double x, double y) {
	return (Math.sin(x) * Math.sinh(y)) / x;
}
def code(x, y):
	return (math.sin(x) * math.sinh(y)) / x
function code(x, y)
	return Float64(Float64(sin(x) * sinh(y)) / x)
end
function tmp = code(x, y)
	tmp = (sin(x) * sinh(y)) / x;
end
code[x_, y_] := N[(N[(N[Sin[x], $MachinePrecision] * N[Sinh[y], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}

\\
\frac{\sin x \cdot \sinh y}{x}
\end{array}

Alternative 1: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\sin x}{x} \cdot \sinh y \end{array} \]
(FPCore (x y) :precision binary64 (* (/ (sin x) x) (sinh y)))
double code(double x, double y) {
	return (sin(x) / x) * sinh(y);
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (sin(x) / x) * sinh(y)
end function
public static double code(double x, double y) {
	return (Math.sin(x) / x) * Math.sinh(y);
}
def code(x, y):
	return (math.sin(x) / x) * math.sinh(y)
function code(x, y)
	return Float64(Float64(sin(x) / x) * sinh(y))
end
function tmp = code(x, y)
	tmp = (sin(x) / x) * sinh(y);
end
code[x_, y_] := N[(N[(N[Sin[x], $MachinePrecision] / x), $MachinePrecision] * N[Sinh[y], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\sin x}{x} \cdot \sinh y
\end{array}
Derivation
  1. Initial program 87.5%

    \[\frac{\sin x \cdot \sinh y}{x} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{\sin x \cdot \sinh y}{x}} \]
    2. lift-*.f64N/A

      \[\leadsto \frac{\color{blue}{\sin x \cdot \sinh y}}{x} \]
    3. associate-*l/N/A

      \[\leadsto \color{blue}{\frac{\sin x}{x} \cdot \sinh y} \]
    4. lower-*.f64N/A

      \[\leadsto \color{blue}{\frac{\sin x}{x} \cdot \sinh y} \]
    5. lower-/.f6499.9

      \[\leadsto \color{blue}{\frac{\sin x}{x}} \cdot \sinh y \]
  4. Applied rewrites99.9%

    \[\leadsto \color{blue}{\frac{\sin x}{x} \cdot \sinh y} \]
  5. Add Preprocessing

Alternative 2: 83.2% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\sin x \cdot \sinh y}{x}\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;\frac{y \cdot \left(\mathsf{fma}\left(x \cdot x, x \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, -0.0001984126984126984, 0.008333333333333333\right), -0.16666666666666666\right), x\right) \cdot \mathsf{fma}\left(y, y \cdot 0.16666666666666666, 1\right)\right)}{x}\\ \mathbf{elif}\;t\_0 \leq 10^{-6}:\\ \;\;\;\;\frac{\sin x}{x} \cdot \mathsf{fma}\left(y \cdot y, y \cdot 0.16666666666666666, y\right)\\ \mathbf{else}:\\ \;\;\;\;\sinh y \cdot 1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (* (sin x) (sinh y)) x)))
   (if (<= t_0 (- INFINITY))
     (/
      (*
       y
       (*
        (fma
         (* x x)
         (*
          x
          (fma
           (* x x)
           (fma (* x x) -0.0001984126984126984 0.008333333333333333)
           -0.16666666666666666))
         x)
        (fma y (* y 0.16666666666666666) 1.0)))
      x)
     (if (<= t_0 1e-6)
       (* (/ (sin x) x) (fma (* y y) (* y 0.16666666666666666) y))
       (* (sinh y) 1.0)))))
double code(double x, double y) {
	double t_0 = (sin(x) * sinh(y)) / x;
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = (y * (fma((x * x), (x * fma((x * x), fma((x * x), -0.0001984126984126984, 0.008333333333333333), -0.16666666666666666)), x) * fma(y, (y * 0.16666666666666666), 1.0))) / x;
	} else if (t_0 <= 1e-6) {
		tmp = (sin(x) / x) * fma((y * y), (y * 0.16666666666666666), y);
	} else {
		tmp = sinh(y) * 1.0;
	}
	return tmp;
}
function code(x, y)
	t_0 = Float64(Float64(sin(x) * sinh(y)) / x)
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(Float64(y * Float64(fma(Float64(x * x), Float64(x * fma(Float64(x * x), fma(Float64(x * x), -0.0001984126984126984, 0.008333333333333333), -0.16666666666666666)), x) * fma(y, Float64(y * 0.16666666666666666), 1.0))) / x);
	elseif (t_0 <= 1e-6)
		tmp = Float64(Float64(sin(x) / x) * fma(Float64(y * y), Float64(y * 0.16666666666666666), y));
	else
		tmp = Float64(sinh(y) * 1.0);
	end
	return tmp
end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[Sin[x], $MachinePrecision] * N[Sinh[y], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(y * N[(N[(N[(x * x), $MachinePrecision] * N[(x * N[(N[(x * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * -0.0001984126984126984 + 0.008333333333333333), $MachinePrecision] + -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] * N[(y * N[(y * 0.16666666666666666), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[t$95$0, 1e-6], N[(N[(N[Sin[x], $MachinePrecision] / x), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * N[(y * 0.16666666666666666), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision], N[(N[Sinh[y], $MachinePrecision] * 1.0), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{\sin x \cdot \sinh y}{x}\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;\frac{y \cdot \left(\mathsf{fma}\left(x \cdot x, x \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, -0.0001984126984126984, 0.008333333333333333\right), -0.16666666666666666\right), x\right) \cdot \mathsf{fma}\left(y, y \cdot 0.16666666666666666, 1\right)\right)}{x}\\

\mathbf{elif}\;t\_0 \leq 10^{-6}:\\
\;\;\;\;\frac{\sin x}{x} \cdot \mathsf{fma}\left(y \cdot y, y \cdot 0.16666666666666666, y\right)\\

\mathbf{else}:\\
\;\;\;\;\sinh y \cdot 1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 (sin.f64 x) (sinh.f64 y)) x) < -inf.0

    1. Initial program 100.0%

      \[\frac{\sin x \cdot \sinh y}{x} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \frac{\color{blue}{y \cdot \left(\sin x + \frac{1}{6} \cdot \left({y}^{2} \cdot \sin x\right)\right)}}{x} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{y \cdot \left(\sin x + \frac{1}{6} \cdot \color{blue}{\left(\sin x \cdot {y}^{2}\right)}\right)}{x} \]
      2. associate-*r*N/A

        \[\leadsto \frac{y \cdot \left(\sin x + \color{blue}{\left(\frac{1}{6} \cdot \sin x\right) \cdot {y}^{2}}\right)}{x} \]
      3. lower-*.f64N/A

        \[\leadsto \frac{\color{blue}{y \cdot \left(\sin x + \left(\frac{1}{6} \cdot \sin x\right) \cdot {y}^{2}\right)}}{x} \]
      4. associate-*r*N/A

        \[\leadsto \frac{y \cdot \left(\sin x + \color{blue}{\frac{1}{6} \cdot \left(\sin x \cdot {y}^{2}\right)}\right)}{x} \]
      5. *-commutativeN/A

        \[\leadsto \frac{y \cdot \left(\sin x + \frac{1}{6} \cdot \color{blue}{\left({y}^{2} \cdot \sin x\right)}\right)}{x} \]
      6. *-lft-identityN/A

        \[\leadsto \frac{y \cdot \left(\color{blue}{1 \cdot \sin x} + \frac{1}{6} \cdot \left({y}^{2} \cdot \sin x\right)\right)}{x} \]
      7. associate-*r*N/A

        \[\leadsto \frac{y \cdot \left(1 \cdot \sin x + \color{blue}{\left(\frac{1}{6} \cdot {y}^{2}\right) \cdot \sin x}\right)}{x} \]
      8. distribute-rgt-inN/A

        \[\leadsto \frac{y \cdot \color{blue}{\left(\sin x \cdot \left(1 + \frac{1}{6} \cdot {y}^{2}\right)\right)}}{x} \]
      9. lower-*.f64N/A

        \[\leadsto \frac{y \cdot \color{blue}{\left(\sin x \cdot \left(1 + \frac{1}{6} \cdot {y}^{2}\right)\right)}}{x} \]
      10. lower-sin.f64N/A

        \[\leadsto \frac{y \cdot \left(\color{blue}{\sin x} \cdot \left(1 + \frac{1}{6} \cdot {y}^{2}\right)\right)}{x} \]
      11. +-commutativeN/A

        \[\leadsto \frac{y \cdot \left(\sin x \cdot \color{blue}{\left(\frac{1}{6} \cdot {y}^{2} + 1\right)}\right)}{x} \]
      12. unpow2N/A

        \[\leadsto \frac{y \cdot \left(\sin x \cdot \left(\frac{1}{6} \cdot \color{blue}{\left(y \cdot y\right)} + 1\right)\right)}{x} \]
      13. associate-*r*N/A

        \[\leadsto \frac{y \cdot \left(\sin x \cdot \left(\color{blue}{\left(\frac{1}{6} \cdot y\right) \cdot y} + 1\right)\right)}{x} \]
      14. *-commutativeN/A

        \[\leadsto \frac{y \cdot \left(\sin x \cdot \left(\color{blue}{y \cdot \left(\frac{1}{6} \cdot y\right)} + 1\right)\right)}{x} \]
      15. lower-fma.f64N/A

        \[\leadsto \frac{y \cdot \left(\sin x \cdot \color{blue}{\mathsf{fma}\left(y, \frac{1}{6} \cdot y, 1\right)}\right)}{x} \]
      16. *-commutativeN/A

        \[\leadsto \frac{y \cdot \left(\sin x \cdot \mathsf{fma}\left(y, \color{blue}{y \cdot \frac{1}{6}}, 1\right)\right)}{x} \]
      17. lower-*.f6468.9

        \[\leadsto \frac{y \cdot \left(\sin x \cdot \mathsf{fma}\left(y, \color{blue}{y \cdot 0.16666666666666666}, 1\right)\right)}{x} \]
    5. Applied rewrites68.9%

      \[\leadsto \frac{\color{blue}{y \cdot \left(\sin x \cdot \mathsf{fma}\left(y, y \cdot 0.16666666666666666, 1\right)\right)}}{x} \]
    6. Taylor expanded in x around 0

      \[\leadsto \frac{y \cdot \left(\left(x \cdot \left(1 + {x}^{2} \cdot \left({x}^{2} \cdot \left(\frac{1}{120} + \frac{-1}{5040} \cdot {x}^{2}\right) - \frac{1}{6}\right)\right)\right) \cdot \mathsf{fma}\left(\color{blue}{y}, y \cdot \frac{1}{6}, 1\right)\right)}{x} \]
    7. Step-by-step derivation
      1. Applied rewrites58.2%

        \[\leadsto \frac{y \cdot \left(\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, -0.0001984126984126984, 0.008333333333333333\right), -0.16666666666666666\right) \cdot x, x\right) \cdot \mathsf{fma}\left(\color{blue}{y}, y \cdot 0.16666666666666666, 1\right)\right)}{x} \]

      if -inf.0 < (/.f64 (*.f64 (sin.f64 x) (sinh.f64 y)) x) < 9.99999999999999955e-7

      1. Initial program 78.4%

        \[\frac{\sin x \cdot \sinh y}{x} \]
      2. Add Preprocessing
      3. Taylor expanded in y around 0

        \[\leadsto \color{blue}{y \cdot \left(\frac{1}{6} \cdot \frac{{y}^{2} \cdot \sin x}{x} + \frac{\sin x}{x}\right)} \]
      4. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto y \cdot \color{blue}{\left(\frac{\sin x}{x} + \frac{1}{6} \cdot \frac{{y}^{2} \cdot \sin x}{x}\right)} \]
        2. distribute-lft-inN/A

          \[\leadsto \color{blue}{y \cdot \frac{\sin x}{x} + y \cdot \left(\frac{1}{6} \cdot \frac{{y}^{2} \cdot \sin x}{x}\right)} \]
        3. associate-*r/N/A

          \[\leadsto y \cdot \frac{\sin x}{x} + y \cdot \color{blue}{\frac{\frac{1}{6} \cdot \left({y}^{2} \cdot \sin x\right)}{x}} \]
        4. *-commutativeN/A

          \[\leadsto y \cdot \frac{\sin x}{x} + y \cdot \frac{\frac{1}{6} \cdot \color{blue}{\left(\sin x \cdot {y}^{2}\right)}}{x} \]
        5. associate-*r*N/A

          \[\leadsto y \cdot \frac{\sin x}{x} + y \cdot \frac{\color{blue}{\left(\frac{1}{6} \cdot \sin x\right) \cdot {y}^{2}}}{x} \]
        6. associate-*r/N/A

          \[\leadsto y \cdot \frac{\sin x}{x} + \color{blue}{\frac{y \cdot \left(\left(\frac{1}{6} \cdot \sin x\right) \cdot {y}^{2}\right)}{x}} \]
        7. associate-*r*N/A

          \[\leadsto y \cdot \frac{\sin x}{x} + \frac{y \cdot \color{blue}{\left(\frac{1}{6} \cdot \left(\sin x \cdot {y}^{2}\right)\right)}}{x} \]
        8. *-commutativeN/A

          \[\leadsto y \cdot \frac{\sin x}{x} + \frac{y \cdot \left(\frac{1}{6} \cdot \color{blue}{\left({y}^{2} \cdot \sin x\right)}\right)}{x} \]
        9. associate-*r*N/A

          \[\leadsto y \cdot \frac{\sin x}{x} + \frac{y \cdot \color{blue}{\left(\left(\frac{1}{6} \cdot {y}^{2}\right) \cdot \sin x\right)}}{x} \]
        10. associate-*r*N/A

          \[\leadsto y \cdot \frac{\sin x}{x} + \frac{\color{blue}{\left(y \cdot \left(\frac{1}{6} \cdot {y}^{2}\right)\right) \cdot \sin x}}{x} \]
        11. associate-/l*N/A

          \[\leadsto y \cdot \frac{\sin x}{x} + \color{blue}{\left(y \cdot \left(\frac{1}{6} \cdot {y}^{2}\right)\right) \cdot \frac{\sin x}{x}} \]
        12. distribute-rgt-outN/A

          \[\leadsto \color{blue}{\frac{\sin x}{x} \cdot \left(y + y \cdot \left(\frac{1}{6} \cdot {y}^{2}\right)\right)} \]
        13. *-rgt-identityN/A

          \[\leadsto \frac{\sin x}{x} \cdot \left(\color{blue}{y \cdot 1} + y \cdot \left(\frac{1}{6} \cdot {y}^{2}\right)\right) \]
        14. distribute-lft-inN/A

          \[\leadsto \frac{\sin x}{x} \cdot \color{blue}{\left(y \cdot \left(1 + \frac{1}{6} \cdot {y}^{2}\right)\right)} \]
      5. Applied rewrites99.0%

        \[\leadsto \color{blue}{\frac{\sin x}{x} \cdot \mathsf{fma}\left(y \cdot y, y \cdot 0.16666666666666666, y\right)} \]

      if 9.99999999999999955e-7 < (/.f64 (*.f64 (sin.f64 x) (sinh.f64 y)) x)

      1. Initial program 100.0%

        \[\frac{\sin x \cdot \sinh y}{x} \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. lift-/.f64N/A

          \[\leadsto \color{blue}{\frac{\sin x \cdot \sinh y}{x}} \]
        2. lift-*.f64N/A

          \[\leadsto \frac{\color{blue}{\sin x \cdot \sinh y}}{x} \]
        3. associate-*l/N/A

          \[\leadsto \color{blue}{\frac{\sin x}{x} \cdot \sinh y} \]
        4. lower-*.f64N/A

          \[\leadsto \color{blue}{\frac{\sin x}{x} \cdot \sinh y} \]
        5. lower-/.f64100.0

          \[\leadsto \color{blue}{\frac{\sin x}{x}} \cdot \sinh y \]
      4. Applied rewrites100.0%

        \[\leadsto \color{blue}{\frac{\sin x}{x} \cdot \sinh y} \]
      5. Taylor expanded in x around 0

        \[\leadsto \color{blue}{1} \cdot \sinh y \]
      6. Step-by-step derivation
        1. Applied rewrites77.3%

          \[\leadsto \color{blue}{1} \cdot \sinh y \]
      7. Recombined 3 regimes into one program.
      8. Final simplification83.2%

        \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin x \cdot \sinh y}{x} \leq -\infty:\\ \;\;\;\;\frac{y \cdot \left(\mathsf{fma}\left(x \cdot x, x \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, -0.0001984126984126984, 0.008333333333333333\right), -0.16666666666666666\right), x\right) \cdot \mathsf{fma}\left(y, y \cdot 0.16666666666666666, 1\right)\right)}{x}\\ \mathbf{elif}\;\frac{\sin x \cdot \sinh y}{x} \leq 10^{-6}:\\ \;\;\;\;\frac{\sin x}{x} \cdot \mathsf{fma}\left(y \cdot y, y \cdot 0.16666666666666666, y\right)\\ \mathbf{else}:\\ \;\;\;\;\sinh y \cdot 1\\ \end{array} \]
      9. Add Preprocessing

      Developer Target 1: 99.8% accurate, 1.0× speedup?

      \[\begin{array}{l} \\ \sin x \cdot \frac{\sinh y}{x} \end{array} \]
      (FPCore (x y) :precision binary64 (* (sin x) (/ (sinh y) x)))
      double code(double x, double y) {
      	return sin(x) * (sinh(y) / x);
      }
      
      real(8) function code(x, y)
          real(8), intent (in) :: x
          real(8), intent (in) :: y
          code = sin(x) * (sinh(y) / x)
      end function
      
      public static double code(double x, double y) {
      	return Math.sin(x) * (Math.sinh(y) / x);
      }
      
      def code(x, y):
      	return math.sin(x) * (math.sinh(y) / x)
      
      function code(x, y)
      	return Float64(sin(x) * Float64(sinh(y) / x))
      end
      
      function tmp = code(x, y)
      	tmp = sin(x) * (sinh(y) / x);
      end
      
      code[x_, y_] := N[(N[Sin[x], $MachinePrecision] * N[(N[Sinh[y], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \sin x \cdot \frac{\sinh y}{x}
      \end{array}
      

      Reproduce

      ?
      herbie shell --seed 2024223 
      (FPCore (x y)
        :name "Linear.Quaternion:$ccosh from linear-1.19.1.3"
        :precision binary64
      
        :alt
        (! :herbie-platform default (* (sin x) (/ (sinh y) x)))
      
        (/ (* (sin x) (sinh y)) x))