rsin B (should all be same)

Percentage Accurate: 76.1% → 99.5%
Time: 35.2s
Alternatives: 11
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ r \cdot \frac{\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(r * Float64(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[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
r \cdot \frac{\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 11 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.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ r \cdot \frac{\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(r * Float64(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[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 99.5% accurate, 0.3× speedup?

\[\begin{array}{l} \\ r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, \sin b \cdot \left(-\sin a\right)\right)} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (* r (/ (sin b) (fma (cos b) (cos a) (* (sin b) (- (sin a)))))))
double code(double r, double a, double b) {
	return r * (sin(b) / fma(cos(b), cos(a), (sin(b) * -sin(a))));
}
function code(r, a, b)
	return Float64(r * Float64(sin(b) / fma(cos(b), cos(a), Float64(sin(b) * Float64(-sin(a))))))
end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision] + N[(N[Sin[b], $MachinePrecision] * (-N[Sin[a], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, \sin b \cdot \left(-\sin a\right)\right)}
\end{array}
Derivation
  1. Initial program 78.9%

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

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

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

      \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}} \]
    2. cancel-sign-sub-inv99.5%

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

      \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\mathsf{fma}\left(\cos b, \cos a, \left(-\sin b\right) \cdot \sin a\right)}} \]
  6. Applied egg-rr99.5%

    \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\mathsf{fma}\left(\cos b, \cos a, \left(-\sin b\right) \cdot \sin a\right)}} \]
  7. Final simplification99.5%

    \[\leadsto r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, \sin b \cdot \left(-\sin a\right)\right)} \]
  8. Add Preprocessing

Alternative 2: 99.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ r \cdot \frac{\sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (* r (/ (sin b) (- (* (cos b) (cos a)) (* (sin b) (sin a))))))
double code(double r, double a, double b) {
	return r * (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a))));
}
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(b) * cos(a)) - (sin(b) * sin(a))))
end function
public static double code(double r, double a, double b) {
	return r * (Math.sin(b) / ((Math.cos(b) * Math.cos(a)) - (Math.sin(b) * Math.sin(a))));
}
def code(r, a, b):
	return r * (math.sin(b) / ((math.cos(b) * math.cos(a)) - (math.sin(b) * math.sin(a))))
function code(r, a, b)
	return Float64(r * Float64(sin(b) / Float64(Float64(cos(b) * cos(a)) - Float64(sin(b) * sin(a)))))
end
function tmp = code(r, a, b)
	tmp = r * (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a))));
end
code[r_, a_, b_] := N[(r * 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]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

    \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}} \]
  7. Add Preprocessing

Alternative 3: 77.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ r \cdot \frac{\sin b}{0.5 \cdot \left(2 \cdot \cos \left(b - a\right)\right) - \sin b \cdot \sin a} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (* r (/ (sin b) (- (* 0.5 (* 2.0 (cos (- b a)))) (* (sin b) (sin a))))))
double code(double r, double a, double b) {
	return r * (sin(b) / ((0.5 * (2.0 * cos((b - a)))) - (sin(b) * sin(a))));
}
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) / ((0.5d0 * (2.0d0 * cos((b - a)))) - (sin(b) * sin(a))))
end function
public static double code(double r, double a, double b) {
	return r * (Math.sin(b) / ((0.5 * (2.0 * Math.cos((b - a)))) - (Math.sin(b) * Math.sin(a))));
}
def code(r, a, b):
	return r * (math.sin(b) / ((0.5 * (2.0 * math.cos((b - a)))) - (math.sin(b) * math.sin(a))))
function code(r, a, b)
	return Float64(r * Float64(sin(b) / Float64(Float64(0.5 * Float64(2.0 * cos(Float64(b - a)))) - Float64(sin(b) * sin(a)))))
end
function tmp = code(r, a, b)
	tmp = r * (sin(b) / ((0.5 * (2.0 * cos((b - a)))) - (sin(b) * sin(a))));
