rsin A (should all be same)

Percentage Accurate: 76.7% → 99.5%
Time: 8.2s
Alternatives: 11
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));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(r, a, b)
use fmin_fmax_functions
    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 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.7% 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));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(r, a, b)
use fmin_fmax_functions
    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{r \cdot \sin b}{\mathsf{fma}\left(\sin b, -\sin a, \cos b \cdot \cos a\right)} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (/ (* r (sin b)) (fma (sin b) (- (sin a)) (* (cos b) (cos a)))))
double code(double r, double a, double b) {
	return (r * sin(b)) / fma(sin(b), -sin(a), (cos(b) * cos(a)));
}
function code(r, a, b)
	return Float64(Float64(r * sin(b)) / fma(sin(b), Float64(-sin(a)), Float64(cos(b) * cos(a))))
end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[Sin[b], $MachinePrecision] * (-N[Sin[a], $MachinePrecision]) + N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

    \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-cos.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos \left(a + b\right)}} \]
    2. lift-+.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\cos \color{blue}{\left(a + b\right)}} \]
    3. cos-sumN/A

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos a \cdot \cos b - \sin a \cdot \sin b}} \]
    4. lift-sin.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\cos a \cdot \cos b - \sin a \cdot \color{blue}{\sin b}} \]
    5. fp-cancel-sub-sign-invN/A

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos a \cdot \cos b + \left(\mathsf{neg}\left(\sin a\right)\right) \cdot \sin b}} \]
    6. +-commutativeN/A

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\left(\mathsf{neg}\left(\sin a\right)\right) \cdot \sin b + \cos a \cdot \cos b}} \]
    7. *-commutativeN/A

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\sin b \cdot \left(\mathsf{neg}\left(\sin a\right)\right)} + \cos a \cdot \cos b} \]
    8. lower-fma.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\mathsf{fma}\left(\sin b, \mathsf{neg}\left(\sin a\right), \cos a \cdot \cos b\right)}} \]
    9. lower-neg.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\mathsf{fma}\left(\sin b, \color{blue}{-\sin a}, \cos a \cdot \cos b\right)} \]
    10. lower-sin.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\mathsf{fma}\left(\sin b, -\color{blue}{\sin a}, \cos a \cdot \cos b\right)} \]
    11. *-commutativeN/A

      \[\leadsto \frac{r \cdot \sin b}{\mathsf{fma}\left(\sin b, -\sin a, \color{blue}{\cos b \cdot \cos a}\right)} \]
    12. lower-*.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\mathsf{fma}\left(\sin b, -\sin a, \color{blue}{\cos b \cdot \cos a}\right)} \]
    13. lower-cos.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\mathsf{fma}\left(\sin b, -\sin a, \color{blue}{\cos b} \cdot \cos a\right)} \]
    14. lower-cos.f6499.5

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

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

Alternative 2: 99.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \frac{r \cdot \sin b}{\mathsf{fma}\left(\cos b, \cos a, \left(-\sin b\right) \cdot \sin a\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(Float64(r * sin(b)) / fma(cos(b), cos(a), Float64(Float64(-sin(b)) * sin(a))))
end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision] + N[((-N[Sin[b], $MachinePrecision]) * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

    \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-cos.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos \left(a + b\right)}} \]
    2. lift-+.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\cos \color{blue}{\left(a + b\right)}} \]
    3. cos-sumN/A

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos a \cdot \cos b - \sin a \cdot \sin b}} \]
    4. lift-sin.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\cos a \cdot \cos b - \sin a \cdot \color{blue}{\sin b}} \]
    5. *-commutativeN/A

      \[\leadsto \frac{r \cdot \sin b}{\cos a \cdot \cos b - \color{blue}{\sin b \cdot \sin a}} \]
    6. fp-cancel-sub-sign-invN/A

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos a \cdot \cos b + \left(\mathsf{neg}\left(\sin b\right)\right) \cdot \sin a}} \]
    7. *-commutativeN/A

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos b \cdot \cos a} + \left(\mathsf{neg}\left(\sin b\right)\right) \cdot \sin a} \]
    8. lower-fma.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\mathsf{fma}\left(\cos b, \cos a, \left(\mathsf{neg}\left(\sin b\right)\right) \cdot \sin a\right)}} \]
    9. lower-cos.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\mathsf{fma}\left(\color{blue}{\cos b}, \cos a, \left(\mathsf{neg}\left(\sin b\right)\right) \cdot \sin a\right)} \]
    10. lower-cos.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\mathsf{fma}\left(\cos b, \color{blue}{\cos a}, \left(\mathsf{neg}\left(\sin b\right)\right) \cdot \sin a\right)} \]
    11. lower-*.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\mathsf{fma}\left(\cos b, \cos a, \color{blue}{\left(\mathsf{neg}\left(\sin b\right)\right) \cdot \sin a}\right)} \]
    12. lower-neg.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\mathsf{fma}\left(\cos b, \cos a, \color{blue}{\left(-\sin b\right)} \cdot \sin a\right)} \]
    13. lower-sin.f6499.4

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

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

