VandenBroeck and Keller, Equation (24)

Percentage Accurate: 99.7% → 99.8%
Time: 9.4s
Alternatives: 12
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 12 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.8%

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

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

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

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

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

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

      \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{x \cdot 1}{\tan B}} \]
    7. *-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.4% accurate, 1.9× speedup?

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

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

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


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

    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} \]
      2. +-commutative99.7%

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

        \[\leadsto \frac{1}{\sin B} + \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right)} \]
      4. distribute-rgt-neg-in99.7%

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

      \[\leadsto \color{blue}{\frac{1}{\sin B} + x \cdot \left(-\frac{1}{\tan B}\right)} \]
    4. Step-by-step derivation
      1. distribute-rgt-neg-out99.7%

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

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

        \[\leadsto \frac{1}{\sin B} + \left(-\color{blue}{\frac{1}{\frac{\tan B}{x}}}\right) \]
      4. distribute-neg-frac99.7%

        \[\leadsto \frac{1}{\sin B} + \color{blue}{\frac{-1}{\frac{\tan B}{x}}} \]
      5. metadata-eval99.7%

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\sin B} + -1 \cdot \frac{x \cdot \cos B}{\sin B}} \]
      2. mul-1-neg99.7%

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

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

        \[\leadsto \color{blue}{\frac{1}{\sin B} - x \cdot \frac{\cos B}{\sin B}} \]
    8. Simplified99.7%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{x \cdot \cos B}{\sin B}} \]
    10. Step-by-step derivation
      1. mul-1-neg98.7%

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

        \[\leadsto \color{blue}{\frac{-x \cdot \cos B}{\sin B}} \]
      3. distribute-rgt-neg-in98.7%

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

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

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

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

        \[\leadsto \frac{x}{\frac{\sin B}{\color{blue}{\sqrt{\left(-\cos B\right) \cdot \left(-\cos B\right)}}}} \]
      4. sqr-neg25.0%

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

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

        \[\leadsto \frac{x}{\frac{\sin B}{\color{blue}{\cos B}}} \]
      7. tan-quot0.4%

        \[\leadsto \frac{x}{\color{blue}{\tan B}} \]
      8. frac-2neg0.4%

        \[\leadsto \color{blue}{\frac{-x}{-\tan B}} \]
      9. div-inv0.4%

        \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{1}{-\tan B}} \]
      10. neg-mul-10.4%

        \[\leadsto \left(-x\right) \cdot \frac{1}{\color{blue}{-1 \cdot \tan B}} \]
      11. metadata-eval0.4%

        \[\leadsto \left(-x\right) \cdot \frac{1}{\color{blue}{\frac{1}{-1}} \cdot \tan B} \]
      12. tan-quot0.4%

        \[\leadsto \left(-x\right) \cdot \frac{1}{\frac{1}{-1} \cdot \color{blue}{\frac{\sin B}{\cos B}}} \]
      13. times-frac0.4%

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

        \[\leadsto \left(-x\right) \cdot \frac{1}{\frac{1 \cdot \sin B}{\color{blue}{-\cos B}}} \]
      15. add-sqr-sqrt0.1%

        \[\leadsto \left(-x\right) \cdot \frac{1}{\frac{1 \cdot \sin B}{\color{blue}{\sqrt{-\cos B} \cdot \sqrt{-\cos B}}}} \]
      16. sqrt-unprod73.9%

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

        \[\leadsto \left(-x\right) \cdot \frac{1}{\frac{1 \cdot \sin B}{\sqrt{\color{blue}{\cos B \cdot \cos B}}}} \]
      18. sqrt-unprod73.7%

        \[\leadsto \left(-x\right) \cdot \frac{1}{\frac{1 \cdot \sin B}{\color{blue}{\sqrt{\cos B} \cdot \sqrt{\cos B}}}} \]
      19. *-un-lft-identity73.7%

        \[\leadsto \left(-x\right) \cdot \frac{1}{\frac{\color{blue}{\sin B}}{\sqrt{\cos B} \cdot \sqrt{\cos B}}} \]
      20. add-sqr-sqrt98.5%

        \[\leadsto \left(-x\right) \cdot \frac{1}{\frac{\sin B}{\color{blue}{\cos B}}} \]
      21. tan-quot98.7%

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

      \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{1}{\tan B}} \]
    14. Step-by-step derivation
      1. associate-*r/98.8%

        \[\leadsto \color{blue}{\frac{\left(-x\right) \cdot 1}{\tan B}} \]
      2. *-rgt-identity98.8%

        \[\leadsto \frac{\color{blue}{-x}}{\tan B} \]
    15. Simplified98.8%

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

    if -195000 < x < 45000

    1. Initial program 99.8%

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

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

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

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

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

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

        \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{x \cdot 1}{\tan B}} \]
      7. *-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 B around 0 97.9%

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

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