end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[(0.5 * N[(2.0 * N[Cos[N[(b - a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
r \cdot \frac{\sin b}{0.5 \cdot \left(2 \cdot \cos \left(b - a\right)\right) - \sin b \cdot \sin a}
\end{array}
Derivation
  1. Initial program 78.9%

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

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

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

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

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

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

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

      \[\leadsto r \cdot \frac{\sin b}{\frac{1}{\frac{2}{\color{blue}{\left(\cos b \cdot \cos a - \sin b \cdot \sin a\right)} + \cos \left(b - a\right)}} - \sin b \cdot \sin a} \]
    4. cancel-sign-sub-inv80.7%

      \[\leadsto r \cdot \frac{\sin b}{\frac{1}{\frac{2}{\color{blue}{\left(\cos b \cdot \cos a + \left(-\sin b\right) \cdot \sin a\right)} + \cos \left(b - a\right)}} - \sin b \cdot \sin a} \]
    5. add-sqr-sqrt39.7%

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

      \[\leadsto r \cdot \frac{\sin b}{\frac{1}{\frac{2}{\left(\cos b \cdot \cos a + \color{blue}{\sqrt{\left(-\sin b\right) \cdot \left(-\sin b\right)}} \cdot \sin a\right) + \cos \left(b - a\right)}} - \sin b \cdot \sin a} \]
    7. sqr-neg80.3%

      \[\leadsto r \cdot \frac{\sin b}{\frac{1}{\frac{2}{\left(\cos b \cdot \cos a + \sqrt{\color{blue}{\sin b \cdot \sin b}} \cdot \sin a\right) + \cos \left(b - a\right)}} - \sin b \cdot \sin a} \]
    8. sqrt-unprod40.5%

      \[\leadsto r \cdot \frac{\sin b}{\frac{1}{\frac{2}{\left(\cos b \cdot \cos a + \color{blue}{\left(\sqrt{\sin b} \cdot \sqrt{\sin b}\right)} \cdot \sin a\right) + \cos \left(b - a\right)}} - \sin b \cdot \sin a} \]
    9. add-sqr-sqrt80.2%

      \[\leadsto r \cdot \frac{\sin b}{\frac{1}{\frac{2}{\left(\cos b \cdot \cos a + \color{blue}{\sin b} \cdot \sin a\right) + \cos \left(b - a\right)}} - \sin b \cdot \sin a} \]
    10. cos-diff80.4%

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

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

      \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\frac{1}{2} \cdot \left(\cos \left(b - a\right) + \cos \left(b - a\right)\right)} - \sin b \cdot \sin a} \]
    2. metadata-eval80.5%

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

      \[\leadsto r \cdot \frac{\sin b}{0.5 \cdot \color{blue}{\left(2 \cdot \cos \left(b - a\right)\right)} - \sin b \cdot \sin a} \]
  10. Simplified80.5%

    \[\leadsto r \cdot \frac{\sin b}{\color{blue}{0.5 \cdot \left(2 \cdot \cos \left(b - a\right)\right)} - \sin b \cdot \sin a} \]
  11. Add Preprocessing

Alternative 4: 77.1% accurate, 0.7× speedup?

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

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

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

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

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

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

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

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

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

      \[\leadsto r \cdot \frac{\sin b}{\cos b \cdot \cos a - \left(\frac{\cos \left(b - a\right)}{2} - \frac{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}}{2}\right)} \]
    4. cancel-sign-sub-inv80.6%

      \[\leadsto r \cdot \frac{\sin b}{\cos b \cdot \cos a - \left(\frac{\cos \left(b - a\right)}{2} - \frac{\color{blue}{\cos b \cdot \cos a + \left(-\sin b\right) \cdot \sin a}}{2}\right)} \]
    5. add-sqr-sqrt39.6%

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

      \[\leadsto r \cdot \frac{\sin b}{\cos b \cdot \cos a - \left(\frac{\cos \left(b - a\right)}{2} - \frac{\cos b \cdot \cos a + \color{blue}{\sqrt{\left(-\sin b\right) \cdot \left(-\sin b\right)}} \cdot \sin a}{2}\right)} \]
    7. sqr-neg80.2%

      \[\leadsto r \cdot \frac{\sin b}{\cos b \cdot \cos a - \left(\frac{\cos \left(b - a\right)}{2} - \frac{\cos b \cdot \cos a + \sqrt{\color{blue}{\sin b \cdot \sin b}} \cdot \sin a}{2}\right)} \]
    8. sqrt-unprod40.6%

      \[\leadsto r \cdot \frac{\sin b}{\cos b \cdot \cos a - \left(\frac{\cos \left(b - a\right)}{2} - \frac{\cos b \cdot \cos a + \color{blue}{\left(\sqrt{\sin b} \cdot \sqrt{\sin b}\right)} \cdot \sin a}{2}\right)} \]
    9. add-sqr-sqrt79.9%

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

      \[\leadsto r \cdot \frac{\sin b}{\cos b \cdot \cos a - \left(\frac{\cos \left(b - a\right)}{2} - \frac{\color{blue}{\cos \left(b - a\right)}}{2}\right)} \]
  8. Applied egg-rr80.4%

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

      \[\leadsto r \cdot \frac{\sin b}{\cos b \cdot \cos a - \color{blue}{0}} \]
  10. Simplified80.4%

    \[\leadsto r \cdot \frac{\sin b}{\cos b \cdot \cos a - \color{blue}{0}} \]
  11. Final simplification80.4%

    \[\leadsto r \cdot \frac{\sin b}{\cos b \cdot \cos a} \]
  12. Add Preprocessing

Alternative 5: 75.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -11 \lor \neg \left(b \leq 10500000000000\right):\\ \;\;\;\;r \cdot \frac{\sin b}{\cos b}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{b}{\cos a}\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (or (<= b -11.0) (not (<= b 10500000000000.0)))
   (* r (/ (sin b) (cos b)))
   (* r (/ b (cos a)))))
double code(double r, double a, double b) {
	double tmp;
	if ((b <= -11.0) || !(b <= 10500000000000.0)) {
		tmp = r * (sin(b) / cos(b));
	} 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 <= (-11.0d0)) .or. (.not. (b <= 10500000000000.0d0))) then
        tmp = r * (sin(b) / cos(b))
    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 <= -11.0) || !(b <= 10500000000000.0)) {
		tmp = r * (Math.sin(b) / Math.cos(b));
	} else {
		tmp = r * (b / Math.cos(a));
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if (b <= -11.0) or not (b <= 10500000000000.0):
		tmp = r * (math.sin(b) / math.cos(b))
	else:
		tmp = r * (b / math.cos(a))
	return tmp
function code(r, a, b)
	tmp = 0.0
	if ((b <= -11.0) || !(b <= 10500000000000.0))
		tmp = Float64(r * Float64(sin(b) / cos(b)));
	else
		tmp = Float64(r * Float64(b / cos(a)));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	tmp = 0.0;
	if ((b <= -11.0) || ~((b <= 10500000000000.0)))
		tmp = r * (sin(b) / cos(b));
	else
		tmp = r * (b / cos(a));
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[Or[LessEqual[b, -11.0], N[Not[LessEqual[b, 10500000000000.0]], $MachinePrecision]], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -11 \lor \neg \left(b \leq 10500000000000\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < -11 or 1.05e13 < b

    1. Initial program 57.4%

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

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

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

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

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

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

    if -11 < b < 1.05e13

    1. Initial program 96.0%

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

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

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

      \[\leadsto \color{blue}{\frac{b \cdot r}{\cos a}} \]
    6. Step-by-step derivation
      1. *-commutative95.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -11 \lor \neg \left(b \leq 10500000000000\right):\\ \;\;\;\;r \cdot \frac{\sin b}{\cos b}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{b}{\cos a}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 75.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -11:\\ \;\;\;\;\frac{r \cdot \sin b}{\cos b}\\ \mathbf{elif}\;b \leq 10500000000000:\\ \;\;\;\;r \cdot \frac{b}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos b}\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (<= b -11.0)
   (/ (* r (sin b)) (cos b))
   (if (<= b 10500000000000.0) (* r (/ b (cos a))) (* r (/ (sin b) (cos b))))))
