VandenBroeck and Keller, Equation (24)

Percentage Accurate: 99.7% → 99.8%
Time: 10.0s
Alternatives: 10
Speedup: 1.0×

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

\\
\frac{1}{\sin B} - \frac{x}{\tan 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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\sin B} + {\color{blue}{\left(\sin B \cdot \sin B\right)}}^{\left(\frac{-1}{2}\right)} \cdot \frac{x}{\frac{1}{\cos B}} \]
    18. pow-prod-downN/A

      \[\leadsto \frac{1}{\sin B} + \color{blue}{\left({\sin B}^{\left(\frac{-1}{2}\right)} \cdot {\sin B}^{\left(\frac{-1}{2}\right)}\right)} \cdot \frac{x}{\frac{1}{\cos B}} \]
    19. sqr-powN/A

      \[\leadsto \frac{1}{\sin B} + \color{blue}{{\sin B}^{-1}} \cdot \frac{x}{\frac{1}{\cos B}} \]
    20. inv-powN/A

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

      \[\leadsto \frac{1}{\sin B} + \color{blue}{\frac{1 \cdot x}{\sin B \cdot \frac{1}{\cos B}}} \]
  4. Applied egg-rr99.7%

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

Alternative 2: 98.8% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{B} - \frac{x}{\tan B}\\ \mathbf{if}\;x \leq -350:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;\frac{1 - x}{\sin B}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (B x)
 :precision binary64
 (let* ((t_0 (- (/ 1.0 B) (/ x (tan B)))))
   (if (<= x -350.0) t_0 (if (<= x 1.0) (/ (- 1.0 x) (sin B)) t_0))))