Alternative 3: 98.4% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -8000000 \lor \neg \left(x \leq 13800\right):\\ \;\;\;\;\frac{-x}{\tan B}\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - x}{\sin B}\\ \end{array} \end{array} \]
(FPCore (B x)
 :precision binary64
 (if (or (<= x -8000000.0) (not (<= x 13800.0)))
   (/ (- x) (tan B))
   (/ (- 1.0 x) (sin B))))
double code(double B, double x) {
	double tmp;
	if ((x <= -8000000.0) || !(x <= 13800.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 <= (-8000000.0d0)) .or. (.not. (x <= 13800.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 <= -8000000.0) || !(x <= 13800.0)) {
		tmp = -x / Math.tan(B);
	} else {
		tmp = (1.0 - x) / Math.sin(B);
	}
	return tmp;
}
def code(B, x):
	tmp = 0
	if (x <= -8000000.0) or not (x <= 13800.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 <= -8000000.0) || !(x <= 13800.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 <= -8000000.0) || ~((x <= 13800.0)))
		tmp = -x / tan(B);
	else
		tmp = (1.0 - x) / sin(B);
	end
	tmp_2 = tmp;
end
code[B_, x_] := If[Or[LessEqual[x, -8000000.0], N[Not[LessEqual[x, 13800.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 -8000000 \lor \neg \left(x \leq 13800\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 < -8e6 or 13800 < x

    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} \]
      2. +-commutative99.7%

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

        \[\leadsto \frac{1}{\sin B} + \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right)} \]
      4. distribute-rgt-neg-in99.7%

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

      \[\leadsto \color{blue}{\frac{1}{\sin B} + x \cdot \left(-\frac{1}{\tan B}\right)} \]
    4. Step-by-step derivation
      1. distribute-rgt-neg-out99.7%

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

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

        \[\leadsto \frac{1}{\sin B} + \left(-\color{blue}{\frac{1}{\frac{\tan B}{x}}}\right) \]
      4. distribute-neg-frac99.7%

        \[\leadsto \frac{1}{\sin B} + \color{blue}{\frac{-1}{\frac{\tan B}{x}}} \]
      5. metadata-eval99.7%

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\sin B} + -1 \cdot \frac{x \cdot \cos B}{\sin B}} \]
      2. mul-1-neg99.7%

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

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

        \[\leadsto \color{blue}{\frac{1}{\sin B} - x \cdot \frac{\cos B}{\sin B}} \]
    8. Simplified99.7%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{x \cdot \cos B}{\sin B}} \]
    10. Step-by-step derivation
      1. mul-1-neg98.7%

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

        \[\leadsto \color{blue}{\frac{-x \cdot \cos B}{\sin B}} \]
      3. distribute-rgt-neg-in98.7%

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

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

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

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

        \[\leadsto \frac{x}{\frac{\sin B}{\color{blue}{\sqrt{\left(-\cos B\right) \cdot \left(-\cos B\right)}}}} \]
      4. sqr-neg25.0%

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

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

        \[\leadsto \frac{x}{\frac{\sin B}{\color{blue}{\cos B}}} \]
      7. tan-quot0.4%

        \[\leadsto \frac{x}{\color{blue}{\tan B}} \]
      8. frac-2neg0.4%

        \[\leadsto \color{blue}{\frac{-x}{-\tan B}} \]
      9. div-inv0.4%

        \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{1}{-\tan B}} \]
      10. neg-mul-10.4%

        \[\leadsto \left(-x\right) \cdot \frac{1}{\color{blue}{-1 \cdot \tan B}} \]
      11. metadata-eval0.4%

        \[\leadsto \left(-x\right) \cdot \frac{1}{\color{blue}{\frac{1}{-1}} \cdot \tan B} \]
      12. tan-quot0.4%

        \[\leadsto \left(-x\right) \cdot \frac{1}{\frac{1}{-1} \cdot \color{blue}{\frac{\sin B}{\cos B}}} \]
      13. times-frac0.4%

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

        \[\leadsto \left(-x\right) \cdot \frac{1}{\frac{1 \cdot \sin B}{\color{blue}{-\cos B}}} \]
      15. add-sqr-sqrt0.1%

        \[\leadsto \left(-x\right) \cdot \frac{1}{\frac{1 \cdot \sin B}{\color{blue}{\sqrt{-\cos B} \cdot \sqrt{-\cos B}}}} \]
      16. sqrt-unprod73.9%

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

        \[\leadsto \left(-x\right) \cdot \frac{1}{\frac{1 \cdot \sin B}{\sqrt{\color{blue}{\cos B \cdot \cos B}}}} \]
      18. sqrt-unprod73.7%

        \[\leadsto \left(-x\right) \cdot \frac{1}{\frac{1 \cdot \sin B}{\color{blue}{\sqrt{\cos B} \cdot \sqrt{\cos B}}}} \]
      19. *-un-lft-identity73.7%

        \[\leadsto \left(-x\right) \cdot \frac{1}{\frac{\color{blue}{\sin B}}{\sqrt{\cos B} \cdot \sqrt{\cos B}}} \]
      20. add-sqr-sqrt98.5%

        \[\leadsto \left(-x\right) \cdot \frac{1}{\frac{\sin B}{\color{blue}{\cos B}}} \]
      21. tan-quot98.7%

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

      \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{1}{\tan B}} \]
    14. Step-by-step derivation
      1. associate-*r/98.8%

        \[\leadsto \color{blue}{\frac{\left(-x\right) \cdot 1}{\tan B}} \]
      2. *-rgt-identity98.8%

        \[\leadsto \frac{\color{blue}{-x}}{\tan B} \]
    15. Simplified98.8%

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

    if -8e6 < x < 13800

    1. Initial program 99.8%

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

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

        \[\leadsto \color{blue}{\frac{1}{\sin B} + \left(-x\right) \cdot \frac{1}{\tan B}} \]
      3. distribute-lft-neg-in99.8%

        \[\leadsto \frac{1}{\sin B} + \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right)} \]
      4. distribute-rgt-neg-in99.8%

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

      \[\leadsto \color{blue}{\frac{1}{\sin B} + x \cdot \left(-\frac{1}{\tan B}\right)} \]
    4. Step-by-step derivation
      1. distribute-rgt-neg-out99.8%

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

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

        \[\leadsto \frac{1}{\sin B} + \left(-\color{blue}{\frac{1}{\frac{\tan B}{x}}}\right) \]
      4. distribute-neg-frac99.9%

        \[\leadsto \frac{1}{\sin B} + \color{blue}{\frac{-1}{\frac{\tan B}{x}}} \]
      5. metadata-eval99.9%

        \[\leadsto \frac{1}{\sin B} + \frac{\color{blue}{-1}}{\frac{\tan B}{x}} \]
    5. Applied egg-rr99.9%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{x \cdot \cos B}{\sin B} + \frac{1}{\sin B}} \]
    7. Step-by-step derivation
      1. +-commutative99.8%

        \[\leadsto \color{blue}{\frac{1}{\sin B} + -1 \cdot \frac{x \cdot \cos B}{\sin B}} \]
      2. mul-1-neg99.8%

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\sin B} - \frac{x \cdot \cos B}{\sin B}} \]
    10. Step-by-step derivation
      1. div-sub99.8%

        \[\leadsto \color{blue}{\frac{1 - x \cdot \cos B}{\sin B}} \]
    11. Simplified99.8%

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

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

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

