rsin A (should all be same)

Percentage Accurate: 76.5% → 99.5%
Time: 20.8s
Alternatives: 9
Speedup: 0.4×

Specification

?
\[\begin{array}{l} \\ \frac{r \cdot \sin b}{\cos \left(a + b\right)} \end{array} \]
(FPCore (r a b) :precision binary64 (/ (* r (sin b)) (cos (+ a b))))
double code(double r, double a, double b) {
	return (r * sin(b)) / cos((a + b));
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = (r * sin(b)) / cos((a + b))
end function
public static double code(double r, double a, double b) {
	return (r * Math.sin(b)) / Math.cos((a + b));
}
def code(r, a, b):
	return (r * math.sin(b)) / math.cos((a + b))
function code(r, a, b)
	return Float64(Float64(r * sin(b)) / cos(Float64(a + b)))
end
function tmp = code(r, a, b)
	tmp = (r * sin(b)) / cos((a + b));
end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{r \cdot \sin b}{\cos \left(a + b\right)}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 9 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 76.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{r \cdot \sin b}{\cos \left(a + b\right)} \end{array} \]
(FPCore (r a b) :precision binary64 (/ (* r (sin b)) (cos (+ a b))))
double code(double r, double a, double b) {
	return (r * sin(b)) / cos((a + b));
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = (r * sin(b)) / cos((a + b))
end function
public static double code(double r, double a, double b) {
	return (r * Math.sin(b)) / Math.cos((a + b));
}
def code(r, a, b):
	return (r * math.sin(b)) / math.cos((a + b))
function code(r, a, b)
	return Float64(Float64(r * sin(b)) / cos(Float64(a + b)))
end
function tmp = code(r, a, b)
	tmp = (r * sin(b)) / cos((a + b));
end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{r \cdot \sin b}{\cos \left(a + b\right)}
\end{array}

Alternative 1: 99.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \frac{\sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a} \cdot r \end{array} \]
(FPCore (r a b)
 :precision binary64
 (* (/ (sin b) (- (* (cos b) (cos a)) (* (sin b) (sin a)))) r))
double code(double r, double a, double b) {
	return (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a)))) * r;
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a)))) * r
end function
public static double code(double r, double a, double b) {
	return (Math.sin(b) / ((Math.cos(b) * Math.cos(a)) - (Math.sin(b) * Math.sin(a)))) * r;
}
def code(r, a, b):
	return (math.sin(b) / ((math.cos(b) * math.cos(a)) - (math.sin(b) * math.sin(a)))) * r
function code(r, a, b)
	return Float64(Float64(sin(b) / Float64(Float64(cos(b) * cos(a)) - Float64(sin(b) * sin(a)))) * r)
end
function tmp = code(r, a, b)
	tmp = (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a)))) * r;
end
code[r_, a_, b_] := N[(N[(N[Sin[b], $MachinePrecision] / N[(N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision]
\begin{array}{l}

\\
\frac{\sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a} \cdot r
\end{array}
Derivation
  1. Initial program 77.9%

    \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
  2. Step-by-step derivation
    1. *-commutative77.9%

      \[\leadsto \frac{\color{blue}{\sin b \cdot r}}{\cos \left(a + b\right)} \]
    2. associate-/l*77.9%

      \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(a + b\right)}{r}}} \]
    3. +-commutative77.9%

      \[\leadsto \frac{\sin b}{\frac{\cos \color{blue}{\left(b + a\right)}}{r}} \]
  3. Simplified77.9%

    \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(b + a\right)}{r}}} \]
  4. Step-by-step derivation
    1. associate-/r/78.0%

      \[\leadsto \color{blue}{\frac{\sin b}{\cos \left(b + a\right)} \cdot r} \]
  5. Applied egg-rr78.0%

    \[\leadsto \color{blue}{\frac{\sin b}{\cos \left(b + a\right)} \cdot r} \]
  6. Step-by-step derivation
    1. cos-sum99.5%

      \[\leadsto \frac{\sin b}{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}} \cdot r \]
  7. Applied egg-rr99.5%

    \[\leadsto \frac{\sin b}{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}} \cdot r \]
  8. Final simplification99.5%

    \[\leadsto \frac{\sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a} \cdot r \]

Alternative 2: 76.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -0.00066 \lor \neg \left(a \leq 1.15 \cdot 10^{-14}\right):\\ \;\;\;\;\sin b \cdot \frac{r}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;\sin b \cdot \frac{r}{\cos b}\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (or (<= a -0.00066) (not (<= a 1.15e-14)))
   (* (sin b) (/ r (cos a)))
   (* (sin b) (/ r (cos b)))))
