Midpoint on a great circle

Percentage Accurate: 98.6% → 99.6%
Time: 17.2s
Alternatives: 18
Speedup: 1.0×

Specification

?
\[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
(FPCore (lambda1 lambda2 phi1 phi2)
  :precision binary64
  (+
 lambda1
 (atan2
  (* (cos phi2) (sin (- lambda1 lambda2)))
  (+ (cos phi1) (* (cos phi2) (cos (- lambda1 lambda2)))))))
double code(double lambda1, double lambda2, double phi1, double phi2) {
	return lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + (cos(phi2) * cos((lambda1 - lambda2)))));
}
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(lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    code = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + (cos(phi2) * cos((lambda1 - lambda2)))))
end function
public static double code(double lambda1, double lambda2, double phi1, double phi2) {
	return lambda1 + Math.atan2((Math.cos(phi2) * Math.sin((lambda1 - lambda2))), (Math.cos(phi1) + (Math.cos(phi2) * Math.cos((lambda1 - lambda2)))));
}
def code(lambda1, lambda2, phi1, phi2):
	return lambda1 + math.atan2((math.cos(phi2) * math.sin((lambda1 - lambda2))), (math.cos(phi1) + (math.cos(phi2) * math.cos((lambda1 - lambda2)))))
function code(lambda1, lambda2, phi1, phi2)
	return Float64(lambda1 + atan(Float64(cos(phi2) * sin(Float64(lambda1 - lambda2))), Float64(cos(phi1) + Float64(cos(phi2) * cos(Float64(lambda1 - lambda2))))))
end
function tmp = code(lambda1, lambda2, phi1, phi2)
	tmp = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + (cos(phi2) * cos((lambda1 - lambda2)))));
end
code[lambda1_, lambda2_, phi1_, phi2_] := N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[phi1], $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)}

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

\[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
(FPCore (lambda1 lambda2 phi1 phi2)
  :precision binary64
  (+
 lambda1
 (atan2
  (* (cos phi2) (sin (- lambda1 lambda2)))
  (+ (cos phi1) (* (cos phi2) (cos (- lambda1 lambda2)))))))
double code(double lambda1, double lambda2, double phi1, double phi2) {
	return lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + (cos(phi2) * cos((lambda1 - lambda2)))));
}
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(lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    code = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + (cos(phi2) * cos((lambda1 - lambda2)))))
end function
public static double code(double lambda1, double lambda2, double phi1, double phi2) {
	return lambda1 + Math.atan2((Math.cos(phi2) * Math.sin((lambda1 - lambda2))), (Math.cos(phi1) + (Math.cos(phi2) * Math.cos((lambda1 - lambda2)))));
}
def code(lambda1, lambda2, phi1, phi2):
	return lambda1 + math.atan2((math.cos(phi2) * math.sin((lambda1 - lambda2))), (math.cos(phi1) + (math.cos(phi2) * math.cos((lambda1 - lambda2)))))
function code(lambda1, lambda2, phi1, phi2)
	return Float64(lambda1 + atan(Float64(cos(phi2) * sin(Float64(lambda1 - lambda2))), Float64(cos(phi1) + Float64(cos(phi2) * cos(Float64(lambda1 - lambda2))))))
end
function tmp = code(lambda1, lambda2, phi1, phi2)
	tmp = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + (cos(phi2) * cos((lambda1 - lambda2)))));
end
code[lambda1_, lambda2_, phi1_, phi2_] := N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[phi1], $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)}

Alternative 1: 99.6% accurate, 0.5× speedup?

\[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2 \cdot \cos \lambda_1\right)}{\cos \phi_1 + \cos \phi_2 \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_1 \cdot \cos \lambda_2\right)} \]
(FPCore (lambda1 lambda2 phi1 phi2)
  :precision binary64
  (+
 lambda1
 (atan2
  (*
   (cos phi2)
   (-
    (* (sin lambda1) (cos lambda2))
    (* (sin lambda2) (cos lambda1))))
  (+
   (cos phi1)
   (*
    (cos phi2)
    (+
     (* (sin lambda2) (sin lambda1))
     (* (cos lambda1) (cos lambda2))))))))
double code(double lambda1, double lambda2, double phi1, double phi2) {
	return lambda1 + atan2((cos(phi2) * ((sin(lambda1) * cos(lambda2)) - (sin(lambda2) * cos(lambda1)))), (cos(phi1) + (cos(phi2) * ((sin(lambda2) * sin(lambda1)) + (cos(lambda1) * cos(lambda2))))));
}
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(lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    code = lambda1 + atan2((cos(phi2) * ((sin(lambda1) * cos(lambda2)) - (sin(lambda2) * cos(lambda1)))), (cos(phi1) + (cos(phi2) * ((sin(lambda2) * sin(lambda1)) + (cos(lambda1) * cos(lambda2))))))
end function
public static double code(double lambda1, double lambda2, double phi1, double phi2) {
	return lambda1 + Math.atan2((Math.cos(phi2) * ((Math.sin(lambda1) * Math.cos(lambda2)) - (Math.sin(lambda2) * Math.cos(lambda1)))), (Math.cos(phi1) + (Math.cos(phi2) * ((Math.sin(lambda2) * Math.sin(lambda1)) + (Math.cos(lambda1) * Math.cos(lambda2))))));
}
def code(lambda1, lambda2, phi1, phi2):
	return lambda1 + math.atan2((math.cos(phi2) * ((math.sin(lambda1) * math.cos(lambda2)) - (math.sin(lambda2) * math.cos(lambda1)))), (math.cos(phi1) + (math.cos(phi2) * ((math.sin(lambda2) * math.sin(lambda1)) + (math.cos(lambda1) * math.cos(lambda2))))))
function code(lambda1, lambda2, phi1, phi2)
	return Float64(lambda1 + atan(Float64(cos(phi2) * Float64(Float64(sin(lambda1) * cos(lambda2)) - Float64(sin(lambda2) * cos(lambda1)))), Float64(cos(phi1) + Float64(cos(phi2) * Float64(Float64(sin(lambda2) * sin(lambda1)) + Float64(cos(lambda1) * cos(lambda2)))))))
end
function tmp = code(lambda1, lambda2, phi1, phi2)
	tmp = lambda1 + atan2((cos(phi2) * ((sin(lambda1) * cos(lambda2)) - (sin(lambda2) * cos(lambda1)))), (cos(phi1) + (cos(phi2) * ((sin(lambda2) * sin(lambda1)) + (cos(lambda1) * cos(lambda2))))));
end
code[lambda1_, lambda2_, phi1_, phi2_] := N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[phi1], $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * N[(N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2 \cdot \cos \lambda_1\right)}{\cos \phi_1 + \cos \phi_2 \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_1 \cdot \cos \lambda_2\right)}
Derivation
  1. Initial program 98.6%

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

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

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \color{blue}{\left(\lambda_1 - \lambda_2\right)}}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    3. sin-diffN/A

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

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

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

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

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \color{blue}{\cos \lambda_2} - \cos \lambda_1 \cdot \sin \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    8. *-commutativeN/A

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

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

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\sin \lambda_2} \cdot \cos \lambda_1\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    11. lower-cos.f6498.7%

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2 \cdot \color{blue}{\cos \lambda_1}\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
  3. Applied rewrites98.7%

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

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

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2 \cdot \cos \lambda_1\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \color{blue}{\left(\lambda_1 - \lambda_2\right)}} \]
    3. cos-diffN/A

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

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

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2 \cdot \cos \lambda_1\right)}{\cos \phi_1 + \cos \phi_2 \cdot \color{blue}{\left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)}} \]
    6. lift-sin.f64N/A

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2 \cdot \cos \lambda_1\right)}{\cos \phi_1 + \cos \phi_2 \cdot \left(\color{blue}{\sin \lambda_1} \cdot \sin \lambda_2 + \cos \lambda_1 \cdot \cos \lambda_2\right)} \]
    7. lift-sin.f64N/A

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2 \cdot \cos \lambda_1\right)}{\cos \phi_1 + \cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \color{blue}{\sin \lambda_2} + \cos \lambda_1 \cdot \cos \lambda_2\right)} \]
    8. *-commutativeN/A

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

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2 \cdot \cos \lambda_1\right)}{\cos \phi_1 + \cos \phi_2 \cdot \left(\color{blue}{\sin \lambda_2 \cdot \sin \lambda_1} + \cos \lambda_1 \cdot \cos \lambda_2\right)} \]
    10. lift-cos.f64N/A

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2 \cdot \cos \lambda_1\right)}{\cos \phi_1 + \cos \phi_2 \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \color{blue}{\cos \lambda_1} \cdot \cos \lambda_2\right)} \]
    11. lift-cos.f64N/A

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2 \cdot \cos \lambda_1\right)}{\cos \phi_1 + \cos \phi_2 \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_1 \cdot \color{blue}{\cos \lambda_2}\right)} \]
    12. lower-*.f6499.6%

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2 \cdot \cos \lambda_1\right)}{\cos \phi_1 + \cos \phi_2 \cdot \left(\sin \lambda_2 \cdot \sin \lambda_1 + \color{blue}{\cos \lambda_1 \cdot \cos \lambda_2}\right)} \]
  5. Applied rewrites99.6%

    \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2 \cdot \cos \lambda_1\right)}{\cos \phi_1 + \cos \phi_2 \cdot \color{blue}{\left(\sin \lambda_2 \cdot \sin \lambda_1 + \cos \lambda_1 \cdot \cos \lambda_2\right)}} \]
  6. Add Preprocessing

Alternative 2: 98.7% accurate, 0.7× speedup?