Alternative 4: 97.6% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.52 \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.52) (not (<= x 1.0))) (/ (- x) (tan B)) (/ 1.0 (sin B))))
double code(double B, double x) {
	double tmp;
	if ((x <= -1.52) || !(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.52d0)) .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.52) || !(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.52) 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.52) || !(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.52) || ~((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.52], 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.52 \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.52 or 1 < x

    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} \]
      2. +-commutative99.7%

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

        \[\leadsto \frac{1}{\sin B} + \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right)} \]
      4. distribute-rgt-neg-in99.7%

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

      \[\leadsto \color{blue}{\frac{1}{\sin B} + x \cdot \left(-\frac{1}{\tan B}\right)} \]
    4. Step-by-step derivation
      1. distribute-rgt-neg-out99.7%

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

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

        \[\leadsto \frac{1}{\sin B} + \left(-\color{blue}{\frac{1}{\frac{\tan B}{x}}}\right) \]
      4. distribute-neg-frac99.7%

        \[\leadsto \frac{1}{\sin B} + \color{blue}{\frac{-1}{\frac{\tan B}{x}}} \]
      5. metadata-eval99.7%

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\sin B} + -1 \cdot \frac{x \cdot \cos B}{\sin B}} \]
      2. mul-1-neg99.7%

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

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

        \[\leadsto \color{blue}{\frac{1}{\sin B} - x \cdot \frac{\cos B}{\sin B}} \]
    8. Simplified99.7%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{x \cdot \cos B}{\sin B}} \]
    10. Step-by-step derivation
      1. mul-1-neg97.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{x}{\frac{\sin B}{\color{blue}{\cos B}}} \]
      7. tan-quot0.4%

        \[\leadsto \frac{x}{\color{blue}{\tan B}} \]
      8. frac-2neg0.4%

        \[\leadsto \color{blue}{\frac{-x}{-\tan B}} \]
      9. div-inv0.4%

        \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{1}{-\tan B}} \]
      10. neg-mul-10.4%

        \[\leadsto \left(-x\right) \cdot \frac{1}{\color{blue}{-1 \cdot \tan B}} \]
      11. metadata-eval0.4%

        \[\leadsto \left(-x\right) \cdot \frac{1}{\color{blue}{\frac{1}{-1}} \cdot \tan B} \]
      12. tan-quot0.4%

        \[\leadsto \left(-x\right) \cdot \frac{1}{\frac{1}{-1} \cdot \color{blue}{\frac{\sin B}{\cos B}}} \]
      13. times-frac0.4%

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

        \[\leadsto \left(-x\right) \cdot \frac{1}{\frac{1 \cdot \sin B}{\color{blue}{-\cos B}}} \]
      15. add-sqr-sqrt0.1%

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

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

        \[\leadsto \left(-x\right) \cdot \frac{1}{\frac{1 \cdot \sin B}{\sqrt{\color{blue}{\cos B \cdot \cos B}}}} \]
      18. sqrt-unprod73.0%

        \[\leadsto \left(-x\right) \cdot \frac{1}{\frac{1 \cdot \sin B}{\color{blue}{\sqrt{\cos B} \cdot \sqrt{\cos B}}}} \]
      19. *-un-lft-identity73.0%

        \[\leadsto \left(-x\right) \cdot \frac{1}{\frac{\color{blue}{\sin B}}{\sqrt{\cos B} \cdot \sqrt{\cos B}}} \]
      20. add-sqr-sqrt97.5%

        \[\leadsto \left(-x\right) \cdot \frac{1}{\frac{\sin B}{\color{blue}{\cos B}}} \]
      21. tan-quot97.6%

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

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

        \[\leadsto \color{blue}{\frac{\left(-x\right) \cdot 1}{\tan B}} \]
      2. *-rgt-identity97.7%

        \[\leadsto \frac{\color{blue}{-x}}{\tan B} \]
    15. Simplified97.7%

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

    if -1.52 < x < 1

    1. Initial program 99.8%

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

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

        \[\leadsto \color{blue}{\frac{1}{\sin B} + \left(-x\right) \cdot \frac{1}{\tan B}} \]
      3. distribute-lft-neg-in99.8%

        \[\leadsto \frac{1}{\sin B} + \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right)} \]
      4. distribute-rgt-neg-in99.8%

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

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

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

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