Alternative 3: 99.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \frac{r \cdot \sin b}{\cos b \cdot \cos a - \sin a \cdot \sin b} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (/ (* r (sin b)) (- (* (cos b) (cos a)) (* (sin a) (sin b)))))
double code(double r, double a, double b) {
	return (r * sin(b)) / ((cos(b) * cos(a)) - (sin(a) * sin(b)));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(r, a, b)
use fmin_fmax_functions
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = (r * sin(b)) / ((cos(b) * cos(a)) - (sin(a) * sin(b)))
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(a) * Math.sin(b)));
}
def code(r, a, b):
	return (r * math.sin(b)) / ((math.cos(b) * math.cos(a)) - (math.sin(a) * math.sin(b)))
function code(r, a, b)
	return Float64(Float64(r * sin(b)) / Float64(Float64(cos(b) * cos(a)) - Float64(sin(a) * sin(b))))
end
function tmp = code(r, a, b)
	tmp = (r * sin(b)) / ((cos(b) * cos(a)) - (sin(a) * sin(b)));
end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[a], $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

    \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-cos.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos \left(a + b\right)}} \]
    2. lift-+.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\cos \color{blue}{\left(a + b\right)}} \]
    3. cos-sumN/A

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos a \cdot \cos b - \sin a \cdot \sin b}} \]
    4. lower--.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos a \cdot \cos b - \sin a \cdot \sin b}} \]
    5. *-commutativeN/A

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos b \cdot \cos a} - \sin a \cdot \sin b} \]
    6. lower-*.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos b \cdot \cos a} - \sin a \cdot \sin b} \]
    7. lower-cos.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos b} \cdot \cos a - \sin a \cdot \sin b} \]
    8. lower-cos.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\cos b \cdot \color{blue}{\cos a} - \sin a \cdot \sin b} \]
    9. lift-sin.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\cos b \cdot \cos a - \sin a \cdot \color{blue}{\sin b}} \]
    10. lower-*.f64N/A

      \[\leadsto \frac{r \cdot \sin b}{\cos b \cdot \cos a - \color{blue}{\sin a \cdot \sin b}} \]
    11. lower-sin.f6499.4

      \[\leadsto \frac{r \cdot \sin b}{\cos b \cdot \cos a - \color{blue}{\sin a} \cdot \sin b} \]
  4. Applied rewrites99.4%

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

Alternative 4: 75.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -2.25 \cdot 10^{+17} \lor \neg \left(b \leq 1.15 \cdot 10^{+15}\right):\\ \;\;\;\;\frac{r}{\cos b} \cdot \sin b\\ \mathbf{else}:\\ \;\;\;\;\frac{r \cdot \sin b}{\cos a}\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (or (<= b -2.25e+17) (not (<= b 1.15e+15)))
   (* (/ r (cos b)) (sin b))
   (/ (* r (sin b)) (cos a))))