double code(double r, double a, double b) {
	double tmp;
	if ((a <= -0.00066) || !(a <= 1.15e-14)) {
		tmp = sin(b) * (r / cos(a));
	} else {
		tmp = sin(b) * (r / cos(b));
	}
	return tmp;
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if ((a <= (-0.00066d0)) .or. (.not. (a <= 1.15d-14))) then
        tmp = sin(b) * (r / cos(a))
    else
        tmp = sin(b) * (r / cos(b))
    end if
    code = tmp
end function
public static double code(double r, double a, double b) {
	double tmp;
	if ((a <= -0.00066) || !(a <= 1.15e-14)) {
		tmp = Math.sin(b) * (r / Math.cos(a));
	} else {
		tmp = Math.sin(b) * (r / Math.cos(b));
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if (a <= -0.00066) or not (a <= 1.15e-14):
		tmp = math.sin(b) * (r / math.cos(a))
	else:
		tmp = math.sin(b) * (r / math.cos(b))
	return tmp
function code(r, a, b)
	tmp = 0.0
	if ((a <= -0.00066) || !(a <= 1.15e-14))
		tmp = Float64(sin(b) * Float64(r / cos(a)));
	else
		tmp = Float64(sin(b) * Float64(r / cos(b)));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	tmp = 0.0;
	if ((a <= -0.00066) || ~((a <= 1.15e-14)))
		tmp = sin(b) * (r / cos(a));
	else
		tmp = sin(b) * (r / cos(b));
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[Or[LessEqual[a, -0.00066], N[Not[LessEqual[a, 1.15e-14]], $MachinePrecision]], N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.00066 \lor \neg \left(a \leq 1.15 \cdot 10^{-14}\right):\\
\;\;\;\;\sin b \cdot \frac{r}{\cos a}\\

\mathbf{else}:\\
\;\;\;\;\sin b \cdot \frac{r}{\cos b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -6.6e-4 or 1.14999999999999999e-14 < a

    1. Initial program 58.7%

      \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
    2. Step-by-step derivation
      1. *-commutative58.7%

        \[\leadsto \frac{\color{blue}{\sin b \cdot r}}{\cos \left(a + b\right)} \]
      2. associate-/l*58.8%

        \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(a + b\right)}{r}}} \]
      3. +-commutative58.8%

        \[\leadsto \frac{\sin b}{\frac{\cos \color{blue}{\left(b + a\right)}}{r}} \]
    3. Simplified58.8%

      \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(b + a\right)}{r}}} \]
    4. Step-by-step derivation
      1. add-exp-log25.9%

        \[\leadsto \frac{\sin b}{\color{blue}{e^{\log \left(\frac{\cos \left(b + a\right)}{r}\right)}}} \]
    5. Applied egg-rr25.9%

      \[\leadsto \frac{\sin b}{\color{blue}{e^{\log \left(\frac{\cos \left(b + a\right)}{r}\right)}}} \]
    6. Step-by-step derivation
      1. div-inv25.9%

        \[\leadsto \color{blue}{\sin b \cdot \frac{1}{e^{\log \left(\frac{\cos \left(b + a\right)}{r}\right)}}} \]
      2. add-exp-log58.6%

        \[\leadsto \sin b \cdot \frac{1}{\color{blue}{\frac{\cos \left(b + a\right)}{r}}} \]
    7. Applied egg-rr58.6%

      \[\leadsto \color{blue}{\sin b \cdot \frac{1}{\frac{\cos \left(b + a\right)}{r}}} \]
    8. Taylor expanded in b around 0 58.7%

      \[\leadsto \sin b \cdot \color{blue}{\frac{r}{\cos a}} \]

    if -6.6e-4 < a < 1.14999999999999999e-14

    1. Initial program 98.7%

      \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
    2. Step-by-step derivation
      1. *-commutative98.7%

        \[\leadsto \frac{\color{blue}{\sin b \cdot r}}{\cos \left(a + b\right)} \]
      2. associate-/l*98.6%

        \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(a + b\right)}{r}}} \]
      3. +-commutative98.6%

        \[\leadsto \frac{\sin b}{\frac{\cos \color{blue}{\left(b + a\right)}}{r}} \]
    3. Simplified98.6%

      \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(b + a\right)}{r}}} \]
    4. Taylor expanded in a around 0 98.6%

      \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos b}} \]
    5. Step-by-step derivation
      1. associate-/l*98.5%

        \[\leadsto \color{blue}{\frac{r}{\frac{\cos b}{\sin b}}} \]
      2. associate-/r/98.7%

        \[\leadsto \color{blue}{\frac{r}{\cos b} \cdot \sin b} \]
    6. Simplified98.7%

      \[\leadsto \color{blue}{\frac{r}{\cos b} \cdot \sin b} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification77.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -0.00066 \lor \neg \left(a \leq 1.15 \cdot 10^{-14}\right):\\ \;\;\;\;\sin b \cdot \frac{r}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;\sin b \cdot \frac{r}{\cos b}\\ \end{array} \]

