VandenBroeck and Keller, Equation (24)

Percentage Accurate: 99.7% → 99.8%
Time: 8.5s
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. Step-by-step derivation
    1. +-commutative99.7%

      \[\leadsto \color{blue}{\frac{1}{\sin B} + \left(-x \cdot \frac{1}{\tan B}\right)} \]
    2. unsub-neg99.7%

      \[\leadsto \color{blue}{\frac{1}{\sin B} - x \cdot \frac{1}{\tan B}} \]
    3. associate-*r/99.8%

      \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{x \cdot 1}{\tan B}} \]
    4. *-rgt-identity99.8%

      \[\leadsto \frac{1}{\sin B} - \frac{\color{blue}{x}}{\tan B} \]
  3. Simplified99.8%

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

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

Alternative 2: 98.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -180000000000:\\ \;\;\;\;\frac{x \cdot \left(-\cos B\right)}{\sin B}\\ \mathbf{elif}\;x \leq 29000000:\\ \;\;\;\;\frac{1 - x}{\sin B}\\ \mathbf{else}:\\ \;\;\;\;\frac{-x}{\tan B}\\ \end{array} \end{array} \]
(FPCore (B x)
 :precision binary64
 (if (<= x -180000000000.0)
   (/ (* x (- (cos B))) (sin B))
   (if (<= x 29000000.0) (/ (- 1.0 x) (sin B)) (/ (- x) (tan B)))))
double code(double B, double x) {
	double tmp;
	if (x <= -180000000000.0) {
		tmp = (x * -cos(B)) / sin(B);
	} else if (x <= 29000000.0) {
		tmp = (1.0 - x) / sin(B);
	} else {
		tmp = -x / tan(B);
	}
	return tmp;
}
real(8) function code(b, x)
    real(8), intent (in) :: b
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-180000000000.0d0)) then
        tmp = (x * -cos(b)) / sin(b)
    else if (x <= 29000000.0d0) then
        tmp = (1.0d0 - x) / sin(b)
    else
        tmp = -x / tan(b)
    end if
    code = tmp
end function
public static double code(double B, double x) {
	double tmp;
	if (x <= -180000000000.0) {
		tmp = (x * -Math.cos(B)) / Math.sin(B);
	} else if (x <= 29000000.0) {
		tmp = (1.0 - x) / Math.sin(B);
	} else {
		tmp = -x / Math.tan(B);
	}
	return tmp;
}
def code(B, x):
	tmp = 0
	if x <= -180000000000.0:
		tmp = (x * -math.cos(B)) / math.sin(B)
	elif x <= 29000000.0:
		tmp = (1.0 - x) / math.sin(B)
	else:
		tmp = -x / math.tan(B)
	return tmp
function code(B, x)
	tmp = 0.0
	if (x <= -180000000000.0)
		tmp = Float64(Float64(x * Float64(-cos(B))) / sin(B));
	elseif (x <= 29000000.0)
		tmp = Float64(Float64(1.0 - x) / sin(B));
	else
		tmp = Float64(Float64(-x) / tan(B));
	end
	return tmp
end
function tmp_2 = code(B, x)
	tmp = 0.0;
	if (x <= -180000000000.0)
		tmp = (x * -cos(B)) / sin(B);
	elseif (x <= 29000000.0)
		tmp = (1.0 - x) / sin(B);
	else
		tmp = -x / tan(B);
	end
	tmp_2 = tmp;
