VandenBroeck and Keller, Equation (24)

Percentage Accurate: 99.7% → 99.8%
Time: 9.2s
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.7%

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

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

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

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

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

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

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

Alternative 2: 98.1% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -7.5e5 or 5.25e8 < x

    1. Initial program 99.6%

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

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

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

        \[\leadsto \color{blue}{\frac{-x}{\tan B}} + \frac{1}{\sin B} \]
      2. neg-mul-199.8%

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

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

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

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

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

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

        \[\leadsto \frac{1}{\sin B} - \frac{\color{blue}{x \cdot \cos B}}{\sin B} \]
      4. div-sub99.6%

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

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

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

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

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

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

    if -7.5e5 < x < 5.25e8

    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} \]
    3. Simplified99.8%

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

        \[\leadsto \color{blue}{\frac{-x}{\tan B}} + \frac{1}{\sin B} \]
      2. neg-mul-199.8%

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 98.1% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -3.1e7 or 8.4e8 < x

    1. Initial program 99.6%

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

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

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

        \[\leadsto \color{blue}{\frac{-x}{\tan B}} + \frac{1}{\sin B} \]
      2. neg-mul-199.8%

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

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

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

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

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

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

        \[\leadsto \frac{1}{\sin B} - \frac{\color{blue}{x \cdot \cos B}}{\sin B} \]
      4. div-sub99.6%

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

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

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

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

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

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

        \[\leadsto \frac{-\color{blue}{\cos B \cdot x}}{\sin B} \]
      5. distribute-rgt-neg-out99.4%

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

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

    if -3.1e7 < x < 8.4e8

    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} \]
    3. Simplified99.8%

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

        \[\leadsto \color{blue}{\frac{-x}{\tan B}} + \frac{1}{\sin B} \]
      2. neg-mul-199.8%

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 86.8% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -124000000000 \lor \neg \left(x \leq 1.22 \cdot 10^{+48}\right):\\
\;\;\;\;\left(\frac{1}{B} + B \cdot 0.16666666666666666\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.24e11 or 1.22000000000000004e48 < x

    1. Initial program 99.6%

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

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

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

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

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

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

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

    if -1.24e11 < x < 1.22000000000000004e48

    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} \]
    3. Simplified99.8%

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

        \[\leadsto \color{blue}{\frac{-x}{\tan B}} + \frac{1}{\sin B} \]
      2. neg-mul-199.8%

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 76.2% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 99.6%

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

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

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

        \[\leadsto \color{blue}{\frac{-x}{\tan B}} + \frac{1}{\sin B} \]
      2. neg-mul-199.8%

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

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

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

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

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

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

        \[\leadsto \frac{1}{\sin B} - \frac{\color{blue}{x \cdot \cos B}}{\sin B} \]
      4. div-sub99.6%

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-x \cdot \cos B}}{\sin B} \]
      4. *-commutative97.9%

        \[\leadsto \frac{-\color{blue}{\cos B \cdot x}}{\sin B} \]
      5. distribute-rgt-neg-out97.9%

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

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

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

        \[\leadsto \frac{\color{blue}{-x}}{\sin B} \]
    14. Simplified47.7%

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

    if -1 < x < 1.05000000000000004

    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} \]
    3. Simplified99.8%

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

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

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

Alternative 6: 75.0% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1 - x}{B}\\ \mathbf{if}\;x \leq -0.009:\\ \;\;\;\;B \cdot \left(0.16666666666666666 + x \cdot 0.3333333333333333\right) + t_0\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-12}:\\ \;\;\;\;\frac{1}{\sin B}\\ \mathbf{else}:\\ \;\;\;\;t_0 + B \cdot 0.16666666666666666\\ \end{array} \end{array} \]
(FPCore (B x)
 :precision binary64
 (let* ((t_0 (/ (- 1.0 x) B)))
   (if (<= x -0.009)
     (+ (* B (+ 0.16666666666666666 (* x 0.3333333333333333))) t_0)
     (if (<= x 6.2e-12) (/ 1.0 (sin B)) (+ t_0 (* B 0.16666666666666666))))))
