VandenBroeck and Keller, Equation (24)

Percentage Accurate: 99.7% → 99.8%
Time: 8.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. 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: 97.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{+27} \lor \neg \left(x \leq 2000000\right):\\ \;\;\;\;\cos B \cdot \frac{x}{-\sin B}\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - x}{\sin B}\\ \end{array} \end{array} \]
(FPCore (B x)
 :precision binary64
 (if (or (<= x -2e+27) (not (<= x 2000000.0)))
   (* (cos B) (/ x (- (sin B))))
   (/ (- 1.0 x) (sin B))))
double code(double B, double x) {
	double tmp;
	if ((x <= -2e+27) || !(x <= 2000000.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 <= (-2d+27)) .or. (.not. (x <= 2000000.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 <= -2e+27) || !(x <= 2000000.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 <= -2e+27) or not (x <= 2000000.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 <= -2e+27) || !(x <= 2000000.0))
		tmp = Float64(cos(B) * Float64(x / Float64(-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 <= -2e+27) || ~((x <= 2000000.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, -2e+27], N[Not[LessEqual[x, 2000000.0]], $MachinePrecision]], N[(N[Cos[B], $MachinePrecision] * N[(x / (-N[Sin[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 -2 \cdot 10^{+27} \lor \neg \left(x \leq 2000000\right):\\
\;\;\;\;\cos B \cdot \frac{x}{-\sin B}\\

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


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

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\cos B \cdot \left(-\frac{x}{\sin B}\right)} \]
      5. distribute-neg-frac298.6%

        \[\leadsto \cos B \cdot \color{blue}{\frac{x}{-\sin B}} \]
    7. Simplified98.6%

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

    if -2e27 < x < 2e6

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{+27} \lor \neg \left(x \leq 2000000\right):\\ \;\;\;\;\cos B \cdot \frac{x}{-\sin B}\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - x}{\sin B}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 97.8% accurate, 1.0× speedup?

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

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


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

    1. Initial program 99.4%

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

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

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

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

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

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

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

    if -2e27 < x < 2.4e6

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{+27} \lor \neg \left(x \leq 2400000\right):\\ \;\;\;\;x \cdot \frac{\cos B}{-\sin B}\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - x}{\sin B}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 97.9% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := -\sin B\\
\mathbf{if}\;x \leq -2 \cdot 10^{+27}:\\
\;\;\;\;\frac{x \cdot \cos B}{t\_0}\\

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

\mathbf{else}:\\
\;\;\;\;\cos B \cdot \frac{x}{t\_0}\\


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

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

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

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

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

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

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

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

        \[\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. Step-by-step derivation
      1. div-inv99.6%

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

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

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

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

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

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

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

    if -2e27 < x < 6.5e5

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

    if 6.5e5 < x

    1. Initial program 99.3%

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

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

        \[\leadsto \left(-\color{blue}{\frac{1}{\frac{\tan B}{x}}}\right) + \frac{1}{\sin B} \]
    4. Applied egg-rr99.4%

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

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

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

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

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

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

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

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

Alternative 5: 64.4% accurate, 1.9× speedup?

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

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

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


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

    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 68.5%

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

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

    if 0.19500000000000001 < B

    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. div-inv99.7%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\sin B} - \frac{x}{\sin B}} \]
      2. sub-neg45.7%

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

        \[\leadsto \frac{1}{\sin B} + \color{blue}{\frac{-x}{\sin B}} \]
      4. add-sqr-sqrt21.3%

        \[\leadsto \frac{1}{\sin B} + \frac{\color{blue}{\sqrt{-x} \cdot \sqrt{-x}}}{\sin B} \]
      5. sqrt-unprod46.2%

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

        \[\leadsto \frac{1}{\sin B} + \frac{\sqrt{\color{blue}{x \cdot x}}}{\sin B} \]
      7. sqrt-unprod26.3%

        \[\leadsto \frac{1}{\sin B} + \frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{\sin B} \]
      8. add-sqr-sqrt49.4%

        \[\leadsto \frac{1}{\sin B} + \frac{\color{blue}{x}}{\sin B} \]
    10. Applied egg-rr49.4%

      \[\leadsto \color{blue}{\frac{1}{\sin B} + \frac{x}{\sin B}} \]
    11. Step-by-step derivation
      1. *-rgt-identity49.4%

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

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

        \[\leadsto \frac{1}{\sin B} \cdot 1 + \color{blue}{\frac{1}{\sin B} \cdot x} \]
      4. distribute-lft-in49.4%

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

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

        \[\leadsto \frac{\color{blue}{1 + x}}{\sin B} \]
      7. +-commutative49.4%

        \[\leadsto \frac{\color{blue}{x + 1}}{\sin B} \]
    12. Simplified49.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;B \leq 0.195:\\ \;\;\;\;B \cdot 0.16666666666666666 + \left(\frac{1}{B} + x \cdot \left(B \cdot 0.3333333333333333 + \frac{-1}{B}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1 + x}{\sin B}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 62.8% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;B \leq 3.6 \cdot 10^{+16}:\\
\;\;\;\;B \cdot 0.16666666666666666 + \left(\frac{1}{B} + x \cdot \left(B \cdot 0.3333333333333333 + \frac{-1}{B}\right)\right)\\

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


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

    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 67.3%

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

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

    if 3.6e16 < 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 44.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;B \leq 3.6 \cdot 10^{+16}:\\ \;\;\;\;B \cdot 0.16666666666666666 + \left(\frac{1}{B} + x \cdot \left(B \cdot 0.3333333333333333 + \frac{-1}{B}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sin B}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 77.7% accurate, 2.0× speedup?

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

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

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

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

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

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

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

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

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

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

Alternative 8: 51.2% accurate, 12.4× speedup?

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

\\
B \cdot 0.16666666666666666 + \left(\frac{1}{B} + x \cdot \left(B \cdot 0.3333333333333333 + \frac{-1}{B}\right)\right)
\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 53.9%

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

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

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

Alternative 9: 50.1% accurate, 14.9× 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(x / Float64(-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.5%

      \[\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. Taylor expanded in x around inf 47.2%

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

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

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

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

    if -1 < x < 1

    1. Initial program 99.9%

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

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

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

    \[\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} \]
  5. Add Preprocessing

Alternative 10: 51.3% accurate, 23.3× speedup?

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

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

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

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

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

    \[\leadsto 0.16666666666666666 \cdot B + \color{blue}{\frac{1 + -1 \cdot x}{B}} \]
  6. Final simplification53.5%

    \[\leadsto B \cdot 0.16666666666666666 + \frac{1 - x}{B} \]
  7. Add Preprocessing

Alternative 11: 51.1% 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 53.2%

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

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

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

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

Reproduce

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