end
code[B_, x_] := If[LessEqual[x, -180000000000.0], N[(N[(x * (-N[Cos[B], $MachinePrecision])), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 29000000.0], N[(N[(1.0 - x), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision], N[((-x) / N[Tan[B], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -180000000000:\\
\;\;\;\;\frac{x \cdot \left(-\cos B\right)}{\sin B}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{-x}{\tan B}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.8e11

    1. Initial program 99.6%

      \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
    2. Step-by-step derivation
      1. +-commutative99.6%

        \[\leadsto \color{blue}{\frac{1}{\sin B} + \left(-x \cdot \frac{1}{\tan B}\right)} \]
      2. unsub-neg99.6%

        \[\leadsto \color{blue}{\frac{1}{\sin B} - x \cdot \frac{1}{\tan B}} \]
      3. associate-*r/99.7%

        \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{x \cdot 1}{\tan B}} \]
      4. *-rgt-identity99.7%

        \[\leadsto \frac{1}{\sin B} - \frac{\color{blue}{x}}{\tan B} \]
    3. Simplified99.7%

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

      \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{\cos B \cdot x}{\sin B}} \]
    5. Taylor expanded in x around inf 99.5%

      \[\leadsto \color{blue}{-1 \cdot \frac{\cos B \cdot x}{\sin B}} \]
    6. Step-by-step derivation
      1. associate-*r/99.5%

        \[\leadsto \color{blue}{\frac{-1 \cdot \left(\cos B \cdot x\right)}{\sin B}} \]
      2. neg-mul-199.5%

        \[\leadsto \frac{\color{blue}{-\cos B \cdot x}}{\sin B} \]
      3. distribute-lft-neg-in99.5%

        \[\leadsto \frac{\color{blue}{\left(-\cos B\right) \cdot x}}{\sin B} \]
    7. Simplified99.5%

      \[\leadsto \color{blue}{\frac{\left(-\cos B\right) \cdot x}{\sin B}} \]

    if -1.8e11 < x < 2.9e7

    1. Initial program 99.9%

      \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
    2. Step-by-step derivation
      1. +-commutative99.9%

        \[\leadsto \color{blue}{\frac{1}{\sin B} + \left(-x \cdot \frac{1}{\tan B}\right)} \]
      2. unsub-neg99.9%

        \[\leadsto \color{blue}{\frac{1}{\sin B} - x \cdot \frac{1}{\tan B}} \]
      3. associate-*r/99.9%

        \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{x \cdot 1}{\tan B}} \]
      4. *-rgt-identity99.9%

        \[\leadsto \frac{1}{\sin B} - \frac{\color{blue}{x}}{\tan B} \]
    3. Simplified99.9%

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

      \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{\cos B \cdot x}{\sin B}} \]
    5. Step-by-step derivation
      1. sub-div99.8%

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

      \[\leadsto \color{blue}{\frac{1 - \cos B \cdot x}{\sin B}} \]
    7. Taylor expanded in B around 0 97.7%

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

    if 2.9e7 < x

    1. Initial program 99.6%

      \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
    2. Step-by-step derivation
      1. +-commutative99.6%

        \[\leadsto \color{blue}{\frac{1}{\sin B} + \left(-x \cdot \frac{1}{\tan B}\right)} \]
      2. unsub-neg99.6%

        \[\leadsto \color{blue}{\frac{1}{\sin B} - x \cdot \frac{1}{\tan B}} \]
      3. associate-*r/99.8%

        \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{x \cdot 1}{\tan B}} \]
      4. *-rgt-identity99.8%

        \[\leadsto \frac{1}{\sin B} - \frac{\color{blue}{x}}{\tan B} \]
    3. Simplified99.8%

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

      \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{\cos B \cdot x}{\sin B}} \]
    5. Taylor expanded in x around inf 99.6%

      \[\leadsto \color{blue}{-1 \cdot \frac{\cos B \cdot x}{\sin B}} \]
    6. Step-by-step derivation
      1. associate-*r/99.6%

        \[\leadsto \color{blue}{\frac{-1 \cdot \left(\cos B \cdot x\right)}{\sin B}} \]
      2. neg-mul-199.6%

        \[\leadsto \frac{\color{blue}{-\cos B \cdot x}}{\sin B} \]
      3. distribute-lft-neg-in99.6%

        \[\leadsto \frac{\color{blue}{\left(-\cos B\right) \cdot x}}{\sin B} \]
    7. Simplified99.6%

      \[\leadsto \color{blue}{\frac{\left(-\cos B\right) \cdot x}{\sin B}} \]
    8. Step-by-step derivation
      1. associate-/l*99.5%

        \[\leadsto \color{blue}{\frac{-\cos B}{\frac{\sin B}{x}}} \]
      2. distribute-frac-neg99.5%

        \[\leadsto \color{blue}{-\frac{\cos B}{\frac{\sin B}{x}}} \]
      3. add-sqr-sqrt72.3%

        \[\leadsto -\frac{\color{blue}{\sqrt{\cos B} \cdot \sqrt{\cos B}}}{\frac{\sin B}{x}} \]
      4. sqrt-unprod72.6%

        \[\leadsto -\frac{\color{blue}{\sqrt{\cos B \cdot \cos B}}}{\frac{\sin B}{x}} \]
      5. sqr-neg72.6%

        \[\leadsto -\frac{\sqrt{\color{blue}{\left(-\cos B\right) \cdot \left(-\cos B\right)}}}{\frac{\sin B}{x}} \]
      6. sqrt-unprod0.2%

        \[\leadsto -\frac{\color{blue}{\sqrt{-\cos B} \cdot \sqrt{-\cos B}}}{\frac{\sin B}{x}} \]
      7. add-sqr-sqrt0.5%

        \[\leadsto -\frac{\color{blue}{-\cos B}}{\frac{\sin B}{x}} \]
      8. associate-/l*0.5%

        \[\leadsto -\color{blue}{\frac{\left(-\cos B\right) \cdot x}{\sin B}} \]
      9. *-commutative0.5%

        \[\leadsto -\frac{\color{blue}{x \cdot \left(-\cos B\right)}}{\sin B} \]
      10. associate-/l*0.5%

        \[\leadsto -\color{blue}{\frac{x}{\frac{\sin B}{-\cos B}}} \]
      11. add-sqr-sqrt0.2%

        \[\leadsto -\frac{x}{\frac{\sin B}{\color{blue}{\sqrt{-\cos B} \cdot \sqrt{-\cos B}}}} \]
      12. sqrt-unprod72.8%

        \[\leadsto -\frac{x}{\frac{\sin B}{\color{blue}{\sqrt{\left(-\cos B\right) \cdot \left(-\cos B\right)}}}} \]
      13. sqr-neg72.8%

        \[\leadsto -\frac{x}{\frac{\sin B}{\sqrt{\color{blue}{\cos B \cdot \cos B}}}} \]
      14. sqrt-unprod72.4%

        \[\leadsto -\frac{x}{\frac{\sin B}{\color{blue}{\sqrt{\cos B} \cdot \sqrt{\cos B}}}} \]
      15. add-sqr-sqrt99.7%

        \[\leadsto -\frac{x}{\frac{\sin B}{\color{blue}{\cos B}}} \]
      16. tan-quot99.8%

        \[\leadsto -\frac{x}{\color{blue}{\tan B}} \]
      17. div-inv99.6%

        \[\leadsto -\color{blue}{x \cdot \frac{1}{\tan B}} \]
      18. *-commutative99.6%

        \[\leadsto -\color{blue}{\frac{1}{\tan B} \cdot x} \]
      19. neg-mul-199.6%

        \[\leadsto \color{blue}{-1 \cdot \left(\frac{1}{\tan B} \cdot x\right)} \]
    9. Applied egg-rr99.8%

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{\tan B}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification98.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -180000000000:\\ \;\;\;\;\frac{x \cdot \left(-\cos B\right)}{\sin B}\\ \mathbf{elif}\;x \leq 29000000:\\ \;\;\;\;\frac{1 - x}{\sin B}\\ \mathbf{else}:\\ \;\;\;\;\frac{-x}{\tan B}\\ \end{array} \]