double code(double B, double x) {
	double t_0 = (1.0 - x) / B;
	double tmp;
	if (x <= -0.009) {
		tmp = (B * (0.16666666666666666 + (x * 0.3333333333333333))) + t_0;
	} else if (x <= 6.2e-12) {
		tmp = 1.0 / sin(B);
	} else {
		tmp = t_0 + (B * 0.16666666666666666);
	}
	return tmp;
}
real(8) function code(b, x)
    real(8), intent (in) :: b
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (1.0d0 - x) / b
    if (x <= (-0.009d0)) then
        tmp = (b * (0.16666666666666666d0 + (x * 0.3333333333333333d0))) + t_0
    else if (x <= 6.2d-12) then
        tmp = 1.0d0 / sin(b)
    else
        tmp = t_0 + (b * 0.16666666666666666d0)
    end if
    code = tmp
end function
public static double code(double B, double x) {
	double t_0 = (1.0 - x) / B;
	double tmp;
	if (x <= -0.009) {
		tmp = (B * (0.16666666666666666 + (x * 0.3333333333333333))) + t_0;
	} else if (x <= 6.2e-12) {
		tmp = 1.0 / Math.sin(B);
	} else {
		tmp = t_0 + (B * 0.16666666666666666);
	}
	return tmp;
}
def code(B, x):
	t_0 = (1.0 - x) / B
	tmp = 0
	if x <= -0.009:
		tmp = (B * (0.16666666666666666 + (x * 0.3333333333333333))) + t_0
	elif x <= 6.2e-12:
		tmp = 1.0 / math.sin(B)
	else:
		tmp = t_0 + (B * 0.16666666666666666)
	return tmp
function code(B, x)
	t_0 = Float64(Float64(1.0 - x) / B)
	tmp = 0.0
	if (x <= -0.009)
		tmp = Float64(Float64(B * Float64(0.16666666666666666 + Float64(x * 0.3333333333333333))) + t_0);
	elseif (x <= 6.2e-12)
		tmp = Float64(1.0 / sin(B));
	else
		tmp = Float64(t_0 + Float64(B * 0.16666666666666666));
	end
	return tmp
end
function tmp_2 = code(B, x)
	t_0 = (1.0 - x) / B;
	tmp = 0.0;
	if (x <= -0.009)
		tmp = (B * (0.16666666666666666 + (x * 0.3333333333333333))) + t_0;
	elseif (x <= 6.2e-12)
		tmp = 1.0 / sin(B);
	else
		tmp = t_0 + (B * 0.16666666666666666);
	end
	tmp_2 = tmp;
