VandenBroeck and Keller, Equation (24)

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\sin B} - \frac{\color{blue}{-x}}{\tan \left(-B\right)} \]
    11. tan-neg99.8%

      \[\leadsto \frac{1}{\sin B} - \frac{-x}{\color{blue}{-\tan B}} \]
    12. distribute-neg-frac299.8%

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

      \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{-\left(-x\right)}{\tan B}} \]
    14. remove-double-neg99.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. Add Preprocessing
  5. Add Preprocessing

Alternative 2: 98.6% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25:\\
\;\;\;\;\frac{1 - x}{\tan B}\\

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

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


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

    1. Initial program 99.6%

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

        \[\leadsto \color{blue}{\frac{1}{\sin B} + \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. sub-neg99.8%

        \[\leadsto \color{blue}{\frac{1}{\sin B} - \frac{x}{\tan B}} \]
      4. clear-num99.4%

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

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

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

        \[\leadsto \frac{\frac{\tan B}{x} - \color{blue}{1 \cdot \sin B}}{\sin B \cdot \frac{\tan B}{x}} \]
      8. *-un-lft-identity88.9%

        \[\leadsto \frac{\frac{\tan B}{x} - \color{blue}{\sin B}}{\sin B \cdot \frac{\tan B}{x}} \]
    4. Applied egg-rr88.9%

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

        \[\leadsto \color{blue}{\frac{\frac{\frac{\tan B}{x} - \sin B}{\sin B}}{\frac{\tan B}{x}}} \]
      2. div-sub99.5%

        \[\leadsto \frac{\color{blue}{\frac{\frac{\tan B}{x}}{\sin B} - \frac{\sin B}{\sin B}}}{\frac{\tan B}{x}} \]
      3. *-inverses99.5%

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

      \[\leadsto \color{blue}{\frac{\frac{\frac{\tan B}{x}}{\sin B} - 1}{\frac{\tan B}{x}}} \]
    7. Step-by-step derivation
      1. div-sub75.6%

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

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

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

        \[\leadsto \frac{\tan B}{\color{blue}{x \cdot \sin B}} \cdot \frac{1}{\frac{\tan B}{x}} - \frac{1}{\frac{\tan B}{x}} \]
      5. clear-num99.4%

        \[\leadsto \frac{\tan B}{x \cdot \sin B} \cdot \color{blue}{\frac{x}{\tan B}} - \frac{1}{\frac{\tan B}{x}} \]
      6. clear-num99.8%

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

      \[\leadsto \color{blue}{\frac{\tan B}{x \cdot \sin B} \cdot \frac{x}{\tan B} - \frac{x}{\tan B}} \]
    9. Step-by-step derivation
      1. sub-neg99.8%

        \[\leadsto \color{blue}{\frac{\tan B}{x \cdot \sin B} \cdot \frac{x}{\tan B} + \left(-\frac{x}{\tan B}\right)} \]
      2. neg-mul-199.8%

        \[\leadsto \frac{\tan B}{x \cdot \sin B} \cdot \frac{x}{\tan B} + \color{blue}{-1 \cdot \frac{x}{\tan B}} \]
      3. distribute-rgt-in99.8%

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

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

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

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

    if -1.25 < x < 51000

    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. *-commutative99.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\sin B} - \frac{\color{blue}{-x}}{\tan \left(-B\right)} \]
      11. tan-neg99.8%

        \[\leadsto \frac{1}{\sin B} - \frac{-x}{\color{blue}{-\tan B}} \]
      12. distribute-neg-frac299.8%

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

        \[\leadsto \frac{1}{\sin B} - \color{blue}{\frac{-\left(-x\right)}{\tan B}} \]
      14. remove-double-neg99.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. Add Preprocessing
    5. Taylor expanded in B around 0 97.1%

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

    if 51000 < x

    1. Initial program 99.7%

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

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

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

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

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

      \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{\cos B}{\sin B}} \]
    6. Step-by-step derivation
      1. distribute-lft-neg-out98.0%

        \[\leadsto \color{blue}{-x \cdot \frac{\cos B}{\sin B}} \]
      2. clear-num98.0%

        \[\leadsto -x \cdot \color{blue}{\frac{1}{\frac{\sin B}{\cos B}}} \]
      3. tan-quot98.1%

        \[\leadsto -x \cdot \frac{1}{\color{blue}{\tan B}} \]
      4. div-inv98.2%

        \[\leadsto -\color{blue}{\frac{x}{\tan B}} \]
      5. neg-sub098.2%

        \[\leadsto \color{blue}{0 - \frac{x}{\tan B}} \]
    7. Applied egg-rr98.2%

      \[\leadsto \color{blue}{0 - \frac{x}{\tan B}} \]
    8. Step-by-step derivation
      1. neg-sub098.2%

        \[\leadsto \color{blue}{-\frac{x}{\tan B}} \]
      2. distribute-frac-neg298.2%

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

      \[\leadsto \color{blue}{\frac{x}{-\tan B}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 3: 98.2% accurate, 1.8× speedup?

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

    1. Initial program 99.6%

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

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

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

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

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

      \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{\cos B}{\sin B}} \]
    6. Step-by-step derivation
      1. distribute-lft-neg-out97.8%

        \[\leadsto \color{blue}{-x \cdot \frac{\cos B}{\sin B}} \]
      2. clear-num97.8%

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

        \[\leadsto -x \cdot \frac{1}{\color{blue}{\tan B}} \]
      4. div-inv98.1%

        \[\leadsto -\color{blue}{\frac{x}{\tan B}} \]
      5. neg-sub098.1%

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

      \[\leadsto \color{blue}{0 - \frac{x}{\tan B}} \]
    8. Step-by-step derivation
      1. neg-sub098.1%

        \[\leadsto \color{blue}{-\frac{x}{\tan B}} \]
      2. distribute-frac-neg298.1%

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

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

    if -1.025e11 < x < 0.92000000000000004

    1. Initial program 99.8%

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

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

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

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

        \[\leadsto \color{blue}{1 \cdot \frac{1}{\sin B}} + -1 \cdot \frac{x \cdot \cos B}{\sin B} \]
      3. *-lft-identity99.8%

        \[\leadsto \color{blue}{\frac{1}{\sin B}} + -1 \cdot \frac{x \cdot \cos B}{\sin B} \]
      4. rgt-mult-inverse99.7%

        \[\leadsto \frac{\color{blue}{x \cdot \frac{1}{x}}}{\sin B} + -1 \cdot \frac{x \cdot \cos B}{\sin B} \]
      5. associate-*r/75.1%

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

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

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

        \[\leadsto x \cdot \frac{\frac{1}{x}}{\sin B} + \color{blue}{x \cdot \left(-\frac{\cos B}{\sin B}\right)} \]
      9. mul-1-neg75.1%

        \[\leadsto x \cdot \frac{\frac{1}{x}}{\sin B} + x \cdot \color{blue}{\left(-1 \cdot \frac{\cos B}{\sin B}\right)} \]
      10. distribute-lft-in75.1%

        \[\leadsto \color{blue}{x \cdot \left(\frac{\frac{1}{x}}{\sin B} + -1 \cdot \frac{\cos B}{\sin B}\right)} \]
      11. mul-1-neg75.1%

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

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

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

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

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

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

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

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

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

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

