
(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}
Herbie found 19 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 (* 0.5 (- lambda1 lambda2))))
(t_1 (pow t_0 2.0))
(t_2 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0))
(t_3 (+ t_2 (* (* (cos phi2) t_0) (sin (/ (- lambda1 lambda2) 2.0)))))
(t_4 (fma (cos phi1) t_1 (pow (sin (* 0.5 phi1)) 2.0)))
(t_5 (sqrt (- 1.0 t_4))))
(if (<= phi1 -23000.0)
(* R (* 2.0 (atan2 (sqrt t_4) t_5)))
(if (<= phi1 0.00072)
(* R (* 2.0 (atan2 (sqrt t_3) (sqrt (- 1.0 t_3)))))
(* R (* 2.0 (atan2 (sqrt (+ t_2 (* (cos phi1) t_1))) t_5)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin((0.5 * (lambda1 - lambda2)));
double t_1 = pow(t_0, 2.0);
double t_2 = pow(sin(((phi1 - phi2) / 2.0)), 2.0);
double t_3 = t_2 + ((cos(phi2) * t_0) * sin(((lambda1 - lambda2) / 2.0)));
double t_4 = fma(cos(phi1), t_1, pow(sin((0.5 * phi1)), 2.0));
double t_5 = sqrt((1.0 - t_4));
double tmp;
if (phi1 <= -23000.0) {
tmp = R * (2.0 * atan2(sqrt(t_4), t_5));
} else if (phi1 <= 0.00072) {
tmp = R * (2.0 * atan2(sqrt(t_3), sqrt((1.0 - t_3))));
} else {
tmp = R * (2.0 * atan2(sqrt((t_2 + (cos(phi1) * t_1))), t_5));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) t_1 = t_0 ^ 2.0 t_2 = sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0 t_3 = Float64(t_2 + Float64(Float64(cos(phi2) * t_0) * sin(Float64(Float64(lambda1 - lambda2) / 2.0)))) t_4 = fma(cos(phi1), t_1, (sin(Float64(0.5 * phi1)) ^ 2.0)) t_5 = sqrt(Float64(1.0 - t_4)) tmp = 0.0 if (phi1 <= -23000.0) tmp = Float64(R * Float64(2.0 * atan(sqrt(t_4), t_5))); elseif (phi1 <= 0.00072) tmp = Float64(R * Float64(2.0 * atan(sqrt(t_3), sqrt(Float64(1.0 - t_3))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_2 + Float64(cos(phi1) * t_1))), t_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[Power[t$95$0, 2.0], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 + N[(N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision] * N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[Cos[phi1], $MachinePrecision] * t$95$1 + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[Sqrt[N[(1.0 - t$95$4), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi1, -23000.0], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$4], $MachinePrecision] / t$95$5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 0.00072], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$3], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$3), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$2 + N[(N[Cos[phi1], $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t$95$5], $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}^{2}\\
t_2 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
t_3 := t\_2 + \left(\cos \phi_2 \cdot t\_0\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_4 := \mathsf{fma}\left(\cos \phi_1, t\_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)\\
t_5 := \sqrt{1 - t\_4}\\
\mathbf{if}\;\phi_1 \leq -23000:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_4}}{t\_5}\right)\\
\mathbf{elif}\;\phi_1 \leq 0.00072:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_3}}{\sqrt{1 - t\_3}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_2 + \cos \phi_1 \cdot t\_1}}{t\_5}\right)\\
\end{array}
\end{array}
if phi1 < -23000Initial program 46.2%
Taylor expanded in phi2 around 0
Applied rewrites46.9%
Taylor expanded in phi2 around 0
Applied rewrites47.8%
if -23000 < phi1 < 7.20000000000000045e-4Initial program 77.1%
Taylor expanded in phi1 around 0
Applied rewrites76.8%
Taylor expanded in phi1 around 0
Applied rewrites76.8%
if 7.20000000000000045e-4 < phi1 Initial program 47.0%
Taylor expanded in phi2 around 0
Applied rewrites47.1%
Taylor expanded in phi2 around 0
Applied rewrites46.9%
Taylor expanded in phi2 around 0
Applied rewrites47.7%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_1 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0))
(t_2 (+ t_1 (* (cos phi2) t_0)))
(t_3 (fma (cos phi1) t_0 (pow (sin (* 0.5 phi1)) 2.0)))
(t_4 (sqrt (- 1.0 t_3))))
(if (<= phi1 -23000.0)
(* R (* 2.0 (atan2 (sqrt t_3) t_4)))
(if (<= phi1 0.00072)
(* R (* 2.0 (atan2 (sqrt t_2) (sqrt (- 1.0 t_2)))))
(* R (* 2.0 (atan2 (sqrt (+ t_1 (* (cos phi1) t_0))) t_4)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin((0.5 * (lambda1 - lambda2))), 2.0);
double t_1 = pow(sin(((phi1 - phi2) / 2.0)), 2.0);
double t_2 = t_1 + (cos(phi2) * t_0);
double t_3 = fma(cos(phi1), t_0, pow(sin((0.5 * phi1)), 2.0));
double t_4 = sqrt((1.0 - t_3));
double tmp;
if (phi1 <= -23000.0) {
tmp = R * (2.0 * atan2(sqrt(t_3), t_4));
} else if (phi1 <= 0.00072) {
tmp = R * (2.0 * atan2(sqrt(t_2), sqrt((1.0 - t_2))));
} else {
tmp = R * (2.0 * atan2(sqrt((t_1 + (cos(phi1) * t_0))), t_4));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_1 = sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0 t_2 = Float64(t_1 + Float64(cos(phi2) * t_0)) t_3 = fma(cos(phi1), t_0, (sin(Float64(0.5 * phi1)) ^ 2.0)) t_4 = sqrt(Float64(1.0 - t_3)) tmp = 0.0 if (phi1 <= -23000.0) tmp = Float64(R * Float64(2.0 * atan(sqrt(t_3), t_4))); elseif (phi1 <= 0.00072) tmp = Float64(R * Float64(2.0 * atan(sqrt(t_2), sqrt(Float64(1.0 - t_2))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_1 + Float64(cos(phi1) * t_0))), t_4))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 + N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[Cos[phi1], $MachinePrecision] * t$95$0 + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[Sqrt[N[(1.0 - t$95$3), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi1, -23000.0], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$3], $MachinePrecision] / t$95$4], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 0.00072], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$2], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$2), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$1 + N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t$95$4], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_1 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
t_2 := t\_1 + \cos \phi_2 \cdot t\_0\\
t_3 := \mathsf{fma}\left(\cos \phi_1, t\_0, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)\\
t_4 := \sqrt{1 - t\_3}\\
\mathbf{if}\;\phi_1 \leq -23000:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_3}}{t\_4}\right)\\
\mathbf{elif}\;\phi_1 \leq 0.00072:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_2}}{\sqrt{1 - t\_2}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1 + \cos \phi_1 \cdot t\_0}}{t\_4}\right)\\
\end{array}
\end{array}
if phi1 < -23000Initial program 46.2%
Taylor expanded in phi2 around 0
Applied rewrites46.9%
Taylor expanded in phi2 around 0
Applied rewrites47.8%
if -23000 < phi1 < 7.20000000000000045e-4Initial program 77.1%
Taylor expanded in phi1 around 0
Applied rewrites76.8%
Taylor expanded in phi1 around 0
Applied rewrites76.8%
if 7.20000000000000045e-4 < phi1 Initial program 47.0%
Taylor expanded in phi2 around 0
Applied rewrites47.1%
Taylor expanded in phi2 around 0
Applied rewrites46.9%
Taylor expanded in phi2 around 0
Applied rewrites47.7%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_1 (fma (cos phi2) t_0 (pow (sin (* -0.5 phi2)) 2.0)))
(t_2 (* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))))
(if (<= phi2 -2.35e-5)
t_2
(if (<= phi2 2.85e-8)
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* (cos phi1) t_0)))
(sqrt (- 1.0 (fma (cos phi1) t_0 (pow (sin (* 0.5 phi1)) 2.0)))))))
t_2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin((0.5 * (lambda1 - lambda2))), 2.0);
double t_1 = fma(cos(phi2), t_0, pow(sin((-0.5 * phi2)), 2.0));
double t_2 = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
double tmp;
if (phi2 <= -2.35e-5) {
tmp = t_2;
} else if (phi2 <= 2.85e-8) {
tmp = R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (cos(phi1) * t_0))), sqrt((1.0 - fma(cos(phi1), t_0, pow(sin((0.5 * phi1)), 2.0))))));
} else {
tmp = t_2;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_1 = fma(cos(phi2), t_0, (sin(Float64(-0.5 * phi2)) ^ 2.0)) t_2 = Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1))))) tmp = 0.0 if (phi2 <= -2.35e-5) tmp = t_2; elseif (phi2 <= 2.85e-8) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(cos(phi1) * t_0))), sqrt(Float64(1.0 - fma(cos(phi1), t_0, (sin(Float64(0.5 * phi1)) ^ 2.0))))))); else tmp = t_2; end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi2], $MachinePrecision] * t$95$0 + N[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = 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]}, If[LessEqual[phi2, -2.35e-5], t$95$2, If[LessEqual[phi2, 2.85e-8], 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[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Cos[phi1], $MachinePrecision] * t$95$0 + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_1 := \mathsf{fma}\left(\cos \phi_2, t\_0, {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)\\
t_2 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right)\\
\mathbf{if}\;\phi_2 \leq -2.35 \cdot 10^{-5}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;\phi_2 \leq 2.85 \cdot 10^{-8}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \cos \phi_1 \cdot t\_0}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_1, t\_0, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if phi2 < -2.34999999999999986e-5 or 2.85000000000000004e-8 < phi2 Initial program 46.8%
Taylor expanded in phi1 around 0
Applied rewrites47.4%
Taylor expanded in phi1 around 0
Applied rewrites48.2%
if -2.34999999999999986e-5 < phi2 < 2.85000000000000004e-8Initial program 77.8%
Taylor expanded in phi2 around 0
Applied rewrites77.7%
Taylor expanded in phi2 around 0
Applied rewrites77.7%
Taylor expanded in phi2 around 0
Applied rewrites77.7%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_1 (fma (cos phi2) t_0 (pow (sin (* -0.5 phi2)) 2.0)))
(t_2 (* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))))
(if (<= phi2 -5.4e-11)
t_2
(if (<= phi2 2.8e-8)
(*
R
(*
2.0
(atan2
(sqrt (fma (cos phi1) t_0 (pow (sin (* 0.5 phi1)) 2.0)))
(sqrt
(-
1.0
(+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* (cos phi1) t_0)))))))
t_2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin((0.5 * (lambda1 - lambda2))), 2.0);
double t_1 = fma(cos(phi2), t_0, pow(sin((-0.5 * phi2)), 2.0));
double t_2 = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
double tmp;
if (phi2 <= -5.4e-11) {
tmp = t_2;
} else if (phi2 <= 2.8e-8) {
tmp = R * (2.0 * atan2(sqrt(fma(cos(phi1), t_0, pow(sin((0.5 * phi1)), 2.0))), sqrt((1.0 - (pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (cos(phi1) * t_0))))));
} else {
tmp = t_2;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_1 = fma(cos(phi2), t_0, (sin(Float64(-0.5 * phi2)) ^ 2.0)) t_2 = Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1))))) tmp = 0.0 if (phi2 <= -5.4e-11) tmp = t_2; elseif (phi2 <= 2.8e-8) tmp = Float64(R * Float64(2.0 * atan(sqrt(fma(cos(phi1), t_0, (sin(Float64(0.5 * phi1)) ^ 2.0))), sqrt(Float64(1.0 - Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(cos(phi1) * t_0))))))); else tmp = t_2; end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi2], $MachinePrecision] * t$95$0 + N[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = 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]}, If[LessEqual[phi2, -5.4e-11], t$95$2, If[LessEqual[phi2, 2.8e-8], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Cos[phi1], $MachinePrecision] * t$95$0 + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $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[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_1 := \mathsf{fma}\left(\cos \phi_2, t\_0, {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)\\
t_2 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right)\\
\mathbf{if}\;\phi_2 \leq -5.4 \cdot 10^{-11}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;\phi_2 \leq 2.8 \cdot 10^{-8}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_1, t\_0, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \cos \phi_1 \cdot t\_0\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if phi2 < -5.40000000000000009e-11 or 2.7999999999999999e-8 < phi2 Initial program 47.0%
Taylor expanded in phi1 around 0
Applied rewrites47.3%
Taylor expanded in phi1 around 0
Applied rewrites48.1%
if -5.40000000000000009e-11 < phi2 < 2.7999999999999999e-8Initial program 77.9%
Taylor expanded in phi2 around 0
Applied rewrites77.9%
Taylor expanded in phi2 around 0
Applied rewrites77.9%
Taylor expanded in phi2 around 0
Applied rewrites75.6%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_1 (fma (cos phi1) t_0 (pow (sin (* 0.5 phi1)) 2.0)))
(t_2 (fma (cos phi2) t_0 (pow (sin (* -0.5 phi2)) 2.0)))
(t_3 (* R (* 2.0 (atan2 (sqrt t_2) (sqrt (- 1.0 t_2)))))))
(if (<= phi2 -5.4e-11)
t_3
(if (<= phi2 2.8e-8)
(* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))
t_3))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin((0.5 * (lambda1 - lambda2))), 2.0);
double t_1 = fma(cos(phi1), t_0, pow(sin((0.5 * phi1)), 2.0));
double t_2 = fma(cos(phi2), t_0, pow(sin((-0.5 * phi2)), 2.0));
double t_3 = R * (2.0 * atan2(sqrt(t_2), sqrt((1.0 - t_2))));
double tmp;
if (phi2 <= -5.4e-11) {
tmp = t_3;
} else if (phi2 <= 2.8e-8) {
tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
} else {
tmp = t_3;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_1 = fma(cos(phi1), t_0, (sin(Float64(0.5 * phi1)) ^ 2.0)) t_2 = fma(cos(phi2), t_0, (sin(Float64(-0.5 * phi2)) ^ 2.0)) t_3 = Float64(R * Float64(2.0 * atan(sqrt(t_2), sqrt(Float64(1.0 - t_2))))) tmp = 0.0 if (phi2 <= -5.4e-11) tmp = t_3; elseif (phi2 <= 2.8e-8) tmp = Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1))))); else tmp = t_3; end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi1], $MachinePrecision] * t$95$0 + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Cos[phi2], $MachinePrecision] * t$95$0 + N[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$2], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$2), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -5.4e-11], t$95$3, If[LessEqual[phi2, 2.8e-8], 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], t$95$3]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_1 := \mathsf{fma}\left(\cos \phi_1, t\_0, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)\\
t_2 := \mathsf{fma}\left(\cos \phi_2, t\_0, {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)\\
t_3 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_2}}{\sqrt{1 - t\_2}}\right)\\
\mathbf{if}\;\phi_2 \leq -5.4 \cdot 10^{-11}:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;\phi_2 \leq 2.8 \cdot 10^{-8}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_3\\
\end{array}
\end{array}
if phi2 < -5.40000000000000009e-11 or 2.7999999999999999e-8 < phi2 Initial program 47.0%
Taylor expanded in phi1 around 0
Applied rewrites47.3%
Taylor expanded in phi1 around 0
Applied rewrites48.1%
if -5.40000000000000009e-11 < phi2 < 2.7999999999999999e-8Initial program 77.9%
Taylor expanded in phi2 around 0
Applied rewrites75.6%
Taylor expanded in phi2 around 0
Applied rewrites75.6%
(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}
Initial program 61.8%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0
(fma
(cos phi1)
(pow (sin (* 0.5 (- lambda1 lambda2))) 2.0)
(pow (sin (* 0.5 phi1)) 2.0)))
(t_1
(fma
(cos phi2)
(pow (sin (* 0.5 lambda1)) 2.0)
(pow (sin (* -0.5 phi2)) 2.0)))
(t_2 (* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))))
(if (<= phi2 -6.2e-10)
t_2
(if (<= phi2 2.8e-8)
(* R (* 2.0 (atan2 (sqrt t_0) (sqrt (- 1.0 t_0)))))
t_2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = fma(cos(phi1), pow(sin((0.5 * (lambda1 - lambda2))), 2.0), pow(sin((0.5 * phi1)), 2.0));
double t_1 = fma(cos(phi2), pow(sin((0.5 * lambda1)), 2.0), pow(sin((-0.5 * phi2)), 2.0));
double t_2 = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
double tmp;
if (phi2 <= -6.2e-10) {
tmp = t_2;
} else if (phi2 <= 2.8e-8) {
tmp = R * (2.0 * atan2(sqrt(t_0), sqrt((1.0 - t_0))));
} else {
tmp = t_2;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = fma(cos(phi1), (sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0), (sin(Float64(0.5 * phi1)) ^ 2.0)) t_1 = fma(cos(phi2), (sin(Float64(0.5 * lambda1)) ^ 2.0), (sin(Float64(-0.5 * phi2)) ^ 2.0)) t_2 = Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1))))) tmp = 0.0 if (phi2 <= -6.2e-10) tmp = t_2; elseif (phi2 <= 2.8e-8) tmp = Float64(R * Float64(2.0 * atan(sqrt(t_0), sqrt(Float64(1.0 - t_0))))); else tmp = t_2; end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi1], $MachinePrecision] * N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(0.5 * lambda1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = 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]}, If[LessEqual[phi2, -6.2e-10], t$95$2, If[LessEqual[phi2, 2.8e-8], 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], t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\cos \phi_1, {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)\\
t_1 := \mathsf{fma}\left(\cos \phi_2, {\sin \left(0.5 \cdot \lambda_1\right)}^{2}, {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)\\
t_2 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right)\\
\mathbf{if}\;\phi_2 \leq -6.2 \cdot 10^{-10}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;\phi_2 \leq 2.8 \cdot 10^{-8}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_0}}{\sqrt{1 - t\_0}}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if phi2 < -6.2000000000000003e-10 or 2.7999999999999999e-8 < phi2 Initial program 47.0%
Taylor expanded in lambda2 around 0
Applied rewrites37.8%
Taylor expanded in lambda2 around 0
Applied rewrites37.8%
Taylor expanded in phi1 around 0
Applied rewrites38.0%
Taylor expanded in phi1 around 0
Applied rewrites38.5%
if -6.2000000000000003e-10 < phi2 < 2.7999999999999999e-8Initial program 77.9%
Taylor expanded in phi2 around 0
Applied rewrites75.6%
Taylor expanded in phi2 around 0
Applied rewrites75.6%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0
(fma
(cos phi1)
(pow (sin (* 0.5 lambda1)) 2.0)
(pow (sin (* 0.5 (- phi1 phi2))) 2.0)))
(t_1
(fma
(cos phi1)
(pow (sin (* -0.5 lambda2)) 2.0)
(pow (sin (* 0.5 phi1)) 2.0)))
(t_2 (* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))))
(if (<= lambda2 -3e-14)
t_2
(if (<= lambda2 1.06e-19)
(* R (* 2.0 (atan2 (sqrt t_0) (sqrt (- 1.0 t_0)))))
t_2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = fma(cos(phi1), pow(sin((0.5 * lambda1)), 2.0), pow(sin((0.5 * (phi1 - phi2))), 2.0));
double t_1 = fma(cos(phi1), pow(sin((-0.5 * lambda2)), 2.0), pow(sin((0.5 * phi1)), 2.0));
double t_2 = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
double tmp;
if (lambda2 <= -3e-14) {
tmp = t_2;
} else if (lambda2 <= 1.06e-19) {
tmp = R * (2.0 * atan2(sqrt(t_0), sqrt((1.0 - t_0))));
} else {
tmp = t_2;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = fma(cos(phi1), (sin(Float64(0.5 * lambda1)) ^ 2.0), (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0)) t_1 = fma(cos(phi1), (sin(Float64(-0.5 * lambda2)) ^ 2.0), (sin(Float64(0.5 * phi1)) ^ 2.0)) t_2 = Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1))))) tmp = 0.0 if (lambda2 <= -3e-14) tmp = t_2; elseif (lambda2 <= 1.06e-19) tmp = Float64(R * Float64(2.0 * atan(sqrt(t_0), sqrt(Float64(1.0 - t_0))))); else tmp = t_2; end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi1], $MachinePrecision] * N[Power[N[Sin[N[(0.5 * lambda1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi1], $MachinePrecision] * N[Power[N[Sin[N[(-0.5 * lambda2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = 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]}, If[LessEqual[lambda2, -3e-14], t$95$2, If[LessEqual[lambda2, 1.06e-19], 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], t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\cos \phi_1, {\sin \left(0.5 \cdot \lambda_1\right)}^{2}, {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)\\
t_1 := \mathsf{fma}\left(\cos \phi_1, {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)\\
t_2 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right)\\
\mathbf{if}\;\lambda_2 \leq -3 \cdot 10^{-14}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;\lambda_2 \leq 1.06 \cdot 10^{-19}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_0}}{\sqrt{1 - t\_0}}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if lambda2 < -2.9999999999999998e-14 or 1.06e-19 < lambda2 Initial program 48.3%
Taylor expanded in phi2 around 0
Applied rewrites38.9%
Taylor expanded in phi2 around 0
Applied rewrites39.2%
Taylor expanded in lambda1 around 0
Applied rewrites38.5%
Taylor expanded in lambda1 around 0
Applied rewrites38.4%
if -2.9999999999999998e-14 < lambda2 < 1.06e-19Initial program 76.4%
Taylor expanded in lambda2 around 0
Applied rewrites73.9%
Taylor expanded in lambda2 around 0
Applied rewrites73.9%
Taylor expanded in phi2 around 0
Applied rewrites64.9%
Taylor expanded in phi2 around 0
Applied rewrites63.4%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 phi1)) 2.0))
(t_1 (fma (cos phi1) (pow (sin (* -0.5 lambda2)) 2.0) t_0))
(t_2 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_3 (fma (cos phi1) (pow (sin (* 0.5 lambda1)) 2.0) t_0)))
(if (<= phi1 -4.8e+22)
(* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))
(if (<= phi1 0.0021)
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) t_2))
(sqrt (- 1.0 (fma (cos phi2) t_2 (pow (sin (* -0.5 phi2)) 2.0)))))))
(* R (* 2.0 (atan2 (sqrt t_3) (sqrt (- 1.0 t_3)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin((0.5 * phi1)), 2.0);
double t_1 = fma(cos(phi1), pow(sin((-0.5 * lambda2)), 2.0), t_0);
double t_2 = pow(sin((0.5 * (lambda1 - lambda2))), 2.0);
double t_3 = fma(cos(phi1), pow(sin((0.5 * lambda1)), 2.0), t_0);
double tmp;
if (phi1 <= -4.8e+22) {
tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
} else if (phi1 <= 0.0021) {
tmp = R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + t_2)), sqrt((1.0 - fma(cos(phi2), t_2, pow(sin((-0.5 * phi2)), 2.0))))));
} else {
tmp = R * (2.0 * atan2(sqrt(t_3), sqrt((1.0 - t_3))));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * phi1)) ^ 2.0 t_1 = fma(cos(phi1), (sin(Float64(-0.5 * lambda2)) ^ 2.0), t_0) t_2 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_3 = fma(cos(phi1), (sin(Float64(0.5 * lambda1)) ^ 2.0), t_0) tmp = 0.0 if (phi1 <= -4.8e+22) tmp = Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1))))); elseif (phi1 <= 0.0021) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + t_2)), sqrt(Float64(1.0 - fma(cos(phi2), t_2, (sin(Float64(-0.5 * phi2)) ^ 2.0))))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(t_3), sqrt(Float64(1.0 - t_3))))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi1], $MachinePrecision] * N[Power[N[Sin[N[(-0.5 * lambda2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[(N[Cos[phi1], $MachinePrecision] * N[Power[N[Sin[N[(0.5 * lambda1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + t$95$0), $MachinePrecision]}, If[LessEqual[phi1, -4.8e+22], 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], If[LessEqual[phi1, 0.0021], 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$2), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Cos[phi2], $MachinePrecision] * t$95$2 + N[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$3], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$3), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \phi_1\right)}^{2}\\
t_1 := \mathsf{fma}\left(\cos \phi_1, {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, t\_0\right)\\
t_2 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_3 := \mathsf{fma}\left(\cos \phi_1, {\sin \left(0.5 \cdot \lambda_1\right)}^{2}, t\_0\right)\\
\mathbf{if}\;\phi_1 \leq -4.8 \cdot 10^{+22}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right)\\
\mathbf{elif}\;\phi_1 \leq 0.0021:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t\_2}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_2, t\_2, {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_3}}{\sqrt{1 - t\_3}}\right)\\
\end{array}
\end{array}
if phi1 < -4.8e22Initial program 46.0%
Taylor expanded in phi2 around 0
Applied rewrites46.8%
Taylor expanded in phi2 around 0
Applied rewrites47.8%
Taylor expanded in lambda1 around 0
Applied rewrites38.8%
Taylor expanded in lambda1 around 0
Applied rewrites38.5%
if -4.8e22 < phi1 < 0.00209999999999999987Initial program 76.2%
Taylor expanded in phi2 around 0
Applied rewrites58.5%
Taylor expanded in phi2 around 0
Applied rewrites54.3%
Taylor expanded in phi1 around 0
Applied rewrites57.4%
Taylor expanded in phi1 around 0
Applied rewrites57.4%
if 0.00209999999999999987 < phi1 Initial program 47.0%
Taylor expanded in phi2 around 0
Applied rewrites47.8%
Taylor expanded in phi2 around 0
Applied rewrites48.5%
Taylor expanded in lambda1 around inf
Applied rewrites39.5%
Taylor expanded in lambda1 around inf
Applied rewrites39.2%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_1
(fma
(cos phi1)
(pow (sin (* -0.5 lambda2)) 2.0)
(pow (sin (* 0.5 phi1)) 2.0)))
(t_2 (* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))))
(if (<= phi1 -4.8e+22)
t_2
(if (<= phi1 0.0022)
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) t_0))
(sqrt (- 1.0 (fma (cos phi2) t_0 (pow (sin (* -0.5 phi2)) 2.0)))))))
t_2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin((0.5 * (lambda1 - lambda2))), 2.0);
double t_1 = fma(cos(phi1), pow(sin((-0.5 * lambda2)), 2.0), pow(sin((0.5 * phi1)), 2.0));
double t_2 = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
double tmp;
if (phi1 <= -4.8e+22) {
tmp = t_2;
} else if (phi1 <= 0.0022) {
tmp = R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + t_0)), sqrt((1.0 - fma(cos(phi2), t_0, pow(sin((-0.5 * phi2)), 2.0))))));
} else {
tmp = t_2;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_1 = fma(cos(phi1), (sin(Float64(-0.5 * lambda2)) ^ 2.0), (sin(Float64(0.5 * phi1)) ^ 2.0)) t_2 = Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1))))) tmp = 0.0 if (phi1 <= -4.8e+22) tmp = t_2; elseif (phi1 <= 0.0022) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + t_0)), sqrt(Float64(1.0 - fma(cos(phi2), t_0, (sin(Float64(-0.5 * phi2)) ^ 2.0))))))); else tmp = t_2; end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi1], $MachinePrecision] * N[Power[N[Sin[N[(-0.5 * lambda2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = 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]}, If[LessEqual[phi1, -4.8e+22], t$95$2, If[LessEqual[phi1, 0.0022], 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$0), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Cos[phi2], $MachinePrecision] * t$95$0 + N[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_1 := \mathsf{fma}\left(\cos \phi_1, {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)\\
t_2 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right)\\
\mathbf{if}\;\phi_1 \leq -4.8 \cdot 10^{+22}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;\phi_1 \leq 0.0022:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t\_0}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_2, t\_0, {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if phi1 < -4.8e22 or 0.00220000000000000013 < phi1 Initial program 46.6%
Taylor expanded in phi2 around 0
Applied rewrites47.3%
Taylor expanded in phi2 around 0
Applied rewrites48.1%
Taylor expanded in lambda1 around 0
Applied rewrites39.5%
Taylor expanded in lambda1 around 0
Applied rewrites39.2%
if -4.8e22 < phi1 < 0.00220000000000000013Initial program 76.2%
Taylor expanded in phi2 around 0
Applied rewrites58.5%
Taylor expanded in phi2 around 0
Applied rewrites54.3%
Taylor expanded in phi1 around 0
Applied rewrites57.4%
Taylor expanded in phi1 around 0
Applied rewrites57.4%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
(t_1 (sin (* 0.5 (- lambda1 lambda2))))
(t_2 (pow t_1 2.0))
(t_3 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0))
(t_4 (+ t_3 t_2)))
(if (<= t_0 -0.31)
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (* 0.5 phi1)) 2.0) t_2))
(sqrt (- 1.0 (fma (cos phi2) t_2 (pow (sin (* -0.5 phi2)) 2.0)))))))
(if (<= t_0 0.448)
(* R (* 2.0 (atan2 (sqrt t_4) (sqrt (- 1.0 t_4)))))
(*
R
(*
2.0
(atan2
t_1
(sqrt
(- 1.0 (+ t_3 (* (* (* (cos phi1) (cos phi2)) t_0) t_0)))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
double t_1 = sin((0.5 * (lambda1 - lambda2)));
double t_2 = pow(t_1, 2.0);
double t_3 = pow(sin(((phi1 - phi2) / 2.0)), 2.0);
double t_4 = t_3 + t_2;
double tmp;
if (t_0 <= -0.31) {
tmp = R * (2.0 * atan2(sqrt((pow(sin((0.5 * phi1)), 2.0) + t_2)), sqrt((1.0 - fma(cos(phi2), t_2, pow(sin((-0.5 * phi2)), 2.0))))));
} else if (t_0 <= 0.448) {
tmp = R * (2.0 * atan2(sqrt(t_4), sqrt((1.0 - t_4))));
} else {
tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - (t_3 + (((cos(phi1) * cos(phi2)) * t_0) * t_0))))));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) t_2 = t_1 ^ 2.0 t_3 = sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0 t_4 = Float64(t_3 + t_2) tmp = 0.0 if (t_0 <= -0.31) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(0.5 * phi1)) ^ 2.0) + t_2)), sqrt(Float64(1.0 - fma(cos(phi2), t_2, (sin(Float64(-0.5 * phi2)) ^ 2.0))))))); elseif (t_0 <= 0.448) tmp = Float64(R * Float64(2.0 * atan(sqrt(t_4), sqrt(Float64(1.0 - t_4))))); else tmp = Float64(R * Float64(2.0 * atan(t_1, sqrt(Float64(1.0 - Float64(t_3 + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_0) * t_0))))))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Power[t$95$1, 2.0], $MachinePrecision]}, Block[{t$95$3 = N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$4 = N[(t$95$3 + t$95$2), $MachinePrecision]}, If[LessEqual[t$95$0, -0.31], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Cos[phi2], $MachinePrecision] * t$95$2 + N[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.448], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$4], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$4), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[t$95$1 / N[Sqrt[N[(1.0 - N[(t$95$3 + N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)\\
t_2 := {t\_1}^{2}\\
t_3 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
t_4 := t\_3 + t\_2\\
\mathbf{if}\;t\_0 \leq -0.31:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(0.5 \cdot \phi_1\right)}^{2} + t\_2}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_2, t\_2, {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)}}\right)\\
\mathbf{elif}\;t\_0 \leq 0.448:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_4}}{\sqrt{1 - t\_4}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t\_1}{\sqrt{1 - \left(t\_3 + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_0\right) \cdot t\_0\right)}}\right)\\
\end{array}
\end{array}
if (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) < -0.309999999999999998Initial program 55.4%
Taylor expanded in phi2 around 0
Applied rewrites42.8%
Taylor expanded in phi2 around 0
Applied rewrites39.3%
Taylor expanded in phi1 around 0
Applied rewrites32.6%
Taylor expanded in phi1 around inf
Applied rewrites33.4%
Taylor expanded in phi1 around 0
Applied rewrites33.3%
if -0.309999999999999998 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) < 0.448000000000000009Initial program 68.4%
Taylor expanded in phi2 around 0
Applied rewrites63.1%
Taylor expanded in phi2 around 0
Applied rewrites62.6%
Taylor expanded in phi1 around 0
Applied rewrites58.3%
Taylor expanded in phi1 around 0
Applied rewrites57.7%
if 0.448000000000000009 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) Initial program 57.3%
Taylor expanded in phi1 around 0
Applied rewrites41.8%
Taylor expanded in phi2 around 0
Applied rewrites34.1%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
(t_1 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0))
(t_2 (sin (* 0.5 (- lambda1 lambda2))))
(t_3 (pow t_2 2.0))
(t_4 (+ t_1 t_3)))
(if (<= t_0 -0.31)
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (* 0.5 phi1)) 2.0) (* (cos phi1) t_3)))
(sqrt (- 1.0 t_3)))))
(if (<= t_0 0.448)
(* R (* 2.0 (atan2 (sqrt t_4) (sqrt (- 1.0 t_4)))))
(*
R
(*
2.0
(atan2
t_2
(sqrt
(- 1.0 (+ t_1 (* (* (* (cos phi1) (cos phi2)) t_0) t_0)))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
double t_1 = pow(sin(((phi1 - phi2) / 2.0)), 2.0);
double t_2 = sin((0.5 * (lambda1 - lambda2)));
double t_3 = pow(t_2, 2.0);
double t_4 = t_1 + t_3;
double tmp;
if (t_0 <= -0.31) {
tmp = R * (2.0 * atan2(sqrt((pow(sin((0.5 * phi1)), 2.0) + (cos(phi1) * t_3))), sqrt((1.0 - t_3))));
} else if (t_0 <= 0.448) {
tmp = R * (2.0 * atan2(sqrt(t_4), sqrt((1.0 - t_4))));
} else {
tmp = R * (2.0 * atan2(t_2, sqrt((1.0 - (t_1 + (((cos(phi1) * cos(phi2)) * t_0) * t_0))))));
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(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 = sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0
t_2 = sin((0.5d0 * (lambda1 - lambda2)))
t_3 = t_2 ** 2.0d0
t_4 = t_1 + t_3
if (t_0 <= (-0.31d0)) then
tmp = r * (2.0d0 * atan2(sqrt(((sin((0.5d0 * phi1)) ** 2.0d0) + (cos(phi1) * t_3))), sqrt((1.0d0 - t_3))))
else if (t_0 <= 0.448d0) then
tmp = r * (2.0d0 * atan2(sqrt(t_4), sqrt((1.0d0 - t_4))))
else
tmp = r * (2.0d0 * atan2(t_2, sqrt((1.0d0 - (t_1 + (((cos(phi1) * cos(phi2)) * t_0) * t_0))))))
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.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0);
double t_2 = Math.sin((0.5 * (lambda1 - lambda2)));
double t_3 = Math.pow(t_2, 2.0);
double t_4 = t_1 + t_3;
double tmp;
if (t_0 <= -0.31) {
tmp = R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin((0.5 * phi1)), 2.0) + (Math.cos(phi1) * t_3))), Math.sqrt((1.0 - t_3))));
} else if (t_0 <= 0.448) {
tmp = R * (2.0 * Math.atan2(Math.sqrt(t_4), Math.sqrt((1.0 - t_4))));
} else {
tmp = R * (2.0 * Math.atan2(t_2, Math.sqrt((1.0 - (t_1 + (((Math.cos(phi1) * Math.cos(phi2)) * t_0) * t_0))))));
}
return tmp;
}
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) t_2 = math.sin((0.5 * (lambda1 - lambda2))) t_3 = math.pow(t_2, 2.0) t_4 = t_1 + t_3 tmp = 0 if t_0 <= -0.31: tmp = R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin((0.5 * phi1)), 2.0) + (math.cos(phi1) * t_3))), math.sqrt((1.0 - t_3)))) elif t_0 <= 0.448: tmp = R * (2.0 * math.atan2(math.sqrt(t_4), math.sqrt((1.0 - t_4)))) else: tmp = R * (2.0 * math.atan2(t_2, math.sqrt((1.0 - (t_1 + (((math.cos(phi1) * math.cos(phi2)) * t_0) * t_0)))))) return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0 t_2 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) t_3 = t_2 ^ 2.0 t_4 = Float64(t_1 + t_3) tmp = 0.0 if (t_0 <= -0.31) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(0.5 * phi1)) ^ 2.0) + Float64(cos(phi1) * t_3))), sqrt(Float64(1.0 - t_3))))); elseif (t_0 <= 0.448) tmp = Float64(R * Float64(2.0 * atan(sqrt(t_4), sqrt(Float64(1.0 - t_4))))); else tmp = Float64(R * Float64(2.0 * atan(t_2, sqrt(Float64(1.0 - Float64(t_1 + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_0) * t_0))))))); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(((lambda1 - lambda2) / 2.0)); t_1 = sin(((phi1 - phi2) / 2.0)) ^ 2.0; t_2 = sin((0.5 * (lambda1 - lambda2))); t_3 = t_2 ^ 2.0; t_4 = t_1 + t_3; tmp = 0.0; if (t_0 <= -0.31) tmp = R * (2.0 * atan2(sqrt(((sin((0.5 * phi1)) ^ 2.0) + (cos(phi1) * t_3))), sqrt((1.0 - t_3)))); elseif (t_0 <= 0.448) tmp = R * (2.0 * atan2(sqrt(t_4), sqrt((1.0 - t_4)))); else tmp = R * (2.0 * atan2(t_2, sqrt((1.0 - (t_1 + (((cos(phi1) * cos(phi2)) * t_0) * t_0)))))); 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[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Power[t$95$2, 2.0], $MachinePrecision]}, Block[{t$95$4 = N[(t$95$1 + t$95$3), $MachinePrecision]}, If[LessEqual[t$95$0, -0.31], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * t$95$3), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$3), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.448], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$4], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$4), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[t$95$2 / N[Sqrt[N[(1.0 - N[(t$95$1 + N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $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}\\
t_2 := \sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)\\
t_3 := {t\_2}^{2}\\
t_4 := t\_1 + t\_3\\
\mathbf{if}\;t\_0 \leq -0.31:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(0.5 \cdot \phi_1\right)}^{2} + \cos \phi_1 \cdot t\_3}}{\sqrt{1 - t\_3}}\right)\\
\mathbf{elif}\;t\_0 \leq 0.448:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_4}}{\sqrt{1 - t\_4}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t\_2}{\sqrt{1 - \left(t\_1 + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_0\right) \cdot t\_0\right)}}\right)\\
\end{array}
\end{array}
if (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) < -0.309999999999999998Initial program 55.4%
Taylor expanded in phi2 around 0
Applied rewrites42.8%
Taylor expanded in phi2 around 0
Applied rewrites39.3%
Taylor expanded in phi1 around 0
Applied rewrites32.6%
Taylor expanded in phi1 around inf
Applied rewrites33.4%
Taylor expanded in phi2 around 0
Applied rewrites33.0%
if -0.309999999999999998 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) < 0.448000000000000009Initial program 68.4%
Taylor expanded in phi2 around 0
Applied rewrites63.1%
Taylor expanded in phi2 around 0
Applied rewrites62.6%
Taylor expanded in phi1 around 0
Applied rewrites58.3%
Taylor expanded in phi1 around 0
Applied rewrites57.7%
if 0.448000000000000009 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) Initial program 57.3%
Taylor expanded in phi1 around 0
Applied rewrites41.8%
Taylor expanded in phi2 around 0
Applied rewrites34.1%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
(t_1 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_2 (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) t_1))
(t_3
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (* 0.5 phi1)) 2.0) (* (cos phi1) t_1)))
(sqrt (- 1.0 t_1)))))))
(if (<= t_0 -0.31)
t_3
(if (<= t_0 0.448)
(* R (* 2.0 (atan2 (sqrt t_2) (sqrt (- 1.0 t_2)))))
t_3))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
double t_1 = pow(sin((0.5 * (lambda1 - lambda2))), 2.0);
double t_2 = pow(sin(((phi1 - phi2) / 2.0)), 2.0) + t_1;
double t_3 = R * (2.0 * atan2(sqrt((pow(sin((0.5 * phi1)), 2.0) + (cos(phi1) * t_1))), sqrt((1.0 - t_1))));
double tmp;
if (t_0 <= -0.31) {
tmp = t_3;
} else if (t_0 <= 0.448) {
tmp = R * (2.0 * atan2(sqrt(t_2), sqrt((1.0 - t_2))));
} else {
tmp = t_3;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: tmp
t_0 = sin(((lambda1 - lambda2) / 2.0d0))
t_1 = sin((0.5d0 * (lambda1 - lambda2))) ** 2.0d0
t_2 = (sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + t_1
t_3 = r * (2.0d0 * atan2(sqrt(((sin((0.5d0 * phi1)) ** 2.0d0) + (cos(phi1) * t_1))), sqrt((1.0d0 - t_1))))
if (t_0 <= (-0.31d0)) then
tmp = t_3
else if (t_0 <= 0.448d0) then
tmp = r * (2.0d0 * atan2(sqrt(t_2), sqrt((1.0d0 - t_2))))
else
tmp = t_3
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.pow(Math.sin((0.5 * (lambda1 - lambda2))), 2.0);
double t_2 = Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_1;
double t_3 = R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin((0.5 * phi1)), 2.0) + (Math.cos(phi1) * t_1))), Math.sqrt((1.0 - t_1))));
double tmp;
if (t_0 <= -0.31) {
tmp = t_3;
} else if (t_0 <= 0.448) {
tmp = R * (2.0 * Math.atan2(Math.sqrt(t_2), Math.sqrt((1.0 - t_2))));
} else {
tmp = t_3;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((lambda1 - lambda2) / 2.0)) t_1 = math.pow(math.sin((0.5 * (lambda1 - lambda2))), 2.0) t_2 = math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_1 t_3 = R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin((0.5 * phi1)), 2.0) + (math.cos(phi1) * t_1))), math.sqrt((1.0 - t_1)))) tmp = 0 if t_0 <= -0.31: tmp = t_3 elif t_0 <= 0.448: tmp = R * (2.0 * math.atan2(math.sqrt(t_2), math.sqrt((1.0 - t_2)))) else: tmp = t_3 return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_2 = Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + t_1) t_3 = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(0.5 * phi1)) ^ 2.0) + Float64(cos(phi1) * t_1))), sqrt(Float64(1.0 - t_1))))) tmp = 0.0 if (t_0 <= -0.31) tmp = t_3; elseif (t_0 <= 0.448) tmp = Float64(R * Float64(2.0 * atan(sqrt(t_2), sqrt(Float64(1.0 - t_2))))); else tmp = t_3; end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(((lambda1 - lambda2) / 2.0)); t_1 = sin((0.5 * (lambda1 - lambda2))) ^ 2.0; t_2 = (sin(((phi1 - phi2) / 2.0)) ^ 2.0) + t_1; t_3 = R * (2.0 * atan2(sqrt(((sin((0.5 * phi1)) ^ 2.0) + (cos(phi1) * t_1))), sqrt((1.0 - t_1)))); tmp = 0.0; if (t_0 <= -0.31) tmp = t_3; elseif (t_0 <= 0.448) tmp = R * (2.0 * atan2(sqrt(t_2), sqrt((1.0 - t_2)))); else tmp = t_3; 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[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.31], t$95$3, If[LessEqual[t$95$0, 0.448], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$2], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$2), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$3]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_2 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t\_1\\
t_3 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(0.5 \cdot \phi_1\right)}^{2} + \cos \phi_1 \cdot t\_1}}{\sqrt{1 - t\_1}}\right)\\
\mathbf{if}\;t\_0 \leq -0.31:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;t\_0 \leq 0.448:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_2}}{\sqrt{1 - t\_2}}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_3\\
\end{array}
\end{array}
if (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) < -0.309999999999999998 or 0.448000000000000009 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) Initial program 56.3%
Taylor expanded in phi2 around 0
Applied rewrites44.2%
Taylor expanded in phi2 around 0
Applied rewrites40.7%
Taylor expanded in phi1 around 0
Applied rewrites33.0%
Taylor expanded in phi1 around inf
Applied rewrites33.9%
Taylor expanded in phi2 around 0
Applied rewrites33.5%
if -0.309999999999999998 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) < 0.448000000000000009Initial program 68.4%
Taylor expanded in phi2 around 0
Applied rewrites63.1%
Taylor expanded in phi2 around 0
Applied rewrites62.6%
Taylor expanded in phi1 around 0
Applied rewrites58.3%
Taylor expanded in phi1 around 0
Applied rewrites57.7%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(pow (sin (* 0.5 (- lambda1 lambda2))) 2.0)))
(t_1
(fma
(cos phi2)
(pow (sin (* 0.5 lambda1)) 2.0)
(pow (sin (* -0.5 phi2)) 2.0))))
(if (<= lambda1 -1.38e-33)
(* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))
(* 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 = pow(sin(((phi1 - phi2) / 2.0)), 2.0) + pow(sin((0.5 * (lambda1 - lambda2))), 2.0);
double t_1 = fma(cos(phi2), pow(sin((0.5 * lambda1)), 2.0), pow(sin((-0.5 * phi2)), 2.0));
double tmp;
if (lambda1 <= -1.38e-33) {
tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
} else {
tmp = R * (2.0 * atan2(sqrt(t_0), sqrt((1.0 - t_0))));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + (sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0)) t_1 = fma(cos(phi2), (sin(Float64(0.5 * lambda1)) ^ 2.0), (sin(Float64(-0.5 * phi2)) ^ 2.0)) tmp = 0.0 if (lambda1 <= -1.38e-33) tmp = Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(t_0), sqrt(Float64(1.0 - t_0))))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(0.5 * lambda1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda1, -1.38e-33], 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], 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 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_1 := \mathsf{fma}\left(\cos \phi_2, {\sin \left(0.5 \cdot \lambda_1\right)}^{2}, {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)\\
\mathbf{if}\;\lambda_1 \leq -1.38 \cdot 10^{-33}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_0}}{\sqrt{1 - t\_0}}\right)\\
\end{array}
\end{array}
if lambda1 < -1.38e-33Initial program 49.8%
Taylor expanded in lambda2 around 0
Applied rewrites47.2%
Taylor expanded in lambda2 around 0
Applied rewrites47.2%
Taylor expanded in phi1 around 0
Applied rewrites38.6%
Taylor expanded in phi1 around 0
Applied rewrites38.9%
if -1.38e-33 < lambda1 Initial program 66.2%
Taylor expanded in phi2 around 0
Applied rewrites57.2%
Taylor expanded in phi2 around 0
Applied rewrites55.2%
Taylor expanded in phi1 around 0
Applied rewrites47.0%
Taylor expanded in phi1 around 0
Applied rewrites43.7%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
(t_1 (pow (sin (* 0.5 (- phi1 phi2))) 2.0))
(t_2 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_3
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (* 0.5 phi1)) 2.0) (* (cos phi1) t_2)))
(sqrt (- 1.0 t_2)))))))
(if (<= t_0 -2e-16)
t_3
(if (<= t_0 0.2)
(* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))
t_3))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
double t_1 = pow(sin((0.5 * (phi1 - phi2))), 2.0);
double t_2 = pow(sin((0.5 * (lambda1 - lambda2))), 2.0);
double t_3 = R * (2.0 * atan2(sqrt((pow(sin((0.5 * phi1)), 2.0) + (cos(phi1) * t_2))), sqrt((1.0 - t_2))));
double tmp;
if (t_0 <= -2e-16) {
tmp = t_3;
} else if (t_0 <= 0.2) {
tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
} else {
tmp = t_3;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: tmp
t_0 = sin(((lambda1 - lambda2) / 2.0d0))
t_1 = sin((0.5d0 * (phi1 - phi2))) ** 2.0d0
t_2 = sin((0.5d0 * (lambda1 - lambda2))) ** 2.0d0
t_3 = r * (2.0d0 * atan2(sqrt(((sin((0.5d0 * phi1)) ** 2.0d0) + (cos(phi1) * t_2))), sqrt((1.0d0 - t_2))))
if (t_0 <= (-2d-16)) then
tmp = t_3
else if (t_0 <= 0.2d0) then
tmp = r * (2.0d0 * atan2(sqrt(t_1), sqrt((1.0d0 - t_1))))
else
tmp = t_3
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.pow(Math.sin((0.5 * (phi1 - phi2))), 2.0);
double t_2 = Math.pow(Math.sin((0.5 * (lambda1 - lambda2))), 2.0);
double t_3 = R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin((0.5 * phi1)), 2.0) + (Math.cos(phi1) * t_2))), Math.sqrt((1.0 - t_2))));
double tmp;
if (t_0 <= -2e-16) {
tmp = t_3;
} else if (t_0 <= 0.2) {
tmp = R * (2.0 * Math.atan2(Math.sqrt(t_1), Math.sqrt((1.0 - t_1))));
} else {
tmp = t_3;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((lambda1 - lambda2) / 2.0)) t_1 = math.pow(math.sin((0.5 * (phi1 - phi2))), 2.0) t_2 = math.pow(math.sin((0.5 * (lambda1 - lambda2))), 2.0) t_3 = R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin((0.5 * phi1)), 2.0) + (math.cos(phi1) * t_2))), math.sqrt((1.0 - t_2)))) tmp = 0 if t_0 <= -2e-16: tmp = t_3 elif t_0 <= 0.2: tmp = R * (2.0 * math.atan2(math.sqrt(t_1), math.sqrt((1.0 - t_1)))) else: tmp = t_3 return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0 t_2 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_3 = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(0.5 * phi1)) ^ 2.0) + Float64(cos(phi1) * t_2))), sqrt(Float64(1.0 - t_2))))) tmp = 0.0 if (t_0 <= -2e-16) tmp = t_3; elseif (t_0 <= 0.2) tmp = Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1))))); else tmp = t_3; end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(((lambda1 - lambda2) / 2.0)); t_1 = sin((0.5 * (phi1 - phi2))) ^ 2.0; t_2 = sin((0.5 * (lambda1 - lambda2))) ^ 2.0; t_3 = R * (2.0 * atan2(sqrt(((sin((0.5 * phi1)) ^ 2.0) + (cos(phi1) * t_2))), sqrt((1.0 - t_2)))); tmp = 0.0; if (t_0 <= -2e-16) tmp = t_3; elseif (t_0 <= 0.2) tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1)))); else tmp = t_3; 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[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$2), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e-16], t$95$3, If[LessEqual[t$95$0, 0.2], 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], t$95$3]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\\
t_2 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_3 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(0.5 \cdot \phi_1\right)}^{2} + \cos \phi_1 \cdot t\_2}}{\sqrt{1 - t\_2}}\right)\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-16}:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;t\_0 \leq 0.2:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_3\\
\end{array}
\end{array}
if (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) < -2e-16 or 0.20000000000000001 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) Initial program 56.9%
Taylor expanded in phi2 around 0
Applied rewrites44.9%
Taylor expanded in phi2 around 0
Applied rewrites41.9%
Taylor expanded in phi1 around 0
Applied rewrites33.7%
Taylor expanded in phi1 around inf
Applied rewrites33.9%
Taylor expanded in phi2 around 0
Applied rewrites33.5%
if -2e-16 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) < 0.20000000000000001Initial program 73.4%
Taylor expanded in lambda2 around 0
Applied rewrites65.9%
Taylor expanded in lambda2 around 0
Applied rewrites65.8%
Taylor expanded in lambda1 around 0
Applied rewrites58.6%
Taylor expanded in lambda1 around 0
Applied rewrites58.6%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 (- phi1 phi2))) 2.0))
(t_1 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_2 (sin (/ (- lambda1 lambda2) 2.0)))
(t_3 (* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))))
(if (<= t_2 -2e-16)
t_3
(if (<= t_2 0.2)
(* R (* 2.0 (atan2 (sqrt t_0) (sqrt (- 1.0 t_0)))))
t_3))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin((0.5 * (phi1 - phi2))), 2.0);
double t_1 = pow(sin((0.5 * (lambda1 - lambda2))), 2.0);
double t_2 = sin(((lambda1 - lambda2) / 2.0));
double t_3 = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
double tmp;
if (t_2 <= -2e-16) {
tmp = t_3;
} else if (t_2 <= 0.2) {
tmp = R * (2.0 * atan2(sqrt(t_0), sqrt((1.0 - t_0))));
} else {
tmp = t_3;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: tmp
t_0 = sin((0.5d0 * (phi1 - phi2))) ** 2.0d0
t_1 = sin((0.5d0 * (lambda1 - lambda2))) ** 2.0d0
t_2 = sin(((lambda1 - lambda2) / 2.0d0))
t_3 = r * (2.0d0 * atan2(sqrt(t_1), sqrt((1.0d0 - t_1))))
if (t_2 <= (-2d-16)) then
tmp = t_3
else if (t_2 <= 0.2d0) then
tmp = r * (2.0d0 * atan2(sqrt(t_0), sqrt((1.0d0 - t_0))))
else
tmp = t_3
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.pow(Math.sin((0.5 * (phi1 - phi2))), 2.0);
double t_1 = Math.pow(Math.sin((0.5 * (lambda1 - lambda2))), 2.0);
double t_2 = Math.sin(((lambda1 - lambda2) / 2.0));
double t_3 = R * (2.0 * Math.atan2(Math.sqrt(t_1), Math.sqrt((1.0 - t_1))));
double tmp;
if (t_2 <= -2e-16) {
tmp = t_3;
} else if (t_2 <= 0.2) {
tmp = R * (2.0 * Math.atan2(Math.sqrt(t_0), Math.sqrt((1.0 - t_0))));
} else {
tmp = t_3;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.pow(math.sin((0.5 * (phi1 - phi2))), 2.0) t_1 = math.pow(math.sin((0.5 * (lambda1 - lambda2))), 2.0) t_2 = math.sin(((lambda1 - lambda2) / 2.0)) t_3 = R * (2.0 * math.atan2(math.sqrt(t_1), math.sqrt((1.0 - t_1)))) tmp = 0 if t_2 <= -2e-16: tmp = t_3 elif t_2 <= 0.2: tmp = R * (2.0 * math.atan2(math.sqrt(t_0), math.sqrt((1.0 - t_0)))) else: tmp = t_3 return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0 t_1 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_2 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_3 = Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1))))) tmp = 0.0 if (t_2 <= -2e-16) tmp = t_3; elseif (t_2 <= 0.2) tmp = Float64(R * Float64(2.0 * atan(sqrt(t_0), sqrt(Float64(1.0 - t_0))))); else tmp = t_3; end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = sin((0.5 * (phi1 - phi2))) ^ 2.0; t_1 = sin((0.5 * (lambda1 - lambda2))) ^ 2.0; t_2 = sin(((lambda1 - lambda2) / 2.0)); t_3 = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1)))); tmp = 0.0; if (t_2 <= -2e-16) tmp = t_3; elseif (t_2 <= 0.2) tmp = R * (2.0 * atan2(sqrt(t_0), sqrt((1.0 - t_0)))); else tmp = t_3; end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = 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]}, If[LessEqual[t$95$2, -2e-16], t$95$3, If[LessEqual[t$95$2, 0.2], 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], t$95$3]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\\
t_1 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_2 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_3 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right)\\
\mathbf{if}\;t\_2 \leq -2 \cdot 10^{-16}:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;t\_2 \leq 0.2:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_0}}{\sqrt{1 - t\_0}}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_3\\
\end{array}
\end{array}
if (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) < -2e-16 or 0.20000000000000001 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) Initial program 56.9%
Taylor expanded in phi2 around 0
Applied rewrites45.1%
Taylor expanded in phi2 around 0
Applied rewrites45.3%
Taylor expanded in phi1 around 0
Applied rewrites33.4%
Taylor expanded in phi1 around 0
Applied rewrites32.9%
if -2e-16 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) < 0.20000000000000001Initial program 73.4%
Taylor expanded in lambda2 around 0
Applied rewrites65.9%
Taylor expanded in lambda2 around 0
Applied rewrites65.8%
Taylor expanded in lambda1 around 0
Applied rewrites58.6%
Taylor expanded in lambda1 around 0
Applied rewrites58.6%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (let* ((t_0 (pow (sin (* 0.5 (- phi1 phi2))) 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 = pow(sin((0.5 * (phi1 - phi2))), 2.0);
return R * (2.0 * atan2(sqrt(t_0), sqrt((1.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((0.5d0 * (phi1 - phi2))) ** 2.0d0
code = r * (2.0d0 * atan2(sqrt(t_0), sqrt((1.0d0 - t_0))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.pow(Math.sin((0.5 * (phi1 - phi2))), 2.0);
return R * (2.0 * Math.atan2(Math.sqrt(t_0), Math.sqrt((1.0 - t_0))));
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.pow(math.sin((0.5 * (phi1 - phi2))), 2.0) return R * (2.0 * math.atan2(math.sqrt(t_0), math.sqrt((1.0 - t_0))))
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0 return Float64(R * Float64(2.0 * atan(sqrt(t_0), sqrt(Float64(1.0 - t_0))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) t_0 = sin((0.5 * (phi1 - phi2))) ^ 2.0; tmp = R * (2.0 * atan2(sqrt(t_0), sqrt((1.0 - t_0)))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $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 := {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_0}}{\sqrt{1 - t\_0}}\right)
\end{array}
\end{array}
Initial program 61.8%
Taylor expanded in lambda2 around 0
Applied rewrites46.0%
Taylor expanded in lambda2 around 0
Applied rewrites45.9%
Taylor expanded in lambda1 around 0
Applied rewrites29.6%
Taylor expanded in lambda1 around 0
Applied rewrites29.6%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 phi1)) 2.0))
(t_1 (pow (sin (* -0.5 phi2)) 2.0))
(t_2 (* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))))
(if (<= phi2 -2.2e-35)
t_2
(if (<= phi2 4.3e-14)
(* R (* 2.0 (atan2 (sqrt t_0) (sqrt (- 1.0 t_0)))))
t_2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin((0.5 * phi1)), 2.0);
double t_1 = pow(sin((-0.5 * phi2)), 2.0);
double t_2 = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
double tmp;
if (phi2 <= -2.2e-35) {
tmp = t_2;
} else if (phi2 <= 4.3e-14) {
tmp = R * (2.0 * atan2(sqrt(t_0), sqrt((1.0 - t_0))));
} else {
tmp = t_2;
}
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) :: tmp
t_0 = sin((0.5d0 * phi1)) ** 2.0d0
t_1 = sin(((-0.5d0) * phi2)) ** 2.0d0
t_2 = r * (2.0d0 * atan2(sqrt(t_1), sqrt((1.0d0 - t_1))))
if (phi2 <= (-2.2d-35)) then
tmp = t_2
else if (phi2 <= 4.3d-14) then
tmp = r * (2.0d0 * atan2(sqrt(t_0), sqrt((1.0d0 - t_0))))
else
tmp = t_2
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.pow(Math.sin((0.5 * phi1)), 2.0);
double t_1 = Math.pow(Math.sin((-0.5 * phi2)), 2.0);
double t_2 = R * (2.0 * Math.atan2(Math.sqrt(t_1), Math.sqrt((1.0 - t_1))));
double tmp;
if (phi2 <= -2.2e-35) {
tmp = t_2;
} else if (phi2 <= 4.3e-14) {
tmp = R * (2.0 * Math.atan2(Math.sqrt(t_0), Math.sqrt((1.0 - t_0))));
} else {
tmp = t_2;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.pow(math.sin((0.5 * phi1)), 2.0) t_1 = math.pow(math.sin((-0.5 * phi2)), 2.0) t_2 = R * (2.0 * math.atan2(math.sqrt(t_1), math.sqrt((1.0 - t_1)))) tmp = 0 if phi2 <= -2.2e-35: tmp = t_2 elif phi2 <= 4.3e-14: tmp = R * (2.0 * math.atan2(math.sqrt(t_0), math.sqrt((1.0 - t_0)))) else: tmp = t_2 return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * phi1)) ^ 2.0 t_1 = sin(Float64(-0.5 * phi2)) ^ 2.0 t_2 = Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1))))) tmp = 0.0 if (phi2 <= -2.2e-35) tmp = t_2; elseif (phi2 <= 4.3e-14) tmp = Float64(R * Float64(2.0 * atan(sqrt(t_0), sqrt(Float64(1.0 - t_0))))); else tmp = t_2; end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = sin((0.5 * phi1)) ^ 2.0; t_1 = sin((-0.5 * phi2)) ^ 2.0; t_2 = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1)))); tmp = 0.0; if (phi2 <= -2.2e-35) tmp = t_2; elseif (phi2 <= 4.3e-14) tmp = R * (2.0 * atan2(sqrt(t_0), sqrt((1.0 - t_0)))); else tmp = t_2; end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = 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]}, If[LessEqual[phi2, -2.2e-35], t$95$2, If[LessEqual[phi2, 4.3e-14], 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], t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \phi_1\right)}^{2}\\
t_1 := {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\\
t_2 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right)\\
\mathbf{if}\;\phi_2 \leq -2.2 \cdot 10^{-35}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;\phi_2 \leq 4.3 \cdot 10^{-14}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_0}}{\sqrt{1 - t\_0}}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if phi2 < -2.19999999999999994e-35 or 4.29999999999999998e-14 < phi2 Initial program 48.3%
Taylor expanded in lambda2 around 0
Applied rewrites38.5%
Taylor expanded in lambda2 around 0
Applied rewrites38.5%
Taylor expanded in lambda1 around 0
Applied rewrites29.3%
Taylor expanded in lambda1 around 0
Applied rewrites29.6%
Taylor expanded in phi1 around 0
Applied rewrites28.6%
Taylor expanded in phi1 around 0
Applied rewrites28.5%
if -2.19999999999999994e-35 < phi2 < 4.29999999999999998e-14Initial program 78.2%
Taylor expanded in lambda2 around 0
Applied rewrites55.1%
Taylor expanded in lambda2 around 0
Applied rewrites54.9%
Taylor expanded in lambda1 around 0
Applied rewrites29.8%
Taylor expanded in lambda1 around 0
Applied rewrites29.6%
Taylor expanded in phi1 around inf
Applied rewrites27.4%
Taylor expanded in phi1 around inf
Applied rewrites27.4%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (let* ((t_0 (pow (sin (* -0.5 phi2)) 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 = pow(sin((-0.5 * phi2)), 2.0);
return R * (2.0 * atan2(sqrt(t_0), sqrt((1.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(((-0.5d0) * phi2)) ** 2.0d0
code = r * (2.0d0 * atan2(sqrt(t_0), sqrt((1.0d0 - t_0))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.pow(Math.sin((-0.5 * phi2)), 2.0);
return R * (2.0 * Math.atan2(Math.sqrt(t_0), Math.sqrt((1.0 - t_0))));
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.pow(math.sin((-0.5 * phi2)), 2.0) return R * (2.0 * math.atan2(math.sqrt(t_0), math.sqrt((1.0 - t_0))))
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(-0.5 * phi2)) ^ 2.0 return Float64(R * Float64(2.0 * atan(sqrt(t_0), sqrt(Float64(1.0 - t_0))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) t_0 = sin((-0.5 * phi2)) ^ 2.0; tmp = R * (2.0 * atan2(sqrt(t_0), sqrt((1.0 - t_0)))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $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 := {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_0}}{\sqrt{1 - t\_0}}\right)
\end{array}
\end{array}
Initial program 61.8%
Taylor expanded in lambda2 around 0
Applied rewrites46.0%
Taylor expanded in lambda2 around 0
Applied rewrites45.9%
Taylor expanded in lambda1 around 0
Applied rewrites29.6%
Taylor expanded in lambda1 around 0
Applied rewrites29.6%
Taylor expanded in phi1 around 0
Applied rewrites19.2%
Taylor expanded in phi1 around 0
Applied rewrites19.2%
herbie shell --seed 2025121
(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))))))))))