double code(double r, double a, double b) {
	double tmp;
	if ((b <= -2.25e+17) || !(b <= 1.15e+15)) {
		tmp = (r / cos(b)) * sin(b);
	} else {
		tmp = (r * sin(b)) / cos(a);
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(r, a, b)
use fmin_fmax_functions
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if ((b <= (-2.25d+17)) .or. (.not. (b <= 1.15d+15))) then
        tmp = (r / cos(b)) * sin(b)
    else
        tmp = (r * sin(b)) / cos(a)
    end if
    code = tmp
end function
public static double code(double r, double a, double b) {
	double tmp;
	if ((b <= -2.25e+17) || !(b <= 1.15e+15)) {
		tmp = (r / Math.cos(b)) * Math.sin(b);
	} else {
		tmp = (r * Math.sin(b)) / Math.cos(a);
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if (b <= -2.25e+17) or not (b <= 1.15e+15):
		tmp = (r / math.cos(b)) * math.sin(b)
	else:
		tmp = (r * math.sin(b)) / math.cos(a)
	return tmp
function code(r, a, b)
	tmp = 0.0
	if ((b <= -2.25e+17) || !(b <= 1.15e+15))
		tmp = Float64(Float64(r / cos(b)) * sin(b));
	else
		tmp = Float64(Float64(r * sin(b)) / cos(a));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	tmp = 0.0;
	if ((b <= -2.25e+17) || ~((b <= 1.15e+15)))
		tmp = (r / cos(b)) * sin(b);
	else
		tmp = (r * sin(b)) / cos(a);
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[Or[LessEqual[b, -2.25e+17], N[Not[LessEqual[b, 1.15e+15]], $MachinePrecision]], N[(N[(r / N[Cos[b], $MachinePrecision]), $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision], N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.25 \cdot 10^{+17} \lor \neg \left(b \leq 1.15 \cdot 10^{+15}\right):\\
\;\;\;\;\frac{r}{\cos b} \cdot \sin b\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < -2.25e17 or 1.15e15 < b

    1. Initial program 57.9%

      \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos b}} \]
    4. Step-by-step derivation
      1. Applied rewrites58.4%

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

      if -2.25e17 < b < 1.15e15

      1. Initial program 94.0%

        \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
      2. Add Preprocessing
      3. Taylor expanded in b around 0

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

          \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos a}} \]
      5. Recombined 2 regimes into one program.
      6. Final simplification78.6%

        \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.25 \cdot 10^{+17} \lor \neg \left(b \leq 1.15 \cdot 10^{+15}\right):\\ \;\;\;\;\frac{r}{\cos b} \cdot \sin b\\ \mathbf{else}:\\ \;\;\;\;\frac{r \cdot \sin b}{\cos a}\\ \end{array} \]
      7. Add Preprocessing

      Alternative 5: 76.3% accurate, 1.0× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -14500000000 \lor \neg \left(b \leq 0.051\right):\\ \;\;\;\;\frac{r}{\cos b} \cdot \sin b\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.008333333333333333, b \cdot b, -0.16666666666666666\right) \cdot r, b \cdot b, r\right) \cdot b}{\cos \left(a + b\right)}\\ \end{array} \end{array} \]
      (FPCore (r a b)
       :precision binary64
       (if (or (<= b -14500000000.0) (not (<= b 0.051)))
         (* (/ r (cos b)) (sin b))
         (/
          (*
           (fma
            (* (fma 0.008333333333333333 (* b b) -0.16666666666666666) r)
            (* b b)
            r)
           b)
          (cos (+ a b)))))
      double code(double r, double a, double b) {
      	double tmp;
      	if ((b <= -14500000000.0) || !(b <= 0.051)) {
      		tmp = (r / cos(b)) * sin(b);
      	} else {
      		tmp = (fma((fma(0.008333333333333333, (b * b), -0.16666666666666666) * r), (b * b), r) * b) / cos((a + b));
      	}
      	return tmp;
      }
      
      function code(r, a, b)
      	tmp = 0.0
      	if ((b <= -14500000000.0) || !(b <= 0.051))
      		tmp = Float64(Float64(r / cos(b)) * sin(b));
      	else
      		tmp = Float64(Float64(fma(Float64(fma(0.008333333333333333, Float64(b * b), -0.16666666666666666) * r), Float64(b * b), r) * b) / cos(Float64(a + b)));
      	end
      	return tmp
      end
      
      code[r_, a_, b_] := If[Or[LessEqual[b, -14500000000.0], N[Not[LessEqual[b, 0.051]], $MachinePrecision]], N[(N[(r / N[Cos[b], $MachinePrecision]), $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(0.008333333333333333 * N[(b * b), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] * r), $MachinePrecision] * N[(b * b), $MachinePrecision] + r), $MachinePrecision] * b), $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;b \leq -14500000000 \lor \neg \left(b \leq 0.051\right):\\
      \;\;\;\;\frac{r}{\cos b} \cdot \sin b\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.008333333333333333, b \cdot b, -0.16666666666666666\right) \cdot r, b \cdot b, r\right) \cdot b}{\cos \left(a + b\right)}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if b < -1.45e10 or 0.0509999999999999967 < b

        1. Initial program 55.7%

          \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
        2. Add Preprocessing
        3. Taylor expanded in a around 0

          \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos b}} \]
        4. Step-by-step derivation
          1. Applied rewrites56.1%

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

          if -1.45e10 < b < 0.0509999999999999967

          1. Initial program 97.0%

            \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
          2. Add Preprocessing
          3. Taylor expanded in b around 0

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

              \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(0.008333333333333333, b \cdot b, -0.16666666666666666\right) \cdot r, b \cdot b, r\right) \cdot b}}{\cos \left(a + b\right)} \]
          5. Recombined 2 regimes into one program.
          6. Final simplification78.6%

            \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -14500000000 \lor \neg \left(b \leq 0.051\right):\\ \;\;\;\;\frac{r}{\cos b} \cdot \sin b\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.008333333333333333, b \cdot b, -0.16666666666666666\right) \cdot r, b \cdot b, r\right) \cdot b}{\cos \left(a + b\right)}\\ \end{array} \]
          7. Add Preprocessing

          Alternative 6: 76.7% accurate, 1.0× speedup?

          \[\begin{array}{l} \\ \frac{r}{\cos \left(a + b\right)} \cdot \sin b \end{array} \]
          (FPCore (r a b) :precision binary64 (* (/ r (cos (+ a b))) (sin b)))
          double code(double r, double a, double b) {
          	return (r / cos((a + b))) * sin(b);
          }
          
          module fmin_fmax_functions
              implicit none
              private
              public fmax
              public fmin
          
              interface fmax
                  module procedure fmax88
                  module procedure fmax44
                  module procedure fmax84
                  module procedure fmax48
              end interface
              interface fmin
                  module procedure fmin88
                  module procedure fmin44
                  module procedure fmin84
                  module procedure fmin48
              end interface
          contains
              real(8) function fmax88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(4) function fmax44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(8) function fmax84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmax48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
              end function
              real(8) function fmin88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(4) function fmin44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(8) function fmin84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmin48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
              end function
          end module
          
          real(8) function code(r, a, b)
          use fmin_fmax_functions
              real(8), intent (in) :: r
              real(8), intent (in) :: a
              real(8), intent (in) :: b
              code = (r / cos((a + b))) * sin(b)
          end function
          
          public static double code(double r, double a, double b) {
          	return (r / Math.cos((a + b))) * Math.sin(b);
          }
          
          def code(r, a, b):
          	return (r / math.cos((a + b))) * math.sin(b)
          
          function code(r, a, b)
          	return Float64(Float64(r / cos(Float64(a + b))) * sin(b))
          end
          
          function tmp = code(r, a, b)
          	tmp = (r / cos((a + b))) * sin(b);
          end
          
          code[r_, a_, b_] := N[(N[(r / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision]
          
          \begin{array}{l}
          
          \\
          \frac{r}{\cos \left(a + b\right)} \cdot \sin b
          \end{array}
          
          Derivation
          1. Initial program 78.5%

            \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
          2. Add Preprocessing
          3. Step-by-step derivation
            1. lift-/.f64N/A

              \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos \left(a + b\right)}} \]
            2. lift-*.f64N/A

              \[\leadsto \frac{\color{blue}{r \cdot \sin b}}{\cos \left(a + b\right)} \]
            3. *-commutativeN/A

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

              \[\leadsto \color{blue}{\sin b \cdot \frac{r}{\cos \left(a + b\right)}} \]
            5. *-commutativeN/A

              \[\leadsto \color{blue}{\frac{r}{\cos \left(a + b\right)} \cdot \sin b} \]
            6. lower-*.f64N/A

              \[\leadsto \color{blue}{\frac{r}{\cos \left(a + b\right)} \cdot \sin b} \]
            7. lower-/.f6478.5

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

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

          Alternative 7: 55.6% accurate, 1.4× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -14500000000 \lor \neg \left(b \leq 4.5\right):\\ \;\;\;\;\frac{r \cdot \sin b}{1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.008333333333333333, b \cdot b, -0.16666666666666666\right) \cdot r, b \cdot b, r\right) \cdot b}{\cos \left(a + b\right)}\\ \end{array} \end{array} \]
          (FPCore (r a b)
           :precision binary64
           (if (or (<= b -14500000000.0) (not (<= b 4.5)))
             (/ (* r (sin b)) 1.0)
             (/
              (*
               (fma
                (* (fma 0.008333333333333333 (* b b) -0.16666666666666666) r)
                (* b b)
                r)
               b)
              (cos (+ a b)))))
          double code(double r, double a, double b) {
          	double tmp;
          	if ((b <= -14500000000.0) || !(b <= 4.5)) {
          		tmp = (r * sin(b)) / 1.0;
          	} else {
          		tmp = (fma((fma(0.008333333333333333, (b * b), -0.16666666666666666) * r), (b * b), r) * b) / cos((a + b));
          	}
          	return tmp;
          }
          
          function code(r, a, b)
          	tmp = 0.0
          	if ((b <= -14500000000.0) || !(b <= 4.5))
          		tmp = Float64(Float64(r * sin(b)) / 1.0);
          	else
          		tmp = Float64(Float64(fma(Float64(fma(0.008333333333333333, Float64(b * b), -0.16666666666666666) * r), Float64(b * b), r) * b) / cos(Float64(a + b)));
          	end
          	return tmp
          end
          
          code[r_, a_, b_] := If[Or[LessEqual[b, -14500000000.0], N[Not[LessEqual[b, 4.5]], $MachinePrecision]], N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / 1.0), $MachinePrecision], N[(N[(N[(N[(N[(0.008333333333333333 * N[(b * b), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] * r), $MachinePrecision] * N[(b * b), $MachinePrecision] + r), $MachinePrecision] * b), $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;b \leq -14500000000 \lor \neg \left(b \leq 4.5\right):\\
          \;\;\;\;\frac{r \cdot \sin b}{1}\\
          
          \mathbf{else}:\\
          \;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.008333333333333333, b \cdot b, -0.16666666666666666\right) \cdot r, b \cdot b, r\right) \cdot b}{\cos \left(a + b\right)}\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if b < -1.45e10 or 4.5 < b

            1. Initial program 55.7%

              \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
            2. Add Preprocessing
            3. Taylor expanded in a around 0

              \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos b}} \]
            4. Step-by-step derivation
              1. Applied rewrites56.0%

                \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos b}} \]
              2. Taylor expanded in b around 0

                \[\leadsto \frac{r \cdot \sin b}{1} \]
              3. Step-by-step derivation
                1. Applied rewrites12.4%

                  \[\leadsto \frac{r \cdot \sin b}{1} \]

                if -1.45e10 < b < 4.5

                1. Initial program 97.0%

                  \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
                2. Add Preprocessing
                3. Taylor expanded in b around 0

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

                    \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(0.008333333333333333, b \cdot b, -0.16666666666666666\right) \cdot r, b \cdot b, r\right) \cdot b}}{\cos \left(a + b\right)} \]
                5. Recombined 2 regimes into one program.
                6. Final simplification59.0%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -14500000000 \lor \neg \left(b \leq 4.5\right):\\ \;\;\;\;\frac{r \cdot \sin b}{1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.008333333333333333, b \cdot b, -0.16666666666666666\right) \cdot r, b \cdot b, r\right) \cdot b}{\cos \left(a + b\right)}\\ \end{array} \]
                7. Add Preprocessing

                Alternative 8: 55.4% accurate, 1.7× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -16600000000 \lor \neg \left(b \leq 4.8\right):\\ \;\;\;\;\frac{r \cdot \sin b}{1}\\ \mathbf{else}:\\ \;\;\;\;\frac{r}{\cos a} \cdot b\\ \end{array} \end{array} \]
                (FPCore (r a b)
                 :precision binary64
                 (if (or (<= b -16600000000.0) (not (<= b 4.8)))
                   (/ (* r (sin b)) 1.0)
                   (* (/ r (cos a)) b)))
                double code(double r, double a, double b) {
                	double tmp;
                	if ((b <= -16600000000.0) || !(b <= 4.8)) {
                		tmp = (r * sin(b)) / 1.0;
                	} else {
                		tmp = (r / cos(a)) * b;
                	}
                	return tmp;
                }
                
                module fmin_fmax_functions
                    implicit none
                    private
                    public fmax
                    public fmin
                
                    interface fmax
                        module procedure fmax88
                        module procedure fmax44
                        module procedure fmax84
                        module procedure fmax48
                    end interface
                    interface fmin
                        module procedure fmin88
                        module procedure fmin44
                        module procedure fmin84
                        module procedure fmin48
                    end interface
                contains
                    real(8) function fmax88(x, y) result (res)
                        real(8), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                    end function
                    real(4) function fmax44(x, y) result (res)
                        real(4), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                    end function
                    real(8) function fmax84(x, y) result(res)
                        real(8), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                    end function
                    real(8) function fmax48(x, y) result(res)
                        real(4), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                    end function
                    real(8) function fmin88(x, y) result (res)
                        real(8), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                    end function
                    real(4) function fmin44(x, y) result (res)
                        real(4), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                    end function
                    real(8) function fmin84(x, y) result(res)
                        real(8), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                    end function
                    real(8) function fmin48(x, y) result(res)
                        real(4), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                    end function
                end module
                
                real(8) function code(r, a, b)
                use fmin_fmax_functions
                    real(8), intent (in) :: r
                    real(8), intent (in) :: a
                    real(8), intent (in) :: b
                    real(8) :: tmp
                    if ((b <= (-16600000000.0d0)) .or. (.not. (b <= 4.8d0))) then
                        tmp = (r * sin(b)) / 1.0d0
                    else
                        tmp = (r / cos(a)) * b
                    end if
                    code = tmp
                end function
                
                public static double code(double r, double a, double b) {
                	double tmp;
                	if ((b <= -16600000000.0) || !(b <= 4.8)) {
                		tmp = (r * Math.sin(b)) / 1.0;
                	} else {
                		tmp = (r / Math.cos(a)) * b;
                	}
                	return tmp;
                }
                
                def code(r, a, b):
                	tmp = 0
                	if (b <= -16600000000.0) or not (b <= 4.8):
                		tmp = (r * math.sin(b)) / 1.0
                	else:
                		tmp = (r / math.cos(a)) * b
                	return tmp
                
                function code(r, a, b)
                	tmp = 0.0
                	if ((b <= -16600000000.0) || !(b <= 4.8))
                		tmp = Float64(Float64(r * sin(b)) / 1.0);
                	else
                		tmp = Float64(Float64(r / cos(a)) * b);
                	end
                	return tmp
                end
                
                function tmp_2 = code(r, a, b)
                	tmp = 0.0;
                	if ((b <= -16600000000.0) || ~((b <= 4.8)))
                		tmp = (r * sin(b)) / 1.0;
                	else
                		tmp = (r / cos(a)) * b;
                	end
                	tmp_2 = tmp;
                end
                
                code[r_, a_, b_] := If[Or[LessEqual[b, -16600000000.0], N[Not[LessEqual[b, 4.8]], $MachinePrecision]], N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / 1.0), $MachinePrecision], N[(N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;b \leq -16600000000 \lor \neg \left(b \leq 4.8\right):\\
                \;\;\;\;\frac{r \cdot \sin b}{1}\\
                
                \mathbf{else}:\\
                \;\;\;\;\frac{r}{\cos a} \cdot b\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if b < -1.66e10 or 4.79999999999999982 < b

                  1. Initial program 55.7%

                    \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
                  2. Add Preprocessing
                  3. Taylor expanded in a around 0

                    \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos b}} \]
                  4. Step-by-step derivation
                    1. Applied rewrites56.0%

                      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos b}} \]
                    2. Taylor expanded in b around 0

                      \[\leadsto \frac{r \cdot \sin b}{1} \]
                    3. Step-by-step derivation
                      1. Applied rewrites12.4%

                        \[\leadsto \frac{r \cdot \sin b}{1} \]

                      if -1.66e10 < b < 4.79999999999999982

                      1. Initial program 97.0%

                        \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
                      2. Add Preprocessing
                      3. Taylor expanded in b around 0

                        \[\leadsto \color{blue}{\frac{b \cdot r}{\cos a}} \]
                      4. Step-by-step derivation
                        1. Applied rewrites96.8%

                          \[\leadsto \color{blue}{\frac{r}{\cos a} \cdot b} \]
                      5. Recombined 2 regimes into one program.
                      6. Final simplification58.9%

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

                      Alternative 9: 51.4% accurate, 1.9× speedup?

                      \[\begin{array}{l} \\ \frac{r}{\cos a} \cdot b \end{array} \]
                      (FPCore (r a b) :precision binary64 (* (/ r (cos a)) b))
                      double code(double r, double a, double b) {
                      	return (r / cos(a)) * b;
                      }
                      
                      module fmin_fmax_functions
                          implicit none
                          private
                          public fmax
                          public fmin
                      
                          interface fmax
                              module procedure fmax88
                              module procedure fmax44
                              module procedure fmax84
                              module procedure fmax48
                          end interface
                          interface fmin
                              module procedure fmin88
                              module procedure fmin44
                              module procedure fmin84
                              module procedure fmin48
                          end interface
                      contains
                          real(8) function fmax88(x, y) result (res)
                              real(8), intent (in) :: x
                              real(8), intent (in) :: y
                              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                          end function
                          real(4) function fmax44(x, y) result (res)
                              real(4), intent (in) :: x
                              real(4), intent (in) :: y
                              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                          end function
                          real(8) function fmax84(x, y) result(res)
                              real(8), intent (in) :: x
                              real(4), intent (in) :: y
                              res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                          end function
                          real(8) function fmax48(x, y) result(res)
                              real(4), intent (in) :: x
                              real(8), intent (in) :: y
                              res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                          end function
                          real(8) function fmin88(x, y) result (res)
                              real(8), intent (in) :: x
                              real(8), intent (in) :: y
                              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                          end function
                          real(4) function fmin44(x, y) result (res)
                              real(4), intent (in) :: x
                              real(4), intent (in) :: y
                              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                          end function
                          real(8) function fmin84(x, y) result(res)
                              real(8), intent (in) :: x
                              real(4), intent (in) :: y
                              res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                          end function
                          real(8) function fmin48(x, y) result(res)
                              real(4), intent (in) :: x
                              real(8), intent (in) :: y
                              res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                          end function
                      end module
                      
                      real(8) function code(r, a, b)
                      use fmin_fmax_functions
                          real(8), intent (in) :: r
                          real(8), intent (in) :: a
                          real(8), intent (in) :: b
                          code = (r / cos(a)) * b
                      end function
                      
                      public static double code(double r, double a, double b) {
                      	return (r / Math.cos(a)) * b;
                      }
                      
                      def code(r, a, b):
                      	return (r / math.cos(a)) * b
                      
                      function code(r, a, b)
                      	return Float64(Float64(r / cos(a)) * b)
                      end
                      
                      function tmp = code(r, a, b)
                      	tmp = (r / cos(a)) * b;
                      end
                      
                      code[r_, a_, b_] := N[(N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision]
                      
                      \begin{array}{l}
                      
                      \\
                      \frac{r}{\cos a} \cdot b
                      \end{array}
                      
                      Derivation
                      1. Initial program 78.5%

                        \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
                      2. Add Preprocessing
                      3. Taylor expanded in b around 0

                        \[\leadsto \color{blue}{\frac{b \cdot r}{\cos a}} \]
                      4. Step-by-step derivation
                        1. Applied rewrites54.9%

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

                        Alternative 10: 51.4% accurate, 1.9× 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));
                        }
                        
                        module fmin_fmax_functions
                            implicit none
                            private
                            public fmax
                            public fmin
                        
                            interface fmax
                                module procedure fmax88
                                module procedure fmax44
                                module procedure fmax84
                                module procedure fmax48
                            end interface
                            interface fmin
                                module procedure fmin88
                                module procedure fmin44
                                module procedure fmin84
                                module procedure fmin48
                            end interface
                        contains
                            real(8) function fmax88(x, y) result (res)
                                real(8), intent (in) :: x
                                real(8), intent (in) :: y
                                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                            end function
                            real(4) function fmax44(x, y) result (res)
                                real(4), intent (in) :: x
                                real(4), intent (in) :: y
                                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                            end function
                            real(8) function fmax84(x, y) result(res)
                                real(8), intent (in) :: x
                                real(4), intent (in) :: y
                                res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                            end function
                            real(8) function fmax48(x, y) result(res)
                                real(4), intent (in) :: x
                                real(8), intent (in) :: y
                                res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                            end function
                            real(8) function fmin88(x, y) result (res)
                                real(8), intent (in) :: x
                                real(8), intent (in) :: y
                                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                            end function
                            real(4) function fmin44(x, y) result (res)
                                real(4), intent (in) :: x
                                real(4), intent (in) :: y
                                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                            end function
                            real(8) function fmin84(x, y) result(res)
                                real(8), intent (in) :: x
                                real(4), intent (in) :: y
                                res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                            end function
                            real(8) function fmin48(x, y) result(res)
                                real(4), intent (in) :: x
                                real(8), intent (in) :: y
                                res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                            end function
                        end module
                        
                        real(8) function code(r, a, b)
                        use fmin_fmax_functions
                            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.5%

                          \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
                        2. Add Preprocessing
                        3. Taylor expanded in b around 0

                          \[\leadsto \color{blue}{\frac{b \cdot r}{\cos a}} \]
                        4. Step-by-step derivation
                          1. Applied rewrites54.9%

                            \[\leadsto \color{blue}{\frac{r}{\cos a} \cdot b} \]
                          2. Step-by-step derivation
                            1. Applied rewrites54.9%

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

                            Alternative 11: 34.7% accurate, 36.7× 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;
                            }
                            
                            module fmin_fmax_functions
                                implicit none
                                private
                                public fmax
                                public fmin
                            
                                interface fmax
                                    module procedure fmax88
                                    module procedure fmax44
                                    module procedure fmax84
                                    module procedure fmax48
                                end interface
                                interface fmin
                                    module procedure fmin88
                                    module procedure fmin44
                                    module procedure fmin84
                                    module procedure fmin48
                                end interface
                            contains
                                real(8) function fmax88(x, y) result (res)
                                    real(8), intent (in) :: x
                                    real(8), intent (in) :: y
                                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                end function
                                real(4) function fmax44(x, y) result (res)
                                    real(4), intent (in) :: x
                                    real(4), intent (in) :: y
                                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                end function
                                real(8) function fmax84(x, y) result(res)
                                    real(8), intent (in) :: x
                                    real(4), intent (in) :: y
                                    res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                end function
                                real(8) function fmax48(x, y) result(res)
                                    real(4), intent (in) :: x
                                    real(8), intent (in) :: y
                                    res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                end function
                                real(8) function fmin88(x, y) result (res)
                                    real(8), intent (in) :: x
                                    real(8), intent (in) :: y
                                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                end function
                                real(4) function fmin44(x, y) result (res)
                                    real(4), intent (in) :: x
                                    real(4), intent (in) :: y
                                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                end function
                                real(8) function fmin84(x, y) result(res)
                                    real(8), intent (in) :: x
                                    real(4), intent (in) :: y
                                    res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                end function
                                real(8) function fmin48(x, y) result(res)
                                    real(4), intent (in) :: x
                                    real(8), intent (in) :: y
                                    res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                end function
                            end module
                            
                            real(8) function code(r, a, b)
                            use fmin_fmax_functions
                                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.5%

                              \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
                            2. Add Preprocessing
                            3. Taylor expanded in b around 0

                              \[\leadsto \color{blue}{\frac{b \cdot r}{\cos a}} \]
                            4. Step-by-step derivation
                              1. Applied rewrites54.9%

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

                                \[\leadsto r \cdot b \]
                              3. Step-by-step derivation
                                1. Applied rewrites38.4%

                                  \[\leadsto r \cdot b \]
                                2. Add Preprocessing

                                Reproduce

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