\[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2 \cdot \cos \lambda_1\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
(FPCore (lambda1 lambda2 phi1 phi2)
  :precision binary64
  (+
 lambda1
 (atan2
  (*
   (cos phi2)
   (-
    (* (sin lambda1) (cos lambda2))
    (* (sin lambda2) (cos lambda1))))
  (+ (cos phi1) (* (cos phi2) (cos (- lambda1 lambda2)))))))
double code(double lambda1, double lambda2, double phi1, double phi2) {
	return lambda1 + atan2((cos(phi2) * ((sin(lambda1) * cos(lambda2)) - (sin(lambda2) * cos(lambda1)))), (cos(phi1) + (cos(phi2) * cos((lambda1 - lambda2)))));
}
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(lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    code = lambda1 + atan2((cos(phi2) * ((sin(lambda1) * cos(lambda2)) - (sin(lambda2) * cos(lambda1)))), (cos(phi1) + (cos(phi2) * cos((lambda1 - lambda2)))))
end function
public static double code(double lambda1, double lambda2, double phi1, double phi2) {
	return lambda1 + Math.atan2((Math.cos(phi2) * ((Math.sin(lambda1) * Math.cos(lambda2)) - (Math.sin(lambda2) * Math.cos(lambda1)))), (Math.cos(phi1) + (Math.cos(phi2) * Math.cos((lambda1 - lambda2)))));
}
def code(lambda1, lambda2, phi1, phi2):
	return lambda1 + math.atan2((math.cos(phi2) * ((math.sin(lambda1) * math.cos(lambda2)) - (math.sin(lambda2) * math.cos(lambda1)))), (math.cos(phi1) + (math.cos(phi2) * math.cos((lambda1 - lambda2)))))
function code(lambda1, lambda2, phi1, phi2)
	return Float64(lambda1 + atan(Float64(cos(phi2) * Float64(Float64(sin(lambda1) * cos(lambda2)) - Float64(sin(lambda2) * cos(lambda1)))), Float64(cos(phi1) + Float64(cos(phi2) * cos(Float64(lambda1 - lambda2))))))
end
function tmp = code(lambda1, lambda2, phi1, phi2)
	tmp = lambda1 + atan2((cos(phi2) * ((sin(lambda1) * cos(lambda2)) - (sin(lambda2) * cos(lambda1)))), (cos(phi1) + (cos(phi2) * cos((lambda1 - lambda2)))));
end
code[lambda1_, lambda2_, phi1_, phi2_] := N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[phi1], $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2 \cdot \cos \lambda_1\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)}
Derivation
  1. Initial program 98.6%

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

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

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \color{blue}{\left(\lambda_1 - \lambda_2\right)}}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    3. sin-diffN/A

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

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

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

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

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \color{blue}{\cos \lambda_2} - \cos \lambda_1 \cdot \sin \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    8. *-commutativeN/A

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

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

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\sin \lambda_2} \cdot \cos \lambda_1\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    11. lower-cos.f6498.7%

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2 \cdot \color{blue}{\cos \lambda_1}\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
  3. Applied rewrites98.7%

    \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2 \cdot \cos \lambda_1\right)}}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
  4. Add Preprocessing

Alternative 3: 98.6% accurate, 0.8× speedup?

\[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
(FPCore (lambda1 lambda2 phi1 phi2)
  :precision binary64
  (+
 lambda1
 (atan2
  (* (cos phi2) (- (* (sin lambda1) (cos lambda2)) (sin lambda2)))
  (+ (cos phi1) (* (cos phi2) (cos (- lambda1 lambda2)))))))
double code(double lambda1, double lambda2, double phi1, double phi2) {
	return lambda1 + atan2((cos(phi2) * ((sin(lambda1) * cos(lambda2)) - sin(lambda2))), (cos(phi1) + (cos(phi2) * cos((lambda1 - lambda2)))));
}
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(lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    code = lambda1 + atan2((cos(phi2) * ((sin(lambda1) * cos(lambda2)) - sin(lambda2))), (cos(phi1) + (cos(phi2) * cos((lambda1 - lambda2)))))
end function
public static double code(double lambda1, double lambda2, double phi1, double phi2) {
	return lambda1 + Math.atan2((Math.cos(phi2) * ((Math.sin(lambda1) * Math.cos(lambda2)) - Math.sin(lambda2))), (Math.cos(phi1) + (Math.cos(phi2) * Math.cos((lambda1 - lambda2)))));
}
def code(lambda1, lambda2, phi1, phi2):
	return lambda1 + math.atan2((math.cos(phi2) * ((math.sin(lambda1) * math.cos(lambda2)) - math.sin(lambda2))), (math.cos(phi1) + (math.cos(phi2) * math.cos((lambda1 - lambda2)))))
function code(lambda1, lambda2, phi1, phi2)
	return Float64(lambda1 + atan(Float64(cos(phi2) * Float64(Float64(sin(lambda1) * cos(lambda2)) - sin(lambda2))), Float64(cos(phi1) + Float64(cos(phi2) * cos(Float64(lambda1 - lambda2))))))
end
function tmp = code(lambda1, lambda2, phi1, phi2)
	tmp = lambda1 + atan2((cos(phi2) * ((sin(lambda1) * cos(lambda2)) - sin(lambda2))), (cos(phi1) + (cos(phi2) * cos((lambda1 - lambda2)))));
end
code[lambda1_, lambda2_, phi1_, phi2_] := N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] - N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[phi1], $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)}
Derivation
  1. Initial program 98.6%

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

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

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \color{blue}{\left(\lambda_1 - \lambda_2\right)}}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    3. sin-diffN/A

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

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

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

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

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \color{blue}{\cos \lambda_2} - \cos \lambda_1 \cdot \sin \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    8. *-commutativeN/A

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

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

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\sin \lambda_2} \cdot \cos \lambda_1\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    11. lower-cos.f6498.7%

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2 \cdot \color{blue}{\cos \lambda_1}\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
  3. Applied rewrites98.7%

    \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \color{blue}{\left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2 \cdot \cos \lambda_1\right)}}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
  4. Taylor expanded in lambda1 around 0

    \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\sin \lambda_2}\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
  5. Step-by-step derivation
    1. lower-sin.f6498.6%

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \sin \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
  6. Applied rewrites98.6%

    \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \lambda_1 \cdot \cos \lambda_2 - \color{blue}{\sin \lambda_2}\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
  7. Add Preprocessing

Alternative 4: 97.9% accurate, 1.0× speedup?

\[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(-\lambda_2\right)} \]
(FPCore (lambda1 lambda2 phi1 phi2)
  :precision binary64
  (+
 lambda1
 (atan2
  (* (cos phi2) (sin (- lambda1 lambda2)))
  (+ (cos phi1) (* (cos phi2) (cos (- lambda2)))))))
double code(double lambda1, double lambda2, double phi1, double phi2) {
	return lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + (cos(phi2) * cos(-lambda2))));
}
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(lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    code = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + (cos(phi2) * cos(-lambda2))))
end function
public static double code(double lambda1, double lambda2, double phi1, double phi2) {
	return lambda1 + Math.atan2((Math.cos(phi2) * Math.sin((lambda1 - lambda2))), (Math.cos(phi1) + (Math.cos(phi2) * Math.cos(-lambda2))));
}
def code(lambda1, lambda2, phi1, phi2):
	return lambda1 + math.atan2((math.cos(phi2) * math.sin((lambda1 - lambda2))), (math.cos(phi1) + (math.cos(phi2) * math.cos(-lambda2))))
function code(lambda1, lambda2, phi1, phi2)
	return Float64(lambda1 + atan(Float64(cos(phi2) * sin(Float64(lambda1 - lambda2))), Float64(cos(phi1) + Float64(cos(phi2) * cos(Float64(-lambda2))))))
end
function tmp = code(lambda1, lambda2, phi1, phi2)
	tmp = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + (cos(phi2) * cos(-lambda2))));
end
code[lambda1_, lambda2_, phi1_, phi2_] := N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[phi1], $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * N[Cos[(-lambda2)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(-\lambda_2\right)}
Derivation
  1. Initial program 98.6%

    \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
  2. Taylor expanded in lambda1 around 0

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

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} \]
    2. lower-neg.f6497.9%

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(-\lambda_2\right)} \]
  4. Applied rewrites97.9%

    \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \color{blue}{\cos \left(-\lambda_2\right)}} \]
  5. Add Preprocessing

Alternative 5: 88.6% accurate, 0.8× speedup?

\[\begin{array}{l} t_0 := \cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)\\ t_1 := \cos \left(\lambda_1 - \lambda_2\right)\\ t_2 := \cos \phi_2 \cdot t\_1\\ \mathbf{if}\;\cos \phi_2 \leq -0.15:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(\lambda_2 \cdot \left(0.16666666666666666 \cdot \lambda_2\right) - 1\right)\right)}{\cos \phi_1 + t\_2}\\ \mathbf{elif}\;\cos \phi_2 \leq 0.9999999837576065:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{1 + t\_2}\\ \mathbf{else}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + t\_1}\\ \end{array} \]
(FPCore (lambda1 lambda2 phi1 phi2)
  :precision binary64
  (let* ((t_0 (* (cos phi2) (sin (- lambda1 lambda2))))
       (t_1 (cos (- lambda1 lambda2)))
       (t_2 (* (cos phi2) t_1)))
  (if (<= (cos phi2) -0.15)
    (+
     lambda1
     (atan2
      (*
       (cos phi2)
       (+
        lambda1
        (*
         lambda2
         (- (* lambda2 (* 0.16666666666666666 lambda2)) 1.0))))
      (+ (cos phi1) t_2)))
    (if (<= (cos phi2) 0.9999999837576065)
      (+ lambda1 (atan2 t_0 (+ 1.0 t_2)))
      (+ lambda1 (atan2 t_0 (+ (cos phi1) t_1)))))))
