Linear.Quaternion:$cexp from linear-1.19.1.3

Percentage Accurate: 99.8% → 99.8%
Time: 3.4s
Alternatives: 7
Speedup: 1.0×

Specification

?
\[x \cdot \frac{\sin y}{y} \]
(FPCore (x y)
  :precision binary64
  :pre TRUE
  (* x (/ (sin y) y)))
double code(double x, double y) {
	return x * (sin(y) / y);
}
real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = x * (sin(y) / y)
end function
public static double code(double x, double y) {
	return x * (Math.sin(y) / y);
}
def code(x, y):
	return x * (math.sin(y) / y)
function code(x, y)
	return Float64(x * Float64(sin(y) / y))
end
function tmp = code(x, y)
	tmp = x * (sin(y) / y);
end
code[x_, y_] := N[(x * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
f(x, y):
	x in [-inf, +inf],
	y in [-inf, +inf]
code: THEORY
BEGIN
f(x, y: real): real =
	x * ((sin(y)) / y)
END code
x \cdot \frac{\sin y}{y}

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 7 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: 99.8% accurate, 1.0× speedup?

\[x \cdot \frac{\sin y}{y} \]
(FPCore (x y)
  :precision binary64
  :pre TRUE
  (* x (/ (sin y) y)))
double code(double x, double y) {
	return x * (sin(y) / y);
}
real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = x * (sin(y) / y)
end function
public static double code(double x, double y) {
	return x * (Math.sin(y) / y);
}
def code(x, y):
	return x * (math.sin(y) / y)
function code(x, y)
	return Float64(x * Float64(sin(y) / y))
end
function tmp = code(x, y)
	tmp = x * (sin(y) / y);
end
code[x_, y_] := N[(x * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
f(x, y):
	x in [-inf, +inf],
	y in [-inf, +inf]
code: THEORY
BEGIN
f(x, y: real): real =
	x * ((sin(y)) / y)
END code
x \cdot \frac{\sin y}{y}

Alternative 1: 99.7% accurate, 0.5× speedup?

\[\begin{array}{l} \mathbf{if}\;\frac{\sin y}{y} \leq 0.9995:\\ \;\;\;\;\frac{x \cdot \sin y}{y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(y \cdot y, -0.16666666666666666, 1\right)\\ \end{array} \]
(FPCore (x y)
  :precision binary64
  :pre TRUE
  (if (<= (/ (sin y) y) 0.9995)
  (/ (* x (sin y)) y)
  (* x (fma (* y y) -0.16666666666666666 1.0))))
double code(double x, double y) {
	double tmp;
	if ((sin(y) / y) <= 0.9995) {
		tmp = (x * sin(y)) / y;
	} else {
		tmp = x * fma((y * y), -0.16666666666666666, 1.0);
	}
	return tmp;
}
function code(x, y)
	tmp = 0.0
	if (Float64(sin(y) / y) <= 0.9995)
		tmp = Float64(Float64(x * sin(y)) / y);
	else
		tmp = Float64(x * fma(Float64(y * y), -0.16666666666666666, 1.0));
	end
	return tmp
end
code[x_, y_] := If[LessEqual[N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], 0.9995], N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], N[(x * N[(N[(y * y), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision]), $MachinePrecision]]
f(x, y):
	x in [-inf, +inf],
	y in [-inf, +inf]
code: THEORY
BEGIN
f(x, y: real): real =
	LET tmp = IF (((sin(y)) / y) <= (9995000000000000550670620214077644050121307373046875e-52)) THEN ((x * (sin(y))) / y) ELSE (x * (((y * y) * (-1666666666666666574148081281236954964697360992431640625e-55)) + (1))) ENDIF IN
	tmp
END code
\begin{array}{l}
\mathbf{if}\;\frac{\sin y}{y} \leq 0.9995:\\
\;\;\;\;\frac{x \cdot \sin y}{y}\\

\mathbf{else}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(y \cdot y, -0.16666666666666666, 1\right)\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sin.f64 y) y) < 0.99950000000000006

    1. Initial program 99.8%

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

      \[\leadsto \frac{x \cdot \sin y}{y} \]
    3. Step-by-step derivation
      1. Applied rewrites88.8%

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

      if 0.99950000000000006 < (/.f64 (sin.f64 y) y)

      1. Initial program 99.8%

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

        \[\leadsto x \cdot \left(1 + \frac{-1}{6} \cdot {y}^{2}\right) \]
      3. Step-by-step derivation
        1. Applied rewrites50.5%

          \[\leadsto x \cdot \left(1 + -0.16666666666666666 \cdot {y}^{2}\right) \]
        2. Step-by-step derivation
          1. Applied rewrites50.5%

            \[\leadsto x \cdot \mathsf{fma}\left(y \cdot y, -0.16666666666666666, 1\right) \]
        3. Recombined 2 regimes into one program.
        4. Add Preprocessing

        Alternative 2: 63.4% accurate, 1.9× speedup?

        \[\begin{array}{l} \mathbf{if}\;\left|y\right| \leq 26110.61450005739:\\ \;\;\;\;x \cdot \left(\mathsf{fma}\left(-0.16666666666666666 \cdot \left|y\right|, \left|y\right|, 0.5\right) + 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(0.16666666666666666 \cdot \left|y\right|\right) \cdot \frac{\left|y\right|}{x}}\\ \end{array} \]
        (FPCore (x y)
          :precision binary64
          :pre TRUE
          (if (<= (fabs y) 26110.61450005739)
          (* x (+ (fma (* -0.16666666666666666 (fabs y)) (fabs y) 0.5) 0.5))
          (/ 1.0 (* (* 0.16666666666666666 (fabs y)) (/ (fabs y) x)))))
        double code(double x, double y) {
        	double tmp;
        	if (fabs(y) <= 26110.61450005739) {
        		tmp = x * (fma((-0.16666666666666666 * fabs(y)), fabs(y), 0.5) + 0.5);
        	} else {
        		tmp = 1.0 / ((0.16666666666666666 * fabs(y)) * (fabs(y) / x));
        	}
        	return tmp;
        }
        
        function code(x, y)
        	tmp = 0.0
        	if (abs(y) <= 26110.61450005739)
        		tmp = Float64(x * Float64(fma(Float64(-0.16666666666666666 * abs(y)), abs(y), 0.5) + 0.5));
        	else
        		tmp = Float64(1.0 / Float64(Float64(0.16666666666666666 * abs(y)) * Float64(abs(y) / x)));
        	end
        	return tmp
        end
        
        code[x_, y_] := If[LessEqual[N[Abs[y], $MachinePrecision], 26110.61450005739], N[(x * N[(N[(N[(-0.16666666666666666 * N[Abs[y], $MachinePrecision]), $MachinePrecision] * N[Abs[y], $MachinePrecision] + 0.5), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(0.16666666666666666 * N[Abs[y], $MachinePrecision]), $MachinePrecision] * N[(N[Abs[y], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
        
        f(x, y):
        	x in [-inf, +inf],
        	y in [-inf, +inf]
        code: THEORY
        BEGIN
        f(x, y: real): real =
        	LET tmp = IF ((abs(y)) <= (2611061450005738879553973674774169921875e-35)) THEN (x * (((((-1666666666666666574148081281236954964697360992431640625e-55) * (abs(y))) * (abs(y))) + (5e-1)) + (5e-1))) ELSE ((1) / (((1666666666666666574148081281236954964697360992431640625e-55) * (abs(y))) * ((abs(y)) / x))) ENDIF IN
        	tmp
        END code
        \begin{array}{l}
        \mathbf{if}\;\left|y\right| \leq 26110.61450005739:\\
        \;\;\;\;x \cdot \left(\mathsf{fma}\left(-0.16666666666666666 \cdot \left|y\right|, \left|y\right|, 0.5\right) + 0.5\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;\frac{1}{\left(0.16666666666666666 \cdot \left|y\right|\right) \cdot \frac{\left|y\right|}{x}}\\
        
        
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if y < 26110.614500057389

          1. Initial program 99.8%

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

            \[\leadsto x \cdot \left(1 + \frac{-1}{6} \cdot {y}^{2}\right) \]
          3. Step-by-step derivation
            1. Applied rewrites50.5%

              \[\leadsto x \cdot \left(1 + -0.16666666666666666 \cdot {y}^{2}\right) \]
            2. Step-by-step derivation
              1. Applied rewrites50.5%

                \[\leadsto x \cdot \left(\mathsf{fma}\left(-0.16666666666666666 \cdot y, y, 0.5\right) + 0.5\right) \]

              if 26110.614500057389 < y

              1. Initial program 99.8%

                \[x \cdot \frac{\sin y}{y} \]
              2. Step-by-step derivation
                1. Applied rewrites88.3%

                  \[\leadsto \frac{1}{\frac{y}{\sin y \cdot x}} \]
                2. Taylor expanded in y around 0

                  \[\leadsto \frac{1}{\frac{1}{6} \cdot \frac{{y}^{2}}{x} + \frac{1}{x}} \]
                3. Step-by-step derivation
                  1. Applied rewrites63.2%

                    \[\leadsto \frac{1}{\mathsf{fma}\left(0.16666666666666666, \frac{{y}^{2}}{x}, \frac{1}{x}\right)} \]
                  2. Taylor expanded in y around inf

                    \[\leadsto \frac{1}{\frac{1}{6} \cdot \frac{{y}^{2}}{x}} \]
                  3. Step-by-step derivation
                    1. Applied rewrites16.6%

                      \[\leadsto \frac{1}{0.16666666666666666 \cdot \frac{{y}^{2}}{x}} \]
                    2. Applied rewrites16.6%

                      \[\leadsto \frac{1}{\left(0.16666666666666666 \cdot y\right) \cdot \frac{y}{x}} \]
                  4. Recombined 2 regimes into one program.
                  5. Add Preprocessing

                  Alternative 3: 63.2% accurate, 0.9× speedup?

                  \[\begin{array}{l} \mathbf{if}\;\frac{\sin y}{y} \leq 3.1115210104175464 \cdot 10^{-119}:\\ \;\;\;\;0 \cdot 1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 1\\ \end{array} \]
                  (FPCore (x y)
                    :precision binary64
                    :pre TRUE
                    (if (<= (/ (sin y) y) 3.1115210104175464e-119) (* 0.0 1.0) (* x 1.0)))
                  double code(double x, double y) {
                  	double tmp;
                  	if ((sin(y) / y) <= 3.1115210104175464e-119) {
                  		tmp = 0.0 * 1.0;
                  	} else {
                  		tmp = x * 1.0;
                  	}
                  	return tmp;
                  }
                  
                  real(8) function code(x, y)
                  use fmin_fmax_functions
                      real(8), intent (in) :: x
                      real(8), intent (in) :: y
                      real(8) :: tmp
                      if ((sin(y) / y) <= 3.1115210104175464d-119) then
                          tmp = 0.0d0 * 1.0d0
                      else
                          tmp = x * 1.0d0
                      end if
                      code = tmp
                  end function
                  
                  public static double code(double x, double y) {
                  	double tmp;
                  	if ((Math.sin(y) / y) <= 3.1115210104175464e-119) {
                  		tmp = 0.0 * 1.0;
                  	} else {
                  		tmp = x * 1.0;
                  	}
                  	return tmp;
                  }
                  
                  def code(x, y):
                  	tmp = 0
                  	if (math.sin(y) / y) <= 3.1115210104175464e-119:
                  		tmp = 0.0 * 1.0
                  	else:
                  		tmp = x * 1.0
                  	return tmp
                  
                  function code(x, y)
                  	tmp = 0.0
                  	if (Float64(sin(y) / y) <= 3.1115210104175464e-119)
                  		tmp = Float64(0.0 * 1.0);
                  	else
                  		tmp = Float64(x * 1.0);
                  	end
                  	return tmp
                  end
                  
                  function tmp_2 = code(x, y)
                  	tmp = 0.0;
                  	if ((sin(y) / y) <= 3.1115210104175464e-119)
                  		tmp = 0.0 * 1.0;
                  	else
                  		tmp = x * 1.0;
                  	end
                  	tmp_2 = tmp;
                  end
                  
                  code[x_, y_] := If[LessEqual[N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], 3.1115210104175464e-119], N[(0.0 * 1.0), $MachinePrecision], N[(x * 1.0), $MachinePrecision]]
                  
                  f(x, y):
                  	x in [-inf, +inf],
                  	y in [-inf, +inf]
                  code: THEORY
                  BEGIN
                  f(x, y: real): real =
                  	LET tmp = IF (((sin(y)) / y) <= (311152101041754642290024565439875431740613962063175481148591194442996388678289957470708513147988336046540112239599631655494021672392081353289379760901846390424021238903116260518260409730045459215395629766697200463532105992136490754611180397706904128805760152687370442659154707830946630375823502845378243364393711090087890625e-442)) THEN ((0) * (1)) ELSE (x * (1)) ENDIF IN
                  	tmp
                  END code
                  \begin{array}{l}
                  \mathbf{if}\;\frac{\sin y}{y} \leq 3.1115210104175464 \cdot 10^{-119}:\\
                  \;\;\;\;0 \cdot 1\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;x \cdot 1\\
                  
                  
                  \end{array}
                  
                  Derivation
                  1. Split input into 2 regimes
                  2. if (/.f64 (sin.f64 y) y) < 3.1115210104175464e-119

                    1. Initial program 99.8%

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

                      \[\leadsto x \cdot 1 \]
                    3. Step-by-step derivation
                      1. Applied rewrites51.2%

                        \[\leadsto x \cdot 1 \]
                      2. Taylor expanded in undef-var around zero

                        \[\leadsto 0 \cdot 1 \]
                      3. Step-by-step derivation
                        1. Applied rewrites15.8%

                          \[\leadsto 0 \cdot 1 \]

                        if 3.1115210104175464e-119 < (/.f64 (sin.f64 y) y)

                        1. Initial program 99.8%

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

                          \[\leadsto x \cdot 1 \]
                        3. Step-by-step derivation
                          1. Applied rewrites51.2%

                            \[\leadsto x \cdot 1 \]
                        4. Recombined 2 regimes into one program.
                        5. Add Preprocessing

                        Alternative 4: 63.2% accurate, 2.0× speedup?

                        \[\frac{1}{\mathsf{fma}\left(0.16666666666666666 \cdot y, \frac{y}{x}, \frac{1}{x}\right)} \]
                        (FPCore (x y)
                          :precision binary64
                          :pre TRUE
                          (/ 1.0 (fma (* 0.16666666666666666 y) (/ y x) (/ 1.0 x))))
                        double code(double x, double y) {
                        	return 1.0 / fma((0.16666666666666666 * y), (y / x), (1.0 / x));
                        }
                        
                        function code(x, y)
                        	return Float64(1.0 / fma(Float64(0.16666666666666666 * y), Float64(y / x), Float64(1.0 / x)))
                        end
                        
                        code[x_, y_] := N[(1.0 / N[(N[(0.16666666666666666 * y), $MachinePrecision] * N[(y / x), $MachinePrecision] + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
                        
                        f(x, y):
                        	x in [-inf, +inf],
                        	y in [-inf, +inf]
                        code: THEORY
                        BEGIN
                        f(x, y: real): real =
                        	(1) / ((((1666666666666666574148081281236954964697360992431640625e-55) * y) * (y / x)) + ((1) / x))
                        END code
                        \frac{1}{\mathsf{fma}\left(0.16666666666666666 \cdot y, \frac{y}{x}, \frac{1}{x}\right)}
                        
                        Derivation
                        1. Initial program 99.8%

                          \[x \cdot \frac{\sin y}{y} \]
                        2. Step-by-step derivation
                          1. Applied rewrites88.3%

                            \[\leadsto \frac{1}{\frac{y}{\sin y \cdot x}} \]
                          2. Taylor expanded in y around 0

                            \[\leadsto \frac{1}{\frac{1}{6} \cdot \frac{{y}^{2}}{x} + \frac{1}{x}} \]
                          3. Step-by-step derivation
                            1. Applied rewrites63.2%

                              \[\leadsto \frac{1}{\mathsf{fma}\left(0.16666666666666666, \frac{{y}^{2}}{x}, \frac{1}{x}\right)} \]
                            2. Applied rewrites63.2%

                              \[\leadsto \frac{1}{\mathsf{fma}\left(0.16666666666666666 \cdot y, \frac{y}{x}, \frac{1}{x}\right)} \]
                            3. Add Preprocessing

                            Alternative 5: 62.4% accurate, 2.5× speedup?

                            \[\frac{1}{\frac{\mathsf{fma}\left(y \cdot y, 0.16666666666666666, 1\right)}{x}} \]
                            (FPCore (x y)
                              :precision binary64
                              :pre TRUE
                              (/ 1.0 (/ (fma (* y y) 0.16666666666666666 1.0) x)))
                            double code(double x, double y) {
                            	return 1.0 / (fma((y * y), 0.16666666666666666, 1.0) / x);
                            }
                            
                            function code(x, y)
                            	return Float64(1.0 / Float64(fma(Float64(y * y), 0.16666666666666666, 1.0) / x))
                            end
                            
                            code[x_, y_] := N[(1.0 / N[(N[(N[(y * y), $MachinePrecision] * 0.16666666666666666 + 1.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
                            
                            f(x, y):
                            	x in [-inf, +inf],
                            	y in [-inf, +inf]
                            code: THEORY
                            BEGIN
                            f(x, y: real): real =
                            	(1) / ((((y * y) * (1666666666666666574148081281236954964697360992431640625e-55)) + (1)) / x)
                            END code
                            \frac{1}{\frac{\mathsf{fma}\left(y \cdot y, 0.16666666666666666, 1\right)}{x}}
                            
                            Derivation
                            1. Initial program 99.8%

                              \[x \cdot \frac{\sin y}{y} \]
                            2. Step-by-step derivation
                              1. Applied rewrites88.3%

                                \[\leadsto \frac{1}{\frac{y}{\sin y \cdot x}} \]
                              2. Taylor expanded in y around 0

                                \[\leadsto \frac{1}{\frac{1}{6} \cdot \frac{{y}^{2}}{x} + \frac{1}{x}} \]
                              3. Step-by-step derivation
                                1. Applied rewrites63.2%

                                  \[\leadsto \frac{1}{\mathsf{fma}\left(0.16666666666666666, \frac{{y}^{2}}{x}, \frac{1}{x}\right)} \]
                                2. Step-by-step derivation
                                  1. Applied rewrites63.2%

                                    \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(y \cdot y, 0.16666666666666666, 1\right)}{x}} \]
                                  2. Add Preprocessing

                                  Alternative 6: 51.2% accurate, 10.3× speedup?

                                  \[x \cdot 1 \]
                                  (FPCore (x y)
                                    :precision binary64
                                    :pre TRUE
                                    (* x 1.0))
                                  double code(double x, double y) {
                                  	return x * 1.0;
                                  }
                                  
                                  real(8) function code(x, y)
                                  use fmin_fmax_functions
                                      real(8), intent (in) :: x
                                      real(8), intent (in) :: y
                                      code = x * 1.0d0
                                  end function
                                  
                                  public static double code(double x, double y) {
                                  	return x * 1.0;
                                  }
                                  
                                  def code(x, y):
                                  	return x * 1.0
                                  
                                  function code(x, y)
                                  	return Float64(x * 1.0)
                                  end
                                  
                                  function tmp = code(x, y)
                                  	tmp = x * 1.0;
                                  end
                                  
                                  code[x_, y_] := N[(x * 1.0), $MachinePrecision]
                                  
                                  f(x, y):
                                  	x in [-inf, +inf],
                                  	y in [-inf, +inf]
                                  code: THEORY
                                  BEGIN
                                  f(x, y: real): real =
                                  	x * (1)
                                  END code
                                  x \cdot 1
                                  
                                  Derivation
                                  1. Initial program 99.8%

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

                                    \[\leadsto x \cdot 1 \]
                                  3. Step-by-step derivation
                                    1. Applied rewrites51.2%

                                      \[\leadsto x \cdot 1 \]
                                    2. Add Preprocessing

                                    Reproduce

                                    ?
                                    herbie shell --seed 2026092 
                                    (FPCore (x y)
                                      :name "Linear.Quaternion:$cexp from linear-1.19.1.3"
                                      :precision binary64
                                      (* x (/ (sin y) y)))