VandenBroeck and Keller, Equation (24)

Percentage Accurate: 99.7% → 99.8%
Time: 8.6s
Alternatives: 10
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 10 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, 1.0× speedup?

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

\\
\frac{-x}{\tan B} - \frac{-1}{\sin B}
\end{array}
Derivation
  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 \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B}} \]
    2. *-lft-identityN/A

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(x\right)}{\tan B}} - \left(\mathsf{neg}\left(1\right)\right) \cdot \frac{1}{\sin B} \]
    11. lower-neg.f64N/A

      \[\leadsto \frac{\color{blue}{-x}}{\tan B} - \left(\mathsf{neg}\left(1\right)\right) \cdot \frac{1}{\sin B} \]
    12. metadata-evalN/A

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

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

      \[\leadsto \frac{-x}{\tan B} - \color{blue}{\frac{-1}{\sin B}} \]
    15. lower-/.f6499.8

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

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

Alternative 2: 98.2% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
t_0 := x \cdot \frac{-1}{\tan B} - \frac{-1}{\sin B}\\
\mathbf{if}\;t\_0 \leq -200 \lor \neg \left(t\_0 \leq 20\right):\\
\;\;\;\;\frac{1 - x}{\tan B}\\

\mathbf{else}:\\
\;\;\;\;\frac{1 - x}{\sin B}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (neg.f64 (*.f64 x (/.f64 #s(literal 1 binary64) (tan.f64 B)))) (/.f64 #s(literal 1 binary64) (sin.f64 B))) < -200 or 20 < (+.f64 (neg.f64 (*.f64 x (/.f64 #s(literal 1 binary64) (tan.f64 B)))) (/.f64 #s(literal 1 binary64) (sin.f64 B)))

    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 \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B}} \]
      2. *-lft-identityN/A

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(x\right)}{\tan B}} - \left(\mathsf{neg}\left(1\right)\right) \cdot \frac{1}{\sin B} \]
      11. lower-neg.f64N/A

        \[\leadsto \frac{\color{blue}{-x}}{\tan B} - \left(\mathsf{neg}\left(1\right)\right) \cdot \frac{1}{\sin B} \]
      12. metadata-evalN/A

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

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

        \[\leadsto \frac{-x}{\tan B} - \color{blue}{\frac{-1}{\sin B}} \]
      15. lower-/.f6499.8

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

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

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

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

        \[\leadsto \frac{-x}{\tan B} - \color{blue}{\frac{-1}{\sin B}} \]
      4. frac-subN/A

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(\sin B, -x, \tan B\right)}{\sin B}}{\tan B}} \]
    7. Taylor expanded in B around 0

      \[\leadsto \frac{\color{blue}{1 + -1 \cdot x}}{\tan B} \]
    8. Step-by-step derivation
      1. mul-1-negN/A

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

        \[\leadsto \frac{\color{blue}{1 - x}}{\tan B} \]
      3. lower--.f6498.8

        \[\leadsto \frac{\color{blue}{1 - x}}{\tan B} \]
    9. Applied rewrites98.8%

      \[\leadsto \frac{\color{blue}{1 - x}}{\tan B} \]

    if -200 < (+.f64 (neg.f64 (*.f64 x (/.f64 #s(literal 1 binary64) (tan.f64 B)))) (/.f64 #s(literal 1 binary64) (sin.f64 B))) < 20

    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 \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B}} \]
      2. lift-neg.f64N/A

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{-x}, \sin B, \tan B\right)}{\tan B \cdot \sin B} \]
      13. lower-*.f6499.6

        \[\leadsto \frac{\mathsf{fma}\left(-x, \sin B, \tan B\right)}{\color{blue}{\tan B \cdot \sin B}} \]
    4. Applied rewrites99.6%

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

      \[\leadsto \color{blue}{x \cdot \left(-1 \cdot \frac{\cos B}{\sin B} + \frac{1}{x \cdot \sin B}\right)} \]
    6. Step-by-step derivation
      1. distribute-rgt-inN/A

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

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

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

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

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

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

        \[\leadsto \frac{-1 \cdot \left(x \cdot \cos B\right)}{\sin B} + \color{blue}{\frac{\frac{1}{x} \cdot x}{\sin B}} \]
      8. div-add-revN/A

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

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

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{-x}, \cos B, 1\right)}{\sin B} \]
      15. lower-cos.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(-x, \color{blue}{\cos B}, 1\right)}{\sin B} \]
      16. lower-sin.f6499.7

        \[\leadsto \frac{\mathsf{fma}\left(-x, \cos B, 1\right)}{\color{blue}{\sin B}} \]
    7. Applied rewrites99.7%

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

      \[\leadsto \frac{1 + -1 \cdot x}{\sin \color{blue}{B}} \]
    9. Step-by-step derivation
      1. Applied rewrites96.7%

        \[\leadsto \frac{1 - x}{\sin \color{blue}{B}} \]
    10. Recombined 2 regimes into one program.
    11. Final simplification98.3%

      \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot \frac{-1}{\tan B} - \frac{-1}{\sin B} \leq -200 \lor \neg \left(x \cdot \frac{-1}{\tan B} - \frac{-1}{\sin B} \leq 20\right):\\ \;\;\;\;\frac{1 - x}{\tan B}\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - x}{\sin B}\\ \end{array} \]
    12. Add Preprocessing

    Alternative 3: 99.7% accurate, 1.1× speedup?

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

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

      \[\leadsto \color{blue}{\frac{1}{\sin B} - \frac{x \cdot \cos B}{\sin B}} \]
    4. Step-by-step derivation
      1. sub-negN/A

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

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

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

        \[\leadsto \color{blue}{\frac{-1 \cdot \left(x \cdot \cos B\right)}{\sin B}} + \frac{1}{\sin B} \]
      5. div-add-revN/A

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

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{-x}, \cos B, 1\right)}{\sin B} \]
      11. lower-cos.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(-x, \color{blue}{\cos B}, 1\right)}{\sin B} \]
      12. lower-sin.f6499.7

        \[\leadsto \frac{\mathsf{fma}\left(-x, \cos B, 1\right)}{\color{blue}{\sin B}} \]
    5. Applied rewrites99.7%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(-x, \cos B, 1\right)}{\sin B}} \]
    6. Final simplification99.7%

      \[\leadsto \frac{\mathsf{fma}\left(-x, \cos B, 1\right)}{\sin B} \]
    7. Add Preprocessing

    Alternative 4: 63.2% accurate, 1.1× speedup?

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

      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} + \left(\frac{1}{3} \cdot x + {B}^{2} \cdot \left(\frac{7}{360} + \left(\frac{-1}{9} \cdot x + \left(\frac{2}{15} \cdot x + {B}^{2} \cdot \left(\frac{31}{15120} + \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)\right)\right)\right)\right) - x}{B}} \]
      4. Applied rewrites67.1%

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

      if 2.0499999999999998 < B

      1. Initial program 99.4%

        \[\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 \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B}} \]
        2. lift-neg.f64N/A

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{-x}, \sin B, \tan B\right)}{\tan B \cdot \sin B} \]
        13. lower-*.f6499.5

          \[\leadsto \frac{\mathsf{fma}\left(-x, \sin B, \tan B\right)}{\color{blue}{\tan B \cdot \sin B}} \]
      4. Applied rewrites99.5%

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

        \[\leadsto \color{blue}{x \cdot \left(-1 \cdot \frac{\cos B}{\sin B} + \frac{1}{x \cdot \sin B}\right)} \]
      6. Step-by-step derivation
        1. distribute-rgt-inN/A

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

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

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

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

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

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

          \[\leadsto \frac{-1 \cdot \left(x \cdot \cos B\right)}{\sin B} + \color{blue}{\frac{\frac{1}{x} \cdot x}{\sin B}} \]
        8. div-add-revN/A

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

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

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

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

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

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

          \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{-x}, \cos B, 1\right)}{\sin B} \]
        15. lower-cos.f64N/A

          \[\leadsto \frac{\mathsf{fma}\left(-x, \color{blue}{\cos B}, 1\right)}{\sin B} \]
        16. lower-sin.f6499.4

          \[\leadsto \frac{\mathsf{fma}\left(-x, \cos B, 1\right)}{\color{blue}{\sin B}} \]
      7. Applied rewrites99.4%

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

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

          \[\leadsto \color{blue}{\frac{1}{\sin B}} \]
        2. lower-sin.f6441.9

          \[\leadsto \frac{1}{\color{blue}{\sin B}} \]
      10. Applied rewrites41.9%

        \[\leadsto \color{blue}{\frac{1}{\sin B}} \]
    3. Recombined 2 regimes into one program.
    4. Final simplification60.3%

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

    Alternative 5: 77.1% accurate, 2.0× speedup?

    \[\begin{array}{l} \\ \frac{1 - x}{\sin B} \end{array} \]
    (FPCore (B x) :precision binary64 (/ (- 1.0 x) (sin B)))
    double code(double B, double x) {
    	return (1.0 - x) / sin(B);
    }
    
    real(8) function code(b, x)
        real(8), intent (in) :: b
        real(8), intent (in) :: x
        code = (1.0d0 - x) / sin(b)
    end function
    
    public static double code(double B, double x) {
    	return (1.0 - x) / Math.sin(B);
    }
    
    def code(B, x):
    	return (1.0 - x) / math.sin(B)
    
    function code(B, x)
    	return Float64(Float64(1.0 - x) / sin(B))
    end
    
    function tmp = code(B, x)
    	tmp = (1.0 - x) / sin(B);
    end
    
    code[B_, x_] := N[(N[(1.0 - x), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \frac{1 - x}{\sin B}
    \end{array}
    
    Derivation
    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 \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B}} \]
      2. lift-neg.f64N/A

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{-x}, \sin B, \tan B\right)}{\tan B \cdot \sin B} \]
      13. lower-*.f6483.8

        \[\leadsto \frac{\mathsf{fma}\left(-x, \sin B, \tan B\right)}{\color{blue}{\tan B \cdot \sin B}} \]
    4. Applied rewrites83.8%

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

      \[\leadsto \color{blue}{x \cdot \left(-1 \cdot \frac{\cos B}{\sin B} + \frac{1}{x \cdot \sin B}\right)} \]
    6. Step-by-step derivation
      1. distribute-rgt-inN/A

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

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

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

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

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

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

        \[\leadsto \frac{-1 \cdot \left(x \cdot \cos B\right)}{\sin B} + \color{blue}{\frac{\frac{1}{x} \cdot x}{\sin B}} \]
      8. div-add-revN/A

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

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

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{-x}, \cos B, 1\right)}{\sin B} \]
      15. lower-cos.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(-x, \color{blue}{\cos B}, 1\right)}{\sin B} \]
      16. lower-sin.f6499.7

        \[\leadsto \frac{\mathsf{fma}\left(-x, \cos B, 1\right)}{\color{blue}{\sin B}} \]
    7. Applied rewrites99.7%

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

      \[\leadsto \frac{1 + -1 \cdot x}{\sin \color{blue}{B}} \]
    9. Step-by-step derivation
      1. Applied rewrites72.2%

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

      Alternative 6: 51.1% accurate, 7.5× speedup?

      \[\begin{array}{l} \\ \frac{\mathsf{fma}\left(\left(0.3333333333333333 \cdot B\right) \cdot x, B, 1 - x\right)}{B} \end{array} \]
      (FPCore (B x)
       :precision binary64
       (/ (fma (* (* 0.3333333333333333 B) x) B (- 1.0 x)) B))
      double code(double B, double x) {
      	return fma(((0.3333333333333333 * B) * x), B, (1.0 - x)) / B;
      }
      
      function code(B, x)
      	return Float64(fma(Float64(Float64(0.3333333333333333 * B) * x), B, Float64(1.0 - x)) / B)
      end
      
      code[B_, x_] := N[(N[(N[(N[(0.3333333333333333 * B), $MachinePrecision] * x), $MachinePrecision] * B + N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / B), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \frac{\mathsf{fma}\left(\left(0.3333333333333333 \cdot B\right) \cdot x, B, 1 - x\right)}{B}
      \end{array}
      
      Derivation
      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 \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B}} \]
        2. *-lft-identityN/A

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(x\right)}{\tan B}} - \left(\mathsf{neg}\left(1\right)\right) \cdot \frac{1}{\sin B} \]
        11. lower-neg.f64N/A

          \[\leadsto \frac{\color{blue}{-x}}{\tan B} - \left(\mathsf{neg}\left(1\right)\right) \cdot \frac{1}{\sin B} \]
        12. metadata-evalN/A

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

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

          \[\leadsto \frac{-x}{\tan B} - \color{blue}{\frac{-1}{\sin B}} \]
        15. lower-/.f6499.8

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{3}, x, \frac{1}{6}\right) \cdot B, B, 1 + \color{blue}{\left(\mathsf{neg}\left(x\right)\right)}\right)}{B} \]
        12. sub-negN/A

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

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

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

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

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

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

        Alternative 7: 49.7% accurate, 8.6× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -410 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\frac{-x}{B}\\ \mathbf{else}:\\ \;\;\;\;\frac{x + 1}{B}\\ \end{array} \end{array} \]
        (FPCore (B x)
         :precision binary64
         (if (or (<= x -410.0) (not (<= x 1.0))) (/ (- x) B) (/ (+ x 1.0) B)))
        double code(double B, double x) {
        	double tmp;
        	if ((x <= -410.0) || !(x <= 1.0)) {
        		tmp = -x / B;
        	} else {
        		tmp = (x + 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 <= (-410.0d0)) .or. (.not. (x <= 1.0d0))) then
                tmp = -x / b
            else
                tmp = (x + 1.0d0) / b
            end if
            code = tmp
        end function
        
        public static double code(double B, double x) {
        	double tmp;
        	if ((x <= -410.0) || !(x <= 1.0)) {
        		tmp = -x / B;
        	} else {
        		tmp = (x + 1.0) / B;
        	}
        	return tmp;
        }
        
        def code(B, x):
        	tmp = 0
        	if (x <= -410.0) or not (x <= 1.0):
        		tmp = -x / B
        	else:
        		tmp = (x + 1.0) / B
        	return tmp
        
        function code(B, x)
        	tmp = 0.0
        	if ((x <= -410.0) || !(x <= 1.0))
        		tmp = Float64(Float64(-x) / B);
        	else
        		tmp = Float64(Float64(x + 1.0) / B);
        	end
        	return tmp
        end
        
        function tmp_2 = code(B, x)
        	tmp = 0.0;
        	if ((x <= -410.0) || ~((x <= 1.0)))
        		tmp = -x / B;
        	else
        		tmp = (x + 1.0) / B;
        	end
        	tmp_2 = tmp;
        end
        
        code[B_, x_] := If[Or[LessEqual[x, -410.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[((-x) / B), $MachinePrecision], N[(N[(x + 1.0), $MachinePrecision] / B), $MachinePrecision]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;x \leq -410 \lor \neg \left(x \leq 1\right):\\
        \;\;\;\;\frac{-x}{B}\\
        
        \mathbf{else}:\\
        \;\;\;\;\frac{x + 1}{B}\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if x < -410 or 1 < x

          1. Initial program 99.5%

            \[\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 \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B}} \]
            2. *-lft-identityN/A

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

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

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

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

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

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

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

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

              \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(x\right)}{\tan B}} - \left(\mathsf{neg}\left(1\right)\right) \cdot \frac{1}{\sin B} \]
            11. lower-neg.f64N/A

              \[\leadsto \frac{\color{blue}{-x}}{\tan B} - \left(\mathsf{neg}\left(1\right)\right) \cdot \frac{1}{\sin B} \]
            12. metadata-evalN/A

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

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

              \[\leadsto \frac{-x}{\tan B} - \color{blue}{\frac{-1}{\sin B}} \]
            15. lower-/.f6499.8

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{3}, x, \frac{1}{6}\right) \cdot B, B, 1 + \color{blue}{\left(\mathsf{neg}\left(x\right)\right)}\right)}{B} \]
            12. sub-negN/A

              \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{3}, x, \frac{1}{6}\right) \cdot B, B, \color{blue}{1 - x}\right)}{B} \]
            13. lower--.f6447.8

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

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

            \[\leadsto \frac{-1 \cdot \left(x \cdot \left(1 + \frac{-1}{3} \cdot {B}^{2}\right)\right)}{B} \]
          9. Step-by-step derivation
            1. Applied rewrites47.4%

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

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

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

              if -410 < x < 1

              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--.f6452.8

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

                \[\leadsto \color{blue}{\frac{1 - x}{B}} \]
              6. Step-by-step derivation
                1. Applied rewrites52.8%

                  \[\leadsto \frac{\frac{1}{\frac{1 + x}{1 - x \cdot x}}}{B} \]
                2. Step-by-step derivation
                  1. Applied rewrites52.4%

                    \[\leadsto \frac{x + 1}{B} \]
                3. Recombined 2 regimes into one program.
                4. Final simplification49.5%

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

                Alternative 8: 49.5% accurate, 8.9× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -3.4 \cdot 10^{-14} \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\frac{-x}{B}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{B}\\ \end{array} \end{array} \]
                (FPCore (B x)
                 :precision binary64
                 (if (or (<= x -3.4e-14) (not (<= x 1.0))) (/ (- x) B) (/ 1.0 B)))
                double code(double B, double x) {
                	double tmp;
                	if ((x <= -3.4e-14) || !(x <= 1.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 <= (-3.4d-14)) .or. (.not. (x <= 1.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 <= -3.4e-14) || !(x <= 1.0)) {
                		tmp = -x / B;
                	} else {
                		tmp = 1.0 / B;
                	}
                	return tmp;
                }
                
                def code(B, x):
                	tmp = 0
                	if (x <= -3.4e-14) or not (x <= 1.0):
                		tmp = -x / B
                	else:
                		tmp = 1.0 / B
                	return tmp
                
                function code(B, x)
                	tmp = 0.0
                	if ((x <= -3.4e-14) || !(x <= 1.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 <= -3.4e-14) || ~((x <= 1.0)))
                		tmp = -x / B;
                	else
                		tmp = 1.0 / B;
                	end
                	tmp_2 = tmp;
                end
                
                code[B_, x_] := If[Or[LessEqual[x, -3.4e-14], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[((-x) / B), $MachinePrecision], N[(1.0 / B), $MachinePrecision]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;x \leq -3.4 \cdot 10^{-14} \lor \neg \left(x \leq 1\right):\\
                \;\;\;\;\frac{-x}{B}\\
                
                \mathbf{else}:\\
                \;\;\;\;\frac{1}{B}\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if x < -3.40000000000000003e-14 or 1 < x

                  1. Initial program 99.5%

                    \[\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 \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B}} \]
                    2. *-lft-identityN/A

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

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

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

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

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

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

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

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

                      \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(x\right)}{\tan B}} - \left(\mathsf{neg}\left(1\right)\right) \cdot \frac{1}{\sin B} \]
                    11. lower-neg.f64N/A

                      \[\leadsto \frac{\color{blue}{-x}}{\tan B} - \left(\mathsf{neg}\left(1\right)\right) \cdot \frac{1}{\sin B} \]
                    12. metadata-evalN/A

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

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

                      \[\leadsto \frac{-x}{\tan B} - \color{blue}{\frac{-1}{\sin B}} \]
                    15. lower-/.f6499.8

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

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

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{3}, x, \frac{1}{6}\right) \cdot B, B, 1 + \color{blue}{\left(\mathsf{neg}\left(x\right)\right)}\right)}{B} \]
                    12. sub-negN/A

                      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{3}, x, \frac{1}{6}\right) \cdot B, B, \color{blue}{1 - x}\right)}{B} \]
                    13. lower--.f6447.0

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

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

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

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

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

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

                      if -3.40000000000000003e-14 < x < 1

                      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--.f6454.1

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

                        \[\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 rewrites53.7%

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

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

                      Alternative 9: 50.8% 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.6%

                        \[\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--.f6449.9

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

                        \[\leadsto \color{blue}{\frac{1 - x}{B}} \]
                      6. Final simplification49.9%

                        \[\leadsto \frac{1 - x}{B} \]
                      7. Add Preprocessing

                      Alternative 10: 25.8% 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.6%

                        \[\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--.f6449.9

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

                        \[\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 rewrites25.3%

                          \[\leadsto \frac{1}{B} \]
                        2. Final simplification25.3%

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

                        Reproduce

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