Alternative 3: 98.5% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -180000000000 \lor \neg \left(x \leq 4500000\right):\\ \;\;\;\;\frac{-x}{\tan B}\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - x}{\sin B}\\ \end{array} \end{array} \]
(FPCore (B x)
 :precision binary64
 (if (or (<= x -180000000000.0) (not (<= x 4500000.0)))
   (/ (- x) (tan B))
   (/ (- 1.0 x) (sin B))))
double code(double B, double x) {
	double tmp;
	if ((x <= -180000000000.0) || !(x <= 4500000.0)) {
		tmp = -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) :: tmp
    if ((x <= (-180000000000.0d0)) .or. (.not. (x <= 4500000.0d0))) then
        tmp = -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 tmp;
	if ((x <= -180000000000.0) || !(x <= 4500000.0)) {
		tmp = -x / Math.tan(B);
	} else {
		tmp = (1.0 - x) / Math.sin(B);
	}
	return tmp;
}
def code(B, x):
	tmp = 0
	if (x <= -180000000000.0) or not (x <= 4500000.0):
		tmp = -x / math.tan(B)
	else:
		tmp = (1.0 - x) / math.sin(B)
	return tmp
function code(B, x)
	tmp = 0.0
	if ((x <= -180000000000.0) || !(x <= 4500000.0))
		tmp = Float64(Float64(-x) / tan(B));
	else
		tmp = Float64(Float64(1.0 - x) / sin(B));
	end
	return tmp
end
function tmp_2 = code(B, x)
	tmp = 0.0;
	if ((x <= -180000000000.0) || ~((x <= 4500000.0)))
		tmp = -x / tan(B);
	else
		tmp = (1.0 - x) / sin(B);
	end
	tmp_2 = tmp;
