
(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 (* (- lambda2 lambda1) -0.5)) (t_1 (sin (* -0.5 phi2))))
(*
(* 2.0 R)
(atan2
(sqrt
(fma
(pow (sin t_0) 2.0)
(* (cos phi2) (cos phi1))
(pow
(-
(* (cos (* 0.5 phi1)) t_1)
(* (cos (* 0.5 phi2)) (sin (* -0.5 phi1))))
2.0)))
(sqrt
(-
1.0
(fma
(* (- 0.5 (* 0.5 (cos (* 2.0 t_0)))) (cos phi2))
(cos phi1)
(pow
(fma
(cos (* -0.5 phi2))
(sin (* 0.5 phi1))
(* t_1 (cos (* -0.5 phi1))))
2.0))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (lambda2 - lambda1) * -0.5;
double t_1 = sin((-0.5 * phi2));
return (2.0 * R) * atan2(sqrt(fma(pow(sin(t_0), 2.0), (cos(phi2) * cos(phi1)), pow(((cos((0.5 * phi1)) * t_1) - (cos((0.5 * phi2)) * sin((-0.5 * phi1)))), 2.0))), sqrt((1.0 - fma(((0.5 - (0.5 * cos((2.0 * t_0)))) * cos(phi2)), cos(phi1), pow(fma(cos((-0.5 * phi2)), sin((0.5 * phi1)), (t_1 * cos((-0.5 * phi1)))), 2.0)))));
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(Float64(lambda2 - lambda1) * -0.5) t_1 = sin(Float64(-0.5 * phi2)) return Float64(Float64(2.0 * R) * atan(sqrt(fma((sin(t_0) ^ 2.0), Float64(cos(phi2) * cos(phi1)), (Float64(Float64(cos(Float64(0.5 * phi1)) * t_1) - Float64(cos(Float64(0.5 * phi2)) * sin(Float64(-0.5 * phi1)))) ^ 2.0))), sqrt(Float64(1.0 - fma(Float64(Float64(0.5 - Float64(0.5 * cos(Float64(2.0 * t_0)))) * cos(phi2)), cos(phi1), (fma(cos(Float64(-0.5 * phi2)), sin(Float64(0.5 * phi1)), Float64(t_1 * cos(Float64(-0.5 * phi1)))) ^ 2.0)))))) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(lambda2 - lambda1), $MachinePrecision] * -0.5), $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision]}, N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[t$95$0], $MachinePrecision], 2.0], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * t$95$1), $MachinePrecision] - N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[(N[(0.5 - N[(0.5 * N[Cos[N[(2.0 * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[Power[N[(N[Cos[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] + N[(t$95$1 * N[Cos[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\lambda_2 - \lambda_1\right) \cdot -0.5\\
t_1 := \sin \left(-0.5 \cdot \phi_2\right)\\
\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left({\sin t\_0}^{2}, \cos \phi_2 \cdot \cos \phi_1, {\left(\cos \left(0.5 \cdot \phi_1\right) \cdot t\_1 - \cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(-0.5 \cdot \phi_1\right)\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(\left(0.5 - 0.5 \cdot \cos \left(2 \cdot t\_0\right)\right) \cdot \cos \phi_2, \cos \phi_1, {\left(\mathsf{fma}\left(\cos \left(-0.5 \cdot \phi_2\right), \sin \left(0.5 \cdot \phi_1\right), t\_1 \cdot \cos \left(-0.5 \cdot \phi_1\right)\right)\right)}^{2}\right)}}
\end{array}
\end{array}
Initial program 63.4%
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-/.f6464.1
Applied rewrites64.1%
Taylor expanded in R around 0
Applied rewrites64.1%
Applied rewrites77.4%
Applied rewrites77.4%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (* -0.5 phi2)))
(t_1 (sin (* 0.5 phi1)))
(t_2 (sin (/ (- lambda1 lambda2) 2.0)))
(t_3 (* (- lambda2 lambda1) -0.5))
(t_4 (pow (sin t_3) 2.0))
(t_5
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* (* (* (cos phi1) (cos phi2)) t_2) t_2)))
(t_6 (* (cos phi2) (cos phi1))))
(if (<= (* 2.0 (atan2 (sqrt t_5) (sqrt (- 1.0 t_5)))) 2e-12)
(*
(* 2.0 R)
(atan2
(sqrt (fma t_4 t_6 (pow (sin (* (- phi2 phi1) -0.5)) 2.0)))
(sqrt (- 1.0 (fma t_4 (cos phi1) (pow t_1 2.0))))))
(*
(* 2.0 R)
(atan2
(sqrt
(fma
(- 0.5 (* 0.5 (cos (* 2.0 t_3))))
t_6
(pow
(-
(* (cos (* 0.5 phi1)) t_0)
(* (cos (* 0.5 phi2)) (sin (* -0.5 phi1))))
2.0)))
(sqrt
(-
1.0
(fma
(* t_4 (cos phi2))
(cos phi1)
(pow
(fma (cos (* -0.5 phi2)) t_1 (* t_0 (cos (* -0.5 phi1))))
2.0)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin((-0.5 * phi2));
double t_1 = sin((0.5 * phi1));
double t_2 = sin(((lambda1 - lambda2) / 2.0));
double t_3 = (lambda2 - lambda1) * -0.5;
double t_4 = pow(sin(t_3), 2.0);
double t_5 = pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (((cos(phi1) * cos(phi2)) * t_2) * t_2);
double t_6 = cos(phi2) * cos(phi1);
double tmp;
if ((2.0 * atan2(sqrt(t_5), sqrt((1.0 - t_5)))) <= 2e-12) {
tmp = (2.0 * R) * atan2(sqrt(fma(t_4, t_6, pow(sin(((phi2 - phi1) * -0.5)), 2.0))), sqrt((1.0 - fma(t_4, cos(phi1), pow(t_1, 2.0)))));
} else {
tmp = (2.0 * R) * atan2(sqrt(fma((0.5 - (0.5 * cos((2.0 * t_3)))), t_6, pow(((cos((0.5 * phi1)) * t_0) - (cos((0.5 * phi2)) * sin((-0.5 * phi1)))), 2.0))), sqrt((1.0 - fma((t_4 * cos(phi2)), cos(phi1), pow(fma(cos((-0.5 * phi2)), t_1, (t_0 * cos((-0.5 * phi1)))), 2.0)))));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(-0.5 * phi2)) t_1 = sin(Float64(0.5 * phi1)) t_2 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_3 = Float64(Float64(lambda2 - lambda1) * -0.5) t_4 = sin(t_3) ^ 2.0 t_5 = Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_2) * t_2)) t_6 = Float64(cos(phi2) * cos(phi1)) tmp = 0.0 if (Float64(2.0 * atan(sqrt(t_5), sqrt(Float64(1.0 - t_5)))) <= 2e-12) tmp = Float64(Float64(2.0 * R) * atan(sqrt(fma(t_4, t_6, (sin(Float64(Float64(phi2 - phi1) * -0.5)) ^ 2.0))), sqrt(Float64(1.0 - fma(t_4, cos(phi1), (t_1 ^ 2.0)))))); else tmp = Float64(Float64(2.0 * R) * atan(sqrt(fma(Float64(0.5 - Float64(0.5 * cos(Float64(2.0 * t_3)))), t_6, (Float64(Float64(cos(Float64(0.5 * phi1)) * t_0) - Float64(cos(Float64(0.5 * phi2)) * sin(Float64(-0.5 * phi1)))) ^ 2.0))), sqrt(Float64(1.0 - fma(Float64(t_4 * cos(phi2)), cos(phi1), (fma(cos(Float64(-0.5 * phi2)), t_1, Float64(t_0 * cos(Float64(-0.5 * phi1)))) ^ 2.0)))))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[(lambda2 - lambda1), $MachinePrecision] * -0.5), $MachinePrecision]}, Block[{t$95$4 = N[Power[N[Sin[t$95$3], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$5 = 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$2), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$6 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(2.0 * N[ArcTan[N[Sqrt[t$95$5], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2e-12], N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[N[(t$95$4 * t$95$6 + N[Power[N[Sin[N[(N[(phi2 - phi1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(t$95$4 * N[Cos[phi1], $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[N[(N[(0.5 - N[(0.5 * N[Cos[N[(2.0 * t$95$3), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$6 + N[Power[N[(N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision] - N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[(t$95$4 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[Power[N[(N[Cos[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision] * t$95$1 + N[(t$95$0 * N[Cos[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(-0.5 \cdot \phi_2\right)\\
t_1 := \sin \left(0.5 \cdot \phi_1\right)\\
t_2 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_3 := \left(\lambda_2 - \lambda_1\right) \cdot -0.5\\
t_4 := {\sin t\_3}^{2}\\
t_5 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_2\right) \cdot t\_2\\
t_6 := \cos \phi_2 \cdot \cos \phi_1\\
\mathbf{if}\;2 \cdot \tan^{-1}_* \frac{\sqrt{t\_5}}{\sqrt{1 - t\_5}} \leq 2 \cdot 10^{-12}:\\
\;\;\;\;\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_4, t\_6, {\sin \left(\left(\phi_2 - \phi_1\right) \cdot -0.5\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(t\_4, \cos \phi_1, {t\_1}^{2}\right)}}\\
\mathbf{else}:\\
\;\;\;\;\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(0.5 - 0.5 \cdot \cos \left(2 \cdot t\_3\right), t\_6, {\left(\cos \left(0.5 \cdot \phi_1\right) \cdot t\_0 - \cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(-0.5 \cdot \phi_1\right)\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(t\_4 \cdot \cos \phi_2, \cos \phi_1, {\left(\mathsf{fma}\left(\cos \left(-0.5 \cdot \phi_2\right), t\_1, t\_0 \cdot \cos \left(-0.5 \cdot \phi_1\right)\right)\right)}^{2}\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))))))))) < 1.99999999999999996e-12Initial program 95.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-/.f6495.8
Applied rewrites95.8%
Taylor expanded in R around 0
Applied rewrites95.8%
Taylor expanded in phi2 around 0
Applied rewrites95.8%
if 1.99999999999999996e-12 < (*.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-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-/.f6462.0
Applied rewrites62.0%
Taylor expanded in R around 0
Applied rewrites62.0%
Applied rewrites76.2%
Applied rewrites76.2%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* (- lambda2 lambda1) -0.5)) 2.0)))
(*
(* 2.0 R)
(atan2
(sqrt
(fma
t_0
(* (cos phi2) (cos phi1))
(pow (sin (* (- phi2 phi1) -0.5)) 2.0)))
(sqrt
(-
1.0
(fma
(* t_0 (cos phi2))
(cos phi1)
(pow
(fma
(cos (* -0.5 phi2))
(sin (* 0.5 phi1))
(* (sin (* -0.5 phi2)) (cos (* -0.5 phi1))))
2.0))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin(((lambda2 - lambda1) * -0.5)), 2.0);
return (2.0 * R) * atan2(sqrt(fma(t_0, (cos(phi2) * cos(phi1)), pow(sin(((phi2 - phi1) * -0.5)), 2.0))), sqrt((1.0 - fma((t_0 * cos(phi2)), cos(phi1), pow(fma(cos((-0.5 * phi2)), sin((0.5 * phi1)), (sin((-0.5 * phi2)) * cos((-0.5 * phi1)))), 2.0)))));
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda2 - lambda1) * -0.5)) ^ 2.0 return Float64(Float64(2.0 * R) * atan(sqrt(fma(t_0, Float64(cos(phi2) * cos(phi1)), (sin(Float64(Float64(phi2 - phi1) * -0.5)) ^ 2.0))), sqrt(Float64(1.0 - fma(Float64(t_0 * cos(phi2)), cos(phi1), (fma(cos(Float64(-0.5 * phi2)), sin(Float64(0.5 * phi1)), Float64(sin(Float64(-0.5 * phi2)) * cos(Float64(-0.5 * phi1)))) ^ 2.0)))))) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(N[(lambda2 - lambda1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[N[(t$95$0 * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[N[(N[(phi2 - phi1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $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]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\sin \left(\left(\lambda_2 - \lambda_1\right) \cdot -0.5\right)}^{2}\\
\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_0, \cos \phi_2 \cdot \cos \phi_1, {\sin \left(\left(\phi_2 - \phi_1\right) \cdot -0.5\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(t\_0 \cdot \cos \phi_2, \cos \phi_1, {\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)}}
\end{array}
\end{array}
Initial program 63.4%
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-/.f6464.1
Applied rewrites64.1%
Taylor expanded in R around 0
Applied rewrites64.1%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0))))
(*
R
(*
2.0
(atan2
(sqrt
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* (* (* (cos phi1) (cos phi2)) t_0) t_0)))
(sqrt
(-
(pow (cos (/ (- phi1 phi2) -2.0)) 2.0)
(* t_0 (* (* t_0 (cos phi1)) (cos phi2))))))))))
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 - phi2) / 2.0)), 2.0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0))), sqrt((pow(cos(((phi1 - phi2) / -2.0)), 2.0) - (t_0 * ((t_0 * cos(phi1)) * cos(phi2)))))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
t_0 = sin(((lambda1 - lambda2) / 2.0d0))
code = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0))), sqrt(((cos(((phi1 - phi2) / (-2.0d0))) ** 2.0d0) - (t_0 * ((t_0 * cos(phi1)) * cos(phi2)))))))
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 - phi2) / 2.0)), 2.0) + (((Math.cos(phi1) * Math.cos(phi2)) * t_0) * t_0))), Math.sqrt((Math.pow(Math.cos(((phi1 - phi2) / -2.0)), 2.0) - (t_0 * ((t_0 * Math.cos(phi1)) * Math.cos(phi2)))))));
}
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 - phi2) / 2.0)), 2.0) + (((math.cos(phi1) * math.cos(phi2)) * t_0) * t_0))), math.sqrt((math.pow(math.cos(((phi1 - phi2) / -2.0)), 2.0) - (t_0 * ((t_0 * math.cos(phi1)) * math.cos(phi2)))))))
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((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_0) * t_0))), sqrt(Float64((cos(Float64(Float64(phi1 - phi2) / -2.0)) ^ 2.0) - Float64(t_0 * Float64(Float64(t_0 * cos(phi1)) * cos(phi2)))))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(((lambda1 - lambda2) / 2.0)); tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0))), sqrt(((cos(((phi1 - phi2) / -2.0)) ^ 2.0) - (t_0 * ((t_0 * cos(phi1)) * cos(phi2))))))); 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[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[(N[(phi1 - phi2), $MachinePrecision] / -2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(t$95$0 * N[(N[(t$95$0 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $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{{\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(\frac{\phi_1 - \phi_2}{-2}\right)}^{2} - t\_0 \cdot \left(\left(t\_0 \cdot \cos \phi_1\right) \cdot \cos \phi_2\right)}}\right)
\end{array}
\end{array}
Initial program 63.4%
lift--.f64N/A
lift-+.f64N/A
associate--r+N/A
lift-*.f64N/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
lower-+.f64N/A
Applied rewrites63.5%
Final simplification63.5%
(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 63.4%
Applied rewrites63.5%
(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 63.4%
Taylor expanded in lambda1 around 0
Applied rewrites63.4%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0))) (t_1 (/ (- phi1 phi2) 2.0)))
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin t_1) 2.0) (* (* (* (cos phi1) (cos phi2)) t_0) t_0)))
(sqrt
(-
1.0
(/
(fma
(+ (cos (- phi1 phi2)) (cos (+ phi2 phi1)))
(pow t_0 2.0)
(- 1.0 (cos (* 2.0 t_1))))
2.0))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
double t_1 = (phi1 - phi2) / 2.0;
return R * (2.0 * atan2(sqrt((pow(sin(t_1), 2.0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0))), sqrt((1.0 - (fma((cos((phi1 - phi2)) + cos((phi2 + phi1))), pow(t_0, 2.0), (1.0 - cos((2.0 * t_1)))) / 2.0)))));
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = Float64(Float64(phi1 - phi2) / 2.0) return Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(t_1) ^ 2.0) + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_0) * t_0))), sqrt(Float64(1.0 - Float64(fma(Float64(cos(Float64(phi1 - phi2)) + cos(Float64(phi2 + phi1))), (t_0 ^ 2.0), Float64(1.0 - cos(Float64(2.0 * t_1)))) / 2.0)))))) 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[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[t$95$1], $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[(N[(N[Cos[N[(phi1 - phi2), $MachinePrecision]], $MachinePrecision] + N[Cos[N[(phi2 + phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Power[t$95$0, 2.0], $MachinePrecision] + N[(1.0 - N[Cos[N[(2.0 * t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $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 := \frac{\phi_1 - \phi_2}{2}\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin t\_1}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_0\right) \cdot t\_0}}{\sqrt{1 - \frac{\mathsf{fma}\left(\cos \left(\phi_1 - \phi_2\right) + \cos \left(\phi_2 + \phi_1\right), {t\_0}^{2}, 1 - \cos \left(2 \cdot t\_1\right)\right)}{2}}}\right)
\end{array}
\end{array}
Initial program 63.4%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
cos-multN/A
associate-*l/N/A
lift-pow.f64N/A
unpow2N/A
lift-sin.f64N/A
Applied rewrites63.8%
Final simplification63.8%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* (- lambda2 lambda1) -0.5)) 2.0))
(t_1 (sin (/ (- lambda1 lambda2) 2.0))))
(if (or (<= phi1 -2.9e-7) (not (<= phi1 1.72e-7)))
(*
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) (* t_0 (cos phi1)))))))
(*
R
(*
2.0
(atan2
(sqrt
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* (* (* (cos phi1) (cos phi2)) t_1) t_1)))
(sqrt (- (pow (cos (* 0.5 phi2)) 2.0) (* t_0 (cos phi2))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin(((lambda2 - lambda1) * -0.5)), 2.0);
double t_1 = sin(((lambda1 - lambda2) / 2.0));
double tmp;
if ((phi1 <= -2.9e-7) || !(phi1 <= 1.72e-7)) {
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) - (t_0 * cos(phi1))))));
} else {
tmp = R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (((cos(phi1) * cos(phi2)) * t_1) * t_1))), sqrt((pow(cos((0.5 * phi2)), 2.0) - (t_0 * cos(phi2))))));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda2 - lambda1) * -0.5)) ^ 2.0 t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) tmp = 0.0 if ((phi1 <= -2.9e-7) || !(phi1 <= 1.72e-7)) 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(t_0 * cos(phi1))))))); 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_1) * t_1))), sqrt(Float64((cos(Float64(0.5 * phi2)) ^ 2.0) - Float64(t_0 * cos(phi2))))))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(N[(lambda2 - lambda1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[phi1, -2.9e-7], N[Not[LessEqual[phi1, 1.72e-7]], $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[(t$95$0 * N[Cos[phi1], $MachinePrecision]), $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$1), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\sin \left(\left(\lambda_2 - \lambda_1\right) \cdot -0.5\right)}^{2}\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
\mathbf{if}\;\phi_1 \leq -2.9 \cdot 10^{-7} \lor \neg \left(\phi_1 \leq 1.72 \cdot 10^{-7}\right):\\
\;\;\;\;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} - t\_0 \cdot \cos \phi_1}}\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\_1\right) \cdot t\_1}}{\sqrt{{\cos \left(0.5 \cdot \phi_2\right)}^{2} - t\_0 \cdot \cos \phi_2}}\right)\\
\end{array}
\end{array}
if phi1 < -2.8999999999999998e-7 or 1.72e-7 < phi1 Initial program 52.5%
Taylor expanded in phi2 around 0
Applied rewrites53.1%
Taylor expanded in phi2 around 0
Applied rewrites53.6%
if -2.8999999999999998e-7 < phi1 < 1.72e-7Initial program 74.8%
Taylor expanded in phi1 around 0
Applied rewrites74.9%
Final simplification64.0%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* (- lambda2 lambda1) -0.5)) 2.0)))
(if (or (<= phi1 -2.9e-7) (not (<= phi1 1.72e-7)))
(*
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) (* t_0 (cos phi1)))))))
(*
(* 2.0 R)
(atan2
(sqrt
(fma
t_0
(* (cos phi2) (cos phi1))
(pow (sin (* (- phi2 phi1) -0.5)) 2.0)))
(sqrt (- 1.0 (fma t_0 (cos phi2) (pow (sin (* -0.5 phi2)) 2.0)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin(((lambda2 - lambda1) * -0.5)), 2.0);
double tmp;
if ((phi1 <= -2.9e-7) || !(phi1 <= 1.72e-7)) {
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) - (t_0 * cos(phi1))))));
} else {
tmp = (2.0 * R) * atan2(sqrt(fma(t_0, (cos(phi2) * cos(phi1)), pow(sin(((phi2 - phi1) * -0.5)), 2.0))), sqrt((1.0 - fma(t_0, cos(phi2), pow(sin((-0.5 * phi2)), 2.0)))));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda2 - lambda1) * -0.5)) ^ 2.0 tmp = 0.0 if ((phi1 <= -2.9e-7) || !(phi1 <= 1.72e-7)) 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(t_0 * cos(phi1))))))); else tmp = Float64(Float64(2.0 * R) * atan(sqrt(fma(t_0, Float64(cos(phi2) * cos(phi1)), (sin(Float64(Float64(phi2 - phi1) * -0.5)) ^ 2.0))), sqrt(Float64(1.0 - fma(t_0, cos(phi2), (sin(Float64(-0.5 * phi2)) ^ 2.0)))))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(N[(lambda2 - lambda1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, If[Or[LessEqual[phi1, -2.9e-7], N[Not[LessEqual[phi1, 1.72e-7]], $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[(t$95$0 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[N[(t$95$0 * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[N[(N[(phi2 - phi1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(t$95$0 * N[Cos[phi2], $MachinePrecision] + N[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\sin \left(\left(\lambda_2 - \lambda_1\right) \cdot -0.5\right)}^{2}\\
\mathbf{if}\;\phi_1 \leq -2.9 \cdot 10^{-7} \lor \neg \left(\phi_1 \leq 1.72 \cdot 10^{-7}\right):\\
\;\;\;\;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} - t\_0 \cdot \cos \phi_1}}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_0, \cos \phi_2 \cdot \cos \phi_1, {\sin \left(\left(\phi_2 - \phi_1\right) \cdot -0.5\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(t\_0, \cos \phi_2, {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)}}\\
\end{array}
\end{array}
if phi1 < -2.8999999999999998e-7 or 1.72e-7 < phi1 Initial program 52.5%
Taylor expanded in phi2 around 0
Applied rewrites53.1%
Taylor expanded in phi2 around 0
Applied rewrites53.6%
if -2.8999999999999998e-7 < phi1 < 1.72e-7Initial program 74.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-/.f6474.8
Applied rewrites74.8%
Taylor expanded in R around 0
Applied rewrites74.8%
Taylor expanded in phi1 around 0
Applied rewrites74.8%
Final simplification64.0%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* (- lambda2 lambda1) -0.5)) 2.0))
(t_1 (pow (sin (* (- phi2 phi1) -0.5)) 2.0))
(t_2 (sin (/ (- lambda1 lambda2) 2.0))))
(if (or (<= phi2 -82000.0) (not (<= phi2 1.7e+30)))
(*
R
(*
2.0
(atan2
(sqrt t_1)
(sqrt
(-
1.0
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* (* (* (cos phi1) (cos phi2)) t_2) t_2)))))))
(*
(* 2.0 R)
(atan2
(sqrt (fma t_0 (* (cos phi2) (cos phi1)) t_1))
(sqrt (- 1.0 (fma t_0 (cos phi1) (pow (sin (* 0.5 phi1)) 2.0)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin(((lambda2 - lambda1) * -0.5)), 2.0);
double t_1 = pow(sin(((phi2 - phi1) * -0.5)), 2.0);
double t_2 = sin(((lambda1 - lambda2) / 2.0));
double tmp;
if ((phi2 <= -82000.0) || !(phi2 <= 1.7e+30)) {
tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - (pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (((cos(phi1) * cos(phi2)) * t_2) * t_2))))));
} else {
tmp = (2.0 * R) * atan2(sqrt(fma(t_0, (cos(phi2) * cos(phi1)), t_1)), sqrt((1.0 - fma(t_0, cos(phi1), pow(sin((0.5 * phi1)), 2.0)))));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda2 - lambda1) * -0.5)) ^ 2.0 t_1 = sin(Float64(Float64(phi2 - phi1) * -0.5)) ^ 2.0 t_2 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) tmp = 0.0 if ((phi2 <= -82000.0) || !(phi2 <= 1.7e+30)) tmp = Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_2) * t_2))))))); else tmp = Float64(Float64(2.0 * R) * atan(sqrt(fma(t_0, Float64(cos(phi2) * cos(phi1)), t_1)), sqrt(Float64(1.0 - fma(t_0, cos(phi1), (sin(Float64(0.5 * phi1)) ^ 2.0)))))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(N[(lambda2 - lambda1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sin[N[(N[(phi2 - phi1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[phi2, -82000.0], N[Not[LessEqual[phi2, 1.7e+30]], $MachinePrecision]], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$1], $MachinePrecision] / N[Sqrt[N[(1.0 - 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$2), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[N[(t$95$0 * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(t$95$0 * N[Cos[phi1], $MachinePrecision] + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\sin \left(\left(\lambda_2 - \lambda_1\right) \cdot -0.5\right)}^{2}\\
t_1 := {\sin \left(\left(\phi_2 - \phi_1\right) \cdot -0.5\right)}^{2}\\
t_2 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
\mathbf{if}\;\phi_2 \leq -82000 \lor \neg \left(\phi_2 \leq 1.7 \cdot 10^{+30}\right):\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_2\right) \cdot t\_2\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_0, \cos \phi_2 \cdot \cos \phi_1, t\_1\right)}}{\sqrt{1 - \mathsf{fma}\left(t\_0, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}\\
\end{array}
\end{array}
if phi2 < -82000 or 1.7000000000000001e30 < phi2 Initial program 51.7%
Taylor expanded in lambda1 around 0
Applied rewrites41.0%
Taylor expanded in lambda2 around 0
Applied rewrites33.3%
if -82000 < phi2 < 1.7000000000000001e30Initial program 73.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-/.f6473.1
Applied rewrites73.1%
Taylor expanded in R around 0
Applied rewrites73.1%
Taylor expanded in phi2 around 0
Applied rewrites70.9%
Final simplification54.0%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
(t_1 (* (cos phi1) (cos phi2)))
(t_2 (* (- lambda2 lambda1) -0.5))
(t_3 (sqrt (pow (sin t_2) 2.0)))
(t_4 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)))
(if (<= t_0 -0.05)
(*
R
(*
2.0
(atan2
t_3
(sqrt
(-
(pow (cos (* -0.5 phi1)) 2.0)
(* (- 0.5 (* 0.5 (cos (* 2.0 t_2)))) (cos phi1)))))))
(if (<= t_0 0.08)
(*
R
(*
2.0
(atan2
(sqrt (pow (sin (* (- phi2 phi1) -0.5)) 2.0))
(sqrt (- 1.0 (+ t_4 (* (* t_1 t_0) t_0)))))))
(*
R
(* 2.0 (atan2 t_3 (sqrt (- (- 1.0 (* (pow t_0 2.0) t_1)) t_4)))))))))
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);
double t_2 = (lambda2 - lambda1) * -0.5;
double t_3 = sqrt(pow(sin(t_2), 2.0));
double t_4 = pow(sin(((phi1 - phi2) / 2.0)), 2.0);
double tmp;
if (t_0 <= -0.05) {
tmp = R * (2.0 * atan2(t_3, sqrt((pow(cos((-0.5 * phi1)), 2.0) - ((0.5 - (0.5 * cos((2.0 * t_2)))) * cos(phi1))))));
} else if (t_0 <= 0.08) {
tmp = R * (2.0 * atan2(sqrt(pow(sin(((phi2 - phi1) * -0.5)), 2.0)), sqrt((1.0 - (t_4 + ((t_1 * t_0) * t_0))))));
} else {
tmp = R * (2.0 * atan2(t_3, sqrt(((1.0 - (pow(t_0, 2.0) * t_1)) - t_4))));
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: t_4
real(8) :: tmp
t_0 = sin(((lambda1 - lambda2) / 2.0d0))
t_1 = cos(phi1) * cos(phi2)
t_2 = (lambda2 - lambda1) * (-0.5d0)
t_3 = sqrt((sin(t_2) ** 2.0d0))
t_4 = sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0
if (t_0 <= (-0.05d0)) then
tmp = r * (2.0d0 * atan2(t_3, sqrt(((cos(((-0.5d0) * phi1)) ** 2.0d0) - ((0.5d0 - (0.5d0 * cos((2.0d0 * t_2)))) * cos(phi1))))))
else if (t_0 <= 0.08d0) then
tmp = r * (2.0d0 * atan2(sqrt((sin(((phi2 - phi1) * (-0.5d0))) ** 2.0d0)), sqrt((1.0d0 - (t_4 + ((t_1 * t_0) * t_0))))))
else
tmp = r * (2.0d0 * atan2(t_3, sqrt(((1.0d0 - ((t_0 ** 2.0d0) * t_1)) - t_4))))
end if
code = tmp
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);
double t_2 = (lambda2 - lambda1) * -0.5;
double t_3 = Math.sqrt(Math.pow(Math.sin(t_2), 2.0));
double t_4 = Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0);
double tmp;
if (t_0 <= -0.05) {
tmp = R * (2.0 * Math.atan2(t_3, Math.sqrt((Math.pow(Math.cos((-0.5 * phi1)), 2.0) - ((0.5 - (0.5 * Math.cos((2.0 * t_2)))) * Math.cos(phi1))))));
} else if (t_0 <= 0.08) {
tmp = R * (2.0 * Math.atan2(Math.sqrt(Math.pow(Math.sin(((phi2 - phi1) * -0.5)), 2.0)), Math.sqrt((1.0 - (t_4 + ((t_1 * t_0) * t_0))))));
} else {
tmp = R * (2.0 * Math.atan2(t_3, Math.sqrt(((1.0 - (Math.pow(t_0, 2.0) * t_1)) - t_4))));
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((lambda1 - lambda2) / 2.0)) t_1 = math.cos(phi1) * math.cos(phi2) t_2 = (lambda2 - lambda1) * -0.5 t_3 = math.sqrt(math.pow(math.sin(t_2), 2.0)) t_4 = math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) tmp = 0 if t_0 <= -0.05: tmp = R * (2.0 * math.atan2(t_3, math.sqrt((math.pow(math.cos((-0.5 * phi1)), 2.0) - ((0.5 - (0.5 * math.cos((2.0 * t_2)))) * math.cos(phi1)))))) elif t_0 <= 0.08: tmp = R * (2.0 * math.atan2(math.sqrt(math.pow(math.sin(((phi2 - phi1) * -0.5)), 2.0)), math.sqrt((1.0 - (t_4 + ((t_1 * t_0) * t_0)))))) else: tmp = R * (2.0 * math.atan2(t_3, math.sqrt(((1.0 - (math.pow(t_0, 2.0) * t_1)) - t_4)))) return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = Float64(cos(phi1) * cos(phi2)) t_2 = Float64(Float64(lambda2 - lambda1) * -0.5) t_3 = sqrt((sin(t_2) ^ 2.0)) t_4 = sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0 tmp = 0.0 if (t_0 <= -0.05) tmp = Float64(R * Float64(2.0 * atan(t_3, sqrt(Float64((cos(Float64(-0.5 * phi1)) ^ 2.0) - Float64(Float64(0.5 - Float64(0.5 * cos(Float64(2.0 * t_2)))) * cos(phi1))))))); elseif (t_0 <= 0.08) tmp = Float64(R * Float64(2.0 * atan(sqrt((sin(Float64(Float64(phi2 - phi1) * -0.5)) ^ 2.0)), sqrt(Float64(1.0 - Float64(t_4 + Float64(Float64(t_1 * t_0) * t_0))))))); else tmp = Float64(R * Float64(2.0 * atan(t_3, sqrt(Float64(Float64(1.0 - Float64((t_0 ^ 2.0) * t_1)) - t_4))))); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(((lambda1 - lambda2) / 2.0)); t_1 = cos(phi1) * cos(phi2); t_2 = (lambda2 - lambda1) * -0.5; t_3 = sqrt((sin(t_2) ^ 2.0)); t_4 = sin(((phi1 - phi2) / 2.0)) ^ 2.0; tmp = 0.0; if (t_0 <= -0.05) tmp = R * (2.0 * atan2(t_3, sqrt(((cos((-0.5 * phi1)) ^ 2.0) - ((0.5 - (0.5 * cos((2.0 * t_2)))) * cos(phi1)))))); elseif (t_0 <= 0.08) tmp = R * (2.0 * atan2(sqrt((sin(((phi2 - phi1) * -0.5)) ^ 2.0)), sqrt((1.0 - (t_4 + ((t_1 * t_0) * t_0)))))); else tmp = R * (2.0 * atan2(t_3, sqrt(((1.0 - ((t_0 ^ 2.0) * t_1)) - t_4)))); end tmp_2 = 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[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(lambda2 - lambda1), $MachinePrecision] * -0.5), $MachinePrecision]}, Block[{t$95$3 = N[Sqrt[N[Power[N[Sin[t$95$2], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[t$95$0, -0.05], N[(R * N[(2.0 * N[ArcTan[t$95$3 / N[Sqrt[N[(N[Power[N[Cos[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(N[(0.5 - N[(0.5 * N[Cos[N[(2.0 * t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.08], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[Power[N[Sin[N[(N[(phi2 - phi1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(t$95$4 + N[(N[(t$95$1 * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[t$95$3 / N[Sqrt[N[(N[(1.0 - N[(N[Power[t$95$0, 2.0], $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision] - t$95$4), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \cos \phi_1 \cdot \cos \phi_2\\
t_2 := \left(\lambda_2 - \lambda_1\right) \cdot -0.5\\
t_3 := \sqrt{{\sin t\_2}^{2}}\\
t_4 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
\mathbf{if}\;t\_0 \leq -0.05:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t\_3}{\sqrt{{\cos \left(-0.5 \cdot \phi_1\right)}^{2} - \left(0.5 - 0.5 \cdot \cos \left(2 \cdot t\_2\right)\right) \cdot \cos \phi_1}}\right)\\
\mathbf{elif}\;t\_0 \leq 0.08:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\left(\phi_2 - \phi_1\right) \cdot -0.5\right)}^{2}}}{\sqrt{1 - \left(t\_4 + \left(t\_1 \cdot t\_0\right) \cdot t\_0\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t\_3}{\sqrt{\left(1 - {t\_0}^{2} \cdot t\_1\right) - t\_4}}\right)\\
\end{array}
\end{array}
if (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) < -0.050000000000000003Initial program 53.9%
Taylor expanded in phi2 around 0
Applied rewrites43.4%
Taylor expanded in phi2 around 0
Applied rewrites38.5%
Taylor expanded in phi1 around 0
Applied rewrites31.6%
Applied rewrites31.6%
if -0.050000000000000003 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) < 0.0800000000000000017Initial program 79.5%
Taylor expanded in lambda1 around 0
Applied rewrites73.4%
Taylor expanded in lambda2 around 0
Applied rewrites70.5%
if 0.0800000000000000017 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) Initial program 59.0%
Taylor expanded in phi1 around 0
Applied rewrites43.1%
Taylor expanded in phi2 around 0
Applied rewrites31.2%
lift--.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate--r+N/A
lower--.f64N/A
Applied rewrites31.2%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* (- lambda2 lambda1) -0.5)) 2.0))
(t_1 (sin (/ (- lambda1 lambda2) 2.0))))
(if (or (<= phi2 -1.2e-5) (not (<= phi2 1.7e+30)))
(*
R
(*
2.0
(atan2
(sqrt (pow (sin (* (- phi2 phi1) -0.5)) 2.0))
(sqrt
(-
1.0
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* (* (* (cos phi1) (cos phi2)) t_1) 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) (* t_0 (cos phi1))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin(((lambda2 - lambda1) * -0.5)), 2.0);
double t_1 = sin(((lambda1 - lambda2) / 2.0));
double tmp;
if ((phi2 <= -1.2e-5) || !(phi2 <= 1.7e+30)) {
tmp = R * (2.0 * atan2(sqrt(pow(sin(((phi2 - phi1) * -0.5)), 2.0)), sqrt((1.0 - (pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (((cos(phi1) * cos(phi2)) * t_1) * 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) - (t_0 * cos(phi1))))));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda2 - lambda1) * -0.5)) ^ 2.0 t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) tmp = 0.0 if ((phi2 <= -1.2e-5) || !(phi2 <= 1.7e+30)) tmp = Float64(R * Float64(2.0 * atan(sqrt((sin(Float64(Float64(phi2 - phi1) * -0.5)) ^ 2.0)), sqrt(Float64(1.0 - Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_1) * 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(t_0 * cos(phi1))))))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(N[(lambda2 - lambda1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[phi2, -1.2e-5], N[Not[LessEqual[phi2, 1.7e+30]], $MachinePrecision]], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[Power[N[Sin[N[(N[(phi2 - phi1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - 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]), $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[(t$95$0 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\sin \left(\left(\lambda_2 - \lambda_1\right) \cdot -0.5\right)}^{2}\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
\mathbf{if}\;\phi_2 \leq -1.2 \cdot 10^{-5} \lor \neg \left(\phi_2 \leq 1.7 \cdot 10^{+30}\right):\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\left(\phi_2 - \phi_1\right) \cdot -0.5\right)}^{2}}}{\sqrt{1 - \left({\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\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} - t\_0 \cdot \cos \phi_1}}\right)\\
\end{array}
\end{array}
if phi2 < -1.2e-5 or 1.7000000000000001e30 < phi2 Initial program 51.9%
Taylor expanded in lambda1 around 0
Applied rewrites40.6%
Taylor expanded in lambda2 around 0
Applied rewrites32.9%
if -1.2e-5 < phi2 < 1.7000000000000001e30Initial program 73.4%
Taylor expanded in phi2 around 0
Applied rewrites72.4%
Taylor expanded in phi2 around 0
Applied rewrites71.1%
Final simplification53.4%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (- lambda2 lambda1) -0.5)))
(*
R
(*
2.0
(atan2
(sqrt (pow (sin t_0) 2.0))
(sqrt
(-
(pow (cos (* -0.5 phi1)) 2.0)
(* (- 0.5 (* 0.5 (cos (* 2.0 t_0)))) (cos phi1)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (lambda2 - lambda1) * -0.5;
return R * (2.0 * atan2(sqrt(pow(sin(t_0), 2.0)), sqrt((pow(cos((-0.5 * phi1)), 2.0) - ((0.5 - (0.5 * cos((2.0 * t_0)))) * cos(phi1))))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
t_0 = (lambda2 - lambda1) * (-0.5d0)
code = r * (2.0d0 * atan2(sqrt((sin(t_0) ** 2.0d0)), sqrt(((cos(((-0.5d0) * phi1)) ** 2.0d0) - ((0.5d0 - (0.5d0 * cos((2.0d0 * t_0)))) * cos(phi1))))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (lambda2 - lambda1) * -0.5;
return R * (2.0 * Math.atan2(Math.sqrt(Math.pow(Math.sin(t_0), 2.0)), Math.sqrt((Math.pow(Math.cos((-0.5 * phi1)), 2.0) - ((0.5 - (0.5 * Math.cos((2.0 * t_0)))) * Math.cos(phi1))))));
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = (lambda2 - lambda1) * -0.5 return R * (2.0 * math.atan2(math.sqrt(math.pow(math.sin(t_0), 2.0)), math.sqrt((math.pow(math.cos((-0.5 * phi1)), 2.0) - ((0.5 - (0.5 * math.cos((2.0 * t_0)))) * math.cos(phi1))))))
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(Float64(lambda2 - lambda1) * -0.5) return Float64(R * Float64(2.0 * atan(sqrt((sin(t_0) ^ 2.0)), sqrt(Float64((cos(Float64(-0.5 * phi1)) ^ 2.0) - Float64(Float64(0.5 - Float64(0.5 * cos(Float64(2.0 * t_0)))) * cos(phi1))))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) t_0 = (lambda2 - lambda1) * -0.5; tmp = R * (2.0 * atan2(sqrt((sin(t_0) ^ 2.0)), sqrt(((cos((-0.5 * phi1)) ^ 2.0) - ((0.5 - (0.5 * cos((2.0 * t_0)))) * cos(phi1)))))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(lambda2 - lambda1), $MachinePrecision] * -0.5), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[Power[N[Sin[t$95$0], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(N[(0.5 - N[(0.5 * N[Cos[N[(2.0 * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\lambda_2 - \lambda_1\right) \cdot -0.5\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin t\_0}^{2}}}{\sqrt{{\cos \left(-0.5 \cdot \phi_1\right)}^{2} - \left(0.5 - 0.5 \cdot \cos \left(2 \cdot t\_0\right)\right) \cdot \cos \phi_1}}\right)
\end{array}
\end{array}
Initial program 63.4%
Taylor expanded in phi2 around 0
Applied rewrites48.6%
Taylor expanded in phi2 around 0
Applied rewrites43.2%
Taylor expanded in phi1 around 0
Applied rewrites27.0%
Applied rewrites27.1%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (- lambda2 lambda1) -0.5)))
(*
R
(*
2.0
(atan2
(sqrt (- 0.5 (* 0.5 (cos (* 2.0 t_0)))))
(sqrt
(-
(pow (cos (* -0.5 phi1)) 2.0)
(* (pow (sin t_0) 2.0) (cos phi1)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (lambda2 - lambda1) * -0.5;
return R * (2.0 * atan2(sqrt((0.5 - (0.5 * cos((2.0 * t_0))))), sqrt((pow(cos((-0.5 * phi1)), 2.0) - (pow(sin(t_0), 2.0) * cos(phi1))))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
t_0 = (lambda2 - lambda1) * (-0.5d0)
code = r * (2.0d0 * atan2(sqrt((0.5d0 - (0.5d0 * cos((2.0d0 * t_0))))), sqrt(((cos(((-0.5d0) * phi1)) ** 2.0d0) - ((sin(t_0) ** 2.0d0) * cos(phi1))))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (lambda2 - lambda1) * -0.5;
return R * (2.0 * Math.atan2(Math.sqrt((0.5 - (0.5 * Math.cos((2.0 * t_0))))), Math.sqrt((Math.pow(Math.cos((-0.5 * phi1)), 2.0) - (Math.pow(Math.sin(t_0), 2.0) * Math.cos(phi1))))));
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = (lambda2 - lambda1) * -0.5 return R * (2.0 * math.atan2(math.sqrt((0.5 - (0.5 * math.cos((2.0 * t_0))))), math.sqrt((math.pow(math.cos((-0.5 * phi1)), 2.0) - (math.pow(math.sin(t_0), 2.0) * math.cos(phi1))))))
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(Float64(lambda2 - lambda1) * -0.5) return Float64(R * Float64(2.0 * atan(sqrt(Float64(0.5 - Float64(0.5 * cos(Float64(2.0 * t_0))))), sqrt(Float64((cos(Float64(-0.5 * phi1)) ^ 2.0) - Float64((sin(t_0) ^ 2.0) * cos(phi1))))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) t_0 = (lambda2 - lambda1) * -0.5; tmp = R * (2.0 * atan2(sqrt((0.5 - (0.5 * cos((2.0 * t_0))))), sqrt(((cos((-0.5 * phi1)) ^ 2.0) - ((sin(t_0) ^ 2.0) * cos(phi1)))))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(lambda2 - lambda1), $MachinePrecision] * -0.5), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(0.5 - N[(0.5 * N[Cos[N[(2.0 * t$95$0), $MachinePrecision]], $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[t$95$0], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\lambda_2 - \lambda_1\right) \cdot -0.5\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{0.5 - 0.5 \cdot \cos \left(2 \cdot t\_0\right)}}{\sqrt{{\cos \left(-0.5 \cdot \phi_1\right)}^{2} - {\sin t\_0}^{2} \cdot \cos \phi_1}}\right)
\end{array}
\end{array}
Initial program 63.4%
Taylor expanded in phi2 around 0
Applied rewrites48.6%
Taylor expanded in phi2 around 0
Applied rewrites43.2%
Taylor expanded in phi1 around 0
Applied rewrites27.0%
Applied rewrites24.4%
herbie shell --seed 2024346
(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))))))))))