double code(double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = cos(phi2) * sin((lambda1 - lambda2));
	double t_1 = cos((lambda1 - lambda2));
	double t_2 = cos(phi2) * t_1;
	double tmp;
	if (cos(phi2) <= -0.15) {
		tmp = lambda1 + atan2((cos(phi2) * (lambda1 + (lambda2 * ((lambda2 * (0.16666666666666666 * lambda2)) - 1.0)))), (cos(phi1) + t_2));
	} else if (cos(phi2) <= 0.9999999837576065) {
		tmp = lambda1 + atan2(t_0, (1.0 + t_2));
	} else {
		tmp = lambda1 + atan2(t_0, (cos(phi1) + t_1));
	}
	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(lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
    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) :: tmp
    t_0 = cos(phi2) * sin((lambda1 - lambda2))
    t_1 = cos((lambda1 - lambda2))
    t_2 = cos(phi2) * t_1
    if (cos(phi2) <= (-0.15d0)) then
        tmp = lambda1 + atan2((cos(phi2) * (lambda1 + (lambda2 * ((lambda2 * (0.16666666666666666d0 * lambda2)) - 1.0d0)))), (cos(phi1) + t_2))
    else if (cos(phi2) <= 0.9999999837576065d0) then
        tmp = lambda1 + atan2(t_0, (1.0d0 + t_2))
    else
        tmp = lambda1 + atan2(t_0, (cos(phi1) + t_1))
    end if
    code = tmp
end function
public static double code(double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = Math.cos(phi2) * Math.sin((lambda1 - lambda2));
	double t_1 = Math.cos((lambda1 - lambda2));
	double t_2 = Math.cos(phi2) * t_1;
	double tmp;
	if (Math.cos(phi2) <= -0.15) {
		tmp = lambda1 + Math.atan2((Math.cos(phi2) * (lambda1 + (lambda2 * ((lambda2 * (0.16666666666666666 * lambda2)) - 1.0)))), (Math.cos(phi1) + t_2));
	} else if (Math.cos(phi2) <= 0.9999999837576065) {
		tmp = lambda1 + Math.atan2(t_0, (1.0 + t_2));
	} else {
		tmp = lambda1 + Math.atan2(t_0, (Math.cos(phi1) + t_1));
	}
	return tmp;
}
def code(lambda1, lambda2, phi1, phi2):
	t_0 = math.cos(phi2) * math.sin((lambda1 - lambda2))
	t_1 = math.cos((lambda1 - lambda2))
	t_2 = math.cos(phi2) * t_1
	tmp = 0
	if math.cos(phi2) <= -0.15:
		tmp = lambda1 + math.atan2((math.cos(phi2) * (lambda1 + (lambda2 * ((lambda2 * (0.16666666666666666 * lambda2)) - 1.0)))), (math.cos(phi1) + t_2))
	elif math.cos(phi2) <= 0.9999999837576065:
		tmp = lambda1 + math.atan2(t_0, (1.0 + t_2))
	else:
		tmp = lambda1 + math.atan2(t_0, (math.cos(phi1) + t_1))
	return tmp
function code(lambda1, lambda2, phi1, phi2)
	t_0 = Float64(cos(phi2) * sin(Float64(lambda1 - lambda2)))
	t_1 = cos(Float64(lambda1 - lambda2))
	t_2 = Float64(cos(phi2) * t_1)
	tmp = 0.0
	if (cos(phi2) <= -0.15)
		tmp = Float64(lambda1 + atan(Float64(cos(phi2) * Float64(lambda1 + Float64(lambda2 * Float64(Float64(lambda2 * Float64(0.16666666666666666 * lambda2)) - 1.0)))), Float64(cos(phi1) + t_2)));
	elseif (cos(phi2) <= 0.9999999837576065)
		tmp = Float64(lambda1 + atan(t_0, Float64(1.0 + t_2)));
	else
		tmp = Float64(lambda1 + atan(t_0, Float64(cos(phi1) + t_1)));
	end
	return tmp
end
function tmp_2 = code(lambda1, lambda2, phi1, phi2)
	t_0 = cos(phi2) * sin((lambda1 - lambda2));
	t_1 = cos((lambda1 - lambda2));
	t_2 = cos(phi2) * t_1;
	tmp = 0.0;
	if (cos(phi2) <= -0.15)
		tmp = lambda1 + atan2((cos(phi2) * (lambda1 + (lambda2 * ((lambda2 * (0.16666666666666666 * lambda2)) - 1.0)))), (cos(phi1) + t_2));
	elseif (cos(phi2) <= 0.9999999837576065)
		tmp = lambda1 + atan2(t_0, (1.0 + t_2));
	else
		tmp = lambda1 + atan2(t_0, (cos(phi1) + t_1));
	end
	tmp_2 = tmp;
end
code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Cos[phi2], $MachinePrecision] * t$95$1), $MachinePrecision]}, If[LessEqual[N[Cos[phi2], $MachinePrecision], -0.15], N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * N[(lambda1 + N[(lambda2 * N[(N[(lambda2 * N[(0.16666666666666666 * lambda2), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[phi1], $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Cos[phi2], $MachinePrecision], 0.9999999837576065], N[(lambda1 + N[ArcTan[t$95$0 / N[(1.0 + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(lambda1 + N[ArcTan[t$95$0 / N[(N[Cos[phi1], $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)\\
t_1 := \cos \left(\lambda_1 - \lambda_2\right)\\
t_2 := \cos \phi_2 \cdot t\_1\\
\mathbf{if}\;\cos \phi_2 \leq -0.15:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(\lambda_2 \cdot \left(0.16666666666666666 \cdot \lambda_2\right) - 1\right)\right)}{\cos \phi_1 + t\_2}\\

\mathbf{elif}\;\cos \phi_2 \leq 0.9999999837576065:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{1 + t\_2}\\

\mathbf{else}:\\
\;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + t\_1}\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (cos.f64 phi2) < -0.14999999999999999

    1. Initial program 98.6%

      \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    2. Taylor expanded in lambda1 around 0

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

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

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \left(\mathsf{neg}\left(\lambda_2\right)\right) + \color{blue}{\lambda_1} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      3. lower-neg.f64N/A

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \left(-\lambda_2\right) + \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      4. lower-*.f64N/A

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \left(-\lambda_2\right) + \lambda_1 \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)}\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      5. lower-cos.f64N/A

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \left(-\lambda_2\right) + \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      6. lower-neg.f6497.9%

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \left(-\lambda_2\right) + \lambda_1 \cdot \cos \left(-\lambda_2\right)\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    4. Applied rewrites97.9%

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \color{blue}{\left(\sin \left(-\lambda_2\right) + \lambda_1 \cdot \cos \left(-\lambda_2\right)\right)}}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    5. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(\lambda_2 \cdot \left(\frac{-1}{2} \cdot \lambda_1 + \frac{1}{6} \cdot \lambda_2\right) - 1\right)\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      7. lower-*.f6476.8%

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(\lambda_2 \cdot \left(-0.5 \cdot \lambda_1 + 0.16666666666666666 \cdot \lambda_2\right) - 1\right)\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    7. Applied rewrites76.8%

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\lambda_1 + \color{blue}{\lambda_2 \cdot \left(\lambda_2 \cdot \left(-0.5 \cdot \lambda_1 + 0.16666666666666666 \cdot \lambda_2\right) - 1\right)}\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    8. Taylor expanded in lambda1 around 0

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(\lambda_2 \cdot \left(\frac{1}{6} \cdot \lambda_2\right) - 1\right)\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    9. Step-by-step derivation
      1. lower-*.f6476.8%

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(\lambda_2 \cdot \left(0.16666666666666666 \cdot \lambda_2\right) - 1\right)\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    10. Applied rewrites76.8%

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(\lambda_2 \cdot \left(0.16666666666666666 \cdot \lambda_2\right) - 1\right)\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]

    if -0.14999999999999999 < (cos.f64 phi2) < 0.99999998375760646

    1. Initial program 98.6%

      \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    2. Taylor expanded in phi1 around 0

      \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{1} + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
    3. Step-by-step derivation
      1. Applied rewrites78.4%

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{1} + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]

      if 0.99999998375760646 < (cos.f64 phi2)

      1. Initial program 98.6%

        \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      2. Taylor expanded in phi2 around 0

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

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

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

          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
        4. lower--.f6478.1%

          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
      4. Applied rewrites78.1%

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}} \]
    4. Recombined 3 regimes into one program.
    5. Add Preprocessing

    Alternative 6: 88.1% accurate, 0.8× speedup?

    \[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ t_1 := \cos \phi_2 \cdot t\_0\\ t_2 := \cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\cos \phi_2 \leq -0.005:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\lambda_1 + \lambda_2 \cdot -1\right)}{\cos \phi_1 + t\_1}\\ \mathbf{elif}\;\cos \phi_2 \leq 0.9999999837576065:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_2}{1 + t\_1}\\ \mathbf{else}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_2}{\cos \phi_1 + t\_0}\\ \end{array} \]
    (FPCore (lambda1 lambda2 phi1 phi2)
      :precision binary64
      (let* ((t_0 (cos (- lambda1 lambda2)))
           (t_1 (* (cos phi2) t_0))
           (t_2 (* (cos phi2) (sin (- lambda1 lambda2)))))
      (if (<= (cos phi2) -0.005)
        (+
         lambda1
         (atan2
          (* (cos phi2) (+ lambda1 (* lambda2 -1.0)))
          (+ (cos phi1) t_1)))
        (if (<= (cos phi2) 0.9999999837576065)
          (+ lambda1 (atan2 t_2 (+ 1.0 t_1)))
          (+ lambda1 (atan2 t_2 (+ (cos phi1) t_0)))))))
    double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = cos((lambda1 - lambda2));
    	double t_1 = cos(phi2) * t_0;
    	double t_2 = cos(phi2) * sin((lambda1 - lambda2));
    	double tmp;
    	if (cos(phi2) <= -0.005) {
    		tmp = lambda1 + atan2((cos(phi2) * (lambda1 + (lambda2 * -1.0))), (cos(phi1) + t_1));
    	} else if (cos(phi2) <= 0.9999999837576065) {
    		tmp = lambda1 + atan2(t_2, (1.0 + t_1));
    	} else {
    		tmp = lambda1 + atan2(t_2, (cos(phi1) + t_0));
    	}
    	return tmp;
    }
    
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    real(8) function code(lambda1, lambda2, phi1, phi2)
    use fmin_fmax_functions
        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) :: tmp
        t_0 = cos((lambda1 - lambda2))
        t_1 = cos(phi2) * t_0
        t_2 = cos(phi2) * sin((lambda1 - lambda2))
        if (cos(phi2) <= (-0.005d0)) then
            tmp = lambda1 + atan2((cos(phi2) * (lambda1 + (lambda2 * (-1.0d0)))), (cos(phi1) + t_1))
        else if (cos(phi2) <= 0.9999999837576065d0) then
            tmp = lambda1 + atan2(t_2, (1.0d0 + t_1))
        else
            tmp = lambda1 + atan2(t_2, (cos(phi1) + t_0))
        end if
        code = tmp
    end function
    
    public static double code(double lambda1, double lambda2, double phi1, double phi2) {
    	double t_0 = Math.cos((lambda1 - lambda2));
    	double t_1 = Math.cos(phi2) * t_0;
    	double t_2 = Math.cos(phi2) * Math.sin((lambda1 - lambda2));
    	double tmp;
    	if (Math.cos(phi2) <= -0.005) {
    		tmp = lambda1 + Math.atan2((Math.cos(phi2) * (lambda1 + (lambda2 * -1.0))), (Math.cos(phi1) + t_1));
    	} else if (Math.cos(phi2) <= 0.9999999837576065) {
    		tmp = lambda1 + Math.atan2(t_2, (1.0 + t_1));
    	} else {
    		tmp = lambda1 + Math.atan2(t_2, (Math.cos(phi1) + t_0));
    	}
    	return tmp;
    }
    
    def code(lambda1, lambda2, phi1, phi2):
    	t_0 = math.cos((lambda1 - lambda2))
    	t_1 = math.cos(phi2) * t_0
    	t_2 = math.cos(phi2) * math.sin((lambda1 - lambda2))
    	tmp = 0
    	if math.cos(phi2) <= -0.005:
    		tmp = lambda1 + math.atan2((math.cos(phi2) * (lambda1 + (lambda2 * -1.0))), (math.cos(phi1) + t_1))
    	elif math.cos(phi2) <= 0.9999999837576065:
    		tmp = lambda1 + math.atan2(t_2, (1.0 + t_1))
    	else:
    		tmp = lambda1 + math.atan2(t_2, (math.cos(phi1) + t_0))
    	return tmp
    
    function code(lambda1, lambda2, phi1, phi2)
    	t_0 = cos(Float64(lambda1 - lambda2))
    	t_1 = Float64(cos(phi2) * t_0)
    	t_2 = Float64(cos(phi2) * sin(Float64(lambda1 - lambda2)))
    	tmp = 0.0
    	if (cos(phi2) <= -0.005)
    		tmp = Float64(lambda1 + atan(Float64(cos(phi2) * Float64(lambda1 + Float64(lambda2 * -1.0))), Float64(cos(phi1) + t_1)));
    	elseif (cos(phi2) <= 0.9999999837576065)
    		tmp = Float64(lambda1 + atan(t_2, Float64(1.0 + t_1)));
    	else
    		tmp = Float64(lambda1 + atan(t_2, Float64(cos(phi1) + t_0)));
    	end
    	return tmp
    end
    
    function tmp_2 = code(lambda1, lambda2, phi1, phi2)
    	t_0 = cos((lambda1 - lambda2));
    	t_1 = cos(phi2) * t_0;
    	t_2 = cos(phi2) * sin((lambda1 - lambda2));
    	tmp = 0.0;
    	if (cos(phi2) <= -0.005)
    		tmp = lambda1 + atan2((cos(phi2) * (lambda1 + (lambda2 * -1.0))), (cos(phi1) + t_1));
    	elseif (cos(phi2) <= 0.9999999837576065)
    		tmp = lambda1 + atan2(t_2, (1.0 + t_1));
    	else
    		tmp = lambda1 + atan2(t_2, (cos(phi1) + t_0));
    	end
    	tmp_2 = tmp;
    end
    
    code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[Cos[phi2], $MachinePrecision] * N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Cos[phi2], $MachinePrecision], -0.005], N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * N[(lambda1 + N[(lambda2 * -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[phi1], $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Cos[phi2], $MachinePrecision], 0.9999999837576065], N[(lambda1 + N[ArcTan[t$95$2 / N[(1.0 + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(lambda1 + N[ArcTan[t$95$2 / N[(N[Cos[phi1], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]
    
    \begin{array}{l}
    t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
    t_1 := \cos \phi_2 \cdot t\_0\\
    t_2 := \cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)\\
    \mathbf{if}\;\cos \phi_2 \leq -0.005:\\
    \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\lambda_1 + \lambda_2 \cdot -1\right)}{\cos \phi_1 + t\_1}\\
    
    \mathbf{elif}\;\cos \phi_2 \leq 0.9999999837576065:\\
    \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_2}{1 + t\_1}\\
    
    \mathbf{else}:\\
    \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_2}{\cos \phi_1 + t\_0}\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if (cos.f64 phi2) < -0.0050000000000000001

      1. Initial program 98.6%

        \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      2. Taylor expanded in lambda1 around 0

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

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

          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \left(\mathsf{neg}\left(\lambda_2\right)\right) + \color{blue}{\lambda_1} \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        3. lower-neg.f64N/A

          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \left(-\lambda_2\right) + \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        4. lower-*.f64N/A

          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \left(-\lambda_2\right) + \lambda_1 \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)}\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        5. lower-cos.f64N/A

          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \left(-\lambda_2\right) + \lambda_1 \cdot \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        6. lower-neg.f6497.9%

          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\sin \left(-\lambda_2\right) + \lambda_1 \cdot \cos \left(-\lambda_2\right)\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      4. Applied rewrites97.9%

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \color{blue}{\left(\sin \left(-\lambda_2\right) + \lambda_1 \cdot \cos \left(-\lambda_2\right)\right)}}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      5. Taylor expanded in lambda2 around 0

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

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

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

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

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

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

          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(\lambda_2 \cdot \left(\frac{-1}{2} \cdot \lambda_1 + \frac{1}{6} \cdot \lambda_2\right) - 1\right)\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        7. lower-*.f6476.8%

          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\lambda_1 + \lambda_2 \cdot \left(\lambda_2 \cdot \left(-0.5 \cdot \lambda_1 + 0.16666666666666666 \cdot \lambda_2\right) - 1\right)\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      7. Applied rewrites76.8%

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\lambda_1 + \color{blue}{\lambda_2 \cdot \left(\lambda_2 \cdot \left(-0.5 \cdot \lambda_1 + 0.16666666666666666 \cdot \lambda_2\right) - 1\right)}\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      8. Taylor expanded in lambda2 around 0

        \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\lambda_1 + \lambda_2 \cdot -1\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
      9. Step-by-step derivation
        1. Applied rewrites76.4%

          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \left(\lambda_1 + \lambda_2 \cdot -1\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]

        if -0.0050000000000000001 < (cos.f64 phi2) < 0.99999998375760646

        1. Initial program 98.6%

          \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        2. Taylor expanded in phi1 around 0

          \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{1} + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
        3. Step-by-step derivation
          1. Applied rewrites78.4%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{1} + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]

          if 0.99999998375760646 < (cos.f64 phi2)

          1. Initial program 98.6%

            \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          2. Taylor expanded in phi2 around 0

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

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

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            4. lower--.f6478.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          4. Applied rewrites78.1%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}} \]
        4. Recombined 3 regimes into one program.
        5. Add Preprocessing

        Alternative 7: 87.8% accurate, 0.9× speedup?

        \[\begin{array}{l} t_0 := \cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\cos \phi_2 \leq 0.94:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \cos \phi_2 \cdot \cos \lambda_1}\\ \mathbf{else}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}\\ \end{array} \]
        (FPCore (lambda1 lambda2 phi1 phi2)
          :precision binary64
          (let* ((t_0 (* (cos phi2) (sin (- lambda1 lambda2)))))
          (if (<= (cos phi2) 0.94)
            (+
             lambda1
             (atan2 t_0 (+ (cos phi1) (* (cos phi2) (cos lambda1)))))
            (+ lambda1 (atan2 t_0 (+ (cos phi1) (cos (- lambda1 lambda2))))))))
        double code(double lambda1, double lambda2, double phi1, double phi2) {
        	double t_0 = cos(phi2) * sin((lambda1 - lambda2));
        	double tmp;
        	if (cos(phi2) <= 0.94) {
        		tmp = lambda1 + atan2(t_0, (cos(phi1) + (cos(phi2) * cos(lambda1))));
        	} else {
        		tmp = lambda1 + atan2(t_0, (cos(phi1) + cos((lambda1 - lambda2))));
        	}
        	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(lambda1, lambda2, phi1, phi2)
        use fmin_fmax_functions
            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 = cos(phi2) * sin((lambda1 - lambda2))
            if (cos(phi2) <= 0.94d0) then
                tmp = lambda1 + atan2(t_0, (cos(phi1) + (cos(phi2) * cos(lambda1))))
            else
                tmp = lambda1 + atan2(t_0, (cos(phi1) + cos((lambda1 - lambda2))))
            end if
            code = tmp
        end function
        
        public static double code(double lambda1, double lambda2, double phi1, double phi2) {
        	double t_0 = Math.cos(phi2) * Math.sin((lambda1 - lambda2));
        	double tmp;
        	if (Math.cos(phi2) <= 0.94) {
        		tmp = lambda1 + Math.atan2(t_0, (Math.cos(phi1) + (Math.cos(phi2) * Math.cos(lambda1))));
        	} else {
        		tmp = lambda1 + Math.atan2(t_0, (Math.cos(phi1) + Math.cos((lambda1 - lambda2))));
        	}
        	return tmp;
        }
        
        def code(lambda1, lambda2, phi1, phi2):
        	t_0 = math.cos(phi2) * math.sin((lambda1 - lambda2))
        	tmp = 0
        	if math.cos(phi2) <= 0.94:
        		tmp = lambda1 + math.atan2(t_0, (math.cos(phi1) + (math.cos(phi2) * math.cos(lambda1))))
        	else:
        		tmp = lambda1 + math.atan2(t_0, (math.cos(phi1) + math.cos((lambda1 - lambda2))))
        	return tmp
        
        function code(lambda1, lambda2, phi1, phi2)
        	t_0 = Float64(cos(phi2) * sin(Float64(lambda1 - lambda2)))
        	tmp = 0.0
        	if (cos(phi2) <= 0.94)
        		tmp = Float64(lambda1 + atan(t_0, Float64(cos(phi1) + Float64(cos(phi2) * cos(lambda1)))));
        	else
        		tmp = Float64(lambda1 + atan(t_0, Float64(cos(phi1) + cos(Float64(lambda1 - lambda2)))));
        	end
        	return tmp
        end
        
        function tmp_2 = code(lambda1, lambda2, phi1, phi2)
        	t_0 = cos(phi2) * sin((lambda1 - lambda2));
        	tmp = 0.0;
        	if (cos(phi2) <= 0.94)
        		tmp = lambda1 + atan2(t_0, (cos(phi1) + (cos(phi2) * cos(lambda1))));
        	else
        		tmp = lambda1 + atan2(t_0, (cos(phi1) + cos((lambda1 - lambda2))));
        	end
        	tmp_2 = tmp;
        end
        
        code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Cos[phi2], $MachinePrecision], 0.94], N[(lambda1 + N[ArcTan[t$95$0 / N[(N[Cos[phi1], $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(lambda1 + N[ArcTan[t$95$0 / N[(N[Cos[phi1], $MachinePrecision] + N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
        
        \begin{array}{l}
        t_0 := \cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)\\
        \mathbf{if}\;\cos \phi_2 \leq 0.94:\\
        \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \cos \phi_2 \cdot \cos \lambda_1}\\
        
        \mathbf{else}:\\
        \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}\\
        
        
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (cos.f64 phi2) < 0.93999999999999995

          1. Initial program 98.6%

            \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          2. Taylor expanded in lambda2 around 0

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \color{blue}{\cos \lambda_1}} \]
          3. Step-by-step derivation
            1. lower-cos.f6479.8%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \lambda_1} \]
          4. Applied rewrites79.8%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \color{blue}{\cos \lambda_1}} \]

          if 0.93999999999999995 < (cos.f64 phi2)

          1. Initial program 98.6%

            \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          2. Taylor expanded in phi2 around 0

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

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

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            4. lower--.f6478.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          4. Applied rewrites78.1%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}} \]
        3. Recombined 2 regimes into one program.
        4. Add Preprocessing

        Alternative 8: 87.7% accurate, 1.0× speedup?

        \[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ t_1 := \cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\cos \phi_1 \leq 0.99998:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_1}{\cos \phi_1 + t\_0}\\ \mathbf{else}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_1}{1 + \cos \phi_2 \cdot t\_0}\\ \end{array} \]
        (FPCore (lambda1 lambda2 phi1 phi2)
          :precision binary64
          (let* ((t_0 (cos (- lambda1 lambda2)))
               (t_1 (* (cos phi2) (sin (- lambda1 lambda2)))))
          (if (<= (cos phi1) 0.99998)
            (+ lambda1 (atan2 t_1 (+ (cos phi1) t_0)))
            (+ lambda1 (atan2 t_1 (+ 1.0 (* (cos phi2) t_0)))))))
        double code(double lambda1, double lambda2, double phi1, double phi2) {
        	double t_0 = cos((lambda1 - lambda2));
        	double t_1 = cos(phi2) * sin((lambda1 - lambda2));
        	double tmp;
        	if (cos(phi1) <= 0.99998) {
        		tmp = lambda1 + atan2(t_1, (cos(phi1) + t_0));
        	} else {
        		tmp = lambda1 + atan2(t_1, (1.0 + (cos(phi2) * t_0)));
        	}
        	return tmp;
        }
        
        module fmin_fmax_functions
            implicit none
            private
            public fmax
            public fmin
        
            interface fmax
                module procedure fmax88
                module procedure fmax44
                module procedure fmax84
                module procedure fmax48
            end interface
            interface fmin
                module procedure fmin88
                module procedure fmin44
                module procedure fmin84
                module procedure fmin48
            end interface
        contains
            real(8) function fmax88(x, y) result (res)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
            end function
            real(4) function fmax44(x, y) result (res)
                real(4), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
            end function
            real(8) function fmax84(x, y) result(res)
                real(8), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
            end function
            real(8) function fmax48(x, y) result(res)
                real(4), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
            end function
            real(8) function fmin88(x, y) result (res)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
            end function
            real(4) function fmin44(x, y) result (res)
                real(4), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
            end function
            real(8) function fmin84(x, y) result(res)
                real(8), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
            end function
            real(8) function fmin48(x, y) result(res)
                real(4), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
            end function
        end module
        
        real(8) function code(lambda1, lambda2, phi1, phi2)
        use fmin_fmax_functions
            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 = cos((lambda1 - lambda2))
            t_1 = cos(phi2) * sin((lambda1 - lambda2))
            if (cos(phi1) <= 0.99998d0) then
                tmp = lambda1 + atan2(t_1, (cos(phi1) + t_0))
            else
                tmp = lambda1 + atan2(t_1, (1.0d0 + (cos(phi2) * t_0)))
            end if
            code = tmp
        end function
        
        public static double code(double lambda1, double lambda2, double phi1, double phi2) {
        	double t_0 = Math.cos((lambda1 - lambda2));
        	double t_1 = Math.cos(phi2) * Math.sin((lambda1 - lambda2));
        	double tmp;
        	if (Math.cos(phi1) <= 0.99998) {
        		tmp = lambda1 + Math.atan2(t_1, (Math.cos(phi1) + t_0));
        	} else {
        		tmp = lambda1 + Math.atan2(t_1, (1.0 + (Math.cos(phi2) * t_0)));
        	}
        	return tmp;
        }
        
        def code(lambda1, lambda2, phi1, phi2):
        	t_0 = math.cos((lambda1 - lambda2))
        	t_1 = math.cos(phi2) * math.sin((lambda1 - lambda2))
        	tmp = 0
        	if math.cos(phi1) <= 0.99998:
        		tmp = lambda1 + math.atan2(t_1, (math.cos(phi1) + t_0))
        	else:
        		tmp = lambda1 + math.atan2(t_1, (1.0 + (math.cos(phi2) * t_0)))
        	return tmp
        
        function code(lambda1, lambda2, phi1, phi2)
        	t_0 = cos(Float64(lambda1 - lambda2))
        	t_1 = Float64(cos(phi2) * sin(Float64(lambda1 - lambda2)))
        	tmp = 0.0
        	if (cos(phi1) <= 0.99998)
        		tmp = Float64(lambda1 + atan(t_1, Float64(cos(phi1) + t_0)));
        	else
        		tmp = Float64(lambda1 + atan(t_1, Float64(1.0 + Float64(cos(phi2) * t_0))));
        	end
        	return tmp
        end
        
        function tmp_2 = code(lambda1, lambda2, phi1, phi2)
        	t_0 = cos((lambda1 - lambda2));
        	t_1 = cos(phi2) * sin((lambda1 - lambda2));
        	tmp = 0.0;
        	if (cos(phi1) <= 0.99998)
        		tmp = lambda1 + atan2(t_1, (cos(phi1) + t_0));
        	else
        		tmp = lambda1 + atan2(t_1, (1.0 + (cos(phi2) * t_0)));
        	end
        	tmp_2 = tmp;
        end
        
        code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi2], $MachinePrecision] * N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Cos[phi1], $MachinePrecision], 0.99998], N[(lambda1 + N[ArcTan[t$95$1 / N[(N[Cos[phi1], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(lambda1 + N[ArcTan[t$95$1 / N[(1.0 + N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
        
        \begin{array}{l}
        t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
        t_1 := \cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)\\
        \mathbf{if}\;\cos \phi_1 \leq 0.99998:\\
        \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_1}{\cos \phi_1 + t\_0}\\
        
        \mathbf{else}:\\
        \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_1}{1 + \cos \phi_2 \cdot t\_0}\\
        
        
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (cos.f64 phi1) < 0.99997999999999998

          1. Initial program 98.6%

            \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          2. Taylor expanded in phi2 around 0

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

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

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            4. lower--.f6478.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          4. Applied rewrites78.1%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}} \]

          if 0.99997999999999998 < (cos.f64 phi1)

          1. Initial program 98.6%

            \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          2. Taylor expanded in phi1 around 0

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{1} + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          3. Step-by-step derivation
            1. Applied rewrites78.4%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{1} + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          4. Recombined 2 regimes into one program.
          5. Add Preprocessing

          Alternative 9: 78.1% accurate, 1.2× speedup?

          \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          (FPCore (lambda1 lambda2 phi1 phi2)
            :precision binary64
            (+
           lambda1
           (atan2
            (* (cos phi2) (sin (- lambda1 lambda2)))
            (+ (cos phi1) (cos (- lambda1 lambda2))))))
          double code(double lambda1, double lambda2, double phi1, double phi2) {
          	return lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + cos((lambda1 - lambda2))));
          }
          
          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(lambda1, lambda2, phi1, phi2)
          use fmin_fmax_functions
              real(8), intent (in) :: lambda1
              real(8), intent (in) :: lambda2
              real(8), intent (in) :: phi1
              real(8), intent (in) :: phi2
              code = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + cos((lambda1 - lambda2))))
          end function
          
          public static double code(double lambda1, double lambda2, double phi1, double phi2) {
          	return lambda1 + Math.atan2((Math.cos(phi2) * Math.sin((lambda1 - lambda2))), (Math.cos(phi1) + Math.cos((lambda1 - lambda2))));
          }
          
          def code(lambda1, lambda2, phi1, phi2):
          	return lambda1 + math.atan2((math.cos(phi2) * math.sin((lambda1 - lambda2))), (math.cos(phi1) + math.cos((lambda1 - lambda2))))
          
          function code(lambda1, lambda2, phi1, phi2)
          	return Float64(lambda1 + atan(Float64(cos(phi2) * sin(Float64(lambda1 - lambda2))), Float64(cos(phi1) + cos(Float64(lambda1 - lambda2)))))
          end
          
          function tmp = code(lambda1, lambda2, phi1, phi2)
          	tmp = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + cos((lambda1 - lambda2))));
          end
          
          code[lambda1_, lambda2_, phi1_, phi2_] := N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[phi1], $MachinePrecision] + N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
          
          \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}
          
          Derivation
          1. Initial program 98.6%

            \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          2. Taylor expanded in phi2 around 0

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

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

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            4. lower--.f6478.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          4. Applied rewrites78.1%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}} \]
          5. Add Preprocessing

          Alternative 10: 77.7% accurate, 1.2× speedup?

          \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(-\lambda_2\right)} \]
          (FPCore (lambda1 lambda2 phi1 phi2)
            :precision binary64
            (+
           lambda1
           (atan2
            (* (cos phi2) (sin (- lambda1 lambda2)))
            (+ (cos phi1) (cos (- lambda2))))))
          double code(double lambda1, double lambda2, double phi1, double phi2) {
          	return lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + cos(-lambda2)));
          }
          
          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(lambda1, lambda2, phi1, phi2)
          use fmin_fmax_functions
              real(8), intent (in) :: lambda1
              real(8), intent (in) :: lambda2
              real(8), intent (in) :: phi1
              real(8), intent (in) :: phi2
              code = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + cos(-lambda2)))
          end function
          
          public static double code(double lambda1, double lambda2, double phi1, double phi2) {
          	return lambda1 + Math.atan2((Math.cos(phi2) * Math.sin((lambda1 - lambda2))), (Math.cos(phi1) + Math.cos(-lambda2)));
          }
          
          def code(lambda1, lambda2, phi1, phi2):
          	return lambda1 + math.atan2((math.cos(phi2) * math.sin((lambda1 - lambda2))), (math.cos(phi1) + math.cos(-lambda2)))
          
          function code(lambda1, lambda2, phi1, phi2)
          	return Float64(lambda1 + atan(Float64(cos(phi2) * sin(Float64(lambda1 - lambda2))), Float64(cos(phi1) + cos(Float64(-lambda2)))))
          end
          
          function tmp = code(lambda1, lambda2, phi1, phi2)
          	tmp = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (cos(phi1) + cos(-lambda2)));
          end
          
          code[lambda1_, lambda2_, phi1_, phi2_] := N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[phi1], $MachinePrecision] + N[Cos[(-lambda2)], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
          
          \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(-\lambda_2\right)}
          
          Derivation
          1. Initial program 98.6%

            \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          2. Taylor expanded in phi2 around 0

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

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

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            4. lower--.f6478.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          4. Applied rewrites78.1%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}} \]
          5. Taylor expanded in phi1 around 0

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            2. lower-cos.f64N/A

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            3. lower--.f6468.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          7. Applied rewrites68.1%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)}} \]
          8. Taylor expanded in lambda1 around 0

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \color{blue}{\cos \left(\mathsf{neg}\left(\lambda_2\right)\right)}} \]
          9. Step-by-step derivation
            1. lower-+.f64N/A

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} \]
            3. lower-cos.f64N/A

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} \]
            4. lower-neg.f6477.7%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(-\lambda_2\right)} \]
          10. Applied rewrites77.7%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \color{blue}{\cos \left(-\lambda_2\right)}} \]
          11. Add Preprocessing

          Alternative 11: 75.4% accurate, 1.2× speedup?

          \[\begin{array}{l} t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\left|\phi_1\right| \leq 4 \cdot 10^{-12}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + t\_0}\\ \mathbf{else}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(-\lambda_2\right)}{\cos \left(\left|\phi_1\right|\right) + t\_0}\\ \end{array} \]
          (FPCore (lambda1 lambda2 phi1 phi2)
            :precision binary64
            (let* ((t_0 (cos (- lambda1 lambda2))))
            (if (<= (fabs phi1) 4e-12)
              (+
               lambda1
               (atan2 (* (cos phi2) (sin (- lambda1 lambda2))) (+ 1.0 t_0)))
              (+
               lambda1
               (atan2
                (* (cos phi2) (sin (- lambda2)))
                (+ (cos (fabs phi1)) t_0))))))
          double code(double lambda1, double lambda2, double phi1, double phi2) {
          	double t_0 = cos((lambda1 - lambda2));
          	double tmp;
          	if (fabs(phi1) <= 4e-12) {
          		tmp = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (1.0 + t_0));
          	} else {
          		tmp = lambda1 + atan2((cos(phi2) * sin(-lambda2)), (cos(fabs(phi1)) + t_0));
          	}
          	return tmp;
          }
          
          module fmin_fmax_functions
              implicit none
              private
              public fmax
              public fmin
          
              interface fmax
                  module procedure fmax88
                  module procedure fmax44
                  module procedure fmax84
                  module procedure fmax48
              end interface
              interface fmin
                  module procedure fmin88
                  module procedure fmin44
                  module procedure fmin84
                  module procedure fmin48
              end interface
          contains
              real(8) function fmax88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(4) function fmax44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(8) function fmax84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmax48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
              end function
              real(8) function fmin88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(4) function fmin44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(8) function fmin84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmin48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
              end function
          end module
          
          real(8) function code(lambda1, lambda2, phi1, phi2)
          use fmin_fmax_functions
              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 = cos((lambda1 - lambda2))
              if (abs(phi1) <= 4d-12) then
                  tmp = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (1.0d0 + t_0))
              else
                  tmp = lambda1 + atan2((cos(phi2) * sin(-lambda2)), (cos(abs(phi1)) + t_0))
              end if
              code = tmp
          end function
          
          public static double code(double lambda1, double lambda2, double phi1, double phi2) {
          	double t_0 = Math.cos((lambda1 - lambda2));
          	double tmp;
          	if (Math.abs(phi1) <= 4e-12) {
          		tmp = lambda1 + Math.atan2((Math.cos(phi2) * Math.sin((lambda1 - lambda2))), (1.0 + t_0));
          	} else {
          		tmp = lambda1 + Math.atan2((Math.cos(phi2) * Math.sin(-lambda2)), (Math.cos(Math.abs(phi1)) + t_0));
          	}
          	return tmp;
          }
          
          def code(lambda1, lambda2, phi1, phi2):
          	t_0 = math.cos((lambda1 - lambda2))
          	tmp = 0
          	if math.fabs(phi1) <= 4e-12:
          		tmp = lambda1 + math.atan2((math.cos(phi2) * math.sin((lambda1 - lambda2))), (1.0 + t_0))
          	else:
          		tmp = lambda1 + math.atan2((math.cos(phi2) * math.sin(-lambda2)), (math.cos(math.fabs(phi1)) + t_0))
          	return tmp
          
          function code(lambda1, lambda2, phi1, phi2)
          	t_0 = cos(Float64(lambda1 - lambda2))
          	tmp = 0.0
          	if (abs(phi1) <= 4e-12)
          		tmp = Float64(lambda1 + atan(Float64(cos(phi2) * sin(Float64(lambda1 - lambda2))), Float64(1.0 + t_0)));
          	else
          		tmp = Float64(lambda1 + atan(Float64(cos(phi2) * sin(Float64(-lambda2))), Float64(cos(abs(phi1)) + t_0)));
          	end
          	return tmp
          end
          
          function tmp_2 = code(lambda1, lambda2, phi1, phi2)
          	t_0 = cos((lambda1 - lambda2));
          	tmp = 0.0;
          	if (abs(phi1) <= 4e-12)
          		tmp = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (1.0 + t_0));
          	else
          		tmp = lambda1 + atan2((cos(phi2) * sin(-lambda2)), (cos(abs(phi1)) + t_0));
          	end
          	tmp_2 = tmp;
          end
          
          code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Abs[phi1], $MachinePrecision], 4e-12], N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(1.0 + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * N[Sin[(-lambda2)], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[N[Abs[phi1], $MachinePrecision]], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
          
          \begin{array}{l}
          t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
          \mathbf{if}\;\left|\phi_1\right| \leq 4 \cdot 10^{-12}:\\
          \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + t\_0}\\
          
          \mathbf{else}:\\
          \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(-\lambda_2\right)}{\cos \left(\left|\phi_1\right|\right) + t\_0}\\
          
          
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if phi1 < 3.9999999999999999e-12

            1. Initial program 98.6%

              \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
            2. Taylor expanded in phi2 around 0

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

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

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

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
              4. lower--.f6478.1%

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            4. Applied rewrites78.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}} \]
            5. Taylor expanded in phi1 around 0

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

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
              2. lower-cos.f64N/A

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
              3. lower--.f6468.1%

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            7. Applied rewrites68.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)}} \]

            if 3.9999999999999999e-12 < phi1

            1. Initial program 98.6%

              \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
            2. Taylor expanded in phi2 around 0

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

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

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

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
              4. lower--.f6478.1%

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            4. Applied rewrites78.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}} \]
            5. Taylor expanded in lambda1 around 0

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

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
              2. lower-neg.f6472.3%

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(-\lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            7. Applied rewrites72.3%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \color{blue}{\sin \left(-\lambda_2\right)}}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          3. Recombined 2 regimes into one program.
          4. Add Preprocessing

          Alternative 12: 71.6% accurate, 1.0× speedup?

          \[\begin{array}{l} t_0 := \cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\cos \phi_1 \leq 0.43:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \lambda_1 + \cos \phi_1}\\ \mathbf{else}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{1 + \cos \left(\lambda_1 - \lambda_2\right)}\\ \end{array} \]
          (FPCore (lambda1 lambda2 phi1 phi2)
            :precision binary64
            (let* ((t_0 (* (cos phi2) (sin (- lambda1 lambda2)))))
            (if (<= (cos phi1) 0.43)
              (+ lambda1 (atan2 t_0 (+ (cos lambda1) (cos phi1))))
              (+ lambda1 (atan2 t_0 (+ 1.0 (cos (- lambda1 lambda2))))))))
          double code(double lambda1, double lambda2, double phi1, double phi2) {
          	double t_0 = cos(phi2) * sin((lambda1 - lambda2));
          	double tmp;
          	if (cos(phi1) <= 0.43) {
          		tmp = lambda1 + atan2(t_0, (cos(lambda1) + cos(phi1)));
          	} else {
          		tmp = lambda1 + atan2(t_0, (1.0 + cos((lambda1 - lambda2))));
          	}
          	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(lambda1, lambda2, phi1, phi2)
          use fmin_fmax_functions
              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 = cos(phi2) * sin((lambda1 - lambda2))
              if (cos(phi1) <= 0.43d0) then
                  tmp = lambda1 + atan2(t_0, (cos(lambda1) + cos(phi1)))
              else
                  tmp = lambda1 + atan2(t_0, (1.0d0 + cos((lambda1 - lambda2))))
              end if
              code = tmp
          end function
          
          public static double code(double lambda1, double lambda2, double phi1, double phi2) {
          	double t_0 = Math.cos(phi2) * Math.sin((lambda1 - lambda2));
          	double tmp;
          	if (Math.cos(phi1) <= 0.43) {
          		tmp = lambda1 + Math.atan2(t_0, (Math.cos(lambda1) + Math.cos(phi1)));
          	} else {
          		tmp = lambda1 + Math.atan2(t_0, (1.0 + Math.cos((lambda1 - lambda2))));
          	}
          	return tmp;
          }
          
          def code(lambda1, lambda2, phi1, phi2):
          	t_0 = math.cos(phi2) * math.sin((lambda1 - lambda2))
          	tmp = 0
          	if math.cos(phi1) <= 0.43:
          		tmp = lambda1 + math.atan2(t_0, (math.cos(lambda1) + math.cos(phi1)))
          	else:
          		tmp = lambda1 + math.atan2(t_0, (1.0 + math.cos((lambda1 - lambda2))))
          	return tmp
          
          function code(lambda1, lambda2, phi1, phi2)
          	t_0 = Float64(cos(phi2) * sin(Float64(lambda1 - lambda2)))
          	tmp = 0.0
          	if (cos(phi1) <= 0.43)
          		tmp = Float64(lambda1 + atan(t_0, Float64(cos(lambda1) + cos(phi1))));
          	else
          		tmp = Float64(lambda1 + atan(t_0, Float64(1.0 + cos(Float64(lambda1 - lambda2)))));
          	end
          	return tmp
          end
          
          function tmp_2 = code(lambda1, lambda2, phi1, phi2)
          	t_0 = cos(phi2) * sin((lambda1 - lambda2));
          	tmp = 0.0;
          	if (cos(phi1) <= 0.43)
          		tmp = lambda1 + atan2(t_0, (cos(lambda1) + cos(phi1)));
          	else
          		tmp = lambda1 + atan2(t_0, (1.0 + cos((lambda1 - lambda2))));
          	end
          	tmp_2 = tmp;
          end
          
          code[lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Cos[phi1], $MachinePrecision], 0.43], N[(lambda1 + N[ArcTan[t$95$0 / N[(N[Cos[lambda1], $MachinePrecision] + N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(lambda1 + N[ArcTan[t$95$0 / N[(1.0 + N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
          
          \begin{array}{l}
          t_0 := \cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)\\
          \mathbf{if}\;\cos \phi_1 \leq 0.43:\\
          \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{\cos \lambda_1 + \cos \phi_1}\\
          
          \mathbf{else}:\\
          \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t\_0}{1 + \cos \left(\lambda_1 - \lambda_2\right)}\\
          
          
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (cos.f64 phi1) < 0.42999999999999999

            1. Initial program 98.6%

              \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
            2. Taylor expanded in phi2 around 0

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

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

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

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
              4. lower--.f6478.1%

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            4. Applied rewrites78.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}} \]
            5. Taylor expanded in phi1 around 0

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

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
              2. lower-cos.f64N/A

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
              3. lower--.f6468.1%

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            7. Applied rewrites68.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)}} \]
            8. Taylor expanded in lambda2 around 0

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \lambda_1} \]
            9. Step-by-step derivation
              1. lower-+.f64N/A

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \lambda_1} \]
              2. lower-cos.f6463.2%

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \lambda_1} \]
            10. Applied rewrites63.2%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \lambda_1} \]
            11. Taylor expanded in lambda2 around 0

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

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

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \lambda_1 + \cos \phi_1} \]
              3. lower-cos.f6468.2%

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \lambda_1 + \cos \phi_1} \]
            13. Applied rewrites68.2%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \lambda_1 + \color{blue}{\cos \phi_1}} \]

            if 0.42999999999999999 < (cos.f64 phi1)

            1. Initial program 98.6%

              \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
            2. Taylor expanded in phi2 around 0

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

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

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

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
              4. lower--.f6478.1%

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            4. Applied rewrites78.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}} \]
            5. Taylor expanded in phi1 around 0

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

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
              2. lower-cos.f64N/A

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
              3. lower--.f6468.1%

                \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            7. Applied rewrites68.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)}} \]
          3. Recombined 2 regimes into one program.
          4. Add Preprocessing

          Alternative 13: 68.1% accurate, 1.5× speedup?

          \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          (FPCore (lambda1 lambda2 phi1 phi2)
            :precision binary64
            (+
           lambda1
           (atan2
            (* (cos phi2) (sin (- lambda1 lambda2)))
            (+ 1.0 (cos (- lambda1 lambda2))))))
          double code(double lambda1, double lambda2, double phi1, double phi2) {
          	return lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (1.0 + cos((lambda1 - lambda2))));
          }
          
          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(lambda1, lambda2, phi1, phi2)
          use fmin_fmax_functions
              real(8), intent (in) :: lambda1
              real(8), intent (in) :: lambda2
              real(8), intent (in) :: phi1
              real(8), intent (in) :: phi2
              code = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (1.0d0 + cos((lambda1 - lambda2))))
          end function
          
          public static double code(double lambda1, double lambda2, double phi1, double phi2) {
          	return lambda1 + Math.atan2((Math.cos(phi2) * Math.sin((lambda1 - lambda2))), (1.0 + Math.cos((lambda1 - lambda2))));
          }
          
          def code(lambda1, lambda2, phi1, phi2):
          	return lambda1 + math.atan2((math.cos(phi2) * math.sin((lambda1 - lambda2))), (1.0 + math.cos((lambda1 - lambda2))))
          
          function code(lambda1, lambda2, phi1, phi2)
          	return Float64(lambda1 + atan(Float64(cos(phi2) * sin(Float64(lambda1 - lambda2))), Float64(1.0 + cos(Float64(lambda1 - lambda2)))))
          end
          
          function tmp = code(lambda1, lambda2, phi1, phi2)
          	tmp = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (1.0 + cos((lambda1 - lambda2))));
          end
          
          code[lambda1_, lambda2_, phi1_, phi2_] := N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
          
          \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)}
          
          Derivation
          1. Initial program 98.6%

            \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          2. Taylor expanded in phi2 around 0

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

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

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            4. lower--.f6478.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          4. Applied rewrites78.1%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}} \]
          5. Taylor expanded in phi1 around 0

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            2. lower-cos.f64N/A

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            3. lower--.f6468.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          7. Applied rewrites68.1%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)}} \]
          8. Add Preprocessing

          Alternative 14: 68.0% accurate, 1.5× speedup?

          \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(-\lambda_2\right)} \]
          (FPCore (lambda1 lambda2 phi1 phi2)
            :precision binary64
            (+
           lambda1
           (atan2
            (* (cos phi2) (sin (- lambda1 lambda2)))
            (+ 1.0 (cos (- lambda2))))))
          double code(double lambda1, double lambda2, double phi1, double phi2) {
          	return lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (1.0 + cos(-lambda2)));
          }
          
          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(lambda1, lambda2, phi1, phi2)
          use fmin_fmax_functions
              real(8), intent (in) :: lambda1
              real(8), intent (in) :: lambda2
              real(8), intent (in) :: phi1
              real(8), intent (in) :: phi2
              code = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (1.0d0 + cos(-lambda2)))
          end function
          
          public static double code(double lambda1, double lambda2, double phi1, double phi2) {
          	return lambda1 + Math.atan2((Math.cos(phi2) * Math.sin((lambda1 - lambda2))), (1.0 + Math.cos(-lambda2)));
          }
          
          def code(lambda1, lambda2, phi1, phi2):
          	return lambda1 + math.atan2((math.cos(phi2) * math.sin((lambda1 - lambda2))), (1.0 + math.cos(-lambda2)))
          
          function code(lambda1, lambda2, phi1, phi2)
          	return Float64(lambda1 + atan(Float64(cos(phi2) * sin(Float64(lambda1 - lambda2))), Float64(1.0 + cos(Float64(-lambda2)))))
          end
          
          function tmp = code(lambda1, lambda2, phi1, phi2)
          	tmp = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (1.0 + cos(-lambda2)));
          end
          
          code[lambda1_, lambda2_, phi1_, phi2_] := N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Cos[(-lambda2)], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
          
          \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(-\lambda_2\right)}
          
          Derivation
          1. Initial program 98.6%

            \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          2. Taylor expanded in phi2 around 0

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

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

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            4. lower--.f6478.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          4. Applied rewrites78.1%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}} \]
          5. Taylor expanded in phi1 around 0

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            2. lower-cos.f64N/A

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            3. lower--.f6468.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          7. Applied rewrites68.1%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)}} \]
          8. Taylor expanded in lambda2 around 0

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \lambda_1} \]
          9. Step-by-step derivation
            1. lower-+.f64N/A

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \lambda_1} \]
            2. lower-cos.f6463.2%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \lambda_1} \]
          10. Applied rewrites63.2%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \lambda_1} \]
          11. Taylor expanded in lambda1 around 0

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} \]
          12. Step-by-step derivation
            1. lower-+.f64N/A

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} \]
            2. lower-cos.f64N/A

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\mathsf{neg}\left(\lambda_2\right)\right)} \]
            3. lower-neg.f6468.0%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(-\lambda_2\right)} \]
          13. Applied rewrites68.0%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(-\lambda_2\right)} \]
          14. Add Preprocessing

          Alternative 15: 64.8% accurate, 1.5× speedup?

          \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(-\lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          (FPCore (lambda1 lambda2 phi1 phi2)
            :precision binary64
            (+
           lambda1
           (atan2
            (* (cos phi2) (sin (- lambda2)))
            (+ 1.0 (cos (- lambda1 lambda2))))))
          double code(double lambda1, double lambda2, double phi1, double phi2) {
          	return lambda1 + atan2((cos(phi2) * sin(-lambda2)), (1.0 + cos((lambda1 - lambda2))));
          }
          
          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(lambda1, lambda2, phi1, phi2)
          use fmin_fmax_functions
              real(8), intent (in) :: lambda1
              real(8), intent (in) :: lambda2
              real(8), intent (in) :: phi1
              real(8), intent (in) :: phi2
              code = lambda1 + atan2((cos(phi2) * sin(-lambda2)), (1.0d0 + cos((lambda1 - lambda2))))
          end function
          
          public static double code(double lambda1, double lambda2, double phi1, double phi2) {
          	return lambda1 + Math.atan2((Math.cos(phi2) * Math.sin(-lambda2)), (1.0 + Math.cos((lambda1 - lambda2))));
          }
          
          def code(lambda1, lambda2, phi1, phi2):
          	return lambda1 + math.atan2((math.cos(phi2) * math.sin(-lambda2)), (1.0 + math.cos((lambda1 - lambda2))))
          
          function code(lambda1, lambda2, phi1, phi2)
          	return Float64(lambda1 + atan(Float64(cos(phi2) * sin(Float64(-lambda2))), Float64(1.0 + cos(Float64(lambda1 - lambda2)))))
          end
          
          function tmp = code(lambda1, lambda2, phi1, phi2)
          	tmp = lambda1 + atan2((cos(phi2) * sin(-lambda2)), (1.0 + cos((lambda1 - lambda2))));
          end
          
          code[lambda1_, lambda2_, phi1_, phi2_] := N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * N[Sin[(-lambda2)], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
          
          \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(-\lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)}
          
          Derivation
          1. Initial program 98.6%

            \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          2. Taylor expanded in phi2 around 0

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

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

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            4. lower--.f6478.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          4. Applied rewrites78.1%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}} \]
          5. Taylor expanded in phi1 around 0

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            2. lower-cos.f64N/A

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            3. lower--.f6468.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          7. Applied rewrites68.1%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)}} \]
          8. Taylor expanded in lambda1 around 0

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \color{blue}{\sin \left(\mathsf{neg}\left(\lambda_2\right)\right)}}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          9. Step-by-step derivation
            1. lower-sin.f64N/A

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\mathsf{neg}\left(\lambda_2\right)\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            2. lower-neg.f6464.8%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(-\lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          10. Applied rewrites64.8%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \color{blue}{\sin \left(-\lambda_2\right)}}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          11. Add Preprocessing

          Alternative 16: 63.2% accurate, 1.5× speedup?

          \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \lambda_1} \]
          (FPCore (lambda1 lambda2 phi1 phi2)
            :precision binary64
            (+
           lambda1
           (atan2
            (* (cos phi2) (sin (- lambda1 lambda2)))
            (+ 1.0 (cos lambda1)))))
          double code(double lambda1, double lambda2, double phi1, double phi2) {
          	return lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (1.0 + cos(lambda1)));
          }
          
          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(lambda1, lambda2, phi1, phi2)
          use fmin_fmax_functions
              real(8), intent (in) :: lambda1
              real(8), intent (in) :: lambda2
              real(8), intent (in) :: phi1
              real(8), intent (in) :: phi2
              code = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (1.0d0 + cos(lambda1)))
          end function
          
          public static double code(double lambda1, double lambda2, double phi1, double phi2) {
          	return lambda1 + Math.atan2((Math.cos(phi2) * Math.sin((lambda1 - lambda2))), (1.0 + Math.cos(lambda1)));
          }
          
          def code(lambda1, lambda2, phi1, phi2):
          	return lambda1 + math.atan2((math.cos(phi2) * math.sin((lambda1 - lambda2))), (1.0 + math.cos(lambda1)))
          
          function code(lambda1, lambda2, phi1, phi2)
          	return Float64(lambda1 + atan(Float64(cos(phi2) * sin(Float64(lambda1 - lambda2))), Float64(1.0 + cos(lambda1))))
          end
          
          function tmp = code(lambda1, lambda2, phi1, phi2)
          	tmp = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), (1.0 + cos(lambda1)));
          end
          
          code[lambda1_, lambda2_, phi1_, phi2_] := N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
          
          \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \lambda_1}
          
          Derivation
          1. Initial program 98.6%

            \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          2. Taylor expanded in phi2 around 0

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

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

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            4. lower--.f6478.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          4. Applied rewrites78.1%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}} \]
          5. Taylor expanded in phi1 around 0

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            2. lower-cos.f64N/A

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            3. lower--.f6468.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          7. Applied rewrites68.1%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)}} \]
          8. Taylor expanded in lambda2 around 0

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \lambda_1} \]
          9. Step-by-step derivation
            1. lower-+.f64N/A

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \lambda_1} \]
            2. lower-cos.f6463.2%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \lambda_1} \]
          10. Applied rewrites63.2%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \lambda_1} \]
          11. Add Preprocessing

          Alternative 17: 63.1% accurate, 2.0× speedup?

          \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{2} \]
          (FPCore (lambda1 lambda2 phi1 phi2)
            :precision binary64
            (+ lambda1 (atan2 (* (cos phi2) (sin (- lambda1 lambda2))) 2.0)))
          double code(double lambda1, double lambda2, double phi1, double phi2) {
          	return lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), 2.0);
          }
          
          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(lambda1, lambda2, phi1, phi2)
          use fmin_fmax_functions
              real(8), intent (in) :: lambda1
              real(8), intent (in) :: lambda2
              real(8), intent (in) :: phi1
              real(8), intent (in) :: phi2
              code = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), 2.0d0)
          end function
          
          public static double code(double lambda1, double lambda2, double phi1, double phi2) {
          	return lambda1 + Math.atan2((Math.cos(phi2) * Math.sin((lambda1 - lambda2))), 2.0);
          }
          
          def code(lambda1, lambda2, phi1, phi2):
          	return lambda1 + math.atan2((math.cos(phi2) * math.sin((lambda1 - lambda2))), 2.0)
          
          function code(lambda1, lambda2, phi1, phi2)
          	return Float64(lambda1 + atan(Float64(cos(phi2) * sin(Float64(lambda1 - lambda2))), 2.0))
          end
          
          function tmp = code(lambda1, lambda2, phi1, phi2)
          	tmp = lambda1 + atan2((cos(phi2) * sin((lambda1 - lambda2))), 2.0);
          end
          
          code[lambda1_, lambda2_, phi1_, phi2_] := N[(lambda1 + N[ArcTan[N[(N[Cos[phi2], $MachinePrecision] * N[Sin[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0], $MachinePrecision]), $MachinePrecision]
          
          \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{2}
          
          Derivation
          1. Initial program 98.6%

            \[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)} \]
          2. Taylor expanded in phi2 around 0

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

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

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            4. lower--.f6478.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          4. Applied rewrites78.1%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{\color{blue}{\cos \phi_1 + \cos \left(\lambda_1 - \lambda_2\right)}} \]
          5. Taylor expanded in phi1 around 0

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

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            2. lower-cos.f64N/A

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
            3. lower--.f6468.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \left(\lambda_1 - \lambda_2\right)} \]
          7. Applied rewrites68.1%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \color{blue}{\cos \left(\lambda_1 - \lambda_2\right)}} \]
          8. Taylor expanded in lambda2 around 0

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \lambda_1} \]
          9. Step-by-step derivation
            1. lower-+.f64N/A

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \lambda_1} \]
            2. lower-cos.f6463.2%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \lambda_1} \]
          10. Applied rewrites63.2%

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{1 + \cos \lambda_1} \]
          11. Taylor expanded in lambda1 around 0

            \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{2} \]
          12. Step-by-step derivation
            1. Applied rewrites63.1%

              \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\cos \phi_2 \cdot \sin \left(\lambda_1 - \lambda_2\right)}{2} \]
            2. Add Preprocessing

            Reproduce

            ?
            herbie shell --seed 2025258 
            (FPCore (lambda1 lambda2 phi1 phi2)
              :name "Midpoint on a great circle"
              :precision binary64
              (+ lambda1 (atan2 (* (cos phi2) (sin (- lambda1 lambda2))) (+ (cos phi1) (* (cos phi2) (cos (- lambda1 lambda2)))))))