double code(double r, double a, double b) {
	double tmp;
	if (b <= -11.0) {
		tmp = (r * sin(b)) / cos(b);
	} else if (b <= 10500000000000.0) {
		tmp = r * (b / cos(a));
	} else {
		tmp = r * (sin(b) / 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 (b <= (-11.0d0)) then
        tmp = (r * sin(b)) / cos(b)
    else if (b <= 10500000000000.0d0) then
        tmp = r * (b / cos(a))
    else
        tmp = r * (sin(b) / cos(b))
    end if
    code = tmp
end function
public static double code(double r, double a, double b) {
	double tmp;
	if (b <= -11.0) {
		tmp = (r * Math.sin(b)) / Math.cos(b);
	} else if (b <= 10500000000000.0) {
		tmp = r * (b / Math.cos(a));
	} else {
		tmp = r * (Math.sin(b) / Math.cos(b));
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if b <= -11.0:
		tmp = (r * math.sin(b)) / math.cos(b)
	elif b <= 10500000000000.0:
		tmp = r * (b / math.cos(a))
	else:
		tmp = r * (math.sin(b) / math.cos(b))
	return tmp
function code(r, a, b)
	tmp = 0.0
	if (b <= -11.0)
		tmp = Float64(Float64(r * sin(b)) / cos(b));
	elseif (b <= 10500000000000.0)
		tmp = Float64(r * Float64(b / cos(a)));
	else
		tmp = Float64(r * Float64(sin(b) / cos(b)));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	tmp = 0.0;
	if (b <= -11.0)
		tmp = (r * sin(b)) / cos(b);
	elseif (b <= 10500000000000.0)
		tmp = r * (b / cos(a));
	else
		tmp = r * (sin(b) / cos(b));
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[LessEqual[b, -11.0], N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 10500000000000.0], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -11:\\
\;\;\;\;\frac{r \cdot \sin b}{\cos b}\\

\mathbf{elif}\;b \leq 10500000000000:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\

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


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

    1. Initial program 51.4%

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

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

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

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

    if -11 < b < 1.05e13

    1. Initial program 96.0%

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

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

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

      \[\leadsto \color{blue}{\frac{b \cdot r}{\cos a}} \]
    6. Step-by-step derivation
      1. *-commutative95.9%

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

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

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

    if 1.05e13 < b

    1. Initial program 63.8%

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

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

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

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

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

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

Alternative 7: 76.1% accurate, 1.0× speedup?

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

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

    \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
  2. Add Preprocessing
  3. Final simplification78.9%

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

Alternative 8: 54.5% accurate, 1.0× speedup?

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

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

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

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

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

    \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\cos a}} \]
  6. Add Preprocessing

Alternative 9: 50.7% accurate, 2.0× speedup?

\[\begin{array}{l} \\ r \cdot \frac{b}{\cos a} \end{array} \]
(FPCore (r a b) :precision binary64 (* r (/ b (cos a))))
double code(double r, double a, double b) {
	return r * (b / 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 = r * (b / cos(a))
end function
public static double code(double r, double a, double b) {
	return r * (b / Math.cos(a));
}
def code(r, a, b):
	return r * (b / math.cos(a))
function code(r, a, b)
	return Float64(r * Float64(b / cos(a)))
end
function tmp = code(r, a, b)
	tmp = r * (b / cos(a));
end
code[r_, a_, b_] := N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

    \[\leadsto \color{blue}{\frac{b \cdot r}{\cos a}} \]
  6. Step-by-step derivation
    1. *-commutative55.3%

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

      \[\leadsto \color{blue}{r \cdot \frac{b}{\cos a}} \]
  7. Simplified55.3%

    \[\leadsto \color{blue}{r \cdot \frac{b}{\cos a}} \]
  8. Add Preprocessing

Alternative 10: 50.7% accurate, 2.0× speedup?

\[\begin{array}{l} \\ b \cdot \frac{r}{\cos a} \end{array} \]
(FPCore (r a b) :precision binary64 (* b (/ r (cos a))))
double code(double r, double a, double b) {
	return 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 = b * (r / cos(a))
end function
public static double code(double r, double a, double b) {
	return b * (r / Math.cos(a));
}
def code(r, a, b):
	return b * (r / math.cos(a))
function code(r, a, b)
	return Float64(b * Float64(r / cos(a)))
end
function tmp = code(r, a, b)
	tmp = b * (r / cos(a));
end
code[r_, a_, b_] := N[(b * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

      \[\leadsto \color{blue}{b \cdot \frac{r}{\cos a}} \]
  7. Simplified55.3%

    \[\leadsto \color{blue}{b \cdot \frac{r}{\cos a}} \]
  8. Add Preprocessing

Alternative 11: 34.3% accurate, 69.0× speedup?

\[\begin{array}{l} \\ r \cdot b \end{array} \]
(FPCore (r a b) :precision binary64 (* r b))
double code(double r, double a, double b) {
	return r * 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 * b
end function
public static double code(double r, double a, double b) {
	return r * b;
}
def code(r, a, b):
	return r * b
function code(r, a, b)
	return Float64(r * b)
end
function tmp = code(r, a, b)
	tmp = r * b;
end
code[r_, a_, b_] := N[(r * b), $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

      \[\leadsto \color{blue}{b \cdot \frac{r}{\cos a}} \]
  7. Simplified55.3%

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

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

      \[\leadsto \color{blue}{r \cdot b} \]
  10. Simplified41.0%

    \[\leadsto \color{blue}{r \cdot b} \]
  11. Add Preprocessing

Reproduce

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