Alternative 4: 98.4% accurate, 1.8× speedup?

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

\mathbf{elif}\;x \leq 0.92:\\
\;\;\;\;\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.1499999999999999

    1. Initial program 99.6%

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

        \[\leadsto \color{blue}{\frac{1}{\sin B} + \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. sub-neg99.8%

        \[\leadsto \color{blue}{\frac{1}{\sin B} - \frac{x}{\tan B}} \]
      4. clear-num99.4%

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

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

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

        \[\leadsto \frac{\frac{\tan B}{x} - \color{blue}{1 \cdot \sin B}}{\sin B \cdot \frac{\tan B}{x}} \]
      8. *-un-lft-identity88.9%

        \[\leadsto \frac{\frac{\tan B}{x} - \color{blue}{\sin B}}{\sin B \cdot \frac{\tan B}{x}} \]
    4. Applied egg-rr88.9%

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

        \[\leadsto \color{blue}{\frac{\frac{\frac{\tan B}{x} - \sin B}{\sin B}}{\frac{\tan B}{x}}} \]
      2. div-sub99.5%

        \[\leadsto \frac{\color{blue}{\frac{\frac{\tan B}{x}}{\sin B} - \frac{\sin B}{\sin B}}}{\frac{\tan B}{x}} \]
      3. *-inverses99.5%

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

      \[\leadsto \color{blue}{\frac{\frac{\frac{\tan B}{x}}{\sin B} - 1}{\frac{\tan B}{x}}} \]
    7. Step-by-step derivation
      1. div-sub75.6%

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

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

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

        \[\leadsto \frac{\tan B}{\color{blue}{x \cdot \sin B}} \cdot \frac{1}{\frac{\tan B}{x}} - \frac{1}{\frac{\tan B}{x}} \]
      5. clear-num99.4%

        \[\leadsto \frac{\tan B}{x \cdot \sin B} \cdot \color{blue}{\frac{x}{\tan B}} - \frac{1}{\frac{\tan B}{x}} \]
      6. clear-num99.8%

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

      \[\leadsto \color{blue}{\frac{\tan B}{x \cdot \sin B} \cdot \frac{x}{\tan B} - \frac{x}{\tan B}} \]
    9. Step-by-step derivation
      1. sub-neg99.8%

        \[\leadsto \color{blue}{\frac{\tan B}{x \cdot \sin B} \cdot \frac{x}{\tan B} + \left(-\frac{x}{\tan B}\right)} \]
      2. neg-mul-199.8%

        \[\leadsto \frac{\tan B}{x \cdot \sin B} \cdot \frac{x}{\tan B} + \color{blue}{-1 \cdot \frac{x}{\tan B}} \]
      3. distribute-rgt-in99.8%

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

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

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

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

    if -1.1499999999999999 < x < 0.92000000000000004

    1. Initial program 99.8%

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

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

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

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

        \[\leadsto \color{blue}{1 \cdot \frac{1}{\sin B}} + -1 \cdot \frac{x \cdot \cos B}{\sin B} \]
      3. *-lft-identity99.8%

        \[\leadsto \color{blue}{\frac{1}{\sin B}} + -1 \cdot \frac{x \cdot \cos B}{\sin B} \]
      4. rgt-mult-inverse99.7%

        \[\leadsto \frac{\color{blue}{x \cdot \frac{1}{x}}}{\sin B} + -1 \cdot \frac{x \cdot \cos B}{\sin B} \]
      5. associate-*r/74.9%

        \[\leadsto \color{blue}{x \cdot \frac{\frac{1}{x}}{\sin B}} + -1 \cdot \frac{x \cdot \cos B}{\sin B} \]
      6. mul-1-neg74.9%

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

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

        \[\leadsto x \cdot \frac{\frac{1}{x}}{\sin B} + \color{blue}{x \cdot \left(-\frac{\cos B}{\sin B}\right)} \]
      9. mul-1-neg74.9%

        \[\leadsto x \cdot \frac{\frac{1}{x}}{\sin B} + x \cdot \color{blue}{\left(-1 \cdot \frac{\cos B}{\sin B}\right)} \]
      10. distribute-lft-in74.9%

        \[\leadsto \color{blue}{x \cdot \left(\frac{\frac{1}{x}}{\sin B} + -1 \cdot \frac{\cos B}{\sin B}\right)} \]
      11. mul-1-neg74.9%

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

        \[\leadsto x \cdot \color{blue}{\left(\frac{\frac{1}{x}}{\sin B} - \frac{\cos B}{\sin B}\right)} \]
      13. div-sub74.9%

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

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

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

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

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

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

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

    if 0.92000000000000004 < x

    1. Initial program 99.7%

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

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

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

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

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

      \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{\cos B}{\sin B}} \]
    6. Step-by-step derivation
      1. distribute-lft-neg-out96.9%

        \[\leadsto \color{blue}{-x \cdot \frac{\cos B}{\sin B}} \]
      2. clear-num96.9%

        \[\leadsto -x \cdot \color{blue}{\frac{1}{\frac{\sin B}{\cos B}}} \]
      3. tan-quot97.1%

        \[\leadsto -x \cdot \frac{1}{\color{blue}{\tan B}} \]
      4. div-inv97.2%

        \[\leadsto -\color{blue}{\frac{x}{\tan B}} \]
      5. neg-sub097.2%

        \[\leadsto \color{blue}{0 - \frac{x}{\tan B}} \]
    7. Applied egg-rr97.2%

      \[\leadsto \color{blue}{0 - \frac{x}{\tan B}} \]
    8. Step-by-step derivation
      1. neg-sub097.2%

        \[\leadsto \color{blue}{-\frac{x}{\tan B}} \]
      2. distribute-frac-neg297.2%

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

      \[\leadsto \color{blue}{\frac{x}{-\tan B}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 5: 97.7% accurate, 1.8× speedup?

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

    1. Initial program 99.6%

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

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

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

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

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

      \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{\cos B}{\sin B}} \]
    6. Step-by-step derivation
      1. distribute-lft-neg-out98.2%

        \[\leadsto \color{blue}{-x \cdot \frac{\cos B}{\sin B}} \]
      2. clear-num98.2%

        \[\leadsto -x \cdot \color{blue}{\frac{1}{\frac{\sin B}{\cos B}}} \]
      3. tan-quot98.3%

        \[\leadsto -x \cdot \frac{1}{\color{blue}{\tan B}} \]
      4. div-inv98.5%

        \[\leadsto -\color{blue}{\frac{x}{\tan B}} \]
      5. neg-sub098.5%

        \[\leadsto \color{blue}{0 - \frac{x}{\tan B}} \]
    7. Applied egg-rr98.5%

      \[\leadsto \color{blue}{0 - \frac{x}{\tan B}} \]
    8. Step-by-step derivation
      1. neg-sub098.5%

        \[\leadsto \color{blue}{-\frac{x}{\tan B}} \]
      2. distribute-frac-neg298.5%

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

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

    if -1.55000000000000004 < x < 1

    1. Initial program 99.8%

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

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

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