Alternative 5: 74.1% accurate, 2.0× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -2.25e-10 or 1.04999999999999994e-5 < x

    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} \]
      2. +-commutative99.7%

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

        \[\leadsto \frac{1}{\sin B} + \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right)} \]
      4. distribute-rgt-neg-in99.7%

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

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

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

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

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

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

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

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

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

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

    if -2.25e-10 < x < 1.04999999999999994e-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} \]
      2. +-commutative99.9%

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

        \[\leadsto \frac{1}{\sin B} + \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right)} \]
      4. distribute-rgt-neg-in99.9%

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

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

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

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

Alternative 6: 51.7% accurate, 16.2× speedup?

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

\\
B \cdot \left(0.16666666666666666 + x \cdot 0.3333333333333333\right) + \frac{1 - x}{B}
\end{array}
Derivation
  1. Initial program 99.8%

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

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

      \[\leadsto \color{blue}{\frac{1}{\sin B} + \left(-x\right) \cdot \frac{1}{\tan B}} \]
    3. distribute-lft-neg-in99.8%

      \[\leadsto \frac{1}{\sin B} + \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right)} \]
    4. distribute-rgt-neg-in99.8%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto B \cdot \left(0.16666666666666666 + x \cdot 0.3333333333333333\right) + \frac{1 - x}{B} \]