end
code[B_, x_] := Block[{t$95$0 = N[(N[(1.0 - x), $MachinePrecision] / B), $MachinePrecision]}, If[LessEqual[x, -0.009], N[(N[(B * N[(0.16666666666666666 + N[(x * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision], If[LessEqual[x, 6.2e-12], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision], N[(t$95$0 + N[(B * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{1 - x}{B}\\
\mathbf{if}\;x \leq -0.009:\\
\;\;\;\;B \cdot \left(0.16666666666666666 + x \cdot 0.3333333333333333\right) + t_0\\

\mathbf{elif}\;x \leq 6.2 \cdot 10^{-12}:\\
\;\;\;\;\frac{1}{\sin B}\\

\mathbf{else}:\\
\;\;\;\;t_0 + B \cdot 0.16666666666666666\\


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.00899999999999999932 < x < 6.2000000000000002e-12

    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} \]
    3. Simplified99.8%

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

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

    if 6.2000000000000002e-12 < x

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto B \cdot 0.16666666666666666 + \color{blue}{\frac{1 - x}{B}} \]
    7. Applied egg-rr44.1%

      \[\leadsto \color{blue}{B \cdot 0.16666666666666666 + \frac{1 - x}{B}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification71.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.009:\\ \;\;\;\;B \cdot \left(0.16666666666666666 + x \cdot 0.3333333333333333\right) + \frac{1 - x}{B}\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-12}:\\ \;\;\;\;\frac{1}{\sin B}\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - x}{B} + B \cdot 0.16666666666666666\\ \end{array} \]

Alternative 7: 77.3% accurate, 2.0× speedup?

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-x}{\tan B}} + \frac{1}{\sin B} \]
    2. neg-mul-199.8%

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

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

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

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

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

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

      \[\leadsto \frac{1}{\sin B} - \frac{\color{blue}{x \cdot \cos B}}{\sin B} \]
    4. div-sub99.7%

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

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

    \[\leadsto \frac{1 - \color{blue}{x}}{\sin B} \]
  10. Final simplification73.0%

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

Alternative 8: 51.6% accurate, 19.1× speedup?

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-x}{\tan B}} + \frac{1}{\sin B} \]
    2. neg-mul-199.8%

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

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

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

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

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

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

      \[\leadsto \frac{1}{\sin B} - \frac{\color{blue}{x \cdot \cos B}}{\sin B} \]
    4. div-sub99.7%

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

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

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

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

      \[\leadsto \color{blue}{B \cdot \left(0.5 \cdot x - -0.16666666666666666 \cdot \left(1 - x\right)\right)} + \left(\frac{1}{B} - \frac{x}{B}\right) \]
    3. cancel-sign-sub-inv44.5%

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

      \[\leadsto B \cdot \left(\color{blue}{x \cdot 0.5} + \left(--0.16666666666666666\right) \cdot \left(1 - x\right)\right) + \left(\frac{1}{B} - \frac{x}{B}\right) \]
    5. metadata-eval44.5%

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

      \[\leadsto B \cdot \left(x \cdot 0.5 + 0.16666666666666666 \cdot \left(1 - x\right)\right) + \color{blue}{\frac{1 - x}{B}} \]
  11. Simplified44.5%

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

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

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

Alternative 9: 50.3% accurate, 25.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\frac{-x}{B}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{B}\\ \end{array} \end{array} \]
(FPCore (B x)
 :precision binary64
 (if (or (<= x -1.0) (not (<= x 1.0))) (/ (- x) B) (/ 1.0 B)))
double code(double B, double x) {
	double tmp;
	if ((x <= -1.0) || !(x <= 1.0)) {
		tmp = -x / B;
	} else {
		tmp = 1.0 / B;
	}
	return tmp;
}
real(8) function code(b, x)
    real(8), intent (in) :: b
    real(8), intent (in) :: x
    real(8) :: tmp
    if ((x <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
        tmp = -x / b
    else
        tmp = 1.0d0 / b
    end if
    code = tmp
end function
public static double code(double B, double x) {
	double tmp;
	if ((x <= -1.0) || !(x <= 1.0)) {
		tmp = -x / B;
	} else {
		tmp = 1.0 / B;
	}
	return tmp;
}
def code(B, x):
	tmp = 0
	if (x <= -1.0) or not (x <= 1.0):
		tmp = -x / B
	else:
		tmp = 1.0 / B
	return tmp
function code(B, x)
	tmp = 0.0
	if ((x <= -1.0) || !(x <= 1.0))
		tmp = Float64(Float64(-x) / B);
	else
		tmp = Float64(1.0 / B);
	end
	return tmp
end
function tmp_2 = code(B, x)
	tmp = 0.0;
	if ((x <= -1.0) || ~((x <= 1.0)))
		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, 1.0]], $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 1\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 1 < x

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1 < 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} \]
    3. Simplified99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{0.16666666666666666 \cdot B} \]
  6. Step-by-step derivation
    1. *-commutative2.9%

      \[\leadsto \color{blue}{B \cdot 0.16666666666666666} \]
  7. Simplified2.9%

    \[\leadsto \color{blue}{B \cdot 0.16666666666666666} \]
  8. Final simplification2.9%

    \[\leadsto B \cdot 0.16666666666666666 \]

Alternative 12: 26.7% accurate, 70.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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