
(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 12 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 (sin (/ (- lambda1 lambda2) 2.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)
(*
(*
(*
(cos phi1)
(fma (sin phi2) (cos (/ PI 2.0)) (* (cos phi2) (sin (/ PI 2.0)))))
t_0)
t_0)))
(sqrt
(+
1.0
(+
(* -1.0 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0))
(*
(*
(/
(+
(- (* (cos phi1) (cos phi2)) (* (sin phi1) (sin phi2)))
(cos (- phi1 phi2)))
2.0)
(* -1.0 t_0))
t_0)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.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) + (((cos(phi1) * fma(sin(phi2), cos((((double) M_PI) / 2.0)), (cos(phi2) * sin((((double) M_PI) / 2.0))))) * t_0) * t_0))), sqrt((1.0 + ((-1.0 * pow(sin(((phi1 - phi2) / 2.0)), 2.0)) + ((((((cos(phi1) * cos(phi2)) - (sin(phi1) * sin(phi2))) + cos((phi1 - phi2))) / 2.0) * (-1.0 * t_0)) * t_0))))));
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.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) + Float64(Float64(Float64(cos(phi1) * fma(sin(phi2), cos(Float64(pi / 2.0)), Float64(cos(phi2) * sin(Float64(pi / 2.0))))) * t_0) * t_0))), sqrt(Float64(1.0 + Float64(Float64(-1.0 * (sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0)) + Float64(Float64(Float64(Float64(Float64(Float64(cos(phi1) * cos(phi2)) - Float64(sin(phi1) * sin(phi2))) + cos(Float64(phi1 - phi2))) / 2.0) * Float64(-1.0 * t_0)) * t_0))))))) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $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[(N[Sin[phi2], $MachinePrecision] * N[Cos[N[(Pi / 2.0), $MachinePrecision]], $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * N[Sin[N[(Pi / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 + N[(N[(-1.0 * N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Cos[N[(phi1 - phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] * N[(-1.0 * t$95$0), $MachinePrecision]), $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)\\
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 \mathsf{fma}\left(\sin \phi_2, \cos \left(\frac{\pi}{2}\right), \cos \phi_2 \cdot \sin \left(\frac{\pi}{2}\right)\right)\right) \cdot t\_0\right) \cdot t\_0}}{\sqrt{1 + \left(-1 \cdot {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\frac{\left(\cos \phi_1 \cdot \cos \phi_2 - \sin \phi_1 \cdot \sin \phi_2\right) + \cos \left(\phi_1 - \phi_2\right)}{2} \cdot \left(-1 \cdot t\_0\right)\right) \cdot t\_0\right)}}\right)
\end{array}
\end{array}
Initial program 62.8%
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-/.f6463.9
Applied rewrites63.9%
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
cos-multN/A
lower-/.f64N/A
lower-+.f64N/A
lower-cos.f64N/A
lower-+.f64N/A
lower-cos.f64N/A
lift--.f6464.2
Applied rewrites64.2%
lift-+.f64N/A
lift-cos.f64N/A
cos-sumN/A
lower--.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6464.7
Applied rewrites64.7%
lift-cos.f64N/A
sin-+PI/2-revN/A
lift-/.f64N/A
lift-PI.f64N/A
sin-sumN/A
lower-fma.f64N/A
lift-sin.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lift-cos.f64N/A
lower-sin.f6464.7
Applied rewrites64.7%
Final simplification64.7%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi1) (cos phi2)))
(t_1 (sin (/ (- lambda1 lambda2) 2.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_0 t_1) t_1)))
(sqrt
(+
1.0
(+
(* -1.0 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0))
(*
(*
(/ (+ (- t_0 (* (sin phi1) (sin phi2))) (cos (- phi1 phi2))) 2.0)
(* -1.0 t_1))
t_1)))))))))
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));
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_0 * t_1) * t_1))), sqrt((1.0 + ((-1.0 * pow(sin(((phi1 - phi2) / 2.0)), 2.0)) + (((((t_0 - (sin(phi1) * sin(phi2))) + cos((phi1 - phi2))) / 2.0) * (-1.0 * t_1)) * 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 = cos(phi1) * cos(phi2)
t_1 = sin(((lambda1 - lambda2) / 2.0d0))
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_0 * t_1) * t_1))), sqrt((1.0d0 + (((-1.0d0) * (sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0)) + (((((t_0 - (sin(phi1) * sin(phi2))) + cos((phi1 - phi2))) / 2.0d0) * ((-1.0d0) * t_1)) * t_1))))))
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));
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_0 * t_1) * t_1))), Math.sqrt((1.0 + ((-1.0 * Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0)) + (((((t_0 - (Math.sin(phi1) * Math.sin(phi2))) + Math.cos((phi1 - phi2))) / 2.0) * (-1.0 * t_1)) * t_1))))));
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.cos(phi1) * math.cos(phi2) t_1 = math.sin(((lambda1 - lambda2) / 2.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_0 * t_1) * t_1))), math.sqrt((1.0 + ((-1.0 * math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0)) + (((((t_0 - (math.sin(phi1) * math.sin(phi2))) + math.cos((phi1 - phi2))) / 2.0) * (-1.0 * t_1)) * t_1))))))
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi1) * cos(phi2)) t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.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) + Float64(Float64(t_0 * t_1) * t_1))), sqrt(Float64(1.0 + Float64(Float64(-1.0 * (sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0)) + Float64(Float64(Float64(Float64(Float64(t_0 - Float64(sin(phi1) * sin(phi2))) + cos(Float64(phi1 - phi2))) / 2.0) * Float64(-1.0 * t_1)) * t_1))))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(phi1) * cos(phi2); t_1 = sin(((lambda1 - lambda2) / 2.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_0 * t_1) * t_1))), sqrt((1.0 + ((-1.0 * (sin(((phi1 - phi2) / 2.0)) ^ 2.0)) + (((((t_0 - (sin(phi1) * sin(phi2))) + cos((phi1 - phi2))) / 2.0) * (-1.0 * t_1)) * t_1)))))); 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]}, 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[(t$95$0 * t$95$1), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 + N[(N[(-1.0 * N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(N[(t$95$0 - N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Cos[N[(phi1 - phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] * N[(-1.0 * t$95$1), $MachinePrecision]), $MachinePrecision] * t$95$1), $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)\\
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(t\_0 \cdot t\_1\right) \cdot t\_1}}{\sqrt{1 + \left(-1 \cdot {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\frac{\left(t\_0 - \sin \phi_1 \cdot \sin \phi_2\right) + \cos \left(\phi_1 - \phi_2\right)}{2} \cdot \left(-1 \cdot t\_1\right)\right) \cdot t\_1\right)}}\right)
\end{array}
\end{array}
Initial program 62.8%
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-/.f6463.9
Applied rewrites63.9%
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
cos-multN/A
lower-/.f64N/A
lower-+.f64N/A
lower-cos.f64N/A
lower-+.f64N/A
lower-cos.f64N/A
lift--.f6464.2
Applied rewrites64.2%
lift-+.f64N/A
lift-cos.f64N/A
cos-sumN/A
lower--.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6464.7
Applied rewrites64.7%
Final simplification64.7%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.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)
(* (* (* (cos phi1) (cos phi2)) t_0) t_0)))
(sqrt
(+
1.0
(+
(* -1.0 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0))
(*
(* (/ (+ (cos (+ phi1 phi2)) (cos (- phi1 phi2))) 2.0) (* -1.0 t_0))
t_0)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.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) + (((cos(phi1) * cos(phi2)) * t_0) * t_0))), sqrt((1.0 + ((-1.0 * pow(sin(((phi1 - phi2) / 2.0)), 2.0)) + ((((cos((phi1 + phi2)) + cos((phi1 - phi2))) / 2.0) * (-1.0 * t_0)) * t_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
t_0 = sin(((lambda1 - lambda2) / 2.0d0))
code = r * (2.0d0 * atan2(sqrt(((((sin((phi1 / 2.0d0)) * cos((phi2 / 2.0d0))) - (cos((phi1 / 2.0d0)) * sin((phi2 / 2.0d0)))) ** 2.0d0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0))), sqrt((1.0d0 + (((-1.0d0) * (sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0)) + ((((cos((phi1 + phi2)) + cos((phi1 - phi2))) / 2.0d0) * ((-1.0d0) * t_0)) * t_0))))))
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));
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) + (((Math.cos(phi1) * Math.cos(phi2)) * t_0) * t_0))), Math.sqrt((1.0 + ((-1.0 * Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0)) + ((((Math.cos((phi1 + phi2)) + Math.cos((phi1 - phi2))) / 2.0) * (-1.0 * t_0)) * t_0))))));
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((lambda1 - lambda2) / 2.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) + (((math.cos(phi1) * math.cos(phi2)) * t_0) * t_0))), math.sqrt((1.0 + ((-1.0 * math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0)) + ((((math.cos((phi1 + phi2)) + math.cos((phi1 - phi2))) / 2.0) * (-1.0 * t_0)) * t_0))))))
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.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) + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_0) * t_0))), sqrt(Float64(1.0 + Float64(Float64(-1.0 * (sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0)) + Float64(Float64(Float64(Float64(cos(Float64(phi1 + phi2)) + cos(Float64(phi1 - phi2))) / 2.0) * Float64(-1.0 * t_0)) * t_0))))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(((lambda1 - lambda2) / 2.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) + (((cos(phi1) * cos(phi2)) * t_0) * t_0))), sqrt((1.0 + ((-1.0 * (sin(((phi1 - phi2) / 2.0)) ^ 2.0)) + ((((cos((phi1 + phi2)) + cos((phi1 - phi2))) / 2.0) * (-1.0 * t_0)) * t_0)))))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $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$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 + N[(N[(-1.0 * N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(N[Cos[N[(phi1 + phi2), $MachinePrecision]], $MachinePrecision] + N[Cos[N[(phi1 - phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] * N[(-1.0 * t$95$0), $MachinePrecision]), $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)\\
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\_0\right) \cdot t\_0}}{\sqrt{1 + \left(-1 \cdot {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\frac{\cos \left(\phi_1 + \phi_2\right) + \cos \left(\phi_1 - \phi_2\right)}{2} \cdot \left(-1 \cdot t\_0\right)\right) \cdot t\_0\right)}}\right)
\end{array}
\end{array}
Initial program 62.8%
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-/.f6463.9
Applied rewrites63.9%
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
cos-multN/A
lower-/.f64N/A
lower-+.f64N/A
lower-cos.f64N/A
lower-+.f64N/A
lower-cos.f64N/A
lift--.f6464.2
Applied rewrites64.2%
Final simplification64.2%
(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 62.8%
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-/.f6463.9
Applied rewrites63.9%
(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 phi2) 2.0)) 2.0) t_1))
(sqrt
(-
1.0
(+
(pow
(-
(* (sin (/ phi1 2.0)) (cos (/ phi2 2.0)))
(* (cos (/ phi1 2.0)) (sin (/ 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 - phi2) / 2.0)), 2.0) + t_1)), sqrt((1.0 - (pow(((sin((phi1 / 2.0)) * cos((phi2 / 2.0))) - (cos((phi1 / 2.0)) * sin((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 - phi2) / 2.0d0)) ** 2.0d0) + t_1)), sqrt((1.0d0 - ((((sin((phi1 / 2.0d0)) * cos((phi2 / 2.0d0))) - (cos((phi1 / 2.0d0)) * sin((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 - phi2) / 2.0)), 2.0) + t_1)), Math.sqrt((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) + 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 - phi2) / 2.0)), 2.0) + t_1)), math.sqrt((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) + 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((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + t_1)), sqrt(Float64(1.0 - 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)))))) 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 - phi2) / 2.0)) ^ 2.0) + t_1)), sqrt((1.0 - ((((sin((phi1 / 2.0)) * cos((phi2 / 2.0))) - (cos((phi1 / 2.0)) * sin((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[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - 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]], $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{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t\_1}}{\sqrt{1 - \left({\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\right)}}\right)
\end{array}
\end{array}
Initial program 62.8%
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-/.f6463.8
Applied rewrites63.8%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (* 0.5 (- lambda1 lambda2))))
(t_1 (* t_0 t_0))
(t_2 (sin (/ (- lambda1 lambda2) 2.0)))
(t_3 (sin (* -0.5 phi2)))
(t_4 (sin (* 0.5 (- phi1 phi2))))
(t_5 (* t_4 t_4))
(t_6 (* (* (* (cos phi1) (cos phi2)) t_2) t_2)))
(if (<= (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) t_6) 2e-166)
(*
R
(*
2.0
(atan2
(sqrt (fma (cos phi2) t_1 (* t_3 t_3)))
(sqrt (- 1.0 (+ (pow (sin (/ (* -1.0 phi2) 2.0)) 2.0) t_6))))))
(*
R
(*
2.0
(atan2
(pow (fma (cos phi1) (* (cos phi2) t_1) t_5) 0.5)
(exp
(*
(log
(+
1.0
(/
(fma
(pow (cos phi1) 3.0)
(* (pow (cos phi2) 3.0) (pow t_0 6.0))
(pow t_4 6.0))
(-
(*
-1.0
(fma
(pow (cos phi1) 2.0)
(* (pow (cos phi2) 2.0) (pow t_0 4.0))
(pow t_4 4.0)))
(* (* -1.0 (cos phi1)) (* (cos phi2) (* t_1 t_5)))))))
0.5))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin((0.5 * (lambda1 - lambda2)));
double t_1 = t_0 * t_0;
double t_2 = sin(((lambda1 - lambda2) / 2.0));
double t_3 = sin((-0.5 * phi2));
double t_4 = sin((0.5 * (phi1 - phi2)));
double t_5 = t_4 * t_4;
double t_6 = ((cos(phi1) * cos(phi2)) * t_2) * t_2;
double tmp;
if ((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + t_6) <= 2e-166) {
tmp = R * (2.0 * atan2(sqrt(fma(cos(phi2), t_1, (t_3 * t_3))), sqrt((1.0 - (pow(sin(((-1.0 * phi2) / 2.0)), 2.0) + t_6)))));
} else {
tmp = R * (2.0 * atan2(pow(fma(cos(phi1), (cos(phi2) * t_1), t_5), 0.5), exp((log((1.0 + (fma(pow(cos(phi1), 3.0), (pow(cos(phi2), 3.0) * pow(t_0, 6.0)), pow(t_4, 6.0)) / ((-1.0 * fma(pow(cos(phi1), 2.0), (pow(cos(phi2), 2.0) * pow(t_0, 4.0)), pow(t_4, 4.0))) - ((-1.0 * cos(phi1)) * (cos(phi2) * (t_1 * t_5))))))) * 0.5))));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) t_1 = Float64(t_0 * t_0) t_2 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_3 = sin(Float64(-0.5 * phi2)) t_4 = sin(Float64(0.5 * Float64(phi1 - phi2))) t_5 = Float64(t_4 * t_4) t_6 = Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_2) * t_2) tmp = 0.0 if (Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + t_6) <= 2e-166) tmp = Float64(R * Float64(2.0 * atan(sqrt(fma(cos(phi2), t_1, Float64(t_3 * t_3))), sqrt(Float64(1.0 - Float64((sin(Float64(Float64(-1.0 * phi2) / 2.0)) ^ 2.0) + t_6)))))); else tmp = Float64(R * Float64(2.0 * atan((fma(cos(phi1), Float64(cos(phi2) * t_1), t_5) ^ 0.5), exp(Float64(log(Float64(1.0 + Float64(fma((cos(phi1) ^ 3.0), Float64((cos(phi2) ^ 3.0) * (t_0 ^ 6.0)), (t_4 ^ 6.0)) / Float64(Float64(-1.0 * fma((cos(phi1) ^ 2.0), Float64((cos(phi2) ^ 2.0) * (t_0 ^ 4.0)), (t_4 ^ 4.0))) - Float64(Float64(-1.0 * cos(phi1)) * Float64(cos(phi2) * Float64(t_1 * t_5))))))) * 0.5))))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$5 = N[(t$95$4 * t$95$4), $MachinePrecision]}, Block[{t$95$6 = N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$2), $MachinePrecision] * t$95$2), $MachinePrecision]}, If[LessEqual[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + t$95$6), $MachinePrecision], 2e-166], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Cos[phi2], $MachinePrecision] * t$95$1 + N[(t$95$3 * t$95$3), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Power[N[Sin[N[(N[(-1.0 * phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + t$95$6), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Power[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * t$95$1), $MachinePrecision] + t$95$5), $MachinePrecision], 0.5], $MachinePrecision] / N[Exp[N[(N[Log[N[(1.0 + N[(N[(N[Power[N[Cos[phi1], $MachinePrecision], 3.0], $MachinePrecision] * N[(N[Power[N[Cos[phi2], $MachinePrecision], 3.0], $MachinePrecision] * N[Power[t$95$0, 6.0], $MachinePrecision]), $MachinePrecision] + N[Power[t$95$4, 6.0], $MachinePrecision]), $MachinePrecision] / N[(N[(-1.0 * N[(N[Power[N[Cos[phi1], $MachinePrecision], 2.0], $MachinePrecision] * N[(N[Power[N[Cos[phi2], $MachinePrecision], 2.0], $MachinePrecision] * N[Power[t$95$0, 4.0], $MachinePrecision]), $MachinePrecision] + N[Power[t$95$4, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(-1.0 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[(t$95$1 * t$95$5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.5), $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)\\
t_1 := t\_0 \cdot t\_0\\
t_2 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_3 := \sin \left(-0.5 \cdot \phi_2\right)\\
t_4 := \sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\\
t_5 := t\_4 \cdot t\_4\\
t_6 := \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_2\right) \cdot t\_2\\
\mathbf{if}\;{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t\_6 \leq 2 \cdot 10^{-166}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_2, t\_1, t\_3 \cdot t\_3\right)}}{\sqrt{1 - \left({\sin \left(\frac{-1 \cdot \phi_2}{2}\right)}^{2} + t\_6\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{{\left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot t\_1, t\_5\right)\right)}^{0.5}}{e^{\log \left(1 + \frac{\mathsf{fma}\left({\cos \phi_1}^{3}, {\cos \phi_2}^{3} \cdot {t\_0}^{6}, {t\_4}^{6}\right)}{-1 \cdot \mathsf{fma}\left({\cos \phi_1}^{2}, {\cos \phi_2}^{2} \cdot {t\_0}^{4}, {t\_4}^{4}\right) - \left(-1 \cdot \cos \phi_1\right) \cdot \left(\cos \phi_2 \cdot \left(t\_1 \cdot t\_5\right)\right)}\right) \cdot 0.5}}\right)\\
\end{array}
\end{array}
if (+.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))))) < 2.00000000000000008e-166Initial program 57.6%
Taylor expanded in phi1 around 0
lower-*.f6457.6
Applied rewrites57.6%
Taylor expanded in phi1 around 0
lower-fma.f64N/A
lift-cos.f64N/A
pow2N/A
lift-*.f64N/A
lift--.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
unpow2N/A
lower-*.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-*.f6467.3
Applied rewrites67.3%
if 2.00000000000000008e-166 < (+.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 63.2%
Applied rewrites63.1%
Taylor expanded in lambda1 around 0
Applied rewrites63.1%
Applied rewrites63.2%
Final simplification63.5%
(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))
(t_2 (/ (- phi1 phi2) 2.0)))
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin t_2) 2.0) t_1))
(sqrt (- 1.0 (+ (/ (- 1.0 (cos (+ t_2 t_2))) 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;
double t_2 = (phi1 - phi2) / 2.0;
return R * (2.0 * atan2(sqrt((pow(sin(t_2), 2.0) + t_1)), sqrt((1.0 - (((1.0 - cos((t_2 + t_2))) / 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
real(8) :: t_2
t_0 = sin(((lambda1 - lambda2) / 2.0d0))
t_1 = ((cos(phi1) * cos(phi2)) * t_0) * t_0
t_2 = (phi1 - phi2) / 2.0d0
code = r * (2.0d0 * atan2(sqrt(((sin(t_2) ** 2.0d0) + t_1)), sqrt((1.0d0 - (((1.0d0 - cos((t_2 + t_2))) / 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;
double t_2 = (phi1 - phi2) / 2.0;
return R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(t_2), 2.0) + t_1)), Math.sqrt((1.0 - (((1.0 - Math.cos((t_2 + t_2))) / 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 t_2 = (phi1 - phi2) / 2.0 return R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(t_2), 2.0) + t_1)), math.sqrt((1.0 - (((1.0 - math.cos((t_2 + t_2))) / 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) t_2 = Float64(Float64(phi1 - phi2) / 2.0) return Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(t_2) ^ 2.0) + t_1)), sqrt(Float64(1.0 - Float64(Float64(Float64(1.0 - cos(Float64(t_2 + t_2))) / 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; t_2 = (phi1 - phi2) / 2.0; tmp = R * (2.0 * atan2(sqrt(((sin(t_2) ^ 2.0) + t_1)), sqrt((1.0 - (((1.0 - cos((t_2 + t_2))) / 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]}, Block[{t$95$2 = N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[t$95$2], $MachinePrecision], 2.0], $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[(N[(1.0 - N[Cos[N[(t$95$2 + t$95$2), $MachinePrecision]], $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\\
t_2 := \frac{\phi_1 - \phi_2}{2}\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin t\_2}^{2} + t\_1}}{\sqrt{1 - \left(\frac{1 - \cos \left(t\_2 + t\_2\right)}{2} + t\_1\right)}}\right)
\end{array}
\end{array}
Initial program 62.8%
lift-pow.f64N/A
lift-sin.f64N/A
lift--.f64N/A
lift-/.f64N/A
unpow2N/A
sin-multN/A
lower-/.f64N/A
Applied rewrites62.8%
Final simplification62.8%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (* 0.5 (- lambda1 lambda2))))
(t_1 (sin (/ (- lambda1 lambda2) 2.0)))
(t_2
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* (* (* (cos phi1) (cos phi2)) t_1) t_1)))
(t_3 (sin (* 0.5 (- phi1 phi2))))
(t_4 (* t_3 t_3))
(t_5 (* t_0 t_0)))
(if (<= t_2 2e-166)
(* R (* 2.0 (atan2 (sqrt t_5) (sqrt (- 1.0 t_2)))))
(*
R
(*
2.0
(atan2
(pow (fma (cos phi1) (* (cos phi2) t_5) t_4) 0.5)
(exp
(*
(log
(+
1.0
(/
(fma
(pow (cos phi1) 3.0)
(* (pow (cos phi2) 3.0) (pow t_0 6.0))
(pow t_3 6.0))
(-
(*
-1.0
(fma
(pow (cos phi1) 2.0)
(* (pow (cos phi2) 2.0) (pow t_0 4.0))
(pow t_3 4.0)))
(* (* -1.0 (cos phi1)) (* (cos phi2) (* t_5 t_4)))))))
0.5))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin((0.5 * (lambda1 - lambda2)));
double t_1 = sin(((lambda1 - lambda2) / 2.0));
double t_2 = pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (((cos(phi1) * cos(phi2)) * t_1) * t_1);
double t_3 = sin((0.5 * (phi1 - phi2)));
double t_4 = t_3 * t_3;
double t_5 = t_0 * t_0;
double tmp;
if (t_2 <= 2e-166) {
tmp = R * (2.0 * atan2(sqrt(t_5), sqrt((1.0 - t_2))));
} else {
tmp = R * (2.0 * atan2(pow(fma(cos(phi1), (cos(phi2) * t_5), t_4), 0.5), exp((log((1.0 + (fma(pow(cos(phi1), 3.0), (pow(cos(phi2), 3.0) * pow(t_0, 6.0)), pow(t_3, 6.0)) / ((-1.0 * fma(pow(cos(phi1), 2.0), (pow(cos(phi2), 2.0) * pow(t_0, 4.0)), pow(t_3, 4.0))) - ((-1.0 * cos(phi1)) * (cos(phi2) * (t_5 * t_4))))))) * 0.5))));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_2 = Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_1) * t_1)) t_3 = sin(Float64(0.5 * Float64(phi1 - phi2))) t_4 = Float64(t_3 * t_3) t_5 = Float64(t_0 * t_0) tmp = 0.0 if (t_2 <= 2e-166) tmp = Float64(R * Float64(2.0 * atan(sqrt(t_5), sqrt(Float64(1.0 - t_2))))); else tmp = Float64(R * Float64(2.0 * atan((fma(cos(phi1), Float64(cos(phi2) * t_5), t_4) ^ 0.5), exp(Float64(log(Float64(1.0 + Float64(fma((cos(phi1) ^ 3.0), Float64((cos(phi2) ^ 3.0) * (t_0 ^ 6.0)), (t_3 ^ 6.0)) / Float64(Float64(-1.0 * fma((cos(phi1) ^ 2.0), Float64((cos(phi2) ^ 2.0) * (t_0 ^ 4.0)), (t_3 ^ 4.0))) - Float64(Float64(-1.0 * cos(phi1)) * Float64(cos(phi2) * Float64(t_5 * t_4))))))) * 0.5))))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = 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$1), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[(t$95$3 * t$95$3), $MachinePrecision]}, Block[{t$95$5 = N[(t$95$0 * t$95$0), $MachinePrecision]}, If[LessEqual[t$95$2, 2e-166], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$5], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$2), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Power[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * t$95$5), $MachinePrecision] + t$95$4), $MachinePrecision], 0.5], $MachinePrecision] / N[Exp[N[(N[Log[N[(1.0 + N[(N[(N[Power[N[Cos[phi1], $MachinePrecision], 3.0], $MachinePrecision] * N[(N[Power[N[Cos[phi2], $MachinePrecision], 3.0], $MachinePrecision] * N[Power[t$95$0, 6.0], $MachinePrecision]), $MachinePrecision] + N[Power[t$95$3, 6.0], $MachinePrecision]), $MachinePrecision] / N[(N[(-1.0 * N[(N[Power[N[Cos[phi1], $MachinePrecision], 2.0], $MachinePrecision] * N[(N[Power[N[Cos[phi2], $MachinePrecision], 2.0], $MachinePrecision] * N[Power[t$95$0, 4.0], $MachinePrecision]), $MachinePrecision] + N[Power[t$95$3, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(-1.0 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[(t$95$5 * t$95$4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.5), $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)\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_1\right) \cdot t\_1\\
t_3 := \sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\\
t_4 := t\_3 \cdot t\_3\\
t_5 := t\_0 \cdot t\_0\\
\mathbf{if}\;t\_2 \leq 2 \cdot 10^{-166}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_5}}{\sqrt{1 - t\_2}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{{\left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot t\_5, t\_4\right)\right)}^{0.5}}{e^{\log \left(1 + \frac{\mathsf{fma}\left({\cos \phi_1}^{3}, {\cos \phi_2}^{3} \cdot {t\_0}^{6}, {t\_3}^{6}\right)}{-1 \cdot \mathsf{fma}\left({\cos \phi_1}^{2}, {\cos \phi_2}^{2} \cdot {t\_0}^{4}, {t\_3}^{4}\right) - \left(-1 \cdot \cos \phi_1\right) \cdot \left(\cos \phi_2 \cdot \left(t\_5 \cdot t\_4\right)\right)}\right) \cdot 0.5}}\right)\\
\end{array}
\end{array}
if (+.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))))) < 2.00000000000000008e-166Initial program 57.6%
Taylor expanded in phi1 around 0
+-commutativeN/A
sqr-powN/A
lower-fma.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites66.4%
Taylor expanded in phi2 around 0
pow2N/A
lift-*.f64N/A
lift--.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-sin.f64N/A
lift-*.f6451.2
Applied rewrites51.2%
if 2.00000000000000008e-166 < (+.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 63.2%
Applied rewrites63.1%
Taylor expanded in lambda1 around 0
Applied rewrites63.1%
Applied rewrites63.2%
Final simplification62.3%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (* 0.5 (- lambda1 lambda2))))
(t_1 (* t_0 t_0))
(t_2 (sin (* 0.5 (- phi1 phi2))))
(t_3 (* t_2 t_2)))
(*
R
(*
2.0
(atan2
(pow (fma (cos phi1) (* (cos phi2) t_1) t_3) 0.5)
(exp
(*
(log
(+
1.0
(/
(fma
(pow (cos phi1) 3.0)
(* (pow (cos phi2) 3.0) (pow t_0 6.0))
(pow t_2 6.0))
(-
(*
-1.0
(fma
(pow (cos phi1) 2.0)
(* (pow (cos phi2) 2.0) (pow t_0 4.0))
(pow t_2 4.0)))
(* (* -1.0 (cos phi1)) (* (cos phi2) (* t_1 t_3)))))))
0.5)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin((0.5 * (lambda1 - lambda2)));
double t_1 = t_0 * t_0;
double t_2 = sin((0.5 * (phi1 - phi2)));
double t_3 = t_2 * t_2;
return R * (2.0 * atan2(pow(fma(cos(phi1), (cos(phi2) * t_1), t_3), 0.5), exp((log((1.0 + (fma(pow(cos(phi1), 3.0), (pow(cos(phi2), 3.0) * pow(t_0, 6.0)), pow(t_2, 6.0)) / ((-1.0 * fma(pow(cos(phi1), 2.0), (pow(cos(phi2), 2.0) * pow(t_0, 4.0)), pow(t_2, 4.0))) - ((-1.0 * cos(phi1)) * (cos(phi2) * (t_1 * t_3))))))) * 0.5))));
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) t_1 = Float64(t_0 * t_0) t_2 = sin(Float64(0.5 * Float64(phi1 - phi2))) t_3 = Float64(t_2 * t_2) return Float64(R * Float64(2.0 * atan((fma(cos(phi1), Float64(cos(phi2) * t_1), t_3) ^ 0.5), exp(Float64(log(Float64(1.0 + Float64(fma((cos(phi1) ^ 3.0), Float64((cos(phi2) ^ 3.0) * (t_0 ^ 6.0)), (t_2 ^ 6.0)) / Float64(Float64(-1.0 * fma((cos(phi1) ^ 2.0), Float64((cos(phi2) ^ 2.0) * (t_0 ^ 4.0)), (t_2 ^ 4.0))) - Float64(Float64(-1.0 * cos(phi1)) * Float64(cos(phi2) * Float64(t_1 * t_3))))))) * 0.5))))) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 * t$95$2), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Power[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * t$95$1), $MachinePrecision] + t$95$3), $MachinePrecision], 0.5], $MachinePrecision] / N[Exp[N[(N[Log[N[(1.0 + N[(N[(N[Power[N[Cos[phi1], $MachinePrecision], 3.0], $MachinePrecision] * N[(N[Power[N[Cos[phi2], $MachinePrecision], 3.0], $MachinePrecision] * N[Power[t$95$0, 6.0], $MachinePrecision]), $MachinePrecision] + N[Power[t$95$2, 6.0], $MachinePrecision]), $MachinePrecision] / N[(N[(-1.0 * N[(N[Power[N[Cos[phi1], $MachinePrecision], 2.0], $MachinePrecision] * N[(N[Power[N[Cos[phi2], $MachinePrecision], 2.0], $MachinePrecision] * N[Power[t$95$0, 4.0], $MachinePrecision]), $MachinePrecision] + N[Power[t$95$2, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(-1.0 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[(t$95$1 * t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.5), $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)\\
t_1 := t\_0 \cdot t\_0\\
t_2 := \sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\\
t_3 := t\_2 \cdot t\_2\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{{\left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot t\_1, t\_3\right)\right)}^{0.5}}{e^{\log \left(1 + \frac{\mathsf{fma}\left({\cos \phi_1}^{3}, {\cos \phi_2}^{3} \cdot {t\_0}^{6}, {t\_2}^{6}\right)}{-1 \cdot \mathsf{fma}\left({\cos \phi_1}^{2}, {\cos \phi_2}^{2} \cdot {t\_0}^{4}, {t\_2}^{4}\right) - \left(-1 \cdot \cos \phi_1\right) \cdot \left(\cos \phi_2 \cdot \left(t\_1 \cdot t\_3\right)\right)}\right) \cdot 0.5}}\right)
\end{array}
\end{array}
Initial program 62.8%
Applied rewrites58.4%
Taylor expanded in lambda1 around 0
Applied rewrites58.5%
Applied rewrites58.5%
Final simplification58.5%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (* 0.5 (- lambda1 lambda2))))
(t_1 (sin (* 0.5 (- phi1 phi2))))
(t_2 (* t_1 t_1)))
(*
R
(*
2.0
(atan2
(pow
(fma
(cos phi1)
(* (cos phi2) (* t_0 (sin (* 0.5 (* -1.0 lambda2)))))
t_2)
0.5)
(pow
(+
1.0
(/
(fma
(pow (cos phi1) 3.0)
(* (pow (cos phi2) 3.0) (pow t_0 6.0))
(pow t_1 6.0))
(-
(*
-1.0
(fma
(pow (cos phi1) 2.0)
(* (pow (cos phi2) 2.0) (pow t_0 4.0))
(pow t_1 4.0)))
(* (* -1.0 (cos phi1)) (* (cos phi2) (* (* t_0 t_0) t_2))))))
0.5))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin((0.5 * (lambda1 - lambda2)));
double t_1 = sin((0.5 * (phi1 - phi2)));
double t_2 = t_1 * t_1;
return R * (2.0 * atan2(pow(fma(cos(phi1), (cos(phi2) * (t_0 * sin((0.5 * (-1.0 * lambda2))))), t_2), 0.5), pow((1.0 + (fma(pow(cos(phi1), 3.0), (pow(cos(phi2), 3.0) * pow(t_0, 6.0)), pow(t_1, 6.0)) / ((-1.0 * fma(pow(cos(phi1), 2.0), (pow(cos(phi2), 2.0) * pow(t_0, 4.0)), pow(t_1, 4.0))) - ((-1.0 * cos(phi1)) * (cos(phi2) * ((t_0 * t_0) * t_2)))))), 0.5)));
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) t_1 = sin(Float64(0.5 * Float64(phi1 - phi2))) t_2 = Float64(t_1 * t_1) return Float64(R * Float64(2.0 * atan((fma(cos(phi1), Float64(cos(phi2) * Float64(t_0 * sin(Float64(0.5 * Float64(-1.0 * lambda2))))), t_2) ^ 0.5), (Float64(1.0 + Float64(fma((cos(phi1) ^ 3.0), Float64((cos(phi2) ^ 3.0) * (t_0 ^ 6.0)), (t_1 ^ 6.0)) / Float64(Float64(-1.0 * fma((cos(phi1) ^ 2.0), Float64((cos(phi2) ^ 2.0) * (t_0 ^ 4.0)), (t_1 ^ 4.0))) - Float64(Float64(-1.0 * cos(phi1)) * Float64(cos(phi2) * Float64(Float64(t_0 * t_0) * t_2)))))) ^ 0.5)))) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * t$95$1), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Power[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[(t$95$0 * N[Sin[N[(0.5 * N[(-1.0 * lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision], 0.5], $MachinePrecision] / N[Power[N[(1.0 + N[(N[(N[Power[N[Cos[phi1], $MachinePrecision], 3.0], $MachinePrecision] * N[(N[Power[N[Cos[phi2], $MachinePrecision], 3.0], $MachinePrecision] * N[Power[t$95$0, 6.0], $MachinePrecision]), $MachinePrecision] + N[Power[t$95$1, 6.0], $MachinePrecision]), $MachinePrecision] / N[(N[(-1.0 * N[(N[Power[N[Cos[phi1], $MachinePrecision], 2.0], $MachinePrecision] * N[(N[Power[N[Cos[phi2], $MachinePrecision], 2.0], $MachinePrecision] * N[Power[t$95$0, 4.0], $MachinePrecision]), $MachinePrecision] + N[Power[t$95$1, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(-1.0 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[(N[(t$95$0 * t$95$0), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)\\
t_1 := \sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\\
t_2 := t\_1 \cdot t\_1\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{{\left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \left(t\_0 \cdot \sin \left(0.5 \cdot \left(-1 \cdot \lambda_2\right)\right)\right), t\_2\right)\right)}^{0.5}}{{\left(1 + \frac{\mathsf{fma}\left({\cos \phi_1}^{3}, {\cos \phi_2}^{3} \cdot {t\_0}^{6}, {t\_1}^{6}\right)}{-1 \cdot \mathsf{fma}\left({\cos \phi_1}^{2}, {\cos \phi_2}^{2} \cdot {t\_0}^{4}, {t\_1}^{4}\right) - \left(-1 \cdot \cos \phi_1\right) \cdot \left(\cos \phi_2 \cdot \left(\left(t\_0 \cdot t\_0\right) \cdot t\_2\right)\right)}\right)}^{0.5}}\right)
\end{array}
\end{array}
Initial program 62.8%
Applied rewrites58.4%
Taylor expanded in lambda1 around 0
Applied rewrites58.5%
Taylor expanded in lambda1 around 0
lower-*.f6442.5
Applied rewrites42.5%
Final simplification42.5%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (* 0.5 (- lambda1 lambda2))))
(t_1 (sin (* -0.5 lambda2)))
(t_2 (sin (* 0.5 (- phi1 phi2))))
(t_3 (* t_2 t_2)))
(*
R
(*
2.0
(atan2
(pow
(fma
(cos phi1)
(* (cos phi2) (* t_0 (sin (* 0.5 (* -1.0 lambda2)))))
t_3)
0.5)
(pow
(-
1.0
(/
(fma
(pow (cos phi1) 3.0)
(* (pow (cos phi2) 3.0) (pow t_0 6.0))
(pow t_2 6.0))
(-
(fma
(pow (cos phi1) 2.0)
(*
(pow (cos phi2) 2.0)
(fma
2.0
(*
lambda1
(* (sin (fma -0.5 lambda2 (/ PI 2.0))) (* (* t_1 t_1) t_1)))
(pow t_1 4.0)))
(pow t_2 4.0))
(* (- (* -1.0 (cos phi1))) (* (cos phi2) (* (* t_0 t_0) t_3))))))
0.5))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin((0.5 * (lambda1 - lambda2)));
double t_1 = sin((-0.5 * lambda2));
double t_2 = sin((0.5 * (phi1 - phi2)));
double t_3 = t_2 * t_2;
return R * (2.0 * atan2(pow(fma(cos(phi1), (cos(phi2) * (t_0 * sin((0.5 * (-1.0 * lambda2))))), t_3), 0.5), pow((1.0 - (fma(pow(cos(phi1), 3.0), (pow(cos(phi2), 3.0) * pow(t_0, 6.0)), pow(t_2, 6.0)) / (fma(pow(cos(phi1), 2.0), (pow(cos(phi2), 2.0) * fma(2.0, (lambda1 * (sin(fma(-0.5, lambda2, (((double) M_PI) / 2.0))) * ((t_1 * t_1) * t_1))), pow(t_1, 4.0))), pow(t_2, 4.0)) - (-(-1.0 * cos(phi1)) * (cos(phi2) * ((t_0 * t_0) * t_3)))))), 0.5)));
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) t_1 = sin(Float64(-0.5 * lambda2)) t_2 = sin(Float64(0.5 * Float64(phi1 - phi2))) t_3 = Float64(t_2 * t_2) return Float64(R * Float64(2.0 * atan((fma(cos(phi1), Float64(cos(phi2) * Float64(t_0 * sin(Float64(0.5 * Float64(-1.0 * lambda2))))), t_3) ^ 0.5), (Float64(1.0 - Float64(fma((cos(phi1) ^ 3.0), Float64((cos(phi2) ^ 3.0) * (t_0 ^ 6.0)), (t_2 ^ 6.0)) / Float64(fma((cos(phi1) ^ 2.0), Float64((cos(phi2) ^ 2.0) * fma(2.0, Float64(lambda1 * Float64(sin(fma(-0.5, lambda2, Float64(pi / 2.0))) * Float64(Float64(t_1 * t_1) * t_1))), (t_1 ^ 4.0))), (t_2 ^ 4.0)) - Float64(Float64(-Float64(-1.0 * cos(phi1))) * Float64(cos(phi2) * Float64(Float64(t_0 * t_0) * t_3)))))) ^ 0.5)))) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(-0.5 * lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 * t$95$2), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Power[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[(t$95$0 * N[Sin[N[(0.5 * N[(-1.0 * lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$3), $MachinePrecision], 0.5], $MachinePrecision] / N[Power[N[(1.0 - N[(N[(N[Power[N[Cos[phi1], $MachinePrecision], 3.0], $MachinePrecision] * N[(N[Power[N[Cos[phi2], $MachinePrecision], 3.0], $MachinePrecision] * N[Power[t$95$0, 6.0], $MachinePrecision]), $MachinePrecision] + N[Power[t$95$2, 6.0], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Power[N[Cos[phi1], $MachinePrecision], 2.0], $MachinePrecision] * N[(N[Power[N[Cos[phi2], $MachinePrecision], 2.0], $MachinePrecision] * N[(2.0 * N[(lambda1 * N[(N[Sin[N[(-0.5 * lambda2 + N[(Pi / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(N[(t$95$1 * t$95$1), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[t$95$1, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[t$95$2, 4.0], $MachinePrecision]), $MachinePrecision] - N[((-N[(-1.0 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]) * N[(N[Cos[phi2], $MachinePrecision] * N[(N[(t$95$0 * t$95$0), $MachinePrecision] * t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)\\
t_1 := \sin \left(-0.5 \cdot \lambda_2\right)\\
t_2 := \sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\\
t_3 := t\_2 \cdot t\_2\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{{\left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \left(t\_0 \cdot \sin \left(0.5 \cdot \left(-1 \cdot \lambda_2\right)\right)\right), t\_3\right)\right)}^{0.5}}{{\left(1 - \frac{\mathsf{fma}\left({\cos \phi_1}^{3}, {\cos \phi_2}^{3} \cdot {t\_0}^{6}, {t\_2}^{6}\right)}{\mathsf{fma}\left({\cos \phi_1}^{2}, {\cos \phi_2}^{2} \cdot \mathsf{fma}\left(2, \lambda_1 \cdot \left(\sin \left(\mathsf{fma}\left(-0.5, \lambda_2, \frac{\pi}{2}\right)\right) \cdot \left(\left(t\_1 \cdot t\_1\right) \cdot t\_1\right)\right), {t\_1}^{4}\right), {t\_2}^{4}\right) - \left(--1 \cdot \cos \phi_1\right) \cdot \left(\cos \phi_2 \cdot \left(\left(t\_0 \cdot t\_0\right) \cdot t\_3\right)\right)}\right)}^{0.5}}\right)
\end{array}
\end{array}
Initial program 62.8%
Applied rewrites58.4%
Taylor expanded in lambda1 around 0
Applied rewrites58.5%
Taylor expanded in lambda1 around 0
lower-*.f6442.5
Applied rewrites42.5%
Taylor expanded in lambda1 around 0
lower-fma.f64N/A
Applied rewrites42.3%
Final simplification42.3%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (* -0.5 lambda2)))
(t_1 (sin (* 0.5 (- phi1 phi2))))
(t_2 (* t_1 t_1)))
(*
R
(*
2.0
(atan2
(pow
(fma
(cos phi1)
(*
(cos phi2)
(* (sin (* 0.5 (- lambda1 lambda2))) (sin (* 0.5 (* -1.0 lambda2)))))
t_2)
0.5)
(pow
(-
1.0
(/
(fma
(pow (cos phi1) 3.0)
(* (pow (cos phi2) 3.0) (pow t_0 6.0))
(pow t_1 6.0))
(-
(fma
(pow (cos phi1) 2.0)
(* (pow (cos phi2) 2.0) (pow t_0 4.0))
(pow t_1 4.0))
(* (cos phi1) (* (cos phi2) (* (* t_0 t_0) t_2))))))
0.5))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin((-0.5 * lambda2));
double t_1 = sin((0.5 * (phi1 - phi2)));
double t_2 = t_1 * t_1;
return R * (2.0 * atan2(pow(fma(cos(phi1), (cos(phi2) * (sin((0.5 * (lambda1 - lambda2))) * sin((0.5 * (-1.0 * lambda2))))), t_2), 0.5), pow((1.0 - (fma(pow(cos(phi1), 3.0), (pow(cos(phi2), 3.0) * pow(t_0, 6.0)), pow(t_1, 6.0)) / (fma(pow(cos(phi1), 2.0), (pow(cos(phi2), 2.0) * pow(t_0, 4.0)), pow(t_1, 4.0)) - (cos(phi1) * (cos(phi2) * ((t_0 * t_0) * t_2)))))), 0.5)));
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(-0.5 * lambda2)) t_1 = sin(Float64(0.5 * Float64(phi1 - phi2))) t_2 = Float64(t_1 * t_1) return Float64(R * Float64(2.0 * atan((fma(cos(phi1), Float64(cos(phi2) * Float64(sin(Float64(0.5 * Float64(lambda1 - lambda2))) * sin(Float64(0.5 * Float64(-1.0 * lambda2))))), t_2) ^ 0.5), (Float64(1.0 - Float64(fma((cos(phi1) ^ 3.0), Float64((cos(phi2) ^ 3.0) * (t_0 ^ 6.0)), (t_1 ^ 6.0)) / Float64(fma((cos(phi1) ^ 2.0), Float64((cos(phi2) ^ 2.0) * (t_0 ^ 4.0)), (t_1 ^ 4.0)) - Float64(cos(phi1) * Float64(cos(phi2) * Float64(Float64(t_0 * t_0) * t_2)))))) ^ 0.5)))) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(-0.5 * lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * t$95$1), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Power[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[(N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * N[(-1.0 * lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision], 0.5], $MachinePrecision] / N[Power[N[(1.0 - N[(N[(N[Power[N[Cos[phi1], $MachinePrecision], 3.0], $MachinePrecision] * N[(N[Power[N[Cos[phi2], $MachinePrecision], 3.0], $MachinePrecision] * N[Power[t$95$0, 6.0], $MachinePrecision]), $MachinePrecision] + N[Power[t$95$1, 6.0], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Power[N[Cos[phi1], $MachinePrecision], 2.0], $MachinePrecision] * N[(N[Power[N[Cos[phi2], $MachinePrecision], 2.0], $MachinePrecision] * N[Power[t$95$0, 4.0], $MachinePrecision]), $MachinePrecision] + N[Power[t$95$1, 4.0], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[(N[(t$95$0 * t$95$0), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(-0.5 \cdot \lambda_2\right)\\
t_1 := \sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\\
t_2 := t\_1 \cdot t\_1\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{{\left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \left(\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \sin \left(0.5 \cdot \left(-1 \cdot \lambda_2\right)\right)\right), t\_2\right)\right)}^{0.5}}{{\left(1 - \frac{\mathsf{fma}\left({\cos \phi_1}^{3}, {\cos \phi_2}^{3} \cdot {t\_0}^{6}, {t\_1}^{6}\right)}{\mathsf{fma}\left({\cos \phi_1}^{2}, {\cos \phi_2}^{2} \cdot {t\_0}^{4}, {t\_1}^{4}\right) - \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \left(\left(t\_0 \cdot t\_0\right) \cdot t\_2\right)\right)}\right)}^{0.5}}\right)
\end{array}
\end{array}
Initial program 62.8%
Applied rewrites58.4%
Taylor expanded in lambda1 around 0
Applied rewrites58.5%
Taylor expanded in lambda1 around 0
lower-*.f6442.5
Applied rewrites42.5%
Taylor expanded in lambda1 around 0
Applied rewrites42.2%
herbie shell --seed 2025066
(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))))))))))