double code(double B, double x) {
	double t_0 = (1.0 / B) - (x / tan(B));
	double tmp;
	if (x <= -350.0) {
		tmp = t_0;
	} else if (x <= 1.0) {
		tmp = (1.0 - x) / sin(B);
	} else {
		tmp = t_0;
	}
	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 = (1.0d0 / b) - (x / tan(b))
    if (x <= (-350.0d0)) then
        tmp = t_0
    else if (x <= 1.0d0) then
        tmp = (1.0d0 - x) / sin(b)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double B, double x) {
	double t_0 = (1.0 / B) - (x / Math.tan(B));
	double tmp;
	if (x <= -350.0) {
		tmp = t_0;
	} else if (x <= 1.0) {
		tmp = (1.0 - x) / Math.sin(B);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(B, x):
	t_0 = (1.0 / B) - (x / math.tan(B))
	tmp = 0
	if x <= -350.0:
		tmp = t_0
	elif x <= 1.0:
		tmp = (1.0 - x) / math.sin(B)
	else:
		tmp = t_0
	return tmp
function code(B, x)
	t_0 = Float64(Float64(1.0 / B) - Float64(x / tan(B)))
	tmp = 0.0
	if (x <= -350.0)
		tmp = t_0;
	elseif (x <= 1.0)
		tmp = Float64(Float64(1.0 - x) / sin(B));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(B, x)
	t_0 = (1.0 / B) - (x / tan(B));
	tmp = 0.0;
	if (x <= -350.0)
		tmp = t_0;
	elseif (x <= 1.0)
		tmp = (1.0 - x) / sin(B);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[B_, x_] := Block[{t$95$0 = N[(N[(1.0 / B), $MachinePrecision] - N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -350.0], t$95$0, If[LessEqual[x, 1.0], N[(N[(1.0 - x), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{1}{B} - \frac{x}{\tan B}\\
\mathbf{if}\;x \leq -350:\\
\;\;\;\;t\_0\\

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

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -350 or 1 < 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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\sin B} + {\color{blue}{\left(\sin B \cdot \sin B\right)}}^{\left(\frac{-1}{2}\right)} \cdot \frac{x}{\frac{1}{\cos B}} \]
      18. pow-prod-downN/A

        \[\leadsto \frac{1}{\sin B} + \color{blue}{\left({\sin B}^{\left(\frac{-1}{2}\right)} \cdot {\sin B}^{\left(\frac{-1}{2}\right)}\right)} \cdot \frac{x}{\frac{1}{\cos B}} \]
      19. sqr-powN/A

        \[\leadsto \frac{1}{\sin B} + \color{blue}{{\sin B}^{-1}} \cdot \frac{x}{\frac{1}{\cos B}} \]
      20. inv-powN/A

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

        \[\leadsto \frac{1}{\sin B} + \color{blue}{\frac{1 \cdot x}{\sin B \cdot \frac{1}{\cos B}}} \]
    4. Applied egg-rr99.7%

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

      \[\leadsto \color{blue}{\frac{1}{B}} - \frac{x}{\tan B} \]
    6. Step-by-step derivation
      1. /-lowering-/.f6498.0

        \[\leadsto \color{blue}{\frac{1}{B}} - \frac{x}{\tan B} \]
    7. Simplified98.0%

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

    if -350 < 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}{-1 \cdot \frac{x}{B}} + \frac{1}{\sin B} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

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

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

        \[\leadsto \color{blue}{\frac{x}{\mathsf{neg}\left(B\right)}} + \frac{1}{\sin B} \]
      4. neg-lowering-neg.f6498.8

        \[\leadsto \frac{x}{\color{blue}{-B}} + \frac{1}{\sin B} \]
    5. Simplified98.8%

      \[\leadsto \color{blue}{\frac{x}{-B}} + \frac{1}{\sin B} \]
    6. Step-by-step derivation
      1. frac-addN/A

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x, \frac{\sin B}{1}, \mathsf{neg}\left(B\right)\right)}}{\left(\mathsf{neg}\left(B\right)\right) \cdot \frac{\sin B}{1}} \]
      7. /-rgt-identityN/A

        \[\leadsto \frac{\mathsf{fma}\left(x, \color{blue}{\sin B}, \mathsf{neg}\left(B\right)\right)}{\left(\mathsf{neg}\left(B\right)\right) \cdot \frac{\sin B}{1}} \]
      8. remove-double-negN/A

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

        \[\leadsto \frac{\mathsf{fma}\left(x, \color{blue}{\sin \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(B\right)\right)\right)\right)}, \mathsf{neg}\left(B\right)\right)}{\left(\mathsf{neg}\left(B\right)\right) \cdot \frac{\sin B}{1}} \]
      10. remove-double-negN/A

        \[\leadsto \frac{\mathsf{fma}\left(x, \sin \color{blue}{B}, \mathsf{neg}\left(B\right)\right)}{\left(\mathsf{neg}\left(B\right)\right) \cdot \frac{\sin B}{1}} \]
      11. remove-double-negN/A

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

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(x, \sin B, \mathsf{neg}\left(B\right)\right)}{\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(B\right)\right)\right)\right)\right)\right)} \cdot \frac{\sin B}{1}} \]
      17. distribute-lft-neg-outN/A

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

        \[\leadsto \frac{\mathsf{fma}\left(x, \sin B, \mathsf{neg}\left(B\right)\right)}{\color{blue}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(B\right)\right)\right)\right) \cdot \frac{\sin B}{1}\right)}} \]
      19. *-lowering-*.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(x, \sin B, \mathsf{neg}\left(B\right)\right)}{\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(B\right)\right)\right)\right) \cdot \frac{\sin B}{1}}\right)} \]
    7. Applied egg-rr75.6%

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

      \[\leadsto \frac{\mathsf{fma}\left(x, \color{blue}{B}, \mathsf{neg}\left(B\right)\right)}{\mathsf{neg}\left(B \cdot \sin B\right)} \]
    9. Step-by-step derivation
      1. Simplified75.6%

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

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

          \[\leadsto \color{blue}{\frac{1}{\sin B} + -1 \cdot \frac{x}{\sin B}} \]
        2. mul-1-negN/A

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

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

          \[\leadsto \color{blue}{\frac{1 - x}{\sin B}} \]
        5. unsub-negN/A

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

          \[\leadsto \frac{1 + \color{blue}{-1 \cdot x}}{\sin B} \]
        7. /-lowering-/.f64N/A

          \[\leadsto \color{blue}{\frac{1 + -1 \cdot x}{\sin B}} \]
        8. mul-1-negN/A

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

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

          \[\leadsto \frac{\color{blue}{1 - x}}{\sin B} \]
        11. sin-lowering-sin.f6498.9

          \[\leadsto \frac{1 - x}{\color{blue}{\sin B}} \]
      4. Simplified98.9%

        \[\leadsto \color{blue}{\frac{1 - x}{\sin B}} \]
    10. Recombined 2 regimes into one program.
    11. Add Preprocessing

    Alternative 3: 62.6% accurate, 2.0× speedup?

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

      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. Simplified67.2%

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

      if 0.47999999999999998 < B

      1. Initial program 99.6%

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

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

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

          \[\leadsto \frac{1}{\color{blue}{\sin B}} \]
      5. Simplified48.9%

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

    Alternative 4: 76.6% 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.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}{-1 \cdot \frac{x}{B}} + \frac{1}{\sin B} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

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

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

        \[\leadsto \color{blue}{\frac{x}{\mathsf{neg}\left(B\right)}} + \frac{1}{\sin B} \]
      4. neg-lowering-neg.f6474.3

        \[\leadsto \frac{x}{\color{blue}{-B}} + \frac{1}{\sin B} \]
    5. Simplified74.3%

      \[\leadsto \color{blue}{\frac{x}{-B}} + \frac{1}{\sin B} \]
    6. Step-by-step derivation
      1. frac-addN/A

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x, \frac{\sin B}{1}, \mathsf{neg}\left(B\right)\right)}}{\left(\mathsf{neg}\left(B\right)\right) \cdot \frac{\sin B}{1}} \]
      7. /-rgt-identityN/A

        \[\leadsto \frac{\mathsf{fma}\left(x, \color{blue}{\sin B}, \mathsf{neg}\left(B\right)\right)}{\left(\mathsf{neg}\left(B\right)\right) \cdot \frac{\sin B}{1}} \]
      8. remove-double-negN/A

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

        \[\leadsto \frac{\mathsf{fma}\left(x, \color{blue}{\sin \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(B\right)\right)\right)\right)}, \mathsf{neg}\left(B\right)\right)}{\left(\mathsf{neg}\left(B\right)\right) \cdot \frac{\sin B}{1}} \]
      10. remove-double-negN/A

        \[\leadsto \frac{\mathsf{fma}\left(x, \sin \color{blue}{B}, \mathsf{neg}\left(B\right)\right)}{\left(\mathsf{neg}\left(B\right)\right) \cdot \frac{\sin B}{1}} \]
      11. remove-double-negN/A

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

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(x, \sin B, \mathsf{neg}\left(B\right)\right)}{\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(B\right)\right)\right)\right)\right)\right)} \cdot \frac{\sin B}{1}} \]
      17. distribute-lft-neg-outN/A

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

        \[\leadsto \frac{\mathsf{fma}\left(x, \sin B, \mathsf{neg}\left(B\right)\right)}{\color{blue}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(B\right)\right)\right)\right) \cdot \frac{\sin B}{1}\right)}} \]
      19. *-lowering-*.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(x, \sin B, \mathsf{neg}\left(B\right)\right)}{\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(B\right)\right)\right)\right) \cdot \frac{\sin B}{1}}\right)} \]
    7. Applied egg-rr59.0%

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

      \[\leadsto \frac{\mathsf{fma}\left(x, \color{blue}{B}, \mathsf{neg}\left(B\right)\right)}{\mathsf{neg}\left(B \cdot \sin B\right)} \]
    9. Step-by-step derivation
      1. Simplified59.6%

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

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

          \[\leadsto \color{blue}{\frac{1}{\sin B} + -1 \cdot \frac{x}{\sin B}} \]
        2. mul-1-negN/A

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

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

          \[\leadsto \color{blue}{\frac{1 - x}{\sin B}} \]
        5. unsub-negN/A

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

          \[\leadsto \frac{1 + \color{blue}{-1 \cdot x}}{\sin B} \]
        7. /-lowering-/.f64N/A

          \[\leadsto \color{blue}{\frac{1 + -1 \cdot x}{\sin B}} \]
        8. mul-1-negN/A

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

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

          \[\leadsto \frac{\color{blue}{1 - x}}{\sin B} \]
        11. sin-lowering-sin.f6475.3

          \[\leadsto \frac{1 - x}{\color{blue}{\sin B}} \]
      4. Simplified75.3%

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

      Alternative 5: 50.7% accurate, 7.5× speedup?

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

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

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

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

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

          \[\leadsto \frac{\mathsf{fma}\left(B \cdot B, \color{blue}{x \cdot \frac{1}{3}} + \frac{1}{6}, 1\right) - x}{B} \]
        9. accelerator-lowering-fma.f6450.8

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

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

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

          \[\leadsto \frac{\mathsf{fma}\left(B \cdot B, \color{blue}{x \cdot \frac{1}{3}}, 1\right) - x}{B} \]
        2. *-lowering-*.f6450.8

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

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

      Alternative 6: 49.5% accurate, 9.0× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{-B}\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 54000:\\ \;\;\;\;\frac{1}{B}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
      (FPCore (B x)
       :precision binary64
       (let* ((t_0 (/ x (- B))))
         (if (<= x -1.0) t_0 (if (<= x 54000.0) (/ 1.0 B) t_0))))
      double code(double B, double x) {
      	double t_0 = x / -B;
      	double tmp;
      	if (x <= -1.0) {
      		tmp = t_0;
      	} else if (x <= 54000.0) {
      		tmp = 1.0 / B;
      	} else {
      		tmp = t_0;
      	}
      	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 / -b
          if (x <= (-1.0d0)) then
              tmp = t_0
          else if (x <= 54000.0d0) then
              tmp = 1.0d0 / b
          else
              tmp = t_0
          end if
          code = tmp
      end function
      
      public static double code(double B, double x) {
      	double t_0 = x / -B;
      	double tmp;
      	if (x <= -1.0) {
      		tmp = t_0;
      	} else if (x <= 54000.0) {
      		tmp = 1.0 / B;
      	} else {
      		tmp = t_0;
      	}
      	return tmp;
      }
      
      def code(B, x):
      	t_0 = x / -B
      	tmp = 0
      	if x <= -1.0:
      		tmp = t_0
      	elif x <= 54000.0:
      		tmp = 1.0 / B
      	else:
      		tmp = t_0
      	return tmp
      
      function code(B, x)
      	t_0 = Float64(x / Float64(-B))
      	tmp = 0.0
      	if (x <= -1.0)
      		tmp = t_0;
      	elseif (x <= 54000.0)
      		tmp = Float64(1.0 / B);
      	else
      		tmp = t_0;
      	end
      	return tmp
      end
      
      function tmp_2 = code(B, x)
      	t_0 = x / -B;
      	tmp = 0.0;
      	if (x <= -1.0)
      		tmp = t_0;
      	elseif (x <= 54000.0)
      		tmp = 1.0 / B;
      	else
      		tmp = t_0;
      	end
      	tmp_2 = tmp;
      end
      
      code[B_, x_] := Block[{t$95$0 = N[(x / (-B)), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 54000.0], N[(1.0 / B), $MachinePrecision], t$95$0]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := \frac{x}{-B}\\
      \mathbf{if}\;x \leq -1:\\
      \;\;\;\;t\_0\\
      
      \mathbf{elif}\;x \leq 54000:\\
      \;\;\;\;\frac{1}{B}\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_0\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if x < -1 or 54000 < x

        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. /-lowering-/.f64N/A

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

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

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

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

            \[\leadsto \frac{\color{blue}{\mathsf{neg}\left(x\right)}}{B} \]
          2. neg-lowering-neg.f6443.5

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

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

        if -1 < x < 54000

        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. /-lowering-/.f64N/A

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

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

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

          \[\leadsto \color{blue}{\frac{1}{B}} \]
        7. Step-by-step derivation
          1. /-lowering-/.f6454.3

            \[\leadsto \color{blue}{\frac{1}{B}} \]
        8. Simplified54.3%

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{x}{-B}\\ \mathbf{elif}\;x \leq 54000:\\ \;\;\;\;\frac{1}{B}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{-B}\\ \end{array} \]
      5. Add Preprocessing

      Alternative 7: 50.6% accurate, 9.0× speedup?

      \[\begin{array}{l} \\ \frac{\mathsf{fma}\left(B, B \cdot 0.16666666666666666, 1\right) - x}{B} \end{array} \]
      (FPCore (B x)
       :precision binary64
       (/ (- (fma B (* B 0.16666666666666666) 1.0) x) B))
      double code(double B, double x) {
      	return (fma(B, (B * 0.16666666666666666), 1.0) - x) / B;
      }
      
      function code(B, x)
      	return Float64(Float64(fma(B, Float64(B * 0.16666666666666666), 1.0) - x) / B)
      end
      
      code[B_, x_] := N[(N[(N[(B * N[(B * 0.16666666666666666), $MachinePrecision] + 1.0), $MachinePrecision] - x), $MachinePrecision] / B), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \frac{\mathsf{fma}\left(B, B \cdot 0.16666666666666666, 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}{-1 \cdot \frac{x}{B}} + \frac{1}{\sin B} \]
      4. Step-by-step derivation
        1. mul-1-negN/A

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

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

          \[\leadsto \color{blue}{\frac{x}{\mathsf{neg}\left(B\right)}} + \frac{1}{\sin B} \]
        4. neg-lowering-neg.f6474.3

          \[\leadsto \frac{x}{\color{blue}{-B}} + \frac{1}{\sin B} \]
      5. Simplified74.3%

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(B, B \cdot \frac{1}{6}, 1\right)} - x}{B} \]
        12. *-lowering-*.f6450.6

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

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

      Alternative 8: 50.6% 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. /-lowering-/.f64N/A

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

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

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

      Alternative 9: 26.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. /-lowering-/.f64N/A

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

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

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

        \[\leadsto \color{blue}{\frac{1}{B}} \]
      7. Step-by-step derivation
        1. /-lowering-/.f6431.1

          \[\leadsto \color{blue}{\frac{1}{B}} \]
      8. Simplified31.1%

        \[\leadsto \color{blue}{\frac{1}{B}} \]
      9. Add Preprocessing

      Alternative 10: 3.1% accurate, 38.8× speedup?

      \[\begin{array}{l} \\ B \cdot 0.16666666666666666 \end{array} \]
      (FPCore (B x) :precision binary64 (* B 0.16666666666666666))
      double code(double B, double x) {
      	return B * 0.16666666666666666;
      }
      
      real(8) function code(b, x)
          real(8), intent (in) :: b
          real(8), intent (in) :: x
          code = b * 0.16666666666666666d0
      end function
      
      public static double code(double B, double x) {
      	return B * 0.16666666666666666;
      }
      
      def code(B, x):
      	return B * 0.16666666666666666
      
      function code(B, x)
      	return Float64(B * 0.16666666666666666)
      end
      
      function tmp = code(B, x)
      	tmp = B * 0.16666666666666666;
      end
      
      code[B_, x_] := N[(B * 0.16666666666666666), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      B \cdot 0.16666666666666666
      \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. /-lowering-/.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. --lowering--.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. accelerator-lowering-fma.f64N/A

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

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

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

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

          \[\leadsto \frac{\mathsf{fma}\left(B \cdot B, \color{blue}{x \cdot \frac{1}{3}} + \frac{1}{6}, 1\right) - x}{B} \]
        9. accelerator-lowering-fma.f6450.8

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

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

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

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

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

          \[\leadsto B \cdot \left(\color{blue}{x \cdot \frac{1}{3}} + \frac{1}{6}\right) \]
        4. accelerator-lowering-fma.f642.9

          \[\leadsto B \cdot \color{blue}{\mathsf{fma}\left(x, 0.3333333333333333, 0.16666666666666666\right)} \]
      8. Simplified2.9%

        \[\leadsto \color{blue}{B \cdot \mathsf{fma}\left(x, 0.3333333333333333, 0.16666666666666666\right)} \]
      9. Taylor expanded in x around 0

        \[\leadsto \color{blue}{\frac{1}{6} \cdot B} \]
      10. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{B \cdot \frac{1}{6}} \]
        2. *-lowering-*.f643.1

          \[\leadsto \color{blue}{B \cdot 0.16666666666666666} \]
      11. Simplified3.1%

        \[\leadsto \color{blue}{B \cdot 0.16666666666666666} \]
      12. Add Preprocessing

      Reproduce

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