rsin B (should all be same)

Percentage Accurate: 76.7% → 99.5%
Time: 8.9s
Alternatives: 10
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)));
}
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(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 10 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} \\ 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)));
}
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(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.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.5% accurate, 0.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 53.2% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(a + b\right)\\ \mathbf{if}\;\frac{\sin b}{t\_0} \leq 2 \cdot 10^{-14}:\\ \;\;\;\;r \cdot \frac{b}{t\_0}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{\sin b}{1}\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (let* ((t_0 (cos (+ a b))))
   (if (<= (/ (sin b) t_0) 2e-14) (* r (/ b t_0)) (* r (/ (sin b) 1.0)))))
double code(double r, double a, double b) {
	double t_0 = cos((a + b));
	double tmp;
	if ((sin(b) / t_0) <= 2e-14) {
		tmp = r * (b / t_0);
	} else {
		tmp = r * (sin(b) / 1.0);
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = cos((a + b))
    if ((sin(b) / t_0) <= 2d-14) then
        tmp = r * (b / t_0)
    else
        tmp = r * (sin(b) / 1.0d0)
    end if
    code = tmp
end function
public static double code(double r, double a, double b) {
	double t_0 = Math.cos((a + b));
	double tmp;
	if ((Math.sin(b) / t_0) <= 2e-14) {
		tmp = r * (b / t_0);
	} else {
		tmp = r * (Math.sin(b) / 1.0);
	}
	return tmp;
}
def code(r, a, b):
	t_0 = math.cos((a + b))
	tmp = 0
	if (math.sin(b) / t_0) <= 2e-14:
		tmp = r * (b / t_0)
	else:
		tmp = r * (math.sin(b) / 1.0)
	return tmp
function code(r, a, b)
	t_0 = cos(Float64(a + b))
	tmp = 0.0
	if (Float64(sin(b) / t_0) <= 2e-14)
		tmp = Float64(r * Float64(b / t_0));
	else
		tmp = Float64(r * Float64(sin(b) / 1.0));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	t_0 = cos((a + b));
	tmp = 0.0;
	if ((sin(b) / t_0) <= 2e-14)
		tmp = r * (b / t_0);
	else
		tmp = r * (sin(b) / 1.0);
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := Block[{t$95$0 = N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[Sin[b], $MachinePrecision] / t$95$0), $MachinePrecision], 2e-14], N[(r * N[(b / t$95$0), $MachinePrecision]), $MachinePrecision], N[(r * N[(N[Sin[b], $MachinePrecision] / 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(a + b\right)\\
\mathbf{if}\;\frac{\sin b}{t\_0} \leq 2 \cdot 10^{-14}:\\
\;\;\;\;r \cdot \frac{b}{t\_0}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < 2e-14

    1. Initial program 85.4%

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

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

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

      if 2e-14 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b)))

      1. Initial program 57.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\mathsf{fma}\left(\cos b, \cos a, \left(-\sin a\right) \cdot \sin b\right)}} \]
      5. Taylor expanded in a around 0

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

          \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\mathsf{fma}\left(-a, \sin b, \cos b\right)}} \]
        2. Taylor expanded in b around 0

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

            \[\leadsto r \cdot \frac{\sin b}{1} \]
        4. Recombined 2 regimes into one program.
        5. Add Preprocessing

        Alternative 4: 75.7% accurate, 1.0× speedup?

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

          1. Initial program 57.5%

            \[r \cdot \frac{\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.1%

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

            if -1.08e20 < b < 3.05e7

            1. Initial program 94.6%

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

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

                \[\leadsto r \cdot \frac{\color{blue}{\mathsf{fma}\left({b}^{3}, \mathsf{fma}\left(0.008333333333333333, b \cdot b, -0.16666666666666666\right), b\right)}}{\cos \left(a + b\right)} \]
              2. Taylor expanded in b around 0

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

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

                \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.08 \cdot 10^{+20} \lor \neg \left(b \leq 30500000\right):\\ \;\;\;\;\sin b \cdot \frac{r}{\cos b}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{\mathsf{fma}\left(b \cdot b, -0.16666666666666666, 1\right) \cdot b}{\cos \left(a + b\right)}\\ \end{array} \]
              6. Add Preprocessing

              Alternative 5: 76.7% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

              Alternative 6: 76.7% 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)));
              }
              
              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(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}
              
              Derivation
              1. Initial program 78.5%

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

              Alternative 7: 55.5% accurate, 1.5× speedup?

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

                1. Initial program 56.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\mathsf{fma}\left(\cos b, \cos a, \left(-\sin a\right) \cdot \sin b\right)}} \]
                5. Taylor expanded in a around 0

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

                    \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\mathsf{fma}\left(-a, \sin b, \cos b\right)}} \]
                  2. Taylor expanded in b around 0

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

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

                    if -2.25e17 < b < 100

                    1. Initial program 95.9%

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

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

                        \[\leadsto r \cdot \frac{\color{blue}{\mathsf{fma}\left({b}^{3}, \mathsf{fma}\left(0.008333333333333333, b \cdot b, -0.16666666666666666\right), b\right)}}{\cos \left(a + b\right)} \]
                      2. Taylor expanded in b around 0

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

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

                        \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.25 \cdot 10^{+17} \lor \neg \left(b \leq 100\right):\\ \;\;\;\;r \cdot \frac{\sin b}{1}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{\mathsf{fma}\left(b \cdot b, -0.16666666666666666, 1\right) \cdot b}{\cos \left(a + b\right)}\\ \end{array} \]
                      6. 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 8.2\right):\\ \;\;\;\;r \cdot \frac{\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 8.2)))
                         (* r (/ (sin b) 1.0))
                         (* (/ r (cos a)) b)))
                      double code(double r, double a, double b) {
                      	double tmp;
                      	if ((b <= -16600000000.0) || !(b <= 8.2)) {
                      		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 <= 8.2d0))) 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 <= 8.2)) {
                      		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 <= 8.2):
                      		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 <= 8.2))
                      		tmp = Float64(r * Float64(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 <= 8.2)))
                      		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, 8.2]], $MachinePrecision]], N[(r * N[(N[Sin[b], $MachinePrecision] / 1.0), $MachinePrecision]), $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 8.2\right):\\
                      \;\;\;\;r \cdot \frac{\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 8.1999999999999993 < b

                        1. Initial program 55.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

                          \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\mathsf{fma}\left(\cos b, \cos a, \left(-\sin a\right) \cdot \sin b\right)}} \]
                        5. Taylor expanded in a around 0

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

                            \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\mathsf{fma}\left(-a, \sin b, \cos b\right)}} \]
                          2. Taylor expanded in b around 0

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

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

                            if -1.66e10 < b < 8.1999999999999993

                            1. Initial program 97.1%

                              \[r \cdot \frac{\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 8.2\right):\\ \;\;\;\;r \cdot \frac{\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%

                              \[r \cdot \frac{\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: 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%

                                \[r \cdot \frac{\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 B (should all be same)"
                                    :precision binary64
                                    (* r (/ (sin b) (cos (+ a b)))))