end
code[B_, x_] := If[Or[LessEqual[x, -180000000000.0], N[Not[LessEqual[x, 4500000.0]], $MachinePrecision]], N[((-x) / N[Tan[B], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -180000000000 \lor \neg \left(x \leq 4500000\right):\\
\;\;\;\;\frac{-x}{\tan B}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.8e11 or 4.5e6 < x

    1. Initial program 99.6%

      \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
    2. Step-by-step derivation
      1. +-commutative99.6%

        \[\leadsto \color{blue}{\frac{1}{\sin B} + \left(-x \cdot \frac{1}{\tan B}\right)} \]
      2. unsub-neg99.6%

        \[\leadsto \color{blue}{\frac{1}{\sin B} - x \cdot \frac{1}{\tan B}} \]
      3. associate-*r/99.7%

        \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{x \cdot 1}{\tan B}} \]
      4. *-rgt-identity99.7%

        \[\leadsto \frac{1}{\sin B} - \frac{\color{blue}{x}}{\tan B} \]
    3. Simplified99.7%

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

      \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{\cos B \cdot x}{\sin B}} \]
    5. Taylor expanded in x around inf 99.6%

      \[\leadsto \color{blue}{-1 \cdot \frac{\cos B \cdot x}{\sin B}} \]
    6. Step-by-step derivation
      1. associate-*r/99.6%

        \[\leadsto \color{blue}{\frac{-1 \cdot \left(\cos B \cdot x\right)}{\sin B}} \]
      2. neg-mul-199.6%

        \[\leadsto \frac{\color{blue}{-\cos B \cdot x}}{\sin B} \]
      3. distribute-lft-neg-in99.6%

        \[\leadsto \frac{\color{blue}{\left(-\cos B\right) \cdot x}}{\sin B} \]
    7. Simplified99.6%

      \[\leadsto \color{blue}{\frac{\left(-\cos B\right) \cdot x}{\sin B}} \]
    8. Step-by-step derivation
      1. associate-/l*99.4%

        \[\leadsto \color{blue}{\frac{-\cos B}{\frac{\sin B}{x}}} \]
      2. distribute-frac-neg99.4%

        \[\leadsto \color{blue}{-\frac{\cos B}{\frac{\sin B}{x}}} \]
      3. add-sqr-sqrt70.4%

        \[\leadsto -\frac{\color{blue}{\sqrt{\cos B} \cdot \sqrt{\cos B}}}{\frac{\sin B}{x}} \]
      4. sqrt-unprod70.6%

        \[\leadsto -\frac{\color{blue}{\sqrt{\cos B \cdot \cos B}}}{\frac{\sin B}{x}} \]
      5. sqr-neg70.6%

        \[\leadsto -\frac{\sqrt{\color{blue}{\left(-\cos B\right) \cdot \left(-\cos B\right)}}}{\frac{\sin B}{x}} \]
      6. sqrt-unprod0.2%

        \[\leadsto -\frac{\color{blue}{\sqrt{-\cos B} \cdot \sqrt{-\cos B}}}{\frac{\sin B}{x}} \]
      7. add-sqr-sqrt0.4%

        \[\leadsto -\frac{\color{blue}{-\cos B}}{\frac{\sin B}{x}} \]
      8. associate-/l*0.4%

        \[\leadsto -\color{blue}{\frac{\left(-\cos B\right) \cdot x}{\sin B}} \]
      9. *-commutative0.4%

        \[\leadsto -\frac{\color{blue}{x \cdot \left(-\cos B\right)}}{\sin B} \]
      10. associate-/l*0.4%

        \[\leadsto -\color{blue}{\frac{x}{\frac{\sin B}{-\cos B}}} \]
      11. add-sqr-sqrt0.2%

        \[\leadsto -\frac{x}{\frac{\sin B}{\color{blue}{\sqrt{-\cos B} \cdot \sqrt{-\cos B}}}} \]
      12. sqrt-unprod70.9%

        \[\leadsto -\frac{x}{\frac{\sin B}{\color{blue}{\sqrt{\left(-\cos B\right) \cdot \left(-\cos B\right)}}}} \]
      13. sqr-neg70.9%

        \[\leadsto -\frac{x}{\frac{\sin B}{\sqrt{\color{blue}{\cos B \cdot \cos B}}}} \]
      14. sqrt-unprod70.6%

        \[\leadsto -\frac{x}{\frac{\sin B}{\color{blue}{\sqrt{\cos B} \cdot \sqrt{\cos B}}}} \]
      15. add-sqr-sqrt99.6%

        \[\leadsto -\frac{x}{\frac{\sin B}{\color{blue}{\cos B}}} \]
      16. tan-quot99.6%

        \[\leadsto -\frac{x}{\color{blue}{\tan B}} \]
      17. div-inv99.5%

        \[\leadsto -\color{blue}{x \cdot \frac{1}{\tan B}} \]
      18. *-commutative99.5%

        \[\leadsto -\color{blue}{\frac{1}{\tan B} \cdot x} \]
      19. neg-mul-199.5%

        \[\leadsto \color{blue}{-1 \cdot \left(\frac{1}{\tan B} \cdot x\right)} \]
    9. Applied egg-rr99.6%

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

    if -1.8e11 < x < 4.5e6

    1. Initial program 99.9%

      \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
    2. Step-by-step derivation
      1. +-commutative99.9%

        \[\leadsto \color{blue}{\frac{1}{\sin B} + \left(-x \cdot \frac{1}{\tan B}\right)} \]
      2. unsub-neg99.9%

        \[\leadsto \color{blue}{\frac{1}{\sin B} - x \cdot \frac{1}{\tan B}} \]
      3. associate-*r/99.9%

        \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{x \cdot 1}{\tan B}} \]
      4. *-rgt-identity99.9%

        \[\leadsto \frac{1}{\sin B} - \frac{\color{blue}{x}}{\tan B} \]
    3. Simplified99.9%

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

      \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{\cos B \cdot x}{\sin B}} \]
    5. Step-by-step derivation
      1. sub-div99.8%

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

      \[\leadsto \color{blue}{\frac{1 - \cos B \cdot x}{\sin B}} \]
    7. Taylor expanded in B around 0 97.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -180000000000 \lor \neg \left(x \leq 4500000\right):\\ \;\;\;\;\frac{-x}{\tan B}\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - x}{\sin B}\\ \end{array} \]