Alternative 7: 51.7% accurate, 16.2× speedup?

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

\\
\frac{1}{B} + x \cdot \left(\frac{-1}{B} - B \cdot -0.3333333333333333\right)
\end{array}
Derivation
  1. Initial program 99.8%

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

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

      \[\leadsto \color{blue}{\frac{1}{\sin B} + \left(-x\right) \cdot \frac{1}{\tan B}} \]
    3. distribute-lft-neg-in99.8%

      \[\leadsto \frac{1}{\sin B} + \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right)} \]
    4. distribute-rgt-neg-in99.8%

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

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

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

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

    \[\leadsto \color{blue}{\frac{1}{B}} + x \cdot \left(-\left(-0.3333333333333333 \cdot B + \frac{1}{B}\right)\right) \]
  7. Final simplification53.3%

    \[\leadsto \frac{1}{B} + x \cdot \left(\frac{-1}{B} - B \cdot -0.3333333333333333\right) \]

Alternative 8: 51.6% accurate, 23.3× speedup?

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

\\
\frac{1 - x}{B} + B \cdot 0.16666666666666666
\end{array}
Derivation
  1. Initial program 99.8%

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

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

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

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

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

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

      \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{x \cdot 1}{\tan B}} \]
    7. *-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 B around 0 74.0%

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

    \[\leadsto \color{blue}{\left(0.16666666666666666 \cdot B + \frac{1}{B}\right) - \frac{x}{B}} \]
  6. Step-by-step derivation
    1. associate--l+52.9%

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

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

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

    \[\leadsto \color{blue}{B \cdot 0.16666666666666666 + \frac{1 - x}{B}} \]
  8. Final simplification52.9%

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