Alternative 3: 76.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -0.00136 \lor \neg \left(a \leq 1.15 \cdot 10^{-14}\right):\\ \;\;\;\;\frac{\sin b}{\frac{\cos a}{r}}\\ \mathbf{else}:\\ \;\;\;\;\sin b \cdot \frac{r}{\cos b}\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (or (<= a -0.00136) (not (<= a 1.15e-14)))
   (/ (sin b) (/ (cos a) r))
   (* (sin b) (/ r (cos b)))))
double code(double r, double a, double b) {
	double tmp;
	if ((a <= -0.00136) || !(a <= 1.15e-14)) {
		tmp = sin(b) / (cos(a) / r);
	} else {
		tmp = sin(b) * (r / cos(b));
	}
	return tmp;
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if ((a <= (-0.00136d0)) .or. (.not. (a <= 1.15d-14))) then
        tmp = sin(b) / (cos(a) / r)
    else
        tmp = sin(b) * (r / cos(b))
    end if
    code = tmp
end function
public static double code(double r, double a, double b) {
	double tmp;
	if ((a <= -0.00136) || !(a <= 1.15e-14)) {
		tmp = Math.sin(b) / (Math.cos(a) / r);
	} else {
		tmp = Math.sin(b) * (r / Math.cos(b));
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if (a <= -0.00136) or not (a <= 1.15e-14):
		tmp = math.sin(b) / (math.cos(a) / r)
	else:
		tmp = math.sin(b) * (r / math.cos(b))
	return tmp
function code(r, a, b)
	tmp = 0.0
	if ((a <= -0.00136) || !(a <= 1.15e-14))
		tmp = Float64(sin(b) / Float64(cos(a) / r));
	else
		tmp = Float64(sin(b) * Float64(r / cos(b)));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	tmp = 0.0;
	if ((a <= -0.00136) || ~((a <= 1.15e-14)))
		tmp = sin(b) / (cos(a) / r);
	else
		tmp = sin(b) * (r / cos(b));
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[Or[LessEqual[a, -0.00136], N[Not[LessEqual[a, 1.15e-14]], $MachinePrecision]], N[(N[Sin[b], $MachinePrecision] / N[(N[Cos[a], $MachinePrecision] / r), $MachinePrecision]), $MachinePrecision], N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.00136 \lor \neg \left(a \leq 1.15 \cdot 10^{-14}\right):\\
\;\;\;\;\frac{\sin b}{\frac{\cos a}{r}}\\

\mathbf{else}:\\
\;\;\;\;\sin b \cdot \frac{r}{\cos b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -0.00136 or 1.14999999999999999e-14 < a

    1. Initial program 58.7%

      \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
    2. Step-by-step derivation
      1. *-commutative58.7%

        \[\leadsto \frac{\color{blue}{\sin b \cdot r}}{\cos \left(a + b\right)} \]
      2. associate-/l*58.8%

        \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(a + b\right)}{r}}} \]
      3. +-commutative58.8%

        \[\leadsto \frac{\sin b}{\frac{\cos \color{blue}{\left(b + a\right)}}{r}} \]
    3. Simplified58.8%

      \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(b + a\right)}{r}}} \]
    4. Taylor expanded in b around 0 58.7%

      \[\leadsto \frac{\sin b}{\frac{\color{blue}{\cos a}}{r}} \]

    if -0.00136 < a < 1.14999999999999999e-14

    1. Initial program 98.7%

      \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
    2. Step-by-step derivation
      1. *-commutative98.7%

        \[\leadsto \frac{\color{blue}{\sin b \cdot r}}{\cos \left(a + b\right)} \]
      2. associate-/l*98.6%

        \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(a + b\right)}{r}}} \]
      3. +-commutative98.6%

        \[\leadsto \frac{\sin b}{\frac{\cos \color{blue}{\left(b + a\right)}}{r}} \]
    3. Simplified98.6%

      \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(b + a\right)}{r}}} \]
    4. Taylor expanded in a around 0 98.6%

      \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos b}} \]
    5. Step-by-step derivation
      1. associate-/l*98.5%

        \[\leadsto \color{blue}{\frac{r}{\frac{\cos b}{\sin b}}} \]
      2. associate-/r/98.7%

        \[\leadsto \color{blue}{\frac{r}{\cos b} \cdot \sin b} \]
    6. Simplified98.7%

      \[\leadsto \color{blue}{\frac{r}{\cos b} \cdot \sin b} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification77.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -0.00136 \lor \neg \left(a \leq 1.15 \cdot 10^{-14}\right):\\ \;\;\;\;\frac{\sin b}{\frac{\cos a}{r}}\\ \mathbf{else}:\\ \;\;\;\;\sin b \cdot \frac{r}{\cos b}\\ \end{array} \]

