VandenBroeck and Keller, Equation (24)

Percentage Accurate: 99.7% → 99.8%
Time: 8.5s
Alternatives: 13
Speedup: 1.1×

Specification

?
\[\begin{array}{l} \\ \left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \end{array} \]
(FPCore (B x)
 :precision binary64
 (+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))
double code(double B, double x) {
	return -(x * (1.0 / tan(B))) + (1.0 / sin(B));
}
real(8) function code(b, x)
    real(8), intent (in) :: b
    real(8), intent (in) :: x
    code = -(x * (1.0d0 / tan(b))) + (1.0d0 / sin(b))
end function
public static double code(double B, double x) {
	return -(x * (1.0 / Math.tan(B))) + (1.0 / Math.sin(B));
}
def code(B, x):
	return -(x * (1.0 / math.tan(B))) + (1.0 / math.sin(B))
function code(B, x)
	return Float64(Float64(-Float64(x * Float64(1.0 / tan(B)))) + Float64(1.0 / sin(B)))
end
function tmp = code(B, x)
	tmp = -(x * (1.0 / tan(B))) + (1.0 / sin(B));
end
code[B_, x_] := N[((-N[(x * N[(1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]) + N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B}
\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 13 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.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \end{array} \]
(FPCore (B x)
 :precision binary64
 (+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))
double code(double B, double x) {
	return -(x * (1.0 / tan(B))) + (1.0 / sin(B));
}
real(8) function code(b, x)
    real(8), intent (in) :: b
    real(8), intent (in) :: x
    code = -(x * (1.0d0 / tan(b))) + (1.0d0 / sin(b))
end function
public static double code(double B, double x) {
	return -(x * (1.0 / Math.tan(B))) + (1.0 / Math.sin(B));
}
def code(B, x):
	return -(x * (1.0 / math.tan(B))) + (1.0 / math.sin(B))
function code(B, x)
	return Float64(Float64(-Float64(x * Float64(1.0 / tan(B)))) + Float64(1.0 / sin(B)))
end
function tmp = code(B, x)
	tmp = -(x * (1.0 / tan(B))) + (1.0 / sin(B));
end
code[B_, x_] := N[((-N[(x * N[(1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]) + N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B}
\end{array}

Alternative 1: 99.8% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \frac{-x}{\tan B} + {\sin B}^{-1} \end{array} \]
(FPCore (B x) :precision binary64 (+ (/ (- x) (tan B)) (pow (sin B) -1.0)))
double code(double B, double x) {
	return (-x / tan(B)) + pow(sin(B), -1.0);
}
real(8) function code(b, x)
    real(8), intent (in) :: b
    real(8), intent (in) :: x
    code = (-x / tan(b)) + (sin(b) ** (-1.0d0))
end function
public static double code(double B, double x) {
	return (-x / Math.tan(B)) + Math.pow(Math.sin(B), -1.0);
}
def code(B, x):
	return (-x / math.tan(B)) + math.pow(math.sin(B), -1.0)
function code(B, x)
	return Float64(Float64(Float64(-x) / tan(B)) + (sin(B) ^ -1.0))
end
function tmp = code(B, x)
	tmp = (-x / tan(B)) + (sin(B) ^ -1.0);
end
code[B_, x_] := N[(N[((-x) / N[Tan[B], $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[B], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{-x}{\tan B} + {\sin B}^{-1}
\end{array}
Derivation
  1. Initial program 99.7%

    \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \left(-\color{blue}{x \cdot \frac{1}{\tan B}}\right) + \frac{1}{\sin B} \]
    2. lift-/.f64N/A

      \[\leadsto \left(-x \cdot \color{blue}{\frac{1}{\tan B}}\right) + \frac{1}{\sin B} \]
    3. un-div-invN/A

      \[\leadsto \left(-\color{blue}{\frac{x}{\tan B}}\right) + \frac{1}{\sin B} \]
    4. lower-/.f6499.8

      \[\leadsto \left(-\color{blue}{\frac{x}{\tan B}}\right) + \frac{1}{\sin B} \]
  4. Applied rewrites99.8%

    \[\leadsto \left(-\color{blue}{\frac{x}{\tan B}}\right) + \frac{1}{\sin B} \]
  5. Final simplification99.8%

    \[\leadsto \frac{-x}{\tan B} + {\sin B}^{-1} \]
  6. Add Preprocessing

Alternative 2: 98.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.08 \lor \neg \left(x \leq 0.00049\right):\\ \;\;\;\;\frac{-x}{\tan B} + {B}^{-1}\\ \mathbf{else}:\\ \;\;\;\;\left(-\frac{x}{B}\right) + {\sin B}^{-1}\\ \end{array} \end{array} \]
(FPCore (B x)
 :precision binary64
 (if (or (<= x -1.08) (not (<= x 0.00049)))
   (+ (/ (- x) (tan B)) (pow B -1.0))
   (+ (- (/ x B)) (pow (sin B) -1.0))))
double code(double B, double x) {
	double tmp;
	if ((x <= -1.08) || !(x <= 0.00049)) {
		tmp = (-x / tan(B)) + pow(B, -1.0);
	} else {
		tmp = -(x / B) + pow(sin(B), -1.0);
	}
	return tmp;
}
real(8) function code(b, x)
    real(8), intent (in) :: b
    real(8), intent (in) :: x
    real(8) :: tmp
    if ((x <= (-1.08d0)) .or. (.not. (x <= 0.00049d0))) then
        tmp = (-x / tan(b)) + (b ** (-1.0d0))
    else
        tmp = -(x / b) + (sin(b) ** (-1.0d0))
    end if
    code = tmp
end function
public static double code(double B, double x) {
	double tmp;
	if ((x <= -1.08) || !(x <= 0.00049)) {
		tmp = (-x / Math.tan(B)) + Math.pow(B, -1.0);
	} else {
		tmp = -(x / B) + Math.pow(Math.sin(B), -1.0);
	}
	return tmp;
}
def code(B, x):
	tmp = 0
	if (x <= -1.08) or not (x <= 0.00049):
		tmp = (-x / math.tan(B)) + math.pow(B, -1.0)
	else:
		tmp = -(x / B) + math.pow(math.sin(B), -1.0)
	return tmp
function code(B, x)
	tmp = 0.0
	if ((x <= -1.08) || !(x <= 0.00049))
		tmp = Float64(Float64(Float64(-x) / tan(B)) + (B ^ -1.0));
	else
		tmp = Float64(Float64(-Float64(x / B)) + (sin(B) ^ -1.0));
	end
	return tmp
end
function tmp_2 = code(B, x)
	tmp = 0.0;
	if ((x <= -1.08) || ~((x <= 0.00049)))
		tmp = (-x / tan(B)) + (B ^ -1.0);
	else
		tmp = -(x / B) + (sin(B) ^ -1.0);
	end
	tmp_2 = tmp;
end
code[B_, x_] := If[Or[LessEqual[x, -1.08], N[Not[LessEqual[x, 0.00049]], $MachinePrecision]], N[(N[((-x) / N[Tan[B], $MachinePrecision]), $MachinePrecision] + N[Power[B, -1.0], $MachinePrecision]), $MachinePrecision], N[((-N[(x / B), $MachinePrecision]) + N[Power[N[Sin[B], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.08 \lor \neg \left(x \leq 0.00049\right):\\
\;\;\;\;\frac{-x}{\tan B} + {B}^{-1}\\

\mathbf{else}:\\
\;\;\;\;\left(-\frac{x}{B}\right) + {\sin B}^{-1}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.0800000000000001 or 4.8999999999999998e-4 < x

    1. Initial program 99.6%

      \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \left(-\color{blue}{x \cdot \frac{1}{\tan B}}\right) + \frac{1}{\sin B} \]
      2. lift-/.f64N/A

        \[\leadsto \left(-x \cdot \color{blue}{\frac{1}{\tan B}}\right) + \frac{1}{\sin B} \]
      3. un-div-invN/A

        \[\leadsto \left(-\color{blue}{\frac{x}{\tan B}}\right) + \frac{1}{\sin B} \]
      4. lower-/.f6499.8

        \[\leadsto \left(-\color{blue}{\frac{x}{\tan B}}\right) + \frac{1}{\sin B} \]
    4. Applied rewrites99.8%

      \[\leadsto \left(-\color{blue}{\frac{x}{\tan B}}\right) + \frac{1}{\sin B} \]
    5. Taylor expanded in B around 0

      \[\leadsto \left(-\frac{x}{\tan B}\right) + \color{blue}{\frac{1}{B}} \]
    6. Step-by-step derivation
      1. lower-/.f6497.9

        \[\leadsto \left(-\frac{x}{\tan B}\right) + \color{blue}{\frac{1}{B}} \]
    7. Applied rewrites97.9%

      \[\leadsto \left(-\frac{x}{\tan B}\right) + \color{blue}{\frac{1}{B}} \]

    if -1.0800000000000001 < x < 4.8999999999999998e-4

    1. Initial program 99.8%

      \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
    2. Add Preprocessing
    3. Taylor expanded in B around 0

      \[\leadsto \left(-\color{blue}{\frac{x}{B}}\right) + \frac{1}{\sin B} \]
    4. Step-by-step derivation
      1. lower-/.f6499.1

        \[\leadsto \left(-\color{blue}{\frac{x}{B}}\right) + \frac{1}{\sin B} \]
    5. Applied rewrites99.1%

      \[\leadsto \left(-\color{blue}{\frac{x}{B}}\right) + \frac{1}{\sin B} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.08 \lor \neg \left(x \leq 0.00049\right):\\ \;\;\;\;\frac{-x}{\tan B} + {B}^{-1}\\ \mathbf{else}:\\ \;\;\;\;\left(-\frac{x}{B}\right) + {\sin B}^{-1}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 58.1% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;B \leq 0.0035:\\ \;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.022222222222222223, x, 0.019444444444444445\right) \cdot B, B, \mathsf{fma}\left(0.3333333333333333, x, 0.16666666666666666\right)\right), B \cdot B, 1 - x\right)}{B}\\ \mathbf{else}:\\ \;\;\;\;\left(0.3333333333333333 \cdot B\right) \cdot x + {\sin B}^{-1}\\ \end{array} \end{array} \]
(FPCore (B x)
 :precision binary64
 (if (<= B 0.0035)
   (/
    (fma
     (fma
      (* (fma 0.022222222222222223 x 0.019444444444444445) B)
      B
      (fma 0.3333333333333333 x 0.16666666666666666))
     (* B B)
     (- 1.0 x))
    B)
   (+ (* (* 0.3333333333333333 B) x) (pow (sin B) -1.0))))
double code(double B, double x) {
	double tmp;
	if (B <= 0.0035) {
		tmp = fma(fma((fma(0.022222222222222223, x, 0.019444444444444445) * B), B, fma(0.3333333333333333, x, 0.16666666666666666)), (B * B), (1.0 - x)) / B;
	} else {
		tmp = ((0.3333333333333333 * B) * x) + pow(sin(B), -1.0);
	}
	return tmp;
}
function code(B, x)
	tmp = 0.0
	if (B <= 0.0035)
		tmp = Float64(fma(fma(Float64(fma(0.022222222222222223, x, 0.019444444444444445) * B), B, fma(0.3333333333333333, x, 0.16666666666666666)), Float64(B * B), Float64(1.0 - x)) / B);
	else
		tmp = Float64(Float64(Float64(0.3333333333333333 * B) * x) + (sin(B) ^ -1.0));
	end
	return tmp
end
code[B_, x_] := If[LessEqual[B, 0.0035], N[(N[(N[(N[(N[(0.022222222222222223 * x + 0.019444444444444445), $MachinePrecision] * B), $MachinePrecision] * B + N[(0.3333333333333333 * x + 0.16666666666666666), $MachinePrecision]), $MachinePrecision] * N[(B * B), $MachinePrecision] + N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / B), $MachinePrecision], N[(N[(N[(0.3333333333333333 * B), $MachinePrecision] * x), $MachinePrecision] + N[Power[N[Sin[B], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;B \leq 0.0035:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.022222222222222223, x, 0.019444444444444445\right) \cdot B, B, \mathsf{fma}\left(0.3333333333333333, x, 0.16666666666666666\right)\right), B \cdot B, 1 - x\right)}{B}\\

\mathbf{else}:\\
\;\;\;\;\left(0.3333333333333333 \cdot B\right) \cdot x + {\sin B}^{-1}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if B < 0.00350000000000000007

    1. Initial program 99.8%

      \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \left(-\color{blue}{x \cdot \frac{1}{\tan B}}\right) + \frac{1}{\sin B} \]
      2. lift-/.f64N/A

        \[\leadsto \left(-x \cdot \color{blue}{\frac{1}{\tan B}}\right) + \frac{1}{\sin B} \]
      3. un-div-invN/A

        \[\leadsto \left(-\color{blue}{\frac{x}{\tan B}}\right) + \frac{1}{\sin B} \]
      4. lift-tan.f64N/A

        \[\leadsto \left(-\frac{x}{\color{blue}{\tan B}}\right) + \frac{1}{\sin B} \]
      5. tan-quotN/A

        \[\leadsto \left(-\frac{x}{\color{blue}{\frac{\sin B}{\cos B}}}\right) + \frac{1}{\sin B} \]
      6. lift-sin.f64N/A

        \[\leadsto \left(-\frac{x}{\frac{\color{blue}{\sin B}}{\cos B}}\right) + \frac{1}{\sin B} \]
      7. associate-/r/N/A

        \[\leadsto \left(-\color{blue}{\frac{x}{\sin B} \cdot \cos B}\right) + \frac{1}{\sin B} \]
      8. associate-*l/N/A

        \[\leadsto \left(-\color{blue}{\frac{x \cdot \cos B}{\sin B}}\right) + \frac{1}{\sin B} \]
      9. lower-/.f64N/A

        \[\leadsto \left(-\color{blue}{\frac{x \cdot \cos B}{\sin B}}\right) + \frac{1}{\sin B} \]
      10. lower-*.f64N/A

        \[\leadsto \left(-\frac{\color{blue}{x \cdot \cos B}}{\sin B}\right) + \frac{1}{\sin B} \]
      11. lower-cos.f6499.8

        \[\leadsto \left(-\frac{x \cdot \color{blue}{\cos B}}{\sin B}\right) + \frac{1}{\sin B} \]
    4. Applied rewrites99.8%

      \[\leadsto \left(-\color{blue}{\frac{x \cdot \cos B}{\sin B}}\right) + \frac{1}{\sin B} \]
    5. Taylor expanded in B around 0

      \[\leadsto \color{blue}{\frac{\left(1 + {B}^{2} \cdot \left(\left(\frac{1}{6} + \left(\frac{-1}{6} \cdot x + {B}^{2} \cdot \left(\left(\frac{7}{360} + \left(\frac{-1}{6} \cdot \left(\frac{-1}{2} \cdot x - \frac{-1}{6} \cdot x\right) + \frac{1}{120} \cdot x\right)\right) - \frac{1}{24} \cdot x\right)\right)\right) - \frac{-1}{2} \cdot x\right)\right) - x}{B}} \]
    6. Applied rewrites64.4%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.022222222222222223, x, 0.019444444444444445\right) \cdot B, B, \mathsf{fma}\left(0.3333333333333333, x, 0.16666666666666666\right)\right), B \cdot B, 1 - x\right)}{B}} \]

    if 0.00350000000000000007 < B

    1. Initial program 99.5%

      \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
    2. Add Preprocessing
    3. Taylor expanded in B around 0

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

        \[\leadsto \color{blue}{\left(\frac{\frac{1}{3} \cdot \left({B}^{2} \cdot x\right)}{B} - \frac{x}{B}\right)} + \frac{1}{\sin B} \]
      2. sub-negN/A

        \[\leadsto \color{blue}{\left(\frac{\frac{1}{3} \cdot \left({B}^{2} \cdot x\right)}{B} + \left(\mathsf{neg}\left(\frac{x}{B}\right)\right)\right)} + \frac{1}{\sin B} \]
      3. mul-1-negN/A

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

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

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

        \[\leadsto \left(\frac{\color{blue}{\left(B \cdot B\right)} \cdot x}{B} \cdot \frac{1}{3} + -1 \cdot \frac{x}{B}\right) + \frac{1}{\sin B} \]
      7. associate-*l*N/A

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

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

        \[\leadsto \left(\left(B \cdot \frac{\color{blue}{x \cdot B}}{B}\right) \cdot \frac{1}{3} + -1 \cdot \frac{x}{B}\right) + \frac{1}{\sin B} \]
      10. associate-/l*N/A

        \[\leadsto \left(\left(B \cdot \color{blue}{\left(x \cdot \frac{B}{B}\right)}\right) \cdot \frac{1}{3} + -1 \cdot \frac{x}{B}\right) + \frac{1}{\sin B} \]
      11. *-inversesN/A

        \[\leadsto \left(\left(B \cdot \left(x \cdot \color{blue}{1}\right)\right) \cdot \frac{1}{3} + -1 \cdot \frac{x}{B}\right) + \frac{1}{\sin B} \]
      12. *-rgt-identityN/A

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(B \cdot x, \frac{1}{3}, -1 \cdot \frac{x}{B}\right)} + \frac{1}{\sin B} \]
      14. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{B \cdot x}, \frac{1}{3}, -1 \cdot \frac{x}{B}\right) + \frac{1}{\sin B} \]
      15. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(B \cdot x, \frac{1}{3}, \color{blue}{\mathsf{neg}\left(\frac{x}{B}\right)}\right) + \frac{1}{\sin B} \]
      16. distribute-neg-fracN/A

        \[\leadsto \mathsf{fma}\left(B \cdot x, \frac{1}{3}, \color{blue}{\frac{\mathsf{neg}\left(x\right)}{B}}\right) + \frac{1}{\sin B} \]
      17. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(B \cdot x, \frac{1}{3}, \color{blue}{\frac{\mathsf{neg}\left(x\right)}{B}}\right) + \frac{1}{\sin B} \]
      18. lower-neg.f6429.1

        \[\leadsto \mathsf{fma}\left(B \cdot x, 0.3333333333333333, \frac{\color{blue}{-x}}{B}\right) + \frac{1}{\sin B} \]
    5. Applied rewrites29.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(B \cdot x, 0.3333333333333333, \frac{-x}{B}\right)} + \frac{1}{\sin B} \]
    6. Taylor expanded in B around inf

      \[\leadsto \frac{1}{3} \cdot \color{blue}{\left(B \cdot x\right)} + \frac{1}{\sin B} \]
    7. Step-by-step derivation
      1. Applied rewrites29.1%

        \[\leadsto \left(0.3333333333333333 \cdot B\right) \cdot \color{blue}{x} + \frac{1}{\sin B} \]
    8. Recombined 2 regimes into one program.
    9. Final simplification55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;B \leq 0.0035:\\ \;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.022222222222222223, x, 0.019444444444444445\right) \cdot B, B, \mathsf{fma}\left(0.3333333333333333, x, 0.16666666666666666\right)\right), B \cdot B, 1 - x\right)}{B}\\ \mathbf{else}:\\ \;\;\;\;\left(0.3333333333333333 \cdot B\right) \cdot x + {\sin B}^{-1}\\ \end{array} \]
    10. Add Preprocessing

    Alternative 4: 99.8% accurate, 1.1× speedup?

    \[\begin{array}{l} \\ \frac{1 - \cos B \cdot x}{\sin B} \end{array} \]
    (FPCore (B x) :precision binary64 (/ (- 1.0 (* (cos B) x)) (sin B)))
    double code(double B, double x) {
    	return (1.0 - (cos(B) * x)) / sin(B);
    }
    
    real(8) function code(b, x)
        real(8), intent (in) :: b
        real(8), intent (in) :: x
        code = (1.0d0 - (cos(b) * x)) / sin(b)
    end function
    
    public static double code(double B, double x) {
    	return (1.0 - (Math.cos(B) * x)) / Math.sin(B);
    }
    
    def code(B, x):
    	return (1.0 - (math.cos(B) * x)) / math.sin(B)
    
    function code(B, x)
    	return Float64(Float64(1.0 - Float64(cos(B) * x)) / sin(B))
    end
    
    function tmp = code(B, x)
    	tmp = (1.0 - (cos(B) * x)) / sin(B);
    end
    
    code[B_, x_] := N[(N[(1.0 - N[(N[Cos[B], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \frac{1 - \cos B \cdot x}{\sin B}
    \end{array}
    
    Derivation
    1. Initial program 99.7%

      \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \left(-\color{blue}{x \cdot \frac{1}{\tan B}}\right) + \frac{1}{\sin B} \]
      2. lift-/.f64N/A

        \[\leadsto \left(-x \cdot \color{blue}{\frac{1}{\tan B}}\right) + \frac{1}{\sin B} \]
      3. un-div-invN/A

        \[\leadsto \left(-\color{blue}{\frac{x}{\tan B}}\right) + \frac{1}{\sin B} \]
      4. lower-/.f6499.8

        \[\leadsto \left(-\color{blue}{\frac{x}{\tan B}}\right) + \frac{1}{\sin B} \]
    4. Applied rewrites99.8%

      \[\leadsto \left(-\color{blue}{\frac{x}{\tan B}}\right) + \frac{1}{\sin B} \]
    5. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(-\frac{x}{\tan B}\right) + \frac{1}{\sin B}} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\frac{1}{\sin B} + \left(-\frac{x}{\tan B}\right)} \]
      3. lift-neg.f64N/A

        \[\leadsto \frac{1}{\sin B} + \color{blue}{\left(\mathsf{neg}\left(\frac{x}{\tan B}\right)\right)} \]
      4. unsub-negN/A

        \[\leadsto \color{blue}{\frac{1}{\sin B} - \frac{x}{\tan B}} \]
      5. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{1}{\sin B}} - \frac{x}{\tan B} \]
      6. lift-/.f64N/A

        \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{x}{\tan B}} \]
      7. div-invN/A

        \[\leadsto \frac{1}{\sin B} - \color{blue}{x \cdot \frac{1}{\tan B}} \]
      8. lift-tan.f64N/A

        \[\leadsto \frac{1}{\sin B} - x \cdot \frac{1}{\color{blue}{\tan B}} \]
      9. tan-quotN/A

        \[\leadsto \frac{1}{\sin B} - x \cdot \frac{1}{\color{blue}{\frac{\sin B}{\cos B}}} \]
      10. lift-sin.f64N/A

        \[\leadsto \frac{1}{\sin B} - x \cdot \frac{1}{\frac{\color{blue}{\sin B}}{\cos B}} \]
      11. lift-cos.f64N/A

        \[\leadsto \frac{1}{\sin B} - x \cdot \frac{1}{\frac{\sin B}{\color{blue}{\cos B}}} \]
      12. clear-numN/A

        \[\leadsto \frac{1}{\sin B} - x \cdot \color{blue}{\frac{\cos B}{\sin B}} \]
      13. associate-/l*N/A

        \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{x \cdot \cos B}{\sin B}} \]
      14. lift-*.f64N/A

        \[\leadsto \frac{1}{\sin B} - \frac{\color{blue}{x \cdot \cos B}}{\sin B} \]
      15. sub-divN/A

        \[\leadsto \color{blue}{\frac{1 - x \cdot \cos B}{\sin B}} \]
      16. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1 - x \cdot \cos B}{\sin B}} \]
      17. lower--.f6499.7

        \[\leadsto \frac{\color{blue}{1 - x \cdot \cos B}}{\sin B} \]
      18. lift-*.f64N/A

        \[\leadsto \frac{1 - \color{blue}{x \cdot \cos B}}{\sin B} \]
      19. *-commutativeN/A

        \[\leadsto \frac{1 - \color{blue}{\cos B \cdot x}}{\sin B} \]
      20. lower-*.f6499.7

        \[\leadsto \frac{1 - \color{blue}{\cos B \cdot x}}{\sin B} \]
    6. Applied rewrites99.7%

      \[\leadsto \color{blue}{\frac{1 - \cos B \cdot x}{\sin B}} \]
    7. Add Preprocessing

    Alternative 5: 75.7% accurate, 1.1× speedup?

    \[\begin{array}{l} \\ \left(-\frac{x}{B}\right) + {\sin B}^{-1} \end{array} \]
    (FPCore (B x) :precision binary64 (+ (- (/ x B)) (pow (sin B) -1.0)))
    double code(double B, double x) {
    	return -(x / B) + pow(sin(B), -1.0);
    }
    
    real(8) function code(b, x)
        real(8), intent (in) :: b
        real(8), intent (in) :: x
        code = -(x / b) + (sin(b) ** (-1.0d0))
    end function
    
    public static double code(double B, double x) {
    	return -(x / B) + Math.pow(Math.sin(B), -1.0);
    }
    
    def code(B, x):
    	return -(x / B) + math.pow(math.sin(B), -1.0)
    
    function code(B, x)
    	return Float64(Float64(-Float64(x / B)) + (sin(B) ^ -1.0))
    end
    
    function tmp = code(B, x)
    	tmp = -(x / B) + (sin(B) ^ -1.0);
    end
    
    code[B_, x_] := N[((-N[(x / B), $MachinePrecision]) + N[Power[N[Sin[B], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \left(-\frac{x}{B}\right) + {\sin B}^{-1}
    \end{array}
    
    Derivation
    1. Initial program 99.7%

      \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
    2. Add Preprocessing
    3. Taylor expanded in B around 0

      \[\leadsto \left(-\color{blue}{\frac{x}{B}}\right) + \frac{1}{\sin B} \]
    4. Step-by-step derivation
      1. lower-/.f6474.7

        \[\leadsto \left(-\color{blue}{\frac{x}{B}}\right) + \frac{1}{\sin B} \]
    5. Applied rewrites74.7%

      \[\leadsto \left(-\color{blue}{\frac{x}{B}}\right) + \frac{1}{\sin B} \]
    6. Final simplification74.7%

      \[\leadsto \left(-\frac{x}{B}\right) + {\sin B}^{-1} \]
    7. Add Preprocessing

    Alternative 6: 52.5% accurate, 1.8× speedup?

    \[\begin{array}{l} \\ \mathsf{fma}\left(0.3333333333333333 \cdot x, B, \frac{-x}{B}\right) + {B}^{-1} \end{array} \]
    (FPCore (B x)
     :precision binary64
     (+ (fma (* 0.3333333333333333 x) B (/ (- x) B)) (pow B -1.0)))
    double code(double B, double x) {
    	return fma((0.3333333333333333 * x), B, (-x / B)) + pow(B, -1.0);
    }
    
    function code(B, x)
    	return Float64(fma(Float64(0.3333333333333333 * x), B, Float64(Float64(-x) / B)) + (B ^ -1.0))
    end
    
    code[B_, x_] := N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] * B + N[((-x) / B), $MachinePrecision]), $MachinePrecision] + N[Power[B, -1.0], $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \mathsf{fma}\left(0.3333333333333333 \cdot x, B, \frac{-x}{B}\right) + {B}^{-1}
    \end{array}
    
    Derivation
    1. Initial program 99.7%

      \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \left(-\color{blue}{x \cdot \frac{1}{\tan B}}\right) + \frac{1}{\sin B} \]
      2. lift-/.f64N/A

        \[\leadsto \left(-x \cdot \color{blue}{\frac{1}{\tan B}}\right) + \frac{1}{\sin B} \]
      3. un-div-invN/A

        \[\leadsto \left(-\color{blue}{\frac{x}{\tan B}}\right) + \frac{1}{\sin B} \]
      4. lower-/.f6499.8

        \[\leadsto \left(-\color{blue}{\frac{x}{\tan B}}\right) + \frac{1}{\sin B} \]
    4. Applied rewrites99.8%

      \[\leadsto \left(-\color{blue}{\frac{x}{\tan B}}\right) + \frac{1}{\sin B} \]
    5. Taylor expanded in B around 0

      \[\leadsto \left(-\frac{x}{\tan B}\right) + \color{blue}{\frac{1}{B}} \]
    6. Step-by-step derivation
      1. lower-/.f6472.5

        \[\leadsto \left(-\frac{x}{\tan B}\right) + \color{blue}{\frac{1}{B}} \]
    7. Applied rewrites72.5%

      \[\leadsto \left(-\frac{x}{\tan B}\right) + \color{blue}{\frac{1}{B}} \]
    8. Taylor expanded in B around 0

      \[\leadsto \color{blue}{\frac{{B}^{2} \cdot \left(\frac{1}{3} \cdot x + {B}^{2} \cdot \left(\frac{-1}{9} \cdot x + \left(\frac{2}{15} \cdot x + {B}^{2} \cdot \left(\frac{-1}{3} \cdot \left(\frac{-1}{9} \cdot x + \frac{2}{15} \cdot x\right) + \left(\frac{-2}{45} \cdot x + \frac{17}{315} \cdot x\right)\right)\right)\right)\right) - x}{B}} + \frac{1}{B} \]
    9. Step-by-step derivation
      1. div-subN/A

        \[\leadsto \color{blue}{\left(\frac{{B}^{2} \cdot \left(\frac{1}{3} \cdot x + {B}^{2} \cdot \left(\frac{-1}{9} \cdot x + \left(\frac{2}{15} \cdot x + {B}^{2} \cdot \left(\frac{-1}{3} \cdot \left(\frac{-1}{9} \cdot x + \frac{2}{15} \cdot x\right) + \left(\frac{-2}{45} \cdot x + \frac{17}{315} \cdot x\right)\right)\right)\right)\right)}{B} - \frac{x}{B}\right)} + \frac{1}{B} \]
      2. sub-negN/A

        \[\leadsto \color{blue}{\left(\frac{{B}^{2} \cdot \left(\frac{1}{3} \cdot x + {B}^{2} \cdot \left(\frac{-1}{9} \cdot x + \left(\frac{2}{15} \cdot x + {B}^{2} \cdot \left(\frac{-1}{3} \cdot \left(\frac{-1}{9} \cdot x + \frac{2}{15} \cdot x\right) + \left(\frac{-2}{45} \cdot x + \frac{17}{315} \cdot x\right)\right)\right)\right)\right)}{B} + \left(\mathsf{neg}\left(\frac{x}{B}\right)\right)\right)} + \frac{1}{B} \]
      3. mul-1-negN/A

        \[\leadsto \left(\frac{{B}^{2} \cdot \left(\frac{1}{3} \cdot x + {B}^{2} \cdot \left(\frac{-1}{9} \cdot x + \left(\frac{2}{15} \cdot x + {B}^{2} \cdot \left(\frac{-1}{3} \cdot \left(\frac{-1}{9} \cdot x + \frac{2}{15} \cdot x\right) + \left(\frac{-2}{45} \cdot x + \frac{17}{315} \cdot x\right)\right)\right)\right)\right)}{B} + \color{blue}{-1 \cdot \frac{x}{B}}\right) + \frac{1}{B} \]
    10. Applied rewrites48.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\left(x \cdot 0.0021164021164021165\right) \cdot B, B, 0.022222222222222223 \cdot x\right), B \cdot B, 0.3333333333333333 \cdot x\right), B, \frac{-x}{B}\right)} + \frac{1}{B} \]
    11. Taylor expanded in B around 0

      \[\leadsto \mathsf{fma}\left(\frac{1}{3} \cdot x, B, \frac{-x}{B}\right) + \frac{1}{B} \]
    12. Step-by-step derivation
      1. Applied rewrites48.6%

        \[\leadsto \mathsf{fma}\left(0.3333333333333333 \cdot x, B, \frac{-x}{B}\right) + \frac{1}{B} \]
      2. Final simplification48.6%

        \[\leadsto \mathsf{fma}\left(0.3333333333333333 \cdot x, B, \frac{-x}{B}\right) + {B}^{-1} \]
      3. Add Preprocessing

      Alternative 7: 52.5% accurate, 1.8× speedup?

      \[\begin{array}{l} \\ \mathsf{fma}\left(B \cdot x, 0.3333333333333333, \frac{-x}{B}\right) + {B}^{-1} \end{array} \]
      (FPCore (B x)
       :precision binary64
       (+ (fma (* B x) 0.3333333333333333 (/ (- x) B)) (pow B -1.0)))
      double code(double B, double x) {
      	return fma((B * x), 0.3333333333333333, (-x / B)) + pow(B, -1.0);
      }
      
      function code(B, x)
      	return Float64(fma(Float64(B * x), 0.3333333333333333, Float64(Float64(-x) / B)) + (B ^ -1.0))
      end
      
      code[B_, x_] := N[(N[(N[(B * x), $MachinePrecision] * 0.3333333333333333 + N[((-x) / B), $MachinePrecision]), $MachinePrecision] + N[Power[B, -1.0], $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \mathsf{fma}\left(B \cdot x, 0.3333333333333333, \frac{-x}{B}\right) + {B}^{-1}
      \end{array}
      
      Derivation
      1. Initial program 99.7%

        \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
      2. Add Preprocessing
      3. Taylor expanded in B around 0

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

          \[\leadsto \color{blue}{\left(\frac{\frac{1}{3} \cdot \left({B}^{2} \cdot x\right)}{B} - \frac{x}{B}\right)} + \frac{1}{\sin B} \]
        2. sub-negN/A

          \[\leadsto \color{blue}{\left(\frac{\frac{1}{3} \cdot \left({B}^{2} \cdot x\right)}{B} + \left(\mathsf{neg}\left(\frac{x}{B}\right)\right)\right)} + \frac{1}{\sin B} \]
        3. mul-1-negN/A

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

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

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

          \[\leadsto \left(\frac{\color{blue}{\left(B \cdot B\right)} \cdot x}{B} \cdot \frac{1}{3} + -1 \cdot \frac{x}{B}\right) + \frac{1}{\sin B} \]
        7. associate-*l*N/A

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

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

          \[\leadsto \left(\left(B \cdot \frac{\color{blue}{x \cdot B}}{B}\right) \cdot \frac{1}{3} + -1 \cdot \frac{x}{B}\right) + \frac{1}{\sin B} \]
        10. associate-/l*N/A

          \[\leadsto \left(\left(B \cdot \color{blue}{\left(x \cdot \frac{B}{B}\right)}\right) \cdot \frac{1}{3} + -1 \cdot \frac{x}{B}\right) + \frac{1}{\sin B} \]
        11. *-inversesN/A

          \[\leadsto \left(\left(B \cdot \left(x \cdot \color{blue}{1}\right)\right) \cdot \frac{1}{3} + -1 \cdot \frac{x}{B}\right) + \frac{1}{\sin B} \]
        12. *-rgt-identityN/A

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

          \[\leadsto \color{blue}{\mathsf{fma}\left(B \cdot x, \frac{1}{3}, -1 \cdot \frac{x}{B}\right)} + \frac{1}{\sin B} \]
        14. lower-*.f64N/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{B \cdot x}, \frac{1}{3}, -1 \cdot \frac{x}{B}\right) + \frac{1}{\sin B} \]
        15. mul-1-negN/A

          \[\leadsto \mathsf{fma}\left(B \cdot x, \frac{1}{3}, \color{blue}{\mathsf{neg}\left(\frac{x}{B}\right)}\right) + \frac{1}{\sin B} \]
        16. distribute-neg-fracN/A

          \[\leadsto \mathsf{fma}\left(B \cdot x, \frac{1}{3}, \color{blue}{\frac{\mathsf{neg}\left(x\right)}{B}}\right) + \frac{1}{\sin B} \]
        17. lower-/.f64N/A

          \[\leadsto \mathsf{fma}\left(B \cdot x, \frac{1}{3}, \color{blue}{\frac{\mathsf{neg}\left(x\right)}{B}}\right) + \frac{1}{\sin B} \]
        18. lower-neg.f6461.8

          \[\leadsto \mathsf{fma}\left(B \cdot x, 0.3333333333333333, \frac{\color{blue}{-x}}{B}\right) + \frac{1}{\sin B} \]
      5. Applied rewrites61.8%

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

        \[\leadsto \mathsf{fma}\left(B \cdot x, \frac{1}{3}, \frac{-x}{B}\right) + \color{blue}{\frac{1}{B}} \]
      7. Step-by-step derivation
        1. lower-/.f6448.6

          \[\leadsto \mathsf{fma}\left(B \cdot x, 0.3333333333333333, \frac{-x}{B}\right) + \color{blue}{\frac{1}{B}} \]
      8. Applied rewrites48.6%

        \[\leadsto \mathsf{fma}\left(B \cdot x, 0.3333333333333333, \frac{-x}{B}\right) + \color{blue}{\frac{1}{B}} \]
      9. Final simplification48.6%

        \[\leadsto \mathsf{fma}\left(B \cdot x, 0.3333333333333333, \frac{-x}{B}\right) + {B}^{-1} \]
      10. Add Preprocessing

      Alternative 8: 52.4% accurate, 1.8× speedup?

      \[\begin{array}{l} \\ \mathsf{fma}\left(0.3333333333333333, B, \frac{-1}{B}\right) \cdot x + {B}^{-1} \end{array} \]
      (FPCore (B x)
       :precision binary64
       (+ (* (fma 0.3333333333333333 B (/ -1.0 B)) x) (pow B -1.0)))
      double code(double B, double x) {
      	return (fma(0.3333333333333333, B, (-1.0 / B)) * x) + pow(B, -1.0);
      }
      
      function code(B, x)
      	return Float64(Float64(fma(0.3333333333333333, B, Float64(-1.0 / B)) * x) + (B ^ -1.0))
      end
      
      code[B_, x_] := N[(N[(N[(0.3333333333333333 * B + N[(-1.0 / B), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] + N[Power[B, -1.0], $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \mathsf{fma}\left(0.3333333333333333, B, \frac{-1}{B}\right) \cdot x + {B}^{-1}
      \end{array}
      
      Derivation
      1. Initial program 99.7%

        \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \left(-\color{blue}{x \cdot \frac{1}{\tan B}}\right) + \frac{1}{\sin B} \]
        2. lift-/.f64N/A

          \[\leadsto \left(-x \cdot \color{blue}{\frac{1}{\tan B}}\right) + \frac{1}{\sin B} \]
        3. un-div-invN/A

          \[\leadsto \left(-\color{blue}{\frac{x}{\tan B}}\right) + \frac{1}{\sin B} \]
        4. lower-/.f6499.8

          \[\leadsto \left(-\color{blue}{\frac{x}{\tan B}}\right) + \frac{1}{\sin B} \]
      4. Applied rewrites99.8%

        \[\leadsto \left(-\color{blue}{\frac{x}{\tan B}}\right) + \frac{1}{\sin B} \]
      5. Taylor expanded in B around 0

        \[\leadsto \left(-\frac{x}{\tan B}\right) + \color{blue}{\frac{1}{B}} \]
      6. Step-by-step derivation
        1. lower-/.f6472.5

          \[\leadsto \left(-\frac{x}{\tan B}\right) + \color{blue}{\frac{1}{B}} \]
      7. Applied rewrites72.5%

        \[\leadsto \left(-\frac{x}{\tan B}\right) + \color{blue}{\frac{1}{B}} \]
      8. Taylor expanded in B around 0

        \[\leadsto \color{blue}{\frac{\frac{1}{3} \cdot \left({B}^{2} \cdot x\right) - x}{B}} + \frac{1}{B} \]
      9. Step-by-step derivation
        1. div-subN/A

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

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

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

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

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

          \[\leadsto \left(\color{blue}{x \cdot \frac{\frac{1}{3} \cdot {B}^{2}}{B}} - x \cdot \frac{1}{B}\right) + \frac{1}{B} \]
        7. distribute-lft-out--N/A

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

          \[\leadsto x \cdot \left(\frac{\frac{1}{3} \cdot {B}^{2}}{\color{blue}{1 \cdot B}} - \frac{1}{B}\right) + \frac{1}{B} \]
        9. times-fracN/A

          \[\leadsto x \cdot \left(\color{blue}{\frac{\frac{1}{3}}{1} \cdot \frac{{B}^{2}}{B}} - \frac{1}{B}\right) + \frac{1}{B} \]
        10. metadata-evalN/A

          \[\leadsto x \cdot \left(\color{blue}{\frac{1}{3}} \cdot \frac{{B}^{2}}{B} - \frac{1}{B}\right) + \frac{1}{B} \]
        11. unpow2N/A

          \[\leadsto x \cdot \left(\frac{1}{3} \cdot \frac{\color{blue}{B \cdot B}}{B} - \frac{1}{B}\right) + \frac{1}{B} \]
        12. associate-/l*N/A

          \[\leadsto x \cdot \left(\frac{1}{3} \cdot \color{blue}{\left(B \cdot \frac{B}{B}\right)} - \frac{1}{B}\right) + \frac{1}{B} \]
        13. *-inversesN/A

          \[\leadsto x \cdot \left(\frac{1}{3} \cdot \left(B \cdot \color{blue}{1}\right) - \frac{1}{B}\right) + \frac{1}{B} \]
        14. *-rgt-identityN/A

          \[\leadsto x \cdot \left(\frac{1}{3} \cdot \color{blue}{B} - \frac{1}{B}\right) + \frac{1}{B} \]
        15. metadata-evalN/A

          \[\leadsto x \cdot \left(\color{blue}{\left(\mathsf{neg}\left(\frac{-1}{3}\right)\right)} \cdot B - \frac{1}{B}\right) + \frac{1}{B} \]
        16. distribute-lft-neg-inN/A

          \[\leadsto x \cdot \left(\color{blue}{\left(\mathsf{neg}\left(\frac{-1}{3} \cdot B\right)\right)} - \frac{1}{B}\right) + \frac{1}{B} \]
        17. unsub-negN/A

          \[\leadsto x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(\frac{-1}{3} \cdot B\right)\right) + \left(\mathsf{neg}\left(\frac{1}{B}\right)\right)\right)} + \frac{1}{B} \]
        18. distribute-neg-inN/A

          \[\leadsto x \cdot \color{blue}{\left(\mathsf{neg}\left(\left(\frac{-1}{3} \cdot B + \frac{1}{B}\right)\right)\right)} + \frac{1}{B} \]
        19. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left(\frac{-1}{3} \cdot B + \frac{1}{B}\right)\right)\right) \cdot x} + \frac{1}{B} \]
        20. lower-*.f64N/A

          \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left(\frac{-1}{3} \cdot B + \frac{1}{B}\right)\right)\right) \cdot x} + \frac{1}{B} \]
      10. Applied rewrites48.6%

        \[\leadsto \color{blue}{\mathsf{fma}\left(0.3333333333333333, B, \frac{-1}{B}\right) \cdot x} + \frac{1}{B} \]
      11. Final simplification48.6%

        \[\leadsto \mathsf{fma}\left(0.3333333333333333, B, \frac{-1}{B}\right) \cdot x + {B}^{-1} \]
      12. Add Preprocessing

      Alternative 9: 52.2% accurate, 2.0× speedup?

      \[\begin{array}{l} \\ \left(-\frac{x}{B}\right) + {B}^{-1} \end{array} \]
      (FPCore (B x) :precision binary64 (+ (- (/ x B)) (pow B -1.0)))
      double code(double B, double x) {
      	return -(x / B) + pow(B, -1.0);
      }
      
      real(8) function code(b, x)
          real(8), intent (in) :: b
          real(8), intent (in) :: x
          code = -(x / b) + (b ** (-1.0d0))
      end function
      
      public static double code(double B, double x) {
      	return -(x / B) + Math.pow(B, -1.0);
      }
      
      def code(B, x):
      	return -(x / B) + math.pow(B, -1.0)
      
      function code(B, x)
      	return Float64(Float64(-Float64(x / B)) + (B ^ -1.0))
      end
      
      function tmp = code(B, x)
      	tmp = -(x / B) + (B ^ -1.0);
      end
      
      code[B_, x_] := N[((-N[(x / B), $MachinePrecision]) + N[Power[B, -1.0], $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \left(-\frac{x}{B}\right) + {B}^{-1}
      \end{array}
      
      Derivation
      1. Initial program 99.7%

        \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \left(-\color{blue}{x \cdot \frac{1}{\tan B}}\right) + \frac{1}{\sin B} \]
        2. lift-/.f64N/A

          \[\leadsto \left(-x \cdot \color{blue}{\frac{1}{\tan B}}\right) + \frac{1}{\sin B} \]
        3. un-div-invN/A

          \[\leadsto \left(-\color{blue}{\frac{x}{\tan B}}\right) + \frac{1}{\sin B} \]
        4. lower-/.f6499.8

          \[\leadsto \left(-\color{blue}{\frac{x}{\tan B}}\right) + \frac{1}{\sin B} \]
      4. Applied rewrites99.8%

        \[\leadsto \left(-\color{blue}{\frac{x}{\tan B}}\right) + \frac{1}{\sin B} \]
      5. Taylor expanded in B around 0

        \[\leadsto \left(-\frac{x}{\tan B}\right) + \color{blue}{\frac{1}{B}} \]
      6. Step-by-step derivation
        1. lower-/.f6472.5

          \[\leadsto \left(-\frac{x}{\tan B}\right) + \color{blue}{\frac{1}{B}} \]
      7. Applied rewrites72.5%

        \[\leadsto \left(-\frac{x}{\tan B}\right) + \color{blue}{\frac{1}{B}} \]
      8. Taylor expanded in B around 0

        \[\leadsto \left(-\color{blue}{\frac{x}{B}}\right) + \frac{1}{B} \]
      9. Step-by-step derivation
        1. lower-/.f6448.4

          \[\leadsto \left(-\color{blue}{\frac{x}{B}}\right) + \frac{1}{B} \]
      10. Applied rewrites48.4%

        \[\leadsto \left(-\color{blue}{\frac{x}{B}}\right) + \frac{1}{B} \]
      11. Final simplification48.4%

        \[\leadsto \left(-\frac{x}{B}\right) + {B}^{-1} \]
      12. Add Preprocessing

      Alternative 10: 52.3% accurate, 7.3× speedup?

      \[\begin{array}{l} \\ \frac{\mathsf{fma}\left(\mathsf{fma}\left(0.3333333333333333, x, 0.16666666666666666\right), B \cdot B, 1\right) - x}{B} \end{array} \]
      (FPCore (B x)
       :precision binary64
       (/ (- (fma (fma 0.3333333333333333 x 0.16666666666666666) (* B B) 1.0) x) B))
      double code(double B, double x) {
      	return (fma(fma(0.3333333333333333, x, 0.16666666666666666), (B * B), 1.0) - x) / B;
      }
      
      function code(B, x)
      	return Float64(Float64(fma(fma(0.3333333333333333, x, 0.16666666666666666), Float64(B * B), 1.0) - x) / B)
      end
      
      code[B_, x_] := N[(N[(N[(N[(0.3333333333333333 * x + 0.16666666666666666), $MachinePrecision] * N[(B * B), $MachinePrecision] + 1.0), $MachinePrecision] - x), $MachinePrecision] / B), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \frac{\mathsf{fma}\left(\mathsf{fma}\left(0.3333333333333333, x, 0.16666666666666666\right), B \cdot B, 1\right) - x}{B}
      \end{array}
      
      Derivation
      1. Initial program 99.7%

        \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
      2. Add Preprocessing
      3. Taylor expanded in B around 0

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

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

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

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

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

          \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\frac{1}{6} + \frac{1}{3} \cdot x, {B}^{2}, 1\right)} - x}{B} \]
        6. +-commutativeN/A

          \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{\frac{1}{3} \cdot x + \frac{1}{6}}, {B}^{2}, 1\right) - x}{B} \]
        7. lower-fma.f64N/A

          \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\frac{1}{3}, x, \frac{1}{6}\right)}, {B}^{2}, 1\right) - x}{B} \]
        8. unpow2N/A

          \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{3}, x, \frac{1}{6}\right), \color{blue}{B \cdot B}, 1\right) - x}{B} \]
        9. lower-*.f6448.5

          \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(0.3333333333333333, x, 0.16666666666666666\right), \color{blue}{B \cdot B}, 1\right) - x}{B} \]
      5. Applied rewrites48.5%

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.3333333333333333, x, 0.16666666666666666\right), B \cdot B, 1\right) - x}{B}} \]
      6. Add Preprocessing

      Alternative 11: 50.1% accurate, 8.9× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2.5 \cdot 10^{+28} \lor \neg \left(x \leq 13500\right):\\ \;\;\;\;\frac{-x}{B}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{B}\\ \end{array} \end{array} \]
      (FPCore (B x)
       :precision binary64
       (if (or (<= x -2.5e+28) (not (<= x 13500.0))) (/ (- x) B) (/ 1.0 B)))
      double code(double B, double x) {
      	double tmp;
      	if ((x <= -2.5e+28) || !(x <= 13500.0)) {
      		tmp = -x / B;
      	} else {
      		tmp = 1.0 / B;
      	}
      	return tmp;
      }
      
      real(8) function code(b, x)
          real(8), intent (in) :: b
          real(8), intent (in) :: x
          real(8) :: tmp
          if ((x <= (-2.5d+28)) .or. (.not. (x <= 13500.0d0))) then
              tmp = -x / b
          else
              tmp = 1.0d0 / b
          end if
          code = tmp
      end function
      
      public static double code(double B, double x) {
      	double tmp;
      	if ((x <= -2.5e+28) || !(x <= 13500.0)) {
      		tmp = -x / B;
      	} else {
      		tmp = 1.0 / B;
      	}
      	return tmp;
      }
      
      def code(B, x):
      	tmp = 0
      	if (x <= -2.5e+28) or not (x <= 13500.0):
      		tmp = -x / B
      	else:
      		tmp = 1.0 / B
      	return tmp
      
      function code(B, x)
      	tmp = 0.0
      	if ((x <= -2.5e+28) || !(x <= 13500.0))
      		tmp = Float64(Float64(-x) / B);
      	else
      		tmp = Float64(1.0 / B);
      	end
      	return tmp
      end
      
      function tmp_2 = code(B, x)
      	tmp = 0.0;
      	if ((x <= -2.5e+28) || ~((x <= 13500.0)))
      		tmp = -x / B;
      	else
      		tmp = 1.0 / B;
      	end
      	tmp_2 = tmp;
      end
      
      code[B_, x_] := If[Or[LessEqual[x, -2.5e+28], N[Not[LessEqual[x, 13500.0]], $MachinePrecision]], N[((-x) / B), $MachinePrecision], N[(1.0 / B), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;x \leq -2.5 \cdot 10^{+28} \lor \neg \left(x \leq 13500\right):\\
      \;\;\;\;\frac{-x}{B}\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{1}{B}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if x < -2.49999999999999979e28 or 13500 < x

        1. Initial program 99.7%

          \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
        2. Add Preprocessing
        3. Taylor expanded in B around 0

          \[\leadsto \color{blue}{\frac{1 - x}{B}} \]
        4. Step-by-step derivation
          1. lower-/.f64N/A

            \[\leadsto \color{blue}{\frac{1 - x}{B}} \]
          2. lower--.f6451.8

            \[\leadsto \frac{\color{blue}{1 - x}}{B} \]
        5. Applied rewrites51.8%

          \[\leadsto \color{blue}{\frac{1 - x}{B}} \]
        6. Taylor expanded in x around inf

          \[\leadsto \frac{-1 \cdot x}{B} \]
        7. Step-by-step derivation
          1. Applied rewrites51.3%

            \[\leadsto \frac{-x}{B} \]

          if -2.49999999999999979e28 < x < 13500

          1. Initial program 99.8%

            \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
          2. Add Preprocessing
          3. Taylor expanded in B around 0

            \[\leadsto \color{blue}{\frac{1 - x}{B}} \]
          4. Step-by-step derivation
            1. lower-/.f64N/A

              \[\leadsto \color{blue}{\frac{1 - x}{B}} \]
            2. lower--.f6445.3

              \[\leadsto \frac{\color{blue}{1 - x}}{B} \]
          5. Applied rewrites45.3%

            \[\leadsto \color{blue}{\frac{1 - x}{B}} \]
          6. Taylor expanded in x around 0

            \[\leadsto \frac{1}{B} \]
          7. Step-by-step derivation
            1. Applied rewrites43.7%

              \[\leadsto \frac{1}{B} \]
          8. Recombined 2 regimes into one program.
          9. Final simplification47.4%

            \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.5 \cdot 10^{+28} \lor \neg \left(x \leq 13500\right):\\ \;\;\;\;\frac{-x}{B}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{B}\\ \end{array} \]
          10. Add Preprocessing

          Alternative 12: 52.2% accurate, 15.5× speedup?

          \[\begin{array}{l} \\ \frac{1 - x}{B} \end{array} \]
          (FPCore (B x) :precision binary64 (/ (- 1.0 x) B))
          double code(double B, double x) {
          	return (1.0 - x) / B;
          }
          
          real(8) function code(b, x)
              real(8), intent (in) :: b
              real(8), intent (in) :: x
              code = (1.0d0 - x) / b
          end function
          
          public static double code(double B, double x) {
          	return (1.0 - x) / B;
          }
          
          def code(B, x):
          	return (1.0 - x) / B
          
          function code(B, x)
          	return Float64(Float64(1.0 - x) / B)
          end
          
          function tmp = code(B, x)
          	tmp = (1.0 - x) / B;
          end
          
          code[B_, x_] := N[(N[(1.0 - x), $MachinePrecision] / B), $MachinePrecision]
          
          \begin{array}{l}
          
          \\
          \frac{1 - x}{B}
          \end{array}
          
          Derivation
          1. Initial program 99.7%

            \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
          2. Add Preprocessing
          3. Taylor expanded in B around 0

            \[\leadsto \color{blue}{\frac{1 - x}{B}} \]
          4. Step-by-step derivation
            1. lower-/.f64N/A

              \[\leadsto \color{blue}{\frac{1 - x}{B}} \]
            2. lower--.f6448.4

              \[\leadsto \frac{\color{blue}{1 - x}}{B} \]
          5. Applied rewrites48.4%

            \[\leadsto \color{blue}{\frac{1 - x}{B}} \]
          6. Add Preprocessing

          Alternative 13: 27.2% accurate, 19.4× speedup?

          \[\begin{array}{l} \\ \frac{1}{B} \end{array} \]
          (FPCore (B x) :precision binary64 (/ 1.0 B))
          double code(double B, double x) {
          	return 1.0 / B;
          }
          
          real(8) function code(b, x)
              real(8), intent (in) :: b
              real(8), intent (in) :: x
              code = 1.0d0 / b
          end function
          
          public static double code(double B, double x) {
          	return 1.0 / B;
          }
          
          def code(B, x):
          	return 1.0 / B
          
          function code(B, x)
          	return Float64(1.0 / B)
          end
          
          function tmp = code(B, x)
          	tmp = 1.0 / B;
          end
          
          code[B_, x_] := N[(1.0 / B), $MachinePrecision]
          
          \begin{array}{l}
          
          \\
          \frac{1}{B}
          \end{array}
          
          Derivation
          1. Initial program 99.7%

            \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
          2. Add Preprocessing
          3. Taylor expanded in B around 0

            \[\leadsto \color{blue}{\frac{1 - x}{B}} \]
          4. Step-by-step derivation
            1. lower-/.f64N/A

              \[\leadsto \color{blue}{\frac{1 - x}{B}} \]
            2. lower--.f6448.4

              \[\leadsto \frac{\color{blue}{1 - x}}{B} \]
          5. Applied rewrites48.4%

            \[\leadsto \color{blue}{\frac{1 - x}{B}} \]
          6. Taylor expanded in x around 0

            \[\leadsto \frac{1}{B} \]
          7. Step-by-step derivation
            1. Applied rewrites24.1%

              \[\leadsto \frac{1}{B} \]
            2. Add Preprocessing

            Reproduce

            ?
            herbie shell --seed 2024324 
            (FPCore (B x)
              :name "VandenBroeck and Keller, Equation (24)"
              :precision binary64
              (+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))