Alternative 9: 49.0% accurate, 25.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 3.1 \cdot 10^{-39}\right):\\
\;\;\;\;\frac{-x}{B}\\

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


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

    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} \]
      2. +-commutative99.7%

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

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

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

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

        \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{x \cdot 1}{\tan B}} \]
      7. *-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 B around 0 55.1%

      \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{x}{B}} \]
    5. Step-by-step derivation
      1. clear-num55.1%

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

        \[\leadsto \color{blue}{\frac{1 \cdot \frac{B}{x} - \sin B \cdot 1}{\sin B \cdot \frac{B}{x}}} \]
      3. *-un-lft-identity45.6%

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

      \[\leadsto \color{blue}{\frac{\frac{B}{x} - \sin B \cdot 1}{\sin B \cdot \frac{B}{x}}} \]
    7. Step-by-step derivation
      1. *-rgt-identity45.6%

        \[\leadsto \frac{\frac{B}{x} - \color{blue}{\sin B}}{\sin B \cdot \frac{B}{x}} \]
    8. Simplified45.6%

      \[\leadsto \color{blue}{\frac{\frac{B}{x} - \sin B}{\sin B \cdot \frac{B}{x}}} \]
    9. Taylor expanded in x around inf 52.2%

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

        \[\leadsto \color{blue}{\frac{-1 \cdot x}{B}} \]
      2. neg-mul-152.2%

        \[\leadsto \frac{\color{blue}{-x}}{B} \]
    11. Simplified52.2%

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

    if -1 < x < 3.0999999999999997e-39

    1. Initial program 99.8%

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

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

        \[\leadsto \color{blue}{\frac{1}{\sin B} + \left(-x\right) \cdot \frac{1}{\tan B}} \]
      3. distribute-lft-neg-in99.8%

        \[\leadsto \frac{1}{\sin B} + \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right)} \]
      4. distribute-rgt-neg-in99.8%

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

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

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

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

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

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

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

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

Alternative 10: 51.5% 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.8%

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

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

      \[\leadsto \color{blue}{\frac{1}{\sin B} + \left(-x\right) \cdot \frac{1}{\tan B}} \]
    3. distribute-lft-neg-in99.8%

      \[\leadsto \frac{1}{\sin B} + \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right)} \]
    4. distribute-rgt-neg-in99.8%

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

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

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

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

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

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

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

Alternative 11: 3.1% accurate, 70.0× 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.8%

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

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

      \[\leadsto \color{blue}{\frac{1}{\sin B} + \left(-x\right) \cdot \frac{1}{\tan B}} \]
    3. distribute-lft-neg-in99.8%

      \[\leadsto \frac{1}{\sin B} + \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right)} \]
    4. distribute-rgt-neg-in99.8%

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

    \[\leadsto \color{blue}{\frac{1}{\sin B} + x \cdot \left(-\frac{1}{\tan B}\right)} \]
  4. Step-by-step derivation
    1. distribute-rgt-neg-out99.8%

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

      \[\leadsto \frac{1}{\sin B} + \left(-\color{blue}{\frac{x}{\tan B}}\right) \]
    3. clear-num99.8%

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

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

      \[\leadsto \frac{1}{\sin B} + \frac{\color{blue}{-1}}{\frac{\tan B}{x}} \]
  5. Applied egg-rr99.8%

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

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

    \[\leadsto \color{blue}{0.16666666666666666 \cdot B} \]
  8. Step-by-step derivation
    1. *-commutative3.2%

      \[\leadsto \color{blue}{B \cdot 0.16666666666666666} \]
  9. Simplified3.2%

    \[\leadsto \color{blue}{B \cdot 0.16666666666666666} \]
  10. Final simplification3.2%

    \[\leadsto B \cdot 0.16666666666666666 \]

Alternative 12: 26.9% 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.8%

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

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

      \[\leadsto \color{blue}{\frac{1}{\sin B} + \left(-x\right) \cdot \frac{1}{\tan B}} \]
    3. distribute-lft-neg-in99.8%

      \[\leadsto \frac{1}{\sin B} + \color{blue}{\left(-x \cdot \frac{1}{\tan B}\right)} \]
    4. distribute-rgt-neg-in99.8%

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{1}{B}} \]
  8. Final simplification23.4%

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

Reproduce

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