
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
(t_1
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* (* (* (cos phi1) (cos phi2)) t_0) t_0))))
(* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
double t_1 = pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0);
return R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
t_0 = sin(((lambda1 - lambda2) / 2.0d0))
t_1 = (sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0)
code = r * (2.0d0 * atan2(sqrt(t_1), sqrt((1.0d0 - t_1))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.sin(((lambda1 - lambda2) / 2.0));
double t_1 = Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (((Math.cos(phi1) * Math.cos(phi2)) * t_0) * t_0);
return R * (2.0 * Math.atan2(Math.sqrt(t_1), Math.sqrt((1.0 - t_1))));
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((lambda1 - lambda2) / 2.0)) t_1 = math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (((math.cos(phi1) * math.cos(phi2)) * t_0) * t_0) return R * (2.0 * math.atan2(math.sqrt(t_1), math.sqrt((1.0 - t_1))))
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_0) * t_0)) return Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(((lambda1 - lambda2) / 2.0)); t_1 = (sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0); tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1)))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$1], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_0\right) \cdot t\_0\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right)
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 14 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
(t_1
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* (* (* (cos phi1) (cos phi2)) t_0) t_0))))
(* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
double t_1 = pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0);
return R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
t_0 = sin(((lambda1 - lambda2) / 2.0d0))
t_1 = (sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0)
code = r * (2.0d0 * atan2(sqrt(t_1), sqrt((1.0d0 - t_1))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.sin(((lambda1 - lambda2) / 2.0));
double t_1 = Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (((Math.cos(phi1) * Math.cos(phi2)) * t_0) * t_0);
return R * (2.0 * Math.atan2(Math.sqrt(t_1), Math.sqrt((1.0 - t_1))));
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((lambda1 - lambda2) / 2.0)) t_1 = math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (((math.cos(phi1) * math.cos(phi2)) * t_0) * t_0) return R * (2.0 * math.atan2(math.sqrt(t_1), math.sqrt((1.0 - t_1))))
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_0) * t_0)) return Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(((lambda1 - lambda2) / 2.0)); t_1 = (sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0); tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1)))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$1], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_0\right) \cdot t\_0\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right)
\end{array}
\end{array}
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi2) (cos phi1)))
(t_1 (- 1.0 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)))
(t_2
(pow
(-
(* (sin (/ phi1 2.0)) (cos (/ phi2 2.0)))
(* (cos (/ phi1 2.0)) (sin (/ phi2 2.0))))
2.0))
(t_3 (sin (/ (- lambda1 lambda2) 2.0)))
(t_4 (* (pow t_3 2.0) t_0)))
(*
R
(*
2.0
(atan2
(sqrt (+ t_2 (* (* (* (cos phi1) (cos phi2)) t_3) t_3)))
(sqrt
(/
(-
(pow (- 1.0 t_2) 3.0)
(pow
(*
(pow
(-
(* (sin (/ lambda1 2.0)) (cos (/ lambda2 2.0)))
(* (cos (/ lambda1 2.0)) (sin (/ lambda2 2.0))))
2.0)
t_0)
3.0))
(fma t_1 t_1 (+ (pow t_4 2.0) (* t_1 t_4))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi2) * cos(phi1);
double t_1 = 1.0 - pow(sin(((phi1 - phi2) / 2.0)), 2.0);
double t_2 = pow(((sin((phi1 / 2.0)) * cos((phi2 / 2.0))) - (cos((phi1 / 2.0)) * sin((phi2 / 2.0)))), 2.0);
double t_3 = sin(((lambda1 - lambda2) / 2.0));
double t_4 = pow(t_3, 2.0) * t_0;
return R * (2.0 * atan2(sqrt((t_2 + (((cos(phi1) * cos(phi2)) * t_3) * t_3))), sqrt(((pow((1.0 - t_2), 3.0) - pow((pow(((sin((lambda1 / 2.0)) * cos((lambda2 / 2.0))) - (cos((lambda1 / 2.0)) * sin((lambda2 / 2.0)))), 2.0) * t_0), 3.0)) / fma(t_1, t_1, (pow(t_4, 2.0) + (t_1 * t_4)))))));
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi2) * cos(phi1)) t_1 = Float64(1.0 - (sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0)) t_2 = Float64(Float64(sin(Float64(phi1 / 2.0)) * cos(Float64(phi2 / 2.0))) - Float64(cos(Float64(phi1 / 2.0)) * sin(Float64(phi2 / 2.0)))) ^ 2.0 t_3 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_4 = Float64((t_3 ^ 2.0) * t_0) return Float64(R * Float64(2.0 * atan(sqrt(Float64(t_2 + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_3) * t_3))), sqrt(Float64(Float64((Float64(1.0 - t_2) ^ 3.0) - (Float64((Float64(Float64(sin(Float64(lambda1 / 2.0)) * cos(Float64(lambda2 / 2.0))) - Float64(cos(Float64(lambda1 / 2.0)) * sin(Float64(lambda2 / 2.0)))) ^ 2.0) * t_0) ^ 3.0)) / fma(t_1, t_1, Float64((t_4 ^ 2.0) + Float64(t_1 * t_4)))))))) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 - N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[(N[(N[Sin[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[(N[Power[t$95$3, 2.0], $MachinePrecision] * t$95$0), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$2 + N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$3), $MachinePrecision] * t$95$3), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(N[Power[N[(1.0 - t$95$2), $MachinePrecision], 3.0], $MachinePrecision] - N[Power[N[(N[Power[N[(N[(N[Sin[N[(lambda1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(lambda2 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[N[(lambda1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(lambda2 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * t$95$0), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] / N[(t$95$1 * t$95$1 + N[(N[Power[t$95$4, 2.0], $MachinePrecision] + N[(t$95$1 * t$95$4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \phi_1\\
t_1 := 1 - {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
t_2 := {\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2}\\
t_3 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_4 := {t\_3}^{2} \cdot t\_0\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_2 + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_3\right) \cdot t\_3}}{\sqrt{\frac{{\left(1 - t\_2\right)}^{3} - {\left({\left(\sin \left(\frac{\lambda_1}{2}\right) \cdot \cos \left(\frac{\lambda_2}{2}\right) - \cos \left(\frac{\lambda_1}{2}\right) \cdot \sin \left(\frac{\lambda_2}{2}\right)\right)}^{2} \cdot t\_0\right)}^{3}}{\mathsf{fma}\left(t\_1, t\_1, {t\_4}^{2} + t\_1 \cdot t\_4\right)}}}\right)
\end{array}
\end{array}
Initial program 64.1%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-/.f6465.1
Applied rewrites65.1%
lift--.f64N/A
lift-+.f64N/A
associate--r+N/A
flip3--N/A
Applied rewrites65.0%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-/.f6465.2
Applied rewrites65.2%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-/.f6465.5
Applied rewrites65.5%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (- 1.0 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)))
(t_1 (* (cos phi2) (cos phi1)))
(t_2 (sin (/ (- lambda1 lambda2) 2.0)))
(t_3 (* (pow t_2 2.0) t_1)))
(*
R
(*
2.0
(atan2
(sqrt
(+
(pow
(-
(* (sin (/ phi1 2.0)) (cos (/ phi2 2.0)))
(* (cos (/ phi1 2.0)) (sin (/ phi2 2.0))))
2.0)
(* (* (* (cos phi1) (cos phi2)) t_2) t_2)))
(sqrt
(/
(-
(pow t_0 3.0)
(pow
(*
(pow
(-
(* (sin (/ lambda1 2.0)) (cos (/ lambda2 2.0)))
(* (cos (/ lambda1 2.0)) (sin (/ lambda2 2.0))))
2.0)
t_1)
3.0))
(fma t_0 t_0 (+ (pow t_3 2.0) (* t_0 t_3))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = 1.0 - pow(sin(((phi1 - phi2) / 2.0)), 2.0);
double t_1 = cos(phi2) * cos(phi1);
double t_2 = sin(((lambda1 - lambda2) / 2.0));
double t_3 = pow(t_2, 2.0) * t_1;
return R * (2.0 * atan2(sqrt((pow(((sin((phi1 / 2.0)) * cos((phi2 / 2.0))) - (cos((phi1 / 2.0)) * sin((phi2 / 2.0)))), 2.0) + (((cos(phi1) * cos(phi2)) * t_2) * t_2))), sqrt(((pow(t_0, 3.0) - pow((pow(((sin((lambda1 / 2.0)) * cos((lambda2 / 2.0))) - (cos((lambda1 / 2.0)) * sin((lambda2 / 2.0)))), 2.0) * t_1), 3.0)) / fma(t_0, t_0, (pow(t_3, 2.0) + (t_0 * t_3)))))));
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(1.0 - (sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0)) t_1 = Float64(cos(phi2) * cos(phi1)) t_2 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_3 = Float64((t_2 ^ 2.0) * t_1) return Float64(R * Float64(2.0 * atan(sqrt(Float64((Float64(Float64(sin(Float64(phi1 / 2.0)) * cos(Float64(phi2 / 2.0))) - Float64(cos(Float64(phi1 / 2.0)) * sin(Float64(phi2 / 2.0)))) ^ 2.0) + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_2) * t_2))), sqrt(Float64(Float64((t_0 ^ 3.0) - (Float64((Float64(Float64(sin(Float64(lambda1 / 2.0)) * cos(Float64(lambda2 / 2.0))) - Float64(cos(Float64(lambda1 / 2.0)) * sin(Float64(lambda2 / 2.0)))) ^ 2.0) * t_1) ^ 3.0)) / fma(t_0, t_0, Float64((t_3 ^ 2.0) + Float64(t_0 * t_3)))))))) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(1.0 - N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[Power[t$95$2, 2.0], $MachinePrecision] * t$95$1), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[(N[(N[Sin[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$2), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(N[Power[t$95$0, 3.0], $MachinePrecision] - N[Power[N[(N[Power[N[(N[(N[Sin[N[(lambda1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(lambda2 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[N[(lambda1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(lambda2 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * t$95$1), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] / N[(t$95$0 * t$95$0 + N[(N[Power[t$95$3, 2.0], $MachinePrecision] + N[(t$95$0 * t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
t_1 := \cos \phi_2 \cdot \cos \phi_1\\
t_2 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_3 := {t\_2}^{2} \cdot t\_1\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_2\right) \cdot t\_2}}{\sqrt{\frac{{t\_0}^{3} - {\left({\left(\sin \left(\frac{\lambda_1}{2}\right) \cdot \cos \left(\frac{\lambda_2}{2}\right) - \cos \left(\frac{\lambda_1}{2}\right) \cdot \sin \left(\frac{\lambda_2}{2}\right)\right)}^{2} \cdot t\_1\right)}^{3}}{\mathsf{fma}\left(t\_0, t\_0, {t\_3}^{2} + t\_0 \cdot t\_3\right)}}}\right)
\end{array}
\end{array}
Initial program 64.1%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-/.f6465.1
Applied rewrites65.1%
lift--.f64N/A
lift-+.f64N/A
associate--r+N/A
flip3--N/A
Applied rewrites65.0%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-/.f6465.2
Applied rewrites65.2%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
(t_1 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0))
(t_2 (+ t_1 (* (* (* (cos phi1) (cos phi2)) t_0) t_0)))
(t_3 (sqrt (- 1.0 t_2))))
(if (<= (* 2.0 (atan2 (sqrt t_2) t_3)) 0.2)
(*
R
(*
2.0
(atan2
(sqrt
(+ t_1 (* (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0) (cos phi1))))
(sqrt
(-
1.0
(fma
(* (cos phi2) (cos phi1))
(pow (sin (* -0.5 lambda2)) 2.0)
(pow (sin (* (- phi2 phi1) -0.5)) 2.0)))))))
(*
R
(*
2.0
(atan2
(sqrt
(fma
(*
(- 1.0 (cos (- lambda1 lambda2)))
(+ (cos (- phi1 phi2)) (cos (+ phi2 phi1))))
0.25
(pow (sin (* (- phi1 phi2) 0.5)) 2.0)))
t_3))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
double t_1 = pow(sin(((phi1 - phi2) / 2.0)), 2.0);
double t_2 = t_1 + (((cos(phi1) * cos(phi2)) * t_0) * t_0);
double t_3 = sqrt((1.0 - t_2));
double tmp;
if ((2.0 * atan2(sqrt(t_2), t_3)) <= 0.2) {
tmp = R * (2.0 * atan2(sqrt((t_1 + (pow(sin(((lambda1 - lambda2) * 0.5)), 2.0) * cos(phi1)))), sqrt((1.0 - fma((cos(phi2) * cos(phi1)), pow(sin((-0.5 * lambda2)), 2.0), pow(sin(((phi2 - phi1) * -0.5)), 2.0))))));
} else {
tmp = R * (2.0 * atan2(sqrt(fma(((1.0 - cos((lambda1 - lambda2))) * (cos((phi1 - phi2)) + cos((phi2 + phi1)))), 0.25, pow(sin(((phi1 - phi2) * 0.5)), 2.0))), t_3));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0 t_2 = Float64(t_1 + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_0) * t_0)) t_3 = sqrt(Float64(1.0 - t_2)) tmp = 0.0 if (Float64(2.0 * atan(sqrt(t_2), t_3)) <= 0.2) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_1 + Float64((sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0) * cos(phi1)))), sqrt(Float64(1.0 - fma(Float64(cos(phi2) * cos(phi1)), (sin(Float64(-0.5 * lambda2)) ^ 2.0), (sin(Float64(Float64(phi2 - phi1) * -0.5)) ^ 2.0))))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(fma(Float64(Float64(1.0 - cos(Float64(lambda1 - lambda2))) * Float64(cos(Float64(phi1 - phi2)) + cos(Float64(phi2 + phi1)))), 0.25, (sin(Float64(Float64(phi1 - phi2) * 0.5)) ^ 2.0))), t_3))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 + N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Sqrt[N[(1.0 - t$95$2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(2.0 * N[ArcTan[N[Sqrt[t$95$2], $MachinePrecision] / t$95$3], $MachinePrecision]), $MachinePrecision], 0.2], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$1 + N[(N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * N[Power[N[Sin[N[(-0.5 * lambda2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[N[(N[(phi2 - phi1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[(N[(1.0 - N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(N[Cos[N[(phi1 - phi2), $MachinePrecision]], $MachinePrecision] + N[Cos[N[(phi2 + phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.25 + N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t$95$3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
t_2 := t\_1 + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_0\right) \cdot t\_0\\
t_3 := \sqrt{1 - t\_2}\\
\mathbf{if}\;2 \cdot \tan^{-1}_* \frac{\sqrt{t\_2}}{t\_3} \leq 0.2:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1 + {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2} \cdot \cos \phi_1}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_2 \cdot \cos \phi_1, {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, {\sin \left(\left(\phi_2 - \phi_1\right) \cdot -0.5\right)}^{2}\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\left(1 - \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(\cos \left(\phi_1 - \phi_2\right) + \cos \left(\phi_2 + \phi_1\right)\right), 0.25, {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)}}{t\_3}\right)\\
\end{array}
\end{array}
if (*.f64 #s(literal 2 binary64) (atan2.f64 (sqrt.f64 (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))) (sqrt.f64 (-.f64 #s(literal 1 binary64) (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))))))))) < 0.20000000000000001Initial program 92.4%
Taylor expanded in lambda1 around 0
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
unpow2N/A
sqr-neg-revN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
Applied rewrites93.0%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-cos.f6493.0
Applied rewrites93.0%
if 0.20000000000000001 < (*.f64 #s(literal 2 binary64) (atan2.f64 (sqrt.f64 (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))) (sqrt.f64 (-.f64 #s(literal 1 binary64) (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))))))))) Initial program 61.3%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lift-sin.f64N/A
lift-sin.f64N/A
sin-multN/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
cos-multN/A
frac-timesN/A
metadata-evalN/A
metadata-evalN/A
Applied rewrites61.8%
Taylor expanded in lambda1 around inf
Applied rewrites61.8%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi1) (cos phi2)))
(t_1 (sin (/ (- lambda1 lambda2) 2.0)))
(t_2 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)))
(*
R
(*
2.0
(atan2
(sqrt (+ t_2 (* (* t_0 t_1) t_1)))
(sqrt
(/
(-
(pow
(-
1.0
(pow
(-
(* (sin (/ phi1 2.0)) (cos (/ phi2 2.0)))
(* (cos (/ phi1 2.0)) (sin (/ phi2 2.0))))
2.0))
2.0)
(* (pow t_0 2.0) (pow t_1 4.0)))
(+ (- 1.0 t_2) (* t_0 (pow t_1 2.0))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi1) * cos(phi2);
double t_1 = sin(((lambda1 - lambda2) / 2.0));
double t_2 = pow(sin(((phi1 - phi2) / 2.0)), 2.0);
return R * (2.0 * atan2(sqrt((t_2 + ((t_0 * t_1) * t_1))), sqrt(((pow((1.0 - pow(((sin((phi1 / 2.0)) * cos((phi2 / 2.0))) - (cos((phi1 / 2.0)) * sin((phi2 / 2.0)))), 2.0)), 2.0) - (pow(t_0, 2.0) * pow(t_1, 4.0))) / ((1.0 - t_2) + (t_0 * pow(t_1, 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(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
t_0 = cos(phi1) * cos(phi2)
t_1 = sin(((lambda1 - lambda2) / 2.0d0))
t_2 = sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0
code = r * (2.0d0 * atan2(sqrt((t_2 + ((t_0 * t_1) * t_1))), sqrt(((((1.0d0 - (((sin((phi1 / 2.0d0)) * cos((phi2 / 2.0d0))) - (cos((phi1 / 2.0d0)) * sin((phi2 / 2.0d0)))) ** 2.0d0)) ** 2.0d0) - ((t_0 ** 2.0d0) * (t_1 ** 4.0d0))) / ((1.0d0 - t_2) + (t_0 * (t_1 ** 2.0d0)))))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.cos(phi1) * Math.cos(phi2);
double t_1 = Math.sin(((lambda1 - lambda2) / 2.0));
double t_2 = Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0);
return R * (2.0 * Math.atan2(Math.sqrt((t_2 + ((t_0 * t_1) * t_1))), Math.sqrt(((Math.pow((1.0 - Math.pow(((Math.sin((phi1 / 2.0)) * Math.cos((phi2 / 2.0))) - (Math.cos((phi1 / 2.0)) * Math.sin((phi2 / 2.0)))), 2.0)), 2.0) - (Math.pow(t_0, 2.0) * Math.pow(t_1, 4.0))) / ((1.0 - t_2) + (t_0 * Math.pow(t_1, 2.0)))))));
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.cos(phi1) * math.cos(phi2) t_1 = math.sin(((lambda1 - lambda2) / 2.0)) t_2 = math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) return R * (2.0 * math.atan2(math.sqrt((t_2 + ((t_0 * t_1) * t_1))), math.sqrt(((math.pow((1.0 - math.pow(((math.sin((phi1 / 2.0)) * math.cos((phi2 / 2.0))) - (math.cos((phi1 / 2.0)) * math.sin((phi2 / 2.0)))), 2.0)), 2.0) - (math.pow(t_0, 2.0) * math.pow(t_1, 4.0))) / ((1.0 - t_2) + (t_0 * math.pow(t_1, 2.0)))))))
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi1) * cos(phi2)) t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_2 = sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0 return Float64(R * Float64(2.0 * atan(sqrt(Float64(t_2 + Float64(Float64(t_0 * t_1) * t_1))), sqrt(Float64(Float64((Float64(1.0 - (Float64(Float64(sin(Float64(phi1 / 2.0)) * cos(Float64(phi2 / 2.0))) - Float64(cos(Float64(phi1 / 2.0)) * sin(Float64(phi2 / 2.0)))) ^ 2.0)) ^ 2.0) - Float64((t_0 ^ 2.0) * (t_1 ^ 4.0))) / Float64(Float64(1.0 - t_2) + Float64(t_0 * (t_1 ^ 2.0)))))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(phi1) * cos(phi2); t_1 = sin(((lambda1 - lambda2) / 2.0)); t_2 = sin(((phi1 - phi2) / 2.0)) ^ 2.0; tmp = R * (2.0 * atan2(sqrt((t_2 + ((t_0 * t_1) * t_1))), sqrt(((((1.0 - (((sin((phi1 / 2.0)) * cos((phi2 / 2.0))) - (cos((phi1 / 2.0)) * sin((phi2 / 2.0)))) ^ 2.0)) ^ 2.0) - ((t_0 ^ 2.0) * (t_1 ^ 4.0))) / ((1.0 - t_2) + (t_0 * (t_1 ^ 2.0))))))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$2 + N[(N[(t$95$0 * t$95$1), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(N[Power[N[(1.0 - N[Power[N[(N[(N[Sin[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] - N[(N[Power[t$95$0, 2.0], $MachinePrecision] * N[Power[t$95$1, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 - t$95$2), $MachinePrecision] + N[(t$95$0 * N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \phi_1 \cdot \cos \phi_2\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_2 + \left(t\_0 \cdot t\_1\right) \cdot t\_1}}{\sqrt{\frac{{\left(1 - {\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2}\right)}^{2} - {t\_0}^{2} \cdot {t\_1}^{4}}{\left(1 - t\_2\right) + t\_0 \cdot {t\_1}^{2}}}}\right)
\end{array}
\end{array}
Initial program 64.1%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-/.f6465.0
Applied rewrites65.0%
Applied rewrites64.0%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-/.f6465.1
Applied rewrites65.1%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
(t_1 (* (* (* (cos phi1) (cos phi2)) t_0) t_0)))
(*
R
(*
2.0
(atan2
(sqrt
(+
(pow
(-
(* (sin (/ phi1 2.0)) (cos (/ phi2 2.0)))
(* (cos (/ phi1 2.0)) (sin (/ phi2 2.0))))
2.0)
t_1))
(sqrt (- 1.0 (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) t_1))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
double t_1 = ((cos(phi1) * cos(phi2)) * t_0) * t_0;
return R * (2.0 * atan2(sqrt((pow(((sin((phi1 / 2.0)) * cos((phi2 / 2.0))) - (cos((phi1 / 2.0)) * sin((phi2 / 2.0)))), 2.0) + t_1)), sqrt((1.0 - (pow(sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
t_0 = sin(((lambda1 - lambda2) / 2.0d0))
t_1 = ((cos(phi1) * cos(phi2)) * t_0) * t_0
code = r * (2.0d0 * atan2(sqrt(((((sin((phi1 / 2.0d0)) * cos((phi2 / 2.0d0))) - (cos((phi1 / 2.0d0)) * sin((phi2 / 2.0d0)))) ** 2.0d0) + t_1)), sqrt((1.0d0 - ((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + t_1)))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.sin(((lambda1 - lambda2) / 2.0));
double t_1 = ((Math.cos(phi1) * Math.cos(phi2)) * t_0) * t_0;
return R * (2.0 * Math.atan2(Math.sqrt((Math.pow(((Math.sin((phi1 / 2.0)) * Math.cos((phi2 / 2.0))) - (Math.cos((phi1 / 2.0)) * Math.sin((phi2 / 2.0)))), 2.0) + t_1)), Math.sqrt((1.0 - (Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)))));
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((lambda1 - lambda2) / 2.0)) t_1 = ((math.cos(phi1) * math.cos(phi2)) * t_0) * t_0 return R * (2.0 * math.atan2(math.sqrt((math.pow(((math.sin((phi1 / 2.0)) * math.cos((phi2 / 2.0))) - (math.cos((phi1 / 2.0)) * math.sin((phi2 / 2.0)))), 2.0) + t_1)), math.sqrt((1.0 - (math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)))))
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_0) * t_0) return Float64(R * Float64(2.0 * atan(sqrt(Float64((Float64(Float64(sin(Float64(phi1 / 2.0)) * cos(Float64(phi2 / 2.0))) - Float64(cos(Float64(phi1 / 2.0)) * sin(Float64(phi2 / 2.0)))) ^ 2.0) + t_1)), sqrt(Float64(1.0 - Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + t_1)))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(((lambda1 - lambda2) / 2.0)); t_1 = ((cos(phi1) * cos(phi2)) * t_0) * t_0; tmp = R * (2.0 * atan2(sqrt(((((sin((phi1 / 2.0)) * cos((phi2 / 2.0))) - (cos((phi1 / 2.0)) * sin((phi2 / 2.0)))) ^ 2.0) + t_1)), sqrt((1.0 - ((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + t_1))))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[(N[(N[Sin[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[N[(phi1 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi2 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_0\right) \cdot t\_0\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\phi_2}{2}\right)\right)}^{2} + t\_1}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t\_1\right)}}\right)
\end{array}
\end{array}
Initial program 64.1%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-/.f6465.1
Applied rewrites65.1%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0)))
(*
(* 2.0 R)
(atan2
(sqrt
(fma
(* t_0 (cos phi1))
(cos phi2)
(pow
(fma
(cos (* -0.5 phi2))
(sin (* 0.5 phi1))
(* (sin (* -0.5 phi2)) (cos (* -0.5 phi1))))
2.0)))
(sqrt
(-
1.0
(fma
(* (cos phi1) (cos phi2))
t_0
(pow (sin (* (- phi1 phi2) 0.5)) 2.0))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin(((lambda1 - lambda2) * 0.5)), 2.0);
return (2.0 * R) * atan2(sqrt(fma((t_0 * cos(phi1)), cos(phi2), pow(fma(cos((-0.5 * phi2)), sin((0.5 * phi1)), (sin((-0.5 * phi2)) * cos((-0.5 * phi1)))), 2.0))), sqrt((1.0 - fma((cos(phi1) * cos(phi2)), t_0, pow(sin(((phi1 - phi2) * 0.5)), 2.0)))));
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0 return Float64(Float64(2.0 * R) * atan(sqrt(fma(Float64(t_0 * cos(phi1)), cos(phi2), (fma(cos(Float64(-0.5 * phi2)), sin(Float64(0.5 * phi1)), Float64(sin(Float64(-0.5 * phi2)) * cos(Float64(-0.5 * phi1)))) ^ 2.0))), sqrt(Float64(1.0 - fma(Float64(cos(phi1) * cos(phi2)), t_0, (sin(Float64(Float64(phi1 - phi2) * 0.5)) ^ 2.0)))))) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[N[(N[(t$95$0 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision] + N[Power[N[(N[Cos[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] + N[(N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0 + N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\\
\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_0 \cdot \cos \phi_1, \cos \phi_2, {\left(\mathsf{fma}\left(\cos \left(-0.5 \cdot \phi_2\right), \sin \left(0.5 \cdot \phi_1\right), \sin \left(-0.5 \cdot \phi_2\right) \cdot \cos \left(-0.5 \cdot \phi_1\right)\right)\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_1 \cdot \cos \phi_2, t\_0, {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)}}
\end{array}
\end{array}
Initial program 64.1%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-/.f6465.1
Applied rewrites65.1%
Taylor expanded in R around 0
Applied rewrites65.0%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi2) (cos phi1)))
(t_1 (pow (sin (/ (- lambda1 lambda2) 2.0)) 2.0)))
(*
(atan2
(sqrt (fma t_1 t_0 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)))
(sqrt (- (pow (cos (/ (- phi1 phi2) -2.0)) 2.0) (* t_1 t_0))))
(* R 2.0))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi2) * cos(phi1);
double t_1 = pow(sin(((lambda1 - lambda2) / 2.0)), 2.0);
return atan2(sqrt(fma(t_1, t_0, pow(sin(((phi1 - phi2) / 2.0)), 2.0))), sqrt((pow(cos(((phi1 - phi2) / -2.0)), 2.0) - (t_1 * t_0)))) * (R * 2.0);
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi2) * cos(phi1)) t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) ^ 2.0 return Float64(atan(sqrt(fma(t_1, t_0, (sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0))), sqrt(Float64((cos(Float64(Float64(phi1 - phi2) / -2.0)) ^ 2.0) - Float64(t_1 * t_0)))) * Float64(R * 2.0)) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, N[(N[ArcTan[N[Sqrt[N[(t$95$1 * t$95$0 + N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(N[(phi1 - phi2), $MachinePrecision] / -2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(t$95$1 * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(R * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \phi_1\\
t_1 := {\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}^{2}\\
\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_1, t\_0, {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}}{\sqrt{{\cos \left(\frac{\phi_1 - \phi_2}{-2}\right)}^{2} - t\_1 \cdot t\_0}} \cdot \left(R \cdot 2\right)
\end{array}
\end{array}
Initial program 64.1%
Applied rewrites64.1%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0
(fma
(* (cos phi2) (cos phi1))
(pow (sin (* (- lambda2 lambda1) -0.5)) 2.0)
(pow (sin (* (- phi2 phi1) -0.5)) 2.0))))
(* R (* 2.0 (atan2 (sqrt t_0) (sqrt (- 1.0 t_0)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = fma((cos(phi2) * cos(phi1)), pow(sin(((lambda2 - lambda1) * -0.5)), 2.0), pow(sin(((phi2 - phi1) * -0.5)), 2.0));
return R * (2.0 * atan2(sqrt(t_0), sqrt((1.0 - t_0))));
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = fma(Float64(cos(phi2) * cos(phi1)), (sin(Float64(Float64(lambda2 - lambda1) * -0.5)) ^ 2.0), (sin(Float64(Float64(phi2 - phi1) * -0.5)) ^ 2.0)) return Float64(R * Float64(2.0 * atan(sqrt(t_0), sqrt(Float64(1.0 - t_0))))) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * N[Power[N[Sin[N[(N[(lambda2 - lambda1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[N[(N[(phi2 - phi1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$0], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\cos \phi_2 \cdot \cos \phi_1, {\sin \left(\left(\lambda_2 - \lambda_1\right) \cdot -0.5\right)}^{2}, {\sin \left(\left(\phi_2 - \phi_1\right) \cdot -0.5\right)}^{2}\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_0}}{\sqrt{1 - t\_0}}\right)
\end{array}
\end{array}
Initial program 64.1%
Taylor expanded in lambda1 around 0
Applied rewrites64.1%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (/ (- lambda1 lambda2) 2.0))
(t_1 (sin t_0))
(t_2 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)))
(*
R
(*
2.0
(atan2
(sqrt (+ t_2 (* (* (* (cos phi1) (cos phi2)) t_1) t_1)))
(sqrt
(-
1.0
(+
t_2
(/
(*
(- 1.0 (cos (* 2.0 t_0)))
(+ (cos (- phi1 phi2)) (cos (+ phi2 phi1))))
4.0)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (lambda1 - lambda2) / 2.0;
double t_1 = sin(t_0);
double t_2 = pow(sin(((phi1 - phi2) / 2.0)), 2.0);
return R * (2.0 * atan2(sqrt((t_2 + (((cos(phi1) * cos(phi2)) * t_1) * t_1))), sqrt((1.0 - (t_2 + (((1.0 - cos((2.0 * t_0))) * (cos((phi1 - phi2)) + cos((phi2 + phi1)))) / 4.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(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
t_0 = (lambda1 - lambda2) / 2.0d0
t_1 = sin(t_0)
t_2 = sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0
code = r * (2.0d0 * atan2(sqrt((t_2 + (((cos(phi1) * cos(phi2)) * t_1) * t_1))), sqrt((1.0d0 - (t_2 + (((1.0d0 - cos((2.0d0 * t_0))) * (cos((phi1 - phi2)) + cos((phi2 + phi1)))) / 4.0d0))))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (lambda1 - lambda2) / 2.0;
double t_1 = Math.sin(t_0);
double t_2 = Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0);
return R * (2.0 * Math.atan2(Math.sqrt((t_2 + (((Math.cos(phi1) * Math.cos(phi2)) * t_1) * t_1))), Math.sqrt((1.0 - (t_2 + (((1.0 - Math.cos((2.0 * t_0))) * (Math.cos((phi1 - phi2)) + Math.cos((phi2 + phi1)))) / 4.0))))));
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = (lambda1 - lambda2) / 2.0 t_1 = math.sin(t_0) t_2 = math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) return R * (2.0 * math.atan2(math.sqrt((t_2 + (((math.cos(phi1) * math.cos(phi2)) * t_1) * t_1))), math.sqrt((1.0 - (t_2 + (((1.0 - math.cos((2.0 * t_0))) * (math.cos((phi1 - phi2)) + math.cos((phi2 + phi1)))) / 4.0))))))
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(Float64(lambda1 - lambda2) / 2.0) t_1 = sin(t_0) t_2 = sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0 return Float64(R * Float64(2.0 * atan(sqrt(Float64(t_2 + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_1) * t_1))), sqrt(Float64(1.0 - Float64(t_2 + Float64(Float64(Float64(1.0 - cos(Float64(2.0 * t_0))) * Float64(cos(Float64(phi1 - phi2)) + cos(Float64(phi2 + phi1)))) / 4.0))))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) t_0 = (lambda1 - lambda2) / 2.0; t_1 = sin(t_0); t_2 = sin(((phi1 - phi2) / 2.0)) ^ 2.0; tmp = R * (2.0 * atan2(sqrt((t_2 + (((cos(phi1) * cos(phi2)) * t_1) * t_1))), sqrt((1.0 - (t_2 + (((1.0 - cos((2.0 * t_0))) * (cos((phi1 - phi2)) + cos((phi2 + phi1)))) / 4.0)))))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]}, Block[{t$95$1 = N[Sin[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$2 + N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(t$95$2 + N[(N[(N[(1.0 - N[Cos[N[(2.0 * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(N[Cos[N[(phi1 - phi2), $MachinePrecision]], $MachinePrecision] + N[Cos[N[(phi2 + phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\lambda_1 - \lambda_2}{2}\\
t_1 := \sin t\_0\\
t_2 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_2 + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_1\right) \cdot t\_1}}{\sqrt{1 - \left(t\_2 + \frac{\left(1 - \cos \left(2 \cdot t\_0\right)\right) \cdot \left(\cos \left(\phi_1 - \phi_2\right) + \cos \left(\phi_2 + \phi_1\right)\right)}{4}\right)}}\right)
\end{array}
\end{array}
Initial program 64.1%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lift-sin.f64N/A
lift-sin.f64N/A
sin-multN/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
cos-multN/A
frac-timesN/A
metadata-evalN/A
metadata-evalN/A
Applied rewrites64.6%
Final simplification64.6%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
(t_1 (pow (sin (* -0.5 phi2)) 2.0))
(t_2 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)))
(if (or (<= phi2 -1.76e+44) (not (<= phi2 19.0)))
(*
R
(*
2.0
(atan2
(sqrt (fma (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0) (cos phi2) t_1))
(sqrt
(-
1.0
(fma (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0) (cos phi2) t_1))))))
(*
R
(*
2.0
(atan2
(sqrt
(+ t_2 (* (pow (sin (* (- lambda2 lambda1) -0.5)) 2.0) (cos phi1))))
(sqrt (- 1.0 (+ t_2 (* (* (* (cos phi1) (cos phi2)) t_0) t_0))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
double t_1 = pow(sin((-0.5 * phi2)), 2.0);
double t_2 = pow(sin(((phi1 - phi2) / 2.0)), 2.0);
double tmp;
if ((phi2 <= -1.76e+44) || !(phi2 <= 19.0)) {
tmp = R * (2.0 * atan2(sqrt(fma(pow(sin(((lambda1 - lambda2) * 0.5)), 2.0), cos(phi2), t_1)), sqrt((1.0 - fma(pow(sin((0.5 * (lambda1 - lambda2))), 2.0), cos(phi2), t_1)))));
} else {
tmp = R * (2.0 * atan2(sqrt((t_2 + (pow(sin(((lambda2 - lambda1) * -0.5)), 2.0) * cos(phi1)))), sqrt((1.0 - (t_2 + (((cos(phi1) * cos(phi2)) * t_0) * t_0))))));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = sin(Float64(-0.5 * phi2)) ^ 2.0 t_2 = sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0 tmp = 0.0 if ((phi2 <= -1.76e+44) || !(phi2 <= 19.0)) tmp = Float64(R * Float64(2.0 * atan(sqrt(fma((sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0), cos(phi2), t_1)), sqrt(Float64(1.0 - fma((sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0), cos(phi2), t_1)))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_2 + Float64((sin(Float64(Float64(lambda2 - lambda1) * -0.5)) ^ 2.0) * cos(phi1)))), sqrt(Float64(1.0 - Float64(t_2 + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_0) * t_0))))))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, If[Or[LessEqual[phi2, -1.76e+44], N[Not[LessEqual[phi2, 19.0]], $MachinePrecision]], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi2], $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi2], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$2 + N[(N[Power[N[Sin[N[(N[(lambda2 - lambda1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(t$95$2 + N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\\
t_2 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
\mathbf{if}\;\phi_2 \leq -1.76 \cdot 10^{+44} \lor \neg \left(\phi_2 \leq 19\right):\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left({\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}, \cos \phi_2, t\_1\right)}}{\sqrt{1 - \mathsf{fma}\left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, \cos \phi_2, t\_1\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_2 + {\sin \left(\left(\lambda_2 - \lambda_1\right) \cdot -0.5\right)}^{2} \cdot \cos \phi_1}}{\sqrt{1 - \left(t\_2 + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_0\right) \cdot t\_0\right)}}\right)\\
\end{array}
\end{array}
if phi2 < -1.76e44 or 19 < phi2 Initial program 44.3%
Taylor expanded in phi2 around 0
Applied rewrites20.6%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-fma.f64N/A
lower-pow.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-cos.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f6421.3
Applied rewrites21.3%
Taylor expanded in phi1 around 0
lower--.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-cos.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f6446.0
Applied rewrites46.0%
if -1.76e44 < phi2 < 19Initial program 82.4%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites82.5%
Final simplification64.9%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
(t_1 (pow (sin (* -0.5 phi2)) 2.0)))
(if (or (<= phi2 -6.8e-6) (not (<= phi2 4.8e-20)))
(*
R
(*
2.0
(atan2
(sqrt (fma (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0) (cos phi2) t_1))
(sqrt
(-
1.0
(fma (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0) (cos phi2) t_1))))))
(*
R
(*
2.0
(atan2
(sqrt
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* (* (* (cos phi1) (cos phi2)) t_0) t_0)))
(sqrt
(-
(pow (cos (* -0.5 phi1)) 2.0)
(* (pow (sin (* (- lambda2 lambda1) -0.5)) 2.0) (cos phi1))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
double t_1 = pow(sin((-0.5 * phi2)), 2.0);
double tmp;
if ((phi2 <= -6.8e-6) || !(phi2 <= 4.8e-20)) {
tmp = R * (2.0 * atan2(sqrt(fma(pow(sin(((lambda1 - lambda2) * 0.5)), 2.0), cos(phi2), t_1)), sqrt((1.0 - fma(pow(sin((0.5 * (lambda1 - lambda2))), 2.0), cos(phi2), t_1)))));
} else {
tmp = R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0))), sqrt((pow(cos((-0.5 * phi1)), 2.0) - (pow(sin(((lambda2 - lambda1) * -0.5)), 2.0) * cos(phi1))))));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = sin(Float64(-0.5 * phi2)) ^ 2.0 tmp = 0.0 if ((phi2 <= -6.8e-6) || !(phi2 <= 4.8e-20)) tmp = Float64(R * Float64(2.0 * atan(sqrt(fma((sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0), cos(phi2), t_1)), sqrt(Float64(1.0 - fma((sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0), cos(phi2), t_1)))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_0) * t_0))), sqrt(Float64((cos(Float64(-0.5 * phi1)) ^ 2.0) - Float64((sin(Float64(Float64(lambda2 - lambda1) * -0.5)) ^ 2.0) * cos(phi1))))))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, If[Or[LessEqual[phi2, -6.8e-6], N[Not[LessEqual[phi2, 4.8e-20]], $MachinePrecision]], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi2], $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi2], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(N[Power[N[Sin[N[(N[(lambda2 - lambda1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\\
\mathbf{if}\;\phi_2 \leq -6.8 \cdot 10^{-6} \lor \neg \left(\phi_2 \leq 4.8 \cdot 10^{-20}\right):\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left({\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}, \cos \phi_2, t\_1\right)}}{\sqrt{1 - \mathsf{fma}\left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, \cos \phi_2, t\_1\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_0\right) \cdot t\_0}}{\sqrt{{\cos \left(-0.5 \cdot \phi_1\right)}^{2} - {\sin \left(\left(\lambda_2 - \lambda_1\right) \cdot -0.5\right)}^{2} \cdot \cos \phi_1}}\right)\\
\end{array}
\end{array}
if phi2 < -6.80000000000000012e-6 or 4.79999999999999986e-20 < phi2 Initial program 46.1%
Taylor expanded in phi2 around 0
Applied rewrites22.0%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-fma.f64N/A
lower-pow.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-cos.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f6422.5
Applied rewrites22.5%
Taylor expanded in phi1 around 0
lower--.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-cos.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f6447.5
Applied rewrites47.5%
if -6.80000000000000012e-6 < phi2 < 4.79999999999999986e-20Initial program 84.5%
Taylor expanded in phi2 around 0
Applied rewrites84.5%
Final simplification64.9%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))
(t_1 (pow (sin (* -0.5 phi2)) 2.0)))
(if (or (<= phi2 -6.8e-6) (not (<= phi2 4.8e-20)))
(*
R
(*
2.0
(atan2
(sqrt (fma t_0 (cos phi2) t_1))
(sqrt
(-
1.0
(fma (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0) (cos phi2) t_1))))))
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* t_0 (cos phi1))))
(sqrt
(-
(pow (cos (* -0.5 phi1)) 2.0)
(* (pow (sin (* (- lambda2 lambda1) -0.5)) 2.0) (cos phi1))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin(((lambda1 - lambda2) * 0.5)), 2.0);
double t_1 = pow(sin((-0.5 * phi2)), 2.0);
double tmp;
if ((phi2 <= -6.8e-6) || !(phi2 <= 4.8e-20)) {
tmp = R * (2.0 * atan2(sqrt(fma(t_0, cos(phi2), t_1)), sqrt((1.0 - fma(pow(sin((0.5 * (lambda1 - lambda2))), 2.0), cos(phi2), t_1)))));
} else {
tmp = R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * cos(phi1)))), sqrt((pow(cos((-0.5 * phi1)), 2.0) - (pow(sin(((lambda2 - lambda1) * -0.5)), 2.0) * cos(phi1))))));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0 t_1 = sin(Float64(-0.5 * phi2)) ^ 2.0 tmp = 0.0 if ((phi2 <= -6.8e-6) || !(phi2 <= 4.8e-20)) tmp = Float64(R * Float64(2.0 * atan(sqrt(fma(t_0, cos(phi2), t_1)), sqrt(Float64(1.0 - fma((sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0), cos(phi2), t_1)))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_0 * cos(phi1)))), sqrt(Float64((cos(Float64(-0.5 * phi1)) ^ 2.0) - Float64((sin(Float64(Float64(lambda2 - lambda1) * -0.5)) ^ 2.0) * cos(phi1))))))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, If[Or[LessEqual[phi2, -6.8e-6], N[Not[LessEqual[phi2, 4.8e-20]], $MachinePrecision]], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$0 * N[Cos[phi2], $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi2], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$0 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(N[Power[N[Sin[N[(N[(lambda2 - lambda1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\\
t_1 := {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\\
\mathbf{if}\;\phi_2 \leq -6.8 \cdot 10^{-6} \lor \neg \left(\phi_2 \leq 4.8 \cdot 10^{-20}\right):\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_0, \cos \phi_2, t\_1\right)}}{\sqrt{1 - \mathsf{fma}\left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, \cos \phi_2, t\_1\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t\_0 \cdot \cos \phi_1}}{\sqrt{{\cos \left(-0.5 \cdot \phi_1\right)}^{2} - {\sin \left(\left(\lambda_2 - \lambda_1\right) \cdot -0.5\right)}^{2} \cdot \cos \phi_1}}\right)\\
\end{array}
\end{array}
if phi2 < -6.80000000000000012e-6 or 4.79999999999999986e-20 < phi2 Initial program 46.1%
Taylor expanded in phi2 around 0
Applied rewrites22.0%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-fma.f64N/A
lower-pow.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-cos.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f6422.5
Applied rewrites22.5%
Taylor expanded in phi1 around 0
lower--.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-cos.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f6447.5
Applied rewrites47.5%
if -6.80000000000000012e-6 < phi2 < 4.79999999999999986e-20Initial program 84.5%
Taylor expanded in phi2 around 0
Applied rewrites84.5%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-cos.f6484.5
Applied rewrites84.5%
Final simplification64.9%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_1 (pow (sin (* -0.5 phi2)) 2.0)))
(if (or (<= phi2 -7.5e-28) (not (<= phi2 1.2e-21)))
(*
R
(*
2.0
(atan2
(sqrt (fma (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0) (cos phi2) t_1))
(sqrt (- 1.0 (fma t_0 (cos phi2) t_1))))))
(*
R
(*
2.0
(atan2
(sqrt (fma t_0 (cos phi1) (pow (sin (* 0.5 phi1)) 2.0)))
(sqrt
(-
(pow (cos (* -0.5 phi1)) 2.0)
(* (pow (sin (* (- lambda2 lambda1) -0.5)) 2.0) (cos phi1))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin((0.5 * (lambda1 - lambda2))), 2.0);
double t_1 = pow(sin((-0.5 * phi2)), 2.0);
double tmp;
if ((phi2 <= -7.5e-28) || !(phi2 <= 1.2e-21)) {
tmp = R * (2.0 * atan2(sqrt(fma(pow(sin(((lambda1 - lambda2) * 0.5)), 2.0), cos(phi2), t_1)), sqrt((1.0 - fma(t_0, cos(phi2), t_1)))));
} else {
tmp = R * (2.0 * atan2(sqrt(fma(t_0, cos(phi1), pow(sin((0.5 * phi1)), 2.0))), sqrt((pow(cos((-0.5 * phi1)), 2.0) - (pow(sin(((lambda2 - lambda1) * -0.5)), 2.0) * cos(phi1))))));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_1 = sin(Float64(-0.5 * phi2)) ^ 2.0 tmp = 0.0 if ((phi2 <= -7.5e-28) || !(phi2 <= 1.2e-21)) tmp = Float64(R * Float64(2.0 * atan(sqrt(fma((sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0), cos(phi2), t_1)), sqrt(Float64(1.0 - fma(t_0, cos(phi2), t_1)))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(fma(t_0, cos(phi1), (sin(Float64(0.5 * phi1)) ^ 2.0))), sqrt(Float64((cos(Float64(-0.5 * phi1)) ^ 2.0) - Float64((sin(Float64(Float64(lambda2 - lambda1) * -0.5)) ^ 2.0) * cos(phi1))))))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, If[Or[LessEqual[phi2, -7.5e-28], N[Not[LessEqual[phi2, 1.2e-21]], $MachinePrecision]], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi2], $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(t$95$0 * N[Cos[phi2], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$0 * N[Cos[phi1], $MachinePrecision] + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(N[Power[N[Sin[N[(N[(lambda2 - lambda1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_1 := {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\\
\mathbf{if}\;\phi_2 \leq -7.5 \cdot 10^{-28} \lor \neg \left(\phi_2 \leq 1.2 \cdot 10^{-21}\right):\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left({\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}, \cos \phi_2, t\_1\right)}}{\sqrt{1 - \mathsf{fma}\left(t\_0, \cos \phi_2, t\_1\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_0, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}{\sqrt{{\cos \left(-0.5 \cdot \phi_1\right)}^{2} - {\sin \left(\left(\lambda_2 - \lambda_1\right) \cdot -0.5\right)}^{2} \cdot \cos \phi_1}}\right)\\
\end{array}
\end{array}
if phi2 < -7.5000000000000003e-28 or 1.2e-21 < phi2 Initial program 47.4%
Taylor expanded in phi2 around 0
Applied rewrites24.2%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-fma.f64N/A
lower-pow.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-cos.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f6424.7
Applied rewrites24.7%
Taylor expanded in phi1 around 0
lower--.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-cos.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f6448.8
Applied rewrites48.8%
if -7.5000000000000003e-28 < phi2 < 1.2e-21Initial program 84.5%
Taylor expanded in phi2 around 0
Applied rewrites84.6%
Taylor expanded in lambda2 around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites62.1%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-cos.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f6482.1
Applied rewrites82.1%
Final simplification63.8%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
R
(*
2.0
(atan2
(sqrt
(fma
(pow (sin (* 0.5 (- lambda1 lambda2))) 2.0)
(cos phi1)
(pow (sin (* 0.5 phi1)) 2.0)))
(sqrt
(-
(pow (cos (* -0.5 phi1)) 2.0)
(* (pow (sin (* (- lambda2 lambda1) -0.5)) 2.0) (cos phi1))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * (2.0 * atan2(sqrt(fma(pow(sin((0.5 * (lambda1 - lambda2))), 2.0), cos(phi1), pow(sin((0.5 * phi1)), 2.0))), sqrt((pow(cos((-0.5 * phi1)), 2.0) - (pow(sin(((lambda2 - lambda1) * -0.5)), 2.0) * cos(phi1))))));
}
function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * Float64(2.0 * atan(sqrt(fma((sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0), cos(phi1), (sin(Float64(0.5 * phi1)) ^ 2.0))), sqrt(Float64((cos(Float64(-0.5 * phi1)) ^ 2.0) - Float64((sin(Float64(Float64(lambda2 - lambda1) * -0.5)) ^ 2.0) * cos(phi1))))))) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(N[Power[N[Sin[N[(N[(lambda2 - lambda1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}{\sqrt{{\cos \left(-0.5 \cdot \phi_1\right)}^{2} - {\sin \left(\left(\lambda_2 - \lambda_1\right) \cdot -0.5\right)}^{2} \cdot \cos \phi_1}}\right)
\end{array}
Initial program 64.1%
Taylor expanded in phi2 around 0
Applied rewrites51.3%
Taylor expanded in lambda2 around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites38.0%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-cos.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f6448.6
Applied rewrites48.6%
herbie shell --seed 2024356
(FPCore (R lambda1 lambda2 phi1 phi2)
:name "Distance on a great circle"
:precision binary64
(* R (* 2.0 (atan2 (sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* (* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0))) (sin (/ (- lambda1 lambda2) 2.0))))) (sqrt (- 1.0 (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* (* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0))) (sin (/ (- lambda1 lambda2) 2.0))))))))))