Alternative 4: 76.0% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \lor \neg \left(x \leq 2.7\right):\\
\;\;\;\;\frac{-x}{\sin B}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.05000000000000004 or 2.7000000000000002 < x

    1. Initial program 99.6%

      \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
    2. Step-by-step derivation
      1. +-commutative99.6%

        \[\leadsto \color{blue}{\frac{1}{\sin B} + \left(-x \cdot \frac{1}{\tan B}\right)} \]
      2. unsub-neg99.6%

        \[\leadsto \color{blue}{\frac{1}{\sin B} - x \cdot \frac{1}{\tan B}} \]
      3. associate-*r/99.7%

        \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{x \cdot 1}{\tan B}} \]
      4. *-rgt-identity99.7%

        \[\leadsto \frac{1}{\sin B} - \frac{\color{blue}{x}}{\tan B} \]
    3. Simplified99.7%

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

      \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{\cos B \cdot x}{\sin B}} \]
    5. Taylor expanded in x around inf 97.9%

      \[\leadsto \color{blue}{-1 \cdot \frac{\cos B \cdot x}{\sin B}} \]
    6. Step-by-step derivation
      1. associate-*r/97.9%

        \[\leadsto \color{blue}{\frac{-1 \cdot \left(\cos B \cdot x\right)}{\sin B}} \]
      2. neg-mul-197.9%

        \[\leadsto \frac{\color{blue}{-\cos B \cdot x}}{\sin B} \]
      3. distribute-lft-neg-in97.9%

        \[\leadsto \frac{\color{blue}{\left(-\cos B\right) \cdot x}}{\sin B} \]
    7. Simplified97.9%

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

      \[\leadsto \frac{\color{blue}{-1 \cdot x}}{\sin B} \]
    9. Step-by-step derivation
      1. neg-mul-151.2%

        \[\leadsto \frac{\color{blue}{-x}}{\sin B} \]
    10. Simplified51.2%

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

    if -1.05000000000000004 < x < 2.7000000000000002

    1. Initial program 99.9%

      \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
    2. Step-by-step derivation
      1. distribute-lft-neg-in99.9%

        \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{1}{\tan B}} + \frac{1}{\sin B} \]
    3. Simplified99.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.05 \lor \neg \left(x \leq 2.7\right):\\ \;\;\;\;\frac{-x}{\sin B}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sin B}\\ \end{array} \]