Alternative 4: 76.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sin b \cdot \frac{r}{\cos \left(b + a\right)} \end{array} \]
(FPCore (r a b) :precision binary64 (* (sin b) (/ r (cos (+ b a)))))
double code(double r, double a, double b) {
	return sin(b) * (r / cos((b + a)));
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = sin(b) * (r / cos((b + a)))
end function
public static double code(double r, double a, double b) {
	return Math.sin(b) * (r / Math.cos((b + a)));
}
def code(r, a, b):
	return math.sin(b) * (r / math.cos((b + a)))
function code(r, a, b)
	return Float64(sin(b) * Float64(r / cos(Float64(b + a))))
end
function tmp = code(r, a, b)
	tmp = sin(b) * (r / cos((b + a)));
end
code[r_, a_, b_] := N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\sin b \cdot \frac{r}{\cos \left(b + a\right)}
\end{array}
Derivation
  1. Initial program 77.9%

    \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
  2. Step-by-step derivation
    1. *-commutative77.9%

      \[\leadsto \frac{\color{blue}{\sin b \cdot r}}{\cos \left(a + b\right)} \]
    2. associate-/l*77.9%

      \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(a + b\right)}{r}}} \]
    3. +-commutative77.9%

      \[\leadsto \frac{\sin b}{\frac{\cos \color{blue}{\left(b + a\right)}}{r}} \]
  3. Simplified77.9%

    \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(b + a\right)}{r}}} \]
  4. Step-by-step derivation
    1. clear-num77.3%

      \[\leadsto \color{blue}{\frac{1}{\frac{\frac{\cos \left(b + a\right)}{r}}{\sin b}}} \]
    2. associate-/r/77.8%

      \[\leadsto \color{blue}{\frac{1}{\frac{\cos \left(b + a\right)}{r}} \cdot \sin b} \]
    3. clear-num78.0%

      \[\leadsto \color{blue}{\frac{r}{\cos \left(b + a\right)}} \cdot \sin b \]
  5. Applied egg-rr78.0%

    \[\leadsto \color{blue}{\frac{r}{\cos \left(b + a\right)} \cdot \sin b} \]
  6. Final simplification78.0%

    \[\leadsto \sin b \cdot \frac{r}{\cos \left(b + a\right)} \]

Alternative 5: 54.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sin b \cdot \frac{r}{\cos a} \end{array} \]
(FPCore (r a b) :precision binary64 (* (sin b) (/ r (cos a))))
double code(double r, double a, double b) {
	return sin(b) * (r / cos(a));
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = sin(b) * (r / cos(a))
end function
public static double code(double r, double a, double b) {
	return Math.sin(b) * (r / Math.cos(a));
}
def code(r, a, b):
	return math.sin(b) * (r / math.cos(a))
function code(r, a, b)
	return Float64(sin(b) * Float64(r / cos(a)))
end
function tmp = code(r, a, b)
	tmp = sin(b) * (r / cos(a));
end
code[r_, a_, b_] := N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\sin b \cdot \frac{r}{\cos a}
\end{array}
Derivation
  1. Initial program 77.9%

    \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
  2. Step-by-step derivation
    1. *-commutative77.9%

      \[\leadsto \frac{\color{blue}{\sin b \cdot r}}{\cos \left(a + b\right)} \]
    2. associate-/l*77.9%

      \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(a + b\right)}{r}}} \]
    3. +-commutative77.9%

      \[\leadsto \frac{\sin b}{\frac{\cos \color{blue}{\left(b + a\right)}}{r}} \]
  3. Simplified77.9%

    \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(b + a\right)}{r}}} \]
  4. Step-by-step derivation
    1. add-exp-log35.2%

      \[\leadsto \frac{\sin b}{\color{blue}{e^{\log \left(\frac{\cos \left(b + a\right)}{r}\right)}}} \]
  5. Applied egg-rr35.2%

    \[\leadsto \frac{\sin b}{\color{blue}{e^{\log \left(\frac{\cos \left(b + a\right)}{r}\right)}}} \]
  6. Step-by-step derivation
    1. div-inv35.2%

      \[\leadsto \color{blue}{\sin b \cdot \frac{1}{e^{\log \left(\frac{\cos \left(b + a\right)}{r}\right)}}} \]
    2. add-exp-log77.8%

      \[\leadsto \sin b \cdot \frac{1}{\color{blue}{\frac{\cos \left(b + a\right)}{r}}} \]
  7. Applied egg-rr77.8%

    \[\leadsto \color{blue}{\sin b \cdot \frac{1}{\frac{\cos \left(b + a\right)}{r}}} \]
  8. Taylor expanded in b around 0 55.8%

    \[\leadsto \sin b \cdot \color{blue}{\frac{r}{\cos a}} \]
  9. Final simplification55.8%

    \[\leadsto \sin b \cdot \frac{r}{\cos a} \]