Alternative 6: 62.9% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;B \leq 0.0023:\\ \;\;\;\;\frac{1 - x}{B}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sin B}\\ \end{array} \end{array} \]
(FPCore (B x)
 :precision binary64
 (if (<= B 0.0023) (/ (- 1.0 x) B) (/ 1.0 (sin B))))
double code(double B, double x) {
	double tmp;
	if (B <= 0.0023) {
		tmp = (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 (b <= 0.0023d0) then
        tmp = (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 (B <= 0.0023) {
		tmp = (1.0 - x) / B;
	} else {
		tmp = 1.0 / Math.sin(B);
	}
	return tmp;
}
def code(B, x):
	tmp = 0
	if B <= 0.0023:
		tmp = (1.0 - x) / B
	else:
		tmp = 1.0 / math.sin(B)
	return tmp
function code(B, x)
	tmp = 0.0
	if (B <= 0.0023)
		tmp = 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 (B <= 0.0023)
		tmp = (1.0 - x) / B;
	else
		tmp = 1.0 / sin(B);
	end
	tmp_2 = tmp;
end
code[B_, x_] := If[LessEqual[B, 0.0023], N[(N[(1.0 - x), $MachinePrecision] / B), $MachinePrecision], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;B \leq 0.0023:\\
\;\;\;\;\frac{1 - x}{B}\\

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


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

    1. Initial program 99.8%

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

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

    if 0.0023 < B

    1. Initial program 99.6%

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

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

Alternative 7: 51.3% 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. Add Preprocessing
  3. Taylor expanded in B around 0 48.9%

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

Alternative 8: 26.9% accurate, 52.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{-x}{B}} \]
  9. Final simplification27.4%

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

Alternative 9: 2.5% accurate, 70.0× speedup?

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

\\
\frac{x}{B}
\end{array}
Derivation
  1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{-x}{B}} \]
  9. Step-by-step derivation
    1. div-inv27.3%

      \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{1}{B}} \]
    2. add-sqr-sqrt14.3%

      \[\leadsto \color{blue}{\left(\sqrt{-x} \cdot \sqrt{-x}\right)} \cdot \frac{1}{B} \]
    3. sqrt-unprod14.5%

      \[\leadsto \color{blue}{\sqrt{\left(-x\right) \cdot \left(-x\right)}} \cdot \frac{1}{B} \]
    4. sqr-neg14.5%

      \[\leadsto \sqrt{\color{blue}{x \cdot x}} \cdot \frac{1}{B} \]
    5. sqrt-unprod1.5%

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

      \[\leadsto \color{blue}{x} \cdot \frac{1}{B} \]
  10. Applied egg-rr2.5%

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

      \[\leadsto \color{blue}{\frac{x \cdot 1}{B}} \]
    2. *-rgt-identity2.5%

      \[\leadsto \frac{\color{blue}{x}}{B} \]
  12. Simplified2.5%

    \[\leadsto \color{blue}{\frac{x}{B}} \]
  13. Add Preprocessing

Reproduce

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