Alternative 5: 97.8% accurate, 1.9× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.8500000000000001 or 1 < x

    1. Initial program 99.6%

      \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
    2. Step-by-step derivation
      1. +-commutative99.6%

        \[\leadsto \color{blue}{\frac{1}{\sin B} + \left(-x \cdot \frac{1}{\tan B}\right)} \]
      2. unsub-neg99.6%

        \[\leadsto \color{blue}{\frac{1}{\sin B} - x \cdot \frac{1}{\tan B}} \]
      3. associate-*r/99.7%

        \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{x \cdot 1}{\tan B}} \]
      4. *-rgt-identity99.7%

        \[\leadsto \frac{1}{\sin B} - \frac{\color{blue}{x}}{\tan B} \]
    3. Simplified99.7%

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

      \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{\cos B \cdot x}{\sin B}} \]
    5. Taylor expanded in x around inf 97.9%

      \[\leadsto \color{blue}{-1 \cdot \frac{\cos B \cdot x}{\sin B}} \]
    6. Step-by-step derivation
      1. associate-*r/97.9%

        \[\leadsto \color{blue}{\frac{-1 \cdot \left(\cos B \cdot x\right)}{\sin B}} \]
      2. neg-mul-197.9%

        \[\leadsto \frac{\color{blue}{-\cos B \cdot x}}{\sin B} \]
      3. distribute-lft-neg-in97.9%

        \[\leadsto \frac{\color{blue}{\left(-\cos B\right) \cdot x}}{\sin B} \]
    7. Simplified97.9%

      \[\leadsto \color{blue}{\frac{\left(-\cos B\right) \cdot x}{\sin B}} \]
    8. Step-by-step derivation
      1. associate-/l*97.7%

        \[\leadsto \color{blue}{\frac{-\cos B}{\frac{\sin B}{x}}} \]
      2. distribute-frac-neg97.7%

        \[\leadsto \color{blue}{-\frac{\cos B}{\frac{\sin B}{x}}} \]
      3. add-sqr-sqrt69.8%

        \[\leadsto -\frac{\color{blue}{\sqrt{\cos B} \cdot \sqrt{\cos B}}}{\frac{\sin B}{x}} \]
      4. sqrt-unprod70.0%

        \[\leadsto -\frac{\color{blue}{\sqrt{\cos B \cdot \cos B}}}{\frac{\sin B}{x}} \]
      5. sqr-neg70.0%

        \[\leadsto -\frac{\sqrt{\color{blue}{\left(-\cos B\right) \cdot \left(-\cos B\right)}}}{\frac{\sin B}{x}} \]
      6. sqrt-unprod0.2%

        \[\leadsto -\frac{\color{blue}{\sqrt{-\cos B} \cdot \sqrt{-\cos B}}}{\frac{\sin B}{x}} \]
      7. add-sqr-sqrt0.4%

        \[\leadsto -\frac{\color{blue}{-\cos B}}{\frac{\sin B}{x}} \]
      8. associate-/l*0.4%

        \[\leadsto -\color{blue}{\frac{\left(-\cos B\right) \cdot x}{\sin B}} \]
      9. *-commutative0.4%

        \[\leadsto -\frac{\color{blue}{x \cdot \left(-\cos B\right)}}{\sin B} \]
      10. associate-/l*0.4%

        \[\leadsto -\color{blue}{\frac{x}{\frac{\sin B}{-\cos B}}} \]
      11. add-sqr-sqrt0.2%

        \[\leadsto -\frac{x}{\frac{\sin B}{\color{blue}{\sqrt{-\cos B} \cdot \sqrt{-\cos B}}}} \]
      12. sqrt-unprod70.2%

        \[\leadsto -\frac{x}{\frac{\sin B}{\color{blue}{\sqrt{\left(-\cos B\right) \cdot \left(-\cos B\right)}}}} \]
      13. sqr-neg70.2%

        \[\leadsto -\frac{x}{\frac{\sin B}{\sqrt{\color{blue}{\cos B \cdot \cos B}}}} \]
      14. sqrt-unprod69.9%

        \[\leadsto -\frac{x}{\frac{\sin B}{\color{blue}{\sqrt{\cos B} \cdot \sqrt{\cos B}}}} \]
      15. add-sqr-sqrt97.9%

        \[\leadsto -\frac{x}{\frac{\sin B}{\color{blue}{\cos B}}} \]
      16. tan-quot98.0%

        \[\leadsto -\frac{x}{\color{blue}{\tan B}} \]
      17. div-inv97.8%

        \[\leadsto -\color{blue}{x \cdot \frac{1}{\tan B}} \]
      18. *-commutative97.8%

        \[\leadsto -\color{blue}{\frac{1}{\tan B} \cdot x} \]
      19. neg-mul-197.8%

        \[\leadsto \color{blue}{-1 \cdot \left(\frac{1}{\tan B} \cdot x\right)} \]
    9. Applied egg-rr98.0%

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

    if -1.8500000000000001 < x < 1

    1. Initial program 99.9%

      \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
    2. Step-by-step derivation
      1. distribute-lft-neg-in99.9%

        \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{1}{\tan B}} + \frac{1}{\sin B} \]
    3. Simplified99.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.85 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\frac{-x}{\tan B}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sin B}\\ \end{array} \]