Alternative 6: 55.1% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -0.68 \lor \neg \left(b \leq 9200000\right):\\ \;\;\;\;\sin b \cdot r\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{b}{\cos a}\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (or (<= b -0.68) (not (<= b 9200000.0)))
   (* (sin b) r)
   (* r (/ b (cos a)))))
double code(double r, double a, double b) {
	double tmp;
	if ((b <= -0.68) || !(b <= 9200000.0)) {
		tmp = sin(b) * r;
	} else {
		tmp = r * (b / cos(a));
	}
	return tmp;
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if ((b <= (-0.68d0)) .or. (.not. (b <= 9200000.0d0))) then
        tmp = sin(b) * r
    else
        tmp = r * (b / cos(a))
    end if
    code = tmp
end function
public static double code(double r, double a, double b) {
	double tmp;
	if ((b <= -0.68) || !(b <= 9200000.0)) {
		tmp = Math.sin(b) * r;
	} else {
		tmp = r * (b / Math.cos(a));
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if (b <= -0.68) or not (b <= 9200000.0):
		tmp = math.sin(b) * r
	else:
		tmp = r * (b / math.cos(a))
	return tmp
function code(r, a, b)
	tmp = 0.0
	if ((b <= -0.68) || !(b <= 9200000.0))
		tmp = Float64(sin(b) * r);
	else
		tmp = Float64(r * Float64(b / cos(a)));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	tmp = 0.0;
	if ((b <= -0.68) || ~((b <= 9200000.0)))
		tmp = sin(b) * r;
	else
		tmp = r * (b / cos(a));
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[Or[LessEqual[b, -0.68], N[Not[LessEqual[b, 9200000.0]], $MachinePrecision]], N[(N[Sin[b], $MachinePrecision] * r), $MachinePrecision], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.68 \lor \neg \left(b \leq 9200000\right):\\
\;\;\;\;\sin b \cdot r\\

\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < -0.680000000000000049 or 9.2e6 < b

    1. Initial program 55.7%

      \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
    2. Step-by-step derivation
      1. *-commutative55.7%

        \[\leadsto \frac{\color{blue}{\sin b \cdot r}}{\cos \left(a + b\right)} \]
      2. associate-/l*55.7%

        \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(a + b\right)}{r}}} \]
      3. +-commutative55.7%

        \[\leadsto \frac{\sin b}{\frac{\cos \color{blue}{\left(b + a\right)}}{r}} \]
    3. Simplified55.7%

      \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(b + a\right)}{r}}} \]
    4. Step-by-step derivation
      1. add-exp-log26.8%

        \[\leadsto \frac{\sin b}{\color{blue}{e^{\log \left(\frac{\cos \left(b + a\right)}{r}\right)}}} \]
    5. Applied egg-rr26.8%

      \[\leadsto \frac{\sin b}{\color{blue}{e^{\log \left(\frac{\cos \left(b + a\right)}{r}\right)}}} \]
    6. Taylor expanded in b around 0 5.8%

      \[\leadsto \frac{\sin b}{\color{blue}{-1 \cdot \frac{b \cdot \sin a}{r} + \frac{\cos a}{r}}} \]
    7. Step-by-step derivation
      1. +-commutative5.8%

        \[\leadsto \frac{\sin b}{\color{blue}{\frac{\cos a}{r} + -1 \cdot \frac{b \cdot \sin a}{r}}} \]
      2. mul-1-neg5.8%

        \[\leadsto \frac{\sin b}{\frac{\cos a}{r} + \color{blue}{\left(-\frac{b \cdot \sin a}{r}\right)}} \]
      3. unsub-neg5.8%

        \[\leadsto \frac{\sin b}{\color{blue}{\frac{\cos a}{r} - \frac{b \cdot \sin a}{r}}} \]
      4. associate-/l*6.1%

        \[\leadsto \frac{\sin b}{\frac{\cos a}{r} - \color{blue}{\frac{b}{\frac{r}{\sin a}}}} \]
    8. Simplified6.1%

      \[\leadsto \frac{\sin b}{\color{blue}{\frac{\cos a}{r} - \frac{b}{\frac{r}{\sin a}}}} \]
    9. Taylor expanded in a around 0 11.1%

      \[\leadsto \color{blue}{r \cdot \sin b} \]
    10. Step-by-step derivation
      1. *-commutative11.1%

        \[\leadsto \color{blue}{\sin b \cdot r} \]
    11. Simplified11.1%

      \[\leadsto \color{blue}{\sin b \cdot r} \]

    if -0.680000000000000049 < b < 9.2e6

    1. Initial program 98.8%

      \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
    2. Step-by-step derivation
      1. *-commutative98.8%

        \[\leadsto \frac{\color{blue}{\sin b \cdot r}}{\cos \left(a + b\right)} \]
      2. associate-/l*98.8%

        \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(a + b\right)}{r}}} \]
      3. +-commutative98.8%

        \[\leadsto \frac{\sin b}{\frac{\cos \color{blue}{\left(b + a\right)}}{r}} \]
    3. Simplified98.8%

      \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(b + a\right)}{r}}} \]
    4. Taylor expanded in b around 0 97.6%

      \[\leadsto \color{blue}{\frac{b \cdot r}{\cos a}} \]
    5. Step-by-step derivation
      1. associate-/l*97.5%

        \[\leadsto \color{blue}{\frac{b}{\frac{\cos a}{r}}} \]
      2. associate-/r/97.6%

        \[\leadsto \color{blue}{\frac{b}{\cos a} \cdot r} \]
    6. Simplified97.6%

      \[\leadsto \color{blue}{\frac{b}{\cos a} \cdot r} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification55.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -0.68 \lor \neg \left(b \leq 9200000\right):\\ \;\;\;\;\sin b \cdot r\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{b}{\cos a}\\ \end{array} \]

