Equirectangular approximation to distance on a great circle

Percentage Accurate: 58.6% → 79.4%
Time: 7.1s
Alternatives: 14
Speedup: 0.5×

Specification

?
\[\begin{array}{l} t_0 := \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\\ R \cdot \sqrt{t\_0 \cdot t\_0 + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
  :precision binary64
  (let* ((t_0 (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0)))))
  (* R (sqrt (+ (* t_0 t_0) (* (- phi1 phi2) (- phi1 phi2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0));
	return R * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
}
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, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0d0))
    code = r * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (lambda1 - lambda2) * Math.cos(((phi1 + phi2) / 2.0));
	return R * Math.sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = (lambda1 - lambda2) * math.cos(((phi1 + phi2) / 2.0))
	return R * math.sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))))
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi1 + phi2) / 2.0)))
	return Float64(R * sqrt(Float64(Float64(t_0 * t_0) + Float64(Float64(phi1 - phi2) * Float64(phi1 - phi2)))))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0));
	tmp = R * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(N[(phi1 + phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(R * N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] + N[(N[(phi1 - phi2), $MachinePrecision] * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\\
R \cdot \sqrt{t\_0 \cdot t\_0 + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}
\end{array}

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 14 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: 58.6% accurate, 1.0× speedup?

\[\begin{array}{l} t_0 := \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\\ R \cdot \sqrt{t\_0 \cdot t\_0 + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
  :precision binary64
  (let* ((t_0 (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0)))))
  (* R (sqrt (+ (* t_0 t_0) (* (- phi1 phi2) (- phi1 phi2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0));
	return R * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
}
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, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0d0))
    code = r * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = (lambda1 - lambda2) * Math.cos(((phi1 + phi2) / 2.0));
	return R * Math.sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = (lambda1 - lambda2) * math.cos(((phi1 + phi2) / 2.0))
	return R * math.sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))))
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi1 + phi2) / 2.0)))
	return Float64(R * sqrt(Float64(Float64(t_0 * t_0) + Float64(Float64(phi1 - phi2) * Float64(phi1 - phi2)))))
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0));
	tmp = R * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(N[(phi1 + phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(R * N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] + N[(N[(phi1 - phi2), $MachinePrecision] * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\\
R \cdot \sqrt{t\_0 \cdot t\_0 + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}
\end{array}

Alternative 1: 79.4% accurate, 0.1× speedup?

\[\begin{array}{l} t_0 := 0.5 \cdot \mathsf{min}\left(\phi_1, \phi_2\right)\\ t_1 := 0.5 \cdot \mathsf{max}\left(\phi_1, \phi_2\right)\\ t_2 := {\left(\cos t\_0 \cdot \cos t\_1 - \sin t\_0 \cdot \sin t\_1\right)}^{2}\\ t_3 := \mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\\ t_4 := \mathsf{min}\left(\lambda_1, \lambda_2\right) - \mathsf{max}\left(\lambda_1, \lambda_2\right)\\ t_5 := \sqrt{t\_2}\\ \mathbf{if}\;t\_4 \leq -1 \cdot 10^{+130}:\\ \;\;\;\;-1 \cdot \left(\mathsf{min}\left(\lambda_1, \lambda_2\right) \cdot \left(-1 \cdot \frac{R \cdot \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) \cdot t\_2\right)}{\mathsf{min}\left(\lambda_1, \lambda_2\right) \cdot t\_5} + R \cdot t\_5\right)\right)\\ \mathbf{elif}\;t\_4 \leq -2 \cdot 10^{+63}:\\ \;\;\;\;\sqrt{t\_3 \cdot t\_3 - \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) - \mathsf{min}\left(\lambda_1, \lambda_2\right)\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\mathsf{max}\left(\phi_1, \phi_2\right) + \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot -0.5\right)\right)\right) \cdot t\_4\right)} \cdot R\\ \mathbf{else}:\\ \;\;\;\;t\_3 \cdot R\\ \end{array} \]
(FPCore (R lambda1 lambda2 phi1 phi2)
  :precision binary64
  (let* ((t_0 (* 0.5 (fmin phi1 phi2)))
       (t_1 (* 0.5 (fmax phi1 phi2)))
       (t_2
        (pow (- (* (cos t_0) (cos t_1)) (* (sin t_0) (sin t_1))) 2.0))
       (t_3 (- (fmax phi1 phi2) (fmin phi1 phi2)))
       (t_4 (- (fmin lambda1 lambda2) (fmax lambda1 lambda2)))
       (t_5 (sqrt t_2)))
  (if (<= t_4 -1e+130)
    (*
     -1.0
     (*
      (fmin lambda1 lambda2)
      (+
       (*
        -1.0
        (/
         (* R (* (fmax lambda1 lambda2) t_2))
         (* (fmin lambda1 lambda2) t_5)))
       (* R t_5))))
    (if (<= t_4 -2e+63)
      (*
       (sqrt
        (-
         (* t_3 t_3)
         (*
          (- (fmax lambda1 lambda2) (fmin lambda1 lambda2))
          (*
           (+
            0.5
            (*
             0.5
             (cos
              (*
               2.0
               (* (+ (fmax phi1 phi2) (fmin phi1 phi2)) -0.5)))))
           t_4))))
       R)
      (* t_3 R)))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = 0.5 * fmin(phi1, phi2);
	double t_1 = 0.5 * fmax(phi1, phi2);
	double t_2 = pow(((cos(t_0) * cos(t_1)) - (sin(t_0) * sin(t_1))), 2.0);
	double t_3 = fmax(phi1, phi2) - fmin(phi1, phi2);
	double t_4 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2);
	double t_5 = sqrt(t_2);
	double tmp;
	if (t_4 <= -1e+130) {
		tmp = -1.0 * (fmin(lambda1, lambda2) * ((-1.0 * ((R * (fmax(lambda1, lambda2) * t_2)) / (fmin(lambda1, lambda2) * t_5))) + (R * t_5)));
	} else if (t_4 <= -2e+63) {
		tmp = sqrt(((t_3 * t_3) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5 + (0.5 * cos((2.0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * t_4)))) * R;
	} else {
		tmp = t_3 * R;
	}
	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, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: t_4
    real(8) :: t_5
    real(8) :: tmp
    t_0 = 0.5d0 * fmin(phi1, phi2)
    t_1 = 0.5d0 * fmax(phi1, phi2)
    t_2 = ((cos(t_0) * cos(t_1)) - (sin(t_0) * sin(t_1))) ** 2.0d0
    t_3 = fmax(phi1, phi2) - fmin(phi1, phi2)
    t_4 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2)
    t_5 = sqrt(t_2)
    if (t_4 <= (-1d+130)) then
        tmp = (-1.0d0) * (fmin(lambda1, lambda2) * (((-1.0d0) * ((r * (fmax(lambda1, lambda2) * t_2)) / (fmin(lambda1, lambda2) * t_5))) + (r * t_5)))
    else if (t_4 <= (-2d+63)) then
        tmp = sqrt(((t_3 * t_3) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5d0 + (0.5d0 * cos((2.0d0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * (-0.5d0)))))) * t_4)))) * r
    else
        tmp = t_3 * r
    end if
    code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = 0.5 * fmin(phi1, phi2);
	double t_1 = 0.5 * fmax(phi1, phi2);
	double t_2 = Math.pow(((Math.cos(t_0) * Math.cos(t_1)) - (Math.sin(t_0) * Math.sin(t_1))), 2.0);
	double t_3 = fmax(phi1, phi2) - fmin(phi1, phi2);
	double t_4 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2);
	double t_5 = Math.sqrt(t_2);
	double tmp;
	if (t_4 <= -1e+130) {
		tmp = -1.0 * (fmin(lambda1, lambda2) * ((-1.0 * ((R * (fmax(lambda1, lambda2) * t_2)) / (fmin(lambda1, lambda2) * t_5))) + (R * t_5)));
	} else if (t_4 <= -2e+63) {
		tmp = Math.sqrt(((t_3 * t_3) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5 + (0.5 * Math.cos((2.0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * t_4)))) * R;
	} else {
		tmp = t_3 * R;
	}
	return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2):
	t_0 = 0.5 * fmin(phi1, phi2)
	t_1 = 0.5 * fmax(phi1, phi2)
	t_2 = math.pow(((math.cos(t_0) * math.cos(t_1)) - (math.sin(t_0) * math.sin(t_1))), 2.0)
	t_3 = fmax(phi1, phi2) - fmin(phi1, phi2)
	t_4 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2)
	t_5 = math.sqrt(t_2)
	tmp = 0
	if t_4 <= -1e+130:
		tmp = -1.0 * (fmin(lambda1, lambda2) * ((-1.0 * ((R * (fmax(lambda1, lambda2) * t_2)) / (fmin(lambda1, lambda2) * t_5))) + (R * t_5)))
	elif t_4 <= -2e+63:
		tmp = math.sqrt(((t_3 * t_3) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5 + (0.5 * math.cos((2.0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * t_4)))) * R
	else:
		tmp = t_3 * R
	return tmp
function code(R, lambda1, lambda2, phi1, phi2)
	t_0 = Float64(0.5 * fmin(phi1, phi2))
	t_1 = Float64(0.5 * fmax(phi1, phi2))
	t_2 = Float64(Float64(cos(t_0) * cos(t_1)) - Float64(sin(t_0) * sin(t_1))) ^ 2.0
	t_3 = Float64(fmax(phi1, phi2) - fmin(phi1, phi2))
	t_4 = Float64(fmin(lambda1, lambda2) - fmax(lambda1, lambda2))
	t_5 = sqrt(t_2)
	tmp = 0.0
	if (t_4 <= -1e+130)
		tmp = Float64(-1.0 * Float64(fmin(lambda1, lambda2) * Float64(Float64(-1.0 * Float64(Float64(R * Float64(fmax(lambda1, lambda2) * t_2)) / Float64(fmin(lambda1, lambda2) * t_5))) + Float64(R * t_5))));
	elseif (t_4 <= -2e+63)
		tmp = Float64(sqrt(Float64(Float64(t_3 * t_3) - Float64(Float64(fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * Float64(Float64(0.5 + Float64(0.5 * cos(Float64(2.0 * Float64(Float64(fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * t_4)))) * R);
	else
		tmp = Float64(t_3 * R);
	end
	return tmp
end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
	t_0 = 0.5 * min(phi1, phi2);
	t_1 = 0.5 * max(phi1, phi2);
	t_2 = ((cos(t_0) * cos(t_1)) - (sin(t_0) * sin(t_1))) ^ 2.0;
	t_3 = max(phi1, phi2) - min(phi1, phi2);
	t_4 = min(lambda1, lambda2) - max(lambda1, lambda2);
	t_5 = sqrt(t_2);
	tmp = 0.0;
	if (t_4 <= -1e+130)
		tmp = -1.0 * (min(lambda1, lambda2) * ((-1.0 * ((R * (max(lambda1, lambda2) * t_2)) / (min(lambda1, lambda2) * t_5))) + (R * t_5)));
	elseif (t_4 <= -2e+63)
		tmp = sqrt(((t_3 * t_3) - ((max(lambda1, lambda2) - min(lambda1, lambda2)) * ((0.5 + (0.5 * cos((2.0 * ((max(phi1, phi2) + min(phi1, phi2)) * -0.5))))) * t_4)))) * R;
	else
		tmp = t_3 * R;
	end
	tmp_2 = tmp;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(0.5 * N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[(N[(N[Cos[t$95$0], $MachinePrecision] * N[Cos[t$95$1], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[t$95$0], $MachinePrecision] * N[Sin[t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[(N[Max[phi1, phi2], $MachinePrecision] - N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[Min[lambda1, lambda2], $MachinePrecision] - N[Max[lambda1, lambda2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[Sqrt[t$95$2], $MachinePrecision]}, If[LessEqual[t$95$4, -1e+130], N[(-1.0 * N[(N[Min[lambda1, lambda2], $MachinePrecision] * N[(N[(-1.0 * N[(N[(R * N[(N[Max[lambda1, lambda2], $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision] / N[(N[Min[lambda1, lambda2], $MachinePrecision] * t$95$5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(R * t$95$5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$4, -2e+63], N[(N[Sqrt[N[(N[(t$95$3 * t$95$3), $MachinePrecision] - N[(N[(N[Max[lambda1, lambda2], $MachinePrecision] - N[Min[lambda1, lambda2], $MachinePrecision]), $MachinePrecision] * N[(N[(0.5 + N[(0.5 * N[Cos[N[(2.0 * N[(N[(N[Max[phi1, phi2], $MachinePrecision] + N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(t$95$3 * R), $MachinePrecision]]]]]]]]]
\begin{array}{l}
t_0 := 0.5 \cdot \mathsf{min}\left(\phi_1, \phi_2\right)\\
t_1 := 0.5 \cdot \mathsf{max}\left(\phi_1, \phi_2\right)\\
t_2 := {\left(\cos t\_0 \cdot \cos t\_1 - \sin t\_0 \cdot \sin t\_1\right)}^{2}\\
t_3 := \mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\\
t_4 := \mathsf{min}\left(\lambda_1, \lambda_2\right) - \mathsf{max}\left(\lambda_1, \lambda_2\right)\\
t_5 := \sqrt{t\_2}\\
\mathbf{if}\;t\_4 \leq -1 \cdot 10^{+130}:\\
\;\;\;\;-1 \cdot \left(\mathsf{min}\left(\lambda_1, \lambda_2\right) \cdot \left(-1 \cdot \frac{R \cdot \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) \cdot t\_2\right)}{\mathsf{min}\left(\lambda_1, \lambda_2\right) \cdot t\_5} + R \cdot t\_5\right)\right)\\

\mathbf{elif}\;t\_4 \leq -2 \cdot 10^{+63}:\\
\;\;\;\;\sqrt{t\_3 \cdot t\_3 - \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) - \mathsf{min}\left(\lambda_1, \lambda_2\right)\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\mathsf{max}\left(\phi_1, \phi_2\right) + \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot -0.5\right)\right)\right) \cdot t\_4\right)} \cdot R\\

\mathbf{else}:\\
\;\;\;\;t\_3 \cdot R\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (-.f64 lambda1 lambda2) < -1.0000000000000001e130

    1. Initial program 58.6%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Step-by-step derivation
      1. lift-cos.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{\phi_1 + \phi_2}{2}\right)}\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. lift-/.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(\frac{\phi_1 + \phi_2}{2}\right)}\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      3. lift-+.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\color{blue}{\phi_1 + \phi_2}}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      4. +-commutativeN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\color{blue}{\phi_2 + \phi_1}}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      5. div-addN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(\frac{\phi_2}{2} + \frac{\phi_1}{2}\right)}\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      6. cos-sumN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)}\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      7. lower--.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)}\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      8. lower-*.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\color{blue}{\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      9. lower-cos.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\color{blue}{\cos \left(\frac{\phi_2}{2}\right)} \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      10. mult-flipN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \color{blue}{\left(\phi_2 \cdot \frac{1}{2}\right)} \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      11. metadata-evalN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \color{blue}{\frac{1}{2}}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      12. lower-*.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \color{blue}{\left(\phi_2 \cdot \frac{1}{2}\right)} \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      13. lower-cos.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \color{blue}{\cos \left(\frac{\phi_1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      14. mult-flipN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \color{blue}{\left(\phi_1 \cdot \frac{1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      15. metadata-evalN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \color{blue}{\frac{1}{2}}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      16. lower-*.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \color{blue}{\left(\phi_1 \cdot \frac{1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      17. lower-*.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \color{blue}{\sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      18. lower-sin.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \color{blue}{\sin \left(\frac{\phi_2}{2}\right)} \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      19. mult-flipN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \color{blue}{\left(\phi_2 \cdot \frac{1}{2}\right)} \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      20. metadata-evalN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \color{blue}{\frac{1}{2}}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      21. lower-*.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \color{blue}{\left(\phi_2 \cdot \frac{1}{2}\right)} \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      22. lower-sin.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \color{blue}{\sin \left(\frac{\phi_1}{2}\right)}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      23. mult-flipN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \color{blue}{\left(\phi_1 \cdot \frac{1}{2}\right)}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      24. metadata-evalN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \color{blue}{\frac{1}{2}}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      25. lower-*.f6456.0%

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \color{blue}{\left(\phi_1 \cdot 0.5\right)}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    3. Applied rewrites56.0%

      \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)}\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    4. Step-by-step derivation
      1. lift-cos.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{\phi_1 + \phi_2}{2}\right)}\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. lift-/.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(\frac{\phi_1 + \phi_2}{2}\right)}\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      3. lift-+.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\color{blue}{\phi_1 + \phi_2}}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      4. +-commutativeN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\color{blue}{\phi_2 + \phi_1}}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      5. div-addN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(\frac{\phi_2}{2} + \frac{\phi_1}{2}\right)}\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      6. cos-sumN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)}\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      7. lower--.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)}\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      8. lower-*.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\color{blue}{\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      9. lower-cos.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\color{blue}{\cos \left(\frac{\phi_2}{2}\right)} \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      10. mult-flipN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \color{blue}{\left(\phi_2 \cdot \frac{1}{2}\right)} \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      11. metadata-evalN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \color{blue}{\frac{1}{2}}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      12. lower-*.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \color{blue}{\left(\phi_2 \cdot \frac{1}{2}\right)} \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      13. lower-cos.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \color{blue}{\cos \left(\frac{\phi_1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      14. mult-flipN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \color{blue}{\left(\phi_1 \cdot \frac{1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      15. metadata-evalN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \color{blue}{\frac{1}{2}}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      16. lower-*.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \color{blue}{\left(\phi_1 \cdot \frac{1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      17. lower-*.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \color{blue}{\sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      18. lower-sin.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \color{blue}{\sin \left(\frac{\phi_2}{2}\right)} \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      19. mult-flipN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \color{blue}{\left(\phi_2 \cdot \frac{1}{2}\right)} \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      20. metadata-evalN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \color{blue}{\frac{1}{2}}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      21. lower-*.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \color{blue}{\left(\phi_2 \cdot \frac{1}{2}\right)} \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      22. lower-sin.f64N/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \color{blue}{\sin \left(\frac{\phi_1}{2}\right)}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      23. mult-flipN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \color{blue}{\left(\phi_1 \cdot \frac{1}{2}\right)}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      24. metadata-evalN/A

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \color{blue}{\frac{1}{2}}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      25. lower-*.f6459.2%

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \color{blue}{\left(\phi_1 \cdot 0.5\right)}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    5. Applied rewrites59.2%

      \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)}\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    6. Taylor expanded in lambda1 around -inf

      \[\leadsto \color{blue}{-1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot {\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right) - \sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)}^{2}\right)}{\lambda_1 \cdot \sqrt{{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right) - \sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)}^{2}}} + R \cdot \sqrt{{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right) - \sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)}^{2}}\right)\right)} \]
    7. Step-by-step derivation
      1. Applied rewrites30.2%

        \[\leadsto \color{blue}{-1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot {\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2}\right)}{\lambda_1 \cdot \sqrt{{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2}}} + R \cdot \sqrt{{\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)}^{2}}\right)\right)} \]

      if -1.0000000000000001e130 < (-.f64 lambda1 lambda2) < -2.0000000000000001e63

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Applied rewrites58.6%

        \[\leadsto \color{blue}{\sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\lambda_2 - \lambda_1\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\phi_2 + \phi_1\right) \cdot -0.5\right)\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R} \]

      if -2.0000000000000001e63 < (-.f64 lambda1 lambda2)

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Taylor expanded in phi2 around inf

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \color{blue}{\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)}\right) \]
        2. lower-+.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + \color{blue}{-1 \cdot \frac{\phi_1}{\phi_2}}\right)\right) \]
        3. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \color{blue}{\frac{\phi_1}{\phi_2}}\right)\right) \]
        4. lower-/.f6427.9%

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\color{blue}{\phi_2}}\right)\right) \]
      4. Applied rewrites27.9%

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \color{blue}{R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
        2. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
        3. lower-*.f6427.9%

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
      6. Applied rewrites29.9%

        \[\leadsto \color{blue}{\left(\phi_2 - \phi_1\right) \cdot R} \]
    8. Recombined 3 regimes into one program.
    9. Add Preprocessing

    Alternative 2: 79.3% accurate, 0.1× speedup?

    \[\begin{array}{l} t_0 := -\mathsf{max}\left(\phi_1, \phi_2\right)\\ t_1 := \mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\\ t_2 := 0.5 + 0.5 \cdot \left(\cos \left(\mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot \cos t\_0 - \sin \left(-\mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot \sin t\_0\right)\\ t_3 := \mathsf{min}\left(\lambda_1, \lambda_2\right) - \mathsf{max}\left(\lambda_1, \lambda_2\right)\\ t_4 := \sqrt{--1 \cdot t\_2}\\ \mathbf{if}\;t\_3 \leq -1 \cdot 10^{+130}:\\ \;\;\;\;-1 \cdot \left(\mathsf{min}\left(\lambda_1, \lambda_2\right) \cdot \left(-1 \cdot \frac{R \cdot \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) \cdot t\_2\right)}{\mathsf{min}\left(\lambda_1, \lambda_2\right) \cdot t\_4} + R \cdot t\_4\right)\right)\\ \mathbf{elif}\;t\_3 \leq -2 \cdot 10^{+63}:\\ \;\;\;\;\sqrt{t\_1 \cdot t\_1 - \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) - \mathsf{min}\left(\lambda_1, \lambda_2\right)\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\mathsf{max}\left(\phi_1, \phi_2\right) + \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot -0.5\right)\right)\right) \cdot t\_3\right)} \cdot R\\ \mathbf{else}:\\ \;\;\;\;t\_1 \cdot R\\ \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
      :precision binary64
      (let* ((t_0 (- (fmax phi1 phi2)))
           (t_1 (- (fmax phi1 phi2) (fmin phi1 phi2)))
           (t_2
            (+
             0.5
             (*
              0.5
              (-
               (* (cos (fmin phi1 phi2)) (cos t_0))
               (* (sin (- (fmin phi1 phi2))) (sin t_0))))))
           (t_3 (- (fmin lambda1 lambda2) (fmax lambda1 lambda2)))
           (t_4 (sqrt (- (* -1.0 t_2)))))
      (if (<= t_3 -1e+130)
        (*
         -1.0
         (*
          (fmin lambda1 lambda2)
          (+
           (*
            -1.0
            (/
             (* R (* (fmax lambda1 lambda2) t_2))
             (* (fmin lambda1 lambda2) t_4)))
           (* R t_4))))
        (if (<= t_3 -2e+63)
          (*
           (sqrt
            (-
             (* t_1 t_1)
             (*
              (- (fmax lambda1 lambda2) (fmin lambda1 lambda2))
              (*
               (+
                0.5
                (*
                 0.5
                 (cos
                  (*
                   2.0
                   (* (+ (fmax phi1 phi2) (fmin phi1 phi2)) -0.5)))))
               t_3))))
           R)
          (* t_1 R)))))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = -fmax(phi1, phi2);
    	double t_1 = fmax(phi1, phi2) - fmin(phi1, phi2);
    	double t_2 = 0.5 + (0.5 * ((cos(fmin(phi1, phi2)) * cos(t_0)) - (sin(-fmin(phi1, phi2)) * sin(t_0))));
    	double t_3 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2);
    	double t_4 = sqrt(-(-1.0 * t_2));
    	double tmp;
    	if (t_3 <= -1e+130) {
    		tmp = -1.0 * (fmin(lambda1, lambda2) * ((-1.0 * ((R * (fmax(lambda1, lambda2) * t_2)) / (fmin(lambda1, lambda2) * t_4))) + (R * t_4)));
    	} else if (t_3 <= -2e+63) {
    		tmp = sqrt(((t_1 * t_1) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5 + (0.5 * cos((2.0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * t_3)))) * R;
    	} else {
    		tmp = t_1 * R;
    	}
    	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, lambda1, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: t_0
        real(8) :: t_1
        real(8) :: t_2
        real(8) :: t_3
        real(8) :: t_4
        real(8) :: tmp
        t_0 = -fmax(phi1, phi2)
        t_1 = fmax(phi1, phi2) - fmin(phi1, phi2)
        t_2 = 0.5d0 + (0.5d0 * ((cos(fmin(phi1, phi2)) * cos(t_0)) - (sin(-fmin(phi1, phi2)) * sin(t_0))))
        t_3 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2)
        t_4 = sqrt(-((-1.0d0) * t_2))
        if (t_3 <= (-1d+130)) then
            tmp = (-1.0d0) * (fmin(lambda1, lambda2) * (((-1.0d0) * ((r * (fmax(lambda1, lambda2) * t_2)) / (fmin(lambda1, lambda2) * t_4))) + (r * t_4)))
        else if (t_3 <= (-2d+63)) then
            tmp = sqrt(((t_1 * t_1) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5d0 + (0.5d0 * cos((2.0d0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * (-0.5d0)))))) * t_3)))) * r
        else
            tmp = t_1 * r
        end if
        code = tmp
    end function
    
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = -fmax(phi1, phi2);
    	double t_1 = fmax(phi1, phi2) - fmin(phi1, phi2);
    	double t_2 = 0.5 + (0.5 * ((Math.cos(fmin(phi1, phi2)) * Math.cos(t_0)) - (Math.sin(-fmin(phi1, phi2)) * Math.sin(t_0))));
    	double t_3 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2);
    	double t_4 = Math.sqrt(-(-1.0 * t_2));
    	double tmp;
    	if (t_3 <= -1e+130) {
    		tmp = -1.0 * (fmin(lambda1, lambda2) * ((-1.0 * ((R * (fmax(lambda1, lambda2) * t_2)) / (fmin(lambda1, lambda2) * t_4))) + (R * t_4)));
    	} else if (t_3 <= -2e+63) {
    		tmp = Math.sqrt(((t_1 * t_1) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5 + (0.5 * Math.cos((2.0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * t_3)))) * R;
    	} else {
    		tmp = t_1 * R;
    	}
    	return tmp;
    }
    
    def code(R, lambda1, lambda2, phi1, phi2):
    	t_0 = -fmax(phi1, phi2)
    	t_1 = fmax(phi1, phi2) - fmin(phi1, phi2)
    	t_2 = 0.5 + (0.5 * ((math.cos(fmin(phi1, phi2)) * math.cos(t_0)) - (math.sin(-fmin(phi1, phi2)) * math.sin(t_0))))
    	t_3 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2)
    	t_4 = math.sqrt(-(-1.0 * t_2))
    	tmp = 0
    	if t_3 <= -1e+130:
    		tmp = -1.0 * (fmin(lambda1, lambda2) * ((-1.0 * ((R * (fmax(lambda1, lambda2) * t_2)) / (fmin(lambda1, lambda2) * t_4))) + (R * t_4)))
    	elif t_3 <= -2e+63:
    		tmp = math.sqrt(((t_1 * t_1) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5 + (0.5 * math.cos((2.0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * t_3)))) * R
    	else:
    		tmp = t_1 * R
    	return tmp
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	t_0 = Float64(-fmax(phi1, phi2))
    	t_1 = Float64(fmax(phi1, phi2) - fmin(phi1, phi2))
    	t_2 = Float64(0.5 + Float64(0.5 * Float64(Float64(cos(fmin(phi1, phi2)) * cos(t_0)) - Float64(sin(Float64(-fmin(phi1, phi2))) * sin(t_0)))))
    	t_3 = Float64(fmin(lambda1, lambda2) - fmax(lambda1, lambda2))
    	t_4 = sqrt(Float64(-Float64(-1.0 * t_2)))
    	tmp = 0.0
    	if (t_3 <= -1e+130)
    		tmp = Float64(-1.0 * Float64(fmin(lambda1, lambda2) * Float64(Float64(-1.0 * Float64(Float64(R * Float64(fmax(lambda1, lambda2) * t_2)) / Float64(fmin(lambda1, lambda2) * t_4))) + Float64(R * t_4))));
    	elseif (t_3 <= -2e+63)
    		tmp = Float64(sqrt(Float64(Float64(t_1 * t_1) - Float64(Float64(fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * Float64(Float64(0.5 + Float64(0.5 * cos(Float64(2.0 * Float64(Float64(fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * t_3)))) * R);
    	else
    		tmp = Float64(t_1 * R);
    	end
    	return tmp
    end
    
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	t_0 = -max(phi1, phi2);
    	t_1 = max(phi1, phi2) - min(phi1, phi2);
    	t_2 = 0.5 + (0.5 * ((cos(min(phi1, phi2)) * cos(t_0)) - (sin(-min(phi1, phi2)) * sin(t_0))));
    	t_3 = min(lambda1, lambda2) - max(lambda1, lambda2);
    	t_4 = sqrt(-(-1.0 * t_2));
    	tmp = 0.0;
    	if (t_3 <= -1e+130)
    		tmp = -1.0 * (min(lambda1, lambda2) * ((-1.0 * ((R * (max(lambda1, lambda2) * t_2)) / (min(lambda1, lambda2) * t_4))) + (R * t_4)));
    	elseif (t_3 <= -2e+63)
    		tmp = sqrt(((t_1 * t_1) - ((max(lambda1, lambda2) - min(lambda1, lambda2)) * ((0.5 + (0.5 * cos((2.0 * ((max(phi1, phi2) + min(phi1, phi2)) * -0.5))))) * t_3)))) * R;
    	else
    		tmp = t_1 * R;
    	end
    	tmp_2 = tmp;
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = (-N[Max[phi1, phi2], $MachinePrecision])}, Block[{t$95$1 = N[(N[Max[phi1, phi2], $MachinePrecision] - N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(0.5 + N[(0.5 * N[(N[(N[Cos[N[Min[phi1, phi2], $MachinePrecision]], $MachinePrecision] * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[(-N[Min[phi1, phi2], $MachinePrecision])], $MachinePrecision] * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[Min[lambda1, lambda2], $MachinePrecision] - N[Max[lambda1, lambda2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[Sqrt[(-N[(-1.0 * t$95$2), $MachinePrecision])], $MachinePrecision]}, If[LessEqual[t$95$3, -1e+130], N[(-1.0 * N[(N[Min[lambda1, lambda2], $MachinePrecision] * N[(N[(-1.0 * N[(N[(R * N[(N[Max[lambda1, lambda2], $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision] / N[(N[Min[lambda1, lambda2], $MachinePrecision] * t$95$4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(R * t$95$4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, -2e+63], N[(N[Sqrt[N[(N[(t$95$1 * t$95$1), $MachinePrecision] - N[(N[(N[Max[lambda1, lambda2], $MachinePrecision] - N[Min[lambda1, lambda2], $MachinePrecision]), $MachinePrecision] * N[(N[(0.5 + N[(0.5 * N[Cos[N[(2.0 * N[(N[(N[Max[phi1, phi2], $MachinePrecision] + N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(t$95$1 * R), $MachinePrecision]]]]]]]]
    
    \begin{array}{l}
    t_0 := -\mathsf{max}\left(\phi_1, \phi_2\right)\\
    t_1 := \mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\\
    t_2 := 0.5 + 0.5 \cdot \left(\cos \left(\mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot \cos t\_0 - \sin \left(-\mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot \sin t\_0\right)\\
    t_3 := \mathsf{min}\left(\lambda_1, \lambda_2\right) - \mathsf{max}\left(\lambda_1, \lambda_2\right)\\
    t_4 := \sqrt{--1 \cdot t\_2}\\
    \mathbf{if}\;t\_3 \leq -1 \cdot 10^{+130}:\\
    \;\;\;\;-1 \cdot \left(\mathsf{min}\left(\lambda_1, \lambda_2\right) \cdot \left(-1 \cdot \frac{R \cdot \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) \cdot t\_2\right)}{\mathsf{min}\left(\lambda_1, \lambda_2\right) \cdot t\_4} + R \cdot t\_4\right)\right)\\
    
    \mathbf{elif}\;t\_3 \leq -2 \cdot 10^{+63}:\\
    \;\;\;\;\sqrt{t\_1 \cdot t\_1 - \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) - \mathsf{min}\left(\lambda_1, \lambda_2\right)\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\mathsf{max}\left(\phi_1, \phi_2\right) + \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot -0.5\right)\right)\right) \cdot t\_3\right)} \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_1 \cdot R\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if (-.f64 lambda1 lambda2) < -1.0000000000000001e130

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Applied rewrites58.6%

        \[\leadsto \color{blue}{\sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\lambda_2 - \lambda_1\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\phi_2 + \phi_1\right) \cdot -0.5\right)\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R} \]
      3. Taylor expanded in lambda1 around -inf

        \[\leadsto \color{blue}{-1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{\mathsf{neg}\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}} + R \cdot \sqrt{\mathsf{neg}\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}\right)\right)} \]
      4. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto -1 \cdot \color{blue}{\left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{\mathsf{neg}\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}} + R \cdot \sqrt{\mathsf{neg}\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}\right)\right)} \]
        2. lower-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \color{blue}{\left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{\mathsf{neg}\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}} + R \cdot \sqrt{\mathsf{neg}\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}\right)}\right) \]
      5. Applied rewrites28.3%

        \[\leadsto \color{blue}{-1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(0.5 + 0.5 \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(0.5 + 0.5 \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(0.5 + 0.5 \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right)} \]
      6. Step-by-step derivation
        1. lift-cos.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        2. lift-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        3. lift-+.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        4. distribute-rgt-inN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(\phi_1 \cdot -1 + \phi_2 \cdot -1\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        5. *-commutativeN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \phi_1 + \phi_2 \cdot -1\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        6. lift-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \phi_1 + \phi_2 \cdot -1\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        7. cos-sumN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(-1 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        8. lower--.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(-1 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        9. lift-cos.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(-1 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        10. lower-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(-1 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        11. lift-cos.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(-1 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        12. lift-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(-1 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        13. mul-1-negN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        14. cos-negN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        15. lower-cos.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        16. *-commutativeN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-1 \cdot \phi_2\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        17. mul-1-negN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(\mathsf{neg}\left(\phi_2\right)\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        18. lower-cos.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(\mathsf{neg}\left(\phi_2\right)\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        19. lower-neg.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        20. lower-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        21. lower-sin.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        22. lift-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        23. mul-1-negN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        24. lower-neg.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        25. *-commutativeN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-1 \cdot \phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        26. mul-1-negN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(\mathsf{neg}\left(\phi_2\right)\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
      7. Applied rewrites28.3%

        \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(0.5 + 0.5 \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(0.5 + 0.5 \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(0.5 + 0.5 \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
      8. Step-by-step derivation
        1. lift-cos.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        2. lift-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        3. lift-+.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        4. distribute-rgt-inN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(\phi_1 \cdot -1 + \phi_2 \cdot -1\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        5. *-commutativeN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \phi_1 + \phi_2 \cdot -1\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        6. lift-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \phi_1 + \phi_2 \cdot -1\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        7. cos-sumN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(-1 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        8. lower--.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(-1 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        9. lift-cos.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(-1 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        10. lower-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(-1 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        11. lift-cos.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(-1 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        12. lift-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(-1 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        13. mul-1-negN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        14. cos-negN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        15. lower-cos.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        16. *-commutativeN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-1 \cdot \phi_2\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        17. mul-1-negN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(\mathsf{neg}\left(\phi_2\right)\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        18. lower-cos.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(\mathsf{neg}\left(\phi_2\right)\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        19. lower-neg.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        20. lower-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        21. lower-sin.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        22. lift-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        23. mul-1-negN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        24. lower-neg.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        25. *-commutativeN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-1 \cdot \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        26. mul-1-negN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(\mathsf{neg}\left(\phi_2\right)\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
      9. Applied rewrites29.0%

        \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(0.5 + 0.5 \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(0.5 + 0.5 \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(0.5 + 0.5 \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
      10. Step-by-step derivation
        1. lift-cos.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        2. lift-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        3. lift-+.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right) \]
        4. distribute-rgt-inN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(\phi_1 \cdot -1 + \phi_2 \cdot -1\right)\right)}\right)\right) \]
        5. *-commutativeN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \phi_1 + \phi_2 \cdot -1\right)\right)}\right)\right) \]
        6. lift-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \phi_1 + \phi_2 \cdot -1\right)\right)}\right)\right) \]
        7. cos-sumN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(-1 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}\right)\right) \]
        8. lower--.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(-1 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}\right)\right) \]
        9. lift-cos.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(-1 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}\right)\right) \]
        10. lower-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(-1 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}\right)\right) \]
        11. lift-cos.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(-1 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}\right)\right) \]
        12. lift-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(-1 \cdot \phi_1\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}\right)\right) \]
        13. mul-1-negN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}\right)\right) \]
        14. cos-negN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}\right)\right) \]
        15. lower-cos.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(\phi_2 \cdot -1\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}\right)\right) \]
        16. *-commutativeN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-1 \cdot \phi_2\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}\right)\right) \]
        17. mul-1-negN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(\mathsf{neg}\left(\phi_2\right)\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}\right)\right) \]
        18. lower-cos.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(\mathsf{neg}\left(\phi_2\right)\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}\right)\right) \]
        19. lower-neg.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}\right)\right) \]
        20. lower-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}\right)\right) \]
        21. lower-sin.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}\right)\right) \]
        22. lift-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-1 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}\right)\right) \]
        23. mul-1-negN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(\mathsf{neg}\left(\phi_1\right)\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}\right)\right) \]
        24. lower-neg.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(\phi_2 \cdot -1\right)\right)\right)}\right)\right) \]
        25. *-commutativeN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-1 \cdot \phi_2\right)\right)\right)}\right)\right) \]
        26. mul-1-negN/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(\mathsf{neg}\left(\phi_2\right)\right)\right)\right)}\right)\right) \]
      11. Applied rewrites30.1%

        \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(0.5 + 0.5 \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(0.5 + 0.5 \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(0.5 + 0.5 \cdot \left(\cos \phi_1 \cdot \cos \left(-\phi_2\right) - \sin \left(-\phi_1\right) \cdot \sin \left(-\phi_2\right)\right)\right)}\right)\right) \]

      if -1.0000000000000001e130 < (-.f64 lambda1 lambda2) < -2.0000000000000001e63

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Applied rewrites58.6%

        \[\leadsto \color{blue}{\sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\lambda_2 - \lambda_1\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\phi_2 + \phi_1\right) \cdot -0.5\right)\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R} \]

      if -2.0000000000000001e63 < (-.f64 lambda1 lambda2)

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Taylor expanded in phi2 around inf

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \color{blue}{\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)}\right) \]
        2. lower-+.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + \color{blue}{-1 \cdot \frac{\phi_1}{\phi_2}}\right)\right) \]
        3. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \color{blue}{\frac{\phi_1}{\phi_2}}\right)\right) \]
        4. lower-/.f6427.9%

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\color{blue}{\phi_2}}\right)\right) \]
      4. Applied rewrites27.9%

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \color{blue}{R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
        2. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
        3. lower-*.f6427.9%

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
      6. Applied rewrites29.9%

        \[\leadsto \color{blue}{\left(\phi_2 - \phi_1\right) \cdot R} \]
    3. Recombined 3 regimes into one program.
    4. Add Preprocessing

    Alternative 3: 76.9% accurate, 0.1× speedup?

    \[\begin{array}{l} t_0 := \mathsf{min}\left(\phi_1, \phi_2\right) \cdot 0.5\\ t_1 := \mathsf{min}\left(\phi_1, \phi_2\right) - \mathsf{max}\left(\phi_1, \phi_2\right)\\ t_2 := {\cos \left(0.5 \cdot \left(\mathsf{min}\left(\phi_1, \phi_2\right) + \mathsf{max}\left(\phi_1, \phi_2\right)\right)\right)}^{2}\\ t_3 := \sqrt{t\_2}\\ t_4 := \mathsf{min}\left(\lambda_1, \lambda_2\right) - \mathsf{max}\left(\lambda_1, \lambda_2\right)\\ t_5 := \mathsf{max}\left(\phi_1, \phi_2\right) \cdot 0.5\\ t_6 := t\_4 \cdot \left(\cos t\_5 \cdot \cos t\_0 - \sin t\_5 \cdot \sin t\_0\right)\\ \mathbf{if}\;t\_4 \leq -5 \cdot 10^{+132}:\\ \;\;\;\;-1 \cdot \left(\mathsf{min}\left(\lambda_1, \lambda_2\right) \cdot \left(-1 \cdot \frac{R \cdot \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) \cdot t\_2\right)}{\mathsf{min}\left(\lambda_1, \lambda_2\right) \cdot t\_3} + R \cdot t\_3\right)\right)\\ \mathbf{elif}\;t\_4 \leq -2 \cdot 10^{+63}:\\ \;\;\;\;R \cdot \sqrt{t\_6 \cdot t\_6 + t\_1 \cdot t\_1}\\ \mathbf{else}:\\ \;\;\;\;\left(\mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot R\\ \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
      :precision binary64
      (let* ((t_0 (* (fmin phi1 phi2) 0.5))
           (t_1 (- (fmin phi1 phi2) (fmax phi1 phi2)))
           (t_2
            (pow (cos (* 0.5 (+ (fmin phi1 phi2) (fmax phi1 phi2)))) 2.0))
           (t_3 (sqrt t_2))
           (t_4 (- (fmin lambda1 lambda2) (fmax lambda1 lambda2)))
           (t_5 (* (fmax phi1 phi2) 0.5))
           (t_6
            (* t_4 (- (* (cos t_5) (cos t_0)) (* (sin t_5) (sin t_0))))))
      (if (<= t_4 -5e+132)
        (*
         -1.0
         (*
          (fmin lambda1 lambda2)
          (+
           (*
            -1.0
            (/
             (* R (* (fmax lambda1 lambda2) t_2))
             (* (fmin lambda1 lambda2) t_3)))
           (* R t_3))))
        (if (<= t_4 -2e+63)
          (* R (sqrt (+ (* t_6 t_6) (* t_1 t_1))))
          (* (- (fmax phi1 phi2) (fmin phi1 phi2)) R)))))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = fmin(phi1, phi2) * 0.5;
    	double t_1 = fmin(phi1, phi2) - fmax(phi1, phi2);
    	double t_2 = pow(cos((0.5 * (fmin(phi1, phi2) + fmax(phi1, phi2)))), 2.0);
    	double t_3 = sqrt(t_2);
    	double t_4 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2);
    	double t_5 = fmax(phi1, phi2) * 0.5;
    	double t_6 = t_4 * ((cos(t_5) * cos(t_0)) - (sin(t_5) * sin(t_0)));
    	double tmp;
    	if (t_4 <= -5e+132) {
    		tmp = -1.0 * (fmin(lambda1, lambda2) * ((-1.0 * ((R * (fmax(lambda1, lambda2) * t_2)) / (fmin(lambda1, lambda2) * t_3))) + (R * t_3)));
    	} else if (t_4 <= -2e+63) {
    		tmp = R * sqrt(((t_6 * t_6) + (t_1 * t_1)));
    	} else {
    		tmp = (fmax(phi1, phi2) - fmin(phi1, phi2)) * R;
    	}
    	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, lambda1, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: t_0
        real(8) :: t_1
        real(8) :: t_2
        real(8) :: t_3
        real(8) :: t_4
        real(8) :: t_5
        real(8) :: t_6
        real(8) :: tmp
        t_0 = fmin(phi1, phi2) * 0.5d0
        t_1 = fmin(phi1, phi2) - fmax(phi1, phi2)
        t_2 = cos((0.5d0 * (fmin(phi1, phi2) + fmax(phi1, phi2)))) ** 2.0d0
        t_3 = sqrt(t_2)
        t_4 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2)
        t_5 = fmax(phi1, phi2) * 0.5d0
        t_6 = t_4 * ((cos(t_5) * cos(t_0)) - (sin(t_5) * sin(t_0)))
        if (t_4 <= (-5d+132)) then
            tmp = (-1.0d0) * (fmin(lambda1, lambda2) * (((-1.0d0) * ((r * (fmax(lambda1, lambda2) * t_2)) / (fmin(lambda1, lambda2) * t_3))) + (r * t_3)))
        else if (t_4 <= (-2d+63)) then
            tmp = r * sqrt(((t_6 * t_6) + (t_1 * t_1)))
        else
            tmp = (fmax(phi1, phi2) - fmin(phi1, phi2)) * r
        end if
        code = tmp
    end function
    
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = fmin(phi1, phi2) * 0.5;
    	double t_1 = fmin(phi1, phi2) - fmax(phi1, phi2);
    	double t_2 = Math.pow(Math.cos((0.5 * (fmin(phi1, phi2) + fmax(phi1, phi2)))), 2.0);
    	double t_3 = Math.sqrt(t_2);
    	double t_4 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2);
    	double t_5 = fmax(phi1, phi2) * 0.5;
    	double t_6 = t_4 * ((Math.cos(t_5) * Math.cos(t_0)) - (Math.sin(t_5) * Math.sin(t_0)));
    	double tmp;
    	if (t_4 <= -5e+132) {
    		tmp = -1.0 * (fmin(lambda1, lambda2) * ((-1.0 * ((R * (fmax(lambda1, lambda2) * t_2)) / (fmin(lambda1, lambda2) * t_3))) + (R * t_3)));
    	} else if (t_4 <= -2e+63) {
    		tmp = R * Math.sqrt(((t_6 * t_6) + (t_1 * t_1)));
    	} else {
    		tmp = (fmax(phi1, phi2) - fmin(phi1, phi2)) * R;
    	}
    	return tmp;
    }
    
    def code(R, lambda1, lambda2, phi1, phi2):
    	t_0 = fmin(phi1, phi2) * 0.5
    	t_1 = fmin(phi1, phi2) - fmax(phi1, phi2)
    	t_2 = math.pow(math.cos((0.5 * (fmin(phi1, phi2) + fmax(phi1, phi2)))), 2.0)
    	t_3 = math.sqrt(t_2)
    	t_4 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2)
    	t_5 = fmax(phi1, phi2) * 0.5
    	t_6 = t_4 * ((math.cos(t_5) * math.cos(t_0)) - (math.sin(t_5) * math.sin(t_0)))
    	tmp = 0
    	if t_4 <= -5e+132:
    		tmp = -1.0 * (fmin(lambda1, lambda2) * ((-1.0 * ((R * (fmax(lambda1, lambda2) * t_2)) / (fmin(lambda1, lambda2) * t_3))) + (R * t_3)))
    	elif t_4 <= -2e+63:
    		tmp = R * math.sqrt(((t_6 * t_6) + (t_1 * t_1)))
    	else:
    		tmp = (fmax(phi1, phi2) - fmin(phi1, phi2)) * R
    	return tmp
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	t_0 = Float64(fmin(phi1, phi2) * 0.5)
    	t_1 = Float64(fmin(phi1, phi2) - fmax(phi1, phi2))
    	t_2 = cos(Float64(0.5 * Float64(fmin(phi1, phi2) + fmax(phi1, phi2)))) ^ 2.0
    	t_3 = sqrt(t_2)
    	t_4 = Float64(fmin(lambda1, lambda2) - fmax(lambda1, lambda2))
    	t_5 = Float64(fmax(phi1, phi2) * 0.5)
    	t_6 = Float64(t_4 * Float64(Float64(cos(t_5) * cos(t_0)) - Float64(sin(t_5) * sin(t_0))))
    	tmp = 0.0
    	if (t_4 <= -5e+132)
    		tmp = Float64(-1.0 * Float64(fmin(lambda1, lambda2) * Float64(Float64(-1.0 * Float64(Float64(R * Float64(fmax(lambda1, lambda2) * t_2)) / Float64(fmin(lambda1, lambda2) * t_3))) + Float64(R * t_3))));
    	elseif (t_4 <= -2e+63)
    		tmp = Float64(R * sqrt(Float64(Float64(t_6 * t_6) + Float64(t_1 * t_1))));
    	else
    		tmp = Float64(Float64(fmax(phi1, phi2) - fmin(phi1, phi2)) * R);
    	end
    	return tmp
    end
    
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	t_0 = min(phi1, phi2) * 0.5;
    	t_1 = min(phi1, phi2) - max(phi1, phi2);
    	t_2 = cos((0.5 * (min(phi1, phi2) + max(phi1, phi2)))) ^ 2.0;
    	t_3 = sqrt(t_2);
    	t_4 = min(lambda1, lambda2) - max(lambda1, lambda2);
    	t_5 = max(phi1, phi2) * 0.5;
    	t_6 = t_4 * ((cos(t_5) * cos(t_0)) - (sin(t_5) * sin(t_0)));
    	tmp = 0.0;
    	if (t_4 <= -5e+132)
    		tmp = -1.0 * (min(lambda1, lambda2) * ((-1.0 * ((R * (max(lambda1, lambda2) * t_2)) / (min(lambda1, lambda2) * t_3))) + (R * t_3)));
    	elseif (t_4 <= -2e+63)
    		tmp = R * sqrt(((t_6 * t_6) + (t_1 * t_1)));
    	else
    		tmp = (max(phi1, phi2) - min(phi1, phi2)) * R;
    	end
    	tmp_2 = tmp;
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Min[phi1, phi2], $MachinePrecision] * 0.5), $MachinePrecision]}, Block[{t$95$1 = N[(N[Min[phi1, phi2], $MachinePrecision] - N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Cos[N[(0.5 * N[(N[Min[phi1, phi2], $MachinePrecision] + N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[Sqrt[t$95$2], $MachinePrecision]}, Block[{t$95$4 = N[(N[Min[lambda1, lambda2], $MachinePrecision] - N[Max[lambda1, lambda2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[Max[phi1, phi2], $MachinePrecision] * 0.5), $MachinePrecision]}, Block[{t$95$6 = N[(t$95$4 * N[(N[(N[Cos[t$95$5], $MachinePrecision] * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[t$95$5], $MachinePrecision] * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$4, -5e+132], N[(-1.0 * N[(N[Min[lambda1, lambda2], $MachinePrecision] * N[(N[(-1.0 * N[(N[(R * N[(N[Max[lambda1, lambda2], $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision] / N[(N[Min[lambda1, lambda2], $MachinePrecision] * t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(R * t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$4, -2e+63], N[(R * N[Sqrt[N[(N[(t$95$6 * t$95$6), $MachinePrecision] + N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(N[Max[phi1, phi2], $MachinePrecision] - N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision]]]]]]]]]]
    
    \begin{array}{l}
    t_0 := \mathsf{min}\left(\phi_1, \phi_2\right) \cdot 0.5\\
    t_1 := \mathsf{min}\left(\phi_1, \phi_2\right) - \mathsf{max}\left(\phi_1, \phi_2\right)\\
    t_2 := {\cos \left(0.5 \cdot \left(\mathsf{min}\left(\phi_1, \phi_2\right) + \mathsf{max}\left(\phi_1, \phi_2\right)\right)\right)}^{2}\\
    t_3 := \sqrt{t\_2}\\
    t_4 := \mathsf{min}\left(\lambda_1, \lambda_2\right) - \mathsf{max}\left(\lambda_1, \lambda_2\right)\\
    t_5 := \mathsf{max}\left(\phi_1, \phi_2\right) \cdot 0.5\\
    t_6 := t\_4 \cdot \left(\cos t\_5 \cdot \cos t\_0 - \sin t\_5 \cdot \sin t\_0\right)\\
    \mathbf{if}\;t\_4 \leq -5 \cdot 10^{+132}:\\
    \;\;\;\;-1 \cdot \left(\mathsf{min}\left(\lambda_1, \lambda_2\right) \cdot \left(-1 \cdot \frac{R \cdot \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) \cdot t\_2\right)}{\mathsf{min}\left(\lambda_1, \lambda_2\right) \cdot t\_3} + R \cdot t\_3\right)\right)\\
    
    \mathbf{elif}\;t\_4 \leq -2 \cdot 10^{+63}:\\
    \;\;\;\;R \cdot \sqrt{t\_6 \cdot t\_6 + t\_1 \cdot t\_1}\\
    
    \mathbf{else}:\\
    \;\;\;\;\left(\mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot R\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if (-.f64 lambda1 lambda2) < -5.0000000000000001e132

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Taylor expanded in phi1 around inf

        \[\leadsto \color{blue}{R \cdot \phi_1} \]
      3. Step-by-step derivation
        1. lower-*.f6417.3%

          \[\leadsto R \cdot \color{blue}{\phi_1} \]
      4. Applied rewrites17.3%

        \[\leadsto \color{blue}{R \cdot \phi_1} \]
      5. Taylor expanded in lambda1 around -inf

        \[\leadsto \color{blue}{-1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot {\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}\right)}{\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}} + R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right)} \]
      6. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto -1 \cdot \color{blue}{\left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot {\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}\right)}{\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}} + R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right)} \]
        2. lower-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \color{blue}{\left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot {\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}\right)}{\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}} + R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)}\right) \]
        3. lower-+.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot {\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}\right)}{\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}} + \color{blue}{R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}}\right)\right) \]
      7. Applied rewrites28.3%

        \[\leadsto \color{blue}{-1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot {\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}\right)}{\lambda_1 \cdot \sqrt{{\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}} + R \cdot \sqrt{{\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right)} \]

      if -5.0000000000000001e132 < (-.f64 lambda1 lambda2) < -2.0000000000000001e63

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Step-by-step derivation
        1. lift-cos.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{\phi_1 + \phi_2}{2}\right)}\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        2. lift-/.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(\frac{\phi_1 + \phi_2}{2}\right)}\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        3. lift-+.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\color{blue}{\phi_1 + \phi_2}}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        4. +-commutativeN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\color{blue}{\phi_2 + \phi_1}}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        5. div-addN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(\frac{\phi_2}{2} + \frac{\phi_1}{2}\right)}\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        6. cos-sumN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)}\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        7. lower--.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)}\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        8. lower-*.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\color{blue}{\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        9. lower-cos.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\color{blue}{\cos \left(\frac{\phi_2}{2}\right)} \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        10. mult-flipN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \color{blue}{\left(\phi_2 \cdot \frac{1}{2}\right)} \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        11. metadata-evalN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \color{blue}{\frac{1}{2}}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        12. lower-*.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \color{blue}{\left(\phi_2 \cdot \frac{1}{2}\right)} \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        13. lower-cos.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \color{blue}{\cos \left(\frac{\phi_1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        14. mult-flipN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \color{blue}{\left(\phi_1 \cdot \frac{1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        15. metadata-evalN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \color{blue}{\frac{1}{2}}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        16. lower-*.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \color{blue}{\left(\phi_1 \cdot \frac{1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        17. lower-*.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \color{blue}{\sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        18. lower-sin.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \color{blue}{\sin \left(\frac{\phi_2}{2}\right)} \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        19. mult-flipN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \color{blue}{\left(\phi_2 \cdot \frac{1}{2}\right)} \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        20. metadata-evalN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \color{blue}{\frac{1}{2}}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        21. lower-*.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \color{blue}{\left(\phi_2 \cdot \frac{1}{2}\right)} \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        22. lower-sin.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \color{blue}{\sin \left(\frac{\phi_1}{2}\right)}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        23. mult-flipN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \color{blue}{\left(\phi_1 \cdot \frac{1}{2}\right)}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        24. metadata-evalN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \color{blue}{\frac{1}{2}}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        25. lower-*.f6456.0%

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \color{blue}{\left(\phi_1 \cdot 0.5\right)}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      3. Applied rewrites56.0%

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)}\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      4. Step-by-step derivation
        1. lift-cos.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{\phi_1 + \phi_2}{2}\right)}\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        2. lift-/.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(\frac{\phi_1 + \phi_2}{2}\right)}\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        3. lift-+.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\color{blue}{\phi_1 + \phi_2}}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        4. +-commutativeN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\color{blue}{\phi_2 + \phi_1}}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        5. div-addN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(\frac{\phi_2}{2} + \frac{\phi_1}{2}\right)}\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        6. cos-sumN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)}\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        7. lower--.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)}\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        8. lower-*.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\color{blue}{\cos \left(\frac{\phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        9. lower-cos.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\color{blue}{\cos \left(\frac{\phi_2}{2}\right)} \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        10. mult-flipN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \color{blue}{\left(\phi_2 \cdot \frac{1}{2}\right)} \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        11. metadata-evalN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \color{blue}{\frac{1}{2}}\right) \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        12. lower-*.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \color{blue}{\left(\phi_2 \cdot \frac{1}{2}\right)} \cdot \cos \left(\frac{\phi_1}{2}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        13. lower-cos.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \color{blue}{\cos \left(\frac{\phi_1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        14. mult-flipN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \color{blue}{\left(\phi_1 \cdot \frac{1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        15. metadata-evalN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \color{blue}{\frac{1}{2}}\right) - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        16. lower-*.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \color{blue}{\left(\phi_1 \cdot \frac{1}{2}\right)} - \sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        17. lower-*.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \color{blue}{\sin \left(\frac{\phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        18. lower-sin.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \color{blue}{\sin \left(\frac{\phi_2}{2}\right)} \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        19. mult-flipN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \color{blue}{\left(\phi_2 \cdot \frac{1}{2}\right)} \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        20. metadata-evalN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \color{blue}{\frac{1}{2}}\right) \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        21. lower-*.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \color{blue}{\left(\phi_2 \cdot \frac{1}{2}\right)} \cdot \sin \left(\frac{\phi_1}{2}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        22. lower-sin.f64N/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \color{blue}{\sin \left(\frac{\phi_1}{2}\right)}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        23. mult-flipN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \color{blue}{\left(\phi_1 \cdot \frac{1}{2}\right)}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        24. metadata-evalN/A

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \frac{1}{2}\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \cos \left(\phi_1 \cdot \frac{1}{2}\right) - \sin \left(\phi_2 \cdot \frac{1}{2}\right) \cdot \sin \left(\phi_1 \cdot \color{blue}{\frac{1}{2}}\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
        25. lower-*.f6459.2%

          \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \color{blue}{\left(\phi_1 \cdot 0.5\right)}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      5. Applied rewrites59.2%

        \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)}\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]

      if -2.0000000000000001e63 < (-.f64 lambda1 lambda2)

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Taylor expanded in phi2 around inf

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \color{blue}{\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)}\right) \]
        2. lower-+.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + \color{blue}{-1 \cdot \frac{\phi_1}{\phi_2}}\right)\right) \]
        3. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \color{blue}{\frac{\phi_1}{\phi_2}}\right)\right) \]
        4. lower-/.f6427.9%

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\color{blue}{\phi_2}}\right)\right) \]
      4. Applied rewrites27.9%

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \color{blue}{R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
        2. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
        3. lower-*.f6427.9%

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
      6. Applied rewrites29.9%

        \[\leadsto \color{blue}{\left(\phi_2 - \phi_1\right) \cdot R} \]
    3. Recombined 3 regimes into one program.
    4. Add Preprocessing

    Alternative 4: 76.5% accurate, 0.2× speedup?

    \[\begin{array}{l} t_0 := {\cos \left(0.5 \cdot \left(\mathsf{min}\left(\phi_1, \phi_2\right) + \mathsf{max}\left(\phi_1, \phi_2\right)\right)\right)}^{2}\\ t_1 := \sqrt{t\_0}\\ t_2 := \mathsf{min}\left(\lambda_1, \lambda_2\right) - \mathsf{max}\left(\lambda_1, \lambda_2\right)\\ t_3 := \mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\\ \mathbf{if}\;t\_2 \leq -5 \cdot 10^{+132}:\\ \;\;\;\;-1 \cdot \left(\mathsf{min}\left(\lambda_1, \lambda_2\right) \cdot \left(-1 \cdot \frac{R \cdot \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) \cdot t\_0\right)}{\mathsf{min}\left(\lambda_1, \lambda_2\right) \cdot t\_1} + R \cdot t\_1\right)\right)\\ \mathbf{elif}\;t\_2 \leq -2 \cdot 10^{+63}:\\ \;\;\;\;\sqrt{t\_3 \cdot t\_3 - \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) - \mathsf{min}\left(\lambda_1, \lambda_2\right)\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\mathsf{max}\left(\phi_1, \phi_2\right) + \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot -0.5\right)\right)\right) \cdot t\_2\right)} \cdot R\\ \mathbf{else}:\\ \;\;\;\;t\_3 \cdot R\\ \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
      :precision binary64
      (let* ((t_0
            (pow (cos (* 0.5 (+ (fmin phi1 phi2) (fmax phi1 phi2)))) 2.0))
           (t_1 (sqrt t_0))
           (t_2 (- (fmin lambda1 lambda2) (fmax lambda1 lambda2)))
           (t_3 (- (fmax phi1 phi2) (fmin phi1 phi2))))
      (if (<= t_2 -5e+132)
        (*
         -1.0
         (*
          (fmin lambda1 lambda2)
          (+
           (*
            -1.0
            (/
             (* R (* (fmax lambda1 lambda2) t_0))
             (* (fmin lambda1 lambda2) t_1)))
           (* R t_1))))
        (if (<= t_2 -2e+63)
          (*
           (sqrt
            (-
             (* t_3 t_3)
             (*
              (- (fmax lambda1 lambda2) (fmin lambda1 lambda2))
              (*
               (+
                0.5
                (*
                 0.5
                 (cos
                  (*
                   2.0
                   (* (+ (fmax phi1 phi2) (fmin phi1 phi2)) -0.5)))))
               t_2))))
           R)
          (* t_3 R)))))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = pow(cos((0.5 * (fmin(phi1, phi2) + fmax(phi1, phi2)))), 2.0);
    	double t_1 = sqrt(t_0);
    	double t_2 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2);
    	double t_3 = fmax(phi1, phi2) - fmin(phi1, phi2);
    	double tmp;
    	if (t_2 <= -5e+132) {
    		tmp = -1.0 * (fmin(lambda1, lambda2) * ((-1.0 * ((R * (fmax(lambda1, lambda2) * t_0)) / (fmin(lambda1, lambda2) * t_1))) + (R * t_1)));
    	} else if (t_2 <= -2e+63) {
    		tmp = sqrt(((t_3 * t_3) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5 + (0.5 * cos((2.0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * t_2)))) * R;
    	} else {
    		tmp = t_3 * R;
    	}
    	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, lambda1, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: t_0
        real(8) :: t_1
        real(8) :: t_2
        real(8) :: t_3
        real(8) :: tmp
        t_0 = cos((0.5d0 * (fmin(phi1, phi2) + fmax(phi1, phi2)))) ** 2.0d0
        t_1 = sqrt(t_0)
        t_2 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2)
        t_3 = fmax(phi1, phi2) - fmin(phi1, phi2)
        if (t_2 <= (-5d+132)) then
            tmp = (-1.0d0) * (fmin(lambda1, lambda2) * (((-1.0d0) * ((r * (fmax(lambda1, lambda2) * t_0)) / (fmin(lambda1, lambda2) * t_1))) + (r * t_1)))
        else if (t_2 <= (-2d+63)) then
            tmp = sqrt(((t_3 * t_3) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5d0 + (0.5d0 * cos((2.0d0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * (-0.5d0)))))) * t_2)))) * r
        else
            tmp = t_3 * r
        end if
        code = tmp
    end function
    
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = Math.pow(Math.cos((0.5 * (fmin(phi1, phi2) + fmax(phi1, phi2)))), 2.0);
    	double t_1 = Math.sqrt(t_0);
    	double t_2 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2);
    	double t_3 = fmax(phi1, phi2) - fmin(phi1, phi2);
    	double tmp;
    	if (t_2 <= -5e+132) {
    		tmp = -1.0 * (fmin(lambda1, lambda2) * ((-1.0 * ((R * (fmax(lambda1, lambda2) * t_0)) / (fmin(lambda1, lambda2) * t_1))) + (R * t_1)));
    	} else if (t_2 <= -2e+63) {
    		tmp = Math.sqrt(((t_3 * t_3) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5 + (0.5 * Math.cos((2.0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * t_2)))) * R;
    	} else {
    		tmp = t_3 * R;
    	}
    	return tmp;
    }
    
    def code(R, lambda1, lambda2, phi1, phi2):
    	t_0 = math.pow(math.cos((0.5 * (fmin(phi1, phi2) + fmax(phi1, phi2)))), 2.0)
    	t_1 = math.sqrt(t_0)
    	t_2 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2)
    	t_3 = fmax(phi1, phi2) - fmin(phi1, phi2)
    	tmp = 0
    	if t_2 <= -5e+132:
    		tmp = -1.0 * (fmin(lambda1, lambda2) * ((-1.0 * ((R * (fmax(lambda1, lambda2) * t_0)) / (fmin(lambda1, lambda2) * t_1))) + (R * t_1)))
    	elif t_2 <= -2e+63:
    		tmp = math.sqrt(((t_3 * t_3) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5 + (0.5 * math.cos((2.0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * t_2)))) * R
    	else:
    		tmp = t_3 * R
    	return tmp
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	t_0 = cos(Float64(0.5 * Float64(fmin(phi1, phi2) + fmax(phi1, phi2)))) ^ 2.0
    	t_1 = sqrt(t_0)
    	t_2 = Float64(fmin(lambda1, lambda2) - fmax(lambda1, lambda2))
    	t_3 = Float64(fmax(phi1, phi2) - fmin(phi1, phi2))
    	tmp = 0.0
    	if (t_2 <= -5e+132)
    		tmp = Float64(-1.0 * Float64(fmin(lambda1, lambda2) * Float64(Float64(-1.0 * Float64(Float64(R * Float64(fmax(lambda1, lambda2) * t_0)) / Float64(fmin(lambda1, lambda2) * t_1))) + Float64(R * t_1))));
    	elseif (t_2 <= -2e+63)
    		tmp = Float64(sqrt(Float64(Float64(t_3 * t_3) - Float64(Float64(fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * Float64(Float64(0.5 + Float64(0.5 * cos(Float64(2.0 * Float64(Float64(fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * t_2)))) * R);
    	else
    		tmp = Float64(t_3 * R);
    	end
    	return tmp
    end
    
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	t_0 = cos((0.5 * (min(phi1, phi2) + max(phi1, phi2)))) ^ 2.0;
    	t_1 = sqrt(t_0);
    	t_2 = min(lambda1, lambda2) - max(lambda1, lambda2);
    	t_3 = max(phi1, phi2) - min(phi1, phi2);
    	tmp = 0.0;
    	if (t_2 <= -5e+132)
    		tmp = -1.0 * (min(lambda1, lambda2) * ((-1.0 * ((R * (max(lambda1, lambda2) * t_0)) / (min(lambda1, lambda2) * t_1))) + (R * t_1)));
    	elseif (t_2 <= -2e+63)
    		tmp = sqrt(((t_3 * t_3) - ((max(lambda1, lambda2) - min(lambda1, lambda2)) * ((0.5 + (0.5 * cos((2.0 * ((max(phi1, phi2) + min(phi1, phi2)) * -0.5))))) * t_2)))) * R;
    	else
    		tmp = t_3 * R;
    	end
    	tmp_2 = tmp;
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Cos[N[(0.5 * N[(N[Min[phi1, phi2], $MachinePrecision] + N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[(N[Min[lambda1, lambda2], $MachinePrecision] - N[Max[lambda1, lambda2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[Max[phi1, phi2], $MachinePrecision] - N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -5e+132], N[(-1.0 * N[(N[Min[lambda1, lambda2], $MachinePrecision] * N[(N[(-1.0 * N[(N[(R * N[(N[Max[lambda1, lambda2], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(N[Min[lambda1, lambda2], $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(R * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, -2e+63], N[(N[Sqrt[N[(N[(t$95$3 * t$95$3), $MachinePrecision] - N[(N[(N[Max[lambda1, lambda2], $MachinePrecision] - N[Min[lambda1, lambda2], $MachinePrecision]), $MachinePrecision] * N[(N[(0.5 + N[(0.5 * N[Cos[N[(2.0 * N[(N[(N[Max[phi1, phi2], $MachinePrecision] + N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(t$95$3 * R), $MachinePrecision]]]]]]]
    
    \begin{array}{l}
    t_0 := {\cos \left(0.5 \cdot \left(\mathsf{min}\left(\phi_1, \phi_2\right) + \mathsf{max}\left(\phi_1, \phi_2\right)\right)\right)}^{2}\\
    t_1 := \sqrt{t\_0}\\
    t_2 := \mathsf{min}\left(\lambda_1, \lambda_2\right) - \mathsf{max}\left(\lambda_1, \lambda_2\right)\\
    t_3 := \mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\\
    \mathbf{if}\;t\_2 \leq -5 \cdot 10^{+132}:\\
    \;\;\;\;-1 \cdot \left(\mathsf{min}\left(\lambda_1, \lambda_2\right) \cdot \left(-1 \cdot \frac{R \cdot \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) \cdot t\_0\right)}{\mathsf{min}\left(\lambda_1, \lambda_2\right) \cdot t\_1} + R \cdot t\_1\right)\right)\\
    
    \mathbf{elif}\;t\_2 \leq -2 \cdot 10^{+63}:\\
    \;\;\;\;\sqrt{t\_3 \cdot t\_3 - \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) - \mathsf{min}\left(\lambda_1, \lambda_2\right)\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\mathsf{max}\left(\phi_1, \phi_2\right) + \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot -0.5\right)\right)\right) \cdot t\_2\right)} \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_3 \cdot R\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if (-.f64 lambda1 lambda2) < -5.0000000000000001e132

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Taylor expanded in phi1 around inf

        \[\leadsto \color{blue}{R \cdot \phi_1} \]
      3. Step-by-step derivation
        1. lower-*.f6417.3%

          \[\leadsto R \cdot \color{blue}{\phi_1} \]
      4. Applied rewrites17.3%

        \[\leadsto \color{blue}{R \cdot \phi_1} \]
      5. Taylor expanded in lambda1 around -inf

        \[\leadsto \color{blue}{-1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot {\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}\right)}{\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}} + R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right)} \]
      6. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto -1 \cdot \color{blue}{\left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot {\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}\right)}{\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}} + R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right)} \]
        2. lower-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \color{blue}{\left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot {\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}\right)}{\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}} + R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)}\right) \]
        3. lower-+.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot {\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}\right)}{\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}} + \color{blue}{R \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}}\right)\right) \]
      7. Applied rewrites28.3%

        \[\leadsto \color{blue}{-1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot {\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}\right)}{\lambda_1 \cdot \sqrt{{\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}} + R \cdot \sqrt{{\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right)} \]

      if -5.0000000000000001e132 < (-.f64 lambda1 lambda2) < -2.0000000000000001e63

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Applied rewrites58.6%

        \[\leadsto \color{blue}{\sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\lambda_2 - \lambda_1\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\phi_2 + \phi_1\right) \cdot -0.5\right)\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R} \]

      if -2.0000000000000001e63 < (-.f64 lambda1 lambda2)

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Taylor expanded in phi2 around inf

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \color{blue}{\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)}\right) \]
        2. lower-+.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + \color{blue}{-1 \cdot \frac{\phi_1}{\phi_2}}\right)\right) \]
        3. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \color{blue}{\frac{\phi_1}{\phi_2}}\right)\right) \]
        4. lower-/.f6427.9%

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\color{blue}{\phi_2}}\right)\right) \]
      4. Applied rewrites27.9%

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \color{blue}{R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
        2. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
        3. lower-*.f6427.9%

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
      6. Applied rewrites29.9%

        \[\leadsto \color{blue}{\left(\phi_2 - \phi_1\right) \cdot R} \]
    3. Recombined 3 regimes into one program.
    4. Add Preprocessing

    Alternative 5: 76.4% accurate, 0.2× speedup?

    \[\begin{array}{l} t_0 := \left(\cos \left(\mathsf{min}\left(\phi_1, \phi_2\right) + \mathsf{max}\left(\phi_1, \phi_2\right)\right) + 1\right) \cdot 0.5\\ t_1 := \sqrt{t\_0}\\ t_2 := \mathsf{min}\left(\lambda_1, \lambda_2\right) - \mathsf{max}\left(\lambda_1, \lambda_2\right)\\ t_3 := \mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\\ \mathbf{if}\;t\_2 \leq -5 \cdot 10^{+132}:\\ \;\;\;\;\left(t\_1 \cdot R - \frac{\left(R \cdot \mathsf{max}\left(\lambda_1, \lambda_2\right)\right) \cdot t\_0}{t\_1 \cdot \mathsf{min}\left(\lambda_1, \lambda_2\right)}\right) \cdot \left(-\mathsf{min}\left(\lambda_1, \lambda_2\right)\right)\\ \mathbf{elif}\;t\_2 \leq -2 \cdot 10^{+63}:\\ \;\;\;\;\sqrt{t\_3 \cdot t\_3 - \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) - \mathsf{min}\left(\lambda_1, \lambda_2\right)\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\mathsf{max}\left(\phi_1, \phi_2\right) + \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot -0.5\right)\right)\right) \cdot t\_2\right)} \cdot R\\ \mathbf{else}:\\ \;\;\;\;t\_3 \cdot R\\ \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
      :precision binary64
      (let* ((t_0
            (* (+ (cos (+ (fmin phi1 phi2) (fmax phi1 phi2))) 1.0) 0.5))
           (t_1 (sqrt t_0))
           (t_2 (- (fmin lambda1 lambda2) (fmax lambda1 lambda2)))
           (t_3 (- (fmax phi1 phi2) (fmin phi1 phi2))))
      (if (<= t_2 -5e+132)
        (*
         (-
          (* t_1 R)
          (/
           (* (* R (fmax lambda1 lambda2)) t_0)
           (* t_1 (fmin lambda1 lambda2))))
         (- (fmin lambda1 lambda2)))
        (if (<= t_2 -2e+63)
          (*
           (sqrt
            (-
             (* t_3 t_3)
             (*
              (- (fmax lambda1 lambda2) (fmin lambda1 lambda2))
              (*
               (+
                0.5
                (*
                 0.5
                 (cos
                  (*
                   2.0
                   (* (+ (fmax phi1 phi2) (fmin phi1 phi2)) -0.5)))))
               t_2))))
           R)
          (* t_3 R)))))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = (cos((fmin(phi1, phi2) + fmax(phi1, phi2))) + 1.0) * 0.5;
    	double t_1 = sqrt(t_0);
    	double t_2 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2);
    	double t_3 = fmax(phi1, phi2) - fmin(phi1, phi2);
    	double tmp;
    	if (t_2 <= -5e+132) {
    		tmp = ((t_1 * R) - (((R * fmax(lambda1, lambda2)) * t_0) / (t_1 * fmin(lambda1, lambda2)))) * -fmin(lambda1, lambda2);
    	} else if (t_2 <= -2e+63) {
    		tmp = sqrt(((t_3 * t_3) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5 + (0.5 * cos((2.0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * t_2)))) * R;
    	} else {
    		tmp = t_3 * R;
    	}
    	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, lambda1, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: t_0
        real(8) :: t_1
        real(8) :: t_2
        real(8) :: t_3
        real(8) :: tmp
        t_0 = (cos((fmin(phi1, phi2) + fmax(phi1, phi2))) + 1.0d0) * 0.5d0
        t_1 = sqrt(t_0)
        t_2 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2)
        t_3 = fmax(phi1, phi2) - fmin(phi1, phi2)
        if (t_2 <= (-5d+132)) then
            tmp = ((t_1 * r) - (((r * fmax(lambda1, lambda2)) * t_0) / (t_1 * fmin(lambda1, lambda2)))) * -fmin(lambda1, lambda2)
        else if (t_2 <= (-2d+63)) then
            tmp = sqrt(((t_3 * t_3) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5d0 + (0.5d0 * cos((2.0d0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * (-0.5d0)))))) * t_2)))) * r
        else
            tmp = t_3 * r
        end if
        code = tmp
    end function
    
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = (Math.cos((fmin(phi1, phi2) + fmax(phi1, phi2))) + 1.0) * 0.5;
    	double t_1 = Math.sqrt(t_0);
    	double t_2 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2);
    	double t_3 = fmax(phi1, phi2) - fmin(phi1, phi2);
    	double tmp;
    	if (t_2 <= -5e+132) {
    		tmp = ((t_1 * R) - (((R * fmax(lambda1, lambda2)) * t_0) / (t_1 * fmin(lambda1, lambda2)))) * -fmin(lambda1, lambda2);
    	} else if (t_2 <= -2e+63) {
    		tmp = Math.sqrt(((t_3 * t_3) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5 + (0.5 * Math.cos((2.0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * t_2)))) * R;
    	} else {
    		tmp = t_3 * R;
    	}
    	return tmp;
    }
    
    def code(R, lambda1, lambda2, phi1, phi2):
    	t_0 = (math.cos((fmin(phi1, phi2) + fmax(phi1, phi2))) + 1.0) * 0.5
    	t_1 = math.sqrt(t_0)
    	t_2 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2)
    	t_3 = fmax(phi1, phi2) - fmin(phi1, phi2)
    	tmp = 0
    	if t_2 <= -5e+132:
    		tmp = ((t_1 * R) - (((R * fmax(lambda1, lambda2)) * t_0) / (t_1 * fmin(lambda1, lambda2)))) * -fmin(lambda1, lambda2)
    	elif t_2 <= -2e+63:
    		tmp = math.sqrt(((t_3 * t_3) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5 + (0.5 * math.cos((2.0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * t_2)))) * R
    	else:
    		tmp = t_3 * R
    	return tmp
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	t_0 = Float64(Float64(cos(Float64(fmin(phi1, phi2) + fmax(phi1, phi2))) + 1.0) * 0.5)
    	t_1 = sqrt(t_0)
    	t_2 = Float64(fmin(lambda1, lambda2) - fmax(lambda1, lambda2))
    	t_3 = Float64(fmax(phi1, phi2) - fmin(phi1, phi2))
    	tmp = 0.0
    	if (t_2 <= -5e+132)
    		tmp = Float64(Float64(Float64(t_1 * R) - Float64(Float64(Float64(R * fmax(lambda1, lambda2)) * t_0) / Float64(t_1 * fmin(lambda1, lambda2)))) * Float64(-fmin(lambda1, lambda2)));
    	elseif (t_2 <= -2e+63)
    		tmp = Float64(sqrt(Float64(Float64(t_3 * t_3) - Float64(Float64(fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * Float64(Float64(0.5 + Float64(0.5 * cos(Float64(2.0 * Float64(Float64(fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * t_2)))) * R);
    	else
    		tmp = Float64(t_3 * R);
    	end
    	return tmp
    end
    
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	t_0 = (cos((min(phi1, phi2) + max(phi1, phi2))) + 1.0) * 0.5;
    	t_1 = sqrt(t_0);
    	t_2 = min(lambda1, lambda2) - max(lambda1, lambda2);
    	t_3 = max(phi1, phi2) - min(phi1, phi2);
    	tmp = 0.0;
    	if (t_2 <= -5e+132)
    		tmp = ((t_1 * R) - (((R * max(lambda1, lambda2)) * t_0) / (t_1 * min(lambda1, lambda2)))) * -min(lambda1, lambda2);
    	elseif (t_2 <= -2e+63)
    		tmp = sqrt(((t_3 * t_3) - ((max(lambda1, lambda2) - min(lambda1, lambda2)) * ((0.5 + (0.5 * cos((2.0 * ((max(phi1, phi2) + min(phi1, phi2)) * -0.5))))) * t_2)))) * R;
    	else
    		tmp = t_3 * R;
    	end
    	tmp_2 = tmp;
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(N[Cos[N[(N[Min[phi1, phi2], $MachinePrecision] + N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision] * 0.5), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[(N[Min[lambda1, lambda2], $MachinePrecision] - N[Max[lambda1, lambda2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[Max[phi1, phi2], $MachinePrecision] - N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -5e+132], N[(N[(N[(t$95$1 * R), $MachinePrecision] - N[(N[(N[(R * N[Max[lambda1, lambda2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] / N[(t$95$1 * N[Min[lambda1, lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * (-N[Min[lambda1, lambda2], $MachinePrecision])), $MachinePrecision], If[LessEqual[t$95$2, -2e+63], N[(N[Sqrt[N[(N[(t$95$3 * t$95$3), $MachinePrecision] - N[(N[(N[Max[lambda1, lambda2], $MachinePrecision] - N[Min[lambda1, lambda2], $MachinePrecision]), $MachinePrecision] * N[(N[(0.5 + N[(0.5 * N[Cos[N[(2.0 * N[(N[(N[Max[phi1, phi2], $MachinePrecision] + N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(t$95$3 * R), $MachinePrecision]]]]]]]
    
    \begin{array}{l}
    t_0 := \left(\cos \left(\mathsf{min}\left(\phi_1, \phi_2\right) + \mathsf{max}\left(\phi_1, \phi_2\right)\right) + 1\right) \cdot 0.5\\
    t_1 := \sqrt{t\_0}\\
    t_2 := \mathsf{min}\left(\lambda_1, \lambda_2\right) - \mathsf{max}\left(\lambda_1, \lambda_2\right)\\
    t_3 := \mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\\
    \mathbf{if}\;t\_2 \leq -5 \cdot 10^{+132}:\\
    \;\;\;\;\left(t\_1 \cdot R - \frac{\left(R \cdot \mathsf{max}\left(\lambda_1, \lambda_2\right)\right) \cdot t\_0}{t\_1 \cdot \mathsf{min}\left(\lambda_1, \lambda_2\right)}\right) \cdot \left(-\mathsf{min}\left(\lambda_1, \lambda_2\right)\right)\\
    
    \mathbf{elif}\;t\_2 \leq -2 \cdot 10^{+63}:\\
    \;\;\;\;\sqrt{t\_3 \cdot t\_3 - \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) - \mathsf{min}\left(\lambda_1, \lambda_2\right)\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\mathsf{max}\left(\phi_1, \phi_2\right) + \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot -0.5\right)\right)\right) \cdot t\_2\right)} \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_3 \cdot R\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if (-.f64 lambda1 lambda2) < -5.0000000000000001e132

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Applied rewrites58.6%

        \[\leadsto \color{blue}{\sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\lambda_2 - \lambda_1\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\phi_2 + \phi_1\right) \cdot -0.5\right)\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R} \]
      3. Taylor expanded in lambda1 around -inf

        \[\leadsto \color{blue}{-1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{\mathsf{neg}\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}} + R \cdot \sqrt{\mathsf{neg}\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}\right)\right)} \]
      4. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto -1 \cdot \color{blue}{\left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{\mathsf{neg}\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}} + R \cdot \sqrt{\mathsf{neg}\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}\right)\right)} \]
        2. lower-*.f64N/A

          \[\leadsto -1 \cdot \left(\lambda_1 \cdot \color{blue}{\left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{\mathsf{neg}\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}} + R \cdot \sqrt{\mathsf{neg}\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}\right)}\right) \]
      5. Applied rewrites28.3%

        \[\leadsto \color{blue}{-1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{R \cdot \left(\lambda_2 \cdot \left(0.5 + 0.5 \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}{\lambda_1 \cdot \sqrt{--1 \cdot \left(0.5 + 0.5 \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}} + R \cdot \sqrt{--1 \cdot \left(0.5 + 0.5 \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)\right)} \]
      6. Applied rewrites28.3%

        \[\leadsto \left(\sqrt{\left(\cos \left(\phi_1 + \phi_2\right) + 1\right) \cdot 0.5} \cdot R - \frac{\left(R \cdot \lambda_2\right) \cdot \left(\left(\cos \left(\phi_1 + \phi_2\right) + 1\right) \cdot 0.5\right)}{\sqrt{\left(\cos \left(\phi_1 + \phi_2\right) + 1\right) \cdot 0.5} \cdot \lambda_1}\right) \cdot \color{blue}{\left(-\lambda_1\right)} \]

      if -5.0000000000000001e132 < (-.f64 lambda1 lambda2) < -2.0000000000000001e63

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Applied rewrites58.6%

        \[\leadsto \color{blue}{\sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\lambda_2 - \lambda_1\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\phi_2 + \phi_1\right) \cdot -0.5\right)\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R} \]

      if -2.0000000000000001e63 < (-.f64 lambda1 lambda2)

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Taylor expanded in phi2 around inf

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \color{blue}{\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)}\right) \]
        2. lower-+.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + \color{blue}{-1 \cdot \frac{\phi_1}{\phi_2}}\right)\right) \]
        3. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \color{blue}{\frac{\phi_1}{\phi_2}}\right)\right) \]
        4. lower-/.f6427.9%

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\color{blue}{\phi_2}}\right)\right) \]
      4. Applied rewrites27.9%

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \color{blue}{R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
        2. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
        3. lower-*.f6427.9%

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
      6. Applied rewrites29.9%

        \[\leadsto \color{blue}{\left(\phi_2 - \phi_1\right) \cdot R} \]
    3. Recombined 3 regimes into one program.
    4. Add Preprocessing

    Alternative 6: 75.1% accurate, 0.2× speedup?

    \[\begin{array}{l} t_0 := -0.5 \cdot \left(\mathsf{min}\left(\phi_1, \phi_2\right) + \mathsf{max}\left(\phi_1, \phi_2\right)\right)\\ t_1 := \left|\cos t\_0\right|\\ t_2 := \mathsf{min}\left(\lambda_1, \lambda_2\right) - \mathsf{max}\left(\lambda_1, \lambda_2\right)\\ t_3 := \mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\\ \mathbf{if}\;t\_2 \leq -1 \cdot 10^{+167}:\\ \;\;\;\;\left(\left(t\_1 - \frac{0.5 + 0.5 \cdot \cos \left(2 \cdot t\_0\right)}{t\_1 \cdot \mathsf{max}\left(\lambda_1, \lambda_2\right)} \cdot \mathsf{min}\left(\lambda_1, \lambda_2\right)\right) \cdot \mathsf{max}\left(\lambda_1, \lambda_2\right)\right) \cdot R\\ \mathbf{elif}\;t\_2 \leq -2 \cdot 10^{+63}:\\ \;\;\;\;\sqrt{t\_3 \cdot t\_3 - \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) - \mathsf{min}\left(\lambda_1, \lambda_2\right)\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\mathsf{max}\left(\phi_1, \phi_2\right) + \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot -0.5\right)\right)\right) \cdot t\_2\right)} \cdot R\\ \mathbf{else}:\\ \;\;\;\;t\_3 \cdot R\\ \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
      :precision binary64
      (let* ((t_0 (* -0.5 (+ (fmin phi1 phi2) (fmax phi1 phi2))))
           (t_1 (fabs (cos t_0)))
           (t_2 (- (fmin lambda1 lambda2) (fmax lambda1 lambda2)))
           (t_3 (- (fmax phi1 phi2) (fmin phi1 phi2))))
      (if (<= t_2 -1e+167)
        (*
         (*
          (-
           t_1
           (*
            (/
             (+ 0.5 (* 0.5 (cos (* 2.0 t_0))))
             (* t_1 (fmax lambda1 lambda2)))
            (fmin lambda1 lambda2)))
          (fmax lambda1 lambda2))
         R)
        (if (<= t_2 -2e+63)
          (*
           (sqrt
            (-
             (* t_3 t_3)
             (*
              (- (fmax lambda1 lambda2) (fmin lambda1 lambda2))
              (*
               (+
                0.5
                (*
                 0.5
                 (cos
                  (*
                   2.0
                   (* (+ (fmax phi1 phi2) (fmin phi1 phi2)) -0.5)))))
               t_2))))
           R)
          (* t_3 R)))))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = -0.5 * (fmin(phi1, phi2) + fmax(phi1, phi2));
    	double t_1 = fabs(cos(t_0));
    	double t_2 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2);
    	double t_3 = fmax(phi1, phi2) - fmin(phi1, phi2);
    	double tmp;
    	if (t_2 <= -1e+167) {
    		tmp = ((t_1 - (((0.5 + (0.5 * cos((2.0 * t_0)))) / (t_1 * fmax(lambda1, lambda2))) * fmin(lambda1, lambda2))) * fmax(lambda1, lambda2)) * R;
    	} else if (t_2 <= -2e+63) {
    		tmp = sqrt(((t_3 * t_3) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5 + (0.5 * cos((2.0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * t_2)))) * R;
    	} else {
    		tmp = t_3 * R;
    	}
    	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, lambda1, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: t_0
        real(8) :: t_1
        real(8) :: t_2
        real(8) :: t_3
        real(8) :: tmp
        t_0 = (-0.5d0) * (fmin(phi1, phi2) + fmax(phi1, phi2))
        t_1 = abs(cos(t_0))
        t_2 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2)
        t_3 = fmax(phi1, phi2) - fmin(phi1, phi2)
        if (t_2 <= (-1d+167)) then
            tmp = ((t_1 - (((0.5d0 + (0.5d0 * cos((2.0d0 * t_0)))) / (t_1 * fmax(lambda1, lambda2))) * fmin(lambda1, lambda2))) * fmax(lambda1, lambda2)) * r
        else if (t_2 <= (-2d+63)) then
            tmp = sqrt(((t_3 * t_3) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5d0 + (0.5d0 * cos((2.0d0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * (-0.5d0)))))) * t_2)))) * r
        else
            tmp = t_3 * r
        end if
        code = tmp
    end function
    
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = -0.5 * (fmin(phi1, phi2) + fmax(phi1, phi2));
    	double t_1 = Math.abs(Math.cos(t_0));
    	double t_2 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2);
    	double t_3 = fmax(phi1, phi2) - fmin(phi1, phi2);
    	double tmp;
    	if (t_2 <= -1e+167) {
    		tmp = ((t_1 - (((0.5 + (0.5 * Math.cos((2.0 * t_0)))) / (t_1 * fmax(lambda1, lambda2))) * fmin(lambda1, lambda2))) * fmax(lambda1, lambda2)) * R;
    	} else if (t_2 <= -2e+63) {
    		tmp = Math.sqrt(((t_3 * t_3) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5 + (0.5 * Math.cos((2.0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * t_2)))) * R;
    	} else {
    		tmp = t_3 * R;
    	}
    	return tmp;
    }
    
    def code(R, lambda1, lambda2, phi1, phi2):
    	t_0 = -0.5 * (fmin(phi1, phi2) + fmax(phi1, phi2))
    	t_1 = math.fabs(math.cos(t_0))
    	t_2 = fmin(lambda1, lambda2) - fmax(lambda1, lambda2)
    	t_3 = fmax(phi1, phi2) - fmin(phi1, phi2)
    	tmp = 0
    	if t_2 <= -1e+167:
    		tmp = ((t_1 - (((0.5 + (0.5 * math.cos((2.0 * t_0)))) / (t_1 * fmax(lambda1, lambda2))) * fmin(lambda1, lambda2))) * fmax(lambda1, lambda2)) * R
    	elif t_2 <= -2e+63:
    		tmp = math.sqrt(((t_3 * t_3) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5 + (0.5 * math.cos((2.0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * t_2)))) * R
    	else:
    		tmp = t_3 * R
    	return tmp
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	t_0 = Float64(-0.5 * Float64(fmin(phi1, phi2) + fmax(phi1, phi2)))
    	t_1 = abs(cos(t_0))
    	t_2 = Float64(fmin(lambda1, lambda2) - fmax(lambda1, lambda2))
    	t_3 = Float64(fmax(phi1, phi2) - fmin(phi1, phi2))
    	tmp = 0.0
    	if (t_2 <= -1e+167)
    		tmp = Float64(Float64(Float64(t_1 - Float64(Float64(Float64(0.5 + Float64(0.5 * cos(Float64(2.0 * t_0)))) / Float64(t_1 * fmax(lambda1, lambda2))) * fmin(lambda1, lambda2))) * fmax(lambda1, lambda2)) * R);
    	elseif (t_2 <= -2e+63)
    		tmp = Float64(sqrt(Float64(Float64(t_3 * t_3) - Float64(Float64(fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * Float64(Float64(0.5 + Float64(0.5 * cos(Float64(2.0 * Float64(Float64(fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * t_2)))) * R);
    	else
    		tmp = Float64(t_3 * R);
    	end
    	return tmp
    end
    
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	t_0 = -0.5 * (min(phi1, phi2) + max(phi1, phi2));
    	t_1 = abs(cos(t_0));
    	t_2 = min(lambda1, lambda2) - max(lambda1, lambda2);
    	t_3 = max(phi1, phi2) - min(phi1, phi2);
    	tmp = 0.0;
    	if (t_2 <= -1e+167)
    		tmp = ((t_1 - (((0.5 + (0.5 * cos((2.0 * t_0)))) / (t_1 * max(lambda1, lambda2))) * min(lambda1, lambda2))) * max(lambda1, lambda2)) * R;
    	elseif (t_2 <= -2e+63)
    		tmp = sqrt(((t_3 * t_3) - ((max(lambda1, lambda2) - min(lambda1, lambda2)) * ((0.5 + (0.5 * cos((2.0 * ((max(phi1, phi2) + min(phi1, phi2)) * -0.5))))) * t_2)))) * R;
    	else
    		tmp = t_3 * R;
    	end
    	tmp_2 = tmp;
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(-0.5 * N[(N[Min[phi1, phi2], $MachinePrecision] + N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[Cos[t$95$0], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Min[lambda1, lambda2], $MachinePrecision] - N[Max[lambda1, lambda2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[Max[phi1, phi2], $MachinePrecision] - N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1e+167], N[(N[(N[(t$95$1 - N[(N[(N[(0.5 + N[(0.5 * N[Cos[N[(2.0 * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$1 * N[Max[lambda1, lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Min[lambda1, lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Max[lambda1, lambda2], $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision], If[LessEqual[t$95$2, -2e+63], N[(N[Sqrt[N[(N[(t$95$3 * t$95$3), $MachinePrecision] - N[(N[(N[Max[lambda1, lambda2], $MachinePrecision] - N[Min[lambda1, lambda2], $MachinePrecision]), $MachinePrecision] * N[(N[(0.5 + N[(0.5 * N[Cos[N[(2.0 * N[(N[(N[Max[phi1, phi2], $MachinePrecision] + N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(t$95$3 * R), $MachinePrecision]]]]]]]
    
    \begin{array}{l}
    t_0 := -0.5 \cdot \left(\mathsf{min}\left(\phi_1, \phi_2\right) + \mathsf{max}\left(\phi_1, \phi_2\right)\right)\\
    t_1 := \left|\cos t\_0\right|\\
    t_2 := \mathsf{min}\left(\lambda_1, \lambda_2\right) - \mathsf{max}\left(\lambda_1, \lambda_2\right)\\
    t_3 := \mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\\
    \mathbf{if}\;t\_2 \leq -1 \cdot 10^{+167}:\\
    \;\;\;\;\left(\left(t\_1 - \frac{0.5 + 0.5 \cdot \cos \left(2 \cdot t\_0\right)}{t\_1 \cdot \mathsf{max}\left(\lambda_1, \lambda_2\right)} \cdot \mathsf{min}\left(\lambda_1, \lambda_2\right)\right) \cdot \mathsf{max}\left(\lambda_1, \lambda_2\right)\right) \cdot R\\
    
    \mathbf{elif}\;t\_2 \leq -2 \cdot 10^{+63}:\\
    \;\;\;\;\sqrt{t\_3 \cdot t\_3 - \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) - \mathsf{min}\left(\lambda_1, \lambda_2\right)\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\mathsf{max}\left(\phi_1, \phi_2\right) + \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot -0.5\right)\right)\right) \cdot t\_2\right)} \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_3 \cdot R\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if (-.f64 lambda1 lambda2) < -1e167

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Taylor expanded in lambda2 around inf

        \[\leadsto R \cdot \color{blue}{\left(\lambda_2 \cdot \left(\sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}} + -1 \cdot \frac{\lambda_1 \cdot {\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}{\lambda_2 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}}\right)\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto R \cdot \left(\lambda_2 \cdot \color{blue}{\left(\sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}} + -1 \cdot \frac{\lambda_1 \cdot {\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}{\lambda_2 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}}\right)}\right) \]
        2. lower-+.f64N/A

          \[\leadsto R \cdot \left(\lambda_2 \cdot \left(\sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}} + \color{blue}{-1 \cdot \frac{\lambda_1 \cdot {\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}{\lambda_2 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}}}\right)\right) \]
      4. Applied rewrites26.6%

        \[\leadsto R \cdot \color{blue}{\left(\lambda_2 \cdot \left(\sqrt{{\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}} + -1 \cdot \frac{\lambda_1 \cdot {\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}{\lambda_2 \cdot \sqrt{{\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}}\right)\right)} \]
      5. Applied rewrites26.6%

        \[\leadsto \color{blue}{\left(\left(\left|\cos \left(-0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right| - \frac{0.5 + 0.5 \cdot \cos \left(2 \cdot \left(-0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}{\left|\cos \left(-0.5 \cdot \left(\phi_1 + \phi_2\right)\right)\right| \cdot \lambda_2} \cdot \lambda_1\right) \cdot \lambda_2\right) \cdot R} \]

      if -1e167 < (-.f64 lambda1 lambda2) < -2.0000000000000001e63

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Applied rewrites58.6%

        \[\leadsto \color{blue}{\sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\lambda_2 - \lambda_1\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\phi_2 + \phi_1\right) \cdot -0.5\right)\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R} \]

      if -2.0000000000000001e63 < (-.f64 lambda1 lambda2)

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Taylor expanded in phi2 around inf

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \color{blue}{\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)}\right) \]
        2. lower-+.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + \color{blue}{-1 \cdot \frac{\phi_1}{\phi_2}}\right)\right) \]
        3. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \color{blue}{\frac{\phi_1}{\phi_2}}\right)\right) \]
        4. lower-/.f6427.9%

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\color{blue}{\phi_2}}\right)\right) \]
      4. Applied rewrites27.9%

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \color{blue}{R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
        2. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
        3. lower-*.f6427.9%

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
      6. Applied rewrites29.9%

        \[\leadsto \color{blue}{\left(\phi_2 - \phi_1\right) \cdot R} \]
    3. Recombined 3 regimes into one program.
    4. Add Preprocessing

    Alternative 7: 70.6% accurate, 0.2× speedup?

    \[\begin{array}{l} t_0 := \mathsf{min}\left(\phi_1, \phi_2\right) + \mathsf{max}\left(\phi_1, \phi_2\right)\\ t_1 := \mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\\ \mathbf{if}\;\mathsf{min}\left(\lambda_1, \lambda_2\right) \leq -7.5 \cdot 10^{+132}:\\ \;\;\;\;\left(\left(-\mathsf{min}\left(\lambda_1, \lambda_2\right)\right) \cdot \left|\cos \left(t\_0 \cdot -0.5\right)\right|\right) \cdot R\\ \mathbf{elif}\;\mathsf{min}\left(\lambda_1, \lambda_2\right) \leq -2.5 \cdot 10^{+63}:\\ \;\;\;\;\sqrt{t\_1 \cdot t\_1 - \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) - \mathsf{min}\left(\lambda_1, \lambda_2\right)\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\mathsf{max}\left(\phi_1, \phi_2\right) + \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot -0.5\right)\right)\right) \cdot \left(\mathsf{min}\left(\lambda_1, \lambda_2\right) - \mathsf{max}\left(\lambda_1, \lambda_2\right)\right)\right)} \cdot R\\ \mathbf{elif}\;\mathsf{min}\left(\lambda_1, \lambda_2\right) \leq 5.7 \cdot 10^{-62}:\\ \;\;\;\;t\_1 \cdot R\\ \mathbf{else}:\\ \;\;\;\;\left(\mathsf{max}\left(\lambda_1, \lambda_2\right) \cdot \sqrt{--1 \cdot \left(0.5 + 0.5 \cdot \cos \left(-1 \cdot t\_0\right)\right)}\right) \cdot R\\ \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
      :precision binary64
      (let* ((t_0 (+ (fmin phi1 phi2) (fmax phi1 phi2)))
           (t_1 (- (fmax phi1 phi2) (fmin phi1 phi2))))
      (if (<= (fmin lambda1 lambda2) -7.5e+132)
        (* (* (- (fmin lambda1 lambda2)) (fabs (cos (* t_0 -0.5)))) R)
        (if (<= (fmin lambda1 lambda2) -2.5e+63)
          (*
           (sqrt
            (-
             (* t_1 t_1)
             (*
              (- (fmax lambda1 lambda2) (fmin lambda1 lambda2))
              (*
               (+
                0.5
                (*
                 0.5
                 (cos
                  (*
                   2.0
                   (* (+ (fmax phi1 phi2) (fmin phi1 phi2)) -0.5)))))
               (- (fmin lambda1 lambda2) (fmax lambda1 lambda2))))))
           R)
          (if (<= (fmin lambda1 lambda2) 5.7e-62)
            (* t_1 R)
            (*
             (*
              (fmax lambda1 lambda2)
              (sqrt (- (* -1.0 (+ 0.5 (* 0.5 (cos (* -1.0 t_0))))))))
             R))))))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = fmin(phi1, phi2) + fmax(phi1, phi2);
    	double t_1 = fmax(phi1, phi2) - fmin(phi1, phi2);
    	double tmp;
    	if (fmin(lambda1, lambda2) <= -7.5e+132) {
    		tmp = (-fmin(lambda1, lambda2) * fabs(cos((t_0 * -0.5)))) * R;
    	} else if (fmin(lambda1, lambda2) <= -2.5e+63) {
    		tmp = sqrt(((t_1 * t_1) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5 + (0.5 * cos((2.0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * (fmin(lambda1, lambda2) - fmax(lambda1, lambda2)))))) * R;
    	} else if (fmin(lambda1, lambda2) <= 5.7e-62) {
    		tmp = t_1 * R;
    	} else {
    		tmp = (fmax(lambda1, lambda2) * sqrt(-(-1.0 * (0.5 + (0.5 * cos((-1.0 * t_0))))))) * R;
    	}
    	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, lambda1, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: t_0
        real(8) :: t_1
        real(8) :: tmp
        t_0 = fmin(phi1, phi2) + fmax(phi1, phi2)
        t_1 = fmax(phi1, phi2) - fmin(phi1, phi2)
        if (fmin(lambda1, lambda2) <= (-7.5d+132)) then
            tmp = (-fmin(lambda1, lambda2) * abs(cos((t_0 * (-0.5d0))))) * r
        else if (fmin(lambda1, lambda2) <= (-2.5d+63)) then
            tmp = sqrt(((t_1 * t_1) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5d0 + (0.5d0 * cos((2.0d0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * (-0.5d0)))))) * (fmin(lambda1, lambda2) - fmax(lambda1, lambda2)))))) * r
        else if (fmin(lambda1, lambda2) <= 5.7d-62) then
            tmp = t_1 * r
        else
            tmp = (fmax(lambda1, lambda2) * sqrt(-((-1.0d0) * (0.5d0 + (0.5d0 * cos(((-1.0d0) * t_0))))))) * r
        end if
        code = tmp
    end function
    
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = fmin(phi1, phi2) + fmax(phi1, phi2);
    	double t_1 = fmax(phi1, phi2) - fmin(phi1, phi2);
    	double tmp;
    	if (fmin(lambda1, lambda2) <= -7.5e+132) {
    		tmp = (-fmin(lambda1, lambda2) * Math.abs(Math.cos((t_0 * -0.5)))) * R;
    	} else if (fmin(lambda1, lambda2) <= -2.5e+63) {
    		tmp = Math.sqrt(((t_1 * t_1) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5 + (0.5 * Math.cos((2.0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * (fmin(lambda1, lambda2) - fmax(lambda1, lambda2)))))) * R;
    	} else if (fmin(lambda1, lambda2) <= 5.7e-62) {
    		tmp = t_1 * R;
    	} else {
    		tmp = (fmax(lambda1, lambda2) * Math.sqrt(-(-1.0 * (0.5 + (0.5 * Math.cos((-1.0 * t_0))))))) * R;
    	}
    	return tmp;
    }
    
    def code(R, lambda1, lambda2, phi1, phi2):
    	t_0 = fmin(phi1, phi2) + fmax(phi1, phi2)
    	t_1 = fmax(phi1, phi2) - fmin(phi1, phi2)
    	tmp = 0
    	if fmin(lambda1, lambda2) <= -7.5e+132:
    		tmp = (-fmin(lambda1, lambda2) * math.fabs(math.cos((t_0 * -0.5)))) * R
    	elif fmin(lambda1, lambda2) <= -2.5e+63:
    		tmp = math.sqrt(((t_1 * t_1) - ((fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * ((0.5 + (0.5 * math.cos((2.0 * ((fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * (fmin(lambda1, lambda2) - fmax(lambda1, lambda2)))))) * R
    	elif fmin(lambda1, lambda2) <= 5.7e-62:
    		tmp = t_1 * R
    	else:
    		tmp = (fmax(lambda1, lambda2) * math.sqrt(-(-1.0 * (0.5 + (0.5 * math.cos((-1.0 * t_0))))))) * R
    	return tmp
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	t_0 = Float64(fmin(phi1, phi2) + fmax(phi1, phi2))
    	t_1 = Float64(fmax(phi1, phi2) - fmin(phi1, phi2))
    	tmp = 0.0
    	if (fmin(lambda1, lambda2) <= -7.5e+132)
    		tmp = Float64(Float64(Float64(-fmin(lambda1, lambda2)) * abs(cos(Float64(t_0 * -0.5)))) * R);
    	elseif (fmin(lambda1, lambda2) <= -2.5e+63)
    		tmp = Float64(sqrt(Float64(Float64(t_1 * t_1) - Float64(Float64(fmax(lambda1, lambda2) - fmin(lambda1, lambda2)) * Float64(Float64(0.5 + Float64(0.5 * cos(Float64(2.0 * Float64(Float64(fmax(phi1, phi2) + fmin(phi1, phi2)) * -0.5))))) * Float64(fmin(lambda1, lambda2) - fmax(lambda1, lambda2)))))) * R);
    	elseif (fmin(lambda1, lambda2) <= 5.7e-62)
    		tmp = Float64(t_1 * R);
    	else
    		tmp = Float64(Float64(fmax(lambda1, lambda2) * sqrt(Float64(-Float64(-1.0 * Float64(0.5 + Float64(0.5 * cos(Float64(-1.0 * t_0)))))))) * R);
    	end
    	return tmp
    end
    
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	t_0 = min(phi1, phi2) + max(phi1, phi2);
    	t_1 = max(phi1, phi2) - min(phi1, phi2);
    	tmp = 0.0;
    	if (min(lambda1, lambda2) <= -7.5e+132)
    		tmp = (-min(lambda1, lambda2) * abs(cos((t_0 * -0.5)))) * R;
    	elseif (min(lambda1, lambda2) <= -2.5e+63)
    		tmp = sqrt(((t_1 * t_1) - ((max(lambda1, lambda2) - min(lambda1, lambda2)) * ((0.5 + (0.5 * cos((2.0 * ((max(phi1, phi2) + min(phi1, phi2)) * -0.5))))) * (min(lambda1, lambda2) - max(lambda1, lambda2)))))) * R;
    	elseif (min(lambda1, lambda2) <= 5.7e-62)
    		tmp = t_1 * R;
    	else
    		tmp = (max(lambda1, lambda2) * sqrt(-(-1.0 * (0.5 + (0.5 * cos((-1.0 * t_0))))))) * R;
    	end
    	tmp_2 = tmp;
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Min[phi1, phi2], $MachinePrecision] + N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Max[phi1, phi2], $MachinePrecision] - N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Min[lambda1, lambda2], $MachinePrecision], -7.5e+132], N[(N[((-N[Min[lambda1, lambda2], $MachinePrecision]) * N[Abs[N[Cos[N[(t$95$0 * -0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision], If[LessEqual[N[Min[lambda1, lambda2], $MachinePrecision], -2.5e+63], N[(N[Sqrt[N[(N[(t$95$1 * t$95$1), $MachinePrecision] - N[(N[(N[Max[lambda1, lambda2], $MachinePrecision] - N[Min[lambda1, lambda2], $MachinePrecision]), $MachinePrecision] * N[(N[(0.5 + N[(0.5 * N[Cos[N[(2.0 * N[(N[(N[Max[phi1, phi2], $MachinePrecision] + N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Min[lambda1, lambda2], $MachinePrecision] - N[Max[lambda1, lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[N[Min[lambda1, lambda2], $MachinePrecision], 5.7e-62], N[(t$95$1 * R), $MachinePrecision], N[(N[(N[Max[lambda1, lambda2], $MachinePrecision] * N[Sqrt[(-N[(-1.0 * N[(0.5 + N[(0.5 * N[Cos[N[(-1.0 * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision]]]]]]
    
    \begin{array}{l}
    t_0 := \mathsf{min}\left(\phi_1, \phi_2\right) + \mathsf{max}\left(\phi_1, \phi_2\right)\\
    t_1 := \mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\\
    \mathbf{if}\;\mathsf{min}\left(\lambda_1, \lambda_2\right) \leq -7.5 \cdot 10^{+132}:\\
    \;\;\;\;\left(\left(-\mathsf{min}\left(\lambda_1, \lambda_2\right)\right) \cdot \left|\cos \left(t\_0 \cdot -0.5\right)\right|\right) \cdot R\\
    
    \mathbf{elif}\;\mathsf{min}\left(\lambda_1, \lambda_2\right) \leq -2.5 \cdot 10^{+63}:\\
    \;\;\;\;\sqrt{t\_1 \cdot t\_1 - \left(\mathsf{max}\left(\lambda_1, \lambda_2\right) - \mathsf{min}\left(\lambda_1, \lambda_2\right)\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\mathsf{max}\left(\phi_1, \phi_2\right) + \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot -0.5\right)\right)\right) \cdot \left(\mathsf{min}\left(\lambda_1, \lambda_2\right) - \mathsf{max}\left(\lambda_1, \lambda_2\right)\right)\right)} \cdot R\\
    
    \mathbf{elif}\;\mathsf{min}\left(\lambda_1, \lambda_2\right) \leq 5.7 \cdot 10^{-62}:\\
    \;\;\;\;t\_1 \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;\left(\mathsf{max}\left(\lambda_1, \lambda_2\right) \cdot \sqrt{--1 \cdot \left(0.5 + 0.5 \cdot \cos \left(-1 \cdot t\_0\right)\right)}\right) \cdot R\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 4 regimes
    2. if lambda1 < -7.5000000000000002e132

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Taylor expanded in phi2 around inf

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \color{blue}{\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)}\right) \]
        2. lower-+.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + \color{blue}{-1 \cdot \frac{\phi_1}{\phi_2}}\right)\right) \]
        3. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \color{blue}{\frac{\phi_1}{\phi_2}}\right)\right) \]
        4. lower-/.f6427.9%

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\color{blue}{\phi_2}}\right)\right) \]
      4. Applied rewrites27.9%

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      5. Taylor expanded in lambda1 around -inf

        \[\leadsto R \cdot \color{blue}{\left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right)} \]
      6. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto R \cdot \left(-1 \cdot \color{blue}{\left(\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)}\right) \]
        2. lower-*.f64N/A

          \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}}\right)\right) \]
        3. lower-sqrt.f64N/A

          \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right) \]
        4. lower-pow.f64N/A

          \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right) \]
        5. lower-cos.f64N/A

          \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right) \]
        6. lower-*.f64N/A

          \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right) \]
        7. lower-+.f6417.4%

          \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right) \]
      7. Applied rewrites17.4%

        \[\leadsto R \cdot \color{blue}{\left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right)} \]
      8. Applied rewrites17.4%

        \[\leadsto \color{blue}{\left(\left(-\lambda_1\right) \cdot \left|\cos \left(\left(\phi_1 + \phi_2\right) \cdot -0.5\right)\right|\right) \cdot R} \]

      if -7.5000000000000002e132 < lambda1 < -2.5000000000000001e63

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Applied rewrites58.6%

        \[\leadsto \color{blue}{\sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\lambda_2 - \lambda_1\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\phi_2 + \phi_1\right) \cdot -0.5\right)\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R} \]

      if -2.5000000000000001e63 < lambda1 < 5.6999999999999999e-62

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Taylor expanded in phi2 around inf

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \color{blue}{\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)}\right) \]
        2. lower-+.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + \color{blue}{-1 \cdot \frac{\phi_1}{\phi_2}}\right)\right) \]
        3. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \color{blue}{\frac{\phi_1}{\phi_2}}\right)\right) \]
        4. lower-/.f6427.9%

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\color{blue}{\phi_2}}\right)\right) \]
      4. Applied rewrites27.9%

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \color{blue}{R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
        2. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
        3. lower-*.f6427.9%

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
      6. Applied rewrites29.9%

        \[\leadsto \color{blue}{\left(\phi_2 - \phi_1\right) \cdot R} \]

      if 5.6999999999999999e-62 < lambda1

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Applied rewrites58.6%

        \[\leadsto \color{blue}{\sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\lambda_2 - \lambda_1\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\phi_2 + \phi_1\right) \cdot -0.5\right)\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R} \]
      3. Taylor expanded in lambda2 around inf

        \[\leadsto \color{blue}{\left(\lambda_2 \cdot \sqrt{\mathsf{neg}\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}\right)} \cdot R \]
      4. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto \left(\lambda_2 \cdot \color{blue}{\sqrt{\mathsf{neg}\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}}\right) \cdot R \]
        2. lower-sqrt.f64N/A

          \[\leadsto \left(\lambda_2 \cdot \sqrt{\mathsf{neg}\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}\right) \cdot R \]
        3. lower-neg.f64N/A

          \[\leadsto \left(\lambda_2 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right) \cdot R \]
        4. lower-*.f64N/A

          \[\leadsto \left(\lambda_2 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right) \cdot R \]
        5. lower-+.f64N/A

          \[\leadsto \left(\lambda_2 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right) \cdot R \]
        6. lower-*.f64N/A

          \[\leadsto \left(\lambda_2 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right) \cdot R \]
        7. lower-cos.f64N/A

          \[\leadsto \left(\lambda_2 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right) \cdot R \]
        8. lower-*.f64N/A

          \[\leadsto \left(\lambda_2 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right) \cdot R \]
        9. lower-+.f6416.9%

          \[\leadsto \left(\lambda_2 \cdot \sqrt{--1 \cdot \left(0.5 + 0.5 \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right) \cdot R \]
      5. Applied rewrites16.9%

        \[\leadsto \color{blue}{\left(\lambda_2 \cdot \sqrt{--1 \cdot \left(0.5 + 0.5 \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)} \cdot R \]
    3. Recombined 4 regimes into one program.
    4. Add Preprocessing

    Alternative 8: 68.5% accurate, 0.4× speedup?

    \[\begin{array}{l} t_0 := \mathsf{min}\left(\phi_1, \phi_2\right) + \mathsf{max}\left(\phi_1, \phi_2\right)\\ \mathbf{if}\;\mathsf{min}\left(\lambda_1, \lambda_2\right) \leq -2.6 \cdot 10^{+63}:\\ \;\;\;\;\left(\left(-\mathsf{min}\left(\lambda_1, \lambda_2\right)\right) \cdot \left|\cos \left(t\_0 \cdot -0.5\right)\right|\right) \cdot R\\ \mathbf{elif}\;\mathsf{min}\left(\lambda_1, \lambda_2\right) \leq 5.7 \cdot 10^{-62}:\\ \;\;\;\;\left(\mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\left(\mathsf{max}\left(\lambda_1, \lambda_2\right) \cdot \sqrt{--1 \cdot \left(0.5 + 0.5 \cdot \cos \left(-1 \cdot t\_0\right)\right)}\right) \cdot R\\ \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
      :precision binary64
      (let* ((t_0 (+ (fmin phi1 phi2) (fmax phi1 phi2))))
      (if (<= (fmin lambda1 lambda2) -2.6e+63)
        (* (* (- (fmin lambda1 lambda2)) (fabs (cos (* t_0 -0.5)))) R)
        (if (<= (fmin lambda1 lambda2) 5.7e-62)
          (* (- (fmax phi1 phi2) (fmin phi1 phi2)) R)
          (*
           (*
            (fmax lambda1 lambda2)
            (sqrt (- (* -1.0 (+ 0.5 (* 0.5 (cos (* -1.0 t_0))))))))
           R)))))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = fmin(phi1, phi2) + fmax(phi1, phi2);
    	double tmp;
    	if (fmin(lambda1, lambda2) <= -2.6e+63) {
    		tmp = (-fmin(lambda1, lambda2) * fabs(cos((t_0 * -0.5)))) * R;
    	} else if (fmin(lambda1, lambda2) <= 5.7e-62) {
    		tmp = (fmax(phi1, phi2) - fmin(phi1, phi2)) * R;
    	} else {
    		tmp = (fmax(lambda1, lambda2) * sqrt(-(-1.0 * (0.5 + (0.5 * cos((-1.0 * t_0))))))) * R;
    	}
    	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, lambda1, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: t_0
        real(8) :: tmp
        t_0 = fmin(phi1, phi2) + fmax(phi1, phi2)
        if (fmin(lambda1, lambda2) <= (-2.6d+63)) then
            tmp = (-fmin(lambda1, lambda2) * abs(cos((t_0 * (-0.5d0))))) * r
        else if (fmin(lambda1, lambda2) <= 5.7d-62) then
            tmp = (fmax(phi1, phi2) - fmin(phi1, phi2)) * r
        else
            tmp = (fmax(lambda1, lambda2) * sqrt(-((-1.0d0) * (0.5d0 + (0.5d0 * cos(((-1.0d0) * t_0))))))) * r
        end if
        code = tmp
    end function
    
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = fmin(phi1, phi2) + fmax(phi1, phi2);
    	double tmp;
    	if (fmin(lambda1, lambda2) <= -2.6e+63) {
    		tmp = (-fmin(lambda1, lambda2) * Math.abs(Math.cos((t_0 * -0.5)))) * R;
    	} else if (fmin(lambda1, lambda2) <= 5.7e-62) {
    		tmp = (fmax(phi1, phi2) - fmin(phi1, phi2)) * R;
    	} else {
    		tmp = (fmax(lambda1, lambda2) * Math.sqrt(-(-1.0 * (0.5 + (0.5 * Math.cos((-1.0 * t_0))))))) * R;
    	}
    	return tmp;
    }
    
    def code(R, lambda1, lambda2, phi1, phi2):
    	t_0 = fmin(phi1, phi2) + fmax(phi1, phi2)
    	tmp = 0
    	if fmin(lambda1, lambda2) <= -2.6e+63:
    		tmp = (-fmin(lambda1, lambda2) * math.fabs(math.cos((t_0 * -0.5)))) * R
    	elif fmin(lambda1, lambda2) <= 5.7e-62:
    		tmp = (fmax(phi1, phi2) - fmin(phi1, phi2)) * R
    	else:
    		tmp = (fmax(lambda1, lambda2) * math.sqrt(-(-1.0 * (0.5 + (0.5 * math.cos((-1.0 * t_0))))))) * R
    	return tmp
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	t_0 = Float64(fmin(phi1, phi2) + fmax(phi1, phi2))
    	tmp = 0.0
    	if (fmin(lambda1, lambda2) <= -2.6e+63)
    		tmp = Float64(Float64(Float64(-fmin(lambda1, lambda2)) * abs(cos(Float64(t_0 * -0.5)))) * R);
    	elseif (fmin(lambda1, lambda2) <= 5.7e-62)
    		tmp = Float64(Float64(fmax(phi1, phi2) - fmin(phi1, phi2)) * R);
    	else
    		tmp = Float64(Float64(fmax(lambda1, lambda2) * sqrt(Float64(-Float64(-1.0 * Float64(0.5 + Float64(0.5 * cos(Float64(-1.0 * t_0)))))))) * R);
    	end
    	return tmp
    end
    
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	t_0 = min(phi1, phi2) + max(phi1, phi2);
    	tmp = 0.0;
    	if (min(lambda1, lambda2) <= -2.6e+63)
    		tmp = (-min(lambda1, lambda2) * abs(cos((t_0 * -0.5)))) * R;
    	elseif (min(lambda1, lambda2) <= 5.7e-62)
    		tmp = (max(phi1, phi2) - min(phi1, phi2)) * R;
    	else
    		tmp = (max(lambda1, lambda2) * sqrt(-(-1.0 * (0.5 + (0.5 * cos((-1.0 * t_0))))))) * R;
    	end
    	tmp_2 = tmp;
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Min[phi1, phi2], $MachinePrecision] + N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Min[lambda1, lambda2], $MachinePrecision], -2.6e+63], N[(N[((-N[Min[lambda1, lambda2], $MachinePrecision]) * N[Abs[N[Cos[N[(t$95$0 * -0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision], If[LessEqual[N[Min[lambda1, lambda2], $MachinePrecision], 5.7e-62], N[(N[(N[Max[phi1, phi2], $MachinePrecision] - N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision], N[(N[(N[Max[lambda1, lambda2], $MachinePrecision] * N[Sqrt[(-N[(-1.0 * N[(0.5 + N[(0.5 * N[Cos[N[(-1.0 * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision]]]]
    
    \begin{array}{l}
    t_0 := \mathsf{min}\left(\phi_1, \phi_2\right) + \mathsf{max}\left(\phi_1, \phi_2\right)\\
    \mathbf{if}\;\mathsf{min}\left(\lambda_1, \lambda_2\right) \leq -2.6 \cdot 10^{+63}:\\
    \;\;\;\;\left(\left(-\mathsf{min}\left(\lambda_1, \lambda_2\right)\right) \cdot \left|\cos \left(t\_0 \cdot -0.5\right)\right|\right) \cdot R\\
    
    \mathbf{elif}\;\mathsf{min}\left(\lambda_1, \lambda_2\right) \leq 5.7 \cdot 10^{-62}:\\
    \;\;\;\;\left(\mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;\left(\mathsf{max}\left(\lambda_1, \lambda_2\right) \cdot \sqrt{--1 \cdot \left(0.5 + 0.5 \cdot \cos \left(-1 \cdot t\_0\right)\right)}\right) \cdot R\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if lambda1 < -2.6000000000000001e63

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Taylor expanded in phi2 around inf

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \color{blue}{\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)}\right) \]
        2. lower-+.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + \color{blue}{-1 \cdot \frac{\phi_1}{\phi_2}}\right)\right) \]
        3. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \color{blue}{\frac{\phi_1}{\phi_2}}\right)\right) \]
        4. lower-/.f6427.9%

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\color{blue}{\phi_2}}\right)\right) \]
      4. Applied rewrites27.9%

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      5. Taylor expanded in lambda1 around -inf

        \[\leadsto R \cdot \color{blue}{\left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right)} \]
      6. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto R \cdot \left(-1 \cdot \color{blue}{\left(\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)}\right) \]
        2. lower-*.f64N/A

          \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}}\right)\right) \]
        3. lower-sqrt.f64N/A

          \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right) \]
        4. lower-pow.f64N/A

          \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right) \]
        5. lower-cos.f64N/A

          \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right) \]
        6. lower-*.f64N/A

          \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right) \]
        7. lower-+.f6417.4%

          \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right) \]
      7. Applied rewrites17.4%

        \[\leadsto R \cdot \color{blue}{\left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right)} \]
      8. Applied rewrites17.4%

        \[\leadsto \color{blue}{\left(\left(-\lambda_1\right) \cdot \left|\cos \left(\left(\phi_1 + \phi_2\right) \cdot -0.5\right)\right|\right) \cdot R} \]

      if -2.6000000000000001e63 < lambda1 < 5.6999999999999999e-62

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Taylor expanded in phi2 around inf

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \color{blue}{\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)}\right) \]
        2. lower-+.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + \color{blue}{-1 \cdot \frac{\phi_1}{\phi_2}}\right)\right) \]
        3. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \color{blue}{\frac{\phi_1}{\phi_2}}\right)\right) \]
        4. lower-/.f6427.9%

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\color{blue}{\phi_2}}\right)\right) \]
      4. Applied rewrites27.9%

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \color{blue}{R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
        2. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
        3. lower-*.f6427.9%

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
      6. Applied rewrites29.9%

        \[\leadsto \color{blue}{\left(\phi_2 - \phi_1\right) \cdot R} \]

      if 5.6999999999999999e-62 < lambda1

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Applied rewrites58.6%

        \[\leadsto \color{blue}{\sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\lambda_2 - \lambda_1\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\phi_2 + \phi_1\right) \cdot -0.5\right)\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R} \]
      3. Taylor expanded in lambda2 around inf

        \[\leadsto \color{blue}{\left(\lambda_2 \cdot \sqrt{\mathsf{neg}\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}\right)} \cdot R \]
      4. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto \left(\lambda_2 \cdot \color{blue}{\sqrt{\mathsf{neg}\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}}\right) \cdot R \]
        2. lower-sqrt.f64N/A

          \[\leadsto \left(\lambda_2 \cdot \sqrt{\mathsf{neg}\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)\right)}\right) \cdot R \]
        3. lower-neg.f64N/A

          \[\leadsto \left(\lambda_2 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right) \cdot R \]
        4. lower-*.f64N/A

          \[\leadsto \left(\lambda_2 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right) \cdot R \]
        5. lower-+.f64N/A

          \[\leadsto \left(\lambda_2 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right) \cdot R \]
        6. lower-*.f64N/A

          \[\leadsto \left(\lambda_2 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right) \cdot R \]
        7. lower-cos.f64N/A

          \[\leadsto \left(\lambda_2 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right) \cdot R \]
        8. lower-*.f64N/A

          \[\leadsto \left(\lambda_2 \cdot \sqrt{--1 \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right) \cdot R \]
        9. lower-+.f6416.9%

          \[\leadsto \left(\lambda_2 \cdot \sqrt{--1 \cdot \left(0.5 + 0.5 \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right) \cdot R \]
      5. Applied rewrites16.9%

        \[\leadsto \color{blue}{\left(\lambda_2 \cdot \sqrt{--1 \cdot \left(0.5 + 0.5 \cdot \cos \left(-1 \cdot \left(\phi_1 + \phi_2\right)\right)\right)}\right)} \cdot R \]
    3. Recombined 3 regimes into one program.
    4. Add Preprocessing

    Alternative 9: 67.6% accurate, 0.5× speedup?

    \[\begin{array}{l} \mathbf{if}\;\mathsf{min}\left(\lambda_1, \lambda_2\right) \leq -2.6 \cdot 10^{+63}:\\ \;\;\;\;\left(\left(-\mathsf{min}\left(\lambda_1, \lambda_2\right)\right) \cdot \left|\cos \left(\left(\mathsf{min}\left(\phi_1, \phi_2\right) + \mathsf{max}\left(\phi_1, \phi_2\right)\right) \cdot -0.5\right)\right|\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\left(\mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot R\\ \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
      :precision binary64
      (if (<= (fmin lambda1 lambda2) -2.6e+63)
      (*
       (*
        (- (fmin lambda1 lambda2))
        (fabs (cos (* (+ (fmin phi1 phi2) (fmax phi1 phi2)) -0.5))))
       R)
      (* (- (fmax phi1 phi2) (fmin phi1 phi2)) R)))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (fmin(lambda1, lambda2) <= -2.6e+63) {
    		tmp = (-fmin(lambda1, lambda2) * fabs(cos(((fmin(phi1, phi2) + fmax(phi1, phi2)) * -0.5)))) * R;
    	} else {
    		tmp = (fmax(phi1, phi2) - fmin(phi1, phi2)) * R;
    	}
    	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, lambda1, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: tmp
        if (fmin(lambda1, lambda2) <= (-2.6d+63)) then
            tmp = (-fmin(lambda1, lambda2) * abs(cos(((fmin(phi1, phi2) + fmax(phi1, phi2)) * (-0.5d0))))) * r
        else
            tmp = (fmax(phi1, phi2) - fmin(phi1, phi2)) * r
        end if
        code = tmp
    end function
    
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (fmin(lambda1, lambda2) <= -2.6e+63) {
    		tmp = (-fmin(lambda1, lambda2) * Math.abs(Math.cos(((fmin(phi1, phi2) + fmax(phi1, phi2)) * -0.5)))) * R;
    	} else {
    		tmp = (fmax(phi1, phi2) - fmin(phi1, phi2)) * R;
    	}
    	return tmp;
    }
    
    def code(R, lambda1, lambda2, phi1, phi2):
    	tmp = 0
    	if fmin(lambda1, lambda2) <= -2.6e+63:
    		tmp = (-fmin(lambda1, lambda2) * math.fabs(math.cos(((fmin(phi1, phi2) + fmax(phi1, phi2)) * -0.5)))) * R
    	else:
    		tmp = (fmax(phi1, phi2) - fmin(phi1, phi2)) * R
    	return tmp
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (fmin(lambda1, lambda2) <= -2.6e+63)
    		tmp = Float64(Float64(Float64(-fmin(lambda1, lambda2)) * abs(cos(Float64(Float64(fmin(phi1, phi2) + fmax(phi1, phi2)) * -0.5)))) * R);
    	else
    		tmp = Float64(Float64(fmax(phi1, phi2) - fmin(phi1, phi2)) * R);
    	end
    	return tmp
    end
    
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0;
    	if (min(lambda1, lambda2) <= -2.6e+63)
    		tmp = (-min(lambda1, lambda2) * abs(cos(((min(phi1, phi2) + max(phi1, phi2)) * -0.5)))) * R;
    	else
    		tmp = (max(phi1, phi2) - min(phi1, phi2)) * R;
    	end
    	tmp_2 = tmp;
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[N[Min[lambda1, lambda2], $MachinePrecision], -2.6e+63], N[(N[((-N[Min[lambda1, lambda2], $MachinePrecision]) * N[Abs[N[Cos[N[(N[(N[Min[phi1, phi2], $MachinePrecision] + N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision], N[(N[(N[Max[phi1, phi2], $MachinePrecision] - N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision]]
    
    \begin{array}{l}
    \mathbf{if}\;\mathsf{min}\left(\lambda_1, \lambda_2\right) \leq -2.6 \cdot 10^{+63}:\\
    \;\;\;\;\left(\left(-\mathsf{min}\left(\lambda_1, \lambda_2\right)\right) \cdot \left|\cos \left(\left(\mathsf{min}\left(\phi_1, \phi_2\right) + \mathsf{max}\left(\phi_1, \phi_2\right)\right) \cdot -0.5\right)\right|\right) \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;\left(\mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot R\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if lambda1 < -2.6000000000000001e63

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Taylor expanded in phi2 around inf

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \color{blue}{\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)}\right) \]
        2. lower-+.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + \color{blue}{-1 \cdot \frac{\phi_1}{\phi_2}}\right)\right) \]
        3. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \color{blue}{\frac{\phi_1}{\phi_2}}\right)\right) \]
        4. lower-/.f6427.9%

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\color{blue}{\phi_2}}\right)\right) \]
      4. Applied rewrites27.9%

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      5. Taylor expanded in lambda1 around -inf

        \[\leadsto R \cdot \color{blue}{\left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right)} \]
      6. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto R \cdot \left(-1 \cdot \color{blue}{\left(\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)}\right) \]
        2. lower-*.f64N/A

          \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \color{blue}{\sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}}\right)\right) \]
        3. lower-sqrt.f64N/A

          \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right) \]
        4. lower-pow.f64N/A

          \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right) \]
        5. lower-cos.f64N/A

          \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right) \]
        6. lower-*.f64N/A

          \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right) \]
        7. lower-+.f6417.4%

          \[\leadsto R \cdot \left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right) \]
      7. Applied rewrites17.4%

        \[\leadsto R \cdot \color{blue}{\left(-1 \cdot \left(\lambda_1 \cdot \sqrt{{\cos \left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}^{2}}\right)\right)} \]
      8. Applied rewrites17.4%

        \[\leadsto \color{blue}{\left(\left(-\lambda_1\right) \cdot \left|\cos \left(\left(\phi_1 + \phi_2\right) \cdot -0.5\right)\right|\right) \cdot R} \]

      if -2.6000000000000001e63 < lambda1

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Taylor expanded in phi2 around inf

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \color{blue}{\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)}\right) \]
        2. lower-+.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + \color{blue}{-1 \cdot \frac{\phi_1}{\phi_2}}\right)\right) \]
        3. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \color{blue}{\frac{\phi_1}{\phi_2}}\right)\right) \]
        4. lower-/.f6427.9%

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\color{blue}{\phi_2}}\right)\right) \]
      4. Applied rewrites27.9%

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \color{blue}{R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
        2. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
        3. lower-*.f6427.9%

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
      6. Applied rewrites29.9%

        \[\leadsto \color{blue}{\left(\phi_2 - \phi_1\right) \cdot R} \]
    3. Recombined 2 regimes into one program.
    4. Add Preprocessing

    Alternative 10: 66.8% accurate, 0.4× speedup?

    \[\begin{array}{l} t_0 := \mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\\ \mathbf{if}\;\mathsf{min}\left(\phi_1, \phi_2\right) \leq -1.12 \cdot 10^{+154}:\\ \;\;\;\;t\_0 \cdot R\\ \mathbf{elif}\;\mathsf{min}\left(\phi_1, \phi_2\right) \leq 1.5 \cdot 10^{-206}:\\ \;\;\;\;\sqrt{t\_0 \cdot t\_0 - \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_2 - \lambda_1\right)} \cdot R\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \left(\mathsf{min}\left(\phi_1, \phi_2\right) \cdot \left(R + -1 \cdot \frac{R \cdot \mathsf{max}\left(\phi_1, \phi_2\right)}{\mathsf{min}\left(\phi_1, \phi_2\right)}\right)\right)\\ \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
      :precision binary64
      (let* ((t_0 (- (fmax phi1 phi2) (fmin phi1 phi2))))
      (if (<= (fmin phi1 phi2) -1.12e+154)
        (* t_0 R)
        (if (<= (fmin phi1 phi2) 1.5e-206)
          (*
           (sqrt
            (- (* t_0 t_0) (* (- lambda1 lambda2) (- lambda2 lambda1))))
           R)
          (*
           -1.0
           (*
            (fmin phi1 phi2)
            (+
             R
             (* -1.0 (/ (* R (fmax phi1 phi2)) (fmin phi1 phi2))))))))))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = fmax(phi1, phi2) - fmin(phi1, phi2);
    	double tmp;
    	if (fmin(phi1, phi2) <= -1.12e+154) {
    		tmp = t_0 * R;
    	} else if (fmin(phi1, phi2) <= 1.5e-206) {
    		tmp = sqrt(((t_0 * t_0) - ((lambda1 - lambda2) * (lambda2 - lambda1)))) * R;
    	} else {
    		tmp = -1.0 * (fmin(phi1, phi2) * (R + (-1.0 * ((R * fmax(phi1, phi2)) / fmin(phi1, phi2)))));
    	}
    	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, lambda1, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: t_0
        real(8) :: tmp
        t_0 = fmax(phi1, phi2) - fmin(phi1, phi2)
        if (fmin(phi1, phi2) <= (-1.12d+154)) then
            tmp = t_0 * r
        else if (fmin(phi1, phi2) <= 1.5d-206) then
            tmp = sqrt(((t_0 * t_0) - ((lambda1 - lambda2) * (lambda2 - lambda1)))) * r
        else
            tmp = (-1.0d0) * (fmin(phi1, phi2) * (r + ((-1.0d0) * ((r * fmax(phi1, phi2)) / fmin(phi1, phi2)))))
        end if
        code = tmp
    end function
    
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = fmax(phi1, phi2) - fmin(phi1, phi2);
    	double tmp;
    	if (fmin(phi1, phi2) <= -1.12e+154) {
    		tmp = t_0 * R;
    	} else if (fmin(phi1, phi2) <= 1.5e-206) {
    		tmp = Math.sqrt(((t_0 * t_0) - ((lambda1 - lambda2) * (lambda2 - lambda1)))) * R;
    	} else {
    		tmp = -1.0 * (fmin(phi1, phi2) * (R + (-1.0 * ((R * fmax(phi1, phi2)) / fmin(phi1, phi2)))));
    	}
    	return tmp;
    }
    
    def code(R, lambda1, lambda2, phi1, phi2):
    	t_0 = fmax(phi1, phi2) - fmin(phi1, phi2)
    	tmp = 0
    	if fmin(phi1, phi2) <= -1.12e+154:
    		tmp = t_0 * R
    	elif fmin(phi1, phi2) <= 1.5e-206:
    		tmp = math.sqrt(((t_0 * t_0) - ((lambda1 - lambda2) * (lambda2 - lambda1)))) * R
    	else:
    		tmp = -1.0 * (fmin(phi1, phi2) * (R + (-1.0 * ((R * fmax(phi1, phi2)) / fmin(phi1, phi2)))))
    	return tmp
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	t_0 = Float64(fmax(phi1, phi2) - fmin(phi1, phi2))
    	tmp = 0.0
    	if (fmin(phi1, phi2) <= -1.12e+154)
    		tmp = Float64(t_0 * R);
    	elseif (fmin(phi1, phi2) <= 1.5e-206)
    		tmp = Float64(sqrt(Float64(Float64(t_0 * t_0) - Float64(Float64(lambda1 - lambda2) * Float64(lambda2 - lambda1)))) * R);
    	else
    		tmp = Float64(-1.0 * Float64(fmin(phi1, phi2) * Float64(R + Float64(-1.0 * Float64(Float64(R * fmax(phi1, phi2)) / fmin(phi1, phi2))))));
    	end
    	return tmp
    end
    
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	t_0 = max(phi1, phi2) - min(phi1, phi2);
    	tmp = 0.0;
    	if (min(phi1, phi2) <= -1.12e+154)
    		tmp = t_0 * R;
    	elseif (min(phi1, phi2) <= 1.5e-206)
    		tmp = sqrt(((t_0 * t_0) - ((lambda1 - lambda2) * (lambda2 - lambda1)))) * R;
    	else
    		tmp = -1.0 * (min(phi1, phi2) * (R + (-1.0 * ((R * max(phi1, phi2)) / min(phi1, phi2)))));
    	end
    	tmp_2 = tmp;
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Max[phi1, phi2], $MachinePrecision] - N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Min[phi1, phi2], $MachinePrecision], -1.12e+154], N[(t$95$0 * R), $MachinePrecision], If[LessEqual[N[Min[phi1, phi2], $MachinePrecision], 1.5e-206], N[(N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(lambda2 - lambda1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(-1.0 * N[(N[Min[phi1, phi2], $MachinePrecision] * N[(R + N[(-1.0 * N[(N[(R * N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision] / N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
    
    \begin{array}{l}
    t_0 := \mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\\
    \mathbf{if}\;\mathsf{min}\left(\phi_1, \phi_2\right) \leq -1.12 \cdot 10^{+154}:\\
    \;\;\;\;t\_0 \cdot R\\
    
    \mathbf{elif}\;\mathsf{min}\left(\phi_1, \phi_2\right) \leq 1.5 \cdot 10^{-206}:\\
    \;\;\;\;\sqrt{t\_0 \cdot t\_0 - \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_2 - \lambda_1\right)} \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;-1 \cdot \left(\mathsf{min}\left(\phi_1, \phi_2\right) \cdot \left(R + -1 \cdot \frac{R \cdot \mathsf{max}\left(\phi_1, \phi_2\right)}{\mathsf{min}\left(\phi_1, \phi_2\right)}\right)\right)\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if phi1 < -1.1199999999999999e154

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Taylor expanded in phi2 around inf

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \color{blue}{\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)}\right) \]
        2. lower-+.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + \color{blue}{-1 \cdot \frac{\phi_1}{\phi_2}}\right)\right) \]
        3. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \color{blue}{\frac{\phi_1}{\phi_2}}\right)\right) \]
        4. lower-/.f6427.9%

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\color{blue}{\phi_2}}\right)\right) \]
      4. Applied rewrites27.9%

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \color{blue}{R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
        2. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
        3. lower-*.f6427.9%

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
      6. Applied rewrites29.9%

        \[\leadsto \color{blue}{\left(\phi_2 - \phi_1\right) \cdot R} \]

      if -1.1199999999999999e154 < phi1 < 1.5000000000000001e-206

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Applied rewrites58.6%

        \[\leadsto \color{blue}{\sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\lambda_2 - \lambda_1\right) \cdot \left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(\phi_2 + \phi_1\right) \cdot -0.5\right)\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot R} \]
      3. Taylor expanded in phi2 around 0

        \[\leadsto \sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \phi_1\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_2 - \lambda_1\right)\right)}} \cdot R \]
      4. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto \sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \phi_1\right)\right) \cdot \color{blue}{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_2 - \lambda_1\right)\right)}} \cdot R \]
        2. lower-+.f64N/A

          \[\leadsto \sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \phi_1\right)\right) \cdot \left(\color{blue}{\left(\lambda_1 - \lambda_2\right)} \cdot \left(\lambda_2 - \lambda_1\right)\right)} \cdot R \]
        3. lower-*.f64N/A

          \[\leadsto \sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \phi_1\right)\right) \cdot \left(\left(\lambda_1 - \color{blue}{\lambda_2}\right) \cdot \left(\lambda_2 - \lambda_1\right)\right)} \cdot R \]
        4. lower-cos.f64N/A

          \[\leadsto \sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \phi_1\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_2 - \lambda_1\right)\right)} \cdot R \]
        5. lower-*.f64N/A

          \[\leadsto \sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \phi_1\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_2 - \lambda_1\right)\right)} \cdot R \]
        6. lower-*.f64N/A

          \[\leadsto \sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \phi_1\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\lambda_2 - \lambda_1\right)}\right)} \cdot R \]
        7. lower--.f64N/A

          \[\leadsto \sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(-1 \cdot \phi_1\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\color{blue}{\lambda_2} - \lambda_1\right)\right)} \cdot R \]
        8. lower--.f6457.2%

          \[\leadsto \sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(0.5 + 0.5 \cdot \cos \left(-1 \cdot \phi_1\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_2 - \color{blue}{\lambda_1}\right)\right)} \cdot R \]
      5. Applied rewrites57.2%

        \[\leadsto \sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \color{blue}{\left(0.5 + 0.5 \cdot \cos \left(-1 \cdot \phi_1\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_2 - \lambda_1\right)\right)}} \cdot R \]
      6. Taylor expanded in phi1 around 0

        \[\leadsto \sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\lambda_2 - \lambda_1\right)}} \cdot R \]
      7. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto \sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_2 - \color{blue}{\lambda_1}\right)} \cdot R \]
        2. lower--.f64N/A

          \[\leadsto \sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_2 - \lambda_1\right)} \cdot R \]
        3. lower--.f6455.9%

          \[\leadsto \sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_2 - \lambda_1\right)} \cdot R \]
      8. Applied rewrites55.9%

        \[\leadsto \sqrt{\left(\phi_2 - \phi_1\right) \cdot \left(\phi_2 - \phi_1\right) - \left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\lambda_2 - \lambda_1\right)}} \cdot R \]

      if 1.5000000000000001e-206 < phi1

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Taylor expanded in phi1 around -inf

        \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto -1 \cdot \color{blue}{\left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
        2. lower-*.f64N/A

          \[\leadsto -1 \cdot \left(\phi_1 \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)}\right) \]
        3. lower-+.f64N/A

          \[\leadsto -1 \cdot \left(\phi_1 \cdot \left(R + \color{blue}{-1 \cdot \frac{R \cdot \phi_2}{\phi_1}}\right)\right) \]
        4. lower-*.f64N/A

          \[\leadsto -1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \color{blue}{\frac{R \cdot \phi_2}{\phi_1}}\right)\right) \]
        5. lower-/.f64N/A

          \[\leadsto -1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\color{blue}{\phi_1}}\right)\right) \]
        6. lower-*.f6429.1%

          \[\leadsto -1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right) \]
      4. Applied rewrites29.1%

        \[\leadsto \color{blue}{-1 \cdot \left(\phi_1 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_2}{\phi_1}\right)\right)} \]
    3. Recombined 3 regimes into one program.
    4. Add Preprocessing

    Alternative 11: 58.3% accurate, 0.6× speedup?

    \[\begin{array}{l} \mathbf{if}\;\mathsf{max}\left(\lambda_1, \lambda_2\right) \leq 10^{+207}:\\ \;\;\;\;\left(\mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\mathsf{max}\left(\phi_1, \phi_2\right) \cdot \left(R + -1 \cdot \frac{R \cdot \mathsf{min}\left(\phi_1, \phi_2\right)}{\mathsf{max}\left(\phi_1, \phi_2\right)}\right)\\ \end{array} \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
      :precision binary64
      (if (<= (fmax lambda1 lambda2) 1e+207)
      (* (- (fmax phi1 phi2) (fmin phi1 phi2)) R)
      (*
       (fmax phi1 phi2)
       (+ R (* -1.0 (/ (* R (fmin phi1 phi2)) (fmax phi1 phi2)))))))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (fmax(lambda1, lambda2) <= 1e+207) {
    		tmp = (fmax(phi1, phi2) - fmin(phi1, phi2)) * R;
    	} else {
    		tmp = fmax(phi1, phi2) * (R + (-1.0 * ((R * fmin(phi1, phi2)) / fmax(phi1, phi2))));
    	}
    	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, lambda1, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        real(8) :: tmp
        if (fmax(lambda1, lambda2) <= 1d+207) then
            tmp = (fmax(phi1, phi2) - fmin(phi1, phi2)) * r
        else
            tmp = fmax(phi1, phi2) * (r + ((-1.0d0) * ((r * fmin(phi1, phi2)) / fmax(phi1, phi2))))
        end if
        code = tmp
    end function
    
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	double tmp;
    	if (fmax(lambda1, lambda2) <= 1e+207) {
    		tmp = (fmax(phi1, phi2) - fmin(phi1, phi2)) * R;
    	} else {
    		tmp = fmax(phi1, phi2) * (R + (-1.0 * ((R * fmin(phi1, phi2)) / fmax(phi1, phi2))));
    	}
    	return tmp;
    }
    
    def code(R, lambda1, lambda2, phi1, phi2):
    	tmp = 0
    	if fmax(lambda1, lambda2) <= 1e+207:
    		tmp = (fmax(phi1, phi2) - fmin(phi1, phi2)) * R
    	else:
    		tmp = fmax(phi1, phi2) * (R + (-1.0 * ((R * fmin(phi1, phi2)) / fmax(phi1, phi2))))
    	return tmp
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0
    	if (fmax(lambda1, lambda2) <= 1e+207)
    		tmp = Float64(Float64(fmax(phi1, phi2) - fmin(phi1, phi2)) * R);
    	else
    		tmp = Float64(fmax(phi1, phi2) * Float64(R + Float64(-1.0 * Float64(Float64(R * fmin(phi1, phi2)) / fmax(phi1, phi2)))));
    	end
    	return tmp
    end
    
    function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
    	tmp = 0.0;
    	if (max(lambda1, lambda2) <= 1e+207)
    		tmp = (max(phi1, phi2) - min(phi1, phi2)) * R;
    	else
    		tmp = max(phi1, phi2) * (R + (-1.0 * ((R * min(phi1, phi2)) / max(phi1, phi2))));
    	end
    	tmp_2 = tmp;
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[N[Max[lambda1, lambda2], $MachinePrecision], 1e+207], N[(N[(N[Max[phi1, phi2], $MachinePrecision] - N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision], N[(N[Max[phi1, phi2], $MachinePrecision] * N[(R + N[(-1.0 * N[(N[(R * N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision] / N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    \mathbf{if}\;\mathsf{max}\left(\lambda_1, \lambda_2\right) \leq 10^{+207}:\\
    \;\;\;\;\left(\mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot R\\
    
    \mathbf{else}:\\
    \;\;\;\;\mathsf{max}\left(\phi_1, \phi_2\right) \cdot \left(R + -1 \cdot \frac{R \cdot \mathsf{min}\left(\phi_1, \phi_2\right)}{\mathsf{max}\left(\phi_1, \phi_2\right)}\right)\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if lambda2 < 1e207

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Taylor expanded in phi2 around inf

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \color{blue}{\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)}\right) \]
        2. lower-+.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + \color{blue}{-1 \cdot \frac{\phi_1}{\phi_2}}\right)\right) \]
        3. lower-*.f64N/A

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \color{blue}{\frac{\phi_1}{\phi_2}}\right)\right) \]
        4. lower-/.f6427.9%

          \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\color{blue}{\phi_2}}\right)\right) \]
      4. Applied rewrites27.9%

        \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \color{blue}{R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
        2. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
        3. lower-*.f6427.9%

          \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
      6. Applied rewrites29.9%

        \[\leadsto \color{blue}{\left(\phi_2 - \phi_1\right) \cdot R} \]

      if 1e207 < lambda2

      1. Initial program 58.6%

        \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
      2. Taylor expanded in phi2 around inf

        \[\leadsto \color{blue}{\phi_2 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_1}{\phi_2}\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto \phi_2 \cdot \color{blue}{\left(R + -1 \cdot \frac{R \cdot \phi_1}{\phi_2}\right)} \]
        2. lower-+.f64N/A

          \[\leadsto \phi_2 \cdot \left(R + \color{blue}{-1 \cdot \frac{R \cdot \phi_1}{\phi_2}}\right) \]
        3. lower-*.f64N/A

          \[\leadsto \phi_2 \cdot \left(R + -1 \cdot \color{blue}{\frac{R \cdot \phi_1}{\phi_2}}\right) \]
        4. lower-/.f64N/A

          \[\leadsto \phi_2 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_1}{\color{blue}{\phi_2}}\right) \]
        5. lower-*.f6429.5%

          \[\leadsto \phi_2 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_1}{\phi_2}\right) \]
      4. Applied rewrites29.5%

        \[\leadsto \color{blue}{\phi_2 \cdot \left(R + -1 \cdot \frac{R \cdot \phi_1}{\phi_2}\right)} \]
    3. Recombined 2 regimes into one program.
    4. Add Preprocessing

    Alternative 12: 57.7% accurate, 1.3× speedup?

    \[\left(\mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot R \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
      :precision binary64
      (* (- (fmax phi1 phi2) (fmin phi1 phi2)) R))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	return (fmax(phi1, phi2) - fmin(phi1, phi2)) * R;
    }
    
    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, lambda1, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        code = (fmax(phi1, phi2) - fmin(phi1, phi2)) * r
    end function
    
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	return (fmax(phi1, phi2) - fmin(phi1, phi2)) * R;
    }
    
    def code(R, lambda1, lambda2, phi1, phi2):
    	return (fmax(phi1, phi2) - fmin(phi1, phi2)) * R
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	return Float64(Float64(fmax(phi1, phi2) - fmin(phi1, phi2)) * R)
    end
    
    function tmp = code(R, lambda1, lambda2, phi1, phi2)
    	tmp = (max(phi1, phi2) - min(phi1, phi2)) * R;
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[(N[Max[phi1, phi2], $MachinePrecision] - N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision]
    
    \left(\mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot R
    
    Derivation
    1. Initial program 58.6%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Taylor expanded in phi2 around inf

      \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto R \cdot \left(\phi_2 \cdot \color{blue}{\left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)}\right) \]
      2. lower-+.f64N/A

        \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + \color{blue}{-1 \cdot \frac{\phi_1}{\phi_2}}\right)\right) \]
      3. lower-*.f64N/A

        \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \color{blue}{\frac{\phi_1}{\phi_2}}\right)\right) \]
      4. lower-/.f6427.9%

        \[\leadsto R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\color{blue}{\phi_2}}\right)\right) \]
    4. Applied rewrites27.9%

      \[\leadsto R \cdot \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{R \cdot \left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right)} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
      3. lower-*.f6427.9%

        \[\leadsto \color{blue}{\left(\phi_2 \cdot \left(1 + -1 \cdot \frac{\phi_1}{\phi_2}\right)\right) \cdot R} \]
    6. Applied rewrites29.9%

      \[\leadsto \color{blue}{\left(\phi_2 - \phi_1\right) \cdot R} \]
    7. Add Preprocessing

    Alternative 13: 31.6% accurate, 2.6× speedup?

    \[R \cdot \mathsf{max}\left(\phi_1, \phi_2\right) \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
      :precision binary64
      (* R (fmax phi1 phi2)))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	return R * fmax(phi1, phi2);
    }
    
    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, lambda1, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        code = r * fmax(phi1, phi2)
    end function
    
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	return R * fmax(phi1, phi2);
    }
    
    def code(R, lambda1, lambda2, phi1, phi2):
    	return R * fmax(phi1, phi2)
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	return Float64(R * fmax(phi1, phi2))
    end
    
    function tmp = code(R, lambda1, lambda2, phi1, phi2)
    	tmp = R * max(phi1, phi2);
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision]
    
    R \cdot \mathsf{max}\left(\phi_1, \phi_2\right)
    
    Derivation
    1. Initial program 58.6%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Taylor expanded in phi2 around inf

      \[\leadsto \color{blue}{R \cdot \phi_2} \]
    3. Step-by-step derivation
      1. lower-*.f6418.0%

        \[\leadsto R \cdot \color{blue}{\phi_2} \]
    4. Applied rewrites18.0%

      \[\leadsto \color{blue}{R \cdot \phi_2} \]
    5. Add Preprocessing

    Alternative 14: 17.3% accurate, 46.5× speedup?

    \[R \cdot \phi_1 \]
    (FPCore (R lambda1 lambda2 phi1 phi2)
      :precision binary64
      (* R phi1))
    double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	return R * phi1;
    }
    
    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, lambda1, lambda2, phi1, phi2)
    use fmin_fmax_functions
        real(8), intent (in) :: r
        real(8), intent (in) :: lambda1
        real(8), intent (in) :: lambda2
        real(8), intent (in) :: phi1
        real(8), intent (in) :: phi2
        code = r * phi1
    end function
    
    public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
    	return R * phi1;
    }
    
    def code(R, lambda1, lambda2, phi1, phi2):
    	return R * phi1
    
    function code(R, lambda1, lambda2, phi1, phi2)
    	return Float64(R * phi1)
    end
    
    function tmp = code(R, lambda1, lambda2, phi1, phi2)
    	tmp = R * phi1;
    end
    
    code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * phi1), $MachinePrecision]
    
    R \cdot \phi_1
    
    Derivation
    1. Initial program 58.6%

      \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)} \]
    2. Taylor expanded in phi1 around inf

      \[\leadsto \color{blue}{R \cdot \phi_1} \]
    3. Step-by-step derivation
      1. lower-*.f6417.3%

        \[\leadsto R \cdot \color{blue}{\phi_1} \]
    4. Applied rewrites17.3%

      \[\leadsto \color{blue}{R \cdot \phi_1} \]
    5. Add Preprocessing

    Reproduce

    ?
    herbie shell --seed 2025258 
    (FPCore (R lambda1 lambda2 phi1 phi2)
      :name "Equirectangular approximation to distance on a great circle"
      :precision binary64
      (* R (sqrt (+ (* (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0))) (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0)))) (* (- phi1 phi2) (- phi1 phi2))))))