Alternative 6: 74.9% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{-6} \lor \neg \left(x \leq 2.55 \cdot 10^{-5}\right):\\
\;\;\;\;B \cdot 0.16666666666666666 + \frac{1 - x}{B}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -4.7999999999999998e-6 or 2.54999999999999998e-5 < x

    1. Initial program 99.6%

      \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
    2. Step-by-step derivation
      1. distribute-lft-neg-in99.6%

        \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{1}{\tan B}} + \frac{1}{\sin B} \]
    3. Simplified99.6%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{B} + \left(\left(0.16666666666666666 + 0.3333333333333333 \cdot x\right) \cdot B + \frac{1}{B}\right)} \]
    5. Step-by-step derivation
      1. +-commutative48.9%

        \[\leadsto \color{blue}{\left(\left(0.16666666666666666 + 0.3333333333333333 \cdot x\right) \cdot B + \frac{1}{B}\right) + -1 \cdot \frac{x}{B}} \]
      2. mul-1-neg48.9%

        \[\leadsto \left(\left(0.16666666666666666 + 0.3333333333333333 \cdot x\right) \cdot B + \frac{1}{B}\right) + \color{blue}{\left(-\frac{x}{B}\right)} \]
      3. sub-neg48.9%

        \[\leadsto \color{blue}{\left(\left(0.16666666666666666 + 0.3333333333333333 \cdot x\right) \cdot B + \frac{1}{B}\right) - \frac{x}{B}} \]
      4. associate--l+48.9%

        \[\leadsto \color{blue}{\left(0.16666666666666666 + 0.3333333333333333 \cdot x\right) \cdot B + \left(\frac{1}{B} - \frac{x}{B}\right)} \]
      5. *-commutative48.9%

        \[\leadsto \color{blue}{B \cdot \left(0.16666666666666666 + 0.3333333333333333 \cdot x\right)} + \left(\frac{1}{B} - \frac{x}{B}\right) \]
      6. *-commutative48.9%

        \[\leadsto B \cdot \left(0.16666666666666666 + \color{blue}{x \cdot 0.3333333333333333}\right) + \left(\frac{1}{B} - \frac{x}{B}\right) \]
      7. div-sub48.9%

        \[\leadsto B \cdot \left(0.16666666666666666 + x \cdot 0.3333333333333333\right) + \color{blue}{\frac{1 - x}{B}} \]
    6. Simplified48.9%

      \[\leadsto \color{blue}{B \cdot \left(0.16666666666666666 + x \cdot 0.3333333333333333\right) + \frac{1 - x}{B}} \]
    7. Taylor expanded in x around 0 49.7%

      \[\leadsto \color{blue}{0.16666666666666666 \cdot B} + \frac{1 - x}{B} \]
    8. Step-by-step derivation
      1. *-commutative49.7%

        \[\leadsto \color{blue}{B \cdot 0.16666666666666666} + \frac{1 - x}{B} \]
    9. Simplified49.7%

      \[\leadsto \color{blue}{B \cdot 0.16666666666666666} + \frac{1 - x}{B} \]

    if -4.7999999999999998e-6 < x < 2.54999999999999998e-5

    1. Initial program 99.9%

      \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
    2. Step-by-step derivation
      1. distribute-lft-neg-in99.9%

        \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{1}{\tan B}} + \frac{1}{\sin B} \]
    3. Simplified99.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.8 \cdot 10^{-6} \lor \neg \left(x \leq 2.55 \cdot 10^{-5}\right):\\ \;\;\;\;B \cdot 0.16666666666666666 + \frac{1 - x}{B}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sin B}\\ \end{array} \]

Alternative 7: 51.8% accurate, 23.3× speedup?

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

\\
B \cdot 0.16666666666666666 + \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. Step-by-step derivation
    1. distribute-lft-neg-in99.7%

      \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{1}{\tan B}} + \frac{1}{\sin B} \]
  3. Simplified99.7%

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

    \[\leadsto \color{blue}{-1 \cdot \frac{x}{B} + \left(\left(0.16666666666666666 + 0.3333333333333333 \cdot x\right) \cdot B + \frac{1}{B}\right)} \]
  5. Step-by-step derivation
    1. +-commutative50.9%

      \[\leadsto \color{blue}{\left(\left(0.16666666666666666 + 0.3333333333333333 \cdot x\right) \cdot B + \frac{1}{B}\right) + -1 \cdot \frac{x}{B}} \]
    2. mul-1-neg50.9%

      \[\leadsto \left(\left(0.16666666666666666 + 0.3333333333333333 \cdot x\right) \cdot B + \frac{1}{B}\right) + \color{blue}{\left(-\frac{x}{B}\right)} \]
    3. sub-neg50.9%

      \[\leadsto \color{blue}{\left(\left(0.16666666666666666 + 0.3333333333333333 \cdot x\right) \cdot B + \frac{1}{B}\right) - \frac{x}{B}} \]
    4. associate--l+50.9%

      \[\leadsto \color{blue}{\left(0.16666666666666666 + 0.3333333333333333 \cdot x\right) \cdot B + \left(\frac{1}{B} - \frac{x}{B}\right)} \]
    5. *-commutative50.9%

      \[\leadsto \color{blue}{B \cdot \left(0.16666666666666666 + 0.3333333333333333 \cdot x\right)} + \left(\frac{1}{B} - \frac{x}{B}\right) \]
    6. *-commutative50.9%

      \[\leadsto B \cdot \left(0.16666666666666666 + \color{blue}{x \cdot 0.3333333333333333}\right) + \left(\frac{1}{B} - \frac{x}{B}\right) \]
    7. div-sub50.9%

      \[\leadsto B \cdot \left(0.16666666666666666 + x \cdot 0.3333333333333333\right) + \color{blue}{\frac{1 - x}{B}} \]
  6. Simplified50.9%

    \[\leadsto \color{blue}{B \cdot \left(0.16666666666666666 + x \cdot 0.3333333333333333\right) + \frac{1 - x}{B}} \]
  7. Taylor expanded in x around 0 51.3%

    \[\leadsto \color{blue}{0.16666666666666666 \cdot B} + \frac{1 - x}{B} \]
  8. Step-by-step derivation
    1. *-commutative51.3%

      \[\leadsto \color{blue}{B \cdot 0.16666666666666666} + \frac{1 - x}{B} \]
  9. Simplified51.3%

    \[\leadsto \color{blue}{B \cdot 0.16666666666666666} + \frac{1 - x}{B} \]
  10. Final simplification51.3%

    \[\leadsto B \cdot 0.16666666666666666 + \frac{1 - x}{B} \]