Alternative 7: 55.1% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -0.68 \lor \neg \left(b \leq 9200000\right):\\ \;\;\;\;\sin b \cdot r\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot r}{\cos a}\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (or (<= b -0.68) (not (<= b 9200000.0)))
   (* (sin b) r)
   (/ (* b r) (cos a))))
double code(double r, double a, double b) {
	double tmp;
	if ((b <= -0.68) || !(b <= 9200000.0)) {
		tmp = sin(b) * r;
	} else {
		tmp = (b * r) / cos(a);
	}
	return tmp;
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if ((b <= (-0.68d0)) .or. (.not. (b <= 9200000.0d0))) then
        tmp = sin(b) * r
    else
        tmp = (b * r) / cos(a)
    end if
    code = tmp
end function
public static double code(double r, double a, double b) {
	double tmp;
	if ((b <= -0.68) || !(b <= 9200000.0)) {
		tmp = Math.sin(b) * r;
	} else {
		tmp = (b * r) / Math.cos(a);
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if (b <= -0.68) or not (b <= 9200000.0):
		tmp = math.sin(b) * r
	else:
		tmp = (b * r) / math.cos(a)
	return tmp
function code(r, a, b)
	tmp = 0.0
	if ((b <= -0.68) || !(b <= 9200000.0))
		tmp = Float64(sin(b) * r);
	else
		tmp = Float64(Float64(b * r) / cos(a));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	tmp = 0.0;
	if ((b <= -0.68) || ~((b <= 9200000.0)))
		tmp = sin(b) * r;
	else
		tmp = (b * r) / cos(a);
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[Or[LessEqual[b, -0.68], N[Not[LessEqual[b, 9200000.0]], $MachinePrecision]], N[(N[Sin[b], $MachinePrecision] * r), $MachinePrecision], N[(N[(b * r), $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.68 \lor \neg \left(b \leq 9200000\right):\\
\;\;\;\;\sin b \cdot r\\

\mathbf{else}:\\
\;\;\;\;\frac{b \cdot r}{\cos a}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < -0.680000000000000049 or 9.2e6 < b

    1. Initial program 55.7%

      \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
    2. Step-by-step derivation
      1. *-commutative55.7%

        \[\leadsto \frac{\color{blue}{\sin b \cdot r}}{\cos \left(a + b\right)} \]
      2. associate-/l*55.7%

        \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(a + b\right)}{r}}} \]
      3. +-commutative55.7%

        \[\leadsto \frac{\sin b}{\frac{\cos \color{blue}{\left(b + a\right)}}{r}} \]
    3. Simplified55.7%

      \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(b + a\right)}{r}}} \]
    4. Step-by-step derivation
      1. add-exp-log26.8%

        \[\leadsto \frac{\sin b}{\color{blue}{e^{\log \left(\frac{\cos \left(b + a\right)}{r}\right)}}} \]
    5. Applied egg-rr26.8%

      \[\leadsto \frac{\sin b}{\color{blue}{e^{\log \left(\frac{\cos \left(b + a\right)}{r}\right)}}} \]
    6. Taylor expanded in b around 0 5.8%

      \[\leadsto \frac{\sin b}{\color{blue}{-1 \cdot \frac{b \cdot \sin a}{r} + \frac{\cos a}{r}}} \]
    7. Step-by-step derivation
      1. +-commutative5.8%

        \[\leadsto \frac{\sin b}{\color{blue}{\frac{\cos a}{r} + -1 \cdot \frac{b \cdot \sin a}{r}}} \]
      2. mul-1-neg5.8%

        \[\leadsto \frac{\sin b}{\frac{\cos a}{r} + \color{blue}{\left(-\frac{b \cdot \sin a}{r}\right)}} \]
      3. unsub-neg5.8%

        \[\leadsto \frac{\sin b}{\color{blue}{\frac{\cos a}{r} - \frac{b \cdot \sin a}{r}}} \]
      4. associate-/l*6.1%

        \[\leadsto \frac{\sin b}{\frac{\cos a}{r} - \color{blue}{\frac{b}{\frac{r}{\sin a}}}} \]
    8. Simplified6.1%

      \[\leadsto \frac{\sin b}{\color{blue}{\frac{\cos a}{r} - \frac{b}{\frac{r}{\sin a}}}} \]
    9. Taylor expanded in a around 0 11.1%

      \[\leadsto \color{blue}{r \cdot \sin b} \]
    10. Step-by-step derivation
      1. *-commutative11.1%

        \[\leadsto \color{blue}{\sin b \cdot r} \]
    11. Simplified11.1%

      \[\leadsto \color{blue}{\sin b \cdot r} \]

    if -0.680000000000000049 < b < 9.2e6

    1. Initial program 98.8%

      \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
    2. Step-by-step derivation
      1. *-commutative98.8%

        \[\leadsto \frac{\color{blue}{\sin b \cdot r}}{\cos \left(a + b\right)} \]
      2. associate-/l*98.8%

        \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(a + b\right)}{r}}} \]
      3. +-commutative98.8%

        \[\leadsto \frac{\sin b}{\frac{\cos \color{blue}{\left(b + a\right)}}{r}} \]
    3. Simplified98.8%

      \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(b + a\right)}{r}}} \]
    4. Taylor expanded in b around 0 97.6%

      \[\leadsto \color{blue}{\frac{b \cdot r}{\cos a}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification55.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -0.68 \lor \neg \left(b \leq 9200000\right):\\ \;\;\;\;\sin b \cdot r\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot r}{\cos a}\\ \end{array} \]