Alternative 8: 50.5% accurate, 25.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -750 \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 -750.0) (not (<= x 1.0))) (- (/ x B)) (/ 1.0 B)))
double code(double B, double x) {
	double tmp;
	if ((x <= -750.0) || !(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 <= (-750.0d0)) .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 <= -750.0) || !(x <= 1.0)) {
		tmp = -(x / B);
	} else {
		tmp = 1.0 / B;
	}
	return tmp;
}
def code(B, x):
	tmp = 0
	if (x <= -750.0) or not (x <= 1.0):
		tmp = -(x / B)
	else:
		tmp = 1.0 / B
	return tmp
function code(B, x)
	tmp = 0.0
	if ((x <= -750.0) || !(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 <= -750.0) || ~((x <= 1.0)))
		tmp = -(x / B);
	else
		tmp = 1.0 / B;
	end
	tmp_2 = tmp;
end
code[B_, x_] := If[Or[LessEqual[x, -750.0], 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 -750 \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 < -750 or 1 < x

    1. Initial program 99.6%

      \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
    2. Step-by-step derivation
      1. distribute-lft-neg-in99.6%

        \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{1}{\tan B}} + \frac{1}{\sin B} \]
    3. Simplified99.6%

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

      \[\leadsto \color{blue}{\frac{1 + -1 \cdot x}{B}} \]
    5. Step-by-step derivation
      1. mul-1-neg49.0%

        \[\leadsto \frac{1 + \color{blue}{\left(-x\right)}}{B} \]
      2. sub-neg49.0%

        \[\leadsto \frac{\color{blue}{1 - x}}{B} \]
    6. Simplified49.0%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{B}} \]
    8. Step-by-step derivation
      1. neg-mul-148.3%

        \[\leadsto \color{blue}{-\frac{x}{B}} \]
      2. distribute-neg-frac48.3%

        \[\leadsto \color{blue}{\frac{-x}{B}} \]
    9. Simplified48.3%

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

    if -750 < x < 1

    1. Initial program 99.9%

      \[\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B} \]
    2. Step-by-step derivation
      1. distribute-lft-neg-in99.9%

        \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{1}{\tan B}} + \frac{1}{\sin B} \]
    3. Simplified99.9%

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

      \[\leadsto \color{blue}{\frac{1 + -1 \cdot x}{B}} \]
    5. Step-by-step derivation
      1. mul-1-neg54.1%

        \[\leadsto \frac{1 + \color{blue}{\left(-x\right)}}{B} \]
      2. sub-neg54.1%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -750 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;-\frac{x}{B}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{B}\\ \end{array} \]

Alternative 9: 51.6% accurate, 42.0× 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. Step-by-step derivation
    1. distribute-lft-neg-in99.7%

      \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{1}{\tan B}} + \frac{1}{\sin B} \]
  3. Simplified99.7%

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

    \[\leadsto \color{blue}{\frac{1 + -1 \cdot x}{B}} \]
  5. Step-by-step derivation
    1. mul-1-neg51.3%

      \[\leadsto \frac{1 + \color{blue}{\left(-x\right)}}{B} \]
    2. sub-neg51.3%

      \[\leadsto \frac{\color{blue}{1 - x}}{B} \]
  6. Simplified51.3%

    \[\leadsto \color{blue}{\frac{1 - x}{B}} \]
  7. Final simplification51.3%

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

Alternative 10: 27.1% accurate, 70.0× 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. Step-by-step derivation
    1. distribute-lft-neg-in99.7%

      \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{1}{\tan B}} + \frac{1}{\sin B} \]
  3. Simplified99.7%

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

    \[\leadsto \color{blue}{\frac{1 + -1 \cdot x}{B}} \]
  5. Step-by-step derivation
    1. mul-1-neg51.3%

      \[\leadsto \frac{1 + \color{blue}{\left(-x\right)}}{B} \]
    2. sub-neg51.3%

      \[\leadsto \frac{\color{blue}{1 - x}}{B} \]
  6. Simplified51.3%

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

    \[\leadsto \color{blue}{\frac{1}{B}} \]
  8. Final simplification24.5%

    \[\leadsto \frac{1}{B} \]

Reproduce

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