Alternative 8: 38.4% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \sin b \cdot r \end{array} \]
(FPCore (r a b) :precision binary64 (* (sin b) r))
double code(double r, double a, double b) {
	return sin(b) * r;
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = sin(b) * r
end function
public static double code(double r, double a, double b) {
	return Math.sin(b) * r;
}
def code(r, a, b):
	return math.sin(b) * r
function code(r, a, b)
	return Float64(sin(b) * r)
end
function tmp = code(r, a, b)
	tmp = sin(b) * r;
end
code[r_, a_, b_] := N[(N[Sin[b], $MachinePrecision] * r), $MachinePrecision]
\begin{array}{l}

\\
\sin b \cdot r
\end{array}
Derivation
  1. Initial program 77.9%

    \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
  2. Step-by-step derivation
    1. *-commutative77.9%

      \[\leadsto \frac{\color{blue}{\sin b \cdot r}}{\cos \left(a + b\right)} \]
    2. associate-/l*77.9%

      \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(a + b\right)}{r}}} \]
    3. +-commutative77.9%

      \[\leadsto \frac{\sin b}{\frac{\cos \color{blue}{\left(b + a\right)}}{r}} \]
  3. Simplified77.9%

    \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(b + a\right)}{r}}} \]
  4. Step-by-step derivation
    1. add-exp-log35.2%

      \[\leadsto \frac{\sin b}{\color{blue}{e^{\log \left(\frac{\cos \left(b + a\right)}{r}\right)}}} \]
  5. Applied egg-rr35.2%

    \[\leadsto \frac{\sin b}{\color{blue}{e^{\log \left(\frac{\cos \left(b + a\right)}{r}\right)}}} \]
  6. Taylor expanded in b around 0 53.2%

    \[\leadsto \frac{\sin b}{\color{blue}{-1 \cdot \frac{b \cdot \sin a}{r} + \frac{\cos a}{r}}} \]
  7. Step-by-step derivation
    1. +-commutative53.2%

      \[\leadsto \frac{\sin b}{\color{blue}{\frac{\cos a}{r} + -1 \cdot \frac{b \cdot \sin a}{r}}} \]
    2. mul-1-neg53.2%

      \[\leadsto \frac{\sin b}{\frac{\cos a}{r} + \color{blue}{\left(-\frac{b \cdot \sin a}{r}\right)}} \]
    3. unsub-neg53.2%

      \[\leadsto \frac{\sin b}{\color{blue}{\frac{\cos a}{r} - \frac{b \cdot \sin a}{r}}} \]
    4. associate-/l*53.4%

      \[\leadsto \frac{\sin b}{\frac{\cos a}{r} - \color{blue}{\frac{b}{\frac{r}{\sin a}}}} \]
  8. Simplified53.4%

    \[\leadsto \frac{\sin b}{\color{blue}{\frac{\cos a}{r} - \frac{b}{\frac{r}{\sin a}}}} \]
  9. Taylor expanded in a around 0 37.4%

    \[\leadsto \color{blue}{r \cdot \sin b} \]
  10. Step-by-step derivation
    1. *-commutative37.4%

      \[\leadsto \color{blue}{\sin b \cdot r} \]
  11. Simplified37.4%

    \[\leadsto \color{blue}{\sin b \cdot r} \]
  12. Final simplification37.4%

    \[\leadsto \sin b \cdot r \]

Alternative 9: 34.3% accurate, 69.0× speedup?

\[\begin{array}{l} \\ b \cdot r \end{array} \]
(FPCore (r a b) :precision binary64 (* b r))
double code(double r, double a, double b) {
	return b * r;
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = b * r
end function
public static double code(double r, double a, double b) {
	return b * r;
}
def code(r, a, b):
	return b * r
function code(r, a, b)
	return Float64(b * r)
end
function tmp = code(r, a, b)
	tmp = b * r;
end
code[r_, a_, b_] := N[(b * r), $MachinePrecision]
\begin{array}{l}

\\
b \cdot r
\end{array}
Derivation
  1. Initial program 77.9%

    \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
  2. Step-by-step derivation
    1. *-commutative77.9%

      \[\leadsto \frac{\color{blue}{\sin b \cdot r}}{\cos \left(a + b\right)} \]
    2. associate-/l*77.9%

      \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(a + b\right)}{r}}} \]
    3. +-commutative77.9%

      \[\leadsto \frac{\sin b}{\frac{\cos \color{blue}{\left(b + a\right)}}{r}} \]
  3. Simplified77.9%

    \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(b + a\right)}{r}}} \]
  4. Taylor expanded in b around 0 52.0%

    \[\leadsto \color{blue}{\frac{b \cdot r}{\cos a}} \]
  5. Step-by-step derivation
    1. associate-/l*51.9%

      \[\leadsto \color{blue}{\frac{b}{\frac{\cos a}{r}}} \]
    2. associate-/r/52.0%

      \[\leadsto \color{blue}{\frac{b}{\cos a} \cdot r} \]
  6. Simplified52.0%

    \[\leadsto \color{blue}{\frac{b}{\cos a} \cdot r} \]
  7. Taylor expanded in a around 0 33.8%

    \[\leadsto \color{blue}{b \cdot r} \]
  8. Step-by-step derivation
    1. *-commutative33.8%

      \[\leadsto \color{blue}{r \cdot b} \]
  9. Simplified33.8%

    \[\leadsto \color{blue}{r \cdot b} \]
  10. Final simplification33.8%

    \[\leadsto b \cdot r \]

Reproduce

?
herbie shell --seed 2023279 
(FPCore (r a b)
  :name "rsin A (should all be same)"
  :precision binary64
  (/ (* r (sin b)) (cos (+ a b))))